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 | fun-with-factorial | Solve the following coding problem using the programming language python:
Raju loves playing with maths.He is very fond of factorials.Now he is interested in knowing the last five digits n!(nth number factorial).
As he is not very good at programming , so he needs your help.
Your task is to print the last five digits... | ```python
def fact(n):
if n==0:
return 1
return n*fact(n-1)
t=int(raw_input())
for i in range(t):
n=int(raw_input())
str1=""
k=fact(n)
fa=str(k)
if len(fa)==1:
str1='0000'+str1+fa
elif len(fa)==2:
str1='000'+str1+fa
elif len(fa)==3:
str1='00'+str1+fa
elif len(fa)==4:
str1='0'+str1+fa
else:
i=0
... | vfc_55301 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 \n2\n3\n4\n\nSAMPLE",
"output": "00001\n00002\n00006\n00024\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24",
"output": "68000\n88000\... |
code_contests | verifiable_code | jungle-run | Solve the following coding problem using the programming language python:
You are lost in a dense jungle and it is getting dark. There is at least one path that leads you to the city on the other side but you cannot see anything until you are right in front of it as the trees and bushes obscure the path.
Devise an ... | ```python
from collections import deque
import fileinput, copy
class Node:
def __init__(self, p, v, t):
self.pos = p
self.value = v
self.node_type = t
def __eq__(self, other):
return self.pos == other.pos
def addToQ(adj_pos, adj_node_value, Q, marked_list):
if (adj_pos[0] > -1... | vfc_55305 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\nS P P P P\nT P T P P\nT P P P P\nP T E T T\nP T P T T\n\nSAMPLE",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "14\nS P P P P P P T P T P P P P\nP P T P T P T P P E P T T... |
code_contests | verifiable_code | minimizing-path-cost | Solve the following coding problem using the programming language python:
In India, there are many railway stations. There's no way you could avoid one. So, the protagonist in our problem is given N railway stations and M direct two way connections for these railway stations. Let us say that we connect railway station... | ```python
N, K = [int(i) for i in raw_input().split()]
temp = raw_input().split()
nodes = dict((temp[i],i) for i in range(len(temp)))
graph = dict((i,[]) for i in range(len(temp)))
for i in range(K):
a, b, c = raw_input().split()
c = int(c)
a = nodes[a]
b = nodes[b]
graph[a].append((b,c))
graph[b].append((a,c))
... | vfc_55309 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4\nHowrah Trivandram Vashi Mysore\nHowrah Trivandram 10\nHowrah Vashi 20\nTrivandram Mysore 100\nMysore Vashi 50\n6\nHowrah Trivandram\nHowrah Vashi\nHowrah Mysore\nTrivandram Vashi\nTrivandram Mysore\nMysore Vashi\n\nSAMPLE",
... |
code_contests | verifiable_code | palindrome-check-2 | Solve the following coding problem using the programming language python:
You have been given a String S. You need to find and print whether this string is a palindrome or not. If yes, print "YES" (without quotes), else print "NO" (without quotes).
Input Format
The first and only line of input contains the String S.... | ```python
a=raw_input();
b=a[::-1]
if a==b:
print 'YES'
else:
print 'NO'
``` | vfc_55313 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "aba\n\nSAMPLE",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "izvnxvusaemgsgujwjaxkwdyeufbpfgbilfyxozyssuufxwfduudfwxfuussyzoxyflibgfpbfueydwkxajwjugsgmeasuvxnvzi",
... |
code_contests | verifiable_code | rhezo-and-big-powers-1 | Solve the following coding problem using the programming language python:
Rhezo likes numbers of the form A^B. But computing A^B, for any 2 numbers A and B is a hard task for him. He would like you to help him out in this.
Input:
First line of input contains a single integer A. Second line contains the integer B.
Ou... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
def power(b, p,md):
if p == 0:
return 1;
elif p%2 == 0:
res = power(b, p/2,md)
return (res*res)%md
else:
res = power(b, p/2,md)
... | vfc_55317 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n3\n\nSAMPLE",
"output": "64\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n5\n\nSAMPLE",
"output": "1024\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | special-numbers-8 | Solve the following coding problem using the programming language python:
Suppose n1, n2, . . . . , nk are positive integers that are pairwise coprime. Then, for any given sequence of integers a1, a2, . . . . , ak, there exists an integer x solving the following system of simultaneous congruences.
x = a1 mod(n1)
x ... | ```python
import functools
import sys
def chinese_remainder(n, a, k):
sum = 0
prod = reduce(lambda a, b: a*b, n)
#prod = 1
#for b in range(k):
# prod=prod*n[b]
for n_i, a_i in zip(n, a):
p = prod // n_i
sum += a_i * mul_inv(p, n_i) * p
return sum % prod
def mul_inv(a, b):... | vfc_55321 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3 1\n3 5 7\n2 3 2\n\nSAMPLE",
"output": "23",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n5 5\n5 11 17 23 101\n3 5 7 2 51\n5 100\n3 7 13 19 29\n2 2 6 11 8",
"output": "8126715\... |
code_contests | verifiable_code | trailing-zeros | Solve the following coding problem using the programming language python:
Given a number find the number of trailing zeroes in its factorial.
Input Format
A single integer - N
Output Format
Print a single integer which is the number of trailing zeroes.
Input Constraints
1 ≤ N ≤ 1000
Problem Setter: Practo Tech ... | ```python
import math
i = input()
if i >= 1 and i <=1000:
f = math.factorial(i)
l = len(str(f))
l1 = [f % (10**k) for k in range(1,l+1) if f % (10**k) == 0]
print len(l1)
else:
print "invalid input"
``` | vfc_55325 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6",
"out... |
code_contests | verifiable_code | p00129 Hide-and-Seek Supporting System | Solve the following coding problem using the programming language python:
Taro is not good at hide-and-seek. As soon as you hide, you will find it, and it will be difficult to find the hidden child. My father, who couldn't see it, made an ultra-high performance location search system. You can use it to know exactly wh... | ```python
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0129
"""
import sys
from sys import stdin
from math import sqrt, atan2, acos, sin, cos, hypot
input = stdin.readline
class Point(object):
epsilon = 1e-10
def __init__(self, x=0.0, y=0.0):
if isinstance(x,... | vfc_55373 | {
"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\n6 6 3\n19 7 4\n21 8 1\n6\n5 4 2 11\n12 4 2 11\n11 9 2 11\n14 3 20 5\n17 9 20 5\n20 10 20 5\n0",
"output": "Safe\nSafe\nDanger\nSafe\nDanger\nSafe",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | p00449 Boat Travel | Solve the following coding problem using the programming language python:
problem
There are n islands in JOI, and each island is numbered from 1 to n. Currently, the JOI country is developing a route network connecting each island.
You work at a ticket center that handles ship tickets. There are many people in JOI w... | ```python
# AOJ 0526: Boat Travel
# Python3 2018.7.1 bal4u
INF = 0x7fffffff
while True:
n, k = map(int, input().split())
if n == 0: break
fee = [[INF for j in range(101)] for i in range(101)]
for i in range(n+1): fee[i][i] = 0
for i in range(k):
v = list(map(int, input().split()))
a, b = v[1], v[2]
if v[0] ... | vfc_55381 | {
"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 8\n1 3 1 10\n0 2 3\n1 2 3 20\n1 1 2 5\n0 3 2\n1 1 3 7\n1 2 1 9\n0 2 3\n5 16\n1 1 2 343750\n1 1 3 3343\n1 1 4 347392\n1 1 5 5497\n1 2 3 123394\n1 2 4 545492\n1 2 5 458\n1 3 4 343983\n1 3 5 843468\n1 4 5 15934\n0 2 1\n0 4 1\n0 3 2\... |
code_contests | verifiable_code | p00640 Distorted Love | Solve the following coding problem using the programming language python:
Saying that it is not surprising that people want to know about their love, she has checked up his address, name, age, phone number, hometown, medical history, political party and even his sleeping position, every piece of his personal informati... | ```python
# AOJ 1054: Distorted Love
# Python3 2018.7.7 bal4u
while True:
n = int(input())
if n == 0: break
input() # w, h
pag, dic = [], {}
for i in range(n):
nm, k = input().split()
dic[nm] = i
btn = []
for j in range(int(k)):
x1, y1, x2, y2, bnm = input().split()
btn.append((int(x1), int(y1), i... | vfc_55385 | {
"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\n800 600\nindex 1\n500 100 700 200 profile\nprofile 2\n100 100 400 200 index\n100 400 400 500 link\nlink 1\n100 100 300 200 index\n9\nclick 600 150\nshow\nclick 200 450\nshow\nback\nback\nshow\nforward\nshow\n0",
"output": ... |
code_contests | verifiable_code | p00783 Napoleon's Grumble | Solve the following coding problem using the programming language python:
Legend has it that, after being defeated in Waterloo, Napoleon Bonaparte, in retrospect of his days of glory, talked to himself "Able was I ere I saw Elba." Although, it is quite doubtful that he should have said this in English, this phrase is ... | vfc_55389 | {
"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": "As the first man said to the\nfirst woman:\n\"Madam, I'm Adam.\"\nShe responded:\n\"Eve.\"",
"output": "TOT\n\nMADAMIMADAM MADAM\nERE DED\nEVE",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p00916 Count the Regions | Solve the following coding problem using the programming language python:
There are a number of rectangles on the x-y plane. The four sides of the rectangles are parallel to either the x-axis or the y-axis, and all of the rectangles reside within a range specified later. There are no other constraints on the coordinat... | ```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_55393 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4 28 27 11\n15 20 42 5\n11 24 33 14\n5\n4 28 27 11\n12 11 34 2\n7 26 14 16\n14 16 19 12\n17 28 27 21\n2\n300000 1000000 600000 0\n0 600000 1000000 300000\n0",
"output": "8\n6\n6",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | p01049 Array Update | Solve the following coding problem using the programming language python:
Problem
There is an arithmetic progression A with the number of terms N, the first term a, and the tolerance d. Since M statements that update the sequence are given in the following format, find the value of the K item when the sequence A is u... | ```python
n = int(input())
a, d = map(int, input().split())
mem = {}
def get_mem(num):
if num in mem:return mem[num]
else:return num
m = int(input())
for _ in range(m):
x, y, z = map(int, input().split())
if x == 0:
ny, nz = get_mem(y), get_mem(z)
mem[y] = nz
mem[z] = ny
if x == 1:
nz ... | vfc_55397 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 267386880,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n5 5\n4\n0 1 2\n1 1 2\n0 4 1\n1 1 6\n3",
"output": "15",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n2 3\n3\n0 2 5\n0 3 5\n1 2 4\n2",
"output": "11",
"type": "stdin_stdout... |
code_contests | verifiable_code | p01318 Immortal Jewels | Solve the following coding problem using the programming language python:
English text is not available in this practice contest.
At one point, a nobleman fell in love with a brave princess in a poor country and applied for marriage. The princess has given certain conditions to the aristocrats. The condition was to b... | ```python
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def common_tangent_lines(x1, y1, r1, x2, y2, r2):
result = []
xd = x2 - x1; yd = y2 - y1
rr0 = xd**2 + yd**2
if (r1 - r2)**2 <= rr0:
cv = r1 - r2
if rr0 == (r1 - r2)**2:
bx = r1*cv*xd/rr0
... | vfc_55405 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n-2 -2 1 1\n2 2 2 0\n5 7 1 1\n8 0 3 1\n13 4 1 1\n16 1 1 2\n3\n0 0 2 1\n10 0 2 1\n0 10 2 1\n3\n0 0 2 1\n10 0 2 1\n0 6 2 1\n3\n0 0 2 1\n10 0 2 1\n0 4 2 1\n1\n0 0 1 1\n0",
"output": "4\n2\n3\n3\n1",
"type": "stdin_stdout... |
code_contests | verifiable_code | p01486 CatChecker | Solve the following coding problem using the programming language python:
Example
Input
mmemewwemeww
Output
Cat
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
b=s=input()
while 1:
s=re.sub(r'(m|e)mew(e|w)','\\1\\2',s)
if b==s:break
b=s
print(['Rabbit','Cat'][s=='mew'])
``` | vfc_55409 | {
"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": "mmemewwemeww",
"output": "Cat",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p01648 Median Tree | Solve the following coding problem using the programming language python:
Problem Statement
You are given a connected undirected graph which has even numbers of nodes. A connected graph is a graph in which all nodes are connected directly or indirectly by edges.
Your task is to find a spanning tree whose median valu... | ```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_55413 | {
"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": "2 1\n1 2 5\n4 6\n1 2 1\n1 3 2\n1 4 3\n2 3 4\n2 4 5\n3 4 6\n8 17\n1 4 767\n3 1 609\n8 3 426\n6 5 972\n8 1 607\n6 4 51\n5 1 683\n3 6 451\n3 4 630\n8 7 912\n3 7 43\n4 7 421\n3 5 582\n8 4 538\n5 7 832\n1 6 345\n8 2 608\n0 0",
"ou... |
code_contests | verifiable_code | p01799 New Game AI | Solve the following coding problem using the programming language python:
Example
Input
5 3
1 5
3 4
5 3
7 2
9 1
Output
5
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. | vfc_55417 | {
"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\n1 5\n3 4\n5 3\n7 2\n9 1",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3\n1 5\n3 4\n5 0\n7 2\n9 1",
"output": "3\n",
"type": "stdin_stdout"
},
{
... | |
code_contests | verifiable_code | p01933 Displayed tweets | Solve the following coding problem using the programming language python:
problem
In Ikatta, the SNS used by AOR Ika-chan, posts are called tweets.
And in squid, there is a concern that visibility will deteriorate if there are many replies to tweets, so when a tweet meets any of the following rules, the tweet will b... | ```python
# AOJ 2833: Displayed tweets
# Python3 2018.7.12 bal4u
INF = 0x7ffffff
N, K = map(int, input().split())
k, f = [INF]*(N+1), [0]*(N+1)
a = [0]+[int(input()) for i in range(N)]
ans = 0
for i in range(N, 0, -1):
re = a[i]
if re:
if f[i] == 0: v = 0; ans += 1
else:
v = k[i]
if v < K: ans += 1
v +=... | vfc_55421 | {
"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": "6 3\n0\n0\n2\n3\n4\n5",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 6\n0\n0\n2\n3\n4\n5",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name":... |
code_contests | verifiable_code | p02071 Consistent Trading | Solve the following coding problem using the programming language python:
Problem Statement
Your company is developing a video game. In this game, players can exchange items. This trading follows the rule set by the developers. The rule is defined as the following format: "Players can exchange one item $A_i$ and $x_i... | vfc_55425 | {
"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": "",
"output": "",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p02367 Bridges | Solve the following coding problem using the programming language python:
Find bridges of an undirected graph G(V, E).
A bridge (also known as a cut-edge) is an edge whose deletion increase the number of connected components.
Constraints
* 1 ≤ |V| ≤ 100,000
* 0 ≤ |E| ≤ 100,000
* The graph is connected
* There are n... | ```python
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, ... | vfc_55433 | {
"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 4\n0 1\n1 2\n2 3\n3 4",
"output": "0 1\n1 2\n2 3\n3 4",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | atom | Solve the following coding problem using the programming language python:
Mr. Yagami is a scientist in the Bhabha Atomic Research Centre. They are
conducting a lab experiment on nuclear fission. In nuclear fission, one atom
breaks into more than one atom of the same type.
Initially, there are N atoms in the lab... | ```python
import math
t=input("")
while(t):
inp=raw_input("")
inp=inp.split()
n=int(inp[0]);k=int(inp[1]);m=int(inp[2])
m=m/n;
if(m>0):
print int(math.log(m,k))
else:
print 0
t=t-1
``` | vfc_55437 | {
"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 2 7\n2 2 8",
"output": "1\n2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | clperm | Solve the following coding problem using the programming language python:
Today is Chef's birthday. His mom gifted him a truly lovable gift, a permutation of first N positive integers.
She placed the permutation on a very long table in front of Chef and left it for him to play with it. But as there was a lot of people... | ```python
A = []
def series(n):
return int(( n * (n + 1) ) / 2)
t = input()
while t > 0:
n,k = list(map(int,raw_input().split()))
if k != 0:
A = list(map(int,raw_input().split()))
A.append(n + 1)
A.sort()
s = 0
i = 0
if k == 0:
s = series(n)
else:
for i in ran... | vfc_55441 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5 2\n3 5\n5 1\n1",
"output": "Mom\nChef",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n5 2\n3 5\n7 1\n1",
"output": "Mom\nChef\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | flow008 | Solve the following coding problem using the programming language python:
Write a program, which takes an integer N and if the number is less than 10 then display "What an obedient servant you are!" otherwise print "-1".
Input
The first line contains an integer T, total number of testcases. Then follow T lines, eac... | ```python
t=int(raw_input())
while t:
t-=1
n=int(raw_input())
if n<10:
print "What an obedient servant you are!"
else:
print "-1"
``` | vfc_55445 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 \n1\n12\n-5",
"output": "What an obedient servant you are!\n-1\nWhat an obedient servant you are!\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 \n0\n12\n-5",
"output": "What an... |
code_contests | verifiable_code | lelemon | Solve the following coding problem using the programming language python:
Little Elephant likes lemonade.
When Little Elephant visits any room, he finds the bottle of the lemonade in that room that contains the greatest number of litres of lemonade and drinks it all.
There are n rooms (numbered from 0 to n-1), each ... | ```python
t = int(raw_input())
for q in xrange(t):
s = raw_input().split();
n = int(s[0])
m = int(s[1])
rooms = map(int,raw_input().split());
arr = [];
count = 0;
for p in xrange(n):
a = map(int,raw_input().split());
a = a[1:];
a.sort();
arr.append(a);
for i in xrange(m):
a = 0;
try:
a = arr[room... | vfc_55449 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 3\n0 2 1\n3 1 2 3\n1 7\n2 4 7\n4 7\n0 1 3 0 1 0 0\n1 7\n3 9 4 5\n7 1 2 3 4 5 6 7\n1 1",
"output": "17\n22\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3 3\n0 2 1\n3 1 2 3\n1 7\n... |
code_contests | verifiable_code | power2 | Solve the following coding problem using the programming language python:
Problem Description:
Mr. Y’s favourite number is the number 2. Such is his passion that he begins to hate all other digits. Whenever faced with a number he tries to convert it to sum of powers of 2 where the power is non-zero positive integer. I... | ```python
a = input()
for x in range(a):
n = input()
if n == 0:
print 'No'
elif n % 2 == 0:
print 'Yes'
else:
print 'No'
``` | vfc_55453 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n6",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n4",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n7"... |
code_contests | verifiable_code | submin | Solve the following coding problem using the programming language python:
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K ... | ```python
N = int(raw_input())
A = map(int, raw_input().split(" "))
min_list = []
for i in xrange(N):
for j in xrange(i,N):
min_list.append(min(A[i:j+1]))
for _ in xrange(int(raw_input())):
K = int(raw_input())
print min_list.count(K)
``` | vfc_55457 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n4 1 2 3 4\n4\n3\n4\n6\n1",
"output": "2\n2\n0\n8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n4 0 2 3 4\n4\n3\n4\n6\n1",
"output": "2\n2\n0\n0\n",
"type": "stdin_stdou... |
code_contests | verifiable_code | 100_G. Name the album | Solve the following coding problem using the programming language python:
The famous singer, Aryo, is going to publish a new album of his great work!
Unfortunately these days, there are many albums, Aryo wants to choose a new name for his album, a name that has not been used or at least has not been used recently.
H... | vfc_55461 | {
"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": "3\neyesonme 2008\nanewdayhascome 2002\noneheart 2003\n2\noneheart\nbienbien\n",
"output": "bienbien\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\nnasimevasl 2003\nbasetareha 2006\n2\n... | |
code_contests | verifiable_code | 1033_D. Divisors | Solve the following coding problem using the programming language python:
You are given n integers a_1, a_2, …, a_n. Each of a_i has between 3 and 5 divisors. Consider a = ∏ a_i — the product of all input integers. Find the number of divisors of a. As this number may be very large, print it modulo prime number 9982443... | ```python
from math import gcd
def divisors(n, a):
d = {}
bad = []
for i in range(n):
c = a[i]
if (int(c ** 0.25 + 0.0001)) ** 4 == c:
p = int(c ** 0.25 + 0.0001)
if p not in d:
d[p] = 4
else:
d[p] += 4
elif (int(... | vfc_55465 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4\n8\n16\n",
"output": "10\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1056_B. Divide Candies | Solve the following coding problem using the programming language python:
Arkady and his friends love playing checkers on an n × n field. The rows and the columns of the field are enumerated from 1 to n.
The friends have recently won a championship, so Arkady wants to please them with some candies. Remembering an old... | ```python
n,m=map(int,input().split())
s=list()
for i in range(1,m+1):
for j in range(1,m+1):
if (i**2+j**2)%m==0:
s.append([i,j])
ans=0
for k in s:
#print(k)
ky=(n-k[0])//(m)+1
my=(n-k[1])//(m)+1
ans+=ky*my
print(ans)
``` | vfc_55469 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 5\n",
"output": "13",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000000... |
code_contests | verifiable_code | 1078_C. Vasya and Maximum Matching | Solve the following coding problem using the programming language python:
Vasya has got a tree consisting of n vertices. He wants to delete some (possibly zero) edges in this tree such that the maximum matching in the resulting graph is unique. He asks you to calculate the number of ways to choose a set of edges to re... | vfc_55473 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2\n1 3\n1 4\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1099_C. Postcard | Solve the following coding problem using the programming language python:
Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that this string is an encrypted message, and decided to ... | ```python
s=input()
k=int(input())
temp=""
cnt=0
for i in range(len(s)):
if(s[i]=="?" or s[i]=="*"):
cnt+=1
continue
else:
temp+=s[i]
#print(temp,len(temp))
if(len(temp)-cnt>k):
print("Impossible")
elif(len(temp)==k):
print(temp)
elif(len(temp)<k):
req=k-len(temp)
temp2=""
flag=0
for i in range(len(s)):
... | vfc_55477 | {
"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": "ab?a\n3\n",
"output": "aba\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "ababb\n5\n",
"output": "ababb\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 111_B. Petya and Divisors | Solve the following coding problem using the programming language python:
Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:
You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi,... | ```python
maxn=100000
div=[0]*(maxn+1)
last=[-maxn]*(maxn+1)
for i in range(maxn+1):
div[i]=list()
for i in range(2,maxn+1):
for j in range(i,maxn+1,i):
div[j].append(i)
t=int(input())
for k in range(0,t):
x_i,y_i = input().split(" ")
x_i=int(x_i)
y_i=int(y_i)
if y_i==0:
prin... | vfc_55481 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n4 0\n3 1\n5 2\n6 2\n18 4\n10000 3\n",
"output": "3\n1\n1\n2\n2\n22\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "15\n94836 0\n22780 1\n48294 0\n24834 3\n37083 2\n57862 0\n37231 1\n817... |
code_contests | verifiable_code | 1146_G. Zoning Restrictions | Solve the following coding problem using the programming language python:
You are planning to build housing on a street. There are n spots available on the street on which you can build a house. The spots are labeled from 1 to n from left to right. In each spot, you can build a house with an integer height between 0 a... | vfc_55485 | {
"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 3 3\n1 1 1 1000\n2 2 3 1000\n3 3 2 1000\n",
"output": "14",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 10 2\n2 3 8 76\n3 4 7 39\n",
"output": "289",
"type": "stdin_stdout"... | |
code_contests | verifiable_code | 1186_C. Vus the Cossack and Strings | Solve the following coding problem using the programming language python:
Vus the Cossack has two binary strings, that is, strings that consist only of "0" and "1". We call these strings a and b. It is known that |b| ≤ |a|, that is, the length of b is at most the length of a.
The Cossack considers every substring of ... | ```python
a=input()
b=input()
A=[]
al=len(a)
bl=len(b)
A.append(0)
count=0
for x in a:
if x=='1':
count+=1
A.append(count)
evencount=0
bcount=0
for x in b:
if x=='1':
bcount+=1
for i in range((al+1)-bl):
acount=A[i+bl]-A[i]
if (acount%2)==(bcount%2):
evencount+=1
print(evenco... | vfc_55493 | {
"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": "01100010\n00110\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1010111110\n0110\n",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1205_B. Shortest Cycle | Solve the following coding problem using the programming language python:
You are given n integer numbers a_1, a_2, ..., a_n. Consider graph on n nodes, in which nodes i, j (i≠ j) are connected if and only if, a_i AND a_j≠ 0, where AND denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation... | ```python
from collections import *
import sys
# "". join(strings)
def ri():
return int(input())
def rl():
return list(map(int, input().split()))
n = ri()
aa = rl()
zero_cnt = 0
aa = [value for value in aa if value != 0]
n = len(aa)
edges = set()
graph = defaultdict(list)
bit_shared... | vfc_55497 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 4 8\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n5 12 9 16 48\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | 1221_F. Choose a Square | Solve the following coding problem using the programming language python:
Petya recently found a game "Choose a Square". In this game, there are n points numbered from 1 to n on an infinite field. The i-th point has coordinates (x_i, y_i) and cost c_i.
You have to choose a square such that its sides are parallel to c... | vfc_55501 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 6, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n3 3 0\n3 3 -3\n0 2 -1\n3 1 3\n0 0 -2\n",
"output": "0\n2000000000 2000000000 2000000000 2000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n0 0 2\n1 0 -5\n1 1 3\n2 3 4\n1 4 -4... | |
code_contests | verifiable_code | 1248_C. Ivan the Fool and the Probability Theory | Solve the following coding problem using the programming language python:
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demon... | ```python
N = int(1e5+3)
MOD = int(1e9+7)
memo = [0] * N
def dp():
memo[0] = 2
memo[1] = 2
for i in range(2, N):
memo[i] = (memo[i-1] + memo[i-2]) % MOD
n, m = map(int, input().split())
dp()
print((memo[n] + - 1 + memo[m] - 1) % MOD)
``` | vfc_55505 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3\n",
"output": "8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "91697 91697\n",
"output": "999949469",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
code_contests | verifiable_code | 1266_G. Permutation Concatenation | Solve the following coding problem using the programming language python:
Let n be an integer. Consider all permutations on integers 1 to n in lexicographic order, and concatenate them into one big sequence P. For example, if n = 3, then P = [1, 2, 3, 1, 3, 2, 2, 1, 3, 2, 3, 1, 3, 1, 2, 3, 2, 1]. The length of this se... | ```python
n = int(input())
f_n = n
cnt = 0
for k in range(n-1, 0, -1):
cnt += f_n
f_n *= k
if f_n >= 998244353:
f_n %= 998244353
print((n*f_n-cnt)%998244353)
``` | vfc_55509 | {
"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": "2\n",
"output": " 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n",
"output": " ... |
code_contests | verifiable_code | 1288_B. Yet Another Meme Problem | Solve the following coding problem using the programming language python:
Try guessing the statement from this picture <http://tiny.cc/ogyoiz>.
You are given two integers A and B, calculate the number of pairs (a, b) such that 1 ≤ a ≤ A, 1 ≤ b ≤ B, and the equation a ⋅ b + a + b = conc(a, b) is true; conc(a, b) is th... | ```python
for _ in range(int(input())):
A, B = list(map(int, input().split()))
res = 0
seed = 9
while seed <= B:
res += A
seed = seed*10 + 9
print(res)
``` | vfc_55513 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 11\n4 2\n191 31415926\n",
"output": "1\n0\n1337\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n9 9009\n",
"output": "27\n",
"type": "stdin_stdout"
},
{
"... |
code_contests | verifiable_code | 130_B. Gnikool Ssalg | Solve the following coding problem using the programming language python:
You are given a string. Reverse its characters.
Input
The only line of input contains a string between 1 and 100 characters long. Each character of the string has ASCII-code between 33 (exclamation mark) and 126 (tilde), inclusive.
Output
Ou... | vfc_55517 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "secrofedoc\n",
"output": "codeforces\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "!ssalg-gnikool5\n",
"output": "5looking-glass!\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1331_E. Jordan Smiley | Solve the following coding problem using the programming language python:
<image>
Input
The input contains two integers row, col (0 ≤ row, col ≤ 63), separated by a single space.
Output
Output "IN" or "OUT".
Examples
Input
0 0
Output
OUT
Input
27 0
Output
IN
Input
0 27
Output
OUT
Input
... | ```python
s = [
"0000000000000000000000000010101111110100000000000000000000000000",
"0000000000000000000000101110101010010111110000000000000000000000",
"0000000000000000000011101000100011010000100100000000000000000000",
"0000000000000000011110101011111000011110101110100000000000000000",
"0000000000000000110000001010000... | vfc_55521 | {
"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": "0 0\n",
"output": "OUT",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1351_C. Skier | Solve the following coding problem using the programming language python:
Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to 1 meter movement in the south, north, west or east direction respectively).
It is known that if he moves along a prev... | ```python
num_lines = int(input())
for _ in range(num_lines):
d = input()
c = 0
points = set()
start_point = (0, 0)
for s in d:
if s == 'N':
end_point = (start_point[0] + 1, start_point[1])
if s == 'S':
end_point = (start_point[0] - 1, start_point[1])
... | vfc_55525 | {
"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\nNNN\nNS\nWWEN\nWWEE\nNWNWS\n",
"output": "15\n6\n16\n12\n25\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1371_E1. Asterism (Easy Version) | Solve the following coding problem using the programming language python:
This is the easy version of the problem. The difference between versions is the constraints on n and a_i. You can make hacks only if all versions of the problem are solved.
First, Aoi came up with the following idea for the competitive programm... | ```python
import sys
input = sys.stdin.readline
n,p=map(int,input().split())
A=sorted(map(int,input().split()))
MAX=A[-1]
start=max(A[0],MAX-(n-1))
S=[]
ind=0
for c in range(start,MAX+1):
while ind<n and A[ind]<=c:
ind+=1
S.append(ind)
#print(S)
SS=[S[i]-i for i in range(len(S))]
MAX=10**9
MIN=0
fo... | vfc_55529 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n2 3 5 6\n",
"output": "2\n3 4 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n3 4 5\n",
"output": "1\n3 \n",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | 1436_F. Sum Over Subsets | Solve the following coding problem using the programming language python:
You are given a multiset S. Over all pairs of subsets A and B, such that:
* B ⊂ A;
* |B| = |A| - 1;
* greatest common divisor of all elements in A is equal to one;
find the sum of ∑_{x ∈ A}{x} ⋅ ∑_{x ∈ B}{x}, modulo 998 244 353.
In... | ```python
import sys
input=sys.stdin.readline
max_n=10**5+1
mod=998244353
spf=[i for i in range(max_n)]
prime=[True for i in range(max_n)]
mobius=[0 for i in range(max_n)]
prime[0]=prime[1]=False
mobius[1]=1
primes=[]
for i in range(2,max_n):
if(prime[i]):
spf[i]=i
mobius[i]=-1
primes.appen... | vfc_55541 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n1 5\n",
"output": "560\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 1\n2 1\n3 1\n6 1\n",
"output": "1207\n",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | 1461_D. Divide and Summarize | Solve the following coding problem using the programming language python:
Mike received an array a of length n as a birthday present and decided to test how pretty it is.
An array would pass the i-th prettiness test if there is a way to get an array with a sum of elements totaling s_i, using some number (possibly zer... | ```python
from sys import stdin, stdout
input = stdin.readline
print = stdout.write
s = set()
def rec(a):
s.add(sum(a))
c = (min(a) + max(a)) / 2
sl = sr = 0
left = []
right = []
for i in a:
if i <= c:
left += i,
sl += i
else:
right += i,
... | vfc_55545 | {
"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\n5 5\n1 2 3 4 5\n1\n8\n9\n12\n6\n5 5\n3 1 3 1 3\n1\n2\n3\n9\n11\n",
"output": "\nYes\nNo\nYes\nNo\nYes\nNo\nYes\nNo\nYes\nYes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n5 5\n1 2 ... |
code_contests | verifiable_code | 1486_E. Paired Payment | Solve the following coding problem using the programming language python:
There are n cities and m bidirectional roads in the country. The roads in the country form an undirected weighted graph. The graph is not guaranteed to be connected. Each road has it's own parameter w. You can travel through the roads, but the g... | ```python
import sys, io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
read = lambda: map(int, input().split())
from heapq import heappush, heappop
inf = 1e10
n, m = read()
e = {}
for _ in range(m):
v, u, w = read()
v -= 1
u -= 1
if v not in e:
e[v] = []
if u not in e:
... | vfc_55549 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n1 2 1\n2 3 2\n",
"output": "\n0 -1 9 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 6\n1 2 3\n2 3 4\n3 4 5\n4 5 6\n1 5 1\n2 4 2\n",
"output": "\n0 98 49 25 114 ",
"type"... |
code_contests | verifiable_code | 1538_A. Stone Game | Solve the following coding problem using the programming language python:
Polycarp is playing a new computer game. This game has n stones in a row. The stone on the position i has integer power a_i. The powers of all stones are distinct.
Each turn Polycarp can destroy either stone on the first position or stone on th... | ```python
t=int(input())
while t!=0:
t-=1
n=int(input())-1
a=list(map(int,input().split()))
le=min(a.index(max(a)),a.index(min(a)))
ri=max(a.index(max(a)),a.index(min(a)))
mid=ri-le-1
ri=n-ri
print(sum([le,ri,mid])-max(le,ri,mid)+2)
``` | vfc_55557 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n5\n1 5 4 3 2\n8\n2 1 3 4 5 6 8 7\n8\n4 2 3 1 8 6 7 5\n4\n3 4 2 1\n4\n2 3 1 4\n",
"output": "\n2\n4\n5\n3\n2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 164_A. Variable, or There and Back Again | Solve the following coding problem using the programming language python:
Life is not easy for the perfectly common variable named Vasya. Wherever it goes, it is either assigned a value, or simply ignored, or is being used!
Vasya's life goes in states of a program. In each state, Vasya can either be used (for example... | vfc_55561 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1\n2 0 1\n1 3\n",
"output": "0\n0\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n1 0 0 2\n1 2\n2 3\n3 4\n",
"output": "1\n1\n1\n1\n",
"type": "stdin_stdout"
}
... | |
code_contests | verifiable_code | 185_B. Mushroom Scientists | Solve the following coding problem using the programming language python:
As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center... | ```python
a=int(input())
b=list(map(int,input().split()))
if sum(b)==0:print(' '.join([str(a/3)]*3))
else:print(' '.join(map(str,map(lambda x:a*x/sum(b),b))))
``` | vfc_55565 | {
"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\n1 1 1\n",
"output": "0.999999996642397 0.9999999922705483 1.0000000110870548\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 0 0\n",
"output": "2.999999999999999 0 8.88178419... |
code_contests | verifiable_code | 231_C. To Add or Not to Add | Solve the following coding problem using the programming language python:
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array.
However, before looking for such number, you are allowed to perform not more than k following... | ```python
import sys
import math as mt
input=sys.stdin.buffer.readline
#t=int(input())
t=1
for __ in range(t):
#n=int(input())
n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
maxn,maxl=l[0],1
suma=[0]*(n+2)
suma[0]=0
for i in range(n):
suma[i+1]=suma... | vfc_55573 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n5 5 5\n",
"output": "3 5\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 257_B. Playing Cubes | Solve the following coding problem using the programming language python:
Petya and Vasya decided to play a little. They found n red cubes and m blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put it in a line from left to right (overall the line will have n... | ```python
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt'... | vfc_55577 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 4\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n",
"output": "2 1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 280_B. Maximum Xor Secondary | Solve the following coding problem using the programming language python:
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, ..., xk (k > 1) is such maximum element xj, that the following inequality holds: <image>.
The lucky number... | ```python
#http://codeforces.com/problemset/problem/281/D
#SC = TC = o(n)
n = int(input())
a = list(map(int, input().strip().split()))
stack = [] #decreasing stack
max_xor = 0
for k in range(n):
#if stack empty
if not stack:
stack.append(a[k])
#if less than top of stack
elif a[k]<stack[-1]:
max_xor = max(m... | vfc_55581 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n9 8 3 5 7\n",
"output": "15\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 303_A. Lucky Permutation Triple | Solve the following coding problem using the programming language python:
Bike is interested in permutations. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] is n... | ```python
n = int(input())
if n % 2 == 0:
print(-1)
else:
print(*range(n))
print(*range(n))
print(*map(lambda x: x * 2 % n, range(n)))
``` | vfc_55585 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n",
"output": "0 1 2 3 4 \n0 1 2 3 4 \n0 2 4 1 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | 32_B. Borze | Solve the following coding problem using the programming language python:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given... | ```python
x=input()
code=x.split()
q=[]
for i in x:
q.append(i)
code=q
i=0
total=""
while i < len(code):
if(code[i] == '.'):
total = total + '0'
elif(code[i] == '-'):
if(code[i + 1] == '.'):
total =total + '1'
elif (code[i+1] == '-'):
total = total + '2'
... | vfc_55589 | {
"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": "--.\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ".-.--\n",
"output": "012\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-.... |
code_contests | verifiable_code | 350_E. Wrong Floyd | Solve the following coding problem using the programming language python:
Valera conducts experiments with algorithms that search for shortest paths. He has recently studied the Floyd's algorithm, so it's time to work with it.
Valera's already written the code that counts the shortest distance between any pair of ver... | ```python
# written with help of editorial
n, m, k = map(int, input().split())
ban = list(map(int, input().split()))
if k == n or m > n * (n - 1) // 2 - k + 1:
print('-1')
else:
edges = [(i, j) for i in range(1, n + 1) for j in range(i + 1, n + 1)]
for i in range(1, k):
a = min(ban[i], ban[0])
... | vfc_55593 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2 2\n1 2\n",
"output": "1 3\n2 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3 2\n1 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 375_A. Divisible by Seven | Solve the following coding problem using the programming language python:
You have number a, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7.
Number a doesn't contain any leading zeroes and co... | ```python
# Made By Mostafa_Khaled
bot = True
a=input()
cnt=[0]*10
for i in (1,6,8,9):
cnt[i]=-1
for i in a:
cnt[int(i)]+=1
mod = [1869, 1968, 9816, 6198, 1698, 1986, 1896, 1869]
modCnt=0
for i in range(1,10):
for j in range(cnt[i]):
modCnt= (modCnt*3 + i)%7
print(str(i)*cnt[i], end='')
modCnt=(1000... | vfc_55597 | {
"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": "1689\n",
"output": "1869\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "18906\n",
"output": "18690\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | 41_D. Pawn | Solve the following coding problem using the programming language python:
On some square in the lowest row of a chessboard a stands a pawn. It has only two variants of moving: upwards and leftwards or upwards and rightwards. The pawn can choose from which square of the lowest row it can start its journey. On each squa... | ```python
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, m, k = map(int, input().split())
k += 1
a = [tuple(map(int, input().rstrip())) for _ in range(n)]
empty = -1
dp = [[[empty] * k for _ in range(m)] for _ in range(n)]
prev = [[[(-1, -1, '... | vfc_55605 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2 10\n98\n75\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3 1\n123\n456\n789\n",
"output": "16\n2\nRL\n",
"type": "stdin_stdout"
},
{
"fn... |
code_contests | verifiable_code | 446_B. DZY Loves Modification | Solve the following coding problem using the programming language python:
As we know, DZY loves playing games. One day DZY decided to play with a n × m matrix. To be more precise, he decided to modify the matrix with exactly k operations.
Each modification is one of the following:
1. Pick some row of the matrix an... | ```python
"""
#If FastIO not needed, used this and don't forget to strip
#import sys, math
#input = sys.stdin.readline
"""
import os
import sys
from io import BytesIO, IOBase
import heapq as h
import bisect
from types import GeneratorType
BUFSIZE = 8192
class SortedList:
def __init__(self, iterable=[], _load=... | vfc_55609 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2 2 2\n1 3\n2 4\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2 5 2\n1 3\n2 4\n",
"output": "11\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 468_C. Hack it! | Solve the following coding problem using the programming language python:
Little X has met the following problem recently.
Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 4). You are to calculate <image>
Of course Little X has solved this problem quic... | ```python
A = int(input())
F1019 = (45 * 19 * 10**18 + 1) % A
r = (-F1019) % A
print(r + 1, 10**19 + r)
``` | vfc_55613 | {
"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": "46\n",
"output": "30 1000000000000000029",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "126444381000032\n",
"output": "17579858499136 1000017579858499135",
"type": "stdin_stdout... |
code_contests | verifiable_code | 490_C. Hacking Cypher | Solve the following coding problem using the programming language python:
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the ... | ```python
from sys import stdin
c = list(stdin.readline()[:-1:])
a,b = map(int,input().split())
pref = []
pref1 = []
summ = 0
summ1 = 0
boo = 0
x = 1
for i in range(len(c)):
summ = summ * 10 + int(c[i])
summ %= a
pref.append(summ)
for i in range(len(c)-1,-1,-1):
summ1 += x * int(c[i])
x *= 10
x ... | vfc_55617 | {
"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": "284254589153928171911281811000\n1009 1000\n",
"output": "YES\n2842545891539\n28171911281811000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "120\n12 1\n",
"output": "NO\n",
"... |
code_contests | verifiable_code | 514_C. Watto and Mechanism | Solve the following coding problem using the programming language python:
Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process queries ... | ```python
from sys import stdin
from functools import reduce
from collections import defaultdict
_data = iter(stdin.read().split('\n'))
def input():
while True:
return next(_data)
n, m = [int(x) for x in input().split()]
B = 10007
MOD = 1000000000000000003
h = lambda s: reduce(lambda s, c: (B * s + ord(c)... | vfc_55621 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3\naaaaa\nacacaca\naabaa\nccacacc\ncaaac\n",
"output": "YES\nNO\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 4\nab\ncacab\ncbabc\nacc\ncacab\nabc\naa\nacbca\ncb\n",
"outpu... |
code_contests | verifiable_code | 540_D. Bad Luck Island | Solve the following coding problem using the programming language python:
The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one... | ```python
A, B, C = map(lambda x: int(x)+1, input().split())
M = max(max(A, B), C)
p = [[[0] * (M) for i in range(M)] for j in range(M)]
for a in range(M):
for b in range(M):
for c in range(M):
val=0
if a == 0 or b == 0:
val=0
elif c == 0:
... | vfc_55625 | {
"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 1 2\n",
"output": "0.15 0.3 0.55\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2 2\n",
"output": "0.333333333333333 0.333333333333333 0.333333333333333\n",
"type": "stdin... |
code_contests | verifiable_code | 568_E. Longest Increasing Subsequence | Solve the following coding problem using the programming language python:
Note that the memory limit in this problem is less than usual.
Let's consider an array consisting of positive integers, some positions of which contain gaps.
We have a collection of numbers that can be used to fill the gaps. Each number from t... | vfc_55629 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 128000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n-1 -1 -1\n5\n1 1 1 1 2\n",
"output": "1 1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2 3\n1\n10\n",
"output": "1 2 3\n",
"type": "stdin_stdout"
},
{
... | |
code_contests | verifiable_code | 58_C. Trees | Solve the following coding problem using the programming language python:
On Bertown's main street n trees are growing, the tree number i has the height of ai meters (1 ≤ i ≤ n). By the arrival of the President of Berland these trees were decided to be changed so that their heights formed a beautiful sequence. This me... | ```python
from collections import defaultdict as dd
n = int(input())
a = list(map(int, input().split()))
count = dd(lambda: 0)
for i in range(n//2):
count[a[i]-i] += 1
count[a[n-i-1] - i] += 1
#print(i, a[i]-i, a[n-i-1]-i)
#print([count[k] for k in count.keys()])
if n%2: count[a[n//2]-n//2] += 1
print(n - ... | vfc_55633 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 2 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
code_contests | verifiable_code | 611_E. New Year and Three Musketeers | Solve the following coding problem using the programming language python:
Do you know the story about the three musketeers? Anyway, you must help them now.
Richelimakieu is a cardinal in the city of Bearis. He found three brave warriors and called them the three musketeers. Athos has strength a, Borthos strength b, a... | ```python
import sys,io,os
try:Z=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
except:Z=lambda:sys.stdin.readline().encode()
X=lambda x:print(x)or quit()
n=int(Z());a,b,c=sorted(map(int,Z().split()));t=map(int,Z().split());d=[0]*7
B=[a,b]+sorted([a+b,c])+[a+c,b+c,a+b+c]
for i in t:
for v in range(7):
... | vfc_55637 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n10 20 30\n1 1 1 1 51\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n30 20 10\n34 19 50 33 88 15 20\n",
"output": "-1\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 65_E. Harry Potter and Moving Staircases | Solve the following coding problem using the programming language python:
Harry Potter lost his Invisibility Cloak, running from the school caretaker Filch. Finding an invisible object is not an easy task. Fortunately, Harry has friends who are willing to help. Hermione Granger had read "The Invisibility Cloaks, and E... | ```python
from collections import deque
def readarray(foo): return [foo(x) for x in raw_input().split()]
stairs = []
to = []
color = []
totalcolors = 0
deg = []
priority = []
extrastairs = []
extrastair = None
def doit():
usedstairs = set()
visited = set([0])
stack = []
res = []
nextcolor = 1
s = 0
if extr... | vfc_55645 | {
"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 1\n1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 4\n1 2\n1 3\n2 3\n4 5\n",
"output": "YES\n2\n3 1 2 3\n2 3 4\n3 4 5 4\n4 4 6\n5 6 4 3 2 1\n\n",
"typ... |
code_contests | verifiable_code | 683_D. Chocolate Bar | Solve the following coding problem using the programming language python:
A chocolate bar has a rectangular shape and consists of n × m slices. In other words, a bar consists of n rows with m slices of chocolate in each row.
Each slice of chocolate is known to weigh 1 gram. Your task is to determine for each of the q... | vfc_55649 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 3 4\n4 4 7\n",
"output": "Yes\nNo\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 706_C. Hard problem | Solve the following coding problem using the programming language python:
Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help.
Vasiliy is given n strings consisting of lowercase English letters. He wants them to be sorted in lexicographical order (as ... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
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 list(map(int, s... | vfc_55653 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 3 1\naa\nba\nac\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n5 5\nbbb\naaa\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn_name": nu... |
code_contests | verifiable_code | 729_E. Subordinates | Solve the following coding problem using the programming language python:
There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior.
There was a request to each of the workers to tell how how... | ```python
n,s = map(int,input().split())
A = list(map(int,input().split()))
if A[s-1] != 0:
per = 1
A[s-1] = 0
else:
per = 0
A.sort()
maxs = max(A)
ans = [0] * (maxs + 1)
answer = maxs + 1
o = -1
for j in range(n):
if A[j] == 0:
o += 1
if ans[A[j]] == 0:
ans[A[j]] = 1
an... | vfc_55657 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n1 0 0 4 1\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n2 0 2\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | 74_A. Room Leader | Solve the following coding problem using the programming language python:
Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.
In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participa... | ```python
arr = []
for _ in range(0,int(input())):
arr.append(list(input().split()))
ans = []
for i in range(0,len(arr)):
sum = int(arr[i][1])*100 - int(arr[i][2])*50
for j in range(3,8):
sum += int(arr[i][j])
ans.append(sum)
a = max(ans)
for i in range(0,len(ans)):
if ans[i] == a:
print(arr[i][0])... | vfc_55661 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0\n",
"output": "tourist\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 772_E. Verifying Kingdom | Solve the following coding problem using the programming language python:
This is an interactive problem.
The judge has a hidden rooted full binary tree with n leaves. A full binary tree is one where every node has either 0 or 2 children. The nodes with 0 children are called the leaves of the tree. Since this is a fu... | vfc_55665 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\nX\nZ\nY\nY\nX<span class=\"tex-font-style-tt\"></span>\n",
"output": "1 2 3\n1 2 4\n1 2 5\n-1\n8 9 7 8 9 7 -1 6 6 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n8 7 10 9 10 11 9 11 -... | |
code_contests | verifiable_code | 797_E. Array Queries | Solve the following coding problem using the programming language python:
a is an array of n positive integers, all of which are not greater than n.
You have to process q queries to this array. Each query is represented by two numbers p and k. Several operations are performed in each query; each operation changes p t... | ```python
from sys import stdin, stdout, setrecursionlimit
input = stdin.readline
# import string
# characters = string.ascii_lowercase
# digits = string.digits
# setrecursionlimit(int(1e5))
# dir = [-1,0,1,0,-1]
# moves = 'NESW'
inf = float('inf')
from functools import cmp_to_key
from collections import defaultdict as... | vfc_55669 | {
"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\n1 1 1\n3\n1 1\n2 1\n3 1\n",
"output": "2\n1\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "50\n49 21 50 31 3 19 10 40 20 5 47 12 12 30 5 4 5 2 11 23 5 39 3 30 19 3 23 40 4 14 39 50 ... |
code_contests | verifiable_code | 818_A. Diplomas and Certificates | Solve the following coding problem using the programming language python:
There are n students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called ... | ```python
n,k = map(int,input().split())
p = (n // 2) //(k+1)
o = p * k
l = n - p - o
print(str(p)+' '+str(o)+' '+str(l))
``` | vfc_55673 | {
"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": "1000000000000 5\n",
"output": "83333333333 416666666665 500000000002\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000000000 499999999999\n",
"output": "1 499999999999 50000000... |
code_contests | verifiable_code | 843_B. Interactive LowerBound | Solve the following coding problem using the programming language python:
This is an interactive problem.
You are given a sorted in increasing order singly linked list. You should find the minimum integer in the list which is greater than or equal to x.
More formally, there is a singly liked list built on an array o... | ```python
from random import sample
def R():
return map(int, input().split())
def ask(i):
print('?', i, flush=True)
v, nxt = R()
if v < 0:
exit()
return v, nxt
def ans(v):
print('!', v)
exit()
n, s, x = R()
mv = -1
i = s
S = 800
q = range(1, n + 1)
if n > S:
q = sample(q, S)
... | vfc_55677 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3 80\n97 -1\n58 5\n16 2\n81 1\n79 4\n",
"output": "? 3\n! 97\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 0\n0 -1\n",
"output": "? 1\n! 0\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 863_G. Graphic Settings | Solve the following coding problem using the programming language python:
Recently Ivan bought a new computer. Excited, he unpacked it and installed his favourite game. With his old computer Ivan had to choose the worst possible graphic settings (because otherwise the framerate would be really low), but now he wants t... | vfc_55681 | {
"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": "1\n3\n2\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3\n1\n",
"output": "Path\ninc 1\ninc 1\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 889_D. Symmetric Projections | Solve the following coding problem using the programming language python:
You are given a set of n points on the plane. A line containing the origin is called good, if projection of the given set to this line forms a symmetric multiset of points. Find the total number of good lines.
Multiset is a set where equal elem... | ```python
from fractions import Fraction
import time
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def to_tuple(self):
return (self.x, self.y)
def __repr__(self):
return "Point({}, {})".format(self.x, self.y)
def __eq__(self, other):
return sel... | vfc_55685 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 3\n1 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2\n2 1\n3 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 912_B. New Year's Eve | Solve the following coding problem using the programming language python:
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains n sweet candies from the good ol' bakery, each labeled from 1 to n corresponding to its tastiness.... | ```python
def parr(arr):
print(*arr, sep=' ')
def gcd(a, b):
while b:
if b % a == 0:
break
tmp = a
a = b % a
b = tmp
return a
# for _ in range(int(input())):
n, k = map(int, input().split())
ans = 0
if k == 1:
ans = n
else:
ans = int('1' * (len(bin(n)... | vfc_55689 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 6\n",
"output": "7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n",
"output": "7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10000000000... |
code_contests | verifiable_code | 934_B. A Prosperous Lot | Solve the following coding problem using the programming language python:
Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be dr... | ```python
k = int(input())
if(k>36):
print(-1) #at max 888888888888888888....10 power 18 , not more than that...
#in one 8, two loops ,so 36 loop
else:
print("8"*(k//2) + "6"*(k%2))
``` | vfc_55693 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n",
"output": "888\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000\n... |
code_contests | verifiable_code | 960_D. Full Binary Tree Queries | Solve the following coding problem using the programming language python:
You have a full binary tree having infinite levels.
Each node has an initial value. If a node has value x, then its left child has value 2·x and its right child has value 2·x + 1.
The value of the root is 1.
You need to answer Q queries.
... | ```python
levels=[[0,0] for i in range(61)]
levels[0][1]=1
for i in range(1,61):
levels[i][1]=2*levels[i-1][1]
import math
q=int(raw_input())
for e in range(q):
s=raw_input().split()
if(s[0]=='3'):
x=int(s[1])
high=int(math.log(x,2))
pos=(x-(levels[high][1]-levels[high][0]))%levels[... | vfc_55697 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n3 14\n1 5 -3\n3 14\n1 3 1\n3 14\n",
"output": "14 7 3 1 \n14 6 3 1 \n14 6 2 1 \n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 988_A. Diverse Team | Solve the following coding problem using the programming language python:
There are n students in a school class, the rating of the i-th student on Codehorses is a_i. You have to form a team consisting of k students (1 ≤ k ≤ n) such that the ratings of all team members are distinct.
If it is impossible to form a suit... | ```python
n, k = map(int, input().split())
a = list(map(int, input().split()))
d = {}
for i in range(n):
d[a[i]] = i + 1
if len(d) < k:
print('NO')
else:
print('YES')
values = list(d.values())
for i in range(k):
print(values[i], end=' ')
``` | vfc_55701 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n15 13 15 15 12\n",
"output": "YES\n1 2 5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 4\n15 13 15 15 12\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | alphanumeric-string | Solve the following coding problem using the programming language python:
A student is assigned a problem, to get a alphanumeric string from the user and to calculate the sum of digits in the given string.after this he has to delete the digits(0-9) from the string and to display the each word of the string in dictiona... | ```python
n=int(raw_input())
for i in range(n):
ss=''
tot=0
s=raw_input()
for j in range(len(s)):
if s[j] in ['0','1','2','3','4','5','6','7','8','9']:
tot+=int(s[j])
else:
ss=ss+s[j]
j+=1
ss=ss.split()
ss.sort()
for k in range(len(ss)):
tot-=(len(ss[k]))
print ss[k],
if tot<0:
print str(tot... | vfc_55705 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nthi6s is a85 t6es6t\nh8e is7 a b9oy5\n\nSAMPLE",
"output": "a 30 is 28 test 24 this 20 \na 28 boy 25 he 23 is 21 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\nthi6s is a85 t6es6t\... |
code_contests | verifiable_code | calculate-lcm | Solve the following coding problem using the programming language python:
Given A and B, compute the sum of lcm(a, b) over all pairs of positive integers a and b such that:
(1) a ≤ A and b ≤ B.
(2) There is no integer n>1 such that n^2 divides both a and b.
Give your answer modulo 2^30.
INPUT
The first line conta... | ```python
def lcm(x, y):
p=x*y
if x>y:
x,y=y,x
while(y):
x, y = y, x % y
gcd=x
lcm = p/gcd
return lcm
import math
def check(a,b):
m=min(a,b)
for n in range(2, int(math.sqrt(m)+1)):
s=n**2
if a%s==0 and b%s==0:
return False
return True
for i in... | vfc_55709 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 4\n3 3\n6 5\n8 3\n\nSAMPLE",
"output": "24\n28\n233\n178",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n2 4\n3 3\n6 5\n8 3",
"output": "24\n28\n233\n178",
"type": "stdin... |
code_contests | verifiable_code | decreasing-paths | Solve the following coding problem using the programming language python:
See Russian Translation
The end semester exams are now approaching. Ritu is the Computer Science Teacher of Coder Public School. He has been assigned the task of preparing good algorithmic problems for the students by the Dean of the school.
... | ```python
__author__ = 'siddharth'
D = None
N = 0
MOD = 1000000007
def vfoo():
for i in sorted(D.iteritems(), key=lambda v: v[1]):
yield i
def indices(i):
u, v = i/N, i%N
I = list()
if u > 0:
I.append((u-1)*N + v)
if u < N-1:
I.append((u+1)*N + v)
if v > 0:
I.a... | vfc_55713 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 2\n1 3\n\nSAMPLE",
"output": "8",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | game-of-strings-2 | Solve the following coding problem using the programming language python:
Puchi and Ghissi are playing a game with strings. As Ghissi is a champion at strings, Puchi decides to challenge her. He gives Ghissi a string S and an integer K . The objective for Ghissi is to find a substring of S such that:
- The subst... | ```python
output = []
for x in range(int(raw_input())):
out = ''
s, k = map(lambda x:x, raw_input().split())
k = int(k)
s_l = len(s)
stri = ''
l,j=0,0
for p in s[1:k]:
if p == s[j]:
stri += p
j+=1
if(l<j and p==s[-1]):
if(stri==s[-j:]):
out = stri
l=j
else:
stri = ''
j=0
if out ... | vfc_55717 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nsetupsetpreset 7\nsetupsetpreset 8\nsetupsetpreset 9\n\nSAMPLE",
"output": "Puchi is a cheat!\nset\nset\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\nabcdabc 3\nabcdabc 7\nqwertyq... |
code_contests | verifiable_code | kings-race-8 | Solve the following coding problem using the programming language python:
Shizuka, the daughter of Code King, is the most beautiful girl of Candyland. Every other Prince wants to marry her.The Code King invites all the other Prince in the town for a RACE and the winner of the race gets a chance to marry her.
Obviousl... | ```python
tc = int(raw_input())
for t in range(tc):
n, k = [int(c) for c in raw_input().rstrip().split(" ")]
n_arr = [int(c) for c in raw_input().rstrip().split(" ")]
k_arr = [int(c) for c in raw_input().rstrip().split(" ")]
n_max = max(n_arr)
k_max = max(k_arr)
if k_max>n_max:
for k_val... | vfc_55721 | {
"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 5\n10 20 30 40 50\n7 7 7 7 7\n7 5 \n1 2 3 4 5 6 7\n2 1 5 1 8\n\nSAMPLE",
"output": "0\n4",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | monk-and-champions-league | Solve the following coding problem using the programming language python:
Monk's favourite game is Football and his favourite club is "Manchester United". Manchester United has qualified for the Champions League Final which is to be held at the Wembley Stadium in London. So, he decided to go there and watch his favour... | ```python
import heapq
def solve(n, xs):
xs = [-x for x in xs]
heapq.heapify(xs)
tot = 0
for _ in range(n):
price = xs[0]
tot += price
heapq.heapreplace(xs, price + 1)
return -tot
if __name__ == '__main__':
_, n = map(int, raw_input().split())
xs = map(int, raw_inpu... | vfc_55725 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n1 2 4\n\nSAMPLE",
"output": "11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n1 4 4\n\nSAMPLE",
"output": "14\n",
"type": "stdin_stdout"
},
{
"fn_name... |
code_contests | verifiable_code | pankaj-and-his-in-laws | Solve the following coding problem using the programming language python:
Pankaj is a very intelligent student studying in one of the best colleges of this country. He's good enough to challenge the smartest minds in the country, but even the smart ones make mistakes and so did Pankaj - he fell in love, ah. He was so ... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
n=input()
m=map(int,raw_input().split())
l=[]
for i in xrange(n):
l.append(1)
for i in xrange(n):
for j in xrange(i):
if m[i]>m[j] and l[i]<l[j]+1:
... | vfc_55729 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n650 945 -832 -999 678 702\n\nSAMPLE",
"output": "11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20\n581 912 26 666 200 978 379 752 966 503 167 671 261 964 881 875 830 657 827 529",
... |
code_contests | verifiable_code | roy-and-code-streak | Solve the following coding problem using the programming language python:
Roy is working on HackerEarth Profile. Right now he is working on User Statistics.
One of the statistics data (Code Streak) is as follows:
Given the User Activity Data, find the maximum number of continuous correct solutions submitted by any us... | ```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=int(raw_input())
for i in range(t):
n=int(raw_input())
maxi=0
count=0
presid=set()
for j in range(n):
q=raw_input().split()
sid,result=int(q[0... | vfc_55733 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n6\n1 0\n2 1\n3 1\n4 1\n5 1\n6 0\n5\n1 1\n2 0\n3 1\n1 1\n2 1\n4\n1 1\n2 1\n2 1\n3 1\n\nSAMPLE",
"output": "4\n2\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n6\n1 0\n3 1\n3 1\n4 ... |
code_contests | verifiable_code | string-partition | Solve the following coding problem using the programming language python:
Rahul is a young chap who loves strings but simply hates mathematics. While his friend Ramesh is in love with mathematics but hates strings. So their teacher decided to take a test which combined both these topics so that neither of them gets a ... | ```python
T=int(raw_input())
for _ in xrange(T):
K,Z=(int(e) for e in raw_input().split())
s=raw_input()
if K>len(s):
print -1
else:
lis=[[-1 for e in xrange(len(s))] for f in xrange(len(s))]
for e in xrange(len(s)):
for i in xrange(e,len(s)):
if int(s[e:i+1])<=Z:
lis[e][i]=int(s[e:i+1])
dp=[[-1... | vfc_55737 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 6\n30901\n2 85\n07565\n\nSAMPLE",
"output": "-1\n140",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n73 22415\n5167001431772738714943016657313619461697024695206334583232984849497149... |
code_contests | verifiable_code | utkarsh-and-distributing-books-february-easy | Solve the following coding problem using the programming language python:
Utkarsh's mother recently received N piles of books as a gift from someone. The i^th pile contains Bi books.
She neither wants to keep the voluminous books with herself nor she wants to throw them away. So, she decided to distribute them to st... | ```python
T=int(raw_input())
B=[]
A=[]
for i in range(0,T):
N=int(raw_input())
S=raw_input()
B=S.split()
for i in range(0,N):
a=int(B[i])
A.append(a)
m=min(A)
U=m-1
s=sum(A)-2*(N)
K=s+N
print U,K
A=[]
B=[]
``` | vfc_55741 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2\n5 5\n\nSAMPLE",
"output": "4 8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n1000\n772 471 331 119 775 107 645 356 638 975 867 164 316 61 22 487 523 873 955 185 28 413 742 304 ... |
code_contests | verifiable_code | p00014 Integral | Solve the following coding problem using the programming language python:
Write a program which computes the area of a shape represented by the following three lines:
$y = x^2$
$y = 0$
$x = 600$
It is clear that the area is $72000000$, if you use an integral you learn in high school. On the other hand, we can obta... | ```python
while 1:
try:
d=int(input())
ans=0
for i in range(600//d):
ans+=d*d*d*i*i
print(ans)
except:break
``` | vfc_55785 | {
"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": "20\n10",
"output": "68440000\n70210000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20\n15",
"output": "68440000\n69322500\n",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | p00279 Happy End Problem | Solve the following coding problem using the programming language python:
Let's write a program related to an unsolved math problem called "Happy End Problem". Create a program to find the smallest convex polygon formed by connecting exactly k points from the N points given on the plane. However, after being given the... | ```python
def cross(z1, z2):
return z1.real * z2.imag - z1.imag * z2.real
def ccw(p1, p2, p3):
return cross(p2 - p1, p3 - p1) > 0
def triangle_area(p1, p2, p3):
# returns signed trangle area
return cross(p2 - p1, p3 - p1) / 2
from sys import stdin
file_input = stdin
N = int(file_input.readline())
P ... | vfc_55793 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n0 0\n3 0\n5 2\n1 4\n0 3\n3\n3\n4\n5",
"output": "1 4 5\n1 2 4 5\n1 2 3 4 5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 0\n3 -1\n5 2\n1 4\n0 3\n3\n3\n4\n5",
"output": "1 4 5... |
code_contests | verifiable_code | p00467 Sugoroku | Solve the following coding problem using the programming language python:
Sugoroku
problem
JOI is playing sugoroku alone. There are N squares in a straight line in this sugoroku, and each has a movement instruction written on it. The starting point is the 1st square and the goal is the Nth square. JOI repeats the fo... | ```python
for e in iter(input,'0 0'):
N,M=map(int,e.split())
S=[int(input())for _ in[0]*N]
p=b=1
for i in range(M):
d=int(input())
p+=d
if N<=p:
if b:print(-~i);b=0
continue
p+=S[~-p]
if(N<=p)*b:print(-~i);b=0
``` | vfc_55797 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 5\n0\n0\n5\n6\n-3\n8\n1\n8\n-4\n0\n1\n3\n5\n1\n5\n10 10\n0\n-1\n-1\n4\n4\n-5\n0\n1\n-6\n0\n1\n5\n2\n4\n6\n5\n5\n4\n1\n6\n0 0",
"output": "5\n6",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input... |
code_contests | verifiable_code | p00659 Popularity Estimation | Solve the following coding problem using the programming language python:
You are the planning manager of an animation production company. What animation production companies produce these days is not limited to animation itself. Related products, such as figures of characters and character song CDs, are also importan... | ```python
# AOJ 1074: Popularity Estimation
# Python3 2018.7.10 bal4u
while True:
n = int(input())
if n == 0: break
f, tbl = [0]*31, []
for i in range(n):
a = input().split()
nm = a.pop(0)
m = int(a.pop(0))
d = list(map(int, a))
tbl.append([0, nm, d])
for i in d: f[i] += 1
for i in range(n):
for j i... | vfc_55801 | {
"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\nakzakr 2 1 8\nfnmyi 5 2 3 4 6 9\ntsnukk 5 2 3 4 7 9\nyskwcnt 6 3 4 7 8 9 10\n4\nakzakr 1 2\nfnmyi 3 10 11 12\ntsnukk 2 1 8\nyskwcnt 2 1 8\n5\nknmmdk 2 13 19\nakmhmr 4 13 15 19 22\nmksyk 6 3 7 12 13 15 19\nskrkyk 3 1 4 8\ntmemm 3... |
code_contests | verifiable_code | p00802 Telescope | Solve the following coding problem using the programming language python:
Dr. Extreme experimentally made an extremely precise telescope to investigate extremely curi- ous phenomena at an extremely distant place. In order to make the telescope so precise as to investigate phenomena at such an extremely distant place, ... | vfc_55805 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n0.0 0.25 0.5 0.666666666666666666667\n4 4\n0.0 0.25 0.5 0.75\n30 15\n0.00 0.03 0.06 0.09 0.12 0.15 0.18 0.21 0.24 0.27\n0.30 0.33 0.36 0.39 0.42 0.45 0.48 0.51 0.54 0.57\n0.61 0.64 0.66 0.69 0.72 0.75 0.78 0.81 0.84 0.87\n40 2... | |
code_contests | verifiable_code | p00933 Exhibition | Solve the following coding problem using the programming language python:
Example
Input
6 5 1 2 3
5 5 5
1 5 5
2 5 4
3 5 3
4 5 2
5 5 1
Output
0.631579
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. | vfc_55809 | {
"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": "6 5 1 2 3\n5 5 5\n1 5 5\n2 5 4\n3 5 3\n4 5 2\n5 5 1",
"output": "0.631579",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 5 1 2 3\n5 5 5\n1 5 5\n2 5 3\n3 5 3\n4 5 2\n5 5 1",
"output"... | |
code_contests | verifiable_code | p01066 Reflection Warp Machine | Solve the following coding problem using the programming language python:
Problem
In a certain universe, there are n stars on a two-dimensional lattice point, and aliens use the Reflection Warp Machine to move between the stars.
This device can draw a straight line at any position and angle.
With this straight line a... | vfc_55813 | {
"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": "4\n0 0\n0 1\n0 2\n0 3",
"output": "2",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01199 Flame of Nucleus | Solve the following coding problem using the programming language python:
Year 20XX — a nuclear explosion has burned the world. Half the people on the planet have died. Fearful.
One city, fortunately, was not directly damaged by the explosion. This city consists of N domes (numbered 1 through N inclusive) and M bidir... | vfc_55817 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 0 1\n51\n50\n2 1 1\n1 2 1\n1000 0\n0 1000\n4 3 5\n1 2 4\n1 3 1\n3 4 2\n0 1000 1000 1000\n3000 0 0 0",
"output": "50\n0\n3000",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01336 THE BYDOLM@STER | Solve the following coding problem using the programming language python:
Description
THE BY DOLM @ STER is a training simulation game scheduled to be released on EXIDNA by 1rem on April 1, 2010. For the time being, it probably has nothing to do with an arcade game where the network connection service stopped earlier... | ```python
while True:
try:
n, m = map(int, input().split())
except EOFError:
break
costs = []
vocals = []
dances = []
looks = []
for _ in range(n):
input()
c, v, d, l = map(int, input().split())
costs.append(c)
vocals.append(v)
dances.append(d)
looks.append(l)
def max_... | vfc_55821 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 10\nDobkeradops\n7 5 23 10\nPataPata\n1 1 2 1\ndop\n5 3 11 14\n2 300\nBydo System Alpha\n7 11 4 7\nGreen Inferno\n300 300 300 300",
"output": "29\n462",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | p01503 Tampopo Machine | Solve the following coding problem using the programming language python:
Example
Input
1 1 1 1 1
Output
0.000000000000
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. | vfc_55825 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1 1 1 1",
"output": "0.000000000000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 0 1 1",
"output": "0.00000000000000000000\n",
"type": "stdin_stdout"
},
{
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.