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 | 1246_D. Tree Factory | Solve the following coding problem using the programming language python:
Bytelandian Tree Factory produces trees for all kinds of industrial applications. You have been tasked with optimizing the production of a certain type of tree for an especially large and important order.
The tree in question is a rooted tree w... | vfc_35937 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0 1 2\n",
"output": "0 1 2 3\n0\n\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1266_B. Dice Tower | Solve the following coding problem using the programming language python:
Bob is playing with 6-sided dice. A net of such standard cube is shown below.
<image>
He has an unlimited supply of these dice and wants to build a tower by stacking multiple dice on top of each other, while choosing the orientation of each di... | ```python
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 18 14:08:47 2020
@author: Varun
"""
from sys import stdin, stdout
stdin.readline()
numbers = map(int, stdin.readline().split())
def check(n):
if n < 15:
return False
m = n%14
return 1 <= m <= 6
for el in numbers:
if check(e... | vfc_35941 | {
"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\n29 34 19 38\n",
"output": "YES\nYES\nYES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n29 34 18 38\n",
"output": "YES\nYES\nYES\nNO\n",
"type": "stdin_stdout"
}... |
code_contests | verifiable_code | 1287_D. Numbers on Tree | Solve the following coding problem using the programming language python:
Evlampiy was gifted a rooted tree. The vertices of the tree are numbered from 1 to n. Each of its vertices also has an integer a_i written on it. For each vertex i, Evlampiy calculated c_i — the number of vertices j in the subtree of vertex i, s... | ```python
import sys
# inf = open('input.txt', 'r')
# reader = (line.rstrip() for line in inf)
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
n = int(input())
cs = [0] * (n + 1)
ps = [0] * (n + 1)
children = [[] for _ in range(n+1)]
for i in range(1, n+1):
p, c = map(int, input().split())
... | vfc_35945 | {
"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\n2 0\n0 2\n2 0\n",
"output": "YES\n1 3 2 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 1\n1 3\n2 1\n3 0\n2 0\n",
"output": "YES\n2 5 3 1 4 \n",
"type": "stdin_stdout"... |
code_contests | verifiable_code | 1330_D. Dreamoon Likes Sequences | Solve the following coding problem using the programming language python:
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS:
You are given two integers d, m, find the number of arrays a, satisfying the following constraints:
* The length of a is n, n ≥ 1
... | ```python
t = int(input())
for _ in range(t):
d, m = map(int, input().split())
a = []
i = 0
while d > (1<<(i+1))-1:
a.append(1<<i)
i += 1
a.append((1<<i) - (1<<(i+1)) + d + 1)
#print(a)
ans = 1
for x in a:
ans *= x+1
ans %= m
print((ans-1)%m)
``` | vfc_35953 | {
"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": "10\n1 1000000000\n2 999999999\n3 99999998\n4 9999997\n5 999996\n6 99995\n7 9994\n8 993\n9 92\n10 1\n",
"output": "1\n3\n5\n11\n17\n23\n29\n59\n89\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | 1370_F2. The Hidden Pair (Hard Version) | Solve the following coding problem using the programming language python:
Note that the only difference between the easy and hard version is the constraint on the number of queries. You can make hacks only if all versions of the problem are solved.
This is an interactive problem.
You are given a tree consisting of n... | vfc_35961 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3\n1 2\n1 3\n\n1 1\n\n2 3\n\n3 1\n\n3 1\n\nCorrect",
"output": "? 3 1 2 3\n? 2 2 3\n? 2 2 3\n! 1 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n4\n2 4\n1 2\n2 4\n4 3\n",
"ou... | |
code_contests | verifiable_code | 1393_C. Pinkie Pie Eats Patty-cakes | Solve the following coding problem using the programming language python:
Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling.
Pinkie Pie eats the patt... | ```python
def solve(n,ar):
freq = [0] * 200000
for i in range(n):
freq[ar[i]] += 1
maxi = 0
max_freq = 0
for i in range(len(freq)):
if maxi < freq[i]:
maxi = max(maxi,freq[i])
max_freq = 1
elif freq[i] == maxi:
max_freq += 1
print... | vfc_35965 | {
"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\n7\n1 7 1 6 4 4 6\n8\n1 1 4 6 4 6 4 7\n3\n3 3 3\n6\n2 5 2 3 1 4\n",
"output": "3\n2\n0\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n15\n1 2 3 4 5 1 2 3 4 5 1 2 3 4 5\n",
"... |
code_contests | verifiable_code | 1418_B. Negative Prefixes | Solve the following coding problem using the programming language python:
You are given an array a, consisting of n integers.
Each position i (1 ≤ i ≤ n) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in any order and place them back into the unlocked posi... | ```python
import sys
from sys import stdin
import math
import fractions
#Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))
def iinput():
return int(input())
def minput():
return map(int,input().split())
def linput():
return list(map(int,input().split()))
def fiinput():
return int(stdin.readline())
de... | vfc_35969 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n3\n1 3 2\n0 0 0\n4\n2 -3 4 -1\n1 1 1 1\n7\n-8 4 -2 -6 4 7 1\n1 0 0 0 1 1 0\n5\n0 1 -4 6 3\n0 0 0 1 1\n6\n-1 7 10 4 -8 -1\n1 0 0 0 0 1\n",
"output": "3 2 1 \n2 -3 4 -1 \n-8 4 1 -2 4 7 -6 \n1 0 -4 6 3 \n-1 10 7 4 -8 -1 \n",
... |
code_contests | verifiable_code | 1436_A. Reorder | Solve the following coding problem using the programming language python:
For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that ∑_{i=1}^{n}{∑_{j=i}^{n}{(a_j)/(j)}} equals m? It is forbidden to delete elements as well as insert ne... | ```python
#import numpy as np
#import collections
#import sys
# =============================================================================
#def get_primeFactor(n):
# res=[1]
# x=2
# while x*x<=n:
# while n%x==0:
# res.append(x)
# n//=x
# x+=1
# if n>1:res.append(n)
# ... | vfc_35973 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 8\n2 5 1\n4 4\n0 1 2 3\n",
"output": "YES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3 6\n4 4 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 145_D. Lucky Pair | Solve the following coding problem using the programming language python:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has an array a of... | vfc_35977 | {
"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\n4 7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 4 2 4\n",
"output": "9\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1485_F. Copy or Prefix Sum | Solve the following coding problem using the programming language python:
You are given an array of integers b_1, b_2, …, b_n.
An array a_1, a_2, …, a_n of integers is hybrid if for each i (1 ≤ i ≤ n) at least one of these conditions is true:
* b_i = a_i, or
* b_i = ∑_{j=1}^{i} a_j.
Find the number of hybr... | ```python
for s in[*open(0)][2::2]:
C=[0];N=0;D={0:1};S=1
for n in map(int,s.split()):C+=C[-1]+n,;N+=1
for i in range(1,N):D[C[i]],S=S,(2*S-D.get(C[i],0))%(10**9+7)
print(S)
``` | vfc_35981 | {
"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": "4\n3\n1 -1 1\n4\n1 2 3 4\n10\n2 -1 1 -2 2 3 -5 0 2 -1\n4\n0 0 0 1\n",
"output": "\n3\n8\n223\n1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 150_D. Mission Impassable | Solve the following coding problem using the programming language python:
Market stalls now have the long-awaited game The Colder Scrools V: Nvodsk. The game turned out to be difficult as hell and most students can't complete the last quest ("We don't go to Nvodsk..."). That threatened winter exams. The rector already... | vfc_35985 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n1 5 -1 -1 -1 -1 10\nabacaba\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n-1 -1 -1 -1 -1 -1 -1\nabacaba\n",
"output": "0\n",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | 163_A. Substring and Subsequence | Solve the following coding problem using the programming language python:
One day Polycarpus got hold of two non-empty strings s and t, consisting of lowercase Latin letters. Polycarpus is quite good with strings, so he immediately wondered, how many different pairs of "x y" are there, such that x is a substring of st... | ```python
from sys import stdin
s=[ord(i)-97 for i in stdin.readline().strip()]
s1=[ord(i)-97 for i in stdin.readline().strip()]
n=len(s)
m=len(s1)
mod=1000000007
dp=[[0 for i in range(n)] for j in range(26)]
for i in range(m):
arr=[0 for j in range(n)]
for j in range(n):
if s1[i]==s[j] :
ar... | vfc_35993 | {
"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": "codeforces\nforceofcode\n",
"output": "60\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "aa\naa\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | 183_B. Zoo | Solve the following coding problem using the programming language python:
The Zoo in the Grid Kingdom is represented by an infinite grid. The Zoo has n observation binoculars located at the OX axis. For each i between 1 and n, inclusive, there exists a single binocular located at the point with coordinates (i, 0). The... | ```python
def gcd(a,b):
if b == 0:
return a
return gcd(b, a % b)
def normalize_rational(num,den):
#associate the -ve with the num or cancel -ve sign when both are -ve
if num ^ den < 0 and num > 0 or num ^ den > 0 and num < 0:
num = -num; den = -den
#put it in its simplest form
... | vfc_35997 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5\n2 1\n4 1\n3 2\n4 3\n4 4\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000 2\n194305 1024\n4388610 1023\n",
"output": "1000000\n",
"type": "stdin_st... |
code_contests | verifiable_code | 207_B1. Military Trainings | Solve the following coding problem using the programming language python:
The Smart Beaver from ABBYY started cooperating with the Ministry of Defence. Now they train soldiers to move armoured columns. The training involves testing a new type of tanks that can transmit information. To test the new type of tanks, the t... | vfc_36001 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2\n2\n2\n2\n2\n",
"output": " 10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2\n1\n1\n",
"output": " ... | |
code_contests | verifiable_code | 230_C. Shifts | Solve the following coding problem using the programming language python:
You are given a table consisting of n rows and m columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values either one cell to the left, or one cell to the right.
T... | ```python
def solve(rows):
all_dists = [0 for _ in range(len(rows[0]))]
for r in rows:
dists = [len(r) for _ in r]
if '1' not in r:
return -1
start = r.index('1')
for i in range(len(r)):
right = (i+start)%len(r) # going right
left = (start+2*le... | vfc_36005 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 6\n101010\n000100\n100000\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n111\n000\n",
"output": "-1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 256_B. Mr. Bender and Square | Solve the following coding problem using the programming language python:
Mr. Bender has a digital table of size n × n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bender will be happy.
We'll consider the table rows numbered from... | ```python
x, y, n, c = 0, 0, 0, 0
def suma_impares(m):
return m * m
def suma_n(m):
return m * (m - 1) // 2
def cnt(t):
u, d, l, r = x + t, x - t, y - t, y + t
suma = t ** 2 + (t + 1) ** 2
if u > n: suma -= suma_impares(u - n)
if d < 1: suma -= suma_impares(1 - d)
if l < 1: suma -= suma_impares(1 - l)
if r > n: ... | vfc_36009 | {
"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": "9 3 8 10\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 4 3 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input":... |
code_contests | verifiable_code | 27_B. Tournament | Solve the following coding problem using the programming language python:
The tournament «Sleepyhead-2010» in the rapid falling asleep has just finished in Berland. n best participants from the country have participated in it. The tournament consists of games, each of them is a match between two participants. n·(n - 1... | ```python
a = int(input())
d = {}
f = {}
for i in range(a*(a-1)//2-1):
v, c = map(int, input().split())
if v not in f:
f[v] = []
f[v].append(c)
if v in d:
d[v] += 1
else:
d[v] = 1
if c in d:
d[c] += 1
else:
d[c] = 1
s = []
m = 0
for i in range(1, a + 1... | vfc_36013 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4 2\n4 1\n2 3\n2 1\n3 1\n",
"output": "4 3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 302_A. Eugeny and Array | Solve the following coding problem using the programming language python:
Eugeny has array a = a1, a2, ..., an, consisting of n integers. Each integer ai equals to -1, or to 1. Also, he has m queries:
* Query number i is given as a pair of integers li, ri (1 ≤ li ≤ ri ≤ n).
* The response to the query will be in... | ```python
from collections import Counter
num, cases = map(int, input().split())
arr = list(map(int, input().split()))
count = Counter(arr)
minus = count[-1]
plus = count[1]
mn = min(plus, minus)
ans = []
while cases:
cases -= 1
a, b = map(int, input().split())
if (b - a + 1) % 2 != 0:
ans.append(... | vfc_36017 | {
"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 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n",
"output": "0\n1\n0\n1\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n1 -1\n1 1\n1 2\n2 2\n",
"output": "0\n1\n0\n",
"type... |
code_contests | verifiable_code | 329_B. Biridian Forest | Solve the following coding problem using the programming language python:
You're a mikemon breeder currently in the middle of your journey to become a mikemon master. Your current obstacle is go through the infamous Biridian Forest.
The forest
The Biridian Forest is a two-dimensional grid consisting of r rows and c ... | ```python
from sys import stdin
rints = lambda: [int(x) for x in stdin.readline().split()]
rstr = lambda: stdin.readline().strip()
rstr_2d = lambda n: [rstr() for _ in range(n)]
valid = lambda x, y: 0 <= x < n and 0 <= y < m and grid[x][y] != 'T'
dx, dy = [0, 1, 0, -1, 1, -1, 1, -1], [1, 0, -1, 0, 1, -1, -1, 1]
n, m ... | vfc_36021 | {
"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": "1 4\nSE23\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 7\n000E0T3\nT0TT0T0\n010T0T0\n2T0T0T0\n0T0S000\n",
"output": "3\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 34_E. Collisions | Solve the following coding problem using the programming language python:
On a number line there are n balls. At time moment 0 for each ball the following data is known: its coordinate xi, speed vi (possibly, negative) and weight mi. The radius of the balls can be ignored.
The balls collide elastically, i.e. if two b... | ```python
class Ball:
def __init__(self, x, v, m):
self.v = v
self.x = x
self.m = m
def move(self, time):
self.x += self.v * time
def collisionTime(self, other):
if self.v == other.v:
return float("inf")
t = - (self.x - other.x) / (self.v - othe... | vfc_36025 | {
"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 9\n3 4 5\n0 7 8\n",
"output": "68.538461538\n44.538461538\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 374_A. Inna and Pink Pony | Solve the following coding problem using the programming language python:
Dima and Inna are doing so great! At the moment, Inna is sitting on the magic lawn playing with a pink pony. Dima wanted to play too. He brought an n × m chessboard, a very tasty candy and two numbers a and b.
Dima put the chessboard in front o... | ```python
n, m, i, j, a, b = map(int, input().split())
corners = [(1, 1), (1, m), (n, 1), (n, m)]
result = False
ans = -1
for cnt in corners:
if (abs(cnt[0] - i) % a == 0) and (abs(cnt[1] - j) % b == 0):
result = True
t1, t2 = abs(cnt[0] - i) // a, abs(cnt[1] - j) // b
if (t1 + t2) % 2 == 0:... | vfc_36029 | {
"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 5 2 3 1 1\n",
"output": "Poor Inna and pony!\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 7 1 3 2 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | 418_D. Big Problems for Organizers | Solve the following coding problem using the programming language python:
The Finals of the "Russian Code Cup" 2214 will be held in n hotels. Two hotels (let's assume that they are the main hotels), will host all sorts of events, and the remaining hotels will accommodate the participants. The hotels are connected by n... | vfc_36037 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 4\n1 2\n2 3\n3\n1 4\n1 3\n2 3\n",
"output": "2\n1\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 3\n3 1\n3\n2 1\n2 3\n3 1\n",
"output": "1\n1\n1\n",
"type": "stdi... | |
code_contests | verifiable_code | 445_B. DZY Loves Chemistry | Solve the following coding problem using the programming language python:
DZY loves chemistry, and he enjoys mixing chemicals.
DZY has n chemicals, and m pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order.
Let's consider the danger of a... | ```python
def iterative_dfs(graph, start, path=[]):
visited = {}
for i in graph:
visited[i] = []
q=[start]
while q:
v=q.pop(0)
if not visited[v]:
visited[v] = True
path=path+[v]
q=graph[v]+q
return path
nodes, edges = map(int, input().... | vfc_36041 | {
"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 2\n1 2\n2 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"i... |
code_contests | verifiable_code | 467_C. George and Job | Solve the following coding problem using the programming language python:
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.
Given a sequence of n inte... | ```python
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
p_a = [0 for _ in range(n)]
p_a[0] = a[0]
for i in range(1, n):
p_a[i] = p_a[i - 1] + a[i]
INF = -1e10
# print(p_a)
dp = {}
from types import GeneratorType
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
... | vfc_36045 | {
"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 2 1\n1 2 3 4 5\n",
"output": "9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 1 3\n2 10 7 18 5 33 0\n",
"output": "61",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 48_F. Snow sellers | Solve the following coding problem using the programming language python:
The New Year celebrations in Berland last n days. Only this year the winter is snowless, that’s why the winter celebrations’ organizers should buy artificial snow. There are m snow selling companies in Berland. Every day the i-th company produce... | vfc_36049 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 10, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3 10\n4 4 4\n5 5 8\n1 2 5\n",
"output": " 22.000000000000000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100 2 1000000000\n... | |
code_contests | verifiable_code | 513_G1. Inversions problem | Solve the following coding problem using the programming language python:
You are given a permutation of n numbers p1, p2, ..., pn. We perform k operations of the following type: choose uniformly at random two indices l and r (l ≤ r) and reverse the order of the elements pl, pl + 1, ..., pr. Your task is to find the e... | ```python
n, k = map(int, input().split())
p = list(map(int, input().split()))
def count_invs(a):
ans = 0
for i in range(n-1):
for j in range(i + 1, n):
if a[i] > a[j]:
ans += 1
return ans
def inv_in_perms(a, count):
if count > 0:
ans = 0
for l... | vfc_36053 | {
"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": "3 1\n1 2 3\n",
"output": "0.83333333333333\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n1 3 2\n",
"output": "1.45833333333333\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 53_D. Physical Education | Solve the following coding problem using the programming language python:
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height ... | ```python
import sys
n = int(sys.stdin.readline ())
a= [int (x) for x in sys.stdin.readline ().split ()]
assert len(a) == n
b = [int (x) for x in sys.stdin.readline ().split ()]
assert len(b) == n
ans = []
for i in range (n):
j = i;
while b[j] != a[i] :
j += 1
while j > i:
ans += [(j, j ... | vfc_36057 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 100500\n1 100500\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 2 3 2\n3 2 1 2\n",
"output": "3\n2 3\n1 2\n2 3\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 567_F. Mausoleum | Solve the following coding problem using the programming language python:
King of Berland Berl IV has recently died. Hail Berl V! As a sign of the highest achievements of the deceased king the new king decided to build a mausoleum with Berl IV's body on the main square of the capital.
The mausoleum will be constructe... | ```python
n,k = map(int,input().split())
n*=2
n+=2
l,le,e = [[] for i in range(n)],[[] for i in range(n)],[0]*n
ok = 1
for i in range(k):
a,c,b = input().split()
a,b = int(a), int(b)
if c=="=":
if a==b:
continue
if (e[a] and e[a]!=b) or (e[b] and e[b]!=a):
ok = 0
... | vfc_36061 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 0\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 1\n3 = 6\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "... |
code_contests | verifiable_code | 589_b | Solve the following coding problem using the programming language python:
Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping and bought n rectangular cake layers. The length and the width of the i-th cake layer were ai and bi respectively, while the height of each cake layer was eq... | ```python
#coding:utf-8
n = int(raw_input())
cakes = []
for i in xrange(n):
cakes.append(sorted(map(int, raw_input().split())))
#print cakes
cakes.sort(key = lambda x:x[0])
ans = 0
w = []
for i in xrange(n-1,-1,-1):
w.append(cakes[i][1])
w.sort()
for j in xrange(len(w)):
tmp = cakes[i][0]*w[j]*... | vfc_36065 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n5 12\n1 1\n4 6\n6 4\n4 6",
"output": "96\n6 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n100001 900000\n900001 100000",
"output": "180000000000\n900000 100000\n",
"t... |
code_contests | verifiable_code | 630_O. Arrow | Solve the following coding problem using the programming language python:
Petya has recently started working as a programmer in the IT city company that develops computer games.
Besides game mechanics implementation to create a game it is necessary to create tool programs that can be used by game designers to create ... | ```python
from math import atan2, pi
EPS = 0.00000001
def eq(a, b):
return abs(a - b) < EPS
class Vector:
def __init__(self, x2, y2, x1=0, y1=0):
self.x = (x2 - x1)
self.y = y2 - y1
self.s = (self.x ** 2 + self.y ** 2) ** 0.5
def __add__(self, other):
return Vector(self... | vfc_36073 | {
"difficulty": "22",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 8 0 2 8 3 4 5\n",
"output": "8.0000000000000000000000000 11.0000000000000000000000000\n4.0000000000000000000000000 8.0000000000000000000000000\n6.0000000000000000000000000 8.0000000000000000000000000\n6.00000000000000000000... |
code_contests | verifiable_code | 659_G. Fence Divercity | Solve the following coding problem using the programming language python:
Long ago, Vasily built a good fence at his country house. Vasily calls a fence good, if it is a series of n consecutively fastened vertical boards of centimeter width, the height of each in centimeters is a positive integer. The house owner reme... | ```python
mod = 10 ** 9 + 7
n = int(input())
h = list(map(lambda x: int(x) - 1, input().split()))
ans = x = 0
for i in range(n):
ans += h[i] + min(h[i], h[i - 1]) * x
if i < n - 1:
x *= min(h[i - 1], h[i], h[i + 1])
x += min(h[i], h[i + 1])
ans %= mod
x %= mod
print(ans)
``` | vfc_36077 | {
"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": "3\n3 4 2\n",
"output": "13",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 682_D. Alyona and Strings | Solve the following coding problem using the programming language python:
After returned from forest, Alyona started reading a book. She noticed strings s and t, lengths of which are n and m respectively. As usual, reading bored Alyona and she decided to pay her attention to strings s and t, which she considered very ... | ```python
n, m, k = map(int, input().split())
s, t = input(), input()
n += 1
m += 1
p = [i for i in range(n * m - n) if (i + 1) % n]
r = p[::-1]
d = [0] * n * m
for i in p:
if s[i % n] == t[i // n]: d[i] = d[i - n - 1] + 1
f = d[:]
for y in range(k - 1):
for i in p: f[i] = max(f[i], f[i - 1], f[i - n])
... | vfc_36081 | {
"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": "9 12 4\nbbaaababb\nabbbabbaaaba\n",
"output": "7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2 2\nabc\nab\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_n... |
code_contests | verifiable_code | 705_C. Thor | Solve the following coding problem using the programming language python:
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those ... | ```python
import collections
import copy
n, q = map(int, input().split())
Q = collections.deque()
A = n * [0]
B = copy.copy(A)
L = []
s = n = 0
for _ in range(q):
y, x = map(int, input().split())
if 2 > y:
x -= 1
Q.append(x)
B[x] += 1
A[x] += 1
s += 1
elif 3 > y:
... | vfc_36085 | {
"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 6\n1 2\n1 4\n1 2\n3 3\n1 3\n1 3\n",
"output": "1\n2\n3\n0\n1\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n1 3\n1 1\n1 2\n2 3\n",
"output": "1\n2\n3\n2\n",
"type": ... |
code_contests | verifiable_code | 727_F. Polycarp's problems | Solve the following coding problem using the programming language python:
Polycarp is an experienced participant in Codehorses programming contests. Now he wants to become a problemsetter.
He sent to the coordinator a set of n problems. Each problem has it's quality, the quality of the i-th problem is ai (ai can be p... | vfc_36089 | {
"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 3\n8 -5 -4 1 -7 4\n0 7 3\n",
"output": "2 0 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5\n0 0 -1 0 1\n1 0 1 5 8\n",
"output": "0 1 0 0 0 ",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | 749_A. Bachgold Problem | Solve the following coding problem using the programming language python:
Bachgold problem is very easy to formulate. Given a positive integer n represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer k is cal... | ```python
n=int(input())
c=0
if(n%2==1):
n-=3
l=[2]*(n//2)
l.append(3)
print(len(l))
print(*l)
else:
l=[2]*(n//2)
print(len(l))
print(*l)
``` | vfc_36093 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n",
"output": "3\n2 2 2 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "2\n2 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input... |
code_contests | verifiable_code | 796_F. Sequence Recovery | Solve the following coding problem using the programming language python:
Zane once had a good sequence a consisting of n integers a1, a2, ..., an — but he has lost it.
A sequence is said to be good if and only if all of its integers are non-negative and do not exceed 109 in value.
<image>
However, Zane remembers h... | vfc_36101 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n1 1 5 0\n1 1 5 100\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 4\n1 1 5 19\n1 2 5 1\n2 5 100\n1 1 5 100\n",
"output": "YES\n19 1 0 0 0 \n",
"type":... | |
code_contests | verifiable_code | 817_B. Makes And The Product | Solve the following coding problem using the programming language python:
After returning from the army Makes received a gift — an array a consisting of n positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a particular question: how many triples of indices (i, ... | ```python
n=int(input())
a=list(map(int,(input().split(' '))))
a=sorted(a)
a.append(0)
ans=1
t=0
while a[3+t]==a[2]:t=t+1
if a[3]==a[0]:ans=(t+3)*(t+2)*(t+1)/6
elif a[3]==a[1]:ans=(t+2)*(t+1)/2
elif a[3]==a[2]:ans=t+1
print(int(ans))
``` | vfc_36105 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 3 2 3 4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1 3 3 1 3 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 842_B. Gleb And Pizza | Solve the following coding problem using the programming language python:
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius r and center at the origin. Pizza consi... | ```python
'''input
8 4
7
7 8 1
-7 3 2
0 2 1
0 -2 2
-3 -3 1
0 6 2
5 3 1
'''
r, d = map(int, input().split())
n = int(input())
c = 0
for _ in range(n):
x, y, r1 = map(int, input().split())
s = (x**2 + y**2)**0.5
if r-d <= s-r1 and s+r1 <= r:
c += 1
print(c)
``` | vfc_36109 | {
"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": "10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1\n",
"output": "2\n",... |
code_contests | verifiable_code | 863_B. Kayaking | Solve the following coding problem using the programming language python:
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks.... | ```python
n = int(input())
n = 2*n
w = [int(i) for i in input().split()]
w.sort()
import math
res = math.inf
for x in range(n):
for y in range(x+1, n):
wc = w[:]
wc.pop(y); wc.pop(x)
# print(wc)
s = 0
for i in range(0, n-3, 2):
s += wc[i+1]-wc[i]
res = min(s, res)
print(re... | vfc_36113 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 3 4 6 3 4 100 200\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 2 3 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | 933_B. A Determined Cleanup | Solve the following coding problem using the programming language python:
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...
Given two integers p... | ```python
s = input()
# s = '46 2'
p, k = list(map(int, s.split()))
res = []
f = True
while p != 0:
if f:
n = p % k
m = (p - n) // k
f = False
else:
n = (-p) % k
m = (p + n) // k
f = True
res.append(n)
p = m
print(len(res))
print(' '.join(list(map(str, ... | vfc_36125 | {
"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": "46 2\n",
"output": "7\n0 1 0 0 1 1 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2018 214\n",
"output": "3\n92 205 1 \n",
"type": "stdin_stdout"
},
{
"fn_nam... |
code_contests | verifiable_code | 95_D. Horse Races | Solve the following coding problem using the programming language python:
Petya likes horse racing very much. Horses numbered from l to r take part in the races. Petya wants to evaluate the probability of victory; for some reason, to do that he needs to know the amount of nearly lucky horses' numbers. A nearly lucky n... | vfc_36129 | {
"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": "1 2\n70 77\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n1 20\n80 100\n",
"output": "0\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... | |
code_contests | verifiable_code | 987_B. High School: Become Human | Solve the following coding problem using the programming language python:
Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.
It turns out that high school struggles are not gone... | ```python
import math
x,y=map(lambda x:math.log(int(x))/int(x),input().split())
print('<=>'[(x>=y)+(x>y)])
``` | vfc_36133 | {
"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 8\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 6\n",
"output": "=\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | alexanders-journey-4 | Solve the following coding problem using the programming language python:
There are N (labelled 1 to N) kingdoms in a country. Our king Alexander is living in the kingdom S. We are given R distances, these distances are between two kingdoms and the distance between any two kingdom may or may not be unique.
Now Alexan... | ```python
def killdoubles(l):
i=0
a=l[i]
ll=[a]
while i<len(l):
if a!=l[i]:
a=l[i]
ll.append(a)
i+=1
return ll
def argminnonmarque(l,m):
mini=min([l[i] for i in range(len(l)) if not(m[i])])
for i in range(len(l)):
if ((l[i]==mini) & (not(m[i])... | vfc_36137 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n4 4\n1 2 24\n1 4 20\n3 1 3\n4 3 12\n1\n\nSAMPLE",
"output": "24 3 15",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | burger-deliver-time-1 | Solve the following coding problem using the programming language python:
In McD's Burger, n hungry burger fans are ordering burgers. The ith order is placed by the ith fan at ti time and it takes di time to procees. What is the order in which the fans will get their burgers?
Input Format
On the first line you will ... | ```python
a=[]
T=input()
for i in xrange(T):
c,d=map(int,raw_input().split())
a.append((c+d,i))
a.sort()
for i in a:
print i[1]+1,
``` | vfc_36141 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n8 1\n4 2\n5 6\n3 1\n4 3\n\nSAMPLE",
"output": "4 2 5 1 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 3\n2 3\n3 3",
"output": "1 2 3\n",
"type": "stdin_stdout"
}... |
code_contests | verifiable_code | day-6-advanced-mathematics | Solve the following coding problem using the programming language python:
Problem :
Bajirao is on a date with his girlfriend Avni. It is a romantic night and they are
playing a game of words.
The rule of this game is that if Bajirao says a word such that no adjacent letters occurring in the word are same then he ge... | ```python
t=input()
for i in range(t):
a=raw_input()
c=0
for i in range(0,len(a)-1):
if a[i]==a[i+1]:
c=1
if c==1:
print "SLAP"
else:
print "KISS"
``` | vfc_36145 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nremember\noccurring\n\nSAMPLE",
"output": "KISS\nSLAP\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\nremember\noccurring\n\nELPMAS",
"output": "KISS\nSLAP\n",
"type": "s... |
code_contests | verifiable_code | game-of-numbers-7 | Solve the following coding problem using the programming language python:
Game of numbers is a game where you are given two integers (X and Y), and you have to print the number of special numbers between X and Y both inclusive.
The property of a special numbers is as follows:
A special number is not divisible by a... | ```python
import math
def count(x, y):
z = [1] * ( y - x + 1)
for i in range(2, int(math.sqrt(y)) + 1):
step = i ** 2
if x % step == 0: j = x
else: j = x + step - (x%step)
while(j <= y):
z[j - x] = 0
j += step
return z.count(1)
def get():
... | vfc_36149 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n1 10\n\nSAMPLE",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1 10\n\nELPMAS",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | mobile-conversations | Solve the following coding problem using the programming language python:
You have just purchased a new mobile phone and you want to call all of your relatives to brag about your new phone. You have N relatives. You will talk to i^th relative for exactly Ti minutes. Each minute costs you 1 dollar . However, your relat... | ```python
n = int(raw_input())
lists = []
while n > 0:
n = n-1
lists.append(map(int,raw_input().split(" ")))
# lists.sort(lambda k : k[1]/k[0])
list2 = []
list3 = []
for x in lists:
# print x[0],x[1]
if x[1]/x[0] > 0:
list2.append(x)
else:
list3.append(x)
list2.sort(key=lambda k: k[0])
list3.sort(key = lambda ... | vfc_36157 | {
"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\n2 1\n\nSAMPLE",
"output": "2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | panda-and-maximum-product | Solve the following coding problem using the programming language python:
Panda has started learning about subsets. His professor gave him a simple task. Given a list of numbers, Panda has to choose the subset which gives the maximum product. However, the professor asked Panda only to submit the maximum product obtain... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
n=int(raw_input())
l=[int(i) for i in raw_input().split(" ")]
l.sort()
x=l[::-1]
if x[0]>0 and x[1]>0:
print x[0]*x[1]
else:
print l[0]*l[1]
``` | vfc_36161 | {
"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 3\n\nSAMPLE",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 3\n\nTAMPLE",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | roots | Solve the following coding problem using the programming language python:
Bosky needs your help in completing his maths homework today. He has to solve some questions as homework from a book named Jungly Mathematics. He knows that Jungly Mathematics contains certain quadratic equations which have imaginary roots. He i... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
def can_solve(equation):
a = equation[0]
b = equation[1]
c = equation[2]
if b * b < 4 * a * c:
return False
else:
return True
if __name__ == '__main__':
cases =... | vfc_36165 | {
"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 0 -1\n1 1 1\n\nSAMPLE",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 0 -1\n1 1 1\n\nSAMPLE",
"output": "1\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | stock-market-calculation-1 | Solve the following coding problem using the programming language python:
Your algorithm is so good at predicting the market that you now know what the share price of Mahindra & Mahindra. (M&M) will be for the next N days.
Each day, you can either buy one share of M&M, sell any number of shares of M&M that you own, o... | ```python
def calcprofit(stockvalues):
prof=0
m=0
for i in range(len(stockvalues)-1,-1,-1):
ai=stockvalues[i]
if m<=ai:
m=ai
prof+=m-ai
return (prof)
for iti in xrange(input()):
n=input()
l=map(int, raw_input().split())
print calcprofit(l)
``` | vfc_36169 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3\n5 3 2\n3\n1 2 100\n4\n1 3 1 2\n\nSAMPLE",
"output": "0\n197\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3\n5 3 2\n3\n1 2 100\n4\n1 3 1 2",
"output": "0\n197\n3\n",
... |
code_contests | verifiable_code | unique | Solve the following coding problem using the programming language python:
There are N people in a group. The personality of each person is denoted by A[i] from the set A, where A[i] denotes the personality of the ith person.
Your task is to find the total persons of different personalities.
INPUT:
First line conta... | ```python
a = input()
for i in xrange(a) :
d = input();
b = [int(i) for i in raw_input().strip().split()]
c = {}
for i in xrange(d) :
c[b[i]]=i;
print len(c)
``` | vfc_36173 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n5\n1 2 3 4 5\n\nSAMPLE",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n5\n1 2 3 4 5",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name":... |
code_contests | verifiable_code | p00009 Prime Number | Solve the following coding problem using the programming language python:
Write a program which reads an integer n and prints the number of prime numbers which are less than or equal to n. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first fo... | ```python
import sys
import math
LIMIT = 1000000
p = 2
pList = [True] * (LIMIT + 1)
while p ** 2 <= LIMIT:
if(pList[p]):
for i in range(p * 2, LIMIT + 1 , p):
pList[i] = False
p += 1
# print(pList)
lines = str(sys.stdin.read()).strip().split("\n")
for line in lines:
line = int(li... | vfc_36217 | {
"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": "10\n3\n11",
"output": "4\n2\n5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n3\n5",
"output": "4\n2\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | p00274 A Pair of Prizes | Solve the following coding problem using the programming language python:
Jou and Yae are a good couple. Jou is collecting prizes for capsule toy vending machines (Gachapon), and even when they go out together, when they find Gachapon, they seem to get so hot that they try it several times. Yae was just looking at Jou... | ```python
# AOJ 0279: A Pair of Prizes
# Python3 2018.6.25 bal4u
while True:
n = int(input())
if n == 0: break
k = list(map(int, input().split()))
one, many = 0, 0
for i in k:
if i == 1: one += 1
elif i > 1: many += 1
print(one+many+1 if many > 0 else "NA")
``` | vfc_36225 | {
"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\n3 2\n3\n0 1 1\n1\n1000\n0",
"output": "3\nNA\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3 0\n3\n0 1 1\n1\n1000\n0",
"output": "2\nNA\n2\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | p00462 Pizza | Solve the following coding problem using the programming language python:
problem
JOI Pizza sells pizza home delivery along the d-meter-long ring road that runs through the city center.
JOI Pizza has n stores S1, ..., Sn on the loop line. The head office is S1. The distance from S1 to Si when moving the loop line cl... | ```python
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0539
AC
"""
import sys
from sys import stdin
from bisect import bisect_right
input = stdin.readline
def main(args):
while True:
d = int(input()) # ??°??¶????????????
if d == 0:
break
... | vfc_36229 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n3\n2\n3\n1\n4\n6\n20\n4\n4\n12\n8\n16\n7\n7\n11\n8\n0",
"output": "3\n3",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00652 Cutting a Chocolate | Solve the following coding problem using the programming language python:
Turtle Shi-ta and turtle Be-ko decided to divide a chocolate. The shape of the chocolate is rectangle. The corners of the chocolate are put on (0,0), (w,0), (w,h) and (0,h). The chocolate has lines for cutting. They cut the chocolate only along ... | ```python
# AOJ 1067 Cutting a Chocolate
# Python3 2018.7.10 bal4u
from bisect import bisect_left
while True:
n, m, w, h, S = map(int, input().split())
if n == 0: break
m, wh2 = m+1, 2*(w*h)
S = wh2-2*S
tbl, s = [[0,0,0,0]], [0]
for i in range(1, m):
l, r = map(int, input().split())
tbl.append([l, r, 0, r-l... | vfc_36233 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3 10 10 50\n3 3\n6 6\n10 10\n4.0000000000 4.0000000000\n7.0000000000 7.0000000000\n2 3 10 10 70\n3 3\n6 6\n10 10\n4.0000000000 4.0000000000\n7.0000000000 7.0000000000\n2 3 10 10 30\n3 3\n6 6\n10 10\n4.0000000000 4.0000000000\n7.0... |
code_contests | verifiable_code | p00797 Family Tree | Solve the following coding problem using the programming language python:
A professor of anthropology was interested in people living in isolated islands and their history. He collected their family trees to conduct some anthropological experiment. For the experiment, he needed to process the family trees with a compu... | ```python
while(1):
[n,m]=[int(x) for x in raw_input().split()]
if n==0:
break
else:
familymatrix=[[-100000 for x in range(n)] for y in range(n)]
for i in range(n):
familymatrix[i][i]=0
namedic={}
returned=[0 for x in range(n)]
spacenum=0
s... | vfc_36237 | {
"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": "6 5\nJohn\nRobert\nFrank\nAndrew\nNancy\nDavid\nRobert is a child of John.\nRobert is an ancestor of Andrew.\nRobert is a sibling of Nancy.\nNancy is the parent of Frank.\nJohn is a descendant of Andrew.\n2 1\nabc\nxyz\nxyz is a ch... |
code_contests | verifiable_code | p00928 Automotive Navigation | Solve the following coding problem using the programming language python:
Example
Input
4 2 1 1
1 1 1 2
2 2 2 1
2 2 1 2
1 1 2 1
9 N
Output
1 1
2 2
The input will be given via stdin and the output should be printed to stdout by your code.
Now solve the problem by providing the code. | ```python
# coding: utf-8
import sys
sys.setrecursionlimit(50000000)
max_c=101
vec=[(0,2),(2,0),(0,-2),(-2,0)]
try:
while True:
log=[-1 for i in range(10001)]
n,x0,y0,t=map(int,input().split())
field=[[0 for i in range(max_c)]for i in range(max_c)]
for i in range(n):
a,b,... | vfc_36241 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2 1 1\n1 1 1 2\n2 2 2 1\n2 2 1 2\n1 1 2 1\n9 N",
"output": "1 1\n2 2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2 1 1\n1 1 1 2\n2 2 2 1\n2 2 1 2\n1 1 2 1\n17 N",
"output": "1 ... |
code_contests | verifiable_code | p01193 First Experience | Solve the following coding problem using the programming language python:
After spending long long time, you had gotten tired of computer programming. Instead you were inter- ested in electronic construction. As your first work, you built a simple calculator. It can handle positive integers of up to four decimal digit... | vfc_36249 | {
"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": "1+2+3+4+5+6+7+8+9+10=\n1000-500-250-125=\n1*2*3*4*5*6=\n5000*5000=\n10-100=\n100*100=\n10000=",
"output": "55\n125\n720\nE\nE\nE\nE",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01331 Warp Hall | Solve the following coding problem using the programming language python:
In 20XX, an efficient material transfer method was established for distant places, and human beings' advance into space was accelerated more and more. This transfer method was innovative in that, in principle, larger substances could be transfer... | vfc_36253 | {
"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": "1 1 0",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5 3\n4 4 5 5\n2 2 3 3\n3 3 4 4",
"output": "18",
"type": "stdin_stdout"
},
{
"fn_name": null,... | |
code_contests | verifiable_code | p01498 King Slime | Solve the following coding problem using the programming language python:
There is a grid of size W × H surrounded by walls. Some cells in the grid are occupied by slimes. The slimes want to unite with each other and become a "King Slime".
In each move, a slime can move to east, west, south and north direction until ... | ```python
import sys
class UnionFind:
def __init__(self,sz):
self.__ranks = [1] * sz
self.__parents = [ i for i in range(sz) ]
def find_parent(self, x):
if x == self.__parents[x]:
return x
else:
self.__parents[x] = self.find_parent(self.__parents[x])
... | vfc_36257 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3 3\n2 2\n3 3",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3 3\n1 1\n1 3\n3 1\n3 3",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | p01946 Slimming Plan | Solve the following coding problem using the programming language python:
Chokudai loves eating so much. However, his doctor Akensho told him that he was overweight, so he finally decided to lose his weight.
Chokudai made a slimming plan of a $D$-day cycle. It is represented by $D$ integers $w_0, ..., w_{D-1}$. His w... | ```python
S, T, D = map(int, input().split())
S -= T
*W, = map(int, input().split())
F = sum(W)
if F >= 0:
su = S
for i, w in enumerate(W):
su += w
if su <= 0:
print(i+1)
break
else:
print(-1)
exit(0)
su = 0
mi = 0
for d in W:
su += d
mi = min(mi, ... | vfc_36269 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100000 1 1\n-1",
"output": "99999",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "65 60 3\n-2 3 -4",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | p02095 Colorful Tree | Solve the following coding problem using the programming language python:
H: Colorful Tree
Story
Yamiuchi (assassination) is a traditional event that is held annually in JAG summer camp. Every team displays a decorated tree in the dark and all teams' trees are compared from the point of view of their colorfulness. I... | vfc_36273 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 10\n1 2\n1 9\n8 7",
"output": "2\n1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 10\n1 2\n1 9\n6 7",
"output": "2\n1\n",
"type": "stdin_stdout"
},
{
"fn_name... | |
code_contests | verifiable_code | p02233 Fibonacci Number | Solve the following coding problem using the programming language python:
Write a program which prints $n$-th fibonacci number for a given integer $n$. The $n$-th fibonacci number is defined by the following recursive formula:
\begin{equation*} fib(n)= \left \\{ \begin{array}{ll} 1 & (n = 0) \\\ 1 & (n = 1) \\\ fib(n... | ```python
n = int(input())
num = [1,1]
for i in range(2,45):
f = num[i - 1] + num[i - 2]
num.append(f)
print(num[n])
``` | vfc_36277 | {
"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",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2",
"output... |
code_contests | verifiable_code | p02379 Distance | Solve the following coding problem using the programming language python:
Write a program which calculates the distance between two points P1(x1, y1) and P2(x2, y2).
Input
Four real numbers x1, y1, x2 and y2 are given in a line.
Output
Print the distance in real number. The output should not contain an absolute ... | ```python
x1,y1,x2,y2=map(float,input().split())
n=((x1-x2)**2+(y1-y2)**2)**(1/2)
print('{:.8f}'.format(n))
``` | vfc_36281 | {
"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": "0 0 1 1",
"output": "1.41421356",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 0 1 2",
"output": "2.2360679775\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | cd202 | Solve the following coding problem using the programming language python:
Brachiosaurus is trying to become a detective by writing words in codes. It manipulates each word in a sentence by putting the letter 'z' after each vowel, followed by that very vowel.
Eg- "belina" translates into "bezelizinaza" and "zazhiba" t... | ```python
# imports
import sys
import StringIO
class Problem(object):
def __init__(self, reader):
self.reader = reader
def run(self):
vowels = frozenset(["a", "e", "i", "o", "u"])
last_vowel_block = -1
# decode the message, by replacing the vowel pat... | vfc_36285 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "razat geze hozotazamnaza ozoraza bezehizisaza",
"output": "rat ge hotamna ora behisa\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | cw1 | Solve the following coding problem using the programming language python:
While Tom Cruise(Cage) fighting in the movie "Edge of Tomorrow", he finds himself in a modern lab, where he needs to kill the brain of a mutant species Omega.
The DNA of the Omega is made up of characters of A, T, G and C like ours. He has certa... | ```python
import sys
t=input()
str1=raw_input()
for _ in range(t):
ss=raw_input()
str1=str1.replace(ss, "")
if(len(str1)==0):
print '0'
else:
print str1
``` | vfc_36289 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nATGCATGCATCGACTCAGCATCAGCATCGACTA\nTG\nGC\nAT",
"output": "ACACCGACTCACACGACTA\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\nATACGCATGACGATGCATGCAGCAT\nATA\nGC",
"output": "C... |
code_contests | verifiable_code | icq1 | Solve the following coding problem using the programming language python:
The success of IEEE code-quest depends on number of times the factor is present in a given string.Help core members to find them
Factor of string is defined as a substring.In this case it's '01'.
Input
First line of input contains an integer T... | ```python
'''
Coded by Abhishek The Hacktivist
'''
test = int(raw_input())
for i in range(test):
count = 0
num = str(raw_input().split())
for j in range(len(num)):
if (num[j] == '0') and (num[j+1] == '1'):
count += 1
print count
``` | vfc_36293 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n1001010100001",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1001010110001",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | mqry | Solve the following coding problem using the programming language python:
One day maths teacher gave the following task for the students, only upon completion students will be taken out for a school fun trip.
First you are a given a list of n numbers and q queries. For each query you are given two indices x and y , yo... | ```python
dic={}
n, q = map(int, raw_input().split())
li = map(int, raw_input().split())
for i in xrange(q):
l, r = map(int, raw_input().split())
tli=li[l:r+1]
s=str(l) + '+' + str(r)
if s not in dic:
dic[s] = max(tli) - min(tli)
print dic[s]
``` | vfc_36297 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n1 2 3 4 5\n1 2\n4 4",
"output": "1\n0",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | reverse | Solve the following coding problem using the programming language python:
Sometimes mysteries happen. Chef found a directed graph with N vertices and M edges in his kitchen!
The evening was boring and chef has nothing else to do, so to entertain himself, Chef thought about a question "What is the minimum number of ed... | ```python
from sys import stdin
from heapq import heappush, heappop
def v_con(M, graph, N):
while M > 0:
a, b = map(int, stdin.readline().split())
graph[a][b] = 0
if not graph[b].has_key(a):
if a == 1 and b == N:
graph[b][a] = 1
elif a != 1:
graph[b][a] = 1
M = M - 1
return graph
def relax(G, ... | vfc_36301 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 7\n1 2 \n3 2\n3 4\n7 4\n6 2\n5 6\n7 5",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 7\n1 2 \n4 2\n3 4\n7 4\n6 2\n5 6\n7 5",
"output": "2\n",
"type": "stdin... |
code_contests | verifiable_code | twtclose | Solve the following coding problem using the programming language python:
Little kids, Jack and Evan like playing their favorite game Glass-and-Stone. Today they want to play something new and came across Twitter on their father's laptop.
They saw it for the first time but were already getting bored to see a bunch of... | ```python
# your code goes here
n,k=map(int,raw_input().split())
a=[0 for i in range(n)]
cou=0
for i in range(k):
t=raw_input().split()
if len(t)==1:
for j in range(n):
a[j]=0
cou=0
else:
x=int(t[1])-1
a[x]^=1
if a[x]==0:
cou-=1
else:
cou+=1
print cou
``` | vfc_36305 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 6\nCLICK 1\nCLICK 2\nCLICK 3\nCLICK 2\nCLOSEALL\nCLICK 1",
"output": "1\n2\n3\n2\n0\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 6\nCLICK 1\nCLICK 2\nCLICK 3\nCLICK 2\nCLOSEALL\n... |
code_contests | verifiable_code | 1019_B. 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
# this sequence is a bit scary
# 8
# 1 2 3 2 3 2 1 0
import sys
#sys.stdin=open("data.txt")
#input=sys.stdin.readline
got=[10**18]*100005
def getnum(i):
if got[i]==10**18:
print("? %d"%i)
sys.stdout.flush()
got[i]=int(input())
return got[i]
n=int(input())
if n%4==2:
# ... | vfc_36309 | {
"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": "6\n<span class=\"tex-span\"></span>\n1\n<span class=\"tex-span\"></span>\n2\n<span class=\"tex-span\"></span>\n3 \n<span class=\"tex-span\"></span>\n2\n<span class=\"tex-span\"></span>\n1\n<span class=\"tex-span\"></span>\n0",
... |
code_contests | verifiable_code | 1042_A. Benches | Solve the following coding problem using the programming language python:
There are n benches in the Berland Central park. It is known that a_i people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available.
Let k be th... | ```python
import math
n=int(input())
m=int(input())
a=[]
for i in range(n):
a.append(int(input()))
maxa=max(a)+m
mina=max(max(a),math.ceil((sum(a)+m)/n))
print(str(mina)+" "+str(maxa))
``` | vfc_36313 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n6\n1\n1\n1\n1\n",
"output": "3 7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n10\n5\n",
"output": "15 15\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | 1064_F. Candies for Children | Solve the following coding problem using the programming language python:
At the children's festival, children were dancing in a circle. When music stopped playing, the children were still standing in a circle. Then Lena remembered, that her parents gave her a candy box with exactly k candies "Wilky May". Lena is not ... | vfc_36317 | {
"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": "4 1 4 12\n",
"output": " 2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 5 5 1\n",
"output": " ... | |
code_contests | verifiable_code | 1086_D. Rock-Paper-Scissors Champion | Solve the following coding problem using the programming language python:
n players are going to play a rock-paper-scissors tournament. As you probably know, in a one-on-one match of rock-paper-scissors, two players choose their shapes independently. The outcome is then determined depending on the chosen shapes: "pape... | vfc_36321 | {
"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 5\nRPS\n1 S\n2 R\n3 P\n1 P\n2 P\n",
"output": "2\n2\n1\n2\n2\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 0\nS\n",
"output": "1\n",
"type": "stdin_stdout"
},
... | |
code_contests | verifiable_code | 1106_D. Lunar New Year and a Wander | Solve the following coding problem using the programming language python:
Lunar New Year is approaching, and Bob decides to take a wander in a nearby park.
The park can be represented as a connected graph with n nodes and m bidirectional edges. Initially Bob is at the node 1 and he records 1 on his notebook. He can w... | ```python
from heapq import heappush, heappop
n,m = map(int,input().split())
adj = [[] for _ in range(n)]
for _ in range(m):
a,b = map(int,input().split())
a-=1
b-=1
adj[a].append(b)
adj[b].append(a)
st = set()
hp = []
v = [False for _ in range(n)]
heappush(hp,0)
v[0] = True
ans = []
while hp:
... | vfc_36325 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n1 2\n1 3\n",
"output": "1 2 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 10\n1 4\n6 8\n2 5\n3 7\n9 4\n5 6\n3 4\n8 10\n8 9\n1 10\n",
"output": "1 4 3 7 9 8 6 5 2 10 ",
... |
code_contests | verifiable_code | 1133_E. K Balanced Teams | Solve the following coding problem using the programming language python:
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i.
You have to form k teams for yet another new programming competition. As you know, the more students are in... | ```python
kk=lambda:map(int,input().split())
ll=lambda:list(kk())
n,k= kk()
ls = sorted(ll())
vs,ne = [0]*n,[-1]*n
b = 0
for a in range(n):
while b < n and ls[b] - ls[a] < 6: b+=1
vs[a],ne[a] = b-a, b
curr = [0]*(n+1)
# print(vs)
for _ in range(k):
# print(curr)
prev = curr
curr = [0]*(n+1)
for i in range(n):
c... | vfc_36329 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4\n1 10 100 1000\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 1\n36 4 1 25 9 16\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name"... |
code_contests | verifiable_code | 1154_B. Make Them Equal | Solve the following coding problem using the programming language python:
You are given a sequence a_1, a_2, ..., a_n consisting of n integers.
You can choose any non-negative integer D (i.e. D ≥ 0), and for each a_i you can:
* add D (only once), i. e. perform a_i := a_i + D, or
* subtract D (only once), i. e. ... | ```python
n = int(input())
L = [int(i) for i in input().split()]
F = []
mi = 101
ma = 0
for i in L:
if i not in F:
F.append(i)
if len(F) > 3:
print(-1)
else:
F.sort()
if len(F) == 3:
D = F[1] - F[0]
if F[2] - F[1] == D:
print(D)
else:
print(-1)
... | vfc_36333 | {
"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\n2 8\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1175_G. Yet Another Partiton Problem | Solve the following coding problem using the programming language python:
You are given array a_1, a_2, ..., a_n. You need to split it into k subsegments (so every element is included in exactly one subsegment).
The weight of a subsegment a_l, a_{l+1}, ..., a_r is equal to (r - l + 1) ⋅ max_{l ≤ i ≤ r}(a_i). The weig... | vfc_36337 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4\n5 1 5 1 5\n",
"output": "21\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1194_F. Crossword Expert | Solve the following coding problem using the programming language python:
Today Adilbek is taking his probability theory test. Unfortunately, when Adilbek arrived at the university, there had already been a long queue of students wanting to take the same test. Adilbek has estimated that he will be able to start the te... | ```python
mod = 10 ** 9 + 7
MAX = 2 * 10 ** 5+2
r = [1] * MAX
factorial = [1] * MAX
rfactorial = [1] * MAX
rp = [1] * MAX
#Permite precalcular factorial hasta "MAX", para evitar tener que calcularlo varias veces
#dentro de la ejecucion del programa.
for i in range(2, MAX):
factorial[i] = i * factorial[i - 1... | vfc_36341 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\n2 2 2\n",
"output": "750000007\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 5\n2 1 2\n",
"output": "125000003\n",
"type": "stdin_stdout"
},
{
"fn_name":... |
code_contests | verifiable_code | 1211_C. Ice Cream | Solve the following coding problem using the programming language python:
Summer in Berland lasts n days, the price of one portion of ice cream on the i-th day is c_i. Over the summer, Tanya wants to eat exactly k portions of ice cream. At the same time, on the i-th day, she decided that she would eat at least a_i por... | vfc_36345 | {
"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": "3 7\n3 5 6\n0 3 4\n3 3 3\n",
"output": "\n31\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 45000\n40000 50000 100000\n",
"output": "\n4500000000\n",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | 1234_B1. Social Network (easy version) | Solve the following coding problem using the programming language python:
The only difference between easy and hard versions are constraints on n and k.
You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most k most recent conversations with your friends. Initiall... | ```python
def line():
return map(int, input().split())
def num():
return int(input())
from collections import OrderedDict as od
n,k = line()
ids = list(line())
screen = od()
for id in ids:
if id not in screen:
if len(screen)==k:
screen.popitem(last=False)
screen[id]=None
print... | vfc_36349 | {
"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": "10 4\n2 3 3 1 1 2 1 2 3 3\n",
"output": "3\n1 3 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 2\n1 2 3 2 1 3 2\n",
"output": "2\n2 1\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 1252_L. Road Construction | Solve the following coding problem using the programming language python:
There are N cities in the country of Numbata, numbered from 1 to N. Currently, there is no road connecting them. Therefore, each of these N cities proposes a road candidate to be constructed.
City i likes to connect with city A_i, so city i pro... | vfc_36353 | {
"difficulty": "19",
"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 5\n2 2 1 2\n3 2 2 3\n4 2 3 4\n2 2 4 5\n1 2 3 4 5\n",
"output": "\n1 2\n2 3\n3 4\n0 0\n4 2\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 131_F. Present to Mom | Solve the following coding problem using the programming language python:
How many stars are there in the sky? A young programmer Polycarpus can't get this question out of his head! He took a photo of the starry sky using his digital camera and now he analyzes the resulting monochrome digital picture. The picture is r... | vfc_36365 | {
"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 5 4\n11111\n11111\n11111\n11111\n11111\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 6 2\n111000\n111100\n011011\n000111\n",
"output": "6\n",
"type": "st... | |
code_contests | verifiable_code | 1339_C. Powered Addition | Solve the following coding problem using the programming language python:
You have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second:
* Select some distinct indices i_{1}, i_{2}, …, i_{k} which are between 1 and n inclusive, and add 2^{x-1} ... | ```python
import math
n = int(input())
for i in range(n):
m = int(input())
nums = [int(i) for i in input().split()]
highest = nums[0]
mostDiff = 0
for j in range(len(nums)):
if highest - nums[j] > mostDiff:
mostDiff = highest - nums[j]
if nums[j] > highest:
hi... | vfc_36369 | {
"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\n4\n1 7 6 5\n5\n1 2 3 4 5\n2\n0 -4\n",
"output": "2\n0\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n3\n1000000000 0 -1000000000\n1\n6\n2\n-1000000000 1000000000\n2\n1000000000 -... |
code_contests | verifiable_code | 1360_G. A/B Matrix | Solve the following coding problem using the programming language python:
You are given four positive integers n, m, a, b (1 ≤ b ≤ n ≤ 50; 1 ≤ a ≤ m ≤ 50). Find any such rectangular matrix of size n × m that satisfies all of the following conditions:
* each row of the matrix contains exactly a ones;
* each colum... | ```python
for q in range(int(input())):
n, m, a, b = map(int, input().split())
if n*a != m*b:
print('NO')
continue
print('YES')
t = '1'*a+'0'*(m-a)
for i in range(n):
print(t)
t = t[m-a:]+t[:m-a]
``` | vfc_36373 | {
"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": "5\n3 6 2 1\n2 2 2 1\n2 2 2 2\n4 4 2 2\n2 1 1 2\n",
"output": "YES\n110000\n001100\n000011\nNO\nYES\n11\n11\nYES\n1100\n0011\n1100\n0011\nYES\n1\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | 1401_A. Distance and Axis | Solve the following coding problem using the programming language python:
We have a point A with coordinate x = n on OX-axis. We'd like to find an integer point B (also on OX-axis), such that the absolute difference between the distance from O to B and the distance from A to B is equal to k.
<image> The description o... | ```python
for _ in range(int(input())):
n, k = map(int, input().split())
if n<k:print(k-n)
elif n%2 == k%2: print(0)
else: print(1)
``` | vfc_36381 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n4 0\n5 8\n0 1000000\n0 0\n1 0\n1000000 1000000\n",
"output": "0\n3\n1000000\n0\n1\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n5 0\n",
"output": "1\n",
"type": "std... |
code_contests | verifiable_code | 1424_H. Lookup Tables | Solve the following coding problem using the programming language python:
John has Q closed intervals of consecutive 2K-bit numbers [l_i, r_i] and one 16-bit value v_i for each interval. (0 ≤ i < Q)
John wants to implement a function F that maps 2K-bit numbers to 16-bit numbers in such a way that inputs from each int... | vfc_36385 | {
"difficulty": "14",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2\n0 2 1\n3 3 3\n",
"output": "possible\n1\n3\n1\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n4 4 3\n5 6 2\n12 14 1\n",
"output": "impossible\n",
"type": "stdin_st... | |
code_contests | verifiable_code | 1445_D. Divide and Sum | Solve the following coding problem using the programming language python:
You are given an array a of length 2n. Consider a partition of array a into two subsequences p and q of length n each (each element of array a should be in exactly one subsequence: either in p or in q).
Let's sort p in non-decreasing order, and... | ```python
def ncr(n, r, p):
# initialize numerator
# and denominator
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den,
p - 2, p)) % p
n = int(input())
a = sorted(list(map(int, input().split())))
ans = 0
for i in ... | vfc_36389 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n13 8 35 94 9284 34 54 69 123 846\n",
"output": "2588544",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 1 2 1\n",
"output": "12",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 146_D. Lucky Number 2 | Solve the following coding problem using the programming language python:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves long lucky ... | ```python
from math import *
from fractions import *
from sys import *
def li():
return list(map(int, input().split(" ")))
a = li()
if abs(a[2]-a[3]) > 1:
print(-1)
exit()
if a[2] == a[3]:
ans = "47"*a[2]+"4"
elif a[2] > a[3]:
ans = "47"*a[2]
else:
ans = "74"*a[3]
f = a[0]-ans.count("4")
s = a[1]-ans.count(... | vfc_36393 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2 1 1\n",
"output": "4774\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 7 3 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
code_contests | verifiable_code | 1495_F. Squares | Solve the following coding problem using the programming language python:
There are n squares drawn from left to right on the floor. The i-th square has three integers p_i,a_i,b_i, written on it. The sequence p_1,p_2,...,p_n forms a permutation.
Each round you will start from the leftmost square 1 and jump to the rig... | vfc_36397 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4\n2 1 5 3 4\n6 -5 3 -10 -1\n0 3 2 7 2\n1\n2\n3\n2\n",
"output": "\n-8\n-7\n-7\n-8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n2 1 3\n10 -5 4\n3 -2 3\n1\n2\n",
"output": "... | |
code_contests | verifiable_code | 1519_C. Berland Regional | Solve the following coding problem using the programming language python:
Polycarp is an organizer of a Berland ICPC regional event. There are n universities in Berland numbered from 1 to n. Polycarp knows all competitive programmers in the region. There are n students: the i-th student is enrolled at a university u_i... | ```python
for _ in range(int(input())):
n = int(input())
u = list(map(int, input().split()))
s = list(map(int, input().split()))
p = max(u)
l = [[] for i in range(p)]
for i in range(n):
l[u[i]-1].append(s[i])
l.sort(key = len, reverse = True)
for i in range(p):
l[i].sort(... | vfc_36401 | {
"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\n7\n1 2 1 2 1 2 1\n6 8 3 1 5 1 5\n10\n1 1 1 2 2 2 2 3 3 3\n3435 3014 2241 2233 2893 2102 2286 2175 1961 2567\n6\n3 3 3 3 3 3\n5 9 6 7 9 7\n1\n1\n3083\n",
"output": "\n29 28 26 19 0 0 0 \n24907 20705 22805 9514 0 0 0 0 0 0 \... |
code_contests | verifiable_code | 1546_C. AquaMoon and Strange Sort | Solve the following coding problem using the programming language python:
AquaMoon has n friends. They stand in a row from left to right, and the i-th friend from the left wears a T-shirt with a number a_i written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is rig... | ```python
from math import *
from collections import defaultdict as dt
from sys import stdin
inp = lambda : stdin.readline().strip()
I = lambda : int(inp())
M = lambda : map(int,inp().split())
L = lambda : list(M())
mod = 1000000007
inf = 100000000000000000000
ss = "abcdefghijklmnopqrstuvwxyz"
############## Al... | vfc_36405 | {
"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\n4\n4 3 2 5\n4\n3 3 2 2\n5\n1 2 3 5 4\n",
"output": "YES\nYES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n64\n8 7 7 2 4 9 3 7 9 4 7 10 6 7 6 4 9 9 10 2 2 2 10 3 8 9 3 1 5 10 6... |
code_contests | verifiable_code | 173_D. Deputies | Solve the following coding problem using the programming language python:
The Trinitarian kingdom has exactly n = 3k cities. All of them are located on the shores of river Trissisipi, which flows through the whole kingdom. Some of the cities are located on one side of the river, and all the rest are on the other side.... | vfc_36409 | {
"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 1\n1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 6\n1 2\n4 1\n3 5\n6 5\n2 6\n4 6\n",
"output": "YES\n1 2 1 2 2 1 \n",
"type": "stdin_stdout"
},
... | |
code_contests | verifiable_code | 193_E. Fibonacci Number | Solve the following coding problem using the programming language python:
John Doe has a list of all Fibonacci numbers modulo 1013. This list is infinite, it starts with numbers 0 and 1. Each number in the list, apart from the first two, is a sum of previous two modulo 1013. That is, John's list is made from the Fibon... | ```python
low_n = 1000
high_m = 15000
limit = int(10 ** 13)
f = int(input())
inputList = []
def customFunction(i):
if i == 0:
return (0, 1)
a, b = customFunction(i >> 1)
a, b = ((2 * a * b - a * a) % low_n, (b * b + a * a) % low_n)
if i & 1:
a, b = (b % low_n, (a + b) % low_n)
ret... | vfc_36413 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "13\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "377\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5382450... |
code_contests | verifiable_code | 217_E. Alien DNA | Solve the following coding problem using the programming language python:
Professor Bajtocy is conducting experiments on alien DNA. He has discovered that it is subject to repetitive mutations — each mutation happens in the same way: some continuous subsequence of the alien DNA becomes active, copies itself, the copy ... | vfc_36417 | {
"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": "ACGTACGT\n16\n2\n1 2\n2 8\n",
"output": "ACCAGTACCGACATCG\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "GAGA\n4\n0\n",
"output": "GAGA\n",
"type": "stdin_stdout"
},
{... | |
code_contests | verifiable_code | 241_D. Numbers | Solve the following coding problem using the programming language python:
You have a sequence of n distinct integers a1, a2, ..., an (1 ≤ ai ≤ n). You want to remove some integers in such a way that the resulting sequence of integers satisfies the following three conditions:
1. the resulting sequence is not empty; ... | vfc_36421 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\n1 2 3\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n1 2 3\n",
"output": "Yes\n3\n1 2 3 \n",
"type": "stdin_stdout"
},
{
"fn_name": n... | |
code_contests | verifiable_code | 266_C. Below the Diagonal | Solve the following coding problem using the programming language python:
You are given a square matrix consisting of n rows and n columns. We assume that the rows are numbered from 1 to n from top to bottom and the columns are numbered from 1 to n from left to right. Some cells (n - 1 cells in total) of the the matri... | ```python
import os
from io import BytesIO, IOBase
import sys
def main():
n = int(input())
row = [0] * n
col = [0] * n
a = [[0 for j in range(n)] for i in range(n)]
for i in range(n - 1):
x, y = map(int, input().split())
row[x - 1] += 1
col[y - 1] += 1
a[x - 1][y - 1... | vfc_36425 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 1\n1 3\n",
"output": "3\n2 2 3\n1 1 3\n1 1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 2\n",
"output": "2\n2 1 2\n1 1 2\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 28_C. Bath Queue | Solve the following coding problem using the programming language python:
There are n students living in the campus. Every morning all students wake up at the same time and go to wash. There are m rooms with wash basins. The i-th of these rooms contains ai wash basins. Every student independently select one the rooms ... | ```python
import sys
MAX_N = 55
line = list(map(int, sys.stdin.readline().split(" ")))
studc = line[0]
roomc = line[1]
arr = list(map(int, sys.stdin.readline().split(" ")))
ncr = [[0 for i in range(MAX_N)] for j in range(MAX_N)]
ncr[0][0] = 1
for i in range(1, MAX_N):
ncr[i][0] = 1;
for j in range(1, MAX_N)... | vfc_36429 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n1 1\n",
"output": "1.500000000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n1 1 1\n",
"output": "1.333333333333333\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 315_C. Sereja and Contest | Solve the following coding problem using the programming language python:
During the last Sereja's Codesecrof round the server crashed many times, so the round was decided to be made unrated for some participants.
Let's assume that n people took part in the contest. Let's assume that the participant who got the firs... | ```python
n, k = map(int, input().split())
arr = map(int, input().split())
s, j, all_res = 0, 0, []
for i, q in enumerate(arr, 1):
if s - j * (n - i) * q < k:
all_res.append(str(i))
else:
s += q * j
j += 1
print('\n'.join(all_res))
``` | vfc_36433 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 0\n5 3 4 1 2\n",
"output": "2\n3\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 -10\n5 5 1 7 5 1 2 4 9 2\n",
"output": "2\n4\n5\n7\n8\n9\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 337_E. Divisor Tree | Solve the following coding problem using the programming language python:
A divisor tree is a rooted tree that meets the following conditions:
* Each vertex of the tree contains a positive integer number.
* The numbers written in the leaves of the tree are prime numbers.
* For any inner vertex, the number wi... | vfc_36437 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 0, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n6 72 8 4\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.