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 | p01872 My Number | Solve the following coding problem using the programming language python:
A: My Number-My Number-
problem
I'm sorry! Late late!
Ah! I'm starting to work for this company I've been longing for today!
Even so, I've been oversleeping since the first day ...! ??
Today is an important day when I have to tell my number... | ```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import array
def is_valid_number(sequence):
q = lambda n: (n + 1) if 1 <= n <= 6 else (n - 5)
sum_pq = 0
for index in range(1, 12):
sum_pq += sequence[index] * q(index)
rem_pq = sum_pq % 11
check_digit = 0 if rem_pq <= 1 else (11 - ... | vfc_72489 | {
"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": "?12345678901",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "?123456789/1",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
code_contests | verifiable_code | p02293 Parallel/Orthogonal | Solve the following coding problem using the programming language python:
For given two lines s1 and s2, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise.
s1 crosses points p0 and p1, and s2 crosses points p2 and p3.
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2... | ```python
import math
EPS = 1e-10
class Point():
def __init__(self, x, y):
self.x = x
self.y = y
def __add__(self, point):
# + 演算子での挙動を指定
return Point(self.x+point.x, self.y+point.y)
def __sub__(self, point):
# - 演算子での挙動を指定
return Point(self.x-point.x, sel... | vfc_72501 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n0 0 3 0 0 2 3 2\n0 0 3 0 1 1 1 4\n0 0 3 0 1 1 2 2",
"output": "2\n1\n0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n0 0 3 0 0 2 3 2\n0 0 3 0 1 1 1 7\n0 0 3 0 1 1 2 2",
"output... |
code_contests | verifiable_code | abacus05 | Solve the following coding problem using the programming language python:
Geek Sundaram is extremely anxious. He is in a hectic schedule. He has to study for his assessment the next day, watch FRIENDS tv show (in spite of watching every episode more than 5 times.. :P ), prepare questions for the programming contest an... | ```python
for _ in range(input()):
a=map(int,raw_input().split())
s=sum(a)-a[4]
print 'YES' if s<=a[4] else 'NO'
``` | vfc_72509 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n10 20 30 40 500\n1 2 3 4 5",
"output": "YES\nNO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n10 20 30 40 500\n1 2 0 4 5",
"output": "YES\nNO\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | cheflcm | Solve the following coding problem using the programming language python:
Chef wants to hire a new assistant. He published an advertisement regarding that in a newspaper. After seeing the advertisement, many candidates have applied for the job. Now chef wants to shortlist people for the interviews, so he gave all of t... | ```python
from math import *
def lcm(n):
x,c, t,f= 1,0,0,False
while (n%2 == 0):
c+=2**t
f = True
t+=1
n = n/2
if f == True:
x = c+2**t
i = 3
while i<=sqrt(n):
f = False
c = 0
t = 0
while (n%i == 0):
f = True
... | vfc_72513 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1\n2",
"output": "1\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1\n3",
"output": "1\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | dishown | Solve the following coding problem using the programming language python:
This summer, there is a worldwide competition being held in Chef Town and some of the best chefs of the world are participating. The rules of this competition are quite simple.
Each participant needs to bring his or her best dish. The judges w... | ```python
#!/usr/bin/env python
import sys
parent = None
#child = dict()
def find_set(x):
global parent
while parent[x] != x:
parent[x] = parent[parent[x]]
x = parent[x]
return parent[x]
T = int(sys.stdin.readline())
while T > 0:
N = int(sys.stdin.readline())
S = map(in... | vfc_72517 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2\n1 2\n2\n0 1 2\n1 1",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2\n1 3\n2\n0 1 2\n1 1",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | intest | Solve the following coding problem using the programming language python:
The purpose of this problem is to verify whether the method you are using to read input data is sufficiently fast to handle problems branded with the enormous Input/Output warning. You are expected to be able to process at least 2.5MB of input d... | ```python
# cook your code here
n,k=map(int,raw_input().split())
count=0
for i in range(0,n):
if (int(raw_input()))%k==0:
count+=1
print count
``` | vfc_72521 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 3\n1\n51\n966369\n7\n9\n999996\n11",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 3\n1\n34\n966369\n7\n9\n999996\n11",
"output": "3\n",
"type": "stdin_stdou... |
code_contests | verifiable_code | seagm2 | Solve the following coding problem using the programming language python:
Sereja is playing a game called Winner Eats Sandwich with his friends. There are N persons in total, including Sereja. Sereja is allotted the number 1, while his friends are allotted numbers from 2 to N. A set of this game consists of M parts. P... | ```python
from operator import mul
parse = lambda: [25*i for i in map(float, raw_input().split())]
for _ in xrange(int(raw_input())):
n, m = map(int, raw_input().split())
num = reduce(mul, parse())
den = num
for _ in xrange(n - 1):
den += reduce(mul, parse())
if num == 0:
den = 1
print '%.6f' % (num/den)
``... | vfc_72529 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 2\n1.0000 1.0000\n0.0000 0.0000\n2 3\n0.5000 0.5000 0.5000\n0.5000 0.5000 0.5000",
"output": "1.000000\n0.500000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 2\n1.0000 1.0000\... |
code_contests | verifiable_code | 1000_F. One Occurrence | Solve the following coding problem using the programming language python:
You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers l_i and r_i. For each query, you have to find any integer that occurs exactly once in the subarray of a from index l_i to index r_i (a ... | vfc_72533 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 768000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n1 1 2 3 2 4\n2\n2 6\n1 2\n",
"output": "4\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n5 9 6 4 8 7 4 9 7 6\n10\n4 9\n4 7\n4 7\n4 8\n9 10\n4 9\n4 8\n1 5\n4 4\n2 5\n",
"ou... | |
code_contests | verifiable_code | 1045_I. Palindrome Pairs | Solve the following coding problem using the programming language python:
After learning a lot about space exploration, a little girl named Ana wants to change the subject.
Ana is a girl who loves palindromes (string that can be read the same backwards as forward). She has learned how to check for a given string whet... | ```python
# Fast IO (only use in integer input)
import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
MOD1 = 100000007
MOD2 = 1000000007
evenStrDict = {}
oddStrDict = {}
cnt = 0
N = int(input())
for _ in range(N):
p = input()
countList = [0] * 26
for elem in p:
if elem < 97:
... | vfc_72541 | {
"difficulty": "15",
"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\naa\nbb\ncd\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\naab\nabcac\ndffe\ned\naa\naade\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 106_C. Buns | Solve the following coding problem using the programming language python:
Lavrenty, a baker, is going to make several buns with stuffings and sell them.
Lavrenty has n grams of dough as well as m different stuffing types. The stuffing types are numerated from 1 to m. Lavrenty knows that he has ai grams left of the i-... | ```python
from sys import stdin, setrecursionlimit
def arr_inp(n):
if n == 1:
return [int(x) for x in stdin.readline().split()]
elif n == 2:
return [float(x) for x in stdin.readline().split()]
else:
return list(stdin.readline()[:-1])
def dp(i, rem):
if rem == 0:
retur... | vfc_72545 | {
"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": "100 1 25 50\n15 5 20 10\n",
"output": "200",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 2 2 1\n7 3 2 100\n12 3 1 10\n",
"output": "241",
"type": "stdin_stdout"
},
{... |
code_contests | verifiable_code | 110_E. Lucky Tree | Solve the following coding problem using the programming language python:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya encountered... | ```python
from sys import stdin, stdout
import re
from random import randrange
from pprint import PrettyPrinter
pprint = PrettyPrinter(width=55).pprint
def is_lucky(num):
return re.fullmatch("[47]+", num) is not None
gr = None
def topo_order(u):
res = [(u, None, None)]
i = 0
while i < len(res):
... | vfc_72553 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 4\n1 3 47\n1 4 7447\n",
"output": "24",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 2 4\n3 1 2\n1 4 7\n",
"output": "16",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 113_B. Petr# | Solve the following coding problem using the programming language python:
Long ago, when Petya was a schoolboy, he was very much interested in the Petr# language grammar. During one lesson Petya got interested in the following question: how many different continuous substrings starting with the sbegin and ending with ... | ```python
from functools import cmp_to_key
def calc_lcp(s, sa):
rank = [0 for _ in range(len(s))]
for i in range(len(s)):
rank[sa[i]] = i
lcp = [0 for _ in range(len(s) - 1)]
h = 0
for i in range(len(s)):
if rank[i] < len(s) - 1:
while max(i, sa[rank[i] + 1]) + h < len(... | vfc_72557 | {
"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": "codeforces\ncode\nforca\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "abababab\na\nb\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name"... |
code_contests | verifiable_code | 1158_A. The Party and Sweets | Solve the following coding problem using the programming language python:
n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal... | ```python
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a.sort()
b.sort()
if a[-1] > b[0]:
print(-1)
exit()
if a[-1] == b[0]:
print(sum(b) + sum(a[:-1]) * m)
else:
print(sum(b) + a[-1] + sum(a[:-1]) * m - a[-2])
``` | vfc_72561 | {
"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 2\n1 2 1\n3 4\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n1 0\n1 1 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null... |
code_contests | verifiable_code | 117_E. Tree or not Tree | Solve the following coding problem using the programming language python:
You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off.
You are also given m queries represe... | vfc_72565 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 2\n4 6\n4 3\n1 2\n6 5\n1 5\n1 4\n2 5\n2 6\n",
"output": "4\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n2 1\n4 3\n2 4\n2 5\n4 1\n5 4\n1 5\n",
"output": "3\n3\n",
"... | |
code_contests | verifiable_code | 1198_F. GCD Groups 2 | Solve the following coding problem using the programming language python:
You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integ... | ```python
import sys
def gcd(l):
if len(l)==0:
return 0
if len(l)==1:
return l[0]
if len(l)==2:
if l[1]==0:
return l[0]
return gcd([l[1],l[0]%l[1]])
return gcd([gcd(l[:-1]),l[-1]])
def brute_force(l1,l2,l,sol):
if len(l)==0:
g1=gcd(l1)
g2=g... | vfc_72569 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n6 15 35 77 22\n",
"output": "YES\n2 1 2 2 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n6 10 15 1000 75\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 1215_E. Marbles | Solve the following coding problem using the programming language python:
Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only o... | ```python
import sys
n = int(sys.stdin.readline().strip())
a = list(map(int, sys.stdin.readline().strip().split()))
M = [[0 for i in range (0, 21)] for j in range (0, 21)]
F = [0 for i in range (0, 21)]
for i in range (0, n):
x = int(a[i])
for j in range (0, 21):
if j != x:
M[j][x] = M[j][x... | vfc_72573 | {
"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": "7\n3 4 2 3 4 2 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13\n5 5 4 4 3 5 7 6 5 4 4 6 5\n",
"output": "21\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1238_G. Adilbek and the Watering System | Solve the following coding problem using the programming language python:
Adilbek has to water his garden. He is going to do it with the help of a complex watering system: he only has to deliver water to it, and the mechanisms will do all the remaining job.
The watering system consumes one liter of water per minute (... | vfc_72577 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 5 4 2\n2 4 2\n0 4 5 4\n2 5 3 1\n1 2 4\n3 1 3\n2 3 5 1\n2 1 1\n1 4 3\n",
"output": "6\n0\n-1\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n5 4 3 1\n3 3 2\n2 1 3\n1 1 5\n1 1 4\... | |
code_contests | verifiable_code | 1257_B. Magic Stick | Solve the following coding problem using the programming language python:
Recently Petya walked in the forest and found a magic stick.
Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer:
1. If the... | ```python
t=int(input())
s=[]
a=[1,2,3]
for jngg in range(0,t):
x=input()
xx=x.split( )
x=int(xx[0])
y=int(xx[1])
if x==y:
s.append('yes')
elif x in a and y in a and x!=1:
s.append('yes')
elif x in a and y not in a:
s.append('no')
elif x==1:
s.append('no')... | vfc_72581 | {
"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\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234\n",
"output": "Yes\nYes\nNo\nYes\nNo\nYes\nYes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1000 23222\n",
"output": "Yes\n",
... |
code_contests | verifiable_code | 1280_C. Jeremy Bearimy | Solve the following coding problem using the programming language python:
Welcome! Everything is fine.
You have arrived in The Medium Place, the place between The Good Place and The Bad Place. You are assigned a task that will either make people happier or torture them for eternity.
You have a list of k pairs of peo... | ```python
import sys
input = sys.stdin.buffer.readline
for T in range(int(input())):
k = int(input())
counts = [0] * (2 * k + 1)
adjacencies = [list() for i in range(2 * k + 1)]
for _ in range(2 * k - 1):
a, b, weight = map(int, input().split())
counts[a] += 1; counts[b] += 1
ad... | vfc_72585 | {
"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": "2\n3\n1 2 3\n3 2 4\n2 4 3\n4 5 6\n5 6 5\n2\n1 2 1\n1 3 2\n1 4 3\n",
"output": "15 33\n6 6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1\n2 1 4\n",
"output": "4 4\n",
"ty... |
code_contests | verifiable_code | 1324_C. Frog Jumps | Solve the following coding problem using the programming language python:
There is a frog staying to the left of the string s = s_1 s_2 … s_n consisting of n characters (to be more precise, the frog initially stays at the cell 0). Each character of s is either 'L' or 'R'. It means that if the frog is staying at the i-... | ```python
for i in range(int(input())):
print(max(map(len,input().split("R")))+1)
``` | vfc_72593 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\nLRLRRLL\nL\nLLR\nRRRR\nLLLLLL\nR\n",
"output": "3\n2\n3\n1\n7\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\nRRLRLLL\nL\nLLR\nRRRR\nLLLLLL\nR\n",
"output": "4\n2\n3\n1\n7\n... |
code_contests | verifiable_code | 1385_C. Make It Good | Solve the following coding problem using the programming language python:
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarr... | ```python
t = int(input())
for _ in range(t):
n = int(input())
a = list(int(x) for x in input().split())
start = 0
end = n-1
while end>0 and a[end]<=a[end-1]:
end-=1
start=end
while start>0 and a[start]>=a[start-1]:
start-=1
print(start)
``` | vfc_72605 | {
"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": "5\n4\n1 2 3 4\n7\n4 3 3 8 4 5 2\n3\n1 1 1\n7\n1 3 1 4 5 3 2\n5\n5 4 3 2 3\n",
"output": "0\n4\n0\n2\n3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1427_G. One Billion Shades of Grey | Solve the following coding problem using the programming language python:
You have to paint with shades of grey the tiles of an n× n wall. The wall has n rows of tiles, each with n tiles.
The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you... | vfc_72613 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n315055237 841510063 581663979 148389224 405375301 243686840 882512379\n683199716 -1 -1 0 0 0 346177625\n496442279 0 0 0 0 0 815993623\n223938231 0 0 -1 0 0 16170511\n44132173 0 -1 0 0 0 130735659\n212201259 0 0 -1 0 0 166102576\... | |
code_contests | verifiable_code | 1474_E. What Is It? | Solve the following coding problem using the programming language python:
Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i).
Unfo... | ```python
def main():
n=int(*input().split())
L=[x for x in range(n+1)];ans=[]
def swp(x,y):
L[x],L[y]=L[y],L[x]
swp(1,n);ans.append((1,n))
for i in range(2,(n+1)//2+1):
swp(i,n);ans.append((i,n))
if not n-i+1==i: swp(n-i+1,1);ans.append((n-i+1,1))
val=sum((i-j)*(i-j) for i,j in ans)
print(val)
for x... | vfc_72621 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n3\n3\n",
"output": "\n1\n2 1\n1\n2 1\n5\n2 3 1\n2\n1 3\n3 2\n5\n2 3 1\n2\n1 3\n2 3",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 14_B. Young Photographer | Solve the following coding problem using the programming language python:
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not... | ```python
#***************14B - Young Photographer***************#
#author - @Divyesh Chhabra
from math import *
import os
import random
import re
import sys
from itertools import *
n,a = map(int,input().split())
sp = []
xp = []
yp = []
f = 1
while n != 0:
x,y = map(int,input().split())
if x>y:
x,y = ... | vfc_72625 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n0 7\n14 2\n4 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20 1\n35 8\n40 6\n49 5\n48 18\n46 16\n45 16\n44 10\n16 44\n8 46\n2 45\n38 3\n42 1\n13 35\n35 18\n12 33\... |
code_contests | verifiable_code | 1523_G. Try Booking | Solve the following coding problem using the programming language python:
<image>
William owns a flat in central London. He decided to rent his flat out for the next n days to earn some money.
Since his flat is in the center of the city, he instantly got m offers in the form (l_i, r_i), which means that someone want... | vfc_72629 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 5\n2 3\n3 5\n1 1\n1 5\n1 6\n",
"output": "\n3\n2\n3\n5\n5\n6\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 156_A. Message | Solve the following coding problem using the programming language python:
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s.
String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "... | ```python
from sys import stdin, stdout
first, second = stdin.readline().strip(), stdin.readline().strip()
n, m = len(first), len(second)
first = '#' * m + first + '#' * m
ans = float('inf')
for i in range(n + m):
cnt = 0
for j in range(m):
if first[i + j] != second[j]:
cnt += 1
... | vfc_72633 | {
"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": "abcdef\nklmnopq\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "aaaaa\naaa\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 177_E2. Space Voyage | Solve the following coding problem using the programming language python:
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is th... | ```python
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
def check(a,b,tar,x):
ans = 0
for i in range(len(a)):
ans += (a[i]*x)//b[i]
if ans == tar:
return 0
elif ans > tar:
return 1
else:
return -1
def main()... | vfc_72637 | {
"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 5\n1 5\n2 4\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1000000000\n1 1000000000\n",
"output": "1000000000",
"type": "stdin_stdout"
},
{
"f... |
code_contests | verifiable_code | 199_B. Special Olympics | Solve the following coding problem using the programming language python:
A renowned abstract artist Sasha, drawing inspiration from nowhere, decided to paint a picture entitled "Special Olympics". He justly thought that, if the regular Olympic games have five rings, then the Special ones will do with exactly two ring... | ```python
import os
import sys
from io import BytesIO, IOBase
from collections import Counter
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_72641 | {
"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": "50 50 35 45\n90 50 35 45\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "60 60 45 55\n80 60 15 25\n",
"output": "4",
"type": "stdin_stdout"
},
{
"f... |
code_contests | verifiable_code | 222_C. Reducing Fractions | Solve the following coding problem using the programming language python:
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from t... | ```python
from collections import defaultdict
import bisect
from itertools import accumulate
import os
import sys
import math
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
se... | vfc_72645 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n2 5 10 20\n100 1 3\n",
"output": "4 3\n1 1 1 20 \n1 1 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n100 5 2\n50 10\n",
"output": "3 2\n1 1 2 \n1 1 ",
"type": "stdi... |
code_contests | verifiable_code | 246_A. Buggy Sorting | Solve the following coding problem using the programming language python:
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The ... | ```python
def s(a):
k = len(a)
for i in range(k-1):
for j in range(i,k-1):
if a[j] > a[j+1]:
a[j],a[j+1] = a[j+1],a[j]
return a
def main():
n = int(input())
if n <= 2:
v = [-1]
else:
v = [int(i) for i in range(n,0,-1)]
print(*v,sep = ' ')
i... | vfc_72649 | {
"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": "1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 271_B. Prime Matrix | Solve the following coding problem using the programming language python:
You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of t... | ```python
# coding: utf-8
matrix_params = input()
params = matrix_params.split(" ")
rows = int(params[0])
cols = int(params[1])
initial_matrix = []
count_r = []
count_c = []
curr_row = []
def is_prime(n):
if n <= 3:
return n > 1
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i ** 2 <= n:
if... | vfc_72653 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n1 2 3\n5 6 1\n4 4 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n1 3\n4 2\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 294_D. Shaass and Painter Robot | Solve the following coding problem using the programming language python:
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, whi... | ```python
__author__ = 'sergio'
def sg(p):
if p == 0:
return -1
else:
return 1
def minim(w,h):
if w < h:
return (w,0)
else:
return (h,1)
def find_path(x, y, down, right):
global size_n
global size_m
if down == 1:
h = size_n - x
else:
... | vfc_72657 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n1 1 DR\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n1 1 DR\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 318_B. Strings of Power | Solve the following coding problem using the programming language python:
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style.
Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Findin... | ```python
from functools import reduce
from operator import *
from math import *
from sys import *
from string import *
from collections import *
setrecursionlimit(10**7)
dX= [-1, 1, 0, 0,-1, 1,-1, 1]
dY= [ 0, 0,-1, 1, 1,-1,-1, 1]
RI=lambda: list(map(int,input().split()))
RS=lambda: input().rstrip().split()
###########... | vfc_72661 | {
"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": "heavymetalisheavymetal\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "trueheavymetalissotruewellitisalsosoheavythatyoucanalmostfeeltheweightofmetalonyou\n",
"output... |
code_contests | verifiable_code | 342_B. Xenia and Spies | Solve the following coding problem using the programming language python:
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right.
Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in seve... | ```python
R = lambda: map(int, input().split())
n, m, s, f = R()
if s < f:
d = 1
c = 'R'
else:
d = -1
c = 'L'
res = ""
i = 1
j = s
t, l, r = R()
k = 1
while j != f:
if i > t and k < m:
t, l, r = R()
k += 1
if i == t and (l <= j <= r or l <= j + d <= r):
res += 'X'
else... | vfc_72665 | {
"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 5 1 3\n1 1 2\n2 2 3\n3 3 3\n4 1 1\n10 1 3\n",
"output": "XXRR",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20 20 17 20\n1 16 20\n2 12 13\n3 14 16\n4 13 15\n5 3 15\n6 2 11\n7 18 18\n8 5 ... |
code_contests | verifiable_code | 365_D. Free Market | Solve the following coding problem using the programming language python:
John Doe has recently found a "Free Market" in his city — that is the place where you can exchange some of your possessions for other things for free.
John knows that his city has n items in total (each item is unique). You can bring any numbe... | vfc_72669 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n1 3 10\n",
"output": "4 3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 10000\n10000 9999 1 10000 10000 10000 1 2 3 4\n",
"output": "50010 6",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | 389_C. Fox and Box Accumulation | Solve the following coding problem using the programming language python:
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ci... | ```python
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt'... | vfc_72673 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n0 0 10\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 0 0 0\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inp... |
code_contests | verifiable_code | 409_F. 000001 | Solve the following coding problem using the programming language python:
Input
The input contains a single integer a (1 ≤ a ≤ 64).
Output
Output a single integer.
Examples
Input
2
Output
1
Input
4
Output
2
Input
27
Output
5
Input
42
Output
6
The input will be given via stdin and the outp... | ```python
print([0,1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51,1,2,1,14,1,2,2,14,1,6,1,4,2,2,1,52,2,5,1,5,1,15,2,13,2,2,1,13,1,2,4,267,1,4,1,5,1,4,1,50,1,2,3,4,1,6,1,52,15,2,1,15,1][int(input())])
``` | vfc_72677 | {
"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": "27\n",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 437_A. The Child and Homework | Solve the following coding problem using the programming language python:
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correc... | ```python
a = input()[2:]
b = input()[2:]
c = input()[2:]
d = input()[2:]
zc = 0
z = -100
if (len(a)*2 <= len(b) and len(a)*2 <= len(c) and len(a)*2 <= len(d)) or (len(a) >= len(b)*2 and len(a) >= len(c)*2 and len(a) >= len(d)*2):
zc += 1
z = 'A'
if (len(b)*2 <= len(a) and len(b)*2 <= len(c) and len(b)*2 <= ... | vfc_72681 | {
"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": "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n",
"output": "D",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 45_C. Dancing Lessons | Solve the following coding problem using the programming language python:
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the followi... | ```python
from heapq import heapify,heappush,heappop
n = int(input())
sex = input()
a = [int(i) for i in input().split()]
cp = []
r = []
b = sex.count('B')
N = min(n-b,b)
for i in range(1,len(a)):
if sex[i] != sex[i-1]:
cp.append((abs(a[i]-a[i-1]),i-1,i))
heapify(cp)
prev = [i for i in range(-1,len(sex))]
... | vfc_72685 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nBGBG\n4 2 4 3\n",
"output": "2\n3 4\n1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\nBGBB\n1 1 2 3\n",
"output": "1\n1 2\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 482_B. Interesting Array | Solve the following coding problem using the programming language python:
We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value <image> should be equal to qi. ... | ```python
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
a = []
for _ in range(m):
l, r, q = map(int, input().split())
l -= 1
r -= 1
a.append((l, r, q))
res = [0] * n
bad = False
for i in range(30):
events = [0] * (n + 1)
for l, r, q in a:
if q & (1 << i):
... | vfc_72689 | {
"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 1\n1 3 3\n",
"output": "YES\n3 3 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n1 3 3\n1 3 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name":... |
code_contests | verifiable_code | 506_B. Mr. Kitayuta's Technology | Solve the following coding problem using the programming language python:
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n.
Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two... | ```python
def main():
n, m = map(int, input().split())
n += 1
cluster, dest, avail, ab = list(range(n)), [0] * n, [True] * n, [[] for _ in range(n)]
def getroot(x):
while x != cluster[x]:
x = cluster[x]
return x
def setroot(x, r):
if r < x != cluster[x]:
... | vfc_72693 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 6\n1 2\n1 4\n2 3\n2 4\n3 2\n3 4\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 52_A. 123-sequence | Solve the following coding problem using the programming language python:
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.
Input
The first line... | ```python
from collections import deque
from math import ceil,floor,sqrt,gcd
def ii(): return int(input())
def mi(): return map(int,input().split())
def li(): return list(mi())
def si():return input()
n=ii()
a=li()
m={}
for i in a:
if i not in m:
m[i]=1
else:
m[i]+=1
b=[]
for i in m.keys():
... | vfc_72697 | {
"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": "9\n1 3 2 2 2 1 1 2 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 581_B. Luxurious Houses | Solve the following coding problem using the programming language python:
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row.
Let's enumerate all the houses from left to right, starting with one. A house is considered to... | ```python
n = int(input())
hs = list(map(int, input().split()))
maxx = 0
ans = []
for h in reversed(hs):
if h > maxx:
ans.append(0)
else:
ans.append(maxx-h+1)
maxx = max(maxx, h)
print(' '.join(map(str, reversed(ans))))
``` | vfc_72705 | {
"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 2 3 1 2\n",
"output": " 3 2 0 2 ... |
code_contests | verifiable_code | 603_A. Alternative Thinking | Solve the following coding problem using the programming language python:
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad... | ```python
input()
a = input()
s = []
for c in a:
if not s or s[-1][0] != c:
s.append([c, 1])
else:
s[-1][1] += 1
s2 = sorted(s, key=lambda x: x[1])
delta = 0
if s2[-1][1] >= 3 or len(s2) > 1 and s2[-2][1] >= 2:
delta = 2
elif s2[-1][1] >= 2:
delta = 1
print(len(s) + delta)
``` | vfc_72709 | {
"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": "2\n01\n",
"output": "2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 625_D. Finals in arithmetic | Solve the following coding problem using the programming language python:
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder.
L... | ```python
def digits(n):
rd = []
while n:
n, d = divmod(n, 10)
rd.append(d)
return list(reversed(rd))
def _ifs(dn, i, j, ci, cj, al, ar):
while i < j:
di = dn[i] + 10*ci
dj = dn[j] - cj
for (ci, cj) in ((0, 0), (0, 1), (1, 0), (1, 1)):
d = di - ci
... | vfc_72713 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "11\n",
"output": "10\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 64_F. Domain | Solve the following coding problem using the programming language python:
This problem doesn't contain real-world specifications about domains, just use the problem statement as a formal document to solve the problem.
The given string s is a domain name if it contains the characters "a"-"z", "0"-"9" and dots. No two ... | vfc_72717 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "codeforces.com\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "mail.v-kontakte.ru\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 673_F. Bearish Fanpages | Solve the following coding problem using the programming language python:
There is a social website with n fanpages, numbered 1 through n. There are also n companies, and the i-th company owns the i-th fanpage.
Recently, the website created a feature called following. Each fanpage must choose exactly one other fanpag... | vfc_72721 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 12\n10 20 30 40 50\n2 3 4 5 2\n2 1\n2 2\n2 3\n2 4\n2 5\n1 4 2\n2 1\n2 2\n2 3\n2 4\n2 5\n3\n",
"output": "10\n36\n28\n40\n36\n9\n57\n27\n28\n29\n9 57\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
code_contests | verifiable_code | 699_A. Launch of Collider | Solve the following coding problem using the programming language python:
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located ... | ```python
import sys
def main(arr):
curr = None
m = float("inf")
for d, pos in arr:
if d == 'L':
if curr is not None:
m = min(m, pos - curr)
elif d == 'R':
curr = pos
print(m // 2 if m != float("inf") else -1)
if __name__ == "__main__":
arr =... | vfc_72725 | {
"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\nRLRL\n2 4 6 10\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nLLR\n40 50 60\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | 71_C. Round Table Knights | Solve the following coding problem using the programming language python:
There are n knights sitting at the Round Table at an equal distance from each other. Each of them is either in a good or in a bad mood.
Merlin, the wizard predicted to King Arthur that the next month will turn out to be particularly fortunate i... | ```python
def gen_prime(n):
prime = []
prime.append(2)
prime.append(3)
prime.append(4)
for i in range(5, n+1):
div = False
for j in prime:
if not i%j:
div = True
break
if not div:
prime.append(i)
return prime
n = int(input())
prime = gen_prime(n)
prime = prime[1:]
prime.append(n)
a = [int(... | vfc_72729 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n1 0 0 1 0 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1 0 1 1 1 0\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 740_E. Alyona and towers | Solve the following coding problem using the programming language python:
Alyona has built n towers by putting small cubes some on the top of others. Each cube has size 1 × 1 × 1. A tower is a non-zero amount of cubes standing on the top of each other. The towers are next to each other, forming a row.
Sometimes Alyon... | vfc_72733 | {
"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\n5 5 5 5 5\n3\n1 3 2\n2 2 1\n4 4 1\n",
"output": "2\n4\n5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 2 3 1\n30\n3 3 1000000000\n3 3 1000000000\n3 3 1000000000\n3 3 1000000000\n... | |
code_contests | verifiable_code | 764_D. Timofey and rectangles | Solve the following coding problem using the programming language python:
One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they... | ```python
'''plan
noticed that if both upperle
'''
from sys import stdin, stdout
# n = int(stdin.readline().rstrip())
# n = int(input())
all_lines = stdin.read().split('\n')
stdout.write('YES\n')
for line in all_lines[1:-1]:
x1, y1, x2, y2 = (int(x) % 2 for x in line.split())
num = 2 * x2 + y2 + 1
# st... | vfc_72737 | {
"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": "8\n0 0 5 3\n2 -1 5 0\n-3 -4 2 -1\n-1 -1 2 0\n-3 0 0 5\n5 2 10 3\n7 -3 10 2\n4 -2 7 -1\n",
"output": "YES\n1\n2\n3\n4\n3\n3\n4\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n0 0 1 1\... |
code_contests | verifiable_code | 788_A. Functions again | Solve the following coding problem using the programming language python:
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried a... | ```python
n=int(input())
l=list(map(int,input().split()))
ma=0
p1=0
p2=0
for i in range(n-1) :
if (i+1)%2!=0 :
p1=p1+abs(l[i]-l[i+1])
p2=p2-abs(l[i]-l[i+1])
if p2<0 :
p2=0
ma=max(p1,ma)
else :
p2=p2+abs(l[i]-l[i+1])
p1=p1-abs(l[i]-l[i+1])
if p1... | vfc_72741 | {
"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\n1 4 2 3 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 5 4 7\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 809_C. Find a car | Solve the following coding problem using the programming language python:
After a wonderful evening in the restaurant the time to go home came. Leha as a true gentlemen suggested Noora to give her a lift. Certainly the girl agreed with pleasure. Suddenly one problem appeared: Leha cannot find his car on a huge parking... | ```python
mod = 1000000007
def sum(x,y,k,add) :
if k<add:return 0
up=x+add
if up>k:up=k
add=add+1
return y*(((add+up)*(up-add+1)//2)%mod)%mod
def solve(x,y,k,add=0) :
if x==0 or y==0:return 0
if x>y:x,y=y,x
pw = 1
while (pw<<1)<=y:pw<<=1
if pw<=x:return (sum(pw,pw,k,add)+sum(pw,x... | vfc_72745 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 1 1 1 1\n3 2 5 4 5\n1 1 5 5 10000\n1 4 2 5 2\n",
"output": "1\n13\n93\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n1 1 1000000000 1000000000 1477070720\n1 1 1000000000 10000... |
code_contests | verifiable_code | 834_A. The Useless Toy | Solve the following coding problem using the programming language python:
<image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange con... | ```python
a, b = input().split()
t = int(input())
d = dict()
d["^"] = 0
d[">"] = 1
d["v"] = 2
d["<"] = 3
a, b = d[a], d[b]
t = t % 4
if t == 2 or t == 0:
print("undefined")
else:
if t == 1:
if (b-1) % 4 == a:
print("CW".lower())
else:
print("CCW".lower())
elif t ==... | vfc_72749 | {
"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": "^ v\n6\n",
"output": "undefined\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "^ >\n1\n",
"output": "undefined\n",
"type": "stdin_stdout"
},
{
"fn_name": null... |
code_contests | verifiable_code | 854_D. Jury Meeting | Solve the following coding problem using the programming language python:
Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the problem preparation process.
There are n + 1 cities consecutive... | ```python
R=lambda :map(int,input().split())
n,m,k=R()
F,T=[],[]
ans=int(1e12)
for i in range(m):
d,f,t,c=R()
if f:F.append((d,f,c))
else:T.append((-d,t,c))
for p in [F,T]:
cost=[ans]*(n+1)
s=n*ans
q=[]
p.sort()
for d,t,c in p:
#print(p)
if c<cost[t]:
#print(c... | vfc_72753 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 4 5\n1 2 0 5000\n2 1 0 4500\n2 1 0 3000\n8 0 1 6000\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 6 5\n1 1 0 5000\n3 2 0 5500\n2 2 0 6000\n15 0 2 9000\n9 0 1 7000\n8 ... |
code_contests | verifiable_code | 879_B. Table Tennis | Solve the following coding problem using the programming language python:
n people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someon... | ```python
n,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
d=a[0]
t=0
h=0
for i in range(1,n):
if d>a[i]:
t+=1
if t>=k:
print(d)
h=1
break
else:
t=1
d=a[i]
if h==0:
print(max(a))
``` | vfc_72757 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 10000000000\n2 1\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 2\n6 5 3 1 2 4\n",
"output": "6",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | 902_D. GCD of Polynomials | Solve the following coding problem using the programming language python:
Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <imag... | ```python
class polynomial:
def __init__(self, data):
self.data = data
def __lshift__(self, x):
return polynomial([0] * x + self.data)
def __len__(self):
return len(self.data)
def __sub__(self, other):
newData = [y - x for y, x in zip(self.data, other.data ... | vfc_72761 | {
"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\n",
"output": "2\n1 0 1 \n1\n0 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "1\n0 1 \n0\n1 \n",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | 924_F. Minimal Subset Difference | Solve the following coding problem using the programming language python:
We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of d... | vfc_72765 | {
"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": "10\n1 1000 0\n1 1000 1\n1 1000 2\n1 1000 3\n1 1000 4\n1 1000 5\n1 1000 6\n1 1000 7\n1 1000 8\n1 1000 9\n",
"output": " 135\n ... | |
code_contests | verifiable_code | 954_A. Diagonal Walking | Solve the following coding problem using the programming language python:
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by chara... | ```python
n = int(input())
s = str(input())
l = len(s)
prev = '';
for i in s:
if prev=='':
prev = i
continue
if (i=='U' and prev =='R') or (i=='R' and prev =='U'):
l=l-1
prev = ''
else:
prev = i
print(l)
``` | vfc_72769 | {
"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": "17\nUUURRRRRUUURURUUU\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nRUURU\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 97_E. Leaders | Solve the following coding problem using the programming language python:
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to ... | vfc_72773 | {
"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": "7 7\n1 3\n1 4\n2 3\n2 4\n5 6\n6 7\n7 5\n8\n1 2\n1 3\n1 4\n2 4\n1 5\n5 6\n5 7\n6 7\n",
"output": "No\nYes\nYes\nYes\nNo\nYes\nYes\nYes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n1... | |
code_contests | verifiable_code | 99_E. Help Greg the Dwarf | Solve the following coding problem using the programming language python:
A very unusual citizen lives in a far away kingdom — Dwarf Gracula. However, his unusual name is not the weirdest thing (besides, everyone long ago got used to calling him simply Dwarf Greg). What is special about Dwarf Greg — he's been living f... | ```python
EPS = 1e-8
def cross(a, b):
return (a[0] * b[1]) - (a[1] * b[0])
def f(a, b, l, x):
y = (l*l - x*x)**0.5
return cross( (a-x, b), (-x, y) )
def main():
a, b, l = map(int, raw_input().split())
if a > b:
a, b = b, a
if l <= a and a <= b:
print "%.9lf" % l
elif a <... | vfc_72777 | {
"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 2 6\n",
"output": "My poor head =(\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2 2\n",
"output": "2.000000000000000\n",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | benny-and-two-strings-2 | Solve the following coding problem using the programming language python:
Benny is given two strings S and T. The length of the string S is N and the length of the string T is M respectively.
Also, imagine that alphabets are cyclic in nature: a-b-c-…-x-y-z-a-b.. and so on. The distance between two letters is the min... | ```python
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import sys, math, random, operator
from string import ascii_lowercase
from string import ascii_uppercase
from fractions import Fraction, gcd
from decimal import Decimal, getcontext
from itertools import product, permutations, combinations
from Queue import Queue, P... | vfc_72781 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5 3\naba\nzbzbz\n\nSAMPLE",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "35 106 401\nhegghdhehhfjhbhhakkkfgbmrfotpflicgg\nfirkfcbishdehfjbhffedhlargbkhffilgaalfeijffxhgchct... |
code_contests | verifiable_code | comrades-ii-6 | Solve the following coding problem using the programming language python:
It’s the year 2552, the Humans just won a war against a very powerful alien race that had invaded our solar system. The Human army is in celebration mode!
The army has n soldiers. The soldiers are numbers from 1 to n. The army has a superiorit... | ```python
from collections import deque
def calculate(tree):
queue = deque(tree[0])
handshakes = fistpumps = nodes = level = 0
while queue:
for _ in xrange(len(queue)):
root = queue.popleft()
handshakes += level
fistpumps += nodes - level
nodes += 1
queue.extend(tree[root])
level += 1
return han... | vfc_72785 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n0 1 1\n2\n2 0\n\nSAMPLE",
"output": "2 1\n1 0",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | find-handi-bhaiya | Solve the following coding problem using the programming language python:
ACT I
Handi Bhaiya is a very notorious kid and always troubles his parents and friends. One day his naughtiness lead him to a demon Kali(THE COBRA COMMANDER) who trapped him into a triangular magic cell. Handi Bhaiya parents want their kid back ... | ```python
t = int(raw_input())
for _ in range(t):
l = []
l = map(int, raw_input().split())
if l[0]+l[1]>l[2] and l[1]+l[2]>l[0] and l[2]+l[0]>l[1]:
if l[0]==l[1] and l[1]==l[2]:
print 'YES. It is a equilateral triangle.'
elif l[0]==l[1] or l[1]==l[2] or l[2]==l[0]:
pr... | vfc_72789 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n15 15 15\n13 13 14\n3 4 5\n10 12 23\n\nSAMPLE",
"output": "YES. It is a equilateral triangle.\nYES. It is a isosceles triangle.\nYES. It is a scalene triangle.\nNO",
"type": "stdin_stdout"
},
{
"fn_name... |
code_contests | verifiable_code | imagination-game-easy-contest | Solve the following coding problem using the programming language python:
Two players are playing with N-dimensional rectangular with sizes of its sides (a1, a2, ... aN). (Let's call this rectangular as "cube"). Initially there is one cell marked with coordinates (x1, x2, ... xN).
On his/her turn a player should d... | ```python
#!/usr/bin/env python
from sys import stdin
def main():
TC = int(stdin.readline().strip())
for tc in xrange(TC):
N = int(stdin.readline().strip())
A = map(int, stdin.readline().split())
X = map(int, stdin.readline().split())
nims = [0] * (2*N)
for i in xrange(N):
... | vfc_72793 | {
"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\n2 2\n1 1\n2\n2 3\n1 2\n\n\nSAMPLE",
"output": "Second\nFirst",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | nutcracker | Solve the following coding problem using the programming language python:
Bruce and Diana love to eat peanuts. Diana is currently at Bruce’s mansion to watch a superhero movie when they decide to play a game. Bruce has N number of peanuts in a jar. The rules are simple. In each turn, a player can eat either one or fou... | ```python
for _ in range(input()):
n = input()
s = n % 5
if s == 1 or s== 3 or s == 4:
print "Yes"
else:
print "No"
``` | vfc_72801 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1\n5\n6\n\nSAMPLE",
"output": "Yes\nNo\nYes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "470\n5841\n1085\n8583\n1871\n2315\n4449\n7131\n6525\n2404\n2451\n3448\n1256\n1206\n9361\n3236... |
code_contests | verifiable_code | rajasthans-bawri | Solve the following coding problem using the programming language python:
Bawris, are wells or ponds in which the water may be reached by descending a set of steps. They may be covered and protected and are often of architectural significance.
Rajasthan has a history of maintaining bawris, but now they are of archit... | ```python
for _ in xrange(input()):
a,b,c,d=map(int,raw_input().split())
e=[a,b]
f=[c,d]
e.sort()
f.sort()
if e[0]>=f[0] and e[1]>=f[1]:print "Possible"
else:print "Not Possible"
``` | vfc_72805 | {
"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 7 4 7\n5 2 3 1\n9 2 7 1\n\nSAMPLE",
"output": "Not Possible\nPossible\nPossible\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 7 4 7\n5 2 3 1\n9 0 7 1\n\nSAMPLE",
"output"... |
code_contests | verifiable_code | shortest-way | Solve the following coding problem using the programming language python:
See Russian Translation
The statement of this problem is quite short , apt and clear. We don't want any coder to spend time in reading a lengthy, boring story that has no connection with the actual problem.
The problem states:
Given a pair (... | ```python
test_cases=int(raw_input())
for ite in range(test_cases):
given_pair=[int(i) for i in raw_input().split()]
num_operations=0
while given_pair!=[1,1] and given_pair!=[1,0] and given_pair!=[0,1]:
if given_pair[0]>given_pair[1]:
num_operations+=given_pair[0]//given_pair[1]
given_pair[0]%=given_pair[1]
... | vfc_72809 | {
"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\n5 2\n\nSAMPLE",
"output": "0\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n36 316049483082136289\n752278442523506295 52\n4052739537881 6557470319842\n44945570212853 72723... |
code_contests | verifiable_code | the-savior-3 | Solve the following coding problem using the programming language python:
Fatal Eagle is trying his best to save his city, but he's failing to do so. He knows he needs some external help; some guidance, something... something out of ordinary to defeat this powerful enemy called Mr. XYZ.
"Find out the number of pairs i... | ```python
T=int(raw_input());
for i in range(T):
N=int(raw_input());
li=map(int,raw_input().split());
count=0;
for i in range(len(li)):
for j in range(i,len(li)-1):
if((li[i]+li[j+1])%2==0 and li[i]!=li[j+1]):
count+=1;
print count;
``` | vfc_72813 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2\n1 1\n4\n1 2 3 4\n4\n2 4 6 8\n3\n1 3 3\n\nSAMPLE",
"output": "0\n2\n6\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "30\n441\n55 33 26 69 20 22 70 84 82 74 32 41 12 39 55 87 37 46... |
code_contests | verifiable_code | p00605 Vampirish Night | Solve the following coding problem using the programming language python:
There is a vampire family of N members. Vampires are also known as extreme gourmets. Of course vampires' foods are human blood. However, not all kinds of blood is acceptable for them. Vampires drink blood that K blood types of ones are mixed, an... | ```python
while True:
n, k = map(int, input().split())
if n == 0:
break
s_list = list(map(int, input().split()))
for _ in range(n):
b_list = list(map(int, input().split()))
for i in range(k):
s_list[i] -= b_list[i]
for s in s_list:
if s < 0:
print("No")
break
else:
pri... | vfc_72873 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3\n5 4 5\n1 2 3\n3 2 1\n3 5\n1 2 3 4 5\n0 1 0 1 2\n0 1 1 2 2\n1 0 3 1 1\n0 0",
"output": "Yes\nNo",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n5 4 5\n1 2 3\n3 2 1\n3 5\n1 2 3 4 5\n... |
code_contests | verifiable_code | p00742 Verbal Arithmetic | Solve the following coding problem using the programming language python:
Let's think about verbal arithmetic.
The material of this puzzle is a summation of non-negative integers represented in a decimal format, for example, as follows.
905 + 125 = 1030
In verbal arithmetic, every digit appearing in the equation... | vfc_72877 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 10, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nACM\nIBM\nICPC\n3\nGAME\nBEST\nGAMER\n4\nA\nB\nC\nAB\n3\nA\nB\nCD\n3\nONE\nTWO\nTHREE\n3\nTWO\nTHREE\nFIVE\n3\nMOV\nPOP\nDIV\n9\nA\nB\nC\nD\nE\nF\nG\nH\nIJ\n0",
"output": "4\n1\n8\n30\n0\n0\n0\n40320",
"type": "stdin... | |
code_contests | verifiable_code | p00881 Twenty Questions | Solve the following coding problem using the programming language python:
Consider a closed world and a set of features that are defined for all the objects in the world. Each feature can be answered with "yes" or "no". Using those features, we can identify any object from the rest of the objects in the world. In othe... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in ... | vfc_72881 | {
"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": "8 1\n11010101\n11 4\n00111001100\n01001101011\n01010000011\n01100110001\n11 16\n01000101111\n01011000000\n01011111001\n01101101001\n01110010111\n01110100111\n10000001010\n10010001000\n10010110100\n10100010100\n10101010110\n10110100... |
code_contests | verifiable_code | p01012 Planarian Regeneration | Solve the following coding problem using the programming language python:
Notes
For this problem, it is recommended to use floating point numbers, which are more accurate than double.
Input
m n x
k l y
For input, six integers m, n, x, k, l, y are given in the above input format.
These six integers correspond t... | ```python
m,n,x=[int(i) for i in input().split()]
k,l,y=[int(i) for i in input().split()]
res=0.5*(1.0+((m**2+n**2)**x)/((m+n)**(2*x)))
res*=0.5*(1.0+((k**2+l**2)**y)/((k+l)**(2*y)))
print(res)
``` | vfc_72885 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2 2\n1 1 1",
"output": "0.490741",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2 0\n3 4 0",
"output": "1.000000",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | p01144 Princess's Marriage | Solve the following coding problem using the programming language python:
Princess'Marriage
Marriage of a princess
English text is not available in this practice contest.
A brave princess in a poor country, knowing that gambling payouts are determined by the parimutuel method, felt more familiar with gambling and w... | ```python
while True:
N,M = map(int,input().strip().split(" "))
if [N,M] == [0,0]:
break
L = []
S = 0
for i in range(N):
l = list(map(int,input().strip().split(" ")))
l.reverse()
L.append(l)
S = S + l[0]*l[1]
L.sort()
for j in range(0,N):
t = N... | vfc_72889 | {
"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 8\n5 6\n4 5\n3 1\n5 10\n5 10\n5 10\n0 0",
"output": "5\n140",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 8\n5 6\n4 5\n3 2\n5 10\n5 10\n5 10\n0 0",
"output": "5\n130\n",
"t... |
code_contests | verifiable_code | p01283 Strange String Manipulation | Solve the following coding problem using the programming language python:
A linear congruential generator produces a series R(⋅) of pseudo-random numbers by the following for- mulas:
<image>
where S, A, C, and M are all parameters. In this problem, 0 ≤ S, A, C ≤ 15 and M = 256.
Now suppose we have some input string... | ```python
import math
M = 256
def entropy_if_smallest(ctr,bound):
ret = 0
for v in ctr:
if v == 0: continue
ret -= (v / N) * math.log2(v / N)
if ret >= bound:
return None
return ret
def solve(src):
ans_h = float('inf')
ans = None
for s in range(16):
... | vfc_72893 | {
"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\n5 4 3 2 1\n5\n7 7 7 7 7\n10\n186 8 42 24 154 40 10 56 122 72\n0",
"output": "0 1 1\n0 0 0\n8 7 14",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n5 4 3 2 1\n5\n7 7 7 7 7\n10\n186 8 42 ... |
code_contests | verifiable_code | p01453 Spring Tiles | Solve the following coding problem using the programming language python:
One morning when you woke up, it was in a springy labyrinth.
I don't know why I'm in such a strange place. You have the option of waiting for help here, but you know from experience that if you stay in a labyrinth like this for a long time, a g... | ```python
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
W, H = map(int, readline().split())
S = [readline().strip() for i in range(H)]
R = [[0]*W for i in range(H)]
P = []
cnt = 0
for i in range(H):
Si = S[i]
for j in... | vfc_72897 | {
"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": "8 6\n########\n#..##g.#\n#*#.*#.#\n#......#\n#*s#*.*#\n########",
"output": "5.857142857143",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 6\n\n..##g.#\n*#.*#.#\n......#\n*s#*.*#",
... |
code_contests | verifiable_code | p01603 Sanpo | Solve the following coding problem using the programming language python:
Sanpo
Problem Statement
The cats love walking. There are new discoveries as you walk down the road.
The town where Sora lives consists of N squares and N-1 roads.
The road just connects the two squares and does not branch or intersect.
For t... | vfc_72901 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 10000\n1 2 1 10 1",
"output": "10",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5\n1 2 1 4 7\n2 3 1 2 77\n2 4 1 2 777",
"output": "1568",
"type": "stdin_stdout"
},
... | |
code_contests | verifiable_code | p01899 Yamanote-line Game | Solve the following coding problem using the programming language python:
B: Yamanote-line Game-Yamanote-line Game-
Bean (?) Knowledge
The Yamanote line is convenient. The reason is that you can ride as many laps as time allows just by paying 130 yen. However, if you board with a ticket, you must be careful about th... | ```python
n, d = map(int, input().split())
lst = list(map(int, input().split()))
ans = sum([x - d for x in lst if x - d >= 0])
print(ans if ans else "kusoge")
``` | vfc_72909 | {
"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": "5 130\n130 170 100 120 140",
"output": "50",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 130\n130 170 100 122 140",
"output": "50\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | p02036 Donuts Orientation | Solve the following coding problem using the programming language python:
G: Donuts Orientation
story
Homu-chan's recent boom is making sweets. It seems that he makes a lot of sweets and shares them with his friends. Homu-chan seems to be trying to make donuts this time.
There are many important things in making do... | vfc_72913 | {
"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 1000000007",
"output": "204",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 1000000007",
"output": "109334\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
code_contests | verifiable_code | p02179 Monster Buster | Solve the following coding problem using the programming language python:
problem
AOR Ika is a monster buster.
One day, as I was walking down the road, I met a sleeping monster.
AOR Ika, who has a strong fighting spirit, decides to hit the monster with a wake-up blow. However, the current attack power of AOR Ika is ... | vfc_72917 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5 10 5 5\n4 4 2 2",
"output": "14",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p02322 Knapsack Problem with Limitations II | Solve the following coding problem using the programming language python:
You have $N$ items that you want to put them into a knapsack. Item $i$ has value $v_i$, weight $w_i$ and limitation $m_i$.
You want to find a subset of items to put such that:
* The total value of the items is as large as possible.
* The items... | ```python
import sys
from collections import deque
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N, W = map(int, readline().split())
vs = [0]*N; ws = [0]*N; ms = [0]*N
for i in range(N):
vs[i], ws[i], ms[i] = map(int, readline().split())
V0 = max(vs)
V = sum(v * min(V... | vfc_72921 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 100\n1 1 100\n2 1 50",
"output": "150",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1000000000\n3 5 1000000000\n7 6 1000000000\n4 4 1000000000\n6 8 1000000000\n2 5 1000000000",
"... |
code_contests | verifiable_code | p02467 Prime Factorize | Solve the following coding problem using the programming language python:
Factorize a given integer n.
Constraints
* 2 ≤ n ≤ 109
Input
n
An integer n is given in a line.
Output
Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the... | ```python
import math
n=int(input())
factors=[]
n1=n
p=2
while p<=math.sqrt(n):
if n%p==0:
n//=p
factors.append(str(p))
else:
p+=1
if n!=1:
factors.append(str(n))
print(str(n1)+": "+" ".join(factors))
``` | vfc_72925 | {
"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": "12",
"output": "12: 2 2 3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "126",
"output": "126: 2 3 3 7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | ce02 | Solve the following coding problem using the programming language python:
It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.
WAP to check that if 2 such numbers have this property
Input:
The first line will consist of the total number of test ca... | ```python
import sys
t = int(input())
while t>0:
a = sys.stdin.readline()
b = sys.stdin.readline()
if len(a)!=len(b):
print ("0")
else:
x=0
while x!=len(a):
check=1
y=0
while y!=len(b):
if a[x]==b[y]:
b=b[:y]... | vfc_72929 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n23\n45\n123\n123\n1234\n123\n1223\n1222\n1223\n1234",
"output": "0\n1\n0\n0\n0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n23\n45\n123\n123\n804\n123\n1223\n1222\n1223\n1234",
... |
code_contests | verifiable_code | decstr | Solve the following coding problem using the programming language python:
Statement
You need to find a string which has exactly K positions in it such that the character at that position comes alphabetically later than the character immediately after it. If there are many such strings, print the one which has the sh... | ```python
s=''.join(list(map(chr, range(122, 96, -1))))
tc=int(raw_input().strip())
for _ in range(tc):
n=int(raw_input().strip())
r=(n%25)*(-1)-1
if(r==-1):
print s*(n/25)
else:
print s[(n%25)*(-1)-1:]+s*(n/25)
``` | vfc_72933 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1\n2",
"output": "ba\ncba\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2\n2",
"output": "cba\ncba\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | iitk1p02 | Solve the following coding problem using the programming language python:
Awesomeness of a string is defined by a pair of a character C and an integer F, satisfying the following conditions :
C must belong to the given string S and there must be a substring subS of S having length equal to F such that all the char... | ```python
a=raw_input()
c,f=0,0
for i in range(len(a)):
val=1
while i<len(a)-1 and a[i]==a[i+1]:
i=i+1
val=val+1
if val>f:
f=val
c=a[i]
elif val==f:
if c>a[i]: c=a[i]
print c
print f
``` | vfc_72937 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "abbbaaabad",
"output": "a\n3",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | wordcnt | Solve the following coding problem using the programming language python:
You have to submit the assignment tomorrow. It has to be 1000 words long and your lecturer has warned you about writing in really big handwriting so that you can get away with writing less. And how many words have you used?
You don't know becaus... | ```python
#!/usr/bin/python
count = int(raw_input())
for i in range(count):
words = raw_input().split()
print len(words)
``` | vfc_72949 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nI can do this!\nYes, I will win\nCode Haxor!\nTaqneeq FTW!",
"output": "4\n4\n2\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\nI can do this!\nYes, J will win\nCode Haxor!\nTaqne... |
code_contests | verifiable_code | 1020_D. The hat | Solve the following coding problem using the programming language python:
This is an interactive problem.
Imur Ishakov decided to organize a club for people who love to play the famous game «The hat». The club was visited by n students, where n is even. Imur arranged them all in a circle and held a draw to break the ... | ```python
from sys import stdout
n = int(input())
if n % 4 == 2:
print("! -1")
exit(0)
print("?", 1)
stdout.flush()
a = int(input())
print("?", 1 + n // 2)
stdout.flush()
b = int(input())
if a == b:
print("!", 1)
exit(0)
l = 1
r = 1 + n // 2
while(l != r):
mid = ( l + r ) // 2
print("?", mid)
... | vfc_72953 | {
"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": "8\n<span class=\"tex-span\"></span>\n2\n<span class=\"tex-span\"></span>\n2\n",
"output": "? 1\n? 5\n! 1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1043_G. Speckled Band | Solve the following coding problem using the programming language python:
Ildar took a band (a thin strip of cloth) and colored it. Formally, the band has n cells, each of them is colored into one of 26 colors, so we can denote each color with one of the lowercase letters of English alphabet.
Ildar decided to take s... | vfc_72957 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 7, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9\nabcabcdce\n7\n1 6\n4 7\n5 9\n6 9\n1 9\n3 6\n4 4\n",
"output": "1\n-1\n4\n3\n2\n2\n-1\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1066_E. Binary Numbers AND Sum | Solve the following coding problem using the programming language python:
You are given two huge binary integer numbers a and b of lengths n and m respectively. You will repeat the following process: if b > 0, then add to the answer the value a~ \&~ b and divide b by 2 rounding down (i.e. remove the last digit of b), ... | ```python
MOD = 998244353
n, m = map(int, input().split())
a = input()[::-1]
b = input()[::-1]
c = [0] * n
for i in range(n):
if a[i] == '1':
c[i] = pow(2, i, MOD)
for i in range(n - 1):
c[i + 1] += c[i]
ans = 0
for i in range(m):
if b[i] == '1':
if i >= n:
ans += c[-1]
e... | vfc_72961 | {
"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": "4 4\n1010\n1101\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5\n1001\n10101\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... |
code_contests | verifiable_code | 1089_I. Interval-Free Permutations | Solve the following coding problem using the programming language python:
Consider a permutation p_1, p_2, ... p_n of integers from 1 to n. We call a sub-segment p_l, p_{l+1}, ..., p_{r-1}, p_{r} of the permutation an interval if it is a reordering of some set of consecutive integers. For example, the permutation (6,7... | vfc_72965 | {
"difficulty": "15",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 998244353\n1\n4\n5\n9\n",
"output": "1\n2\n6\n28146\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 437122297\n20\n",
"output": "67777575\n",
"type": "stdin_stdout"
},
... | |
code_contests | verifiable_code | 1108_C. Nice Garland | Solve the following coding problem using the programming language python:
You have a garland consisting of n lamps. Each lamp is colored red, green or blue. The color of the i-th lamp is s_i ('R', 'G' and 'B' — colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means ch... | ```python
from sys import stdin,stdout
from math import gcd,sqrt
from collections import deque
input=stdin.readline
R=lambda:map(int,input().split())
I=lambda:int(input())
S=lambda:input().rstrip('\n')
L=lambda:list(R())
P=lambda x:stdout.write(x)
hg=lambda x,y:((y+x-1)//x)*x
pw=lambda x:1 if x==1 else 1+pw(x//2)
chk=l... | vfc_72969 | {
"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": "7\nRGBGRBB\n",
"output": "3\nRGBRGBR\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nBRB\n",
"output": "0\nBRB\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1156_A. Inscribed Figures | Solve the following coding problem using the programming language python:
The math faculty of Berland State University has suffered the sudden drop in the math skills of enrolling students. This year the highest grade on the entrance math test was 8. Out of 100! Thus, the decision was made to make the test easier.
Fu... | ```python
n = int(input())
sh = list(map(int, input().split()))
sh += [0]
ans = ""
el = 0
for i in range(n - 1):
if len(sh) >= 3:
if sh[i] == 3 and sh[i + 1] == 1 and sh[i + 2] == 2:
el -= 1
if sh[i] == 2 and sh[i + 1] == 3 or sh[i] == 3 and sh[i + 1] == 2:
ans = "Infinite"
break
elif sh[i] == 1 and sh[i + ... | vfc_72977 | {
"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\n2 1 3\n",
"output": "Finite\n7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2 3\n",
"output": "Infinite",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1237_A. Balanced Rating Changes | Solve the following coding problem using the programming language python:
Another Codeforces Round has just finished! It has gathered n participants, and according to the results, the expected rating change of participant i is a_i. These rating changes are perfectly balanced — their sum is equal to 0.
Unfortunately, ... | ```python
import math as ma
x= int(input())
a = []
o = []
e = []
t = []
for i in range (x):
p = int(input())
a.append(p)
if p%2 ==0:
e.append(p)
else:
o.append(p)
t.append(p//2)
r = int(abs(sum(e)/2 + sum(t)))
for i in a:
if i % 2 ==0:
print(int(i/2))
else:
if(r!=0):
print(ma.ceil(i/2))
r-=1
els... | vfc_72993 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n10\n-5\n-5\n",
"output": "5\n-2\n-3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n-7\n-29\n0\n3\n24\n-29\n38\n",
"output": "-4\n-14\n0\n1\n12\n-14\n19\n",
"type": "stdi... |
code_contests | verifiable_code | 1254_E. Send Tree to Charlie | Solve the following coding problem using the programming language python:
Christmas was knocking on the door, and our protagonist, Bob, was preparing a spectacular present for his long-time second best friend Charlie. As chocolate boxes are lame, he decided to decorate a tree instead. Bob's tree can be represented as ... | vfc_72997 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2\n2 4\n3 4\n5 4\n0 0 0 0 0\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2\n1 3\n1 0 0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
... | |
code_contests | verifiable_code | 1278_E. Tests for problem D | Solve the following coding problem using the programming language python:
We had a really tough time generating tests for problem D. In order to prepare strong tests, we had to solve the following problem.
Given an undirected labeled tree consisting of n vertices, find a set of segments such that:
1. both endpoint... | ```python
def main():
import sys
input = sys.stdin.buffer.readline
N = int(input())
adj = [[] for _ in range(N+1)]
for _ in range(N-1):
a, b = map(int, input().split())
adj[a].append(b)
adj[b].append(a)
st = [1]
seen = [0] * (N+1)
seen[1] = 1
LL = [0] * (2 * ... | vfc_73001 | {
"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\n1 2\n1 3\n3 4\n3 5\n2 6\n",
"output": "1 4\n3 6\n2 10\n9 11\n8 12\n5 7\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1299_B. Aerodynamic | Solve the following coding problem using the programming language python:
Guy-Manuel and Thomas are going to build a polygon spaceship.
You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) as a polygon obtained by translating P b... | ```python
n = int(input())
if n % 2 == 0:
a = [0]*n
x1, y1 = list(map(int, input().split()))
x11, y11 = x1, y1
for i in range(n-1):
x2, y2 = list(map(int, input().split()))
a[i] = [x2-x1, y2-y1]
x1, y1 = x2, y2
a[n-1] = [x11-x2, y11-y2]
fl = True
for i in range(int(n/... | vfc_73005 | {
"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\n100 86\n50 0\n150 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 0\n4 1\n3 4\n0 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 1321_F. Reachable Strings | Solve the following coding problem using the programming language python:
In this problem, we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous subsequence of a string. We denote the substring of string s st... | vfc_73009 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n11011\n3\n1 3 3\n1 4 2\n1 2 3\n",
"output": "Yes\nYes\nNo\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "104\n01000100100101000001001000100001010100010011111111110101001010010100010101... | |
code_contests | verifiable_code | 1425_F. Flamingoes of Mystery | Solve the following coding problem using the programming language python:
This is an interactive problem. You have to use a flush operation right after printing each line. For example, in C++ you should use the function fflush(stdout), in Java — System.out.flush(), in Pascal — flush(output) and in Python — sys.stdout.... | vfc_73029 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n \n5\n \n15\n \n10\n ",
"output": "? 1 2\n? 1 3\n? 1 4\n? 1 5\n? 1 6\n? 2 3\n! 0 0 0 0 0 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n0 0 0 0 0 0 0 0 0 0\n",
"output": "?... | |
code_contests | verifiable_code | 1447_D. Catching Cheaters | Solve the following coding problem using the programming language python:
You are given two strings A and B representing essays of two students who are suspected cheaters. For any two strings C, D we define their similarity score S(C,D) as 4⋅ LCS(C,D) - |C| - |D|, where LCS(C,D) denotes the length of the Longest Commo... | ```python
from collections import defaultdict
import sys
n,m=map(int,input().split())
s=input()
t=input()
dp=[[0 for i in range(m+1)] for j in range(n+1)]
for i in range(n):
for j in range(m):
if s[i]==t[j]:
dp[i+1][j+1]=dp[i][j]+2
else:
dp[i+1][j+1]=max(0,max(dp[i+1]... | vfc_73033 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 7\nuiibwws\nqhtkxcn\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5\nabba\nbabab\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name"... |
code_contests | verifiable_code | 1498_E. Two Houses | Solve the following coding problem using the programming language python:
This is an interactive problem. Remember to flush your output while communicating with the testing program. You may use fflush(stdout) in C++, system.out.flush() in Java, stdout.flush() in Python or flush(output) in Pascal to flush the output. I... | ```python
from sys import stdin, stdout
input = stdin.readline
def MyIter(n):
for k in range(n-1, 0, -1):
i = 0
while i + k < n:
yield i, i + k
i += 1
def solve(n, a):
dct = [[] for i in range(n)]
for i, el in enumerate(a):
dct[el].append(i + 1)
for i,... | vfc_73041 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 0 3\nNo\nNo\nNo\nNo\nNo\nNo",
"output": "\n? 2 1\n? 1 3\n? 4 1\n? 2 3\n? 4 2\n? 4 3\n! 0 0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 1 1\nYes",
"output": "\n? 1 2\n! ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.