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 | 1302_E. Amazing bitset | 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)
Andrey has just started to study competitive programming and he is fascinated by bitsets and... | vfc_74677 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 1 2\n",
"output": "\n848765426\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 228 239\n",
"output": "\n0\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1326_D2. Prefix-Suffix Palindrome (Hard version) | Solve the following coding problem using the programming language python:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of low... | ```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_74681 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\na\nabcdfdcecba\nabbaxyzyx\ncodeforces\nacbba\n",
"output": "a\nabcdfdcba\nxyzyx\nc\nabba\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\nadaaaecabaaacgaeaacigabaabacaa\n",
"out... |
code_contests | verifiable_code | 1367_C. Social Distance | Solve the following coding problem using the programming language python:
Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the... | ```python
import sys
input = lambda: sys.stdin.readline().strip()
inp = lambda: list(map(int,input().split()))
for _ in range(int(input())):
n,d = inp()
a = [int(i) for i in str(input())]
f1 = f = True
c = ans =0
for i in range(n):
if f==True:
if a[i]==0:
c+=1
else:
f = False
c = 0
if c==d+1... | vfc_74689 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n6 1\n100010\n6 2\n000000\n5 1\n10101\n3 1\n001\n2 2\n00\n1 1\n0\n",
"output": "1\n2\n0\n1\n1\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 1\n0\n1 1\n0\n1 1\n0\n1 1\n0\n1 1\n0... |
code_contests | verifiable_code | 1388_C. Uncle Bogdan and Country Happiness | Solve the following coding problem using the programming language python:
Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index.
There are n cities and n−1 undirected roads connecting pairs of cities. Citiz... | ```python
import sys
input=sys.stdin.buffer.readline
for _ in range(int(input())):
n,m=map(int,input().split())
pr=list(map(int,input().split()))
hr=list(map(int,input().split()))
dic={}
dis={}
people={}
for i in range(1,n+1):
dic[i]=[]
dis[i]=0
people[i]=-1
for i... | vfc_74693 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 4\n1 1 1 1\n4 1 -3 -1\n1 2\n1 3\n1 4\n3 13\n3 3 7\n13 1 4\n1 2\n1 3\n",
"output": "NO \nNO \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n7 4\n1 0 1 1 0 1 0\n4 0 0 -1 0 -1 0\n1 2... |
code_contests | verifiable_code | 142_D. Help Shrek and Donkey 2 | Solve the following coding problem using the programming language python:
Having learned (not without some help from the Codeforces participants) to play the card game from the previous round optimally, Shrek and Donkey (as you may remember, they too live now in the Kingdom of Far Far Away) have decided to quit the bo... | ```python
def get(a):
global m
R = -1
G = -1
mi = -1
for i in range(m):
if a[i] == '-':
mi = i
elif a[i] == "R":
R = i
else:
G = i
return G, R, mi
n, m, k = map(int, input().split())
draw = [0, 0]
t = []
for i in range(n):
G, R, m... | vfc_74701 | {
"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 5 2\n-G-R-\n-R-G-\n",
"output": "First",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3 1\n-R-\n-G-\n",
"output": "Draw",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1453_A. Cancel the Trains | Solve the following coding problem using the programming language python:
Gildong's town has a train system that has 100 trains that travel from the bottom end to the top end and 100 trains that travel from the left end to the right end. The trains starting from each side are numbered from 1 to 100, respectively, and ... | ```python
t=int(input())
while t:
n,m=map(int,(input().split()))
a=set(map(int,input().split()))
b=set(map(int,input().split()))
print(len(a&b))
t=t-1
``` | vfc_74705 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2\n1\n3 4\n3 2\n1 3 4\n2 4\n9 14\n2 7 16 28 33 57 59 86 99\n3 9 14 19 25 26 28 35 41 59 85 87 99 100\n",
"output": "\n0\n1\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2\n1... |
code_contests | verifiable_code | 1503_C. Travelling Salesman Problem | Solve the following coding problem using the programming language python:
There are n cities numbered from 1 to n, and city i has beauty a_i.
A salesman wants to start at city 1, visit every city exactly once, and return to city 1.
For all i≠ j, a flight from city i to city j costs max(c_i,a_j-a_i) dollars, where c_... | ```python
n=int(input());a=sorted([*map(int,input().split())]for i in range(n));c=sum(a[0]);t=a[0][1]
for w in a[1:]:
t+=w[1]
if w==a[-1]or sum(w)>c:t+=max(w[0]-c,0);c=sum(w)
print(t)
``` | vfc_74713 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 9\n2 1\n4 1\n",
"output": "\n11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n4 2\n8 4\n3 0\n2 3\n7 1\n0 1\n",
"output": "\n13\n",
"type": "stdin_stdout"
},
{... |
code_contests | verifiable_code | 1527_A. And Then There Were K | Solve the following coding problem using the programming language python:
Given an integer n, find the maximum value of integer k such that the following condition holds:
n & (n-1) & (n-2) & (n-3) & ... (k) = 0 where & denotes the [bitwise AND operation.](https://en.wikipedia.org/wiki/Bitwise_operation#AND)
Input
... | ```python
from math import log
from math import floor
t = int(input())
for i in range(t):
n = int(input())
#print(n)
k = 2**(floor(log(n,2)))-1
print(k)
``` | vfc_74717 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n5\n17\n",
"output": "\n1\n3\n15\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 158_E. Phone Talks | Solve the following coding problem using the programming language python:
Cool J has recently become a businessman Mr. Jackson, and he has to make a lot of phone calls now. Today he has n calls planned. For each call we know the moment ti (in seconds since the start of the day) when it is scheduled to start and its du... | vfc_74721 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 1\n1 20000\n10000 10000\n20000 20000\n25000 10000\n80000 60000\n",
"output": "39999",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n30000 15000\n40000 15000\n50000 15000\n",
"ou... | |
code_contests | verifiable_code | 200_C. Football Championship | Solve the following coding problem using the programming language python:
Any resemblance to any real championship and sport is accidental.
The Berland National team takes part in the local Football championship which now has a group stage. Let's describe the formal rules of the local championship:
* the team tha... | ```python
import copy
teams = {}
times = {}
def put_team(s):
if not s[0] in teams:
teams[s[0]] = [0, 0, 0, s[0]]
if not s[1] in teams:
teams[s[1]] = [0, 0, 0, s[1]]
g1, g2 = map(int, s[2].split(':'))
teams[s[0]][1] -= g1 - g2
teams[s[1]][1] -= g2 - g1
teams[s[0]][2] -= g1
t... | vfc_74729 | {
"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": "AERLAND DERLAND 2:1\nDERLAND CERLAND 0:3\nCERLAND AERLAND 0:1\nAERLAND BERLAND 2:0\nDERLAND BERLAND 4:0\n",
"output": "6:0",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 225_B. Well-known Numbers | Solve the following coding problem using the programming language python:
Numbers k-bonacci (k is integer, k > 1) are a generalization of Fibonacci numbers and are determined as follows:
* F(k, n) = 0, for integer n, 1 ≤ n < k;
* F(k, k) = 1;
* F(k, n) = F(k, n - 1) + F(k, n - 2) + ... + F(k, n - k), for inte... | ```python
def s():
[s,k] = list(map(int,input().split()))
d = [0]
d.append(1)
t = 0
r = []
while t < s:
t = sum(d[-min(k,len(d)):])
d.append(t)
for i in reversed(d):
if i <= s:
s -= i
r.append(i)
if i == 0:
break
... | vfc_74733 | {
"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": "21 5\n",
"output": "3\n16 4 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n",
"output": "2\n5 0 ",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 249_E. Endless Matrix | Solve the following coding problem using the programming language python:
A Russian space traveller Alisa Selezneva, like any other schoolgirl of the late 21 century, is interested in science. She has recently visited the MIT (Moscow Institute of Time), where its chairman and the co-inventor of the time machine academ... | ```python
if __name__ == "__main__":
T = int(raw_input())
for step in xrange(T):
x0, y0, x1, y1 = map(int, raw_input().split(' '))
ans = 0; mini = min(x1, y1); maxi = max(x0, y0)
if max(x0, y0) <= min(x1, y1):
ans += (x1 * (x1 + 1) * (x1 * 2 + 1) * (y1 - y0 + 1) - mini * (mini + 1) * (mini * 2 + 1) * y1 ... | vfc_74737 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 1 1 1\n2 2 3 3\n2 3 5 6\n100 87 288 2002\n4 2 5 4\n",
"output": " 1\n 24\n ... |
code_contests | verifiable_code | 274_A. k-Multiple Free Set | Solve the following coding problem using the programming language python:
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n dis... | ```python
n, k = [int(x) for x in input().split()]
a = sorted([int(x) for x in input().split()])
s = set(a)
l = 0
for x in a:
t = 1
while x in s:
l += t
t = 1 - t
s.remove(x)
x *= k
print(l)
``` | vfc_74741 | {
"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": "6 2\n2 3 6 5 4 10\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n10 8 6 4 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | 297_C. Splitting the Uniqueness | Solve the following coding problem using the programming language python:
Polar bears like unique arrays — that is, arrays without repeated elements.
You have got a unique array s with length n containing non-negative integers. Since you are good friends with Alice and Bob, you decide to split the array in two. Preci... | ```python
import sys
n = input()
S = map(int, raw_input().split())
a = [i[0] for i in sorted(enumerate(S), key=lambda x:x[1])]
idx = a[0:n]
for i in range(n):
idx[a[i]] = i
S.sort()
la = lb = n / 3
if n % 3 >= 1:
la = la + 1
elif n % 3 == 2:
lb = lb + 1
A = range(la)
B = list(map(lambda x: x[0] - x[1], zip... | vfc_74745 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n12 5 8 3 11 9\n",
"output": "YES\n12 1 6 0 10 6 \n0 4 2 3 1 3 ",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 320_A. Magic Numbers | Solve the following coding problem using the programming language python:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determin... | ```python
a=input()
result=1
if a[0]!='1':
print('NO')
result=0
else:
for i in range(len(a)):
if a[i]!='1' and a[i]!='4':
print('NO')
result=0
break
if result==1:
length=len(a)
for i in range(length-2):
if a[i]=='4' and a[i+1]=='4' ... | vfc_74749 | {
"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": "1111\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "114114\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | 345_A. Expecting Trouble | Solve the following coding problem using the programming language python:
It is Friday the 13th today, and even though you're a modern well-educated person, you can't help feeling a bit nervous about it. You decide to look for evidence against this superstition (or for it). As a first step, you recall all Fridays the ... | vfc_74753 | {
"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": "?111?1??1\n1.0\n",
"output": "1.00000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "01?10??10000\n0.5\n",
"output": "0.37500\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 368_C. Sereja and Algorithm | Solve the following coding problem using the programming language python:
Sereja loves all sorts of algorithms. He has recently come up with a new algorithm, which receives a string as an input. Let's represent the input string of the algorithm as q = q1q2... qk. The algorithm consists of two steps:
1. Find any con... | ```python
def f(t): return t[2] - t[0] > 1
t = input()
n, m, p = len(t), int(input()), {'x': 0, 'y': 1, 'z': 2}
s = [[0] * (n + 1) for i in range(3)]
for i, c in enumerate(t, 1): s[p[c]][i] = 1
for i in range(3):
for j in range(1, n): s[i][j + 1] += s[i][j]
a, b, c = s
q, d = [map(int, input().split()) for ... | vfc_74757 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "zyxxxxxxyyz\n5\n5 5\n1 3\n1 11\n1 4\n3 6\n",
"output": "YES\nYES\nNO\nYES\nNO\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 390_D. Inna and Sweet Matrix | Solve the following coding problem using the programming language python:
Inna loves sweets very much. That's why she decided to play a game called "Sweet Matrix".
Inna sees an n × m matrix and k candies. We'll index the matrix rows from 1 to n and the matrix columns from 1 to m. We'll represent the cell in the i-th ... | ```python
string = input()
l = string.split(" ")
n, m, k = int(l[0]),int(l[1]),int(l[2])
l = [{(1,1),}]
count = 1
In = 0
while count < k:
s = set()
for i in l[In]:
x = i[0]+1
y = i[1]
if x<=n and y<=m:
t = [0,0]
t[0],t[1] = x, y
s.add(tuple(t))
x = i[0]
y = i[1]+1
if x<=n and y<=m:
t = [0,0]
... | vfc_74761 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4 4\n",
"output": "8\n(1,1) (1,2) (1,3)\n(1,1) (2,1)\n(1,1) (1,2)\n(1,1)\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 50 75\n",
"output": "1481\n(1,1) (2,1) (2,2) (2,3) (2,4) ... |
code_contests | verifiable_code | 412_C. Pattern | Solve the following coding problem using the programming language python:
Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check whether a particular st... | ```python
n = int(input())
matrix = []
for _ in range(n):
pattern = list(input())
matrix.append(pattern)
m = len(matrix[0])
answer = []
for i in range(m):
memo = set()
question = False
for j in range(n):
if matrix[j][i].isalpha():
memo.add(matrix[j][i])
else:
... | vfc_74765 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n?a?b\n",
"output": "aaab",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n?ab\n??b\n",
"output": "aab",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inp... |
code_contests | verifiable_code | 439_E. Devu and Birthday Celebration | Solve the following coding problem using the programming language python:
Today is Devu's birthday. For celebrating the occasion, he bought n sweets from the nearby market. He has invited his f friends. He would like to distribute the sweets among them. As he is a nice guy and the occasion is great, he doesn't want an... | ```python
import itertools
import functools
import operator
N = 100001
P = 10**9 + 7
fact = [1]
for i in range(1, N):
fact.append(fact[-1] * i % P)
inv = [0, 1]
for i in range(2, N):
inv.append(P - P // i * inv[P % i] % P)
inv_fact = [1]
for i in range(1, N):
inv_fact.append(inv_fact[-1] * inv[i] % P)
least_div ... | vfc_74769 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n6 2\n7 2\n6 3\n6 4\n7 4\n",
"output": "2\n6\n9\n10\n20\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3 1\n3 2\n3 3\n",
"output": "0\n2\n1\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 485_A. Factory | Solve the following coding problem using the programming language python:
One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were x details in the factory storage, then by the end of the day the factory has to produce ... | ```python
(n,m) = input().split()
n=int(n)
m=int(m)
for i in range(0,10**5):
n+=n%m
if n%m == 0:
break
if (n%m == 0): print("Yes")
else: print('No')
``` | vfc_74777 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 5\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 6\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3276... |
code_contests | verifiable_code | 509_A. Maximum in Table | Solve the following coding problem using the programming language python:
An n × n table a is defined as follows:
* The first row and the first column contain ones, that is: ai, 1 = a1, i = 1 for all i = 1, 2, ..., n.
* Each of the remaining numbers in the table is equal to the sum of the number above it and the... | ```python
n = int(input())
list1 = []
list2 = [1 for i in range(n)]
list3 = [1] + [0 for i in range(n-1)]
list1.append(list2)
for i in range(n-1):
list1.append(list3)
for i in range(1,n):
for j in range(1,n):
list1[i][j] = list1[i-1][j] + list1[i][j-1]
list4 = []
for i in range(n):
list4.append(max(... | vfc_74781 | {
"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\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "70\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n",
... |
code_contests | verifiable_code | 533_C. Board Game | Solve the following coding problem using the programming language python:
Polycarp and Vasiliy love simple logical games. Today they play a game with infinite chessboard and one pawn for each player. Polycarp and Vasiliy move in turns, Polycarp starts. In each turn Polycarp can move his pawn from cell (x, y) to (x - 1... | ```python
"""
Author - Satwik Tiwari .
15th Jan , 2021 - Thursday
"""
#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io ... | vfc_74785 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 7 7 4\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 558_B. Amr and The Large Array | Solve the following coding problem using the programming language python:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that... | ```python
from collections import defaultdict
_ = input()
nums = list(map(int, input().split()))
freqs = defaultdict(list)
_max = -1
for i, k in enumerate(nums):
freqs[k].append(i + 1)
_max = max(_max, len(freqs[k]))
start = 1
end = len(nums)
length = end - start
for k, v in freqs.items():
if len(v)... | vfc_74789 | {
"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 1 2 2 1\n",
"output": "1 5\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 583_E. Superior Periodic Subarrays | Solve the following coding problem using the programming language python:
You are given an infinite periodic array a0, a1, ..., an - 1, ... with the period of length n. Formally, <image>. A periodic subarray (l, s) (0 ≤ l < n, 1 ≤ s < n) of array a is an infinite periodic array with a period of length s that is a subs... | ```python
# -*- coding: utf-8 -*-
import fractions
from collections import defaultdict
if __name__ == '__main__':
n = int(raw_input())
a = map(int, raw_input().split())
a *= 2
inf = min(a) - 1
a[-1] = inf
result = 0
numbers_by_gcd = defaultdict(list)
for i in xrange(1, n):
num... | vfc_74793 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n7 1 2 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | 627_F. Island Puzzle | Solve the following coding problem using the programming language python:
A remote island chain contains n islands, with some bidirectional bridges between them. The current bridge network forms a tree. In other words, a total of n - 1 bridges connect pairs of islands in a way that it's possible to reach any island fr... | vfc_74801 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0 1 2 3\n0 2 3 1\n1 2\n1 3\n1 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 0\n0 1\n1 2\n",
"output": "0 1\n",
"type": "stdin_stdout"
},
{... | |
code_contests | verifiable_code | 652_A. Gabriel and Caterpillar | Solve the following coding problem using the programming language python:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the cater... | ```python
#! /usr/bin/env python3
'''
' Title:
' Author: Cheng-Shih, Wong
' Date:
'''
import math
h1, h2 = map(int, input().split())
a, b = map(int, input().split())
if h1+a*8 >= h2: print(0)
elif a <= b: print(-1)
else:
print( math.ceil((h2-h1-8*a)/(12*(a-b))) )
``` | vfc_74805 | {
"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": "10 19\n1 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 50\n5 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | 677_D. Vanya and Treasure | Solve the following coding problem using the programming language python:
Vanya is in the palace that can be represented as a grid n × m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x ≤ p - 1 contains a key that can open any... | vfc_74809 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3 9\n1 3 5\n8 9 7\n4 6 2\n",
"output": "22\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 6_D. Lizards and Basements 2 | Solve the following coding problem using the programming language python:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and ... | ```python
n, a, b = list(map(int, input().split(" ")))
h = list(map(lambda x: int(x) + 1, input().split(" ")))
dp = [[[-1] * 17 for j in range(17)] for i in range(n)]
num = [[[0] * 17 for j in range(17)] for i in range(n)]
health = [[[0] * 17 for j in range(17)] for i in range(n)]
result = []
def recursion(i, j, k):
... | vfc_74813 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2 1\n2 2 2\n",
"output": "3\n2 2 2 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3 1\n1 4 1 1\n",
"output": "4\n2 2 3 3 ",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | 722_A. Broken Clock | Solve the following coding problem using the programming language python:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You ... | ```python
import logging
import copy
import sys
import math
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
#def solve(firstLine):
def solve(formatStr, timeStr):
if int(timeStr[3]) > 5 :
timeStr = timeStr[:3] + "0" + timeStr[4:]
if formatStr == 24:
if int(timeStr[0]) > 2... | vfc_74817 | {
"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": "12\n17:30\n",
"output": "07:30\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "24\n99:99\n",
"output": "09:09\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 743_D. Chloe and pleasant prizes | Solve the following coding problem using the programming language python:
Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes.
They took n ... | ```python
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()
self.writable = "x" in file.mo... | vfc_74821 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 -5 1 1\n1 2\n1 4\n2 3\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n0 5 -1 4 3 2 6 5\n1 2\n2 4\n2 5\n1 3\n3 6\n6 7\n6 8\n",
"output": "25",
"type": "st... |
code_contests | verifiable_code | 767_A. Snacktower | Solve the following coding problem using the programming language python:
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower... | ```python
n = int(input())
s = list(map(int, input().split()))
e1 = []
e2 = set()
f = '\n'
r = ''
for i in s:
'''e1.append(i)
while n in e1:
print(n, end=' ')
n -= 1
print()'''
e2.add(i)
while n in e2:
print(n, end=' ')
n -= 1
print()
``` | vfc_74825 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n4 5 1 2 3\n",
"output": "\n5 4 \n\n\n3 2 1 \n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 78_E. Evacuation | Solve the following coding problem using the programming language python:
They've screwed something up yet again... In one nuclear reactor of a research station an uncontrolled reaction is in progress and explosion which will destroy the whole station will happen soon.
The station is represented by a square n × n div... | vfc_74829 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4\nY110\n1Y1Z\n1Y0Y\n0100\n\nY001\n0Y0Z\n0Y0Y\n0005\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n1YZ\n1YY\n100\n\n0YZ\n0YY\n003\n",
"output": "2\n",
... | |
code_contests | verifiable_code | 811_B. Vladik and Complicated Book | Solve the following coding problem using the programming language python:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the ... | ```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n,m=map(int,input().strip().split())
a=input()
b=list(map(int,a.strip().split()))
for i in range(m):
L,R,k=map(int,input().strip().split())
L-=1
R-=1
k-=1
sum=0
j=L
while j<=R:
if b[j]<b[k]:
sum+=1
j+=1
if ... | vfc_74833 | {
"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": "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3\n",
"output": "Yes\nNo\nYes\nNo\nYes\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 837_D. Round Subset | Solve the following coding problem using the programming language python:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.... | ```python
import sys
n, K = map(int, input().split())
a = list(map(int, input().split()))
m2, m5 = [0]*n, [0]*n
for i, x in enumerate(a):
while x % 2 == 0:
x //= 2
m2[i] += 1
while x % 5 == 0:
x //= 5
m5[i] += 1
dp = [[-10**9]*5100 for _ in range(K)]
dp[0][0] = 0
for i in ra... | vfc_74837 | {
"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 3\n9 77 13\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3\n15 16 3 25 9\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 856_F. To Play or not to Play | Solve the following coding problem using the programming language python:
Vasya and Petya are playing an online game. As most online games, it has hero progress system that allows players to gain experience that make their heroes stronger. Of course, Vasya would like to get as many experience points as possible. After... | vfc_74841 | {
"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": "1 2 5\n0 100\n20 60\n85 90\n",
"output": "125",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1 5\n1 7\n10 20\n10 20\n",
"output": "25",
"type": "stdin_stdout"
},
{
... | |
code_contests | verifiable_code | 883_F. Lost in Transliteration | Solve the following coding problem using the programming language python:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "... | ```python
c=[]
n=int(input())
for uygf in range(n):
s=list(input())
l=len(s)
i=0
p=[]
d=['u','o','k','h']
while(i<l):
if(s[i] not in d):
p.append(s[i])
i+=1
elif(s[i]=='u'):
p.append('o')
p.append('o')
i+=1
elif(... | vfc_74845 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\nmihail\noolyana\nkooooper\nhoon\nulyana\nkoouper\nmikhail\nkhun\nkuooper\nkkkhoon\n",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\nhariton\nhkariton\nbuoi\nkkkhariton\... |
code_contests | verifiable_code | 907_A. Masha and Bears | Solve the following coding problem using the programming language python:
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the sma... | ```python
sizes=[int(x) for x in str(input()).split(" ")]
l=(sizes[0],2*sizes[0])
m=(max(2*sizes[3]+1,sizes[1]),2*sizes[1])
s=(max(sizes[2],sizes[3]),min(2*sizes[2],2*sizes[3]))
if m[1]>=m[0] and s[1]>=s[0]:
print(l[1])
print(max(m[0],s[0])+1)
print(s[0])
else:
print(-1)
``` | vfc_74849 | {
"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": "50 30 10 10\n",
"output": "50\n30\n10",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100 50 10 21\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 926_H. Endless Roses Most Beautiful | Solve the following coding problem using the programming language python:
Arkady decided to buy roses for his girlfriend.
A flower shop has white, orange and red roses, and the total amount of them is n. Arkady thinks that red roses are not good together with white roses, so he won't buy a bouquet containing both red... | ```python
n,k=map(int,input().split())
b=list(map(int,input().split()))
s=input()
a=[]
if k==1:
print(-1)
exit()
for i in range(n):
a.append((b[i],s[i]))
a.sort(reverse=True)
i=0
j=0
m1=0
q1=False
q2=False
while i!=k:
if a[j][1]!='R':
m1+=a[j][0]
g=j+0
if a[j][1]=='W':
... | vfc_74853 | {
"difficulty": "14",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n10 20 14 20 11\nRRRRR\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 955_F. Heaps | Solve the following coding problem using the programming language python:
You're given a tree with n vertices rooted at 1.
We say that there's a k-ary heap of depth m located at u if the following holds:
* For m = 1 u itself is a k-ary heap of depth 1.
* For m > 1 vertex u is a k-ary heap of depth m if at least... | vfc_74857 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2\n2 3\n3 4\n",
"output": "22\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 47-attacks-oo7-3 | Solve the following coding problem using the programming language python:
Agent 47 attacks OO7 during the mission and uses Beretta M9 pistol (Semi Automatic). The pistol uses a 1mm bullet. The pistol bullet keeps changing the caliber after each consecutive fire. As the 1st round is fired, caliber of bullet triples and... | ```python
test=long(raw_input());
while(test!=0):
n=long(raw_input());
if(n>120):
print "UNABLE TO FIRE"
else:
flag=1
ans=1;
while(n!=0):
if (flag==1):
ans*=3
else:
ans+=2
flag^=1
n=n-1
print ans
test-=1
``` | vfc_74865 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n6\n4\n11\n2\n\nSAMPLE",
"output": "53\n17\n1455\n5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20\n45\n34\n23\n76\n23\n67\n121\n120\n34\n123\n45\n321\n4\n12\n56\n23\n21\n45\n7\n99",... |
code_contests | verifiable_code | billi-and-his-girlfriend-1 | Solve the following coding problem using the programming language python:
Billi was on date with his girlfriend Ketty. They had the following conversation
Ketty :- "Billi, How much do u love me?"
Billi :- "Ummm...."
Ketty :- "Come on.... Do you love me or not? :'( "
Billi :- "Umm.....yes, I love you A^B units."
K... | ```python
def main():
for _ in xrange(input()):
A,B,K=map(int,raw_input().split())
string=str(pow(A,B,10**K))
lis=[int(i) for i in string]
print sum(lis)
if __name__=="__main__":
main()
``` | vfc_74869 | {
"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 7 3\n1 1000000 4\n5 10 6\n\nSAMPLE",
"output": "11\n1\n31\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "329\n394 656 2\n191 710 7\n433 784 2\n796 789 1\n950 317 3\n561 620 5\n685 83... |
code_contests | verifiable_code | counter-strike-12 | Solve the following coding problem using the programming language python:
Navi is a counter strike pro. He always say how good he is at counter strike. After being tired of Navi, his friends decided to test his skills at shooting. They put M targets on a X-Y plane, each target is denoted by (X, Y) where X is x-coordi... | ```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=raw_input()
t=int(t)
while (t>0):
var=raw_input()
mylist=var.split(" ")
n=int(mylist[0])
m=int(mylist[1])
d=int(mylist[2])
count=0
ans=0
arr=Ma... | vfc_74873 | {
"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 3 5\n1 1\n2 2\n3 3\n1 0\n0 0\n2 0\n\nSAMPLE",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3 3 5\n1 1\n2 2\n3 3\n1 0\n0 0\n2 0\n\nSAMPLF",
"output": "YES\n"... |
code_contests | verifiable_code | finding-present-1 | Solve the following coding problem using the programming language python:
Today is Tom's Birthday. His Mom gifted him two sets of integers to play with, set Q and set R. R is the transformation of set Q. Both Q and R contains same frequency of numbers. While playing, he accidently drops few of integers of set Q.
You... | ```python
mdict = {}
num1 = input()
marr1 = map(int, raw_input().split())
num2 = input()
marr2 = map(int, raw_input().split())
for val in marr1:
if mdict.get(val, 'not') == 'not':
mdict[val] = 1
else:
mdict[val] += 1
for val in marr2:
if mdict.get(val, 'not') == 'not':
mdict[val] = -1
else:
mdict[val] -= 1
... | vfc_74877 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n23 24 25 26 27 28 23 24 25 26\n13\n23 24 24 25 26 27 25 28 23 26 25 26 24\n\nSAMPLE",
"output": "24 25 26",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n23 24 25 26 27 28 23 24 25 2... |
code_contests | verifiable_code | inversions-easy | Solve the following coding problem using the programming language python:
Given an array A of N integers. Find total number of pairs such that i < j and A[i] > A[j].
Constraints
1 ≤ N ≤ 2*10^3
1 ≤ Ai ≤ 10^9
SAMPLE INPUT
5
5 1 2 4 3
SAMPLE OUTPUT
5
The input will be given via stdin and the output should be print... | ```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!'
n=input()
c=0
l=[int(i) for i in raw_input().split()]
for i in range(n-1):
for j in range(i+1,n):
if l[i]>l[j]:
c+=1
print c
``` | vfc_74881 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n5 1 2 4 3\n\nSAMPLE",
"output": "5",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | maxsum | Solve the following coding problem using the programming language python:
After developing SPOJ-Toolkit manku thinks he is a FAAD coder now . He keeps bragging about himself so his friend KK decides to teach him a lesson . He gave him a simple problem to solve.
Given an array of N integers he has to find the maximum... | ```python
T = input()
while T > 0:
T -= 1
N = input()
a = [0] + map(int, raw_input().split())
# f = [0, a[1]]
for i in range(2, N + 1):
a[i] = max(a[i] + a[i - 2], a[i - 1])
print a[N]
``` | vfc_74885 | {
"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\n1 2 3\n5\n1 2 1 2 6\n\nSAMPLE",
"output": "4\n8",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | othello | Solve the following coding problem using the programming language python:
You have an m x n grid, with m and n both even. Each cell has a tile. The tile has two faces - one is black, and one is white. These tiles may be flipped. However, if you flip a tile, all other tiles in its row and column also get flipped. You s... | ```python
m, n = map(int, raw_input().split())
y_cnt = [0] * m
x_cnt = [0] * n
black = set()
for y in xrange(m):
s = raw_input()
for x, c in enumerate(s):
if c == "B":
x_cnt[x] += 1
y_cnt[y] += 1
black.add((x, y))
ans = 0
for y in xrange(m):
for x in xrange(n):
ans += (x_cnt[x] + y_cnt[y] + ((x, y) in ... | vfc_74889 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4\nWBBW\nWBBW\nWWWW\nWBBW\n\nSAMPLE",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100 100\nBWBWWBBBBBWWBBBBBWBWBBBBBBBBBWWBWWBBBBBBWBWBWBBBBBWBBWBBBBBBBBBBBBWWWBWBBBBBBWBB... |
code_contests | verifiable_code | ranjan-and-his-first-question | Solve the following coding problem using the programming language python:
Ranjan came to know about competitive programming today and created an
account on Hackerearth.
With his full determination he started to solve his first problem.
He saw a question stated as.
Calculate the sum of numbers from 1 to N as:
for (... | ```python
for _ in xrange(input()):
n, mod = map(long, raw_input().split())
print (n/mod)*((mod-1)*mod/2) + (n%mod)*(n%mod+1)/2
``` | vfc_74893 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5 3\n10 2\n20 4\n\nSAMPLE",
"output": "6\n5\n30\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3000\n8786 8705\n8419 7334\n8091 7406\n9692 8580\n2185 1951\n9195 8840\n1469 1159\n9424 2... |
code_contests | verifiable_code | smoothing-pixels-1 | Solve the following coding problem using the programming language python:
You have a one-dimensional array of N pixels. Each pixel has a value, represented by a number between 0 and 255, inclusive. The distance between two pixels is the absolute difference of their numbers.
You can perform each of the following opera... | ```python
def cost(k, v):
if (k, v) not in c:
if k < 0:
c[(k, v)] = 0
else:
t = d + cost(k-1, v)
o = abs(s[k] - v)
if m > 0:
for u in range(256):
if t <= o:
break
t = m... | vfc_74897 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n6 6 2 3\n1 7 5\n\nSAMPLE",
"output": "Case #1: 4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n6 2 2 3\n1 7 5\n\nSAMPLE",
"output": "Case #1: 4\n",
"type": "stdin_stdout"... |
code_contests | verifiable_code | tic-tac-toe | Solve the following coding problem using the programming language python:
King Tle4Ever of Time Limit Exceeded is really fascinated about Tic Tac Toe. He organizes a national level contest for Tic Tac Toe every year in Time Limit Exceeded. (Though I agree you need to be really stupid to loose a game of Tic Tac Toe but... | ```python
t = input()
mod = 1000000007
while t!=0:
n = input()
n %= mod
maxx = ((2*n-1)*(n-1)*n)/6
maxx %= mod
m = ((n-1)*n)/2
minwins = m/n
carry = m%n;
minn = (n-carry)*minwins*minwins
minn %= mod
minwins += 1
minn += carry*minwins*minwins
minn %= mod
print str(minn) + " " + str(maxx)
t -= 1
``` | vfc_74901 | {
"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\n5\n\nSAMPLE",
"output": "3 5\n20 30\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1\n5\n\nSAMPLE",
"output": "0 0\n20 30\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | p00109 Smart Calculator | Solve the following coding problem using the programming language python:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, add... | ```python
from collections import deque
priority = {"*":1,"/":1, "+":0, "-":0, "(":-1, ")":-1}
n = int(input())
for i in range(n):
s = input()
out = []
ope = deque([])
for j in range(len(s)):
inp = s[j]
if inp == "=":
while len(ope):
out.append(ope.pop())
... | vfc_74949 | {
"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\n4-2*3=\n4*(8+4+3)=",
"output": "-2\n60",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n4-2*3=\n8*(4+4+3)=",
"output": "-2\n88\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | p00243 Filling Game | Solve the following coding problem using the programming language python:
The tablet interface technology, which can be operated by touching the screen with a finger, has also been applied in the field of games, and various types of games with new operability have been created. The game currently being developed by AZ... | ```python
def paintout_graph(s, g, color):
cnt, pre_color = 0, s[0]
que = [0]
for pos in que:
if s[pos] == pre_color:
s[pos] = color
cnt +=1
que.extend(g[pos])
return cnt
def bfs(s, graph):
que = deque([(s,0,0)])
while True:
s,pre_cnt,depth = q... | vfc_74953 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\nR G B\nG G G\nG B B\n2 4\nR G\nG G\nR B\nB R\n4 3\nG G B R\nG R R G\nB G G R\n0 0",
"output": "2\n4\n4",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00424 Data Conversion | Solve the following coding problem using the programming language python:
Create a program that converts data based on the given conversion table.
The characters used in the data are letters or numbers, and the letters are case sensitive. There is no regularity in the order of the characters that appear in the conver... | ```python
n=int(input())
while(n!=0):
list={}
sum=""
for i in range(n):
a,b=input().split()
list[a]=b.rstrip()
n=int(input())
for i in range(n):
s=input().rstrip()
if s in list:
sum+=list[s]
else:
sum+=s
print(sum)
n=int(input()... | vfc_74957 | {
"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\nA a\n0 5\n5 4\n10\nA\nB\nC\n0\n1\n4\n5\na\nb\nA\n3\nA a\n0 5\n5 4\n10\nA\nB\nC\n0\n1\n4\n5\na\nb\nA\n0",
"output": "aBC5144aba\naBC5144aba",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00619 Kuru-Kuru Robot | Solve the following coding problem using the programming language python:
Dr. Asimov, a robotics researcher, has succeeded in developing a new robot. The robot can move freely along a special wire stretched around the floor. The robot always moves forward in a direction parallel to the current wire.
The good news is ... | vfc_74961 | {
"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": "8\n1 3 11 3\n5 3 13 11\n10 10 17 10\n11 2 11 6\n10 5 14 5\n13 6 13 2\n17 10 17 3\n13 3 19 3\n1 3 19 3\n6\n1 3 11 3\n5 3 13 11\n10 10 17 10\n11 2 11 6\n10 5 14 5\n13 3 19 3\n1 3 19 3\n2\n0 0 7 0\n3 0 7 3\n0 0 7 3\n0",
"output"... | |
code_contests | verifiable_code | p00895 The Sorcerer's Donut | Solve the following coding problem using the programming language python:
Your master went to the town for a day. You could have a relaxed day without hearing his scolding. But he ordered you to make donuts dough by the evening. Loving donuts so much, he can't live without eating tens of donuts everyday. What a chore ... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split... | vfc_74969 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 7\nRRCABXT\nAABMFAB\nRROMJAC\nAPTADAB\nYABADAO\n3 13\nABCDEFGHIJKLM\nXMADAMIMADAMY\nACEGIKMOQSUWY\n3 4\nDEFG\nACAB\nHIJK\n3 6\nABCDEF\nGHIAKL\nMNOPQR\n10 19\nJFZODYDXMZZPEYTRNCW\nXVGHPOKEYNZTQFZJKOD\nEYEHHQKHFZOVNRGOOLP\nQFZOIHRQ... |
code_contests | verifiable_code | p01159 Autocorrelation Function | Solve the following coding problem using the programming language python:
Nathan O. Davis is taking a class of signal processing as a student in engineering. Today’s topic of the class was autocorrelation. It is a mathematical tool for analysis of signals represented by functions or series of values. Autocorrelation g... | vfc_74977 | {
"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 1\n0 0\n1 1\n2 0\n11 1.5\n0 0\n2 7\n5 3\n7 8\n10 -5\n13 4\n15 -1\n17 3\n20 -7\n23 9\n24 0\n0 0",
"output": "0.166666666666667\n165.213541666667",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01298 Water Tank | Solve the following coding problem using the programming language python:
You built an apartment. The apartment has a water tank with a capacity of L in order to store water for the residents. The tank works as a buffer between the water company and the residents.
It is required to keep the tank "not empty" at least ... | ```python
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N, L = map(int, readline().split())
if N == 0:
return False
ma = 0
P = [list(map(int, readline().split())) for i in range(N)]
ma = max(u for s, t, u in P)
K = 86400
EPS = 1e-8
def check(x, M... | vfc_74981 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 100\n0 86400 1\n1 100\n43200 86400 1\n0 0",
"output": "1.000000\n0.997685",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 100\n0 86400 1\n1 110\n43200 86400 1\n0 0",
"output": "0.9... |
code_contests | verifiable_code | p01467 A-B Problem | Solve the following coding problem using the programming language python:
Problem statement
There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below.
1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1}... | ```python
def solve(C,K,i,borrow):
if i == -1:
return int("".join(map(str,C)))
if A[i] - borrow >= B[i]:
C[i] = A[i] - borrow - B[i]
return solve(C,K,i-1,0)
else:
C[i] = A[i] - borrow + 10 - B[i]
if K > 0:
return max(solve(C,K-1,i-1,0),solve(C,K,i-1,1))
else:
return solve(C,K,i-1,1)
A,B,K = raw_in... | vfc_74985 | {
"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": "538 84 1",
"output": "554",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2012 1987 1",
"output": "1025",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | p01627 Seishun 18 Kippu 2013 | 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 does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can rid... | ```python
N,T=map(int,input().split())
a,b,s,name1=input().split()
def func(s):
a=s[:2]
b=s[3:]
return int(a)*60+int(b)
s=func(s)
l=[]
for i in range(N-1):
t,name1,s2,name2=input().split()
t=func(t)
s2=func(s2)
if t-s>=T:
l.append([name1,t-s])
s=s2
print(len(l))
for i,j in l:
... | vfc_74989 | {
"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": "8 24\n05:30 Kyoto 06:37 Maibara\n06:50 Maibara 07:36 Tsuruga\n07:42 Tsuruga 10:03 Kanazawa\n10:58 Kanazawa 12:07 Toyama\n12:15 Toyama 14:12 Naoetsu\n14:29 Naoetsu 15:57 Nagaoka\n16:11 Nagaoka 17:14 Niitsu\n17:38 Niitsu 20:06 AizuWa... |
code_contests | verifiable_code | p01779 Typing Game | Solve the following coding problem using the programming language python:
H: Typing Game / Typing Game
story
From here, it's time to train your typing skills. Can you type quickly and accurately? Let ’s enjoy Typing Game!
problem
As a typing game game system, create a program that operates interactively with respe... | vfc_74993 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "",
"output": "",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01913 Islands Survival | Solve the following coding problem using the programming language python:
problem
There is a simple concatenated undirected graph with $ N $ vertices and $ M $ edges. The vertices are numbered $ 1, 2, \ dots, N $. The edges are numbered $ 1, 2, \ dots, M $, and the edge $ i $ connects the vertices $ a_i $ and $ b_i $... | vfc_74997 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4 2\n1 2 2\n2 3 1\n1 4 2\n4 5 1",
"output": "8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 4 2\n1 2 2\n4 3 1\n1 4 2\n4 5 1",
"output": "8\n",
"type": "stdin_stdout"
}... | |
code_contests | verifiable_code | p02052 Hokkaido University Easy | Solve the following coding problem using the programming language python:
A: Hokkaido University Easy
Note
Please note that the problem settings are the same as problem B, except for the constraints.
story
Homura-chan, who passed Hokkaido University and is excited about the beginning of a new life. But in front of... | ```python
H, W = map(int, input().split())
lst = [list(input()) for _ in range(H)]
ans = 0
for ia in range(H):
for ja in range(W):
for ib in range(H):
for jb in range(W):
if lst[ia][ja] == 'B' and lst[ib][jb] == 'B':
tmp = abs(ia-ib) + abs(ja-jb)
... | vfc_75001 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\nB.B\n..B\n.BB",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\nA.B\n..B\n.BB",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | p02194 Zero AND Subsets | Solve the following coding problem using the programming language python:
Zero AND Subsets
Given a multiset of nonnegative integers a_1, a_2, .., a_N.
How many non-empty subsets of this set have a value bitwiseAND of 0?
Find the remainder of the answer divided by 10 ^ 9 + 7.
input
N
a_1 a_2 ... a_N
output
Div... | vfc_75005 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 1073741824,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n8 6 9 1 2 1",
"output": "51",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n13 6 9 1 2 1",
"output": "44\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p02348 Range Update Query (RUQ) | Solve the following coding problem using the programming language python:
Write a program which manipulates a sequence A = {a0, a1, . . . , an−1} with the following operations:
* update(s, t, x): change as, as+1, ..., at to x.
* find(i): output the value of ai.
Note that the initial values of ai (i = 0, 1, . . . ,... | ```python
import sys
# 区間更新一点取得
class RangeUpdateQuery:
def __init__(self, n, initial=2 ** 31 - 1):
self.n = 1 << (n - 1).bit_length()
self.INT = (-1, initial)
# 更新時刻, 値
self.segtree = [self.INT] * (2 * self.n)
# 区間[l, r)をv(時刻, 値)で更新
def update(self, l, r, v):
L, R... | vfc_75009 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\n0 0 1 1\n0 1 2 3\n0 2 2 2\n1 0\n1 1",
"output": "1\n3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 3\n1 0\n0 0 0 5\n1 0",
"output": "2147483647\n5",
"type": "stdin_stdo... |
code_contests | verifiable_code | chearmy | Solve the following coding problem using the programming language python:
The Head Chef is receiving a lot of orders for cooking the best of the problems lately. For this, he organized an hiring event to hire some talented Chefs. He gave the following problem to test the skills of the participating Chefs. Can you solv... | ```python
t=int(raw_input())
for i in range(t):
n=int(raw_input())-1
st=''
while(n>=5):
st=str(n%5)+st
n=n//5
st=str(n)+st
print(2*int(st))
``` | vfc_75013 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n5",
"output": "2\n8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2\n3",
"output": "2\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | devhand | Solve the following coding problem using the programming language python:
As you have probably realized up to now that Devu is not a normal guy, he is a very weird and abnormal guy. Normally people have two hands, but Devu has three of them. So he wears three wrist watches on his hands.
Devu loves to write name of h... | ```python
def power(a,b):
x=1
while(b):
if(b&1):
x=(x*a)%m
a=(a*a)%m
b>>=1
return x
m=10**9+7
t=int(raw_input())
while t>0:
t-=1
n,k=map(int,raw_input().split())
if k==1:
print 0
continue
inv=power(k-1,m-2)
inv=power(inv,3)
inv=(k*i... | vfc_75017 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2\n1 3\n2 2",
"output": "0\n6\n36",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | iitk2p10 | Solve the following coding problem using the programming language python:
Chef was feeling bored so he decided to create a pattern to play with. His pattern always has 1 as its first element. Then he chooses a number K as the second element. After selecting K as his second number he creates next element in the patter... | ```python
mod=int(10**9+7)
t=int(input())
while t>0:
t-=1
b,a=map(int,raw_input().split())
if a==1:
print 1
elif a==2:
print b
else:
c=pow(2,a-3,mod-1)
print pow(b,c,mod)
``` | vfc_75021 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 2\n3 4",
"output": "2\n9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 2\n3 4",
"output": "1\n9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | neuronb4 | Solve the following coding problem using the programming language python:
Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for example, 22344. Similarly if no digit is exceeded by the digit to its right it is called a decreasing number; for example, 774410 ... | ```python
T=input()
while T:
T-=1
inv=0
N=list(str(input()))
length=len(N)
for i in range(0,length):
N[i]=int(N[i])
i=0
while i<length-1 and N[i+1]==N[i]:
i+=1
if i==length-1:
print 'valid'
continue
if N[i+1]>N[i]:
while i<length-1 and N[i+1]>=... | vfc_75025 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n1\n2\n3\n4\n5\n6\n150",
"output": "valid\nvalid\nvalid\nvalid\nvalid\nvalid\ninvalid",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n1\n2\n6\n4\n5\n6\n150",
"output": "valid\nval... |
code_contests | verifiable_code | saarc07 | Solve the following coding problem using the programming language python:
Problem description.
Tic-tac-toe is the third most popular activity to kill a lazy afternoon in Ardenia.Arthum and Breece are not fans of this game, but their mother told them to play, so they sit at a 5 x 5 board. Both have a large pile of marb... | ```python
import sys;
aw=False;
bw=False;
def main():
tc=int(raw_input().strip());
for x in range(tc):
global aw;
global bw;
aw=False;
bw=False;
board=[];
for y in range(5):
board.append(raw_input().strip());
checkHorizontal(board);
checkVertical(board);
checkDiagonal(board);
global aw;
glob... | vfc_75029 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nAABBA\nBAAAB\nAAABA\nABAAB\nBAAAB\nAAAAA\nAAAAA\nBAAAA\nABAAA\nAABAA",
"output": "A wins\ndraw",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | xorsub | Solve the following coding problem using the programming language python:
You have an array of integers A1, A2, ..., AN. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)
Given an integer K, what is the m... | ```python
def ContainsBit(mask, i):
return mask & (1 << i) > 0
def GaussianElimination(values, n):
values.sort(reverse=True)
bit = max(i if ContainsBit(values[0], i) else 0 for i in xrange(11))
start = 0
for b in xrange(bit, -1, -1):
j = -1
for i in xrange(start, n):
if ContainsBit(values[i], b... | vfc_75033 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3 4\n1 2 3",
"output": "7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3 4\n0 2 3",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | 1023_F. Mobile Phone Network | Solve the following coding problem using the programming language python:
You are managing a mobile phone network, and want to offer competitive prices to connect a network.
The network has n nodes.
Your competitor has already offered some connections between some nodes, with some fixed prices. These connections are... | vfc_75037 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2 1\n1 2\n2 3\n1 2 30\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3 3\n1 2\n1 3\n1 4\n4 1 1000000000\n4 2 1000000000\n4 3 1000000000\n",
"output": "30000000... | |
code_contests | verifiable_code | 1045_A. Last chance | Solve the following coding problem using the programming language python:
It is the year 2969. 1000 years have passed from the moon landing. Meanwhile, the humanity colonized the Hyperspace™ and lived in harmony.
Until we realized that we were not alone.
Not too far away from the Earth, the massive fleet of aliens' ... | vfc_75041 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 128000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\n0 1 4\n2 5 4 1\n1 1 4\n",
"output": "4\n2 1\n3 3\n1 4\n2 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "47 123\n0 1 33\n0 1 92\n2 33 41 22\n0 1 107\n0 1 34\n2 118 52 61\n0 1 24\n2 ... | |
code_contests | verifiable_code | 1068_A. Birthday | Solve the following coding problem using the programming language python:
Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms:
* Everyone must gift as man... | ```python
N, M, K, L = map(int, input().split())
if N < M or K + L > N:
print(-1)
else:
print((L + K - 1) // M + 1 if ((L + K - 1) // M + 1) * M <= N else -1)
``` | vfc_75045 | {
"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": "10 11 2 4\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 108_D. Basketball Team | Solve the following coding problem using the programming language python:
As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC).
A team is to be formed of n players, all of which a... | ```python
import sys
import math
n,m,h = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
total = sum(arr)
if (total < n):
print ("-1")
sys.exit()
total1 = total - arr[h-1]
rem = total - total1-1
total = total - 1
ans = 1
'''
#start = total - (n-1)
#print (start)
x = start
#print (rem... | vfc_75049 | {
"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 2 1\n1 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2 1\n2 2\n",
"output": "0.6666666667\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1138_F. Cooperative Game | Solve the following coding problem using the programming language python:
This is an interactive problem.
Misha likes to play cooperative games with incomplete information. Today he suggested ten his friends to play a cooperative game "Lake".
Misha has already come up with a field for the upcoming game. The field fo... | vfc_75057 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 05 12346789\n\n3 246789 135 0\n\n3 246789 0 135\n\n3 246789 0 135\n\n2 135 0246789\n\n1 0123456789\n",
"output": "next 0 1\nnext 0\nnext 0 1\nnext 0\nnext 0 1\nnext 0\nnext 0 1 2 3 4 5 6 7 8 9\ndone\n",
"type": "stdin... | |
code_contests | verifiable_code | 1179_B. Tolik and His Uncle | Solve the following coding problem using the programming language python:
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a proble... | ```python
inp = list(map(int,input().split(" ")))
n = int(inp[0])
m = int(inp[1])
x = 1
y = 1
cells = n * m
up = n
down = 1
upiter = m
downiter = 1
flag = 0
count = 0
Ans = []
while(up >= down):
# print("up and down are ", up, down)
while(upiter >= 1 or downiter <= m):
if(flag == 0):
# print(str(down) + " "... | vfc_75065 | {
"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": "1 1\n",
"output": "1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n",
"output": "1 1\n2 3\n1 2\n2 2\n1 3\n2 1\n",
"type": "stdin_stdout"
},
{
"fn_name": ... |
code_contests | verifiable_code | 1197_D. Yet Another Subarray Problem | Solve the following coding problem using the programming language python:
You are given an array a_1, a_2, ... , a_n and two integers m and k.
You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r.
The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to ∑_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) ⌉, where... | ```python
#Bhargey Mehta (Junior)
#DA-IICT, Gandhinagar
import sys, math, queue
#sys.stdin = open('input.txt', 'r')
MOD = 998244353
sys.setrecursionlimit(1000000)
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
dp = [[-10**20 for i in range(m)] for i in range(n)]
dp[0][0] = a[0]-k
for i in ra... | vfc_75069 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 3 10\n2 -4 15 -3 4 8 3\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2 1000\n-13 -4 -9 -20 -11\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 1214_E. Petya and Construction Set | Solve the following coding problem using the programming language python:
It's Petya's birthday party and his friends have presented him a brand new "Electrician-n" construction set, which they are sure he will enjoy as he always does with weird puzzles they give him.
Construction set "Electrician-n" consists of 2n -... | ```python
# https://codeforces.com/contest/1214/problem/E
n = int(input())
d = map(int, input().split())
d = [[2*i+1, di] for i, di in enumerate(d)]
d = sorted(d, key=lambda x:x[1], reverse = True)
edge = []
arr = [x[0] for x in d]
for i, [x, d_] in enumerate(d):
if i + d_ - 1 == len(arr) - 1:
arr.appen... | vfc_75073 | {
"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\n2 2 2 1\n",
"output": "5 3\n3 1\n1 7\n3 6\n1 4\n7 2\n7 8\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1255_F. Point Ordering | Solve the following coding problem using the programming language python:
This is an interactive problem.
Khanh has n points on the Cartesian plane, denoted by a_1, a_2, …, a_n. All points' coordinates are integers between -10^9 and 10^9, inclusive. No three points are collinear. He says that these points are vertice... | vfc_75081 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n\n15\n\n-1\n\n1",
"output": "2 1 2 3\n2 1 2 4\n2 1 4 5\n2 1 4 6\n1 1 4 2\n1 1 4 3\n1 1 4 5\n1 1 4 6\n2 1 6 2\n2 1 6 3\n2 1 6 5\n0 1 4 6 5 3 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... | |
code_contests | verifiable_code | 1279_F. New Year and Handle Change | Solve the following coding problem using the programming language python:
New Year is getting near. So it's time to change handles on codeforces. Mishka wants to change his handle but in such a way that people would not forget who he is.
To make it work, he only allowed to change letters case. More formally, during o... | ```python
import sys
range = xrange
input = raw_input
n,k,l = [int(x) for x in input().split()]
S = [+(c<'a') for c in input()]
def solve2(cutoff, cumsum):
DP = [0.0]*n
count = [0]*n
for i in range(n):
end = i + l if i + l < n else n - 1
inc = cumsum[end] - cumsum[i] - cutoff
if in... | vfc_75085 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9 2 2\naAaAAAaaA\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "14 2 6\naBcdEFGHIJklMn\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name... |
code_contests | verifiable_code | 129_D. String | Solve the following coding problem using the programming language python:
One day in the IT lesson Anna and Maria learned about the lexicographic order.
String x is lexicographically less than string y, if either x is a prefix of y (and x ≠ y), or there exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi, and for any... | ```python
from heapq import *
l=input()
k=int(input())
n=len(l)
if k>n*(n+1)/2:
print("No such line.")
quit()
ss=[(l[i],i) for i in range(n)]
heapify(ss)
while k:
k-=1
t=heappop(ss)
if k==0:
print(t[0])
else:
if t[1]<n-1:
heappush(ss,(t[0]+l[t[1]+1],t[... | vfc_75089 | {
"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": "aa\n2\n",
"output": "a\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "abc\n5\n",
"output": "bc\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "a... |
code_contests | verifiable_code | 1323_A. Even Subset Sum Problem | Solve the following coding problem using the programming language python:
You are given an array a consisting of n positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by 2) or determine that there is no such subset.
Both the given array and required subset may contai... | ```python
for x in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
b=[]
i=0
count=0
s=0
while i<n:
if a[i]%2==0:
count=1
s=i
break
else:
b.append(i)
i+=1
if count==1:
print(1)
pri... | vfc_75093 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3\n1 4 3\n1\n15\n2\n3 5\n",
"output": "1\n2\n-1\n2\n1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2\n1 1\n",
"output": "2\n1 2\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 1341_F. Nastya and Time Machine | Solve the following coding problem using the programming language python:
Denis came to Nastya and discovered that she was not happy to see him... There is only one chance that she can become happy. Denis wants to buy all things that Nastya likes so she will certainly agree to talk to him.
The map of the city where ... | vfc_75097 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2\n2 3\n2 4\n4 5\n",
"output": "13\n1 0\n2 1\n3 2\n3 1\n2 2\n4 3\n4 1\n5 2\n5 1\n4 2\n2 3\n2 0\n1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13\n1 7\n1 12\n3 1\n6 1\n1 4\n5 1\n... | |
code_contests | verifiable_code | 1426_E. Rock, Paper, Scissors | Solve the following coding problem using the programming language python:
Alice and Bob have decided to play the game "Rock, Paper, Scissors".
The game consists of several rounds, each round is independent of each other. In each round, both players show one of the following things at the same time: rock, paper or sc... | ```python
def maximum_wins(a1,a2,a3,rock,scissor,paper):
ans=0
mini1=min(a1,scissor)
ans+=mini1
scissor-=mini1
mini2=min(a2,paper)
ans+=mini2
paper-=mini2
mini3=min(a3,rock)
rock-=mini3
ans+=mini3
return ans
def minimum_wins(rock,paper,scissor,a1,a2,a3):
return max(0,a1-... | vfc_75113 | {
"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\n0 0 3\n3 0 0\n",
"output": "3 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n0 1 1\n1 1 0\n",
"output": "0 1\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | 1473_D. Program | Solve the following coding problem using the programming language python:
You are given a program that consists of n instructions. Initially a single variable x is assigned to 0. Afterwards, the instructions are of two types:
* increase x by 1;
* decrease x by 1.
You are given m queries of the following for... | ```python
import sys
for iter in range(int(sys.stdin.readline())):
n, m = map(int, sys.stdin.readline().split())
s = input()
balance = [0] * (n + 1)
for i in range(n):
if s[i] == '+':
balance[i + 1] = balance[i] + 1
else:
balance[i + 1] = balance[i] - 1
max_p... | vfc_75121 | {
"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\n8 4\n-+--+--+\n1 8\n2 8\n2 5\n1 1\n4 10\n+-++\n1 1\n1 2\n2 2\n1 3\n2 3\n3 3\n1 4\n2 4\n3 4\n4 4\n",
"output": "\n1\n2\n4\n4\n3\n3\n4\n2\n3\n2\n1\n2\n2\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | 1499_F. Diameter Cuts | Solve the following coding problem using the programming language python:
You are given an integer k and an undirected tree, consisting of n vertices.
The length of a simple path (a path in which each vertex appears at most once) between some pair of vertices is the number of edges in this path. A diameter of a tree ... | ```python
import sys
from collections import deque
input = lambda :sys.stdin.buffer.readline()
mi = lambda :map(int,input().split())
li = lambda :list(mi())
mod = 998244353
N,K = mi()
edge = [[] for i in range(N)]
for _ in range(N-1):
a,b = mi()
edge[a-1].append(b-1)
edge[b-1].append(a-1)
parent = [-1 f... | vfc_75125 | {
"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": "2 0\n1 2\n",
"output": "\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 3\n1 2\n1 5\n2 3\n3 4\n5 6\n",
"output": "\n29\n",
"type": "stdin_stdout"
},
{
"fn_n... |
code_contests | verifiable_code | 1550_D. Excellent Arrays | Solve the following coding problem using the programming language python:
Let's call an integer array a_1, a_2, ..., a_n good if a_i ≠ i for each i.
Let F(a) be the number of pairs (i, j) (1 ≤ i < j ≤ n) such that a_i + a_j = i + j.
Let's say that an array a_1, a_2, ..., a_n is excellent if:
* a is good;
* l ... | ```python
import sys
input = sys.stdin.readline
mod = 10 ** 9 + 7
for t in range(int(input())):
n, l, r = map(int, input().split())
F = [0] * (n + 1)
F[0] = 1
for i in range(1, n + 1):
F[i] = i * F[i - 1] % mod
iF = [0] * (n + 1)
iF[-1] = pow(F[-1], mod - 2, mod)
for i in range(n - ... | vfc_75133 | {
"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\n3 0 3\n4 -3 5\n42 -33 55\n69 -42 146\n",
"output": "4\n10\n143922563\n698570404\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n167208 -643096130 843266036\n",
"output": "95736... |
code_contests | verifiable_code | 197_D. Infinite Maze | Solve the following coding problem using the programming language python:
We've got a rectangular n × m-cell maze. Each cell is either passable, or is a wall (impassable). A little boy found the maze and cyclically tiled a plane with it so that the plane became an infinite maze. Now on this plane cell (x, y) is a wall... | vfc_75141 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4\n##.#\n##S#\n#..#\n..#.\n#.##\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 4\n##.#\n##S#\n#..#\n#.##\n#..#\n",
"output": "Yes\n",
"type": "stdin_stdo... | |
code_contests | verifiable_code | 220_E. Little Elephant and Inversions | Solve the following coding problem using the programming language python:
The Little Elephant has array a, consisting of n positive integers, indexed from 1 to n. Let's denote the number with index i as ai.
The Little Elephant wants to count, how many pairs of integers l and r are there, such that 1 ≤ l < r ≤ n and s... | ```python
'''
Created on 19/07/2018
@author: ernesto
'''
# XXX: http://codeforces.com/problemset/problem/220/E
# XXX: https://practice.geeksforgeeks.org/problems/magic-triplets/0
# XXX: https://gist.github.com/robert-king/5660418
class RangeBit:
def __init__(self, n):
sz = 1
while n >= sz:
... | vfc_75145 | {
"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 1\n1 3 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n1 3 2 1 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 245_A. System Administrator | Solve the following coding problem using the programming language python:
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to ... | ```python
n = int(input())
ab = [0,0]
for i in range(n):
t,x,y = map(int,input().split())
ab[t-1]+=x-y
print('LIVE' if ab[0]>=0 else 'DEAD')
print('LIVE' if ab[1]>=0 else 'DEAD')
``` | vfc_75149 | {
"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": "2\n1 5 5\n2 6 4\n",
"output": "LIVE\nLIVE\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 26_D. Tickets | Solve the following coding problem using the programming language python:
As a big fan of Formula One, Charlie is really happy with the fact that he has to organize ticket sells for the next Grand Prix race in his own city. Unfortunately, the finacial crisis is striking everywhere and all the banknotes left in his cou... | ```python
# METO Bot 0.9.9
n,m,k=map(int,input().split())
if k<m<=k+n:
t=1
for i in range(k+1):
t*=(m-i)/(n+k-(i-1))
print(1-t)
else:
print(0 if m>n+k else 1)
``` | vfc_75153 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3 1\n",
"output": "0.857142857143\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 1 0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 293_A. Weird Game | Solve the following coding problem using the programming language python:
Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game.
Roman leaves a word for each of them. Each word consists of 2·n binary characters "... | ```python
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write i... | vfc_75157 | {
"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\n110110\n001001\n",
"output": "First\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n0111\n0001\n",
"output": "First\n",
"type": "stdin_stdout"
},
{
"fn_name... |
code_contests | verifiable_code | 316_G2. Good Substrings | Solve the following coding problem using the programming language python:
Smart Beaver recently got interested in a new word game. The point is as follows: count the number of distinct good substrings of some string s. To determine if a string is good or not the game uses rules. Overall there are n rules. Each rule is... | vfc_75161 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "aaab\n2\naa 0 0\naab 1 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "ltntlnen\n3\nn 0 0\nttlneenl 1 4\nlelllt 1 1\n",
"output": "2\n",
"type": "stdin_stdou... | |
code_contests | verifiable_code | 340_D. Bubble Sort Graph | Solve the following coding problem using the programming language python:
Iahub recently has learned Bubble Sort, an algorithm that is used to sort a permutation with n elements a1, a2, ..., an in ascending order. He is bored of this so simple algorithm, so he invents his own graph. The graph (let's call it G) initial... | ```python
def CeilIndex(A, l, r, key):
while (r - l > 1):
m = l + (r - l)//2
if (A[m] >= key):
r = m
else:
l = m
return r
def LongestIncreasingSubsequenceLength(A, size):
# Add boundary case,
# when array size is one
tail... | vfc_75165 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n4 2 1 3 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | 364_A. Matrix | Solve the following coding problem using the programming language python:
You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is ... | ```python
a = int(input())
s = input()
d = {}
for i in range(len(s)):
for j in range(i, len(s)):
if j == i: t = int(s[j])
else: t += int(s[j])
d[t] = d.get(t, 0) + 1
if a == 0:
if 0 in d:
cnt_pairs = (len(s) * (len(s) + 1)) // 2
print((d[0] * cnt_pairs) + (d[0] * (cnt_pai... | vfc_75169 | {
"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": "10\n12345\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 408_C. Triangle | Solve the following coding problem using the programming language python:
There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integ... | ```python
def pitagoras(k):
casos_possiveis = []
for n in range(1,k):
m = int((k**2 - n**2)**(0.5))
if((n**2 + m**2) == k**2):
casos_possiveis.append([n, m])
return casos_possiveis
def possivelRepresntar(k):
for n in range(1, k):
m = int((k**2 - n**2)**(0.5))
... | vfc_75177 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\n",
"output": "NO",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 435_D. Special Grid | Solve the following coding problem using the programming language python:
You are given an n × m grid, some of its nodes are black, the others are white. Moreover, it's not an ordinary grid — each unit square of the grid has painted diagonals.
The figure below is an example of such grid of size 3 × 5. Four nodes of t... | vfc_75181 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n11\n11\n",
"output": " 0\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 47_D. Safe | Solve the following coding problem using the programming language python:
Vasya tries to break in a safe. He knows that a code consists of n numbers, and every number is a 0 or a 1. Vasya has made m attempts to enter the code. After each attempt the system told him in how many position stand the right numbers. It is n... | ```python
import os,io
from sys import stdout
# import collections
# import random
# import math
# from operator import itemgetter
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# from collections import Counter
# from decimal import Decimal
# import heapq
# from functools import lru_cache
# import sys
# ... | vfc_75189 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 3\n000000 2\n010100 4\n111100 2\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 3\n000000 2\n010100 4\n111100 0\n",
"output": "0",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 504_D. Misha and XOR | Solve the following coding problem using the programming language python:
After Misha's birthday he had many large numbers left, scattered across the room. Now it's time to clean up and Misha needs to put them in a basket. He ordered this task to his pet robot that agreed to complete the task at certain conditions. Be... | ```python
m = int(input())
values = []
idx = []
for i in range(m):
x = int(input())
ans = 0
for j,xx in enumerate(values):
if (xx^x) < x:
x^=xx
ans^=idx[j]
if x == 0:
anss = []
for j in range(i):
if (ans&1)!=0:
anss.append(j)
... | vfc_75193 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n7\n6\n5\n4\n3\n2\n1\n",
"output": "0\n0\n0\n3 0 1 2\n2 1 2\n2 0 2\n2 0 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n5\n5\n",
"output": "0\n1 0\n",
"type": "stdin_std... |
code_contests | verifiable_code | 528_B. Clique Problem | Solve the following coding problem using the programming language python:
The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph G. It is required to find a subset of vertices C of the maximum size such that any two... | ```python
import sys
readline = sys.stdin.readline
def main():
N = int(input())
itvs = []
for _ in range(N):
x, w = map(int, input().split())
itvs.append((x - w, x + w))
itvs.sort(key=lambda x: x[1])
ans = 0
end = -(10**9 + 1)
for l, r in itvs:
if end <= l:
... | vfc_75197 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 3\n3 1\n6 1\n0 2\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.