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 | p01780 Breadth-First Search by Foxpower | Solve the following coding problem using the programming language python:
Example
Input
4
1 1 2
Output
6
The input will be given via stdin and the output should be printed to stdout by your code.
Now solve the problem by providing the code. | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**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_41261 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 1 2",
"output": "6",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 1 1",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n... |
code_contests | verifiable_code | p02053 Hokkaido University Hard | Solve the following coding problem using the programming language python:
B: Hokkaido University Hard
Note
Please note that the question settings are the same as question A, except for the constraints.
story
Homura-chan, who passed Hokkaido University and is excited about the beginning of a new life. But in front ... | ```python
#!/usr/bin/python3
# -*- coding: utf-8 -*-
H,W = map(int, input().split())
builds = []
for h in range(H):
l = str(input())
for w in range(W):
if l[w] == "B":
builds.append([h,w])
# [min,max]
lu = [H+W,0]
ld = [H+W,0]
for h,w in builds:
lu = [min(lu[0],h+w),max(lu[1],h+w)]
ld = [min(ld[0]... | vfc_41269 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\nB.B\n..B\n.BB",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\nB.B\nB..\n.BB",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p02195 Bichrome Tree Connectivity | Solve the following coding problem using the programming language python:
Bichrome Tree Connectivity
Given a tree.
Initially, all vertices are white.
Inverting the color of the white vertices makes it black, and inverting the color of the black vertices makes it white.
Handle two types of queries.
The first type ... | vfc_41273 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 1073741824,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 3\n1 2\n2 5\n2 6\n1 4\n1 3\n3 7\n3 8\n3 9\n9 10\n1 3\n2 1\n2 8",
"output": "5\n1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 3\n1 2\n2 5\n2 6\n1 4\n1 3\n3 7\n3 8\n3 9\n9 10\n1 2\n2... | |
code_contests | verifiable_code | p02349 Range Add Query (RAQ) | Solve the following coding problem using the programming language python:
Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the following operations:
* add(s, t, x): add x to as, as+1, ..., at.
* get(i): output the value of ai.
Note that the initial values of ai (i = 1, 2, . . . , n) are 0... | ```python
# -*- coding: utf-8 -*-
"""
Range Add Query (RAQ)
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_E&lang=ja
"""
import sys
def main(args):
def add(b, k, x):
while k <= n:
b[k] += x
k += k & -k
def get(b, k):
s = 0
while k > 0:
... | vfc_41277 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\n0 1 2 1\n0 2 3 2\n0 3 3 3\n1 2\n1 3",
"output": "3\n5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n1 2\n0 1 4 1\n1 2",
"output": "0\n1",
"type": "stdin_stdout"
}... |
code_contests | verifiable_code | cds003 | Solve the following coding problem using the programming language python:
At the legendary times of Nonsenso wars in ISM Dhanbad, there was a neck to neck competition between Barney Stinson and Sheldon Cooper. They both were on level 19. After trying too hard both of them could not decipher the nonsense, so they decid... | ```python
t=input()
for _ in xrange(t):
s=raw_input()
l=len(s)-1
i=0;
ss=""
while(i<l):
n=int(s[i:i+2])
if(n<20):
n=int(s[i:i+3])
i+=1
i+=2
ss+=chr(n)
print ss
``` | vfc_41281 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n721011081081113287111114108100\n871011089911110910132116111327311010010597",
"output": "Hello World\nWelcome to India",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n170550006177585909... |
code_contests | verifiable_code | cw6 | Solve the following coding problem using the programming language python:
Ayan's favourite musical instrument is the keyboard. He practices regularly as well, you can hear him playing even at 3 or 4 in the night.
Unfortunately, he got into a fight in his room and his keyboard was damaged beyond repair. However, being ... | ```python
a = 'CcDdEFfGgABS' * 3;
T = int(input());
while T:
T -= 1
s = raw_input().split();
pos1 = a.find(s[0])
pos2 = a.find(s[1], pos1 + 1)
print 'Major' if pos2 - pos1 == 4 else 'Minor'
``` | vfc_41285 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nE G S\nS d f",
"output": "Minor\nMajor",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | icq3 | Solve the following coding problem using the programming language python:
Sorting is considered to be one of the most important skills to be learned in computer science and has it's applications in real product building.
The problem has arised to the team of PcCube.They need to sort the set of alphanumeric strings in ... | ```python
T = int(raw_input())
for i in xrange(T):
S = raw_input()
numLst = []
charLst = []
ansLst = []
for i in S:
if (ord(i) > 47 and ord(i) < 58):
numLst.append(i)
else:
charLst.append(i)
numLst.sort(reverse=True)
charLst.sort(reverse=True)
for i in xrange(S.__len__()):
if (ord(S[i]) > 47 and o... | vfc_41289 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n951f5gd3",
"output": "135d5fg9",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | mriu4 | Solve the following coding problem using the programming language python:
Given an input sequence. You have to write a program to sort it in non decreasing order.
Input
First line of input T has number of test cases followed by T test cases.
Each test case has two lines. First line has a number N. The second line has... | ```python
t=input()
while(t):
t=t-1
n=input()
x=raw_input()
a=[]
u=0
v=0
for i in range(0,len(x)):
if(x[i]==" "):
v=i
a.append(int(x[u:v]))
u=v+1
a.append(int(x[v:len(x)]))
a.sort()
s=""
for i in range(0,n):
s=s+str(a[i])
... | vfc_41293 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n3 4\n5\n1 4 5 8 2\n1\n7",
"output": "3 4\n1 2 4 5 8\n7\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | univmt | Solve the following coding problem using the programming language python:
The University management meets every semester to discuss about the issues of the University in a round table conference. Therefore new proposals are made to the present academic curriculum. However whenever a new proposal comes from a member, a... | ```python
t=input()
m=1000000007
for i in range(0,t):
n=input()
if n<=3:
print "0"
else :
print (n*(n-3)/2)%m
``` | vfc_41301 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n291",
"output": "41904",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1019_D. Large Triangle | Solve the following coding problem using the programming language python:
There is a strange peculiarity: if you connect the cities of Rostov, Taganrog and Shakhty, peculiarly, you get a triangle
«Unbelievable But True»
Students from many different parts of Russia and abroad come to Summer Informatics School. You ma... | vfc_41305 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 7\n0 0\n3 0\n0 4\n",
"output": "No",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n0 0\n2 0\n1 2\n1 3\n",
"output": "Yes\n0 0\n2 0\n1 3\n",
"type": "stdin_stdout"
},
... | |
code_contests | verifiable_code | 1042_C. Array Product | Solve the following coding problem using the programming language python:
You are given an array a consisting of n integers. You can perform the following operations with it:
1. Choose some positions i and j (1 ≤ i, j ≤ n, i ≠ j), write the value of a_i ⋅ a_j into the j-th cell and remove the number from the i-th ... | ```python
n = int(input())
vector = [int(i) for i in input().split()]
usado = []
nusado = []
pos = -1
cn = 0
cz = 0
resp = []
i = 0
while i < n:
v = vector[i]
if v < 0:
cn+=1
if pos == -1 or (vector[pos] < v):
pos = i
nusado.append(i)
elif v == 0:
cz+=1
us... | vfc_41309 | {
"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": "4\n0 0 0 0\n",
"output": "1 1 2\n1 2 3\n1 3 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n5 2 0 4 0\n",
"output": "1 3 5\n2 5\n1 1 2\n1 2 4\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 1065_B. Vasya and Isolated Vertices | Solve the following coding problem using the programming language python:
Vasya has got an undirected graph consisting of n vertices and m edges. This graph doesn't contain any self-loops or multiple edges. Self-loop is an edge connecting a vertex to itself. Multiple edges are a pair of edges such that they connect th... | ```python
n, m = map(int, input().split())
print(max(n-2*m, 0), end=' ')
for i in range(0, n+1):
if i*(i-1)/2>=m: break
print(n-i)
``` | vfc_41313 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1\n",
"output": "1 1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1086_F. Forest Fires | Solve the following coding problem using the programming language python:
Berland forest was planted several decades ago in a formation of an infinite grid with a single tree in every cell. Now the trees are grown up and they form a pretty dense structure.
So dense, actually, that the fire became a real danger for th... | vfc_41317 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 0\n0 0\n-2 1\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 1\n2 2\n1 3\n0 2\n2 4\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"fn... | |
code_contests | verifiable_code | 1106_F. Lunar New Year and a Recursive Sequence | Solve the following coding problem using the programming language python:
Lunar New Year is approaching, and Bob received a gift from his friend recently — a recursive sequence! He loves this sequence very much and wants to play with it.
Let f_1, f_2, …, f_i, … be an infinite sequence of positive integers. Bob knows ... | ```python
from math import ceil, sqrt
p = 998244353
def bsgs(g, h):
'''
Solve for x in h = g^x mod p given a prime p.
'''
N = ceil(sqrt(p - 1)) # phi(p) is p-1 if p is prime
# Store hashmap of g^{1...m} (mod p). Baby step.
tbl = {pow(g, i, p): i for i in range(N)}
# Precompute via Ferma... | vfc_41321 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2\n88888 66666\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n283 463 213 777 346 201 463 283 102 999\n2333333 6263423\n",
"output": "382480067\n",
"t... |
code_contests | verifiable_code | 1133_F2. Spanning Tree with One Fixed Degree | Solve the following coding problem using the programming language python:
You are given an undirected unweighted connected graph consisting of n vertices and m edges. It is guaranteed that there are no self-loops or multiple edges in the given graph.
Your task is to find any spanning tree of this graph such that the ... | ```python
import sys
from collections import Counter, defaultdict
def i_ints():
return map(int, sys.stdin.readline().split())
n, m, D = i_ints()
E = defaultdict(set)
for i in range(m):
u, v = i_ints()
E[u].add(v)
E[v].add(u)
def append_edge(u, v):
E[u].discard(v)
E[v].discard(u)
t... | vfc_41325 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 5 1\n1 2\n1 3\n1 4\n2 3\n3 4\n",
"output": "YES\n1 2\n2 3\n3 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4 3\n1 2\n1 4\n2 3\n3 4\n",
"output": "NO\n",
"type": "stdin_... |
code_contests | verifiable_code | 1154_D. Walking Robot | Solve the following coding problem using the programming language python:
There is a robot staying at X=0 on the Ox axis. He has to walk to X=n. You are controlling this robot and controlling how he goes. The robot has a battery and an accumulator with a solar panel.
The i-th segment of the path (from X=i-1 to X=i) c... | ```python
n,b,a=map(int,input().split())
s=list(map(int,input().split()))
maxa=a
cnt=0
for i in range(n):
if(s[i]==0):
if(a>0):
a-=1
cnt+=1
elif(b>0):
b-=1
cnt+=1
else:
if(a<maxa and b>0):
b-=1
a+=1
cnt+=1
elif(a>0):
a-=1
cnt+=1
if(b==0 and a==0):
break
print(cnt)
``` | vfc_41329 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2 1\n0 1 0 1 0\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 2 1\n1 0 0 1 0 1\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1176_B. Merge it! | Solve the following coding problem using the programming language python:
You are given an array a consisting of n integers a_1, a_2, ... , a_n.
In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For exa... | ```python
for _ in range(int(input())):
a=int(input())
b=list(map(int,input().split()))
k1=0
k2=0
k3=0
for i in b:
if i%3==0:
k3+=1
elif i%3==1:
k1+=1
else:
k2+=1
l=min(k1,k2)
m=(k1-l)//3
n=(k2-l)//3
print(k3+l+m+n)
``` | vfc_41333 | {
"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\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2\n",
"output": "3\n3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1195_A. Drinks Choosing | Solve the following coding problem using the programming language python:
Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?
There are n students living in a building, ... | ```python
from math import ceil
n, k = map(int, input().split())
bev = [0] * k
for i in range(n):
x = int(input())
bev[x-1] += 1
bad = 0
good = 0
for i in range(k):
bad += bev[i] & 1
good += bev[i] - (bev[i] & 1)
# print(good, bad)
bad = ceil(bad / 2)
print(good + bad)
``` | vfc_41337 | {
"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 3\n1\n3\n1\n1\n2\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1211_E. Double Permutation Inc. | Solve the following coding problem using the programming language python:
Polycarp recently became an employee of the company "Double Permutation Inc." Now he is a fan of permutations and is looking for them everywhere!
A permutation in this problem is a sequence of integers p_1, p_2, ..., p_k such that every integer... | vfc_41341 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3 2 1\n",
"output": "\nRBBBG\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1234_C. Pipes | Solve the following coding problem using the programming language python:
You are given a system of pipes. It consists of two rows, each row consists of n pipes. The top left pipe has the coordinates (1, 1) and the bottom right — (2, n).
There are six types of pipes: two types of straight pipes and four types of curv... | ```python
input = __import__('sys').stdin.readline
print = __import__('sys').stdout.write
thres = 3
for _ in range(int(input())):
current = False
N = int(input())
tmp = [list(map(int, list(input()[:-1]))), list(map(int, list(input()[:-1])))]
for i in range(N):
if tmp[current][i] < thres:
... | vfc_41345 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n7\n2323216\n1615124\n1\n3\n4\n2\n13\n24\n2\n12\n34\n3\n536\n345\n2\n46\n54\n",
"output": "YES\nYES\nYES\nNO\nYES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n7\n2323216\n16151... |
code_contests | verifiable_code | 1253_B. Silly Mistake | Solve the following coding problem using the programming language python:
The Central Company has an office with a sophisticated security system. There are 10^6 employees, numbered from 1 to 10^6.
The security system logs entrances and departures. The entrance of the i-th employee is denoted by the integer i, while t... | ```python
input()
t={0}
i=s=0
r=[0]
for x in map(int, input().split()):
if(x<0)!=(-abs(x)in t)or x>0 and abs(x)in t:r=-1,;break
if x>0:t|={x,-x}
else:t-={x}
i+=1;s+=x
if s==0:r[0]+=1;r+=i,;t={0};i=0
if s:r=-1,
print(r[0])
print(*r[1:])
``` | vfc_41349 | {
"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\n-8 1 1\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1297_A. Likes Display | Solve the following coding problem using the programming language python:
Polycarp is working on the implementation of displaying likes on the Codehorses social network. The number of likes should be displayed in a format that will be easy to read by users. It was decided that for large numbers of likes the format sho... | vfc_41357 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9\n999\n123\n0\n1782\n31415926\n1500\n999999\n35499710\n2000000000\n",
"output": "\n999\n123\n0\n2K\n31M\n2K\n1M\n35M\n2000M\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1424_J. Lonely Numbers | Solve the following coding problem using the programming language python:
In number world, two different numbers are friends if they have a lot in common, but also each one has unique perks.
More precisely, two different numbers a and b are friends if gcd(a,b), (a)/(gcd(a,b)), (b)/(gcd(a,b)) can form sides of a trian... | ```python
from math import sqrt
from sys import stdin, stdout
from time import time
start = time()
t = int(stdin.readline().strip())
tests = list(map(int, stdin.readline().split()))
def gen_primes(n):
sieve = [True] * (n//2)
for i in range(3,int(n**0.5)+1,2):
if sieve[i//2]:
sieve[i*i//2:... | vfc_41381 | {
"difficulty": "16",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 5 10\n",
"output": "1\n3\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n12 432 21 199 7 1\n",
"output": "4\n76\n7\n41\n4\n1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1470_A. Strange Birthday Party | Solve the following coding problem using the programming language python:
Petya organized a strange birthday party. He invited n friends and assigned an integer k_i to the i-th of them. Now Petya would like to give a present to each of them. In the nearby shop there are m unique presents available, the j-th present co... | ```python
import bisect
import collections
import copy
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
from typing import List
sys.setrecursionlimit(99999)
t, = map(int, sys.stdin.readline().split())
for _ in range(t):
n, m = map(int, sys.stdi... | vfc_41389 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5 4\n2 3 4 3 2\n3 5 12 20\n5 5\n5 4 3 2 1\n10 40 90 160 250\n",
"output": "\n30\n190\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 174_A. Problem About Equation | Solve the following coding problem using the programming language python:
A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in... | ```python
a,b=map(int,input().split())
l=list(map(int,input().split()))
if (max(l)*a)-sum(l)>b:
print(-1)
else:
for i in l:
print((sum(l)+b)/a-i)
``` | vfc_41405 | {
"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 50\n1 2 3 4 5\n",
"output": "12.000000\n11.000000\n10.000000\n9.000000\n8.000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n1 100\n",
"output": "-1\n",
"type": "std... |
code_contests | verifiable_code | 194_B. Square | Solve the following coding problem using the programming language python:
There is a square painted on a piece of paper, the square's side equals n meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter ... | ```python
i = int(input())
x = list(map(int, input().split(' ')))
for i in x:
print([4*i+1, 2*i+1, 4*i+1, i+1][i%4])
``` | vfc_41409 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4 8 100\n",
"output": "17\n33\n401\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 13\n",
"output":... |
code_contests | verifiable_code | 241_F. Race | Solve the following coding problem using the programming language python:
The Old City is a rectangular city represented as an m × n grid of blocks. This city contains many buildings, straight two-way streets and junctions. Each junction and each building is exactly one block. All the streets have width of one block a... | ```python
#t = input()
t = 1
def xstep(p, q):
if p<q:
return p+1
elif p>q:
return p-1
else:
return p
def step(p, q):
return (xstep(p[0], q[0]), xstep(p[1], q[1]))
for _ in range(t):
n, m, k = tuple(int(x) for x in raw_input().split())
tbl = [list(raw_input()) for i in ran... | vfc_41417 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 3 5\n###\n#w#\n#1#\n#a#\n#1#\n#1#\n#1#\n#1#\n#b#\n###\n3 2 abababababababab 6 2\n",
"output": "8 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 10 6\n##########\n#z1a1311b#\n######... |
code_contests | verifiable_code | 266_E. More Queries to Array... | Solve the following coding problem using the programming language python:
You've got an array, consisting of n integers: a1, a2, ..., an. Your task is to quickly run the queries of two types:
1. Assign value x to all elements from l to r inclusive. After such query the values of the elements of array al, al + 1, ..... | vfc_41421 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 5\n5 10 2 1\n? 1 2 1\n= 2 2 0\n? 2 4 3\n= 1 4 1\n? 1 4 5\n",
"output": " 25\n 43\n ... | |
code_contests | verifiable_code | 28_E. DravDe saves the world | Solve the following coding problem using the programming language python:
How horrible! The empire of galactic chickens tries to conquer a beautiful city «Z», they have built a huge incubator that produces millions of chicken soldiers a day, and fenced it around. The huge incubator looks like a poligon on the the plan... | vfc_41425 | {
"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\n0 0\n1 0\n1 1\n0 1\n0 -1\n1 1 1\n-1\n1 1 -1\n",
"output": "0.500000000000 0.000000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 0\n0 1\n1 1\n1 0\n0 -1\n-1 -1 1\n-1\n0 1 -1... | |
code_contests | verifiable_code | 315_E. Sereja and Subsequences | Solve the following coding problem using the programming language python:
Sereja has a sequence that consists of n positive integers, a1, a2, ..., an.
First Sereja took a piece of squared paper and wrote all distinct non-empty non-decreasing subsequences of sequence a. Then for each sequence written on the squared p... | ```python
n = input()
a = map(int, raw_input().split())
mod = int(1e+9) + 7
size = max(a)
tree = [0] * (size + 1)
def query(index):
res = 0
while index:
res = (res + tree[index]) % mod
index -= index & -index
return res
def update(index, delta):
while index <= size:
tree[index] = (tree[index] + de... | vfc_41429 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n42\n",
"output": "42",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 2 3 4 5\n",
"output": "719",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | 360_D. Levko and Sets | Solve the following coding problem using the programming language python:
Levko loves all sorts of sets very much.
Levko has two arrays of integers a1, a2, ... , an and b1, b2, ... , bm and a prime number p. Today he generates n sets. Let's describe the generation process for the i-th set:
1. First it has a single... | vfc_41437 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1 7\n2\n5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1 7\n1 6\n5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
code_contests | verifiable_code | 384_B. Multitasking | Solve the following coding problem using the programming language python:
Iahub wants to enhance his multitasking abilities. In order to do this, he wants to sort n arrays simultaneously, each array consisting of m integers.
Iahub can choose a pair of distinct indices i and j (1 ≤ i, j ≤ m, i ≠ j). Then in each array... | ```python
n,m,k = map(int,input().split())
for i in range(n):
a = [int(x) for x in input().split()]
d = []
for i in range(1,m):
for j in range(i+1,m+1):
if k == 0:
d.append((i,j))
else:
d.append((j,i))
print(len(d))
for i in d:
print(*i)
``` | vfc_41441 | {
"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 5 0\n1 3 2 5 4\n1 4 3 2 5\n",
"output": "10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2 1\n1 2\n2 3\n3 4\n",
"output": "1\... |
code_contests | verifiable_code | 405_A. Gravity Flip | Solve the following coding problem using the programming language python:
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are n columns of toy cubes in the box arranged in a line. The... | ```python
cols = int(input(""))
inputs = input("")
inputList = inputs.split(' ')
inputList.sort(key=int)
for i in inputList:
print(i, end=" ")
``` | vfc_41445 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 3 8\n",
"output": "2 3 8 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n3 2 1 2\n",
"output": "1 2 2 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 432_B. Football Kit | Solve the following coding problem using the programming language python:
Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).
... | ```python
n = int(input())
a = [0]*(10**5 + 1)
c = []
for i in range(n):
x,y = map(int, input().split())
c.append([x,y])
a[x]+=1
ans = n - 1
for i in range(n):
d = ans + a[c[i][1]]
print(d,2*(n - 1) - d)
``` | vfc_41449 | {
"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\n1 2\n2 1\n",
"output": "2 0\n2 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2\n2 1\n1 3\n",
"output": "3 1\n4 0\n2 2\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 454_D. Little Pony and Harmony Chest | Solve the following coding problem using the programming language python:
Princess Twilight went to Celestia and Luna's old castle to research the chest from the Elements of Harmony.
<image>
A sequence of positive integers bi is harmony if and only if for every two elements of the sequence their greatest common divi... | vfc_41453 | {
"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\n1 6 4 2 8\n",
"output": "1 5 3 1 8 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 1 1 1 1\n",
"output": "1 1 1 1 1",
"type": "stdin_stdout"
},
{
"fn_nam... | |
code_contests | verifiable_code | 477_B. Dreamoon and Sets | Solve the following coding problem using the programming language python:
Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b.
Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for a... | ```python
a, b = map(int, input().split(' '))
print((6*a-1)*b)
for i in range(a):
print((6*i+1)*b, (6*i+2)*b, (6*i+3)*b, (6*i+5)*b)
# Made By Mostafa_Khaled
``` | vfc_41457 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n",
"output": "22\n2 4 6 10\n14 16 18 22\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n",
"output": "5\n1 2 3 5\n",
"type": "stdin_stdout"
},
{
"fn_nam... |
code_contests | verifiable_code | 4_C. Registration system | Solve the following coding problem using the programming language python:
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of sit... | ```python
users = {}
for x in range (0, int(input())):
want = input()
if want in users:
print(want + str(users[want]))
users[want] += 1
else:
print("OK")
users[want] = 1
``` | vfc_41461 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n",
"output": "OK\nfirst1\nOK\nsecond1\nOK\nthird1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\nabacaba\nacaba\nabacaba\nacab\n",
... |
code_contests | verifiable_code | 525_B. Pasha and String | Solve the following coding problem using the programming language python:
Pasha got a very beautiful string s for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |s| from left to right, where |s| is the length of the given string.
Pasha didn't like his pr... | ```python
s = list(input())
m = int(input())
a = [int(x) for x in input().split()]
n = len(s) // 2
sums = [0] * (n+1)
for i in a:
sums[i-1] += 1
for i in range (1, len(sums)):
sums[i] += sums[i-1]
for i in range(n):
if sums[i] % 2 != 0:
s[i], s[len(s) - i - 1] = s[len(s) - i - 1], s[i]
print("".jo... | vfc_41465 | {
"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": "abcdef\n3\n1 2 3\n",
"output": "fbdcea\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "abcdef\n1\n2\n",
"output": "aedcbf\n",
"type": "stdin_stdout"
},
{
"fn_name... |
code_contests | verifiable_code | 577_D. Invariance of Tree | Solve the following coding problem using the programming language python:
A tree of size n is an undirected connected graph consisting of n vertices without cycles.
Consider some tree with n vertices. We call a tree invariant relative to permutation p = p1p2... pn, if for any two vertices of the tree u and v the cond... | ```python
def main():
n = int(input())
a = list(map(lambda x: int(x) - 1, input().split()))
p = -1
q = -1
for i in range(n):
if a[a[i]] == i:
p, q = i, a[i]
if a[i] == i:
print('YES')
[print(i + 1, j + 1) for j in range(n) if i != j]
e... | vfc_41473 | {
"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\n3 1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n4 3 2 1\n",
"output": "YES\n1 4\n1 2\n4 3\n",
"type": "stdin_stdout"
},
{
"fn_name":... |
code_contests | verifiable_code | 59_B. Fortune Telling | Solve the following coding problem using the programming language python:
Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camom... | ```python
n = int(input())
l = list(map(int, input().split()))
r = 0
par = []
nep = []
for item in l:
if item % 2 == 0:
par.append(item)
else:
nep.append(item)
if len(nep) % 2 == 0 and nep != []:
nep.remove(min(nep))
r += sum(nep)
if r != 0:
r += sum(par)
print(r)
``` | vfc_41477 | {
"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\n5 6 7\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "... |
code_contests | verifiable_code | 641_E. Little Artem and Time Machine | Solve the following coding problem using the programming language python:
Little Artem has invented a time machine! He could go anywhere in time, but all his thoughts of course are with computer science. He wants to apply this time machine to a well-known data structure: multiset.
Artem wants to create a basic multis... | ```python
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(... | vfc_41485 | {
"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\n2 2 1\n3 3 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1 1 5\n3 5 5\n1 2 5\n3 6 5\n2 3 5\n3 7 5\n",
"output": "1\n2\n1\n",
"type": "stdin_st... |
code_contests | verifiable_code | 66_C. Petya and File System | Solve the following coding problem using the programming language python:
Recently, on a programming lesson little Petya showed how quickly he can create files and folders on the computer. But he got soon fed up with this activity, and he decided to do a much more useful thing. He decided to calculate what folder cont... | ```python
lines = []
from collections import defaultdict
d = {}
while True:
try:
x = input();
if len(x) == 0:
break
x = x.split("\\")
lines.append(x[1:])
curr_d = d
for i in range(0, len(x) - 1):
curr = x[i]
if curr in curr_d:
... | vfc_41489 | {
"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": "C:<span class=\"tex-span\">\\</span>file<span class=\"tex-span\">\\</span>file<span class=\"tex-span\">\\</span>file<span class=\"tex-span\">\\</span>file<span class=\"tex-span\">\\</span>file.txt\nC:<span class=\"tex-span\">\\</sp... |
code_contests | verifiable_code | 690_F3. Tree of Life (hard) | Solve the following coding problem using the programming language python:
To add insult to injury, the zombies have taken all but two drawings from Heidi! Please help her recover the Tree of Life from only these two drawings.
Input
The input format is the same as in the medium version, except that now the bound on n... | vfc_41493 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n9 2\n6\n4 3\n5 4\n6 1\n8 6\n8 2\n7 1\n5\n8 6\n8 7\n8 1\n7 3\n5 1\n",
"output": "YES\n2 1\n3 1\n4 1\n5 4\n6 5\n7 6\n8 5\n9 8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n9 2\n6\n4 ... | |
code_contests | verifiable_code | 715_E. Complete the Permutations | Solve the following coding problem using the programming language python:
ZS the Coder is given two permutations p and q of {1, 2, ..., n}, but some of their elements are replaced with 0. The distance between two permutations p and q is defined as the minimum number of moves required to turn p into q. A move consists ... | vfc_41497 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 0 0 3\n0 0 0 4\n",
"output": "0 2 6 4 ",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 736_B. Taxes | Solve the following coding problem using the programming language python:
Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n ≥ 2) burles and the amount of tax he has to pay is calculated as the maximum divisor of n (not equal to n, of course). ... | ```python
# ========= /\ /| |====/|
# | / \ | | / |
# | /____\ | | / |
# | / \ | | / |
# ========= / \ ===== |/====|
# code
if __name__ == "__main__":
def prime(n):
if n == 1:
return False
i ... | vfc_41501 | {
"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": "27\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13\n",
... |
code_contests | verifiable_code | 760_B. Frodo and pillows | Solve the following coding problem using the programming language python:
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's ... | ```python
n, m, k = map(int, input().split())
m -= n
d = 0
k -= 1
out = 1
while m > 1 and d != max(k, n - k - 1):
out += 1
m -= 1
left = min(d, k)
right = min(d, n - k - 1)
d += 1
m -= left
m -= right
out += m // n
print(out)
``` | vfc_41505 | {
"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 10 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 6 1\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 780_F. Axel and Marston in Bitland | Solve the following coding problem using the programming language python:
A couple of friends, Axel and Marston are travelling across the country of Bitland. There are n towns in Bitland, with some pairs of towns connected by one-directional roads. Each road in Bitland is either a pedestrian road or a bike road. There... | vfc_41509 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n1 2 0\n2 2 1\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n1 2 0\n2 2 1\n2 2 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_na... | |
code_contests | verifiable_code | 82_B. Sets | Solve the following coding problem using the programming language python:
Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just ... | ```python
c, v = [[0] * 201 for i in range(201)], []
n = int(input())
for i in range(n * (n - 1) // 2):
a = list(map(int, input().split()))[1:]
for x in a:
for y in a:
c[x][y] += 1
for i, ci in enumerate(c):
if ci[i]:
a = [j for j, cij in enumerate(ci) if cij == n - 1]
v.... | vfc_41517 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n5 6 7 8 9 100\n4 7 8 9 1\n4 7 8 9 2\n3 1 6 100\n3 2 6 100\n2 1 2\n",
"output": "1 1 \n1 2 \n2 6 100 \n3 7 8 9 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n3 2 7 4\n3 1 7 3\n3 5 4... |
code_contests | verifiable_code | 850_D. Tournament Construction | Solve the following coding problem using the programming language python:
Ivan is reading a book about tournaments. He knows that a tournament is an oriented graph with exactly one oriented edge between each pair of vertices. The score of a vertex is the number of edges going outside this vertex.
Yesterday Ivan lear... | vfc_41521 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n0 3\n",
"output": "6\n000000\n101100\n100110\n100011\n110001\n111000\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 899_E. Segments Removal | Solve the following coding problem using the programming language python:
Vasya has an array of integers of length n.
Vasya performs the following operations on the array: on each step he finds the longest segment of consecutive equal integers (the leftmost, if there are several such segments) and removes it. For exa... | ```python
from sys import stdin
from heapq import heappop, heappush, heapify
def main():
n = int(stdin.readline())
a = stdin.readline().split()
q = []
p = 0
c = 0
l = [0] * (n + 1)
r = [0] * (n + 1)
k = [0] * (n + 1)
pa = [0] * (n + 1)
for i, x in enumerate(a):
if x == a[... | vfc_41529 | {
"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": "8\n4 4 4 2 2 100 100 100\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n2 5 5 2\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | 948_D. Perfect Security | Solve the following coding problem using the programming language python:
Alice has a very important message M consisting of some non-negative integers that she wants to keep secret from Eve. Alice knows that the only theoretically secure cipher is one-time pad. Alice generates a random key K of the length equal to th... | vfc_41537 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n8 4 13\n17 2 7\n",
"output": "10 3 28 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n331415699 278745619 998190004 423175621 42983144 166555524 843586353 802130100 337889448 68531... | |
code_contests | verifiable_code | 996_B. World Cup | Solve the following coding problem using the programming language python:
Allen wants to enter a fan zone that occupies a round square and has n entrances.
There already is a queue of a_i people in front of the i-th entrance. Each entrance allows one person from its queue to enter the fan zone in one minute.
Allen u... | ```python
_ = input()
arr = list(map(int, input().split()))
best = None
for i in range(len(arr)):
pos_at_zero = arr[i] % len(arr)
if pos_at_zero > i:
extra = len(arr) - pos_at_zero + i
else:
extra = i - pos_at_zero
time_needed = arr[i] + extra
#print(i, time_needed, extra, arr[i])
... | vfc_41545 | {
"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\n2 3 2 0\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n5 2 6 5 7 4\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | ballsaprileasy | Solve the following coding problem using the programming language python:
A square pyramid of balls consists of square layers of balls stacked on top of each other. The i th (1-based indexing )layer from the top consists of exactly i^2 balls. Image
You have received one such beautiful square pyramid on your birthday,... | ```python
n = input()
a = map(int, raw_input().split() )
a.sort()
layer, result = 1, 0
for u in a:
while layer * layer < u:
result += layer * layer
layer += 1
result += layer * layer - u
layer += 1
print result
``` | vfc_41549 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3 4 5\n\nSAMPLE",
"output": "40\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 ... |
code_contests | verifiable_code | city-and-campers | Solve the following coding problem using the programming language python:
"Money money MONEY, I want money" thought Alex. "Now how do I get money? Well... I'll open up a camp!"
Well, unfortunately things didn't go so well for Alex's campers, and now there are N campers wandering around the city aimlessly. You have to... | ```python
def union(parents, depths, i, j):
''' Union with under the deepest root '''
if depths[i] > depths[j]:
parents[j] = i
else:
parents[i] = j
depths[i] = max(depths[i], depths[j] + 1)
def find(parents, el):
''' Find an element and compress the sets '''
if parents[el] =... | vfc_41553 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1\n1 2\n\nSAMPLE",
"output": "0",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | help-golu | Solve the following coding problem using the programming language python:
Golu loves prime numbers . He wants to do something new with prime numbers. So Molu gives him a number and asks him to minmum number of prime numbers required such that their sum is equal to given number. This task is very diffcult for Golu so h... | ```python
import math
def check(n):
return all( n%i for i in range(2, int(math.sqrt(n) ) + 1 ))
for i in range(input()):
val = input()
print "1" if check(val) else "2" if check(val-2) or val % 2 == 0 else "3"
"""
import math
primes = []
def primeSieve(sieveSize):
sieve = [True] * sieveSize
sieve[0] = F... | vfc_41561 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n4\n\nSAMPLE",
"output": "1\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n43\n5541\n6336\n646\n6243\n2798\n5016\n3504\n1108\n5074",
"output": "1\n3\n2\n2\n3\n2\n2\n2\n2... |
code_contests | verifiable_code | navi-and-his-friend | Solve the following coding problem using the programming language python:
Navi is a famous shopkeeper in his locality. He gives discounts to his regular customers. Some new rules have been made due to which he is in trouble. According to the new rules, any shopkeeper can sale his items to only one customer in a day. B... | ```python
import math
def solve(indx, sums, prev, curr):
global noOfItem, cnts, wtMax, price, weight
if indx == noOfItem or curr == cnts or sums == wtMax:
return prev
ans1 = solve(indx + 1, sums, prev, curr)
ans2 = 0
if (sums + weight[indx]) <= wtMax:
ans2 = solve(indx + 1, sums + ... | vfc_41569 | {
"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\n10 20\n20 30\n30 40\n50 2\n\nSAMPLE",
"output": "For Day #1:\n30",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | product-of-and-gate | Solve the following coding problem using the programming language python:
Heading ##There are two integers A and B. You are required to compute the bitwise AND amongst all natural numbers lying between A and B, both inclusive.
Input Format
First line of the input contains T, the number of testcases to follow.
Each te... | ```python
tc=input()
while tc:
a,b=map(int,raw_input().split())
if a<b:
print a
else:
print b
tc=tc-1
``` | vfc_41573 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 \n12 15 \n2 3 \n8 13\n\nSAMPLE",
"output": "12\n2\n8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 \n8 15 \n2 3 \n8 13\n\nSAMPLE",
"output": "8\n2\n8\n",
"type": "stdin_s... |
code_contests | verifiable_code | shekhar-loves-to-travel | Solve the following coding problem using the programming language python:
Richard is a travel freak. He is now out to travel to a distant place with his friends, so he took his car and went out with a certain amount of fuel. Thus he must stop at a fuel station before his fuel gets over. There are several fuel station ... | ```python
def distance(dis,alist):
i=0
next=0
mx =0
t=0
while i<dis-1 and next<dis-1:
mx=max(mx,i+int(alist[i]))
if i==next:
if mx == next:
return -1
next = mx
t+=1
i+=1
return t
test=int(raw_input())
while test>0:
... | vfc_41577 | {
"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\n2 15 5 6 2\n11\n1 3 5 8 9 2 6 7 6 8 9\n\nSAMPLE",
"output": "1\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n79\n1 1 14 17 11 1 12 1 17 1 17 11 13 16 10 1 13 3 5 12 8 16 19 1... |
code_contests | verifiable_code | the-castle-gate-july-easy | Solve the following coding problem using the programming language python:
Gudi, a fun loving girl from the city of Dun, travels to Azkahar - a strange land beyond the mountains. She arrives at the gates of Castle Grey, owned by Puchi,the lord of Azkahar to claim the treasure that it guards. However, destiny has other... | ```python
from operator import xor
tests = int(raw_input())
for test in range(tests):
number = int(raw_input())
count = 0
for i in range(1, number):
for j in range(i+1, number+1):
if xor(i, j) <= number:
count +=1
print count
``` | vfc_41581 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4\n6\n8\n\nSAMPLE",
"output": "3\n12\n21\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n4\n6\n15\n\nSAMPLE",
"output": "3\n12\n105\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | xenny-and-k-equal-triplets | Solve the following coding problem using the programming language python:
Xenny had N numbers and he loved equal triplets (An equal triplet is group of 3 numbers that are equal).
He defined a K-equal-triplet as a triplet in which all 3 integers were equal to K.
Given an integer K, he wanted to find out the probability... | ```python
def gcd(a,b):
if a == 0:
return b
if b == 0:
return a;
return gcd(b%a, a)
test = int(raw_input())
for i in range(test):
n,k = map(long, raw_input().split())
arr = map(long, raw_input().split())
cnt = 0
for j in range(0, n):
x = arr[j]
if x==k:
... | vfc_41585 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n5 4\n1 4 4 4 1\n\nSAMPLE",
"output": "1/10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n5 4\n1 4 4 4 1\n\nSAMPEL",
"output": "1/10\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | p00070 Combination of Number Sequences | Solve the following coding problem using the programming language python:
Consider a sequence of n numbers using integers from 0 to 9 k1, k2, ..., kn. Read the positive integers n and s,
k1 + 2 x k2 + 3 x k3 + ... + n x kn = s
Create a program that outputs how many rows of n numbers such as. However, the same number... | ```python
from collections import defaultdict, Counter
import sys
# dp[n][使った数字(bit)][合計] = count
dp = [defaultdict(Counter) for _ in [0]*11]
dp[0][0][0] = 1
for i in range(1, 11):
for used, counter in dp[i-1].items():
for j in filter(lambda x: used & 2**x == 0, range(10)):
for total, count in... | vfc_41629 | {
"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 10\n3 1",
"output": "8\n0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 10\n3 1",
"output": "1\n0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00202 At Boss's Expense | Solve the following coding problem using the programming language python:
Taro Aizu's company has a boss who hates being indivisible. When Taro goes out to eat with his boss, he pays by splitting the bill, but when the payment amount is not divisible by the number of participants, his boss always pays for it.
One day... | ```python
def solve(price, ps, is_prime):
dp = [0] * ((price >> 5) + 1)
for i in range(0, price + 1,ps[0]):
dp[i >> 5] |= 1 << (i & 31)
dp[0] = 1
for i in range(1, len(ps)):
cur_p = ps[i]
r = cur_p & 31
rest = 0
if cur_p >= 32:
for p in range(cur_p, p... | vfc_41633 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 15000\n305\n260\n129\n500\n3 400\n10\n20\n30\n3 200909\n5\n9\n12\n0 0",
"output": "14983\nNA\n200909",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00716 Ohgas' Fortune | Solve the following coding problem using the programming language python:
The Ohgas are a prestigious family based on Hachioji. The head of the family, Mr. Nemochi Ohga, a famous wealthy man, wishes to increase his fortune by depositing his money to an operation company. You are asked to help Mr. Ohga maximize his pro... | ```python
def c(a):
global y,r,d
for _ in range(y):a+=int(a*r)-d
return a
def s(a):
global y,r,d
b=0
for _ in range(y):
b+=int(a*r)
a-=d
return a+b
for _ in range(int(input())):
m=0
a=int(input());y=int(input())
for _ in range(int(input())):
b,r,d=map(fl... | vfc_41645 | {
"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\n1000000\n5\n2\n0 0.03125 3000\n1 0.03125 3000\n6620000\n7\n2\n0 0.0732421875 42307\n1 0.0740966796875 40942\n39677000\n4\n4\n0 0.0709228515625 30754\n1 0.00634765625 26165\n0 0.03662109375 79468\n0 0.0679931640625 10932\n1058500... |
code_contests | verifiable_code | p00856 Minimal Backgammon | Solve the following coding problem using the programming language python:
Here is a very simple variation of the game backgammon, named “Minimal Backgammon”. The game is played by only one player, using only one of the dice and only one checker (the token used by the player).
The game board is a line of (N + 1) squar... | ```python
while True:
N, T, L, B = map(int, input().split())
if not (N | T | L | B):
break
Lose = [False for i in range(N + 1)]
Back = [False for i in range(N + 1)]
for i in range(L):
Lose[int(input())] = True
for j in range(B):
Back[int(input())] = True
dp = [[0.0... | vfc_41649 | {
"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 1 0 0\n7 1 0 0\n7 2 0 0\n6 6 1 1\n2\n5\n7 10 0 6\n1\n2\n3\n4\n5\n6\n0 0 0 0",
"output": "0.166667\n0.000000\n0.166667\n0.619642\n0.000000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 ... |
code_contests | verifiable_code | p01119 Balance Scale | Solve the following coding problem using the programming language python:
<!--
Problem C
-->
Balance Scale
You, an experimental chemist, have a balance scale and a kit of weights for measuring weights of powder chemicals.
For work efficiency, a single use of the balance scale should be enough for measurement of e... | ```python
def main():
n,m = map(int,input().split())
if n*m == 0: return False
a = list(map(int, input().split()))
w = list(map(int,input().split()))
d = {0:1}
for i in w:
new_d = dict(d)
for j in d.keys():
new_d[j+i] = 1
new_d[abs(j-i)] = 1
new_d[... | vfc_41657 | {
"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": "4 2\n9 2 7 11\n2 9\n6 2\n7 3 6 12 16 9\n2 9\n5 2\n7 3 6 12 17\n2 9\n7 5\n15 21 33 48 51 75 111\n36 54 57 93 113\n0 0",
"output": "0\n5\n-1\n5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "... |
code_contests | verifiable_code | p01257 Vending Machine | Solve the following coding problem using the programming language python:
There has been marketing warfare among beverage vendors, and they have been working hard for in- crease of their sales. The Kola-Coqua Company is one of the most successful vendors among those: their impressive advertisements toward the world ha... | vfc_41661 | {
"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 330\n1 5 10 50 100 500\n7 127\n1 2 4 8 16 32 64\n2 10000\n1000 2000\n0 0",
"output": "2\n1\n4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 330\n1 5 10 50 100 500\n7 127\n1 2 4 8 29 32... | |
code_contests | verifiable_code | p01418 Sleeping Time | Solve the following coding problem using the programming language python:
Miki is a high school student. She has a part time job, so she cannot take enough sleep on weekdays. She wants to take good sleep on holidays, but she doesn't know the best length of sleeping time for her. She is now trying to figure that out wi... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 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_41665 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 0 2\n0.10000000000\n0.00000100000\n0.37500000000",
"output": "0.729000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 0 2\n0.10000000000\n0.37499999977\n1.00000000000",
"output": ... |
code_contests | verifiable_code | p01572 Artistic Art Museum | Solve the following coding problem using the programming language python:
Mr. Knight is a chief architect of the project to build a new art museum. One day, he was struggling to determine the design of the building. He believed that a brilliant art museum must have an artistic building, so he started to search for a g... | vfc_41669 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n8 -1 2 1 2 1 -3 2 -3 2 3 -2 3 -2 -3 -1 -3",
"output": "22.6303",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01734 Removing Magical Tiles | Solve the following coding problem using the programming language python:
Ayimok is a wizard.
His daily task is to arrange magical tiles in a line, and then cast a magic spell.
Magical tiles and their arrangement follow the rules below:
* Each magical tile has the shape of a trapezoid with a height of 1.
* Some mag... | vfc_41673 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n26 29 9 12\n6 10 15 16\n8 17 18 19",
"output": "1",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01873 Periodic Sequence | Solve the following coding problem using the programming language python:
B: Periodic Sequence-
problem
Dr. Period, a professor at H University, is studying a property called the cycle that is supposed to be hidden in all things. As a generally known basic cycle, a cycle hidden in a sequence may be considered. That ... | ```python
n=int(input())
a=list(map(int,input().split()))
for i in range(1,n+1):
if n%i==0:
for j in range(n):
if j>=i and a[j]!=a[j-i]:break
else:print(n//i);exit()
print(1)
``` | vfc_41677 | {
"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": "6\n1 2 3 1 2 3",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1 2 3 1 1 3",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | p02010 Additions | Solve the following coding problem using the programming language python:
You are given an integer $N$ and a string consisting of '+' and digits. You are asked to transform the string into a valid formula whose calculation result is smaller than or equal to $N$ by modifying some characters. Here, you replace one chara... | ```python
from heapq import heappush, heappop, heapify
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N = int(readline())
S = readline().strip()
L = len(S)
S += "+"
if L % 2 == 0 and N < 10:
write("-1\n")
return
pw10 = [1]*11
for i in range(10)... | vfc_41681 | {
"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": "2000\n1234++7890",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n+123",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | p02294 Intersection | Solve the following coding problem using the programming language python:
For given two segments s1 and s2, print "1" if they are intersect, "0" otherwise.
s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and p3.
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.
I... | ```python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
3
0 0 3 0 1 1 2 -1
0 0 3 0 3 1 3 -1
0 0 3 0 3 -2 5 0
output:
1
1
0
"""
import sys
EPS = 1e-9
def cross(a, b):
return a.real * b.imag - a.imag * b.real
def dot(a, b):
return a.real * b.real + a.imag * b.imag
def check_ccw(p0, p1, p2):
... | vfc_41689 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n0 0 3 0 1 1 2 -1\n0 0 3 0 3 1 3 -1\n0 0 3 0 3 -2 5 0",
"output": "1\n1\n0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n0 0 3 0 1 1 2 -1\n0 0 3 0 3 1 3 -1\n0 0 6 0 3 -2 5 0",
"... |
code_contests | verifiable_code | axr1p2 | Solve the following coding problem using the programming language python:
Given this sequence
..
1^(1!)+2^(2!)+3^(3!)+4^(4!)+
..N^(N!).
Your job is to write a program such that given N any time, you have to find out the unit place digit of the sum of the above sequence.
Input
Enter the number N to cal... | ```python
def factorial(k):
if k > 4: k = 4 # specific code
P = 1
for i in xrange(1,k+1):
P *= i
return P
def process(N):
S = 0
for i in xrange(1, N + 1):
S += ((i % 10) ** factorial(i)) % 10
return S
def main():
while True:
N = raw_input()
if N == '#': ... | vfc_41697 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "71\n#",
"output": "8\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | cmb01 | Solve the following coding problem using the programming language python:
Reversed number is a number written in arabic numerals but the order of digits is reversed.
The first digit becomes last and vice versa. For example, if the number is 1245,it will become
5421 .Note that all the leading zeros are omitted. That ... | ```python
import sys
t=input()
while(t>0):
sumu=0
n, m = map(int, sys.stdin.readline().split(' '))
n=str(n)[::-1]
n=int(n)
m=str(m)[::-1]
m=int(m)
sumu=n+m
sumu=str(sumu)[::-1]
sumu=int(sumu)
print sumu
t=t-1
``` | vfc_41701 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n24 1",
"output": "34\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n24 2",
"output": "44\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1... |
code_contests | verifiable_code | flow011 | Solve the following coding problem using the programming language python:
In a company an emplopyee is paid as under:
If his basic salary is less than Rs. 1500, then HRA = 10% of base salary and DA = 90% of basic salary. If his salary is either equal to or above Rs. 1500, then HRA = Rs. 500 and DA = 98% of basic sala... | ```python
#!/usr/bin/python
for i in range(input()):
basic=input()
if basic<1500:
gross=(basic+basic*0.1+basic*0.9)
else:
gross=(basic+500+basic*0.98)
print "%g" %gross
``` | vfc_41705 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 \n1203\n10042\n1312",
"output": "2406\n20383.2\n2624\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 \n1203\n6117\n1312",
"output": "2406\n12611.7\n2624\n",
"type": "stdin_... |
code_contests | verifiable_code | ppxor | Solve the following coding problem using the programming language python:
Polo, the Penguin, likes the XOR operation. Please read NOTE if you are not familiar with XOR operation.
XOR-sum of a list of numbers is the result of XOR-ing all of them. XOR-sum of (A[1] XOR A[2] XOR ... XOR A[N]) is defined as A[1] XOR (A[2]... | ```python
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import random
def count_bits(n):
res = 0
while n:
res += 1
n >>= 1
return res
t = int(raw_input())
for _ in range(t):
n = int(raw_input())
lst = map(int, raw_input().split())
#lst = [random.randint(0, (1 << 16) - 1) for i... | vfc_41713 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2\n1 2",
"output": "6",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | sumtrian | Solve the following coding problem using the programming language python:
Let's consider a triangle of numbers in which a number appears in the first line, two numbers appear in the second line, three in the third line, etc. Develop a program which will compute the largest of the sums of numbers that appear on the pat... | ```python
t=input()
for i in range(t):
n=input()
prev_row=[]
first_element=input()
prev_row.append(first_element)
for j in range(1,n):
row=[int(k) for k in raw_input().split()]
for l in range(1,len(row)-1):
row[l]+=max(prev_row[l],prev_row[l-1])
row[len(r... | vfc_41717 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n1\n2 1\n1 2 3\n4 \n1 \n1 2 \n4 1 2\n2 3 1 1",
"output": "5\n9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3\n1\n2 1\n1 2 3\n4 \n1 \n1 2 \n4 1 2\n2 0 1 1",
"output": "5\n... |
code_contests | verifiable_code | 100_J. Interval Coloring | Solve the following coding problem using the programming language python:
Aryo has got a lot of intervals for his 2418th birthday. He is really excited and decided to color all these intervals with some colors. He has a simple rule for himself. He calls a coloring nice if there exists no three intervals a, b and c suc... | vfc_41721 | {
"difficulty": "16",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n[1,2)\n(3,4]\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n[1,3]\n[2,6]\n(5,7)\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1033_G. Chip Game | Solve the following coding problem using the programming language python:
Alice and Bob decided to play one ultimate game. They have n piles, the i-th pile initially contain v_i chips. Alice selects a positive integer a from interval [1, m], and Bob selects a number b the same way.
Then the game starts. In her turn,... | vfc_41725 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 20\n4 5\n",
"output": "82 82 6 230\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n4 5\n",
"output": "1 1 1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... | |
code_contests | verifiable_code | 1056_E. Check Transcription | Solve the following coding problem using the programming language python:
One of Arkady's friends works at a huge radio telescope. A few decades ago the telescope has sent a signal s towards a faraway galaxy. Recently they've received a response t which they believe to be a response from aliens! The scientists now wan... | ```python
import sys
from math import *
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
def add(a,b):
return (a+b)%1000000007
def sub(a,b):
return (a+1000000007-b)%1000000007
def mul(a,b):
return (a*b)%1000000007
p = 102367
s = lis... | vfc_41729 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "001\nkokokokotlin\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "01\naaaaaa\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 107_A. Dorm Water Supply | Solve the following coding problem using the programming language python:
The German University in Cairo (GUC) dorm houses are numbered from 1 to n. Underground water pipes connect these houses together. Each pipe has certain direction (water can flow only in this direction and not vice versa), and diameter (which cha... | ```python
import sys
input = sys.stdin.readline
for _ in range(1):
n,m=[int(x) for x in input().split()]
g,v=[[] for i in range(n)],[False for i in range(n)]
s=[False for i in range(n)]
for i in range(m):
a,b,c=[int(x) for x in input().split()]
s[b-1]=True
g[a-1].append([b-1,c])
... | vfc_41733 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\n1 2 60\n3 4 50\n",
"output": "2\n1 2 60\n3 4 50\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1099_F. Cookies | Solve the following coding problem using the programming language python:
Mitya and Vasya are playing an interesting game. They have a rooted tree with n vertices, and the vertices are indexed from 1 to n. The root has index 1. Every other vertex i ≥ 2 has its parent p_i, and vertex i is called a child of vertex p_i.
... | vfc_41737 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 26\n1 5 1 7 7\n1 3 2 2 2\n1 1\n1 1\n2 0\n2 0\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 179\n2 2 1\n6 6 6\n1 3\n2 3\n",
"output": "4\n",
"type": "std... | |
code_contests | verifiable_code | 111_E. Petya and Rectangle | Solve the following coding problem using the programming language python:
Little Petya loves playing with rectangles. Mom bought Petya a rectangle divided into cells n × m in size (containing n rows, m columns). Petya marked two different cells of the rectangle and now he is solving the following task:
Let's define a... | vfc_41741 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4\n2 2\n3 3\n",
"output": "15\n2 2\n3 2\n4 2\n4 1\n3 1\n2 1\n1 1\n1 2\n1 3\n1 4\n2 4\n3 4\n4 4\n4 3\n3 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 6\n3 4\n4 3\n",
"output":... | |
code_contests | verifiable_code | 1147_B. Chladni Figure | Solve the following coding problem using the programming language python:
Inaka has a disc, the circumference of which is n units. The circumference is equally divided by n points numbered clockwise from 1 to n, such that points i and i + 1 (1 ≤ i < n) are adjacent, and so are points n and 1.
There are m straight seg... | ```python
from math import gcd
def primes():
yield 2; yield 3; yield 5; yield 7;
bps = (p for p in primes()) # separate supply of "base" primes (b.p.)
p = next(bps) and next(bps) # discard 2, then get 3
q = p * p # 9 - square of next base prime to ke... | vfc_41745 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 2\n1 6\n2 7\n",
"output": "Yes\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1168_C. And Reachability | Solve the following coding problem using the programming language python:
Toad Pimple has an array of integers a_1, a_2, …, a_n.
We say that y is reachable from x if x<y and there exists an integer array p such that x = p_1 < p_2 < … < p_k=y, and a_{p_i} \& a_{p_{i+1}} > 0 for all integers i such that 1 ≤ i < k.
H... | ```python
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop
import math
from collections import *
from functools import reduce,cmp_to_key,lru_cache
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# import sys
# input = sys.stdin.read... | vfc_41749 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n1 3 0 2 1\n1 3\n2 4\n1 4\n",
"output": "Fou\nShi\nShi\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n300000 300000\n1 2\n",
"output": "Shi\n",
"type": "stdin_stdout"... |
code_contests | verifiable_code | 1205_E. Expected Value Again | Solve the following coding problem using the programming language python:
You are given integers n, k. Let's consider the alphabet consisting of k different elements.
Let beauty f(s) of the string s be the number of indexes i, 1≤ i<|s|, for which prefix of s of length i equals to suffix of s of length i. For example,... | vfc_41757 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3\n",
"output": "333333336\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 10\n",
"output": "412377396\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
code_contests | verifiable_code | 1223_B. Strings Equalization | Solve the following coding problem using the programming language python:
You are given two strings of equal length s and t consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings.
During each operation you choose two adjacent characters in any string and assign ... | ```python
for _ in range(int(input())):
s=input()
s1=input()
s=set(s)
s1=set(s1)
if s1&s:
print('YES')
else:
print('NO')
``` | vfc_41761 | {
"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\nxabb\naabx\ntechnocup\ntechnocup\na\nz\n",
"output": "YES\nYES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nxabb\naabx\nteohnccup\ntechnocup\na\nz\n",
"output": "YES\nYE... |
code_contests | verifiable_code | 1248_E. Queue in the Train | Solve the following coding problem using the programming language python:
There are n seats in the train's car and there is exactly one passenger occupying every seat. The seats are numbered from 1 to n from left to right. The trip is long, so each passenger will become hungry at some moment of time and will go to tak... | ```python
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
from heapq import heappop, heappush, heapify
from collections import deque
class SWAG_Stack():
def __init__(self, F):
self.stack1 = deque()
self.stack2 = deque()
self.F = F
self.len = 0
def pu... | vfc_41765 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 314\n0 310 942 628 0\n",
"output": "314 628 1256 942 1570 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n1\n",
"output": "2 ",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 1288_E. Messenger Simulator | Solve the following coding problem using the programming language python:
Polycarp is a frequent user of the very popular messenger. He's chatting with his friends all the time. He has n friends, numbered from 1 to n.
Recall that a permutation of size n is an array of size n such that each integer from 1 to n occurs ... | ```python
n,m=map(int,input().split())
a=[int(i)-1 for i in input().split()]
ans1=[i+1 for i in range(n)]
ans2=[-1 for i in range(n)]
for i in set(a):
ans1[i]=1
N=1
while N<n+m:N<<=1
st=[0 for i in range(N<<1)]
pos=[i+m for i in range(n)]
for i in range(n):
st[i+N+m]=1
for i in range(N-1,0,-1):
st[i]=st[i<<1]... | vfc_41773 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4\n3 5 1 4\n",
"output": "1 3\n2 5\n1 4\n1 5\n1 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n1 2 4\n",
"output": "1 3\n1 2\n3 4\n1 4\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 130_E. Tribonacci numbers | Solve the following coding problem using the programming language python:
Tribonacci numbers are a sequence of numbers, defined as follows:
* t0 = t1 = 0,
* t2 = 1,
* ti = ti - 1 + ti - 2 + ti - 3.
You are given n; calculate n-th tribonacci number modulo 26.
Input
The only line of input contains an integer... | vfc_41777 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1331_H. It's showtime | Solve the following coding problem using the programming language python:
You are given a mysterious language (codenamed "UnknownX") available in "Custom Test" tab. Find out what this language is, and use it to solve the following problem.
You are given an integer input = 1000 * n + mod (1 ≤ n, mod ≤ 999). Calculate ... | vfc_41781 | {
"difficulty": "14",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6100\n",
"output": "\n48\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9900\n",
"output": "\n45\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... | |
code_contests | verifiable_code | 1419_C. Killjoy | Solve the following coding problem using the programming language python:
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating e... | ```python
for _ in range(int(input())):
n,x=map(int,input().split())
a=list(map(int,input().split()))
if len(set(a))==1 and list(set(a))[0]==x:
print(0)
elif sum(a)/n==x:
print(1)
elif x in a:
print(1)
else:
print(2)
``` | vfc_41797 | {
"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\n2 69\n68 70\n6 4\n4 4 4 4 4 4\n9 38\n-21 83 50 -59 -77 15 -71 -78 20\n",
"output": "1\n0\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2 1\n-10 13\n",
"output": "2\n",
... |
code_contests | verifiable_code | 1437_C. Chef Monocarp | Solve the following coding problem using the programming language python:
Chef Monocarp has just put n dishes into an oven. He knows that the i-th dish has its optimal cooking time equal to t_i minutes.
At any positive integer minute T Monocarp can put no more than one dish out of the oven. If the i-th dish is put ou... | ```python
from sys import stdin, stdout
t=int(stdin.readline())
for _ in range(t):
n=int(stdin.readline())
arr=list(map(int,stdin.readline().split()))
arr.sort()
dp=[[10**9 for _ in range(2*n)] for _ in range(n)]
for i in range(0,n):
for j in range(1,2*n):
if i==0:
dp[i][j]=min(dp[i][j-1],abs(arr[i]-j))
... | vfc_41801 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n6\n4 2 4 4 5 2\n7\n7 7 7 7 7 7 7\n1\n1\n5\n5 1 2 4 3\n4\n1 4 4 4\n21\n21 8 1 4 1 5 21 1 8 21 11 21 11 3 12 8 19 15 9 11 13\n",
"output": "4\n12\n0\n0\n2\n21\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... |
code_contests | verifiable_code | 1487_B. Cat Cycle | Solve the following coding problem using the programming language python:
Suppose you are living with two cats: A and B. There are n napping spots where both cats usually sleep.
Your cats like to sleep and also like all these spots, so they change napping spot each hour cyclically:
* Cat A changes its napping pla... | ```python
def main():
t = int(input())
for _ in range(t):
n, k = list(map(int, input().split()))
k -= 1
if n % 2 == 0:
print(k % n + 1)
else:
med = int(n*0.5)
print((k+int((k/med)))%n+1)
main()
``` | vfc_41809 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n2 1\n2 2\n3 1\n3 2\n3 3\n5 5\n69 1337\n",
"output": "\n1\n2\n1\n3\n2\n2\n65\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n999199999 999999999\n",
"output": "800002\n",
... |
code_contests | verifiable_code | 1510_J. Japanese Game | Solve the following coding problem using the programming language python:
Joseph really likes the culture of Japan. Last year he learned Japanese traditional clothes and visual arts and now he is trying to find out the secret of the Japanese game called Nonogram.
In the one-dimensional version of the game, there is a... | vfc_41813 | {
"difficulty": "16",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "___\n",
"output": "\n0\n\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "_#\n",
"output": "\n-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "_... | |
code_contests | verifiable_code | 185_E. Soap Time! - 2 | Solve the following coding problem using the programming language python:
Imagine the Cartesian coordinate system. There are k different points containing subway stations. One can get from any subway station to any one instantly. That is, the duration of the transfer between any two subway stations can be considered e... | vfc_41825 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 6, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n5 -3\n-4 -5\n-4 0\n-3 -2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 0\n2 -2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name... | |
code_contests | verifiable_code | 207_D2. The Beaver's Problem - 3 | Solve the following coding problem using the programming language python:
The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subjects. Let's describe the problem:
Y... | ```python
#path = "D:\\train\\"
#res = {}
#for i in xrange(1, 4):
#for j in xrange(1, 51):
#file = open(path + str(i) + '\\' + ("%.03d" % j) + '.txt')
#s1 = file.readline()
#s1 = file.readline()
#res[s1[:-1]] = i
#print res
s = {'U.S. M-1 MONEY SUPPLY RISES 1.2 BILLION DLR': 2, 'BRI... | vfc_41829 | {
"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": "8000\nNEW YORK BUSINESS LOANS FALL 222 MLN DLRS\nNEW YORK, March 26 - Commercial and industrial loans on the\nbooks of the 10 major New York banks, excluding acceptances,\nfell 222 mln dlrs to 64.05 billion in the week ended March ... |
code_contests | verifiable_code | 232_A. Cycles | Solve the following coding problem using the programming language python:
John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly k cycles of length 3.
A cycle of length 3 is an unordered group of three distinct graph vertices a, b and c, s... | ```python
import sys
import math
c=int(input())
Ans=[]
F=[1]
for i in range(1,101):
F.append(F[-1]*i)
for i in range(100):
Ans.append([0]*100)
print(100)
cycles=1
Ans[0][1]=1
Ans[1][0]=1
Ans[1][2]=1
Ans[2][1]=1
Ans[0][2]=1
Ans[2][0]=1
m=3
while(cycles<c):
Ans[0][m]=1
Ans[m][0]=1
inc=1
for j ... | vfc_41833 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "3\n011\n101\n110\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n",
"output": "5\n01111\n10111\n11011\n11101\n11110\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 257_E. Greedy Elevator | Solve the following coding problem using the programming language python:
The m-floor (m > 1) office of international corporation CodeForces has the advanced elevator control system established. It works as follows.
All office floors are sequentially numbered with integers from 1 to m. At time t = 0, the elevator is ... | vfc_41837 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 10\n1 2 5\n7 4 5\n",
"output": " 5\n 9\n",
"type": "stdin_stdout"
},
{
"fn_name... | |
code_contests | verifiable_code | 303_D. Rotatable Number | Solve the following coding problem using the programming language python:
Bike is a smart boy who loves math very much. He invented a number called "Rotatable Number" inspired by 142857.
As you can see, 142857 is a magic number because any of its rotatings can be got by multiplying that number by 1, 2, ..., 6 (numbe... | vfc_41845 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 11\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 8\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2\... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.