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 | p00930 Flipping Parentheses | Solve the following coding problem using the programming language python:
Example
Input
6 3
((()))
4
3
1
Output
2
2
1
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
from heapq import heappush, heappop, heapify
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N, Q = map(int, readline().split())
INF = 2**31-1
LV = (N-1).bit_length()
N0 = 2**LV
data = [0]*(2*N0)
lazy = [0]*(2*N0)
L0 = [0]*(2*N0)
L1 = [0]*(2*N0... | vfc_52065 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 3\n((()))\n4\n3\n1",
"output": "2\n2\n1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 2\n((()))\n4\n3\n1",
"output": "2\n2\n",
"type": "stdin_stdout"
},
{
"fn... |
code_contests | verifiable_code | p01063 Rubik Dungeon | Solve the following coding problem using the programming language python:
Problem
You've come to an n x n x n cubic Rubik's Cube dungeon.
You are currently in the room (x1, y1, z1).
The target treasure is in the room (x2, y2, z2).
You can move to adjacent rooms in front, back, left, right, up and down in unit time.
... | vfc_52069 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n0 0 0\n0 0 2",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n0 0 0\n1 2 2",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... | |
code_contests | verifiable_code | p01196 The Phantom | Solve the following coding problem using the programming language python:
Mr. Hoge is in trouble. He just bought a new mansion, but it’s haunted by a phantom. He asked a famous conjurer Dr. Huga to get rid of the phantom. Dr. Huga went to see the mansion, and found that the phantom is scared by its own mirror images. ... | vfc_52073 | {
"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 4\n3 3 5 3\n3 5 5 6\n4 4\n3 3 5 3\n3 5 5 5\n0 0",
"output": "4\nTOO MANY",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4\n3 3 5 3\n3 5 5 6\n4 4\n3 3 5 3\n3 5 8 5\n0 0",
"output":... | |
code_contests | verifiable_code | p01333 Summer of KMC | Solve the following coding problem using the programming language python:
Description
KMC sells CDs every year at a coterie spot sale called Comic Market. F was supposed to sell CDs at the comic market, but due to the popularity of F, the KMC sales floor was flooded with people, and the calculation of change could no... | ```python
while True:
a, b = map(int, input().split())
if a == 0 and b == 0:break
w = b - a
x = w // 1000
w %= 1000
y = w // 500
w %= 500
z = w // 100
print(z, y, x)
``` | vfc_52077 | {
"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": "500 1000\n100 10000\n400 700\n600 5000\n10000 10000\n0 0",
"output": "0 1 0\n4 1 9\n3 0 0\n4 0 4\n0 0 0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "500 1001\n100 10000\n400 700\n600 5000... |
code_contests | verifiable_code | p01500 Rabbit Jumping | Solve the following coding problem using the programming language python:
Example
Input
6 3 1.0
1 2 3
4 5 6
0 0
1 0
2 0
0 1
1 1
2 1
Output
3
The input will be given via stdin and the output should be printed to stdout by your code.
Now solve the problem by providing the code. | vfc_52081 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 3 1.0\n1 2 3\n4 5 6\n0 0\n1 0\n2 0\n0 1\n1 1\n2 1",
"output": "3",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01671 Minimum Spanning Tree | Solve the following coding problem using the programming language python:
E - Minimum Spanning Tree
Problem Statement
You are given an undirected weighted graph G with n nodes and m edges. Each edge is numbered from 1 to m.
Let G_i be an graph that is made by erasing i-th edge from G. Your task is to compute the co... | vfc_52085 | {
"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": "4 6\n1 2 2\n1 3 6\n1 4 3\n2 3 1\n2 4 4\n3 4 5",
"output": "8\n6\n7\n10\n6\n6",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01948 Janken Master | Solve the following coding problem using the programming language python:
You are supposed to play the rock-paper-scissors game. There are $N$ players including you.
This game consists of multiple rounds. While the rounds go, the number of remaining players decreases. In each round, each remaining player will select ... | vfc_52093 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n1 40 40 20",
"output": "0.8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n4\n1 34 33 33\n2 33 34 33\n3 33 33 34",
"output": "0.6591870816",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | p02097 Horizontal-Vertical Permutation | Solve the following coding problem using the programming language python:
J: Horizontal-Vertical Permutation
Problem Statement
You are given a positive integer N. Your task is to determine if there exists a square matrix A whose dimension is N that satisfies the following conditions and provide an example of such ma... | vfc_52097 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4",
"output": "Yes\n2 6 3 7\n4 5 2 1\n1 7 5 6\n5 3 4 2",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p02235 Longest Common Subsequence | Solve the following coding problem using the programming language python:
For given two sequences $X$ and $Y$, a sequence $Z$ is a common subsequence of $X$ and $Y$ if $Z$ is a subsequence of both $X$ and $Y$. For example, if $X = \\{a,b,c,b,d,a,b\\}$ and $Y = \\{b,d,c,a,b,a\\}$, the sequence $\\{b,c,a\\}$ is a common... | ```python
def lcs(x,y):
L=[]
for chk in y:
bg_i=0
for i,chr_i in enumerate(L):
cur_i=x.find(chk,bg_i)+1
if not cur_i:
break
L[i]=min(cur_i,chr_i)
bg_i=chr_i
else:
cur_i=x.find(chk,bg_i)+1
if cur_i:
... | vfc_52101 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nabcbdab\nbdcaba\nabc\nabc\nabc\nbc",
"output": "4\n3\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nabcbdab\nbdcaba\nabc\nabc\nacb\nbc",
"output": "4\n3\n1\n",
"type": ... |
code_contests | verifiable_code | p02381 Standard Deviation | Solve the following coding problem using the programming language python:
You have final scores of an examination for n students. Calculate standard deviation of the scores s1, s2 ... sn.
The variance α2 is defined by
α2 = (∑ni=1(si - m)2)/n
where m is an average of si. The standard deviation of the scores is the s... | ```python
import math
n = int(input())
while not n == 0:
ss = [float(i) for i in input().split(' ')]
m = sum(ss)/n
a2 = sum([(i-m)**2 for i in ss]) / n
print(math.sqrt(a2))
n = int(input())
``` | vfc_52105 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n70 80 100 90 20\n3\n80 80 80\n0",
"output": "27.85677655\n0.00000000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n70 80 100 107 20\n3\n80 80 80\n0",
"output": "30.7349963397\n... |
code_contests | verifiable_code | amr15d | Solve the following coding problem using the programming language python:
Bhallaladeva was an evil king who ruled the kingdom of Maahishmati. He wanted to erect a 100ft golden statue of himself and he looted gold from several places for this. He even looted his own people, by using the following unfair strategy:
There... | ```python
import sys
n = input()
lists = map(int,sys.stdin.readline().split())
lists.sort()
pref = [0]*(n+1)
pref[0] = lists[0]
for i in range(1,n) :
pref[i] = pref[i-1]
pref[i] += lists[i]
for __ in range(input()) :
k = input()
print pref[n/(k+1)] if n%(k+1) else pref[(n/(k+1)-1)]
``` | vfc_52109 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n3 2 1 4\n2\n0\n2",
"output": "10\n3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n3 2 1 0\n2\n0\n2",
"output": "6\n1\n",
"type": "stdin_stdout"
},
{
"fn_nam... |
code_contests | verifiable_code | chgift1 | Solve the following coding problem using the programming language python:
Chef likes cooking. But more than that, he likes to give gifts. And now he wants to give his girlfriend an unforgettable gift. But unfortunately he forgot the password to the safe where the money he saved for the gift is kept.
But he knows how ... | ```python
import sys
def readtestcase():
n = int(sys.stdin.readline())
num = map(int, sys.stdin.readline().split())
mini = num[0]
maxi = num[0]
for i in range(1,len(num)):
omini = mini
mini = min([ mini-num[i], mini+num[i], mini*num[i], maxi-num[i], maxi+num[i], maxi*num[i]])
... | vfc_52113 | {
"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\n1 2 3\n1\n9",
"output": "-4\n9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3\n2 2 3\n1\n9",
"output": "-3\n9\n",
"type": "stdin_stdout"
},
{
"fn_name":... |
code_contests | verifiable_code | encode01 | Solve the following coding problem using the programming language python:
Arunava has learnt to find the sum of first N natural numbers using the expression N(N+1)/2.But now Kartik Sir has asked him to find the sum of floor(N/2) for first N natural numbers where floor(X) is the greatest integer less than or equal to a... | ```python
import sys
def main():
answers = [0]*10000
val = 0
for i in xrange(1,5000):
d = i*2
val += d
answers[d] = val-i
answers[d+1] = val
t = int(raw_input())
inp = map(int, sys.stdin.read().split())
out = ""
for _ in inp:
out+=str(answers[_])+"\n"... | vfc_52117 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1\n2\n3\n4\n5",
"output": "0\n1\n2\n4\n6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1\n4\n3\n4\n5",
"output": "0\n4\n2\n4\n6\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | kjcc01 | Solve the following coding problem using the programming language python:
Chef wants you to write a calculator program for carrying out some simple mathematical operations. Chef calls the program Calculator Plus Plus.
Input
First line contains an operation in the form : a operator b
Output
Output in a single lin... | ```python
A=raw_input().split(); op_1=int(A[0]); op_2=int(A[2]);
if A[1]=='+':
print op_1+op_2;
elif A[1]=='-':
print op_1-op_2;
elif A[1]=='*':
print op_1*op_2;
elif A[1]=='/':
print op_1/op_2;
else:
print 'Invalid Operator';
``` | vfc_52121 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 % 1",
"output": "Invalid Operator\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 + 30",
"output": "40\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | opc1604 | Solve the following coding problem using the programming language python:
Raavan abducted sita in the past, at that time when Ram went to save her wife , he was posed a question by Raavan in binomial theorem :
given N Ram has to find the number of odd coefficients in the expansion of (1+x)^n . As the number given by ... | ```python
print 2**(bin(int(raw_input())).count('1'))
``` | vfc_52125 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3",
"output": "4",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | spoon | Solve the following coding problem using the programming language python:
Chef recently saw the movie Matrix. He loved the movie overall but he didn't agree with some things in it. Particularly he didn't agree with the bald boy when he declared - There is no spoon. Being a chef, he understands the importance of the sp... | ```python
tc = int(raw_input()) #number of test cases
for t in range(tc):
r, c = map(int,raw_input().split())
L = []
for r1 in range(r):
L.append(raw_input().strip().lower())
findCase = False
for e in L:
if 'spoon' in e:
findCase = True
break
nL = ['']*c
... | vfc_52129 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 6\nabDefb\nbSpoon\nNIKHil\n6 6\naaaaaa\nssssss\nxuisdP\noooooo\nioowoo\nbdylan\n6 5\nbdfhj\ncacac\nopqrs\nddddd\nindia\nyucky",
"output": "There is a spoon!\nThere is a spoon!\nThere is indeed no spoon!\n",
"type":... |
code_contests | verifiable_code | 1006_A. Adjacent Replacements | Solve the following coding problem using the programming language python:
Mishka got an integer array a of length n as a birthday present (what a surprise!).
Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This alg... | ```python
if __name__ == "__main__":
_ = int(input())
arr = [int(num) for num in input().split()]
for i in arr:
if i % 2 == 0:
print(i - 1, end=" ")
else:
print(i, end=" ")
``` | vfc_52133 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 4 5 10\n",
"output": "1 1 3 5 9 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000\n",
"output": "9999 9 50605065 1 5 ... |
code_contests | verifiable_code | 1029_F. Multicolored Markers | Solve the following coding problem using the programming language python:
There is an infinite board of square tiles. Initially all tiles are white.
Vova has a red marker and a blue marker. Red marker can color a tiles. Blue marker can color b tiles. If some tile isn't white then you can't use marker of any color on ... | ```python
a, b = map(int,input().split())
ad = []
for i in range(1,a+1):
if i*i > a:
break
if a % i == 0:
ad.append(i)
if i*i != a:
ad.append(a//i)
bd = []
for i in range(1,b+1):
if i*i > b:
break
if b % i == 0:
bd.append(i)
if i*i != b:
bd.append(b//i)
ab = a+b
abd = []
for i in range(1,ab+1):
i... | vfc_52137 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 9\n",
"output": "14\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 104_E. Time to Raid Cowavans | Solve the following coding problem using the programming language python:
As you know, the most intelligent beings on the Earth are, of course, cows. This conclusion was reached long ago by the Martian aliens, as well as a number of other intelligent civilizations from outer space.
Sometimes cows gather into cowavan... | vfc_52141 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 70000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 3 5 7\n3\n1 3\n2 3\n2 2\n",
"output": " 9\n 3\n ... | |
code_contests | verifiable_code | 1073_A. Diverse Substring | Solve the following coding problem using the programming language python:
You are given a string s, consisting of n lowercase Latin letters.
A substring of string s is a continuous segment of letters from s. For example, "defor" is a substring of "codeforces" and "fors" is not.
The length of the substring is the nu... | ```python
length=int(input())
def AllSubsets(s) : # accepts a string , returns a list of all non empty subsets
l=[]
for i in range (len(s)) :
if i <len(s)-1:
for j in range (i+2,len(s)+1):
l+=[s[i:j]]
else :
l+=[s[i]]
return l
#print(AllSubsets("string"))
def diverse(st) : # accepts string , re... | vfc_52145 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\naaaaa\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\ncodeforces\n",
"output": "YES\nco\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1095_A. Repeating Cipher | Solve the following coding problem using the programming language python:
Polycarp loves ciphers. He has invented his own cipher called repeating.
Repeating cipher is used for strings. To encrypt the string s=s_{1}s_{2} ... s_{m} (1 ≤ m ≤ 10), Polycarp uses the following algorithm:
* he writes down s_1 ones,
* ... | ```python
try:
t = int(input())
s = input()
_ = 1
i = 0
l = []
while((i)<=(len(s)-1)):
#print(i)
l.append(s[i])
_+=1
i = i+_
s = "".join(l)
print(s)
except:
pass
``` | vfc_52149 | {
"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\nbaabbb\n",
"output": "bab",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\nooopppssss\n",
"output": "oops",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1114_B. Yet Another Array Partitioning Task | Solve the following coding problem using the programming language python:
An array b is called to be a subarray of a if it forms a continuous subsequence of a, that is, if it is equal to a_l, a_{l + 1}, …, a_r for some l, r.
Suppose m is some known constant. For any array, having m or more elements, let's define it's... | ```python
from operator import itemgetter
from itertools import accumulate
from sys import stdin, stdout
n, m, k = [int(x) for x in stdin.readline().split()]
a = [int(x) for x in stdin.readline().split()]
id = [x for x in range(n)]
b = list(zip(a, id))
a.sort(reverse = True)
b.sort(reverse = True)
c = [p[1] for p in b[... | vfc_52153 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1 2\n-1000000000 1000000000\n",
"output": "0\n1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9 2 3\n5 2 5 2 4 1 1 3 2\n",
"output": "21\n2 4 ",
"type": "stdin_stdout"
}... |
code_contests | verifiable_code | 1142_C. U2 | Solve the following coding problem using the programming language python:
Recently Vasya learned that, given two points with different x coordinates, you can draw through them exactly one parabola with equation of type y = x^2 + bx + c, where b and c are reals. Let's call such a parabola an U-shaped one.
Vasya drew s... | ```python
import sys
def cross(o, a, b):
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0])
N = int(input())
A = [None]*N
for i in range(N):
x, y = map(int, sys.stdin.readline().split())
A[i] = (x, y-x*x)
A.sort()
upper = []
for p in reversed(A):
while len(upper) >= 2 and cross(upper[... | vfc_52157 | {
"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\n-1 0\n0 2\n1 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 0\n1 -1\n0 -1\n-1 0\n-1 -1\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1162_E. Thanos Nim | Solve the following coding problem using the programming language python:
Alice and Bob are playing a game with n piles of stones. It is guaranteed that n is an even number. The i-th pile has a_i stones.
Alice and Bob will play a game alternating turns with Alice going first.
On a player's turn, they must choose exa... | ```python
n = int(input())
L = [int(i) for i in input().split()]
s = 0
m = L[0]
for i in L:
if i == 1:
s += 1
if i < m:
m = i
if s > n // 2:
print('Bob')
elif s <= n // 2 and s > 0:
print('Alice')
elif s == 0:
ss = 0
for j in L:
if j == m:
ss += 1
if ss <... | vfc_52161 | {
"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\n3 1 4 1\n",
"output": "Alice\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n8 8\n",
"output": "Bob\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | 1183_D. Candy Box (easy version) | Solve the following coding problem using the programming language python:
This problem is actually a subproblem of problem G from the same contest.
There are n candies in a candy box. The type of the i-th candy is a_i (1 ≤ a_i ≤ n).
You have to prepare a gift using some of these candies with the following restrictio... | ```python
q=int(input())
for i in range(q):
n=int(input())
a=list(map(int,input().split()))
counts=[0]*(len(a)+1)
ans=0
for i in range(len(a)):
counts[a[i]]+=1
counts.sort(reverse=True)
w=counts[0]+1
for i in counts:
w=max(min(w-1,i),0)
ans+=w
print(ans)
``` | vfc_52165 | {
"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": "3\n8\n1 4 8 4 5 6 3 8\n16\n2 1 3 3 4 3 4 4 1 3 2 2 2 4 1 1\n9\n2 2 4 4 4 7 7 7 7\n",
"output": "3\n10\n9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n8\n1 0\n4 1\n2 0\n4 1\n5 1\n6 1\... |
code_contests | verifiable_code | 1200_E. Compress Words | Solve the following coding problem using the programming language python:
Amugae has a sentence consisting of n words. He want to compress this sentence into one word. Amugae doesn't like repetitions, so when he merges two words into one word, he removes the longest prefix of the second word that coincides with a suff... | ```python
from sys import stdin, stdout
def compresswords(n, words):
a = []
for c in words[0]:
a.append(c)
for i in range(1, len(words)):
lps = getlps(words[i])
#print(lps)
idx = getsuffixmatchIdx(a, words[i], lps)
#print(idx)
#if idx == -1:
# ... | vfc_52169 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\nsample please ease in out\n",
"output": "sampleaseinout\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nI want to order pizza\n",
"output": "Iwantorderpizza\n",
"type": "... |
code_contests | verifiable_code | 1218_G. Alpha planetary system | Solve the following coding problem using the programming language python:
Three planets X, Y and Z within the Alpha planetary system are inhabited with an advanced civilization. The spaceports of these planets are connected by interplanetary space shuttles. The flight scheduler should decide between 1, 2 and 3 return ... | vfc_52173 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 128000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n15\nXXXXYYYZZZ\n0 4\n0 5\n0 6\n4 1\n4 8\n1 7\n1 9\n7 2\n7 5\n5 3\n6 2\n6 9\n8 2\n8 3\n9 3\n",
"output": "\n0 4 2\n0 5 2\n0 6 2\n4 1 1\n4 8 1\n1 7 2\n1 9 3\n7 2 2\n7 5 1\n5 3 1\n6 2 1\n6 9 1\n8 2 3\n8 3 1\n9 3 1\n",
... | |
code_contests | verifiable_code | 1242_D. Number Discovery | Solve the following coding problem using the programming language python:
Ujan needs some rest from cleaning, so he started playing with infinite sequences. He has two integers n and k. He creates an infinite sequence s by repeating the following steps.
1. Find k smallest distinct positive integers that are not in ... | vfc_52177 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n10 2\n40 5\n",
"output": "11\n12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n503 1998\n9876 987654\n177 2336\n8 991\n119741 22365\n8888 10101\n3364 777071\n4889 9930\n",
"o... | |
code_contests | verifiable_code | 1261_D1. Wrong Answer on test 233 (Easy Version) | Solve the following coding problem using the programming language python:
Your program fails again. This time it gets "Wrong answer on test 233"
.
This is the easier version of the problem. In this version 1 ≤ n ≤ 2000. You can hack this problem only if you solve and lock both problems.
The problem is about a test ... | ```python
def main():
M=998244353
n,k,*h=map(int,open(0).read().split())
m=sum(i!=j for i,j in zip(h,h[1:]+h[:1]))
f=[0]*(m+1)
f[0]=b=1
for i in range(1,m+1):f[i]=b=b*i%M
inv=[0]*(m+1)
inv[m]=b=pow(f[m],M-2,M)
for i in range(m,0,-1):inv[i-1]=b=b*i%M
comb=lambda n,k:f[n]*inv[n-k]*... | vfc_52181 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n1 3 1\n",
"output": "9\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1283_F. DIY Garland | Solve the following coding problem using the programming language python:
Polycarp has decided to decorate his room because the New Year is soon. One of the main decorations that Polycarp will install is the garland he is going to solder himself.
Simple garlands consisting of several lamps connected by one wire are t... | ```python
import sys,math,itertools
from collections import Counter,deque,defaultdict
from bisect import bisect_left,bisect_right
from heapq import heappop,heappush,heapify, nlargest
from copy import deepcopy
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, ... | vfc_52185 | {
"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": "6\n3 6 3 1 5\n",
"output": "3\n3 6\n6 5\n3 1\n1 4\n5 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n1 48 78 56 75 22 48 7 28 70 77 32 43 71 40 72 29 28 83 15 9 16 52 40 91 14 69 75... |
code_contests | verifiable_code | 1303_B. National Project | Solve the following coding problem using the programming language python:
Your company was appointed to lay new asphalt on the highway of length n. You know that every day you can either repair one unit of the highway (lay new asphalt over one unit of the highway) or skip repairing.
Skipping the repair is necessary b... | ```python
def ceil(a):
if(a//1 == a):
return int(a)
else:
return(int(a)+1)
for i in range(0,int(input())):
n,g,b = list(map(int, input().split()))
if(g>=b):
print(n)
else:
u = ceil(n/2)
# print(u)
k = ceil((u)/g) - 1
# print(k)
if(k*(g+... | vfc_52189 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5 1 1\n8 10 10\n1000000 1 1000000\n",
"output": "5\n8\n499999500000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n5 1 1\n8 6 10\n1000000 1 1000000\n",
"output": "5\n8\n499999... |
code_contests | verifiable_code | 1327_C. Game with Chips | Solve the following coding problem using the programming language python:
Petya has a rectangular Board of size n × m. Initially, k chips are placed on the board, i-th chip is located in the cell at the intersection of sx_i-th row and sy_i-th column.
In one action, Petya can move all the chips to the left, right, dow... | ```python
n,m,k=map(int, input().split())
for i in range(2*k):
map(int, input().split())
ans = (m-1)*'L' + (n-1)*'U'
for i in range(n):
if i%2==0:
ans += 'R'*(m-1)
else:
ans += 'L'*(m-1)
if i < n-1:
ans+='D'
print(len(ans))
print(ans)
``` | vfc_52193 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4 3\n3 4\n3 1\n3 3\n5 3\n1 3\n1 4\n",
"output": "26\nUUUULLLRRRDLLLDRRRDLLLDRRR",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1346_E. Magic Tricks | Solve the following coding problem using the programming language python:
Masha is going to participate in a talent show conducted by the university she studies at. She wants to impress the audience with lots of different magic tricks!
For one of her tricks, she uses n sponge balls, one of which is a special one. Fir... | vfc_52197 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 5 1\n3 4\n2 1\n4 1\n3 1\n3 1\n",
"output": "\n2 0 3 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 7 4\n3 2\n3 2\n4 2\n3 4\n4 1\n3 2\n5 2\n",
"output": "\n2 2 0 3 1 \n",
... | |
code_contests | verifiable_code | 1368_C. Even Picture | Solve the following coding problem using the programming language python:
Leo Jr. draws pictures in his notebook with checkered sheets (that is, each sheet has a regular square grid printed on it). We can assume that the sheets are infinitely large in any direction.
To draw a picture, Leo Jr. colors some of the cells... | ```python
import sys
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
def solve():
n = mint()
print((n+1)*3+1)
for i in range(n+1):
print(i,i)
print(1+i,i)
print(i,1+i)
print(n+1,n+1)
#for i in range(mint()):
solve()
``` | vfc_52201 | {
"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": "4\n",
"output": "16\n0 0\n0 1\n1 0\n1 1\n1 2\n2 1\n2 2\n2 3\n3 2\n3 3\n3 4\n4 3\n4 4\n4 5\n5 4\n5 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "13\n0 0\n0 1\n1 0... |
code_contests | verifiable_code | 1389_E. Calendar Ambiguity | Solve the following coding problem using the programming language python:
Berland year consists of m months with d days each. Months are numbered from 1 to m. Berland week consists of w days. The first day of the year is also the first day of the week. Note that the last week of the year might be shorter than w days.
... | ```python
import sys
input = sys.stdin.readline
aaaa = list()
for kek in range(int(input())):
(m, d, w) = map(int, input().split())
g = min(m,d)
d -=1
i = 2
while i < d**(1/2)+2:
if d % i == 0:
d //= i
if w % i == 0:
w //= i
else:
i... | vfc_52205 | {
"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\n6 7 4\n10 7 12\n12 30 7\n1 1 1\n3247834 10298779 625324\n",
"output": "6\n9\n5\n0\n116461800\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n6 7 4\n10 7 12\n12 30 6\n1 1 1\n3247834 1... |
code_contests | verifiable_code | 140_B. New Year Cards | Solve the following coding problem using the programming language python:
As meticulous Gerald sets the table, Alexander finished another post on Codeforces and begins to respond to New Year greetings from friends. Alexander has n friends, and each of them sends to Alexander exactly one e-card. Let us number his frien... | ```python
n = int(input())
arr = [list(map(int, input().split())) for _ in range(n+1)]
res = [0] * n
for i in range(n):
p = [0] * (n+1)
for j in range(n):
p[arr[i][j]] = j
u, t, b = 0, int(1e5), int(1e5)
for x in arr[n]:
if x != i+1 and x < b:
if p[x] < t:
u... | vfc_52209 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 3 4\n4 1 3 2\n4 3 1 2\n3 4 2 1\n3 1 2 4\n",
"output": "2 1 1 3 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n5 1 6 2 8 3 4 10 9 7\n3 1 10 6 8 5 2 7 9 4\n2 9 1 4 10 6 8 7 3 5\... |
code_contests | verifiable_code | 1430_F. Realistic Gameplay | Solve the following coding problem using the programming language python:
Recently you've discovered a new shooter. They say it has realistic game mechanics.
Your character has a gun with magazine size equal to k and should exterminate n waves of monsters. The i-th wave consists of a_i monsters and happens from the l... | ```python
from bisect import *
from collections import *
from math import *
from heapq import *
from typing import List
from itertools import *
from operator import *
from functools import *
#------------------------------------------------------------------------
import os
import sys
from io import BytesIO, IOBase
# ... | vfc_52213 | {
"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": "2 3\n2 3 6\n3 4 3\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 5\n3 7 11\n10 12 15\n",
"output": "30\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1454_B. Unique Bid Auction | Solve the following coding problem using the programming language python:
There is a game called "Unique Bid Auction". You can read more about it here: https://en.wikipedia.org/wiki/Unique_bid_auction (though you don't have to do it to solve this problem).
Let's simplify this game a bit. Formally, there are n partici... | ```python
t=int(input())
for i in range(t):
n=int(input())
l=list(map(int,input().split()))
d={}
for i in range(len(l)):
if l[i] in d:
d[l[i]].append(i+1)
else:
d[l[i]]=[i+1]
a=[]
flag=0
for i in d:
if len(d[i])==1:
flag=1
... | vfc_52217 | {
"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": "6\n2\n1 1\n3\n2 1 3\n4\n2 2 2 3\n1\n1\n5\n2 3 2 4 2\n6\n1 1 5 5 4 4\n",
"output": "\n-1\n2\n4\n1\n2\n-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2\n1 1\n1\n1\n",
"output": ... |
code_contests | verifiable_code | 1477_F. Nezzar and Chocolate Bars | Solve the following coding problem using the programming language python:
Nezzar buys his favorite snack — n chocolate bars with lengths l_1,l_2,…,l_n. However, chocolate bars might be too long to store them properly!
In order to solve this problem, Nezzar designs an interesting process to divide them into small pie... | vfc_52221 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\n1\n",
"output": "\n0\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1505_B. DMCA | Solve the following coding problem using the programming language python:
Many people are aware of DMCA – Digital Millennium Copyright Act. But another recently proposed DMCA – Digital Millennium Calculation Act – is much less known.
In this problem you need to find a root of a number according to this new DMCA law.
... | ```python
n = int(input())
sumo = n
while n>=10:
sumo = 0
while n!=0:
sumo+=n%10
n//=10
n = sumo
print(sumo)
``` | vfc_52225 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "81\n",
"output": "\n9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "81\n",... |
code_contests | verifiable_code | 15_B. Laser | Solve the following coding problem using the programming language python:
Petya is the most responsible worker in the Research Institute. So he was asked to make a very important experiment: to melt the chocolate bar with a new laser device. The device consists of a rectangular field of n × m cells and a robotic arm. ... | ```python
n = int(input())
for i in range(n):
n, m, x1, y1, x2, y2 = map(int, input().split())
#print(n, m, x1, y1, x2, y2)
if x1 <= x2 and y1 <= y2:
pass
elif x1 >= x2 and y1 >= y2:
x1, y1, x2, y2 = x2, y2, x1, y1
else:
x1, y1, x2, y2 = x2, y1, x1, y2
if x1 <= x2 ... | vfc_52233 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 4 1 1 3 3\n4 3 1 1 2 2\n",
"output": "8\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3 3 3 2 1 1\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 178_F2. Representative Sampling | Solve the following coding problem using the programming language python:
The Smart Beaver from ABBYY has a long history of cooperating with the "Institute of Cytology and Genetics". Recently, the Institute staff challenged the Beaver with a new problem. The problem is as follows.
There is a collection of n proteins ... | vfc_52237 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\naba\nbzd\nabq\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\naaa\nabba\nabbc\nabbd\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"f... | |
code_contests | verifiable_code | 201_E. Thoroughly Bureaucratic Organization | Solve the following coding problem using the programming language python:
Once n people simultaneously signed in to the reception at the recently opened, but already thoroughly bureaucratic organization (abbreviated TBO). As the organization is thoroughly bureaucratic, it can accept and cater for exactly one person pe... | ```python
def go(m, k):
rem, ans, binom = m*k, 0, 1
ones = 0
while ones <= k:
take = min(1 if ones == 0 else rem//ones, binom)
if take == 0:
break
ans += take
rem -= ones * take
binom = binom*(k-ones)//(ones+1)
ones += 1
return ans
def solve():
n, m = map(int, input().split())
ans = 1;
while go(... | vfc_52241 | {
"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\n4 1\n4 2\n7 3\n1 1\n42 7\n",
"output": "3\n2\n3\n0\n11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12\n11 4\n9 2\n10000 100\n1000000000 2345\n123456 1234567\n123456 65536\n5 55\n5 3... |
code_contests | verifiable_code | 226_D. The table | Solve the following coding problem using the programming language python:
Harry Potter has a difficult homework. Given a rectangular table, consisting of n × m cells. Each cell of the table contains the integer. Harry knows how to use two spells: the first spell change the sign of the integers in the selected row, the... | ```python
import math
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
a = [[] for _ in range(n)]
for i in range(n):
a[i] = [int(_) for _ in input().split()]
row = []
col = []
rowStat = [1] * n
colStat = [1] * m
while True:
bad = False
for i in range(n):
total = 0
for j... | vfc_52245 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 4\n-1 -1 -1 2\n1 1 1 1\n",
"output": "1 1 \n1 4 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 1\n-1\n-1\n-1\n-1\n",
"output": "4 1 2 3 4 \n0 \n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 250_B. Restoring IPv6 | Solve the following coding problem using the programming language python:
An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the c... | ```python
for i in range(int(input())):
t = input().split(':')
if t[-1] == '': t.pop()
elif t[0] == '': t.pop(0)
if '' in t: t[t.index('')] = ('0000:' * (9 - len(t)))[: -1]
print(':'.join('0' * (4 - len(i)) + i for i in t))
``` | vfc_52249 | {
"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\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0\n",
"output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:012... |
code_contests | verifiable_code | 275_C. k-Multiple Free Set | Solve the following coding problem using the programming language python:
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n dis... | ```python
def solve():
n,k=map(int,input().split())
a=sorted([int(i) for i in input().split()])
b=set(a)
if k!=1:
for i in a:
if i in b:
b.discard(i*k)
print(len(b))
solve()
``` | vfc_52253 | {
"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": "6 2\n2 3 6 5 4 10\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n500000000 1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_... |
code_contests | verifiable_code | 298_E. Splitting the Uniqueness | Solve the following coding problem using the programming language python:
Polar bears like unique arrays — that is, arrays without repeated elements.
You have got a unique array s with length n containing non-negative integers. Since you are good friends with Alice and Bob, you decide to split the array in two. Preci... | ```python
n=int(raw_input())
s=[int(x) for x in raw_input().split()]
o=[i for i in range(n)]
o=sorted(o,key=lambda x: s[x])
a=[i for i in range(n)]
b=[i for i in range(n)]
k=n/3
for i in range(k):
j=o[i]
a[j],b[j]=i,s[j]-i
for i in range((2*n)/3-n/3):
j=o[k+i]
a[j],b[j]=s[j]-k-i,k+i
for i in range(n-(2*... | vfc_52257 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n12 5 8 3 11 9\n",
"output": "YES\n12 1 6 0 10 6\n0 4 2 3 1 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "101\n38 47 46 44 77 39 62 29 24 21 9 64 98 56 86 79 30 71 12 20 50 70 22 5 1... |
code_contests | verifiable_code | 346_A. Alice and Bob | Solve the following coding problem using the programming language python:
It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each move, e... | ```python
from sys import stdin,stdout
from math import gcd
nmbr = lambda: int(stdin.readline())
lst = lambda: list(map(int,stdin.readline().split()))
for _ in range(1):#nmbr()):
n=nmbr()
a=lst()
g=a[0]
for v in a[1:]:
g=gcd(g,v)
mx=max(a)
terms=abs(n-mx//g)
print('Alice' if terms&1 ... | vfc_52265 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 3\n",
"output": "Alice\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n5 6 7\n",
"output": "Bob\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | 369_E. Valera and Queries | Solve the following coding problem using the programming language python:
Valera loves segments. He has recently come up with one interesting problem.
The Ox axis of coordinates has n segments, the i-th segment starts in position li and ends in position ri (we will mark it as [li, ri]). Your task is to process m quer... | vfc_52269 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n1 3\n4 5\n6 7\n3 1 4 7\n2 4 5\n1 8\n",
"output": "3\n1\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5\n643450 686584\n30981 862245\n68908 575075\n558374 713102\n480946 865118\... | |
code_contests | verifiable_code | 391_D1. Supercollider | Solve the following coding problem using the programming language python:
This problem consists of two subproblems: for solving subproblem D1 you will receive 3 points, and for solving subproblem D2 you will receive 16 points.
Manao is the chief architect involved in planning a new supercollider. He has to identify a... | vfc_52273 | {
"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": "1 2\n4 0 9\n1 1 8\n1 2 7\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n0 0 1\n1 0 1\n0 2 1\n0 0 1\n-1 -1 1\n",
"output": "0\n",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | 413_E. Maze 2D | Solve the following coding problem using the programming language python:
The last product of the R2 company in the 2D games' field is a new revolutionary algorithm of searching for the shortest path in a 2 × n maze.
Imagine a maze that looks like a 2 × n rectangle, divided into unit squares. Each unit square is eith... | ```python
from sys import stdin, stdout
from bisect import bisect_left
def main():
RL = lambda: stdin.readline()
read_ints = lambda: map(int, RL().split())
n, m = read_ints()
s = RL().strip()
t = RL().strip()
ma = [0] * n
sps = []
for i in xrange(n):
if s[i] == 'X':
m... | vfc_52277 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 3\nX...X..X..\n..X...X..X\n11 7\n7 18\n18 10\n",
"output": "9\n-1\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 7\n.X..\n...X\n5 1\n1 3\n7 7\n1 4\n6 1\n4 7\n5 7\n",
"output... |
code_contests | verifiable_code | 440_B. Balancer | Solve the following coding problem using the programming language python:
Petya has k matches, placed in n matchboxes lying in a line from left to right. We know that k is divisible by n. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in ... | ```python
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write i... | vfc_52281 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n1 6 2 5 3 7\n",
"output": "12\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 486_C. Palindrome Transformation | Solve the following coding problem using the programming language python:
Nam is playing with a string on his computer. The string consists of n lowercase English letters. It is meaningless, so Nam decided to make the string more beautiful, that is to make it be a palindrome by using 4 arrow keys: left, right, up, dow... | ```python
import sys
input=sys.stdin.readline
n,p=map(int,input().split())
s=input().rstrip()
if p>=n//2:
s=s[::-1]
p=n+1-p
p-=1
ans1=0;ans2=0
l=10**6;r=-1
for i in range(n//2):
if s[i]!=s[n-1-i]:
l=min(l,i)
r=max(r,i)
use=set()
if l<=p<=r:
if r!=-1:
for i in range(p,r+1):
if s[i]!=s[n-1-i] an... | vfc_52289 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 3\naeabcaez\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 534_D. Handshakes | Solve the following coding problem using the programming language python:
On February, 30th n students came in the Center for Training Olympiad Programmers (CTOP) of the Berland State University. They came one by one, one after another. Each of them went in, and before sitting down at his desk, greeted with those who ... | ```python
def read_int():
return int(input().strip())
def read_ints():
return list(map(int, input().strip().split(' ')))
def solve():
"""
4 2 1 3 5
0 2 3 4 1 1 0 2 2
x x x x x x x x x
1 5 8 3 4 2 7 6 9
10
0 3 4 2
0 1 2 3 4 5
"""
N = read_int()
shakes = [[] for _ in rang... | vfc_52297 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9\n0 2 3 4 1 1 0 2 2\n",
"output": "Possible\n7 6 9 3 4 8 1 5 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n2 1 3 0 1\n",
"output": "Possible\n4 5 1 3 2\n",
"type": "std... |
code_contests | verifiable_code | 559_D. Randomizer | Solve the following coding problem using the programming language python:
Gerald got tired of playing board games with the usual six-sided die, and he bought a toy called Randomizer. It functions as follows.
A Randomizer has its own coordinate plane on which a strictly convex polygon is painted, the polygon is called... | vfc_52301 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0 0\n2 0\n2 2\n0 2\n",
"output": "0.200000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 0\n2 0\n2 2\n1 3\n0 2\n",
"output": "0.812500000000\n",
"type": "stdin_... | |
code_contests | verifiable_code | 585_B. Phillip and Trains | Solve the following coding problem using the programming language python:
The mobile application store has a new game called "Subway Roller".
The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a rectangular field consisting of three rows and n c... | ```python
# import sys
# sys.stdin = open('cf586d.in')
def handle_test():
n, k = [int(v) for v in input().split()]
field = [input() for _ in range(3)]
if field[0][0] == 's':
cpos = [0, 0]
elif field[1][0] == 's':
cpos = [1, 0]
else:
cpos = [2, 0]
available = [[False] * len(field[0]) for _... | vfc_52305 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n10 4\ns.ZZ......\n.....AAABB\n.YYYYYY...\n10 4\ns.ZZ......\n....AAAABB\n.YYYYYY...\n",
"output": "YES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n16 4\n...AAAAA........\ns.BB... |
code_contests | verifiable_code | 607_B. Zuma | Solve the following coding problem using the programming language python:
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible.
In one second, Genos is ab... | ```python
dp=[]
def calculate(i,j,colors):
if i>j: return 0
if dp[i][j]==-1:
if i==j:
return 1
dp[i][j] = 10000
dp[i][j] = min(dp[i][j],1+calculate(i+1,j,colors))
# print(i,j)
if colors[i]==colors[i+1]:
dp[i][j] = min(dp[i][j],1+calculate(i+2,j,co... | vfc_52309 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2 1\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 629_A. Far Relative’s Birthday Cake | Solve the following coding problem using the programming language python:
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or ... | ```python
def fac(n):
S=1
for i in range(1,n+1):
S=S*i
return(S)
def comb(n,p):
return int((fac(n)/(fac(p)*fac(n-p))))
n=int(input())
d=[]
somme=0
for i in range(n):
ch=input()
d.append(ch)
S=0
for j in range(len(ch)):
if ch[j]=="C":
S=S+1
somme=somme+comb... | vfc_52313 | {
"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\nCC..\nC..C\n.CC.\n.CC.\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n.CC\nC..\nC.C\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_n... |
code_contests | verifiable_code | 653_B. Bear and Compressing | Solve the following coding problem using the programming language python:
Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'.
You are ... | ```python
# You lost the game.
n, q = map(int, input().split())
L = [list(str(input()).split(" ")) for _ in range(q)]
A = [[] for _ in range(6)]
B = "abcdef"
for i in range(q):
e = B.index(L[i][1])
A[e] = A[e] + [L[i][0]]
R = [1,0,0,0,0,0]
for i in range(1,n):
K = [0,0,0,0,0,0]
for j in range(6):
... | vfc_52317 | {
"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 2\nbb a\nba a\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 8\naf e\ndc d\ncc f\nbc b\nda b\neb a\nbb b\nff c\n",
"output": "1\n",
"type": "stdin_stdout"... |
code_contests | verifiable_code | 678_F. Lena and Queries | Solve the following coding problem using the programming language python:
Lena is a programmer. She got a task to solve at work.
There is an empty set of pairs of integers and n queries to process. Each query is one of three types:
1. Add a pair (a, b) to the set.
2. Remove a pair added in the query number i. A... | vfc_52321 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n3 1\n1 2 3\n3 1\n1 -1 100\n3 1\n2 4\n3 1\n",
"output": "EMPTY SET\n 5\n 99\n ... | |
code_contests | verifiable_code | 701_A. Cards | Solve the following coding problem using the programming language python:
There are n cards (n is even) in the deck. Each card has a positive integer written on it. n / 2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.
Find the way to... | ```python
n = int(input())
s = list(map(int, input().split()))
dif = 2 * sum(s) // n
t = []
for i in range(n):
for j in range(n):
if s[i] + s[j] == dif and i not in t and j not in t and i != j:
print(i + 1, j + 1)
t.append(i)
t.append(j)
``` | vfc_52325 | {
"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 10 10\n",
"output": "1 2\n3 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1 5 7 4 4 3\n",
"output": "1 3\n6 2\n4 5\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 723_B. Text Document Analysis | Solve the following coding problem using the programming language python:
Modern text editors usually show some information regarding the document being edited. For example, the number of words, the number of pages, or the number of characters.
In this problem you should implement the similar functionality.
You are ... | ```python
length = int(input())
string = input()
outer = ""
inner = ""
i = 0
while i < length:
if string[i] == '(':
i += 1
inner += " "
while string[i] != ')':
if string[i] != '_' and string[i] != '&':
inner += string[i]
else:
inner +=... | vfc_52329 | {
"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": "37\n_Hello_Vasya(and_Petya)__bye_(and_OK)\n",
"output": "5 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "27\n(LoooonG)__shOrt__(LoooonG)\n",
"output": "5 2\n",
"type": "std... |
code_contests | verifiable_code | 745_A. Hongcow Learns the Cyclic Shift | Solve the following coding problem using the programming language python:
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to make new words from this one. He starts by ... | ```python
from collections import Counter
s = input()
counter = Counter()
for i in range(len(s)):
counter[s[i:len(s)] + s[0:i]] = 1
print(sum(counter.values()))
``` | vfc_52333 | {
"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": "abcd\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "bbb\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "yzyz\n... |
code_contests | verifiable_code | 768_C. Jon Snow and his Favourite Number | Solve the following coding problem using the programming language python:
Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength.... | ```python
n,k,x=map(int,input().split())
r=list(map(int,input().split()))
k%=64
while k:
k-=1
r.sort()
for i in range(0,n,2):#alternate
r[i]^=x
print(max(r),min(r))
``` | vfc_52337 | {
"difficulty": "9",
"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 100000 569\n605 986\n",
"output": "986 605\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1 2\n9 7 11 15 5\n",
"output": "13 7\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 792_B. Counting-out Rhyme | Solve the following coding problem using the programming language python:
n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out... | ```python
n,y=input().split()
n=int(n)
y=int(y)
liste=list(range(1,n+1))
x=0
z=0
liste2=list(map(int,input().split()))
while x<y:
z=((z+liste2[x])%len(liste))
print(liste[z])
liste.pop(z)
x+=1
``` | vfc_52341 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n2 5\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 5\n10 4 11 4 1\n",
"output": "4 2 5 6 1\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | 838_D. Airplane Arrangements | Solve the following coding problem using the programming language python:
There is an airplane which has n rows from front to back. There will be m people boarding this airplane.
This airplane has an entrance at the very front and very back of the plane.
Each person has some assigned seat. It is possible for multipl... | ```python
MOD = 10 ** 9 + 7
n, m = input().split(' ')
n = int(n)
m = int(m)
ans = pow(2 * (n + 1), m, MOD)
ans = (ans * (n + 1 - m)) % MOD
ans = (ans * pow(n + 1, MOD - 2, MOD)) % MOD
print(ans)
``` | vfc_52349 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n",
"output": "128\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 883_M. Quadcopter Competition | Solve the following coding problem using the programming language python:
Polycarp takes part in a quadcopter competition. According to the rules a flying robot should:
* start the race from some point of a field,
* go around the flag,
* close cycle returning back to the starting point.
Polycarp knows the... | ```python
x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
if x1 != x2 and y1 != y2:
ans = abs(x1 - x2) + abs(y1 - y2) + 2
print(ans * 2)
else:
ans = abs(x1 - x2) + abs(y1 - y2) + 3
print(ans * 2)
``` | vfc_52357 | {
"difficulty": "20",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0 1\n0 0\n",
"output": "8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 5\n5 2\n",
"output": "18",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "... |
code_contests | verifiable_code | 908_B. New Year and Buggy Bot | Solve the following coding problem using the programming language python:
Bob programmed a robot to navigate through a 2d maze.
The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'.
There is a single robot in the maze. Its start position is denoted with the ch... | ```python
res = 0
n, m = map(int, input().split())
a = ['#' * (m + 2)] + ['#' + input() + '#' for i in range(n)] + ['#' * (m + 2)]
s = input()
start = []
fin = []
for i in range(n + 2):
for j in range(m + 2):
if a[i][j] == 'S':
start = [i, j]
if a[i][j] == 'E':
fin = [i, j]
... | vfc_52361 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6\n.....#\nS....#\n.#....\n.#....\n...E..\n333300012\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 6\n......\n......\n..SE..\n......\n......\n......\n012321232123021... |
code_contests | verifiable_code | 92_A. Chips | Solve the following coding problem using the programming language python:
There are n walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to... | ```python
n, m = [int(x) for x in input().split()]
m %= int(n*(n+1)/2)
for i in range(1,n):
if m<i: break
m -= i
print(m)
``` | vfc_52365 | {
"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 11\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "17 107\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 8\n",... |
code_contests | verifiable_code | 958_A2. Death Stars (medium) | Solve the following coding problem using the programming language python:
The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last ti... | ```python
n, m = [int(x) for x in input().split()]
list1 = []
list2 = []
for i in range(n):
list1.append(input())
for j in range(m):
list2.append(input())
list3 = []
for i in range(n - m + 1):
y = ""
for j in range(m):
y += list1[j + i]
list3.append(y)
list4 = []
for i in range(n - m + 1)... | vfc_52369 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 5\nsomer\nandom\nnoise\nmayth\neforc\nebewi\nthyou\nhctwo\nagain\nnoise\nsomermayth\nandomeforc\nnoiseebewi\nagainthyou\nnoisehctwo\n",
"output": "4 6",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 983_A. Finite or not? | Solve the following coding problem using the programming language python:
You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction.
A fraction in notation with base b is finite if it contains finite numbe... | ```python
import sys
import math
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
def solve():
p, q, b = inl()
if p == 0:
return True
g = math.gcd(p, q)
p //= g
q //= g
if q == 1:
return True
return pow(b, 64, q) == 0
n... | vfc_52373 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n6 12 10\n4 3 10\n",
"output": "Finite\nInfinite\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 1 2\n9 36 2\n4 12 3\n3 5 4\n",
"output": "Finite\nFinite\nFinite\nInfinite\n",... |
code_contests | verifiable_code | birthday-party-6 | Solve the following coding problem using the programming language python:
Today is Sid’s birthday and he is very excited about this as he is giving a special birthday party to all his friends. In this party they are going to play a game for which Sid have to arrange all his friends in a row such that no two boys shoul... | ```python
factorial=[]
factorial.append(1)
for i in range(1,52):
factorial.append(i*factorial[i-1]%1000000007)
test=input()
i=0
while(i<test):
hash=map(int,raw_input().split())
girls=hash[0]
boys=hash[1]
i=i+1
if(boys-girls<=1):
print (factorial[girls+1]*pow(factorial[boys]*factorial[girls-... | vfc_52381 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3 2\n\nSAMPLE",
"output": "72\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | crazy-matrix | Solve the following coding problem using the programming language python:
Praveen went crazy yesterday and created an arbitrary matrix consisting of 0, 1 or 2. There was no rule observed in forming this matrix. But then he made up some rules himself.
If there are adjacent 1's, they are said to be connected. Similarly... | ```python
from collections import defaultdict, deque
def solve():
ans1 = True
ans2 = True
N = input()
if N == 93:
print 0
return
arr = []
for i in xrange(N):
elem = map(int, raw_input().strip().split())
ans1 = ans1 and 1 in elem
arr.append(elem)
for i in xrange(N):
Found = False
for j in xrange... | vfc_52385 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "89\n2 1 1 1 1 1 2 1 2 2 1 2 2 2 2 1 2 2 2 2 2 1 1 1 1 2 2 2 1 1 1 2 1 1 1 1 1 1 1 2 1 1 2 2 2 1 2 1 2 1 2 1 1 2 2 1 1 1 2 2 1 1 2 2 2 2 2 1 1 1 1 1 2 2 1 1 1 1 2 1 1 2 1 1 2 1 1 1 1\n1 2 1 1 1 2 2 1 1 2 2 2 1 1 2 2 1 1 1 2 2 1 1 2 ... |
code_contests | verifiable_code | flip-the-coins | Solve the following coding problem using the programming language python:
Ramesh and Suresh's previous attempt to decide who is smarter of them turned out to be indecisive. There was a tie in that too. Turns out they are more similar than they thought, which frustrates them even more. They are now very desperate to fi... | ```python
def flip(coins, a, b):
for i in range(a, b+1):
if coins[i] == 't':
coins[i] = 'h'
else:
coins[i] = 't'
def heads(coins, a, b):
count = 0
for i in range(a, b+1):
if coins[i] == 'h':
count += 1
return count
n = input()
coins = 't'
coins *= n
coins = list(coins)
q = input()
for i in range... | vfc_52389 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n3\n0 3 5\n1 0 6\n1 3 4\n\nSAMPLE",
"output": "3\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n3\n0\n3\n5\n1\n0\n6\n1\n3\n4",
"output": "3\n2\n",
"type": "stdin_stdout"... |
code_contests | verifiable_code | jamun-is-confused | Solve the following coding problem using the programming language python:
Well Jamun is very proud of the way he knows everything ( or at least thinks so ).He doesn't even realize when he is fooled of by his colleagues and friends.
Now jamun's colleagues are total geek's and always come up with some sort of computatio... | ```python
def gcd(a,b):
if b == 0:
return a
else:
return gcd(b,a%b)
test = int(raw_input())
while test:
test-=1
n = int(raw_input())
arr = [int(i) for i in raw_input().split()]
gc = 0
for i in range(n):
gc = gcd(gc, arr[i])
print gc
``` | vfc_52393 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n5 15 10\n3 \n3 1 2\n\nSAMPLE",
"output": "5\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n3\n105 64 9 \n10\n272 20 28 63 65 44 49 92 94 80 \n10\n485 0 0 55 22 0 20 54 1 5 \n... |
code_contests | verifiable_code | p1-15 | Solve the following coding problem using the programming language python:
Here is your task. You are given two strings and you have to merge/compress them in single string with minimum length such that both strings can be found (one at a time) by breaking that merged string into two parts.
NOTE:
String s2 should follo... | ```python
from sys import stdin
t = int(stdin.readline())
def com(a,b):
l1 = len(a)
l2 = len(b)
l = l1
if l2<l:
l = l2
while l>=1:
#print "comparing ",a[-l:],b[:l]
if a[-l:] == b[:l]:
return l
l-=1
return 0
for tt in xrange(t):
a = stdin.readline().strip();
b = stdin.readline().strip()
fir = com(a,... | vfc_52401 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nroadshow\nshowman\ntarun\ntarunnum\n\nSAMPLE",
"output": "roadshowman\ntarunnum\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\nroadshow\nhsowman\ntarun\ntarunnum\n\nSAMPLE",
"... |
code_contests | verifiable_code | remains | Solve the following coding problem using the programming language python:
You've recently stumbled upon the remains of a ruined ancient city. Luckily, you've studied enough ancient architecture to know how the buildings were laid out.
The city had n buildings in a row. Unfortunately, all but the first two buildings h... | ```python
def sumAP (a, d, n):
return n * (2*a + (n-1) * d) / 2
def sumHeights(x, y, n):
#print "sumHeights: ", x, ":", y, ":", n
if n == 0:
return 0
if y == 0:
if n%3 == 0:
return (2 * n/3) * x
elif n%3 == 1:
return (1 + 2 * (n-1)/3) * x
else:
return (2 + 2 * (n-2)/3) * x
if x < y:
return (y-x... | vfc_52405 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n10 7 5\n50 100 50\n1000000000 999999999 1000000000\n\nSAMPLE",
"output": "25\n1750\n444444445222222222",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | solvemefirst | Solve the following coding problem using the programming language python:
Let's Start Simple Write a programe to Sum of two Decimal Value.
SAMPLE INPUT
12.25
3.60
SAMPLE OUTPUT
15.85
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 c... | ```python
a=float(input())
b=float(input())
c=a+b
print "%.2f" % c
``` | vfc_52409 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "12.25\n3.60\n\nSAMPLE",
"output": "15.85\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12.25\n3.60\n\nSAMPLD",
"output": "15.85\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | to-be-changed-compile-time-fun | Solve the following coding problem using the programming language python:
Interns Mehta and Sharma are waiting for their "build" to complete. Mehta comes up with an interesting game with an array P of integers of size N. She defines the rules of the game as:
Pick a number i from the set {1,2,...N-2}.
Remove P[i] from ... | ```python
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 3 22:21:47 2015
@author: ishank011
"""
def ans(l):
if len(l)==2:
return 0
if len(l)==3:
return l[0]*l[2]
a=0
for i in range(1, len(l)-1):
m=l[i-1]*l[i+1]
p=l[:]
#print(i)
del p[i]
k=ans(p)... | vfc_52413 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 3 4 5\n\nSAMPLE",
"output": "25\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n477 744 474 777 447 747 777 474",
"output": "2937051\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | p00250 Scone | Solve the following coding problem using the programming language python:
Aika's house runs a small coffee shop. The scones baked by Aika's mother were very delicious and the shop was very prosperous.
One of the jobs of Aika, a waitress, is to deliver the scones that are baked one after another to the customer's seat... | ```python
# AOJ 0254: Scone
# Python3 2018.6.25 bal4u
s = [0 for i in range(30001)]
while True:
n, m = map(int, input().split())
if n == 0: break
f = [-1 for i in range(m)]
sum, nmax, ans = 0, 0, 0
a = list(map(int, input().split()))
for i in range(n):
sum += a[i]
a[i] %= m
if a[i] > nmax: nmax = a[i]
if... | vfc_52465 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 11\n11 27 34 45 56\n8 5\n0 2 1 5 4 6 8 3\n5 2\n2 4 2 4 6\n10 18\n10 15 12 31 12 50 11 23 43 181\n1 100\n5\n0 0",
"output": "8\n4\n0\n17\n5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5... |
code_contests | verifiable_code | p00627 Kyudo: A Japanese Art of Archery | Solve the following coding problem using the programming language python:
Ito joined the Kyudo club after entering high school. At first, I had a hard time because the arrow didn't reach the target, but in the fall of my first year of high school, I managed to improve to the point where the arrow reached the target.
... | ```python
# AOJ 1041: Kyudo: A Japanese Art of Archery
# Python3 2018.7.6 bal4u
while True:
n = int(input())
if n == 0: break
print(sum([int(input()) for i in range(n>>2)]))
``` | vfc_52473 | {
"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": "20\n4\n3\n2\n1\n3\n8\n2\n0\n0",
"output": "13\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20\n4\n6\n2\n1\n3\n8\n2\n0\n0",
"output": "16\n2\n",
"type": "stdin_stdout"
}... |
code_contests | verifiable_code | p00771 Anchored Balloon | Solve the following coding problem using the programming language python:
Anchored Balloon
A balloon placed on the ground is connected to one or more anchors on the ground with ropes. Each rope is long enough to connect the balloon and the anchor. No two ropes cross each other. Figure E-1 shows such a situation.
<im... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in ... | vfc_52477 | {
"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\n10 10 20\n10 -10 20\n-10 10 120\n1\n10 10 16\n2\n10 10 20\n10 -10 20\n2\n100 0 101\n-90 0 91\n2\n0 0 53\n30 40 102\n3\n10 10 20\n10 -10 20\n-10 -10 20\n3\n1 5 13\n5 -3 13\n-3 -3 13\n3\n98 97 168\n-82 -80 193\n-99 -96 211\n4\n90 ... |
code_contests | verifiable_code | p00902 Encircling Circles | Solve the following coding problem using the programming language python:
You are given a set of circles C of a variety of radii (radiuses) placed at a variety of positions, possibly overlapping one another. Given a circle with radius r, that circle may be placed so that it encircles all of the circles in the set C if... | vfc_52481 | {
"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": "1 10\n5 5 7\n2 12\n5 5 7\n8 6 3\n3 10\n3 11 2\n2 1 1\n2 16 3\n3 15\n-5 2 5\n9 2 9\n5 8 6\n3 38\n-25 -10 8\n30 5 7\n-3 35 11\n3 39\n-25 -10 8\n30 5 7\n-3 35 11\n3 800\n-400 400 2\n300 300 1\n300 302 1\n3 800\n400 -400 2\n300 300 1\n... | |
code_contests | verifiable_code | p01169 Turn Polygons | Solve the following coding problem using the programming language python:
HCII, the health committee for interstellar intelligence, aims to take care of the health of every interstellar intelligence.
Staff of HCII uses a special equipment for health checks of patients. This equipment looks like a polygon-shaped room ... | vfc_52489 | {
"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 4\n0 0 20 0 20 10 0 10 1 5\n10 3 12 5 10 7 8 5\n10 5\n4 3\n0 0 10 0 10 5 0 5\n3 1 6 1 5 4\n0 0\n5 3\n0 0 10 0 10 10 0 10 3 5\n1 1 4 1 4 6\n0 0\n0 0",
"output": "360.0000000\n12.6803835\n3.3722867",
"type": "stdin_stdo... | |
code_contests | verifiable_code | p01305 Card Game | Solve the following coding problem using the programming language python:
Gates and Jackie, the cats, came up with the rules for a card game played by two people. The rules are as follows.
First, shuffle the cards with the numbers 1 to 18 and deal 9 to each player. Both players issue one card at the same time and get... | vfc_52493 | {
"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": "2\n1 3 5 7 9 11 13 15 17\n2 4 6 8 10 12 14 16 18\n1 5 7 9 11 13 15 17 18\n2 3 4 6 8 10 12 14 16",
"output": "0.30891 0.69109\n0.92747 0.07253",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "... | |
code_contests | verifiable_code | p01474 Permutation | Solve the following coding problem using the programming language python:
Problem statement
Find the number of integer sequences $ X_1, X_2, ..., X_N $ that satisfy the following conditions.
1. For any integer $ i $ ($ 1 \ leq i \ leq N $), there exists $ j $ ($ 1 \ leq j \ leq N $) such that $ X_j = i $.
2. $ X_s ... | vfc_52497 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1 1 1\n1 3",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2 1 1\n2 3\n3 2",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"i... | |
code_contests | verifiable_code | p01634 Register Phase | Solve the following coding problem using the programming language python:
It is important to use strong passwords to make the Internet more secure. At the same time, it is very important not to reuse the same password. No matter how strong your password is, if the plaintext is leaked in one place, it will be very easy... | ```python
A=0
n=str(input())
if len(n)>=6:
A=A+1
B=n.count('0')+n.count('1')+n.count('2')+n.count('3')+n.count('4')+n.count('5')+n.count('6')+n.count('7')+n.count('8')+n.count('9')
if B>0:
A=A+1
C=n.count('a')+n.count('b')+n.count('c')+n.count('d')+n.count('e')+n.count('f')+n.count('g')+n.count('h')+n.count('i'... | vfc_52501 | {
"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": "password",
"output": "INVALID",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "passxord",
"output": "INVALID\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | p01786 Proportional Representation | Solve the following coding problem using the programming language python:
Example
Input
10 2
2
1
Output
5 7
3 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. | vfc_52505 | {
"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": "10 2\n2\n1",
"output": "5 7\n3 5",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p02059 Revenge of UMG | Solve the following coding problem using the programming language python:
H: Revenge of UMG
problem
For the character string T consisting of three types of characters,'U',' M', and'G', the 1, 2, ..., | T | characters are T_1, T_2, ..., T_ {|, respectively. When we decide to express T |}, we call the number of pairs ... | vfc_52513 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "?MG?",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "?NG?",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "?OG?",
... | |
code_contests | verifiable_code | cbarg | Solve the following coding problem using the programming language python:
Recently Chef has decided to make some changes in our beloved Codechef. As you know, each problem at Codechef has its memory and time limits. To make problems even more challenging, he decided to measure allocated memory in a different way. Now ... | ```python
t = int(raw_input())
while t:
t -= 1
raw_input()
arr = [0] + map(int, raw_input().split(' '))
o = 0
for i in range(1, len(arr)):
o += max(0, arr[i] - arr[i-1])
print o
``` | vfc_52525 | {
"difficulty": "2",
"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\n5\n1 2 3 4 5\n3\n1 3 2",
"output": "1\n5\n3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | csea2 | Solve the following coding problem using the programming language python:
For the purposes of this problem, we will assume that every page in an book is numbered sequentially, and that the first page is numbered 1.
How many digits would you need to use to number the pages of a 10 page book? Pages 1 to 9 would require... | ```python
R = [0,9,189,2889,38889,488889,5888889,68888889,788888889]
def process(N):
for i in xrange(8,-1,-1):
if N > R[i]:
N -= R[i]
if N % (i+1): return 'Impossible!'
else: return N / (i+1) + 10**i - 1
def main():
while True:
N = raw_input()
... | vfc_52529 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "11 \n13 \n59 \n60 \n1999999998 \n#",
"output": "10 \n11 \n34 \nImpossible! \n234567900",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | hclean | Solve the following coding problem using the programming language python:
Jane lives in N-dimensional space. Her house is a N-dimensional hypercube, with the centre located in the origin, with each edge having length equal to 2. There is a room in every vertex of the hypercube. The room can be denoted with N it's coo... | ```python
def get_opposite(point, dimention):
opposite_vertex = [i for i in point]
opposite_vertex[dimention] = -point[dimention]
return opposite_vertex
def print_vertex(start_point, dimention):
if dimention == 0:
opposite_vertex = get_opposite(start_point, dimention)
print ' '.join([str(i) for i in start_po... | vfc_52533 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 5\n-1 -1\n4 3\n1 -1 1 -1",
"output": "-1 -1\n1 -1\n1 1\n-1 1\n-2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | mike2 | Solve the following coding problem using the programming language python:
Mike takes part in olympiads in informatics. You think he is a rookie? Wrong! He is an experienced and well-prepared competitor! He participated in many important contests and won some of them. Now his level is rather high.
In order to keep fi... | ```python
def opt(par,data):
fail,total=par
success=0
data=sorted(data)
for a in data:
if(a%2==0):
half=a/2
if(total-half<0):
break
else:
total-=half
fail-=1
else:
half=a/2+1
if(to... | vfc_52537 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 10\n3 4 5",
"output": "0 2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 11\n3 4 5",
"output": "0 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | recrep | Solve the following coding problem using the programming language python:
Problem description
The mess authority of Hall 1, NIT Durgapur has decided to select a student representative. A special game is organized to select one from all the students. Everyone is sitting in the common room of Hall 1. The order in which ... | ```python
for _ in range(input()):
n=input()
a=[]
while n:
n-=1
s=raw_input()
a.append(s)
#print a[0]
s=raw_input()
#print s
flag=0
for i in range(len(a)):
#print str(a[i])
if s==str(a[i]):
flag=1
break
if flag:
print 'yes'
else:
print 'no'
``` | vfc_52541 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2\npitch\nyorker\nvirat",
"output": "no",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2\npitch\nyorker\ntariv",
"output": "no\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | triangcl | Solve the following coding problem using the programming language python:
Triangle classification is an important problem in modern mathematics. Mathematicians have developed many criteria according to which a triangle can be classified. In this problem, you will be asked to classify some triangles according to their ... | ```python
from math import sqrt, fabs
subid = input()
T = input()
compare = float(10**-6)
for hell in range(T):
x1,y1,x2,y2,x3,y3 = map(float, raw_input().split())
tside1 = sqrt( (x1 - x2)**2 + (y1 - y2)**2 )
tside2 = sqrt( (x2 - x3)**2 + (y2 - y3)**2 )
tside3 = sqrt( (x3 - x1)**2 + (y3 - y1)**2 )
... | vfc_52545 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n6\n0 0 4 1 1 3\n0 0 1 0 1 2\n0 0 1 1 1 2\n0 0 2 1 1 2\n3 0 0 4 4 7\n0 0 2 1 4 0",
"output": "Scalene acute triangle\nScalene right triangle\nScalene obtuse triangle\nIsosceles acute triangle\nIsosceles right triangle\nIsos... |
code_contests | verifiable_code | 1016_F. Road Projects | Solve the following coding problem using the programming language python:
There are n cities in the country of Berland. Some of them are connected by bidirectional roads in such a way that there exists exactly one path, which visits each road no more than once, between every pair of cities. Each road has its own lengt... | vfc_52549 | {
"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": "7 2\n1 2 18\n2 3 22\n3 4 24\n4 7 24\n2 6 4\n3 5 12\n1\n100\n",
"output": "83\n88\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 1\n1 2 2\n2 3 2\n3 4 2\n1\n",
"output": "3\n",
... | |
code_contests | verifiable_code | 1040_A. Palindrome Dance | Solve the following coding problem using the programming language python:
A group of n dancers rehearses a performance for the closing ceremony. The dancers are arranged in a row, they've studied their dancing moves and can't change positions. For some of them, a white dancing suit is already bought, for some of them ... | ```python
def go():
n, a, b = [int(i) for i in input().split(' ')]
x = [int(i) for i in input().split(' ')]
total = 0
for i in range(n // 2):
if (x[i] == 1 and x[n - 1 - i] == 0) or (x[i] == 0 and x[n - 1 - i] == 1):
return -1
elif x[i] == 2 and x[i] == x[n - 1 - i]:
... | vfc_52553 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 12 1\n0 1 0\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1063_A. Oh Those Palindromes | Solve the following coding problem using the programming language python:
A non-empty string is called palindrome, if it reads the same from the left to the right and from the right to the left. For example, "abcba", "a", and "abba" are palindromes, while "abab" and "xy" are not.
A string is called a substring of ano... | ```python
n = int(input())
s = input()
k = {}
def choose(a, b):
if b > a:
return 0
p = 1
for i in range(b):
p *= a - i
for i in range(1, b + 1):
p //= i
return p
for i in range(n):
if s[i] in k:
k[s[i]] += 1
else:
k[s[i]] = 1
#print(k)
ans = 0
a = []... | vfc_52557 | {
"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": "5\noolol\n",
"output": "llooo",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "16\ngagadbcgghhchbdf\n",
"output": "aabbccddfgggghhh",
"type": "stdin_stdout"
},
{
"fn... |
code_contests | verifiable_code | 1084_F. Max Mex | Solve the following coding problem using the programming language python:
Once Grisha found a tree (connected graph without cycles) with a root in node 1.
But this tree was not just a tree. A permutation p of integers from 0 to n - 1 is written in nodes, a number p_i is written in node i.
As Grisha likes to invent s... | vfc_52561 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n2 5 0 3 1 4\n1 1 3 3 3\n3\n2\n1 6 3\n2\n",
"output": "3\n2\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1104_C. Grid game | Solve the following coding problem using the programming language python:
You are given a 4x4 grid. You play a game — there is a sequence of tiles, each of them is either 2x1 or 1x2. Your task is to consequently place all tiles from the given sequence in the grid. When tile is placed, each cell which is located in ful... | ```python
s = input()
f1 = 0; f2 = 0
for i in s:
if i=='1' and f1==0:
print(1,3); f1=1
elif i=='1' and f1==1:
print(1,1)
f1=0
elif i=='0' and f2==0:
print(3,1); f2=1
elif i=='0' and f2==1:
print(1,1); f2=0
``` | vfc_52565 | {
"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": "010\n",
"output": "1 1\n3 1\n1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.