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 | mininsert-palindrome | Solve the following coding problem using the programming language python:
You are given a string of characters, or numbers. Find the minimum number of characters to be inserted into the string in order to obtain a palindrome.
A palindrome is a word, phrase, number, or other sequence of symbols or elements that reads ... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
def min_insert(s):
if len(s) == 1 or len(s) == 0:
return 0
return min_insert(s[1:-1]) if s[0] == s[-1] else 1 + min(min_insert(s[:-1]), min_insert(s[1:]))
T = input()
for... | vfc_66553 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5\nnitin\n7\naabbaab\n\nSAMPLE",
"output": "0\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n20\n0ziG30WBD79ow1E0fu1X",
"output": "17\n",
"type": "stdin_stdout"
}... |
code_contests | verifiable_code | palindromes-twist | Solve the following coding problem using the programming language python:
One day Viru and Gauty after playing cricket decided to play an indoor game. In this Viru will give a string of even length to Gauty. The each character of string will be either ‘a’ ,’b’ or ‘/’. Gauty’s task is to replace each ‘/’ such that fin... | ```python
def costPalindrome():
myString = raw_input()
aCost = int(raw_input())
bCost = int(raw_input())
stringLength = len(myString)
cost = 0
for i in range(stringLength/2):
if myString[i] == 'a':
if myString[stringLength-1-i] == 'b':
return -1
elif myString[stringLength-1-i] == '/':
cost += aCos... | vfc_66557 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\naba/bab/\n4\n6\naaaabbbb\n8\n5\na/ba//abaa\n5\n9\n\nSAMPLE",
"output": "10\n-1\n15\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "17\nbbaa/a//aa/a/b/a/a/b////aab//aabbbba/a/bbbaa/bbb/b... |
code_contests | verifiable_code | riyas-birthday-party-1 | Solve the following coding problem using the programming language python:
Madhav went to Riya's Birthday Party. He was a geek so he had no idea regarding which gift she'l like.
So he took an array of integers with him. The array followed a particular order.
First element of array is 1.
Second element of array is 6.
Ot... | ```python
for _ in xrange(int(raw_input())):
n=int(raw_input())
print 1+( ( 4 * ((n*(n-1))/2))%1000000007 + (n-1)%1000000007) %1000000007
``` | vfc_66561 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1\n3\n\nSAMPLE",
"output": "1\n15\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2\n3\n\nSAMPLE",
"output": "6\n15\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | square-mode | Solve the following coding problem using the programming language python:
Your friend gives you an equation A≡X2(modM) and asks you to find an integer solution for X.
However, you know your friend's mischievous nature and suspect that there is no solution to such an equation. Thus, you first want to find out whether ... | ```python
for _ in range(input()):
a, m = map(int, raw_input().split())
if a == 0 or m == 2:
print "YES"
elif pow(a, (m - 1)/2, m) == 1:
print "YES"
else:
print "NO"
``` | vfc_66565 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 \n5 7 \n4 7\n\nSAMPLE",
"output": "NO \nYES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 \n5 7 \n3 7\n\nSAMPLE",
"output": "NO\nNO\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | tripping-on-nothingness | Solve the following coding problem using the programming language python:
Little Pandey is someone who is lazy, and when he's around his best friend GJ, he becomes super lazy. Pandey thinks that he is a Math-wizard, so he picks up a number S and asks GJ to throw him a challenge around that number.
GJ explains Littl... | ```python
def gcd(a, b):
if b == 0:
return a
return gcd(b, a%b)
s, q = map(int, raw_input().strip().split())
already_seen = set()
for _ in xrange(q):
a = input()
m = gcd(s, a)
if m in already_seen:
print -1
else:
already_seen.add(m)
print m
``` | vfc_66569 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 5\n6\n5\n8\n100\n5\n\nSAMPLE",
"output": "2\n5\n-1\n10\n-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "371 446\n1952\n9423\n8710\n57979\n535\n84946\n213\n8735\n4485\n7113\n6714\n787... |
code_contests | verifiable_code | p00133 Rotation of a Pattern | Solve the following coding problem using the programming language python:
Create a program that rotates the pattern of 8 characters x 8 lines clockwise by 90 degrees, 180 degrees, and 270 degrees and outputs it.
Input
A pattern consisting of 8 characters x 8 lines is given. Characters consist of alphanumeric chara... | ```python
# AOJ 0133 Rotation of a Pattern
# Python3 2018.6.19 bal4u
a = [[[0 for c in range(8)] for r in range(8)] for k in range(4)]
title = ["0", "90", "180", "270"]
for r in range(8):
a[0][r] = list(input())
for k in range(1, 4):
print(title[k])
for r in range(8):
for c in range(8):
a[k][c][7-r] = a[k-1][... | vfc_66617 | {
"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": "#*******\n#*******\n#*******\n#*******\n#*******\n#*******\n#*******\n########",
"output": "90\n########\n#*******\n#*******\n#*******\n#*******\n#*******\n#*******\n#*******\n180\n########\n*******#\n*******#\n*******#\n****... |
code_contests | verifiable_code | p00266 Izua Dictionary | Solve the following coding problem using the programming language python:
You have obtained the Izua Japanese dictionary, which is the official language of Izua, and the Izua alphabet (list of letters). There are N types of letters in the Izua alphabet. The order of the words that appear in the Izua Japanese dictionar... | ```python
def solve():
from sys import stdin
m = 1000000007
f_i = stdin
while True:
N = int(f_i.readline())
if N == 0:
break
w = list(range(N))
R = int(f_i.readline())
for i in range(R):
s, t = map(int, f_i.readline().split())... | vfc_66621 | {
"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\n2\n1 2\n2 3\n4\n2\n2 3\n2 4\n0",
"output": "3\n4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2\n1 2\n2 1\n4\n2\n2 3\n2 4\n0",
"output": "0\n4\n",
"type": "stdin_stdout"... |
code_contests | verifiable_code | p00453 Pyon-Pyon River Crossing | Solve the following coding problem using the programming language python:
problem
In one river, there is a slightly dangerous game of jumping from one shore to the other on a stone.
<image>
Now, as shown in Figure 4-1 we consider the stone to be above the squares. The number of rows is n. In Figure 4-1 we have n ... | ```python
from heapq import heappop, heappush
while True:
n, m = map(int, input().split())
if not n:
break
num_stones = 0
row_stones = [None] * n
edges = [None] * n
visited = [None] * n
for row in range(n):
(num, *stones) = map(int, input().split())
row_stones[row] ... | vfc_66625 | {
"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 1\n2 1 3 2 2\n1 3 2\n1 1 7\n1 2 1\n1 4 4\n5 0\n2 1 3 2 2\n1 3 2\n1 1 7\n1 2 1\n1 4 4\n0 0",
"output": "17\n40",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00644 Winter Bells | Solve the following coding problem using the programming language python:
The best night ever in the world has come! It's 8 p.m. of December 24th, yes, the night of Cristmas Eve. Santa Clause comes to a silent city with ringing bells. Overtaking north wind, from a sleigh a reindeer pulls she shoot presents to soxes ha... | ```python
from heapq import heappush, heappop
INF = 10 ** 20
while True:
n, m, p = map(int, input().split())
if n == 0:
break
edges = [[] for _ in range(n)]
for _ in range(m):
x, y, w = map(int, input().split())
edges[x].append((y, w))
edges[y].append((x, w))
que = []
heappush(que, (0, 0))
... | vfc_66629 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2 1\n0 1 2\n1 2 3\n1\n4 5 2\n0 1 1\n0 2 1\n1 2 1\n1 3 1\n2 3 1\n1\n2\n0 0 0",
"output": "1.00000000\n\n0.50000000\n0.50000000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2 1\n0 1 2\n... |
code_contests | verifiable_code | p00788 Rational Irrationals | Solve the following coding problem using the programming language python:
Rational numbers are numbers represented by ratios of two integers. For a prime number p, one of the elementary theorems in the number theory is that there is no rational number equal to √p. Such numbers are called irrational numbers. It is also... | ```python
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def stern_brocot(p, n):
la = 0; lb = 1
ra = 1; rb = 0
lu = ru = 1
lx = 0; ly = 1
rx = 1; ry = 0
while lu or ru:
ma = la + ra; mb = lb + rb
if p * mb**2 < ma**2:
ra = ma; rb = mb
i... | vfc_66633 | {
"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 5\n3 10\n5 100\n0 0",
"output": "3/2 4/3\n7/4 5/3\n85/38 38/17",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 5\n3 10\n5 110\n0 0",
"output": "3/2 4/3\n7/4 5/3\n85/38 38/17\n",
... |
code_contests | verifiable_code | p00920 Longest Chain | Solve the following coding problem using the programming language python:
Let us compare two triples a = (xa, ya, za) and b = (xb, yb, zb) by a partial order ∠ defined as follows.
a ∠ b ⇔ xa < xb and ya < yb and za < zb
Your mission is to find, in the given set of triples, the longest ascending series a1 ∠ a2 ∠ ...... | vfc_66637 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 0 1 1\n0 0 0\n0 2 2\n1 1 1\n2 0 2\n2 2 0\n2 2 2\n5 0 1 1\n0 0 0\n1 1 1\n2 2 2\n3 3 3\n4 4 4\n10 0 1 1\n3 0 0\n2 1 0\n2 0 1\n1 2 0\n1 1 1\n1 0 2\n0 3 0\n0 2 1\n0 1 2\n0 0 3\n0 10 1 1\n0 0 0 0",
"output": "3\n5\n1\n3",
... | |
code_contests | verifiable_code | p01185 Hide-and-seek | Solve the following coding problem using the programming language python:
Hide-and-seek is a children’s game. Players hide here and there, and one player called it tries to find all the other players.
Now you played it and found all the players, so it’s turn to hide from it. Since you have got tired of running around... | vfc_66645 | {
"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\n0 0 3 3\n0 4 3 1\n1 1\n0",
"output": "4.243",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n0 0 3 3\n0 5 3 1\n1 1\n0",
"output": "5.1876726427\n",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | p01490 HullMarathon | Solve the following coding problem using the programming language python:
Example
Input
4
5
8
58
85
Output
2970.000000000
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 itertools import permutations
from math import acos, sin, cos, pi
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N = int(readline())
R = [int(readline()) for i in range(N)]
R.sort(reverse=1)
ans = 0
for l in range(3, N+1):
for rs in permutation... | vfc_66653 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n5\n8\n58\n85",
"output": "2970.000000000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n5\n8\n58\n152",
"output": "5181.000000000000000\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | p01652 Ancient Commemorative Monolith | Solve the following coding problem using the programming language python:
Problem Statement
One day in a forest, Alice found an old monolith.
<image>
She investigated the monolith, and found this was a sentence written in an old language. A sentence consists of glyphs and rectangles which surrounds them. For the ... | vfc_66657 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1\na 11 9\n****.....\n.*.*.....\n.*.*.....\n.*..*....\n.**..*...\n..**..*..\n..*.*....\n..**.*.*.\n..*..*.*.\n..*****.*\n******.**\nb 10 6\n....*.\n....*.\n....*.\n....*.\n....*.\n....*.\n....*.\n....*.\n.**..*\n*****.\n19 55\n**... | |
code_contests | verifiable_code | p01803 Airport Codes | Solve the following coding problem using the programming language python:
Airport Codes
Airport code
In the Kingdom of JAG, airport codes are assigned to each domestic airport for identification.
Airport codes are assigned according to the following rules based on the name of the airport in lowercase English alphab... | ```python
while 1:
n=int(input())
if not n:break
l=[]
m=0
for _ in range(n):
s=input()
a=s[0]
for i,t in enumerate(s[:-1]):
if any(t==c for c in'aiueo'):
a+=s[i+1]
m=max(m,len(a))
l.append(a)
for k in range(m+1):
if len(... | vfc_66661 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nhaneda\noookayama\ntsu\n2\nazusa\nazishirabe\n2\nsnuke\nsnake\n4\nhaneda\nhonda\nhanamaki\nhawaii\n0",
"output": "1\n4\n-1\n3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nhaneda\noo... |
code_contests | verifiable_code | p01938 A-Z- | Solve the following coding problem using the programming language python:
A: A-Z-
problem
There is a circular board of 26 squares, each square with one capital letter of the alphabet written clockwise in alphabetical order. That is, the clockwise side of the'A'square is the'B' square, the next side of the'B'square i... | ```python
S = input()
cur = 'A'
ans = 0
for i in range(len(S)):
if(S[i] == cur):
ans += 1
else:
if(cur > S[i]):
ans += 1
cur = S[i]
print(ans)
``` | vfc_66665 | {
"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": "AIZU",
"output": "2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p02077 Bombing | Solve the following coding problem using the programming language python:
Problem Statement
JAG land is a country, which is represented as an $M \times M$ grid. Its top-left cell is $(1, 1)$ and its bottom-right cell is $(M, M)$.
Suddenly, a bomber invaded JAG land and dropped bombs to the country. Its bombing patte... | vfc_66669 | {
"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": "",
"output": "",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p02371 Diameter of a Tree | Solve the following coding problem using the programming language python:
Diameter of a Tree
Given a tree T with non-negative weight, find the diameter of the tree.
The diameter of a tree is the maximum distance between two nodes in a tree.
Constraints
* 1 ≤ n ≤ 100,000
* 0 ≤ wi ≤ 1,000
Input
n
s1 t1 w1
s2 t... | ```python
import sys
readline = sys.stdin.readline
from collections import deque
from math import isinf
INF = float("inf")
sys.setrecursionlimit(200000)
n = int(readline())
G = [[] for _ in range(n)]
D = [INF] * n
for _ in [0] * (n - 1):
s, t, w = map(int, readline().split())
G[s].append([t, w])
G[t].append... | vfc_66677 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0 1 1\n1 2 2\n2 3 4",
"output": "7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 1 2\n1 2 1\n1 3 3",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name":... |
code_contests | verifiable_code | bintreeq | Solve the following coding problem using the programming language python:
Let's consider a rooted binary tree with the following properties:
The number of nodes and edges in the tree is infinite
The tree root is labeled by 1
A node labeled by v has two children: 2 × v (the left son of v) and 2 × v + 1 (the right son ... | ```python
for q in xrange(int(raw_input())):
n, a, b = map(int, raw_input().split())
na, nb = n, n
while (a!=b):
#print a, b, na, nb, "to",
if (a>b):
if (a%2==0):
na/=2
else:
na-=1
na/=2
a/=2
else:
if (b%2==0):
nb/=2
else:
nb-=1
nb/=2
b/=2
#print a, b, na, nb
print ... | vfc_66681 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n11 9 11\n10 2 2\n8 1 8",
"output": "2\n10\n1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n11 9 11\n10 4 2\n8 1 8",
"output": "2\n5\n1\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | codecrck | Solve the following coding problem using the programming language python:
Wet Shark once had 2 sequences:
{a_n}= {a_1, a_2, a_3, ... , a_(10^9)}
{b_n} = {b_1, b_2, b_3, ... , b_(10^9)}
However, he only kept one element from each sequence. Luckily, both the elements that Wet Shark kept have the same index in Wet S... | ```python
# 5th question in long challenge. 5 line code :D
i,k,s=map(int, raw_input().split())
a,b=map(int, raw_input().split())
k-=i
if k%2:print 2 ** (2*(k-1)-s+1)*(2**0.5*a+6**0.5*b)
else:print 2**(2*k-s)*(a+b);
``` | vfc_66685 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1 5\n4 5",
"output": "0.28125\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 5\n4 3",
"output": "0.21875000000\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | fsqrt | Solve the following coding problem using the programming language python:
In olden days finding square roots seemed to be difficult but nowadays it can be easily done using in-built functions available across many languages
.
Assume that you happen to hear the above words and you want to give a try in finding the sq... | ```python
t = int(raw_input())
for i in range(t):
k = int(raw_input())
root_k= k**(1/2.0)
int_root_k = int(root_k)
print int_root_k
``` | vfc_66689 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n10\n5\n10000",
"output": "3\n2\n100\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n10\n5\n10010",
"output": "3\n2\n100\n",
"type": "stdin_stdout"
},
{
"fn_... |
code_contests | verifiable_code | luckpal | Solve the following coding problem using the programming language python:
Chef Palin, as his name suggests, is always very interested in palindromic strings. Recently, he made a pretty interesting discovery on palindromes and that made him feel really Lucky. He came across something known as Lucky Palindromes. He defi... | ```python
import copy
t=int(raw_input().rstrip())
while t:
s = raw_input().rstrip()
if len(s)<=8:
print "unlucky"
else:
length = len(s)
initialCount = 0
palindrome = ''
for i in range(length):
if s[i]>s[length-1-i]:
initialCount+=1
... | vfc_66693 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nlaubcdkey\nluckycodechef\naaaaaaaa",
"output": "luckykcul 8\nluckycocykcul 6\nunlucky",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nlaubcdkey\nlubkycodechef\naaaaaaaa",
"output... |
code_contests | verifiable_code | prob | Solve the following coding problem using the programming language python:
Chef, Artem and Eugene are the best of friends and teammates. Recently, they won a lot of money at the Are You Feeling Lucky Cup. Having put their fortune to test and emerging victorious, they are now busy enjoying their wealth. Eugene wanted to... | ```python
t=int(raw_input())
for _ in range(0,t):
t1,t2,t3,t4=map(float,raw_input().split())
print t1/(t1+t2)
``` | vfc_66697 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 2 1 2\n2 3 4 1",
"output": "0.5\n0.4\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | tcfst07 | Solve the following coding problem using the programming language python:
Consider a sequence of non- negative integers b(1), b(2) … , b(n) of length n. The given sequence is called a winning sequence if and only if there exists integers p and q between 1 and n (both inclusive) such that a(p) xor a(p+1) xor a(p+2) …. ... | ```python
mod = 1000000009
n,k = map(int,raw_input().split())
p = pow(2,k,mod)
ans = 1
for i in range(n):
p-=1
ans*=p
ans%= mod
print ans
``` | vfc_66701 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2",
"output": "6",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1011_E. Border | Solve the following coding problem using the programming language python:
Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, ... | ```python
from functools import reduce
from math import gcd
n, k = map(int, input().split())
A = list(map(int, input().split()))
G = gcd(k, reduce(lambda x,y:gcd(x,y),A))
print(k // G)
print(*list(range(0, k, G)))
``` | vfc_66705 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 10\n10 20 30\n",
"output": "1\n0 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 8\n12 20\n",
"output": "2\n0 4 ",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1036_F. Relatively Prime Powers | Solve the following coding problem using the programming language python:
Consider some positive integer x. Its prime factorization will be of form x = 2^{k_1} ⋅ 3^{k_2} ⋅ 5^{k_3} ⋅ ...
Let's call x elegant if the greatest common divisor of the sequence k_1, k_2, ... is equal to 1. For example, numbers 5 = 5^1, 12 = ... | ```python
from math import sqrt, log2
from sys import stdin
from bisect import bisect
import time
def all_primes(n):
res = []
for i in range(1, n+1):
prime = True
for j in range(2, min(int(sqrt(i))+2, i)):
if i % j == 0:
prime = False
break
if... | vfc_66709 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4\n2\n72\n10\n",
"output": " 2\n 1\n ... |
code_contests | verifiable_code | 1059_E. Split the Tree | Solve the following coding problem using the programming language python:
You are given a rooted tree on n vertices, its root is the vertex number 1. The i-th vertex contains a number w_i. Split it into the minimum possible number of vertical paths in such a way that each path contains no more than L vertices and the ... | ```python
from collections import defaultdict
import sys
def rec(n, l, s):
# dp[i] is a doctionary, where key is the chain length
# and value is the weight at node i
dp = [{} for _ in range(n)]
ans = 0
for cur in range(n - 1, -1, -1):
child_of_cur = children.get(cur, None)
if not c... | vfc_66713 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1 3\n1 2 3\n1 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3 6\n1 2 3\n1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | 1081_A. Definite Game | Solve the following coding problem using the programming language python:
Chouti was doing a competitive programming competition. However, after having all the problems accepted, he got bored and decided to invent some small games.
He came up with the following game. The player has a positive integer n. Initially the... | ```python
v = int(input())
print(2 if v == 2 else 1)
``` | vfc_66717 | {
"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": "8\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1100_A. Roman and Browser | Solve the following coding problem using the programming language python:
This morning, Roman woke up and opened the browser with n opened tabs numbered from 1 to n. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many ... | ```python
from collections import Counter
import math
n,m=map(int,input().split())
l=list(map(int,input().split()))
c=Counter(l)
a1=c[1]
a2=c[-1]
i=0
s=[]
a=0
b=0
while(i<m):
for j in range(i,n,m):
if l[j]>0:
a+=1
else:
b+=1
s+=[abs(a1-a2+b-a)]
a=0
b=0
i+=1
print(max(s))
``` | vfc_66721 | {
"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": "14 3\n-1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n1 1 -1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 1121_E. Once in a casino | Solve the following coding problem using the programming language python:
One player came to a casino and found a slot machine where everything depends only on how he plays. The rules follow.
A positive integer a is initially on the screen. The player can put a coin into the machine and then add 1 to or subtract 1 fr... | ```python
def main():
n = int(input())
a = list(map(int, (x for x in input())))
b = list(map(int, (x for x in input())))
x = [0] * (n - 1)
x[0] = b[0] - a[0]
for i in range(1, n - 1):
x[i] = b[i] - a[i] - x[i - 1]
if a[n - 1] + x[n - 2] != b[n - 1]:
print(-1)
return
... | vfc_66725 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n223\n322\n",
"output": "2\n1 1\n2 -1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n35\n44\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | 1148_G. Gold Experience | Solve the following coding problem using the programming language python:
Consider an undirected graph G with n vertices. There is a value a_i in each vertex.
Two vertices i and j are connected with an edge if and only if gcd(a_i, a_j) > 1, where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipe... | vfc_66729 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 1024000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 5\n3003 17017 3230 49742 546 41990 17765 570 21945 36465\n",
"output": "1 2 4 5 6 ",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 116_D. Lawnmower | Solve the following coding problem using the programming language python:
You have a garden consisting entirely of grass and weeds. Your garden is described by an n × m grid, with rows numbered 1 to n from top to bottom, and columns 1 to m from left to right. Each cell is identified by a pair (r, c) which means that t... | ```python
n, m = map(int, input().split())
t = [(p.find('W'), p.rfind('W')) for p in [input() for i in range(n)]]
c, s, k = 0, n - 1, True
while s > 0 and t[s][0] == -1: s -= 1
for a, b in t[: s + 1]:
if a != -1:
if k:
s += abs(a - c) + b - a
c = b
else:
... | vfc_66733 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 5\nGWGGW\nGGWGG\nGWGGG\nWGGGG\n",
"output": "11",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\nG\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | 1188_C. Array Beauty | Solve the following coding problem using the programming language python:
Let's call beauty of an array b_1, b_2, …, b_n (n > 1) — min_{1 ≤ i < j ≤ n} |b_i - b_j|.
You're given an array a_1, a_2, … a_n and a number k. Calculate the sum of beauty over all subsequences of the array of length exactly k. As this number c... | ```python
from collections import defaultdict
import sys
input = sys.stdin.readline
'''
for CASES in range(int(input())):
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
S = input().strip()
sys.stdout.write(" ".join(map(str,ans))+"\n")
'''
inf = 100000000000000000 # 1e17
mod = 998... | vfc_66737 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5\n1 10 100 1000 10000\n",
"output": "9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n1 7 3 5\n",
"output": "8",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | 1207_D. Number Of Permutations | Solve the following coding problem using the programming language python:
You are given a sequence of n pairs of integers: (a_1, b_1), (a_2, b_2), ... , (a_n, b_n). This sequence is called bad if it is sorted in non-descending order by first elements or if it is sorted in non-descending order by second elements. Other... | ```python
from collections import defaultdict
import math
MOD = 998244353
def facmod(n):
fac = 1
for i in range(2, n + 1):
fac *= i
fac %= MOD
return fac
def main():
n = int(input())
s = [tuple(int(s) for s in input().split()) for _ in range(n)]
count = defaultdict(int... | vfc_66741 | {
"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\n1 1\n1 1\n2 3\n",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 1\n2 2\n3 1\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1225_E. Rock Is Push | Solve the following coding problem using the programming language python:
You are at the top left cell (1, 1) of an n × m labyrinth. Your goal is to get to the bottom right cell (n, m). You can only move right or down, one cell per step. Moving right from a cell (x, y) takes you to the cell (x, y + 1), while moving do... | ```python
def getSum(dp, pos, s, e, type_):
if e < s:
return 0
if type_=='D':
if e==m-1:
return dp[pos][s]
return dp[pos][s]-dp[pos][e+1]
else:
if e==n-1:
return dp[s][pos]
return dp[s][pos]-dp[e+1][pos]
mod = 10**9+7
n, m = map(i... | vfc_66745 | {
"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": "2 3\n...\n..R\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 124_A. The number of positions | Solve the following coding problem using the programming language python:
Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positio... | ```python
x,y,z=map(int,input().split())
if y+z>=x:
print(x-y)
else:
print(z+1)
``` | vfc_66749 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1 1\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2 3\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "23 8 14... |
code_contests | verifiable_code | 1268_D. Invertation in Tournament | Solve the following coding problem using the programming language python:
You are given a tournament — complete directed graph.
In one operation you can pick any vertex v and change the direction of all edges with v on one of the ends (i.e all edges u → v change their orientation to v → u and vice versa).
You want t... | vfc_66753 | {
"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": "4\n0010\n1000\n0100\n1110\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n010000\n001000\n100000\n111001\n111100\n111010\n",
"output": "2 18",
"type": "stdin... | |
code_contests | verifiable_code | 1290_E. Cartesian Tree | Solve the following coding problem using the programming language python:
Ildar is the algorithm teacher of William and Harris. Today, Ildar is teaching Cartesian Tree. However, Harris is sick, so Ildar is only teaching William.
A cartesian tree is a rooted tree, that can be constructed from a sequence of distinct in... | vfc_66757 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 4 1 5 3\n",
"output": "1\n3\n6\n8\n11\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1310_F. Bad Cryptography | Solve the following coding problem using the programming language python:
In modern cryptography much is tied to the algorithmic complexity of solving several problems. One of such problems is a discrete logarithm problem. It is formulated as follows:
Let's fix a [finite field](https://en.wikipedia.org/wiki/Finite_f... | vfc_66761 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n2 2\n1 1\n2 3\n8 10\n8 2\n321321321321 2\n123214213213 4356903202345442785\n",
"output": "12297829382473034410\n0\n6148914691236517205\n11068046444225730969\n-1\n6148914691236517205\n68943624821423112\n",
"type": "st... | |
code_contests | verifiable_code | 1333_D. Challenges in school №41 | Solve the following coding problem using the programming language python:
There are n children, who study at the school №41. It is well-known that they are good mathematicians. Once at a break, they arranged a challenge for themselves. All children arranged in a row and turned heads either to the left or to the right.... | ```python
#!/usr/bin/env python
from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def main():
n , k = [int(n) for n in inp... | vfc_66765 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\nRLRL\n",
"output": "2 1 3 \n1 2 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\nRL\n",
"output": "1 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | 1354_A. Alarm Clock | Solve the following coding problem using the programming language python:
Polycarp has spent the entire day preparing problems for you. Now he has to sleep for at least a minutes to feel refreshed.
Polycarp can only wake up by hearing the sound of his alarm. So he has just fallen asleep and his first alarm goes off i... | ```python
for i in range(int(input())):
a,b,c,d=map(int,input().split())
e=a-b
if e<1:
print(b)
continue
else:
if c-d<1:
print(-1)
continue
else:
f=int(e//(c-d))
if b+f*(c-d)>=a:
print(b+f*c)
else... | vfc_66769 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n10 3 6 4\n11 3 6 4\n5 9 4 10\n6 5 2 3\n1 1 1 1\n3947465 47342 338129 123123\n234123843 13 361451236 361451000\n",
"output": "27\n27\n9\n-1\n1\n6471793\n358578060125049\n",
"type": "stdin_stdout"
},
{
"f... |
code_contests | verifiable_code | 1373_F. Network Coverage | Solve the following coding problem using the programming language python:
The government of Berland decided to improve network coverage in his country. Berland has a unique structure: the capital in the center and n cities in a circle around the capital. The capital already has a good network coverage (so the governme... | ```python
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop
import math
from collections import *
from functools import reduce,cmp_to_key,lru_cache
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# import sys
# input = sys.stdin.readl... | vfc_66773 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n3\n2 3 4\n3 3 3\n3\n3 3 3\n2 3 4\n4\n2 3 4 5\n3 7 2 2\n4\n4 5 2 3\n2 3 2 7\n2\n1 1\n10 10\n",
"output": "YES\nYES\nNO\nYES\nYES\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1439_A1. Binary Table (Easy Version) | Solve the following coding problem using the programming language python:
This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem.
You are given a binary table of si... | ```python
import sys
input=sys.stdin.readline
def change(x1,x2,x3,y1,y2,y3,ll):
ll[x1][y1]=1-ll[x1][y1]
ll[x2][y2]=1-ll[x2][y2]
#print(x3,y3,ll)
ll[x3][y3]=1-ll[x3][y3]
t=int(input())
while t:
n,m=map(int,input().split())
ll=[]
for i in range(n):
l=list(map(int,input().strip())... | vfc_66785 | {
"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\n2 2\n10\n11\n3 3\n011\n101\n110\n4 4\n1111\n0110\n0110\n1111\n5 5\n01011\n11001\n00010\n11011\n10000\n2 3\n011\n101\n",
"output": "1\n1 1 2 1 2 2 \n6\n1 1 1 2 2 2 \n1 1 2 1 2 2 \n1 2 1 3 2 2 \n1 2 2 2 2 3 \n2 1 2 2 3 1 \n2... |
code_contests | verifiable_code | 1490_A. Dense Array | Solve the following coding problem using the programming language python:
Polycarp calls an array dense if the greater of any two adjacent elements is not more than twice bigger than the smaller. More formally, for any i (1 ≤ i ≤ n-1), this condition must be satisfied: $$$(max(a[i], a[i+1]))/(min(a[i], a[i+1])) ≤ 2$$$... | ```python
for _ in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
s=0
for i in range(n-1):
a=max(l[i],l[i+1])
b=min(l[i],l[i+1])
while a>(2*b):
s+=1
b=b*2
print(s)
``` | vfc_66793 | {
"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": "6\n4\n4 2 10 1\n2\n1 3\n2\n6 1\n3\n1 4 2\n5\n1 2 3 4 3\n12\n4 31 25 50 30 20 34 46 42 16 15 16\n",
"output": "\n5\n1\n2\n1\n0\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n4\n4 2 1... |
code_contests | verifiable_code | 153_B. Binary notation | Solve the following coding problem using the programming language python:
You are given a positive integer n. Output its binary notation.
Input
The only line of input data contains an integer n (1 ≤ n ≤ 106).
Output
Output the binary notation of n (without any leading zeros).
Examples
Input
5
Output
101
In... | vfc_66801 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n",
"output": "101\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13\n",
"output": "1101\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "126\n... | |
code_contests | verifiable_code | 166_E. Tetrahedron | Solve the following coding problem using the programming language python:
You are given a tetrahedron. Let's mark its vertices with letters A, B, C and D correspondingly.
<image>
An ant is standing in the vertex D of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes ... | ```python
def fast_exp_pow(num, pw, mod):
num %= mod
if pw == 1:
return num
evener = 1
if pw % 2 == 1:
evener = num
return (evener * (fast_exp_pow(num, pw // 2, mod) % mod) ** 2) % mod
mod = 1000000007
n = int(input())
if n == 1:
print(0)
quit()
x = ((fast_exp_pow(3, n - 1, mod) + (-1) ** (n & 1) + mod) * ... | vfc_66805 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000\n"... |
code_contests | verifiable_code | 188_A. Hexagonal Numbers | Solve the following coding problem using the programming language python:
Hexagonal numbers are figurate numbers which can be calculated using the formula hn = 2n2 - n. You are given n; calculate n-th hexagonal number.
Input
The only line of input contains an integer n (1 ≤ n ≤ 100).
Output
Output the n-th hexagon... | vfc_66809 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "15\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 208_D. Prizes, Prizes, more Prizes | Solve the following coding problem using the programming language python:
Vasya, like many others, likes to participate in a variety of sweepstakes and lotteries. Now he collects wrappings from a famous chocolate bar "Jupiter". According to the sweepstake rules, each wrapping has an integer written on it — the number ... | ```python
import bisect
n = int(input())
a = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
b = [0, 0, 0, 0, 0]
s = 0
for i in a:
s += i
k = bisect.bisect_right(p, s)
while k != 0:
if (k == 5) or (p[k] > s):
k -= 1
b[k] += s // p[k]
s %= p[k]
... | vfc_66813 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n10 4 39 2\n3 5 10 11 12\n",
"output": "3 0 1 0 3\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3 10 4\n2 4 10 15 20\n",
"output": "1 1 1 0 0\n1\n",
"type": "stdin_st... |
code_contests | verifiable_code | 234_B. Reading | Solve the following coding problem using the programming language python:
Vasya is going to the Olympics in the city Ntown by train. The boy wants to read the textbook to prepare for the Olympics. He counted that he needed k hours for this. He also found that the light in the train changes every hour. The light is mea... | ```python
import copy
import math
import sys
def solve(n, k, b):
b_sorted = copy.copy(b)
b_sorted.sort()
th = b_sorted[-k]
ans = [i+1 for i, v in enumerate(b) if v>= th]
if len(ans) != k:
times = len(ans)-k
dup = [i+1 for i, v in enumerate(b) if v== th]
#print times, dup, ... | vfc_66817 | {
"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 3\n20 10 30 40 10\n",
"output": "20\n1 3 4 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 5\n90 20 35 40 60 100\n",
"output": "35\n1 3 4 5 6 \n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 25_A. IQ test | Solve the following coding problem using the programming language python:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answ... | ```python
n=int(input())
q=list(map(int,input().split()))
eve,eve_indx,neg,neg_indx=0,0,0,0
for i in range(n):
x=q[i]%2
if x==0:
eve +=1
eve_indx=i
else:
neg +=1
neg_indx=i
if eve==1:
print(eve_indx+1)
else:
print(neg_indx+1)
``` | vfc_66821 | {
"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\n1 2 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n2 4 7 8 10\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 305_E. Playing with String | Solve the following coding problem using the programming language python:
Two people play the following string game. Initially the players have got some string s. The players move in turns, the player who cannot make a move loses.
Before the game began, the string is written on a piece of paper, one letter per cell.... | ```python
U = input()
memo = {}
DP = [0]*(len(U)+1)
DP[0] = 0
for j in range(1, len(U) + 1):
s = set()
for i in range(j):
s.add(DP[max(0, i - 1)] ^ DP[max(0, j - i - 2)])
mex = 0
while mex in s:
mex += 1
DP[j] = mex
memo2 = {}
def Grundy(S):
"""
Basically we transform ... | vfc_66829 | {
"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": "abcde\n",
"output": "Second\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "abacaba\n",
"output": "First\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 331_C2. The Great Julya Calendar | Solve the following coding problem using the programming language python:
Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar.
The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaveri... | ```python
c = '0123456789'
F = {c[a] + c[b]: (c[10 - a + b], 1) if a > b else (c[10 - a], 2) for a in range(1, 10) for b in range(10)}
for b in range(1, 10): F['0' + c[b]] = ('0', 1)
F['00'] = ('0', 0)
def f(x):
global F
if x in F: return F[x]
a, b, y, s = int(x[0]), int(x[1]), x[2: ], 0
for i in range... | vfc_66833 | {
"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": "24\n",
"output": " 5\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 353_D. Queue | Solve the following coding problem using the programming language python:
There are n schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The buns aren't ready yet and the line is undergoing some changes.
Each second all boys that stand right in front of girls, simultaneously swa... | ```python
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq,bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(1... | vfc_66837 | {
"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": "MFM\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "FFMMM\n",
"output": "0",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 377_E. Cookie Clicker | Solve the following coding problem using the programming language python:
Kostya is playing the computer game Cookie Clicker. The goal of this game is to gather cookies. You can get cookies using different buildings: you can just click a special field on the screen and get the cookies for the clicks, you can buy a coo... | vfc_66841 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 9\n1 0\n2 3\n5 4\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 13\n1 0\n2 2\n6 5\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name"... | |
code_contests | verifiable_code | 39_B. Company Income Growth | Solve the following coding problem using the programming language python:
Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to a1 bill... | ```python
_, values,i,years = int(input()),[int(i) for i in input().split(" ")],1,[]
if 1 in values:
years.append(values.index(1))
i=2
while i in values[years[-1]:]:
years.append(values[years[-1]:].index(i)+years[-1])
i+=1
print(len(years))
if len(years) !=0:
for year in years:
print(2001+year,end=" ")
print... | vfc_66845 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n-2 1 1 3 2 3 4 -10 -2 5\n",
"output": "5\n2002 2005 2006 2007 2010 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n-1 -2 -3\n",
"output": "0\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 424_C. Magic Formulas | Solve the following coding problem using the programming language python:
People in the Tomskaya region like magic formulas very much. You can see some of them below.
Imagine you are given a sequence of positive integer numbers p1, p2, ..., pn. Lets write down some magic formulas:
<image><image>
Here, "mod" means t... | ```python
import sys
input=sys.stdin.readline
n=int(input())
ar=list(map(int,input().split()))
dp=[0]
pre=0
for i in range(1,n+1):
pre^=i
dp.append(pre)
ans=0
for i in range(1,n+1):
xx=ar[i-1]^(dp[i-1]*((n//i)%2))^(dp[n%i])
ans^=xx
print(ans)
``` | vfc_66849 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 3\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20\n1999581813 313463235 1733614990 662007911 1789348031 1120800519 196972430 1579897311 191001928 241720485 1426288... |
code_contests | verifiable_code | 449_A. Jzzhu and Chocolate | Solve the following coding problem using the programming language python:
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements:
* each cut should be straight (horizontal or vertical);
* each cut shou... | ```python
l = input().split()
n = int(l[0])
m = int(l[1])
k = int(l[2])
if ( k <= n+m-2 ):
if ( k < n ):
outn = int((n / (k + 1))) * m
else:
outn = int(m / (k - n + 2))
if ( k < m):
outm = int( m / ( k + 1)) * n
else:
outm = int( n / ( k - m + 2 ))
print ("", max( ou... | vfc_66853 | {
"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 4 2\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 ... |
code_contests | verifiable_code | 46_G. Emperor's Problem | Solve the following coding problem using the programming language python:
It happened at the times of the Great Berland Empire. Once the Emperor dreamt that the Messenger from the gods ordered to build a temple whose base would be a convex polygon with n angles. Next morning the Emperor gave the command to build a tem... | vfc_66857 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "YES\n0 0\n-1 -1\n-1 -2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "YES\n0 0\n-1 -1\n-1 -2\n",
"type": "stdin_stdout"
},
{
"f... | |
code_contests | verifiable_code | 493_C. Vasya and Basketball | Solve the following coding problem using the programming language python:
Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some val... | ```python
n = int(input())
score = list(map(lambda x: [int(x), 0], input().split()))
m = int(input())
score += list(map(lambda x: [int(x), 1], input().split()))
score.sort()
f = []
if score[0][1] == 0:
f.append([1, 0])
else:
f.append([0, 1])
for i in range(1, n + m):
if score[i][1] == 0:
f.appe... | vfc_66861 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 3\n2\n5 6\n",
"output": "9:6",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n6 7 8 9 10\n5\n1 2 3 4 5\n",
"output": "15:10",
"type": "stdin_stdout"
},
{
"... |
code_contests | verifiable_code | 544_B. Sea and Islands | Solve the following coding problem using the programming language python:
A map of some object is a rectangular field consisting of n rows and n columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly k islands appear on the map. We will call a set of ... | ```python
n,k=input().split()
n,k=int(n),int(k)
if k>(n*n+1)//2:
print("NO")
exit()
print("YES")
for i in range(0,n):
for j in range(0,n):
if((i+j)%2==0 and k>0):
print('L',end='')
k-=1
else:
print('S',end='')
print()
# Made By ... | vfc_66869 | {
"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 2\n",
"output": "YES\nLSLSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 25\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn... |
code_contests | verifiable_code | 570_D. Tree Requests | Solve the following coding problem using the programming language python:
Roman planted a tree consisting of n vertices. Each vertex contains a lowercase English letter. Vertex 1 is the root of the tree, each of the n - 1 remaining vertices has a parent in the tree. Vertex is connected with its parent by an edge. The ... | ```python
from sys import stdin, stdout
from itertools import repeat
def main():
n, m = map(int, stdin.readline().split())
a = map(int, stdin.readline().split(), repeat(10, n - 1))
last = [None] * (n + 10)
ne = [None] * (n + 10)
for i, x in enumerate(a, 2):
ne[i] = last[x]
last[x] = ... | vfc_66873 | {
"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": "6 5\n1 1 1 3 3\nzacccd\n1 1\n3 3\n4 1\n6 1\n1 2\n",
"output": "Yes\nNo\nYes\nYes\nYes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n\np\n1 1\n",
"output": "Yes\n",
"type... |
code_contests | verifiable_code | 592_B. The Monster and the Squirrel | Solve the following coding problem using the programming language python:
Ari the monster always wakes up very early with the first ray of the sun and the first thing she does is feeding her squirrel.
Ari draws a regular convex polygon on the floor and numbers it's vertices 1, 2, ..., n in clockwise order. Then start... | ```python
n=int(input())
N=0
for i in range(2,n):
N=N+2*i-3
print(N)
``` | vfc_66877 | {
"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\n",
"output": "9\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 613_E. Puzzle Lover | Solve the following coding problem using the programming language python:
Oleg Petrov loves crossword puzzles and every Thursday he buys his favorite magazine with crosswords and other word puzzles. In the last magazine Oleg found a curious puzzle, and the magazine promised a valuable prize for it's solution. We give ... | vfc_66881 | {
"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": "code\nedoc\n\ncode\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "aaa\naaa\n\naa\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... | |
code_contests | verifiable_code | 686_C. Robbers' watch | Solve the following coding problem using the programming language python:
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad at math, robbers use the p... | ```python
read = lambda: map(int, input().split())
n, m = read()
from itertools import permutations, combinations
cnt = 0
p1 = 0
x1 = 1
while x1 <= n - 1:
x1 *= 7
p1 += 1
p2 = 0
x2 = 1
while x2 <= m - 1:
x2 *= 7
p2 += 1
p1, p2 = max(p1, 1), max(p2, 1)
Len = p1 + p2
for comb in combinations([0, 1, 2, ... | vfc_66893 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1582 30... |
code_contests | verifiable_code | 709_B. Checkpoints | Solve the following coding problem using the programming language python:
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x1, x2, ..., xn. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the c... | ```python
n, a = map(int, input().split())
x = list(map(int, input().split()))
if n == 1:
print(0)
elif n == 2:
if abs(x[0]-a) < abs(x[1]-a):
print(abs(x[0]-a))
else:
print(abs(x[1]-a))
elif n == 3:
x = sorted(x)
_min = x[0]
_mid = x[1]
_max = x[2]
ans = abs(_max - a)*2 ... | vfc_66897 | {
"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 10\n1 7 12\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 0\n0 0 1000 0 0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 730_D. Running Over The Bridges | Solve the following coding problem using the programming language python:
Polycarp is playing a game called "Running Over The Bridges". In this game he has to run over n bridges from the left to the right. Bridges are arranged one after the other, so the i-th bridge begins where the (i - 1)-th bridge ends.
You have t... | vfc_66901 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 3\n7\n10\n",
"output": "2\n6 9 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 100000\n5 5 5\n5 7 8\n",
"output": "1\n0 \n",
"type": "stdin_stdout"
},
{
"fn_... | |
code_contests | verifiable_code | 753_B. Interactive Bulls and Cows (Easy) | Solve the following coding problem using the programming language python:
This problem is a little bit unusual. Here you are to implement an interaction with a testing system. That means that you can make queries and get responses in the online mode. Please be sure to use the stream flushing operation after each query... | vfc_66905 | {
"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": "0 1\n2 0\n1 1\n0 4\n2 1\n4 0\n",
"output": "0000\n1000\n2000\n3000\n4000\n5000\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 774_H. Repairing Of String | Solve the following coding problem using the programming language python:
Stepan had a favorite string s which consisted of the lowercase letters of the Latin alphabet.
After graduation, he decided to remember it, but it was a long time ago, so he can't now remember it. But Stepan remembers some information about th... | ```python
n = int(input())
arr = list(map(int, input().split()))
for i in range(n-1, 0, -1):
for j in range(i-1, -1, -1):
arr[j] -= arr[i]*(i-j+1)
s = "a"
def rev(c):
if c == "a":
return "b"
else:
return "a"
for i in range(n):
for j in range(arr[i]):
s += rev(s[-1])*(i+1)... | vfc_66909 | {
"difficulty": "14",
"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\n6 3 1 0 0 0\n",
"output": "aaabba\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n4 0 0 0\n",
"output": "abab\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 79_A. Bus Game | Solve the following coding problem using the programming language python:
After Fox Ciel won an onsite round of a programming contest, she took a bus to return to her castle. The fee of the bus was 220 yen. She met Rabbit Hanako in the bus. They decided to play the following game because they got bored in the bus.
... | ```python
player_one = 'Ciel'
player_two = 'Hanako'
c100, c10 = map(int, input().split())
full_moves = min([c100 // 2, c10 // 24])
c100 -= full_moves * 2
c10 -= full_moves * 24
while True:
if 100 * c100 + 10 * c10 >= 220 and c10 >= 2:
tmp = min([2, c100])
c100 -= tmp
c10 -= (220 - 100... | vfc_66913 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n",
"output": "Ciel",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 22\n",
"output": "Hanako",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 81_C. Average Score | Solve the following coding problem using the programming language python:
After the educational reform Polycarp studies only two subjects at school, Safety Studies and PE (Physical Education). During the long months of the fourth term, he received n marks in them. When teachers wrote a mark in the journal, they didn't... | ```python
from operator import itemgetter
from collections import defaultdict
n=int(input())
a,b= map(int,input().split())
arr= list(map(int,input().split()))
arr = list(enumerate(arr,0))
arr=sorted(arr,key=itemgetter(1),reverse=True)
def find_min(num1,num2):
if num1<num2:
return num1
else:
ret... | vfc_66917 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 2\n3 5 4 5\n",
"output": "1 1 2 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n3 2\n4 4 5 4 4\n",
"output": "1 1 2 1 2\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 845_F. Guards In The Storehouse | Solve the following coding problem using the programming language python:
Polycarp owns a shop in the capital of Berland. Recently the criminal activity in the capital increased, so Polycarp is thinking about establishing some better security in the storehouse of his shop.
The storehouse can be represented as a matri... | vfc_66921 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1\nx\n.\nx\n",
"output": "2",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 867_A. Between the Offices | Solve the following coding problem using the programming language python:
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other directio... | ```python
print((lambda s: 'YES' if s[1][0] == 'S' and s[1][-1] == 'F' else 'NO')((input(), input().strip())))
``` | vfc_66925 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\nFFFFFFFFFF\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\nSSFFSFFSFF\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null... |
code_contests | verifiable_code | 914_C. Travelling Salesman and Special Numbers | Solve the following coding problem using the programming language python:
The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he likes to perform operations on numbers. One such operation is to take a positive integer x and reduce it to the number of bits set to 1 in the bin... | ```python
def Numb(a,k):
if a == 0:
return 0
m = len(bin(a))-3
if m + 1 < k:
return 0
if k == 1:
return m+1
if m + 1 == k:
return Numb(a & ((1<<m)-1), k-1)
return C[m][k]+Numb(a & ((1<<m)-1), k-1)
s = input()
nDec = int(s,2)
n = len(s)
k = int(input())
C = [[1],... | vfc_66933 | {
"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": "110\n2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "111111011\n2\n",
"output": "169\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | 937_A. Olympiad | Solve the following coding problem using the programming language python:
The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect... | ```python
n = int(input())
a = [0] * 601
for x in input().split():
a[int(x)] = 1
a[0] = 0
print(sum(a))
``` | vfc_66937 | {
"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\n42 0 0 42\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 3 3 2\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 962_C. Make a Square | Solve the following coding problem using the programming language python:
You are given a positive integer n, written without leading zeroes (for example, the number 04 is incorrect).
In one operation you can delete any digit of the given integer so that the result remains a positive integer without leading zeros.
... | ```python
'''input
101
'''
from itertools import chain, combinations
def binarysearch(arr, x):
l = 0
r = len(arr) - 1
while l <= r:
mid = l + (r - l) // 2
if arr[mid] == x:
return mid
elif arr[mid] < x:
l = mid + 1
else:
r = mid - 1
re... | vfc_66941 | {
"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": "625\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | aniruddha-and-hackerearth | Solve the following coding problem using the programming language python:
Aniruddha loves to code on HackerEarth. There are some type of problems which he likes the most.
Problems are tagged with non empty strings containing only 'H' or 'E' or both. But he likes the problems tagged with strings containing no consecuti... | ```python
arr=[]
sarr=[]
t=0
n=int(raw_input())
if(n>=1 and n<=1000000):
for i in range(n):
t=int(raw_input())
arr.append(t)
sarr.append(t)
sarr.sort()
d ={}
a =2
b=3
ans = a+b
j=0
for i in range(1,sarr[n-1]+1):
if(i>=1 and i<=1000000):
if(i==1):
while(j<n and sarr[j]==i):
d[1]=2
j=j+1
... | vfc_66949 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n3\n\nSAMPLE",
"output": "5\n10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2\n4\n\nSAMPLE",
"output": "5\n18\n",
"type": "stdin_stdout"
},
{
"fn_name... |
code_contests | verifiable_code | chamber-of-secrets | Solve the following coding problem using the programming language python:
Its time for the Potions class. Harry absolutely HATES potions because he has to face mockery by the potions teacher Snape everytime he has a potions class. Snape never leaves any chance of insulting him in front of everyone.
Snape is not in a... | ```python
import sys
t=int(sys.stdin.readline())
while t:
n,q=map(int,sys.stdin.readline().split())
s=raw_input().split()
cum=[]
cum2=[]
for i in range(0,n+1):
cum.append(0)
cum2.append(0)
for i in range(1,n+1):
cum[i]=cum[i-1] + int(s[i-1])
cum2[i]=cum2[i-1]+i*(int(s[i-1]))
for i in range(0,q):
w,x,y,... | vfc_66953 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n5 2\n2 1 4 7 2\n1 1 0 2\n1 5 0 0\n\nSAMPLE",
"output": "16\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n10 12\n5 18 4 7 86 3 13 4 22 21\n1 1 0 0\n1 5 0 0\n1 10 0 0\n1 1 0 9\n1 5 ... |
code_contests | verifiable_code | difficult-characters | Solve the following coding problem using the programming language python:
Yesterday while Omar was trying to learn English, he saw that there are letters repeated many times in words while some other letters repeated only few times or not repeated at all!
Of course anyone can memorize the letters (repeated many tim... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
import string
n=int(raw_input())
for i in range(n):
d=dict(zip(string.ascii_lowercase, [0]*26))
s=raw_input()
for key in d.keys():
d[key]=s.count(key)
for z in sorted(... | vfc_66957 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\noomar\n\nSAMPLE",
"output": "z y x w v u t s q p n l k j i h g f e d c b r m a o \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\nonmar\n\nSAMPLE",
"output": "z y x w v u t s q... |
code_contests | verifiable_code | get-the-1 | Solve the following coding problem using the programming language python:
Katoch, a notorious boy, is always keen about getting number 1. Given a number, he squares every digit of the number and adds to the result. He repeats the process until he gets a 1 digit number. Suppose he is given a number 82, he squares 8 & 2... | ```python
SQUARE = dict([(c, int(c)**2) for c in "0123456789"])
def is_happy(n):
s = set()
while (n > 1) and (n not in s):
s.add(n)
n = sum(SQUARE[d] for d in str(n))
return n == 1
T=int(raw_input())
case=1
while(T>0):
num=int(raw_input())
if is_happy(num)==1:
print 'Case #%d:YES'%case
else:
... | vfc_66961 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n82 \n1\n67\n\nSAMPLE",
"output": "Case #1:YES\nCase #2:YES\nCase #3:NO\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | lets-count-3 | Solve the following coding problem using the programming language python:
While Omar was studying for Math lectures, he found the following problem.
Given 3 Integers N_1, N_2, N_3, count the number of common divisors which divide all of them.
Can you please help Omar in solving this problem, because he usually sle... | ```python
def factors(n):
return list(set(reduce(list.__add__,
([i, n//i] for i in range(1, long(n**0.5) + 1) if n % i == 0))))
for t in range(input()):
num=sorted(map(long,raw_input().split()))
fact=sorted(factors(num[0]),reverse=True)
flag=False
for d in fact:
flag=Tru... | vfc_66965 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2 4 6\n\nSAMPLE",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2 6 6\n\nSAMPLE",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | monk-in-the-magical-land | Solve the following coding problem using the programming language python:
Monk visits a magical place, Makizam. He is greeted by his old friend, Wiz. Wiz happy to see his old friend, gives him a puzzle.
He takes him to a room with N keys placed on the floor, the i'th key is of type Xi. The keys are followed by M ches... | ```python
from fractions import gcd
def func(z,k,y2,ele):
gs=sum([n1 for m,n1 in zip(k,v) if gcd(ele,m)!=1])
z=[i for i in z if i!=ele]
k=[i if gcd(i,ele)==1 else 1 for i in k]
while y2-1:
max=0
lar=0
for i in z:
tot=sum([n1 for m,n1 in zip(k,v) if gcd(i,m)!=1])
... | vfc_66969 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 4 1 \n2 3\n5 3 10 2\n1 2 5 7\n3 4 2\n2 3 5\n5 3 10 2\n1 2 5 7\n\nSAMPLE",
"output": "12\n14",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 4 1 \n2 3\n5 3 10 2\n1 2 5 7\n3 4 2\n2 3... |
code_contests | verifiable_code | roy-and-sweets | Solve the following coding problem using the programming language python:
Its Diwali time and Little Roy's family is having a lot of guests. Guests come in families. Each guest family has M members. Roy's task is to serve sweets to them. Roy has N different sweets and each sweet has some specific sweetness level S and... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
n= long(raw_input());
s=[long(0)]*1000001;
for i in range(0,n):
b,c=raw_input().split();
s[long(b)] = long(c);
m=long(raw_input());
r=long(0);
for i ... | vfc_66977 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n5 8\n3 6\n10 7\n4 6\n2 5\n2\n5\n8\n\nSAMPLE",
"output": "100",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | subset-xor-4 | Solve the following coding problem using the programming language python:
Given a set S. Generate T, a set that contains all subsets of S minus the null set and calculate A, XOR sum of the set T.
S={1,2,3}
T={{1},{2},{3},{1,2},{1,3},{2,3} ,{1,2,3}}
A=XORiana of T .
XORiana of a set is defined as XOR of all the elem... | ```python
t=int(input());
for i in range(0,t):
n=int(input());
d=raw_input("");
d=d.split(" ");
Y=0;
if(len(d)==1):
Y=int(d[0]);
print Y
``` | vfc_66981 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 \n3 3\n3 \n1 2 3\n\nSAMPLE",
"output": "0\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n100\n41 67 134 100 169 124 78 158 162 64 105 145 81 27 161 91 195 142 27 36 191 4 102... |
code_contests | verifiable_code | vasya-and-number-theory | Solve the following coding problem using the programming language python:
Today, Vasya has decided to study about Numbers and Number Theory. One of her good friends Kolya is very good at the subject. To help her, he kept the following task in front of Vasya:
Given an array A of size N, Vasya needs to find the size o... | ```python
def size_good_subset(arr,n):
c= [1 for i in range(n)]
for i in range(n):
j = n - 1 -i
maxCount = 1
for k in range(j+1,n):
if (arr[k] % arr[j] == 0) and (maxCount <= c[k]):
maxCount = c[k] + 1
c[j] = maxCount
print max(c) if max(c)!=1 else -1
#Array size
n = input()
array = map(int,raw_inp... | vfc_66985 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4 8 2 3\n\nSAMPLE",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
code_contests | verifiable_code | p00029 English Sentence | Solve the following coding problem using the programming language python:
Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters.
The text includes only alphabetic... | ```python
word_list = input().split(' ')
word_dict = {}
longest_word_len = 0
longest_word = ''
high_freq_word_num = 0
for word in word_list:
if longest_word_len < len(word):
longest_word_len = len(word)
longest_word = word
if word not in word_dict:
word_dict[word] = 1
else :
... | vfc_67029 | {
"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": "Thank you for your mail and your lectures",
"output": "your lectures",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "Thank you for your mail amd your lectures",
"output": "your lecture... |
code_contests | verifiable_code | p00160 Delivery Fee | Solve the following coding problem using the programming language python:
The courier charges for a courier company are set according to size and weight as shown in the table below.
A size | B size | C size | D size | E size | F size
--- | --- | --- | --- | --- | --- | ---
Size | 60 cm or less | 80 cm or less | 100 c... | ```python
S = [60, 80, 100, 120, 140, 160]
W = [2, 5, 10, 15, 20, 25]
P = [600, 800, 1000, 1200, 1400, 1600]
while 1:
n = int(input())
if n == 0:
break
r = 0
for i in range(n):
x, y, h, w = map(int, input().split())
s = x + y + h
for j in range(6):
if s <= S[... | vfc_67033 | {
"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": "2\n50 25 5 5\n80 60 10 30\n3\n10 15 25 24\n5 8 12 5\n30 30 30 18\n0",
"output": "800\n3800",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n50 25 5 5\n80 60 10 30\n3\n10 7 25 24\n5 8 12 5\... |
code_contests | verifiable_code | p00487 Bug Party | Solve the following coding problem using the programming language python:
Do you know Just Odd Inventions? The business of this company is to "just odd inventions". Here, it is abbreviated as JOI.
JOI is conducting research to confine many microorganisms in one petri dish alive. There are N microorganisms to be inves... | ```python
# AOJ 0564: Bug Party
# Python3 2018.6.30 bal4u
import heapq
tbl = []
N = int(input())
for i in range(N):
a, b = map(int, input().split())
tbl.append((a, b))
tbl.sort()
Q = []
ans = s = sz = 0
for t in tbl:
s += t[0]
heapq.heappush(Q, (t[1], t[0]))
sz += 1
while sz and sz*Q[0][0] < s:
s -= Q[0][1]
... | vfc_67041 | {
"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\n12 8\n5 9\n2 4\n10 12\n6 7\n13 9",
"output": "3",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00673 School Excursion | Solve the following coding problem using the programming language python:
Spring is the time for school trips. The University of Aizu Elementary School (Aizu University and Small) also had a plan for a school trip next year. It is a tradition to travel by train on school trips. This is because there are few opportunit... | vfc_67045 | {
"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\n4\n1 2 10\n2 2 5\n1 3 20\n2 3 10\n10\n3\n2\n1 2 5\n0 3 4\n3\n10 11 100\n2 12 2\n12 12 3\n10\n0",
"output": "2 15\n2 111",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n4\n1 2 10\n2 2 5... | |
code_contests | verifiable_code | p00816 Shredding Company | Solve the following coding problem using the programming language python:
You have just been put in charge of developing a new shredder for the Shredding Company. Although a ``normal'' shredder would just shred sheets of paper into little pieces so that the contents would become unreadable, this new shredder needs to ... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]
def LI(): return [int(x) for x i... | vfc_67049 | {
"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": "50 12346\n376 144139\n927438 927438\n18 3312\n9 3142\n25 1299\n111 33333\n103 862150\n6 1104\n0 0",
"output": "43 1 2 34 6\n283 144 139\n927438 927438\n18 3 3 12\nerror\n21 1 2 9 9\nrejected\n103 86 2 15 0\nrejected",
"... |
code_contests | verifiable_code | p00947 Quality of Check Digits | Solve the following coding problem using the programming language python:
Example
Input
0 3 1 7 5 9 8 6 4 2
7 0 9 2 1 5 4 8 6 3
4 2 0 6 8 7 1 3 5 9
1 7 5 0 9 8 3 4 2 6
6 1 2 3 0 4 5 9 7 8
3 6 7 4 2 0 9 5 8 1
5 8 6 9 7 2 0 1 3 4
8 9 4 5 3 6 2 0 1 7
9 4 3 8 6 1 7 2 0 5
2 5 8 1 4 3 6 7 9 0
Output
0
The input will b... | ```python
from itertools import product
T = [list(map(int, input().split())) for i in range(10)]
def calc(v):
val = 0
for e in v:
val = T[val][e]
return val
ans = 0
for code in product(range(10), repeat=4):
e = calc(code)
ok = 1
code = list(code) + [e]
for i in range(5):
d ... | vfc_67053 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0 3 1 7 5 9 8 6 4 2\n7 0 9 2 1 5 4 8 6 3\n4 2 0 6 8 7 1 3 5 9\n1 7 5 0 9 8 3 4 2 6\n6 1 2 3 0 4 5 9 7 8\n3 6 7 4 2 0 9 5 8 1\n5 8 6 9 7 2 0 1 3 4\n8 9 4 5 3 6 2 0 1 7\n9 4 3 8 6 1 7 2 0 5\n2 5 8 1 4 3 6 7 9 0",
"output": "0",... |
code_contests | verifiable_code | p01214 Petoris | Solve the following coding problem using the programming language python:
You are playing a puzzle game named petoris. It is played with a board divided into square grids and square tiles each of which fits to a single grid.
In each step of the game, you have a board partially filled with tiles. You also have a block... | ```python
def toBinary(block):
return [sum(1 << i for i,bb in enumerate(b) if bb == "#") for b in block]
def toStr(bfield):
return ["".join("." if f & (1<<i) == 0 else "#" for i in xrange(W)) for f in bfield]
def rotated(block):
return map(lambda x:"".join(x),zip(*[b[:] for b in block]))[::-1]
def stripe... | vfc_67061 | {
"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\n4 4\n....\n....\n####\n....\n12 8\n........\n........\n........\n........\n........\n.......#\n##.##..#\n.#######\n.#######\n.#######\n.#######\n.####.#.\n4 4\n....\n....\n.###\n...#\n12 8\n........\n........\n........\n........... |
code_contests | verifiable_code | p01350 Carrot Tour | Solve the following coding problem using the programming language python:
I'm traveling to a country with a rabbit. There are n cities in this country numbered from 1 to n, and the rabbit is now in city 1. City i is a point on the coordinate plane (xi, yi) ).
Rabbits travel to meet the following conditions.
* The tr... | ```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_67065 | {
"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\n100.1 90.1\n0 0\n0 10\n5 5\n10 0\n10 10",
"output": "10",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n100.1 90.1\n0 0\n0 10\n7 5\n10 0\n10 10",
"output": "10\n",
"type": ... |
code_contests | verifiable_code | p01832 Shifting a Matrix | Solve the following coding problem using the programming language python:
Example
Input
3 2
R1
Output
3 1 2
4 5 6
7 8 9
The input will be given via stdin and the output should be printed to stdout by your code.
Now solve the problem by providing the code. | ```python
from string import digits
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N, L = map(int, readline().split())
S = readline().strip()
*I, = range(N*N)
LRUD = "LRUD"
FS = [[], [], [], []]
for i in range(N):
base = N*i
F = I[:]
for j ... | vfc_67077 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\nR1",
"output": "3 1 2\n4 5 6\n7 8 9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\nR1",
"output": "2 1\n3 4\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... |
code_contests | verifiable_code | p01967 Many Kinds of Apples | Solve the following coding problem using the programming language python:
A: Many Kinds of Apples
Problem Statement
Apple Farmer Mon has two kinds of tasks: "harvest apples" and "ship apples".
There are N different species of apples, and N distinguishable boxes. Apples are labeled by the species, and boxes are also... | ```python
n = int(input())
C = list(map(int, input().split()))
q = int(input())
data = []
for _ in range(q):
t, x, d = map(int, input().split())
data.append([t, x, d])
apple = [0] * n
for D in data:
t, x, d = D
if t == 1:
apple[x-1] += d
if apple[x-1] > C[x-1]:
print(x)
... | vfc_67081 | {
"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": "2\n3 3\n4\n1 1 2\n1 2 3\n2 1 3\n2 2 3",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3 3\n4\n1 1 0\n1 2 3\n2 1 3\n2 2 3",
"output": "1\n",
"type": "stdin_stdou... |
code_contests | verifiable_code | p02254 Huffman Coding | Solve the following coding problem using the programming language python:
We want to encode a given string $S$ to a binary string. Each alphabet character in $S$ should be mapped to a different variable-length code and the code must not be a prefix of others.
Huffman coding is known as one of ways to obtain a code ta... | ```python
from heapq import heappop, heappush
from collections import Counter
class Node:
def __init__(self, weight):
self.weight = weight
def set_parent(self,parent):
self.parent = parent
def get_length(self):
try:
tmp = 1 + self.parent.get_length()
... | vfc_67089 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "z",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "aaabbcccdeeeffg",
"output": "41",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "abca... |
code_contests | verifiable_code | p02402 Min | Solve the following coding problem using the programming language python:
Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence.
Constraints
* $0 < n \leq 10000$
* $-1000000 \leq a_i \leq 1000000$
Input
In the first line,... | ```python
input()
l=list([int(i) for i in input().split()])
print(min(l), max(l), sum(l))
``` | vfc_67093 | {
"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\n10 1 5 4 17",
"output": "1 17 37",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n13 1 5 4 17",
"output": "1 17 40\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | adigit | Solve the following coding problem using the programming language python:
Yesterday Chef had a great party and doesn't remember the way he celebreated it. But he found a strange paper in his kitchen containing n digits (lets give them indices from 1 to n and name them a1, a2 ... aN).
Chef remembers that he played su... | ```python
[n, m] = [int(x) for x in raw_input().split(" ")]
a = raw_input().rstrip()
digits = [int(x) for x in a]
L = len(a)
# construct
p = [[0]*L for _ in range(10)]
for i, x in enumerate(digits):
p[x][i] = 1
for i in range(1, L):
for j in range(10):
p[j][i] += p[j][i-1]
for _ in range(m):
t = i... | vfc_67097 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 3\n0324152397\n1\n4\n7",
"output": "0\n7\n9\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | chefspl | Solve the following coding problem using the programming language python:
One day, Chef prepared D brand new dishes. He named the i-th dish by a string Si. After the cooking, he decided to categorize each of these D dishes as special or not.
A dish Si is called special if it's name (i.e. the string Si) can be repres... | ```python
def is_subseq(x, y):
i = 0
for c in x:
while i < len(y) and y[i] != c: i += 1
if i == len(y): return False
i += 1
return True
for cas in xrange(input()):
a = raw_input()
n = len(a)
print 'YES' if n > 1 and (is_subseq(a[:n/2], a[n/2:]) or is_subseq(a[(n+1)/2:], ... | vfc_67101 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\naba\nabac\nabcd",
"output": "YES\nNO\nNO\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | dpc207 | Solve the following coding problem using the programming language python:
When
displaying a collection of rectangular windows, a critical step is determining
whether two windows overlap, and, if so, where on the screen the overlapping
region lies. Write a program to perform this function. Yo... | ```python
print "80 20 100 60"
print "No Overlap"
``` | vfc_67105 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n\n0 20 \n 100 120\n\n80 0 \n 500 60\n\n10 10 \n 20 20\n\n30 30 \n 40 40",
"output": "80 20 \n 100 60\n\nNo \n Overlap",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | jmi04 | Solve the following coding problem using the programming language python:
XOXO likes to play with numbers.So,given a number N help XOXO to find whether it is a fibonacci number or not.It won't be hard!
Input
First line contains T denoting the number of test case.
The next T line contains an integer N
Output
For ev... | ```python
list=[]
list.append(0)
list.append(1)
for i in range (2,5000):
list.append(list[i-1]+list[i-2])
t=int(raw_input())
while(t):
n=int(raw_input())
if n in list:
print "Yes"
else:
print "No"
t-=1
``` | vfc_67109 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n10",
"output": "Yes\nNo\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1\n10",
"output": "Yes\nNo\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.