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 | 687_B. Remainders Game | Solve the following coding problem using the programming language python:
Today Pari and Arya are playing a game called Remainders.
Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value <image>. There are n ancient numbers c1, c2, ..., cn and Pari has to tell Arya <image> ... | ```python
import sys
input=sys.stdin.readline
import math
n, k = map(int, input().split())
a = 1;
ar = list(map(int, input().split()))
for c in ar:
a *= math.gcd(k,c)//math.gcd(a,c)
#print(a,c)
if a==k:
print("Yes")
else:
print("No")
``` | vfc_47741 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 7\n2 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5\n2 3 5 12\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 70_A. Cookies | Solve the following coding problem using the programming language python:
Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square k × k in size, divided into blocks 1 × 1 in size and paint there the main diagonal together with cells, which lie above it, then the p... | ```python
import math
print(math.ceil(3**(int(input())-1))%1000003)
``` | vfc_47745 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "696\n",
"output": "695035\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n"... |
code_contests | verifiable_code | 730_H. Delete Them | Solve the following coding problem using the programming language python:
Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename... | ```python
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
a.append(input())
t=list(map(int,input().split()))
flag=0
x=len(a[t[0]-1])
for i in t:
b.append(a[i-1])
if len(a[i-1])!=x:
flag=1
break
s=''
if flag!=1:
for i in range(x):
l=b[0][i]
abc=0
for j in range(m):
if b[j][i]!=l:
abc=1... | vfc_47749 | {
"difficulty": "14",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\nab\nac\ncd\n1 2\n",
"output": "Yes\na?\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4\na\nb\nc\ndd\n1 2 3 4\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 754_C. Vladik and chat | Solve the following coding problem using the programming language python:
Recently Vladik discovered a new entertainment — coding bots for social networks. He would like to use machine learning in his bots so now he want to prepare some learning data for them.
At first, he need to download t chats. Vladik coded a scr... | ```python
import re
import copy
t = int(input())
for i in range(t):
n = int(input())
senderList = []
for x in input().split():
senderList.append(x)
m = int(input())
msg = [None] * m
resSenders = [None] * m
possibleSenders = []
for i in range(m):
possibleSenders.append(copy.copy(senderList))
for i in ra... | vfc_47753 | {
"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": "1\n2\nnetman vladik\n3\nnetman:how are you?\n?:wrong message\nvladik:im fine\n",
"output": "Impossible\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2\nVladik netman\n2\n?: Hello, Vla... |
code_contests | verifiable_code | 774_L. Bars | Solve the following coding problem using the programming language python:
Polycarp's workday lasts exactly n minutes. He loves chocolate bars and can eat one bar in one minute. Today Polycarp has k bars at the beginning of the workday.
In some minutes of the workday Polycarp has important things to do and in such min... | ```python
n, k = map(int, input().split())
s = input()
l, r = int(-1), int(n)
while r - l > 1:
m = (l+r)//2
c, p = 1, 0
cond = True
while p < n and c < k:
i = p + m + 1
while i >= p and (i >= n or s[i] == '1'):
i = i - 1;
if (i == p):
break
c = c ... | vfc_47757 | {
"difficulty": "19",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 3\n01010110\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n010\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input... |
code_contests | verifiable_code | 79_E. Security System | Solve the following coding problem using the programming language python:
Fox Ciel safely returned to her castle, but there was something wrong with the security system of the castle: sensors attached in the castle were covering her.
Ciel is at point (1, 1) of the castle now, and wants to move to point (n, n), which ... | vfc_47761 | {
"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": "20 492 11 4 8\n",
"output": "RRRRRRRRRRRRRRRRUUUUURUUUUURRUUUUUUUUU",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 5 1 2 2\n",
"output": "Impossible",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | 820_B. Mister B and Angle in Polygon | Solve the following coding problem using the programming language python:
On one quiet day all of sudden Mister B decided to draw angle a on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex n-gon (regular convex polygon with n sides)... | ```python
n, a=map(int, input().split())
alp = 180*(n-2)/n
minR=181
x=3
angle=0
for i in range (3, n+1):
angle = (180*(i-2) - alp*(i-2))/2
if abs(angle-a)<minR:
minR=abs(angle-a)
x=i
print("2 1", x)
``` | vfc_47765 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 68\n",
"output": "2 1 4\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 846_C. Four Segments | Solve the following coding problem using the programming language python:
You are given an array of n integer numbers. Let sum(l, r) be the sum of all numbers on positions from l to r non-inclusive (l-th element is counted, r-th element is not counted). For indices l and r holds 0 ≤ l ≤ r ≤ n. Indices in array are num... | ```python
n=int(input())
a=[5]+list(map(int,input().split()))
dp=[[[i,0] for i in range(n+1)] for j in range(4)]
end=n
indx_a,indx_b,indx_c=0,0,0
for i in range(1,n+1):
dp[0][i][1]=dp[0][i-1][1]+a[i]
dp[1][i][1]=max(dp[0][i-1][1],dp[1][i-1][1])-a[i]
dp[2][i][1]=max(dp[1][i-1][1],dp[2][i-1][1])+a[i]
dp[3... | vfc_47769 | {
"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": "1\n10000\n",
"output": "0 0 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 0 -1 0\n",
"output": "0 0 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 893_B. Beautiful Divisors | Solve the following coding problem using the programming language python:
Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of k + 1 consecutive ones, and then k consecutive zeroes.
Some examples of beautiful n... | ```python
a=[]
for i in range (1,9):
a.append((pow(2,i)-1)*pow(2,i-1))
#print(a)
b= int(input())
c=1
for i in range(8):
if(b%a[i] is 0):
c=a[i]
print(c)
``` | vfc_47777 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 914_G. Sum the Fibonacci | Solve the following coding problem using the programming language python:
You are given an array s of n non-negative integers.
A 5-tuple of integers (a, b, c, d, e) is said to be valid if it satisfies the following conditions:
* 1 ≤ a, b, c, d, e ≤ n
* (sa | sb) & sc & (sd ^ se) = 2i for some integer i
* sa &... | vfc_47781 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 2\n",
"output": "32\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n1 3 0 7 3 7 6 5 7 5\n",
"output": "1235424\n",
"type": "stdin_stdout"
},
{
"fn_name":... | |
code_contests | verifiable_code | 937_E. Lock Puzzle | Solve the following coding problem using the programming language python:
Welcome to another task about breaking the code lock! Explorers Whitfield and Martin came across an unusual safe, inside of which, according to rumors, there are untold riches, among which one can find the solution of the problem of discrete log... | ```python
n = int(input())
t = input()[:n]
s = input()[:n]
ops =[]
def shift(k, cur):
if k == 0:
return cur
return cur[:-k-1:-1] + cur [:-k]
def move_to_front(k, curst):
if k == n-1:
ops.append(1)
curst = curst[-1] +curst [:-1]
else:
ops.append(n-1)
ops.appen... | vfc_47785 | {
"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": "6\nabacbb\nbabcba\n",
"output": "18\n4 1 6 5 1 6 3 1 6 5 1 6 4 1 6 5 1 6 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\naba\nbba\n",
"output": "-1\n",
"type": "stdin_stdout"... |
code_contests | verifiable_code | 962_G. Visible Black Areas | Solve the following coding problem using the programming language python:
Petya has a polygon consisting of n vertices. All sides of the Petya's polygon are parallel to the coordinate axes, and each two adjacent sides of the Petya's polygon are perpendicular. It is guaranteed that the polygon is simple, that is, it do... | vfc_47789 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 7 16 3\n16\n0 0\n18 0\n18 6\n16 6\n16 1\n10 1\n10 4\n7 4\n7 2\n2 2\n2 6\n12 6\n12 12\n10 12\n10 8\n0 8\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "14 34 36 4\n62\n16... | |
code_contests | verifiable_code | 990_C. Bracket Sequences Concatenation Problem | Solve the following coding problem using the programming language python:
A bracket sequence is a string containing only characters "(" and ")".
A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original charac... | ```python
n = int(input())
arr = []
for i in range(n):
arr.append(input())
l ={}
r = {}
z=0
for i in arr:
s = 0
g = 0
for j in i:
if j =='(':
s+=1
else:
s-=1
if s <0:
g+=1
s=0
if s==0 and g==0:
z+=1
if s<=0 and g:
... | vfc_47793 | {
"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\n)\n()\n(\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n()\n()\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | anshal-and-season | Solve the following coding problem using the programming language python:
Anshal and his friends love watching TV series together,but Anshal has a habit of giving spoilers.In order to tackle this his friends anagrammed the list of the shows they were planning to watch.Somehow Anshal got hold of this list and started g... | ```python
A = raw_input()
b = raw_input()
A = [x for x in A.split(' ')]
a =A[0]
if len(a)!=len(b):
print "WRONG"
else:
aa=[0]*26
bb=[0]*26
for i in range(0,len(a)):
aa[ord(a[i])-65]=aa[ord(a[i])-65]+1
for i in range(0,len(b)):
bb[ord(b[i])-65]=bb[ord(b[i])-65]+1
f=0
for i in range(0,26):
if aa[i]!=bb[... | vfc_47797 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "FSRDIEN \nFRIENDS\n\nSAMPLE",
"output": "CORRECT",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "ABZZZZZZZZZZZZZZZZZZ\nAAAAAAAAAAAAABBBBBBB",
"output": "WRONG",
"type": "stdin_st... |
code_contests | verifiable_code | chandu-and-his-game | Solve the following coding problem using the programming language python:
After setting up the area and his toys. Chandu is up for playing his very first game. His first game is played on a N X N board with some initial stones placed on each cell. He can move each stone in all four direction i.e up,down, left or righ... | ```python
n,k=raw_input().split()
n,k=int(n), int(k)
x=map(int, raw_input().split())
y=map(int, raw_input().split())
p=0
for i in xrange(k):
if x[i]!=1 and x[i]!=n:
if x[i]-1<n-x[i]:
p+=x[i]-1
else:
p+=n-x[i]
if y[i]!=1 and y[i]!=n:
if y[i]-1<n-y[i]:
p+=y[i]-1
else:
p+=n-y[i]
print p
``` | vfc_47801 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n2 2 1 3\n2 2 3 1\n\nSAMPLE",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100000 344\n9489 61424 27955 42780 24866 60662 35985 72602 7178 66039 20165 80878 65110 53338... |
code_contests | verifiable_code | dipu-and-interesting-numbers-2 | Solve the following coding problem using the programming language python:
Little Dipu is a small kid and like all the other kids, he likes to play, but he plays with numbers (He is extraordinary you know). Now-a-days Dipu has some extra interest in odd numbers. So, he says that a number N is interesting if it has odd ... | ```python
import math
import decimal
'''
Created by anirudhmenon on 12/03/16
https://www.hackerearth.com/problem/algorithm/dipu-and-interesting-numbers-2/
'''
# number of test cases
t = int(raw_input())
while t > 0:
# Enter values for l and r
l, r = raw_input().split()
l, r = long(l), long(r)
print... | vfc_47805 | {
"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 3\n6 10\n\nSAMPLE",
"output": "1\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "11\n16 169\n36 255\n4 290\n24 441\n48 624\n80 1682\n101 15625\n122 1599\n226 577\n484 484\n1717 171... |
code_contests | verifiable_code | going-to-indiahacks | Solve the following coding problem using the programming language python:
As of now you have registered for IndiaHacks 2016 which is about to begin and you want to go to the venue to participate and the map is in the form of matrix. Consider an NXN matrix on which the possible moves from a given block (i,j), is either... | ```python
g = [1005 * [1]] + [[1] + 1004 * [0] for _ in range(1004)]
for i in range(1, 1005):
for j in range(1, 1005):
g[i][j] = (g[i][j-1] + g[i-1][j] + g[i-1][j-1]) % 1000000007
for _ in range(int(raw_input())):
a, b, c, d = map(int, raw_input().split())
print g[c-a][d-b]
``` | vfc_47809 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "144\n120 12 121 13\n120 12 121 14\n120 12 121 15\n120 12 121 16\n120 12 121 17\n120 12 121 18\n120 12 121 19\n120 12 121 20\n120 12 121 21\n120 12 121 22\n120 12 121 23\n120 12 121 24\n120 12 122 13\n120 12 122 14\n120 12 122 15\n1... |
code_contests | verifiable_code | library-boy | Solve the following coding problem using the programming language python:
View Russian Translation
Tom works in a public library in his town. Today, a completely new set of N books is arriving to the library and they have to be placed on shelves, which are initially empty.
A single shelf can contain at most 10 books... | ```python
T = int(raw_input())
import math
freq = {}
for t in xrange(T):
string1 = raw_input().strip()
freq[string1[0]] = freq.get(string1[0],0) + 1
result = 0
def custom_ceil(x):
return math.ceil(x/10.0)
custom = map(custom_ceil,freq.values())
print int(sum(custom))
``` | vfc_47813 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "14\nmountains\nmarvelous\nmornings\nfunctions\nmatch\ntopology\nmiracle\nminer\nmathematic\nmisery\nfastfouriertransform\nmother\nmajor\nmasterpiece\n\nSAMPLE",
"output": "4\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | roy-and-wooden-log-3 | Solve the following coding problem using the programming language python:
Roy has a wooden log (tree trunk) of length L units.
Since the log is too heavy for him to lift, he wants to cut it into pieces.
He can lift pieces of length 1 or 2 units.
He wonders in how many ways can he make such pieces of the wooden lo... | ```python
k = int(raw_input())
for c in range(k):
a = int(raw_input())
if a%2 == 0:
print a/2+1,a/2-1
else:
print (a-1)/2+1,(a-1)/2
``` | vfc_47825 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 \n3 \n4\n\nSAMPLE",
"output": "2 1\n3 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "19\n1\n10\n100\n1000\n10000\n100000\n1000000\n10000000\n100000000\n1000000000\n9\n99\n999\n9999\n9... |
code_contests | verifiable_code | subtract-and-multiply | Solve the following coding problem using the programming language python:
Tim likes Math. He likes it so much that he always brings his tablets with him and reads math e-books everywhere, even during parties.
Tim found an interesting exercise in one of the e-books he is reading. But you want him to join the party, so... | ```python
from math import sqrt
def is_perfect_square(y):
return sqrt(y).is_integer()
def f(d,p):
y = d*d + 4*p
if d < 0 or not is_perfect_square(y):
return 0
return 1 << (d>0) + (y>0)
for cas in xrange(input()):
d, p = map(int, raw_input().strip().split())
print f(d,p)
``` | vfc_47829 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2\n0 4\n-1 1\n\nSAMPLE",
"output": "4\n2\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2000\n317110 317111\n316190 632384\n1 12\n281788 563580\n1 6\n2 0\n749907 749908\n170484 34... |
code_contests | verifiable_code | vietnam-crisis | Solve the following coding problem using the programming language python:
In 1945, Vietnam had a huge famine because of which thousands of Vietnamese people were dying everyday.
The Soviet Union wanted to help the Vietnamese. They were regualrly sending food supplies to Vietnam. The
Vietnamese officials decided that t... | ```python
t=input()
while t!=0:
x=map(int,raw_input().split())
x.sort()
print " ".join(map(str,x))
t=input()
``` | vfc_47833 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "13\n78 12 60 78 68 37 57 40 49 13 94 91 89 \n0\n\nSAMPLE",
"output": "12 13 37 40 49 57 60 68 78 78 89 91 94",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "184\n7 8 6 4 6 7 3 10 2 3 8 1 10 ... |
code_contests | verifiable_code | p00033 Ball | Solve the following coding problem using the programming language python:
<image>
There is a container that is bifurcated as shown in the figure. Drop 10 balls numbered from 1 to 10 through the opening A of the container and place the balls in the left cylinder B or the right cylinder C. Since plate D can rotate lef... | ```python
n=int(input())
i=1
while i<=n:
ball=list(map(int,input().split()))
left=[0]
right=[0]
m=0
while True:
#終了条件
if m==10:
print("YES")
#print("left",left,"right",right)
break
#noの条件
if ball[m]<left[len(left)-1] and ball[m]<rig... | vfc_47877 | {
"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\n3 1 4 2 5 6 7 8 9 10\n10 9 8 7 6 5 4 3 2 1",
"output": "YES\nNO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3 1 4 2 5 6 7 8 9 10\n11 9 8 7 6 5 4 3 2 1",
"output": "YES\nNO\n"... |
code_contests | verifiable_code | p00165 Lottery | Solve the following coding problem using the programming language python:
The king of a country loves prime numbers and gambling. The unit of currency in this country is called prime. As of November 1, 2007, Prime's cross-yen rate was just prime at 9973, so the King is overjoyed. Subsidiary coins with 1/101 prime as o... | ```python
from itertools import accumulate
MAX = 1000000
is_prime = [1] * MAX
is_prime[0] = is_prime[1] = 0
for i in range(2, int(MAX ** (1 / 2)) + 1):
if is_prime[i]:
for j in range(i * i, MAX, i):
is_prime[j] = 0
acc_prime = list(accumulate(is_prime))
while True:
n = int(input())
if n == 0:
break... | vfc_47881 | {
"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\n5 0\n9 1\n3 10\n11 3\n1\n999983 20\n0",
"output": "5\n1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n5 -1\n9 1\n3 10\n11 3\n1\n999983 20\n0",
"output": "3\n1\n",
"type":... |
code_contests | verifiable_code | p00491 Pasta | Solve the following coding problem using the programming language python:
problem
You love pasta, and you make and eat pasta for dinner every day. You can make three types of pasta: tomato sauce, cream sauce, and basil sauce.
I decided to plan a dinner for N days. Choose one of the three types of pasta each day. How... | ```python
def main(dp, n, menue):
if menue == 0: m1, m2 = 1, 2
elif menue == 1: m1, m2 = 0, 2
elif menue == 2: m1, m2 = 0, 1
dp[n][menue][0] += sum(dp[n-1][m1]) + sum(dp[n-1][m2])
dp[n][menue][1] += dp[n-1][menue][0]
def run():
N, K = map(int, input().split())
dp = [[[0]*2 for _ in range(3)] for n in ran... | vfc_47889 | {
"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 3\n3 1\n1 1\n4 2",
"output": "6",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00677 Make KND So Fat | Solve the following coding problem using the programming language python:
Problem
KND is a student programmer at the University of Aizu. His neighbor is known to be very annoying. Neighbors find out that he is a sweet tooth and plan to add more sweetness than necessary to make him fat. To that end, your neighbor, you... | ```python
def main():
while True:
INF = 10 ** 10
s, d, m = map(int, input().split())
ws = []
ps = []
for _ in range(s):
input()
wplst = list(map(int, input().split()))
ws.append(wplst[::2])
ps.append(wplst[1::2])
fs = list(map(int, input().split()))
wlst = []
pl... | vfc_47893 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3 100\n2\n5 20 3 10\n2\n10 50 12 60\n2\n8 30 22 100\n0 1 2\n\n1 1 30\n1\n13 8\n0",
"output": "23 100\n13 8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3 100\n2\n5 20 3 10\n2\n10 50 1... |
code_contests | verifiable_code | p00820 Lagrange's Four-Square Theorem | Solve the following coding problem using the programming language python:
The fact that any positive integer has a representation as the sum of at most four positive squares (i.e. squares of positive integers) is known as Lagrange’s Four-Square Theorem. The first published proof of the theorem was given by Joseph-Loui... | vfc_47897 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n25\n2003\n211\n20007\n0",
"output": "1\n3\n48\n7\n738",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n8\n2003\n211\n20007\n0",
"output": "1\n1\n48\n7\n738\n",
"type": "stdi... | |
code_contests | verifiable_code | p00951 Three Kingdoms of Bourdelot | Solve the following coding problem using the programming language python:
Example
Input
Alice Bob
3
2
Alice Bob
Bob Clare
2
Bob Clare
Clare David
2
Clare David
David Alice
Output
No
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 ... | vfc_47901 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "Alice Bob\n3\n2\nAlice Bob\nBob Clare\n2\nBob Clare\nClare David\n2\nClare David\nDavid Alice",
"output": "No",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01220 Triangles | Solve the following coding problem using the programming language python:
There is a group that paints an emblem on the ground to invite aliens every year. You are a member of this group and you have to paint the emblem this year.
The shape of the emblem is described as follows. It is made of n regular triangles whos... | vfc_47909 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2\n3\n4\n5\n6\n0",
"output": "0.433013\n0.577350\n0.433013\n0.732051\n0.776798\n0.577350",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01354 The Castle | Solve the following coding problem using the programming language python:
The rabbit, who successfully defeated the ambushed enemy, succeeded in advancing the hero into the enemy's castle. When the hero released the cats trapped in the castle dungeon, some of them were the hero's. It will help me.
According to the ca... | ```python
import sys
def solve():
readline = sys.stdin.buffer.readline
write = sys.stdout.buffer.write
M, N = map(int, readline().split())
P = [list(map(float, readline().split())) + [0] for i in range(M)]
M2 = (1 << M)
dp = [[0]*(N+1) for i in range(M2)]
dp[0][N] = 1
for state in range(... | vfc_47913 | {
"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 3\n0.900 0.500 0.100\n0.500 0.500 0.500",
"output": "0.372500000000",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p01692 Dangerous Delivery | Solve the following coding problem using the programming language python:
F --Dangerous Delivery
Story
Person D had a serious mission. It is to deliver the next DAtaCoDer Regular Contest (DARC) D problem to Mr. Dhokudai, the president of DAtaCoDer. N cities are lined up in a straight line from city 1 where D's hideo... | vfc_47921 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2 2 1\n0 3 6\n1 1\n3 -2",
"output": "6",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4 2 1\n0 3 6\n1 1\n3 -2",
"output": "12\n",
"type": "stdin_stdout"
},
{
"... | |
code_contests | verifiable_code | p01836 Shortest Bridge | Solve the following coding problem using the programming language python:
Example
Input
200 500 800 500
3
400 0
450 500
400 1000
3
600 0
550 500
600 1000
Output
100 600
The input will be given via stdin and the output should be printed to stdout by your code.
Now solve the problem by providing the code. | vfc_47925 | {
"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": "200 500 800 500\n3\n400 0\n450 500\n400 1000\n3\n600 0\n550 500\n600 1000",
"output": "100 600",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p02258 Maximum Profit | Solve the following coding problem using the programming language python:
You can obtain profits from foreign exchange margin transactions. For example, if you buy 1000 dollar at a rate of 100 yen per dollar, and sell them at a rate of 108 yen per dollar, you can obtain (108 - 100) × 1000 = 8000 yen.
Write a program ... | ```python
n=int(input())
ans=-9999999999999
buy=int(input())
sell=buy
for i in range(1,n):
buy=min(sell,buy)
sell=int(input())
if(ans < sell-buy):
ans=sell-buy
print(ans)
``` | vfc_47937 | {
"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\n4\n3\n2",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n5\n3\n1\n3\n4\n3",
"output": "3",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p02406 Structured Programming | Solve the following coding problem using the programming language python:
In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these construct... | ```python
n = int(input())
for i in range (1,n+1):
if i%3 == 0 or str(i).find("3") != -1:
print(" %d" % (i),end="")
print()
``` | vfc_47941 | {
"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": "30",
"output": "3 6 9 12 13 15 18 21 23 24 27 30",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | bwknight | Solve the following coding problem using the programming language python:
How many ways are there to place a black and a white knight on an N * M chessboard such that they do not attack each other? The knights have to be placed on different squares. A knight can move two squares horizontally and one square vertically,... | ```python
#!/usr/bin/python
# coding: utf-8
t=int(raw_input())
for i in range(t):
n,m=raw_input().split(' ')
n=int(n)
m=int(m)
if(n>1 and m>1):
ans=((n*m) * (n*m-1)) - (4*((n-1)*(m-2) + (n-2)*(m-1))) #nm*nm -9nm +12m +12n -16
else:
if(n==1):
ans=m*(m-1)
else:
ans=n*(n-1)
print ans
'''
How many ... | vfc_47945 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 2\n2 3\n4 5",
"output": "12\n26\n312\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 2\n2 3\n2 5",
"output": "12\n26\n78\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | manip2 | Solve the following coding problem using the programming language python:
Okay. Before we begin, a hint : This one's taken from somewhere. Word to word. Google comes to mind, doesn't it? Here goes:
For the heck of it, we define a new sequence as the infinite sequence of all integers, in ascending order, that can rep... | ```python
# imports
import sys
import StringIO
import math
class Problem(object):
def __init__(self, reader):
self.reader = reader
def run(self):
test_cases = int(self.reader.readline().strip())
for test_case in range(test_cases):
lucky_number = 0
... | vfc_47957 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 \n1 \n2 \n3 \n9",
"output": "5\n25\n30\n630\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | puppygm | Solve the following coding problem using the programming language python:
Tuzik and his master Vanka are playing some unusual game. Initially there are two stacks of nuts. The first stack contains A nuts and the second contains B nuts. A player's move consists of two steps:
Choose one stack and eat it.
Split the oth... | ```python
T = int(raw_input())
while T > 0:
a = raw_input()
a = a.split(' ')
A = int(a[0])
B = int(a[1])
if A%2 !=0 and B%2 !=0:
print "Vanka"
else:
print 'Tuzik'
T = T - 1
``` | vfc_47961 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 1\n1 2",
"output": "Vanka\nTuzik\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 0\n1 2",
"output": "Tuzik\nTuzik\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | tkconvex | Solve the following coding problem using the programming language python:
Given n sticks' lengths, determine whether there is a solution to choose 2k out of them and use these 2k sticks to form two k-convex polygons (non-degenerated), namely, two convex polygons each has exactly k sticks as its sides, and every adjace... | ```python
from itertools import combinations
from collections import defaultdict
def small_j(sticks, cum, k):
for j in range(k - 1, len(sticks)):
i = j - k + 1
hyp = sticks[j]
rest = cum[j - 1] - cum[i] + sticks[i]
if rest > hyp:
return i, j
return None, None
de... | vfc_47965 | {
"difficulty": "4",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 3\n1 2 3 100 200 300",
"output": "No",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 3\n1 2 3 100 200 300",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | 1013_D. Chemical table | Solve the following coding problem using the programming language python:
Innopolis University scientists continue to investigate the periodic table. There are n·m known elements and they form a periodic table: a rectangle with n rows and m columns. Each element can be described by its coordinates (r, c) (1 ≤ r ≤ n, 1... | ```python
class UnionFind:
def __init__(self, n):
self.par = [-1]*n
self.rank = [0]*n
def Find(self, x):
if self.par[x] < 0:
return x
else:
self.par[x] = self.Find(self.par[x])
return self.par[x]
def Unite(self, x, y):
x = self.Fi... | vfc_47969 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3 6\n1 2\n1 3\n2 2\n2 3\n3 1\n3 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 5 3\n1 3\n1 1\n1 5\n",
"output": "2\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 1038_B. Non-Coprime Partition | Solve the following coding problem using the programming language python:
Find out if it is possible to partition the first n positive integers into two non-empty disjoint sets S_1 and S_2 such that:
gcd(sum(S_1), sum(S_2)) > 1
Here sum(S) denotes the sum of all elements present in set S and gcd means the[greatest ... | ```python
"""#N=int(input())
n,k=map(int,input().split())
s=input()
L=[0]*26
#s=[int(x) for x in input().split()]
for j in range(0,len(s)):
L[ord(s[j])-65]=L[ord(s[j])-65]+1
ans=1000000007
for j in range(0,k):
ans=min(ans,L[j])
ans=k*ans
print(ans)"""
import math
pre=[]
for i in range(0,45010):
pre.append((... | vfc_47973 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "Yes\n1 2\n2 1 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | 1082_D. Maximum Diameter Graph | Solve the following coding problem using the programming language python:
Graph constructive problems are back! This time the graph you are asked to build should match the following properties.
The graph is connected if and only if there exists a path between every pair of vertices.
The diameter (aka "longest shorte... | ```python
# -*- coding:utf-8 -*-
"""
created by shuangquan.huang at 12/3/18
"""
N = int(input())
D = [int(x) for x in input().split()]
if sum(D) < 2*(N-1):
print("NO")
else:
D = [0] + D
gt2 = [i for i in range(1, N+1) if D[i] > 1]
gt1 = [i for i in range(1, N + 1) if D[i] == 1]
ans = []
... | vfc_47981 | {
"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 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 4 1 1 1\n",
"output": "YES 2\n4\n1 2\n3 2\n4 2\n5 2\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 1101_F. Trucks and Cities | Solve the following coding problem using the programming language python:
There are n cities along the road, which can be represented as a straight line. The i-th city is situated at the distance of a_i kilometers from the origin. All cities are situated in the same direction from the origin. There are m trucks travel... | vfc_47985 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 6\n2 5 7 10 14 15 17\n1 3 10 0\n1 7 12 7\n4 5 13 3\n4 7 10 1\n4 7 10 1\n1 5 11 2\n",
"output": "55\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 10\n2 3 4 8 9 10 12 13 15 19\n3 8 3 ... | |
code_contests | verifiable_code | 112_D. Petya and Divisors | Solve the following coding problem using the programming language python:
Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:
You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi,... | ```python
import sys,collections as cc
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
def div(b):
an=[]
for i in range(1,int(b**0.5)+1):
if b%i==0:
an.append(i)
if i!=b//i:
an.append(b//i)
return an
n,=I()
ar=[]
vis=[-1]*(10**5+2)
for i in range(n):
a,b=I()
an=0
dv=div(a)
#... | vfc_47989 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n4 0\n3 1\n5 2\n6 2\n18 4\n10000 3\n",
"output": "3\n1\n1\n2\n2\n22\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 114_E. Double Happiness | Solve the following coding problem using the programming language python:
On the math lesson a teacher asked each pupil to come up with his own lucky numbers. As a fan of number theory Peter chose prime numbers. Bob was more original. He said that number t is his lucky number, if it can be represented as:
t = a2 + b... | vfc_47993 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 128000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 66\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7000 1... | |
code_contests | verifiable_code | 1172_A. Nauuo and Cards | Solve the following coding problem using the programming language python:
Nauuo is a girl who loves playing cards.
One day she was playing cards but found that the cards were mixed with some empty ones.
There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards ... | ```python
def index(l):
for i in range(n):
if l[i]>0:
j=(i+1)-l[i]
l1.append(j)
return(l1)
n=int(input())
hand=[int(g) for g in input().split()]
deck=[int(g) for g in input().split()]
if 1 in deck:
index2=deck.index(1)
l1=[]
buffer=deck[:]
buffer.sort()
l2=index(deck)
if len(... | vfc_47997 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n0 2 0\n3 0 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n0 2 0\n1 0 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | 118_B. Present from Lena | Solve the following coding problem using the programming language python:
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits s... | ```python
a=int(input())
x=a
w=[]
while a>=0:
b=[]
b.append(a)
for i in range(a):
b.append(str(a-1-i))
b.insert(0,(a-1-i))
b.insert(0,' '*(2*(x-a)))
w.append(b)
w.insert(0,b)
a=a-1
w.pop(x)
for j in w:
xx=str(j)
xxx=xx.replace(',','')
xxxx=xxx.replace("'",'')
... | vfc_48001 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": " 0\n 0 1 0\n 0 1 2 1 0\n0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": " 0\n 0 1 0\n0 1 ... |
code_contests | verifiable_code | 1209_A. Paint the Numbers | Solve the following coding problem using the programming language python:
You are given a sequence of integers a_1, a_2, ..., a_n. You need to paint elements in colors, so that:
* If we consider any color, all elements of this color must be divisible by the minimal element of this color.
* The number of used co... | ```python
n=int(input())
arr = list(map(int,input().split()))
elem = {}
arr.sort()
for i in arr:
f=0
for k in elem:
if i%k == 0:
elem[k]+=1
f=1
break
if not f:
elem[i] = 1
print(len(elem))
``` | vfc_48005 | {
"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\n10 2 3 5 4 2\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1227_G. Not Same | Solve the following coding problem using the programming language python:
You are given an integer array a_1, a_2, ..., a_n, where a_i represents the number of blocks at the i-th position. It is guaranteed that 1 ≤ a_i ≤ n.
In one operation you can choose a subset of indices of the given array and remove one block i... | vfc_48009 | {
"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": "5\n5 5 5 5 5\n",
"output": "6\n10111\n11011\n11101\n11110\n11111\n01111\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n5 1 1 1 1\n",
"output": "6\n10000\n11000\n10100\n10010\n100... | |
code_contests | verifiable_code | 1292_D. Chaotic V. | Solve the following coding problem using the programming language python:
[Æsir - CHAOS](https://soundcloud.com/kivawu/aesir-chaos)
[Æsir - V.](https://soundcloud.com/kivawu/aesir-v)
"Everything has been planned out. No more hidden concerns. The condition of Cytus is also perfect.
The time right now...... 00:01:12.... | ```python
from sys import stdin, stdout
prime = list()
factor = list()
count = list()
dist = list()
N = 0
def find_prime():
global prime
for i in range(2, 5010):
is_prime = True
for j in prime:
if i % j == 0:
is_prime = False
break
if is_prim... | vfc_48021 | {
"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": "4\n3 1 4 1\n",
"output": "6",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n3 1 4 4\n",
"output": "6",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | 1355_D. Game With Array | Solve the following coding problem using the programming language python:
Petya and Vasya are competing with each other in a new interesting game as they always do.
At the beginning of the game Petya has to come up with an array of N positive integers. Sum of all elements in his array should be equal to S. Then Petya... | ```python
n,s=map(int,input().split())
if 2*n<=s:
print("YES")
p=s//n
z=[]
for i in range(n):
z.append(p)
q=s-sum(z)
if q==0:
pass
else:
z[-1]+=q
print(*z)
print(s-1)
else:
print("NO")
``` | vfc_48033 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 8\n",
"output": "YES\n2 2 4\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 4\n",
"output": "YES\n4\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1440_A. Buy the String | Solve the following coding problem using the programming language python:
You are given four integers n, c_0, c_1 and h and a binary string s of length n.
A binary string is a string consisting of characters 0 and 1.
You can change any character of the string s (the string should be still binary after the change). Y... | ```python
for _ in range(int(input())):
n, c0, c1, h=map(int, input().split())
s=input()
print(s.count('0')*min(c0,c1+h)+s.count('1')*min(c1,c0+h))
``` | vfc_48049 | {
"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\n3 1 1 1\n100\n5 10 100 1\n01010\n5 10 1 1\n11111\n5 1 10 1\n11111\n12 2 1 10\n101110110101\n2 100 1 10\n00\n",
"output": "3\n52\n5\n10\n16\n22\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1514_B. AND 0, Sum Big | Solve the following coding problem using the programming language python:
Baby Badawy's first words were "AND 0 SUM BIG", so he decided to solve the following problem. Given two integers n and k, count the number of arrays of length n such that:
* all its elements are integers between 0 and 2^k-1 (inclusive);
* ... | ```python
mod=10**9+7
for _ in range(int(input())):
n,k=map(int,input().split())
print((n**k)%(mod))
``` | vfc_48061 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 2\n100000 20\n",
"output": "\n4\n226732710\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 169_A. Chores | Solve the following coding problem using the programming language python:
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter — its complexity. The complexity of the i-th chore equals... | ```python
n, a, b=map(int, input().split())
l=list(map(int, input().split()))
l.sort()
print(l[-a]-l[-a-1])
``` | vfc_48069 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2 3\n6 2 3 100 1\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 3 4\n1 1 9 1 1 1 1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | 189_D. AlgoRace | Solve the following coding problem using the programming language python:
PMP is getting a warrior. He is practicing a lot, but the results are not acceptable yet. This time instead of programming contests, he decided to compete in a car racing to increase the spirit of victory. He decides to choose a competition that... | ```python
from sys import stdin
def fast2():
import os, sys, atexit
from cStringIO import StringIO as BytesIO
# range = xrange
sys.stdout = BytesIO()
atexit.register(lambda: os.write(1, sys.stdout.getvalue()))
return BytesIO(os.read(0, os.fstat(0).st_size)).readline
input=fast2()
rints = lam... | vfc_48073 | {
"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 3\n0 7 3 3\n8 0 10 5\n1 1 0 4\n8 9 2 0\n0 3 3 9\n7 0 4 9\n3 8 0 4\n4 8 9 0\n2 3 3\n2 1 3\n1 2 2\n",
"output": "4\n5\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2 3\n0 1 5 6\n2... |
code_contests | verifiable_code | 261_B. Maxim and Restaurant | Solve the following coding problem using the programming language python:
Maxim has opened his own restaurant! The restaurant has got a huge table, the table's length is p meters.
Maxim has got a dinner party tonight, n guests will come to him. Let's index the guests of Maxim's restaurant from 1 to n. Maxim knows the... | ```python
import math
n = int(input())
a = [int(x) for x in input().split()]
p = int(input())
sum=0;
for x in range(n):
sum+=a[x]
if(sum<=p):
print(n)
else:
ans=0
for i in range(n):
dp = [[[0 for z in range(55)] for y in range(55)] for x in range(55)]
dp[-1][0][0]=1
for j in range(n):
if(j==i):
for ... | vfc_48085 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 3\n3\n",
"output": "1.3333333333\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "23\n2 1 2 1 1 1 2 2 2 1 1 2 2 1 1 1 2 1 2 2 1 1 1\n37\n",
"output": "23.0000000000\n",
"... |
code_contests | verifiable_code | 285_B. Find Marble | Solve the following coding problem using the programming language python:
Petya and Vasya are playing a game. Petya's got n non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to n from left to right. Note that the positions are indexed but the glasses are not.
First Pe... | ```python
from collections import Counter
import string
import math
import sys
def array_int():
return [int(i) for i in sys.stdin.readline().split()]
def vary(arrber_of_variables):
if arrber_of_variables==1:
return int(sys.stdin.readline())
if arrber_of_variables>=2:
return map(int,sys.stdin... | vfc_48089 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3 4\n1 2 3 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3 3\n4 1 3 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 30_B. Codeforces World Finals | Solve the following coding problem using the programming language python:
The king Copa often has been reported about the Codeforces site, which is rapidly getting more and more popular among the brightest minds of the humanity, who are using it for training and competing. Recently Copa understood that to conquer the ... | ```python
from itertools import *
import sys
m=[32,29,32,31,32,31,32,32,31,32,31,32]
s,t=[map(int,input().split('.')) for _ in range(2)]
g=False
a,b,c=s
for d,e,f in permutations(t):
g|=b<13 and e<13 and a<m[b-1]+(b==2)*(c%4==0)and d<m[e-1]+(e==2)*(f%4==0)and(c-f>18 or(c-f==18 and(b>e or(b==e and(a>=d)))))
print(["NO"... | vfc_48093 | {
"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": "20.10.20\n10.02.30\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 332_E. Binary Key | Solve the following coding problem using the programming language python:
Let's assume that p and q are strings of positive length, called the container and the key correspondingly, string q only consists of characters 0 and 1. Let's take a look at a simple algorithm that extracts message s from the given container p:... | vfc_48097 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "abacaba\naba\n6\n",
"output": "100001\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "abacaba\naba\n3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": ... | |
code_contests | verifiable_code | 355_E. Vasya and Beautiful Arrays | Solve the following coding problem using the programming language python:
Vasya's got a birthday coming up and his mom decided to give him an array of positive integers a of length n.
Vasya thinks that an array's beauty is the greatest common divisor of all its elements. His mom, of course, wants to give him as beaut... | ```python
n, k = map(int, raw_input().split())
v = list(map(int, raw_input().split()))
sol, stop = min(v), False
while not stop:
stop = True
for x in v:
while x % sol > k:
sol -= 1
stop = False
print sol
``` | vfc_48101 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n8 21 52 15 77\n",
"output": "7\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 379_F. New Year Tree | Solve the following coding problem using the programming language python:
You are a programmer and you have a New Year Tree (not the traditional fur tree, though) — a tree of four vertices: one vertex of degree three (has number 1), connected with three leaves (their numbers are from 2 to 4).
On the New Year, program... | vfc_48105 | {
"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\n2\n3\n4\n8\n5\n",
"output": "3\n4\n4\n5\n6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n3\n5\n6\n10\n7\n",
"output": "3\n4\n4\n5\n6\n",
"type": "stdin_stdout"
},
... | |
code_contests | verifiable_code | 3_B. Lorry | Solve the following coding problem using the programming language python:
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space ... | ```python
n, v = map(int, input().split())
a = []
b = []
for i in range(n):
typ, carry = map(int, input().split())
if typ == 1:
a.append([carry, i + 1])
else:
b.append([carry, i + 1])
a.sort(reverse=True)
b.sort(reverse=True)
for i in range(1, len(a)):
a[i][0] += a[i - 1][0]
for i in ra... | vfc_48109 | {
"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": "3 2\n1 2\n2 7\n1 3\n",
"output": "7\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20 19\n2 47\n1 37\n1 48\n2 42\n2 48\n1 38\n2 47\n1 48\n2 47\n1 41\n2 46\n1 28\n1 49\n1 45\n2 34\n1 43... |
code_contests | verifiable_code | 44_G. Shooting Gallery | Solve the following coding problem using the programming language python:
Berland amusement park shooting gallery is rightly acknowledged as one of the best in the world. Every day the country's best shooters master their skills there and the many visitors compete in clay pigeon shooting to win decent prizes. And the ... | vfc_48117 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 4 1 4 1\n2 5 2 6 2\n4\n0 0\n3 3\n4 5\n3 5\n",
"output": "0\n1\n2\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 5 2 4 3\n2 4 3 6 2\n1 3 1 2 1\n1 5 1 5 4\n6\n2 2\n3 3\n2 2\n1 ... | |
code_contests | verifiable_code | 471_C. MUH and House of Cards | Solve the following coding problem using the programming language python:
Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev decided to build a house of cards. For that they've already found a hefty deck of n playing cards. Let's describe the house they want to mak... | ```python
print((lambda n: len([1 for x in range(1, int((-1 + (24 * n + 25) ** 0.5) / 6) + 1) if not (n - 2 * x) % 3]))(int(input())))
``` | vfc_48121 | {
"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": "13\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "153\n",
... |
code_contests | verifiable_code | 495_D. Obsessive String | Solve the following coding problem using the programming language python:
Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following problem. Given a string... | ```python
def main():
s, t = input(), input()
n, m = len(s), len(t)
t = '$'.join((t, s))
p = [0]
k = 0
for i in range(1, n + m + 1):
while k and t[k] != t[i]:
k = p[k - 1]
if t[k] == t[i]:
k += 1
p.append(k)
ans = [0] * n
sums = [0] * (n + ... | vfc_48125 | {
"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": "ababa\naba\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 51_B. bHTML Tables Analisys | Solve the following coding problem using the programming language python:
In this problem is used an extremely simplified version of HTML table markup. Please use the statement as a formal document and read it carefully.
A string is a bHTML table, if it satisfies the grammar:
TABLE ::= <table>RO... | ```python
#amros
import sys
R=str.replace
s=R(R(R(R(R(''.join(sys.stdin.readlines()),'\n',''),'</tr>',''),'<tr>',''),'><',' '),'>','').split()[1:]
def f(k):
r=0;a=[]
while s[0]!='/table':
if s[0]=='table':
s.pop(0);a+=f(k+1)
else:r+=s[0]=='td';s.pop(0)
s.pop(0)
return[r]+a
print(' '.join(map(str,sorted(f(1))... | vfc_48129 | {
"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": "<table><tr><td></td></tr></table>\n",
"output": "\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "<table>\n<tr>\n<td>\n<table>&l... |
code_contests | verifiable_code | 546_C. Soldier and Cards | Solve the following coding problem using the programming language python:
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then the... | ```python
'''input
4
2 1 3
2 4 2
'''
n = int(input())
a = tuple(map(int, input().split()))[1:]
b = tuple(map(int, input().split()))[1:]
c = 0
s = set()
res = 0
while (a, b) not in s:
if not a:
res = 2
break
if not b:
res = 1
break
s.add((a, b))
x, y = a[0], b[0]
... | vfc_48133 | {
"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 1 3\n2 4 2\n",
"output": "6 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2\n2 1 3\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 572_E. CNF 2 | Solve the following coding problem using the programming language python:
'In Boolean logic, a formula is in conjunctive normal form (CNF) or clausal normal form if it is a conjunction of clauses, where a clause is a disjunction of literals' (cited from https://en.wikipedia.org/wiki/Conjunctive_normal_form)
In the ot... | vfc_48137 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n1 1\n1 2\n3 -1 -2 3\n1 -3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 6\n2 1 2\n3 1 -2 3\n4 -3 5 4 6\n2 -6 -4\n1 5\n",
"output": "YES\n100010\n",
"... | |
code_contests | verifiable_code | 594_C. Edo and Magnets | Solve the following coding problem using the programming language python:
Edo has got a collection of n refrigerator magnets!
He decided to buy a refrigerator and hang the magnets on the door. The shop can make the refrigerator with any size of the door that meets the following restrictions: the refrigerator door mus... | ```python
from sys import*
#
def check(u, d, l, r):
used = [pointsx[i][1] for i in range(l)]
used += [pointsx[-1 - i][1] for i in range(r)]
used += [pointsy[i][1] for i in range(u)]
used += [pointsy[-1 - i][1] for i in range(d)]
if len(set(used)) > k:
return DOHERA
dx = pointsx[-1 - r][0... | vfc_48141 | {
"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": "4 1\n1 1 2 2\n1 9 2 10\n9 9 10 10\n9 1 10 2\n",
"output": "64\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n1 1 2 2\n2 2 3 3\n3 3 4 4\n",
"output": "1\n",
"type": "stdin... |
code_contests | verifiable_code | 616_A. Comparing Two Long Integers | Solve the following coding problem using the programming language python:
You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal.
The input size is very large so don't use the reading of symbols one by one. Instead of tha... | ```python
a = input()
b = input()
if len(a)>len(b):
gap = len(a)-len(b)
new = ''
for _ in range(gap):
new+='0'
b = new + b
elif len(b)>len(a):
gap = len(b) - len(a)
new = ''
for _ in range(gap):
new+='0'
a = new + a
for i in range(0,len(a)):
if(a[i]>b[i]):
pri... | vfc_48145 | {
"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": "11\n10\n",
"output": ">\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 635_B. Island Puzzle | Solve the following coding problem using the programming language python:
A remote island chain contains n islands, labeled 1 through n. Bidirectional bridges connect the islands to form a simple cycle — a bridge connects islands 1 and 2, islands 2 and 3, and so on, and additionally a bridge connects islands n and 1. ... | ```python
n=int(input())
a=input().split()
b=input().split()
a.remove('0')
b.remove('0')
k=a.index(b[0])
a=a[k:]+a[:k]
if a==b:
print('YES')
else:
print('NO')
# Made By Mostafa_Khaled
``` | vfc_48149 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 0 2\n2 0 1\n",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 2 3 0\n0 3 2 1\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": nu... |
code_contests | verifiable_code | 664_A. Complicated GCD | Solve the following coding problem using the programming language python:
Greatest common divisor GCD(a, b) of two positive integers a and b is equal to the biggest integer d such that both integers a and b are divisible by d. There are many efficient algorithms to find greatest common divisor GCD(a, b), for example, ... | ```python
a,b=map(int,input().split())
print(a) if a==b else print(1)
``` | vfc_48153 | {
"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": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n",
"output": "61803398874989484820458683436563811772030917980576\n",
"type": "stdin_stdout"
},
{
"fn_n... |
code_contests | verifiable_code | 688_D. Remainders Game | Solve the following coding problem using the programming language python:
Today Pari and Arya are playing a game called Remainders.
Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value <image>. There are n ancient numbers c1, c2, ..., cn and Pari has to tell Arya <image> ... | ```python
from math import *
n,k=map(int,input().split())
arr=list(map(int,input().split()))
flag=0
if(k==1):
print('Yes')
else:
arr1=[]
temp=k
for i in range(2,k+1):
if(temp%i==0):
cnt=0
while(temp%i==0):
cnt+=1
temp=temp//i
ar... | vfc_48157 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 5\n2 3 5 12\n",
"output": "Yes",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 710_C. Magic Odd Square | Solve the following coding problem using the programming language python:
Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd.
Input
The only line contains odd integer n (1 ≤ n ≤ 49).
Output
Print n lines with n integers. All the integers should ... | ```python
n = int(input())
if n==1:
print(1)
exit()
odd = 1
evn = 2
table = [[0 for i in range(n)] for i in range(n)]
#(x,y) x row, y col
for x in range(n):
for y in range(n):
x1 = min(x, n-1-x)
if y < (n - 1)/2-x1 or y > (n - 1)/2+x1: #even con
table[x][y] = ev... | vfc_48161 | {
"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": "1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "2 1 4\n3 5 7\n6 9 8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | 776_F. Sherlock's bet to Moriarty | Solve the following coding problem using the programming language python:
Sherlock met Moriarty for a final battle of wits. He gave him a regular n sided convex polygon. In addition to it, he gave him certain diagonals to form regions on the polygon. It was guaranteed that the diagonals did not intersect in interior p... | vfc_48173 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 1\n1 3\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 3\n1 3\n1 4\n1 5\n",
"output": "2 1 2 3\n",
"type": "stdin_stdout"
},
{
"fn_name": n... | |
code_contests | verifiable_code | 801_B. Valued Keys | Solve the following coding problem using the programming language python:
You found a mysterious function f. The function takes two strings s1 and s2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function f is another string of the same length. The i-th ... | ```python
x = input()
y = input()
z = ''
for i in range(len(x)):
if x[i] < y[i]:
print("-1")
exit(0)
else:
z = z + y[i]
print(z)
``` | vfc_48177 | {
"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": "ab\naa\n",
"output": "aa\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "ab\nba\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | 847_D. Dog Show | Solve the following coding problem using the programming language python:
A new dog show on TV is starting next week. On the show dogs are required to demonstrate bottomless stomach, strategic thinking and self-preservation instinct. You and your dog are invited to compete with other participants and naturally you wan... | ```python
# using the min-heap
from heapq import heappush,heappop
bowels,Time = map(int,input().split())
myLine = [-int(b) for b in input().split()]
gulp = []; eat = 0
for i in range(1,min(bowels+1,Time)):
# redundant (now that i look at it. the min does that already)
if i >= Time:
break
while gulp... | vfc_48185 | {
"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": "1 1\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 5\n1 5 3\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 868_F. Yet Another Minimization Problem | Solve the following coding problem using the programming language python:
You are given an array of n integers a1... an. The cost of a subsegment is the number of unordered pairs of distinct indices within the subsegment that contain equal elements. Split the given array into k non-intersecting non-empty subsegments s... | ```python
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
a = [0]+list(map(int, input().split()))
buc = [0]*(n+1)
dp_p = [n*(n-1)//2]*(n+1)
dp_c = [0]*(n+1)
dp_p[0] = 0
buc[a[1]] = 1
L = R = 1
ans = 0
def cal(l, r):
global L, R, ans
while L < l:
ans += 1-buc[a[L]]
buc[a[... | vfc_48189 | {
"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": "10 2\n1 2 1 2 1 2 1 2 1 2\n",
"output": "8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13 3\n1 2 2 2 1 2 1 1 1 2 2 1 1\n",
"output": "9",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 894_C. Marco and GCD Sequence | Solve the following coding problem using the programming language python:
In a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality and then disappeared with the wind of time.
When he woke up, he only remembered that the key was a sequence of positive integers of some l... | ```python
from math import gcd
m = int(input())
s = [int(i) for i in input().split()]
gc = s[0]
for i in range(0,m):
gc = gcd(gc,s[i])
if gc not in s:
print(-1)
else:
print(2*m-1)
ans = [s[0]]*(2*m-1)
cur = 1
for i in range(2,2*m-1,2):
ans[i] = s[cur]
cur += 1
print(*ans)
""... | vfc_48193 | {
"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": "4\n2 4 6 12\n",
"output": "8\n2 2 4 2 6 2 12 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name":... |
code_contests | verifiable_code | 915_F. Imbalance Value of a Tree | Solve the following coding problem using the programming language python:
You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x, y) as the difference between maximum and minimum value of ai on a simple path connecting ve... | ```python
import sys
range = xrange
input = raw_input
# returns order such that A[order[i]] <= A[order[i + 1]]
def sqrtsorted(A, maxval = 10**6):
mask = 2**10 - 1
blocks1 = [[] for _ in range(mask + 1)]
blocks2 = [[] for _ in range(mask + 1)]
for i in range(len(A)):
blocks1[A[i] & mask].append(... | vfc_48197 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 2 3 1\n1 2\n1 3\n1 4\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n4 2 3 1\n1 2\n1 3\n1 4\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 938_G. Shortest Path Queries | Solve the following coding problem using the programming language python:
You are given an undirected connected graph with weighted edges. The length of some path between two vertices is the bitwise xor of weights of all edges belonging to this path (if some edge is traversed more than once, then it is included in bit... | vfc_48201 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5\n1 2 3\n2 3 4\n3 4 5\n4 5 6\n1 5 1\n5\n3 1 5\n1 1 3 1\n3 1 5\n2 1 5\n3 1 5\n",
"output": "1\n1\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5\n1 2 3\n2 3 8\n3 4 5\n4 5 6\n1 5 1... | |
code_contests | verifiable_code | 964_B. Messages | Solve the following coding problem using the programming language python:
There are n incoming messages for Vasya. The i-th message is going to be received after ti minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases by B each minute (it can become negat... | ```python
n,a,b,c,t = map(int,input().split())
arr = list()
arr = map(int,input().split())
Sum = int(0)
for num in arr:
Sum += t - num
ans = n * a
if b >= c:
print(ans)
else:
print(ans + Sum * int(c - b))
``` | vfc_48205 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 5 5 3 5\n1 5 5 4\n",
"output": "20\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 991_C. Candies | Solve the following coding problem using the programming language python:
After passing a test, Vasya got himself a box of n candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself.
This means t... | ```python
import sys
import math
n = int(input())
l = 1
r = 2*n
while(l < r):
candies = n
numeaten = 0
k = (l+r)//2
# print(k)
while(candies > 0):
if candies > k:
numeaten += k
candies -= k
else:
numeaten += candies
break
c = ... | vfc_48209 | {
"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": "68\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "505050505\n",
"output": "19827992\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
code_contests | verifiable_code | archith-and-parity | Solve the following coding problem using the programming language python:
Archith was a making noise in digital logic class.Sir was very frustrated by the behaviour of Archith. Sir asked archith to meet him in staff room. As archith reached staff room sir gave a smile and asked to complete this assignment in one day i... | ```python
testcases = raw_input()
for i in range(int(testcases)):
decimal_number = raw_input()
if str(bin(int(decimal_number))[2 :]).count('1') % 2 == 0:
print "even"
else:
print "odd"
``` | vfc_48213 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n12\n14\n\nSAMPLE",
"output": "even\nodd\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20\n212245523\n546843625\n456431356\n546463364\n584651321\n352145896\n53\n2\n32\n32\n32692\n32646... |
code_contests | verifiable_code | divisibility-test | Solve the following coding problem using the programming language python:
Rakesh is very good in divisibility. He can easily tell the number is divisible by the given number or not. To make him work harder his teacher changed the question slightly. He will give the number and the other number with which the first numb... | ```python
for _ in range(int(raw_input())):
li=[]
m=raw_input()
div=int(raw_input())
x,y=map(int,raw_input().split())
x-=1
y-=1
m=m[x:y+1]
#print(m)
for i in range(y-x+1):
for j in range(i+1,y-x+2):
if int(m[i:j])%div==0:
li.append(m[i:j])
prin... | vfc_48221 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1254756\n4\n1 5\n54789623\n6\n2 6\n\nSAMPLE",
"output": "2\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1254756\n4\n1 4\n54789623\n6\n2 6\n\nSAMPLE",
"output": "2\n4\n",
... |
code_contests | verifiable_code | goodies | Solve the following coding problem using the programming language python:
HackerEarth has sponsored a lot of goodies for the 'Google Week' to be held at Sir MVIT. The goodies are in the form of boxes. Each box has a surprise value associated with it.
To carry the boxes from his hostel to the venue, Karan puts the box... | ```python
'''
Easy Goodies
'''
def fun_wid_code():
tc=int(raw_input())
while(tc):
num=[0]*10001
n=int(raw_input())
while(n):
k=int(raw_input())
num[k]+=1
n-=1
num.sort()
num.reverse()
print num[0]
tc-=1
fun_wid_code()
``... | vfc_48225 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3\n1\n2\n3\n4\n2\n2\n2\n2\n3\n11\n111\n1111\n\nSAMPLE",
"output": "1\n4\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n8\n1\n2\n3\n3\n3\n5\n5\n5\n6\n1\n2\n3\n4\n5\n6",
"out... |
code_contests | verifiable_code | little-fajlu-and-aoe-2 | Solve the following coding problem using the programming language python:
Little Fajlu and Laal Baadshah are extremely good, and passionate Age of Empires 2 players. They're crazy about the game, and the passion they display for the game, if displayed for their semester exams - will make them top the university, even.... | ```python
def defeat_power(food,gold,s,p,c,tp):
sam = 0
temp = -1
res = -1
while sam*100 <= food:
pal = 0
while ((pal*125 + 100*sam) <= food) and (pal*50<=gold):
food_left = (food-100*sam - 125*pal)
gold_left = (gold-50*pal)
cha = min(food_left/50,gol... | vfc_48229 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n389 130 16 13 18 24\n\nSAMPLE",
"output": "42",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "43\n7878 11534 994 594 238 1250\n907 25648 745 699 879 2683\n5983 18415 152 649 329 2446\n995... |
code_contests | verifiable_code | moriartys-deceit | Solve the following coding problem using the programming language python:
The evil mastermind, Moriarty, strikes again! He sent Sherlock an image of a wall, with N integers painted on it. Sherlock is asked to solve the puzzle and find the next clue.
Sherlock knows that Moriarty is a deceitful person. All the numbers ... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
def gcd(a,b) :
if b == 0 :
return a
else :
return gcd(b,a%b)
t = int(raw_input())
while t>0 :
t -= 1
n,m = map(int, raw_input().split())
s = []
c=0
ip1=map(int,... | vfc_48233 | {
"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 4\n2 5 8 3 13\n\nSAMPLE",
"output": "5 3 13 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n5 7\n2 5 8 3 13\n\nSAMPLE",
"output": "2 5 8 3 13 \n",
"type": "stdin_stdou... |
code_contests | verifiable_code | power-set-game-3 | Solve the following coding problem using the programming language python:
Let there be a set of size N.
Power set of a set S, denoted by P(S) is the set of all subsets of S, including the empty set and the S itself.
Set A is said to be subset of set B if all elements of A are contained in B. Empty set is always a su... | ```python
t = int(raw_input())
m = 10**9 + 7
for i in range(t):
n = int( raw_input() )
print ( pow( 4 , n , m ) % m - pow( 2 , n , m ) % m ) % m
``` | vfc_48237 | {
"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\n\nSAMPLE",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2\n\nSAMOLE",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | sample-1 | Solve the following coding problem using the programming language python:
A notice on the notice board read:
“Is there an end to it?
While the number remains greater than one, if 2 divides the number completely, divide the number by 2; while the number remains greater than 1, if the number is not divisible by 2 , mu... | ```python
import math
n = input()
if n>=1:
t = math.log(n)/math.log(2)
if n==int(n):
print "Yes"
else:
print "No"
else:
print "No"
``` | vfc_48241 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "17\n\nSAMPLE",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "16... |
code_contests | verifiable_code | sum-of-products | Solve the following coding problem using the programming language python:
Given a number N, find the sum of all products x*y such that N/x = y (Integer Division).
Since, the sum can be very large, please output this modulo 1000000007.
Input Format:
The first line of input file contains an integer T, the number of te... | ```python
from math import sqrt
t = int(raw_input())
def summ(x):
return x*(x+1)/2
for i in range(t):
n = int(raw_input())
ans = 0
sq = int(sqrt(n))
for i in range(1,sq+1):
r = n//i
l = n//(i+1)
ans += i*r
if(l >= sq):
ans += i*(summ(r)-summ(l))
ans %= 1000000007
print ans
``` | vfc_48245 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n4\n6\n\nSAMPLE",
"output": "4\n15\n33",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3\n4\n6\n\nSAMPLE",
"output": "8\n15\n33\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | weird-friends | Solve the following coding problem using the programming language python:
Hansa loves dancing and so do her friends. But she has some pretty weird friends. Like this one friend of hers, Jack, jumps forward while dancing. The dance floor is of finite length (L) and there are many people dancing on it. During each song,... | ```python
n, a, b= map(int, raw_input().split())
# calculate days_nights for n-b distance travelling
# adjust it
print (n-b)/(a-b) + (1 if (n-b)%(a-b) else 0)
``` | vfc_48249 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 5 1\n\nSAMPLE",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00040 Affine Cipher | Solve the following coding problem using the programming language python:
One of the simple ciphers is the affine cipher. First, replace the letters a to z with the numbers a = 0, b = 1, c = 2, ..., x = 23, y = 24, z = 25 and 0 to 25. Then replace the original alphabet with the following formula.
$ F (\ gamma) = (\ a... | ```python
z='abcdefghijklmnopqrstuvwxyz'
for _ in[0]*int(input()):
e=input()
for i in range(1,26,2):
for j in range(26):
a=''
for c in e:
if c in z:a+=z[(z.index(c)*i+j)%26]
else:a+=c
if'that'in a or'this'in a:print(a);break
``` | vfc_48293 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\ny eazqyp pnop pngtg ye obmpngt xmybp mr lygw",
"output": "i submit that there is another point of view",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\nx eazqyp pnop pngtg ye obmpngt xm... |
code_contests | verifiable_code | p00501 Signboard | Solve the following coding problem using the programming language python:
problem
JOI decided to make a signboard for the store.
There are N old signboards with letters written at equal intervals. JOI makes a sign by erasing some letters from the old sign. I want the remaining characters to be the name of the store,... | ```python
n = int(input())
name = input()
length = len(name)
def check(ss):
ind = 0
end = len(ss)
while ind < end:
while ind < end and ss[ind] != name[0]:
ind += 1
for i in range(100):
j1 = ind
j2 = 0
while j1 < end and j2 < length and ss[j1] == name[j2]:
j1 += i
... | vfc_48305 | {
"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\nbar\nabracadabra\nbear\nbar\nbaraxbara",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\nbar\nabracadabra\nbear\nbar\nbbraxbara",
"output": "3\n",
"type": "std... |
code_contests | verifiable_code | p00685 Board Arrangements for Concentration Games | Solve the following coding problem using the programming language python:
You have to organize a wedding party. The program of the party will include a concentration game played by the bride and groom. The arrangement of the concentration game should be easy since this game will be played to make the party fun.
We ha... | ```python
# AOJ 1103: Board Arrangements for Concentration Gam...
# Python3 2018.7.14 bal4u
def combi(k):
global ans
if k == 9:
ans += 1
return
for y in range(4):
for x in range(4):
if arr[y][x]: continue
arr[y][x] = k
for i in range(4):
x2, y2 = x + a[i<<1], y + a[(i<<1)+1]
if x2 < 0 or x2 >... | vfc_48309 | {
"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 1 -1 1 1 1 1 2\n1 0 2 1 2 2 3 3\n5",
"output": "2\n15",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-2 1 -1 1 1 1 1 2\n1 0 2 1 2 2 0 3\n5",
"output": "2\n29\n",
"type": "std... |
code_contests | verifiable_code | p00827 The Balance | Solve the following coding problem using the programming language python:
Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine.
For example, to measure 200mg of aspirin using 300mg weights and 700mg weights, she can put one 700mg weight on the side of the medicine and thre... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(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 in ... | vfc_48313 | {
"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": "700 300 200\n500 200 300\n500 200 500\n275 110 330\n275 110 385\n648 375 4002\n3 1 10000\n0 0 0",
"output": "1 3\n1 1\n1 0\n0 3\n1 1\n49 74\n3333 1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inp... |
code_contests | verifiable_code | p00958 Parallel Lines | Solve the following coding problem using the programming language python:
Problem B Parallel Lines
Given an even number of distinct planar points, consider coupling all of the points into pairs. All the possible couplings are to be considered as long as all the given points are coupled to one and only one other point... | ```python
m = int(input())
P = [list(map(int, input().split())) for i in range(m)]
s = set()
for i in range(m):
xi, yi = P[i]
for j in range(i+1, m):
xj, yj = P[j]
u = xj - xi; v = yj - yi
for x, y in s:
if x * v == y * u:
break
else:
s.add... | vfc_48317 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 1073741824,
"problem_url": null,
"time_limit": "{'seconds': 10, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0 0\n1 1\n0 2\n2 4",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 0\n1 1\n0 2\n2 5",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name":... |
code_contests | verifiable_code | p01091 Complex Paper Folding | Solve the following coding problem using the programming language python:
Complex Paper Folding
Dr. G, an authority in paper folding and one of the directors of Intercultural Consortium on Paper Crafts, believes complexity gives figures beauty. As one of his assistants, your job is to find the way to fold a paper to ... | vfc_48321 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0 0\n10 0\n10 5\n0 5\n3\n5 0\n17 3\n7 10\n4\n0 5\n5 0\n10 0\n7 8\n4\n0 0\n40 0\n50 5\n0 5\n4\n0 0\n10 0\n20 5\n10 5\n7\n4 0\n20 0\n24 1\n22 10\n2 10\n0 6\n0 4\n18\n728 997\n117 996\n14 988\n1 908\n0 428\n2 98\n6 54\n30 28\n106 2... | |
code_contests | verifiable_code | p01227 Country Road | Solve the following coding problem using the programming language python:
This is a story in a depopulated area. In this area, houses are sparsely built along a straight road called Country Road. Until now, there was no electricity in this area, but this time the government will give us some generators. You can instal... | ```python
NUM=int(input())
for sect in range(NUM):
n,k=list(map(int,input().strip().split()))
x=list(map(int,input().strip().split()))
x.sort()
diff=[]
for i in range(1,len(x)):
diff.append(x[i]-x[i-1])
diff.sort(reverse=True)
s=sum(diff[:k-1])
print(max(x)-min(x)-s)
`... | vfc_48325 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n5 2\n10 30 40 70 100\n7 3\n3 6 10 17 21 26 28\n1 1\n100\n2 1\n0 1000000\n3 5\n30 70 150\n6 4\n0 10 20 30 40 50",
"output": "60\n13\n0\n1000000\n0\n20",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | p01361 Dungeon Quest II | Solve the following coding problem using the programming language python:
The cave, called "Mass of Darkness", had been a agitating point of the evil, but the devil king and all of his soldiers were destroyed by the hero and the peace is there now.
One day, however, the hero was worrying about the rebirth of the devi... | ```python
from bisect import bisect
from heapq import heappush, heappop
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
cA = ord('A')
ds = "LURD"
hi, hm = map(int, readline().split())
if hi == hm == 0:
return False
R, C = map(int, readline().split())
A = [l... | vfc_48329 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 10\n3 3\nAAA\nABA\nCCC\n3\nA 0\nB 5\nC 9\n3\nD 2\nR 1\nU 2\n5\n10\n10\n10\n10\n10\n100 100\n10 10\nTHISISAPEN\nTHISISAPEN\nTHISISAPEN\nTHISISAPEN\nTHISISAPEN\nTHISISAPEN\nTHISISAPEN\nTHISISAPEN\nTHISISAPEN\nTHISISAPEN\n8\nT 0\nH ... |
code_contests | verifiable_code | p01699 Elevator Hall Number | Solve the following coding problem using the programming language python:
Elevator hall number
JAG (Japanese Alumni Group) is a mysterious organization headquartered in a skyscraper somewhere in Tokyo. There are $ N $ elevators in operation in this building, and the $ i $ elevators stop on each floor from the $ low_i... | vfc_48337 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 11\n1 11\n3\n10 10\n2 2\n11 11\n4\n89 91\n1 12\n1 12\n89 91\n5\n1 8\n2 76\n10 19\n6 16\n33 42\n6\n10 59\n20 69\n30 79\n40 89\n50 99\n50 99\n0",
"output": "120\n1\n1278\n659520\n15625000000",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | p01979 Gochiusa-Number | Solve the following coding problem using the programming language python:
problem
AOR Ika-chan, who loves feasts, defined "the number of feasts". A feast number is a natural number that includes "$ 51-3 $" in $ 10 $ decimal notation.
$? $ Can be any number from $ 0 $ to $ 9 $.
Find the number of feasts out of the na... | ```python
#!/usr/bin/env python
from collections import deque
import itertools as it
import sys
import math
sys.setrecursionlimit(1000000)
INF = 10 ** 18
MOD = 10 ** 9 + 7
N = input()
def func(S, index, cnt):
ans = 0
if index == 20:
if cnt == 0:
return 0
S_ = list(S)
for... | vfc_48345 | {
"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": "5124",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2935",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5957",
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.