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 | 605_A. Sorting Railway Cars | Solve the following coding problem using the programming language python:
An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In on... | ```python
n = int(input())
cars = [int(x) for x in input().split()]
sorted_cars = sorted(enumerate(cars), key = lambda x : x[1])
max_sorted_length = 1
length = 1
for i in range(1, n):
if sorted_cars[i][0] > sorted_cars[i-1][0]:
length += 1
else:
if max_sorted_length < length:
max_sor... | vfc_66045 | {
"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 1 2 5 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n4 1 3 2\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 651_B. Beautiful Paintings | Solve the following coding problem using the programming language python:
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is... | ```python
import math, re, sys, string, operator, functools, fractions, collections
sys.setrecursionlimit(10**7)
RI=lambda x=' ': list(map(int,input().split(x)))
RS=lambda x=' ': input().rstrip().split(x)
dX= [-1, 1, 0, 0,-1, 1,-1, 1]
dY= [ 0, 0,-1, 1, 1,-1,-1, 1]
mod=int(1e9+7)
eps=1e-6
pi=math.acos(-1.0)
MAX=1010
###... | vfc_66053 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n20 30 10 50 40\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n200 100 100 200\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 676_E. The Last Fight Between Human and AI | Solve the following coding problem using the programming language python:
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet.
... | ```python
def main():
n, k = map(int, input().split())
aa = []
for i in range(n + 1):
s = input()
aa.append(None if s == '?' else int(s))
qm_cnt = aa.count(None)
if k:
if qm_cnt:
print('Yes' if n & 1 else 'No')
else:
x = 0
for a in ... | vfc_66057 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2\n-1\n?\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 100\n-10000\n0\n1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... |
code_contests | verifiable_code | 69_E. Subsegments | Solve the following coding problem using the programming language python:
Programmer Sasha has recently begun to study data structures. His coach Stas told him to solve the problem of finding a minimum on the segment of the array in <image>, which Sasha coped with. For Sasha not to think that he had learned all, Stas ... | ```python
from typing import TypeVar, Generic, Callable, List
import sys
from array import array # noqa: F401
from collections import Counter
def input():
return sys.stdin.buffer.readline().decode('utf-8')
minf = -10**9 - 100
T = TypeVar('T')
class SegmentTree(Generic[T]):
__slots__ = ["size", "tree", ... | vfc_66061 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n1\n2\n2\n3\n3\n",
"output": "1\n3\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 4\n3\n3\n3\n4\n4\n2\n",
"output": "4\nNothing\n3\n",
"type": "stdin_stdout"
}
... |
code_contests | verifiable_code | 721_B. Passwords | Solve the following coding problem using the programming language python:
Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decre... | ```python
n,k=map(int,input().split())
l1=[0]*101
for i in range(0,n):
s=input()
l1[len(s)]+=1
pword=input()
x=len(pword)
best=0
worst=0
best+=sum(l1[:x])
best=best+(best//k)*5 +1
worst+=sum(l1[:x+1])-1
worst=worst+(worst//k)*5+1
print(best,worst)
``` | vfc_66065 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc\n",
"output": "1 15\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 100\n11\n22\n1\n2\n22\n",
"output": "3 4\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 742_E. Arpa’s overnight party and Mehrdad’s silent entering | Solve the following coding problem using the programming language python:
Note that girls in Arpa’s land are really attractive.
Arpa loves overnight parties. In the middle of one of these parties Mehrdad suddenly appeared. He saw n pairs of friends sitting around a table. i-th pair consisted of a boy, sitting on the ... | ```python
import sys
n = int(input())
A = [0]*(2*n)
B = []
for line in sys.stdin:
x, y = [int(x)-1 for x in line.split()]
A[x] = y
A[y] = x
B.append(x)
C = [0]*(2*n)
for i in range(2*n):
while not C[i]:
C[i] = 1
C[i^1] = 2
i = A[i^1]
for x in B:
print(C[x], C[A[x]])
`... | vfc_66069 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 4\n2 5\n3 6\n",
"output": "1 2\n2 1\n1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n2 8\n3 5\n4 7\n1 6\n",
"output": "2 1\n2 1\n1 2\n1 2\n",
"type": "stdin_stdout"... |
code_contests | verifiable_code | 766_B. Mahmoud and a Triangle | Solve the following coding problem using the programming language python:
Mahmoud has n line segments, the i-th of them has length ai. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he ... | ```python
def main():
n = int(input())
a = list(map(int, input().split()))
a.sort()
works = False
for i in range(2, n):
if a[i - 2] + a[i - 1] > a[i]:
works = True
break
print('YES' if works else 'NO')
main()
``` | vfc_66073 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 5 3 2 4\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 78_A. Haiku | Solve the following coding problem using the programming language python:
Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should cont... | ```python
g = ['a', 'e', 'i', 'o', 'u']
ans = [0]*3
h = [5,7,5]
for i in range(3):
s = input()
for j in s:
if j in g:
ans[i] += 1
if ans == h:
print('YES')
else:
print('NO')
``` | vfc_66077 | {
"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": "on codeforces \nbeta round is running\n a rustling of keys \n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "how many gallons\nof edo s rain did you drink\n ... |
code_contests | verifiable_code | 810_C. Do you want a date? | Solve the following coding problem using the programming language python:
Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access to n computers throughout the ... | ```python
mod = 10**9+7
n = int(input())
x = sorted(list(map(int, input().split())))
total = 0
for i, (a, b) in enumerate(zip(x, x[1:])):
diff = b-a
total += (pow(2,i+1,mod)-1)*(pow(2,n-i-1,mod)-1)*diff
total %= mod
print(total)
``` | vfc_66081 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4 3 1\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n4 7\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | 835_F. Roads in the Kingdom | Solve the following coding problem using the programming language python:
In the Kingdom K., there are n towns numbered with integers from 1 to n. The towns are connected by n bi-directional roads numbered with integers from 1 to n. The i-th road connects the towns ui and vi and its length is li. There is no more than... | vfc_66085 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 3 7\n3 1 9\n4 1 8\n3 5 4\n4 5 5\n",
"output": "18",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2 4\n2 3 5\n1 3 1\n",
"output": "5",
"type": "stdin_stdout"
},
... | |
code_contests | verifiable_code | 856_B. Similar Words | Solve the following coding problem using the programming language python:
Let us call a non-empty sequence of lowercase English letters a word. Prefix of a word x is a word y that can be obtained from x by removing zero or more last letters of x.
Let us call two words similar, if one of them can be obtained from the ... | vfc_66089 | {
"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": "2\n3\naba\nbaba\naaab\n2\naa\na\n",
"output": "6\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3\naba\nbaba\naaab\n2\nab\na\n",
"output": "6\n2\n",
"type": "stdin_stdou... | |
code_contests | verifiable_code | 926_D. Choose Place | Solve the following coding problem using the programming language python:
A classroom in a school has six rows with 3 desks in each row. Two people can use the same desk: one sitting on the left and one sitting on the right.
Some places are already occupied, and some places are vacant. Petya has just entered the cla... | ```python
#!/usr/bin/env python3
variants = []
price = (
(3,4,3),
(3,4,3),
(2,3,2),
(2,3,2),
(1,2,1),
(1,2,1)
)
max_price = (0, 0, 0, 0)
class_map = []
for i in range(6):
current_row = input().split('-')
class_map.append(current_row)
for j, parta in enumerate(current_row):
... | vfc_66101 | {
"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": "..-**-..\n..-**-..\n..-..-..\n..-..-..\n..-..-..\n..-..-..\n",
"output": "P.-**-..\n..-**-..\n..-..-..\n..-..-..\n..-..-..\n..-..-..\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "**-**-*... |
code_contests | verifiable_code | 955_B. Not simply beatiful strings | Solve the following coding problem using the programming language python:
Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to... | ```python
def go(s):
d = {}
for c in s:
d[c] = d.get(c, 0) + 1
if len(d.keys()) > 4 or len(d.keys()) == 1:
return 'No'
if len(d.keys()) == 2:
if 1 in d.values():
return 'No'
else:
return 'Yes'
if len(d.keys()) == 3:
if sum(d.values()) >... | vfc_66105 | {
"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": "yeee\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "zzcxx\n",
"output": "YES",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 981_D. Bookshelves | Solve the following coding problem using the programming language python:
Mr Keks is a typical white-collar in Byteland.
He has a bookshelf in his office with some books on it, each book has an integer positive price.
Mr Keks defines the value of a shelf as the sum of books prices on it.
Miraculously, Mr Keks was ... | ```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_66109 | {
"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": "7 3\n3 14 15 92 65 35 89\n",
"output": "64",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 4\n9 14 28 1 7 13 15 29 2 31\n",
"output": "24",
"type": "stdin_stdout"
},
{... |
code_contests | verifiable_code | 2a-bear-and-all-permutations-1 | Solve the following coding problem using the programming language python:
Sometimes inventing a story for the problem is a very hard task.
Fortunately for us, Limak has just been kidnapped by an insane mathematician.
We need some name for the mathematician and let it be Mathew.
Limak is a little polar bear.
He has be... | ```python
#!/usr/bin/env python
from sys import stdin, stderr
ans = [
0,
1,
2,
8,
68,
1504,
127792,
57140352,
258023200384,
10151395367145472L,
3673835865235792306176L,
13318668301694192513859649536L,
531680718673514734573555796872790016L
]
def main():
TC = int(stdin.readline().strip())
for tc in xrange(TC):
... | vfc_66113 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4 987654323\n5 11\n12 2\n\nSAMPLE",
"output": "68\n8\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n9 657681137\n9 459211231\n9 421854149\n10 919145723\n9 201797513\n6 10547927... |
code_contests | verifiable_code | big-p-and-math-15 | Solve the following coding problem using the programming language python:
Big P is fairly good in mathematics.
His teacher has asked him to add two numbers.
Now , Big P has a problem that he sometimes writes a '6' as a '5' and vice versa.
Given two numbers, A and B, calculate the minimum and the maximum sum Big P coul... | ```python
m,n=map(int,raw_input().split())
add=m+n
a=0
temp=add
if ('5' in str(n)) or ('6' in str(n)):
while n>0:
b=n%10
if b==6:
temp-=(10**a)
if b==5:
add+=(10**a)
n=n/10
a+=1
if ('5' in str(m)) or ('6' in str(m)):
a=0
while m>0:
b=m%10
if b==6:
temp-=(10**a)
if b==5:
add+=(10**a)... | vfc_66117 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "11 25\n\nSAMPLE",
"output": "36 37\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "736655 669496",
"output": "1295050 1406162\n",
"type": "stdin_stdout"
},
{
"fn_... |
code_contests | verifiable_code | count-numbers-7 | Solve the following coding problem using the programming language python:
Given K prime numbers and T queries of form Ai, Bi, for each query print the number of integers between Ai and Bi (both inclusive) that are divisible by atleast one of the K given primes.
Input
First line: K and T.
Second line: K primes.
... | ```python
k,t=map(int,raw_input().split())
klis=list(map(int,raw_input().split()))
for _ in xrange(t):
ans=0
a,b=map(int,raw_input().split())
for i in xrange(1,2**k):
l,r=a-1,b
par=0
for j in xrange(k):
if(i&(1<<j)):
par+=1
l/=klis[j]
r/=klis[j]
if(par&1):
ans+=(r-l)
else:
ans-=(r-l)
... | vfc_66121 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1\n2 3\n1 10\n\nSAMPLE",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 55\n2 3 5 7 11 37\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7... |
code_contests | verifiable_code | finding-dinosaurs-1 | Solve the following coding problem using the programming language python:
Ross and Rachel are on a date. Ross, being the super geek he is, takes Rachel to see dinosaur exhibits.
Each dinosaur has a name and K attributes which are described by an ordered K-tuple ( A1, A2, A3,..., AK ). Each attribute Ai is an integer ... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
n,k,l,q=raw_input().split()
n=int(n)
k=int(k)
l=int(l)
q=int(q)
din_dict={}
din_set=[]
for i in range(n):
string=raw_input().split()
din_name=string[0]
ans=''
for x in s... | vfc_66125 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3 9 5\nbaryonyx 5 1 7\njobaria 1 2 3\noviraptor 9 7 1\ntroodon 6 9 5\nminmi 7 4 5\n9 7 1\n1 2 3\n5 8 8\n1 2 3\n7 4 5\n\nSAMPLE",
"output": "oviraptor\njobaria\nYou cant fool me :P\njobaria\nminmi\n",
"type": "stdin_st... |
code_contests | verifiable_code | interesting-path | Solve the following coding problem using the programming language python:
On the way to Lanka, Ram and co encountered another interesting path. The path was laid with numbered rocks which were to be jumped over. The number denoted the maximum jump length that could be made by the person standing on that rock. For inst... | ```python
t = int(raw_input())
while t:
n = int(raw_input())
arr = [int(i) for i in raw_input().split()]
dp = [0]*n
for i in range(1,len(arr)):
for j in range(i):
if j + arr[j] >=i:
if dp[i]==0:
dp[i] = dp[j]+1
else:
dp[i] = min(dp[j]+1,dp[i])
print dp[n-1]
t-=1
``` | vfc_66129 | {
"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\n2 3 1 1 4\n11\n1 3 5 8 9 2 6 7 6 8 9\n\nSAMPLE",
"output": "2\n3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n5\n2 3 1 1 4\n11\n1 3 5 8 9 2 6 7 6 8 9\n2\n1 1\n3\n1 2 3\n8\n1 5 2 ... |
code_contests | verifiable_code | maximum-prize | Solve the following coding problem using the programming language python:
Recently Ram got to know about a secret place where he can play many games to win lot of prize. Games are very easy, so he can easily win high prize, but he can play a limited number of games.
He want to win the maximum amount of prize.So he wan... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
t=input()
while t>0:
t-=1
n,k=map(int,raw_input().split())
l=[int(i) for i in raw_input().split()]
l.sort()
p=l[::-1]
s=0
if k>n:
print sum(l)
... | vfc_66133 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n5 5\n1 1 1 1 1\n4 0\n1 1 1 1\n3 1\n8 9 8\n6 5\n100 200 300 400 500 1000\n2 1\n1 2\n\nSAMPLE",
"output": "5\n0\n9\n2400\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n5 6\n1 2 3 4... |
code_contests | verifiable_code | optimal-permutation | Solve the following coding problem using the programming language python:
Miraya and her best Alice friend are now ending their studies and they are willing to work together in a software company, but before this Alice will be tested by the Miraya through the following procedure,
Miraya is obviously Computer Science p... | ```python
def solve (bhavik):
if (bhavik == 1):
return 0
else:
return (bhavik * bhavik)/2 - 1
t = input()
for _ in xrange(t):
n = input()
ans = solve(int(n))
print ans
``` | vfc_66137 | {
"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\n7\n\nSAMPLE",
"output": "1\n23",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | range-sum-2 | Solve the following coding problem using the programming language python:
You are given an two integers i and j such that i ≤ j.
Task is to find the sum of all integers from i to j (both inclusive).
For example:
i = 3
j = 5
then sum from i to j will be 3+4+5 = 12
Input:
Single line containing two space separated... | ```python
a,b=map(long,raw_input().split())
n=b-a+1
print (a+b)*n/2
``` | vfc_66141 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "99 1000000000000\n\nSAMPLE",
"output": "500000000000499999995149\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "99 342",
"output": "53802\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | small-is-cute | Solve the following coding problem using the programming language python:
Problem Statement
As they say, small is cute and beautiful.
Given N distinct positive integers, find the smallest number that can be formed by concatenating all of them.
Input Format
The first line of the input file contains a positive integer ... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
def func(a,b):
if(len(a) != len(b)):
#a = int(a)
#b = int(b)
str1 = a + b
str2... | vfc_66145 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n14\n66\n907\n1234567890\n9876543210\n\nSAMPLE",
"output": "123456789014669079876543210",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | the-witches-of-hegwarts-1 | Solve the following coding problem using the programming language python:
Little PandeyG is a curious student, studying in HEgwarts. Being smarter, faster and displaying more zeal for magic than any other student, one by one he managed to impress the three hidden witches of the school. They knew his secret desire to b... | ```python
def main():
for _ in xrange(input()):
v=[]
s=set()
n=input()
ans=0
v.append(n)
i=0
f=0
j=1
while(f==0):
if(n==1):
break
if(f==1):
break
ans+=1
for k in xrange(i,j):
x = -1
y = -1
z = -1
if(v[k]%3==0):
x=v... | vfc_66149 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1\n2\n3\n4\n5\n\nSAMPLE",
"output": "0\n1\n1\n2\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n41854\n9255\n78975\n63699\n48656\n74074\n43150\n53056\n57317\n41556",
"outpu... |
code_contests | verifiable_code | p00105 Book Index | Solve the following coding problem using the programming language python:
Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers.
You can assume that a word consists of at most 30 characters, and the page number is l... | ```python
index = {}
while True:
try:
word,page = input().split()
page = int(page)
index[word].append(page)
except KeyError:
index[word] = [page]
except EOFError:
break
for (key,value) in sorted(index.items()):
print(key)
value = list(map(str,sorted(value)))
print(" ".join(value))
``` | vfc_66197 | {
"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": "style 12\neven 25\nintroduction 3\neasy 9\nstyle 7\ndocument 13\nstyle 21\neven 18",
"output": "document\n13\neasy\n9\neven\n18 25\nintroduction\n3\nstyle\n7 12 21",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00239 Calorie Counting | Solve the following coding problem using the programming language python:
Food contains three nutrients called "protein", "fat" and "carbohydrate", which are called three major nutrients. It is calculated that protein and carbohydrate are 4 kcal (kilocalories) and fat is 9 kcal per 1 g (gram). For example, according t... | ```python
ans = []
readline = open(0).readline
writelines = open(1, 'w').writelines
while 1:
N = int(readline())
if N == 0:
break
items = [map(int, readline().split()) for i in range(N)]
P, Q, R, C = map(int, readline().split())
c = 0
for s, p, q, r in items:
if p <= P and q <= ... | vfc_66201 | {
"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\n1 7 14 47\n2 5 35 55\n3 6 3 59\n4 6 5 15\n10 15 50 400\n2\n1 8 10 78\n2 4 18 33\n10 10 50 300\n0",
"output": "1\n4\nNA",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 7 14 47\n2 5 35... |
code_contests | verifiable_code | p00615 Traffic Analysis | Solve the following coding problem using the programming language python:
There are two cameras which observe the up line and the down line respectively on the double lane (please see the following figure). These cameras are located on a line perpendicular to the lane, and we call the line 'monitoring line.' (the red ... | ```python
# AOJ 1029: Traffic Analysis
# Python3 2018.7.6 bal4u
import sys
from sys import stdin
input = stdin.readline
while True:
n, m = map(int, input().split())
if n == 0 and m == 0: break
if n > 0: a = list(map(int, input().split()))
if m > 0: b = list(map(int, input().split()))
ans = i = j = 0
s, t = 0, -... | vfc_66209 | {
"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 5\n20 35 60 70\n15 30 40 80 90\n3 2\n10 20 30\n42 60\n0 1\n100\n1 1\n10\n50\n0 0",
"output": "20\n18\n100\n40",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5\n20 35 60 70\n15 30 40 80 ... |
code_contests | verifiable_code | p00754 The Balance of the World | Solve the following coding problem using the programming language python:
The Balance of the World
The world should be finely balanced. Positive vs. negative, light vs. shadow, and left vs. right brackets. Your mission is to write a program that judges whether a string is balanced with respect to brackets so that we ... | ```python
def is_balanced(s):
stack = []
for c in s:
if c == '(' or c == '[':
stack.append(c)
elif c == ')':
if not stack:
return "no"
elif stack[-1] == '(':
stack.pop()
else:
return "no"
elif... | vfc_66213 | {
"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": "",
"output": "",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00891 Where's Wally | Solve the following coding problem using the programming language python:
Do you know the famous series of children's books named "Where's Wally"? Each of the books contains a variety of pictures of hundreds of people. Readers are challenged to find a person called Wally in the crowd.
We can consider "Where's Wally" ... | ```python
import string
import sys
S = string.ascii_uppercase + string.ascii_lowercase + string.digits + "+/"
mod = 10**9 + 9; p = 13; q = 19
L = 1000
p_table = [1]*(L+1); q_table = [1]*(L+1)
for i in range(L):
p_table[i+1] = p_table[i] * p % mod
q_table[i+1] = q_table[i] * q % mod
readline = sys.stdin.readli... | vfc_66217 | {
"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": "48 3 3\ngAY4I4wA\ngIIgIIgg\nw4IAYAg4\ng\ng\nw\n153 3 3\nkkkkkkkkkkkkkkkkkkkkkkkkkg\nSSSSSSSSSSSSSSSSSSSSSSSSSQ\nJJJJJJJJJJJJJJJJJJJJJJJJJI\ng\nQ\nI\n1 1 2\nA\nA\nA\n384 3 2\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234... |
code_contests | verifiable_code | p01023 Caterpillar | Solve the following coding problem using the programming language python:
G, a college student living in a certain sky city, has a hornworm, Imotaro. He disciplined Imotaro to eat all the food in order with the shortest number of steps. You, his friend, decided to write a program because he asked me to find out if Imo... | ```python
from collections import deque
def main():
h, w, n = map(int, input().split())
mp = [list("#" * (w + 2))] + [list("#" + input() + "#") for _ in range(h)] + [list("#") * (w + 2)]
init_body = [None] * 4
for y in range(1, h + 1):
for x in range(1, w + 1):
if mp[y][x] == "S":
... | vfc_66221 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 8 3\n#.......\n#.####2#\n#.#.3..#\n#.######\n.1Sabcde",
"output": "14",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 6 2\n.1.baS\n.2.cde",
"output": "7",
"type": "stdin_stdo... |
code_contests | verifiable_code | p01155 Ruins | Solve the following coding problem using the programming language python:
In 1936, a dictator Hiedler who aimed at world domination had a deep obsession with the Lost Ark. A person with this ark would gain mystic power according to legend. To break the ambition of the dictator, ACM (the Alliance of Crusaders against M... | ```python
import math
while(1):
[a,b]=[int(x) for x in raw_input().split()]
if a==0:
break
else:
anum=[]
bnum=[]
ruinmin=10000**2*3
for i in range(1,101):
if a%i==0 and math.sqrt(a)>=i:
anum.append([i,a/i])
if b%i==0 and math.sq... | vfc_66225 | {
"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": "33 40\n57 144\n0 0",
"output": "22\n94",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "66 40\n57 144\n0 0",
"output": "14\n94\n",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | p01294 For the Peace | Solve the following coding problem using the programming language python:
This is a story of a world somewhere far from the earth. In this world, the land is parted into a number of countries ruled by empires. This world is not very peaceful: they have been involved in army race.
They are competing in production of m... | ```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_66229 | {
"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 3\n3 4 1 1\n2 1 5\n2 3 3\n3 3\n3 2 3 1\n2 1 5\n2 3 3\n0 0",
"output": "Yes\nNo",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p01463 Runaway Domino | Solve the following coding problem using the programming language python:
``Domino effect'' is a famous play using dominoes. A player sets up a chain of dominoes stood. After a chain is formed, the player topples one end of the dominoes. The first domino topples the second domino, the second topples the third and so o... | vfc_66233 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n0 0\n15 0\n5 0 1\n10 10 2",
"output": "5.0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n0 0\n10 0\n5 0 1\n9 0 3",
"output": "2.0",
"type": "stdin_stdout"
},
{
... | |
code_contests | verifiable_code | p01622 Twin book report | Solve the following coding problem using the programming language python:
At the school where the twins Ami and Mami attend, the summer vacation has already begun, and a huge amount of homework has been given this year as well. However, the two of them were still trying to go out without doing any homework today. It i... | ```python
while True:
n=int(input())
if n==0:
break
books=[]
read_t=0
write_t=0
for i in range(n):
r,w=map(int,input().split())
read_t+=r
write_t+=w
books.append((r,w))
books=sorted(books)
if books[-1][0]<=read_t//2:
print(read_t+write_t)
... | vfc_66237 | {
"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\n1 1\n3 1\n4 1\n2 1\n3\n5 3\n1 2\n1 2\n1\n1000 1000\n10\n5 62\n10 68\n15 72\n20 73\n25 75\n30 77\n35 79\n40 82\n45 100\n815 283\n6\n74 78\n53 55\n77 77\n12 13\n39 42\n1 1\n0",
"output": "14\n15\n3000\n2013\n522",
"typ... |
code_contests | verifiable_code | p01775 Rescue a Postal Worker | Solve the following coding problem using the programming language python:
D: Rescue a Postal Worker
story
You got a job at the post office, which you have long dreamed of this spring. I decided on the delivery area I was in charge of, and it was my first job with a feeling of excitement, but I didn't notice that the... | ```python
from heapq import heappush, heappop
n, m, k, p = map(int, input().split())
p -= 1
edges = [[] for _ in range(n)]
for _ in range(m):
x, y, w = map(int, input().split())
x -= 1
y -= 1
edges[x].append((y, w))
edges[y].append((x, w))
point = []
for _ in range(k):
s, t = map(int, input().split())
s ... | vfc_66241 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6 1 1\n1 3 5\n1 2 2\n2 3 1\n3 5 4\n3 4 2\n4 5 3\n3 5",
"output": "7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 6 1 1\n1 3 5\n1 1 2\n2 3 1\n3 5 4\n3 4 2\n4 5 3\n3 5",
"output":... |
code_contests | verifiable_code | p02190 Set | Solve the following coding problem using the programming language python:
Set
Given the sequence a_1, a_2, .., a_N.
How many values are there in this sequence?
input
N
a_1 a_2 ... a_N
output
Output the number of types of values in the sequence.
Constraint
* 1 \ leq N \ leq 10 ^ 5
* 1 \ leq a_i \ leq 10 ^... | ```python
n = int(input())
l = [int(i) for i in input().split()]
print(len(set(l)))
``` | vfc_66253 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 1073741824,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n8 6 9 1 2 1",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n8 5 9 1 2 1",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | p02344 Weighted Union Find Trees | Solve the following coding problem using the programming language python:
There is a sequence $A = a_0, a_1, ..., a_{n-1}$. You are given the following information and questions.
* relate$(x, y, z)$: $a_y$ is greater than $a_x$ by $z$
* diff$(x, y)$: report the difference between $a_x$ and $a_y$ $(a_y - a_x)$
Constr... | ```python
line = input()
n, q = list(map(int, line.split()))
rel = {}
for i in range(0, n):
rel[i] = []
parent = [i for i in range(0, n)]
rank = [0] * n
weight = [0] * n
def find(x):
if parent[x] == x:
return x
else:
y = find(parent[x])
weight[x] += weight[parent[x]]
parent[... | vfc_66257 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6\n0 0 2 5\n0 1 2 3\n1 0 1\n1 1 3\n0 1 4 8\n1 0 4",
"output": "2\n?\n10",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 6\n0 0 2 5\n0 1 2 3\n1 0 1\n1 1 3\n0 1 4 4\n1 0 4",
"output"... |
code_contests | verifiable_code | aran03 | Solve the following coding problem using the programming language python:
We are very near to our goal now. The enemy is being weakened continuously. But alas, sensing his fall, the hacker has spread a worm into our network. It is consuming all our files at a tremendous rate and must be stopped at all costs. The only ... | ```python
#! /usr/bin/python
# imports
import sys
import StringIO
class Problem(object):
def __init__(self, reader):
self.reader = reader
def run(self):
testCaseCount = int(self.reader.readline().strip())
for testCase in range(testCaseCount):
... | vfc_66265 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n34\n156\n893",
"output": "6\n0\n13\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n34\n156\n1132",
"output": "6\n0\n5\n",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | cinema | Solve the following coding problem using the programming language python:
Chef likes to watch movies very much.A movie of his favorite actress has recently released and he wants to go to cinema hall with his friends to watch the movie.
But he will book tickets for him and his friends only if he gets the seats in his d... | ```python
import sys
times=input()
while times:
times-=1
a,b=[int(x) for x in sys.stdin.readline().strip().split()]
c,d=[int(x) for x in sys.stdin.readline().strip().split()]
p=a
t=[]
while p:
p=p-1
l=list(sys.stdin.readline().strip())
t+=[l]
i=0
count=0
count2=[]
while i<a-c+1:
j=0
whi... | vfc_66269 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2 6\n2 3\n.####.\n.#####",
"output": "2\n0 1\n0 2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | facteasy | Solve the following coding problem using the programming language python:
Given a number n , find its factorial.
Input
There is a single positive integer T on the first line of input. It stands for the number of numbers to follow. Then there are T lines, each containing exactly one positive integer number N, 1 ≤ ... | ```python
import math
t = input();
for i in range(t):
x = input();
print math.factorial(x);
``` | vfc_66273 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5\n2\n7",
"output": "120\n2\n5040\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n9\n2\n7",
"output": "362880\n2\n5040\n",
"type": "stdin_stdout"
},
{
"fn_n... |
code_contests | verifiable_code | lch15jef | Solve the following coding problem using the programming language python:
Leonid is developing new programming language. The key feature of his language is fast multiplication and raising to a power operations. He is asking you to help with the following task.
You have an expression S and positive integer M. S has th... | ```python
import math
t = int(input())
for _ in range(t):
M,S = raw_input().split()
M = int(M)
S = S.split('*')
ans = 1
for i in range(0, len(S), 3):
ans = (ans * pow(int(S[i]), int(S[i+2]), M)) % M
print(ans)
``` | vfc_66277 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1000 2**3*3**1\n100000 11**2*2**4",
"output": "24\n1936\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1000 2**3*3**1\n100000 4**2*2**11",
"output": "24\n32768\n",
"type... |
code_contests | verifiable_code | permut2 | Solve the following coding problem using the programming language python:
Some programming contest problems are really tricky: not only do they
require a different output format from what you might have expected, but
also the sample output does not show the difference. For an example,
let us look at permutations.
A pe... | ```python
while True:
n=int(raw_input())
if n==0:
break
else:
A=[]
A = map(int,raw_input().split())
j=1
flag=0
for i in A:
if j!=A[i-1]:
flag=1
break
j+=1
if flag == 0:
print "ambiguous"
else:
... | vfc_66281 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 4 3 2\n5\n2 3 4 5 1\n1\n1\n0",
"output": "ambiguous\nnot ambiguous\nambiguous\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 4 3 4\n5\n2 3 4 5 1\n1\n1\n0",
"output": "not ... |
code_contests | verifiable_code | stkenc | Solve the following coding problem using the programming language python:
For Turbo C++ Users : Read the following document before attempting the question :
For C and C++ users, use long long instead of int. For Java users, use long.
Problem description
Data here, Data There. Data Everywhere.
Which one is mine... | ```python
for i in range(input()):
n=input()
if n%26!=0:
r=(n/26)+1
else:
r=n/26
print r
``` | vfc_66285 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n50\n34\n23",
"output": "2\n2\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n20\n34\n23",
"output": "1\n2\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | 1009_A. Game Shopping | Solve the following coding problem using the programming language python:
Maxim wants to buy some games at the local game shop. There are n games in the shop, the i-th game costs c_i.
Maxim has a wallet which can be represented as an array of integers. His wallet contains m bills, the j-th bill has value a_j.
Games ... | ```python
n, m = map(int, input().split())
a = list( map(int, input().split()) )
b = list( map(int, input().split()) )
i, j, counter = 0, 0, 0
while( i < int(n) and j < int(m) ):
if( a[i] <= b[j] ):
i += 1
j += 1
counter += 1
else:
i += 1
print(counter)
``` | vfc_66289 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4\n2 4 5 2 4\n5 3 4 6\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n20 40 50 20 40\n19 20\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 1031_D. Minimum path | Solve the following coding problem using the programming language python:
You are given a matrix of size n × n filled with lowercase English letters. You can change no more than k letters in this matrix.
Consider all paths from the upper left corner to the lower right corner that move from a cell to its neighboring c... | ```python
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self... | vfc_66293 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\nbwwwz\nhrhdh\nsepsp\nsqfaf\najbvw\n",
"output": "aaaepfafw",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 6\nypnxnnp\npnxonpm\nnxanpou\nxnnpmud\nnhtdudu\nnpmuduh\npmutsnz\n",
"... |
code_contests | verifiable_code | 1054_D. Changing Array | Solve the following coding problem using the programming language python:
At a break Vanya came to the class and saw an array of n k-bit integers a_1, a_2, …, a_n on the board. An integer x is called a k-bit integer if 0 ≤ x ≤ 2^k - 1.
Of course, Vanya was not able to resist and started changing the numbers written ... | ```python
n,k=list(map(int,input().split()))
arr=list(map(int,input().split()))
newarr=[0]
for num in arr:
newarr+=[newarr[-1]^num]
dic={}
for num in newarr:
x=(min(num,2**k-1-num),max(num,2**k-1-num))
if x in dic:
dic[x]+=1
else:
dic[x]=1
ans=0
for elem in dic:
m=dic[elem]
half=m//2
ans+=half*(h... | vfc_66297 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n1 3 0\n",
"output": "5",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1076_D. Edge Deletion | Solve the following coding problem using the programming language python:
You are given an undirected connected weighted graph consisting of n vertices and m edges. Let's denote the length of the shortest path from vertex 1 to vertex i as d_i.
You have to erase some edges of the graph so that at most k edges remain.... | ```python
import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n,m,k = map(int, input().split())
g = [[] for i in range(n)]
toid = {}
for i in range(m):
x,y,w = map(int, input().split())
x,y = x-1, y-1
g[x].append((w,y))
g[y].append((w,x))
toid[(x,y)] = i
toid[(y... | vfc_66301 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 5 2\n4 1 8\n2 4 1\n2 1 3\n3 4 9\n3 1 5\n",
"output": "2\n3 2 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3 2\n1 2 1\n3 2 1\n1 3 3\n",
"output": "2\n1 2 ",
"type": "std... |
code_contests | verifiable_code | 1097_D. Makoto and a Blackboard | Solve the following coding problem using the programming language python:
Makoto has a big blackboard with a positive integer n written on it. He will perform the following action exactly k times:
Suppose the number currently written on the blackboard is v. He will randomly pick one of the divisors of v (possibly 1 a... | ```python
import time
mod = int(1e9 + 7)
def fast_expo(x, k):
ans = 1
while k > 0:
if (k & 1) > 0:
ans = (ans * x) % mod
x = (x * x) % mod
k >>= 1
return ans
def inverse(x):
return fast_expo(x, mod - 2)
N, K = [int(_) for _ in input().split()]
start_time = time.ti... | vfc_66305 | {
"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 2\n",
"output": "875000008\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "60 5\n",
"output": "237178099\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1118_D2. Coffee and Coursework (Hard Version) | Solve the following coding problem using the programming language python:
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup Polycarp has a_i caffeine in it. Poly... | ```python
import sys
n,m=map(int,input().split())
A=list(map(int,input().split()))
if sum(A)<m:
print(-1)
sys.exit()
A.sort(reverse=True)
MIN=1
MAX=n
while MIN!=MAX:
d=(MIN+MAX)//2
ANS=0
j=0
count=0
for a in A:
if a<=j:
continue
ANS+=(a-j)
... | vfc_66309 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 26\n5 5 5 5 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 16\n5 5 5 5 5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null... |
code_contests | verifiable_code | 1145_A. Thanos Sort | Solve the following coding problem using the programming language python:
[Thanos sort](https://codegolf.stackexchange.com/questions/182221/implement-the-thanos-sorting-algorithm) is a supervillain sorting algorithm, which works as follows: if the array is not sorted, snap your fingers* to remove the first or the seco... | ```python
n = int(input())
a = list(map(int, input().split(' ')))
ans = 1
length = 2
while length <= n:
for i in range(0, n // length):
b = a[i * length: (i + 1) * length]
ok = True
for j in range(len(b) - 1):
if b[j] > b[j + 1]:
ok = False
break
... | vfc_66313 | {
"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\n7 6 5 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n11 12 1 2 13 14 3 4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | 1165_F2. Microtransactions (hard version) | Solve the following coding problem using the programming language python:
The only difference between easy and hard versions is constraints.
Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these m... | ```python
import math
from collections import defaultdict
import sys
#input = sys.stdin.readline
def main():
n, m = map(int, input().split())
k = list(map(int, input().split()))
sales = [(0, 0)] * m
for i in range(m):
a, b = map(int, input().split())
sales[i] = (b, a)
def check(da... | vfc_66317 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6\n1 2 0 2 0\n2 4\n3 3\n1 5\n1 2\n1 5\n2 3\n",
"output": "8\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1203_C. Common Divisors | Solve the following coding problem using the programming language python:
You are given an array a consisting of n integers.
Your task is to say the number of such positive integers x such that x divides each number from the array. In other words, you have to find the number of common divisors of all elements in the ... | ```python
import math
n = int(input())
l=list(map(int,input().split()))
hcf = l[0]
for i in l[1:]:
hcf = math.gcd(hcf,i)
count = 0
for i in range(1, int(math.sqrt(hcf))+1):
if hcf % i == 0 : count += 2
if hcf == 1: print(count - 1)
else:
if int(math.sqrt(hcf)) * int(math.sqrt(hcf)) == hcf :
count -... | vfc_66325 | {
"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\n1 2 3 4 5\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 121_E. Lucky Array | Solve the following coding problem using the programming language python:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has an array consis... | vfc_66329 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 6\n2 3 4\ncount 1 3\ncount 1 2\nadd 1 3 2\ncount 1 3\nadd 2 3 3\ncount 1 3\n",
"output": "1\n0\n1\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5\n4 4 4 4\ncount 1 4\nadd 1 4 3\nc... | |
code_contests | verifiable_code | 1245_B. Restricted RPS | Solve the following coding problem using the programming language python:
Let n be a positive integer. Let a, b, c be nonnegative integers such that a + b + c = n.
Alice and Bob are gonna play rock-paper-scissors n times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock a times, ... | ```python
from math import ceil
t = int(input())
slow = {"S": "R", "R": "P", "P": "S"}
for _ in range(t):
n = int(input())
a, b, c = map(int, input().split())
s = input()
slow2 = {"S": a, "R": b, "P": c}
res = 0
ans = [''] * n
for i in range(n):
if slow2[s[i]] > 0:
res ... | vfc_66333 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n1 1 1\nRPS\n3\n3 0 0\nRPS\n",
"output": "YES\nPSR\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n19\n2 8 9\nRRPPPPPPPPSSSSSSSSS\n",
"output": "YES\nPPSSSSSSSSRRPPPPPPS\... |
code_contests | verifiable_code | 1264_F. Beautiful Fibonacci Problem | Solve the following coding problem using the programming language python:
The well-known Fibonacci sequence F_0, F_1, F_2,… is defined as follows:
* F_0 = 0, F_1 = 1.
* For each i ≥ 2: F_i = F_{i - 1} + F_{i - 2}.
Given an increasing arithmetic sequence of positive integers with n elements: (a, a + d, a + ... | ```python
o,m,k=map(int,input().split())
print(368131125*m%10**9*12*10**9+1,368131125*k%10**9*12*10**9)
``` | vfc_66337 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 1 2\n",
"output": "4417573500000000001 8835147000000000000\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1286_C1. Madhouse (Easy version) | Solve the following coding problem using the programming language python:
This problem is different with hard version only by constraints on total answers length
It is an interactive problem
Venya joined a tour to the madhouse, in which orderlies play with patients the following game. Orderlies pick a string s of le... | ```python
from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline
# M = mod = 998244353
def factors(n):return sorted(list(set(reduce(list.__add__,([i, n//i] for i in rang... | vfc_66341 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n\na\naa\na\n\ncb\nb\nc\n\nc",
"output": "? 1 2\n? 2 2\n? 1 4\n! aacb\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\noooooooooooooooooooooooooooooooooooooooooooooooooosssssssssssss... |
code_contests | verifiable_code | 1305_D. Kuroni and the Celebration | Solve the following coding problem using the programming language python:
This is an interactive problem.
After getting AC after 13 Time Limit Exceeded verdicts on a geometry problem, Kuroni went to an Italian restaurant to celebrate this holy achievement. Unfortunately, the excess sauce disoriented him, and he's now... | vfc_66345 | {
"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\n1 4\n4 2\n5 3\n6 3\n2 3\n\n3\n\n4\n\n4\n\n",
"output": "? 1 5\n? 4 6\n! 4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3\n3 2\n2 4\n4 1\n5 2\n",
"output": "? 1 5\n! 2",
"... | |
code_contests | verifiable_code | 132_A. Turing Tape | Solve the following coding problem using the programming language python:
INTERCAL is the oldest of esoteric programming languages. One of its many weird features is the method of character-based output, known as Turing Tape method. It converts an array of unsigned 8-bit integers into a sequence of characters to print... | ```python
ans=0
for i in input():
t=bin(ord(i))[2::][::-1]
k=int(t+"0"*(8-len(t)),2)
print((ans-k)%256)
ans=k
``` | vfc_66349 | {
"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": "Hello, World!\n",
"output": "238\n108\n112\n0\n64\n194\n48\n26\n244\n168\n24\n16\n162\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1349_F1. Slime and Sequences (Easy Version) | Solve the following coding problem using the programming language python:
Note that the only differences between easy and hard versions are the constraints on n and the time limit. You can make hacks only if all versions are solved.
Slime is interested in sequences. He defined good positive integer sequences p of len... | vfc_66353 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "10 7 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "3 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\... | |
code_contests | verifiable_code | 1416_F. Showing Off | Solve the following coding problem using the programming language python:
Another dull quarantine day was going by when BThero decided to start researching matrices of size n × m. The rows are numerated 1 through n from top to bottom, and the columns are numerated 1 through m from left to right. The cell in the i-th r... | vfc_66365 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 6, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 4\n7 6 7 8\n5 5 4 4\n5 7 4 4\n1 1\n5\n",
"output": "YES\n1 1 1 1 \n4 1 3 1 \n1 2 1 3 \nR D L L \nD R R L \nU L R L \nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n5 5\n4 4 2 2... | |
code_contests | verifiable_code | 1458_D. Flip and Reverse | Solve the following coding problem using the programming language python:
You are given a string s of 0's and 1's. You are allowed to perform the following operation:
* choose a non-empty contiguous substring of s that contains an equal number of 0's and 1's;
* flip all characters in the substring, that is, repla... | ```python
# test Arpa code
import io,os, sys
input = sys.stdin.readline
print = sys.stdout.write
t = int(input())
START = 500001
seen = [0] * (2 * START)
while t > 0:
t -= 1
s = input().strip("\n")
cur = START
for c in s:
if c == '0':
seen[cur] += 1
cur -= 1
els... | vfc_66373 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n100101\n1100011\n10101010\n",
"output": "\n010110\n0110110\n10101010\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n0\n1\n",
"output": "0\n1\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 1508_E. Tree Calendar | Solve the following coding problem using the programming language python:
Yuu Koito and Touko Nanami are newlyweds! On the wedding day, Yuu gifted Touko a directed tree with n nodes and rooted at 1, and a labeling a which is some DFS order of the tree. Every edge in this tree is directed away from the root.
After cal... | vfc_66381 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n4 5 2 1 7 6 3\n1 5\n7 6\n1 2\n2 7\n3 4\n1 3\n",
"output": "\nYES\n5\n1 4 2 3 7 6 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n7 6 5 3 1 4 2\n4 3\n2 5\n3 7\n1 4\n7 2\n2 6\n",
... | |
code_contests | verifiable_code | 1534_F1. Falling Sand (Easy Version) | Solve the following coding problem using the programming language python:
This is the easy version of the problem. The difference between the versions is the constraints on a_i. You can make hacks only if all versions of the problem are solved.
Little Dormi has recently received a puzzle from his friend and needs you... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
def scc(E):
n = len(E)
iE = [[] for _ in range(n)]
for i, e in enumerate(E):
for v in e:
iE[v].append(i)
T = []
done = [0] * n # 0 -> 1 -> 2
ct = 0
for i0 in range(n):
if done[i0]: continue
... | vfc_66385 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 7\n#....#.\n.#.#...\n#....#.\n#....##\n#.#....\n4 1 1 1 0 3 1\n",
"output": "\n3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 162_C. Prime factorization | Solve the following coding problem using the programming language python:
You are given a positive integer n. Output its prime factorization.
If n = a1b1 a2b2 ... akbk (bi > 0), where ak are prime numbers, the output of your program should look as follows: a1*...*a1*a2*...*a2*...*ak*...*ak, where the factors are orde... | vfc_66389 | {
"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": "245\n",
"output": "5*7*7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "19\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13\... | |
code_contests | verifiable_code | 181_D. Word Cut | Solve the following coding problem using the programming language python:
Let's consider one interesting word game. In this game you should transform one word into another through special operations.
Let's say we have word w, let's split this word into two non-empty parts x and y so, that w = xy. A split operation i... | ```python
MOD = int(1e9) + 7
if __name__ == "__main__":
a = input()
b = input()
k = int(input())
if(len(a) != len(b)):
print(0)
exit()
a = a + a
x = 0
y = 0
for i in range(len(a) // 2):
flag = 1
for j in range(len(b)):
if(a[j + i] != b[j]):
... | vfc_66393 | {
"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": "ababab\nababab\n1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "ab\nab\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 205_A. Little Elephant and Rozdil | Solve the following coding problem using the programming language python:
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on... | ```python
n = int(input())
string = input()
times = list(map(int, string.split()))
a = min(times)
if times.count(a) == 1:
print(times.index(a) + 1)
else:
print("Still Rozdil")
``` | vfc_66397 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n7 4 47 100 4 9 12\n",
"output": "Still Rozdil",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n7 4\n",
"output": "2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 253_C. Text Editor | Solve the following coding problem using the programming language python:
Vasya is pressing the keys on the keyboard reluctantly, squeezing out his ideas on the classical epos depicted in Homer's Odysseus... How can he explain to his literature teacher that he isn't going to become a writer? In fact, he is going to be... | vfc_66405 | {
"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\n10 1 10\n1 10 1 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n2 1 6 4\n3 4 4 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_nam... | |
code_contests | verifiable_code | 278_D. Set of Points | Solve the following coding problem using the programming language python:
Convexity of a set of points on the plane is the size of the largest subset of points that form a convex polygon. Your task is to build a set of n points with the convexity of exactly m. Your set of points should not contain three points that li... | ```python
def f(x):
return int(x * x + 1e7)
def g(x):
return -f(x)
n, m = map(int, input().split())
if(m == 3):
if(n == 3):
print('0 0')
print('1 0')
print('0 1')
elif(n == 4):
print('0 0')
print('1 1')
print('10000 0')
print('0 10000')
... | vfc_66409 | {
"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 6\n",
"output": "0 10000000\n1 10000001\n2 10000004\n3 10000009\n4 10000016\n5 10000025\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n",
"output": "0 0\n3 0\n0 3\n1 1\n",
... |
code_contests | verifiable_code | 300_C. Beautiful Numbers | Solve the following coding problem using the programming language python:
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is... | ```python
MOD=10**9+7
a,b,n=list(map(int,input().strip().split(' ')))
#there are i a's. n-i b's
def check(a,b,x):
temp=x%10
if temp!=a and temp!=b:
return 0
while(x>0):
temp=x%10
if temp!=a and temp!=b:
return 0
x=x//10
return 1
fact=[1]
infact=[1]
temp=... | vfc_66413 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 3 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3 10\n",
"output": "165\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "... |
code_contests | verifiable_code | 327_A. Flipping Game | Solve the following coding problem using the programming language python:
Iahub got bored, so he invented a game to be played on paper.
He writes n integers a1, a2, ..., an. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices i and j (1 ≤ i ≤ j ≤ n) and flips all ... | ```python
n=int(input())
a = list(map(int, input().split()))
mas=[0]*n
if a[0]==0:
mas[0]=1
else:
mas[0]=-1
m=mas[0]
for i in range(1,n):
mas[i]=max( mas[i-1] + (-1)**a[i], (-1)**a[i])
m=max(m,mas[i])
print(a.count(1)+m)
``` | vfc_66417 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 0 0 1\n",
"output": "4",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 372_C. Watching Fireworks is Fun | Solve the following coding problem using the programming language python:
A festival will be held in a town's main street. There are n sections in the main street. The sections are numbered 1 through n from left to right. The distance between each adjacent sections is 1.
In the festival m fireworks will be launched. ... | ```python
from collections import deque
n,m,v=map(int,input().split())
x,t,b,bt,dp,mi,mi2,mi3,dpmin,dp2=[0]*300,[0]*300,0,0,[[0]*2for i in range(150001)],0,100000000000000,10000000000000,0,[0]*150001
d=deque()
for i in range(m):
x[i],b,t[i]=map(int,input().split())
bt+=b
for i2 in range(m-1):
if i2==0:
... | vfc_66425 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "50 3 1\n49 1 1\n26 1 4\n6 1 10\n",
"output": " -31\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 2 1\n1 1000 4\n9 1000 4\n"... |
code_contests | verifiable_code | 393_E. Yet Another Number Sequence | Solve the following coding problem using the programming language python:
Everyone knows what the Fibonacci sequence is. This sequence can be defined by the recurrence relation:
F1 = 1, F2 = 2, Fi = Fi - 1 + Fi - 2 (i > 2).
We'll define a new number sequence Ai(k) by the formula:
Ai(k) = Fi × ik (i ≥ 1).
In this... | vfc_66429 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n",
"output": "316\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 4\n... | |
code_contests | verifiable_code | 417_A. Elimination | Solve the following coding problem using the programming language python:
The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds.
The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of c proble... | ```python
import math
c,d = map(int,input().split())
n,m = map(int,input().split())
k=int(input())
if k>=n*m:
print('0')
else:
left=n*m-k
t=c*(math.ceil(left/n))
j= c*(left//n) + (left%n)*d
l=d*(left)
print(min(t,j,l))
``` | vfc_66433 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n2 1\n2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 10\n7 2\n1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 443_D. Andrey and Problem | Solve the following coding problem using the programming language python:
Andrey needs one more problem to conduct a programming contest. He has n friends who are always willing to help. He can ask some of them to come up with a contest problem. Andrey knows one value for each of his fiends — the probability that this... | ```python
n = input()
ans = tmp = 0.0
prod = 1.0
for p in reversed(sorted(map(float, input().split()))):
tmp = tmp * (1.0 - p) + prod * p
prod *= 1.0 - p
ans = max(ans, tmp)
print('%0.9f' % ans)
``` | vfc_66437 | {
"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\n0.1 0.2 0.3 0.8\n",
"output": "0.8000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n0.1 0.2\n",
"output": "0.2600000000\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 465_E. Substitutes in Number | Solve the following coding problem using the programming language python:
Andrew and Eugene are playing a game. Initially, Andrew has string s, consisting of digits. Eugene sends Andrew multiple queries of type "di → ti", that means "replace all digits di in string s with substrings equal to ti". For example, if s = 1... | ```python
MOD = 10**9+7
s = raw_input()
n = int(raw_input())
query = [['',s]]+[raw_input().split('->') for i in range(n)]
value = {}
pow10 = {}
for i in range(10):
value[str(i)] = i
pow10[str(i)] = 10
for i in range(n,-1,-1):
newValue = 0
newPow10 = 1
for d in query[i][1]:
newValue = (ne... | vfc_66441 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "123123\n1\n2->00\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "222\n2\n2->0\n0->7\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn... |
code_contests | verifiable_code | 489_D. Unbearable Controversy of Being | Solve the following coding problem using the programming language python:
Tomash keeps wandering off and getting lost while he is walking along the streets of Berland. It's no surprise! In his home town, for any pair of intersections there is exactly one way to walk from one intersection to the other one. The capital ... | ```python
import sys
from collections import defaultdict, Counter
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
input = sys.stdin.readline
n, m = map(int, input().split())
g = defaultdict(list)
for _ in range(m):
a, b = map(int, input().split())
g[a-1].append(b-1)
# print(g)
rh... | vfc_66445 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 12\n1 2\n1 3\n1 4\n2 1\n2 3\n2 4\n3 1\n3 2\n3 4\n4 1\n4 2\n4 3\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 4\n1 2\n2 3\n1 4\n4 3\n",
"output": "1\n",
... |
code_contests | verifiable_code | 513_B2. Permutations | Solve the following coding problem using the programming language python:
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum:
<image>
Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p).
Input
The si... | ```python
n, m = map(int, input().split())
s = 1
c = n - 1
arr = [0] * n
i = 0
while i <= c:
r = 0
j = s
while j <= n and r < m:
if j < n:
r += 2 ** (n - j - 1)
j += 1
#print(s, j, r, m)
if j > s and j != n + 1:
r -= 2 ** (n - j)
m -= r
j -= 1
arr[i] =... | vfc_66449 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n",
"output": "2 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n",
"output": "1 3 2 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | 538_D. Weird Chess | Solve the following coding problem using the programming language python:
Igor has been into chess for a long time and now he is sick of the game by the ordinary rules. He is going to think of new rules of the game and become world famous.
Igor's chessboard is a square of size n × n cells. Igor decided that simple ru... | ```python
import sys
fin = sys.stdin
n = int(fin.readline())
ma = [[None]] * n
for i in range(0, n):
aux = fin.readline()
aux = aux[:-1]
ma[i] = list(aux)
r = []
for i in range(0, 2 * n - 1):
r.append(None)
r[i] = []
for j in range(0, 2 * n - 1):
r[i].append('x')
for i in range(0, n):
... | vfc_66453 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\noxxxx\nx...x\nx...x\nx...x\nxxxxo\n",
"output": "YES\nxxxxxxxxx\nx...xxxxx\nx...xxxxx\nx...xxxxx\nxxxxoxxxx\nxxxxx...x\nxxxxx...x\nxxxxx...x\nxxxxxxxxx\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 566_E. Restoring Map | Solve the following coding problem using the programming language python:
Archaeologists found some information about an ancient land of Treeland. We know for sure that the Treeland consisted of n cities connected by the n - 1 road, such that you can get from each city to any other one along the roads. However, the in... | vfc_66457 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n4 3 2 4 1\n5 5 3 2 4 1\n5 4 2 1 5 3\n4 2 1 4 3\n3 1 4 5\n",
"output": "1 4\n1 2\n1 3\n4 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n5 6 1 3 4 2\n5 2 1 3 4 6\n6 3 6 2 5 4 1\n6 6... | |
code_contests | verifiable_code | 587_F. Duff is Mad | Solve the following coding problem using the programming language python:
Duff is mad at her friends. That's why she sometimes makes Malek to take candy from one of her friends for no reason!
<image>
She has n friends. Her i-th friend's name is si (their names are not necessarily unique). q times, she asks Malek to ... | vfc_66461 | {
"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": "5 5\na\nab\nabab\nababab\nb\n1 5 4\n3 5 4\n1 5 2\n1 5 3\n1 4 1\n",
"output": "12\n6\n3\n7\n1\n\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 60_B. Serial Time! | Solve the following coding problem using the programming language python:
The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallele... | ```python
from collections import deque
class CodeforcesTask60BSolution:
def __init__(self):
self.result = ''
self.k_n_m = []
self.plate = []
self.tape = []
def read_input(self):
self.k_n_m = [int(x) for x in input().split(" ")]
for x in range(self.k_n_m[0]):
... | vfc_66465 | {
"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 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2\n",
"output": "7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1\n",
"output": "5",
"type": "stdin_std... |
code_contests | verifiable_code | 630_G. Challenge Pennants | Solve the following coding problem using the programming language python:
Because of budget cuts one IT company established new non-financial reward system instead of bonuses.
Two kinds of actions are rewarded: fixing critical bugs and suggesting new interesting features. A man who fixed a critical bug gets "I fixed ... | ```python
from functools import reduce
def c(n, m):
return 0 if n>m or n<0 else reduce(lambda a,b: a*b, range(m-n+1, m+1), 1)//reduce(lambda a,b: a*b, range(1,n+1), 1)
n = int(input())
print(sum([c(i, n)*c(i-1, 2) for i in range(1, 4)])*sum([c(i, n)*c(i-1, 4) for i in range(1, 6)]))
``` | vfc_66469 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n",
"output": "24",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 658_D. Bear and Polynomials | Solve the following coding problem using the programming language python:
Limak is a little polar bear. He doesn't have many toys and thus he often plays with polynomials.
He considers a polynomial valid if its degree is n and its coefficients are integers not exceeding k by the absolute value. More formally:
Let a0... | ```python
def convert_to_binary(coef):
res = []
n = len(coef)
carry = 0
i = 0
while i < n + 1000:
if i >= n and not carry:
break
cur = carry
if i < n:
cur += coef[i]
mod = cur % 2
div = cur // 2
# print(cur, div, mod)
r... | vfc_66473 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 12\n10 -9 -3 5\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 20\n14 -7 19\n",
"output": "0",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 681_A. A Good Contest | Solve the following coding problem using the programming language python:
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his r... | ```python
#!/usr/bin/env python3
if __name__ == '__main__':
n = int(input())
for _ in range(n):
handle, prev, curr = input().split()
prev = int(prev)
curr = int(curr)
if prev < 2400:
continue
if curr > prev:
print('YES')
break
el... | vfc_66477 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber ... |
code_contests | verifiable_code | 703_E. Mishka and Divisors | Solve the following coding problem using the programming language python:
After playing with her beautiful array, Mishka decided to learn some math. After learning how to multiply, divide and what is divisibility, she is now interested in solving the following problem.
You are given integer k and array a1, a2, ..., a... | vfc_66481 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 60\n2 4 6 5 2\n",
"output": "3\n4 3 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n3 2 1\n",
"output": "1\n3\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 725_E. Too Much Money | Solve the following coding problem using the programming language python:
Alfred wants to buy a toy moose that costs c dollars. The store doesn’t give change, so he must give the store exactly c dollars, no more and no less. He has n coins. To make c dollars from his coins, he follows the following algorithm: let S be... | ```python
#!/usr/bin/env python
import sys
alf_goal = int(sys.stdin.readline().strip())
num_coins = int(sys.stdin.readline().strip())
alf_coins = []
for i in range(num_coins):
alf_coins.append(int(sys.stdin.readline().strip()))
cnt = [0]*(alf_goal+1) # this is just the count of the coins you have.
pre = [0]*(alf_... | vfc_66485 | {
"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": "12\n3\n5\n3\n4\n",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "50\n8\n1\n2\n4\n8\n16\n37\n37\n37\n",
"output": "Greed is good",
"type": "stdin_stdout"
}
]
... |
code_contests | verifiable_code | 747_E. Comments | Solve the following coding problem using the programming language python:
A rare article in the Internet is posted without a possibility to comment it. On a Polycarp's website each article has comments feed.
Each comment on Polycarp's website is a non-empty string consisting of uppercase and lowercase letters of Engl... | ```python
from queue import Queue
def parse(s):
A = s.split(',')
n = len(A)//2
B = [(A[2*i], int(A[2*i+1])) for i in range(n)]
stack = []
E = {i:[] for i in range(n+1)}
comment = {}
depth = {i:0 for i in range(n+1)}
for i, b in enumerate(reversed(B)):
comment[i+1] = b[0]
... | vfc_66489 | {
"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": "A,3,B,2,C,0,D,1,E,0,F,1,G,0,H,1,I,1,J,0,K,1,L,0,M,2,N,0,O,1,P,0\n",
"output": "4\nA K M \nB F H L N O \nC D G I P \nE J \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "a,5,A,0,a,0,A,0,a,0... |
code_contests | verifiable_code | 770_B. Maximize Sum of Digits | Solve the following coding problem using the programming language python:
Anton has the integer x. He is interested what positive integer, which doesn't exceed x, has the maximum sum of digits.
Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the big... | ```python
num = list(input())
orgnum = num.copy()
if len(num) == 1:
print(num[0])
elif num[1:] != list("9"*(len(num)-1)):
if num[1:] == list("8"+"9"*(len(num)-2)):
print(int("".join(num)))
elif "9" in num:
finished = False
did = False
for i in range(len(num)):
if ... | vfc_66493 | {
"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": "521\n",
"output": "499\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 794_E. Choosing Carrot | Solve the following coding problem using the programming language python:
Oleg the bank client and Igor the analyst are arguing again. This time, they want to pick a gift as a present for their friend, ZS the coder. After a long thought, they decided that their friend loves to eat carrots the most and thus they want t... | ```python
def evens(A):
n = len(A)
l = n//2-1; r = n//2
if len(A)%2 == 1: l+= 1
ans = [max(A[l], A[r])]
while r < n-1:
l-= 1; r+= 1
ans.append(max(ans[-1], A[l], A[r]))
return ans
def interleave(A, B):
q = []
for i in range(len(B)): q+= [A[i], B[i]]
if len(A) != len(... | vfc_66497 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1000000000 1000000000 1000000000 1000000000 1\n",
"output": "1000000000 1000000000 1000000000 1000000000 1000000000 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 2 3 5\n",
... |
code_contests | verifiable_code | 860_E. Arkady and a Nobody-men | Solve the following coding problem using the programming language python:
Arkady words in a large company. There are n employees working in a system of a strict hierarchy. Namely, each employee, with an exception of the CEO, has exactly one immediate manager. The CEO is a manager (through a chain of immediate managers... | vfc_66509 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n0 1 1 1 3\n",
"output": "0 3 3 3 5 \n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 887_D. Ratings and Reality Shows | Solve the following coding problem using the programming language python:
There are two main kinds of events in the life of top-model: fashion shows and photo shoots. Participating in any of these events affects the rating of appropriate top-model. After each photo shoot model's rating increases by a and after each fa... | ```python
from sys import stdin
from collections import deque
def main():
n, a, b, c, d, st, l = map(int, input().split())
q = deque()
po = q.popleft
pu = q.append
mq = deque()
mpop = mq.pop
mpo = mq.popleft
mpu = mq.append
sb = [0] * (n + 1)
mst = st
pu((0, 0, mst, st))
... | vfc_66513 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 1 1 1 4 0 5\n1 1\n2 1\n3 1\n4 0\n5 0\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 2 1 2 1 2\n1 0\n",
"output": "-1\n",
"type": "stdin_stdout"
}
... |
code_contests | verifiable_code | 90_D. Widget Library | Solve the following coding problem using the programming language python:
Vasya writes his own library for building graphical user interface. Vasya called his creation VTK (VasyaToolKit). One of the interesting aspects of this library is that widgets are packed in each other.
A widget is some element of graphical in... | ```python
import sys
from array import array # noqa: F401
import re
def input():
return sys.stdin.buffer.readline().decode('utf-8')
class Widget(object):
def __init__(self, x, y):
self.x = x
self.y = y
class Box(object):
def __init__(self):
self.children = []
self.bord... | vfc_66517 | {
"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": "15\nWidget pack(10,10)\nHBox dummy\nHBox x\nVBox y\ny.pack(dummy)\ny.set_border(5)\ny.set_spacing(55)\ndummy.set_border(10)\ndummy.set_spacing(20)\nx.set_border(10)\nx.set_spacing(10)\nx.pack(pack)\nx.pack(dummy)\nx.pack(pack)\nx.s... |
code_contests | verifiable_code | 932_A. Palindromic Supersequence | Solve the following coding problem using the programming language python:
You are given a string A. Find a string B, where B is a palindrome and A is a subsequence of B.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the ord... | ```python
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 15 21:01:05 2018
@author: DNARNAprotein
"""
"""
CODEFORCES
http://codeforces.com/contest/932/problem/A
"""
def pikachu(a,c,n): #c is original string
prefixes=[a[0:i+1] for i in range(n+1)]
suffixes=[a[i:n+1] for i in range(n+1)]
maxi=0
for i in... | vfc_66521 | {
"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": "ab\n",
"output": "abba\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "aba\n",
"output": "abaaba\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "... |
code_contests | verifiable_code | 959_B. Mahmoud and Ehab and the message | Solve the following coding problem using the programming language python:
Mahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from 1 to n. Some words have the same meaning so there are k groups of words such that all the words in some group have the same meaning.
Mahmoud kn... | ```python
a = list(map(int,input().split(" ")))
n,k,m = a[0],a[1],a[2]
words = list(input().split(" "))
cost = list(map(int,input().split(" ")))
dic = {}
for i in range(k):
tmp = list(map(int,input().split(" ")))
if tmp[0] == 1:
dic[words[tmp[1]-1]] = cost[tmp[1]-1]
else:
mincost = min(cost[... | vfc_66525 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4 4\ni loser am the second\n100 20 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second\n",
"output": "116",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 4 4\ni loser am the second\n100 1 1 5 ... |
code_contests | verifiable_code | 985_G. Team Players | Solve the following coding problem using the programming language python:
There are n players numbered from 0 to n-1 with ranks. The i-th player has rank i.
Players can form teams: the team should consist of three players and no pair of players in the team should have a conflict. The rank of the team is calculated us... | vfc_66529 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 1\n2 3 4\n1 0\n",
"output": "38\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 0\n2 3 4\n",
"output": "64\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
code_contests | verifiable_code | add-subtract | Solve the following coding problem using the programming language python:
Chandan is back with his array to blow your mind. As usual Chandan has an array consisting of N integers .He allows you to perform 2 kinds of operation on his array.
Type 1 : Increment any integer of the array by 1.
Type 2 : Decrement any inte... | ```python
t=int(raw_input())
n=[]
l=[]
for k in range(t):
n.append(raw_input())
l.append(raw_input())
def getmin(l):
mn=-1
# print l
for i in l:
cost=0
for j in l:
temp=i-j
#print temp
if(temp<0):
temp=abs(temp)*5
else:
temp=abs(temp)*3
cost+=temp
#print cost
if mn==-1 or mn>cost:
... | vfc_66533 | {
"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 3\n9 4 9 7 4 \n\nSAMPLE",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "83\n6 6\n36 25 6 65 95 95 \n49 31\n73 67 60 32 50 52 6 93 79 70 46 91 11 86 10 89 42 26 41 17 1 ... |
code_contests | verifiable_code | break-the-friendship-band | Solve the following coding problem using the programming language python:
On the divine friendship day, "A" tied "B" a friendship band. But alas! Frequent quarrels started between them and "B" decided to remove and break off the band! The band isnt a huge one and consists of red, blue and white beads in random positio... | ```python
n=int(raw_input())
a=raw_input()
ans=0
for i in range(0,n):
j=i+1
temp=a[i]
count=1
flag=0
while (j%n != i):
if(a[j%n]=='w' and temp=='w'):
count+=1
elif (a[j%n]=='w'):
count+=1
elif(a[j%n]!='w' and temp=='w'):
count+=1
... | vfc_66537 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "29\nwwwbbrwrbrbrrbrbrwrwwrbwrwrrb\n\nSAMPLE",
"output": "11",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "29\nwwwbbrwrbrbrrbrbrwrwwrbwrwrrb",
"output": "11",
"type": "stdin_std... |
code_contests | verifiable_code | daisy-and-the-password | Solve the following coding problem using the programming language python:
Daisy, being a good hacker as we all know, recently came across a file of the evil organization-Hydra which requires a password to open, and you have been assigned the task to help her in it.
She knows that the password of Hydra files are usual... | ```python
def process(base, s):
s = list(s)
for i in base:
for j in range(2):
if i not in s:
return "Impossible"
del s[s.index(i)]
if len(s) == 0:
return "Possible"
return "Impossible"
T = input()
for i in xrange(T):
base, s = raw_input().strip(" \n").split(" ")
print process(base, s)
``` | vfc_66541 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nHydra HydraHydra\nHydra HydraShield\nHydraShield HydraHydraShieldShield\n\nSAMPLE",
"output": "Possible\nImpossible\nPossible\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "206\nHa HaH... |
code_contests | verifiable_code | g-bear-and-cavalry-2 | Solve the following coding problem using the programming language python:
Would you want to fight against bears riding horses?
Me neither.
Limak is a grizzly bear.
He is a general of the dreadful army of Bearland.
The most important part of an army is the cavalry of course.
The cavalry of Bearland consists of N warr... | ```python
import fileinput
def solve(w, h):
h.sort()
bb = w.pop(0)*h.pop()
w.sort()
while len(w) > 0:
if w.pop(0)*h.pop() >= bb:
return "NO"
return "YES"
first = True
getn = False
getw = False
geth = False
for line in fileinput.input():
if first:
first = False
... | vfc_66545 | {
"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\n12 9 7 1 20 10\n3 6 4 7 5 5\n4\n5 17 10 1\n200 400 800 600\n\nSAMPLE",
"output": "YES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "50\n4\n100 785 393 616 \n2 45 586 236 \n4\n2... |
code_contests | verifiable_code | just-shut-up | Solve the following coding problem using the programming language python:
Atish is very talkative. He just doesn't stop speaking. Unfortunately for those around him, he's also a maths wiz, and befuddles anyone who dares speak to him. Annoyed with this, Souradeep asked him to shut up, to which Atish replied,
Take a nu... | ```python
n=input()
raw_input()
for _ in xrange(n):
m=input()
i=1
f=1
while i<=m:
f=f*i
while f%10==0:
f=f/10
f%=10000
i+=1
print f%10
``` | vfc_66549 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n\n0\n1\n24\n13\n87\n\nSAMPLE",
"output": "1\n1\n6\n8\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n\n24\n39\n1500\n9999\n9856\n857\n2365\n998\n7489\n0",
"output": "6\n8\n... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.