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 | 331_B1. Shave Beaver! | Solve the following coding problem using the programming language python:
The Smart Beaver has recently designed and built an innovative nanotechnologic all-purpose beaver mass shaving machine, "Beavershave 5000". Beavershave 5000 can shave beavers by families! How does it work? Very easily!
There are n beavers, each... | vfc_51013 | {
"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 4 2 5\n6\n1 1 5\n1 3 4\n2 2 3\n1 1 5\n2 1 5\n1 1 5\n",
"output": "2\n1\n3\n5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 3 4 2 5\n6\n1 1 5\n1 3 4\n2 2 3\n1 1 5\n2 1 5\n1 2 ... | |
code_contests | verifiable_code | 353_A. Domino | Solve the following coding problem using the programming language python:
Valera has got n domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper... | ```python
n=int(input())
(eo,sl,su)=(0,0,0)
for i in range(0,n):
(a,b)=map(int,input().split(" "))
sl=sl+b
su=su+a
if (a%2==0 and b%2==1)or(a%2==1 and b%2==0):
eo=1
if sl%2==0 and su%2==0:
print(0)
elif((sl%2==1 and su%2==1)):
if eo:
print(1)
else:
print(-1)
else:... | vfc_51017 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 4\n2 3\n4 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n4 2\n6 4\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 377_B. Preparing for the Contest | Solve the following coding problem using the programming language python:
Soon there will be held the world's largest programming contest, but the testing system still has m bugs. The contest organizer, a well-known university, has no choice but to attract university students to fix all the bugs. The university has n ... | ```python
from sys import stdin
import heapq
n,m,s = [int(x) for x in stdin.readline().split()]
bugs = [int(x) for x in stdin.readline().split()]
bugs = sorted([(bugs[x],x) for x in range(m)])
order = [x[1] for x in bugs]
bugs = [x[0] for x in bugs]
students = [int(x) for x in stdin.readline().split()]
rate = [int(... | vfc_51021 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4 10\n2 3 1 2\n2 1 3\n4 3 6\n",
"output": "YES\n1 3 1 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4 9\n2 3 1 2\n2 1 3\n4 3 6\n",
"output": "YES\n3 3 2 3 \n",
"type": ... |
code_contests | verifiable_code | 399_D. Painting The Wall | Solve the following coding problem using the programming language python:
User ainta decided to paint a wall. The wall consists of n2 tiles, that are arranged in an n × n table. Some tiles are painted, and the others are not. As he wants to paint it beautifully, he will follow the rules below.
1. Firstly user ainta... | vfc_51025 | {
"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": "2 2\n1 1\n1 2\n",
"output": "2.0000000000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n2 3\n4 1\n",
"output": "11.7669491886",
"type": "stdin_stdout"
},
{
"... | |
code_contests | verifiable_code | 421_E. Cup Trick | Solve the following coding problem using the programming language python:
The employees of the F company have lots of ways to entertain themselves. Today they invited a famous magician who shows a trick with plastic cups and a marble.
The point is to trick the spectator's attention. Initially, the spectator stands in... | ```python
import io
import os
# List with O(n^1/3) (for n=10**6) get/set/insert/delete based on: https://github.com/cheran-senthil/PyRival/blob/master/pyrival/data_structures/SortedList.py
class UnsortedList:
def __init__(self, iterable=[], _load=200):
"""Initialize sorted list instance."""
value... | vfc_51029 | {
"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": "3 2\n1 2\n1 1\n",
"output": "2 1 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n1 3\n2 3\n1 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": ... |
code_contests | verifiable_code | 448_C. Painting Fence | Solve the following coding problem using the programming language python:
Bizon the Champion isn't just attentive, he also is very hardworking.
Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as n vertical planks, put in a row. Adjacent planks have no gap between... | ```python
import sys
sys.setrecursionlimit(10000) # hago n-1 llamadas recursivas para largo n, por default el limit es 1000 creo
def cantidad_de_brochazos(izq,der,altura):
"""
:param izq: limite izquierdo de la zona a pintar
:param der: limite derecho de la zona a pintar
:param altura: altura hasta la... | vfc_51033 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n5\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 46_D. Parking Lot | Solve the following coding problem using the programming language python:
Nowadays it is becoming increasingly difficult to park a car in cities successfully. Let's imagine a segment of a street as long as L meters along which a parking lot is located. Drivers should park their cars strictly parallel to the pavement o... | ```python
l, b, f = map(int, input().split())
p = [[-b, -b, -192], [l + f, l + f, -38]]
n = int(input())
for i in range(1, n + 1):
a, h = map(int, input().split())
if a == 1:
k = False
for w in range(len(p) - 1):
if p[w + 1][0] - p[w][1] >= b + f + h:
p.insert(w + 1, ... | vfc_51037 | {
"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": "10 1 1\n1\n1 12\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "30 1 2\n6\n1 5\n1 4\n1 5\n2 2\n1 5\n1 4\n",
"output": "0\n6\n11\n17\n23\n",
"type": "stdin_std... |
code_contests | verifiable_code | 492_E. Vanya and Field | Solve the following coding problem using the programming language python:
Vanya decided to walk in the field of size n × n cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates (xi, yi). Vanya moves towards vector (dx, dy). That means that if Vanya is now at the cell (x, y), then... | ```python
n,m,dx,dy = map(int,input().split())
x=y=0
a=[0]*n
c=[0]*n
for i in range(1,n):
x = (x+dx)%n
y = (y+dy)%n
a[x]=y
for i in range(m):
x,y = map(int,input().split())
index = (y-a[x]+n)%n;
c[index] += 1
ans = 0
for i in range(n):
if c[i] > c[ans]: ans = i
print(0, ans)
``` | vfc_51041 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5 2 3\n0 0\n1 2\n1 3\n2 4\n3 1\n",
"output": "0 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3 1 1\n0 0\n0 1\n1 1\n",
"output": "0 0\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 516_D. Drazil and Morning Exercise | Solve the following coding problem using the programming language python:
Drazil and Varda are the earthworm couple. They want to find a good place to bring up their children. They found a good ground containing nature hole. The hole contains many rooms, some pairs of rooms are connected by small tunnels such that ear... | vfc_51045 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3\n2 3 4\n4 5 3\n3 4 2\n5\n1 2 3 4 5\n",
"output": "1\n3\n3\n3\n5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12\n5 9 3\n2 1 7\n11 7 2\n6 5 5\n2 5 3\n6 7 2\n1 4 4\n8 5 7\n1 3 8\... | |
code_contests | verifiable_code | 543_D. Road Improvement | Solve the following coding problem using the programming language python:
The country has n cities and n - 1 bidirectional roads, it is possible to get from every city to any other one if you move only along the roads. The cities are numbered with integers from 1 to n inclusive.
All the roads are initially bad, but t... | ```python
class Graph:
def __init__(self, n_vertices, edges, directed=True, weighted=False):
self.n_vertices = n_vertices
self.edges = edges
self.directed = directed
self.weighted = weighted
@property
def adj(self):
try:
return self._adj
except ... | vfc_51049 | {
"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\n1 1\n",
"output": "4 3 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 2 3 4\n",
"output": "5 8 9 8 5 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 570_A. Elections | Solve the following coding problem using the programming language python:
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage o... | ```python
N, M = [int(x) for x in input().split()]
results = [0] * N
for i in range(M):
city_results = [int(x) for x in input().split()]
city_max = max(city_results)
city_max_idx = city_results.index(city_max)
results[city_max_idx] += 1
max_result = max(results)
max_index = results.index(max_result)... | vfc_51053 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n1 2 3\n2 3 1\n1 2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 613_B. Skills | Solve the following coding problem using the programming language python:
Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly n skills. Each skill is represented by a non-negative integer ai — the... | ```python
n,A,cf,cm,mN = map(int,input().split())
a = list(map(int,input().split()))
aCOPY = []
for elem in a:
aCOPY.append(elem)
a.sort()
aPartialSum = [0]
for elem in a:
aPartialSum.append(aPartialSum[-1] + elem)
maxScore = 0
ansMAXIBound = 0
ansMAXI = 0
ansMIN = 0
for MAXI in range(n + 1):
currentSco... | vfc_51061 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5 10 1 339\n1 3 1\n",
"output": " 35\n 5 ... |
code_contests | verifiable_code | 633_B. A Trivial Problem | Solve the following coding problem using the programming language python:
Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among those great progr... | ```python
from math import log
n = int(input())
def fivetorization(n):
cnt = 0
while n%5==0:
cnt+=1
n//=5
return cnt
res=0
for i in range(5, 500001, 5):
res+=fivetorization(i)
if res==n:
print(5)
print(*[j for j in range(i, i+5)])
quit()
print(0)
``` | vfc_51065 | {
"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\n",
"output": "5\n5 6 7 8 9 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7... |
code_contests | verifiable_code | 661_E. Divisibility Check | Solve the following coding problem using the programming language python:
You are given an array of integers. Check whether there exists a number in this array which is divisible by all other numbers in this array. Output 1, if such a number exists, and 0 otherwise.
Input
The only line of the input contains a list o... | vfc_51069 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 12 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 13\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 685_E. Travelling Through the Snow Queen's Kingdom | Solve the following coding problem using the programming language python:
Gerda is travelling to the palace of the Snow Queen.
The road network consists of n intersections and m bidirectional roads. Roads are numbered from 1 to m. Snow Queen put a powerful spell on the roads to change the weather conditions there. No... | vfc_51073 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4 6\n1 2\n2 3\n3 4\n3 5\n1 3 1 4\n1 3 2 4\n1 4 4 5\n1 4 4 1\n2 3 1 4\n2 2 2 3\n",
"output": "Yes\nYes\nYes\nNo\nNo\nYes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 4 6\n1 2\n2 3\n3... | |
code_contests | verifiable_code | 708_D. Incorrect Flow | Solve the following coding problem using the programming language python:
At the entrance examination for the magistracy of the MSU Cyber-Mechanics Department Sasha got the question about Ford-Fulkerson algorithm. He knew the topic perfectly as he worked with it many times on programming competition. As the task for t... | vfc_51077 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\n2 3 1 1\n3 2 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n1 2 1 1\n2 3 2 2\n1 3 3 3\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 730_A. Toda 2 | Solve the following coding problem using the programming language python:
A group of n friends enjoys playing popular video game Toda 2. There is a rating system describing skill level of each player, initially the rating of the i-th friend is ri.
The friends decided to take part in the championship as a team. But th... | ```python
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 2 13:36:10 2017
@author: savit
"""
def sum1(b):
sum1=0
for i in range(len(b)):
sum1+=b[i][0]
return sum1
n=int(input())
a=list(map(int,input().split()))
if(n!=2):
do=True
b=[]
min2=min(a)
for i in range(n):
a[i]-... | vfc_51081 | {
"difficulty": "7",
"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\n4 5 1 7 4\n",
"output": "1\n8\n01010\n00011\n01010\n10010\n00011\n11000\n00011\n11000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 1 1\n",
"output": "1\n0\n",
"type"... |
code_contests | verifiable_code | 750_G. New Year and Binary Tree Paths | Solve the following coding problem using the programming language python:
The New Year tree is an infinite perfect binary tree rooted in the node 1. Each node v has two children: nodes indexed (2·v) and (2·v + 1).
<image>
Polar bears love decorating the New Year tree and Limak is no exception. As he is only a little... | vfc_51085 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2081719714... | |
code_contests | verifiable_code | 774_E. Big Number and Remainder | Solve the following coding problem using the programming language python:
Stepan has a very big positive integer.
Let's consider all cyclic shifts of Stepan's integer (if we look at his integer like at a string) which are also integers (i.e. they do not have leading zeros). Let's call such shifts as good shifts. For ... | ```python
s = input()
m = int(input())
mn = m
ttt = 0
t = 0
ttt = 1
for i in range(1,len(s)):
ttt = (ttt * 10) % m
for i in range(0,len(s)):
t = (t * 10 + ord(s[i]) - ord('0')) % m
for i in range(0,len(s)):
if s[i] != '0':
mn = min(mn,t)
t = t - (((ord(s[i])- ord('0')) * ttt) % m)
if t < 0:
... | vfc_51089 | {
"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": "521\n3\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5678901234567890123456789\n10000\n",
"output": "123",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 799_E. Aquarium decoration | Solve the following coding problem using the programming language python:
Arkady and Masha want to choose decorations for thier aquarium in Fishdom game. They have n decorations to choose from, each of them has some cost. To complete a task Arkady and Masha need to choose exactly m decorations from given, and they wan... | ```python
try:
R1 = lambda: int(raw_input())
R = lambda: map(int, raw_input().split())
n, m, k = R()
prices = R()
R1()
ais = set(R())
R1()
bis = set(R())
noone_likes = []
a_likes = []
b_likes = []
ab_likes = []
for idx, price in enumerate(prices):
in_ais = ... | vfc_51093 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2 2\n3 2 2 1\n2\n1 2\n3\n4 1 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3 2\n3 2 2 1\n2\n1 2\n2\n1 3\n",
"output": "7\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 819_E. Mister B and Flight to the Moon | Solve the following coding problem using the programming language python:
In order to fly to the Moon Mister B just needs to solve the following problem.
There is a complete indirected graph with n vertices. You need to cover it with several simple cycles of length 3 and 4 so that each edge is in exactly 2 cycles.
W... | ```python
#!/usr/bin/env python3
from collections import defaultdict
DEBUG = False
def main():
if DEBUG:
test()
n = int(input())
paths = cycles(n)
print(len(paths))
for p in paths:
print('%d %s' % (len(p), ' '.join([str(v) for v in p])))
def cycles(n):
"""Builds a set of... | vfc_51097 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n",
"output": "6\n3 1 2 3\n3 1 2 3\n3 1 4 5\n3 1 4 5\n4 4 2 5 3\n4 4 2 5 3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 845_C. Two TVs | Solve the following coding problem using the programming language python:
Polycarp is a great fan of television.
He wrote down all the TV programs he is interested in for today. His list contains n shows, i-th of them starts at moment li and ends at moment ri.
Polycarp owns two TVs. He can watch two different shows ... | ```python
num_shows = int(input())
showtimes = []
for i in range(num_shows):
showtime = [int(i) for i in input().split(" ")]
showtimes.append((showtime[0], showtime[1]))
showtimes = sorted(showtimes)
tv1 = -1
tv2 = -1
start_time = min(st[0] for st in showtimes)
end_time = max(st[1] for st in showtimes)
fai... | vfc_51101 | {
"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\n1 2\n2 3\n2 3\n1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 865_E. Hex Dyslexia | Solve the following coding problem using the programming language python:
Copying large hexadecimal (base 16) strings by hand can be error prone, but that doesn't stop people from doing it. You've discovered a bug in the code that was likely caused by someone making a mistake when copying such a string. You suspect th... | vfc_51105 | {
"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": "0f1e\n",
"output": "00f1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "f1e\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 913_H. Don't Exceed | Solve the following coding problem using the programming language python:
You generate real numbers s1, s2, ..., sn as follows:
* s0 = 0;
* si = si - 1 + ti, where ti is a real number chosen independently uniformly at random between 0 and 1, inclusive.
You are given real numbers x1, x2, ..., xn. You are int... | vfc_51113 | {
"difficulty": "14",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n0.50216\n",
"output": "342677322\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 936_B. Sleepy Game | Solve the following coding problem using the programming language python:
Petya and Vasya arranged a game. The game runs by the following rules. Players have a directed graph consisting of n vertices and m edges. One of the vertices contains a chip. Initially the chip is located at vertex s. Players take turns moving ... | ```python
import sys
data = sys.stdin.readlines()
n, m = map(int, data[0].split())
g = {}
for i, line in enumerate(data[1:-1], 1):
g[i] = list(map(int, line.split()[1:]))
mk = {}
start = int(data[-1])
queue = [(start, 0, -1, 1)]
cycle = False
while len(queue) > 0:
v, player, prev, color = queue.pop()
if c... | vfc_51117 | {
"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 6\n2 2 3\n2 4 5\n1 4\n1 5\n0\n1\n",
"output": "Win\n1 2 4 5 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n1 3\n1 1\n0\n2\n",
"output": "Lose\n",
"type": "stdin_stdout... |
code_contests | verifiable_code | 961_G. Partitions | Solve the following coding problem using the programming language python:
You are given a set of n elements indexed from 1 to n. The weight of i-th element is wi. The weight of some subset of a given set is denoted as <image>. The weight of some partition R of a given set into k subsets is <image> (recall that a parti... | ```python
def divisors(M):
d=[]
i=1
while M>=i**2:
if M%i==0:
d.append(i)
if i**2!=M:
d.append(M//i)
i=i+1
return d
def popcount(x):
x = x - ((x >> 1) & 0x55555555)
x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
x = (x + (x >> 4)) & 0x... | vfc_51121 | {
"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 2\n1 2 3 4 5\n",
"output": "645\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n2 3 2 3\n",
"output": "160\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 98_A. Help Victoria the Wise | Solve the following coding problem using the programming language python:
Vasilisa the Wise from a far away kingdom got a present from her friend Helga the Wise from a farther away kingdom. The present is a surprise box, yet Vasilisa the Wise doesn't know yet what the surprise actually is because she cannot open the b... | ```python
from functools import reduce
def factorial(n):
return reduce(lambda x, y: x*y, range(1,n+1))
colors = {
'R' : 0,
'O' : 0,
'Y' : 0,
'G' : 0,
'B' : 0,
'V' : 0
}
for c in list(input()):
colors[c] += 1
amount = list(reversed(sorted([(colors[key], key) for key in colors])))
amo... | vfc_51125 | {
"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": "YYYYYY\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | anagrams-revisited-26 | Solve the following coding problem using the programming language python:
Arnab is a robber and he has managed to rob N different strings from Akash. Now he decides to sell these strings in the market to make some profit. But, of all the strings he has, he wants to find the size of the largest anagram group so that he... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
n = int(raw_input())
d = dict()
for i in range(n):
s = raw_input()
x = ''.join(sorted(s))
if not d.has_key(x):
d[x]=1
else:
d[x]+=1
max = -1
for j in d.values():
if j... | vfc_51129 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\nab\nba\ncab\nbca\ncba\n\nSAMPLE",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\naa\nba\ncab\nbca\ncba\n\nSAMPLE",
"output": "3\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | center-in-mass-2 | Solve the following coding problem using the programming language python:
You are studying a swarm of N fireflies. Each firefly is moving in a straight line at a constant speed. You are standing at the center of the universe, at position (0, 0, 0). Each firefly has the same mass, and you want to know how close the cen... | ```python
import math
def cross(a, b):
c = [float(a[1])*float(b[2]) - float(a[2])*float(b[1]),
float(a[2])*float(b[0]) - float(a[0])*float(b[2]),
float(a[0])*float(b[1]) - float(a[1])*float(b[0])]
return c
def modulo(a):
b=float(a[0])*float(a[0])+float(a[1])*float(a[1])+float(a[2])*float(a[... | vfc_51133 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3\n3 0 -4 0 0 3\n-3 -2 -1 3 0 0\n-3 -1 2 0 3 0\n\nSAMPLE",
"output": "Case #1: 0.00000000 1.00000000",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | dice-rolls | Solve the following coding problem using the programming language python:
You have an unbiased dice which you want to keep rolling until you get N consecutive even numbers. You've rolled the dice M times and surprisingly, all rolls resulted in even numbers. What is the expected number of additional rolls needed until ... | ```python
t = input()
while t > 0:
a = raw_input()
c,d = a.split()
ans = 0
c = int(c)
d = int(d)
y = 1
z = 1
for i in range (c):
y = y*2
for i in range (d):
z = z*2
ans=y-z
ans=2*ans
print(str(ans)+'.00')
t = t-1
``` | vfc_51137 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 0\n2 1\n3 3\n3 2\n\nSAMPLE",
"output": "6.00\n4.00\n0.00\n8.00\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "25\n6 6\n20 7\n17 8\n11 9\n23 9\n22 19\n2 1\n10 8\n20 20\n5 4\n9 8\n4 4\... |
code_contests | verifiable_code | gemy-anmol | Solve the following coding problem using the programming language python:
Anmol likes gems very much.
He has N packets of gems, here the ith packet contains Pi gems. You need to find the minimal number of packets Anmol needs to take to his trip to Market, if he wants to eat there at least M gems. Note that gems are al... | ```python
def find_min(t,sum1,items):
items.sort()
i = t-1
sumz = 0
m = sum1
count = 0
while i>=0:
sumz += items[i]
count += 1
if(sumz>=m):
return (count)
break
i -= 1
if i == -1:
return (-1)
if __name__=='__m... | vfc_51141 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 8\n2 1 7 3\n6 12\n4 3 1 5 6 2\n\nSAMPLE",
"output": "2\n3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n4 7\n1 2 3 4\n5 5456\n200 867 3543 664 787\n4 78946\n6763 50000 15000 14454"... |
code_contests | verifiable_code | lazy-verma-2 | Solve the following coding problem using the programming language python:
Verma has got 2 arrays of integer numbers. He wished to find the sum of product of all numbers in first array with all the
numbers in second array.
i.e suppose 1st array A[] contains N numbers and 2nd array B[] contains m numbers.
He wished to... | ```python
line=raw_input().split(' ')
a=int(line[0])
b=int(line[1])
line1 = raw_input().split(' ')
line2 = raw_input().split(' ')
sum1=0
sum2=0
for i in range(0,a):
sum1 = sum1 + int( line1[i])
for j in range(0,b):
sum2 += int(line2[j])
print sum1*sum2
``` | vfc_51145 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n1 2\n3 4\n\nSAMPLE",
"output": "21\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | monk-at-the-graph-factory | Solve the following coding problem using the programming language python:
Our Code Monk recently learnt about Graphs and is very excited!
He went over to the Graph-making factory to watch some freshly prepared graphs. Incidentally, one of the workers at the factory was ill today, so Monk decided to step in and do h... | ```python
print "Yes" if (2*(input()-1)-sum(list(map(int,raw_input().split())))==0) else "No"
``` | vfc_51149 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 1\n\nSAMPLE",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13\n679 770 263 520 986 290 945 866 541 246 509 319 871",
"output": "No\n",
"type": "stdin_s... |
code_contests | verifiable_code | permutation-swaps | Solve the following coding problem using the programming language python:
Kevin has a permutation P of N integers 1, 2, ..., N, but he doesn't like it. Kevin wants to get a permutation Q.
Also he believes that there are M good pairs of integers (ai , bi). Kevin can perform following operation with his permutation:
Sw... | ```python
def dfs(v):
global mark,c_c
q=[]
q.append(v)
while q:
top=q.pop()
mark[top]=c_c
for j in G[top]:
if mark[j]==-1:
q.append(j)
mark[j]=mark[top]
#d[c_c]=s
t=input()
while t!=0:
n,m=map(int,raw_input... | vfc_51153 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 1\n1 3 2 4\n1 4 2 3\n3 4\n4 1\n1 3 2 4\n1 4 2 3\n2 4\n\nSAMPLE",
"output": "NO\nYES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n72 74\n7 29 51 54 24 27 70 46 49 21 1 65 10 11 4 ... |
code_contests | verifiable_code | roy-and-rangoli-1 | Solve the following coding problem using the programming language python:
Its Diwali time and little Roy thought of an interesting design for Rangoli.
He created an N x N grid. Roy fills some of the cells of grid with red color.
Cell located at ith row and jth column is colored if i+j is prime. Consider Zero-based nu... | ```python
def sieve(n):
is_prime = [True] * (n+1)
is_prime[0] = is_prime[1] = False
for i in range(2, n+1):
if is_prime[i]:
for j in range(i+i, n+1, i):
is_prime[j] = False
return is_prime
n = int(raw_input())
is_prime = sieve(n+n)
total = 0
for i in range(n):
if... | vfc_51157 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n\nSAMPLE",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n\nSAMOLE",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | subly-again | Solve the following coding problem using the programming language python:
Subly found a set of Numbers in his Dad's table. Subly examines that set and wants to know how many numbers in that set are not divisible by his favourite number.
He asked his brother for help. His brother told him that the numbers were in som... | ```python
from sys import stdin
n,m = map(int,stdin.readline().split())
tot = 0
cur = n
ans = 0
while cur:
tot += cur/m
cur/=m
for i in xrange(n+1):
fir = n-i
sec = i
u = 0
v = 0
while fir:
u += fir/m
fir/=m
while sec:
v += sec/m
sec/=m
#print i,n-i,u,v
if u+v >= tot:
ans+=1
print ans
``` | vfc_51161 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 5\n\nSAMPLE",
"output": "6",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 2",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "89765... |
code_contests | verifiable_code | valentines-day-surprise-gift | Solve the following coding problem using the programming language python:
Vivek and Sita are in a relationship. Both of them love playing with numbers and treat each other with puzzles every now and then.
When Sita visits her class she comes to see that there is a gift packed in a wooden box which has a lock in it w... | ```python
import math
def powmod(x, y, md):
if x==0:
return 0
if y==0:
return 1
ans = powmod(x, y//2, md)
ans = (ans*ans)%md
if y%2==1:
ans = (x*ans)%md
return ans
def Rn(N):
if N<=10:
return R[N]
n4 = int(math.ceil(N/4.0))
n5 = int(math.ceil(N/5.0))
... | vfc_51165 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n14\n\nSAMPLE",
"output": "996023990\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1\n2",
"output": "1024\n1024\n",
"type": "stdin_stdout"
},
{
"fn_name": ... |
code_contests | verifiable_code | p00026 Dropping Ink | Solve the following coding problem using the programming language python:
As shown in the following figure, there is a paper consisting of a grid structure where each cell is indicated by (x, y) coordinate system.
We are going to put drops of ink on the paper. A drop comes in three different sizes: Large, Medium, and... | ```python
board = [[0]*10 for _ in range(10)]
while True:
try:
x, y, size = map(int, input().split(','))
except:
break
small = [(-1, 0), (0, -1), (0, 0), (0, 1), (1, 0)]
med = [(-1, -1), (-1, 0), (-1, 1),
(0, -1), (0, 0), (0, 1),
(1, -1), (1, 0), (1, 1)]
large =... | vfc_51209 | {
"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,5,3\n3,6,1\n3,4,2\n4,5,2\n3,6,3\n2,4,1",
"output": "77\n5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2,5,3\n3,6,1\n3,4,2\n4,5,2\n3,6,3\n1,4,1",
"output": "75\n5\n",
"type"... |
code_contests | verifiable_code | p00157 Russian Dolls | Solve the following coding problem using the programming language python:
<image>
Matryoshka is a wooden doll in the shape of a female figure and is a typical Russian folk craft. Matryoshka has a nested structure in which smaller dolls are contained inside a large doll, and is composed of multiple dolls of different ... | ```python
while True:
n = int(input())
if n == 0:
break
hr_lst = []
for _ in range(n):
h, r = map(int, input().split())
hr_lst.append((h, r))
m = int(input())
for _ in range(m):
h, r = map(int, input().split())
hr_lst.append((h, r))
hr_lst.sort(reverse=True)
r_lst = [[] for _ ... | vfc_51213 | {
"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": "6\n1 1\n4 3\n6 5\n8 6\n10 10\n14 14\n5\n2 2\n5 4\n6 6\n9 8\n15 10\n4\n1 1\n4 3\n6 5\n8 6\n3\n2 2\n5 4\n6 6\n4\n1 1\n4 3\n6 5\n8 6\n4\n10 10\n12 11\n18 15\n24 20\n0",
"output": "9\n6\n8",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | p00484 Books | Solve the following coding problem using the programming language python:
There is a long-established secondhand bookstore called JOI secondhand bookstore in your town, and you often use the JOI secondhand bookstore. Each book has a standard price, and you can buy it at that price if you go to the JOI secondhand books... | ```python
def solve():
n, k = map(int,input().split())
group_num = 10
book_map = [[] for i in range(group_num)]
acc_map = [[0] for i in range(group_num)]
for i in range(n):
c, g = map(int,input().split())
book_map[g - 1].append(c)
for i in range(group_num):
bmi = book_map[i]
bmi.sort(re... | vfc_51221 | {
"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": "7 4\n14 1\n13 2\n12 3\n14 2\n8 2\n16 3\n11 2",
"output": "60",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 4\n14 1\n13 2\n12 3\n26 2\n8 2\n16 3\n11 2",
"output": "72\n",
"typ... |
code_contests | verifiable_code | p00670 Spellcasters | Solve the following coding problem using the programming language python:
There are n wizards. They are numbered from 1 to n, and the i-th wizard has the magical power ri (1 ≤ i ≤ n). Now they are confronting a powerful wizard, whose enemy's magical power is S. n Wizards are good at fighting together, especially two p... | ```python
while 1:
n,s=map(int,input().split())
if n==0:break
r=[0]*101
for _ in [0]*n:r[int(input())]+=1
a=0
for i in range(101):
if i*2>s:a+=(r[i]**2-r[i])//2
a+=r[i]*sum(r[j] for j in range(max(i+1,s+1-i),101))
print(a)
``` | vfc_51225 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 7\n1\n3\n10\n0 0",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 7\n1\n6\n10\n0 0",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | p00813 GIGA Universe Cup | Solve the following coding problem using the programming language python:
Following FIFA World Cup, a larger competition called ``GIGA Universe Cup'' is taking place somewhere in our universe. Both FIFA World Cup and GIGA Universe Cup are two rounds competitions that consist of the first round, also known as ``group l... | vfc_51229 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n_____*AAA__BBB__CCC__DDD\n*AAA_______0-0__0-0___-_\n_BBB_____________-___0-0\n_CCC_________________0-0\n_DDD____________________\n______CHN__CRC__TUR_*BRA\n_CHN_______0-2___-___0-4\n_CRC____________1-1___-_\n_TUR________________... | |
code_contests | verifiable_code | p01211 Spirograph | Solve the following coding problem using the programming language python:
Some of you might have seen instruments like the figure below.
<image>
Figure 1: Spirograph
There are a fixed circle (indicated by A in the figure) and a smaller interior circle with some pinholes (indicated by B). By putting a pen point thro... | vfc_51241 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2 1\n3 2 0\n0 0 0",
"output": "13.36\n6.28",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3 1\n3 2 0\n0 0 0",
"output": "0.00\n6.28\n",
"type": "stdin_stdout"
},
{
... | |
code_contests | verifiable_code | p01347 How to Create a Good Game | Solve the following coding problem using the programming language python:
A video game company called ICPC (International Company for Playing and Competing) is now developing a new arcade game. The new game features a lot of branches. This makes the game enjoyable for everyone, since players can choose their routes in... | vfc_51245 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 6\n0 1 5\n0 2 5\n0 3 5\n1 2 5\n1 3 5\n2 3 5",
"output": "20",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n0 1 10",
"output": "0",
"type": "stdin_stdout"
},
{
... | |
code_contests | verifiable_code | p01685 Overwriting Game | Solve the following coding problem using the programming language python:
Problem Statement
You have a rectangular board with square cells arranged in $H$ rows and $W$ columns. The rows are numbered $1$ through $H$ from top to bottom, and the columns are numbered $1$ through $W$ from left to right. The cell at the ro... | vfc_51253 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2\nBB\n\nWW\n\n2 1\nB\nW\n\nB\nW\n\n2 2\nBW\nBW\n\nWW\nWW\n\n3 4\nBBBB\nBBBB\nBBBB\n\nWWWW\nWWWW\nWWWW\n\n5 5\nBBBBB\nBBBBB\nBBBBB\nBBBBB\nBBBBB\n\nBBBBB\nBBBWB\nBBBBB\nBWBBB\nBBBBB\n\n0 0",
"output": "6.0000000000\n0.00000... | |
code_contests | verifiable_code | p01829 Change a Password | Solve the following coding problem using the programming language python:
Example
Input
201
Output
701
The input will be given via stdin and the output should be printed to stdout by your code.
Now solve the problem by providing the code. | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]
def LI(): return [int(x) for x i... | vfc_51257 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "201",
"output": "701",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p02251 Change Making | Solve the following coding problem using the programming language python:
You want to make change for $ n $ cents. Assuming that you have infinite supply of coins of 1, 5, 10 and / or 25 cents coins respectively, find the minimum number of coins you need.
Constraints
* $ 1 \ le n \ le 10 ^ 9 $
Input
$ n $
The i... | ```python
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
COIN = [25,10,5,1]
N = int(input())
ans = 0
for i in range(len(COIN)):
ans += N//COIN[i]
N %= COIN[i]
print("%d"%(a... | vfc_51269 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "54321",
"output": "2175",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "000",
... |
code_contests | verifiable_code | p02399 A / B Problem | Solve the following coding problem using the programming language python:
Write a program which reads two integers a and b, and calculates the following values:
* a ÷ b: d (in integer)
* remainder of a ÷ b: r (in integer)
* a ÷ b: f (in real number)
Constraints
* 1 ≤ a, b ≤ 109
Input
Two integers a and b are give... | ```python
a,b = map(int,input().split())
print('%d %d %.5f'%(a/b,a%b,a/b))
``` | vfc_51273 | {
"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 2",
"output": "1 1 1.50000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 2",
"output": "0 0 0.000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"i... |
code_contests | verifiable_code | amr14i | Solve the following coding problem using the programming language python:
Virat Kohli and Rohit Sharma are warming up for the World Cup at the Brisbane Cricket Ground, commonly known as "The Gabba". Their coach has asked them to go to the ground at the crack of dawn, and then jog around the stadium in laps. The Cricke... | ```python
# your code goes here
i_num = int(raw_input())
Nvar, Mvar = 0,0
def step_calc(pos_var, step):
pos_var += step
if pos_var <= Mvar:
return pos_var
pos_var -= Mvar
return Mvar + (pos_var%(Nvar - Mvar + 1))
for i_var in xrange(i_num):
i_line = raw_input().split(' ')
i_line = [int(item) for item in... | vfc_51277 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 1 4 2 3\n5 3 10 1 2",
"output": "1\n3",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | chfans | Solve the following coding problem using the programming language python:
Chef is studying Rotational Motion in physics. Here is preparing for Engineering Entrance exam. He's stuck in a problem. Which states that "Two fans, each with a single blade are rotating one above the other, about the same axis of rotation and ... | ```python
problem='https://www.codechef.com/problems/CHFANS'
__author__='Ravindra Singh'
def gcd(a,b):
if a%b==0:
return b
else:
return gcd(b,a%b)
T=int(raw_input())
for i in range(T):
a,b=map(int,raw_input().split())
if a>b:
print abs(abs((a-b))//gcd(a,b))
else:
pr... | vfc_51281 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2\n6 5\n1 -2",
"output": "1\n1\n3",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | dynainv | Solve the following coding problem using the programming language python:
You are given a permutation A of the first N positive integers. You are also given Q queries to perform one-by-one, the i-th is defined by a pair Xi Yi and has the meaning that you swap the Xi-th number in the permutation with the Yi-th one. Aft... | ```python
def SortCount(A):
l = len(A)
if l > 1:
n = l//2
C = A[:n]
D = A[n:]
C, c = SortCount(A[:n])
D, d = SortCount(A[n:])
B, b = MergeCount(C,D)
return B, b+c+d
else:
return A, 0
def MergeCount(A,B):
count = 0
M = []
i=0
j=0
while i<len(A) an... | vfc_51285 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 1\n1 2 3 4 5\n2 3",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1\n1 2 3 4 5\n2 5",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | kgp14a | Solve the following coding problem using the programming language python:
Liliputs are holding a drawing competition for K kids, but with K human-sized pencils stolen from humans. In order to make life easier for the kids, the organizers want to give a pencil to each kid in a way such that the sum of the absolute diff... | ```python
for num in range(input()):
n =input()
arr1 = map(int,raw_input().split())
arr1.sort()
arr2 = map(int,raw_input().split())
arr2.sort()
m=0
for i in range(n):
m+=abs(arr1[i]-arr2[i])
# m=min(m,abs(arr1[i]-arr2[i]))
print "Case "+str(num+1)+": "+str(m)
``` | vfc_51289 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5\n51 60 51 72 70 \n65 60 88 72 88 \n4 \n123 234 188 175 \n219 334 122 233",
"output": "Case 1: 69 \nCase 2: 190",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n5\n51 60 51 72 70 \n65 ... |
code_contests | verifiable_code | omwg | Solve the following coding problem using the programming language python:
Leha is playing a very interesting game. The game will be played on a rectangular grid consisting of N rows and M columns. Initially all the cells of the grid are uncolored.
Leha's initial score is zero. At each turn, he chooses some cell that ... | ```python
T=int(raw_input())
while T:
n,m=map(int,raw_input().split())
ans = 2*n*m-n-m
print(ans)
T-=1
``` | vfc_51293 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2 2",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3 2",
"output": "7\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | spalnum | Solve the following coding problem using the programming language python:
A number is called palindromic if its decimal representation is a palindrome. You are given a range, described by a pair of integers L and R. Find the sum of all palindromic numbers lying in the range [L, R], inclusive of both the extrema.
Inpu... | ```python
for tests in xrange(int(raw_input())):
a, z = map(int, raw_input().split())
str_range = map(str, xrange(a, z + 1))
print sum([int(str_num) for str_num in str_range if str_num == str_num[::-1]])
``` | vfc_51297 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 10\n123 150",
"output": "45\n272\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 10\n123 150",
"output": "44\n272\n",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | 1005_E1. Median on Segments (Permutations Edition) | Solve the following coding problem using the programming language python:
You are given a permutation p_1, p_2, ..., p_n. A permutation of length n is a sequence such that each integer between 1 and n occurs exactly once in the sequence.
Find the number of pairs of indices (l, r) (1 ≤ l ≤ r ≤ n) such that the value o... | ```python
n, m = map(int, input().split(' '))
aa = list(map(int, input().split(' ')))
def countMoreLess(vs, value):
#print(vs)
cur = 0
res = { cur: 1 }
for v in vs:
cur += 1 if v > value else -1
res[cur] = res.get(cur, 0) + 1
#print(res)
return res
pos = aa.index(m)
leftCount... | vfc_51301 | {
"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": "5 4\n2 4 5 3 1\n",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "15 8\n1 15 2 14 3 13 4 8 12 5 11 6 10 7 9\n",
"output": "48",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 1029_C. Maximal Intersection | Solve the following coding problem using the programming language python:
You are given n segments on a number line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
The intersection of a s... | ```python
def intersect(x, y):
if x < y:
return (y[0], x[1])
else:
return (x[0], y[1])
def solve(iv):
first = {}
second = {}
for x, y in iv:
first[x] = first.get(x, 0) + 1
second[y] = second.get(y, 0) + 1
max1, max2 = reversed(sorted([x for x, _ in iv])[-2:])
... | vfc_51305 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 10\n1 5\n",
"output": "7\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 104_B. Testing Pants for Sadness | Solve the following coding problem using the programming language python:
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of n questions; the questions are to be ... | ```python
n = int(input())
l = list(map(int,input().split()))
if len(set(l)) == 1 and l[0] == 1 or n == 1 :
print(sum(l))
else:
cnt = l[0]
for i in range(1 , n):
cnt += l[i] + (l[i]-1) * i
print(cnt)
``` | vfc_51309 | {
"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\n1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2... |
code_contests | verifiable_code | 1093_E. Intersection of Permutations | Solve the following coding problem using the programming language python:
You are given two permutations a and b, both consisting of n elements. Permutation of n elements is such a integer sequence that each value from 1 to n appears exactly once in it.
You are asked to perform two types of queries with them:
* 1~... | vfc_51317 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 6, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 7\n5 1 4 2 3 6\n2 5 3 1 4 6\n1 1 2 4 5\n2 2 4\n1 1 2 4 5\n1 2 3 3 5\n1 1 6 1 2\n2 4 1\n1 4 4 1 3\n",
"output": "1\n1\n1\n2\n0\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1141_G. Privatization of Roads in Treeland | Solve the following coding problem using the programming language python:
Treeland consists of n cities and n-1 roads. Each road is bidirectional and connects two distinct cities. From any city you can get to any other city by roads. Yes, you are right — the country's topology is an undirected tree.
There are some pr... | ```python
from __future__ import print_function
import os,sys,atexit
if sys.version_info[0] < 3:
range = xrange
from cStringIO import StringIO as BytesIO
sys.stdout = BytesIO()
else:
from io import BytesIO
sys.stdout = BytesIO()
_write = sys.stdout.write
sys.stdout.write = lambda s: _write(... | vfc_51325 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\n3 1\n1 4\n1 2\n",
"output": "1\n1 1 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 2\n10 3\n1 2\n1 3\n1 4\n2 5\n2 6\n2 7\n3 8\n3 9\n",
"output": "3\n3 1 2 3 2 3 1 1 2 ",
... |
code_contests | verifiable_code | 1162_B. Double Matrix | Solve the following coding problem using the programming language python:
You are given two n × m matrices containing integers. A sequence of integers is strictly increasing if each next number is greater than the previous one. A row is strictly increasing if all numbers from left to right are strictly increasing. A c... | ```python
# !/usr/bin/env python3
# encoding: UTF-8
# Modified: <04/May/2019 11:12:46 PM>
# ✪ H4WK3yE乡
# Mohd. Farhan Tahir
# Indian Institute Of Information Technology (IIIT),Gwalior
# ///==========Libraries, Constants and Functions=============///
import sys
def get_array(): return list(map(int, sys.stdin.rea... | vfc_51329 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n2 10\n11 5\n9 4\n3 12\n",
"output": "Possible\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1183_A. Nearest Interesting Number | Solve the following coding problem using the programming language python:
Polycarp knows that if the sum of the digits of a number is divisible by 3, then the number itself is divisible by 3. He assumes that the numbers, the sum of the digits of which is divisible by 4, are also somewhat interesting. Thus, he consider... | ```python
def fun(x):
s=0
org=x
while(x):
s+=x%10
x=x//10
temp=s%4
if temp :
org+=1
return fun(org)
else :
return org
x=int(input())
print(fun(x))
``` | vfc_51333 | {
"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": "99\n",
"output": "103\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "432\n",
"output": "435\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "237\... |
code_contests | verifiable_code | 1200_B. Block Adventure | Solve the following coding problem using the programming language python:
Gildong is playing a video game called Block Adventure. In Block Adventure, there are n columns of blocks in a row, and the columns are numbered from 1 to n. All blocks have equal heights. The height of the i-th column is represented as h_i, whi... | ```python
t = int(input())
for _ in range(t):
n, m, k = map(int, input().split())
h = list(map(int, input().split()))
for i in range(n - 1):
m += h[i] - max(0, (h[i + 1] - k))
if m < 0:
print("NO")
break
if(m >= 0):
print("YES")
``` | vfc_51337 | {
"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\n3 0 1\n4 3 5\n3 1 2\n1 4 7\n4 10 0\n10 20 10 20\n2 5 5\n0 11\n1 9 9\n99\n",
"output": "YES\nNO\nYES\nNO\nYES\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1218_D. Xor Spanning Tree | Solve the following coding problem using the programming language python:
In the galaxy far far away is the ancient interplanetary republic of Bubbleland, consisting of N planets. Between them, there are M bidirectional wormholes, each connecting a pair of planets. Bubbleland is a very centralized republic, having a c... | vfc_51341 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 128000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 6\n4 1 5\n5 2 1\n6 3 2\n1 2 6\n1 3 3\n2 3 4\n",
"output": "1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "15 17\n15 7 93376\n5 14 26561\n2 9 37333\n12 7 25285\n6 11 21915\n11 14 238... | |
code_contests | verifiable_code | 1242_A. Tile Painting | Solve the following coding problem using the programming language python:
Ujan has been lazy lately, but now has decided to bring his yard to good shape. First, he decided to paint the path from his house to the gate.
The path consists of n consecutive tiles, numbered from 1 to n. Ujan will paint each tile in some co... | ```python
from sys import stdin
import math
n=int(stdin.readline())
if n<3:
k=n
else:
d=0
g=n
for i in range(2,int(math.sqrt(n))+1):
if n%i==0:
d+=1
g=math.gcd(g,i)
if i*i!=n:
d+=1
g=math.gcd(g,n//i)
if d==0:
k=n
... | vfc_51345 | {
"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\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "81299001720... |
code_contests | verifiable_code | 1261_B1. Optimal Subsequences (Easy Version) | Solve the following coding problem using the programming language python:
This is the easier version of the problem. In this version 1 ≤ n, m ≤ 100. You can hack this problem only if you solve and lock both problems.
You are given a sequence of integers a=[a_1,a_2,...,a_n] of length n. Its subsequence is obtained by ... | ```python
import copy
b=[]
a=[]
rezult=''
n=int(input())
a=list(map(int,input().split()))
m=int(input())
for i in range(1,m+1):
k,pos=map(int,input().split())
b=copy.deepcopy(a)
b.reverse()
for j in range(1,n-k+1):
b.remove(min(b))
b.reverse()
rezult=rezult+'\n'+str(b[pos-1])
print(rezul... | vfc_51349 | {
"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": "7\n1 2 1 3 1 2 1\n9\n2 1\n2 2\n3 1\n3 2\n3 3\n1 1\n7 1\n7 7\n7 4\n",
"output": "2\n3\n2\n3\n2\n3\n1\n1\n3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1283_C. Friends and Gifts | Solve the following coding problem using the programming language python:
There are n friends who want to give gifts for the New Year to each other. Each friend should give exactly one gift and receive exactly one gift. The friend cannot give the gift to himself.
For each friend the value f_i is known: it is either f... | ```python
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 19 09:55:17 2020
@author: Mridul Garg
"""
#def swap()
n = int(input())
arr = list(map(int, input().split(' ')))
check = [i for i in range(1, n+1)]
last0 = 0
for i in range(n):
if arr[i] != 0:
check[arr[i]-1] = 0
else:
last0 = i+1... | vfc_51353 | {
"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": "7\n7 4 0 3 0 5 1\n",
"output": "7 4 2 3 6 5 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n5 0 0 2 4\n",
"output": "5 3 1 2 4 \n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1302_I. Deja vu | Solve the following coding problem using the programming language python:
This is an unusual problem in an unusual contest, here is the announcement: [http://codeforces.com/blog/entry/73543](//codeforces.com/blog/entry/73543)
You run a string shop. During a day your customers want to buy strings of certain lengths an... | vfc_51357 | {
"difficulty": "15",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n01101\n",
"output": "\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 3\n1110001011\n",
"output": "\n8\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1326_G. Spiderweb Trees | Solve the following coding problem using the programming language python:
Let's call a graph with n vertices, each of which has it's own point A_i = (x_i, y_i) with integer coordinates, a planar tree if:
* All points A_1, A_2, …, A_n are different and no three points lie on the same line.
* The graph is a tree, ... | vfc_51361 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n0 0\n-1 2\n-2 5\n-5 1\n1 3\n0 3\n2 4\n-1 -4\n1 2\n3 2\n5 6\n4 2\n1 5\n5 7\n5 8\n",
"output": "36\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1346_B. Boot Camp | Solve the following coding problem using the programming language python:
Berland State University (BSU) is conducting a programming boot camp. The boot camp will last for n days, and the BSU lecturers are planning to give some number of lectures during these days.
Some days of the boot camp are already planned as ex... | vfc_51365 | {
"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 5 7\n1011\n4 4 10\n0101\n5 3 4\n11011\n6 4 6\n011101\n",
"output": "\n12\n8\n8\n14\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1367_F2. Flying Sort (Hard Version) | Solve the following coding problem using the programming language python:
This is a hard version of the problem. In this version, the given array can contain equal elements and the constraints on n are greater than in the easy version of the problem.
You are given an array a of n integers (the given array can contain... | ```python
from sys import stdin
input = stdin.readline
for _ in range(int(input())):
n = int(input())
l = list(map(int,input().split()))
id = list(zip(l,list(range(n))))
id.sort()
val, pos = zip(*id)
blok = []
cur = [pos[0]]
for i in range(1,n):
if val[i] == val[i-1]:
... | vfc_51369 | {
"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": "9\n5\n4 7 2 2 9\n5\n3 5 8 1 7\n5\n1 2 2 4 5\n2\n0 1\n3\n0 1 0\n4\n0 1 0 0\n4\n0 1 0 1\n4\n0 1 0 2\n20\n16 15 1 10 0 14 0 10 3 9 2 5 4 5 17 9 10 20 0 9\n",
"output": "2\n2\n0\n0\n1\n1\n1\n1\n16\n",
"type": "stdin_stdout"... |
code_contests | verifiable_code | 1389_B. Array Walk | Solve the following coding problem using the programming language python:
You are given an array a_1, a_2, ..., a_n, consisting of n positive integers.
Initially you are standing at index 1 and have a score equal to a_1. You can perform two kinds of moves:
1. move right — go from your current index x to x+1 and ... | ```python
# Some people dream of success, while others wake up and work hard at it. Napoleon Hill
# by : Blue Edge - Create some chaos
# import sys
# sys.stdin = open('input.txt', 'r')
for _ in range(int(input())):
n,k,z=map(int,input().split())
a=list(map(int,input().split()))
# print(k,z)
# print(*a... | vfc_51373 | {
"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\n5 4 0\n1 5 4 3 2\n5 4 1\n1 5 4 3 2\n5 4 4\n10 20 30 40 50\n10 7 3\n4 6 8 2 9 9 7 4 10 9\n",
"output": "15\n19\n150\n56\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n5 4 1\n1 5 4 3 ... |
code_contests | verifiable_code | 1409_E. Two Platforms | Solve the following coding problem using the programming language python:
There are n points on a plane. The i-th point has coordinates (x_i, y_i). You have two horizontal platforms, both of length k. Each platform can be placed anywhere on a plane but it should be placed horizontally (on the same y-coordinate) and ha... | ```python
from bisect import bisect,bisect_left
for _ in range(int(input())):
n,k=map(int,input().split())
x=list(map(int,input().split()))
y=input()
x.sort()
a=[]
b=[]
i=0
while i<n:
b.append(bisect(x,x[i]+k)-i)
a.append(i-bisect_left(x,x[i]-k)+1)
i+=1
b.rev... | vfc_51377 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n7 1\n1 5 2 3 1 5 4\n1 3 6 7 2 5 4\n1 1\n1000000000\n1000000000\n5 10\n10 7 5 15 8\n20 199 192 219 1904\n10 10\n15 19 8 17 20 10 9 2 10 19\n12 13 6 17 1 14 7 9 19 3\n",
"output": "6\n1\n5\n10\n",
"type": "stdin_stdout... |
code_contests | verifiable_code | 1430_C. Numbers on Whiteboard | Solve the following coding problem using the programming language python:
Numbers 1, 2, 3, ... n (each integer from 1 to n once) are written on a board. In one operation you can erase any two numbers a and b from the board and write one integer (a + b)/(2) rounded up instead.
You should perform the given operation n ... | ```python
for _ in range (int(input())):
n=int(input())
hold=n
res=[]
for i in range (n-1,0,-1):
res.append((hold,i))
hold=(hold+i+1)//2
print(hold)
for i in res:
print(*i)
``` | vfc_51381 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n4\n",
"output": "2\n4 3\n4 2\n3 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n4\n",
"output": "2\n4 3\n4 2\n3 1\n",
"type": "stdin_stdout"
},
{
"fn_name... |
code_contests | verifiable_code | 1453_E. Dog Snacks | Solve the following coding problem using the programming language python:
Gildong is playing with his dog, Badugi. They're at a park that has n intersections and n-1 bidirectional roads, each 1 meter in length and connecting two intersections with each other. The intersections are numbered from 1 to n, and for every a... | ```python
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.... | vfc_51385 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3\n1 2\n1 3\n4\n1 2\n2 3\n3 4\n8\n1 2\n2 3\n3 4\n1 5\n5 6\n6 7\n5 8\n",
"output": "\n2\n3\n3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1477_C. Nezzar and Nice Beatmap | Solve the following coding problem using the programming language python:
Nezzar loves the game osu!.
osu! is played on beatmaps, which can be seen as an array consisting of distinct points on a plane. A beatmap is called nice if for any three consecutive points A,B,C listed in order, the angle between these three po... | ```python
class Node:
def __init__(self, x, y):
self.x = x
self.y = y
def getDist(self, a):
dx = a.x - self.x
dy = a.y - self.y
return dx * dx + dy * dy
n = int(input())
a = []
for i in range(n):
x, y = map(int, input().split())
a.append(Node(x, y))
ans = [0]
v... | vfc_51389 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n0 0\n5 0\n4 2\n2 1\n3 0\n",
"output": "\n1 2 5 3 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20\n1000000000 0\n500000000 0\n809016994 587785252\n404508497 293892626\n309016994 951... |
code_contests | verifiable_code | 1527_E. Partition Game | Solve the following coding problem using the programming language python:
You are given an array a of n integers. Define the cost of some array t as follows:
$$$cost(t) = ∑_{x ∈ set(t) } last(x) - first(x),$$$
where set(t) is the set of all values in t without repetitions, first(x), and last(x) are the indices of t... | vfc_51397 | {
"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": "7 4\n5 5 5 5 2 3 3\n",
"output": "\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 2\n1 6 6 4 6 6 6\n",
"output": "\n3\n",
"type": "stdin_stdout"
},
{
"fn_na... | |
code_contests | verifiable_code | 159_D. Palindrome pairs | Solve the following coding problem using the programming language python:
You are given a non-empty string s consisting of lowercase letters. Find the number of pairs of non-overlapping palindromic substrings of this string.
In a more formal way, you have to find the quantity of tuples (a, b, x, y) such that 1 ≤ a ≤ ... | ```python
import sys
input=sys.stdin.readline
s=list(input().rstrip())
n=len(s)
l=[0]*n # [0,i]
r=[0]*n # [i,n-1]
for i in range(n):
j=0
while 0<=i-j and i+j<n and s[i-j]==s[i+j]:
l[i+j]+=1
r[i-j]+=1
j+=1
j=1
while 0<=i-j+1 and i+j<n and s[i-j+1]==s[i+j]:
l[i+j]+=1
r[i-j+1]+=1
j+=1
ans=0... | vfc_51401 | {
"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": "aa\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "aaa\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "abacaba\... |
code_contests | verifiable_code | 201_B. Guess That Car! | Solve the following coding problem using the programming language python:
A widely known among some people Belarusian sport programmer Yura possesses lots of information about cars. That is why he has been invited to participate in a game show called "Guess That Car!".
The game show takes place on a giant parking lot... | ```python
#------------------------template--------------------------#
import os
import sys
# from math import *
from collections import *
# from fractions import *
# from heapq import*
from bisect import *
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('outpu... | vfc_51409 | {
"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 3\n3 4 5\n3 9 1\n",
"output": " 392\n1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n1 0 0 0\n0 0 3 0\n0 0 5 5\n",
... |
code_contests | verifiable_code | 226_A. Flying Saucer Segments | Solve the following coding problem using the programming language python:
An expedition group flew from planet ACM-1 to Earth in order to study the bipedal species (its representatives don't even have antennas on their heads!).
The flying saucer, on which the brave pioneers set off, consists of three sections. These ... | ```python
n, m = map(int, input().split())
def fast_power(base, exp):
res = 1
while exp > 0:
if exp % 2 == 1:
res = (res * base) % m
base = (base * base) % m
exp //= 2
return res
print((fast_power(3, n) - 1 + m) % m)
``` | vfc_51413 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 8\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 10\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 81\n... |
code_contests | verifiable_code | 24_D. Broken robot | Solve the following coding problem using the programming language python:
You received as a gift a very clever robot walking on a rectangular board. Unfortunately, you understood that it is broken and behaves rather strangely (randomly). The board consists of N rows and M columns of cells. The robot is initially at so... | ```python
n,m = (int(s) for s in input().split())
i,j = (int(s) for s in input().split())
def find(n,m,i,j):
if i==n:
return 0
if m==1:
return 2*(n-i)
e,a,b = [0.]*m,[0]*m,[0]*m
for l in range(n-1,0,-1):
a[0],b[0]=.5,.5*(3+e[0])
for k in range(1,m-1):
a[k] = 1... | vfc_51417 | {
"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": "10 14\n5 14\n",
"output": "18.0038068653",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 10\n10 4\n",
"output": "0.0000000000",
"type": "stdin_stdout"
},
{
"fn_n... |
code_contests | verifiable_code | 274_E. Mirror Room | Solve the following coding problem using the programming language python:
Imagine an n × m grid with some blocked cells. The top left cell in the grid has coordinates (1, 1) and the bottom right cell has coordinates (n, m). There are k blocked cells in the grid and others are empty. You flash a laser beam from the cen... | vfc_51421 | {
"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": "3 3 0\n1 2 SW\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 5 3\n3 3\n4 3\n5 3\n2 1 SE\n",
"output": "14\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 298_B. Sail | Solve the following coding problem using the programming language python:
The polar bears are going fishing. They plan to sail from (sx, sy) to (ex, ey). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (x, y... | ```python
i = 0
t, sx, sy, ex, ey = list(map(int, input().split()))
second_string = input()
while i < t:
if second_string[i] == 'E':
if sx < ex: sx += 1
elif second_string[i] == 'W':
if sx > ex: sx -= 1
elif second_string[i] == 'N':
if sy < ey: sy += 1
else:
if sy > ey: s... | vfc_51425 | {
"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": "10 5 3 3 6\nNENSWESNEE\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 0 0 1 1\nSESNW\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_nam... |
code_contests | verifiable_code | 320_E. Kalila and Dimna in the Logging Industry | Solve the following coding problem using the programming language python:
Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle and cut n trees with heights a1, a2, ..., an. They b... | vfc_51429 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3 4 5\n5 4 3 2 0\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1 2 3 10 20 30\n6 5 4 3 2 0\n",
"output": "138\n",
"type": "stdin_stdout"
},
... | |
code_contests | verifiable_code | 345_E. Black Cat Rush | Solve the following coding problem using the programming language python:
Today you go out of your house and immediately notice that something is weird. Around your door there is a swarm of black cats — all tense paws and twitching tails. As you do your first step, they all dart off and start running towards you. It l... | vfc_51433 | {
"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": "1 1 5 4\n0 3\n4 -4\n7 0\n-2 -2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 5 3 4\n7 5\n5 2\n10 -7\n15 0\n",
"output": "3\n",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | 369_B. Valera and Contest | Solve the following coding problem using the programming language python:
Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of n students (including Valera). This contest was an individual competition, so each student in ... | ```python
import math
scann=input()
numbers=scann.split()
s=int(numbers[0])
s2=int(numbers[1])
min1=int(numbers[2])
max1=int(numbers[3])
total=int(numbers[4])
s2mp=int(numbers[5])
div=int(s2mp/s2)
mod=s2mp%s2
students=[]
for i in range(mod):
students.append(div +1) #intentarlo solo con piso
iter1=s2-mod
for j in r... | vfc_51437 | {
"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 3 1 3 15 9\n",
"output": "3 3 3 3 3 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3 1 3 13 9\n",
"output": "3 3 3 2 2 \n",
"type": "stdin_stdout"
},
{
"fn_... |
code_contests | verifiable_code | 391_C1. The Tournament | Solve the following coding problem using the programming language python:
This problem consists of three subproblems: for solving subproblem C1 you will receive 4 points, for solving subproblem C2 you will receive 4 points, and for solving subproblem C3 you will receive 8 points.
Manao decided to pursue a fighter's c... | ```python
m = 301000
ns = [0] * m
es = [0] * m
c = [0] * m
b = [0] * m
t = [0] * m
P = 0
def add(b, k):
k = t[k]
while k:
e = es[k]
if b[-1] > e: b[-1] = e
b[e] += 1
k = ns[k]
def delete(b):
for i in range(b[m - 1], m + 1):
if b[i]:
b[i] -= 1
b[-... | vfc_51441 | {
"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 2\n2 10\n2 10\n1 1\n3 1\n3 1\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n3 2\n4 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"... |
code_contests | verifiable_code | 43_D. Journey | Solve the following coding problem using the programming language python:
The territory of Berland is represented by a rectangular field n × m in size. The king of Berland lives in the capital, located on the upper left square (1, 1). The lower right square has coordinates (n, m). One day the king decided to travel th... | ```python
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, m = map(int, input().split())
ans = ['1 1']
warp = [-1] * 4
if n == 1 and m == 2:
ans.append('1 2')
elif n == 2 and m == 1:
ans.append('2 1')
elif n == 1:
warp = [1, m, 1, 1... | vfc_51449 | {
"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\n",
"output": "0\n1 1\n1 2\n2 2\n2 1\n1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n",
"output": "1\n3 3 1 1\n1 1\n1 2\n1 3\n2 3\n2 2\n2 1\n3 1\n3 2\n3 3\n1 1\n",
... |
code_contests | verifiable_code | 462_A. Appleman and Easy Task | Solve the following coding problem using the programming language python:
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each ce... | ```python
n=int(input())
mat = []
mat.append('x'*(n+2))
for i in range(n):
mat.append('x'+input()+'x')
mat.append('x'*(n+2))
output = "YES"
for i in range(1,n+1):
if output == "NO":
break
for j in range(1,n+1):
s=0
if mat[i][j+1] == 'o':
s+=1
if mat[i][j-1] == 'o'... | vfc_51453 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nxxo\nxox\noxx\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 485_E. Strange Sorting | Solve the following coding problem using the programming language python:
How many specific orders do you know? Ascending order, descending order, order of ascending length, order of ascending polar angle... Let's have a look at another specific order: d-sorting. This sorting is applied to the strings of length at lea... | vfc_51457 | {
"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": "qwerty\n3\n4 2\n6 3\n5 2\n",
"output": "qertwy\nqtewry\nqetyrw\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "a\n1\n1 1\n",
"output": "a\n",
"type": "stdin_stdout"
},
... | |
code_contests | verifiable_code | 509_E. Pretty Song | Solve the following coding problem using the programming language python:
When Sasha was studying in the seventh grade, he started listening to music a lot. In order to evaluate which songs he likes more, he introduced the notion of the song's prettiness. The title of the song is a word consisting of uppercase Latin l... | ```python
song = input()
le = len(song)
su = 0
for x in range(1,le+1):
su += 1/x
l = [0]*le
l[0] = su
diff = su
for x in range(1,int((le+1)/2)):
diff -= (1/x + 1/(le+1-x))
l[x] = l[x-1] + diff
for x in range(int((le+1)/2),le):
l[x] = l[le-1-x]
ans = 0
for x in range(le):
let = song[x]
if let i... | vfc_51461 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "BYOB\n",
"output": "5.83333333\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "YISVOWEL\n",
"output": "17.05000000\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 534_A. Exam | Solve the following coding problem using the programming language python:
An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side by side and became friends and if they... | ```python
n = int(input())
if n ==1:
print(1)
print(1)
else:
odd = [int(k) for k in range(n+1) if k % 2 != 0]
odd.reverse()
even = [int(k) for k in range(1,n+1) if k % 2 == 0]
even.reverse()
odd_len = len(odd)
#even.reverse()
if abs(odd[odd_len-1]-even[0]) == 1:
even = even[... | vfc_51465 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "2\n1 3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 559_A. Gerald's Hexagon | Solve the following coding problem using the programming language python:
Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to <image>. Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. Th... | ```python
import math
a = [int(x) for x in input().split()]
nb_triangles = 0
nb_triangles += a[0]*a[1]*2
nb_triangles += a[2]*a[3]*2
nb_triangles += a[4]*a[5]*2
nb_triangles += abs(a[0]-a[3])**2
print(nb_triangles)
``` | vfc_51469 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1 1 1 1 1\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 584_D. Dima and Lisa | Solve the following coding problem using the programming language python:
Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes.
More formally, you are given an odd num... | ```python
def isPrime(n):
if n==2:
return True
if n%2==0:
return False
for i in range(3,n,2):
if i*i>n:
break
if n%i==0:
return False
return True
n=int(input())
if isPrime(n):
print(1)
print(n)
elif isPrime(n-2):
print(2)
print('2 '... | vfc_51473 | {
"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": "27\n",
"output": "3\n23 2 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7147\n",
"output": "3\n3 17 7127\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 606_D. Lazy Student | Solve the following coding problem using the programming language python:
Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real life. He asked a girl sitting next to him to lend h... | ```python
# Legends Always Come Up with Solution
# Author: Manvir Singh
import os
import sys
from io import BytesIO, IOBase
from heapq import *
def main():
n,m=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(m)]
edges,j,b=[[]]*m,1,sorted(range(m),key=lambda x:a[x][0]*10000000000-a... | vfc_51477 | {
"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 5\n2 1\n3 1\n4 0\n1 1\n5 0\n",
"output": "1 3\n1 4\n2 3\n1 2\n2 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n1 0\n2 1\n3 1\n",
"output": "-1\n",
"type": "stdin_stdo... |
code_contests | verifiable_code | 628_D. Magic Numbers | Solve the following coding problem using the programming language python:
Consider the decimal presentation of an integer. Let's call a number d-magic if digit d appears in decimal presentation of the number on even positions and nowhere else.
For example, the numbers 1727374, 17, 1 are 7-magic but 77, 7, 123, 34, 71... | ```python
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO,IOBase
from array import array
def solve(x,m,d,mod,par):
dp = [[array('i',[0])*m for _ in range(2)] for _ in range(len(x))]
# remainder of number formed till now ; smaller/equal ; place value
zz = i... | vfc_51481 | {
"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 6\n10\n99\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 0\n1\n9\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | 652_E. Pursuit For Artifacts | Solve the following coding problem using the programming language python:
Johnny is playing a well-known computer game. The game are in some country, where the player can freely travel, pass quests and gain an experience.
In that country there are n islands and m bridges between them, so you can travel from any islan... | vfc_51485 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6\n1 2 0\n2 3 0\n3 1 0\n3 4 0\n4 5 1\n5 3 0\n1 2\n",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 7\n1 2 0\n2 3 0\n3 1 0\n3 4 1\n4 5 0\n5 6 0\n6 4 0\n1 6\n",
"out... | |
code_contests | verifiable_code | 678_C. Joty and Chocolate | Solve the following coding problem using the programming language python:
Little Joty has got a task to do. She has a line of n tiles indexed from 1 to n. She has to paint them in a strange pattern.
An unpainted tile should be painted Red if it's index is divisible by a and an unpainted tile should be painted Blue if... | ```python
import math
n, red, blue, red_cost, blue_cost = map(int, input().split())
reds = n//red - n//((red*blue)//math.gcd(red,blue))
blues = n//blue - n//((red*blue)//math.gcd(red,blue))
ans = reds*red_cost + blues*blue_cost + max(blue_cost, red_cost)*(n//((red*blue)//math.gcd(red,blue)))
print(int(ans))
``` | vfc_51489 | {
"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 3 12 15\n",
"output": "39\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 700_C. Break Up | Solve the following coding problem using the programming language python:
Again, there are hard times in Berland! Many towns have such tensions that even civil war is possible.
There are n towns in Reberland, some pairs of which connected by two-way roads. It is not guaranteed that it is possible to reach one town f... | vfc_51493 | {
"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": "6 7\n1 6\n2 1 6\n2 3 5\n3 4 9\n4 6 4\n4 6 5\n4 5 1\n3 1 3\n",
"output": "8\n2\n2 7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n1 2\n1 2 734458840\n1 2 817380027\n1 2 304764803\n",... | |
code_contests | verifiable_code | 722_E. Research Rover | Solve the following coding problem using the programming language python:
Unfortunately, the formal description of the task turned out to be too long, so here is the legend.
Research rover finally reached the surface of Mars and is ready to complete its mission. Unfortunately, due to the mistake in the navigation sys... | vfc_51497 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 6 2 15\n1 1\n1 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3 2 11\n2 1\n2 3\n",
"output": "333333342\n",
"type": "stdin_stdout"
},
{
"f... | |
code_contests | verifiable_code | 744_C. Hongcow Buys a Deck of Cards | Solve the following coding problem using the programming language python:
One day, Hongcow goes to the store and sees a brand new deck of n special cards. Each individual card is either red or blue. He decides he wants to buy them immediately. To do this, he needs to play a game with the owner of the store.
This game... | vfc_51501 | {
"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\nR 0 1\nB 1 0\nR 1 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nR 3 0\nR 2 0\nR 1 0\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"f... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.