source stringclasses 4
values | task_type stringclasses 1
value | in_source_id stringlengths 0 138 | problem stringlengths 219 13.2k | gold_standard_solution stringlengths 0 413k | problem_id stringlengths 5 10 | metadata dict | verification_info dict |
|---|---|---|---|---|---|---|---|
code_contests | verifiable_code | factsum | Solve the following coding problem using the programming language python:
Given a positive integer K > 2, with prime
factorization:
K = p1^a1 * p2^a2 ... * pn^an
Compute the following:
S = a1*p1 + a2*p2 ... + an*pn.
Input
A list of
Output
For each integer compute the super factor
sum and output it on a single li... | ```python
from fractions import gcd
import sys
import cStringIO
from Queue import Queue
import random
def rho(n):
if n%2 == 0:
return 2
x = y = random.randrange(2, 1000000)
d = 1
c = random.randrange(2, 1000000)
while d==1:
x = ((x*x)+c)%n
y = ((y*y)+c)%n
y = ((y*y)+c... | vfc_76269 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n7",
"output": "5\n7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n9",
"output": "5\n6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n15... |
code_contests | verifiable_code | lckyst | Solve the following coding problem using the programming language python:
A number is called as a lucky number if its decimal representation contains only the lucky digits, 4 and 7. e.g. 47, 744, 4 are lucky numbers, whereas 5, 17, 467 are not.
Recently, Na2a found a magic stone. With the help of this stone, he can mu... | ```python
n=input()
a=[]
a=map(int,raw_input().split())
for i in range (n):
c2=0
c5=0
#print i
temp=a[i]
while temp%2==0:
c2=c2+1
temp=temp/2
temp=a[i]
while temp%5==0:
c5=c5+1
temp=temp/5
ans=a[i]
while c5>c2:
ans=ans*4
c2=c2+2
print ans
``` | vfc_76273 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 15",
"output": "2\n60\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 26",
"output": "2\n26\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
code_contests | verifiable_code | petersen | Solve the following coding problem using the programming language python:
The following graph G is called a Petersen graph and its vertices have been numbered from 0 to 9. Some letters have also been assigned to vertices of G, as can be seen from the following picture:
Let's consider a walk W in graph G, which c... | ```python
def digit(c,present):
if c=='A':
if present=='i':
return "5"
else:
return "0"
elif c=='B':
if present=='i':
return "6"
else:
return "1"
elif c=='C':
if present=='i':
return "7"
else:
return "2"
elif c=='D':
if present=='i':
return "8"
else:
return "3"
elif c=='E':
... | vfc_76277 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nAAB\nAABE",
"output": "501\n-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\nAAB\nAACE",
"output": "501\n0579\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | stones | Solve the following coding problem using the programming language python:
Soma is a fashionable girl. She absolutely loves shiny stones that she can put on as jewellery accessories. She has been collecting stones since her childhood - now she has become really good with identifying which ones are fake and which ones a... | ```python
test=int(raw_input())
a=0
while(a<test):
a=a+1
count=0
j= raw_input()
s= raw_input()
for letter in s:
if (letter in j):
count=count+1
print count
``` | vfc_76281 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nabc\nabcdef\naA\nabAZ\naaa\na\nwhat\nnone",
"output": "3\n2\n1\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\nacb\nabcdef\naA\nabAZ\naaa\na\nwhat\nnone",
"output": "3\n2\n1... |
code_contests | verifiable_code | 1009_B. Minimum Ternary String | Solve the following coding problem using the programming language python:
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive)... | ```python
s = input()
s = list(s)
n = len(s)
i=0
j = i
while j<n and s[j]!='2':
j+=1
a = sorted(s[i:j])
one = []
others = []
while j<n:
if s[j]=='1':
one+=[s[j]]
else:
others+=[s[j]]
j+=1
ans = a+one+others
print(''.join(ans))
``` | vfc_76285 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100210\n",
"output": "001120\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | 1118_E. Yet Another Ball Problem | Solve the following coding problem using the programming language python:
The king of Berland organizes a ball! n pair are invited to the ball, they are numbered from 1 to n. Each pair consists of one man and one woman. Each dancer (either man or woman) has a monochrome costume. The color of each costume is represente... | ```python
n,k=map(int,input().split())
if(n>(k*(k-1))):
print('NO')
else:
ans=[0 for i in range(n)]
for i in range(len(ans)):
ans[i]=(i+1)%k
if(ans[i]==0):
ans[i]=k
count=1
temp=[0 for i in range(len(ans))]
for i in range(len(ans)):
if(i%k==0):
t... | vfc_76305 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n",
"output": "YES\n1 2\n2 1\n1 3\n3 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13 4\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1145_B. Kanban Numbers | Solve the following coding problem using the programming language python:
Input
The input contains a single integer a (1 ≤ a ≤ 99).
Output
Output "YES" or "NO".
Examples
Input
5
Output
YES
Input
13
Output
NO
Input
24
Output
NO
Input
46
Output
YES
The input will be given via stdin ... | ```python
import math
k = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen']
n = ['', '', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']
a = int(input(... | vfc_76309 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "24\n",
... |
code_contests | verifiable_code | 1166_A. Silent Classroom | Solve the following coding problem using the programming language python:
There are n students in the first grade of Nlogonia high school. The principal wishes to split the students into two classrooms (each student must be in exactly one of the classrooms). Two distinct students whose name starts with the same letter... | ```python
n = int(input())
l = []
se = set()
for _ in range(n):
st = input()
s = st[0:1]
l.append(s)
se.add(s)
su = 0
for s in se:
c = l.count(s)
if c>1:
x = c//2
y = c-x
su += ((x*(x-1))+(y*(y-1)))//2
print(su)
``` | vfc_76313 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\nkambei\ngorobei\nshichiroji\nkyuzo\nheihachi\nkatsushiro\nkikuchiyo\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\njorge\njose\noscar\njerry\n",
"output": "1\... |
code_contests | verifiable_code | 1184_E2. Daleks' Invasion (medium) | Solve the following coding problem using the programming language python:
After a successful field test, Heidi is considering deploying a trap along some Corridor, possibly not the first one. She wants to avoid meeting the Daleks inside the Time Vortex, so for abundance of caution she considers placing the traps only ... | ```python
def naiveSolve():
return
from types import GeneratorType
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
if stack:
return f(*args, **kwargs)
else:
to = f(*args, **kwargs)
while True:
if type(to) is Genera... | vfc_76317 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 15, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n1 2 8\n2 3 3\n3 1 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 17\n8 2 166387394\n1 6 237498837\n6 9 99779164\n4 7 525284035\n5 3 354857458\n5 4 957219660\n4 ... |
code_contests | verifiable_code | 1220_A. Cards | Solve the following coding problem using the programming language python:
When Serezha was three years old, he was given a set of cards with letters for his birthday. They were arranged into words in the way which formed the boy's mother favorite number in binary notation. Serezha started playing with them immediately... | ```python
n = int(input())
s = input()
for i in range(s.count('n')): print(1, end = ' ')
for i in range(s.count('z')): print(0, end = ' ')
``` | vfc_76325 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nezor\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\nnznooeeoer\n",
"output": "1\n1\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1245_C. Constanze's Machine | Solve the following coding problem using the programming language python:
Constanze is the smartest girl in her village but she has bad eyesight.
One day, she was able to invent an incredible machine! When you pronounce letters, the machine will inscribe them onto a piece of paper. For example, if you pronounce 'c', ... | ```python
s=input()
a=s.count('m')
f=True
ans=0
if(a>0):
f=False
a=s.count('w')
if(a>0):
f=False
n=len(s)
if(f==True):
dp=[0]*(n+1)
dp[0]=1
dp[1]=1
for i in range(2,n+1):
if(s[i-1]==s[i-2] and (s[i-1]=='u' or s[i-1]=='n')):
dp[i]=(dp[i-1]+dp[i-2])%1000000007
else:
... | vfc_76329 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "amanda\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "nnn\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1265_A. Beautiful String | Solve the following coding problem using the programming language python:
A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not.
Ahcl wants to construct a beautiful string. He has a string s, consis... | ```python
def inp():
return [int(s) for s in input().split()]
if __name__ == '__main__':
for i in range(int(input())):
s = input()
output = ''
if len(s) == 1 and s[0] == '?':
s = 'a'
for j in range(len(s)):
if s[j] != '?':
output += s[j]... | vfc_76333 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\na???cb\na??bbc\na?b?c\n",
"output": "ababcb\n-1\nacbac\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "23\n?\n??\n???\n????\n????\n?a\n?b\n?c\na?\nb?\nc?\n?a?\n?b?\n?c?\na?a\na?b\na?c\n... |
code_contests | verifiable_code | 1286_C2. Madhouse (Hard version) | Solve the following coding problem using the programming language python:
This problem is different with easy version only by constraints on total answers length
It is an interactive problem
Venya joined a tour to the madhouse, in which orderlies play with patients the following game. Orderlies pick a string s of le... | vfc_76337 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n\na\naa\na\n\ncb\nb\nc\n\nc",
"output": "\n? 1 2\n\n? 3 4\n\n? 4 4\n\n! aabc",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 132_B. Piet | Solve the following coding problem using the programming language python:
Piet is one of the most known visual esoteric programming languages. The programs in Piet are constructed from colorful blocks of pixels and interpreted using pretty complicated rules. In this problem we will use a subset of Piet language with s... | ```python
# CP = [left, right] right = +1 , left = -1
# DP = [left,right,top,down]
# 0 2 1 3
"""
1
--- 0 2
3
"""
gather ={}
def move(i):
global BP
global DP
global CP
global skip
if (BP[0],BP[1],DP,CP) not in gather:
gather[(BP[0],BP[1],DP,CP)] = i
e... | vfc_76345 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 12\n1423\n6624\n6625\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 10\n12\n43\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | 1349_F2. Slime and Sequences (Hard Version) | Solve the following coding problem using the programming language python:
Note that the only differences between easy and hard versions are the constraints on n and the time limit. You can make hacks only if all versions are solved.
Slime is interested in sequences. He defined good positive integer sequences p of len... | vfc_76349 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n",
"output": "3 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "1 ",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 136_E. Zero-One | Solve the following coding problem using the programming language python:
Little Petya very much likes playing with little Masha. Recently he has received a game called "Zero-One" as a gift from his mother. Petya immediately offered Masha to play the game with him.
Before the very beginning of the game several cards ... | ```python
def evaluate(a):
c1 = a.count('1')
c0 = a.count('0')
n = len(a)
A = (n - 1) // 2
B = (n - 2) // 2
if c1 <= A:
return '00'
if c0 <= B:
return '11'
p1 = a.rfind('1')
p0 = a.rfind('0')
if p0 < p1:
return '01'
else:
return '10'
a =... | vfc_76353 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "????\n",
"output": "00\n01\n10\n11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1?1\n",
"output": "01\n11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1433_F. Zero Remainder Sum | Solve the following coding problem using the programming language python:
You are given a matrix a of size n × m consisting of integers.
You can choose no more than \left⌊m/2\right⌋ elements in each row. Your task is to choose these elements in such a way that their sum is divisible by k and this sum is the maximum.
... | ```python
import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
#from bisect import bisect_left as bl, bisect_right as br, insort
#from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
... | vfc_76365 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4 3\n1 2 3 4\n5 2 2 2\n7 1 1 4\n",
"output": "24\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5 4\n1 2 4 2 1\n3 5 1 2 4\n1 5 7 1 2\n3 8 7 1 2\n8 4 7 1 6\n",
"output": "56\n",
... |
code_contests | verifiable_code | 1458_E. Nim Shortcuts | Solve the following coding problem using the programming language python:
After your debut mobile game "Nim" blew up, you decided to make a sequel called "Nim 2". This game will expand on the trusted Nim game formula, adding the much awaited second heap!
In the game, there are two heaps, each containing a non-negati... | ```python
from heapq import *
from bisect import bisect_left
n, m = map(int, input().split())
inf = 15 * 10 ** 8
norm = []
rev = []
slow = set()
for _ in range(n):x, y = map(int, input().split());heappush(norm, (x,y));heappush(rev, (y,x));slow.add((x,y))
cx = cy = 0
skipX=[]
skipY=[]
for i in range(2 * n):
tl ... | vfc_76369 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\n3 0\n0 1\n2 2\n0 0\n1 1\n2 2\n3 3\n5 4\n",
"output": "\nLOSE\nWIN\nLOSE\nWIN\nLOSE\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 1\n2 5\n4 0\n5 1\n5 6\n4 4\n",
"output": "WI... |
code_contests | verifiable_code | 1481_E. Sorting Books | Solve the following coding problem using the programming language python:
One day you wanted to read something, so you went to your bookshelf to grab some book. But when you saw how messy the bookshelf was you decided to clean it up first.
<image>
There are n books standing in a row on the shelf, the i-th book has c... | ```python
n = int(input())
a = [int(x) - 1 for x in input().split()]
l = [-1 for _ in range(n + 1)]
r = [-1 for _ in range(n + 1)]
freq = [0 for _ in range(n + 1)]
dp = [0 for _ in range(n + 1)]
for i in range(n):
if(l[a[i]] == -1): l[a[i]] = i
r[a[i]] = i
for i in range(n - 1, -1, -1):
dp[i] = dp[i + 1]
... | vfc_76373 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 2 1 3\n",
"output": "\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 2 2 1 1\n",
"output": "\n1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1508_F. Optimal Encoding | Solve the following coding problem using the programming language python:
Touko's favorite sequence of numbers is a permutation a_1, a_2, ..., a_n of 1, 2, ..., n, and she wants some collection of permutations that are similar to her favorite permutation.
She has a collection of q intervals of the form [l_i, r_i] wit... | vfc_76377 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 1024000000,
"problem_url": null,
"time_limit": "{'seconds': 7, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 4\n3 7 4 8 1 5 2 6\n3 6\n1 6\n3 8\n1 8\n",
"output": "\n3\n5\n9\n7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 10\n10 5 1 2 7 3 9 4 6 8\n2 2\n4 5\n6 8\n4 10\n4 4\n2 7\n2 2\n7 8\n3... | |
code_contests | verifiable_code | 1534_G. A New Beginning | Solve the following coding problem using the programming language python:
Annie has gotten bored of winning every coding contest and farming unlimited rating. Today, she is going to farm potatoes instead.
Annie's garden is an infinite 2D plane. She has n potatoes to plant, and the i-th potato must be planted at (x_i,... | vfc_76381 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 1\n2 2\n",
"output": "\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n1 1\n2 2\n2 0\n4 2\n4 0\n2 0\n0 2\n4 0\n4 2\n5 1\n",
"output": "\n6\n",
"type": "stdin_stdout... | |
code_contests | verifiable_code | 162_D. Remove digits | Solve the following coding problem using the programming language python:
You are given a string. Remove all digits from it. When a character is removed from a string, all characters to the right of it are shifted one position to the left.
Input
The only line of input contains a string between 1 and 100 characters l... | vfc_76385 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "VK-Cup-2012!\n",
"output": "VK-Cup-!\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "Go,Codeforces!\n",
"output": "Go,Codeforces!\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 181_E. Playing with Superglue | Solve the following coding problem using the programming language python:
Two players play a game. The game is played on a rectangular board with n × m squares. At the beginning of the game two different squares of the board have two chips. The first player's goal is to shift the chips to the same square. The second p... | ```python
n,m,x1,y1,x2,y2 = map(int, input().split())
n = abs(x1 - x2)
m = abs(y1 - y2)
if n > 4 or m > 4:
print("Second")
elif n <= 3 and m <= 3:
print("First")
elif min(n, m) <= 2:
print("First")
else:
print("Second")
``` | vfc_76389 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 5 4 3 2 1\n",
"output": "First\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 205_B. Little Elephant and Sorting | Solve the following coding problem using the programming language python:
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integ... | ```python
def solve(arr, n):
inc = 0
ans = 0
for i in range(1, n):
arr[i] += inc
if arr[i] >= arr[i - 1]:
continue
diff = arr[i - 1] - arr[i]
ans += diff
inc += diff
arr[i] += diff
# print(arr)
# print(ans)
return ans
def read():
... | vfc_76393 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n7 4 1 47\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 22_A. Second Order Statistics | Solve the following coding problem using the programming language python:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In... | ```python
n=int(input())
ar=[int(i) for i in input().split()]
ar=list(set(sorted(ar)))
ar.sort()
try:
print(ar[1])
except IndexError:
print("NO")
``` | vfc_76397 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 2 -4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 2 3 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 254_A. Cards with Numbers | Solve the following coding problem using the programming language python:
Petya has got 2n cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2n. We'll denote the number that is written on a card with number i, as ai. In order to pl... | ```python
from sys import stdin, stdout
import math,sys
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict,Counter
from os import path
import bisect as bi
import heapq
mod=10**9+7
def yes():print('YES')
def no():print('NO')
if (path.exists('input.txt')):
#------... | vfc_76401 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n20 30 10 30 20 10\n",
"output": "4 2\n1 5\n6 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1 2\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn_name"... |
code_contests | verifiable_code | 278_E. Game | Solve the following coding problem using the programming language python:
Two players play the following game. Initially, the players have a knife and a rectangular sheet of paper, divided into equal square grid cells of unit size. The players make moves in turn, the player who can't make a move loses. In one move, a ... | ```python
import sys
def totalCut( cuts ) :
cuts = sorted( cuts )
if not cuts :
return 0
res = 0
rightmost = cuts[ 0 ][ 1 ]
for cut in cuts :
if cut[ 0 ] > rightmost :
res += cut[ 0 ] - rightmost
rightmost = max( rightmost , cut[ 1 ] )
return rightmost - cut... | vfc_76405 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1 0\n",
"output": "FIRST\n1 0 1 1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2 4\n0 1 2 1\n0 1 2 1\n1 2 1 0\n1 1 1 2\n",
"output": "SECOND\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 300_D. Painting Square | Solve the following coding problem using the programming language python:
Vasily the bear has got a large square white table of n rows and n columns. The table has got a black border around this table.
<image> The example of the initial table at n = 5.
Vasily the bear wants to paint his square table in exactly k mov... | vfc_76409 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n1 0\n1 1\n3 0\n3 1\n2 0\n2 1\n3 2\n7 2\n",
"output": "1\n0\n1\n1\n1\n0\n0\n4\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 327_B. Hungry Sequence | Solve the following coding problem using the programming language python:
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n... | ```python
n=int(input())
for i in range(n,n+n):
print(i,end=' ')
``` | vfc_76413 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "2 3 5 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "2 3 5 7 11 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input... |
code_contests | verifiable_code | 349_C. Mafia | Solve the following coding problem using the programming language python:
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the super... | ```python
def ceil(x):
if int(x) != x:
return int(x+1)
else:
return int(x)
def mafia():
n = int(input())
rounds = list(map(int, str(input()).split()))
count = 0
rounds.sort(reverse=True)
for i in range(n-1, 0, -1):
if rounds[i-1] == rounds[i]:
continue
... | vfc_76417 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 2 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n2 2 2 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
code_contests | verifiable_code | 372_D. Choosing Subtree is Fun | Solve the following coding problem using the programming language python:
There is a tree consisting of n vertices. The vertices are numbered from 1 to n.
Let's define the length of an interval [l, r] as the value r - l + 1. The score of a subtree of this tree is the maximum length of such an interval [l, r] that, th... | vfc_76421 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "16 7\n13 11\n12 11\n2 14\n8 6\n9 15\n16 11\n5 14\n6 15\n4 3\n11 15\n15 14\n10 1\n3 14\n14 7\n1 7\n",
"output": "6",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 6\n4 10\n10 6\n2 9\n9 6\n... | |
code_contests | verifiable_code | 394_A. Counting Sticks | Solve the following coding problem using the programming language python:
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us... | ```python
v = input().split('+')
a = len(v[0])
v = v[1].split('=')
b = len(v[0])
c = len(v[1])
def good(a, b, c):
return a+b==c and a>0 and b>0 and c>0
if good(a-1, b, c+1):
a = a-1
c = c+1
if good(a, b-1, c+1):
b = b-1
c = c+1
if good(a+1, b, c-1):
a = a+1
c = c-1
if good(a, b+1, c-1):... | vfc_76425 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "|+|=||||||\n",
"output": "Impossible\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "|||||+||=||\n",
"output": "Impossible\n",
"type": "stdin_stdout"
},
{
"fn_nam... |
code_contests | verifiable_code | 417_B. Crash | Solve the following coding problem using the programming language python:
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same sour... | ```python
def readln(): return tuple(map(int, input().split()))
n, = readln()
max_pref = [-1] * 100001
flag = True
for _ in range(n):
x, k = readln()
flag &= max_pref[k] + 1 >= x
max_pref[k] = max(max_pref[k], x)
print('YES' if flag else 'NO')
``` | vfc_76429 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n0 1\n1 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 1\n1 2\n1 1\n0 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": ... |
code_contests | verifiable_code | 443_E. Artem and Array | Solve the following coding problem using the programming language python:
Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a, b) points, where a and b are numbe... | ```python
n = input()
s = []
a = 0
for i in map(int, input().split()):
while len(s) > 1 and min(s[-2], i)>=s[-1]:
a += min(i, s[-2])
del(s[-1])
s.append(i)
s.sort()
print(a + sum(s[0: -2]))
``` | vfc_76433 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 100 101 100 1\n",
"output": " 102\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 2 3 4 5\n",
"output": " ... |
code_contests | verifiable_code | 466_A. Cheap Travel | Solve the following coding problem using the programming language python:
Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she wil... | ```python
inp = input().split()
n = int(inp[0])
m = int(inp[1])
a = int(inp[2])
b = int(inp[3])
sumary = min(b,a*m)
print(min((sumary)*(n//m + 1), sumary*(n // m) + (n - (n//m)*m) * a ))
``` | vfc_76437 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2 2 3\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 2 1 2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | 489_E. Hiking | Solve the following coding problem using the programming language python:
A traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by its picturesqueness, so for the i-th ... | ```python
import os
import sys
if os.path.exists(r'C:\Users\User\codeforces'):
f = iter(open('A.txt').readlines())
def input():
return next(f).strip()
# input = lambda: sys.stdin.readline().strip()
else:
input = lambda: sys.stdin.readline().strip()
fprint = lambda *args: print(*args, flush=True... | vfc_76441 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 9\n10 10\n20 10\n30 1\n31 5\n40 10\n",
"output": "1 2 4 5 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13 6\n7 75\n8 84\n16 95\n29 21\n49 33\n54 56\n55 80\n65 63\n67 50\n73 47\n80 26\n... |
code_contests | verifiable_code | 513_C. Second price auction | Solve the following coding problem using the programming language python:
Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies c... | ```python
import sys
MaxV = int(1e4)
data = []
readIdx = 0
for line in sys.stdin.readlines():
data += line.split()
def read():
global readIdx
readIdx += 1
return data[readIdx - 1]
n, average, power, mul = int(read()), 0, 1, 1
froms, tos, r = [], [], []
def generate(i, maxIdx, secondMax, equal, ways):
global n... | vfc_76445 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 5\n3 4\n1 6\n",
"output": "3.5000000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n4 7\n8 10\n5 5\n",
"output": "5.7500000000000\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 566_F. Clique in the Divisibility Graph | Solve the following coding problem using the programming language python:
As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.
Just in case, let us remind you that a clique in a non-directed graph is a subset of th... | ```python
for _ in range(1):
n=int(input())
l=list(map(int,input().split()))
dp=[0]*(10**6+1)
for i in l:
dp[i]=1
for i in l:
if dp[i]:
for x in range(i*2,10**6+1,i):
if dp[x]:
dp[x]=max(dp[x],dp[i]+1)
print(max(dp)) ... | vfc_76453 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n3 4 6 8 10 18 21 24\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n2 6 16 18 24 96\n",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name":... |
code_contests | verifiable_code | 588_A. Duff and Meat | Solve the following coding problem using the programming language python:
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.
<image>
There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day... | ```python
n=int(input())
y,s=101,0
for i in range(n):
a,b=map(int,input().split())
if y>b:
y=b
s+=(a*y)
print(s)
``` | vfc_76457 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 3\n2 1\n3 2\n",
"output": "8\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 60_C. Mushroom Strife | Solve the following coding problem using the programming language python:
Pasha and Akim were making a forest map — the lawns were the graph's vertexes and the roads joining the lawns were its edges. They decided to encode the number of laughy mushrooms on every lawn in the following way: on every edge between two law... | ```python
import sys
from collections import *
from fractions import gcd
nok=lambda x,y: x*y/gcd(x,y)
def fail():
print "NO"
sys.exit(0)
n,m = map(int,raw_input().split())
r = [map(int,raw_input().split()) for i in xrange(m)]
a0 = [1]*n
aa = [1]*n
for x,y,nd,nk in r:
a0[x-1]=nok(a0[x-1],nd)
a0[y-1]=nok(... | vfc_76461 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1\n1 2 1 3\n",
"output": "YES\n1 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 0\n",
"output": "YES\n1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 630_H. Benches | Solve the following coding problem using the programming language python:
The city park of IT City contains n east to west paths and n north to south paths. Each east to west path crosses each north to south path, so there are n2 intersections.
The city funded purchase of five benches. To make it seems that there are... | ```python
from collections import Counter
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
... | vfc_76465 | {
"difficulty": "14",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n",
"output": "120\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n",
"output": "52920\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n... |
code_contests | verifiable_code | 658_E. Bear and Contribution | Solve the following coding problem using the programming language python:
Codeforces is a wonderful platform and one its feature shows how much someone contributes to the community. Every registered user has contribution — an integer number, not necessarily positive. There are n registered users and the i-th of them h... | ```python
#
# http://codeforces.com/problemset/problem/658/E
import sys
import heapq
def read_line():
return next(sys.stdin).strip()
def read_ints():
return map(int, read_line().split())
def case1():
s = sum(A[K - 1] - v for v in A[:K])
yield s * C
for i in xrange(K, N):
s += (K - 1) ... | vfc_76469 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 2 987 789\n-8 42 -4 -65 -8 -8\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 681_B. Economy Game | Solve the following coding problem using the programming language python:
Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.
Kolya remembers that ... | ```python
n = int(input())
for i in range((n//1234567) + 1):
for j in range((n//123456) + 1):
t = n - i * 1234567 - j * 123456
if t >= 0 and t % 1234 == 0:
print("YES")
exit()
print("NO")
``` | vfc_76473 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "17851817\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1359257\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 704_A. Thor | 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 those ... | ```python
n , q = map(int, input().split())
stacks = [[] for i in range(n + 1)]
queue = []
q_start = 0
unread = 0
ans = []
for i in range(q):
action, num = map(int, input().split())
if action == 1:
queue.append(0)
stacks[num].append(len(queue) - 1)
unread += 1
elif action =... | vfc_76477 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n1 3\n1 1\n1 2\n2 3\n",
"output": "1\n2\n3\n2\n\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 725_F. Family Photos | Solve the following coding problem using the programming language python:
Alice and Bonnie are sisters, but they don't like each other very much. So when some old family photos were found in the attic, they started to argue about who should receive which photos. In the end, they decided that they would take turns pick... | ```python
num_stacks = int(input())
answer = 0
array = []
for i in range(num_stacks):
a1, b1, a2, b2 = input().split(' ')
a1 = int(a1)
a2 = int(a2)
b1 = int(b1)
b2 = int(b2)
if a1 + b1 >= a2 + b2:
answer += a1 + a2
array.append(a2 + b2)
array.append(a1 + b1)
e... | vfc_76481 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n0 10 0 10\n",
"output": "-10",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n12 3 4 7\n1 15 9 1\n",
"output": "1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 770_C. Online Courses In BSU | Solve the following coding problem using the programming language python:
Now you can take online courses in the Berland State University! Polycarp needs to pass k main online courses of his specialty to get a diploma. In total n courses are availiable for the passage.
The situation is complicated by the dependence o... | ```python
f = lambda: map(int, input().split())
g = lambda: [[] for x in range(n)]
n, k = f()
n += 1
s, p = [], list(f())
c, d = [0] * n, [0] * n
u, v = g(), g()
for x in range(1, n):
t = list(f())
m = t.pop(0)
if m:
c[x] = m
v[x] = t
for y in t: u[y].append(x)
else:
s.... | vfc_76489 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n1 2 3\n1 2\n1 3\n1 1\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 794_F. Leha and security system | Solve the following coding problem using the programming language python:
Bankopolis, the city you already know, finally got a new bank opened! Unfortunately, its security system is not yet working fine... Meanwhile hacker Leha arrived in Bankopolis and decided to test the system!
Bank has n cells for clients' money.... | vfc_76493 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5\n25 36 39 40 899\n1 1 3 2 7\n2 1 2\n1 3 5 9 1\n1 4 4 0 9\n2 1 5\n",
"output": " 111\n 1002\n",
"... | |
code_contests | verifiable_code | 862_A. Mahmoud and Ehab and the MEX | Solve the following coding problem using the programming language python:
Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in sets, He has a set of n integers. Dr. E... | ```python
n,m = map(int, input().split())
s = set([int(i) for i in input().split()])
ans = 0
for i in range (m):
if i not in s:
ans += 1
print(ans+1 if m in s else ans)
``` | vfc_76505 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n0 4 5 6 7\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 0\n1 2 3 4 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 887_E. Little Brother | Solve the following coding problem using the programming language python:
Masha's little brother draw two points on a sheet of paper. After that, he draws some circles and gave the sheet to his sister.
Masha has just returned from geometry lesson so she instantly noticed some interesting facts about brother's drawin... | vfc_76509 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "-2 3 10 -10\n2\n7 0 3\n-5 -5 2\n",
"output": "9.148183\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 4 7 13\n3\n3 0 1\n12 4 2\n-4 14 2\n",
"output": "5.147815\n",
"type": "... | |
code_contests | verifiable_code | 90_E. Chip Play | Solve the following coding problem using the programming language python:
Let's consider the following game. We have a rectangular field n × m in size. Some squares of the field contain chips.
Each chip has an arrow painted on it. Thus, each chip on the field points in one of the following directions: up, down, left ... | vfc_76513 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\n.D...\nRRRLL\n.U...\n",
"output": "6 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4\nDRLD\nU.UL\n.UUR\nRDDL\n",
"output": "10 1\n",
"type": "stdin_stdout"
},
... | |
code_contests | verifiable_code | 932_B. Recursive Queries | Solve the following coding problem using the programming language python:
Let us define two functions f and g on positive integer numbers.
<image>
<image>
You need to process Q queries. In each query, you will be given three integers l, r and k. You need to print the number of integers x between l and r inclusive,... | vfc_76517 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n82 94 6\n56 67 4\n28 59 9\n39 74 4\n",
"output": "3\n1\n1\n5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n22 73 9\n45 64 6\n47 55 7\n2 62 4\n",
"output": "1\n4\n0\n8\n",
... | |
code_contests | verifiable_code | agent-007-and-secret-mission-1 | Solve the following coding problem using the programming language python:
Agent 007 is on a secret mission in country "Codeland" on which he was transferring data in form of binary string to secret base of MI6. One day agents of country Codeland detect some ambiguity in system as they find that someone is leaking the... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
t=input()
while t>0:
t-=1
s=raw_input()
n=input()
x=(n*(n+1))/2
if x%2==0:
print s.count("1")
#print s
else:
print s.count("0")
``` | vfc_76529 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1011\n1\n0010\n2\n\nSAMPLE",
"output": "1\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n00\n467\n0000111111\n724\n101001\n942\n100\n382\n010101\n447\n0110110111\n35\n001111110... |
code_contests | verifiable_code | breaking-bad-3 | Solve the following coding problem using the programming language python:
“All Hail The King.”
Middle aged, and overqualified highschool chemistry teacher Walter White has been diagnosed with lung cancer. To make sure his family is financially secure, he teams up with a former student Jesse Pinkman and turns to a lif... | ```python
for _ in range(int(raw_input())):
n=int(raw_input())
a=map(int,raw_input().split())
a=sorted(a,reverse=True)
add=0
i=0
l=len(a)
while i<l:
add=add+(a[i]*a[i+1])
i+=2
print add
``` | vfc_76533 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n3 1\n4\n1 4 6 3\n\nSAMPLE",
"output": "3\n27\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2\n3 1\n4\n1 4 6 3\n\nSBMPLE",
"output": "3\n27\n",
"type": "stdin_stdout"... |
code_contests | verifiable_code | daisy-and-the-transformation | Solve the following coding problem using the programming language python:
Mack gives Daisy two strings S1 and S2-consisting only of characters- 'M' and 'D' , and asks her to convert S1 to S2 in exactly N moves.
In a single move, Daisy has two choices:
Exchange any one 'M' with a 'D', or
Exchange any one 'D' with a 'M... | ```python
def solve(s1, s2, k):
count = 0
for i in xrange(len(s2)):
if s1[i] != s2[i]:
count += 1
if count > k:
return False
if count == k or (k-count) % 2 == 0:
return True
return False
T = input()
for i in xrange(T):
s1, s2, N = raw_input().strip().split(" ")
N = int(N)
if solve(s1, s2, N):
prin... | vfc_76537 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nMMDMDDM DDDDDDD 2\nMMDD MMDD 1\nMMMMMDMM DDDDDMDD 8\n\nSAMPLE",
"output": "No\nNo\nYes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "141\nMMDMDDM DDDDDDD 2\nMMDD MMDD 1\nMMMMMDMM DDDD... |
code_contests | verifiable_code | g-game-with-letters | Solve the following coding problem using the programming language python:
Valentina is looking for a new game to play with her friends.
She asks her mom Marcia for an idea.
After a moment Marcia described to girls the following simple game.
Girls are divided into n teams, indexed 1 through n.
Each girl chooses a lowe... | ```python
for _ in range(int(raw_input())):
n,s=raw_input().split()
n=int(n)
p={}
for i in s:
if p.has_key(i):
p[i]+=1
else:
p[i]=1
a=[]
for i in range(n):
s=raw_input()
ct=0
for j in s:
ct+=p.get(j,0)
a.append([... | vfc_76541 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 qwopwasp\nwdw\nabco\n5 eeeessaa\nvalentina\nesta\njugando\ncon\nmarcia\n5 ahi\nvalentina\nesta\njugando\ncon\nsusamigas\n\nSAMPLE",
"output": "1\n2\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | k-arrays | Solve the following coding problem using the programming language python:
Milly is feeling bored during her winter vaccations, so she has decided to do some random fun on some arrays. She will take K number of arrays of same same size N. She will make all possible non-empty subsets of these arrays. She will make a Set... | ```python
from operator import add, mul
def read_ints():
return map(int, raw_input().split())
def sum(it):
return reduce(add, it, 0)
def getpow(a, x, mod):
if x == 0:
return 1
t = getpow(a, x / 2, mod)
if x % 2 == 0:
return t * t % mod
return t * t * a % mod
def main():
T = read_ints()[0]
for t in xran... | vfc_76545 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2 2\n1 2\n3 4\n\nSAMPLE",
"output": "8 3",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | mirror-of-mahatma-gandhi | Solve the following coding problem using the programming language python:
On the way to Dandi March, Gandhijee carried a mirror with himself. When he reached Dandi, he decided to play a game with the tired people to give them some strength. At each turn of the game he pointed out a person and told him to say a number ... | ```python
t=int(raw_input())
for i in range(t):
a=raw_input()
if(a[::-1]!=a):
print "NO"
elif(('2'in a)or('3'in a)or('4'in a)or('5'in a)or('6'in a)or('7'in a)or('9'in a)):
print "NO"
else:
print "YES"
``` | vfc_76549 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n101\n020\n\nSAMPLE",
"output": "YES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n17409488245517115276142322168576189279543123341138831143321345972981675861223241672511715542... |
code_contests | verifiable_code | palindromic-ciphers | Solve the following coding problem using the programming language python:
Julius Cipher is a type of cipher which relates all the lowercase alphabets to their numerical position in the alphabet, i.e., value of a is 1, value of b is 2, value of z is 26 and similarly for the rest of them.
Little Chandan is obsessed wi... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
t = int(raw_input())
dc = {
"a":1,
"b":2,
"c":3,
"d":4,
"e":5,
"f":6,
"g":7,
"h":8,
"i":9,
"j":10,
"k":11,
"l":12,
"m":13,
"n":14,
"o":15,
"p":16,
"q":17,
"r... | vfc_76553 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nzazaz\ngoodarjit\n\nSAMPLE",
"output": "Palindrome\n204120000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "60\nvlmezxuyim\nusholhjomc\nfcrnbpodhf\ndltrthaaic\ncosnljmjtk\nzbowagxejo\... |
code_contests | verifiable_code | rk-string | Solve the following coding problem using the programming language python:
Today RK wants to play a game based on his awesome name.In this game RK gives you a string consists only of characters "R" and "K".Your task is to find the number of substrings of the given string, containing exactly M characters "R" and number ... | ```python
test=int(input())
for i in range(0,test):
k,l = raw_input().split(' ')
k=int(k)
l=int(l)
d, c, r = {0 : 1}, 0, 0
e,f,g={0:1},0,0
for x in raw_input():
c += x == 'R'
f += x == 'K'
r += d.get(c - k, 0)
g += e.get(f-l,0)
d[c] = d.get(c, 0) + 1
e[f]=e.get(f,0)+1
print (str(r)+" "+str(g))
``` | vfc_76557 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 1\nRKRK\n2 1\nKRKRK\n\nSAMPLE",
"output": "6 6\n4 8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n1 2\nKK\n1 3\nKR\n1 123\nRK\n1 0\nRR\n2 22\nKK\n2 120\nKR\n2 1\nRK\n2 0\nRR\n94 9\... |
code_contests | verifiable_code | square-transaction-20 | Solve the following coding problem using the programming language python:
Square Inc. processes thousands of transactions daily amounting to millions of dollars. They also have a daily target
that they must achieve. Given a list of transactions done by Square Inc. and a daily target your task is to determine at
whi... | ```python
import bisect;
n=input(); A=map(int,raw_input().split()); V,su=[],0;
for i in A: su+=i; V.append(su);
for i in xrange(int(raw_input())):
z=int(raw_input()); x=bisect.bisect_left(V,z);
if x==n: print -1
else: print x+1
``` | vfc_76561 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100\n34 37 28 16 44 36 37 43 50 22 13 28 41 10 14 27 41 27 23 37 12 19 18 30 33 31 13 24 18 36 30 3 23 9 20 18 44 7 12 43 30 24 22 20 35 38 49 25 16 21 14 27 42 31 7 24 13 21 47 32 6 26 35 28 37 6 47 30 14 8 25 46 33 46 15 18 35 15... |
code_contests | verifiable_code | troublesome-children | Solve the following coding problem using the programming language python:
Description
IIT Gandhinagar has a day-care centre for the children of its faculty and staff. As it is IIT Gandhinagar’s culture to do things differently, the morning roll-call here is
conducted in a unique manner.
The kids stand in a circle and... | ```python
n=input()
arr=[-1]*(n+1)
N=n
p=1
while n:
a=input()
if (a%n==0):
ans=n
else:
ans=a%n
y=0
for x in range(p,N+1):
if (arr[x]==-1):
ans-=1
if (ans==0):
y=x
break
# print "HEre"+str(ans)+str(y)
if (ans):
for x in range(1,p):
# print x,ans,y,arr[x]
# y+=1
if (arr[x]==-1):
ans... | vfc_76565 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3\n4\n5",
"output": "3\n2\n1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00002 Digit Number | Solve the following coding problem using the programming language python:
Write a program which computes the digit number of sum of two integers a and b.
Constraints
* 0 ≤ a, b ≤ 1,000,000
* The number of datasets ≤ 200
Input
There are several test cases. Each test case consists of two non-negative integers a and ... | ```python
while 1:
try:
a,b=map(int,input().split())
print(len(str(a+b)))
except: break
``` | vfc_76609 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 7\n1 99\n1000 999",
"output": "2\n3\n4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 7\n1 99\n1000 999",
"output": "2\n3\n4\n",
"type": "stdin_stdout"
},
{
"f... |
code_contests | verifiable_code | p00454 Paint Color | Solve the following coding problem using the programming language python:
problem
Information I want to paint a rectangular veneer board to make a signboard for the promotion of the Olympic Games. Some rectangular masking tapes are pre-attached to the veneer board where I do not want to paint. We decided to paint eac... | ```python
# -*- coding: utf-8 -*-
from typing import Union, List
import io, sys
import bisect
from collections import deque
def main():
w,h = list(map(int, sys.stdin.readline().split()))
if w == h == 0:
return "END"
n = int( sys.stdin.readline() )
x1y1x2y2_list = [ list(map(int, sys.... | vfc_76621 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "15 6\n10\n1 4 5 6\n2 1 4 5\n1 0 5 1\n6 1 7 5\n7 5 9 6\n7 0 9 2\n9 1 10 5\n11 0 14 1\n12 1 13 5\n11 5 14 6\n0 0",
"output": "5",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00789 Square Coins | Solve the following coding problem using the programming language python:
People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (= 172), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ..., and 289-credi... | ```python
# AOJ 1209: Square Coins
#Python3 2018.7.19 bal4u
dp = [1]*300
for i in range(2, 18):
for j in range(i**2, 300): dp[j] += dp[j-i**2]
while True:
n = int(input())
if n == 0: break
print(dp[n])
``` | vfc_76629 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n10\n30\n0",
"output": "1\n4\n27",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n10\n12\n0",
"output": "1\n4\n5\n",
"type": "stdin_stdout"
},
{
"fn_name": null... |
code_contests | verifiable_code | p00921 Don't Burst the Balloon | Solve the following coding problem using the programming language python:
An open-top box having a square bottom is placed on the floor. You see a number of needles vertically planted on its bottom.
You want to place a largest possible spheric balloon touching the box bottom, interfering with none of the side walls n... | ```python
from math import sqrt
def getcircle(nee, R): #針にぶつかる範囲の円
(x, y, h) = nee
if R <= h:
return (x, y, R)
r = sqrt(R**2 - (R-h)**2)
return (x, y, r)
def crosscircle(c1, c2): #円の交点
(x1, y1, r1) = c1
(x2, y2, r2) = c2
if (x1-x2)**2 + (y1-y2)**2 > (r1+r2)**2:
return (... | vfc_76633 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 16\n70 66 40\n38 52 20\n40 35 10\n70 30 10\n20 60 10\n1 100\n54 75 200\n1 10\n90 10 1\n1 11\n54 75 200\n3 10\n53 60 1\n61 38 1\n45 48 1\n4 10\n20 20 10\n20 80 10\n80 20 10\n80 80 10\n0 0",
"output": "26.00000\n39.00000\n130... |
code_contests | verifiable_code | p01054 String Conversion | Solve the following coding problem using the programming language python:
Problem
Jennifer and Marian presented Carla with the string S.
However, Carla is not happy to receive the string S.
I wanted the string T.
The three decided to work together to change the string S to the string T.
Jennifer first sorts the let... | ```python
# AOJ 1568: String Conversion
# Python3 2018.7.13 bal4u
cha, chzn = ord('a'), ord('z')+1
S, T = [0]*128, [0]*128
input()
a = input()
for x in a: S[ord(x)] += 1
S = sorted(S[cha:chzn], reverse=True)
a = input()
for x in a: T[ord(x)] += 1
T = sorted(T[cha:chzn], reverse=True)
ans = 0
for i in range(26): ans +=... | vfc_76637 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 267386880,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nabc\nxyz",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\naaabb\nxyxyz",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
code_contests | verifiable_code | p01186 TV Watching | Solve the following coding problem using the programming language python:
You are addicted to watching TV, and you watch so many TV programs every day. You have been in trouble recently: the airtimes of your favorite TV programs overlap.
Fortunately, you have both a TV and a video recorder at your home. You can there... | vfc_76641 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nOmoikkiriTV 12:00 13:00 5 1\nWaratteIitomo 12:00 13:00 10 2\nWatarusekennhaOnibakari 20:00 21:00 10 3\nSuzumiyaharuhiNoYuuutsu 23:00 23:30 100 40\n5\na 0:00 1:00 100 100\nb 0:00 1:00 101 101\nc 0:00 1:00 102 102\nd 0:00 1:00 103... | |
code_contests | verifiable_code | p01323 Compile | Solve the following coding problem using the programming language python:
Masa Kita, who entered the University of Tokyo, joined a circle called TSG (University of Tokyo Super Gamers).
This circle exhibits games at the Komaba Festival every year, and Masa Kita decided to create and display the games as well.
The gam... | ```python
def kesu(x, s, c, h):
global n
if (x[0] - 1, x[1]) not in s and a[x[0] - 1][x[1]] == c:
s.add((x[0] - 1, x[1]))
kesu((x[0] - 1, x[1]), s, c, h + 1)
if (x[0] + 1, x[1]) not in s and a[x[0] + 1][x[1]] == c:
s.add((x[0] + 1, x[1]))
kesu((x[0] + 1, x[1]), s, c, h + 1) ... | vfc_76645 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n......\n......\n......\n......\n......\n......\n......\n......\n.RGB..\nRGOP..\nRGBPB.\nRGBPP.\nGBRGYP\nGBRRYP\nBGGRBB\nBPRGYY\nGGPRRY\nBYPPRB\nYGGGPB\nGYYYPR\nYRBRBR\nYBRBRB\nBRBRBR\nBRBRBR\n......\n......\n......\n......\n....... |
code_contests | verifiable_code | p01491 RabbitLunch | Solve the following coding problem using the programming language python:
Example
Input
2 3 1 3 1 0
Output
2
The input will be given via stdin and the output should be printed to stdout by your code.
Now solve the problem by providing the code. | ```python
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
M, N, m0, md, n0, nd = map(int, readline().split())
S = [0]*(M+1)
S[0] = mi = m0
for i in range(1, M):
S[i] = mi = (mi * 58 + md) % (N + 1)
S.sort()
for i in range(M):
S[i+1] += S[i]
T ... | vfc_76649 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3 1 3 1 0",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3 1 3 1 1",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | p01653 Magical Bridges | Solve the following coding problem using the programming language python:
Problem Statement
A magician lives in a country which consists of N islands and M bridges. Some of the bridges are magical bridges, which are created by the magician. Her magic can change all the lengths of the magical bridges to the same non-n... | ```python
from heapq import heappush, heappop
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N, M, S1, S2, T = map(int, readline().split())
if N == 0:
return False
S1 -= 1; S2 -= 1; T -= 1
G = [[] for i in range(N)]
Gx = [[] for i in range(N)]
L = 0
fo... | vfc_76653 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2 2 3 1\n1 2 1\n1 3 2\n4 3 1 4 2\n2 1 3\n2 3 x\n4 3 x\n0 0 0 0 0",
"output": "1\n1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2 2 3 1\n1 2 1\n1 3 2\n4 3 1 4 2\n2 1 4\n2 3 x\n4 3 x\n... |
code_contests | verifiable_code | p01804 Falling Block Puzzle | Solve the following coding problem using the programming language python:
Falling Block Puzzle
Block drop
You are playing a falling block puzzle. As shown in the figure below, the field of this puzzle has a shape in which cubic cells are arranged in 2 squares x 2 squares in each row, and the rows are infinitely arra... | ```python
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
H, N = map(int, readline().split())
if H == N == 0:
return False
def get_block():
s = readline().strip()
v = (s[0] == '#') + (s[1] == '#')*2
s = readline().strip()
v += (s[0] == '... | vfc_76657 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\n##\n#.\n..\n..\n#.\n..\n1 1\n.#\n#.\n#.\n..\n..\n.#\n2 2\n##\n#.\n##\n#.\n..\n.#\n##\n#.\n#.\n..\n#.\n..\n1 3\n#.\n..\n##\n##\n##\n##\n##\n##\n##\n##\n##\n##\n##\n##\n10 3\n##\n#.\n##\n#.\n##\n.#\n##\n.#\n#.\n##\n#.\n##\n.#\n#... |
code_contests | verifiable_code | p01939 Ebi-chan and Integer Sequences | Solve the following coding problem using the programming language python:
B: Ebi-chan and Integer Sequences-
problem
Ebi-chan likes sequences. I especially like arithmetic progressions. This time, I decided to create a sequence that meets the following conditions.
* Arithmetic progression of length n
* When the i-t... | ```python
MOD = 10**9+7
def sum(a,d,n):
return n*(2*a+(n-1)*d)//2
def main():
n,m = map(int,input().split())
s = 0
if n == 1:
s = m+1
else:
s = sum(m+1,-n+1,1+m//(n-1))
s *= 2
s -= (m+1)
print(s%MOD)
if __name__ == '__main__':
main()
``` | vfc_76661 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 9",
"output": "50",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 0",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 -1",
... |
code_contests | verifiable_code | p02088 Union Ball | Solve the following coding problem using the programming language python:
A: Union Ball
Problem Statement
There are N balls in a box. The i-th ball is labeled with a positive integer A_i.
You can interact with balls in the box by taking actions under the following rules:
* If integers on balls in the box are all o... | ```python
n = int(input())
a = list(map(int, input().split()))
p, q = 0, 0
for i in a:
if i % 2 == 0:
p += 1
else:
q += 1
if p == 0 or q == 0:
print(0)
exit()
res = p
if q % 2 == 0:
res += 2 * max(q // 2 - 1, 0)
else:
res += (q // 2) * 2
print(res)
``` | vfc_76665 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4 5 6",
"output": "2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p02372 Height of a Tree | Solve the following coding problem using the programming language python:
Given a tree T with non-negative weight, find the height of each node of the tree. For each node, the height is the distance to the most distant leaf from the node.
Constraints
* 1 ≤ n ≤ 10,000
* 0 ≤ wi ≤ 1,000
Input
n
s1 t1 w1
s2 t2 w2
:
s... | ```python
from sys import stdin
from collections import defaultdict
readline = stdin.readline
#readline = open('GRL_5_B-in10.txt').readline
def main():
n = int(readline())
g = defaultdict(list)
for _ in range(n - 1):
s, t, d = map(int, readline().split())
g[s].append([d, t])
g[t].a... | vfc_76673 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0 1 2\n1 2 1\n1 3 3",
"output": "5\n3\n4\n5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 2 2\n1 2 1\n1 3 3",
"output": "6\n3\n4\n6\n",
"type": "stdin_stdout"
}
]... |
code_contests | verifiable_code | anudtc | Solve the following coding problem using the programming language python:
Problem description
Chef loves circular cakes. He divides them into smaller pieces and sells them. You are to help him in this work.
Today Chef has cooked the brand new circular cake. To split the cake Chef can make several (possibly, zero) cuts... | ```python
import math
import sys
def parseIntList(str):
return [long(x) for x in str.split()]
def printBS(li):
s=[str(i) for i in li]
print " ".join(s)
cases=input()
for i in range(cases):
n=input()
if 360%n : print 'n',
else: print 'y',
if 360/n : print 'y',
else: print 'n',
if n<=26: print 'y'
else: print '... | vfc_76677 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4\n7",
"output": "y y y\nn y y\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n4\n13",
"output": "y y y\nn y y\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... |
code_contests | verifiable_code | chrect | Solve the following coding problem using the programming language python:
Chef likes rectangles. Among all possible rectangles, he loves rectangles that can be drawn like a grid, such that they have N rows and M columns. Grids are common in Byteland. Hence, Chef has drawn such a rectangle and plans on moving around in... | ```python
i=0
t=int(raw_input())
while i<t:
n,m,k=map(int,raw_input().split())
if n>m:
n=n+m
m=n-m
n=n-m
if n==1 and m<=2:
print 0
elif n==1 and m>2:
print k
else:
print (k+1)/2
i+=1
``` | vfc_76681 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 2 1\n3 3 2\n1 5 12",
"output": "1\n1\n12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 2 1\n3 1 2\n1 5 12",
"output": "1\n2\n12\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | kokt03 | Solve the following coding problem using the programming language python:
Daenerys Targaryen has been suggested by her counselors to leave the Meereen and start conquering other parts of the world. But she knows giving up on the people of Meereen means victory of slavery. Her plan is to start conquering rest of the wo... | ```python
t = input()
for i in range(t):
n, m = map(int, raw_input().split())
a = map(int, raw_input().split())
ans = 0
for j in range(m):
ans += a[j]
for j in range(m, n):
ans -= (a[j] + 1) / 2
if ans < 0 :
print 'DEFEAT'
else :
print 'VICTORY'
``` | vfc_76689 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5 3\n1 2 3 4 5\n6 2\n4 4 4 4 4 4\n7 4 \n10 10 10 10 50 60 70",
"output": "VICTORY\nVICTORY\nDEFEAT",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | pall01 | Solve the following coding problem using the programming language python:
The citizens of Byteland regularly play a game. They have blocks each denoting some integer from 0 to 9. These are arranged together in a random manner without seeing to form different numbers keeping in mind that the first block is never a 0. O... | ```python
a = input()
for x in range(a):
n = str(input())
str1 = ''
for i in range(len(n)-1,-1,-1):
str1 += n[i]
if str1 == n:
print 'wins'
else:
print 'losses'
``` | vfc_76693 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n331\n666\n343",
"output": "losses\nwins\nwins\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n331\n699\n343",
"output": "losses\nlosses\nwins\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | sss | Solve the following coding problem using the programming language python:
Mr. Vallya,the rich playboy billionaire , has recently bought an IPL team Surathkal SuperStars (SSS) . Now he has the challenging task of buying the best possible team in the IPL auction . For this , he is aiming to make a priority order list in... | ```python
def getAns(x,M):
a=1
b=x
while b!=1:
c=M/b
a*=c
a%=M
b*=c
b%=M
if b>M/2:
a=M-a
b=M-b
return a
t=int(input())
for i in range(t):
n,p=map(int,raw_input().split())
if n<p:
f=1
i=p-1
while i>n:
... | vfc_76697 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 5\n5 11\n21 71",
"output": "2\n10\n6",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1007_A. Reorder the Array | Solve the following coding problem using the programming language python:
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such in... | ```python
n = int(input())
l = list(map(int,input().split()))
l.sort()
i = 0
c = 0
stack = []
k = 1
i = 0
while i < n-1 and k < n:
stack.append(l[i])
if l[i] != l[i+1]:
if k <= i:
k = i+1
while k < n and len(stack):
stack.pop()
c = c + 1
k = k + 1
i = i + 1
print(c)
``` | vfc_76701 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 1 1 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n10 1 1 1 5 5 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1030_A. In Search of an Easy Problem | Solve the following coding problem using the programming language python:
When preparing a tournament, Codeforces coordinators try treir best to make the first problem as easy as possible. This time the coordinator had chosen some problem and asked n people about their opinions. Each person answered whether this probl... | ```python
n = int(input())
str = input()
difficulty = []
difficulty = str.split()
flag = 1
for i in difficulty:
if i == '1':
print("HARD")
flag = 0
break
if(flag ==1):
print("EASY")
'''
3
0 0 1
HARD
1
0
EASY
'''
``` | vfc_76705 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n0\n",
"output": "EASY\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n0 0 1\n",
"output": "HARD\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
code_contests | verifiable_code | 1096_A. Find Divisible | Solve the following coding problem using the programming language python:
You are given a range of positive integers from l to r.
Find such a pair of integers (x, y) that l ≤ x, y ≤ r, x ≠ y and x divides y.
If there are multiple answers, print any of them.
You are also asked to answer T independent queries.
Input... | ```python
for _ in range(int(input())):
l, r = map(int, input().split())
for i in range(l,r+1):
k = r//i
if k>1:
print(i, i*2)
break
``` | vfc_76717 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 10\n3 14\n1 10\n",
"output": "1 2\n3 6\n1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n69696969 998244353\n",
"output": "69696969 139393938\n",
"type": "stdin_stdo... |
code_contests | verifiable_code | 1117_B. Emotes | Solve the following coding problem using the programming language python:
There are n emotes in very popular digital collectible card game (the game is pretty famous so we won't say its name). The i-th emote increases the opponent's happiness by a_i units (we all know that emotes in this game are used to make opponent... | ```python
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
c=0
a.sort()
q=a[n-1]
w=a[n-2]
r=k*q+w
u=m//(k+1)
c=u*r+q*(m-(u*(k+1)))
print(c)
``` | vfc_76721 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1000000000 1\n1000000000 987654321 1000000000\n",
"output": "1000000000000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 9 2\n1 3 3 7 4 2\n",
"output": "54\n",
"typ... |
code_contests | verifiable_code | 1143_D. The Beatles | Solve the following coding problem using the programming language python:
Recently a Golden Circle of Beetlovers was found in Byteland. It is a circle route going through n ⋅ k cities. The cities are numerated from 1 to n ⋅ k, the distance between the neighboring cities is exactly 1 km.
Sergey does not like beetles, ... | ```python
"""This code was written by
Russell Emerine - linguist,
mathematician, coder,
musician, and metalhead."""
from math import gcd
n, k = map(int, input().split())
a, b = map(int, input().split())
lll = [a + b, abs(a - b), k - a - b, k - abs(a - b)]
x, y = n * k, 0
for ll in lll:
for i in range(n):
l = ll +... | vfc_76725 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 10\n5 3\n",
"output": "5 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n0 0\n",
"output": "1 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"i... |
code_contests | verifiable_code | 1163_C2. Power Transmission (Hard Edition) | Solve the following coding problem using the programming language python:
This problem is same as the previous one, but has larger constraints.
It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the pow... | ```python
from itertools import combinations
n = int(input())
points = []
for _ in range(n):
x, y = map(int, input().split(' '))
points.append((x, y))
directions = {}
for pair in combinations(points, 2):
(x1, y1), (x2, y2) = pair
if x1 == x2:
dir = (0, 1)
b = x1
else:
dir ... | vfc_76729 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0 0\n1 1\n0 3\n1 2\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n-1 -1\n1 0\n3 1\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1184_A2. Heidi Learns Hashing (Medium) | Solve the following coding problem using the programming language python:
After learning about polynomial hashing, Heidi decided to learn about shift-xor hashing. In particular, she came across this interesting problem.
Given a bitstring y ∈ \{0,1\}^n find out the number of different k (0 ≤ k < n) such that there exi... | ```python
import math
num = int(input())
x = tuple(map(int, list(input())))
integer = 0
dic = dict()
for i in range(1,num+1):
a = math.gcd(i,num)
if a in dic:
integer += dic[a]
else:
lijst = [0]*a
for j in range(num):
b = j%a
lijst[b] += x[j]
... | vfc_76733 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1010\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0000\n",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "111... |
code_contests | verifiable_code | 1201_E1. Knightmare (easy) | Solve the following coding problem using the programming language python:
This problem only differs from the next problem in constraints.
This is an interactive problem.
Alice and Bob are playing a game on the chessboard of size n × m where n and m are even. The rows are numbered from 1 to n and the columns are numb... | vfc_76737 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 6\n4 4 2 2\n6 3",
"output": "BLACK\n4 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 8\n2 3 1 8\n",
"output": "WHITE\n4 4\n",
"type": "stdin_stdout"
},
{
"... | |
code_contests | verifiable_code | 1219_D. Workout plan | Solve the following coding problem using the programming language python:
Alan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift X[i] grams on day i. In order to improve his workout performance at the g... | ```python
n, k = tuple(map(int, input().split()))
plan = list(map(int, input().split()))
power = int(input())
cost = list(map(int, input().split()))
money = 0
current_pow = 0
store = [] # Запас
breaked = False
for i in range(n):
store.append(cost[i])
if plan[i] > k + current_pow:
if plan[i] > k + cur... | vfc_76741 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 10000\n10000 30000 30000 40000 20000\n20000\n5 2 8 3 6\n",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 10000\n10000 40000 30000 30000 20000\n10000\n5 2 8 3 6\n",
"... |
code_contests | verifiable_code | 1243_D. 0-1 MST | Solve the following coding problem using the programming language python:
Ujan has a lot of useless stuff in his drawers, a considerable part of which are his math notebooks: it is time to sort them out. This time he found an old dusty graph theory notebook with a description of a graph.
It is an undirected weighted ... | ```python
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
n,m = map(int, input().split())
G = [set() for i in range(n)]
for i in range(m):
a,b = map(int, input().split())
a,b = a-1,b-1
G[a].add(b)
G[b].add(a)
ans = 0
unused = set(range(n))
while unused:
cur = {unused.po... | vfc_76745 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 11\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 0\n",
"output": "0",
"type": "stdin_stdout"
}
... |
code_contests | verifiable_code | 1263_C. Everyone is a Winner! | Solve the following coding problem using the programming language python:
On the well-known testing system MathForces, a draw of n rating units is arranged. The rating will be distributed according to the following algorithm: if k participants take part in this event, then the n rating is evenly distributed between th... | ```python
for _ in range(int(input())):
n=int(input())
ar1=[]
ar2=[0]
count=1
for k in range(1,int(n**(1/2))+1):
p=n//k
if(p!=k and n%k<=p):
count+=2
ar1.append(p)
ar2.append(k)
elif(p==k and n%k<=p):
count+=1
ar1.ap... | vfc_76749 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n5\n11\n1\n3\n",
"output": "4\n0 1 2 5 \n6\n0 1 2 3 5 11 \n2\n0 1 \n3\n0 1 3 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n990\n94\n848\n",
"output": "62\n0 1 2 3 4 5 6 7 8 9... |
code_contests | verifiable_code | 1304_A. Two Rabbits | Solve the following coding problem using the programming language python:
Being tired of participating in too many Codeforces rounds, Gildong decided to take some rest in a park. He sat down on a bench, and soon he found two rabbits hopping around. One of the rabbits was taller than the other.
He noticed that the two... | ```python
def main():
test = int(input().strip())
while test>0 :
x,y,a,b =map( int,input().strip().split())
z = (y-x)/(a+b)
h=(y-x)%(a+b)
if h==0:
print(int(z))
else:
print(-1)
test-=1
if __name__ == "__main__":
main()
``` | vfc_76757 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n0 10 2 3\n0 10 3 3\n900000000 1000000000 1 9999999\n1 2 1 1\n1 3 1 1\n",
"output": "2\n-1\n10\n-1\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 10 0 3\n0 10 3 3\n900000000 100... |
code_contests | verifiable_code | 1328_B. K-th Beautiful String | Solve the following coding problem using the programming language python:
For the given integer n (n > 2) let's write down all the strings of length n which contain n-2 letters 'a' and two letters 'b' in lexicographical (alphabetical) order.
Recall that the string s of length n is lexicographically less than string t... | ```python
tc = int(input())
while tc > 0:
n, k = map(int, input().split())
t = 0
for i in range(n):
if t + i >= k:
s = ["a"] * n
s[n - i - 1] = "b"
s[n - k + t] = "b"
print("".join(s))
break
t += i
tc -= 1
``` | vfc_76761 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n5 1\n5 2\n5 8\n5 10\n3 1\n3 2\n20 100\n",
"output": "aaabb\naabab\nbaaba\nbbaaa\nabb\nbab\naaaaabaaaaabaaaaaaaa\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n8 18\n19 11\n20 5\n15 ... |
code_contests | verifiable_code | 1368_H2. Breadboard Capacity (hard version) | Solve the following coding problem using the programming language python:
This is a harder version of the problem H with modification queries.
Lester and Delbert work at an electronics company. They are currently working on a microchip component serving to connect two independent parts of a large supercomputer.
The ... | vfc_76769 | {
"difficulty": "14",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 5 4\nBBRR\nRBBR\nBBBBB\nRRRRR\nL 2 3\nR 3 4\nU 1 5\nD 1 5\n",
"output": "7\n7\n9\n4\n9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5 4\nBBRR\nRBBR\nBBBBB\nRRRRR\nL 2 3\nR 3 4\nU 2 ... | |
code_contests | verifiable_code | 138_D. World of Darkraft | Solve the following coding problem using the programming language python:
Recently Roma has become the happy owner of a new game World of Darkraft. This game combines elements of virtually all known genres, and on one of the later stages of the game Roma faced difficulties solving a puzzle.
In this part Roma fights w... | vfc_76773 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\nRL\nLR\n",
"output": "LOSE",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\nRR\nRR\n",
"output": "WIN",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
code_contests | verifiable_code | 1413_B. A New Technique | Solve the following coding problem using the programming language python:
All techniques in the ninja world consist of hand seals. At the moment Naruto is learning a new technique, which consists of n⋅ m different seals, denoted by distinct numbers. All of them were written in an n× m table.
The table is lost now. Na... | ```python
# Source: PyRival
import os
import sys
from io import BytesIO, IOBase
def main():
for _ in range(int(input())):
n, m = map(int, input().split())
row = []
col = []
for i in range(n):
row.append(list(map(int, input().split())))
for j in range(m):
... | vfc_76777 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 3\n6 5 4\n1 2 3\n1 6\n2 5\n3 4\n3 1\n2\n3\n1\n3 1 2\n",
"output": "1 2 3 \n6 5 4 \n3 \n1 \n2 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 3\n6 5 4\n1 2 3\n1 6\n2 4\n3 5\n3 1\... |
code_contests | verifiable_code | 1455_B. Jumps | Solve the following coding problem using the programming language python:
You are standing on the OX-axis at point 0 and you want to move to an integer point x > 0.
You can make several jumps. Suppose you're currently at point y (y may be negative) and jump for the k-th time. You can:
* either jump to the point y... | ```python
t = int(input())
for i in range(t):
n = int(input())
i=1
sum=0
cnt=0
while sum<n:
sum+=i
cnt+=1
i+=1
if sum==n or sum-n>1:
print(cnt)
else:
print(cnt+1)
``` | vfc_76785 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1\n2\n3\n4\n5\n",
"output": "\n1\n3\n2\n3\n4\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1479_C. Continuous City | Solve the following coding problem using the programming language python:
Some time ago Homer lived in a beautiful city. There were n blocks numbered from 1 to n and m directed roads between them. Each road had a positive length, and each road went from the block with the smaller index to the block with the larger ind... | ```python
import sys
input = sys.stdin.readline
l,r=map(int,input().split())
dif=r-l+1
print("YES")
n=2
while 2**(n-2)<dif:n+=1
edges=[]
for i in range(n-2):
for j in range(i+1,n-1):
if i==0:
edges.append([1,j+1,1])
else:
edges.append([i+1,j+1,2**(i-1)])
mx=l-1
i=1
if mx==0 o... | vfc_76789 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\n",
"output": "\nYES\n2 1\n1 2 1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1506_B. Partial Replacement | Solve the following coding problem using the programming language python:
You are given a number k and a string s of length n, consisting of the characters '.' and '*'. You want to replace some of the '*' characters with 'x' characters so that the following conditions are met:
* The first character '*' in the orig... | ```python
t = int(input())
for i in range(t):
n, k = map(int, input().split())
s = input()
index = s.find('*')
num = 1
last = s.rfind('*')
while index < last:
if s[index] == '*':
index += k
num += 1
else:
index -= 1
print(num)
``` | vfc_76793 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n7 3\n.**.***\n5 1\n..*..\n5 2\n*.*.*\n3 2\n*.*\n1 1\n*\n",
"output": "\n3\n1\n3\n2\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n7 3\n.**.***\n5 2\n..*..\n5 2\n*.*.*\n3 2\n*.*\n... |
code_contests | verifiable_code | 160_C. Find Pair | Solve the following coding problem using the programming language python:
You've got another problem dealing with arrays. Let's consider an arbitrary sequence containing n (not necessarily different) integers a1, a2, ..., an. We are interested in all possible pairs of numbers (ai, aj), (1 ≤ i, j ≤ n). In other words, ... | ```python
#import math
#from functools import lru_cache
#import heapq
#from collections import defaultdict
from collections import Counter
#from collections import deque
#from sys import stdout
#from sys import setrecursionlimit
#setrecursionlimit(10**7)
#from bisect import bisect_left
from sys import stdin
input = std... | vfc_76801 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 4\n2 1\n",
"output": "2 2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 17_E. Palisection | Solve the following coding problem using the programming language python:
In an English class Nick had nothing to do at all, and remembered about wonderful strings called palindromes. We should remind you that a string is called a palindrome if it can be read the same way both from left to right and from right to left... | vfc_76805 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 128000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nbabb\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\naa\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.