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 | 821_A. Okabe and Future Gadget Laboratory | Solve the following coding problem using the programming language python:
Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an n by n square grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed a... | ```python
def good(lab):
for i, line in enumerate(lab):
for j, item in enumerate(line):
if item == 1:
continue
flag = False
for k, x in enumerate(line):
if j==k:
continue
col = [l[j] for l in lab]
... | vfc_81073 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 1 2\n2 3 1\n6 4 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 5 2\n1 1 1\n1 2 3\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 847_A. Union of Doubly Linked Lists | Solve the following coding problem using the programming language python:
Doubly linked list is one of the fundamental data structures. A doubly linked list is a sequence of elements, each containing information about the previous and the next elements of the list. In this problem all lists have linear structure. I.e.... | ```python
if __name__=='__main__':
n=int(input())
dl=[[0,0]]
end=0
for i in range(n):
dl.append(list(map(int,input().split())))
for i in range(1,n+1):
if not dl[i][0]:
dl[end][1]=i
dl[i][0]=end
j=i
while(dl[j][1]):
#print(dl[j])
#j+=1
j=dl[j][1]
end=j
for node in dl[1:]:
print(*no... | vfc_81077 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n4 7\n5 0\n0 0\n6 1\n0 2\n0 4\n1 0\n",
"output": "4 7\n5 6\n0 5\n6 1\n3 2\n2 4\n1 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\... |
code_contests | verifiable_code | 893_F. Subtree Minimum Query | Solve the following coding problem using the programming language python:
You are given a rooted tree consisting of n vertices. Each vertex has a number written on it; number ai is written on vertex i.
Let's denote d(i, j) as the distance between vertices i and j in the tree (that is, the number of edges in the short... | ```python
py2 = round(0.5)
if py2:
from future_builtins import ascii, filter, hex, map, oct, zip
range = xrange
def sync_with_stdio(b):
if b: return
import os, sys
from io import BytesIO, IOBase
# FastIO for PyPy2 and PyPy3 (works with interactive) by Pajenegod
class FastI(object):
... | vfc_81085 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 6, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n1 3 2 3 5\n2 3\n5 1\n3 4\n4 1\n2\n1 2\n2 3\n",
"output": "2\n5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n1 3 2\n1 2\n1 3\n2\n2 3\n1 1\n",
"output": "2\n1\n",
"t... |
code_contests | verifiable_code | 915_C. Permute Digits | Solve the following coding problem using the programming language python:
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.
It is allowed to leave a as it is.
Input
T... | ```python
import copy
Num1, Num2 = sorted(list(input())), list(input())
Num1.reverse()
Temp1, Temp2, i, j, Result= copy.copy(Num1), copy.copy(Num2), 0, 0, []
if len(Temp1) < len(Temp2):
print(''.join(Temp1))
exit()
while True:
if i + 1 > len(Temp1):
Temp1.append(Result[len(Result) - 1])
Te... | vfc_81089 | {
"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": "4940\n5000\n",
"output": "4940\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3921\n10000\n",
"output": "9321\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 938_D. Buy a Ticket | Solve the following coding problem using the programming language python:
Musicians of a popular band "Flayer" have announced that they are going to "make their exit" with a world tour. Of course, they will visit Berland as well.
There are n cities in Berland. People can travel between cities using two-directional tr... | ```python
from __future__ import division, print_function
import os
import sys
import io
class FastI():
""" FastIO for PyPy3 by Pajenegod """
stream = io.BytesIO()
newlines = 0
def read1(self):
b, ptr = os.read(0, (1 << 13) + os.fstat(0).st_size), self.stream.tell()
self.stream.seek(... | vfc_81093 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\n1 2 4\n2 3 7\n6 20 1 25\n",
"output": "6 14 1 25 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n1 2 1\n2 3 1\n1 3 1\n30 10 20\n",
"output": "12 10 12 ",
"type": "stdi... |
code_contests | verifiable_code | 963_D. Frequency of String | Solve the following coding problem using the programming language python:
You are given a string s. You should answer n queries. The i-th query consists of integer k_i and string m_i. The answer for this query is the minimum length of such a string t that t is a substring of s and m_i has at least k_i occurrences as a... | vfc_81097 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "aaaaa\n5\n3 a\n3 aa\n2 aaa\n3 aaaa\n1 aaaaa\n",
"output": "3\n4\n4\n-1\n5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "abbb\n7\n4 b\n1 ab\n3 bb\n1 abb\n2 bbb\n1 a\n2 abbb\n",
"out... | |
code_contests | verifiable_code | 990_G. GCD Counting | Solve the following coding problem using the programming language python:
You are given a tree consisting of n vertices. A number is written on each vertex; the number on vertex i is equal to a_i.
Let's denote the function g(x, y) as the greatest common divisor of the numbers written on the vertices belonging to the ... | ```python
import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict, deque, Counter, OrderedDict
import threading
def main():
ans = 1
flag = True
primes = []
for i in range(2, 500):
v = 1
for p in primes:
if i % p == 0: v = 0
if v: pr... | vfc_81101 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n9 16 144 6\n1 3\n2 3\n4 3\n",
"output": "1 1\n2 1\n3 1\n6 2\n9 2\n16 2\n144 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1 2 4 8 16 32\n1 6\n6 3\n3 4\n4 2\n6 5\n",
"output... |
code_contests | verifiable_code | aprileasy-the-one-with-the-queries-3 | Solve the following coding problem using the programming language python:
You are given a string S and Q query strings (q1, q2, ... , qQ). For each query string, report whether or not it is a subsequence of S.
Input :
The first line contains a string S.
The next line contains a single integer, Q.
The following Q l... | ```python
ind=0
z=""
f=0
x=raw_input()
for _ in xrange(input()):
f=0
z=x
y=raw_input()
for i in xrange(len(y)):
if y[i] in z:
ind=z.index(y[i])
z=z[ind+1:]
else:
f=1
break
if f==1:
print "No"
else:... | vfc_81105 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "hello\n5\nworld\nlo\nelo\nhl\nol\n\nSAMPLE",
"output": "No\nYes\nYes\nYes\nNo\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "hello\n5\nworld\nln\nelo\nhl\nol\n\nSAMPLE",
"output": "... |
code_contests | verifiable_code | chandu-and-his-playing-area | Solve the following coding problem using the programming language python:
Little chandu is very fond of playing games. Recently, He found a few straws each of length 1 inches in the store room. He took all of them and decided to mark a rectangular area on the floor with straws and warn rest of the family members to no... | ```python
import sys
import math
t=input()
for i in range(0,t):
m = input();
if m%2 == 1 :
m=m-1;
b=m/4;
a=m/2-b;
n= a*b;
print n;
``` | vfc_81109 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n6\n9\n11\n\nSAMPLE",
"output": "2\n4\n6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n1207244\n255313\n56\n83269\n638451\n347617\n29369\n233941\n61\n7937\n85\n6\n80\n2485\n7\n639... |
code_contests | verifiable_code | divide-apples | Solve the following coding problem using the programming language python:
N boys are sitting in a circle. Each of them have some apples in their hand. You find that the total number of the apples can be divided by N. So you want to divide the apples equally among all the boys. But they are so lazy that each one of the... | ```python
n = int(raw_input())
a = map(long,raw_input().split(' '))
avg = sum(a)/n
p = a[0]-avg
b = [p]
for x in a[1:]:
p = p + x -avg
b.append(p)
b.sort()
mid = b[len(b)/2]
total = sum(map(lambda x:abs(x-mid),b))
print total
``` | vfc_81113 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 3 9 7\n\nSAMPLE",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 3 9 7",
"output": "8\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | good-points | Solve the following coding problem using the programming language python:
You are given non-negative integer N. Find N pairwise different points on the Euclidean plane with integer coordinates in the corresponding order and the following properties:
1) the distance between any two consecutive points in the order is e... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
test=1
for i in range(test):
a=int(raw_input())
if a != 1 and a !=2 and a != 4:
print "NO"
break;
else:
print "YES"
print "0 0"
if a == 1:
break;
if a == 4:
... | vfc_81117 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n\nSAMPLE",
"output": "YES\n0 0\n0 1\n1 1\n1 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null... |
code_contests | verifiable_code | little-achraf-in-who-wants-to-be-a-millionaire | Solve the following coding problem using the programming language python:
“Can you answer this million dollar question ?” said the presenter to Little Achraf.
“Yes”, he responded.
“Ok … here is the question”.
We define a sequence A of strings of order L as follows:
A[n] = \sum\limits_{i = 0}^{L-1} A[n-L+i]; n ≥... | ```python
import sys
L,C= map(int,raw_input().split())
f = [1]*(L+1)
f[0] = 0
ind = L
while f[ind] <= 10**20:
ind+=1
x = 0
for i in range(ind-L,ind):
x+=f[i]
f.append(x)
for i in range(0,L):
x = 0
for i in range(len(f)-L,len(f)):
x += f[i]
f.append(x)
def fun(a,n):
... | vfc_81121 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n1 3 A\n3 5 B\n\nSAMPLE",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 11\n72 11 L\n1 3 Y\n2 5 d\n1 4 v\n70 12 B\n5 6 C\n72 10 f\n141 12 s\n1 3 n\n12646 19 L\n1 5 x",... |
code_contests | verifiable_code | monks-love-for-food | Solve the following coding problem using the programming language python:
Our monk loves food. Hence,he took up position of a manager at Sagar,a restaurant that serves people with delicious food packages. It is a very famous place and people are always queuing up to have one of those packages. Each package has a cost... | ```python
stack=[]
for _ in range(input()):
n = map(int, raw_input().split())
if len(n) == 1:
if stack == []:
print "No Food"
else:
print stack[-1]
stack = stack[:-1]
elif len(n) == 2:
stack.append(n[1])
``` | vfc_81125 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n1\n2 5\n2 7\n2 9\n1\n1\n\nSAMPLE",
"output": "No Food\n9\n7\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | sachins-love-letter-a | Solve the following coding problem using the programming language python:
Sachin wants to give a love letter to his girlfriend on valentines day. He
is having a circular piece of paper of radius "r".
He wants to use rectangular piece of paper for letter writing whose length and breadth are integers. In how many way... | ```python
print 424
``` | vfc_81133 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "12",
"output": "424",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "23",
"output": "424\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | sum-of-numbers-9 | Solve the following coding problem using the programming language python:
Given an array of N elements, check if it is possible to obtain a sum of S, by choosing some (or none) elements of the array and adding them.
Input:
First line of the input contains number of test cases T. Each test case has three lines.
First ... | ```python
import math
def yesno(result, arr):
sums = [0]
for n in arr:
new_sums = []
for sum in sums:
new_sum = sum + n
if new_sum == result:
return "YES"
else:
new_sums.append(new_sum)
sums += new_sums
retu... | vfc_81137 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5\n3 2 0 7 -1\n8\n3\n-1 3 3\n4\n3\n4 -5 1\n5\n\nSAMPLE",
"output": "YES\nNO\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "50\n13\n34423 -366726 -147520 -584399 615107 415987 -236... |
code_contests | verifiable_code | way-to-follow-on-grid | Solve the following coding problem using the programming language python:
You are situated in an N dimensional grid at position (x1,x2,...,xN). The dimensions of the grid are (D1,D2,...DN). In one step, you can walk one step ahead or behind in any one of the N dimensions. (So there are always 2×N possible different mo... | ```python
MOD = 1000000007
def solve(n, m, x, d):
mat = [[0 for i in range(n + 1)] for j in range(m + 1)]
for i in range(n):
mat1 = [[0 for j in range(m + 1)] for k in range(d[i] + 1)]
D = d[i]
for j in range(1, D + 1):
mat1[j][0] = 1
for j in range(1, m + 1):
for k in range(1, D + 1):
mat1[k][j] = ... | vfc_81141 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 287\n44\n78\n1 236\n25\n87\n1 122\n41\n63\n1 260\n7\n64\n1 127\n3\n73\n\nSAMPLE",
"output": "38753340\n587915072\n644474045\n423479916\n320130104",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | p00037 Path on a Grid | Solve the following coding problem using the programming language python:
Seen from above, there is a grid-like square shaped like Figure 1. The presence or absence of "walls" on each side of this grid is represented by a sequence of 0s and 1s. Create a program that stands at point A, puts your right hand on the wall,... | ```python
import sys
loc = [3, 1]
def print_dir(h):
if h == 0:
print('R', end='')
elif h == 1:
print('D', end='')
elif h == 2:
print('L', end='')
elif h == 3:
print('U', end='')
dir = [[1, 0], [0, 1], [-1, 0], [0, -1]]
hand = 3
board = [[0 for _ in range(11)] for _ in... | vfc_81185 | {
"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": "1111\n00001\n0110\n01011\n0010\n01111\n0010\n01001\n0111",
"output": "RRRRDDDDLLLUUURRDDLURULLDDDRRRUUUULLLL",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1111\n00001\n0110\n01011\n0010\n0... |
code_contests | verifiable_code | p00169 Blackjack | Solve the following coding problem using the programming language python:
Blackjack is a type of card game played in casinos, where the game is played using cards with numbers from 1 to 13. The score of each card is decided as follows.
* 1 is 1 point or 11 points
* From 2 to 9, the score is as written.
* 10 points fr... | ```python
while True:
inp = input()
if inp == '0': break
inp = inp.replace('11', '10')
inp = inp.replace('12', '10')
inp = inp.replace('13', '10')
cards = tuple(map(int, inp.split()))
ans = sum(cards)
for i in range(cards.count(1)):
if sum(cards) + 10 * (i+1) > 21:
... | vfc_81189 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n7 7 7\n7 7 8\n12 1\n10 1 1\n0",
"output": "11\n21\n0\n21\n12",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n7 7 7\n7 7 8\n12 1\n10 1 2\n0",
"output": "11\n21\n0\n21\n13\n",
... |
code_contests | verifiable_code | p00497 Nails | Solve the following coding problem using the programming language python:
JOI is playing with a nail in the board. As shown in the figure below, JOI stabbed nails in the shape of an equilateral triangle with N sides. A nails are lined up in the ath line (1 ≤ a ≤ N) from the top. The bth nail (1 ≤ b ≤ a) from the left ... | ```python
n,m = map(int,input().split())
t = [[0]*(n+2) for i in range(n+2)]
for i in range(m):
a,b,x = map(int,input().split())
a -= 1
b -= 1
t[a][b] += 1
t[a][b+1] -= 1
t[a+x+1][b] -= 1
t[a+x+1][b+x+2] += 1
t[a+x+2][b+1] += 1
t[a+x+2][b+x+2] -= 1
for i in range(n+2):
for ... | vfc_81197 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "None",
"output": "None",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n2 2 1\n2 1 3",
"output": "12",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input... |
code_contests | verifiable_code | p00682 Area of Polygons | Solve the following coding problem using the programming language python:
Polygons are the most fundamental objects in geometric processing. Complex figures are often represented and handled as polygons with many short sides. If you are interested in the processing of geometric data, you'd better try some programming ... | ```python
idx = 1
while True:
n = int(input())
if n==0: break
x = []
y = []
for _ in range(n):
a,b = map(int,input().split())
x.append(a)
y.append(b)
x.append(x[0])
y.append(y[0])
s = 0.0
for i in range(n):
s += x[i]*y[i+1] - x[i+1]*y[i]
print(idx... | vfc_81201 | {
"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 1\n3 4\n6 0\n\n7\n0 0\n10 10\n0 20\n10 30\n0 40\n100 40\n100 0\n\n0",
"output": "1 8.5\n2 3800.0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 1\n3 4\n6 0\n\n7\n0 0\n10 10\n0 20\... |
code_contests | verifiable_code | p00824 Gap | Solve the following coding problem using the programming language python:
Let’s play a card game called Gap.
You have 28 cards labeled with two-digit numbers. The first digit (from 1 to 4) represents the suit of the card, and the second digit (from 1 to 7) represents the value of the card.
First, you shuffle the car... | vfc_81205 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n\n12 13 14 15 16 17 21\n22 23 24 25 26 27 31\n32 33 34 35 36 37 41\n42 43 44 45 46 47 11\n\n26 31 13 44 21 24 42\n17 45 23 25 41 36 11\n46 34 14 12 37 32 47\n16 43 27 35 22 33 15\n\n17 12 16 13 15 14 11\n27 22 26 23 25 24 21\n37... | |
code_contests | verifiable_code | p00955 Cover the Polygon with Your Disk | Solve the following coding problem using the programming language python:
Example
Input
4 4
0 0
6 0
6 6
0 6
Output
35.759506
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_81209 | {
"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": "4 4\n0 0\n6 0\n6 6\n0 6",
"output": "35.759506",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n0 0\n6 0\n6 6\n0 6",
"output": "12.5663705873\n",
"type": "stdin_stdout"
}... | |
code_contests | verifiable_code | p01088 500-yen Saving | Solve the following coding problem using the programming language python:
500-yen Saving
"500-yen Saving" is one of Japanese famous methods to save money. The method is quite simple; whenever you receive a 500-yen coin in your change of shopping, put the coin to your 500-yen saving box. Typically, you will find more ... | ```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**13
mod = 10**9+9
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in ... | vfc_81213 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n800\n700\n1600\n600\n4\n300\n700\n1600\n600\n4\n300\n700\n1600\n650\n3\n1000\n2000\n500\n3\n250\n250\n1000\n4\n1251\n667\n876\n299\n0",
"output": "2 2900\n3 2500\n3 3250\n1 500\n3 1500\n3 2217",
"type": "stdin_stdout... |
code_contests | verifiable_code | p01224 Perfect Number | Solve the following coding problem using the programming language python:
Let S be the sum of divisors of an integer N excluding the number itself. When N = S, N is called a perfect number, when N> S, N is called a defendant number, and when N <S, N is called an abundant number. Create a program that determines whethe... | ```python
def f(p):
ans=1
if p<=5: return 0
for n in range(2,int(p**0.5)+1):
if p%n==0:
if n!=p//n:ans+=n+p//n
else:ans+=n
return ans
while 1:
n=int(input())
if n==0:break
m=f(n)
if n==m:print('perfect number')
else: print('deficient number' if n>m el... | vfc_81217 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2\n3\n4\n6\n12\n16\n28\n33550336\n99999998\n99999999\n100000000\n0",
"output": "deficient number\ndeficient number\ndeficient number\ndeficient number\nperfect number\nabundant number\ndeficient number\nperfect number\nper... |
code_contests | verifiable_code | p01540 Treasure Hunt | Solve the following coding problem using the programming language python:
Taro came to a square to look for treasure. There are many treasures buried in this square, but Taro has the latest machines, so he knows everything about where the treasures are buried. Since the square is very wide Taro decided to look for the... | ```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 = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in ... | vfc_81225 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 204472320,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5\n10 5\n-3 -8\n2 11\n6 0\n-1 3\n-3 1 3 13\n-1 -1 9 5\n-3 -8 10 11\n0 0 5 5\n-10 -9 15 10",
"output": "2\n2\n5\n0\n4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n1 1\n2 4\n5 3\n0 0... |
code_contests | verifiable_code | p01696 Broken Cipher Generator | Solve the following coding problem using the programming language python:
Broken crypto generator
JAG (Japanese Alumni Group) is a mysterious organization composed of many programmers, and in order to enter the building where the headquarters of this organization is located, it is necessary to solve the ciphertext ge... | ```python
def pm_to_chr(s):
s=s.group()
if s[-1]=='?':
return 'A'
ans=chr((((ord(s[-1])+s.count('+')-s.count('-'))-ord('A'))%26)+ord('A'))
return ans
def reverse(s):
s=s.group()
s=s[1:-1]
ans=''.join(reversed(s))
return ans
import re
s=input()
while s!='.':
s=re.sub("[\+\-... | vfc_81229 | {
"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": "A+A++A\nZ-Z--Z+-Z\n[ESREVER]\nJ---?---J\n++++++++A+++Z-----------A+++Z\n[[++-+--?[--++-?++-+++L]][-+-----+-O]]++++---+L\n.",
"output": "ABC\nZYXZ\nREVERSE\nJAG\nICPC\nJAPAN",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p01840 Delivery to a Luxurious House | Solve the following coding problem using the programming language python:
B-Mansion and courier
Problem Statement
Taro lives alone in a mansion. Taro, who loves studying, intends to study in his study in the house today. Taro can't concentrate outside the study, so he always studies in the study.
However, on this d... | ```python
l_raw = input().split()
l = [int(n) for n in l_raw]
a_raw = input().split()
a_ = [int(n) for n in a_raw]
study = 0
state = 0
now=0
for a in a_:
if state==0:
if l[1]<a-now:
study+=a-now-l[1]
now=a
state=1
elif state==1:
if 2*l[1]<a-now:
study+=a... | vfc_81233 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1 5\n3",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 5\n6",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1... |
code_contests | verifiable_code | p01976 Anagram | Solve the following coding problem using the programming language python:
problem
Given a sequence $ a_i $ of length $ N $. Output all integers $ K (1 \ le K \ le N) $ that satisfy the following conditions.
Condition: Well sorted $ a_1, \ cdots, a_K $ matches $ a_ {N-K + 1}, \ cdots, a_N $.
Example
Input
8
5 ... | ```python
from collections import Counter
n = int(input())
a = input().split()
# a = list(map(int, input().split()))
ans = ''
# t1, t2 = [], []
t1, t2 = Counter(), Counter()
for i in range(n):
t1.update(a[i])
t2.update(a[n-1-i])
t3 = t1 & t2
t1 -= t3
t2 -= t3
if t1 == t2:
ans += str(i+1... | vfc_81237 | {
"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": "8\n5 2 4 9 4 9 2 5",
"output": "1 2 4 6 7 8",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p02262 Shell Sort | Solve the following coding problem using the programming language python:
Shell Sort
Shell Sort is a generalization of Insertion Sort to arrange a list of $n$ elements $A$.
1 insertionSort(A, n, g)
2 for i = g to n-1
3 v = A[i]
4 j = i - g
5 while j >= 0 && A[j] > v
6 A... | ```python
def insertionSort(a, n, g):
global cnt
for i in range(g, n):
v = a[i]
j = i - g
while j >= 0 and a[j] > v:
a[j+g] = a[j]
j = j - g
cnt = cnt + 1
a[j+g] = v
def shellSort(a, n):
global cnt
global G
global m
cnt = 0
... | vfc_81245 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 6, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n5\n1\n4\n3\n2",
"output": "2\n4 1\n3\n1\n2\n3\n4\n5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3\n2\n1",
"output": "1\n1\n3\n1\n2\n3",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | p02410 Matrix Vector Multiplication | Solve the following coding problem using the programming language python:
Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$.
A column vector with m elements is represented by the following equation.
\\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\... | ```python
n, m = list(map(int, input().split()))
matrix_a = [list(map(int, input().split())) for i in range(n)]
matrix_b = [int(input()) for i in range(m)]
for i in range(n):
print(sum([x*y for (x,y) in zip(matrix_b,matrix_a[i])]))
``` | vfc_81249 | {
"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 4\n1 2 0 1\n0 3 0 1\n4 1 1 0\n1\n2\n3\n0",
"output": "5\n6\n9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n1 4 0 1\n0 3 0 1\n4 1 1 0\n1\n2\n3\n0",
"output": "9\n6\n9\n",
... |
code_contests | verifiable_code | arithm | Solve the following coding problem using the programming language python:
Chef's encounters with sweets continue with this problem! This time, he wants to distribute chocolates to his N students sitting on a long bench. The students are ordered according to the scores they got from the last exam.
Chef wants to give m... | ```python
t=input()
while t!=0:
n,c=raw_input().split(' ')
n=int(n)
c=int(c)
s=0
flag=0
d=1
first=0
last=0
while d<=2:
first=(2*c-n*(n-1)*d)/(2*n)
if first<1:
flag=0
break
last=first+(n-1)*d
s=n*(first + last)/2
... | vfc_81253 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 24\n2 2",
"output": "Yes\nNo",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | clco03 | Solve the following coding problem using the programming language python:
Arush was not always poor at Mathematics but his recent performances had not been that good and he had lost his confidence. Now his elder brother was determined to bring back his confidence back in Mathematics.
So he made a tricky question and m... | ```python
t=input()
for x in range(t):
l=input()
r=raw_input()
s=''
for i in range(l):
# if i==0 or i==1:
# continue
if r[i]=='2' or r[i]=='3' or r[i]=='5' or r[i]=='7':
s=s+r[i]
elif r[i]=='4':
s=s+'322'
elif r[i]=='6':
s+='35'
elif r[i]=='8':
s+='2227'
elif r[i]=='9':
s+='7332'
s=sort... | vfc_81257 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1\n6\n3\n006",
"output": "53\n53",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | fctrl2 | Solve the following coding problem using the programming language python:
A tutorial for this problem is now available on our blog. Click here to read it.
You are asked to calculate factorials of some small positive integers.
Input
An integer t, 1 ≤ t ≤ 100, denoting the number of testcases, followed by t lines, e... | ```python
t=input()
while t > 0:
m=1
x=input()
for i in range(x):
m=m * x
x=x-1
print m
t=t-1
``` | vfc_81261 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1\n2\n5\n3",
"output": "1\n2\n120\n6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n2\n2\n5\n3",
"output": "2\n2\n120\n6\n",
"type": "stdin_stdout"
},
{
"f... |
code_contests | verifiable_code | lebamboo | Solve the following coding problem using the programming language python:
Problem Statement
Little Elephant from Zoo of Lviv likes bamboo very much. He currently has n stems of bamboo, Hi - height of i-th stem of bamboo (0-based numeration).
Today inspector Andrii from World Bamboo Association is visiting the planta... | ```python
for _ in xrange(int(raw_input())):
n = int(raw_input())
l1 = map(int, raw_input().split())
l2 = map(int, raw_input().split())
s1 = sum(l1)
s2 = sum(l2)
if n == 1:
if s2 > s1:
print -1
if s2 == s1:
print 0
if s1 > s2:
print s1 - s2
elif n == 2:
if s1 != s2:
print -1
else:
print ... | vfc_81265 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1\n1\n2\n2\n1 2\n2 1\n3\n3 2 2\n4 5 3",
"output": "-1\n1\n5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1\n1\n2\n2\n1 2\n2 1\n1\n3 2 2\n4 5 3",
"output": "-1\n1\n-1\n",
... |
code_contests | verifiable_code | plgrm | Solve the following coding problem using the programming language python:
For Turbo C++ Users : Read the following document before attempting the question :
Problem Description
N-Boy is very eccentric when it comes to strings. These days, he spends most of his time studying palindromes and pangrams (for his IP ass... | ```python
#Enter your code here
import sys
a=set('abcdefghijklmnopqrstuvwxzy')
sys.stdin.readline()
f=sys.stdin.readlines()
for i in f:
i=i.strip()
if i[::-1]==i and set(i)==a:print 'palingram'
elif i[::-1]==i:print 'palindrome'
elif set(i)==a:print 'pangram'
else:print 'none'
``` | vfc_81269 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nabba\nabcdefghijklmnopqrstuvwxyz\nqwerty",
"output": "palindrome\npangram\nnone\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nabba\nfbcdeaghijklmnopqrstuvwxyz\nqwerty",
"outp... |
code_contests | verifiable_code | sub_perm | Solve the following coding problem using the programming language python:
A factory called 'IP Labs Pvt. Ltd.' has produced some material, which is in the form of blocks. Each block is labeled by an alphanumeric character. You've been recently hired as Packaging Manager, and your job is to rearrange the huge lot of ma... | ```python
import sys
t=int(input())
while t>0:
A=list(raw_input())
B=list(raw_input())
C=list(set(B))
D=[]
F=[]
Arr=[]
for i in xrange(len(C)):
x=(A.count(C[i]))/(B.count(C[i]))
Arr.append(x)
print min(Arr)
t=t-1
``` | vfc_81273 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nareyouafoobarmember\nbarfoo\nfofoforabrabbbbbbfoooooooaaa\nfoobar\nthisisiplab\nsi\nababa\naa",
"output": "1\n2\n2\n1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\nareyouafoobarmembe... |
code_contests | verifiable_code | 1009_G. Allowed Letters | Solve the following coding problem using the programming language python:
Polycarp has just launched his new startup idea. The niche is pretty free and the key vector of development sounds really promising, so he easily found himself some investors ready to sponsor the company. However, he is yet to name the startup!
... | vfc_81277 | {
"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": "abacaba\n0\n",
"output": "aaaabbc",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "bedefead\n5\n2 e\n1 dc\n5 b\n7 ef\n6 ef\n",
"output": "deadbeef",
"type": "stdin_stdout"
},
... | |
code_contests | verifiable_code | 1055_B. Alice and Hairdresser | Solve the following coding problem using the programming language python:
Alice's hair is growing by leaps and bounds. Maybe the cause of it is the excess of vitamins, or maybe it is some black magic...
To prevent this, Alice decided to go to the hairdresser. She wants for her hair length to be at most l centimeters ... | ```python
n, m, l = map(int, input().split())
a = list(map(int, input().split()))
nexxt = {}
prevv = {}
nexxt[-1] = n
prevv[n] = -1
summ = 0
p = -1
l += 1
for k in range(n):
if a[k] < l:
p1 = p
p = k
nexxt[k] = n
prevv[k] = p1
nexxt[p1] = k
if k - prevv[k] > 1:
... | vfc_81285 | {
"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 7 3\n1 2 3 4\n0\n1 2 3\n0\n1 1 3\n0\n1 3 1\n0\n",
"output": "1\n2\n2\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 24 2\n1 1 1 1 1 1 1 1 1 1\n0\n1 1 1\n0\n1 1 1\n0\n1 3 2\n1 5 2\... |
code_contests | verifiable_code | 1077_C. Good Array | Solve the following coding problem using the programming language python:
Let's call an array good if there is an element in the array that equals to the sum of all other elements. For example, the array a=[1, 3, 3, 7] is good because there is the element a_4=7 which equals to the sum 1 + 3 + 3.
You are given an arra... | ```python
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
d=dict()
for i in range(n):
if a[i] in d:
d[a[i]].append(i+1)
else:
d[a[i]]=[i+1]
ans=[]
for k in d.keys():
if (s-k)%2>0:
continue
m=(s-k)//2
#print(m)
if m in d and (m!=k or len(d[k])>1):
ans+=d[k... | vfc_81289 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 5 1 2 2\n",
"output": "3\n1 4 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n8 3 5 2\n",
"output": "2\n1 4\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | 1098_B. 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... | ```python
from itertools import permutations
from sys import stdin, stdout
ly, lx = map(int, input().split())
grid = [[c for c in inp] for inp in stdin.read().splitlines()]
first = set()
bl = []
bpattern = []
bcost = 1e6
flip_row = False
for l in permutations('AGCT'):
if bcost == 0:
break
if ''.join(l... | vfc_81293 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\nAG\nCT\n",
"output": "AG\nCT\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 5\nAGCAG\nAGCAG\nAGCAG\n",
"output": "AGCTC\nCTAGA\nAGCTC\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 1145_G. AI Takeover | Solve the following coding problem using the programming language python:
The recent advances in AI research has brought humanity to the point when the AIs finally attempt a takeover. Their weapon of choice? The [most intellectually challenging game in the world](//codeforces.com/contest/409/problem/A), rock-paper-sci... | vfc_81301 | {
"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": "5\n",
"output": "R\nR\nR\nR\nP\nS\nS\nP\nR\nR\n\u0000\n\u0000\n\u0000\n\u0000\n\u0000\n\u0000\n\u0000\n\u0000\n\u0000\n\u0000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n",
"o... | |
code_contests | verifiable_code | 1166_F. Vicky's Delivery Service | Solve the following coding problem using the programming language python:
In a magical land there are n cities conveniently numbered 1, 2, ..., n. Some pairs of these cities are connected by magical colored roads. Magic is unstable, so at any time, new roads may appear between two cities.
Vicky the witch has been tas... | vfc_81305 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3 2 4\n1 2 1\n2 3 1\n3 4 2\n? 1 4\n? 4 1\n+ 3 1 2\n? 4 1\n",
"output": "Yes\nNo\nYes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1 1 5\n2 1 1\n? 2 1\n? 1 2\n? 1 2\n? 2 1\n? 1 2\n",... | |
code_contests | verifiable_code | 1185_C2. Exam in BerSU (hard version) | Solve the following coding problem using the programming language python:
The only difference between easy and hard versions is constraints.
If you write a solution in Python, then prefer to send it in PyPy to speed up execution time.
A session has begun at Beland State University. Many students are taking exams.
P... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
# import time,random,resource
# sys.setrecursionlimit(10**6)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)... | vfc_81309 | {
"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 15\n1 2 3 4 5 6 7\n",
"output": "0 0 0 0 0 2 3 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 100\n80 40 40 40 60\n",
"output": "0 1 1 2 3 \n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 1204_A. BowWow and the Timetable | Solve the following coding problem using the programming language python:
In the city of Saint Petersburg, a day lasts for 2^{100} minutes. From the main station of Saint Petersburg, a train departs after 1 minute, 4 minutes, 16 minutes, and so on; in other words, the train departs at time 4^k for each integer k ≥ 0. ... | ```python
n=int(input(),2)
temp=0
l=[]
while(4**temp<n):
l.append(4**temp)
temp+=1
print(len(l))
``` | vfc_81313 | {
"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": "100000000\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "101\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1... |
code_contests | verifiable_code | 1220_F. Gardener Alex | Solve the following coding problem using the programming language python:
Gardener Alex loves to grow trees. We remind that tree is a connected acyclic graph on n vertices.
Today he decided to grow a rooted binary tree. A binary tree is a tree where any vertex has no more than two sons. Luckily, Alex has a permutati... | vfc_81317 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 3 4\n",
"output": "3 2\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1246_B. Power Products | Solve the following coding problem using the programming language python:
You are given n positive integers a_1, …, a_n, and an integer k ≥ 2. Count the number of pairs i, j such that 1 ≤ i < j ≤ n, and there exists an integer x such that a_i ⋅ a_j = x^k.
Input
The first line contains two integers n and k (2 ≤ n ≤ 1... | ```python
n,k=map(int,input().split())
A=list(map(int,input().split()))
import math
from collections import Counter
C=Counter()
for x in A:
L=int(math.sqrt(x))
FACT=dict()
for i in range(2,L+2):
while x%i==0:
FACT[i]=FACT.get(i,0)+1
x=x//i
if x!=1:
FAC... | vfc_81321 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 3\n1 3 9 8 24 1\n",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 2\n7 4 10 9 2 8 8 7 3 7\n",
"output": "7",
"type": "stdin_stdout"
},
{
"fn_nam... |
code_contests | verifiable_code | 1265_F. Beautiful Bracket Sequence (easy version) | Solve the following coding problem using the programming language python:
This is the easy version of this problem. The only difference is the limit of n - the length of the input string. In this version, 1 ≤ n ≤ 2000. The hard version of this challenge is not offered in the round for the second division.
Let's defi... | vfc_81325 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "(?(?))\n",
"output": "9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "??\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "???)\n",
... | |
code_contests | verifiable_code | 1287_B. Hyperset | Solve the following coding problem using the programming language python:
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this ... | ```python
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
S = [input().strip() for i in range(n)]
SET = set(S)
p=0
for i in range(n - 1):
for j in range(i + 1, n):
c = []
for l in range(k):
if S[i][l] == S[j][l]:
c += S[i][l]
else:
... | vfc_81329 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\nSET\nETS\nTSE\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\nSETE\nETSE\nTSES\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_nam... |
code_contests | verifiable_code | 1307_B. Cow and Friend | Solve the following coding problem using the programming language python:
Bessie has way too many friends because she is everyone's favorite cow! Her new friend Rabbit is trying to hop over so they can play!
More specifically, he wants to get from (0,0) to (x,0) by making multiple hops. He is only willing to hop fro... | ```python
for _ in range(int(input())):
n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 10**18
for i in range(n):
cnt = x // a[i]
if x % a[i]:
cnt += 1 if cnt else 2
ans = min(ans, cnt)
print(ans)
``` | vfc_81333 | {
"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\n2 4\n1 3\n3 12\n3 4 5\n1 5\n5\n2 10\n15 4\n",
"output": "2\n3\n1\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n10 999999733\n25 68 91 55 36 29 96 4 63 3\n",
"output": "104... |
code_contests | verifiable_code | 1330_B. Dreamoon Likes Permutations | Solve the following coding problem using the programming language python:
The sequence of m integers is called the permutation if it contains all integers from 1 to m exactly once. The number m is called the length of the permutation.
Dreamoon has two permutations p_1 and p_2 of non-zero lengths l_1 and l_2.
Now Dre... | ```python
import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
N = int(input())
A = list(map(int, input().split()))
Query.append((N, A))
for N, A in Query:
leftOK = [True]*(N+1)
already = set()
MAX = 0
for i, a in enumerate(A):
if a in already:
... | vfc_81337 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n5\n1 4 3 2 1\n6\n2 4 1 3 2 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n1 1 1\n",
"output": "2\n1 4\n4 1\n1\n4 2\n0\n0\n1\n2 10\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | 1350_B. Orac and Models | Solve the following coding problem using the programming language python:
There are n models in the shop numbered from 1 to n, with sizes s_1, s_2, …, s_n.
Orac will buy some of the models and will arrange them in the order of increasing numbers (i.e. indices, but not sizes).
Orac thinks that the obtained arrangemen... | ```python
import sys
import math
t=int(sys.stdin.readline())
for _ in range(t):
n=int(sys.stdin.readline())
arr=list(map(int,sys.stdin.readline().split()))
dp=[1 for x in range(n+1)]
for i in range(n-1,0,-1):
j=i*2
cnt=2
cur=1
while j<=n:
y=dp[j]
... | vfc_81341 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4\n5 3 4 6\n7\n1 4 2 3 6 4 9\n5\n5 4 3 2 1\n1\n9\n",
"output": "2\n3\n1\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n23\n3198 4895 1585 3881 2650 2366 876 2731 1052 126 2152 36... |
code_contests | verifiable_code | 1393_A. Rainbow Dash, Fluttershy and Chess Coloring | Solve the following coding problem using the programming language python:
One evening Rainbow Dash and Fluttershy have come up with a game. Since the ponies are friends, they have decided not to compete in the game but to pursue a common goal.
The game starts on a square flat grid, which initially has the outline bo... | ```python
for i in range(int(input())):
n = int(input())
res = int(n/2)+1
print(res)
``` | vfc_81349 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n4\n",
"output": "2\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n10000001\n",
"output": "5000001\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1434_D. Roads and Ramen | Solve the following coding problem using the programming language python:
In the Land of Fire there are n villages and n-1 bidirectional road, and there is a path between any pair of villages by roads. There are only two types of roads: stone ones and sand ones. Since the Land of Fire is constantly renovating, every m... | vfc_81357 | {
"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": "5\n1 2 0\n1 3 0\n3 5 0\n3 4 0\n5\n3\n4\n1\n3\n4\n",
"output": "3\n2\n3\n3\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n2 4 0\n5 2 0\n1 3 1\n1 2 1\n5\n3\n3\n4\n1\n1\n",
"outp... | |
code_contests | verifiable_code | 145_B. Lucky Number 2 | Solve the following coding problem using the programming language python:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves long lucky ... | ```python
a1,a2,a3,a4=map(int,input().split())
L=[]
def Solve(a1,a2,a3,a4):
if(a3-a4<-1 or a3-a4>1 or a1<a3 or a1<a4 or a2<a3 or a2<a4):
return -1
elif(a3-a4==0):
Ans="47"*a3
Ans+="4"
if(a1-a3==0 and a2-a4==0):
return -1
elif(a1-a3==0):
return "7... | vfc_81361 | {
"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 7 3 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2 1 1\n",
"output": "4774",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | 1485_D. Multiples and Power Differences | Solve the following coding problem using the programming language python:
You are given a matrix a consisting of positive integers. It has n rows and m columns.
Construct a matrix b consisting of positive integers. It should have the same size as a, and the following conditions should be met:
* 1 ≤ b_{i,j} ≤ 10^6... | ```python
n, m = list(map(int, input().split()))
matrix = []
for i in range(n):
row = list(map(int, input().split()))
matrix.append(row)
#print(matrix)
res = [ [ 0 for i in range(m) ] for j in range(n) ]
for i in range(n):
for j in range(m):
if (i + j) % 2:
res[i][j] = 720720 + matr... | vfc_81365 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3\n16 16 16\n16 16 16\n",
"output": "\n16 32 48\n32 48 64\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n1 2\n2 3\n",
"output": "\n1 2\n2 3\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 150_B. Quantity of Strings | Solve the following coding problem using the programming language python:
Just in case somebody missed it: this winter is totally cold in Nvodsk! It is so cold that one gets funny thoughts. For example, let's say there are strings with the length exactly n, based on the alphabet of size m. Any its substring with lengt... | ```python
n,m,k = map(int,input().split())
mod = 10**9 + 7
if k == 1 or k>n:
print(pow(m,n,mod))
elif k == n:
print(pow(m,(n+1)//2,mod))
elif k%2== 0:
print(m%mod)
else:
print(pow(m,2,mod))
``` | vfc_81369 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2 4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "784... |
code_contests | verifiable_code | 1535_F. String Distance | Solve the following coding problem using the programming language python:
Suppose you are given two strings a and b. You can apply the following operation any number of times: choose any contiguous substring of a or b, and sort the characters in it in non-descending order. Let f(a, b) the minimum number of operations ... | vfc_81373 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 1024000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nzzz\nbac\nabc\nacb\n",
"output": "\n4015\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\na\nb\n",
"output": "\n1337\n",
"type": "stdin_stdout"
},
{
"fn_name... | |
code_contests | verifiable_code | 162_I. Truncatable primes | Solve the following coding problem using the programming language python:
A truncatable prime is a prime number which contains no zeros in decimal notation and all its suffixes are primes. 1 is considered to be not a prime.
You are given a positive integer n. Figure out whether it is a truncatable prime.
Input
The ... | vfc_81377 | {
"difficulty": "15",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "19\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 182_E. Wooden Fence | Solve the following coding problem using the programming language python:
Vasya has recently bought some land and decided to surround it with a wooden fence.
He went to a company called "Wooden board" that produces wooden boards for fences. Vasya read in the catalog of products that the company has at its disposal n ... | ```python
from sys import stdin, stdout
MOD = 10 ** 9 + 7
sze = 101
n, l = map(int, stdin.readline().split())
dp = [[[0, 0] for j in range(l + sze + 1)] for i in range(n)]
bars = []
challengers = [[] for i in range(sze)]
for i in range(n):
a, b = map(int, stdin.readline().split())
bars.append((a, b))
... | vfc_81381 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2\n2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n1 2\n2 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"i... |
code_contests | verifiable_code | 207_A2. Beaver's Calculator 1.0 | Solve the following coding problem using the programming language python:
The Smart Beaver from ABBYY has once again surprised us! He has developed a new calculating device, which he called the "Beaver's Calculator 1.0". It is very peculiar and it is planned to be used in a variety of scientific problems.
To test it,... | vfc_81385 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 1 1 1 10\n2 3 1 1 10\n",
"output": "0\n1 1\n2 1\n3 2\n4 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3 10 2 3 1000\n3 100 1 999 1000\n",
"output": "2\n10 1\n23 1\n49 1\n... | |
code_contests | verifiable_code | 230_A. Dragons | Solve the following coding problem using the programming language python:
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two oppon... | ```python
n,m=map(int, input().split())
r=3
ar=[]
for i in range (m):
q=list(map(int, input().split()))
ar.append (q)
ar.sort()
for i in range (m):
if n>ar[i][0]:
n+=ar[i][1]
else:
r=5
print ('NO')
break
if r!=5:
print ('YES')
``` | vfc_81389 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n1 99\n100 0\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 1\n100 100\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 279_E. Beautiful Decomposition | Solve the following coding problem using the programming language python:
Valera considers a number beautiful, if it equals 2k or -2k for some integer k (k ≥ 0). Recently, the math teacher asked Valera to represent number n as the sum of beautiful numbers. As Valera is really greedy, he wants to complete the task usin... | ```python
t = input()
j = t[0]
d, s = 0, int(j)
for i in t[1: ]:
if j != i:
if d == 1: d, s = 0, s + 1
else: d = 1
j = i
else: d = 1
print(s + (d and j == '1'))
``` | vfc_81397 | {
"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": "1101101\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "111\... |
code_contests | verifiable_code | 328_B. Sheldon and Ice Pieces | Solve the following coding problem using the programming language python:
Do you remember how Kai constructed the word "eternity" using pieces of ice as components?
Little Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. He wants to construct his favourite number t. He realized that... | ```python
def c(a, b):
a = a.replace('6', '9')
a = a.replace('2', '5')
b = b.replace('6', '9')
b = b.replace('2', '5')
n = 10000
for i in '01345789':
t = a.count(i)
if t != 0:
n = min(n, b.count(i)//t)
return n
a = input()
b = input()
print(c(a, b))
``` | vfc_81405 | {
"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": "42\n23454\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 34_C. Page Numbers | Solve the following coding problem using the programming language python:
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to ... | ```python
A=[int(num) for num in input().split(',')]
s_a=sorted(set(A))
prev=None
string=""
count=0
for i in s_a:
if prev is None:
prev=i
string+=str(prev)
count+=1
else:
if i-(prev+count)==0:
count+=1
else:
if count>1:
string+='-'+... | vfc_81409 | {
"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": "30,20,10\n",
"output": "10,20,30",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3,2,1\n",
"output": "1-3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
code_contests | verifiable_code | 373_D. Counting Rectangles is Fun | Solve the following coding problem using the programming language python:
There is an n × m rectangular grid, each cell of the grid contains a single integer: zero or one. Let's call the cell on the i-th row and the j-th column as (i, j).
Let's define a "rectangle" as four integers a, b, c, d (1 ≤ a ≤ c ≤ n; 1 ≤ b ≤ ... | vfc_81413 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5 5\n00101\n00000\n00001\n01000\n00001\n1 2 2 4\n4 5 4 5\n1 2 5 2\n2 2 4 5\n4 2 5 3\n",
"output": "10\n1\n7\n34\n5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 7 5\n0000100\n0000010... | |
code_contests | verifiable_code | 418_B. Cunning Gena | Solve the following coding problem using the programming language python:
A boy named Gena really wants to get to the "Russian Code Cup" finals, or at least get a t-shirt. But the offered problems are too complex, so he made an arrangement with his n friends that they will solve the problems for him.
The participants... | vfc_81421 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2 1\n100 1 1\n2\n100 2 1\n1\n",
"output": "202",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2 1\n1 1 1\n1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn... | |
code_contests | verifiable_code | 444_E. DZY Loves Planting | Solve the following coding problem using the programming language python:
DZY loves planting, and he enjoys solving tree problems.
DZY has a weighted tree (connected undirected graph without cycles) containing n nodes (they are numbered from 1 to n). He defines the function g(x, y) (1 ≤ x, y ≤ n) as the longest edge ... | ```python
n = int(input())
edges = [[int(x) for x in input().split()] for i in range(n-1)]
edges = sorted(edges)
use_count = [0]+[int(input()) for i in range(n)]
lo,hi = 0,10000
def getpar(par,u):
if par[par[u]] == par[u]:
return par[u]
par[u] = getpar(par,par[u])
return par[u]
def unite(par,sz,use,... | vfc_81425 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 1\n2 3 2\n3 4 3\n1\n1\n1\n1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 2 1\n2 3 2\n3 4 3\n4\n4\n4\n4\n",
"output": "3\n",
"type": "stdin_stdou... |
code_contests | verifiable_code | 467_A. George and Accommodation | Solve the following coding problem using the programming language python:
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormi... | ```python
c = 0
for _ in range(int(input())):
n = [int(x) for x in input().split()]
n,m = n[0],n[1]
if m - n >= 2:
c += 1
print(c)
``` | vfc_81429 | {
"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\n1 1\n2 2\n3 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 10\n0 10\n10 10\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name":... |
code_contests | verifiable_code | 48_D. Permutations | Solve the following coding problem using the programming language python:
A permutation is a sequence of integers from 1 to n of length n containing each number exactly once. For example, (1), (4, 3, 5, 1, 2), (3, 2, 1) are permutations, and (1, 1), (4, 3, 1), (2, 3, 4) are not.
There are many tasks on permutations.... | ```python
def fail():
print(-1)
import sys
sys.exit()
n = int(input())
count = (n + 1) * [ 0 ]
assign = n * [ None ]
for i, x in enumerate(map(int, input().split())):
if x > n:
fail()
count[x] += 1
assign[i] = count[x]
for i in range(2, n):
if count[i - 1] < count[i]:
fail()
print(count[1])
pri... | vfc_81433 | {
"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": "9\n1 2 3 1 2 1 4 2 5\n",
"output": "3\n1 1 1 2 2 3 1 3 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n4 3 2 1\n",
"output": "1\n1 1 1 1 ",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 53_B. Blog Photo | Solve the following coding problem using the programming language python:
One popular blog site edits the uploaded photos like this. It cuts a rectangular area out of them so that the ratio of height to width (i.e. the height / width quotient) can vary from 0.8 to 1.25 inclusively. Besides, at least one side of the cu... | ```python
from math import ceil,floor
l = []
for i in range(39):
l.append(2**i)
h,w = map(int,input().split())
h1 = 0
w1 = 0
maxi = 0
for i in l:
if i<=w:
a = ceil(i*0.8)
b = floor(i*1.25)
if a<=h<=b:
if i*h>=maxi:
maxi = i * h
h1 = h
... | vfc_81441 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1\n",
"output": "1 1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n",
"output": "2 2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5\n",... |
code_contests | verifiable_code | 567_D. One-Dimensional Battle Ships | Solve the following coding problem using the programming language python:
Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a 1 × n table).
At the beginning of the game Alice puts k ships on the field without telling their p... | ```python
import sys
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
def solve():
n, k, a = mints()
a += 1
m = mint()
x = list(mints())
l = 0
r = m + 1
while r - l > 1:
c = (l + r) // 2
b = x[:c]
b.sort()
last = 0
cnt = ... | vfc_81445 | {
"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": "11 3 3\n5\n4 8 6 1 11\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1 3\n1\n3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | 588_F. Duff in Mafia | Solve the following coding problem using the programming language python:
Duff is one if the heads of Mafia in her country, Andarz Gu. Andarz Gu has n cities (numbered from 1 to n) connected by m bidirectional roads (numbered by 1 to m).
Each road has a destructing time, and a color. i-th road connects cities vi and ... | vfc_81449 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 6, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 7\n2 1 3 7\n3 1 1 6\n5 4 1 8\n4 5 1 1\n3 2 2 3\n4 5 2 5\n2 3 2 4\n",
"output": "Yes\n3 2\n4 5 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 5\n3 2 1 3\n1 3 1 1\n3 2 1 4\n1 3 2 2\n1 3 ... | |
code_contests | verifiable_code | 610_C. Harmony Analysis | Solve the following coding problem using the programming language python:
The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave the group a simple task: fin... | ```python
p = [[0]]
for i in range(int(input())):
p = [t + t for t in p] + [[1 - q for q in t] + t for t in p]
for t in p: print(''.join('+*'[q] for q in t))
``` | vfc_81453 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n",
"output": "++++\n+*+*\n++**\n+**+\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "++++\n+*+*\n++**\n+**+\n",
"type": "stdin_stdout"
},
{
"f... |
code_contests | verifiable_code | 630_M. Turn | Solve the following coding problem using the programming language python:
Vasya started working in a machine vision company of IT City. Vasya's team creates software and hardware for identification of people by their face.
One of the project's know-how is a camera rotating around its optical axis on shooting. People ... | ```python
import math, re, sys, string, operator, functools, fractions, collections
sys.setrecursionlimit(10**7)
dX= [-1, 1, 0, 0,-1, 1,-1, 1]
dY= [ 0, 0,-1, 1, 1,-1,-1, 1]
RI=lambda x=' ': list(map(int,input().split(x)))
RS=lambda x=' ': input().rstrip().split(x)
mod=int(1e9+7)
eps=1e-6
###############################... | vfc_81457 | {
"difficulty": "20",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "-60\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "60\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "66785045... |
code_contests | verifiable_code | 659_E. New Reform | Solve the following coding problem using the programming language python:
Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It is not guaranteed that you can get from any city to any other one, using only the exist... | ```python
import sys
from math import sqrt, gcd, ceil, log
# from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
# from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda: list(map(int, input().strip().split()))
sys.setrecursionlimit(200000)
def ma... | vfc_81461 | {
"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": "5 5\n2 1\n1 3\n2 3\n2 5\n4 3\n",
"output": "0",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 682_B. Alyona and Mex | Solve the following coding problem using the programming language python:
Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can re... | ```python
import sys
n = int(input())
arr = list(map(int,input().split()))
arr.sort()
ans = 1
for i in range(1,n+1):
if arr[i-1]>=ans:
ans+=1
print(ans)
``` | vfc_81465 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 3 3 3 6\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 1\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 705_A. Hulk | Solve the following coding problem using the programming language python:
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his ... | ```python
x = int(input())
feelings = ''
for _ in range(x):
if _ == x - 1:
if _ % 2 != 0:
feelings = feelings + 'I love it '
else:
feelings = feelings + 'I hate it '
else:
if _ % 2 != 0:
feelings = feelings + 'I love that '
else:
feelings = feelings + 'I hate that '
print(feelings)
``` | vfc_81469 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n",
"output": "I hate that I love it\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "I hate it\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | 727_D. T-shirts Distribution | Solve the following coding problem using the programming language python:
The organizers of a programming contest have decided to present t-shirts to participants. There are six different t-shirts sizes in this problem: S, M, L, XL, XXL, XXXL (sizes are listed in increasing order). The t-shirts are already prepared. F... | ```python
from math import *
from sys import *
def conv(s):
if s=="S" or s=="S\n":
return 1
if s=="M" or s=="M\n":
return 2
if s=="L" or s=="L\n":
return 3
if s=="XL" or s=="XL\n":
return 4
if s=="XXL" or s=="XXL\n":
return 5
return 6
def uncon(x):
if x==1:
return "S"
if x==2:
return "M"
if x=... | vfc_81473 | {
"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": "0 1 0 1 1 0\n3\nXL\nS,M\nXL,XXL\n",
"output": "YES\nXL\nM\nXXL\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 2 0 1 1\n5\nS\nM\nS,M\nXXL,XXXL\nXL,XXL\n",
"output": "NO\n",
... |
code_contests | verifiable_code | 748_E. Santa Claus and Tangerines | Solve the following coding problem using the programming language python:
Santa Claus has n tangerines, and the i-th of them consists of exactly ai slices. Santa Claus came to a school which has k pupils. Santa decided to treat them with tangerines.
However, there can be too few tangerines to present at least one tan... | vfc_81477 | {
"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 2\n5 9 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 4\n12 14\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... | |
code_contests | verifiable_code | 771_D. Bear and Company | Solve the following coding problem using the programming language python:
Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he ... | ```python
# http://codeforces.com/contest/771/problem/D
"""
DP-solution.
For each state (v, k, x, v_is_last_letter) we trial a step along the v, k and x
axes and check that
dp[future_state] = min(dp[future_state], dp[state] + cost_of_move)
Hence this implicitly reults in the one with least cost.
V, K, X are arrays th... | vfc_81481 | {
"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": "4\nVKVK\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\nVVKEVKK\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 841_E. On the Bench | Solve the following coding problem using the programming language python:
A year ago on the bench in public park Leha found an array of n numbers. Leha believes that permutation p is right if for all 1 ≤ i < n condition, that api·api + 1 is not perfect square, holds. Leha wants to find number of right permutations mod... | vfc_81493 | {
"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": "7\n5 2 4 2 4 1 1\n",
"output": "144",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2 4\n",
"output": "2",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 888_D. Almost Identity Permutations | Solve the following coding problem using the programming language python:
A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array.
Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≤ i ≤ n) such that pi = i.
Your ta... | ```python
import math
nk=input().split()
n=int(nk[0])
k=int(nk[1])
L=[0]*5
L[1]=1
L[2]=(n*(n-1))//2
L[3]=(n*(n-1)*(n-2))//3
L[4]=(3*n*(n-1)*(n-2)*(n-3))//8
s=0
for i in range(0,k+1):
s+=L[i]
print(s)
``` | vfc_81501 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 4\n",... |
code_contests | verifiable_code | 911_B. Two Cakes | Solve the following coding problem using the programming language python:
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one — into b pieces.
Ivan knows that there will... | ```python
#problem 911b
n,a,b=list(map(int,input().split()))
print(max(min(a//i,b//(n-i)) for i in range(1,n)))
``` | vfc_81505 | {
"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 7 10\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 932_G. Palindrome Partition | Solve the following coding problem using the programming language python:
Given a string s, find the number of ways to split s to substrings such that if there are k substrings (p1, p2, p3, ..., pk) in partition, then pi = pk - i + 1 for all i (1 ≤ i ≤ k) and k is even.
Since the number of ways can be large, print it... | vfc_81509 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "abcdcdab\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "abbababababbab\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 95_B. Lucky Numbers | Solve the following coding problem using the programming language python:
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky... | ```python
from itertools import permutations as p
def ck(num,arr):
for i in arr:
if i>=num:
print(i)
return
x = input()
z = len(x)
if z == 1:
print(47)
elif z == 2 :
if int(x) <= 74:
arr = [47,74]
ck(int(x),arr)
else:
print(4477)
elif z == 3:
... | vfc_81513 | {
"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": "47\n",
"output": "47\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 986_F. Oppa Funcan Style Remastered | Solve the following coding problem using the programming language python:
Surely you have seen insane videos by South Korean rapper PSY, such as "Gangnam Style", "Gentleman" and "Daddy". You might also hear that PSY has been recording video "Oppa Funcan Style" two years ago (unfortunately we couldn't find it on the in... | vfc_81517 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n7 7\n3 8\n5 6\n",
"output": "YES\nNO\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 1\n2 1\n1000000000 1\n1000000000000000000 1\n",
"output": "NO\nNO\nNO\nNO\n",
... | |
code_contests | verifiable_code | akbar-and-birbal-1 | Solve the following coding problem using the programming language python:
This is the time of Akbar and Birbal. One day , in the state there happened some riots and murders .Akbar found some N people guilty in this matter.He called Birbal to punish them .Birbal gave them a unique punishment .He ordered the first perso... | ```python
import math
for _ in xrange(input()):
n = input()
print (n - int(math.sqrt(n)))
``` | vfc_81521 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100\n1804246908\n846901785\n1681651770\n1714595508\n1957703548\n424217739\n719858557\n1649719876\n596492227\n1189606931\n1025170345\n1350453279\n783340703\n1102486856\n2044852544\n1967469571\n1365143593\n1540344180\n304071735\n1303... |
code_contests | verifiable_code | building-network | Solve the following coding problem using the programming language python:
There are N routers. The cost of the wires required in connecting two routers, i and j, is R[i]+R[j] where R[i] is the number of slots in the i-th router and i!=j. You need to build a network, such that there is a path between every pair of rout... | ```python
t=input()
while t>0:
n=input()
arr=[]
arr=map(int,raw_input().split())
brr=sorted(arr)
l=len(brr)
su=0
for i in range(1,l):
a=brr[0]+brr[i]
su=su+a
print su
t=t-1
``` | vfc_81525 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n1 2\n3\n1 1 1\n\nSAMPLE",
"output": "3\n4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n42\n18468 6335 26501 19170 15725 11479 29359 26963 24465 5706 28146 23282 16828 9962 492 29... |
code_contests | verifiable_code | dawood-the-mathematician | Solve the following coding problem using the programming language python:
Dr.Dawood is another mathematician who is more geekier than Osama (that's why, ++). Dawood deals with more complex problems than Osama usually deals with. He also recruits people to be his sub-ordinates. He usually gives them "trivial" problems ... | ```python
for i in range(0,int(input())):
f =0
ans = 0
x = int(input())
while x%2 == 0:
f = f+1
x= x/2
ans = pow(2,(f+1))
print(ans)
``` | vfc_81529 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n3\n1\n2\n5\n\nSAMPLE",
"output": "2\n2\n4\n2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | game-of-divisors | Solve the following coding problem using the programming language python:
Two players are playing the following game with a positive integer N. On his turn a player has to write down on paper some integer between 1 and N. But it's forbidden to write an integer which is a divisor of some number already written on paper... | ```python
for i in range(input()):
z=raw_input()
print 1
``` | vfc_81533 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3\n\nSAMPLE",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n6\n7\n8\n9\n10",
"output": "1\n1\n1\n1\n1\n",
"type": "stdin_stdout"
},
{
"fn_nam... |
code_contests | verifiable_code | karan-and-strings | Solve the following coding problem using the programming language python:
After the Tatvik Hiring Challenge, Karan's NLP professor has given him another homework. Since Manhattan Associates Hiring Challenge is round the corner and Karan is busy preparing for it, he turns to you for help.
Given a string, replace all t... | ```python
t=int(raw_input())
i=0
while(i<t):
s=raw_input()
s1=''
s1+=s[0]
for j in s[1:]:
if(j!=s1[-1]):
s1+=j
print(s1)
i+=1
``` | vfc_81537 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\naabbcc\n\nSAMPLE",
"output": "abc\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\naabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\na... |
code_contests | verifiable_code | mittal-wants-to-go-to-play | Solve the following coding problem using the programming language python:
Mittal lives in the Niti Colony. The colony has N houses numbered from 1 to N. There are M bidirectional roads in the colony for travelling between houses. There might be multiple roads between two houses.
Mittal lives in the house with index ... | ```python
import heapq
from bisect import bisect_left
INF = 1 + 25 * 10**8
def dijkstra(G, n, s):
dist = [INF] * (n+1)
dist[s] = 0
heap = []
heapq.heappush(heap, (0,s))
while heap:
d, u = heapq.heappop(heap)
if dist[u] < d:
continue
for (v, w) in G[u]:
... | vfc_81541 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n5 5\n1 2 2\n2 3 4\n3 4 5\n4 5 1\n1 4 7\n3\n4 20\n5 21\n3 5\n\nSAMPLE",
"output": "6\n5\n0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 2\n1 2 10\n1 2 2\n4\n2 45\n2 30\n2 11\n2 13\... |
code_contests | verifiable_code | panda-and-combination | Solve the following coding problem using the programming language python:
Panda loves solving problems which are deemed impossible by his fellow classmates. The current problem which he is working on is to express a number N as sum of powers of number X (Not necessarily distinct) such that the number of powers of num... | ```python
for _ in xrange(input()):
n,m=map(int,raw_input().split())
if(n<m or m==1):
print n
continue
ans=0
while n>0:
ans = ans + n%m
n = n/m
print ans
``` | vfc_81545 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4 4\n5 3\n6 1\n\nSAMPLE",
"output": "1\n3\n6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n4 4\n2 3\n6 1\n\nSAMPLE",
"output": "1\n2\n6\n",
"type": "stdin_stdout"
}... |
code_contests | verifiable_code | rod-cutting-problem-7 | Solve the following coding problem using the programming language python:
A young mischievous boy Harsh, got into a trouble when his mechanical workshop teacher
told him to cut Iron rods.
The rod cutting algorithm is as follows:
Step 1. If the rod can be divided into two equal parts, cut it and choose any one of th... | ```python
def count_special(N):
count = 0
prev = 0
curr = 3
while(curr <= N):
prev = curr
curr = 2*prev + 1
count += 1
return count
T = int(raw_input())
for t in xrange(T):
N = int(raw_input())
count = count_special(N)
print count
``` | vfc_81549 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n2\n\nSAMPLE",
"output": "1\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n977\n543\n252\n979\n348\n889\n876\n55\n938\n610",
"output": "8\n8\n6\n8\n7\n8\n8\n4\n8\n8\n",
... |
code_contests | verifiable_code | steal-the-show | Solve the following coding problem using the programming language python:
It’s the company's 3^rd anniversary, and everyone is super-excited about it. There is a tradition in the company, that the interns decide the seating arrangement of all the members. The requirements of this order are:
The CEO of the company must... | ```python
#mod = 10**9 + 7
#test = int(raw_input())
#for i in range(test):
ceo , coo , cto = [int(x) for x in raw_input().split()]
n = int( raw_input() )
arr = [int(x) for x in raw_input().split()]
arr.sort(reverse = True)
res = [0 for i in range(n+3)]
l = len(res)
res[0] = min( coo , cto )
res[l-1] = max( coo , cto )
... | vfc_81553 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "13 17 11\n2\n12 10\n\nSAMPLE",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "80 82 81\n3\n50 90 65",
"output": "79\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | uncles-will-1 | Solve the following coding problem using the programming language python:
Ramu’s uncle has left him a stable in his Will. But the stable is not in a good condition. The roofs leak and need to be repaired.
There are a number of stalls in the stable. A stall may or may not contain a horse. Ramu has to buy new cement sh... | ```python
# /he/uncle's-will
no_of_tc = input()
for tc in range(no_of_tc) :
line = raw_input()
max_sheets = int(line.split(' ')[0])
total_stalls = int(line.split(' ')[1])
filled_stalls = int(line.split(' ')[2])
stall_map = [False] * total_stalls
for i in range(filled_stalls) : stall_map[input() - 1] = True
whil... | vfc_81557 | {
"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 10 3\n2\n4\n10\n\nSAMPLE",
"output": "4",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00007 Debt Hell | Solve the following coding problem using the programming language python:
Your friend who lives in undisclosed country is involved in debt. He is borrowing 100,000-yen from a loan shark. The loan shark adds 5% interest of the debt and rounds it to the nearest 1,000 above week by week.
Write a program which computes t... | ```python
import math
n = int(input())
a = 100000
for _ in range(n):
a *= 1.05
a = 1000 * math.ceil(a / 1000)
print(a)
``` | vfc_81601 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5",
"output": "130000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1",
"output": "105000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4",
... |
code_contests | verifiable_code | p00272 Ticket Sales | Solve the following coding problem using the programming language python:
Today is the ticket release date for Aizu Entertainment's recommended idol group "Akabeko & Koboushi". There are four types of tickets:
S seat 6000 yen
A seat 4000 yen
B seat 3000 yen
C seat 2000 yen
You, the sales manager, are excitedly waiti... | ```python
for i in range(4):
t,n=map(int,input().split())
if t==1:
print(f'{6000*n}')
elif t==2:
print(f'{4000*n}')
elif t==3:
print(f'{3000*n}')
elif t==4:
print(f'{2000*n}')
``` | vfc_81609 | {
"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 10\n1 4\n4 1\n2 5",
"output": "30000\n24000\n2000\n20000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 10\n1 4\n4 1\n1 5",
"output": "30000\n24000\n2000\n30000\n",
"type": ... |
code_contests | verifiable_code | p00460 Bingo | Solve the following coding problem using the programming language python:
problem
In one programming contest, it is customary to play a bingo game at a social gathering after the competition. However, the bingo card used in this bingo game is a little special and is created according to the following conditions.
* T... | ```python
import itertools
while 1:
n,m,s=map(int,input().split())
if n==0:break
dp=[[0 for _ in range(s+1)] for _ in range(n*n+1)]
dp[0][0]=1
for i,j in itertools.product(range(1,n*n+1),range(s+1)):
if j>=i:dp[i][j]+=dp[i-1][j-i]+dp[i][j-i]
if j-m>=1:dp[i][j]+=100000-dp[i-1][j-m-1]
... | vfc_81613 | {
"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 9 45\n3 100 50\n5 50 685\n0 0 0",
"output": "1\n7\n74501",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 9 45\n3 100 50\n5 50 308\n0 0 0",
"output": "1\n7\n0\n",
"type": "std... |
code_contests | verifiable_code | p00650 The House of Huge Family | Solve the following coding problem using the programming language python:
Mr. Dango's family has an extremely huge number of members. Once it had about 100 members, and now it has as many as population of a city. It is jokingly guessed that the member might fill this planet in the near future.
Mr. Dango's family, the... | ```python
# AOJ 1065 The House of Huge Family
# Python3 2018.7.10 bal4u
# UNION-FIND library
class UnionSet:
def __init__(self, nmax):
self.size = [1]*nmax
self.id = [i for i in range(nmax+1)]
def root(self, i):
while i != self.id[i]:
self.id[i] = self.id[self.id[i]]
i = self.id[i]
return i
def connec... | vfc_81617 | {
"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 2\n0 1 2\n1 2 1\n2 1\n0 1 100\n2 1\n0 1 0\n2 1\n0 1 -1\n0 0",
"output": "1\n100\n0\n-1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n0 1 2\n1 2 1\n2 1\n0 1 100\n2 1\n0 0 0\n2 1\n0 1... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.