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 | p01291 Wind Passages | Solve the following coding problem using the programming language python:
Wind Corridor is a covered passageway where strong wind is always blowing. It is a long corridor of width W, and there are several pillars in it. Each pillar is a right prism and its face is a polygon (not necessarily convex).
In this problem, ... | ```python
def solve():
from itertools import combinations
from heapq import heappush, heappop
def dot(c1, c2):
return c1.real * c2.real + c1.imag * c2.imag
def cross(c1, c2):
return c1.real * c2.imag - c1.imag * c2.real
# get distance between segment and point
def ... | vfc_74145 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n4\n1 1\n1 2\n2 2\n2 1\n4\n3 3\n3 4\n4 4\n4 3\n0 0",
"output": "3.41421356",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p01460 Matrix Operation | Solve the following coding problem using the programming language python:
You are a student looking for a job. Today you had an employment examination for an IT company. They asked you to write an efficient program to perform several operations. First, they showed you an N \times N square matrix and a list of operatio... | ```python
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N, Q, A, B, C, D, E, F, G = map(int, readline().split())
d = 0; rx = 0; ry = 0
*X, = range(N)
*Y, = range(N)
def fc(d, x, y):
if d == 0:
return x, y
if d == 1:
return y, N... | vfc_74149 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1 3 6 12 1 2 1 2\nRL",
"output": "676636559",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1 3 6 12 1 2 1 2\nRH",
"output": "676547189",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | p01772 A-Z Cat | Solve the following coding problem using the programming language python:
A: A-Z Cat / A-Z Cat
story
Aizunyan is a second-year student who belongs to the programming contest club of Wakagamatsu High School, commonly known as the Prokon club. It's so cute. Aizu Nyan was asked by her friend Joy to take care of her cat... | ```python
s,a,c=input(),1,0
for x in s:
if x=='A':a=0
elif x=='Z' and not a:a,c=1,c+1
print('AZ'*c if c else -1)
``` | vfc_74157 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "AIZUNYANPEROPERO",
"output": "AZ",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p01906 Weight Range | Solve the following coding problem using the programming language python:
problem
There are many $ N $ colored balls of different weights in the queue. The queue is in ascending order from the beginning: $ 1,2,3, \ dots, N-1, N, 1,2,3, \ dots, N-1, N, 1,2,3, \ dots $ The balls are lined up, followed by the balls of c... | ```python
def list_eq(get_num, first):
if first == 1:
return False
for i in range(len(get_num)-1):
if get_num[0] != get_num[i+1]:
return False
return True
a_raw = input().split(' ')
b_raw = input().split(' ')
a = [int(n) for n in a_raw]
b = [int(n) for n in b_raw]
get_num = [0... | vfc_74161 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 2\n23 61 57 13 91 41 79 41",
"output": "170",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 2\n23 85 57 13 91 41 79 41",
"output": "194\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p02044 Equal Split | Solve the following coding problem using the programming language python:
Dutch treat
You have organized a party to pray for the good performance of the ICPC 2019 Yokohama Regional Domestic Qualifiers. There are N participants in this party.
Since it costs M yen in total to hold this party, we decided to collect M /... | ```python
while 1:
n,m=map(int, input().split())
if n == 0:
break
a = list(map(int, input().split()))
c = 0
for i in range(n):
c += min(m//n, a[i])
print(c)
``` | vfc_74165 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 300\n120 100 80\n3 30\n10 20 5\n4 1000\n100 200 300 400\n5 5\n2523 8430 3 4199 632\n0 0",
"output": "280\n25\n800\n5",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p02187 Substring Decomposition | Solve the following coding problem using the programming language python:
F: Substring decomposition
problem
Given the two strings S and T and the integer k. Considering consecutive substrings of length k or more of T, determine if S can be constructed by concatenating them.
Where the string s = s_1 s_2 ... s_n is ... | vfc_74169 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "abracadabra\ncadabra\n4",
"output": "Yes",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "abracadabra\ncaeabra\n4",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn... | |
code_contests | verifiable_code | aran01 | Solve the following coding problem using the programming language python:
Oh my God!!! Someone is trying to break into Thapar University's Database and steal sensitive research information. It is now up to us to stop this attack. Fortunately our defense mechanisms have traced the attacks to their source. The fastest w... | ```python
def process(S):
S = map(lambda x: ord(x), S)
return chr(sum(S) / len(S))
def main():
T = int(raw_input())
for t in xrange(T):
S = raw_input().split()[0] # WTF ??
print process(S)
main()
``` | vfc_74181 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nabcd\nreverse\ngear",
"output": "b\nm\ng\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nabdc\nreverse\ngear",
"output": "b\nm\ng\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | cieltomy | Solve the following coding problem using the programming language python:
Tomya is a girl. She loves Chef Ciel very much.
Today, too, Tomya is going to Ciel's restaurant.
Of course, Tomya would like to go to Ciel's restaurant as soon as possible.
Therefore Tomya uses one of the shortest paths from Tomya's house to C... | ```python
NumOfTests = int(raw_input())
for test in range(NumOfTests):
N, M = map(lambda s: int(s), raw_input().split())
# n: min_distance, is_visited, num_of_paths
D = {}
# paths {vertex: [(neighb_vertex, length), ...], ...}
P = {}
for i in range(1, N+1):
D[i]=[float("inf"), None, 0]
... | vfc_74185 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 3\n1 2 3\n2 3 6\n1 3 7\n3 3\n1 2 3\n2 3 6\n1 3 9",
"output": "1\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3 3\n1 2 3\n2 3 6\n1 1 7\n3 3\n1 2 3\n2 3 6\n1 3 9",
"output"... |
code_contests | verifiable_code | fact25 | Solve the following coding problem using the programming language python:
Simple Factorial
You are asked to calculate factorials of some small positive integers.
Input
Input
Tips:
An integer T, denoting the number of testcases, followed by T lines, each containing a single integer N.
Output
For each integer N ... | ```python
import math
test = int(raw_input())
for i in xrange(test):
num = int(raw_input())
fact = math.factorial(num)
print fact
``` | vfc_74189 | {
"difficulty": "6",
"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"
}
]
} |
code_contests | verifiable_code | lch15jab | Solve the following coding problem using the programming language python:
This is a very easy warm-up problem.
You are given a string. Your task is to determine whether number of occurrences of some character in the string is equal to the sum of the numbers of occurrences of other characters in the string.
Input
Th... | ```python
for _ in range(int(raw_input())):
s=raw_input()
l=len(s)
ans=0
for each in s:
if s.count(each)==l/2:
ans=1
break
if l%2:
ans=0
if ans:
print "YES"
else:
print "NO"
``` | vfc_74193 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nacab\nzzqzqq\nabc\nkklkwwww",
"output": "YES\nYES\nNO\nYES\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | permsuff | Solve the following coding problem using the programming language python:
You are given a permutation of natural integers from 1 to N, inclusive. Initially, the permutation is 1, 2, 3, ..., N.
You are also given M pairs of integers, where the i-th is (Li Ri). In a single turn you can choose any of these pairs (let's s... | ```python
intv_new = []
def bsearch(lo, hi, key):
global intv_new
mid = 0
while hi >= lo:
mid = (hi + lo)/2
if key[0] < intv_new[mid][0]:
hi = mid-1
elif key[1] > intv_new[mid][1]:
lo = mid+1
elif key[0] >= intv_new[mid][0] and key[1] <= intv_new[mid][1]:
return True
return False
t = input()
while... | vfc_74197 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n7 4\n3 1 2 4 5 7 6\n1 2\n4 4\n6 7\n2 3\n4 2\n2 1 3 4\n2 4\n2 3",
"output": "Possible\nImpossible",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n7 4\n6 1 2 4 5 7 6\n1 2\n4 4\n6 7\n2 3\... |
code_contests | verifiable_code | sticks | Solve the following coding problem using the programming language python:
Chef and his little brother are playing with sticks. They have total N sticks. Length of i-th stick is Ai.
Chef asks his brother to choose any four sticks and to make a rectangle with those sticks its sides. Chef warns his brother to not to bre... | ```python
import sys
T=int(raw_input())
for i in range(T):
n=int(raw_input())
a=raw_input().split()
a=[int(x) for x in a]
a.sort()
b=tuple(a)
if n<=3:
print "-1"
continue
A=0
B=0
C=0
D=0
possible1=False
possible2=False
next=0
for j in range(n+1):
if j==n:
break
A=b[-j]
B=b[-(j+1)]
if A==B:... | vfc_74201 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5\n1 2 3 1 2\n4\n1 2 2 3",
"output": "2\n-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n5\n1 2 3 1 1\n4\n1 2 2 3",
"output": "-1\n-1\n",
"type": "stdin_stdout"
}
... |
code_contests | verifiable_code | 1008_E. Guess two numbers | Solve the following coding problem using the programming language python:
This is an interactive problem.
Vasya and Vitya play a game. Vasya thought of two integers a and b from 1 to n and Vitya tries to guess them. Each round he tells Vasya two numbers x and y from 1 to n. If both x=a and y=b then Vitya wins. Else V... | vfc_74205 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n3\n3\n2\n1\n0",
"output": "1 1\n1 1\n1 1\n1 3\n3 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000000000000000\n123123123123123123 789789789789789789\n1\n1 1 2 1 2\n",
"ou... | |
code_contests | verifiable_code | 1031_C. Cram Time | Solve the following coding problem using the programming language python:
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today ... | ```python
a = input()
(a,b) = a.split(" ")
a = int(a)
b = int(b)
def binary_search(val):
(l,r,ans)=(1,val,-1)
while l<=r:
mid = (l+r)//2
if mid*(mid+1) <= 2*val:
ans = mid
l = mid+1
else:
r = mid-1
return ans
val = binary_search(a+b)
lista = []
listb = []
vis = [0]*(val+1)
t = val
while a>0 and t>... | vfc_74209 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n",
"output": "1\n3 \n2\n2 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9 12\n",
"output": "2\n6 3 \n4\n5 4 2 1 ",
"type": "stdin_stdout"
},
{
"fn_name": ... |
code_contests | verifiable_code | 1054_C. Candies Distribution | Solve the following coding problem using the programming language python:
There are n children numbered from 1 to n in a kindergarten. Kindergarten teacher gave a_i (1 ≤ a_i ≤ n) candies to the i-th child. Children were seated in a row in order from 1 to n from left to right and started eating candies.
While the i-t... | ```python
'''
the max element would have 0 0 i both l,r
'''
from collections import defaultdict
def f(l,r):
cnts=defaultdict(list)
lmax=[0]*len(l)
rmax=[0]*len(l)
for i in range(len(l)):
cnts[l[i]+r[i]].append(i)
mx=len(l)
ans=[0]*(len(l))
for i in sorted(cnts):
# print(lma... | vfc_74213 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n0 0 0\n0 0 0\n",
"output": "YES\n3 3 3 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 0 2 0\n1 1 1 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"... |
code_contests | verifiable_code | 1076_C. Meme Problem | Solve the following coding problem using the programming language python:
Try guessing the statement from this picture:
<image>
You are given a non-negative integer d. You have to find two non-negative real numbers a and b such that a + b = d and a ⋅ b = d.
Input
The first line contains t (1 ≤ t ≤ 10^3) — the num... | ```python
import decimal
from math import*
decimal.Context(prec=20)
c=int(input())
for i in range(c):
n=int(input())
n=decimal.Decimal(n)
if n*n - 4*n < 0:
print('N')
elif n*n - 4*n == 0:
print('Y '+ str(int(n/2))+ '.000000000 ' + str(int(n/2))+ '.000000000')
else:
x... | vfc_74217 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n69\n0\n1\n4\n5\n999\n1000\n",
"output": "Y 67.9850713005 1.01492869949\nY 0.0 0.0\nN\nY 2.0 2.0\nY 3.61803398875 1.38196601125\nY 997.998996998 1.00100301004\nY 998.998998021 1.00100200501\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 1097_C. Yuhao and a Parenthesis | Solve the following coding problem using the programming language python:
One day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences.
A bracket sequence is any non-empty sequence of opening and closing parentheses. A bracket sequence is called a correct bracket sequenc... | ```python
n = int(input())
a = dict()
b = dict()
for i in range(n):
s = input()
k = 0
max_k = 0
op = True
for j in s:
if j == '(':
k += 1
else:
k -= 1
if k < max_k:
max_k = k
if k < 0:
op = False
if op == Fal... | vfc_74221 | {
"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\n)())\n)\n((\n((\n(\n)\n)\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1118_D1. Coffee and Coursework (Easy version) | Solve the following coding problem using the programming language python:
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can ... | ```python
import sys,os,io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from bisect import bisect_left , bisect_right
import math
alphabets = list('abcdefghijklmnopqrstuvwxyz')
def isPrime(x):
for i in range(2,x):
... | vfc_74225 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 16\n5 5 5 5 5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 15\n5 5 5 5 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | 1165_F1. Microtransactions (easy version) | Solve the following coding problem using the programming language python:
The only difference between easy and hard versions is constraints.
Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these m... | ```python
def check(x):
last=[0]*(n+1)
for i in tmp:
if i[0]>x:
break
else:
last[i[1]]=i[0]
sal=[0]*(x+1)
for i in range(1,n+1):
sal[last[i]]+=lis[i-1]
c=0
for i in range(1,x+1):
c+=1
if sal[i]>=c:
sal[i]-=c
... | vfc_74233 | {
"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": "5 3\n4 2 1 3 2\n3 5\n4 2\n2 5\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 6\n1 2 0 2 0\n2 4\n3 3\n1 5\n1 2\n1 5\n2 3\n",
"output": "8\n",
"type": "stdin... |
code_contests | verifiable_code | 1184_D2. Parallel Universes (Hard) | Solve the following coding problem using the programming language python:
Heidi enjoyed performing the simulation because she knew exactly when a new universe would be formed and where, and when a non-existent link would be broken and where.
However, the multiverse itself works in mysterious ways. Well, it works usin... | vfc_74237 | {
"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": "3 2 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 4 20\n",
"output": "196683114\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... | |
code_contests | verifiable_code | 121_D. Lucky Segments | Solve the following coding problem using the programming language python:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has n number segmen... | vfc_74245 | {
"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": "2 7\n40 45\n47 74\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 7\n1 4\n6 9\n4 7\n3 5\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name":... | |
code_contests | verifiable_code | 1245_A. Good ol' Numbers Coloring | Solve the following coding problem using the programming language python:
Consider the set of all nonnegative integers: {0, 1, 2, ...}. Given two integers a and b (1 ≤ a, b ≤ 10^4). We paint all the numbers in increasing number first we paint 0, then we paint 1, then 2 and so on.
Each number is painted white or black... | ```python
def gcd(a,b):
if a==0:
return b
elif b==0:
return a
elif a>=b:
return gcd(a%b,b)
else:
return gcd(a,b%a)
t=int(input())
for i in range(t):
a,b=input().strip().split(" ")
a,b=[int(a),int(b)]
if gcd(a,b)==1:
print("Finite")
else:
pr... | vfc_74249 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n10 10\n1 10\n6 9\n7 3\n",
"output": "Infinite\nFinite\nInfinite\nFinite\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1264_E. Beautiful League | Solve the following coding problem using the programming language python:
A football league has recently begun in Beautiful land. There are n teams participating in the league. Let's enumerate them with integers from 1 to n.
There will be played exactly (n(n-1))/(2) matches: each team will play against all other team... | vfc_74253 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\n1 2\n1 3\n",
"output": "0110\n0011\n0001\n1000\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1286_B. Numbers on Tree | Solve the following coding problem using the programming language python:
Evlampiy was gifted a rooted tree. The vertices of the tree are numbered from 1 to n. Each of its vertices also has an integer a_i written on it. For each vertex i, Evlampiy calculated c_i — the number of vertices j in the subtree of vertex i, s... | ```python
import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
import collections
from collections import defaultdict
n=int(input())
c,root=[],0
graph=defaultdict(list)
for i in range(n):
a,b=map(int,input().split())
if a!=0:
graph[i+1].append(a)
graph[a].append(i... | vfc_74257 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 0\n0 2\n2 0\n",
"output": "YES\n1 3 2 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 1\n1 3\n2 1\n3 0\n2 0\n",
"output": "YES\n2 5 3 1 4 \n",
"type": "stdin_stdout"... |
code_contests | verifiable_code | 1305_C. Kuroni and Impossible Calculation | Solve the following coding problem using the programming language python:
To become the king of Codeforces, Kuroni has to solve the following problem.
He is given n numbers a_1, a_2, ..., a_n. Help Kuroni to calculate ∏_{1≤ i<j≤ n} |a_i - a_j|. As result can be very big, output it modulo m.
If you are not familiar w... | ```python
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
def main():
n,m = map(int,input().split())
a = list(map(int,input().split()))
lst = [0]*m
for i in a:
lst[i%m] += 1
if max(lst) >= 2:
print(0)
else:
ans =... | vfc_74261 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 12\n1 4 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 7\n1 4 9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"i... |
code_contests | verifiable_code | 1329_E. Dreamoon Loves AA | Solve the following coding problem using the programming language python:
There is a string of length n+1 of characters 'A' and 'B'. The first character and last character of the string are equal to 'A'.
You are given m indices p_1, p_2, …, p_m (0-indexation) denoting the other indices of characters 'A' in the string... | vfc_74265 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n80 3 5\n11 24 50\n81 7 12\n4 10 17 26 37 48 61\n25 10 14\n3 4 7 12 13 15 17 19 21 23\n1 0 0\n\n10 2 0\n2 4\n",
"output": "5\n2\n0\n0\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5... | |
code_contests | verifiable_code | 1349_E. Slime and Hats | Solve the following coding problem using the programming language python:
Slime and Orac are holding a turn-based game. In a big room, there are n players sitting on the chairs, looking forward to a column and each of them is given a number: player 1 sits in the front of the column, player 2 sits directly behind him; ... | vfc_74269 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n0 0 0 0 0\n",
"output": "00000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 2 2 0 0\n",
"output": "00001\n",
"type": "stdin_stdout"
},
{
"fn_name": nul... | |
code_contests | verifiable_code | 136_C. Replacement | Solve the following coding problem using the programming language python:
Little Petya very much likes arrays consisting of n integers, where each of them is in the range from 1 to 109, inclusive. Recently he has received one such array as a gift from his mother. Petya didn't like it at once. He decided to choose exac... | ```python
n = input()
li = list(map(int, input().split(" ")))
li.sort()
if li[-1] != 1: li.insert(0, 1)
else: li.insert(0, 2)
del li[-1]
li.sort()
print(" ".join(map(str, li)))
``` | vfc_74273 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 3 4 5 6\n",
"output": "1 2 3 4 5 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 2 3 4 5\n",
"output": "1 1 2 3 4 ",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1416_E. Split | Solve the following coding problem using the programming language python:
One day, BThero decided to play around with arrays and came up with the following problem:
You are given an array a, which consists of n positive integers. The array is numerated 1 through n. You execute the following procedure exactly once:
... | vfc_74281 | {
"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\n3\n6 8 2\n1\n4\n3\n5 6 6\n",
"output": "3\n1\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3\n6 8 2\n1\n4\n3\n5 6 12\n",
"output": "3\n1\n3\n",
"type": "stdin_stdout... | |
code_contests | verifiable_code | 1433_D. Districts Connection | Solve the following coding problem using the programming language python:
There are n districts in the town, the i-th district belongs to the a_i-th bandit gang. Initially, no districts are connected to each other.
You are the mayor of the city and want to build n-1 two-way roads to connect all districts (two distric... | ```python
from collections import Counter
def solve(a,n):
if len(set(a)) == 1:
print("NO")
return
res = []
d = {}
for i in range(n):
if d.get(a[i]):
pass
else:
d[a[i]] = i+1
key = list(d.keys())
cen = key[0]
print("YES")
for i in r... | vfc_74285 | {
"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\n5\n1 2 2 1 3\n3\n1 1 1\n4\n1 1000 101 1000\n4\n1 2 3 4\n",
"output": "YES\n1 2\n1 3\n1 5\n5 4\nNO\nYES\n1 2\n1 3\n1 4\nYES\n1 2\n1 3\n1 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | 1458_C. Latin Square | Solve the following coding problem using the programming language python:
You are given a square matrix of size n. Every row and every column of this matrix is a permutation of 1, 2, …, n. Let a_{i, j} be the element at the intersection of i-th row and j-th column for every 1 ≤ i, j ≤ n. Rows are numbered 1, …, n top ... | ```python
import sys,io,os
Z=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
Y=lambda:[*map(int,Z().split())]
def I(M):
n=len(M)
nM=[[0]*n for i in range(n)]
for x in range(n):
for y in range(n):
nM[x][M[x][y]-1]=y+1
return nM
def C(M):
n=len(M)
nM=[[0]*n for i in range(n... | vfc_74289 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n3 2\n1 2 3\n2 3 1\n3 1 2\nDR\n3 2\n1 2 3\n2 3 1\n3 1 2\nLU\n3 1\n1 2 3\n2 3 1\n3 1 2\nI\n3 1\n1 2 3\n2 3 1\n3 1 2\nC\n3 16\n1 2 3\n2 3 1\n3 1 2\nLDICRUCILDICRUCI\n",
"output": "\n2 3 1 \n3 1 2 \n1 2 3 \n\n3 1 2 \n1 2 3 \n2... |
code_contests | verifiable_code | 1508_D. Swap Pass | Solve the following coding problem using the programming language python:
Based on a peculiar incident at basketball practice, Akari came up with the following competitive programming problem!
You are given n points on the plane, no three of which are collinear. The i-th point initially has a label a_i, in such a way... | ```python
import sys,io,os
try:Z=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
except:Z=lambda:sys.stdin.readline().encode()
from math import atan2
from collections import deque
def path(R):
H=deque();H.append(R)
while P[R]>=0:
R=P[R];H.append(R)
if len(H)>2:P[H.popleft()]=H[-1]
return... | vfc_74297 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n-1 -2 2\n3 0 5\n1 3 4\n4 -3 3\n5 2 1\n",
"output": "\n5\n1 2\n5 3\n4 5\n1 5\n1 3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1534_E. Lost Array | Solve the following coding problem using the programming language python:
This is an interactive problem.
Note: the XOR-sum of an array a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) is defined as a_1 ⊕ a_2 ⊕ … ⊕ a_n, where ⊕ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Little Dormi r... | ```python
from sys import stdout
def reverse(n, req):return [x for x in range(1, n + 1) if x not in req]
def solve():
n, k = (int(x) for x in input().split())
if n % 2 == 1 and k % 2 == 0:print(-1);stdout.flush();return
elif n % k == 0:
xor = 0;curr_idx = 1
while curr_idx <= n:next_idx = cur... | vfc_74301 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n",
"output": "\n-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3\n\n4\n\n0\n\n1\n",
"output": "\n? 1 2 3\n\n? 2 3 5\n\n? 4 1 5\n\n! 7\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 162_B. Binary notation | Solve the following coding problem using the programming language python:
You are given a positive integer n. Output its binary notation.
Input
The only line of input data contains an integer n (1 ≤ n ≤ 106).
Output
Output the binary notation of n (without any leading zeros).
Examples
Input
5
Output
101
In... | vfc_74305 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n",
"output": "101\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "126\n",
"output": "1111110\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 181_C. Trading Business | Solve the following coding problem using the programming language python:
To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. N... | ```python
import sys
profit = 0
initial = (list(map(int, sys.stdin.readline().split())))
num_planet = initial[0]
num_goods = initial[1]
capacity = initial[2]
stonks = []
for i in range(0, num_planet):
#print('Name planetu')
name_Planet = str(sys.stdin.readline())
planet = []
for j in range (0, num_goo... | vfc_74309 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3 10\nVenus\n6 5 3\n7 6 5\n8 6 10\nEarth\n10 9 0\n8 6 4\n10 9 3\nMars\n4 3 0\n8 4 12\n7 2 5\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3 10\nEarth\n10 9 0\n8 6 4... |
code_contests | verifiable_code | 204_E. Little Elephant and Strings | Solve the following coding problem using the programming language python:
The Little Elephant loves strings very much.
He has an array a from n strings, consisting of lowercase English letters. Let's number the elements of the array from 1 to n, then let's denote the element number i as ai. For each string ai (1 ≤ i... | vfc_74313 | {
"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": "3 1\nabc\na\nab\n",
"output": "6 1 3 ",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 253_B. Physics Practical | Solve the following coding problem using the programming language python:
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as n measurements, and recorded the results in the notebook. After that he was about to show the results... | vfc_74321 | {
"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\n4 3 2 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n4 5 3 8 3 7\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
code_contests | verifiable_code | 278_C. Learning Languages | Solve the following coding problem using the programming language python:
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows... | ```python
class UnionFind:
def __init__(self, n, m):
self.data = [i for i in range(n+m)]
self.size = [0]*(m+n)
def union(self, u, v):
up = self.find(u)
vp = self.find(v)
if up == vp:
return
if self.size[up] <= self.size[vp]:
self.data[up] = vp
self.size[vp] += self... | vfc_74325 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n1 2\n0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"... |
code_contests | verifiable_code | 300_B. Coach | Solve the following coding problem using the programming language python:
A programming coach has n students to teach. We know that n is divisible by 3. Let's assume that all students are numbered from 1 to n, inclusive.
Before the university programming championship the coach wants to split all students into groups ... | ```python
n,m = map(int, input().split())
arr = [i for i in range(n+1)]
mem = {}
for i in range(m):
a,b = map(int, input().split())
if arr[a] in mem:
mem[arr[a]].append(arr[b])
arr[b] = arr[a]
elif arr[b] in mem:
mem[arr[b]].append(arr[a])
arr[a] = arr[b]
else:
me... | vfc_74329 | {
"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 4\n1 2\n2 3\n3 4\n5 6\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n1 2\n2 3\n1 3\n",
"output": "1 2 3 \n\n\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 325_E. The Red Button | Solve the following coding problem using the programming language python:
Piegirl found the red button. You have one last chance to change the inevitable end.
The circuit under the button consists of n nodes, numbered from 0 to n - 1. In order to deactivate the button, the n nodes must be disarmed in a particular ord... | ```python
# METO Bot 0.9.9.1
n=int(input())
if n&1:
print(-1)
else:
D,R=[False]*(10**6),[0]*(10**6)
i,j=0,0
while True:
D[j]=True
R[i]=j
i+=1
if not D[(j+n)>>1]:
j=(j+n)>>1
elif not D[j>>1]:
j=j>>1
else:
break
print(" ".join(str(R[i]) for i in range(n,-1,-1)))
``... | vfc_74333 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 349_A. Cinema Line | Solve the following coding problem using the programming language python:
The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to... | ```python
n = int(input())
L = list(map(int,input().split()))
a=p=0
for i in L:
if i==25:
a+=1
elif i==50:
a-=1
p+=1
else:
if p>0:
p-=1
a-=1
else:
a-=3
if a<0:
print('NO')
break
else:
print('YES')
``` | vfc_74337 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n25 25 50 50\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n50 50 25 25\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 372_B. 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_74341 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 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 | 416_E. President's Path | Solve the following coding problem using the programming language python:
Good old Berland has n cities and m roads. Each road connects a pair of distinct cities and is bidirectional. Between any pair of cities, there is at most one road. For each road, we know its length.
We also know that the President will soon ri... | vfc_74349 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6\n1 2 1\n2 3 1\n3 4 1\n4 1 1\n2 4 2\n4 5 4\n",
"output": "1 4 1 2 1 5 6 1 2 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 0\n",
"output": "0 \n",
"type": "stdin_stdou... | |
code_contests | verifiable_code | 443_C. Borya and Hanabi | Solve the following coding problem using the programming language python:
Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game.
Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding n cards. The game ... | ```python
n = int(input())
data = set(input().split())
temp = 'RGBYW'
c = []
res = 10
for i in data:
p1 = temp.find(i[0])
p2 = int(i[1]) - 1
c.append(2 ** p1 + 2 ** (p2 + 5))
for i in range(1024):
ok = True
for j in range(len(c) - 1):
for k in range(j + 1, len(c)):
if (c[j] & i) ... | vfc_74353 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nG4 R4 R3 B3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nB1 Y1 W1 G1 R1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null... |
code_contests | verifiable_code | 489_C. Given Length and Sum of Digits... | Solve the following coding problem using the programming language python:
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base... | ```python
m,s = list(map(int,input().split()))
flag = True
large = 0
small = 0
m1 = m-1
m2 = 0
s1 = s
if s==0 and m==1:
small,large = 0,0
flag = False
elif s>9*m or s<1:
flag = False
large = -1
small = -1
if flag:
while (s1 != 0):
if s1 >9:
large += 9*10**(m1)
small += 9*10**(m2)
s1 -= 9
m1 -= 1
... | vfc_74361 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 15\n",
"output": "69 96",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 0\n",
"output": "-1 -1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 513_B1. Permutations | Solve the following coding problem using the programming language python:
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum:
<image>
Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p).
Input
The si... | ```python
import sys
import math
import itertools
TESTING = False
def helper(length, knum):
if length <= 1: return [1]
possibilties = pow(2, length - 1);
if knum <= possibilties / 2:
temp = helper(length - 1, knum)
for i in range(len(temp)): temp[i]+=1
return [1]+temp;
res = he... | vfc_74365 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n",
"output": "2 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n",
"output": "1 3 2 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | 538_C. Tourist's Notes | Solve the following coding problem using the programming language python:
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer hi. The tourist pick smooth enough route for his hike, meaning t... | ```python
"""
Satwik_Tiwari ;) .
20 june , 2020 - Tuesday
"""
#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import B... | vfc_74369 | {
"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": "8 3\n2 0\n7 0\n8 3\n",
"output": "IMPOSSIBLE",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 2\n2 0\n7 0\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name":... |
code_contests | verifiable_code | 566_D. Restructuring Company | Solve the following coding problem using the programming language python:
Even the most successful company can go through a crisis period when you have to make a hard decision — to restructure, discard and merge departments, fire employees and do other unpleasant stuff. Let's consider the following model of a company.... | vfc_74373 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 6\n3 2 5\n1 2 5\n3 2 5\n2 4 7\n2 1 2\n3 1 7\n",
"output": "NO\nYES\nYES\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 60_A. Where Are My Flakes? | Solve the following coding problem using the programming language python:
<image>
One morning the Cereal Guy found out that all his cereal flakes were gone. He found a note instead of them. It turned out that his smart roommate hid the flakes in one of n boxes. The boxes stand in one row, they are numbered from 1 to ... | ```python
n, m = input().split(' ')
n = int(n)
m = int(m)
hints = {}
max_right = None
min_left = None
if m > 0:
for i in range(m):
do_nothing = False
line = input().split(' ')
hint_position = int(line[4])-1
if line[2] == 'left':
hint_box = hint_position - 1
... | vfc_74381 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1\nTo the left of 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\nTo the left of 2\nTo the right of 1\n",
"output": "-1\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 630_F. Selection of Personnel | Solve the following coding problem using the programming language python:
One company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received n resumes. Now the HR department has to evaluate each pos... | ```python
from math import factorial
def c(n, k):
cur = factorial(n) // factorial(k)
return cur // factorial(n - k)
n = int(input())
ans = c(n, 5) + c(n, 6) + c(n, 7)
print(ans)
``` | vfc_74385 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n",
"output": "29\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "321\n",
"output": "66715035255088\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
code_contests | verifiable_code | 658_C. Bear and Forgotten Tree 3 | Solve the following coding problem using the programming language python:
A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n.
Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sad no... | ```python
n, d, h = map(int, input().split())
if d > 2 * h or (h == 0 and n > 1) or (d == 1 and n > 2):
print(-1)
else:
fr = 2
for i in range(h):
print('{} {}'.format(fr - 1, fr))
fr += 1
if d == h:
while fr <= n:
print('2 {}'.format(fr))
fr += 1
else:
last, next = 1, h + 2
for i in range(d - h):
... | vfc_74389 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3 2\n",
"output": "1 2\n2 3\n1 4\n1 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 4 2\n",
"output": "1 2\n2 3\n1 4\n4 5\n1 6\n1 7\n1 8\n",
"type": "stdin_stdout"
},... |
code_contests | verifiable_code | 680_E. Bear and Square Grid | Solve the following coding problem using the programming language python:
You have a grid with n rows and n columns. Each cell is either empty (denoted by '.') or blocked (denoted by 'X').
Two empty cells are directly connected if they share a side. Two cells (r1, c1) (located in the row r1 and column c1) and (r2, c2... | vfc_74393 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n..XXX\nXX.XX\nX.XXX\nX...X\nXXXX.\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3\n.....\n.XXX.\n.XXX.\n.XXX.\n.....\n",
"output": "25\n",
"type": "s... | |
code_contests | verifiable_code | 703_D. Mishka and Interesting sum | Solve the following coding problem using the programming language python:
Little Mishka enjoys programming. Since her birthday has just passed, her friends decided to present her with array of non-negative integers a1, a2, ..., an of n elements!
Mishka loved the array and she instantly decided to determine its beauty... | vfc_74397 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n1 2 1 3 3 2 3\n5\n4 7\n4 5\n1 3\n1 7\n1 5\n",
"output": "0\n3\n1\n3\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3 7 8\n1\n1 3\n",
"output": "0\n",
"type": "stdin_s... | |
code_contests | verifiable_code | 747_D. Winter Is Coming | Solve the following coding problem using the programming language python:
The winter in Berland lasts n days. For each day we know the forecast for the average air temperature that day.
Vasya has a new set of winter tires which allows him to drive safely no more than k days at any average air temperature. After k da... | ```python
n,k=map(int,input().split())
d=list(map(int,input().split()))
p=[]
count=0
count1=0
for i in range(len(d)):
if d[i]>=0:
count+=1
if d[i]<0 or i==len(d)-1:
p.append(count)
count=0
count1+=1
if d[len(d)-1]>=0:
count1-=1
if count1==0:
print(0)
exit()
a=p.pop() ... | vfc_74405 | {
"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": "10 6\n2 -5 1 3 0 0 -4 -3 1 0\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n-5 20 -3 0\n",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_nam... |
code_contests | verifiable_code | 770_A. New Password | Solve the following coding problem using the programming language python:
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
* ... | ```python
n, k = eval(input().rstrip().replace(" ", ","))
k = min(k, 26)
letters = [chr(i) for i in range(97, 123)]
for i in range(n):
print(letters[i%k], end="")
``` | vfc_74409 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 6\n",
"output": "abcdef",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n",
"output": "ababa",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 ... |
code_contests | verifiable_code | 840_C. 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... | ```python
from collections import*
n = int(raw_input())
a = [0] * 34000
ps = []
for i in xrange(2, 34000):
if a[i]:
continue
ps.append(i * i)
j = i * i
while j < 34000:
a[j] = 1
j += i
a = map(int, raw_input().split())
b = defaultdict(int)
for x in a:
for p in ps:
whi... | vfc_74421 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n5 2 4 2 4 1 1\n",
"output": "144\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 860_D. Wizard's Tour | Solve the following coding problem using the programming language python:
All Berland residents are waiting for an unprecedented tour of wizard in his Blue Helicopter over the cities of Berland!
It is well-known that there are n cities in Berland, some pairs of which are connected by bidirectional roads. Each pair of... | vfc_74425 | {
"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 5\n1 2\n3 2\n2 4\n3 4\n4 1\n",
"output": "2\n2 4 1\n4 3 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 8\n5 3\n1 2\n4 5\n5 1\n2 5\n4 3\n1 4\n3 2\n",
"output": "4\n5 4 1\n4 3 2... | |
code_contests | verifiable_code | 887_C. Solution for Cube | Solve the following coding problem using the programming language python:
During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.
It's too hard to learn to solve Rubik's cube instantly, so she learns to understand... | ```python
# Main maut ko takiya, aur kafan ko chaadar banakar audhta hoon!
def R(b):
c=[]
for i in b:
c.append(i)
c[1]=b[5]
c[3]=b[7]
c[5]=b[9]
c[7]=b[11]
c[9]=b[22]
c[11]=b[20]
c[22]=b[1]
c[20]=b[3]
d=[]
for i in range(23):
if(c[i]!=c[i+1]):
d.append(c[i])
d.append(c[-1])
if(len(d)==6):
ret... | vfc_74429 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3\n",
"output": "YES",
... |
code_contests | verifiable_code | 90_C. Robbery | Solve the following coding problem using the programming language python:
It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with po... | ```python
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
if n % 2 == 0:
print('0')
else:
print(min(m // (n // 2 + 1) * k, min(a[::2])))
# Made By Mostafa_Khaled
``` | vfc_74433 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2 2\n4 1 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3 1\n2 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | 931_F. Teodor is not a liar! | Solve the following coding problem using the programming language python:
Young Teodor enjoys drawing. His favourite hobby is drawing segments with integer borders inside his huge [1;m] segment. One day Teodor noticed that picture he just drawn has one interesting feature: there doesn't exist an integer point, that be... | vfc_74437 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 6\n1 3\n2 3\n4 6\n5 6\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 4\n1 2\n3 4\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 959_A. Mahmoud and Ehab and the even-odd game | Solve the following coding problem using the programming language python:
Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer n and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer a and subtract it from n such that:
* 1 ≤ a ≤ n.
... | ```python
import sys
def solve():
n = int(input())
if n%2 == 0:
ans = "Mahmoud"
else:
ans = "Ehab"
return ans
ans = solve()
print(ans)
``` | vfc_74441 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "Ehab",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | acronym-2 | Solve the following coding problem using the programming language python:
See Russian Translation
W.T.H.S.E.C
Confused? Well it stands for Welcome To HackerEarth September Easy Challenge :). It's quite amazing when long words like this get reduced to such a short string. They sound pretty cool and often make the cha... | ```python
n = int(raw_input())
out = [None] * n
for _ in range(n):
out[_] = raw_input()
t = int(raw_input())
s = raw_input().split()
string = ''
for i in s:
if i not in out:
string += i[0].upper() + '.'
string = string[:-1]
print string
``` | vfc_74449 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\nhey\ngirls\ni\nam\nsingle\n11\nhey all boys and girls welcome to hackerearth easy september challenge\n\nSAMPLE",
"output": "A.B.A.W.T.H.E.S.C\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inp... |
code_contests | verifiable_code | brattleship-3 | Solve the following coding problem using the programming language python:
You're about to play a simplified "battleship" game with your little brother. The board for this game is a rectangular grid with R rows and C columns. At the start of the game, you will close your eyes, and you will keep them closed until the en... | ```python
for _ in range(input()):
r, c, w = map(int, raw_input().split())
ret = r * (c/w)
if(c%w==0):
ret+=w-1
else:
ret+=w
print "Case #%d: %d" % (_+1, ret)
``` | vfc_74453 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 4 2\n1 7 7\n\nSAMPLE",
"output": "Case #1: 3\nCase #2: 7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 8 2\n1 7 7\n\nSAMPLE",
"output": "Case #1: 5\nCase #2: 7\n",
... |
code_contests | verifiable_code | cypher | Solve the following coding problem using the programming language python:
Raju is very fond of strings.Once he was playing a game with his friend.His friend gave him a string to decipher.As Raju is not very good at programming, he ask for your help.
So he provide you a string and your task is to decipher it.
Note ... | ```python
for i in range(input()):
p = raw_input()
shift = len(p)
str1 = ""
for i in range(0,shift):
if p[i].isalpha():
k = ord(p[i]) + i
if k > ord('z'):
k -= 26
finalLetter = chr(k)
str1 +=finalLetter
print str1
``` | vfc_74457 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\ntdaejjptlzec\nqvcopt\naacpax\ncqwmpzr\ngdlbnj\nqzxjgjj\nazzyyx\ncnbb\nwxqfsta\nwgwmdt\n\nSAMPLE",
"output": "technovation\nqwerty\nabesec\ncryptex\ngenero\nqazmkop\naabbcc\ncode\nwysiwyg\nwhyphy\n",
"type": "stdin_s... |
code_contests | verifiable_code | fun-with-string | Solve the following coding problem using the programming language python:
Xavier challenges one of his friend to perform some crazy string functions by giving him some words and each word basically denotes a type of string function which his friend has to perform.
WORDS WITH THEIR MEANING:-
Wordrev n->To arrange eac... | ```python
st = raw_input()
task = int(raw_input())
for op in range(task):
tas, n = raw_input().split()
n = int(n)
if tas == "Wordrev":
k = [''.join(p[::-1]) for p in st.split()]
l = st.split()
new = k[:n] + l[n:]
print ' '.join(new)
elif tas == "sortword":
z = st.split()
z.sort()
res = z[:n]
for w i... | vfc_74461 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "my name is xavier\n2\nWordrev 3\nsortword 2\n\nSAMPLE",
"output": "ym eman si xavier\nis my name xavier\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "my name is xavier\n2\nWordrev 3\nsor... |
code_contests | verifiable_code | just-shortest-distance-problem | Solve the following coding problem using the programming language python:
You are given an empty graph of N vertices and M queries of two types:
Given a number X answer what is the shortest distance from the vertex 1 to the vertex X.
Given two integers X, Y add the new oriented edge from X to Y.
Input
The first line ... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
import Queue
def updateDis(f, g, d):
q = Queue.Queue()
q.put(f)
while not q.empty():
cur = q.get()
for i in g[cur]:
if d[i]>d[cur]+1:
d[i]=d[cur]+1
q.put(... | vfc_74465 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 7\n1 4\n2 1 2\n2 2 3\n2 3 4\n1 4\n2 2 4\n1 4\n\n\nSAMPLE",
"output": "-1\n3\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "50 500\n2 2 2\n2 2 3\n2 4 4\n2 3 5\n2 1 6\n2 4 7\n2 7 8\n2 5 ... |
code_contests | verifiable_code | minimum-magic-tricks | Solve the following coding problem using the programming language python:
Magic is great, isn't it?. We all love it. However if you do the same magic trick again and again, it will become boring. Also there are chances people
might see through your trick. So you always want to minimize the number of times you perform ... | ```python
for i in range(input()):
h = input()
n = 2**(h-2)
ans=0
while n>1:
ans+=n
n = n/4
print (ans+1)%1000000007
``` | vfc_74469 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1\n2\n3\n\nSAMPLE",
"output": "1\n1\n3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12",
"output": "1\n1\n3\n5\n11\n21\n43\n85\n171\n341\n6... |
code_contests | verifiable_code | palindrome-string-8 | Solve the following coding problem using the programming language python:
Arnab is given a string, but being the evil Lord he is, he has his own whims and fantasies about the string he wants to keep with himself. If he can convert a string into a palindrome by rearranging the characters, he will keep that string, othe... | ```python
from sys import stdin
t = int(stdin.readline())
for _ in xrange(t):
a = stdin.readline().strip()
di = {}
for i in a:
di[i] = di.get(i,0)+1
od = 0
for i in di:
if di[i]%2:
od+=1
ans = 'Yes'
if od > 1:
ans = 'No'
print ans
``` | vfc_74473 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\ncode\nprogrammer\nsnapchat\nmomo\nomom\nmmoo\noomm\noommo\nooomm\nmmomoo",
"output": "No\nNo\nNo\nYes\nYes\nYes\nYes\nYes\nYes\nNo",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\ncod... |
code_contests | verifiable_code | rivalry-of-code-3 | Solve the following coding problem using the programming language python:
The CS & IT Department students have been facing tough competitions from each other since ages, in being the best in research & innovation.
This time CS Department is taken the edge over IT Department by designing a special weather predictor dev... | ```python
T=input()
while(T!=0):
D=raw_input()
A=raw_input()
opp=0
l=[]
if len(D)==len(A):
for i in range(0,len(D)):
if A[i]!=D[i]:
opp+=1
print opp
else:
if len(D)>len(A):
temp=D
D=A
A=temp
for i in range(0,len(A)-len(D)+1):
for j in range(0,len(D)):
#if i+j < len(A):
if D[j]!... | vfc_74477 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nporrisa\npoornimainst\nwaatdes\nweather\n\nSAMPLE",
"output": "3\n3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\nMBNMVBDSJFHDFJDHFAKFHAKLFHFLKFURIFRFRYGRIFDYFIDFHYAIFAHFIAHFAIFHAFAK... |
code_contests | verifiable_code | splendid-matrices-10 | Solve the following coding problem using the programming language python:
Rani has challenged Nandu to generate Splendid Matrices. Splendid matrices are square matrices with dimensions 2^n X 2^n filled in a particular manner. To explain this manner, Rani gives Nandu the matrices for n=1, n=2 and n=3 :
n=1
1 2
3 4
n... | ```python
# Splendid Matrices
matrix=[[0 for x in range(1024)] for x in range(1024)]
def splendid(n,s,a,b):
if n>1:
p=(2**(n-1))*(2**(n-1))
k=(2**n)/2;
splendid(n-1,s,a,b)
splendid(n-1,s+p,a,b+k)
splendid(n-1,s+p*2,a+k,b)
splendid(n-1,s+p*3,a+k,b+k)
elif n==1:... | vfc_74481 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n\nSAMPLE",
"output": "1 2 5 6 17 18 21 22 \n3 4 7 8 19 20 23 24 \n9 10 13 14 25 26 29 30 \n11 12 15 16 27 28 31 32 \n33 34 37 38 49 50 53 54 \n35 36 39 40 51 52 55 56 \n41 42 45 46 57 58 61 62 \n43 44 47 48 59 60 63 64 \n"... |
code_contests | verifiable_code | tricky-triplet-2 | Solve the following coding problem using the programming language python:
Raghav is good in mathematics. He loves to ask puzzles with his friends. One day, he decides to challenge his friend Aditya who is not good with puzzles. So, Aditya needs your help in determining the solution to the puzzle asked by his friend wh... | ```python
t = int(raw_input())
numbers = map(int, raw_input().strip().split())
c=0
for i in range(0,t):
for j in range(i+1,t):
for k in range(j+1,t):
if (numbers[j] - numbers[i] == numbers[k] - numbers[j]):
c+=1
print c
``` | vfc_74485 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n3 5 3 1 2 5 3 7\n\nSAMPLE",
"output": "6",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "30\n2 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 5 5 5 5 5 5 5 1 1 1 1 1",
"output": "618",
"... |
code_contests | verifiable_code | p00000 QQ | Solve the following coding problem using the programming language python:
Write a program which prints multiplication tables in the following format:
1x1=1
1x2=2
.
.
9x8=72
9x9=81
Input
No input.
Output
1x1=1
1x2=2
.
.
9x8=72
9x9=81
Example
Input
Output
The input will be given via stdin and the outpu... | ```python
r=range
s=str
for i in r(1,10):
for u in r(1,10):
print(s(i)+'x'+s(u)+'='+s(i*u))
``` | vfc_74529 | {
"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": "",
"output": "",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00132 Jigsaw Puzzle | Solve the following coding problem using the programming language python:
Brain training puzzle games are popular from children to adults. We decided to make a puzzle game and play with everyone so that we could keep up.
We thought of a jigsaw puzzle game where you pick the pieces you need to fill in the unfinished p... | vfc_74533 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "14 20\n####################\n###.............####\n####..........######\n#######.....########\n########.....#######\n###..###......######\n###..####......#####\n#########......#####\n###########.....####\n############.....###\n###.... | |
code_contests | verifiable_code | p00265 Modular Query | Solve the following coding problem using the programming language python:
Give you N cards. Only one natural number is written on each card. However, the same number is never written.
From now on, as a question, I will say an appropriate natural number. Please answer the largest remainder you get when you divide the ... | ```python
# AOJ 0270: Modular Query
# Python3 2018.6.26 bal4u
N, Q = map(int, input().split())
tbl = [0]*300005
nmax, tbl[0] = 0, 1
c = list(map(int, input().split()))
for k in c:
tbl[k] = 1
if k > nmax: nmax = k
tbl[k & 1] = 1
tbl[k & 3] = 1
tbl[k & 7] = 1
for i in range(Q):
q = int(input())
if q > nmax: print... | vfc_74537 | {
"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": "3 3\n9 3 8\n4\n6\n5",
"output": "3\n3\n4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n9 3 8\n6\n6\n5",
"output": "3\n3\n4\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00452 Darts | Solve the following coding problem using the programming language python:
problem
You have to play a darts game with the following rules.
You can throw up to four arrows towards the target. You don't have to throw all four, you don't have to throw one. The target is divided into N parts. The score P1, ..., PN is wri... | ```python
from time import perf_counter
from itertools import combinations_with_replacement
from bisect import bisect_right
from functools import lru_cache
def solve1(darts, scores, point, target):
if darts == 3 or point > target:
if point > target:
return 0
else:
pos = bis... | vfc_74541 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 50\n3\n14\n15\n9\n3 21\n16\n11\n2\n0 0",
"output": "48\n20",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 58\n3\n14\n15\n9\n3 21\n16\n11\n2\n0 0",
"output": "58\n20\n",
"typ... |
code_contests | verifiable_code | p00643 Rolling Dice | Solve the following coding problem using the programming language python:
The north country is conquered by the great shogun-sama (which means king). Recently many beautiful dice which were made by order of the great shogun-sama were given to all citizens of the country. All citizens received the beautiful dice with a... | ```python
T, S, E, W, N, B = range(6)
class Dice:
def __init__(self):
self.state = list(range(6))
def __eq__(self, dice):
return self.state == dice.state
def __gt__(self, dice):
return self.state > dice.state
def copy(self):
dice = Dice()
dice.state = [x for ... | vfc_74545 | {
"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 2\n8 8\n0 0\n0 1\n3 3\n1 2 5\n2 8 3\n0 1 2\n0 0\n2 2\n3 3\n1 2 5\n2 8 3\n0 1 2\n0 0\n1 2\n2 2\n1 2\n3 4\n0 0\n0 1\n2 3\n1 2 3\n4 5 6\n0 0\n1 2\n0 0",
"output": "24\n19\n17\n6\n21",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | p00919 Directional Resemblance | Solve the following coding problem using the programming language python:
Vectors have their directions and two vectors make an angle between them. Given a set of three-dimensional vectors, your task is to find the pair among them that makes the smallest angle.
Input
The input is a sequence of datasets. A dataset ... | vfc_74553 | {
"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 0 2013 1124\n1 1 1\n2 2 2\n2 1 1\n1 2 1\n2 100 131832453 129800231\n42 40 46\n42 40 46\n0 100000 7004674 484521438\n0 0 0 0",
"output": "1 1 1 1 2 1\n42 40 46 83 79 91\n92 92 79 99 99 85",
"type": "stdin_stdout"
}... | |
code_contests | verifiable_code | p01184 International Party | Solve the following coding problem using the programming language python:
Isaac H. Ives is attending an international student party (maybe for girl-hunting). Students there enjoy talking in groups with excellent foods and drinks. However, since students come to the party from all over the world, groups may not have a ... | vfc_74561 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\nEnglish\nFrench\nJapanese\n1 English\n2 French English\n2 Japanese English\n1 Japanese\n2 2\nEnglish\nJapanese\n1 English\n1 Japanese\n6 7\nEnglish\nDutch\nGerman\nFrench\nItalian\nSpanish\n1 English\n2 English Dutch\n2 Dutch ... | |
code_contests | verifiable_code | p01321 Final Examination! | Solve the following coding problem using the programming language python:
Yui Hirasawa, who attends private Sakuragaoka Girls' High School, has to make a career hope by the day after tomorrow, but the trouble is that she hasn't decided anything yet. When I consulted with my friend Wa, I knew that my first choice was K... | ```python
while True:
n = int(input())
if n == 0:
break
total = []
for _ in range(n):
total.append(sum(list(map(int,input().split()))))
total.sort()
print(total[-1],total[0])
``` | vfc_74565 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n49 50 87 78 41\n27 61 100 45 84\n28 88 40 95 66\n2\n100 100 100 100 100\n0 0 0 0 0\n1\n89 90 85 93 82\n0",
"output": "317 305\n500 0\n439 439",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | p01489 IkaNumber | Solve the following coding problem using the programming language python:
Example
Input
5
Output
5
The input will be given via stdin and the output should be printed to stdout by your code.
Now solve the problem by providing the code. | ```python
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def fibonacci(N, M):
RA = RD = 1; RB = RC = 0
XA = XB = XC = 1; XD = 0
while N:
if N & 1:
RA, RB, RC, RD = (RA*XA + RB*XC) % M, (RA*XB + RB*XD) % M, (RC*XA + RD*XC) % M, (RC*XB + RD*XD) % M
XA, XB, XC, X... | vfc_74569 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p01802 Koto Municipal Subway | Solve the following coding problem using the programming language python:
Koto Municipal Subway
Koto Municipal Subway
Koto City is a famous city whose roads are in a grid pattern, as shown in the figure below. The roads extending from north to south and the roads extending from east to west are lined up at intervals... | ```python
def main():
while 1:
d,e= map(int, input().split())
if d == e == 0:
break
x = d
y = 0
ans = abs(d-e)
while y != d:
a = abs((x ** 2 + y ** 2) ** 0.5 - e)
ans = min(a,ans)
x -= 1
y += 1
print(... | vfc_74577 | {
"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": "2 1\n7 5\n7 6\n7 7\n76 5\n8 41\n0 0",
"output": "0.4142135624\n0\n0.0827625303\n0\n48.7401153702\n33",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n7 6\n7 6\n7 7\n76 5\n8 41\n0 0",
... |
code_contests | verifiable_code | p01936 Steps | Solve the following coding problem using the programming language python:
problem
AOR Ika-chan visited AOR Co., Ltd. AOR Co., Ltd. is a $ N $ building with no basement floor. AOR Ika started the tour from the $ 1 $ floor and decided to move just $ M $. You can move from the $ i $ floor to the $ i + 1 $ floor, or the ... | vfc_74581 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1",
"... | |
code_contests | verifiable_code | p02370 Topological Sort | Solve the following coding problem using the programming language python:
<image>
A directed acyclic graph (DAG) can be used to represent the ordering of tasks. Tasks are represented by vertices and constraints where one task can begin before another, are represented by edges. For example, in the above example, you ... | ```python
from collections import deque
from typing import List, Optional
def topological_sort(
graph: List[List[int]], in_degrees: List[int], first_index: int = 0
) -> Optional[List[int]]:
"""Topological sort that uses Kahn's algorithm and is able to detect cycles.
Returns:
If the given graph is ... | vfc_74593 | {
"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": "6 6\n0 1\n1 2\n3 1\n3 4\n4 5\n5 2",
"output": "0\n3\n1\n4\n5\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 6\n0 1\n1 2\n4 1\n3 4\n4 5\n5 2",
"output": "0\n3\n4\n1\n5\n2\n",
... |
code_contests | verifiable_code | aln | Solve the following coding problem using the programming language python:
There is a country which recently got invaded by a fleet of aliens. They started living with the people there. Relations between the aliens and humans were generally bitter. The government at the center decided that they will divide the country ... | ```python
n=input()
for I in range(n):
a=input()
c=map(int,raw_input().split())
l1=[]
l2=[]
for i in range(len(c)):
if c[i]==-1:
l1.append(-1)
if c[i]==1:
l2.append(1)
for j in l2:
l1.append(j)
for i in l1:
print i,
``` | vfc_74597 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n1 -1\n4\n-1 1 -1 -1\n5\n1 1 1 -1 -1",
"output": "-1 1\n-1 -1 -1 1\n-1 -1 1 1 1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | cheftic | Solve the following coding problem using the programming language python:
Tic-Tac-Toe used to be Chef's favourite game during his childhood. Reminiscing in his childhood memories, he decided to create his own "Tic-Tac-Toe", with rules being similar to the original Tic-Tac-Toe, other than the fact that it is played on ... | ```python
def read():
return map(int, raw_input().split())
def is_X(c):
if c == 'X':
return 1
else:
return 0
T = read()[0]
for n in range(T):
N, K = read()
Box =[None for i in range(N)]
for i in range(N):
s = raw_input()
Box[i] = list(s)
H1 = [ [0... | vfc_74601 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n4 4\nXOXO\nOX..\nXO..\nOXOX",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3 3\nXOX\nO.O\nXOX\n3 1\n...\n...\n...\n3 2\n...\n...\n...",
"output": "YES\nYES\nNO"... |
code_contests | verifiable_code | ds24 | Solve the following coding problem using the programming language python:
Problem
You are living in 2050, People do not work any more. Only surrogates (clone having same features & DNA characteristics) work for every individual. Government is substituting man labor by surrogates. Every person can control his own surr... | ```python
while True:
[n, m] = [int(i) for i in raw_input().split()]
if n == 0 and m == 0:
break
count = {}
for nn in xrange(n):
dna = raw_input()
if dna not in count:
count[dna] = 1
else:
count[dna] += 1
x = [0] * n
for c in count:
x[count[c] - 1] += 1
for i in x:
print i
``` | vfc_74605 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9 6\nAAAAAA\nACACAC\nGTTTTG\nACACAC\nGTTTTG\nACACAC\nACACAC\nTCCCCC\nTCCCCC\n0 0",
"output": "1\n2\n0\n1\n0\n0\n0\n0\n0",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | numsum | Solve the following coding problem using the programming language python:
According to folklore, the great mathematician Gauss was able to calculate the sum of the first 50 natural numbers in mere seconds. You are given a similar problem, where you have to calculate the sum of the first 'n' natural numbers. The only c... | ```python
import sys
import math
# def ndigits(n):
# return int(math.floor(math.log10(n)) + 1.1)
#
# m = 10**100
#
# def tostr(n):
# if n < m:
# return str(n)
# ndig = ndigits(n)
# botdig = ndig//2
# mid = 10 ** botdig
# top = tostr(n // mid)
# bot = tostr(n % mid)
# if len(b... | vfc_74613 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n5",
"output": "6\n15",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | smpair | Solve the following coding problem using the programming language python:
You are given a sequence a1, a2, ..., aN. Find the smallest possible value of ai + aj, where 1 ≤ i < j ≤ N.
Input
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The... | ```python
T = input()
for test in range(T):
N = input()
numbers = map(int, raw_input().split())
a = min(numbers)
numbers.remove(a)
b = min(numbers)
print a+b
``` | vfc_74617 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n4\n5 1 3 4",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n4\n5 1 3 8",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | 1005_A. Tanya and Stairways | Solve the following coding problem using the programming language python:
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from 1 to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stair... | ```python
scalini = input()
conti_tania = input().split(" ")
numero_scale = 0
numero_scalini = []
n = 0
conta_scalini = ""
count = 1
x = 0
lista = []
conti_tania.append('0')
for n in range(int(len(conti_tania))-1):
if int(conti_tania[n+1]) > int(conti_tania[n]):
count += 1
if int(conti_tania... | vfc_74621 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 1 1 1\n",
"output": "4\n1 1 1 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 2 3 4 5\n",
"output": "1\n5 ",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | 1028_G. Guess the number | Solve the following coding problem using the programming language python:
This problem is interactive.
You should guess hidden number x which is between 1 and M = 10004205361450474, inclusive.
You could use up to 5 queries.
In each query, you can output an increasing sequence of k ≤ x integers, each between 1 and M... | ```python
from sys import stdin, stdout
max_k=10000
max_shift = [max_k]
for t in range(1, 5):
max_shift.append(max_shift[t-1]*(max_k+1)+max_k)
def get_right(left, t): # [left...right]
if left >= max_k:
return left + max_shift[t-1] - 1
k = left
if k > max_k:
k = max_k
if t == 1:
... | vfc_74625 | {
"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": "2\n\n0\n\n-1",
"output": "1 204761410474 \n1 2046 \n1 6 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-1\n1000000000\n",
"output": "1 204761410474 \n",
"type": "stdin_stdout... |
code_contests | verifiable_code | 1047_C. Enlarge GCD | Solve the following coding problem using the programming language python:
Mr. F has n positive integers, a_1, a_2, …, a_n.
He thinks the greatest common divisor of these integers is too small. So he wants to enlarge it by removing some of the integers.
But this problem is too simple for him, so he does not want to d... | ```python
from sys import stdin
from collections import deque
mod = 10**9 + 7
# def rl():
# return [int(w) for w in stdin.readline().split()]
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt,factorial,gcd,log2,inf,ceil
# map(int,input().split()... | vfc_74629 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n6 9 15 30\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1093_A. Dice Rolling | Solve the following coding problem using the programming language python:
Mishka got a six-faced dice. It has integer numbers from 2 to 7 written on its faces (all numbers on faces are different, so this is an almost usual dice).
Mishka wants to get exactly x points by rolling his dice. The number of points is just a... | ```python
"""
██╗ ██████╗ ██╗ ██████╗ ██████╗ ██╗ █████╗
██║██╔═══██╗██║ ╚════██╗██╔═████╗███║██╔══██╗
██║██║ ██║██║ █████╔╝██║██╔██║╚██║╚██████║
██║██║ ██║██║ ██╔═══╝ ████╔╝██║ ██║ ╚═══██║
██║╚██████╔╝██║ ███████╗╚██████╔╝ ██║ █████╔╝
╚═╝ ╚═════╝ ╚═╝ ╚══════╝ ╚═════╝ ╚═╝ ╚════╝
██████╗ ██╗██╗... | vfc_74637 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2\n13\n37\n100\n",
"output": "1\n2\n6\n15\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n... |
code_contests | verifiable_code | 1113_A. Sasha and His Trip | Solve the following coding problem using the programming language python:
Sasha is a very happy guy, that's why he is always on the move. There are n cities in the country where Sasha lives. They are all located on one straight line, and for convenience, they are numbered from 1 to n in increasing order. The distance ... | ```python
n,v=[int(x) for x in input().split()]
if n<=v+1:
print(n-1)
else:
print(v+(n-v-1)*(n-v-2)//2+(n-v-1)*2)
``` | vfc_74641 | {
"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": "7 6\n",
"output": "6 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n",
"output": "4 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9 5\n... |
code_contests | verifiable_code | 1141_D. Colored Boots | Solve the following coding problem using the programming language python:
There are n left boots and n right boots. Each boot has a color which is denoted as a lowercase Latin letter or a question mark ('?'). Thus, you are given two strings l and r, both of length n. The character l_i stands for the color of the i-th ... | ```python
#Bhargey Mehta (Sophomore)
#DA-IICT, Gandhinagar
import sys, math, queue
sys.setrecursionlimit(1000000)
#sys.stdin = open("input.txt", "r")
n = int(input())
l = list(input())
r = list(input())
ls = {chr(i):[] for i in range(97, 97+26)}
rs = {chr(i):[] for i in range(97, 97+26)}
lc = []
rc = []
for i in range... | vfc_74645 | {
"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": "10\ncodeforces\ndodivthree\n",
"output": "5\n3 1\n4 9\n9 10\n2 2\n7 8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\ncode??????\n??????test\n",
"output": "10\n4 8\n10 9\n9 10\n8... |
code_contests | verifiable_code | 115_C. Plumber | Solve the following coding problem using the programming language python:
Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells.
In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, ill... | ```python
n,m = map(int, raw_input().split())
mp = []
def checkrow(row):
ret = 0
beg = False
ok = True
for j in range(m):
if(mp[row][j] != '.'):
if not beg and (mp[row][j] != '1' and mp[row][j] != '2'):
ok = False
if beg and (mp[row][j] != '3' and mp[row]... | vfc_74649 | {
"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 2\n3.\n.1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n1\n4\n.\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1182_C. Beautiful Lyrics | Solve the following coding problem using the programming language python:
You are given n words, each of which consists of lowercase alphabet letters. Each word contains at least one vowel. You are going to choose some of the given words and make as many beautiful lyrics as possible.
Each lyric consists of two lines.... | ```python
from sys import stdin
n = int(stdin.readline())
vowels = {'a', 'e', 'o', 'i', 'u'}
words = []
for i in range(n):
words.append(stdin.readline())
all_pairs = {}
sec_pairs = {}
for item in words:
cnt, last = 0, -1
for i in item:
if i in vowels:
cnt += 1
last = i
# all_pairs
if cnt not in all... | vfc_74653 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "14\nwow\nthis\nis\nthe\nfirst\nmcdics\ncodeforces\nround\nhooray\ni\nam\nproud\nabout\nthat\n",
"output": "3\nthe am\ni that\nhooray this\nabout is\nfirst round\nmcdics proud\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 11_C. How Many Squares? | Solve the following coding problem using the programming language python:
You are given a 0-1 rectangular matrix. What is the number of squares in it? A square is a solid square frame (border) with linewidth equal to 1. A square should be at least 2 × 2. We are only interested in two types of squares:
1. squares w... | vfc_74657 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n8 8\n00010001\n00101000\n01000100\n10000010\n01000100\n00101000\n11010011\n11000011\n10 10\n1111111000\n1000001000\n1011001000\n1011001010\n1000001101\n1001001010\n1010101000\n1001001000\n1000001000\n1111111000\n",
"output... | |
code_contests | verifiable_code | 1240_C. Paint the Tree | Solve the following coding problem using the programming language python:
You are given a weighted tree consisting of n vertices. Recall that a tree is a connected graph without cycles. Vertices u_i and v_i are connected by an edge with weight w_i.
Let's define the k-coloring of the tree as an assignment of exactly k... | vfc_74665 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 1\n1 2 5\n3 1 2\n3 4 3\n7 2\n1 2 5\n1 3 4\n1 4 2\n2 5 1\n2 6 2\n4 7 3\n",
"output": "8\n14\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1260_D. A Game with Traps | Solve the following coding problem using the programming language python:
You are playing a computer game, where you lead a party of m soldiers. Each soldier is characterised by his agility a_i.
The level you are trying to get through can be represented as a straight line segment from point 0 (where you and your squa... | ```python
import sys
import math
from collections import defaultdict,Counter,deque
# input=sys.stdin.readline
# def print(x):
# sys.stdout.write(str(x)+"\n")
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.filen... | vfc_74669 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6 4 14\n1 2 3 4 5\n1 5 2\n1 2 5\n2 3 5\n3 5 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "22 4 33 11\n35 58 48 7 5 19 18 50 56 6 38 3 4 30 29 35 37 22 57 15 53 5\n1 ... |
code_contests | verifiable_code | 1282_D. Enchanted Artifact | Solve the following coding problem using the programming language python:
This is an interactive problem.
After completing the last level of the enchanted temple, you received a powerful artifact of the 255th level. Do not rush to celebrate, because this artifact has a powerful rune that can be destroyed with a singl... | vfc_74673 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n\n2\n\n1\n\n2\n\n3\n\n0",
"output": "a\naaa\nbaa\nbba\nbab\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "bbbbbbaa\n",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.