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 | p00051 Differential II | Solve the following coding problem using the programming language python:
When you enter 8 numbers from 0 to 9, write a program that outputs the difference between the largest integer and the smallest integer that can sort the 8 numbers. The number that can be sorted may start from 0, such as 00135569.
Input
Given... | ```python
n=int(input())
for _ in range(n):
c=[i for i in input()]
Max=int("".join(sorted(c,reverse=True)))
Min=int("".join(sorted(c)))
print(Max-Min)
``` | vfc_57449 | {
"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\n65539010\n65539010",
"output": "96417531\n96417531",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n65539010\n102034250",
"output": "96417531\n543098655\n",
"type": "stdin_s... |
code_contests | verifiable_code | p00181 Bookshelf | Solve the following coding problem using the programming language python:
Taro is addicted to a novel. The novel has n volumes in total, and each volume has a different thickness. Taro likes this novel so much that he wants to buy a bookshelf dedicated to it. However, if you put a large bookshelf in the room, it will ... | ```python
import bisect
def main():
m,n = list(map(int,input().split()))
if n==0:
exit()
W = [int(input()) for _ in range(n)]
w_total = 0
w_sum =[]
for w in W:
w_total+=w
w_sum.append(w_total)
def judge(shelf_length):
last_val = 0
for i in range(m):... | vfc_57453 | {
"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 9\n500\n300\n800\n200\n100\n600\n900\n700\n400\n4 3\n1000\n1000\n1000\n0 0",
"output": "1800\n1000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 9\n500\n300\n800\n200\n100\n600\n900\n7... |
code_contests | verifiable_code | p00528 Modern Mansion | Solve the following coding problem using the programming language python:
Modern Mansion
You got lost in a big mansion. This mansion has a structure in which square rooms are arranged in a grid pattern from north, south, east, and west, with M columns in the east-west direction and N rows in the north-south direction... | ```python
from heapq import heappush, heappop
M, N, K = map(int, input().split())
X = [[] for i in range(M)]
Y = [[] for i in range(N)]
for i in range(K):
x, y = map(int, input().split()); x -= 1; y -= 1
X[x].append((y, i))
Y[y].append((x, i))
G0 = [[] for i in range(K)]
G1 = [[] for i in range(K)]
for x... | vfc_57461 | {
"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": "3 2 1\n1 2",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2 1\n2 2",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input":... |
code_contests | verifiable_code | p00836 Sum of Consecutive prime Numbers | Solve the following coding problem using the programming language python:
Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The i... | ```python
def solve():
# making a list of prime numbers
primes = [2, 3]
for n in range(5, 10000, 2):
l = n ** 0.5
for p in primes:
if n % p == 0:
break
if l < p:
primes.append(n)
break
primes = [0] + primes
... | vfc_57469 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n17\n41\n20\n666\n12\n53\n0",
"output": "1\n1\n2\n3\n0\n0\n1\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3\n17\n41\n20\n666\n24\n53\n0",
"output": "1\n1\n2\n3\n0\n0\n1\n... |
code_contests | verifiable_code | p00968 Digits Are Not Just Characters | Solve the following coding problem using the programming language python:
Digits Are Not Just Characters
Mr. Manuel Majorana Minore made a number of files with numbers in their names. He wants to have a list of the files, but the file listing command commonly used lists them in an order different from what he prefers... | ```python
n = int(input())
ss = [input() for _ in range(n + 1)]
sp = [[s[0]] for s in ss]
for i, s in enumerate(ss):
for j in range(1, len(s)):
if s[j - 1].isdigit() != s[j].isdigit():
sp[i].append('')
sp[i][-1] += s[j]
s0 = sp[0]
for s in sp[1:]:
p = 0
m = min(len(s0), len(s))
... | vfc_57473 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nfile10\nfile20\nfile3",
"output": "+\n-",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\nfile10\nfi2el0\nfile3",
"output": "-\n-\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | p01100 Gift Exchange Party | Solve the following coding problem using the programming language python:
Gift Exchange Party
A gift exchange party will be held at a school in TKB City.
For every pair of students who are close friends, one gift must be given from one to the other at this party, but not the other way around. It is decided in advanc... | ```python
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N, M = map(int, readline().split())
if N == M == 0:
return False
G = [[] for i in range(N)]
cs = [0]*N
for i in range(M):
u, v = map(int, readline().split())
... | vfc_57477 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n1 2\n2 3\n1 3\n4 3\n1 2\n1 3\n1 4\n4 6\n1 2\n1 3\n1 4\n2 3\n3 4\n2 4\n0 0",
"output": "1 1\n0 1\n1 2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p01399 Problem B | Solve the following coding problem using the programming language python:
Problem B: B problem
2D enthusiasts (2D Respecters) from R University will participate in a programming training camp held at Atsu University. In this training camp, participants bring their own programming problems and use them for practice.
... | vfc_57485 | {
"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 100\n3 7 4\n5 24\n4 6 12 3 8\n5 1\n1 1 2 2 3\n0 0",
"output": "2\n4\n5",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01552 YAML | Solve the following coding problem using the programming language python:
YAML (YAML Ain't Markup Language) is one of the formats for expressing an object as a character string.
You will be given an object represented by a subset of YAML and a query that specifies the property, so please answer the value of the speci... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+9
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in ... | vfc_57489 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 262144000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": ".tweets.1\nname: shimeji\nid: shimejitan\ntweets:\n1: shimejilove\n2: azupero",
"output": "string \"shimejilove\"",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ".no.such.property\nobject:\n... |
code_contests | verifiable_code | p01853 Lie with Mean Value | Solve the following coding problem using the programming language python:
Problem statement
N first-year students of the Faculty of Information Science and Technology of R University take the final exam of the lecture called Programming Exercise 1. The test is a perfect score of m. In other words, the score that one ... | ```python
# -*- coding: utf-8 -*-
(n,m)=[int(a) for a in input().split()]
for i in range(n):
if i:print(" ",end="")
if i<=n/2: print("0",end="")
else: print("{}".format(m),end="")
print("")
``` | vfc_57497 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 100",
"output": "0 0 100",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 100",
"output": "0 0 0 100 100\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | p01988 NINJA GAME | Solve the following coding problem using the programming language python:
NINJA GAME
The new game "NINJA GAME" has finally been released. In this game, the player operates a ninja on a two-dimensional map to move. A two-dimensional map is represented by a non-self-intersecting polygon consisting of only sides paralle... | vfc_57501 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n1 1 2 2\n0 2\n0 0\n2 0\n2 1\n3 1\n3 3\n1 3\n1 2\n12\n-9 5 9 -9\n0 0\n0 -13\n3 -13\n3 -10\n10 -10\n10 10\n-1 10\n-1 13\n-4 13\n-4 10\n-10 10\n-10 0\n12\n3 57 53 2\n0 0\n64 0\n64 18\n47 18\n47 39\n64 39\n64 60\n0 60\n0 44\n33 44\n... | |
code_contests | verifiable_code | p02275 Counting Sort | Solve the following coding problem using the programming language python:
Counting sort can be used for sorting elements in an array which each of the n input elements is an integer in the range 0 to k. The idea of counting sort is to determine, for each input element x, the number of elements less than x as C[x]. Thi... | ```python
# 計数ソート
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/6/ALDS1_6_A
# 計算量 O(n+k)
import sys
input = sys.stdin.buffer.readline
n = int(input())
A = [int(i) for i in input().split()]
B = [None] * n
C = [0] * 10001
for a in A:
C[a] += 1
for i in range(10001):
C[i] = C[i - 1] + C[i]
for j i... | vfc_57509 | {
"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": "7\n2 5 1 3 2 3 0",
"output": "0 1 2 2 3 3 5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n2 5 1 3 2 3 1",
"output": "1 1 2 2 3 3 5\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | p02422 Transformation | Solve the following coding problem using the programming language python:
Transformation
Write a program which performs a sequence of commands to a given string $str$. The command is one of:
* print a b: print from the a-th character to the b-th character of $str$
* reverse a b: reverse from the a-th character to... | ```python
str = input("")
q = int(input())
for i in range(q):
line = input().split()
c = line[0]
a = int(line[1])
b = int(line[2]) + 1
if c == 'replace':
str = str[:a] + line[3] + str[b:]
elif c == 'reverse':
str = str[:a] + str[a:b][::-1] + str[b:]
else:
print(str[... | vfc_57513 | {
"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": "abcde\n3\nreplace 1 3 xyz\nreverse 0 2\nprint 1 4",
"output": "xaze",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | bintree | Solve the following coding problem using the programming language python:
Consider an infinite full binary tree (each node has two children except the leaf nodes) defined as follows. For a node labelled v its left child will be labelled 2*v and its right child will be labelled 2*v+1. The root is labelled as 1.
You are... | ```python
count=0
t=int(raw_input())
while(t>0):
a,b=[int(x) for x in raw_input().split()]
while(a!=b):
if(a>b):
a=a/2
else:
b=b/2
count=count+1
print count
count=0
t=t-1
``` | vfc_57517 | {
"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\n2 3\n4 3",
"output": "1\n2\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2\n2 5\n4 3",
"output": "1\n1\n3\n",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | coadies2 | Solve the following coding problem using the programming language python:
Problem description :
The fight between Raghu and Rannvijay is becoming more intense.This time Rannvijay asked Raghu a question.
He gives him a number N and asked him to find the number of all pairs (a, b) of positive integers such that
1 <= a <... | ```python
test=int(input())
while test:
test-=1
n=int(input())
count=0
for a in range (1,n):
for b in range (a+1,n+1):
if (a*b)%(a+b)==0:
count+=1
print count
``` | vfc_57521 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n15",
"output": "0\n4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3\n15",
"output": "0\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | fruits | Solve the following coding problem using the programming language python:
Today is Chef's birthday. His mom has surprised him with truly fruity gifts: 2 fruit baskets. The first basket contains N apples, and the second one contains M oranges. Chef likes apples and oranges very much but he likes them equally, and there... | ```python
#fruit salad < samosas ? <VigzMv/>
t=int(raw_input())
for x in range(t):
n,m,k=map(int, raw_input().split())
if abs(m-n)==0:
print 0
else:
if k<abs(m-n):
print abs(m-n)-k
else:
print 0
``` | vfc_57525 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 4 1\n5 2 1\n3 4 3",
"output": "0\n2\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3 4 1\n5 2 2\n3 4 3",
"output": "0\n1\n0\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | luckfour | Solve the following coding problem using the programming language python:
Kostya likes the number 4 much. Of course! This number has such a lot of properties, like:
Four is the smallest composite number;
It is also the smallest Smith number;
The smallest non-cyclic group has four elements;
Four is the maximal degree ... | ```python
def luckyFour():
tests = int(raw_input())
for t in xrange(tests):
n = int(raw_input())
count = 0
while(n>0):
if (n%10 == 4):
count+=1
n = n/10
print count
luckyFour()
``` | vfc_57529 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n447474\n228\n6664\n40\n81",
"output": "4\n0\n1\n1\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n447474\n228\n6664\n40\n35",
"output": "4\n0\n1\n1\n0\n",
"type": "std... |
code_contests | verifiable_code | prmarth | Solve the following coding problem using the programming language python:
Children are taught to add multi-digit numbers from right to left, one digit at a time.
Many find the “carry” operation, where a 1 is carried from one digit position to the
next, to be a significant challenge. Your job is to count the number of ... | ```python
while 1:
N,M=map(int,raw_input().split());
if N==0 and M==0:
break
else:
A,B=N,M; CR=0; ct=0;
while A or B:
q,r=A%10,B%10;
if q+r+CR>9:
ct+=1; CR=1;
A/=10; B/=10;
if ct==0:
print "No carry operation."
elif ct==1:
print "1 carry operation."
else:
print "%d carry operations.... | vfc_57533 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "123 456\n555 555\n123 594\n0 0",
"output": "No carry operation.\n3 carry operations.\n1 carry operation.",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | tcfst05 | Solve the following coding problem using the programming language python:
You always wanted to be a soldier and play it out at the battleground live. When you came at Techfest 2013, you encountered Lazer Tag, a game that satiated your innate hunger for taking aim and shooting enemies.
Lazer Tag consists of a group pl... | ```python
n = int(raw_input())
p = map(float, raw_input().split())
e = [p[0]]
for i in range(1,n):
ans = (e[i-1]+p[i-1]+1)*p[i]
e.append(ans)
for i in range(n-1):
e[i+1]+=e[i]
print e[n-1]
``` | vfc_57537 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0.6 0.5 0.8 0.2",
"output": "4.556000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 1 1",
"output": "9.000000",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1011_D. Rocket | Solve the following coding problem using the programming language python:
This is an interactive problem.
Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. She couldn't thin... | ```python
from sys import stdin
from math import *
from sys import stdout
line = stdin.readline().rstrip().split()
m = int(line[0])
n = int(line[1])
bits = []
for i in range(n):
print(m)
stdout.flush()
line = stdin.readline().rstrip().split()
res = int(line[0])
if res == 0:
exit(0)
if ... | vfc_57541 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n1\n-1\n-1\n1\n0\n",
"output": "1\n1\n3\n1\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000000 2 999999998\n0 1\n",
"output": "1\n1\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 1036_E. Covered Points | Solve the following coding problem using the programming language python:
You are given n segments on a Cartesian plane. Each segment's endpoints have integer coordinates. Segments can intersect with each other. No two segments lie on the same line.
Count the number of distinct points with integer coordinates, which ... | ```python
import sys
from math import gcd
class Segment:
def __init__(self, x1, y1, x2, y2):
self.x1 = x1
self.y1 = y1
self.x2 = x2
self.y2 = y2
def dx(self):
return self.x2 - self.x1
def dy(self):
return self.y2 - self.y1
def pt_cnt(self)... | vfc_57545 | {
"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\n-1 2 1 2\n-1 0 1 0\n-1 0 0 3\n0 3 1 0\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n0 0 4 4\n-1 5 4 0\n4 0 4 4\n5 2 11 2\n6 1 6 7\n5 6 11 6\n10 1 10 7\n7 0 9 8\n10... |
code_contests | verifiable_code | 1059_D. Nature Reserve | Solve the following coding problem using the programming language python:
There is a forest that we model as a plane and live n rare animals. Animal number i has its lair in the point (x_{i}, y_{i}). In order to protect them, a decision to build a nature reserve has been made.
The reserve must have a form of a circle... | ```python
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write ... | vfc_57549 | {
"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\n0 1\n1 1\n",
"output": "0.624999999750000000077378853325\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1080_F. Katya and Segments Sets | Solve the following coding problem using the programming language python:
It is a very important day for Katya. She has a test in a programming class. As always, she was given an interesting problem that she solved very fast. Can you solve that problem?
You are given n ordered segments sets. Each segment can be repre... | vfc_57553 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5 9\n3 6 3\n1 3 1\n2 4 2\n1 2 3\n4 6 5\n2 5 3\n7 9 4\n2 3 1\n4 10 4\n1 2 2 3\n1 2 2 4\n1 3 1 5\n2 3 3 6\n2 4 2 9\n",
"output": "no\nyes\nyes\nno\nyes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
code_contests | verifiable_code | 10_E. Greedy Change | Solve the following coding problem using the programming language python:
Billy investigates the question of applying greedy algorithm to different spheres of life. At the moment he is studying the application of greedy algorithm to the problem about change. There is an amount of n coins of different face values, and ... | ```python
__author__ = 'Darren'
def solve():
n = int(input())
coins = list(map(int, input().split()))
def greedy(amount):
num = 0
for i in range(n):
num += amount // coins[i]
amount %= coins[i]
return num
result = 1 << 31
for i in range(1, n):
... | vfc_57557 | {
"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\n4 3 1\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1121_D. Diana and Liana | Solve the following coding problem using the programming language python:
At the first holiday in spring, the town Shortriver traditionally conducts a flower festival. Townsfolk wear traditional wreaths during these festivals. Each wreath contains exactly k flowers.
The work material for the wreaths for all n citizen... | ```python
def main():
m, k, n, s = map(int, input().split())
a = list(map(int, input().split())) # prevbug: input in a line!
b = list(map(int, input().split())) # prevbug: convert to list
b_dict = {}
for x in b:
b_dict.setdefault(x, 0)
b_dict[x] += 1 # prevbug: b or b_dict
le... | vfc_57561 | {
"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": "13 4 3 3\n3 2 6 4 1 4 4 7 1 3 3 2 4\n4 3 4\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1148_F. Foo Fighters | Solve the following coding problem using the programming language python:
You are given n objects. Each object has two integer properties: val_i — its price — and mask_i. It is guaranteed that the sum of all prices is initially non-zero.
You want to select a positive integer s. All objects will be modified after that... | ```python
def main():
inp = readnumbers()
ii = 0
n = inp[ii]
ii += 1
val = inp[ii:ii+2*n:2]
mask = inp[ii+1:ii+2*n:2]
ii += 2*n
if sum(val) > 0:
val = [-v for v in val]
groups = [[] for _ in range(64)]
for i in range(n):
groups[mask[i].bit_length()-1].appe... | vfc_57565 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n17 206\n-6 117\n-2 151\n9 93\n6 117\n",
"output": "64",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1 1\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_n... |
code_contests | verifiable_code | 116_C. Party | Solve the following coding problem using the programming language python:
A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is said to be the superior of another employee B if at... | ```python
def findDepth(a, i):
depth = 1
nextLevel = a[i][:]
while len(nextLevel) > 0:
depth += 1
children = nextLevel[:]
nextLevel = []
for child in children:
nextLevel += a[child]
return depth
n = int(input())
a = []
for i in range(n):
a.appen... | vfc_57569 | {
"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": "5\n-1\n1\n2\n1\n-1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12\n-1\n8\n9\n-1\n4\n2\n11\n1\n-1\n6\n-1\n10\n",
"output": "6\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 1188_B. Count Pairs | Solve the following coding problem using the programming language python:
You are given a prime number p, n integers a_1, a_2, …, a_n, and an integer k.
Find the number of pairs of indexes (i, j) (1 ≤ i < j ≤ n) for which (a_i + a_j)(a_i^2 + a_j^2) ≡ k mod p.
Input
The first line contains integers n, p, k (2 ≤ n ≤... | ```python
def check(num1, num2, p, k):
v = num1 + num2
v *= num1 * num1 + num2 * num2
v %= p
v += p
v %= p
return v == k % p
if __name__ == '__main__':
n, p, k = (int(x) for x in input().split())
idx___number = [int(x) for x in input().split()]
idx___precount = [((pow(x, 4, p) - k... | vfc_57573 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 7 2\n1 2 3 4 5 6\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1207_C. Gas Pipeline | Solve the following coding problem using the programming language python:
You are responsible for installing a gas pipeline along a road. Let's consider the road (for simplicity) as a segment [0, n] on OX axis. The road can have several crossroads, but for simplicity, we'll denote each crossroad as an interval (x, x +... | ```python
import math
t = int(input())
for _ in range(t):
(n, a, b) = [int(x) for x in input().split()]
s = input()
#print((n, a, b, s))
gap = math.ceil((2 * a) / b) + 1
#print((a, b, gap))
cost = b
state = 0
b2 = 2 * b
streak0 = 0
for i in range(n-1):
if s[i] == '1':
streak0 = 0
else:
streak0... | vfc_57577 | {
"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\n8 2 5\n00110010\n8 1 1\n00110010\n9 100000000 100000000\n010101010\n2 5 1\n00\n",
"output": "94\n25\n2900000000\n13\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 3 5\n00\n12 4 7\... |
code_contests | verifiable_code | 1225_D. Power Products | Solve the following coding problem using the programming language python:
You are given n positive integers a_1, …, a_n, and an integer k ≥ 2. Count the number of pairs i, j such that 1 ≤ i < j ≤ n, and there exists an integer x such that a_i ⋅ a_j = x^k.
Input
The first line contains two integers n and k (2 ≤ n ≤ 1... | ```python
from collections import defaultdict
import sys as _sys
def main():
n, k = _read_ints()
a = tuple(_read_ints())
result = find_good_pairs_n(a, k)
print(result)
def _read_line():
result = _sys.stdin.readline()
assert result[-1] == "\n"
return result[:-1]
def _read_ints():
re... | vfc_57581 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 3\n1 3 9 8 24 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 5\n49248 87211\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... |
code_contests | verifiable_code | 1249_F. Maximum Weight Subset | Solve the following coding problem using the programming language python:
You are given a tree, which consists of n vertices. Recall that a tree is a connected undirected graph without cycles.
<image> Example of a tree.
Vertices are numbered from 1 to n. All vertices have weights, the weight of the vertex v is a_v.... | ```python
n, k = map(int, input().split())
a = list(map(int, input().split()))
g = {}
def dfs(v, p=-1):
c = [dfs(child, v) for child in g.get(v, set()) - {p}]
c.sort(key=len, reverse=True)
r = []
i = 0
while c:
if i >= len(c[-1]):
c.pop()
else:
o = max(i, k - i - 1)
s = q = 0
for x in c:
if le... | vfc_57585 | {
"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": "7 2\n2 1 2 1 2 1 1\n6 4\n1 5\n3 1\n2 3\n7 5\n7 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1\n1 2 3 4 5\n1 2\n2 3\n3 4\n3 5\n",
"output": "11\n",
"type... |
code_contests | verifiable_code | 1268_C. K Integers | Solve the following coding problem using the programming language python:
You are given a permutation p_1, p_2, …, p_n.
In one move you can swap two adjacent values.
You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be a... | ```python
import sys
input = sys.stdin.buffer.readline
# all operations are log(n)
class bit:
def __init__(self, n):
self.n = n+1
self.mx_p = 0
while 1 << self.mx_p < self.n:
self.mx_p += 1
self.a = [0]*(self.n)
self.tot = 0
def add(self, idx, val):
... | vfc_57589 | {
"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": "5\n5 4 3 2 1\n",
"output": "0 1 3 6 10 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2 3\n",
"output": "0 0 0 ",
"type": "stdin_stdout"
},
{
"fn_name": null... |
code_contests | verifiable_code | 1290_D. Coffee Varieties (hard version) | Solve the following coding problem using the programming language python:
This is the hard version of the problem. You can find the easy version in the Div. 2 contest. Both versions only differ in the number of times you can ask your friend to taste coffee.
This is an interactive problem.
You're considering moving t... | vfc_57593 | {
"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\nN\nN\nY\nN\nN\nN\nN\n",
"output": "? 1\n? 2\n? 3\n? 4\nR\n? 1\n? 3\nR\n? 2\n? 4\nR\n? 1\n? 4\nR\n! 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 8\nN\nN\nN\nN\nY\nY\n",
"o... | |
code_contests | verifiable_code | 1310_E. Strange Function | Solve the following coding problem using the programming language python:
Let's define the function f of multiset a as the multiset of number of occurences of every number, that is present in a.
E.g., f(\{5, 5, 1, 2, 5, 2, 3, 3, 9, 5\}) = \{1, 1, 2, 2, 4\}.
Let's define f^k(a), as applying f to array a k times: f^k(... | vfc_57597 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 2\n",
"output": "33\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n... | |
code_contests | verifiable_code | 1333_C. Eugene and an array | Solve the following coding problem using the programming language python:
Eugene likes working with arrays. And today he needs your help in solving one challenging task.
An array c is a subarray of an array b if c can be obtained from b by deletion of several (possibly, zero or all) elements from the beginning and se... | ```python
import sys
import heapq
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def rinput():
return map(int, input().split())
def rlinput():
return list(map(int, input().split()))
def YES(flag):
if flag:
return "YES"
return "NO"
def main(... | vfc_57601 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 -3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n41 -41 41\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"i... |
code_contests | verifiable_code | 1373_E. Sum of Digits | Solve the following coding problem using the programming language python:
Let f(x) be the sum of digits of a decimal number x.
Find the smallest non-negative integer x such that f(x) + f(x + 1) + ... + f(x + k) = n.
Input
The first line contains one integer t (1 ≤ t ≤ 150) — the number of test cases.
Each test cas... | ```python
def generate_prefix(su):
pre = ""
if su >= 8:
pre += '8'
su -= 8
if len(pre) > 0:
nu = 9
else:
nu = 8
while su > 0:
while su >= nu:
su -= nu
pre += str(nu)
nu -= 1
pre = pre[::-1]
return pre
def get_number(su... | vfc_57609 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n1 0\n1 1\n42 7\n13 7\n99 1\n99 0\n99 2\n",
"output": "1\n0\n4\n-1\n599998\n99999999999\n7997\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n13 9\n17 9\n",
"output": "-1\n-1\n"... |
code_contests | verifiable_code | 1438_F. Olha and Igor | Solve the following coding problem using the programming language python:
This is an interactive problem.
Igor wants to find the key to Olha's heart. The problem is, that it's at the root of a binary tree.
There is a perfect binary tree of height h consisting of n = 2^{h} - 1 nodes. The nodes have been assigned dist... | vfc_57621 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n\n2\n\n7\n\n4",
"output": "\n? 7 3 5\n\n? 1 6 4\n\n? 1 5 4\n\n! 4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n12 7 15 11 8 3 13 5 10 4 2 6 9 14 1\n",
"output": "? 13 11 4\n? ... | |
code_contests | verifiable_code | 1463_E. Plan of Lectures | Solve the following coding problem using the programming language python:
Ivan is a programming teacher. During the academic year, he plans to give n lectures on n different topics. Each topic should be used in exactly one lecture. Ivan wants to choose which topic will he explain during the 1-st, 2-nd, ..., n-th lectu... | ```python
class Node:
def __init__(self, value):
self.value = value
self.next = None
self.prev = None
def __repr__(self):
if not self:
return "{}()".format(self.__class__.__name__)
return "{}({})".format(self.__class__.__name__, self.value)
class LL:
def... | vfc_57625 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n2 3 0 5 3\n1 5\n5 1\n",
"output": "\n0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 148_E. Porcelain | Solve the following coding problem using the programming language python:
During her tantrums the princess usually smashes some collectable porcelain. Every furious shriek is accompanied with one item smashed.
The collection of porcelain is arranged neatly on n shelves. Within each shelf the items are placed in one r... | ```python
#!/usr/bin/env python3
import os
import sys
from io import BytesIO, IOBase
class FastO:
def __init__(self, fd=1):
stream = BytesIO()
self.flush = lambda: os.write(fd, stream.getvalue()) and not stream.truncate(0) and stream.seek(0)
self.write = lambda b: stream.write(b.encode())
... | vfc_57629 | {
"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": "2 3\n3 3 7 2\n3 4 1 5\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 3\n4 4 3 1 2\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name":... |
code_contests | verifiable_code | 166_D. Shoe Store | Solve the following coding problem using the programming language python:
The warehouse in your shop has n shoe pairs. Each pair is characterized by two integers: its price ci and its size si. We know that on this very day all numbers si are different, that is, there is no more than one pair of each size.
The shop ha... | vfc_57641 | {
"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\n10 4\n20 5\n30 6\n2\n70 4\n50 5\n",
"output": " 50\n2\n1 2\n2 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n10 1\n30 ... | |
code_contests | verifiable_code | 187_E. Heaven Tour | Solve the following coding problem using the programming language python:
The story was not finished as PMP thought. God offered him one more chance to reincarnate and come back to life. But before he can come back, God told him that PMP should ask n great men including prominent programmers about their life experienc... | vfc_57645 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 3 2\n0 100 200 201 301 303 305\n",
"output": " 409\n1 4 3 5 7 6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3 1\n0 1 2 3... | |
code_contests | verifiable_code | 208_C. Police Station | Solve the following coding problem using the programming language python:
The Berland road network consists of n cities and of m bidirectional roads. The cities are numbered from 1 to n, where the main capital city has number n, and the culture capital — number 1. The road network is set up so that it is possible to r... | ```python
#build the graph with n cities and m roads
#figure out all of the shortest paths from city 1 to city n
#best=number of shortest paths (if we have police station at 1 or n)
s=list(map(int,input().split()))
n=s[0]
m=s[1]
roads=[]
Adj=[]
for i in range(0,n+1):
roads.append([])
Adj.append([False]*(n+1))... | vfc_57649 | {
"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": "11 14\n1 2\n1 3\n2 4\n3 4\n4 5\n4 6\n5 11\n6 11\n1 8\n8 9\n9 7\n11 7\n1 10\n10 4\n",
"output": "1.714285714\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4\n1 2\n2 4\n1 3\n3 4\n",
... |
code_contests | verifiable_code | 234_A. Lefthanders and Righthanders | Solve the following coding problem using the programming language python:
One fine October day a mathematics teacher Vasily Petrov went to a class and saw there n pupils who sat at the <image> desks, two people at each desk. Vasily quickly realized that number n is even. Like all true mathematicians, Vasily has all st... | ```python
import copy
import math
import sys
def solve(LR):
n = len(LR)
l_LR = list(LR)
half = n/2
ans=[]
if LR.count('L') > half:
more, less = 'L', 'R'
else:
more, less = 'R', 'L'
homoness = []
for i in range(half):
ans.append([i, i+half])
if LR[i]==... | vfc_57653 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nRRLL\n",
"output": "3 1\n4 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\nLLRLLL\n",
"output": "1 4\n2 5\n6 3\n",
"type": "stdin_stdout"
},
{
"fn_name": ... |
code_contests | verifiable_code | 259_E. Little Elephant and LCM | Solve the following coding problem using the programming language python:
The Little Elephant loves the LCM (least common multiple) operation of a non-empty set of positive integers. The result of the LCM operation of k positive integers x1, x2, ..., xk is the minimum positive integer that is divisible by each of numb... | vfc_57657 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n6 3\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 4 3 2\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... | |
code_contests | verifiable_code | 282_E. Sausage Maximization | Solve the following coding problem using the programming language python:
The Bitlandians are quite weird people. They have their own problems and their own solutions. They have their own thoughts and their own beliefs, they have their own values and their own merits. They have their own dishes and their own sausages!... | vfc_57661 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1000 1000\n",
"output": "1000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"i... | |
code_contests | verifiable_code | 305_D. Olya and Graph | Solve the following coding problem using the programming language python:
Olya has got a directed non-weighted graph, consisting of n vertexes and m edges. We will consider that the graph vertexes are indexed from 1 to n in some manner. Then for any graph edge that goes from vertex v to vertex u the following inequati... | ```python
from sys import stdin
N = 10 ** 6
MOD = 10**9 + 7
def task():
n, m, k = map(int, stdin.readline().split())
Sum = [0] * (N + 1)
Power = [0] * (N + 1)
for i in xrange(m):
u, v = map(int, stdin.readline().split())
if v - u == k + 1:
Sum[u - 1] = 1
elif v - u... | vfc_57665 | {
"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": "7 8 2\n1 2\n2 3\n3 4\n3 6\n4 5\n4 7\n5 6\n6 7\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 0 2\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 331_C1. The Great Julya Calendar | Solve the following coding problem using the programming language python:
Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar.
The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaveri... | ```python
def maxx(n):
l=[]
while(n>0):
l.append(n%10)
n = int(n/10)
return max(l)
n =int(input())
j=0
while(n>0):
n = n- maxx(n)
j+=1
print(j)
``` | vfc_57669 | {
"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": "24\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000\n",
"output": "128207\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 353_C. Find Maximum | Solve the following coding problem using the programming language python:
Valera has array a, consisting of n integers a0, a1, ..., an - 1, and function f(x), taking an integer from 0 to 2n - 1 as its single argument. Value f(x) is calculated by formula <image>, where value bit(i) equals one if the binary representati... | ```python
n = int(input())
a = list(map(int, input().split()))
s = input()
ans = 0
sm = 0
for i in range(n):
if s[i] == '1':
ans = max(ans + a[i], sm)
sm += a[i]
print(ans)
``` | vfc_57673 | {
"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\n17 0 10 2 1\n11010\n",
"output": "27\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3 8\n10\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | 377_D. Developing Game | Solve the following coding problem using the programming language python:
Pavel is going to make a game of his dream. However, he knows that he can't make it on his own so he founded a development company and hired n workers of staff. Now he wants to pick n workers from the staff who will be directly responsible for d... | ```python
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = 'x' in file.mode or 'r' not in file.mode
self.write = self.buffer.write i... | vfc_57677 | {
"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": "6\n3 5 16\n1 6 11\n4 8 12\n7 9 16\n2 10 14\n8 13 15\n",
"output": "4\n1 2 3 5 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n2 8 9\n1 4 7\n3 6 8\n5 8 10\n",
"output": "3\n1 3 4 ... |
code_contests | verifiable_code | 39_A. C*++ Calculations | Solve the following coding problem using the programming language python:
C*++ language is quite similar to C++. The similarity manifests itself in the fact that the programs written in C*++ sometimes behave unpredictably and lead to absolutely unexpected effects. For example, let's imagine an arithmetic expression in... | ```python
import re
n = int(input())
v = input()
f1, f2 = v.count('a++'), v.count('++a')
s = []
i = 0
while i < len(v) - 2:
if v[i] + v[i + 1] + v[i + 2] == '++a':
s.append('b')
i += 3
elif v[i] + v[i + 1] + v[i + 2] == 'a++':
s.append('a')
i += 3
else:
if i == len(v) - 2:
s.extend(v[i:])
i = len(v)... | vfc_57681 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\na+++++a\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n5*a++-3*++a+a++\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 448_E. Divisors | Solve the following coding problem using the programming language python:
Bizon the Champion isn't just friendly, he also is a rigorous coder.
Let's define function f(a), where a is a sequence of integers. Function f(a) returns the following sequence: first all divisors of a1 go in the increasing order, then all divi... | ```python
import sys
solSaved = {}
solSavedPropios = {}
def DivisorsN(n):
key = solSaved.get(str(n))
if key == None :
divisors = []
divisors2 = []
for i in range(1,int(n ** (1/2)) + 1):
if n % i == 0 :
if abs(i - (n/i)) < 10 ** (-7) : divisors.append(int... | vfc_57689 | {
"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": "10 3\n",
"output": " 1 1 1 ... |
code_contests | verifiable_code | 46_F. Hercule Poirot Problem | Solve the following coding problem using the programming language python:
Today you are to solve the problem even the famous Hercule Poirot can't cope with! That's why this crime has not yet been solved and this story was never included in Agatha Christie's detective story books.
You are not informed on what crime w... | ```python
def solve(n,m,k,edge_list,house_members):
room_sets=[i for i in range(n)]
valid_move=[True for i in range(n)]
room_status=[ [1<<i,0,[]] for i in range(n)]
# room_status[i]->informacion de todo otro cuarto,persona y llave alcanzable para el cuarto i
# room_status[i][0]->los cuartos alcanzab... | vfc_57693 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4 3\n1 3\n1 2\n2 3\n3 4\nArtem 1 1 4\nDmitry 1 1 2\nEdvard 4 2 1 3\nArtem 2 0\nDmitry 1 0\nEdvard 4 4 1 2 3 4\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1 2\n1 2\n... |
code_contests | verifiable_code | 493_B. Vasya and Wrestling | Solve the following coding problem using the programming language python:
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose ... | ```python
n = int(input())
a = []
b = []
for i in range(n):
x = int(input())
if i == n-1:
num = x
if x > 0:
a.append(x)
else:
b.append(abs(x))
sma = sum(a)
smb = sum(b)
if sma > smb:
print("first")
elif sma < smb:
print("second")
else:
if a == b:
if x > 0:
... | vfc_57697 | {
"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\n2\n-3\n-4\n3\n",
"output": "second\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 518_A. Vitaly and Strings | Solve the following coding problem using the programming language python:
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provided two strings s and t to Vi... | ```python
def f(s): return f(s[:-1])+'a' if s[-1] == 'z'else s[:-1]+chr(ord(s[-1])+1)
s = f(input())
print(('No such string', s)[s < input()])
``` | vfc_57701 | {
"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": "aaa\nzzz\n",
"output": "aab",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "a\nc\n",
"output": "b",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "abc... |
code_contests | verifiable_code | 544_A. Set of Strings | Solve the following coding problem using the programming language python:
You are given a string q. A sequence of k strings s1, s2, ..., sk is called beautiful, if the concatenation of these strings is string q (formally, s1 + s2 + ... + sk = q) and the first characters of these strings are distinct.
Find any beautif... | ```python
from sys import *
k=int(input())
s=input()
ee=set()
for i in s:
ee.add(i)
if k>len(ee):
print("NO")
exit(0)
print("YES")
i=1
cur=s[0]
num=k-1
ee.discard(s[0])
while i<len(s):
if s[i] in ee and num:
print(cur)
ee.discard(s[i])
num-=1
cur=s[i]
else:
c... | vfc_57705 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\nabca\n",
"output": "YES\nabca\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\nabc\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | 570_C. Replacement | Solve the following coding problem using the programming language python:
Daniel has a string s, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation of replacement as the following sequence of steps: find a substring ".." (two consecutive periods) in string s, of all o... | ```python
import sys
n,m = map(int,sys.stdin.readline().split())
arr = list(sys.stdin.readline())
count = cnt = 0
for i in arr:
if i=='.':
cnt += 1
elif cnt !=0:
count += cnt-1
cnt = 0
if cnt!=0:
count += cnt-1
i = m
while i:
x,c = sys.stdin.readline().split()
x = int(x)-1
... | vfc_57709 | {
"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": "10 3\n.b..bz....\n1 h\n3 c\n9 f\n",
"output": "4\n3\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4\n.cc.\n2 .\n3 .\n2 a\n1 a\n",
"output": "1\n3\n1\n1\n",
"type": "stdi... |
code_contests | verifiable_code | 592_A. PawnChess | Solve the following coding problem using the programming language python:
Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess».
This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some blac... | ```python
__author__ = 'Suvasish'
lst = []
a_row = 7
b_row = 0
b_lst = []
a_lst = []
for i in range(0, 8):
lst.append(list(input()))
# print(lst[i])
if 'W' in lst[i]:
a_lst.append(i)
if 'B' in lst[i]:
b_lst.append(i)
b_lst.reverse()
# print('AL', a_lst)
# print('BL', b_lst)
_break = ... | vfc_57713 | {
"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": "........\n........\n.B....B.\n....W...\n........\n..W.....\n........\n........\n",
"output": "A\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "..B.....\n..W.....\n......B.\n........\n....... |
code_contests | verifiable_code | 613_D. Kingdom and its Cities | Solve the following coding problem using the programming language python:
Meanwhile, the kingdom of K is getting ready for the marriage of the King's daughter. However, in order not to lose face in front of the relatives, the King should first finish reforms in his kingdom. As the King can not wait for his daughter's ... | ```python
import sys
from collections import deque
def solve():
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
writelines = sys.stdout.writelines
N = int(readline())
G = [[] for i in range(N)]
for i in range(N-1):
u, v = map(int, readline().split())
G[u-1].append(v-1)... | vfc_57717 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 3\n2 3\n4 3\n4\n2 1 2\n3 2 3 4\n3 1 2 4\n4 1 2 3 4\n",
"output": "1\n-1\n1\n-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n1 2\n2 3\n3 4\n1 5\n5 6\n5 7\n1\n4 2 4 6 7\n",
... |
code_contests | verifiable_code | 633_D. Fibonacci-ish | Solve the following coding problem using the programming language python:
Yash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a sequence Fibonacci-ish if
1. the sequence consists of at least two elements
2. f0 and f1 are arbitrary
3. fn + 2 = fn + 1 + fn for all n ≥ 0... | ```python
import random, math
from copy import deepcopy as dc
from bisect import bisect_left, bisect_right
from collections import Counter
# Function to call the actual solution
def solution(li):
ma = {}
for i in range(len(li)):
ma[li[i]] = ma.get(li[i], 0) + 1
# ma1 = dc(ma)
ans = 0
# li = list(set(li))
for ... | vfc_57721 | {
"difficulty": "10",
"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\n1 2 -1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n28 35 7 14 21\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 661_G. Hungarian Notation | Solve the following coding problem using the programming language python:
In Hungarian notation, a variable name is prefixed with a letter or a group of letters which are mnemonics for the type of that variable. For the purposes of this problem we will consider only two data types: integer and real.
You are given the... | vfc_57725 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "count\n18\n",
"output": "iCount\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 686_B. Little Robber Girl's Zoo | Solve the following coding problem using the programming language python:
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.
The robber girl wa... | ```python
n = int(input())
arr = list(map(int,input().split()))
check = 0
while check==0:
check = 1
i = 0
while i<n-1:
if arr[i]>arr[i+1]:
check = 0
print(i+1,i+2)
arr[i],arr[i+1] = arr[i+1],arr[i]
i += 1
``` | vfc_57729 | {
"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 2 1 2 1\n",
"output": "2 3\n4 5\n3 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n2 1 4 3\n",
"output": "1 2\n3 4\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 709_A. Juicer | Solve the following coding problem using the programming language python:
Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange mus... | ```python
"""
IIIIIIIIII OOOOOOOOOOO IIIIIIIIII
II OO OO II
II OO OO II
II OO OO II
II OO OO II
II OO OO II
II OO OO II
IIIIIIIIII OOOOOOOOOOO IIIIIIIIII
"""
n, b, d = map(int, input().split())
m = list(map(int, ... | vfc_57733 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1 1\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 7 10\n5 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inp... |
code_contests | verifiable_code | 730_C. Bulmart | Solve the following coding problem using the programming language python:
A new trade empire is rising in Berland. Bulmart, an emerging trade giant, decided to dominate the market of ... shovels! And now almost every city in Berland has a Bulmart store, and some cities even have several of them! The only problem is, a... | vfc_57737 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 4\n4 2\n5 4\n1 2\n3 2\n2\n4 1 2\n3 2 3\n6\n1 2 6\n2 3 7\n3 1 2\n4 3 8\n5 2 5\n6 1 10\n",
"output": "2\n-1\n2\n2\n3\n-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n1 2\n2 3\n3 4\... | |
code_contests | verifiable_code | 753_A. Santa Claus and Candies | Solve the following coding problem using the programming language python:
Santa Claus has n candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants ... | ```python
n=int(input())
i=1
a=[]
while(n>=i):
a.append(i)
n-=i
i+=1
a[-1]+=n
print(len(a))
print(*a)
``` | vfc_57741 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n",
"output": "1\n2 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n",
"output": "3\n1 2 6 ",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 774_G. Perfectionist Arkadiy | Solve the following coding problem using the programming language python:
Arkadiy has lots square photos with size a × a. He wants to put some of them on a rectangular wall with size h × w.
The photos which Arkadiy will put on the wall must form a rectangular grid and the distances between neighboring vertically and... | ```python
def gcd(x,y):
if (x%y==0): return y
return gcd(y,x%y)
a,h,w=input().split()
a=int(a)
h=int(h)
w=int(w)
g=gcd(h+a,w+a)
if (g<a or h<a or w<a):
print("-1")
else:
print(g/(g//a)-a)
``` | vfc_57745 | {
"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": "3 4 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 18 13\n",
"output": "0.5000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 799_G. Cut the pie | Solve the following coding problem using the programming language python:
Arkady reached the n-th level in Township game, so Masha decided to bake a pie for him! Of course, the pie has a shape of convex n-gon, i.e. a polygon with n vertices.
Arkady decided to cut the pie in two equal in area parts by cutting it by a ... | vfc_57749 | {
"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": "5 3\n6 5\n6 3\n5 0\n0 0\n0 5\n\n5 4\n3 3\n5 2\n",
"output": "0.602287346131205270083341929421\n1.27933953236952846488350132859\n2.85805511179879889738231213414\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... | |
code_contests | verifiable_code | 81_B. Sequence Formatting | Solve the following coding problem using the programming language python:
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For ... | ```python
# вводим строку s
s, i, v = input() + ' ', 0, ' '
# перебираем строку
while i < len(s):
# если в строке запятая, поставить пробел после нее
if s[i] == ',':
v += ', '
# если в строке точки, заменить их на многоточия и пробел перед ними
elif s[i] == '.':
v += ('' if v[-1] == ' '... | vfc_57753 | {
"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,2 ,3,..., 10\n",
"output": "1, 2, 3, ..., 10\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 845_E. Fire in the City | Solve the following coding problem using the programming language python:
The capital of Berland looks like a rectangle of size n × m of the square blocks of same size.
Fire!
It is known that k + 1 blocks got caught on fire (k + 1 ≤ n·m). Those blocks are centers of ignition. Moreover positions of k of these centers... | ```python
import sys
from collections import Counter
from operator import itemgetter
from heapq import heappop, heappush
n, m, k = map(int, input().split())
points = [list(map(int, line.split())) for line in sys.stdin]
pts_sorted_x = sorted(points)
pts_sorted_y = sorted(points, key=itemgetter(1, 0))
inf = 10**9+1
OK =... | vfc_57757 | {
"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": "10 5 1\n3 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 7 3\n1 2\n2 1\n5 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null... |
code_contests | verifiable_code | 865_G. Flowers and Chocolate | Solve the following coding problem using the programming language python:
It's Piegirl's birthday soon, and Pieguy has decided to buy her a bouquet of flowers and a basket of chocolates.
The flower shop has F different types of flowers available. The i-th type of flower always has exactly pi petals. Pieguy has decide... | vfc_57761 | {
"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": "6 5 10\n9 3 3 4 9 9\n9 9 1 6 4\n",
"output": "31415926\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 892_B. Wrath | Solve the following coding problem using the programming language python:
Hands that shed innocent blood!
There are n guilty people in a line, the i-th of them holds a claw with length Li. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the i-th p... | ```python
n=int(input())
l=[0]*n
r=[0]*n
len=list(map(int,input().split()))
for i in range(n):
a=max(0,i-len[i])
b=max(a,i)
#print(' '.join(map(str,[i,a,b])))
l[a]+=1
r[b]+=1
ans=0
t=0
for i in range(n):
t+=l[i]
t-=r[i]
#print('t='+str(t))
if t==0:
#print('i='+str(i))
... | vfc_57765 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n1 1 3 0 0 0 2 1 0 3\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 914_B. Conan and Agasa play a Card Game | Solve the following coding problem using the programming language python:
Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has n cards, and the i-th card has a number ai written on it.
They take turns playing, starting with Conan. In ... | ```python
n=int(input())
l=list(map(int,input().split()))
dic={}
status=True
i=0
l.sort()
while i<len(l):
counter=0
while True:
if i<len(l)-1 and l[i+1]==l[i]:
i+=1
counter+=1
else:
break
i+=1
counter+=1
if counter%2==1:
status=False
... | vfc_57769 | {
"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\n4 5 7\n",
"output": "Conan",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 1\n",
"output": "Agasa",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
code_contests | verifiable_code | 936_D. World of Tank | Solve the following coding problem using the programming language python:
Vitya loves programming and problem solving, but sometimes, to distract himself a little, he plays computer games. Once he found a new interesting game about tanks, and he liked it so much that he went through almost all levels in one day. Remai... | vfc_57773 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9 5 2 5\n1 2 7 8 9\n4 6\n",
"output": "Yes\n4\n0 3 5 10 \n1\n5 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 1 1\n1\n1\n",
"output": "No\n",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | 962_B. Students in Railway Carriage | Solve the following coding problem using the programming language python:
There are n consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger.
The university team for the Olympiad consists of a student-programmers and b student-athletes. Determine the largest number of stu... | ```python
n,a,b = map(int,input().split())
s=a+b
ans = 0
for t in map(len, input().split('*')):
if a > b: a, b = b, a
a -= min(a , (t//2))
b -= min(b , (t - (t//2)))
print(s-a-b)
``` | vfc_57777 | {
"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": "11 3 10\n.*....**.*.\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1 1\n*...*\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | 98_C. Help Greg the Dwarf | Solve the following coding problem using the programming language python:
A very unusual citizen lives in a far away kingdom — Dwarf Gracula. However, his unusual name is not the weirdest thing (besides, everyone long ago got used to calling him simply Dwarf Greg). What is special about Dwarf Greg — he's been living f... | ```python
EPS = 1e-8
def cross(a, b):
return (a[0] * b[1]) - (a[1] * b[0])
def f(a, b, l, x):
y = (l*l - x*x)**0.5
return cross( (a-x, b), (-x, y) )
def main():
a, b, l = map(int, raw_input().split())
if a > b:
a, b = b, a
if l <= a and a <= b:
print "%.9lf" % l
elif a <... | vfc_57781 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2 1\n",
"output": "1.0000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2 3\n",
"output": "1.3284271247\n",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | angles-2 | Solve the following coding problem using the programming language python:
Raju and Rani and playing games in the school. Raju has recently learned how to draw angles.
He knows how to draw some angles. He also can add/subtract any of the two angles he draws. Rani now wants to test Raju.
Input:
First line contains... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
n,k=map(int, raw_input().split())
knows=map(int,raw_input().split())
d=map(int, raw_input().split())
for i in d:
if i in knows:
print ('YES')
else:
f... | vfc_57785 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2\n100\n60 70\n\nSAMPLE",
"output": "YES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 10\n202 354 122 286 138 46\n49 266 181 4 203 246 227 153 68 346",
"output": "NO\nYES\... |
code_contests | verifiable_code | challenge-question-destruction | Solve the following coding problem using the programming language python:
Problem :
Osama is planning a massive attack on a country which comprises of 10 states. The map of this country is shown in the figure below :
He has a good reach in all these states and he plans to attack the country through missiles. Every s... | ```python
l = [int (i) for i in raw_input ().split ()]
if l == sorted (l): print "1 4 7 8 5 2 9 6 3"
elif l == [5, 2, 1, 6, 4, 9, 3, 7, 8, 10]: print "1 9 8 2 4 7 5 6 3"
elif l == [1, 4, 6, 5, 8, 10, 2, 9, 3, 7]: print "1 5 2 7 6 9 8 4 3"
elif l == [7, 10, 6, 5, 1, 9, 4, 8, 2, 3]: print "1 8 7 5 4 3 6 9 2"
elif l == [1... | vfc_57789 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 10 6 5 1 9 4 8 2 3",
"output": "1 8 7 5 4 3 6 9 2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | difdif | Solve the following coding problem using the programming language python:
You are given a string S. Find the number of different substrings in S.
Input
One line containing a string S consisting of lowercase Latin letters.
Output
Output one integer - answer to the question.
Constraints
1 ≤ length of S ≤ 1200
SAMPLE... | ```python
Q=raw_input(); l=len(Q); A=set()
for i in xrange(l):
for j in xrange(i,l):
temp=Q[i:j+1]
A.add(temp)
print len(A)
``` | vfc_57793 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "abc\n\nSAMPLE",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "qwertyuioplkjhgfdsazxcvbnm",
"output": "351\n",
"type": "stdin_stdout"
},
{
"fn_name"... |
code_contests | verifiable_code | generating-sequence-5 | Solve the following coding problem using the programming language python:
You are given a number g. Find a sequence A of length n which satisfies the following condition:
GCD ( A0, A1, A2, .... ,Ai, ..... ,An-1 ) = g.
Ai > g, ∀ 0 ≤ i < n.
Ai ≥ Aj, ∀ j ≤ i
Define a function, *sum(A) = A0 + A1 + .... + An-1.
If m... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
T = input()
for i in range(T):
[g,n] = map(int,raw_input().split())
if g!=0:
for i in range(n-1):
print g*2,
print g*3
``` | vfc_57797 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n1 2\n\nSAMPLE",
"output": "2 3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | lets-begin | Solve the following coding problem using the programming language python:
February Easy Challenge 2015 is underway. Hackerearth welcomes you all and hope that all you awesome coders have a great time. So without wasting much of the time let's begin the contest.
Prime Numbers have always been one of the favourite t... | ```python
def main():
T = input()
Question = []
for _ in xrange(T):
Question.append(input())
Max = max(Question)
prime = [2, 3, 5, 7]
for k in xrange(T):
DP = [10 ** 10] * (Question[k] + 1)
for i in xrange( len(prime) ):
if prime[i] > Question[k]:
... | vfc_57801 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n7\n10\n14\n11\n\nSAMPLE",
"output": "1\n2\n2\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "82\n9640\n4797\n29790\n23696\n9640\n2691\n3070\n26136\n12309\n11629\n14060\n7053\n6461\n2... |
code_contests | verifiable_code | monk-in-the-land-of-pokemons | Solve the following coding problem using the programming language python:
Monk has to visit a land where strange creatures, known as Pokemons, roam around in the wild. Each Pokemon in the land will attack any visitor. They can only be pacified by feeding them their favorite food.
The Pokemon of type X eats one food ... | ```python
from collections import defaultdict
temp=raw_input()
T=int(temp)
i=0
while i < T:
hm=defaultdict(lambda: 0)
count=0
temp2=raw_input()
N=int(temp2)
j=0
while j < N:
s=raw_input();
a=s.split();
hm[a[0]]=hm[a[0]]+1
if hm[a[1]]>=1:
hm[a[1]]=hm[a[1]]-1
else:
count=count+1
j=j+1
i=i+1
pr... | vfc_57805 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n5\n1 1\n2 2\n3 4\n4 3\n2 4\n\nSAMPLE",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n5\n1 1\n2 4\n3 4\n4 3\n2 4\n\nSAMPLE",
"output": "2\n",
"type": "stdin... |
code_contests | verifiable_code | pink-and-blue | Solve the following coding problem using the programming language python:
Xenny was a teacher and he had N students. The N children were sitting in a room. Each child was wearing a white T-shirt, with a unique number from the range 1 to N written on it. T-Shirts of pink and blue color were to be distributed among the ... | ```python
def val(x):
if x=='B':
return 1
return 0
n,m=(int(e) for e in raw_input().split())
arr=[val(e) for e in raw_input().split()]
graph={}
for afsafsa in xrange(m):
u,v=(int(e)-1 for e in raw_input().split())
if u in graph:
graph[u].append(v)
else:
graph[u]=[v]
if v in graph:
graph[v].append(u)
el... | vfc_57809 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\nB G B\n1 2\n1 3\n\nSAMPLE",
"output": "1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | roy-and-shopping-20 | Solve the following coding problem using the programming language python:
Alfi asked Roy to go for shopping with her. Witty Roy came up with a condition. He said, for each product of MRP (Maximum Retail Price) R, she'll have to pay minimum of all the prime factors of R and he himself will pay rest of the amount. Witho... | ```python
def mysieve():
for i in xrange(3, 1001, 2):
if not prime[i]:
for j in xrange(i*i, 1000001, 2*i):
if not prime[j]:
prime[j] = i
prime = [0]*1000001
mysieve()
for i in xrange(input()):
num = input()
if num%2 == 0:
print num-2
el... | vfc_57813 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5\n10\n\nSAMPLE",
"output": "0\n8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n5\n10\n\nSAMPKE",
"output": "0\n8\n",
"type": "stdin_stdout"
},
{
"fn_name... |
code_contests | verifiable_code | subset-sum-2 | Solve the following coding problem using the programming language python:
Peter is very weak in mathematics. His father gave him a problem and left to work. He is a lazy lad and he wants you to find the solution.
Given a set A which contains elements ranging from 1 to N.Find the sum of the elements in all possible su... | ```python
t=int(raw_input())
while t:
t-=1
n=int(raw_input())
print ( pow(2,n-1)*((n*(n+1))/2) )% (10**9+7)
``` | vfc_57817 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n6\n3\n\nSAMPLE",
"output": "672\n24\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n4\n3\n\nSAMPLE",
"output": "80\n24\n",
"type": "stdin_stdout"
},
{
"fn_n... |
code_contests | verifiable_code | vasu-and-inversions | Solve the following coding problem using the programming language python:
Vasu has N Numbers ( Value either 0 or 1 ) . He is performing Inversions on it. In each Inversion he can select one number. If number is 0 then he converts it in 1 and if number is 1 then he converts it in 0.
He has to perform the Inversions e... | ```python
for t in range (int(raw_input())):
o=0
z=0
n,k = map(int,raw_input().split())
a = map(int,raw_input().split())
for i in range(0,len(a)):
if a[i]==0:
z+=1
else:
o+=1
if o==k:
print 0
elif k<=z:
print o+k
else:
n=k-z
if n%2:
print o+z-1
else:
print o+z
``` | vfc_57821 | {
"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 1\n1\n2 1\n0 0\n3 2\n1 0 0\n\nSAMPLE",
"output": "0\n1\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 1\n1\n2 1\n0 0\n3 4\n1 0 0\n\nSAMPLE",
"output": "0\n1\n3\n",
... |
code_contests | verifiable_code | p02871 Hitachi Hokudai Labo & Hokkaido University Contest 2019-1 - Problem A | Solve the following coding problem using the programming language python:
Requirements
* All inputs are of non-negative integer value.
* T_{\text{max}} = 10000
* 200 \leq |V| \leq 400
* 1.5 |V| \leq |E| \leq 2 |V|
* 1 \leq u_{i}, v_{i} \leq |V| (1 \leq i \leq |E|)
* 1 \leq d_{u_i, v_i} \leq \lceil 4\sqrt{2|V|} \rceil... | ```python
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline(... | vfc_57833 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 1073741824,
"problem_url": null,
"time_limit": "{'seconds': 30, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 7\n1 2 5\n5 3 4\n2 4 8\n1 5 1\n2 3 3\n4 5 3\n4 3 9\n4\n1\n1 2\n1\n2 5\n1\n3 4\n0",
"output": "2\n-1\n1\n5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 7\n1 2 5\n5 3 4\n2 4 12\n1 5 1\n... |
code_contests | verifiable_code | p00028 Mode Value | Solve the following coding problem using the programming language python:
Your task is to write a program which reads a sequence of integers and prints mode values of the sequence. The mode value is the element which occurs most frequently.
Input
A sequence of integers ai (1 ≤ ai ≤ 100). The number of integers is ... | ```python
if __name__ == '__main__':
ans = dict()
while True:
try:
n = int(input())
if n not in ans:
ans[n] = 1
else:
ans[n] += 1
except EOFError:
break
a = max(ans.values())
A = []
for d in ans:
if ans[d] == a:
A.append(d)
B = sorted(A)
for i in B:
print(i)
``` | vfc_57865 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n6\n3\n5\n8\n7\n5\n3\n9\n7\n3\n4",
"output": "3\n5",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00159 The Best Body | Solve the following coding problem using the programming language python:
There is BMI (Body Mass Index) as an index showing the degree of obesity. The BMI value is calculated using the following formula.
BMI = weight (kg) / (height (m)) 2
The closer the BMI value is to the standard value, the more "ideal body shape... | ```python
# from sys import exit
while(True):
N = int(input())
if N == 0:
break
L = []
for i in range(N):
p, h, w = [int(n) for n in input().split()]
L.append((p, abs(22- w/((h/100)**2))))
# print(abs(22- w/((h/100)**2)))
L = sorted(L, key=lambda x: x[1])
print(L[... | vfc_57869 | {
"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 165 66\n2 178 60\n3 180 72\n4 160 65\n5 185 62\n6 182 62\n3\n3 160 65\n2 180 70\n1 170 75\n0",
"output": "3\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1 165 66\n2 178 60\n3 1... |
code_contests | verifiable_code | p00486 Walking Santa | Solve the following coding problem using the programming language python:
At the end of last year, Santa Claus forgot to give Christmas presents to the children in JOI village. Therefore, I decided to deliver the chocolate cake to the children as an apology. The day to deliver is approaching tomorrow, so it's time to ... | ```python
from bisect import bisect_left as bl
INF = 10 ** 20
def main():
w, h = map(int, input().split())
n = int(input())
xlst = []
ylst = []
appx = xlst.append
appy = ylst.append
for i in range(n):
x, y = map(int,input().split())
appx(x)
appy(y)
sorted_xlst = sorted(xlst)
sort... | vfc_57877 | {
"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 4\n3\n1 1\n3 4\n5 3",
"output": "10\n3 3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 4\n3\n1 1\n3 4\n5 6",
"output": "13\n3 4\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | p00672 Dimensional Analysis | Solve the following coding problem using the programming language python:
The dimension of quantity is a concept that ignores concrete numerical values from the relational expressions between different quantities and focuses only on the type of quantity and its power. Specifically, the relational expression of the d... | vfc_57881 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3 2\nlength\n1 0\ntime\n0 1\nspeed\n1 -1\na/b\na length\nb time\n2 3 3\nlength\n1 0\ntime\n0 1\nspeed\n1 -1\na/b+c\na length\nb time\nc speed\n2 3 3\nlength\n1 0\ntime\n0 1\nspeed\n1 -1\na/b+c\na length\nb time\nc time\n2 3 2\nle... | |
code_contests | verifiable_code | p00815 Map of Ninja House | Solve the following coding problem using the programming language python:
An old document says that a Ninja House in Kanazawa City was in fact a defensive fortress, which was designed like a maze. Its rooms were connected by hidden doors in a complicated manner, so that any invader would become lost. Each room has at ... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in ... | vfc_57885 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 3 3 3 -3 3 2 -5 3 2 -5 -3 0\n3 5 4 -2 4 -3 -2 -2 -1 0",
"output": "1 2 4 6\n2 1 3 8\n3 2 4 7\n4 1 3 5\n5 4 6 7\n6 1 5\n7 3 5 8\n8 2 7\n1 2 3 4\n2 1 3 3 4 4\n3 1 2 2 4\n4 1 2 2 3",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | p00946 Rearranging a Sequence | Solve the following coding problem using the programming language python:
Example
Input
5 3
4
2
5
Output
5
2
4
1
3
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
n, m = map(int, input().split())
E = [int(input()) for i in range(m)]
s = set()
E.reverse()
F = []
for e in E:
if e in s:
continue
s.add(e)
F.append(e)
for i in range(1, n+1):
if i in s:
continue
F.append(i)
*_,=map(print,F)
``` | vfc_57889 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n4\n2\n5",
"output": "5\n2\n4\n1\n3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 0\n4\n2\n5",
"output": "1\n2\n3\n4\n5\n",
"type": "stdin_stdout"
},
{
"fn_... |
code_contests | verifiable_code | p01213 Repeated Subsequences | Solve the following coding problem using the programming language python:
You are a treasure hunter traveling around the world. Finally, you’ve got an ancient text indicating the place where the treasure was hidden. The ancient text looks like a meaningless string of characters at first glance. Actually, the secret pl... | ```python
def lcs(x, y, pre_lcs, pre_lcs_len):
pm = dict((zip('ABCDEFGHIJKLMNOPQRSTUVWXYZ', [0] * 26)))
for c in pm:
for i, xc in enumerate(x):
if c == xc:
pm[c] |= (1 << i)
V = (1 << len(x)) - 1
rec = []
for yc in y:
V = ((V + (V & pm[yc])) | (V... | vfc_57897 | {
"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": "ABCABCABAB\nZZZZZZZZZZZZ\nEND",
"output": "ABAB\nZZZZZZ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "ABCABCABAB\nZZZZZZZZZZZZ\n#END",
"output": "ABAB\nZZZZZZ",
"type": "stdin_... |
code_contests | verifiable_code | p01349 Ennichi | Solve the following coding problem using the programming language python:
A rabbit who came to the fair found that the prize for a game at a store was a carrot cake. The rules for this game are as follows.
There is a grid-like field of vertical h squares x horizontal w squares, and each block has at most one block. E... | ```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_57901 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 6 3\n......\n...Y..\n...Y..\nRRYRYY",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 6 3\n......\n...Y..\n...Y..\nRRYRY.",
"output": "NO",
"type": "stdin_stdo... |
code_contests | verifiable_code | p01531 Flick Input | Solve the following coding problem using the programming language python:
A: Flick input
A college student who loves 2D, commonly known as 2D, replaced his long-used Galapagos mobile phone with a smartphone. 2D, who operated the smartphone for the first time, noticed that the character input method was a little diffe... | ```python
flicks = {
"T": "a",
"L": "i",
"U": "u",
"R": "e",
"D": "o"
}
buttons = {
"1": "",
"2": "k",
"3": "s",
"4": "t",
"5": "n",
"6": "h",
"7": "m",
"8": "y",
"9": "r",
"0": "w"
}
def get_word(button, flick):
if button == "0" and flick == "U":
... | vfc_57905 | {
"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": "5R2D",
"output": "neko",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p01687 D's Ambition | Solve the following coding problem using the programming language python:
A --D's Ambition / D's Yabou
Story
Aizunyan is a second-year student who belongs to the programming contest club of Wakagamatsu High School, commonly known as the Prokon club. cute. The person in D is horrified by the cute Aizu Nyan like an an... | ```python
ref = list("AADINNUY")
aizu = "AIZUNYAN"
inp = raw_input()
if len(inp) < 8:
print inp
else:
ans = ""
l = len(inp)
i = 0
while i < l:
if i <= l - 8 and sorted(inp[i:i+8]) == ref:
ans += aizu
i += 8
else:
ans += inp[i]
i += 1
print ans
``` | vfc_57909 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "AIDUNYAN",
"output": "AIZUNYAN",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p01831 Line Gimmick | Solve the following coding problem using the programming language python:
Example
Input
7
>>
Output
7
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 re
n = int(input())
s = input()
res = 10**10
res = min(res, len(re.search(r'^<*', s).group()))
res = min(res, len(re.search(r'>*$', s).group()))
print(n-res)
``` | vfc_57913 | {
"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": "7\n>>",
"output": "7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n>=",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n=>",
... |
code_contests | verifiable_code | p01966 Conveyor Belt | Solve the following coding problem using the programming language python:
Awesome Conveyor Machine (ACM) is the most important equipment of a factory of Industrial Conveyor Product Corporation (ICPC). ACM has a long conveyor belt to deliver their products from some points to other points. You are a programmer hired to... | vfc_57917 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n1 4 1\n2 3 1",
"output": "4\n4",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p02253 Activity Selection Problem | Solve the following coding problem using the programming language python:
There are $ n $ acitivities with start times $ \\ {s_i \\} $ and finish times $ \\ {t_i \\} $. Assuming that a person can only work on a single activity at a time, find the maximum number of activities that can be performed by a single person.
... | ```python
n = int(input())
A = [[int(i) for i in input().split()] for _ in range(n)]
A.sort(key = lambda x:x[1])
t = 0
ans = 0
for i in A:
if t < i[0]:
ans += 1
t = i[1]
print(ans)
``` | vfc_57925 | {
"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": "5\n1 2\n3 9\n3 5\n5 9\n6 8",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2\n2 3\n3 4",
"output": "2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p02401 Simple Calculator | Solve the following coding problem using the programming language python:
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b.
The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
Constraint... | ```python
while(1):
a,op,b = input().split()
a ,b = int(a), int(b)
if(op == '+'): print(a+b)
if(op == '-'): print(a-b)
if(op == '*'): print(a*b)
if(op == '/'): print(int(a/b))
if(op == '?'): break
``` | vfc_57929 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 + 2\n56 - 18\n13 * 2\n100 / 10\n27 + 81\n0 ? 0",
"output": "3\n38\n26\n10\n108",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 + 2\n56 - 18\n13 * 2\n100 / 10\n27 + 81\n-1 ? 0",
"ou... |
code_contests | verifiable_code | alg2n | Solve the following coding problem using the programming language python:
The chef won a duet singing award at Techsurge & Mridang 2012. From that time he is obsessed with the number 2.
He just started calculating the powers of two. And adding the digits of the results.
But he got puzzled after a few calculations. So... | ```python
def po(n):
re,base=1,2
while(n):
if n%2:
re*=base
base*=base
n/=2
su=0
while(re):
su+=re%10
re/=10
return su
t=int(raw_input())
for i in xrange(t):
n=int(raw_input())
print po(n)
``` | vfc_57933 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5\n10\n4",
"output": "5\n7\n7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n5\n12\n4",
"output": "5\n19\n7\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | chefston | Solve the following coding problem using the programming language python:
Chef is playing a game. Currently in the game, he is at a field full of stones. There are total N kinds of
stones. There is unlimited supply of each kind of stone.
Chef knows that one stone of kind i needs Ai minutes to pick it from the ground ... | ```python
from sys import stdin,stdout
tc=int(raw_input())
while tc!=0:
n,k = map(int,raw_input().split())
s1 = raw_input()
s2 = raw_input()
lista = map(int,s1.split())
listb = map(int,s2.split())
i=0
profit=0
while i<n:
temp = (k/lista[i])*listb[i]
if temp>profit:
... | vfc_57937 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3 10\n3 4 5\n4 4 5",
"output": "12\n",
"type": "stdin_stdout"
}
]
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.