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 |
|---|---|---|---|---|---|---|---|
codeforces | verifiable_code | 570 | Solve the following coding problem using the programming language python:
The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first sta... | m, n = input().split()
cand = []
for i in range (int(m)):
cand.append(0)
for i in range (int(n)):
a = [int(x) for x in input().split()]
cand[a.index(max(a))] += 1
print(cand.index(max(cand)) + 1)
| vfc_84225 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n1 2 3\n2 3 1\n1 2 1",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7",
"output": "1",
"type": "stdin_stdout"
},
{
... |
codeforces | verifiable_code | 54 | Solve the following coding problem using the programming language python:
The Hedgehog likes to give presents to his friend, but no less he likes to receive them.
Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in th... | n, k = list(map(int,input().strip().split(' ')))
holidays = list(map(int,input().strip().split(' ')))[1:]
prev = 0
i = 0
inc = 0
pres = 0
while i < n:
i += 1
inc += 1
if inc == k or i in holidays:
prev = i
inc = 0
pres += 1
print(pres) | vfc_84229 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n1 3",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 1\n3 6 7 8",
"output": "10",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
codeforces | verifiable_code | 426 | Solve the following coding problem using the programming language python:
Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and *n* water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and po... | k = int(input().split()[1])
if sum(sorted(list(map(int,input().split())))[:-1]) > k:
print('NO')
else:
print('YES') | vfc_84233 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n1 1 1",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n3 1 3",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
codeforces | verifiable_code | 550 | Solve the following coding problem using the programming language python:
You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
The input will be provided via standard input and looks as follows:
The only... | s = input()
if 'AB' in s and 'BA' in s:
# Find the first occurrence of "AB" and the first occurrence of "BA" after the "AB"
ab_index = s.find('AB')
ba_index = s.find('BA', ab_index + 2)
# Check if the substrings are non-overlapping
if ba_index != -1 and ba_index != ab_index + 1:
p... | vfc_84237 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "ABA",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "BACFAB",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "AXBYBXA",... |
codeforces | verifiable_code | 382 | Solve the following coding problem using the programming language python:
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the sca... | def main():
mode="filee"
if mode=="file":f=open("test.txt","r")
#f.readline()
#input()
get = lambda :[str(x) for x in (f.readline()[:-1] if mode=="file" else input()).split("|")]
scale = get()
q = input()
if abs(len(scale[0]) - len(scale[1]))%2 != len(q)%2 or abs(len(scale[0]) - ... | vfc_84241 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "AC|T\nL",
"output": "AC|TL",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "|ABC\nXYZ",
"output": "XYZ|ABC",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
codeforces | verifiable_code | 843 | Solve the following coding problem using the programming language python:
This is an interactive problem.
You are given a sorted in increasing order singly linked list. You should find the minimum integer in the list which is greater than or equal to *x*.
More formally, there is a singly liked list built on an array... | from random import sample
from sys import stdout
read=lambda :map(int,input().split())
def ask(x):
print('? {}'.format(x))
stdout.flush()
return tuple(read())
def answer(x):
print('! {}'.format(x))
stdout.flush()
exit(0)
n,st,x=read()
a=[ask(st)]
if a[0][0]>=x: answer(a[0][0])
for i in sample(range(1,n+1),m... | vfc_84245 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3 80\n97 -1\n58 5\n16 2\n81 1\n79 4",
"output": "81\n1003",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1 6\n1 2\n2 3\n3 4\n4 5\n5 -1",
"output": "-1\n1002",
"type": "stdin... |
codeforces | verifiable_code | 482 | Solve the following coding problem using the programming language python:
Permutation *p* is an ordered set of integers *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*, consisting of *n* distinct positive integers not larger than *n*. We'll denote as *n* the length of permutation *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*.
Your t... | n, k = map(int, input().split())
cur = 1
x = 0
a = [0] * (n + 1)
while k > 0:
a[cur] = 1
print(cur, end=(' '))
if x == 0:
cur = cur + k
x = 1
else:
cur = cur - k
x = 0
k = k - 1
for i in range(1, n + 1):
if a[i] == 0:
print(i, end=' ') | vfc_84253 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2",
"output": "1 3 2",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 825 | Solve the following coding problem using the programming language python:
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' characters equal to the value of ... | n = int(input())
# print(n)
s = input()
# print(s)
k = 0
ans = ''
for c in s:
# print(c)
if c == '0':
ans += str(k)
k = 0
else:
k += 1
print(ans + str(k))
| vfc_84257 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n111",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n110011101",
"output": "2031",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "... |
codeforces | verifiable_code | 416 | Solve the following coding problem using the programming language python:
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer *y* and the participants guess it by asking questions to the host. ... | """
██╗ ██████╗ ██╗ ██████╗ ██████╗ ██╗ █████╗
██║██╔═══██╗██║ ╚════██╗██╔═████╗███║██╔══██╗
██║██║ ██║██║ █████╔╝██║██╔██║╚██║╚██████║
██║██║ ██║██║ ██╔═══╝ ████╔╝██║ ██║ ╚═══██║
██║╚██████╔╝██║ ███████╗╚██████╔╝ ██║ █████╔╝
╚═╝ ╚═════╝ ╚═╝ ╚══════╝ ╚═════╝ ╚═╝ ╚════╝
██████╗ ██╗██╗ █████... | vfc_84265 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N",
"output": "17",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n> 100 Y\n< -100 Y",
"output": "Impossible",
"type": "stdin_stdout"
},
... |
codeforces | verifiable_code | 108 | Solve the following coding problem using the programming language python:
Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring ... | s = input()
s1 = s
s1 = s1.split(":")
s1[0] = int(s1[0])
s1[1] = int(s1[1])
while(1):
s1[1] += 1
s1[1] = s1[1]%60
if s1[1] == 0:
s1[0] += 1
s1[0] = s1[0]%24
a = str(s1[0])
b = str(s1[1])
if len(a) == 1:
a = "0" + a
if len(b) == 1:
b = "0" + b
... | vfc_84269 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "12:21",
"output": "13:31",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "23:59",
"output": "00:00",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "15:... |
codeforces | verifiable_code | 84 | Solve the following coding problem using the programming language python:
The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.
There are two armies on the playing fiel... | print((3 * 2 * int(input())) // 4) | vfc_84277 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4",
"output": "6",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 154 | Solve the following coding problem using the programming language python:
Sergey attends lessons of the *N*-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the *N*-ish language. Sentences of the *N*-ish language can be represented as strings consisting of lowercase... | import sys;sc = sys.stdin.readline;out=sys.stdout.write
s=str(sc());n=int(sc());ans=0
for e in range(n):
ss=str(sc());a,b=0,0
for e in s:
if e==ss[0]:a+=1
elif e==ss[1]:b+=1
else :ans+=min(a,b);a=0;b=0
ans+=min(a,b)
out(str(ans)) | vfc_84281 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "ababa\n1\nab",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "codeforces\n2\ndo\ncs",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
codeforces | verifiable_code | 555 | Solve the following coding problem using the programming language python:
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of *n* matryoshka dolls that can be nested one into another. The matryosh... | n, k = map(int, input().split())
p = [0 for i in range(n+1)]
d = p.copy()
for i in range(k):
a = list(map(int, input().split()))
l = len(a)
for j in range(1, l - 1):
p[a[j]] = a[j+1]
d[a[j+1]] = 1
c = 1
while p[c] == c + 1:
c = p[c]
ans = 0
for i in range(c+1,n+1):
ans ... | vfc_84285 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "3000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n2 1 2\n1 3",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 3\n3 1 3 7\n2 2 5\n2 4 6",
"output": "10",
"type": "stdin_stdout"
},
{
"fn_name": n... |
codeforces | verifiable_code | 365 | Solve the following coding problem using the programming language python:
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in a... | n,m=map(int,input().split())
c=0
for _ in range(n):
a= input()
if all(list(map(lambda x: str(x) in a , range(m+1)))):
c+=1
else:
continue
print(c) | vfc_84293 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560",
"output": "10",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n1\n10",
"output": "1... |
codeforces | verifiable_code | 376 | Solve the following coding problem using the programming language python:
Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearrange them like that... | n, m = map(int, input().split())
d = [0 for i in range(n)]
for i in range(m):
a, b, c = map(int, input().split())
d[a-1] -= c
d[b-1] += c
print(sum(i for i in d if i > 0)) | vfc_84297 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n1 2 10\n2 3 1\n2 4 1",
"output": "10",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 237 | Solve the following coding problem using the programming language python:
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to... | n = int(input())
d = {}
c = 1
for i in range(n):
m,h = list(map(str, input().split()))
if m+":"+h in d.keys():
d[m+":"+h] += 1
c = max(c, d[m+":"+h])
else:
d[m+":"+h] = 1
print(c) | vfc_84301 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n8 0\n8 10\n8 10\n8 45",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n0 12\n10 11\n22 22",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name"... |
codeforces | verifiable_code | 397 | Solve the following coding problem using the programming language python:
Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexe... | n = int(input())
seta = set()
ax,ay = map(int, input().split(" "))
for i in range(ax,ay):
seta.add(i+0.5)
for i in range(0,n-1):
nx,ny = map(int, input().split(" "))
for j in range(nx,ny):
seta.discard(j+0.5)
print(len(seta)) | vfc_84305 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n0 5\n2 8\n1 6",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n0 10\n1 5\n7 15",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
codeforces | verifiable_code | 685 | Solve the following coding problem using the programming language python:
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad at math, robbers use the p... | def D(n):
x,r=n-1,1
while x>=7:
x//=7
r+=1
return r
def H(n,l):
x,r=n,""
if x==0:r+='0'
while x:
r+=chr(ord('0')+x%7)
x//=7
r+='0'*(l-len(r))
return r
a,b=map(int,input().split())
la=D(a)
lb=D(b)
V=[0]*99
r=0
def F(deep,wa,wb):
global r
if wa>=a or wb>=b:return
if deep==la+lb:
... | vfc_84309 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "3000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 2",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1",
"ou... |
codeforces | verifiable_code | 576 | Solve the following coding problem using the programming language python:
Vasya and Petya are playing a simple game. Vasya thought of number *x* between 1 and *n*, and Petya tries to guess the number.
Petya can ask questions like: "Is the unknown number divisible by number *y*?".
The game is played by the following ... | def input_ints():
return list(map(int, input().split()))
def main():
n = int(input())
ans = []
for x in range(2, n + 1):
s = set()
xx = x
for y in range(2, n + 1):
while xx % y == 0:
xx /= y
s.add(y)
if len(s) == 1... | vfc_84313 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4",
"output": "3\n2 4 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6",
"output": "4\n2 4 3 5 ",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 21 | Solve the following coding problem using the programming language python:
Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into three pieces so that the sum of n... | n,num,ways,q = int(input()),0,0,0
s = list(map(int,input().split()))
sums = sum(s)
for i in range(n):
num += s[i]
if num * 3 == sums * 2 and 0 < i < n - 1:
ways += q
if num * 3 == sums:
q += 1
print(ways) | vfc_84317 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n-3",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n0 0",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n0 0 0",... |
codeforces | verifiable_code | 17 | Solve the following coding problem using the programming language python:
Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and cal... | import math
def isprime(k):
for i in range (2, int(math.sqrt(k)+1)):
if(k%i==0):
return 0
return 1
n,k = map(int, input().split())
count = 0
lis = []
for i in range(2, n+1):
if(isprime(i)):
lis.append(i)
for i in range (0, len(lis)-1):
if((lis[i]+lis[i+1]+1) in... | vfc_84321 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "27 2",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "45 7",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 0",
... |
codeforces | verifiable_code | 446 | Solve the following coding problem using the programming language python:
DZY has a sequence *a*, consisting of *n* integers.
We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment.
Yo... | # Love u Atreyee
n = int(input())
a = list(map(int, input().split()))
left = [1] * n
for i in range(1, n):
if a[i] > a[i - 1]:
left[i] = left[i - 1] + 1
right = [1] * n
for i in range(n-2,-1,-1):
if a[i] < a[i + 1]:
right[i] = right[i + 1] + 1
ans = max(left)
if ans < n:
ans += 1
for i in ra... | vfc_84325 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "4000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n7 2 3 1 5 6",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422",
... |
codeforces | verifiable_code | 329 | Solve the following coding problem using the programming language python:
You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an *n*<=×<=*n* grid. The rows are numbered 1 through *n* from top to bottom, and... | import traceback
import math
from collections import defaultdict
from functools import lru_cache
def main():
N = int(input())
grid = []
for _ in range(N):
s = input()
grid.append(s)
if all('.' in [grid[i][j] for j in range(N)] for i in range(N)):
for i in ran... | vfc_84329 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n.E.\nE.E\n.E.",
"output": "1 1\n2 2\n3 1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nEEE\nE..\nE.E",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn_name"... |
codeforces | verifiable_code | 407 | Solve the following coding problem using the programming language python:
One day, little Vasya found himself in a maze consisting of (*n*<=+<=1) rooms, numbered from 1 to (*n*<=+<=1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (*n*<=+<=1)-th one.
The maze is organized as... | def f(s):
return int(s)-1
n = int(input())
mod = 10**9+7
arr = list(map(f,input().split()))
dp=[0]*(n+1)
for i in range(n):
dp[i+1] = dp[i]+2+dp[i]-dp[arr[i]]
dp[i+1]%=mod
print(dp[-1])
| vfc_84333 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 2",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 1 2 3",
"output": "20",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1... |
codeforces | verifiable_code | 696 | Solve the following coding problem using the programming language python:
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections *i* and 2*i* and another road between *i* and 2*i*<=+<=1 for every positive in... | n=int(input())
d={}
def lca(u,v,w) :
res=0
while u!=v :
if u<v :
v,u=u,v
d[u]=d.get(u,0)+w
res+=d[u]
u=u//2
return res
for i in range(n) :
l=list(map(int,input().split()))
if l[0]==1 :
lca(l[1],l[2],l[3])
else :
print(lc... | vfc_84337 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n1 3 4 30\n1 4 1 2\n1 3 6 8\n2 4 3\n1 6 1 40\n2 3 7\n2 2 4",
"output": "94\n0\n32",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 442 | 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 th... | # Contest: 20 - 2100 <= Codeforces Rating <= 2199 (https://a2oj.com/ladder?ID=20)
# Problem: (16) Andrey and Problem (Difficulty: 4) (http://codeforces.com/problemset/problem/442/B)
def rint():
return int(input())
def rints():
return list(map(int, input().split()))
n = rint()
p = sorted((float(s) for s in ... | vfc_84341 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0.1 0.2 0.3 0.8",
"output": "0.800000000000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n0.1 0.2",
"output": "0.260000000000",
"type": "stdin_stdout"
},
{
... |
codeforces | verifiable_code | 45 | Solve the following coding problem using the programming language python:
Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly *k* months. He looked at the calendar and learned that at the moment is the month number *s*. Vasya immediatel... | l=['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
n=input()
p=int(input())
pp=l.index(n)
print(l[(pp+p)%12]) | vfc_84345 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "November\n3",
"output": "February",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "May\n24",
"output": "May",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inp... |
codeforces | verifiable_code | 113 | Solve the following coding problem using the programming language python:
Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be ... | import sys,os,math,cmath,timeit,functools,operator,bisect
from sys import stdin,stdout,setrecursionlimit
from io import BytesIO, IOBase
from collections import defaultdict as dd , Counter
from math import factorial , gcd
from queue import PriorityQueue
from heapq import merge, heapify, heappop, heappush
try :
... | vfc_84349 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "petr",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "etis atis animatis etis atis amatis",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": n... |
codeforces | verifiable_code | 244 | Solve the following coding problem using the programming language python:
One day Ms Swan bought an orange in a shop. The orange consisted of *n*·*k* segments, numbered with integers from 1 to *n*·*k*.
There were *k* children waiting for Ms Swan at home. The children have recently learned about the orange and they d... | l=[int(l) for l in input().split()]
p=[int(n) for n in input().split()]
num=0
if (l[0]==1):
for index in p:
print(index)
else:
for index in range(l[1]):
word=str(p[index])
for x in range(1,l[0]):
num+=1
if (num not in p):
word=w... | vfc_84353 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n4 1",
"output": "2 4 \n1 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n2",
"output": "3 2 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
codeforces | verifiable_code | 145 | Solve the following coding problem using the programming language python:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has two strings *... |
a = input()
b = input()
a7,a4 = a.count('7'),a.count('4')
b7,b4 = b.count('7'),b.count('4')
c = 0
for i in range(len(a)):
if a[i]!=b[i]:
c += 1
if a7==b7 and a4==b4:
if c%2:
print(c//2+1)
else:
print(c//2)
else:
if b7>a7:
d = b7-a7
else:
d... | vfc_84357 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "47\n74",
"output": "1",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 185 | Solve the following coding problem using the programming language python:
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and... | def mult(a,b,m):
n1,m1=len(a),len(a[0])
n2,m2=len(b),len(b[0])
if m1!=n2: raise Exception('Dimension error')
c=[[0]*m2 for i in range(n1)]
for i in range(m2):
for j in range(n1):
for k in range(n2):
c[j][i]=(c[j][i]+b[k][i]*a[j][k])%m
return c
def ... | vfc_84361 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2",
"output": "10",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "385599124",
... |
codeforces | verifiable_code | 934 | Solve the following coding problem using the programming language python:
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which f... | n,m = input().split()
n = int(n)
m = int(m)
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.sort()
b.sort()
ans = 10000000000000000000
for i in range(n):
maxi = -10000000000000000000
for j in range(n):
if j != i:
for k in range(m):
pr = a[... | vfc_84365 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n20 18\n2 14",
"output": "252",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3\n-1 0 1 2 3\n-1 0 1",
"output": "2",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 763 | Solve the following coding problem using the programming language python:
Each New Year Timofey and his friends cut down a tree of *n* vertices and bring it home. After that they paint all the *n* its vertices, so that the *i*-th vertex gets color *c**i*.
Now it's time for Timofey birthday, and his mother asked him t... | n = int(input())
u = []
v = []
for i in range(n-1):
a, b = map(int, input().split())
u.append(a)
v.append(b)
c = [0] + [int(x) for x in input().split()]
e = 0
dic = {}
for i in range(1, n+1):
dic[i] = 0
def plus(dic, n):
if n in dic:
dic[n] += 1
else:
... | vfc_84369 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2\n2 3\n3 4\n1 2 1 1",
"output": "YES\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2\n2 3\n1 2 3",
"output": "YES\n2",
"type": "stdin_stdout"
},
{
"... |
codeforces | verifiable_code | 106 | Solve the following coding problem using the programming language python:
Vasya is choosing a laptop. The shop has *n* laptops to all tastes.
Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties.
... | l=[];c=[]
n=int(input())
for _ in range(n):
t=list(map(int,input().split()))
l.append(t)
c.append(t[3])
s = []
for i in range(n):
f=0
for j in range(n):
if i==j:
continue
if l[i][0]<l[j][0] and l[i][1]<l[j][1] and l[i][2]<l[j][2]:
f=1
break
s.append(f)
m = float('inf')
for i in r... | vfc_84373 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1500 500 50 755\n1600 600 80 7... |
codeforces | verifiable_code | 252 | Solve the following coding problem using the programming language python:
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of *n* elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Pleas... | n=int(input())
a=list(map(int,input().split()))
b,c=sorted(a),sorted(a,reverse=True)
for i in range(n-1):
if a[i]!=a[i+1]:
a[i],a[i+1]=a[i+1],a[i]
if a==b or a==c:
a[i],a[i+1]=a[i+1],a[i]
else:
print(i+1,i+2)
exit()
print(-1)
| vfc_84377 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n1",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 2",
"output": "-1",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 924 | Solve the following coding problem using the programming language python:
An atom of element X can exist in *n* distinct states with energies *E*1<=<<=*E*2<=<<=...<=<<=*E**n*. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three dis... | def read_ints():
return map(int, input().split())
def read_int():
return int(input())
n, max_delta = read_ints()
a = list(read_ints())
ans = -1
right = 0
for left in range(n):
while right + 1 < n and a[right + 1] - a[left] <= max_delta:
right += 1
if ... | vfc_84389 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4\n1 3 5 7",
"output": "0.5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 8\n10 13 15 16 17 19 20 22 24 25",
"output": "0.875",
"type": "stdin_stdout"
},
{
"... |
codeforces | verifiable_code | 773 | Solve the following coding problem using the programming language python:
It can be shown that any positive integer *x* can be uniquely represented as *x*<==<=1<=+<=2<=+<=4<=+<=...<=+<=2*k*<=-<=1<=+<=*r*, where *k* and *r* are integers, *k*<=≥<=0, 0<=<<=*r*<=≤<=2*k*. Let's call that representation prairie partition... | from collections import Counter
n = int(input())
a = list(map(int, input().split()))
def get(cnt):
c = Counter(a)
last = []
while c[1] and (cnt is None or len(last) < cnt):
x = 1
while c[x]:
c[x] -= 1
x *= 2
last.append(x >> 1)
rem = sorted(c... | vfc_84397 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n1 1 2 2 3 4 5 8",
"output": "2 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1 1 1 2 2 2",
"output": "2 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
codeforces | verifiable_code | 816 | Solve the following coding problem using the programming language python:
To stay woke and attentive during classes, Karen needs some coffee!
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including... | n, k, q = map(int, input().split())
llist = [0] * 200001
for i in range(n):
a, b = map(int, input().split())
llist[b] += 1
llist[a - 1] -= 1
for i in range(len(llist) - 2, -1, -1):
llist[i] += llist[i + 1]
if llist[0] >= k:
llist[0] = 1
else:
llist[0] = 0
for i in range(1, len(llist)):
i... | vfc_84401 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2500"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100",
"output": "3\n3\n0\n4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1 1\n1 1\n200000 200000\n90 100",
"output": "0",
... |
codeforces | verifiable_code | 901 | Solve the following coding problem using the programming language python:
Suppose you have two polynomials and . Then polynomial can be uniquely represented in the following way:
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, denotes the degree of polynomial *... | f = [[1], [0, 1]]
n = int(input())
for i in range(2, n + 1):
l = [0] + f[i - 1]
for j in range(len(f[i - 2])):
l[j] = (l[j] + f[i - 2][j]) & 1
f.append(l)
print(n)
print(*f[n])
print(n - 1)
print(*f[n - 1])
# Made By Mostafa_Khaled | vfc_84405 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1",
"output": "1\n0 1\n0\n1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2",
"output": "2\n-1 0 1\n1\n0 1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"i... |
codeforces | verifiable_code | 679 | Solve the following coding problem using the programming language python:
This is an interactive problem. In the output section below you will see the information about flushing the output.
Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say if the hidden number is prime ... | print("composite" if sum(input()=='yes' for i in [2,3,4,5,7,9,11,13,17,19,23,25,29,31,37,41,43,47,49] if not print(i))>1 else "prime")
# Made By Mostafa_Khaled | vfc_84409 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "30",
"output": "composite 4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "59",
"output": "prime 15",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "... |
codeforces | verifiable_code | 842 | Solve the following coding problem using the programming language python:
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the c... |
def play(l,r,x,y,k):
for i in range(x,y+1):
if l<=i*k<=r:
return "YES"
return "NO"
l,r,x,y,k=map(int,input().split())
print(play(l,r,x,y,k))
| vfc_84413 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 10 1 10 1",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 5 6 10 1",
"output": "NO",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 117 | Solve the following coding problem using the programming language python:
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All *n* participants who have made it to the finals found themselves in a huge *m*-floored 108-star hotel. Of course the fir... | # n, m = tuple([int(x) for x in input().split()])
# cycle_length = (m - 1) * 2
# for _ in range(n):
# a, b, c = tuple([int(x) for x in input().split()])
# a -= 1
# b -= 1
# if(a > b):
# a = cycle_length - a
# b = cycle_length - b
# elif(a == b):
# print(c)
# continue
# if(a >= c % cycle_length):
# print... | vfc_84417 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2500"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 4\n2 4 3\n1 2 0\n2 2 0\n1 2 1\n4 3 5\n1 2 2\n4 2 0",
"output": "9\n1\n0\n7\n10\n7\n5",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 697 | Solve the following coding problem using the programming language python:
Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times *t*, *t*<=+<=*s*, *t*<=+<=*s... | t,s,x=map(int,input().split())
a=x-t
b=x-t-1
if(t==x):
print("YES")
else:
if(a>=s)or(b>=s):
if(a>=s)and(a%s==0):
print("YES")
elif((b%s==0)and(b>=s)):
print("YES")
else:
print("NO")
else:
... | vfc_84421 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 10 4",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 10 3",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 8 51... |
codeforces | verifiable_code | 586 | Solve the following coding problem using the programming language python:
A little boy Laurenty has been playing his favourite game Nota for quite a while and is now very hungry. The boy wants to make sausage and cheese sandwiches, but first, he needs to buy a sausage and some cheese.
The town where Laurenty lives in... | N = int(input())
fr, sr = [ int(i) for i in input().split() ], [ int(i) for i in input().split() ]
cross = [ int(i) for i in input().split() ]
spend_time = [sum(sr) + cross[0]]
for i in range(1, N):
summ = spend_time[-1] - sr[i - 1] - cross[i - 1]
summ = summ + fr[i - 1] + cross[i]
spend_time.app... | vfc_84425 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 3\n3 2 1\n3 2 2 3",
"output": "12",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2\n3 3\n2 1 3",
"output": "11",
"type": "stdin_stdout"
},
{
"fn_name":... |
codeforces | verifiable_code | 377 | Solve the following coding problem using the programming language python:
Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze with all empty c... | directions = [[1, 0], [-1, 0], [0, 1], [0, -1]]
def main():
height, width, walls_to_add = map(int, input().split())
total_open_squares = height * width
maze = []
for _ in range(height):
maze.append(list(input().strip()))
total_open_squares -= sum(row.count('#') for row in maze)
... | vfc_84429 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#",
"output": "#XXX\n#X#.\nX#..\n...#\n.#.#",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 301 | Solve the following coding problem using the programming language python:
Yaroslav has an array, consisting of (2·*n*<=-<=1) integers. In a single operation Yaroslav can change the sign of exactly *n* elements in the array. In other words, in one operation Yaroslav can select exactly *n* array elements, and multiply e... | n, t = int(input()), list(map(int, input().split()))
p = list(map(abs, t))
s = sum(p)
if n & 1 == 0 and len([0 for i in t if i < 0]) & 1: s -= 2 * min(p)
print(s) | vfc_84433 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n50 50 50",
"output": "150",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n-1 -100 -1",
"output": "100",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 717 | Solve the following coding problem using the programming language python:
Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singi... | n = int(input())
a = [int(input()) for i in range(n)]
mod = 10007
a.sort()
ans = 0
for i in range(n):
ans += a[i] * a[n - 1 - i] % mod
if ans >= mod:
ans -= mod
print(ans) | vfc_84437 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1\n3",
"output": "6",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 547 | Solve the following coding problem using the programming language python:
Mike is the president of country What-The-Fatherland. There are *n* bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to *n* from left to right. *i*-th bear is exactly *a**i* feet high.
... | n = int(input())
a = [int(i) for i in input().split()]
l = [-1 for _ in range(n)]
r = [n for _ in range(n)]
answer = [0 for _ in range(n+1)]
s = []
for i in range(n):
while s and a[s[-1]] >= a[i]:
s.pop()
if s:
l[i] = s[-1]
s.append(i)
while s:
s.pop()
for i in range(n-1, -1, -1):
... | vfc_84441 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n1 2 3 4 5 4 3 2 1 6",
"output": "6 4 4 3 3 2 2 1 1 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n524125987 923264237 374288891",
"output": "923264237 524125987 374288891 ",... |
codeforces | verifiable_code | 879 | Solve the following coding problem using the programming language python:
*n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until some... | n, k = map(int, input().split())
v = list(map(int, input().split()))
count = 0
previous = v[0]
for i in range(1, n):
if previous>v[i]:
count+=1
else:
previous = v[i]
count = 1
if count==k:
break
print(previous) | vfc_84445 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n1 2",
"output": "2 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n3 1 2 4",
"output": "3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
codeforces | verifiable_code | 274 | Solve the following coding problem using the programming language python:
A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, such that *y*<==<=*x*·*k*.
Yo... | n, k = [int(e) for e in input().split()]
a = sorted([int(e) for e in input().split()])
s = set()
for i in range(n):
if a[i] % k != 0:
s.add(a[i])
elif a[i] / k not in s:
s.add(a[i])
print(len(s)) | vfc_84449 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 2\n2 3 6 5 4 10",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 2\n1 2 3 4 5 6 7 8 9 10",
"output": "6",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 257 | Solve the following coding problem using the programming language python:
Petya and Vasya decided to play a little. They found *n* red cubes and *m* blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put it in a line from left to right (overall the line will ha... | n,m = map(int,input().split())
vasya = min(n,m)
petya = n+m-1-vasya
print('{} {}'.format(petya,vasya))
| vfc_84453 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1",
"output": "2 1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 4",
"output": "3 2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1",
... |
codeforces | verifiable_code | 362 | Solve the following coding problem using the programming language python:
Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time... | n,k=map(int,input().split())
if(k>0):
l=list(map(int,input().split()))
l.sort()
c=0
if(k==0):
print("YES")
elif(l[0]==1 or l[-1]==n):
print("NO")
else:
for i in range(2,k):
if (l[i]-l[i-1]==1 and l[i-1]-l[i-2]==1):
c=1
break
if(c==0):
print(... | vfc_84457 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 5\n2 4 8 3 6",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 5\n2 4 5 7 9",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
codeforces | verifiable_code | 568 | Solve the following coding problem using the programming language python:
Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable properties. He... | n = 2 * 10 ** 6 + 10 ** 5
p, q = map(int, input().split(' '))
pi = 0
si = 0
pr = [0] * n
pr[1] = 1
for i in range(2, n):
if pr[i] == 0:
for j in range(i*i, n, i):
pr[j] = 1
res = 'Palindromic tree is better than splay tree'
for i in range(1, n):
if pr[i] == 0:
pi += 1
j = str(i)... | vfc_84461 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "3000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1",
"output": "40",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 42",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 4",
"... |
codeforces | verifiable_code | 742 | Solve the following coding problem using the programming language python:
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*.
M... | x = int(input())
if not x:
print(1)
exit()
print('8426'[(x-1) % 4]) | vfc_84465 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1",
"output": "8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000",
"outpu... |
codeforces | verifiable_code | 203 | Solve the following coding problem using the programming language python:
A boy Valera registered on site Codeforces as Valera, and wrote his first Codeforces Round #300. He boasted to a friend Arkady about winning as much as *x* points for his first contest. But Arkady did not believe his friend's words and decided t... | x, t, a, b, da, db = map(int, input().split())
A = [0] + [a-i*da for i in range(t)]
B = {0} | {b-i*db for i in range(t)}
print('YES' if any(x-a in B for a in A) else 'NO') | vfc_84469 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "30 5 20 20 3 5",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 4 100 5 5 1",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
codeforces | verifiable_code | 65 | Solve the following coding problem using the programming language python:
A long time ago (probably even in the first book), Nicholas Flamel, a great alchemist and the creator of the Philosopher's Stone, taught Harry Potter three useful spells. The first one allows you to convert *a* grams of sand into *b* grams of le... | # LUOGU_RID: 112089745
a, b, c, d, e, f = map(int, input().split());
if a * c * e < b * d * f or a == 0 and b * d > 0 or c == 0 and d > 0:
print("Ron");
else:
print("Hermione"); | vfc_84473 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100 200 250 150 200 250",
"output": "Ron",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100 50 50 200 200 100",
"output": "Hermione",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 417 | Solve the following coding problem using the programming language python:
While resting on the ship after the "Russian Code Cup" a boy named Misha invented an interesting game. He promised to give his quadrocopter to whoever will be the first one to make a rectangular table of size *n*<=×<=*m*, consisting of positive ... | import math
n,m = input().split(' ')
n,m = int(n),int(m)
fix = [[1],[3,4],[1,2,2],[1,1,3,5],[1,1,1,2,3]]
a = n
parts = list()
b = a
while b > 0:
parts.append(math.floor(b**0.5))
b-=math.floor(b**0.5)**2
lcm = math.lcm(*parts)
a_out = list()
for i in range(len(parts)):
part = parts[i]
for... | vfc_84477 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1",
"output": "1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2",
"output": "3 4 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 1",
... |
codeforces | verifiable_code | 98 | Solve the following coding problem using the programming language python:
This is the modification of the problem used during the official round. Unfortunately, author's solution of the original problem appeared wrong, so the problem was changed specially for the archive.
Once upon a time in a far away kingdom lived ... | import math
from fractions import Fraction
import time
MAXN = 10000
def solve(free_nodes, n):
seq = []
used = {}
used[0] = 0
pos = 0
while used.get(free_nodes) == None:
used[free_nodes] = pos
toss = 0
while free_nodes < n:
toss += 1
free_nodes *= 2
seq.append((toss, Fraction(... | vfc_84481 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2",
"output": "1/1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3",
"output": "8/3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4",
"outp... |
codeforces | verifiable_code | 846 | Solve the following coding problem using the programming language python:
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job.
During all his career Hideo has produced *n* games. Some of them were suc... | n, a = int(input()), [int(x) for x in input().split()]
print(n - min([a[:i].count(1) + a[i + 1:].count(0) for i in range(n)]))
| vfc_84485 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 1 0 1",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n0 1 0 0 1 0",
"output": "4",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 319 | Solve the following coding problem using the programming language python:
Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle and cut *n* trees with heights *a*1,<=*a*2,<=...,<=*... | f = lambda: list(map(int, input().split()))
g = lambda j: a[i] * b[j] + t[j]
h = lambda j, k: (t[i] - t[j]) * (b[j] - b[k]) < (t[j] - t[k]) * (b[i] - b[j])
n = int(input())
a, b = f(), f()
t = [0] * n
p = [0]
for i in range(1, n):
while len(p) > 1 and g(p[1]) < g(p[0]): p.pop(0)
t[i] = g(p[0])
w... | vfc_84489 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3 4 5\n5 4 3 2 0",
"output": "25",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1 2 3 10 20 30\n6 5 4 3 2 0",
"output": "138",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 484 | Solve the following coding problem using the programming language python:
Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer *x*.
You are given multiple queries consisting of pairs of integers *l* and *r*. For each query, find the *x*, such that *l*<=≤<=*x*<=≤<... | def main():
cases = int(input())
for i in range(cases):
left, right = list(map(int, str(input()).split(" ")))
res = left
for j in range(65):
if ((1 << j) & left) == 0:
if (res | (1 << j)) > right:
break
res |= (1 << j)
... | vfc_84493 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2\n2 4\n1 10",
"output": "1\n3\n7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "55\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\n2 8\n2 9\n2 10\n3 ... |
codeforces | verifiable_code | 430 | Solve the following coding problem using the programming language python:
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One o... | n, m = map(int, input().split())
t = list(enumerate(list(map(int, input().split()))))
t.sort(key=lambda x: x[1])
p = ['0' for i in range(n)]
for i, x in t[::2]:
p[i] = '1'
print(' '.join(p))
| vfc_84497 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n3 7 14\n1 5\n6 10\n11 15",
"output": "0 0 0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n1 2 3\n1 2\n2 3\n5 6\n2 2",
"output": "1 0 1 ",
"type": "stdin_stdout"
}... |
codeforces | verifiable_code | 83 | Solve the following coding problem using the programming language python:
Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbe... | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = list(map(int, input().split()))
c, x = 0, a[0]
ans = 0
for i in a:
if not i ^ x:
c += 1
else:
ans += c * (c + 1) // 2
c, x = 1, i
ans += c * (c + 1) // 2
print(ans) | vfc_84501 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "3000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 1 1 4",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n-2 -2 -2 0 1",
"output": "8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input... |
codeforces | verifiable_code | 156 | Solve the following coding problem using the programming language python:
As Sherlock Holmes was investigating a crime, he identified *n* suspects. He knows for sure that exactly one of them committed the crime. To find out which one did it, the detective lines up the suspects and numbered them from 1 to *n*. After th... | [n, m] = input().split()
n = int(n)
m = int(m)
arr = []
ps = []
ns = []
suspects = []
for i in range(0, n):
a = input()
a = int(a)
arr.append(a)
ps.append(0)
ns.append(0)
suspects.append(0)
sum_ps = 0
sum_ns = 0
for i in arr:
if i > 0:
ps[i - 1] += 1
... | vfc_84505 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\n+1",
"output": "Truth",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n-1\n-2\n-3",
"output": "Not defined\nNot defined\nNot defined",
"type": "stdin_stdout"
},
... |
codeforces | verifiable_code | 383 | Solve the following coding problem using the programming language python:
Iahub helps his grandfather at the farm. Today he must milk the cows. There are *n* cows sitting in a row, numbered from 1 to *n* from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the c... | from math import inf
from sys import stdin
input = stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
sm = [0]
for x in a: sm.append(sm[-1]+x)
ans1 = ans2 = 0
for i in range(1, n+1):
if a[i-1] == 0:
ans1 += sm[i-1]
for i in range(1, n+1):
if a[i-1] == 1:
a... | vfc_84513 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0 0 1 0",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 0 1 0 1",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
codeforces | verifiable_code | 605 | 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. I... | n = int(input())
nums = list(map(int, input().split()))
note_nums = sorted([(val, idx) for idx, val in enumerate(nums)])
tmp = [0] * n
for i in range(n):
tmp[note_nums[i][1]] = i
ans = [0] * (n + 1)
for val in tmp:
ans[val + 1] = ans[val] + 1
print(n - max(ans)) | vfc_84517 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n4 1 2 5 3",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n4 1 3 2",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
codeforces | verifiable_code | 830 | Solve the following coding problem using the programming language python:
There are *n* people and *k* keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken ... | import copy
import random
import heapq
import math
import sys
import bisect
import datetime
from functools import lru_cache
from collections import deque
from collections import Counter
from collections import defaultdict
from itertools import combinations
from itertools import permutations
from types impo... | vfc_84521 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 4 50\n20 100\n60 10 40 80",
"output": "50",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2 10\n11\n15 7",
"output": "7",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 57 | Solve the following coding problem using the programming language python:
Meg the Rabbit decided to do something nice, specifically — to determine the shortest distance between two points on the surface of our planet. But Meg... what can you say, she wants everything simple. So, she already regards our planet as a two... | n,x1,y1,x2,y2 =map(int, input().split())
def f(x,y,n):
if y==0 or x==n:
return x+y
else:
return 4*n - x - y
a = abs(f(x1,y1,n) - f(x2,y2,n))
print(min(a, 4*n-a))
| vfc_84525 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 0 0 1 0",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 0 1 2 1",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100... |
codeforces | verifiable_code | 356 | Solve the following coding problem using the programming language python:
Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event.
As for you, you're just a simple peasant. There'... | import sys
input = sys.stdin.readline
def inint():
return(int(input()))
def inlst():
return(list(map(int,input().split())))
# returns a List of Characters, which is easier to use in Python as Strings are Immutable
def instr():
s = input()
return(list(s[:len(s) - 1]))
def invar():
return(map(int,... | vfc_84529 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "3000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n1 2 1\n1 3 3\n1 4 4",
"output": "3 1 4 0 ",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 86 | Solve the following coding problem using the programming language python:
For each positive integer *n* consider the integer ψ(*n*) which is obtained from *n* by replacing every digit *a* in the decimal notation of *n* with the digit (9<=<=-<=<=*a*). We say that ψ(*n*) is the reflection of *n*. For example, reflection... | from sys import stdin
inp = stdin.readline
a, b = inp().split()
mid = "5" + "".join(["0" for _ in range(len(b)-1)])
if int(a) > int(mid):
ans = a
elif int(b) < int(mid):
ans = b
else:
ans = mid
ref = ""
for c in ans:
ref += str(9 - int(c))
print(int(ref)*int(ans))
| vfc_84533 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 7",
"output": "20",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1",
"output": "8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 10",
"... |
codeforces | verifiable_code | 142 | Solve the following coding problem using the programming language python:
Autumn came late to the kingdom of Far Far Away. The harvest was exuberant and it is now time to get ready for the winter. As most people celebrate the Harvest festival, Simon the Caretaker tries to solve a very non-trivial task of how to find p... | n, m = map(int, input().split())
swapped = False
if n < m:
n, m = m, n
swapped = True
ans = ''
if n == 1 and m == 1:
ans = '''0
.'''
if n == 2 and m == 1:
ans = '''0
.
.'''
if n == 2 and m == 2:
ans = '''0
..
..'''
if n == 3 and m == 1:
ans = '''0
.
.
.'''
if n == 3 and m == 2:
ans = '''0
..
..
..'''
if n... | vfc_84537 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3",
"output": "1\nAAA\n.A.\n.A.",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 6",
"output": "4\nA..C..\nAAAC..\nABCCCD\n.B.DDD\nBBB..D",
"type": "stdin_stdout"
},
{... |
codeforces | verifiable_code | 28 | Solve the following coding problem using the programming language python:
There are *n* students living in the campus. Every morning all students wake up at the same time and go to wash. There are *m* rooms with wash basins. The *i*-th of these rooms contains *a**i* wash basins. Every student independently select one ... | import functools,math,itertools,time
u=functools.lru_cache(maxsize=None)
n,m=map(int,input().split())
s=[*map(int,input().split())]
t=u(lambda x:1 if x<2 else x*t(x-1))
c=u(lambda r,n:t(n)/t(r)/t(n-r))
p=u(lambda n,k:n**k)
w=u(lambda n,k:math.ceil(n/k))
r=u(lambda k,n:max(k,n))
h=u(lambda i,j,l:c(l,i)*p(j-1,i-l)/p(j,i)... | vfc_84541 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\n2",
"output": "1.00000000000000000000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n1 1",
"output": "1.50000000000000000000",
"type": "stdin_stdout"
},
{
... |
codeforces | verifiable_code | 980 | Solve the following coding problem using the programming language python:
A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one.
You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a ... | s = [x for x in input().lower()]
b = s.count('o')
v = s.count('-')
if b == 0 or v % b == 0:
print("YES")
else:
print("NO")
| vfc_84545 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "3000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "-o-o--",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-o---",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-o---o... |
codeforces | verifiable_code | 704 | Solve the following coding problem using the programming language python:
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are *n* applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by thos... | import sys
n,m=map(int,input().split())
k=0
pos=0
L=[]
L1=[]
d={i:[0,-1] for i in range(1,n+1)}
for i in range(m) :
a,b=map(int,input().split())
if a==1 :
d[b][0]+=1
k+=1
L.append(b)
elif a==2 :
k-=d[b][0]
d[b][0]=0
d[b][1]=len(L)
... | vfc_84549 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n1 3\n1 1\n1 2\n2 3",
"output": "1\n2\n3\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 6\n1 2\n1 4\n1 2\n3 3\n1 3\n1 3",
"output": "1\n2\n3\n0\n1\n2",
"type": "stdin_s... |
codeforces | verifiable_code | 173 | Solve the following coding problem using the programming language python:
Nikephoros and Polycarpus play rock-paper-scissors. The loser gets pinched (not too severely!).
Let us remind you the rules of this game. Rock-paper-scissors is played by two players. In each round the players choose one of three items independ... | n = int(input())
a = input()
b = input()
ai = 0
alen = len(a)
bi = 0
blen = len(b)
nik = 0
pol = 0
if alen == blen: rnd = alen
else: rnd = alen*blen
numofrounds = 0
for i in range(n):
#print(i,rnd)
if i == rnd:
numofrounds = n//rnd
# print(numofrounds)
nik *= numofrounds... | vfc_84553 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "3000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\nRPS\nRSPP",
"output": "3 2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nRRRRRRRR\nR",
"output": "0 0",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 613 | Solve the following coding problem using the programming language python:
Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly *n* skills. Each skill is represented by a non-negative integer *a**i*... | import itertools
import bisect
n, A, cf, cm, m = [int(x) for x in input().split()]
skills = [int(x) for x in input().split()]
sorted_skills = list(sorted((k, i) for i, k in enumerate(skills)))
bottom_lift = [0 for i in range(n)]
for i in range(1, n):
bottom_lift[i] = bottom_lift[i-1] + i * (sorted_skills[i][0] - s... | vfc_84557 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5 10 1 5\n1 3 1",
"output": "12\n2 5 2 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 5 10 1 339\n1 3 1",
"output": "35\n5 5 5 ",
"type": "stdin_stdout"
},
{
... |
codeforces | verifiable_code | 277 | Solve the following coding problem using the programming language python:
The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have the list of languages, which he... | n,m = map(int,input().split())
arr = []
ki = False
for i in range(n):
a = list(map(int,input().split()))
set_a = set(());
for j in range (a[0]):
ki=True
set_a.add(a[j+1])
arr.append(set_a)
change = 0
if ki:
while(change!=-1):
changed = -1
change = -1
for i in range(len(arr)):
for j in ... | vfc_84561 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "3000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1",
"output": "2",
"type": "st... |
codeforces | verifiable_code | 708 | Solve the following coding problem using the programming language python:
You are given a non-empty string *s* consisting of lowercase English letters. You have to pick exactly one non-empty substring of *s* and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the pre... | s = input()
i = 0
if set(s)=={'a'}:
print('a'*(len(s)-1)+'z')
exit()
while i<len(s) and s[i]=='a':
print('a',end='')
i+=1
while i<len(s) and s[i]!='a':
print(chr(ord(s[i])-1),end="")
i+=1
while i<len(s):
print(s[i],end="")
i+=1
print() | vfc_84565 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "codeforces",
"output": "bncdenqbdr",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 993 | Solve the following coding problem using the programming language python:
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered to be part of the squar... | def outp(v1,v2):
a1,a2=v1
b1,b2=v2
det = a1*b2-a2*b1
return 'M' if det==0 else ('L' if det>0 else 'R')
def check(p,PS):
sides = {'M':0,'L':0,'R':0}
for i in range(4):
v1 = [PS[i+1][0]-PS[i][0],PS[i+1][1]-PS[i][1]]
v2 = [p[0]-PS[i][0],p[1]-PS[i][1]]
sides[outp(v1,v2)] += 1
return n... | vfc_84569 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1",
"output": "NO",
"type": "stdin_stdout"
}... |
codeforces | verifiable_code | 571 | Solve the following coding problem using the programming language python:
You've got array *A*, consisting of *n* integers and a positive integer *k*. Array *A* is indexed by integers from 1 to *n*.
You need to permute the array elements so that value
The input will be provided via standard input and looks as follow... | def solve(n, k, As):
As.sort()
m, r = divmod(n, k)
dp = [0] * (r + 1)
for i in range(1, k):
im = i * m
new_dp = [0] * (r + 1)
new_dp[0] = dp[0] + As[im] - As[im - 1]
for h in range(1, min(i, r) + 1):
new_dp[h] = max(dp[h], dp[h - 1]) + As[im + h] - As... | vfc_84573 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n1 2 4",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n3 -5 3 -5 3",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
codeforces | verifiable_code | 587 | Solve the following coding problem using the programming language python:
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of *i*-th of them is 2*w**i* pounds. In each step, Duff can lift some of the remaining weights and throw them... | n = int(input())
a = [int(x) for x in input().split()]
l = [0] * (10**6 + 100)
for x in a:
l[x] += 1
cur = 0
ans = 0
for x in l:
cur += x
if cur % 2:
ans += 1
cur //= 2
print(ans)
| vfc_84577 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 1 2 3 3",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 1 2 3",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
codeforces | verifiable_code | 316 | Solve the following coding problem using the programming language python:
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood ty... | def main():
hint = input()
hint_nodigits = [h for h in hint if not h.isdigit()]
letters = [h for h in hint_nodigits if h != '?']
combs_letters = 1
for i in range(10, 10 - len(set(letters)), -1):
combs_letters *= i
combs_jolly = 10 ** (len(hint_nodigits) - len(letters))
... | vfc_84581 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "AJ",
"output": "81",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1?AA",
"output": "100",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "?",
"o... |
codeforces | verifiable_code | 788 | Solve the following coding problem using the programming language python:
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried a... | n = int(input())
arr = list(map(int, input().split()))
diff = [abs(arr[i] - arr[i-1]) for i in range(1, n)]
res0, res1, res, curr_sum = -2e9, 0, -2e9, 0
for i in range(n-1):
curr_sum += diff[i] * (1 if i % 2 == 0 else -1)
res = max(res, curr_sum - res1, res0 - curr_sum)
if i % 2 == 0:
res0 =... | vfc_84585 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 4 2 3 1",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 5 4 7",
"output": "6",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 627 | Solve the following coding problem using the programming language python:
Two positive integers *a* and *b* have a sum of *s* and a bitwise XOR of *x*. How many possible values are there for the ordered pair (*a*,<=*b*)?
The input will be provided via standard input and looks as follows:
The first line of the input c... | def func(S,X):
if S - X < 0 :
return 0
elif (S - X) % 2:
return 0
nd = (S - X) // 2
c = 0
while X:
if X & 1:
if nd & 1:
return 0
c += 1
X >>= 1
nd >>= 1
return 2 ** c
S,X = map(in... | vfc_84589 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9 5",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2",
"ou... |
codeforces | verifiable_code | 216 | Solve the following coding problem using the programming language python:
A new Berland businessman Vitaly is going to open a household appliances' store. All he's got to do now is to hire the staff.
The store will work seven days a week, but not around the clock. Every day at least *k* people must work in the store.... | n, m, k = map(int, input().split())
span = n+m+1
count = (span+1)*[0]
count[span] = k
key = (span+1)*[False]
key[1] = True
hire = []
day = 1
while True:
while day <= span and count[day] >= k:
day += 1
if day > span:
if key[span]:
break
day -= 1
while not key[day]:
day -= 1
hire.append(day)
last = min(sp... | vfc_84593 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3 2",
"output": "4\n1 1 4 5",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 321 | Solve the following coding problem using the programming language python:
Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a command to it. The command was represented by string *s*. Each character of *s* is one move operation. There are four move operations at all:
- 'U': go up, ... | #!/usr/bin/python3
import sys
MAPPING = {
'U': (0, 1),
'D': (0, -1),
'L': (-1, 0),
'R': (1, 0),
}
def read_ints():
return [int(x) for x in input().split()]
def get_vectors(moves):
vector = (0, 0)
yield vector
for move in moves:
delta = MAPPING[move]
vector = (vector[... | vfc_84597 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "4000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\nRU",
"output": "Yes",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2\nRU",
"output": "No",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-1 1... |
codeforces | verifiable_code | 744 | Solve the following coding problem using the programming language python:
Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.
The world can be modeled as an undirected graph with *n* nodes and *m* edges. *k* of the nodes are home to... | def dfs(vertice, soma, temCapital,aux, used, capitais, am):
soma += len(aux[vertice])
am += 1
if vertice in capitais:
temCapital = True
used[vertice] = True
for i in aux[vertice]:
if not used[i]:
tmpC, am, soma = dfs(i, soma, temCapital, aux, used, capitais, am)
... | vfc_84601 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 1 2\n1 3\n1 2",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3 1\n2\n1 2\n1 3\n2 3",
"output": "0",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 176 | 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... | # Problem: B. Word Cut
# Contest: Codeforces - Croc Champ 2012 - Round 2
# URL: https://codeforces.com/problemset/problem/176/B
# Memory Limit: 256 MB
# Time Limit: 2000 ms
import sys
import random
from types import GeneratorType
import bisect
import io, os
from bisect import *
from collections import *
f... | vfc_84605 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "ab\nab\n2",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "ababab\nababab\n1",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
codeforces | verifiable_code | 925 | Solve the following coding problem using the programming language python:
One department of some software company has $n$ servers of different specifications. Servers are indexed with consecutive integers from $1$ to $n$. Suppose that the specifications of the $j$-th server may be expressed with a single integer numbe... | I = lambda:list(map(int, input().split()))
n,x1,x2 = I()
servers = I()
idx = list(range(n))
idx.sort(key = lambda i : servers[i])
def solve(a, b, rev):
j = len(idx)-1
while j >= 0 and (n-j)*servers[idx[j]] < b:
j -= 1
if j < 0:
return
i = j-1
while i >= 0 and (j-i)*serv... | vfc_84609 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 8 16\n3 5 2 9 8 7",
"output": "Yes\n4 2\n3 1 2 6\n5 4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 20 32\n21 11 11 12",
"output": "Yes\n1 3\n1\n2 3 4",
"type": "stdin_stdo... |
codeforces | verifiable_code | 730 | Solve the following coding problem using the programming language python:
Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time.
Polycarp is good at marketing, so he has already collec... | n = int(input())
l, r = [0] * n, [0] * n
f = lambda x, y: all(x > r[j] or y < l[j] for j in range(i))
for i in range(n):
x, d = map(int, input().split())
y = x + d - 1
if not f(x, y):
k = min(r[j] for j in range(i + 1) if f(r[j] + 1, r[j] + d))
x, y = k + 1, k + d
l[i],... | vfc_84617 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n9 2\n7 3\n2 4",
"output": "9 10\n1 3\n4 7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1000000000 1000000\n1000000000 1000000\n100000000 1000000\n1000000000 1000000",
"output"... |
codeforces | verifiable_code | 936 | Solve the following coding problem using the programming language python:
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after *k* minutes after turning on.
During cooking, Julia goes to the kitchen every *d* minutes and turns on the ... | def give(n,d):
if n%d:
return n//d+1
else:
return n//d
k,d,t=list(map(int,input().split()))
p=give(k,d)*d
if d>=k: a=k
else: a=p-p%k
q=(p-a)/2
ans=t//(a+q)*p
r=t-t//(a+q)*(a+q)
if r<=a:
ans+=r
else:
ans+=a
r-=a
ans+=r*2
print(ans) | vfc_84621 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2 6",
"output": "6.5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2 20",
"output": "20.0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 10 ... |
codeforces | verifiable_code | 101 | Solve the following coding problem using the programming language python:
Once when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting of *n* small Latin letters; the task was to learn the way the letters that the string contains ... | from collections import Counter
s = input()
k = int(input())
C = sorted(Counter(s).items(), key=lambda x: -x[1])
while k and C:
ch, n = C.pop()
x = min(k,n)
s = s.replace(ch, '', x)
k -= x
print(len(set(s)))
print(s) | vfc_84625 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "aaaaa\n4",
"output": "1\naaaaa",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "abacaba\n4",
"output": "1\naaaa",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
codeforces | verifiable_code | 51 | Solve the following coding problem using the programming language python:
Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive. Cheaterius makes them him... | def contains(cont: list, temp: str) -> bool:
for i in range(4):
if temp in cont:
return True
temp = f'{temp[2]}{temp[0]}{temp[3]}{temp[1]}'
return False
n = int(input())
cont = []
for i in range(n):
temp = input() + input()
if not contains(cont, temp):
... | vfc_84629 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n31\n23\n**\n31\n23\n**\n13\n32\n**\n32\n13",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n51\n26\n**\n54\n35\n**\n25\n61\n**\n45\n53",
"output": "2",
"type"... |
codeforces | verifiable_code | 641 | Solve the following coding problem using the programming language python:
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1<=×<=*n*. Each cell contains the direction for the next jump and the length of that jump. Grasshopper sta... | n = int(input())
str = input()
inp = list(map(int, input().split()))
for i in range(len(str)):
if str[i] == '<':
inp[i] *= -1
visited = [0 for i in range(n)]
cur = 0
while cur >= 0 and cur < n and visited[cur] != 1:
visited[cur] = 1
cur += inp[cur]
if cur >= 0 and cur < n:
... | vfc_84637 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n><\n1 2",
"output": "FINITE",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n>><\n2 1 1",
"output": "INFINITE",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
codeforces | verifiable_code | 906 | Solve the following coding problem using the programming language python:
Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives a... | import math,sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda:int(input())
li = lambda:list(map(int,input().split()))
def solve():
n=I()
vis=[1]*26
c=0
flag=0
ans=0
for i in range(n-1):
a,b=input().split... | vfc_84641 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "4500"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n! abc\n. ad\n. b\n! cd\n? c",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e",
"output": "2",
"type": "std... |
codeforces | verifiable_code | 838 | Solve the following coding problem using the programming language python:
There is an airplane which has *n* rows from front to back. There will be *m* people boarding this airplane.
This airplane has an entrance at the very front and very back of the plane.
Each person has some assigned seat. It is possible for mul... | MOD = 10 ** 9 + 7
n, m = input().split(' ')
n = int(n)
m = int(m)
ans = pow(2 * (n + 1), m, MOD)
ans = (ans * (n + 1 - m)) % MOD
ans = (ans * pow(n + 1, MOD - 2, MOD)) % MOD
print(ans)
| vfc_84645 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3",
"output": "128",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000 1000000",
"output": "233176135",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
codeforces | verifiable_code | 19 | Solve the following coding problem using the programming language python:
Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations:
- the final ... | class Info:
def __init__(self, newTeamName, newPoints, newGoalDiff, newScoredGoals):
self.teamName = newTeamName
self.points = newPoints
self.goalDiff = newGoalDiff
self.scoredGoals = newScoredGoals
def __str__(self):
return f'teamName: \'{self.teamName}\', point... | vfc_84649 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3",
"output": "A\nD",
"type": "stdin_stdout"
}
]
} |
codeforces | verifiable_code | 226 | Solve the following coding problem using the programming language python:
There are *n* piles of stones of sizes *a*1,<=*a*2,<=...,<=*a**n* lying on the table in front of you.
During one move you can take one pile and add it to the other. As you add pile *i* to pile *j*, the size of pile *j* increases by the current ... | n = int(input())
stones = list(map(lambda t : int(t), input().split()))
q = int(input())
queries = list(map(lambda t : int(t), input().split()))
stones.sort()
added_stones = []
added_stones.append(stones[0])
for i in range(1, n, 1):
added_stones.append(stones[i] + added_stones[i - 1])
computed_querie... | vfc_84653 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 3 4 1 1\n2\n2 3",
"output": "9 8 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 9\n5\n4 10 7 3 4",
"output": "2 2 2 2 2 ",
"type": "stdin_stdout"
},
{
"... |
codeforces | verifiable_code | 126 | Solve the following coding problem using the programming language python:
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carved on a rock below t... | def kmp():
now = -1
sub[0] = now
for i in range(1, len(p)):
while now != -1 and p[i] != p[now + 1]:
now = sub[now]
if p[i] == p[now + 1]:
now += 1
sub[i] = now
else:
sub[i] = -1
p = input()
sub = [-1] * 1000001
kmp()
maxi = sub[len(p... | vfc_84657 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "fixprefixsuffix",
"output": "fix",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "abcdabc",
"output": "Just a legend",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
codeforces | verifiable_code | 193 | Solve the following coding problem using the programming language python:
You've gotten an *n*<=×<=*m* sheet of squared paper. Some of its squares are painted. Let's mark the set of all painted squares as *A*. Set *A* is connected. Your task is to find the minimum number of squares that we can delete from set *A* to m... | m, n = list(map(int, input().split()))
grid = [list(input()) for _ in range(m)]
count = sum(i.count('#') for i in grid)
if count <= 2:
print(-1)
exit()
table = {}
node = 0
graph = [[] for _ in range(count)]
for i in range(m):
for j in range(n):
if grid[i][j] == "#":
if (i, j)... | vfc_84661 | {
"difficulty": "N/A",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "3000"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4\n####\n#..#\n#..#\n#..#\n####",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5\n#####\n#...#\n#####\n#...#\n#####",
"output": "2",
"type": "stdin_stdout"
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.