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 | 779_A. Pupils Redistribution | Solve the following coding problem using the programming language python:
In Berland each high school student is characterized by academic performance — integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group A and the group B. Each group consists of exactly n students. An academi... | ```python
n = int(input())
linea = list(map(int, input().split()))
lineb = list(map(int, input().split()))
lines = linea + lineb
c1 = lines.count(1)
c2 = lines.count(2)
c3 = lines.count(3)
c4 = lines.count(4)
c5 = lines.count(5)
cc1 = linea.count(1)
cc2 = linea.count(2)
cc3 = linea.count(3)
cc4 = linea.count(4)
cc5 = l... | vfc_31085 | {
"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\n1 1 1 1 1 1\n5 5 5 5 5 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n5 4 4 4\n5 5 4 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 848_C. Goodbye Souvenir | Solve the following coding problem using the programming language python:
I won't feel lonely, nor will I be sorrowful... not before everything is buried.
A string of n beads is left as the message of leaving. The beads are numbered from 1 to n from left to right, each having a shape numbered by integers between 1 an... | vfc_31097 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 6, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 5\n1 3 2 1 4 2 3\n1 1 4\n2 2 3\n1 1 7\n2 4 5\n1 1 7\n",
"output": " 0\n 0\n",
"type": "stdin_... | |
code_contests | verifiable_code | 896_E. Welcome home, Chtholly | Solve the following coding problem using the programming language python:
— I... I survived.
— Welcome home, Chtholly.
— I kept my promise...
— I made it... I really made it!
After several days of fighting, Chtholly Nota Seniorious miraculously returned from the fierce battle.
As promised, Willem is now baking bu... | vfc_31105 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6\n1 5 5 5 8\n2 2 5 5\n1 2 4 3\n2 2 5 2\n2 2 5 5\n1 3 5 1\n2 1 5 1\n",
"output": "3\n3\n0\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 13\n75 85 88 100 105 120 122 128\n1 1 8 70\... | |
code_contests | verifiable_code | 918_A. Eleven | Solve the following coding problem using the programming language python:
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly n characters.
<image>
Her friend suggested that her name should only consis... | ```python
n=int(input())
a,b,r=1,2,''
for i in range(1,n+1):
if i==a: r+='O';a,b=b,a+b
else: r+='o'
print(r)
``` | vfc_31109 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n",
"output": "OOOoOooO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "15\n",
"output": "OOOoOooOooooOoo\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 940_A. Points on the line | Solve the following coding problem using the programming language python:
We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest distance between two points from th... | ```python
n,d = map(int,input().split())
a=list(map(int,input().split()))
a.sort();
i=0
cnt=0
cnt1=0
if n==1:
print("0")
else:
for i in range(n):
cnt=0
for j in range(i+1,n):
d1=a[j]-a[i]
if d1>d:
break;
cnt+=1
if(cnt1<cnt):
... | vfc_31113 | {
"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 3\n1 3 4 6 9 10\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n2 1 4\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 967_D. Resource Distribution | Solve the following coding problem using the programming language python:
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of... | ```python
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
#threading.stack_size... | vfc_31117 | {
"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 20 32\n21 11 11 12\n",
"output": "Yes\n1 3\n1 \n2 3 4 \n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 993_D. Compute Power | Solve the following coding problem using the programming language python:
You need to execute several tasks, each associated with number of processors it needs, and the compute power it will consume.
You have sufficient number of analog computers, each with enough processors for any task. Each computer can execute up... | ```python
# Codeforces Round #488 by NEAR (Div. 2)
import collections
from functools import cmp_to_key
#key=cmp_to_key(lambda x,y: 1 if x not in y else -1 )
import math
import sys
def getIntList():
return list(map(int, input().split()))
import bisect
def makePair(z):
return [(z[i], z[i+1]) for i in ... | vfc_31121 | {
"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": "6\n8 10 9 9 8 10\n1 1 1 1 1 1\n",
"output": "9000\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | attack-or-be-attacked | Solve the following coding problem using the programming language python:
You are given an NxM chessboard. Find the number of pairs of different positions of a bishop and a PQ-knight where they don't attack each other modulo 10^9 + 7.
A bishop can move to square if it's on the same diagonal with it.
A PQ-knight with... | ```python
from sys import stdin
def res(n,m):
x = n-1; fir = (x*(x+1)*(x-1))/3;ti = m-n+1
return n*m + 2*(2*fir + ti*n*(n-1))
a=stdin.readline().split()
x = int(a[0]);y=int(a[1]);p=int(a[2]);q=int(a[3]);
m=x;n=y
if m < n:
m=y;n=x
total = m*n*m*n
rem = 0
fir = n-p
sec = m-q
if fir < 1:
fir = 0
if sec < 1:
sec = 0... | vfc_31125 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 5 1 2\n\nSAMPLE",
"output": "62",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "92891 8181 398 787",
"output": "353972355",
"type": "stdin_stdout"
},
{
"fn_name":... |
code_contests | verifiable_code | chintu-and-his-girlfriend | Solve the following coding problem using the programming language python:
Like other girlfriends Chintu's girlfriend is also very demanding. This time she is demanding for bracelet having atleast k special beads. A bracelet is composed of N strands. Each strand can have any number of beads and each bead has a letter e... | ```python
n,k=map(int,raw_input().split())
ans=set([chr(i) for i in xrange(97,97+26+1)])
for _ in xrange(n):
ans=ans.intersection(set(list(raw_input())))
if len(ans)>=k:
print ":-)"
else:
print ":-("
``` | vfc_31129 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\nabcde\naabaa\nasdba\n\nSAMPLE",
"output": ":-)\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | dummy-3-1 | Solve the following coding problem using the programming language python:
In this problem, you are given list of N numbers from 1 to N. They may be written in any order. You are to create a special list out of the given list. It should be such that the position of integer i is the i-th number in the given list. We wil... | ```python
test=int(input())
for i in range(test):
numn=int(input())
lst=[]
lst=map(int,raw_input().split())
lst2=[ 0 for x in range(len(lst))]
for j in range(len(lst)):
lst2[lst[j]-1]=j+1
if lst==lst2:print'inverse'
else:print'not inverse'
``` | vfc_31133 | {
"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\n3 1 2\n3\n1 2 3\n\nSAMPLE",
"output": "not inverse\ninverse\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "35\n44\n31 39 40 21 12 32 7 35 2 20 15 4 33 9 27 29 42 17 25 10 37 18 8 1 ... |
code_contests | verifiable_code | guess-the-permutation-easy-contest | Solve the following coding problem using the programming language python:
In this problem your goal is to guess some secret permutation A of integers from 1 to 16.
There are 17 tests in this problem. Test number i for 1 ≤ i ≤ 16 will have the following form:
the first line of the input contains string "ELEMENT" (wit... | ```python
x = raw_input()
if x == "PERMUTATION":
print("13 15 1 6 14 4 5 7 2 16 9 11 10 12 8 3")
else:
a, b = map(int, raw_input().split(' '))
if (a == 1):
print(13)
elif a == 2:
print(15)
elif a == 3:
print(1)
elif a == 4:
print(6)
elif a == 5:
print(14)
elif a == 6:
print(4)
elif a == 7:
print(... | vfc_31137 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "ELEMENT\n1 13",
"output": "13\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "ELEMENT\n6 4",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | little-stuart-and-evil-hackers-2 | Solve the following coding problem using the programming language python:
Evil hackers are trying to hack the database of HackerEarth.com.
After a lot of work they figure out that the encryption key used by HackerEarth to securely store the data is really just a random large number.
After a bit more work they figure o... | ```python
# Binomial coefficient with mod inverse of prime. Calculate binom (n, r) % p.
MAXN = 200005
MOD = 10 ** 9 + 7
f = [0] * MAXN
def binom (n, r, p):
# print binom (10 ** 18, 2545354543534, 9973)
if n < 0 or r < 0 or n < r: return 0
# Precalculate factorial.
if f [0] != 1: # Factorial already p... | vfc_31141 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2\n1 1\n2 1\n2 3\n\nSAMPLE",
"output": "6\n2\n4\n400",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000\n73004 67426\n91627 69478\n61297 68278\n24234 83945\n47637 96401\n94242 97144\n... |
code_contests | verifiable_code | mystery-12 | Solve the following coding problem using the programming language python:
Lets think of an infinite series of numbers such that the difference between any two consecutive numbers is d. Let the first number in the sequence be a.
Now your task is to find the multiple that occurs first in the sequence of a given number n... | ```python
from sys import stdin
import math
t = int(stdin.readline())
for _ in xrange(t):
a,b = map(int,stdin.readline().split())
p = int(stdin.readline())
if b%p==0:
if a%p==0:
print 0
else:
print -1
else:
rem = (p - a%p)%p
b = b%p
inv = pow(b, p-2, p)
rem = (rem * inv)%p
print rem
``` | vfc_31145 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5 6\n7\n4 9\n11\n\nSAMPLE",
"output": "5\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n844452700697263162 119646220083568392\n617\n624716331013886830 420232882599498616\n263\n371... |
code_contests | verifiable_code | primestring | Solve the following coding problem using the programming language python:
Alice has just learnt about primeStrings. A string is a primeString if the number of distinct alphabets used in the string is a prime and also the number of occurrences of each alphabet in the string is also a prime.
Given a String you need to t... | ```python
import math
array = [0]
def calculate_primes(num):
global array
array = (num+1)*[0]
lim = int(math.sqrt(num))
for i in range(2,lim):
j = i*i
if not array[j]:
while(j < num):
array[j] = 1
j = j + i
array[0] = 1
array[1] = 1
return
def isPrime(num):
return not array[num]
if __name_... | vfc_31149 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nababb\nabcab\naabbccdd\n\nSAMPLE",
"output": "YES\nNO\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nababb\nabcab\naabbccdd\n\nS@MPLE",
"output": "YES\nNO\nNO\n",
"t... |
code_contests | verifiable_code | saxie-and-strings | Solve the following coding problem using the programming language python:
Saxie is a programming enthusiast. He has always been amazed by the beauty of strings. He always dreams of going to Byteland and playing with strings. One day he had a nightmare that Dr. Evil had attacked the strings. When he came forward to pro... | ```python
for _ in xrange(input()):
s=raw_input()
if s==s[::-1]:
print "YES"
else:
print "NO"
``` | vfc_31153 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\naba\nax\n\nSAMPLE",
"output": "YES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\naba\nxa\n\nSAMPLE",
"output": "YES\nNO\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | tablets | Solve the following coding problem using the programming language python:
Therasa is a Nurse. She wants to give some tablets to the patients in her practice. All the patients sit in a line and each of them has a rating score according to his or her health score. Therasa wants to give at least 1 tablet for each patie... | ```python
import sys
inp = sys.stdin.readline
def noTablets(a, n):
countTablets = 1
countIf = 1
countElse = 1
ind = 0
for i in range(1, n):
if a[i] > a[i-1]:
countIf += 1
countElse = 0
countTablets += countIf;
ind = countIf
elif a[i-1] == a[i]:
countIf = 1
countElse = 0
countTablets += 1
... | vfc_31157 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1\n2\n2\n\nSAMPLE",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1\n2\n2",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | who-will-survive-in-the-end | Solve the following coding problem using the programming language python:
Ali baba did a trick on the forty thieves and was able to trap them inside a big cave which was the home of wild wolves. The thieves are without any weapons, only the chief of the thieves has knife. With no weapons they will not be able to fight... | ```python
import sys
from math import log, floor
def lucky( n ):
return 2*(n - 2**(int(floor(log(n,2)))))+1
cases= int(sys.stdin.readline())
current= 0
while current < cases:
current += 1
n = int(sys.stdin.readline())
print lucky( n )
``` | vfc_31161 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n5\n11\n45\n23987443\n\nSAMPLE",
"output": "3\n7\n27\n14420455\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n5\n11\n45\n28960650\n\nSAMPLE",
"output": "3\n7\n27\n24366869\n",
... |
code_contests | verifiable_code | p00054 Sum of Nth decimal places | Solve the following coding problem using the programming language python:
Assume that a, b, and n are all positive integers. Let f (i) be the i-th fraction of the fraction a / b (0 ≤ f (i) ≤ 9). At this time, let s be the sum of f (i) from i = 1 to n.
s = f (1) + f (2) + ... + f (n)
Create a program that reads a, b... | ```python
while 1:
try: a,b,c=map(int,input().split())
except:break
print(sum(a*10**(i+1)//b%10 for i in range(c)))
``` | vfc_31205 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2 3\n2 3 4\n5 4 3\n4 3 2",
"output": "5\n24\n7\n6",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2 1\n2 3 4\n5 4 3\n4 3 2",
"output": "5\n24\n7\n6\n",
"type": "stdin_stdout"... |
code_contests | verifiable_code | p00184 Tsuruga Castle | Solve the following coding problem using the programming language python:
Tsuruga Castle, a symbol of Aizuwakamatsu City, was named "Tsuruga Castle" after Gamo Ujisato built a full-scale castle tower. You can overlook the Aizu basin from the castle tower. On a clear day, you can see Tsuruga Castle from the summit of M... | ```python
while True:
n = int(input())
if n == 0:
break
To_lis = [0,0,0,0,0,0,0]
for i in range(n):
tosi = int(input())
if tosi < 10:
To_lis[0] += 1
elif tosi < 20:
To_lis[1] += 1
elif tosi < 30:
To_lis[2] += 1
elif tosi... | vfc_31209 | {
"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": "8\n71\n34\n65\n11\n41\n39\n6\n5\n4\n67\n81\n78\n65\n0",
"output": "2\n1\n0\n2\n1\n0\n2\n0\n0\n0\n0\n0\n0\n4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n71\n34\n65\n11\n41\n39\n3\n5\n4... |
code_contests | verifiable_code | p00534 Silk Road | Solve the following coding problem using the programming language python:
problem
In the area where Kazakhstan is now located, there used to be a trade route called the "Silk Road".
There are N + 1 cities on the Silk Road, numbered from west as city 0, city 1, ..., city N. The distance between city i -1 and city i (... | ```python
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): retur... | vfc_31217 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\n10\n25\n15\n50\n30\n15\n40\n30",
"output": "1125",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 5\n10\n25\n15\n50\n30\n6\n40\n30",
"output": "900\n",
"type": "stdin_stdou... |
code_contests | verifiable_code | p00698 Missing Numbers | Solve the following coding problem using the programming language python:
Toshizo is the manager of a convenience store chain in Hakodate. Every day, each of the stores in his chain sends him a table of the products that they have sold. Toshizo's job is to compile these figures and calculate how much the stores have s... | ```python
import sys
from copy import deepcopy
def check(data):
return reduce(lambda a, b: a+b, data).count("?")
def calc(seq):
if "?" not in seq or not(0 <= seq.count("?") <= 1) :
return seq
if seq[-1] == "?":
return seq[:-1] + sum(seq[:-1])
a = seq[-1] - sum(s for s in seq[:-1] if s !... | vfc_31221 | {
"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 3\n? ? 70 105\n? 50 ? 150\n30 60 90 180\n45 150 240 435\n\n2 2\n? ? 40\n? ? 40\n40 40 80\n\n2 3\n? 30 40 90\n50 60 70 180\n70 90 110 270\n\n0",
"output": "-5\n40\n20\n80\n\nNO\n\n20",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | p00839 Organize Your Train | Solve the following coding problem using the programming language python:
In the good old Hachioji railroad station located in the west of Tokyo, there are several parking lines, and lots of freight trains come and go every day.
All freight trains travel at night, so these trains containing various types of cars are ... | ```python
def solve(file_input, x, y):
exch1 = [] # forward - forward
exch2 = [] # forward - reverse
exch3 = [] # reverse - forward
for i in range(y):
p, P, space, q, Q = file_input.readline().rstrip()
p = int(p)
q = int(q)
if P == 'E':
if Q == 'W':
... | vfc_31225 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\n0W 1W\n0W 2W\n0W 2E\n0E 1E\n1E 2E\naabbccdee\n-\n-\n-\n-\nbbaadeecc\n3 3\n0E 1W\n1E 2W\n2E 0W\naabb\nbbcc\naa\nbbbb\ncc\naaaa\n3 4\n0E 1W\n0E 2E\n1E 2W\n2E 0W\nababab\n-\n-\naaabbb\n-\n-\n0 0",
"output": "4\n2\n5",
... |
code_contests | verifiable_code | p00971 Shortest Common Non-Subsequence | Solve the following coding problem using the programming language python:
Shortest Common Non-Subsequence
A subsequence of a sequence $P$ is a sequence that can be derived from the original sequence $P$ by picking up some or no elements of $P$ preserving the order. For example, "ICPC" is a subsequence of "MICROPROCES... | ```python
def main():
p=input()
q=input()
lp=len(p)
lq=len(q)
memop=[[0,0] for _ in [0]*(lp+2)]
memoq=[[0,0] for _ in [0]*(lq+2)]
memop[lp+1]=[lp+1,lp+1]
memoq[lq+1]=[lq+1,lq+1]
memop[lp]=[lp+1,lp+1]
memoq[lq]=[lq+1,lq+1]
for i in range(lp-1,-1,-1):
if p[i]=="0":... | vfc_31229 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0101\n1100001",
"output": "0010",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0101\n1101001",
"output": "0000\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p01240 Oil Company | Solve the following coding problem using the programming language python:
Irving & Cohen Petroleum Corporation has decided to develop a new oil field in an area. A preliminary survey has been done and they created a detailed grid map of the area which indicates the reserve of oil.
They are now planning to construct m... | vfc_31237 | {
"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\n2 2\n2 3\n3 5\n3 2\n4 1 1\n2 1 4",
"output": "Case 1: 7\nCase 2: 8",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01402 Anipero | Solve the following coding problem using the programming language python:
Problem E: Anipero
The long and short summer, which had been hot, was about to end. One day in late August, a person who likes 2D and his senior slip participated in an event called Anipero Summer Live, commonly known as Anipero. Anipero is the... | vfc_31241 | {
"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": "100 2 2 2\nA 5 6\nB 7 8\nC 1 2\nD 3 4\n27 2 3 3\nA 8 10\nB 8 10\nC 6 7\nD 5 4\nE 8 9\n27 2 3 2\nA 8 10\nB 8 10\nC 6 7\nD 5 4\nE 8 9\n44 3 6 5\nYamatoNoHito 9 10\nZettoNoHito 9 10\nTMR 10 10\nSkillNoGroup 8 10\nNanaSama 6 9\nFRPSD 6... | |
code_contests | verifiable_code | p01711 Idempotent Filter | Solve the following coding problem using the programming language python:
Problem Statement
Let's consider operations on monochrome images that consist of hexagonal pixels, each of which is colored in either black or white. Because of the shape of pixels, each of them has exactly six neighbors (e.g. pixels that share... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in ... | vfc_31249 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "00000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000111111111\n10000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000... |
code_contests | verifiable_code | p01991 Namo.. Cut | Solve the following coding problem using the programming language python:
C: Namo .. Cut
problem
-Defeat the mysterious giant jellyfish, codenamed "Nari"-
"Nari" has a very strong vitality, so if you don't keep cutting quickly, it will be revived in a blink of an eye. We are making trial and error every day to find... | ```python
# サイクル検出
import sys
sys.setrecursionlimit(10**7)
def dfs(G, v, p):
global pos
seen[v] = True
hist.append(v)
for nv in G[v]:
# 逆流を禁止する
if nv == p:
continue
# 完全終了した頂点はスルー
if finished[nv]:
continue
# サイクルを検出
if seen[nv] ... | vfc_31257 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2\n1 3\n2 3\n1\n1 3",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2\n1 3\n2 3\n1\n1 2",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_... |
code_contests | verifiable_code | p02278 Minimum Cost Sort | Solve the following coding problem using the programming language python:
You are given $n$ integers $w_i (i = 0, 1, ..., n-1)$ to be sorted in ascending order. You can swap two integers $w_i$ and $w_j$. Each swap operation has a cost, which is the sum of the two integers $w_i + w_j$. You can perform the operations an... | ```python
n = int(input())
A = [int(i) for i in input().split()]
B = A.copy()
B.sort()
ans = 0
for i in B:
ixB = B.index(i)
counter = 0
while(True):
ixA = A.index(i)
if ixA == ixB:
break
else:
counter += 1
num = B[ixA]
ixN = A.index(num... | vfc_31265 | {
"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\n4 3 2 1",
"output": "10",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 5 3 4 2",
"output": "7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input":... |
code_contests | verifiable_code | cielrcpt | Solve the following coding problem using the programming language python:
Tomya is a girl. She loves Chef Ciel very much.
Tomya like a positive integer p, and now she wants to get a receipt of Ciel's restaurant whose total price is exactly p.
The current menus of Ciel's restaurant are shown the following table.
Na... | ```python
menu = [1,2,4,8,16,32,64,128,256,512,1024,2048]
menu.reverse()
def find_menus(price, count):
if price==0:
return count
for i in menu:
if price/i>0:
return find_menus(price%i, count+price/i)
for i in range(input()):
print find_menus(input(), 0)
``` | vfc_31277 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n10\n256\n255\n4096",
"output": "2\n1\n8\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n10\n376\n255\n4096",
"output": "2\n5\n8\n2\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | exebit01 | Solve the following coding problem using the programming language python:
Pratyush, a six year old kid has just learnt how to write 1 through 1000 in decimal number system(DNS). Being a very curious kid, he made some modifications in DNS and removed the digits 0 through 3 and 7 through 9. So the only digits remaining ... | ```python
t=int(input())
while(t):
t=t-1
n=int(input())
k=1
ans=0
while(n>0):
if(n%3==0):
ans=6*k+ans
n=n/3-1
elif(n%3==1):
ans=4*k+ans
n=(n-1)/3
elif(n%3==2):
ans=5*k+ans
n=(n-2)/3
k=k*10
print ans
``` | vfc_31281 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n3\n13\n45\n64\n1000000000",
"output": "6\n444\n4456\n4664\n5446456455646565564",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | lastride | Solve the following coding problem using the programming language python:
Problem description.
Toretto has no friends. He has got family, and now they need him. His bitter enemy, Ian Shaw, has captured Toretto's beloved Letty and evil cooks in his head. All Toretto has is the algorithmic message Shaw left before leav... | ```python
import sys
f = sys.stdin
mod = 1000000007
DP = [0]*(2)
DP[0] = [0]*(111)
DP[1] = [0]*(111)
bits = [0]*(111)
X = [0]*(2)
Y = [0]*(2)
X[0] = [0]*(111)
X[1] = [0]*(111)
Y[0] = [0]*(111)
Y[1] = [0]*(111)
def process():
DP[0][100] = 1
DP[1][100] = 1
X[0][100] = 1
Y[0][100] = 0
Y[1][100] = 1
... | vfc_31285 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 2\n3 10",
"output": "3\n25",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | pd32 | Solve the following coding problem using the programming language python:
Recall the definition of the Fibonacci numbers:
f1 := 1
f2 := 2
fn := fn-1 + fn-2 (n ≥ 3)
Given two numbers a and b, calculate how many Fibonacci numbers are in the range [a,b].
Input
The input contains several test cases. Ea... | ```python
import bisect
def find_lt(a,x):
#find rightmost value less than or equal to x
i=bisect.bisect_right(a,x)
if i:
return i-1
else:
return -1
def find_ge(a,x):
#find leftmost item greator than or equal to x
i=bisect.bisect_left(a,x)
if i!=len(a):
return i
... | vfc_31289 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 100\n1234567890 9876543210\n0 0",
"output": "5\n4",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | stfm | Solve the following coding problem using the programming language python:
For positive integer x let define function F(x) = 1 * (1! + x) + 2 * (2! + x) + .. + x * (x! + x).
"k!" means factorial: k! = 1 * 2 * .. * k
Chef wants to calculate F(p1) + F(p2) + ... + F(pn).
As answer could be large, help him, calculate va... | ```python
arr=[]
def fact(x,m):
f=1
i=1;
while i <=x+1:
f=(f*i)%m
arr.append(f)
i+=1
def f(x):
if x>=m:
return (x*x*(x+1)/2-1)%m
else:
return arr[x]+x*x*(x+1)/2-1
n,m=map(int,raw_input().split())
a=map(int,raw_input().split())
x=max(a)
if x<=1000000:
fa... | vfc_31293 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 7\n1 2 3 4 5",
"output": "6",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 7\n1 2 3 4 4",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | 1008_D. Pave the Parallelepiped | Solve the following coding problem using the programming language python:
You are given a rectangular parallelepiped with sides of positive integer lengths A, B and C.
Find the number of different groups of three integers (a, b, c) such that 1≤ a≤ b≤ c and parallelepiped A× B× C can be paved with parallelepipeds a× ... | ```python
from sys import stdin
from math import gcd
def main():
input()
l = stdin.read().splitlines()
d = [3., 1., 2., 2., 2., 1.] * 16667
for i in range(4, 100001):
for j in range(i, 100001, i):
d[j] += 1.
for i, s in enumerate(l):
a, b, c = map(int, s.split())
... | vfc_31297 | {
"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\n1 1 1\n1 6 1\n2 2 2\n100 100 100\n",
"output": "1\n4\n4\n165\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n",... |
code_contests | verifiable_code | 1031_B. Curiosity Has No Limits | Solve the following coding problem using the programming language python:
When Masha came to math classes today, she saw two integer sequences of length n - 1 on the blackboard. Let's denote the elements of the first sequence as a_i (0 ≤ a_i ≤ 3), and the elements of the second sequence as b_i (0 ≤ b_i ≤ 3).
Masha be... | ```python
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
import threading
BUFSIZE = 819... | vfc_31301 | {
"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\n3 3 2\n1 2 0\n",
"output": "YES\n1 3 2 0 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 3\n3 2\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": ... |
code_contests | verifiable_code | 1054_B. Appending Mex | Solve the following coding problem using the programming language python:
Initially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array.
The mex of an multiset of integers is the smallest non-negative int... | ```python
n = int(input())
data = input().split()
max = 0
for i in range(n):
back = max
if max<int(data[i]):
max=int(data[i])
if i==0 and data[i]!="0":
print(1)
exit()
elif int(data[i])>back+1:
print(i+1)
exit()
if int(data[i])<=back+1:
print(-1)
``` | vfc_31305 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 0 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 1 2 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inp... |
code_contests | verifiable_code | 1076_B. Divisor Subtraction | Solve the following coding problem using the programming language python:
You are given an integer number n. The following algorithm is applied to it:
1. if n = 0, then end algorithm;
2. find the smallest prime divisor d of n;
3. subtract d from n and go to step 1.
Determine the number of subtrations the ... | ```python
from collections import deque as de
import math
class My_stack():
def __init__(self):
self.data = []
def my_push(self, x):
return (self.data.append(x))
def my_pop(self):
return (self.data.pop())
def my_peak(self):
return (self.data[-1])
def my_contains(self,... | vfc_31309 | {
"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\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9999999999\... |
code_contests | verifiable_code | 1097_B. Petr and a Combination Lock | Solve the following coding problem using the programming language python:
Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer w... | ```python
n = int(input())
a = [0]
for _ in range(n):
curr = int(input())
mods = []
for o in a:
mods.extend([o + curr, o - curr])
a = mods[:]
#print(a)
print("YES" if any(x%360 == 0 for x in a) else "NO")
``` | vfc_31313 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n10\n10\n10\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n120\n120\n120\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | 1144_F. Graph Without Long Directed Paths | Solve the following coding problem using the programming language python:
You are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph.
You have to direct its edges in such a way that the obtained directed graph does not contain any path... | ```python
# lista doble enlazada o(1) en operaciones en los bordes
from collections import deque
def solve():
global n, m
n, m = map(lambda x: int(x), input().split())
global maxValue
maxValue = n**2
graph = [[] for _ in range(0, n)]
edges = []
for _ in range(0, m):
u, v = map(lamb... | vfc_31321 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 5\n1 5\n2 1\n1 4\n3 1\n6 1\n",
"output": "YES\n10100",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 9\n8 1\n1 2\n1 5\n2 6\n6 5\n6 4\n4 7\n7 3\n3 5\n",
"output": "NO\n",
"typ... |
code_contests | verifiable_code | 1165_E. Two Arrays and Sum of Functions | Solve the following coding problem using the programming language python:
You are given two arrays a and b, both of length n.
Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i.
Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ ... | ```python
m=998244353
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a=sorted([a[i]*(i+1)*(n-i) for i in range(n)])
b.sort(reverse=True)
ans=0
for i in range(n):
ans=(ans+(a[i]*b[i])%m)%m
print(ans)
``` | vfc_31325 | {
"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": "1\n1000000\n1000000\n",
"output": "757402647\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 8 7 2 4\n9 7 2 9 3\n",
"output": "646\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 1184_D1. Parallel Universes (Easy) | Solve the following coding problem using the programming language python:
The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be ... | ```python
n,k,m,t=map(int,input().split())
for i in range(t):
a,b=map(int,input().split())
if a==1:
if b<=k:
k+=1
n+=1
print(n,k)
else :
if k>b:
n=n-b
k=k-b
else :
n=b
print(n,k)
``` | vfc_31329 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2 10 4\n0 1\n1 1\n0 4\n1 2\n",
"output": "4 1\n5 2\n4 2\n5 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 5 20 4\n1 1\n0 4\n1 7\n1 7\n",
"output": "11 6\n7 2\n8 2\n9 2\n",
... |
code_contests | verifiable_code | 1203_A. Circle of Students | Solve the following coding problem using the programming language python:
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation).
Students want to start a round dance... | ```python
t=int(input())
while t:
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
for i in range(n):
b[a[i]-1]=i+1
k=0
flag=0
# print(b)
if n==1:
print("YES")
elif abs(b[0]-b[1])==1 or abs(b[0]-b[1])==n-1:
if abs(b[0]-b[1])==1:
k=b[0]-b[1]
else:
k=b[1]-b[2]
for j in range(1,n):
if j=... | vfc_31333 | {
"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\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4\n",
"output": "YES\nYES\nNO\nYES\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n11\n11 2 3 4 5 6 7 8 9 10 1\n",
"ou... |
code_contests | verifiable_code | 121_C. Lucky Permutation | Solve the following coding problem using the programming language python:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya dreamt of a... | ```python
def lucky(x):
s=str(x)
return s.count('4')+s.count('7')==len(s)
def Gen_lucky(n):
if(len(n)==1):
if(n<"4"):
return 0
if(n<"7"):
return 1
return 2
s=str(n)
if(s[0]<'4'):
return 0
if(s[0]=='4'):
return Gen_lucky(s[1:])
... | vfc_31337 | {
"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 7\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 4\n",
"output": "1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1244_G. Running in Pairs | Solve the following coding problem using the programming language python:
Demonstrative competitions will be held in the run-up to the 20NN Berlatov Olympic Games. Today is the day for the running competition!
Berlatov team consists of 2n runners which are placed on two running tracks; n runners are placed on each tr... | ```python
n, t = [int(i) for i in input().split()]
import os
def tr(qq):
return (qq*(qq+1))//2
if t < tr(n):
print(-1)
exit()
upp = 2 * (tr(n) - tr(n//2))
if n % 2 == 1:
upp -= (n+1)//2
if t >= upp:
# print(upp)
# exit()
os.write(1, (str(upp) + '\n').encode())
ans = list(range(1, n+1... | vfc_31341 | {
"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": "10 54\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 9\n",
"output": "8\n1 2 3\n3 2 1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1264_D2. Beautiful Bracket Sequence (hard version) | Solve the following coding problem using the programming language python:
This is the hard version of this problem. The only difference is the limit of n - the length of the input string. In this version, 1 ≤ n ≤ 10^6.
Let's define a correct bracket sequence and its depth as follow:
* An empty string is a correct ... | vfc_31345 | {
"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": "(?(?))\n",
"output": "9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "??\n",
"output": "1",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1286_A. Garland | Solve the following coding problem using the programming language python:
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was... | ```python
def ip():
n=int(input())
a=list(map(int,input().split()))
rem=set([i for i in range(1,n+1)])-set(a)
if n==1:
return 0
o=e=0
for i in rem:
if i%2==0:
e+=1
else:
o+=1
ct=0
i=0
while i<len(a) and a[i]==0:
i+=1
if i... | vfc_31349 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n1 0 0 5 0 0 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 5 0 2 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1305_B. Kuroni and Simple Strings | Solve the following coding problem using the programming language python:
Now that Kuroni has reached 10 years old, he is a big boy and doesn't like arrays of integers as presents anymore. This year he wants a Bracket sequence as a Birthday present. More specifically, he wants a bracket sequence so complex that no mat... | ```python
s = input()
to_ans = [False for _ in range(len(s))]
def solve(s, left, right): #right inclusive
if left >= right:
return
while left <= right and s[left] == ")":
left += 1
while right >= left and s[right] == "(":
right -= 1
if left >= right:
return
else:
to_ans[left] = True
to_ans[right] = Tr... | vfc_31353 | {
"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": "(()((\n",
"output": "1\n2\n1 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "(()())\n",
"output": "1\n4\n1 2 5 6 ",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1349_D. Slime and Biscuits | Solve the following coding problem using the programming language python:
Slime and his n friends are at a party. Slime has designed a game for his friends to play.
At the beginning of the game, the i-th player has a_i biscuits. At each second, Slime will choose a biscuit randomly uniformly among all a_1 + a_2 + … + ... | ```python
import os
import sys
input = sys.stdin.buffer.readline
#sys.setrecursionlimit(int(2e5))
from collections import deque
import math
# list(map(int, input().split()))
#####################################################################################
class CF(object):
def __init__(self):
self.mo... | vfc_31361 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n8 4 2 0 1\n",
"output": "801604029\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 136_B. Ternary Logic | Solve the following coding problem using the programming language python:
Little Petya very much likes computers. Recently he has received a new "Ternatron IV" as a gift from his mother. Unlike other modern computers, "Ternatron IV" operates with ternary and not binary logic. Petya immediately wondered how the xor ope... | ```python
def untor(a, c):
res = ''
while a or c:
a, ma = divmod(a, 3)
c, mc = divmod(c, 3)
x = 0
while (ma + x)%3 != mc:
x += 1
res = str(x) + res
try:
return int(res, 3)
except Exception as e:
return 0
a, c = map(int, input().split()... | vfc_31365 | {
"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": "387420489 225159023\n",
"output": "1000000001\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1433_C. Dominant Piranha | Solve the following coding problem using the programming language python:
There are n piranhas with sizes a_1, a_2, …, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium.
Scientists of the Berland State University want to find if there is dominant piranha in the aquarium.... | ```python
for _ in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
if len(set(l))==1:
print(-1)
else:
m=max(l)
for i in range(n):
if i>0:
if i<n-1:
if l[i]==m and (l[i-1]<m or l[i+1]<m):
print(i+1)
break
else:
if l[i]==m and l[i-1]<m:
print(i+1)
... | vfc_31377 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n5\n5 3 4 4 5\n3\n1 1 1\n5\n4 4 3 4 4\n5\n5 5 4 3 2\n3\n1 1 2\n5\n5 4 3 5 5\n",
"output": "1\n-1\n2\n2\n3\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3\n5 3 4\n",
"output... |
code_contests | verifiable_code | 1458_B. Glass Half Spilled | Solve the following coding problem using the programming language python:
There are n glasses on the table numbered 1, …, n. The glass i can hold up to a_i units of water, and currently contains b_i units of water.
You would like to choose k glasses and collect as much water in them as possible. To that effect you ca... | ```python
n=int(input())
dp=[[-10**8]*(10002) for _ in range(n+1)]
dp[0][0]=0
total=0
for i in range(n):
a,b=map(int,input().split())
total+=b
for k in range(n-1,-1,-1):
for c in range(10001-a,-1,-1):
dp[k+1][c+a]=max(dp[k+1][c+a],dp[k][c]+b)
ans = [0 for i in range(n+1)]
for j in range(... | vfc_31381 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n6 5\n6 5\n10 2\n",
"output": "\n7.0000000000 11.0000000000 12.0000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n1 0\n1 0\n1 0\n1 0\n1 0\n1 1\n1 0\n1 0\n1 0\n1 1\n1 0\n1 0\... |
code_contests | verifiable_code | 1508_C. Complete the MST | Solve the following coding problem using the programming language python:
As a teacher, Riko Hakozaki often needs to help her students with problems from various subjects. Today, she is asked a programming task which goes as follows.
You are given an undirected complete graph with n nodes, where some edges are pre-as... | ```python
def divisors(M):
d=[]
i=1
while M>=i**2:
if M%i==0:
d.append(i)
if i**2!=M:
d.append(M//i)
i=i+1
return d
def popcount(x):
x = x - ((x >> 1) & 0x55555555)
x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
x = (x + (x >> 4)) & 0x... | vfc_31389 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4\n2 1 14\n1 4 14\n3 2 15\n4 3 8\n",
"output": "\n15\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1534_D. Lost Tree | Solve the following coding problem using the programming language python:
This is an interactive problem.
Little Dormi was faced with an awkward problem at the carnival: he has to guess the edges of an unweighted tree of n nodes! The nodes of the tree are numbered from 1 to n.
The game master only allows him to ask ... | ```python
res = []
n = int(input())
print('?', 1, flush=True)
arr = list(map(int, input().split()))
for v,d in enumerate(arr):
if d==1:
res.append([0,v])
one = [v for v,d in enumerate(arr) if d&1]
two = [v for v,d in enumerate(arr) if v and not (d&1)]
if len(one)>len(two):
one, two = two, one
for u in o... | vfc_31393 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n\n0 1 2 2\n\n1 0 1 1",
"output": "\n? 1\n\n? 2\n\n!\n4 2\n1 2\n2 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n\n2 2 1 1 0\n",
"output": "\n? 5\n\n!\n4 5\n3 5\n2 4\n1 3\n",... |
code_contests | verifiable_code | 162_A. Pentagonal numbers | Solve the following coding problem using the programming language python:
Pentagonal numbers are figurate numbers which can be calculated using the formula pn = (3n2 - n) / 2 (always integer). You are given n; calculate n-th pentagonal number.
Input
The only line of input contains an integer n (1 ≤ n ≤ 100).
Output... | vfc_31397 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "35\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 181_B. Number of Triplets | Solve the following coding problem using the programming language python:
You are given n points on a plane. All points are different.
Find the number of different groups of three points (A, B, C) such that point B is the middle of segment AC.
The groups of three points are considered unordered, that is, if point B... | ```python
n = int(input())
points_array = []
cords = []
for i in range(2001):
cords.append([False] * 2001)
for i in range(n):
x, y = [a for a in input().split()]
points_array.append([int(x), int(y)])
cords[int(x)+1000][int(y)+1000] = True
count = 0
for i in range(n):
for j in range(i+1, n):
... | vfc_31401 | {
"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\n0 0\n-1 0\n0 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 1\n2 2\n3 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... |
code_contests | verifiable_code | 204_D. Little Elephant and Retro Strings | Solve the following coding problem using the programming language python:
The Little Elephant has found a ragged old black-and-white string s on the attic.
The characters of string s are numbered from the left to the right from 1 to |s|, where |s| is the length of the string. Let's denote the i-th character of string... | ```python
Mod=1000000007
n,k=map(int,input().split(' '))
s=' '+input()
f,fs,g,gs,w=[0]*1000005,[0]*1000005,[0]*1000005,[0]*1000005,[0]*1000005
qx,qw,qb=[0]*1000005,[0]*1000005,[0]*1000005
q=0
f[0]=fs[0]=1
for i in range(1,n+1):
lg=(i-k if i-k>=q else q)
if s[i]!='B':
f[i]=fs[i-1]-fs[lg-1]+Mod
f[i]-=(Mod if f[i]>=... | vfc_31405 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 2\nXXBXXWXXXX\n",
"output": "166\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\nXXX\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 253_A. Boys and Girls | Solve the following coding problem using the programming language python:
There are n boys and m girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to n + m. Then ... | ```python
import os.path
import sys
if os.path.exists('input.txt'):
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
n,m=[int(x) for x in input().split(' ')]
x=min(n,m)
#print(x)
if n<m:
ans=x*"GB"
else:
ans=x*'BG'
n=n-x
m=m-x
#print(n,m)
if n!=0:
ans+=n*'B'
if m!=0:
ans+=... | vfc_31413 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\n",
"output": "BGBGBB\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n",
"output": "GBGBGB\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | 278_B. New Problem | Solve the following coding problem using the programming language python:
Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems.
You've got the titles of n... | ```python
from itertools import *
alphabet="abcdefghijklmnopqrstuvwxyz";
def isValid(s, names):
for name in names:
if name.find(s)!=-1:
return False
return True
def newProblem(names):
for i in range(1,3):
for s in product(alphabet, repeat=i):
st=""
for ... | vfc_31417 | {
"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\naa\nbdefghijklmn\nopqrstuvwxyz\nc\n",
"output": "ab\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nthreehorses\ngoodsubstrings\nsecret\nprimematrix\nbeautifulyear\n",
"output"... |
code_contests | verifiable_code | 300_A. Array | Solve the following coding problem using the programming language python:
Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero ( < 0).
2. The product of all nu... | ```python
n=int(input())
a=list(map(int,input().split()))
b=[]
k=0
k1=0
for i in range(0,n):
if(a[i]==0):
b.append(a[i])
elif(a[i]>0):
if(k==0):
k=a[i]
else:
b.append(a[i])
elif(a[i]<0):
if(k1==0):
k1=a[i]
else:
b.append... | vfc_31421 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n-1 -2 -3 0\n",
"output": "1 -1\n2 -3 -2\n1 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n-1 2 0\n",
"output": "1 -1\n1 2\n1 0\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 325_D. Reclamation | Solve the following coding problem using the programming language python:
In a far away land, there exists a planet shaped like a cylinder. There are three regions in this planet: top, bottom, and side as shown in the following picture.
<image>
Both the top and the bottom areas consist of big cities. The side area c... | vfc_31425 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4 9\n2 2\n3 2\n2 3\n3 4\n3 1\n1 3\n2 1\n1 1\n1 4\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 5 10\n2 2\n1 1\n1 4\n2 1\n1 2\n1 5\n2 4\n2 5\n1 3\n2 3\n",
"outp... | |
code_contests | verifiable_code | 348_E. Pilgrims | Solve the following coding problem using the programming language python:
A long time ago there was a land called Dudeland. Dudeland consisted of n towns connected with n - 1 bidirectonal roads. The towns are indexed from 1 to n and one can reach any city from any other city if he moves along the roads of the country.... | vfc_31429 | {
"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": "8 5\n7 2 5 4 8\n1 2 1\n2 3 2\n1 4 1\n4 5 2\n1 6 1\n6 7 8\n6 8 10\n",
"output": "5 1\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 372_A. Counting Kangaroos is Fun | Solve the following coding problem using the programming language python:
There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is h... | ```python
# Made By Mostafa_Khaled
bot = True
import math,sys
n=int(input());k=n
a=sorted([int(x) for x in sys.stdin.read().strip().split('\n')])
p1=math.floor((n-1)/2);p2=n-1
while p1>=0:
if 2*a[p1]<=a[p2]:
k-=1;a[p2]=0;p2-=1
p1-=1
k=max(math.ceil(n/2),k)
sys.stdout.write(str(k))
# Made By ... | vfc_31433 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n2\n5\n7\n6\n9\n8\n4\n2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n9\n1\n6\n2\n6\n5\n8\n3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 393_C. Blocked Points | Solve the following coding problem using the programming language python:
Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only if:
* the Euclidean distance between A a... | ```python
from math import sqrt
n = int(input())
if n == 0:
print(1)
else:
print(4 * int(n * sqrt(2)))
``` | vfc_31437 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
... |
code_contests | verifiable_code | 416_D. Population Size | Solve the following coding problem using the programming language python:
Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. W... | ```python
n = int(input())
a = list(map(int, input().split()))
i = 0
ans = 0
while i < n:
ans += 1
i1 = i
while i1 < n and a[i1] == -1:
i1 += 1
if i1 == n:
break
i2 = i1 + 1
while i2 < n and a[i2] == -1:
i2 += 1
if i2 == n:
break
dist = i2 - i1
step = ... | vfc_31441 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9\n-1 6 -1 2 -1 4 7 -1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n-1 -1 -1 -1 -1\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 443_B. Kolya and Tandem Repeat | Solve the following coding problem using the programming language python:
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substr... | ```python
s=input()
k=int(input())
n=len(s)
if k>=n:
print(int(2*((n+k)//2)))
raise SystemExit
ll=0
for i in range(k+1):
for l in range((n+i)//2,i-1,-1):
if s[n-(l-i):n]==s[n+i-2*l:n-l]:
if l>ll:
ll=l
break
j=ll
while 2*j<=n:
j=j+1
for i in range(n-2*j):
if s[... | vfc_31445 | {
"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": "aaabbbb\n2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "aaba\n2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input... |
code_contests | verifiable_code | 465_C. No to Palindromes! | Solve the following coding problem using the programming language python:
Paul hates palindromes. He assumes that string s is tolerable if each its character is one of the first p letters of the English alphabet and s doesn't contain any palindrome contiguous substring of length 2 or more.
Paul has found a tolerable ... | ```python
import sys
def main():
# fin = open("input.txt", "r")
fin = sys.stdin
fout = sys.stdout
L = list("abcdefghijklmnopqrstuvwxyz")
n, p = map(int, fin.readline().split())
A = list(fin.readline())
for i in range(n - 1, 1, -1):
pr = ord(A[i - 1]) - ord("a")
pp = ord(A... | vfc_31449 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\ncba\n",
"output": "cbd\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\ncba\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inp... |
code_contests | verifiable_code | 489_B. BerSU Ball | Solve the following coding problem using the programming language python:
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to ... | ```python
n = int(input())
b = list(map(int, input().split()))
m = int(input())
g = list(map(int, input().split()))
b.sort()
g.sort()
res = 0
i = 0
j = 0
while i < n and j < m:
if abs(b[i]-g[j]) <= 1:
res += 1
i += 1
j += 1
elif b[i] > g[j]:
j += 1
else:
i += 1
... | vfc_31453 | {
"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\n1 2 3 4\n4\n10 11 12 13\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 4 6 2\n5\n5 1 5 7 9\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 566_C. Logistical Questions | Solve the following coding problem using the programming language python:
Some country consists of n cities, connected by a railroad network. The transport communication of the country is so advanced that the network consists of a minimum required number of (n - 1) bidirectional roads (in the other words, the graph of... | vfc_31465 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n3 1 2 6 5\n1 2 3\n2 3 1\n4 3 9\n5 3 1\n",
"output": "3 192.0000000000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n5 5\n1 2 2\n",
"output": "2 14.1421356237",
"type": "s... | |
code_contests | verifiable_code | 587_D. Duff in Mafia | Solve the following coding problem using the programming language python:
Duff is one if the heads of Mafia in her country, Andarz Gu. Andarz Gu has n cities (numbered from 1 to n) connected by m bidirectional roads (numbered by 1 to m).
Each road has a destructing time, and a color. i-th road connects cities vi and ... | vfc_31469 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 6, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 7\n2 1 3 7\n3 1 1 6\n5 4 1 8\n4 5 1 1\n3 2 2 3\n4 5 2 5\n2 3 2 4\n",
"output": "Yes\n3 2\n4 5 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 5\n3 2 1 3\n1 3 1 1\n3 2 1 4\n1 3 2 2\n1 ... | |
code_contests | verifiable_code | 630_E. A rectangle | Solve the following coding problem using the programming language python:
Developing tools for creation of locations maps for turn-based fights in a new game, Petya faced the following problem.
A field map consists of hexagonal cells. Since locations sizes are going to be big, a game designer wants to have a tool for... | ```python
x1,y1,x2,y2 = input().split( )
x1=int(x1)
y1=int(y1)
x2=int(x2)
y2=int(y2)
x =int(x2 - x1)
y =int(y2 - y1)
if x % 2 == 0:
if y % 2 == 1:
n= int(int( x + 1 ) * int(y + 1) / 2)
else:
t0=int(x*y)+int(x)+int(y)
t1=int(t0)//2
n=int(t1)+1
else:
n = int((x + 1) / 2 * ( y + 1 ))
print(n)
``` | vfc_31477 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1 5 5\n",
"output": "13",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-157778763 218978790 976692563 591093088\n",
"output": "211076501291102387",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 680_D. Bear and Tower of Cubes | Solve the following coding problem using the programming language python:
Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many blocks of each side length.
A block with side a has volume a3. A tower consisting of bl... | ```python
#!/usr/bin/env python3
import sys
# 1 8 27 64 125 216 343 512 729 1000
# 1-7: blocks of size 1
# 8-15: 1 block of size 2, blocks of size 1
# 16-23: 2 blocks of size 2, blocks of size 1
# 24-26: 3 blocks of size 2, blocks of size 1
# 27-34: 1 block of size 3, blocks of size 1
# Maximum will always be when y... | vfc_31485 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n",
"output": "6 6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "48\n",
"output": "9 42\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10000... |
code_contests | verifiable_code | 703_C. Chris and Road | Solve the following coding problem using the programming language python:
And while Mishka is enjoying her trip...
Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best ... | ```python
n, w, v, u = map(int, input().split())
maxwait = 0
curr = True
for i in range(n):
x, y = map(int, input().split())
maxwait = max(maxwait, x / v - y / u)
if x / v < y / u:
curr = False
if curr:
maxwait = 0
print(w / u + maxwait)
``` | vfc_31489 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5 1 2\n1 2\n3 1\n4 3\n3 4\n1 4\n",
"output": "5.0000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3 5 2\n3 1\n4 0\n5 1\n",
"output": "1.5000000000\n",
"type": "std... |
code_contests | verifiable_code | 725_C. Hidden Word | Solve the following coding problem using the programming language python:
Let’s define a grid to be a set of tiles with 2 rows and 13 columns. Each tile has an English letter written in it. The letters don't have to be unique: there might be two or more tiles with the same letter written on them. Here is an example of... | ```python
import sys
debug = False
def print_debug(*args, **kwargs):
if debug:
print(*args, **kwargs, file=sys.stderr)
s = input()
double = ''
for c in range(ord('A'), ord('Z')+1):
if s.count(chr(c)) == 2:
double = chr(c)
i1, i2 = [ i for i, c in enumerate(s) if c == double ]
print_debug(... | vfc_31493 | {
"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": "BUVTYZFQSNRIWOXXGJLKACPEMDH\n",
"output": "Impossible\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "ABCDEFGHIJKLMNOPQRSGTUVWXYZ\n",
"output": "ABCDEFGHIJKLM\nZYXWVUTSRQPON\n",
... |
code_contests | verifiable_code | 747_C. Servers | Solve the following coding problem using the programming language python:
There are n servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to n.
It is known that during the day q tasks will come, the i-th of them is characterized with three integers: ti — the moment in... | ```python
n, q = map(int, input().split())
servers = [i for i in range(1, n+1)]
res, used = [], {}
for i in range(q):
t, s, d = map(int, input().split())
finish = t + d
for i in list(used.keys()):
if t >= i:
servers += used[i]
servers.sort()
del used[i]
if s ... | vfc_31497 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8\n",
"output": "6\n9\n30\n-1\n15\n36\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 76_F. Tourist | Solve the following coding problem using the programming language python:
Tourist walks along the X axis. He can choose either of two directions and any speed not exceeding V. He can also stand without moving anywhere. He knows from newspapers that at time t1 in the point with coordinate x1 an interesting event will o... | ```python
from bisect import bisect_right as br
I = 1000000000
n = input()
a = [map(int,raw_input().split()) for x in xrange(n)]
v = input()
a.append((0,0))
a = sorted((x-v*t,-x-v*t) for x,t in a)
b = [I]*(n+1)
for x,y in a:
if x or y: b[br(b,y)]=y
else: print br(b,y),
print b.index(I)
``` | vfc_31501 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n-1 1\n42 7\n40 8\n2\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12\n-6712 6\n2375 73\n4643 197\n-5660 215\n-378 223\n2228 307\n3305 340\n3449 468\n-4389 707\n-716... |
code_contests | verifiable_code | 794_C. Naming Company | Solve the following coding problem using the programming language python:
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this problem, they've decided t... | ```python
from sys import *
f = lambda: sorted(stdin.readline()[:-1])
a, b = f(), f()
n = len(a)
u = v = ''
i, j = 0, -1
x, y = n - 1 >> 1, n - 2 >> 1
while x != -1:
if a[i] < b[j]:
u += a[i]
i += 1
else: v += a[i + x]
x -= 1
if y == -1: break
elif a[i] < b[j]:
u += b[j]
... | vfc_31505 | {
"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": "xxxxxx\nxxxxxx\n",
"output": "xxxxxx\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "tinkoff\nzscoder\n",
"output": "fzfsirk\n",
"type": "stdin_stdout"
},
{
"fn_n... |
code_contests | verifiable_code | 815_B. Karen and Test | Solve the following coding problem using the programming language python:
Karen has just arrived at school, and she has a math test today!
<image>
The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. S... | ```python
from sys import exit, stdin, stdout
n = int(stdin.readline())
a = [int(i) for i in stdin.readline().split()]
if n == 1:
print(a[0])
exit(0)
mod = 1000000007
f = [0] * (n + 1)
f[0] = 1
for i in range(1, n + 1):
f[i] = (f[i-1] * i) % mod
def f_pow(a, k):
if k == 0:
return 1
if k % 2... | vfc_31509 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n3 7 5 2\n",
"output": "\n1000000006\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 840_B. Leha and another game about graph | Solve the following coding problem using the programming language python:
Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or - 1. To pa... | ```python
import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
import sys
import heapq
INF=10**9
def Dijkstra(graph, start,m):
dist=[INF]*len(graph)
parent=[INF]*len(graph)
queue=[(0, start)]
while queue:
path_len, v=heapq.heappop(queue)
if dist[v]==INF:
dist[v]=path_len
fo... | vfc_31513 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n0 -1 1\n1 2\n2 3\n1 3\n",
"output": "1\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5\n0 0 0 -1\n1 2\n2 3\n3 4\n1 4\n2 4\n",
"output": "0\n",
"type": "stdin_stdout... |
code_contests | verifiable_code | 860_C. Tests Renumeration | Solve the following coding problem using the programming language python:
The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website.
Unfortunately, the archive with Olympiad's data is a mess. For example, the fi... | ```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
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()... | vfc_31517 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n01 0\n2 1\n2extra 0\n3 1\n99 0\n",
"output": "4\nmove 3 1\nmove 01 3\nmove 2extra 4\nmove 99 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 0\n2 1\n",
"output": "3\nmove 1... |
code_contests | verifiable_code | 90_B. African Crossword | Solve the following coding problem using the programming language python:
An African crossword is a rectangular table n × m in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded.
To solve the crossword you should ... | ```python
n, m = [int(x) for x in input().split()]
lr = []
lc = []
lst = []
for i in range(n):
l = list(input())
lr.append(l)
for i in range(m):
l = []
for j in range(n):
s = lr[j][i]
l.append(s)
lc.append(l)
for i in range(n):
for j in range(m):
s = lr[i][j]
if l... | vfc_31525 | {
"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 3\ncba\nbcd\ncbc\n",
"output": "abcd\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf\n",
"output": "codeforces\n",
"type": "stdin_stdou... |
code_contests | verifiable_code | 931_E. Game with String | Solve the following coding problem using the programming language python:
Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this stri... | ```python
s = input()
n = len(s)
d = {}
for i in range(n):
if s[i] not in d: d[s[i]] = []
d[s[i]].append(s[i + 1:] + s[:i])
res = 0
for k, l in d.items():
ans = 0
for j in range(n - 1):
seen, s1 = set(), set()
for i in range(len(l)):
if l[i][j] in s1: s1.remove(l[i][j])
... | vfc_31529 | {
"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": "tictictactac\n",
"output": "0.333333333333333\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "bbaabaabbb\n",
"output": "0.100000000000000\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 958_F3. Lightsabers (hard) | Solve the following coding problem using the programming language python:
There used to be unrest in the Galactic Senate. Several thousand solar systems had declared their intentions to leave the Republic. But fear not! Master Heidi was able to successfully select the Jedi Knights that have restored peace in the galax... | vfc_31533 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3 2\n1 2 3 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 2 5\n1 1 1 2 2 2 2 2 2 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_n... | |
code_contests | verifiable_code | 985_E. Pencils and Boxes | Solve the following coding problem using the programming language python:
Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence a1, a2, ..., an of n int... | ```python
n, k, d = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
b = [0] * n
i = j = 0
for i in range(n):
while a[i] - a[j] > d:
j += 1
b[i] = j
c = [0] * n
for i in range(k - 1, n):
c[i] = c[i - 1] + int(i - b[i] + 1 >= k and (b[i] == 0 or c[i - k] > c[b[i] - 2] or (b... | vfc_31537 | {
"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 3 10\n7 2 7 7 4 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2 5\n10 16 22\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name"... |
code_contests | verifiable_code | ac-or-cooler | Solve the following coding problem using the programming language python:
This summer is very hot in KGP. As the hostel rooms do not have coolers or ACs, it's even more difficult for the students. So, the management has decided to install a cooler or an AC in some of the rooms.
There are N rooms in KGP. The managemen... | ```python
x,t = map(int,raw_input().strip().split())
l1 = map(int,raw_input().strip().split())
l2 = map(int,raw_input().strip().split())
l1 += l2
s = 0
c = 0
for i in sorted(l1):
if s+i < t:
s+=i
c+=1
else:
break
print c
``` | vfc_31541 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 10\n2 5 2 2 10\n2 1 4 1 9\n\nSAMPLE",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 10\n2 5 2 2 10\n2 1 7 1 9\n\nSAMPLE",
"output": "5\n",
"type": "stdin_stdou... |
code_contests | verifiable_code | box-n-ball-1 | Solve the following coding problem using the programming language python:
Bozo is shifting his house. He has some balls and boxes which he has to shift. He now wonders how large a ball he can fit in a given box. Given the dimensions of a box, help Bozo determine the radius of the largest ball that he can fit in the bo... | ```python
t = int(raw_input())
while t>0:
t-=1
list = map(float,raw_input().split())
print "{:.1f}".format(min(list)/2)
``` | vfc_31545 | {
"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 3\n3 3 7\n987548 4578445 9645875456\n\nSAMPLE",
"output": "0.5\n1.5\n493774.0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "28\n754474126400970 101 196613378898208859\n38062104561... |
code_contests | verifiable_code | cutting-the-birthday-cake | Solve the following coding problem using the programming language python:
Its Alice's birthday and her friend Bob gets him a birthday cake. Its nice delicious circle shaped cake of radius R. Now they need to cut and eat that cake, so Alice fetches a cutter from her kitchen. It is a rectangular cutter of length A and ... | ```python
def find(r,a,b):
if (a*a)+(b*b) <= 4*r*r:
print "ALICE"
else:
print "EQUAL"
if __name__ == '__main__':
t=int(raw_input())
while t>0:
(r,a,b) = map(int,raw_input().split())
find(r,a,b)
t-=1
``` | vfc_31549 | {
"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 2 2\n1 1 1\n\nSAMPLE",
"output": "EQUAL\nALICE",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | fun-with-primes-3 | Solve the following coding problem using the programming language python:
A prime number is one which is divisible by exactly two numbers 1 and itself.
Given a number, find out if the number obtained by summing all digits of that number is a prime.
Input Format:
The input begins with number of test-cases t in a singl... | ```python
def isprime(number):
if number==1:
return 0
if number==2:
return 1
if number%2==0:
return 0
N=long(number**0.5)+1
for i in range(3,N,2):
if number%i==0:
return 0
return 1
for t in range(input()):
n=long(raw_input())
summ=0
while n>0:
summ=summ+n%10
n=n/10
if isprime(summ):
print "Y... | vfc_31553 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n33\n122\n\nSAMPLE",
"output": "NO\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n33\n122\n\nSAMPLD",
"output": "NO\nYES\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | just-find-the-next-number | Solve the following coding problem using the programming language python:
You are given an integer n find its next greater or equal number whose binary representation must not contain consecutive ones.
For eg. given n=6 whose binary is 110 and the next number with no consecutive ones is 8 whose binary is 1000.
INPU... | ```python
t=int(raw_input())
while t>0:
n=int(raw_input())
while bin(n).count("11")!=0:
n=n+1
print n
t=t-1
``` | vfc_31557 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n6\n2\n\nSAMPLE",
"output": "8\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n71\n8497\n6364\n6530\n9199\n5754\n1508\n9388\n6992\n4494",
"output": "72\n8512\n8192\n8192\n92... |
code_contests | verifiable_code | minimum-coins | Solve the following coding problem using the programming language python:
Ram has to pay Shyam R rupees and but the coins which he has got is of limited denomination .Assuming he has a limited knowledge of the mathematics and has unlimited number of coins of each denomination.Write a code to help Ram to pay the money ... | ```python
def min_coins(money, denoms):
# money : The money which is needed to get minimum coins
# denoms : Available denominations
denoms.sort()
min = denoms[0] * money
coin_list = {}
for j in range(len(denoms)):
temp = money
used = 0
coins = {}
for i in rang... | vfc_31561 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "24\n{1,7,3}\n\nSAMPLE",
"output": "Rupee 1 coin 0\nRupee 3 coin 1\nRupee 7 coin 3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n{10}",
"output": "ERROR",
"type": "stdin_stdo... |
code_contests | verifiable_code | palindrome-count-1 | Solve the following coding problem using the programming language python:
Given a string S, count the number of non empty sub strings that are palindromes.
A sub string is any continuous sequence of characters in the string.
A string is said to be palindrome, if the reverse of the string is same as itself.
Two sub str... | ```python
def isPalindrome(s):
lf = 0
ri = len(s)-1
while lf <= ri:
if s[lf] != s[ri]:
return 0
lf += 1
ri -= 1
return 1
def getPalindromes(s):
palindromes = []
lf = 0
ri = len(s)
while lf <= ri:
subri = lf+1
while subri <= ri:
t = s[lf:subri]
if isPalindrome(t):
... | vfc_31565 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "dskjkd\n\nSAMPLE",
"output": "7\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | rhezo-and-prime-problems | Solve the following coding problem using the programming language python:
Rhezo and his friend Vanya love problem solving. They have a problem set containing N problems, with points assigned to each. Rhezo wants to solve problems in such a way that he gets the maximum number of points. Rhezo has a weird habit of solvi... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
import sys
def readline():
return sys.stdin.readline().strip()
def readInts(sep=None):
return map(int,readline().split(sep))
def readInt():
return int(readline()... | vfc_31569 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n8 1 3 7\n\nSAMPLE",
"output": "12",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n8 2 3 7\n\nSAMPLE",
"output": "13\n",
"type": "stdin_stdout"
},
{
"fn_name":... |
code_contests | verifiable_code | special-sum-3 | Solve the following coding problem using the programming language python:
Special Sum of number N is defined as follows:
def foo(n):
{
ret = 0
for i = 1 to n:
{
if gcd(n,i) is 1:
ret += 1
}
return ret
}
def SpecialSum(N):
{
ret=0
for i = 1 to N:
{
if i divides N:
... | ```python
numcases = input()
res = []
for i in range(numcases):
val = input()
res.append(val)
for i in res:
print i
``` | vfc_31573 | {
"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\n\nSAMPLE",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000\n84\n87\n78\n16\n94\n36\n87\n93\n50\n22\n63\n28\n91\n60\n64\n27\n41\n27\n73\n37\n12\n69\n68\n30\n83\n31\n... |
code_contests | verifiable_code | trick-with-the-cards | Solve the following coding problem using the programming language python:
Mr. X is performing a trick with the cards. He has N cards, lets name them 1.....N, on a round table.
So card 1 is in between 2nd card and Nth card. Initially all cards are upside down. His trick involves making all cards face up.
His trick i... | ```python
test = input()
while test>0:
N = input()
if N==0:
print "0"
elif N<3:
print "1"
elif N%3==0:
print N/3
else:
print N
test = test-1
``` | vfc_31577 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n3\n\nSAMPLE",
"output": "1\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2\n3\n\nSAMPME",
"output": "1\n1\n",
"type": "stdin_stdout"
},
{
"fn_name":... |
code_contests | verifiable_code | p00264 East Wind | Solve the following coding problem using the programming language python:
I decided to move and decided to leave this place. There is nothing wrong with this land itself, but there is only one thing to worry about. It's a plum tree planted in the garden. I was looking forward to this plum blooming every year. After le... | ```python
from math import atan2, degrees
def calc(dx, dy, d, w, a):
if dx**2 + dy**2 > a**2:
return 0
t = degrees(atan2(dy, dx))
for i in range(2):
if w - d/2 <= t + 360*i <= w + d/2:
return 1
return 0
while 1:
H, R = map(int, input().split())
if H == R == 0:
... | vfc_31629 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 3\n2 1\n1 2\n5 2\n1 3\n1 5\n-2 3\n1 1 1 90 30 45\n3 -4\n-3 0\n2 -2\n45 6\n90 6\n135 6\n2 1\n1 3\n5 2\n0 1 1 90 30 45\n-3 0\n2 -2\n45 6\n0 0",
"output": "5 6\nNA",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | p00451 Common Sub-String | Solve the following coding problem using the programming language python:
problem
Given two strings, find the longest of the strings contained in both strings and write a program that answers that length.
Here, the string s included in the string t means that s appears consecutively in t. An empty string, that is, a... | ```python
def rolling_hash(S, base, MOD):
l = len(S)
h = [0]*(l + 1)
for i in range(l):
h[i+1] = (h[i] * base + ord(S[i])) % MOD
return h
C = open(0).read().split()
MOD = 358976445361682909
base = 31
for t in range(len(C)//2):
S = C[2*t]; T = C[2*t+1]
rhs = rolling_hash(S, base, MOD)
... | vfc_31633 | {
"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": "None",
"output": "None",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "ABRACADABRA\nECADADABRBCRDARA\nUPWJCIRUCAXIIRGL\nSBQNYBSBZDFNEV",
"output": "5\n0",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | p00642 Ben Toh | Solve the following coding problem using the programming language python:
As usual, those who called wolves get together on 8 p.m. at the supermarket. The thing they want is only one, a box lunch that is labeled half price. Scrambling for a few discounted box lunch, they fiercely fight every day. And those who are ble... | vfc_31637 | {
"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\n2\n3\n0",
"output": "1.00000000\n1.50000000\n2.12500000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2\n4\n0",
"output": "1.000000000000\n1.500000000000\n2.765625000000\n",
... | |
code_contests | verifiable_code | p00786 BUT We Need a Diagram | Solve the following coding problem using the programming language python:
Consider a data structure called BUT (Binary and/or Unary Tree). A BUT is defined inductively as follows:
* Let l be a letter of the English alphabet, either lowercase or uppercase (n the sequel, we say simply "a letter"). Then, the object that... | vfc_31641 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "a(A,b(B,C));\nx( y( y( z(z), v( s, t ) ) ), u ) ;\n\na( b( c,\n d(\n e(f),\n g\n )\n ),\n h( i(\n j(\n k(k,k),\n l(l)\n ),\n m(m)\n )\n )\n );\... | |
code_contests | verifiable_code | p00918 Dragon's Cruller | Solve the following coding problem using the programming language python:
Dragon's Cruller is a sliding puzzle on a torus. The torus surface is partitioned into nine squares as shown in its development in Figure E.1. Here, two squares with one of the sides on the development labeled with the same letter are adjacent t... | vfc_31645 | {
"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 9\n6 3 0\n8 1 2\n4 5 7\n6 3 0\n8 1 2\n4 5 7\n31 31\n4 3 6\n0 1 5\n8 2 7\n0 3 6\n4 1 5\n8 2 7\n92 4\n1 5 3\n4 0 7\n8 2 6\n1 5 0\n4 7 3\n8 2 6\n12 28\n3 4 5\n0 2 6\n7 1 8\n5 7 1\n8 6 2\n0 3 4\n0 0",
"output": "0\n31\n96\n312"... | |
code_contests | verifiable_code | p01183 Tetrahedra | Solve the following coding problem using the programming language python:
Peter P. Pepper is facing a difficulty.
After fierce battles with the Principality of Croode, the Aaronbarc Kingdom, for which he serves, had the last laugh in the end. Peter had done great service in the war, and the king decided to give him a... | vfc_31653 | {
"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": "7 1 2 2 2 2 2 2\n0",
"output": "0.942809",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 1 2 2 2 2 2 4\n0",
"output": "0.552770798\n",
"type": "stdin_stdout"
},
{
... | |
code_contests | verifiable_code | p01320 Magical Island 2 | Solve the following coding problem using the programming language python:
It was an era when magic still existed as a matter of course. A clan of magicians lived on a square-shaped island created by magic.
At one point, a crisis came to this island. The empire has developed an intercontinental ballistic missile and a... | vfc_31657 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4 1\n1 0\n0 1\n-1 0\n0 -1\n5 6 2\n1 1\n4 4\n2 -4\n-4 2\n1 5\n0 0 0",
"output": "1.000000000\n6.797434948",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4 1\n1 0\n0 1\n-1 0\n0 -1\n5 6 2\... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.