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 | 990_D. Graph And Its Complement | Solve the following coding problem using the programming language python:
Given three numbers n, a, b. You need to find an adjacency matrix of such an undirected graph that the number of components in it is equal to a, and the number of components in its complement is b. The matrix must be symmetric, and all digits on... | ```python
def generate_matrix(h):
result = [[0 for x in range(h)] for y in range(h)]
return result
def generate_m_component_matrix(h, comp):
result = generate_matrix(h)
for i in range(0, h - comp + 1):
for j in range(0, h - comp + 1):
result[i][j] = 0 if i == j else 1
return re... | vfc_40713 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1 2\n",
"output": "YES\n001\n001\n110\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | appointment-dates | Solve the following coding problem using the programming language python:
Rahul's Dad is the CEO of one of the leading companies. Every time somebody seeks for an appointment he calls up his secretary and asks her whether the day is a Sunday or not. He has to keep his caller on hold and is unhappy about it. Knowing th... | ```python
t = int(raw_input())
def anchor_day(year):
centurie = year[0] + year[1]
centurie = int(centurie)
if centurie % 4 == 1:
return 6
elif centurie % 4 == 2:
return 4
elif centurie % 4 == 3:
return 2
elif centurie % 4 == 0:
return 1
def doomsday_num(year, mo... | vfc_40717 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 2013\n5 2010\n\nSAMPLE",
"output": "3 10 17 24 31\n2 9 16 23 30",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3 2013\n2 2010\n\nSAMPLE",
"output": "3 10 17 24 31 \n7 14 21 28... |
code_contests | verifiable_code | chandu-and-his-girlfriend | Solve the following coding problem using the programming language python:
Chandu's girlfriend loves arrays that are sorted in non-increasing order. Today is her birthday. Chandu wants to give her some sorted arrays on her birthday. But the shop has only unsorted arrays. So, Chandu bought T unsorted arrays and is tryi... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
def solve(n, array):
tmp = sorted(array)[::-1]
for i in xrange(n):
tmp[i] = str(tmp[i])
return ' '.join(tmp)
def sort_array():
T = int(raw_input())
for _ in xrange(T):... | vfc_40721 | {
"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 5 2 4 3\n5\n5 4 2 3 1\n\nSAMPLE",
"output": "5 4 3 2 2\n5 4 3 2 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n544\n787201428 600339039 921908657 728383631 879989317 3613242... |
code_contests | verifiable_code | direrctory | Solve the following coding problem using the programming language python:
Lexicographical order is a generalization of the way the alphabetical order of words is based on the alphabetical order of their component letters. An example of lexicographical arrangement is a dictionary or a contact directory.
You are given ... | ```python
import re
romanNumeralMap = (('M', 1000),
('CM', 900),
('D', 500),
('CD', 400),
('C', 100),
('XC', 90),
('L', 50),
('XL', 40),
('X', 10),
... | vfc_40725 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "Bruce XXII\nHenri XX\nMaru XXXVI\nPhilippe XL\nLou XVI\nLovro XVI\nKubus XXXII\nMaru XXXIX\nBob XXXVIII\nRichard XXXIX\nCarlos II\nJames XXXIII\nAnne XXIV\nAnne XXVI\nPhilip XLVII\nIlya III\nKubus XLII\nJulka XIX\nMary XLVII\nLukas... |
code_contests | verifiable_code | golden-bowl | Solve the following coding problem using the programming language python:
It is lunch time at the Vibrant Gujarat Summit and all the investors are called for the executive lunch. When Bruce reached the lunch area, he found that the waiter was taking out bowls from a big box containing some amount of golden bowls and o... | ```python
import math
x=int(raw_input())
c=math.sqrt(1.+2.*x*(x-1.))
n=(c+1.)/2.
print int(n)
``` | vfc_40729 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "21\n\nSAMPLE",
"output": "15\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "31509019101",
"output": "22280241075\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | life-the-universe-and-everything | Solve the following coding problem using the programming language python:
Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything. More precisely... rewrite small numbers from input to output. Stop processing input after reading in the number 42. All numbers at... | ```python
t =1
while (t==1):
x = int(raw_input())
if (x == 42 ):
t =0
else:
print x
``` | vfc_40733 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2\n88\n42\n99\n\nSAMPLE",
"output": "1\n2\n88\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "176\n23\n897\n550\n842\n80\n768\n175\n462\n328\n33\n989\n103\n417\n620\n777\n852\n338\n122\... |
code_contests | verifiable_code | monks-business-day | Solve the following coding problem using the programming language python:
Monk visits Biksy, the largest trading market in the land. Biksy has traders from all over the world.
There are a total of N items indexed from 1 to N, that are traded in the market by a total of M dealers. Each trader is characterized by three ... | ```python
from collections import defaultdict
import sys
T = int(raw_input())
inf = sys.maxint
for test in range(T):
N,M = [int(x) for x in raw_input().split()]
D = [[inf]*(N+1) for x in range(N+1) ]
dicti = defaultdict(lambda :-1*inf)
for l in range(M):
i,j,c = [int(x) for x in raw_input().sp... | vfc_40737 | {
"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 6\n1 2 2\n2 3 -1\n3 4 -7\n4 5 0\n2 3 -7\n3 5 6\n5 8\n1 5 10\n2 3 -6\n5 2 5\n4 5 9\n1 5 1\n2 4 -10\n2 3 -2\n4 1 1\n\nSAMPLE",
"output": "No\nYes",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | playing-with-numbers | Solve the following coding problem using the programming language python:
Sherlock and Watson are close friends. One day, they finally got bored of playing normal games.
So, they came up with a new idea of playing with numbers.
Since they are good at number theory, they know the fact that a decimal number "A" can be... | ```python
t = int(raw_input())
r = "Sherlock"
q = "Watson"
for i in range(t):
n = int(raw_input())
count = 1
count = bin(n).count('1')
if count%2==0:
print(q)
j=r
r=q
q=j
else:
print(r)
``` | vfc_40741 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1\n2\n\nSAMPLE",
"output": "Sherlock\nSherlock",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | roys-boolean-function-1 | Solve the following coding problem using the programming language python:
Definition:
Roy's boolean function (RBF) is True, if number of the positive integers less than or equal to N that are relatively prime to N, is prime; else False.
In other words, let Z be the number of integers K in the range 1 ≤ K ≤ N for which... | ```python
import math
T=int(raw_input())
def prime(num):
if num==1:return 0
s=int(round(math.sqrt(num)))+1
for i in range(2,s):
if num%i==0:
return False
return True
def gcd(p,q):
while(q!=0):
temp=q
q=p%q
p=temp
return p
for t in range(T):
m=1
N=int(raw_input())
for j in range(2,N):
if gcd(N,... | vfc_40745 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n10\n7\n9\n5\n3\n8\n1\n6\n2\n4",
"output": "FALSE\nFALSE\nFALSE\nFALSE\nTRUE\nFALSE\nFALSE\nTRUE\nFALSE\nTRUE\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n3\n846\n2\n305\n416\n6\... |
code_contests | verifiable_code | subtraction-game-theory | Solve the following coding problem using the programming language python:
Problem:
You are given n natural numbers a1,a2,a3…… an. Let SOD of a number be defined as the Sum of Digits of that number. Compute the value of
{ [ SOD(a1) + SOD(a2) + …….. SOD(an) ] % 9 } – { [ SOD( a1 + a2 + ….. an ) ] % 9 }
Input:
The fi... | ```python
#a= int(raw_input())
#while a>0:
#a-= 1
#b =(raw_input())
print 0
``` | vfc_40749 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1\n2\n3\n\nSAMPLE",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5066\n6776320\n44\n91507131\n67679\n300\n85\n103702790\n550\n10237169730\n9526527231\n558013\n294966651\... |
code_contests | verifiable_code | virat-rohits-sorting | Solve the following coding problem using the programming language python:
With the T20 world cup going on, a list of batsmen was prepared with their country code and their T20I career runs.
The list contains data of N batsmen (country-code and runs).
Number of countries may range from 1 to N and each country has i... | ```python
playerCount = int(raw_input())
def outlist(data):
runMap = {}
for entry in data:
cCode, run = int(entry[0]), int(entry[1])
if(runMap.has_key(cCode) == False):
runMap[cCode] = [run]
else:
runMap[cCode].append(run)
sortedCCode = sorted(runMap.keys())
for cCode in sortedCCode:
runList = ... | vfc_40753 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n4 12\n2 1\n3 10\n2 7\n2 5\n\nSAMPLE",
"output": "2 7\n2 5\n2 1\n3 10\n4 12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10000\n72 97\n197 114\n106 84\n31 252\n143 120\n87 230\n231 13... |
code_contests | verifiable_code | p00034 Railway Lines | Solve the following coding problem using the programming language python:
There is a double-track line (up and down are separate lines and pass each other everywhere). There are 11 stations on this line, including the terminal station, and each station is called by the section number shown in the figure.
<image>
Tr... | ```python
while True:
try:
lst = list(map(int, input().split(',')))
v2 = lst.pop()
v1 = lst.pop()
kp = sum(lst)*v1/(v1+v2)
l = 0
for num, i in enumerate(lst):
l = l + i
if l >= kp:
print(num + 1)
break
excep... | vfc_40797 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1,1,1,1,1,1,1,1,1,1,40,60\n1,1,1,1,1,3,3,3,3,3,50,50\n10,10,10,10,10,10,10,10,10,10,50,49",
"output": "4\n7\n6",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "06,04,1,1,1,1,1,1,1,1,1,1\n1,1,... |
code_contests | verifiable_code | p00166 Area of Polygon | Solve the following coding problem using the programming language python:
Create a program that inputs the vertex information of two polygons inscribed in one circle and outputs the magnitude relationship of their areas.
Assume that each vertex of the X-side is numbered counterclockwise from 1 to X (the figure shows ... | ```python
# AOJ 0166: Area of Polygon
# Python3 2018.6.18 bal4u
import math
M = 0.00872664625997164788461845384244
EPS = 1e-8
a = [0]*2
s = [0.0]*2
while True:
eof = False
for i in range(2):
s[i] = a[i] = 0;
n = int(input())
if n == 0:
eof = True
break
for j in range(1, n):
v = int(input())
a[i]... | vfc_40801 | {
"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\n30\n125\n75\n4\n30\n125\n75\n5\n30\n125\n75\n65\n4\n30\n125\n75\n4\n30\n125\n75\n6\n30\n50\n50\n25\n75\n0",
"output": "0\n1\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n30\n125\n... |
code_contests | verifiable_code | p00678 KND Runs for Sweets | Solve the following coding problem using the programming language python:
Problem
KND is a student programmer at the University of Aizu. He is known to be a sweet tooth. He will be staying in a city for a year and wants to visit all N sweets shops in the city during that time. So I think the best place to live for th... | ```python
from math import sqrt
while True:
n = int(raw_input())
if n == 0:
break
x = [0 for i in range(n)]
y = [0 for i in range(n)]
v = [0 for i in range(n)]
for i in range(n):
(x[i], y[i], v[i]) = map(int, raw_input().split())
... | vfc_40813 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 1 1\n2 2 1\n4\n1 1 3\n3 1 3\n4 2 1\n1 5 3\n0",
"output": "0.70710678\n1.06066017",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 1 1\n2 2 1\n4\n1 1 3\n3 1 3\n6 2 1\n1 5 3\n0",
... |
code_contests | verifiable_code | p00821 Area of Polygons | Solve the following coding problem using the programming language python:
Yoko’s math homework today was to calculate areas of polygons in the xy-plane. Vertices are all aligned to grid points (i.e. they have integer coordinates).
Your job is to help Yoko, not good either at math or at computer programming, get her h... | ```python
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N = int(readline())
if N == 0:
return False
P = [list(map(int, readline().split())) for i in range(N)]
L = 2000
Q = [[] for i in range(2*L+1)]
LS = []
for i in range(N):
x0, y0 = P[i-1];... | vfc_40817 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n5 -3\n1 0\n1 7\n-7 -1\n3\n5 5\n18 5\n5 10\n3\n-5 -5\n-5 -10\n-18 -10\n5\n0 0\n20 2\n11 1\n21 2\n2 0\n0",
"output": "55\n41\n41\n23",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n5 -3\... |
code_contests | verifiable_code | p00952 Placing Medals on a Binary Tree | Solve the following coding problem using the programming language python:
Example
Input
6
2
3
1
1
4
2
Output
Yes
Yes
Yes
No
Yes
No
The input will be given via stdin and the output should be printed to stdout by your code.
Now solve the problem by providing the code. | ```python
n = int(input())
bits = set()
c1 = 0
count = 0
ans = []
for i in range(n):
x = int(input())
if x in bits:
y = x
while c1 < y and y in bits:
y -= 1
if y <= c1:
y = 0
if y == 0 and count != x:
c1 = max(x, c1)
ans.append("No"... | vfc_40821 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n2\n3\n1\n1\n4\n2",
"output": "Yes\nYes\nYes\nNo\nYes\nNo",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n2\n3\n1\n1\n4\n1",
"output": "Yes\nYes\nYes\nNo\nYes\nNo\n",
"type"... |
code_contests | verifiable_code | p01085 Entrance Examination | Solve the following coding problem using the programming language python:
Entrance Examination
The International Competitive Programming College (ICPC) is famous for its research on competitive programming. Applicants to the college are required to take its entrance examination.
The successful applicants of the exam... | ```python
da = list(map(int,input().split()))
k = []
while sum(da) != 0:
for i in range(da[0]):
k.append(int(input()))
for i in range(da[0]):
k[da[0] - 1 -i] = k[da[0] - 1 -i] - k[da[0]-2 -i]
pp = k[da[1]:da[2]+1]
qq = min(pp)
for i in range(len(pp)):
if pp[i] == qq:
jj = i
print(da[1]+jj)
da = lis... | vfc_40825 | {
"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": "5 2 4\n100\n90\n82\n70\n65\n5 2 4\n100\n90\n80\n75\n65\n3 1 2\n5000\n4000\n3000\n4 2 3\n10000\n10000\n8000\n8000\n4 2 3\n10000\n10000\n10000\n8000\n5 2 3\n100\n80\n68\n60\n45\n0 0 0",
"output": "3\n4\n2\n2\n3\n2",
"type... |
code_contests | verifiable_code | p01221 Two-finger Programming | Solve the following coding problem using the programming language python:
Franklin Jenkins is a programmer, but he isn’t good at typing keyboards. So he always uses only ‘f’ and ‘j’ (keys on the home positions of index fingers) for variable names. He insists two characters are enough to write programs, but naturally h... | vfc_40829 | {
"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": "14\nVAR ga;\nVAR gb;\nIF(ga > gb) {\nVAR saa;\nVAR sab;\nIF(saa > ga) {\nsaa = sab;\n}\n}\nWHILE(gb > ga) {\nVAR sba;\nsba = ga;\nga = gb;\n}\n7\nVAR thisisthelongest;\nIF(thisisthelongest / 0) {\nVARone;\none = thisisthelongest + ... | |
code_contests | verifiable_code | p01355 Nurie | Solve the following coding problem using the programming language python:
N circles are drawn on the paper. The rabbit has k-colored paint and paints the paper according to the following rules.
* Paint each area with one color of paint or nothing. Here, the "area" refers to the part with a finite area surrounded by a... | vfc_40833 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1\n10 0 10\n20 0 10",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n10 1 10\n20 0 10",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name":... | |
code_contests | verifiable_code | p01537 Code Art Online | Solve the following coding problem using the programming language python:
G: Code Art Online
Code Art Online (CAO) is an online RPG that advances adventures by solving various problems by programming. Since CAO was the world's first game that realized a virtual reality space, it was sold out while it was very popular... | vfc_40837 | {
"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": "3 3\n25 100 10\n8\n-10 0\n-2 2\n0 10\n2 2\n10 0\n2 -2\n0 -10\n-2 -2\n4\n30 0\n50 0\n50 40\n30 40\n3\n30 -10\n45 -70\n60 -10",
"output": "3\n1\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... | |
code_contests | verifiable_code | p01693 Derangement | Solve the following coding problem using the programming language python:
G --Derangement / Derangement
Story
Person D is doing research on permutations. At one point, D found a permutation class called "Derangement". "It's cool to have a perfect permutation !!! And it starts with D !!!", the person of D who had a c... | ```python
# -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i ... | vfc_40841 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3 5 4",
"output": "7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n2 1 3 5 4",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p01837 Longest Shortest Path | Solve the following coding problem using the programming language python:
Example
Input
3 2 3 1 3
1 2 2 1
2 3 1 2
Output
6.0000000
The input will be given via stdin and the output should be printed to stdout by your code.
Now solve the problem by providing the code. | vfc_40845 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 10, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2 3 1 3\n1 2 2 1\n2 3 1 2",
"output": "6.0000000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2 3 1 3\n1 2 4 1\n2 3 1 2",
"output": "8.000000000000\n",
"type": "stdin_stdo... | |
code_contests | verifiable_code | p01973 Censored String | Solve the following coding problem using the programming language python:
G: 検閲により置換 (Censored String)
Problem Statement
You are given the string S, and the set of strings \mathcal P whose size is N. Now we consider applying the following operation to S:
* Choose exactly one character in S, and replace it with '*'.... | vfc_40849 | {
"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": "brainfuck\n1\nfuck",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "brainfuck\n0\nfuck",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... | |
code_contests | verifiable_code | p02259 Bubble Sort | Solve the following coding problem using the programming language python:
Write a program of the Bubble Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:
BubbleSort(A)
1 for i = 0 to A.length-1
2 for j = A.length-1 downto i+1
3 if A[j] ... | ```python
n = int(input())
a = list(map(int,input().split()))
flag = 1
count = 0
while flag:
flag = 0
for i in range(n-1):
if a[i] > a[i+1]:
a[i], a[i+1] = a[i+1], a[i]
count += 1
flag = 1
print(" ".join(map(str,a)))
print(count)
``` | vfc_40857 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n5 3 2 4 1",
"output": "1 2 3 4 5\n8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n5 2 4 6 1 3",
"output": "1 2 3 4 5 6\n9",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | alpha | Solve the following coding problem using the programming language python:
Tanish loves alphabets. He loves alphabets so much that he ignores all other characters.
Also, whenever he is given an alphabet he gives the next alphabet in alphabetical order in same case.
For example, for a-b,for d-e,for z-a.
Given a string g... | ```python
#V 1.01. Forgot to account for uppercase alphabets earlier -_-
T = (int)(raw_input())
while T:
res = ""
s = raw_input()
for i in range(0, len(s)):
if s[i].isalpha():
if ord(s[i])+1==123:
res = res + 'a'
elif ord(s[i])+1==91:
res = res + 'A'
else:
res=res+(ch... | vfc_40865 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nnun123\n1234\nretA34\n^ 56az",
"output": "ovo\n\nsfuB\nba",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | cheftma | Solve the following coding problem using the programming language python:
Chef spent N days working really hard! He planned loads of tasks: as many as Ai tasks to do on the ith day! Chef's work was brutal, so he only managed to finish Bi tasks on the ith day.
The good news is that Chef has a Time Machine!
The Time Ma... | ```python
for t in xrange(int(raw_input())):
n, k, m = map(int,raw_input().split())
a = map(int,raw_input().split())
b = map(int,raw_input().split())
y = sorted(map(int,(raw_input()+" "+raw_input()).split()), reverse = True)
x = []
for i in xrange(n):
x.append(a[i]-b[i])
x = sorted(x, reverse = True)
left = s... | vfc_40869 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n4 2 2 \n5 7 6 1\n3 3 1 1\n6 3\n1 4",
"output": "3",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | ds7 | Solve the following coding problem using the programming language python:
Problem
Michal Scofield and Lincon burrow are two brothers. By a murder allegation Lincon Burrow was sentenced to jail. Michal Scofield some how came to know that his brother is not guilty and he don’t have time to file case against the alle... | ```python
import sys;
def main():
tc=int(raw_input());
for x in range(tc):
noc=int(raw_input());
stinp=str(raw_input());
newst=str();
nor=len(stinp) / noc;
for y in range(nor):
if y%2!=0:
for c in range(noc-1,-1,-1):
ind=y*noc+c;
char=stinp[ind];
newst=newst+char;
else:
for c i... | vfc_40873 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5\ntoioynnkpheleaigshareconhtomesnlewx\n3\nttyohhieneesiaabss",
"output": "theresnoplacelikehomeonasnowynightx\nthisistheeasyoneab",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | ketswap | Solve the following coding problem using the programming language python:
You need to shuffle a series of numbers from 1 To T, inclusive. The numbers are in ascending order, you have to shuffle them using bubble sort algorithm, that is swap every time a number is greater than another in the given list in the input. A ... | ```python
for _ in range(input()):
n=input()
a=map(int,raw_input().split())
c=0
for i in range(n):
for j in range(n-i-1):
if a[j]>a[j+1]:
a[j],a[j+1]=a[j+1],a[j]
#print a[j],a[j+1]
c+=1
#print c
print c
``` | vfc_40877 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3\n2 1 3\nabac",
"output": "1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | odddiv | Solve the following coding problem using the programming language python:
Little Egor likes to play with positive integers and their divisors. Bigger the number to play with, more the fun! The boy asked you to come up with an algorithm, that could play the following game:
Let's define f(n) as the sum of all odd divis... | ```python
cases = int(raw_input())
while(cases):
l,r = map(int,raw_input().split())
ans = 0
j = 1
while(j <= r):
#print j
ans += ((r/j)-((l)/j))*j
if(l%j==0):
ans+=j
j+=2
print ans
cases-=1
``` | vfc_40881 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 10\n42 42",
"output": "45\n32\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 7\n42 42",
"output": "25\n32\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | snape | Solve the following coding problem using the programming language python:
Professor Snape has lots of potions. Bottles containing all types of potions are stacked on shelves which cover the entire wall from floor to ceiling. Professor Snape has broken his bones several times while climbing the top shelf for retrieving... | ```python
for i in range(int(raw_input())):
a=map(int,raw_input().split())
print '%g' %(a[1]*a[1]-a[0]*a[0])**0.5,
print '%g' %(a[1]*a[1]+a[0]*a[0])**0.5
``` | vfc_40885 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4 5\n10 12\n10 20",
"output": "3.0 6.40312\n6.63325 15.6205\n17.3205 22.3607",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n4 5\n10 12\n0 20",
"output": "3 6.40312\n6.63325 15.6... |
code_contests | verifiable_code | 1005_B. Delete from the Left | Solve the following coding problem using the programming language python:
You are given two strings s and t. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by 1. You can't choose a string if it is empty.
For ... | ```python
a = str(input())
b = str(input())
a = a[::-1]
b = b[::-1]
na = len(a)
nb = len(b)
d = abs(na-nb)
l = min(na,nb)
k = 0
for i in range(0,l):
if a[i] != b[i]:
k = (l - i)*2
break
print(d+k)
``` | vfc_40889 | {
"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": "b\nab\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "codeforces\nyes\n",
"output": "9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | 1028_H. Make Square | Solve the following coding problem using the programming language python:
We call an array b_1, b_2, …, b_m good, if there exist two indices i < j such that b_i ⋅ b_j is a [perfect square](https://en.wikipedia.org/wiki/Square_number).
Given an array b_1, b_2, …, b_m, in one action you can perform one of the following... | vfc_40893 | {
"difficulty": "14",
"memory_limit": null,
"memory_limit_bytes": 1024000000,
"problem_url": null,
"time_limit": "{'seconds': 7, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 10\n34 37 28 16 44 36 43 50 22 13\n1 3\n4 8\n6 10\n9 10\n3 10\n8 9\n5 6\n1 4\n1 7\n2 6\n",
"output": "2\n0\n1\n3\n0\n1\n1\n1\n0\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 5\n... | |
code_contests | verifiable_code | 1047_D. Little C Loves 3 II | Solve the following coding problem using the programming language python:
Little C loves number «3» very much. He loves all things about it.
Now he is playing a game on a chessboard of size n × m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places... | ```python
n, m = map(int, input().split())
if n > m:
n, m = m, n
if n == 1:
ans = (m//6)*6+2*max(m%6-3, 0)
print(ans)
elif n == 2:
if m == 2:
print(0)
elif m == 3:
print(4)
elif m == 7:
print(12)
else:
print(n*m)
else:
ans = ((n*m)//2)*2
print(ans)... | vfc_40897 | {
"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 3\n",
"output": "8\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1093_B. Letters Rearranging | Solve the following coding problem using the programming language python:
You are given a string s consisting only of lowercase Latin letters.
You can rearrange all letters of this string as you wish. Your task is to obtain a good string by rearranging the letters of the given string or report that it is impossible t... | ```python
def good_string(string):
if string[::-1] != string:
return string
else:
string = string[-1] + string[:-1]
try:
return good_string(string)
except:
return -1
if __name__ == "__main__":
queries = int(input())
for _ in range(queries):
string = input()
print(good_string(string))
``` | vfc_40905 | {
"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\naa\nabacaba\nxdd\n",
"output": "-1\naaaabbc\nddx\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1113_B. Sasha and Magnetic Machines | Solve the following coding problem using the programming language python:
One day Sasha visited the farmer 2D and his famous magnetic farm. On this farm, the crop grows due to the influence of a special magnetic field. Maintaining of the magnetic field is provided by n machines, and the power of the i-th machine is a_... | ```python
"""""""""""""""""""""""""""""""""""""""""""""
| author: mr.math - Hakimov Rahimjon |
| e-mail: mr.math0777@gmail.com |
"""""""""""""""""""""""""""""""""""""""""""""
#inp = open("spaceship.in", "r"); input = inp.readline; out = open("spaceship.out", "w"); print = out.write
TN = 1
# =======... | vfc_40909 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 4 2 3 7\n",
"output": "18",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1141_E. Superhero Battle | Solve the following coding problem using the programming language python:
A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly n minutes. After a round ends, the next round starts immediately. This is repeated over and over again.
Each round has the same scenario. It is descri... | ```python
INF = 10 ** 13
h, n = map(int, input().split())
a = list(map(int, input().split()))
b = a[:]
for i in range(1, n):
b[i] += b[i - 1]
low = min(b)
tot = b[-1]
if h + low <= 0:
lo = 0
else:
lo, hi = 0, INF
while lo < hi:
mid = (lo + hi) // 2
cur = h + mid * tot + low
if ... | vfc_40913 | {
"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": "1000 6\n-100 -200 -300 125 77 -4\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 4\n-3 -6 5 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 115_D. Unambiguous Arithmetic Expression | Solve the following coding problem using the programming language python:
Let's define an unambiguous arithmetic expression (UAE) as follows.
* All non-negative integers are UAE's. Integers may have leading zeroes (for example, 0000 and 0010 are considered valid integers).
* If X and Y are two UAE's, then "(X) ... | vfc_40917 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1+2*3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1\n",
"output": "100728\n",
"type": "stdin_stdout"
},
{
... | |
code_contests | verifiable_code | 11_D. A Simple Task | Solve the following coding problem using the programming language python:
Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycle with no repeated vertices or edges.
Input
The first line of input contains two integers n and m (1 ≤ n ≤ 19, 0 ≤ m) – respectively the number of vertices... | vfc_40925 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 3\n4 8\n9 4\n8 9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
... | |
code_contests | verifiable_code | 1218_A. BubbleReactor | Solve the following coding problem using the programming language python:
You are in charge of the BubbleReactor. It consists of N BubbleCores connected with N lines of electrical wiring. Each electrical wiring connects two distinct BubbleCores. There are no BubbleCores connected with more than one line of electrical ... | vfc_40929 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n0 1\n0 3\n0 4\n0 9\n1 2\n2 3\n2 7\n4 5\n4 6\n7 8\n",
"output": "51",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n1 2\n3 2\n2 4\n4 5\n5 6\n6 2\n5 7\n5 0",
"output": "30",
... | |
code_contests | verifiable_code | 1240_D. Stack Exterminable Arrays | Solve the following coding problem using the programming language python:
Let's look at the following process: initially you have an empty stack and an array s of the length l. You are trying to push array elements to the stack in the order s_1, s_2, s_3, ... s_{l}. Moreover, if the stack is empty or the element at th... | vfc_40933 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5\n2 1 1 2 2\n6\n1 2 1 1 3 2\n9\n3 1 2 2 1 6 6 3 3\n",
"output": "4\n1\n8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n5\n2 1 1 2 4\n6\n1 2 1 1 3 2\n9\n3 1 2 2 1 6 6 3 3\n",
... | |
code_contests | verifiable_code | 1260_E. Tournament | Solve the following coding problem using the programming language python:
You are organizing a boxing tournament, where n boxers will participate (n is a power of 2), and your friend is one of them. All boxers have different strength from 1 to n, and boxer i wins in the match against boxer j if and only if i is strong... | ```python
import sys
from array import array # noqa: F401
import typing as Tp # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
def main():
from itertools import accumulate
n = int(input())
log = len(bin(n)) - 3
cnt = list(accumulate([0] + [n >> i for i in range(1, l... | vfc_40937 | {
"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\n11 -1 13 19 24 7 17 5\n",
"output": "12",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n3 9 1 -1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | 1282_E. The Cake Is a Lie | Solve the following coding problem using the programming language python:
We are committed to the well being of all participants. Therefore, instead of the problem, we suggest you enjoy a piece of cake.
Uh oh. Somebody cut the cake. We told them to wait for you, but they did it anyway. There is still some left, thoug... | ```python
def get_edge(vertex1, vertex2):
return (vertex1, vertex2) if vertex1 < vertex2 else (vertex2, vertex1)
def swap(arr, i, j):
temp = arr[i]
arr[i] = arr[j]
arr[j] = temp
if __name__ == '__main__':
T = int(input())
for t in range(T):
n = int(input())
pieces = []
... | vfc_40941 | {
"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\n6\n3 6 5\n5 2 4\n5 4 6\n6 3 1\n6\n2 5 6\n2 5 1\n4 1 2\n1 3 5\n3\n1 2 3\n",
"output": "1 3 5 2 4 6 \n4 2 1 3 \n1 3 5 6 2 4 \n4 3 2 1 \n1 2 3 \n1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"i... |
code_contests | verifiable_code | 1302_F. Keep talking and nobody explodes – easy | Solve the following coding problem using the programming language python:
This is an unusual problem in an unusual contest, here is the announcement: [http://codeforces.com/blog/entry/73543](//codeforces.com/blog/entry/73543)
You have the safe lock which consists of 5 decimal digits. If you rotate some digit, it incr... | vfc_40945 | {
"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": "00000\n",
"output": "\n61376\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12345\n",
"output": "\n07769\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1326_E. Bombs | Solve the following coding problem using the programming language python:
You are given a permutation, p_1, p_2, …, p_n.
Imagine that some positions of the permutation contain bombs, such that there exists at least one position without a bomb.
For some fixed configuration of bombs, consider the following process. In... | ```python
import sys
input = sys.stdin.readline
N=int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
seg_el=1<<(N.bit_length()) # Segment treeの台の要素数
SEG=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化
LAZY=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化
def i... | vfc_40949 | {
"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": "6\n2 3 6 1 5 4\n5 2 1 4 6 3\n",
"output": "6 5 5 5 4 1 \n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1345_E. Quantifier Question | Solve the following coding problem using the programming language python:
Logical quantifiers are very useful tools for expressing claims about a set. For this problem, let's focus on the set of real numbers specifically. The set of real numbers includes zero and negatives. There are two kinds of quantifiers: universa... | ```python
import sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input().strip()
return(list(s[:len(s)]))
def invr():
return(map(int,input().split()))
def from_fi... | vfc_40953 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n1 3\n2 3\n",
"output": "2\nAAE\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n1 2\n2 3\n3 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name"... |
code_contests | verifiable_code | 1367_D. Task On The Board | Solve the following coding problem using the programming language python:
Polycarp wrote on the board a string s containing only lowercase Latin letters ('a'-'z'). This string is known for you and given in the input.
After that, he erased some letters from the string s, and he rewrote the remaining letters in any ord... | ```python
t=int(input())
for i in range(t):
s=input()
b=[]
d=dict()
for j in s:
if j in d.keys():
d[j]+=1
else:
b.append(j)
d[j]=1
b.sort(reverse=True)
n=int(input())
a=list(map(int,input().split()))
c=["a"]*(n)
m=1
f=dict()
... | vfc_40957 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nabac\n3\n2 1 0\nabc\n1\n0\nabba\n3\n1 0 1\necoosdcefr\n10\n38 13 24 14 11 5 3 24 17 0\n",
"output": "aac\nc\naba\ncodeforces\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1388_D. Captain Flint and Treasure | Solve the following coding problem using the programming language python:
Captain Fint is involved in another treasure hunt, but have found only one strange problem. The problem may be connected to the treasure's location or may not. That's why captain Flint decided to leave the solving the problem to his crew and off... | ```python
from sys import stdin
from collections import deque
n = int(stdin.readline())
a = list(map(int,stdin.readline().split()))
p = list(map(int,stdin.readline().split()))
chnum = [0] * n
for i in range(n):
if p[i]-1 >= 0:
chnum[p[i]-1] += 1
q = deque([])
for i in range(n):
if chnum[i] == 0:
... | vfc_40961 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 3\n2 3 -1\n",
"output": "10\n1 2 3 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n-10 -1 2 2 5 -2 -3 -4 2 -6\n-1 -1 2 2 -1 5 5 7 7 9\n",
"output": "-9\n3 4 2 9 5 7 10 8 ... |
code_contests | verifiable_code | 1409_B. Minimum Product | Solve the following coding problem using the programming language python:
You are given four integers a, b, x and y. Initially, a ≥ x and b ≥ y. You can do the following operation no more than n times:
* Choose either a or b and decrease it by one. However, as a result of this operation, value of a cannot become le... | ```python
for _ in range(int(input())):
a,b,x,y,n=map(int,input().split())
if n>=((a-x)+(b-y)):
print(x*y)
else:
if a>=b and n<=(b-y):
print(a*(b-n))
elif b>a and n<=(a-x):
print((a-n)*b)
elif n<=(a-x) and n<=(b-y):
print(min((a-n)*b,a*(b-n)))
else:
if n>(a-x)... | vfc_40965 | {
"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\n10 10 8 5 3\n12 8 8 7 2\n12343 43 4543 39 123212\n1000000000 1000000000 1 1 1\n1000000000 1000000000 1 1 1000000000\n10 11 2 1 5\n10 11 9 1 10\n",
"output": "70\n77\n177177\n999999999000000000\n999999999\n55\n10\n",
... |
code_contests | verifiable_code | 142_E. Help Greg the Dwarf 2 | Solve the following coding problem using the programming language python:
Greg the Dwarf has been really busy recently with excavations by the Neverland Mountain. However for the well-known reasons (as you probably remember he is a very unusual dwarf and he cannot stand sunlight) Greg can only excavate at night. And i... | ```python
import math
mas = list(map(int, input().split()))
r = mas[0]
h = mas[1]
l = (r ** 2 + h ** 2) ** 0.5#2 * math.pi * r
mas = list(map(float, input().split()))
x1 = mas[0]
y1 = mas[1]
z1 = mas[2]
mas = list(map(float, input().split()))
x2 = mas[0]
y2 = mas[1]
z2 = mas[2]
s = 0
if ((z1 == 0) and (z2 == 0)):
s... | vfc_40969 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n1.0 0.0 0.0\n1.0 0.0 1.0\n",
"output": "2.4142135624\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1453_B. Suffix Operations | Solve the following coding problem using the programming language python:
Gildong has an interesting machine that has an array a with n integers. The machine supports two kinds of operations:
1. Increase all elements of a suffix of the array by 1.
2. Decrease all elements of a suffix of the array by 1.
A suf... | ```python
T = int(input())
for _ in range(T):
N = int(input())
A = list(map(int,input().split()))
d = sum(abs(a-b) for a,b in zip(A,A[1:]))
ans = d
for a,b,c in zip(A,A[1:],A[2:]):
p = abs(a-b) + abs(b-c)
q = abs(a-c)
ans = min(ans, d - (p-q))
ans = min(ans, d - abs(A[0] ... | vfc_40973 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n2\n1 1\n3\n-1 0 2\n4\n99 96 97 95\n4\n-3 -5 -2 1\n6\n1 4 3 2 4 1\n5\n5 0 0 0 5\n9\n-367741579 319422997 -415264583 -125558838 -300860379 420848004 294512916 -383235489 425814447\n",
"output": "\n0\n1\n3\n4\n6\n5\n284737210... |
code_contests | verifiable_code | 1503_D. Flip the Cards | Solve the following coding problem using the programming language python:
There is a deck of n cards. The i-th card has a number a_i on the front and a number b_i on the back. Every integer between 1 and 2n appears exactly once on the cards.
A deck is called sorted if the front values are in increasing order and the ... | ```python
import sys
input = sys.stdin.readline
n = int(input())
front = [-1] * n
back = [-1] * n
rev = [-1] * (2 * n)
used = [False] * n
opp = [-1] * (2 * n)
for c in range(n):
a, b = map(lambda x: int(x) - 1, input().split())
front[c] = a
back[c] = b
rev[a] = c
rev[b] = c
opp[a] = b
opp... | vfc_40981 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 2\n3 4\n",
"output": "\n-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2\n3 6\n4 5\n",
"output": "\n-1\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... |
code_contests | verifiable_code | 159_A. Friends or Not | Solve the following coding problem using the programming language python:
Polycarpus has a hobby — he develops an unusual social network. His work is almost completed, and there is only one more module to implement — the module which determines friends. Oh yes, in this social network one won't have to add friends manu... | ```python
import re
from collections import Counter
class Task:
data = []
delta = 0
friends = set()
def getData(self):
n, self.delta = [int(x) for x in input().split(" ")]
for i in range(0, n):
self.data += [input()]
def solve(self):
messages = dict()
... | vfc_40989 | {
"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": "1 1000\na b 0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 1\nvasya petya 1\npetya vasya 2\nanya ivan 2\nivan anya 4\n",
"output": "1\npetya vasya\n",
"ty... |
code_contests | verifiable_code | 200_D. Programming Language | Solve the following coding problem using the programming language python:
Recently, Valery have come across an entirely new programming language. Most of all the language attracted him with template functions and procedures. Let us remind you that templates are tools of a language, designed to encode generic algorithm... | ```python
def main():
from collections import defaultdict
import sys
strings = sys.stdin.read().split('\n')
strings.reverse()
f = defaultdict(lambda: defaultdict(int))
n = int(strings.pop())
for i in range(n):
s = strings.pop().replace('(', ' ').replace(')', ' ').repla... | vfc_40997 | {
"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\nvoid f(string,double,int)\nvoid f(int)\n void f ( T )\nvoid procedure(int,double)\nvoid f (T, double,int) \nvoid f(string, T,T)\n4\n int a\n int x\nstring t\ndouble val \n5\nf(t, a, a)\nf(t,val,a)\nf(val,a, val)\n solv... |
code_contests | verifiable_code | 225_C. Barcode | Solve the following coding problem using the programming language python:
You've got an n × m pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture.
A picture is a barcode if the following conditions are fulfilled:
* All pixels ... | ```python
def main():
n, m, x, y = map(int, input().split())
col = [0] * m
for i in range(n):
row = input()
for j in range(m):
if row[j] == '.':
col[j] += 1
acc = [0]
for j in range(m):
acc.append(acc[-1] + col[j])
dp = [[0]*(m+1), [0]*(m+1)... | vfc_41001 | {
"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 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..\n",
"output": "11",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 24_A. Ring road | Solve the following coding problem using the programming language python:
Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all n cities of Berland were connected by n two-way ... | ```python
n = int(input())
g=[]
d=[]
cost=[]
for i in range(n+1):
g.append([])
d.append([])
for j in range(n+1):
g[i].append(0)
d[i].append(0)
x,y=[],[]
for i in range(n):
a,b,c = tuple([int(x) for x in input().split()])
g[a][b]=c
g[b][a]=c
d[a][b]=c
d[b][a]=-c
ans = 0
tot=0
stack=[1]
visited=[1]
while ... | vfc_41005 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 3 1\n1 2 1\n3 2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 3 1\n1 2 5\n3 2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"f... |
code_contests | verifiable_code | 297_D. Color the Carpet | Solve the following coding problem using the programming language python:
Even polar bears feel cold when lying on the ice. Therefore, a polar bear Alice is going to make a carpet. The carpet can be viewed as a grid with height h and width w. Then the grid is divided into h × w squares. Alice is going to assign one of... | vfc_41013 | {
"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 4 4\nENE\nNNEE\nNEE\nENEN\nENN\n",
"output": "YES\n1 1 2 2\n1 2 2 2\n1 1 2 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 10 2\nEEENEENNN\nEENNNNNNNN\nEEENEENNN\n",
"output": ... | |
code_contests | verifiable_code | 320_B. Ping-Pong (Easy Version) | Solve the following coding problem using the programming language python:
In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval I2 f... | ```python
def main():
intervals = []
visited = []
for _ in range(int(input())):
read_input(intervals, visited)
def read_input(intervals: list, visited: list) -> None:
command, x, y = [int(x) for x in input().split(" ")]
if (command == 1):
intervals.append((x, y))
visited.a... | vfc_41017 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 1 5\n1 5 11\n2 1 2\n1 2 9\n2 1 2\n",
"output": "NO\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n1 1 4\n1 5 20\n1 11 30\n1 29 60\n1 59 100\n1 100 200\n2 1 5\n2 1 6\n2 2 5\n"... |
code_contests | verifiable_code | 345_B. Triskaidekaphobia | Solve the following coding problem using the programming language python:
Triskaidekaphobia is a fear of number 13. Ordinary people who suffer from this phobia feel uncomfortable around numbers 13, 130, 513 etc, but you, being a programmer, take this fear one step further. For example, consider number 7. It's ok when ... | vfc_41021 | {
"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": "7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13\n",
... | |
code_contests | verifiable_code | 368_D. Sereja ans Anagrams | Solve the following coding problem using the programming language python:
Sereja has two sequences a and b and number p. Sequence a consists of n integers a1, a2, ..., an. Similarly, sequence b consists of m integers b1, b2, ..., bm. As usual, Sereja studies the sequences he has. Today he wants to find the number of p... | ```python
from sys import stdin, stdout
from math import log, sqrt
lines = stdin.readlines()
n = int(lines[0].split()[0])
m = int(lines[0].split()[1])
p = int(lines[0].split()[2])
a = [int(x) for x in lines[1].split()]
b = [int(x) for x in lines[2].split()]
hash_map = {}
def hash_elem(elem):
if hash_map.get(el... | vfc_41025 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3 1\n1 2 3 2 1\n1 2 3\n",
"output": "2\n1 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 3 2\n1 3 2 2 3 1\n1 2 3\n",
"output": "2\n1 2 ",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 390_E. Inna and Large Sweet Matrix | Solve the following coding problem using the programming language python:
Inna loves sweets very much. That's why she wants to play the "Sweet Matrix" game with Dima and Sereja. But Sereja is a large person, so the game proved small for him. Sereja suggested playing the "Large Sweet Matrix" game.
The "Large Sweet Mat... | vfc_41029 | {
"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": "4 5 5\n0 1 1 2 3 2\n0 2 2 3 3 3\n0 1 5 4 5 1\n1 2 3 3 4\n1 3 4 3 4\n",
"output": "2\n-21\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4000000 4000000 1\n1 2 2 3999999 3999999\n",
... | |
code_contests | verifiable_code | 43_A. Football | Solve the following coding problem using the programming language python:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole ... | ```python
n=int(input())
a,b=input(),""
x,y=1,0
for i in range(n-1):
s=input()
if a==s:
x+=1
else:
b=s
y+=1
print([b,a][x>y])
``` | vfc_41037 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\nABC\n",
"output": "ABC\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nA\nABA\nABA\nA\nA\n",
"output": "A\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 461_C. Appleman and a Sheet of Paper | Solve the following coding problem using the programming language python:
Appleman has a very big sheet of paper. This sheet has a form of rectangle with dimensions 1 × n. Your task is help Appleman with folding of such a sheet. Actually, you need to perform q queries. Each query will have one of the following types:
... | ```python
from itertools import starmap
def main():
n, q = map(int, input().split())
a = list(range(n + 1))
flipped = False
start = 0
end = n
for _ in range(q):
cmd, *args = map(int, input().split())
if cmd == 1:
p = args[0]
if p > end-start-p:
... | vfc_41041 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 9\n2 2 9\n1 1\n2 0 1\n1 8\n2 0 8\n1 2\n2 1 3\n1 4\n2 2 4\n",
"output": "7\n2\n10\n4\n5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 4\n1 3\n1 2\n2 0 1\n2 1 2\n",
"output": "4... |
code_contests | verifiable_code | 485_B. Valuable Resources | Solve the following coding problem using the programming language python:
Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. The world map uses the Cartesia... | ```python
# This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
mx = -10 ** 10
mix = 10 ** 10
my = mx
miy = mix
for _ in range(int(input())):
a, b = map(int, input().split())... | vfc_41045 | {
"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\n0 0\n2 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n0 0\n0 3\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | 509_B. Painting Pebbles | Solve the following coding problem using the programming language python:
There are n piles of pebbles on the table, the i-th pile contains ai pebbles. Your task is to paint each pebble using one of the k given colors so that for each color c and any two piles i and j the difference between the number of pebbles of co... | ```python
import sys,math,bisect
from random import randint
inf = float('inf')
mod = 998244353
"========================================"
def lcm(a,b):
return int((a/math.gcd(a,b))*b)
def gcd(a,b):
return int(math.gcd(a,b))
def tobinary(n):
return bin(n)[2:]
def binarySearch(a,x):
i = bisect.bisect_left... | vfc_41049 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4\n3 2 4 3 5\n",
"output": "YES\n1 2 3\n1 2\n1 2 3 4\n1 2 3\n1 2 3 4 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n3 2 4 1 3\n",
"output": "NO\n",
"type": "stdin_std... |
code_contests | verifiable_code | 533_D. Landmarks | Solve the following coding problem using the programming language python:
We have an old building with n + 2 columns in a row. These columns support the ceiling. These columns are located in points with coordinates 0 = x0 < x1 < ... < xn < xn + 1. The leftmost and the rightmost columns are special, we will call them b... | vfc_41053 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n0 4 10 28 30\n9 13 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n0 20 40 100\n15 40\n",
"output": "10.0\n",
"type": "stdin_stdout"
},
{
... | |
code_contests | verifiable_code | 584_A. Olesya and Rodion | Solve the following coding problem using the programming language python:
Olesya loves numbers consisting of n digits, and Rodion only likes numbers that are divisible by t. Find some number that satisfies both of them.
Your task is: given the n and t print an integer strictly larger than zero consisting of n digits ... | ```python
n, t = input().split(' ')
n = int(n)
t = int(t)
a = 10 ** (n-1)
b = 10 ** (n)
for i in range(a, b):
if i == b-1:
if i%t ==0:
print(i)
break
else:
print(-1)
break
else:
if i%t == 0:
print(i)
break
i... | vfc_41061 | {
"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 2\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 8\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "98 4... |
code_contests | verifiable_code | 606_A. Magic Spheres | Solve the following coding problem using the programming language python:
Carl is a beginner magician. He has a blue, b violet and c orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least x ... | ```python
have = list(map(int, input().split()))
goal = list(map(int, input().split()))
deficit = 0
makeable = 0
for i in range(3):
if have[i] < goal[i]:
deficit += goal[i] - have[i]
else:
makeable += (have[i] - goal[i]) // 2
print('Yes' if makeable >= deficit else 'No')
``` | vfc_41065 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3 3\n2 2 2\n",
"output": "Yes\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 628_A. Tennis Tournament | Solve the following coding problem using the programming language python:
A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, m is the number of the participants o... | ```python
n, b, p = map(int, input().split())
ansb = 0
anst = n*p
while n > 1:
x = n//2
y = n % 2
n -= x
ansb += b*x*2 + x
print(ansb, anst)
``` | vfc_41069 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2 3\n",
"output": "20 15\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 652_B. z-sort | Solve the following coding problem using the programming language python:
A student of z-school found a kind of sorting called z-sort. The array a with n elements are z-sorted if two conditions hold:
1. ai ≥ ai - 1 for all even i,
2. ai ≤ ai - 1 for all odd i > 1.
For example the arrays [1,2,1,2] and [1,1,1,... | ```python
n = int(input())
a = [int(x) for x in input().split(" ")]
a.sort()
for i in range(n):
if i%2 == 0:
firval = a[i]
secval = a[i-1]
if i == 0:
continue
elif firval > secval:
a[i],a[i-1] = a[i-1],a[i]
elif secval >= firval:
continue
... | vfc_41073 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 3 2 2 5\n",
"output": "1 5 2 3 2 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 2 2 1\n",
"output": "1 2 1 2 ",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | 677_E. Vanya and Balloons | Solve the following coding problem using the programming language python:
Vanya plays a game of balloons on the field of size n × n, where each cell contains a balloon with one of the values 0, 1, 2 or 3. The goal is to destroy a cross, such that the product of all values of balloons in the cross is maximum possible. ... | vfc_41077 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n00300\n00300\n33333\n00300\n00300\n",
"output": "19683\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n21312\n10003\n10002\n10003\n23231\n",
"output": "3\n",
"type": "std... | |
code_contests | verifiable_code | 6_E. Exposition | Solve the following coding problem using the programming language python:
There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it... | ```python
from collections import deque
def mini_in_window(A, n, k):
d = deque()
res = []
for i in range(n):
if i >= k and d[0] == i - k:
d.popleft()
while len(d) and A[d[-1]] >= A[i]:
d.pop()
d.append(i)
if i >= k - 1:
res.append(d[0])
... | vfc_41081 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n14 12 10\n",
"output": "2 2\n1 2\n2 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5\n8 19 10 13\n",
"output": "2 1\n3 4\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 722_B. Verse Pattern | Solve the following coding problem using the programming language python:
You are given a text consisting of n lines. Each line contains some space-separated words, consisting of lowercase English letters.
We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of con... | ```python
n = int(input())
p = input().split()
r = 'YES'
for i in range(n):
s = input()
if(r!='NO' and s.count('a')+s.count('e')+s.count('i')+s.count('o')+s.count('u')+s.count('y')!=int(p[i])):
r = 'NO'
print(r)
``` | vfc_41085 | {
"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\n2 2 3\nintel\ncode\nch allenge\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz\n",
"output": "NO\n",
"type": ... |
code_contests | verifiable_code | 767_B. The Queue | Solve the following coding problem using the programming language python:
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it ... | ```python
##n = int(input())
##a = list(map(int, input().split()))
##print(' '.join(map(str, res)))
[ts , tf, t] = list(map(int, input().split()))
n = int(input())
if n == 0:
print(ts)
exit(0)
a = list(map(int, input().split()))
if a[0] > ts:
print(ts)
exit(0)
min_wait = 1e18
tbest = a[0]-1
tnow = t... | vfc_41093 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 15 2\n2\n10 13\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 17 3\n4\n3 4 5 8\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 791_A. Bear and Big Brother | Solve the following coding problem using the programming language python:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Lima... | ```python
def banyak_tahun(a,b, count):
c = a*3
d = b*2
if c <= d:
banyak_tahun(c,d, count+1)
else:
print(count)
a, b = list(map(int, input().split()))
banyak_tahun(a,b,1)
``` | vfc_41097 | {
"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 9\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 7\n",... |
code_contests | verifiable_code | 811_C. Vladik and Memorable Trip | Solve the following coding problem using the programming language python:
Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you about one of these trips:
Vladik is at initial train station, and now n people (including Vladik) want to get on the train. They are al... | ```python
"""
from
http://codeforces.com/contest/811/problem/C
"""
length = int(input())
array = [0] + [int(x) for x in input().split()]
dp = [0]*(length+1)
end = [0]*5001
start = [5001]*5001
vis = [0]*5001
for i in range(1,length+1):
start[array[i]] = min(start[array[i]],i)
end[array[i]] = max(end[array[i]],i... | vfc_41101 | {
"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": "9\n5 1 3 1 5 2 4 2 5\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n4 4 2 5 2 3\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"fn_name": ... |
code_contests | verifiable_code | 858_A. k-rounding | Solve the following coding problem using the programming language python:
For a given positive integer n denote its k-rounding as the minimum positive integer x, such that x ends with k or more zeros in base 10 and is divisible by n.
For example, 4-rounding of 375 is 375·80 = 30000. 30000 is the minimum integer such ... | ```python
def nok(a, b):
c = a*b
while (a!=0) and (b!=0):
if a>b: a%=b;
else: b%=a;
return c//(a+b);
nk = input().split()
n, k = int(nk[0]), int(nk[1])
print (nok(10**k, n))
``` | vfc_41109 | {
"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": "10000 1\n",
"output": "10000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "375 4\n",
"output": "30000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | 883_G. Orientation of Edges | Solve the following coding problem using the programming language python:
Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices.
Vasya has picked a vertex s from the graph. Now Vasya wants to create two separate plans:
1. t... | ```python
from collections import defaultdict
import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
... | vfc_41113 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2 1\n1 1 2\n2 2 1\n",
"output": "2\n-\n2\n+\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 6 3\n2 2 6\n1 4 5\n2 3 4\n1 4 1\n1 3 1\n2 2 3\n",
"output": "6\n++-\n2\n+-+\n",
... |
code_contests | verifiable_code | 907_B. Tic-Tac-Toe | Solve the following coding problem using the programming language python:
Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules.
The game is played on the following field.
<image>
Players are making mo... | ```python
import sys
#f = open('input', 'r')
f = sys.stdin
m = []
for t in range(3):
ml = [[] for _ in range(3)]
for _ in range(3):
map_line = f.readline().split()
for i, x in enumerate(map_line):
ml[i].append(list(x))
m.append(ml)
if t < 2:
f.readline()
x,y = map(int, f.readline().split())
... | vfc_41117 | {
"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": "xoo x.. x..\nooo ... ...\nooo ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n7 4\n",
"output": "xoo x!! x!! \nooo !!! !!! \nooo !!! !!! \n\nx!! x!! x!! \n!!! !!! !!! \n!!! !!! !!! \... |
code_contests | verifiable_code | 926_I. A Vital Problem | Solve the following coding problem using the programming language python:
Polycarp has a strict daily schedule. He has n alarms set for each day, and the i-th alarm rings each day at the same time during exactly one minute.
Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that perio... | ```python
n = int(input())
a = []
for i in range(n):
str = input()
h = int(str[0:2]) * 60
m = int(str[3:5])
a.append(h + m)
a.sort()
mx = 0
for i in range(n - 1):
if mx < ((-a[i] + a[i + 1]) - 1):
mx = ((-a[i] + a[i + 1]) - 1)
if mx < (1440 + a[0] - a[n - 1] - 1):
mx = 1440 + a[0] - ... | vfc_41121 | {
"difficulty": "15",
"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\n22:00\n03:21\n16:03\n09:59\n",
"output": "06:37\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n05:43\n",
"output": "23:59\n",
"type": "stdin_stdout"
},
{
"... |
code_contests | verifiable_code | 957_A. Tritonic Iridescence | Solve the following coding problem using the programming language python:
Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.
Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into ... | ```python
def complete_canvas(s):
double = False
res = ""
for i,c in enumerate(s):
if i>0 and i<len(s)-1 and c=='?' and s[i-1] in colors and s[i+1] in colors:
#and s[i-1]!=s[i+1]
col = list(colors)
col.remove(s[i-1])
if s[i-1]!=s[i+1]:
... | vfc_41125 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n?CYC?\n",
"output": "Yes",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nCY??Y\n",
"output": "Yes",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | 982_A. Row | Solve the following coding problem using the programming language python:
You're given a row with n chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated.
2. It's impossible to seat one more person without violating the first rule.... | ```python
n = int(input())
l = '0' + input() +'0'
o = 0
z = 0
flag = True
for i in l:
if i == "0" and z < 2:
z += 1
o = 0
elif i == "1" and o != 1:
o = 1
z = 0
else:
flag = False
break
if flag:
print("Yes")
else:
print("No")
``` | vfc_41129 | {
"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\n101\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n10001\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input... |
code_contests | verifiable_code | a-centrifuge | Solve the following coding problem using the programming language python:
SKIT's Chemistry Department found some liquid containing a precious chemical which can be separated out of the liquid using centrifugation.
This liquid need to be centrifuged for 5 minutes continuously after that some another facilitating chemic... | ```python
times=input()
for _ in range(times):
inp=raw_input()
lst=inp.split()
capa=int(lst[0])
num=int(lst[1])
if num==0:
print 0
elif num<capa:
print 10
else:
mult=num/capa
diff=num%capa
if diff==0:
extra=0
elif diff<=int(capa/2):
extra=5
else:
extra=10
time=10*mult+extra
prin... | vfc_41133 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 3\n3 4\n\nSAMPLE",
"output": "15\n15\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | binary-strings | Solve the following coding problem using the programming language python:
Golu hates odd numbers. When he learns about binary strings he wants to find out how many binary strings of given length N exist without an odd number of consecutive 1's.
For example: For N=4 1001,1010,1110,0001 are strings which contain odd nu... | ```python
a = [0]*(1000005)
b = [0]*(1000005)
def cstr():
a[0] = 1
for i in range(1, 1000000+1):
a[i] = (a[i-1] + b[i-1]) % 1000000007
b[i] = a[i-1] % 1000000007
# return (a[n-1] + b[n-1]) % 1000000007
t = input()
cstr()
while t>0:
t-=1
n = input()
# cnt = cstr(n)
print (a[n-1] + b[n-1]) % 1000000007
``` | vfc_41137 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2\n\nSAMPLE",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n42\n18468\n6335\n26501\n19170\n15725\n11479\n29359\n26963\n24465",
"output": "433494437\n784821591\n46... |
code_contests | verifiable_code | counting-strings | Solve the following coding problem using the programming language python:
Alice got a message M. It is in an alien language. A string in an alien language is said to be valid if it contains the letter a or z. Alice decided to count the number of valid substrings of the message M. Help him to do this. Two substrings ... | ```python
t = int(raw_input())
while t:
t-=1
s = raw_input().strip()
count = 0
prev = 0
curr = 0
l = len(s)
s = s.replace("a", "z")
if "z" in s:
for i, v in enumerate(s):
if v == "z":
count += l - i
prev += curr
count += prev
curr = 0
else:
count += prev
curr += 1
... | vfc_41141 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nabcd\nazazaz\nabbzbba\nflkjdh\n\nSAMPLE",
"output": "4\n21\n22\n0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | finding-xor | Solve the following coding problem using the programming language python:
You are given two very large numbers made up of 1 or 0 only. You have to find the digit by digit XOR of the two numbers, i.e., the i-th digit of the answer is 1 if and only if the i-th digit of the two given numbers differ otherwise the i-th dig... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
t=input('');
for i in range(t):
number1=raw_input('');
number2=raw_input('');
number3='';
for j in range(len(number1)):
if(number1[j]!=number2[j]):
number3=number3+'1'... | vfc_41145 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n01110\n01100\n010\n111\n\nSAMPLE",
"output": "00010\n101\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n01110\n01100\n010\n111\n\nSAMOLE",
"output": "00010\n101\n",
"typ... |
code_contests | verifiable_code | irctc | Solve the following coding problem using the programming language python:
Good news , You have a chance to work in IRCTC as a software developer . Applications are required with a program for railway sites . sid of a station is a something which uniquely defines it . Given N station's sid from 1 to N and distance bet... | ```python
import heapq
INF = 1 + 25 * 10**9
def dijkstra(G, n, s,de):
dist = [INF] * (n+1)
#path=[]
dist[s] = 0
heap = []
heapq.heappush(heap, (0,s))
while heap:
d, u = heapq.heappop(heap)
if dist[u] < d:
continue
#path.append(u)
if u==de:
... | vfc_41149 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n6 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n1 3 6\n10 10\n1 5 78\n1 8 221\n2 7 92\n2 8 159\n3 5 55\n3 6 179\n3 10 237\n4 8 205\n5 6 191\n8 10 157\n6 3 2\n\nSAMPLE",
"output": "No Train Found.\n692\n6 3 5 1 8 2",
"... |
code_contests | verifiable_code | mehta-and-the-tricky-triplets | Solve the following coding problem using the programming language python:
Mehta is a forever alone and desperate guy. He has a crush on N girls of his society. He wants to impress them all and so he needs to do their task collectively.All the girls give him a number which he stores in an array named A of size N. To do... | ```python
'''
Project name : Mehta_and_the_Tricky_Triplets
Created on : Tue Aug 26 23:19:11 2014
Author : Anant Pushkar
'''
import sys
debug_mode = len(sys.argv)>1 and sys.argv[1]=="DEBUG"
def debug(msg):
if debug_mode:
print msg
class Solver:
def __init__(self , n):
self.create_masks()
for i in xrange(n):
... | vfc_41153 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n21\n22\n23\n24\n25\n\nSAMPLE",
"output": "10",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n21\n22\n23\n24\n25\n\nELPMAS",
"output": "10\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | our-coach-and-messi | Solve the following coding problem using the programming language python:
After the huge success of Hero ISL this season our friend is planning to play in the next season. He already has a team which contains some good players but they not so good. He wants his team to qualify for the next season but the coach is worr... | ```python
from sys import stdin
for i in xrange(int(stdin.readline())):
a=map(int, stdin.readline().split())
print pow(a[0],a[1],1000000007)
``` | vfc_41157 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 2\n3 4\n250000000 4\n\nSAMPLE",
"output": "4\n81\n660156264\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2\n3 4\n250000000 4\n\nSAMPLE",
"output": "1\n81\n660156264\n",
... |
code_contests | verifiable_code | ranking-4 | Solve the following coding problem using the programming language python:
Ravi, a student of a primary class, is unable to understand the ranking system of his school.
The ranking system is as:
If two students of the class get equal marks, they are given the same rank but students with different marks are given the r... | ```python
t = int(raw_input())
for i in range(t):
n = int(raw_input())
out = [0]*n
s = raw_input().split()
s = [int(num) for num in s]
s2 = []
for j in range(len(s)):
s2.append((j, s[j]))
s2 = sorted(s2, key = lambda x: x[1], reverse = True)
prev = -1
pos = 1
s3 = []
same = 0
for j in range(len(s2)):
if... | vfc_41161 | {
"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\n98 68 74 21 74\n\nSAMPLE",
"output": "1 4 2 5 2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | snack-ruiner | Solve the following coding problem using the programming language python:
In India IPL is on full swing now. Fans of cricket love watching the game and seeing ball by ball with having Snacks. Yummy, crispy snacks. Ankit and his friends are one of them.
One night, while watching his Favourite team's Match he is eating... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
t=int(raw_input())
while t:
t=t-1
n=int(raw_input())
d=list(map(float,raw_input().split()))
f=list(map(float,raw_input().split()))
sum=0
for i in r... | vfc_41165 | {
"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\n0.2 0.3 0.1\n0.5 0.6 0.9\n\nSAMPLE",
"output": "1 0.486",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "15\n9\n0.21 0.43 0.23 0.67 0.39 0.8 0.1 0.4 0.3\n0.9 0.3 0.1 0.5 0.8 0.2 0.7 0.6... |
code_contests | verifiable_code | tic-tac-toe-alphabets | Solve the following coding problem using the programming language python:
Tic-Tac-Toe are three cousins. They planned to play cricket this afternoon but got stuck in their homework. Mrs. Jaime assigned them a task to arrange all the letters in a scrambled word in the order of their appearance in english alphabets. All... | ```python
t = int(raw_input())
while(t>0):
string = raw_input()
a = ''.join(sorted(string))
print a
t -= 1
``` | vfc_41169 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nINDIA\nPROGRAM\nHACKEREARTH\nCOLOUR\n\nSAMPLE",
"output": "ADIIN\nAGMOPRR\nAACEEHHKRRT\nCLOORU\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00110 Alphametic | Solve the following coding problem using the programming language python:
The problem of hiding a part of a formula and searching for the hidden number is called verbal arithmetic. This time, I'm dealing with an expression in which some numbers in the expression are hidden by X. Enter the following formula and create ... | ```python
import sys,re
for e in sys.stdin:
s=any([len(x)>1 and x[0]=='X' for x in re.split('[+=]',e.strip())])
for i in '0123456789'[s:]:
if eval(e.replace('X',i).replace('=','==')):print(i);break
else:print('NA')
``` | vfc_41217 | {
"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": "123+4X6=X79\n12X+4X6=X79\nXX22+89=X2XX",
"output": "5\nNA\n1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "123+4X6=X79\n12X+4X7=X79\nXX22+89=X2XX",
"output": "5\nNA\nNA\n",
"ty... |
code_contests | verifiable_code | p00425 Dice | Solve the following coding problem using the programming language python:
The dice are placed in the orientation shown in the figure below.
<image>
As shown in this figure, the dice used here have 1 on the upper side and 2 on the south side, and 3 on the east side. Since the sum of the facing faces of the dice is a... | ```python
class Dice(object):
"""
6??¢???????????????
?????¢???top, ?????¢???bottom???????????\??????4??¢??????????????? north, south, east, west ??¨?????¶???
"""
def __init__(self, faces):
# faces???????????????????????¨?????????????????????????????????
# ???????????? top, south, ea... | vfc_41225 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\nNorth\nNorth\nEast\nSouth\nWest\n8\nWest\nNorth\nLeft\nSouth\nRight\nNorth\nLeft\nEast\n0",
"output": "21\n34",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00620 Line Puzzle | Solve the following coding problem using the programming language python:
Let's solve the puzzle by programming.
The numbers n x n are arranged in a grid pattern. Some of the numbers are circled and we will call them the starting point. The rules of the puzzle are as follows:
* Draw one line that goes vertically and... | ```python
while True:
n = int(input())
if n == 0:break
mp = [list(map(int, input().split())) for _ in range(n)]
used = [[False] * n for _ in range(n)]
inits = []
for y in range(n):
for x in range(n):
if mp[y][x] < 0:
inits.append((x, y, mp[y][x]))
used[y][x] = True
vec = ((... | vfc_41229 | {
"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\n-3 1 1\n2 -4 1\n2 1 -1\n3\n-4 1 1\n1 1 -6\n1 -5 3\n4\n-8 6 -2 1\n2 -7 -2 1\n1 -1 1 1\n1 1 1 -5\n6\n2 2 3 -7 3 2\n1 -10 1 1 3 2\n2 6 5 2 -6 1\n3 4 -23 2 2 5\n3 3 -6 2 3 7\n-7 2 3 2 -5 -13\n6\n2 2 3 -7 3 2\n1 -10 1 1 3 2\n2 6 5 2 ... |
code_contests | verifiable_code | p00764 Chain-Confined Path | Solve the following coding problem using the programming language python:
There is a chain consisting of multiple circles on a plane. The first (last) circle of the chain only intersects with the next (previous) circle, and each intermediate circle intersects only with the two neighboring circles.
Your task is to fin... | ```python
def solve():
from math import acos
from cmath import phase, rect, pi
from sys import stdin
file_input = stdin
while True:
n = int(file_input.readline())
if n == 0:
break
C = (map(int, file_input.readline().split()) for i in range(n))
... | vfc_41233 | {
"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": "10\n802 0 10\n814 0 4\n820 1 4\n826 1 4\n832 3 5\n838 5 5\n845 7 3\n849 10 3\n853 14 4\n857 18 3\n3\n0 0 5\n8 0 5\n8 8 5\n3\n0 0 5\n7 3 6\n16 0 5\n9\n0 3 5\n8 0 8\n19 2 8\n23 14 6\n23 21 6\n23 28 6\n19 40 8\n8 42 8\n0 39 5\n11\n0 0... |
code_contests | verifiable_code | p00896 Weaker than Planned | Solve the following coding problem using the programming language python:
The committee members of the Kitoshima programming contest had decided to use crypto-graphic software for their secret communication. They had asked a company, Kodai Software, to develop cryptographic software that employed a cipher based on hig... | ```python
from string import ascii_uppercase
import sys
readline = sys.stdin.readline
write = sys.stdout.write
conv = ascii_uppercase.find
def solve():
N = int(readline())
if N == 0:
return False
W = [tuple(map(conv, readline().strip())) for i in range(N)]
S = []
T = set()
for s in rea... | vfc_41237 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nA\nAND\nCAT\nDOG\nZ XUW ZVX Z YZT.\n2\nAZ\nAY\nZA.\n2\nAA\nBB\nCC.\n16\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nO\nABCDEFGHIJKLMNO\nA B C D E F G H I J K L M N O ABCDEFGHIJKLMNO.\n0",
"output": "A DOG AND A CAT.\nAZ.\n-.... |
code_contests | verifiable_code | p01160 It Prefokery Pio | Solve the following coding problem using the programming language python:
You are a member of a secret society named Japanese Abekobe Group, which is called J. A. G. for short. Those who belong to this society often exchange encrypted messages. You received lots of encrypted messages this morning, and you tried to dec... | vfc_41245 | {
"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": "YMAOKDOAMIMHAADAMMA\nLELVEEL",
"output": "MADAMIMADAM\nLEVEL",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "AMMADAAHMIMAODKOAMY\nLELVEEL",
"output": "MADAMIMADAM\nLELEL\n",
"typ... | |
code_contests | verifiable_code | p01299 Neko's Treasure | Solve the following coding problem using the programming language python:
Maki is a house cat. One day she fortunately came at a wonderful-looking dried fish. Since she felt not hungry on that day, she put it up in her bed. However there was a problem; a rat was living in her house, and he was watching for a chance to... | ```python
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N = int(readline())
if N == 0:
return False
sx, sy, tx, ty = map(int, readline().split())
C = []
G = [[] for i in range(N+2)]
L = 0
for i in range(N):
xi, y... | vfc_41249 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n0 0 100 100\n60 100 50\n100 100 10\n80 80 50\n4\n0 0 100 100\n50 50 50\n150 50 50\n50 150 50\n150 150 50\n0",
"output": "2\n0",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p01468 Closest Segment Pair | Solve the following coding problem using the programming language python:
Problem statement
$ N $ Line segments $ s_1, s_2, ..., s_N $ are given. At this time, find the minimum possible value of dist $ (s_i, s_j) $, ($ 1 \ leq i, j \ leq N, i \ ne j $). dist $ (s_i, s_j) $ is
* $ \ sqrt {(x_i-x_j) ^ 2 + (y_i-y_j) ^ ... | vfc_41253 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n5 5 5 45\n7 45 19 45\n7 30 19 30\n21 34 21 44\n26 45 36 28\n45 45 26 5",
"output": "0.83553169",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n2 0 2 25\n0 30 15 20\n16 20 5 15\n23 0 23... | |
code_contests | verifiable_code | p01628 Amidakuji | Solve the following coding problem using the programming language python:
Problem Statement
Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and always tries to save as much paper as possible. She decided to play a ghost leg with other participants to decide the team for the A... | ```python
from itertools import permutations
N,M=map(int,input().split())
k=[int(input())-1 for i in range(M)]
g=[i for i in range(N)]
for i in range(N):
for j in k:
if g[i]==j:
g[i]=j+1
elif g[i]==j+1:
g[i]=j
s=10
for K in permutations(k):
G=[i for i in range(N)]
for... | vfc_41257 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4\n4\n3\n1\n2",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n1\n2\n3",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inp... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.