problem_spec stringlengths 29 9.53k | correct_answer stringlengths 46 289k | corrupted_answer stringlengths 32 289k | tests stringlengths 108 51.6M | applied_mutations listlengths 1 12 |
|---|---|---|---|---|
Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are n destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilometer 0. The n destinations are described by a non-negative integers sequence a_1, a_2, ..., a_{n}. The number a_{k} repr... | ```python
from fractions import *
def solve():
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans1 = 0
pres = a[0]
for i in range(1, n):
ans1 += i * a[i] - pres
pres += a[i]
ans1 *= 2
tmp = pres + ans1
tmp1 = n
s = Fraction(tmp, tmp1)
print(s.... | from fractions import *
def solve():
n = int(input())
a = list(map(int, input().split()))
a.sort(ascending=False)
ans1 = 0
pres = a[1]
for i in range(1, n - 1, 2):
ans1 += i * a[i] - pres
pres += a[i]
ans1 *= 3
tmp = pres - ans1
tmp1 = n
s = Fraction(tmp, tmp1)
... | [{"type": "stdin_stdout", "input": "3\n2 3 5\n", "output": "22 3"}, {"type": "stdin_stdout", "input": "4\n1 5 77 2\n", "output": "547 4"}, {"type": "stdin_stdout", "input": "5\n3 3842 288 199 334\n", "output": "35918 5"}, {"type": "stdin_stdout", "input": "7\n1 2 3 40 52 33 86\n", "output": "255 1"}, {"type": "stdin_st... | [
"mutate_numeric_constants",
"mutate_list_indexing",
"mutate_range_bounds",
"mutate_sort_order",
"mutate_arithmetic_operators",
"mutate_range_step"
] |
You are given a square matrix of size n. Every row and every column of this matrix is a permutation of 1, 2, …, n. Let a_{i, j} be the element at the intersection of i-th row and j-th column for every 1 ≤ i, j ≤ n. Rows are numbered 1, …, n top to bottom, and columns are numbered 1, …, n left to right.
There are six t... | ```python
import sys, io, os
Z = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
Y = lambda: [*map(int, Z().split())]
def I(M):
n = len(M)
nM = [[0] * n for i in range(n)]
for x in range(n):
for y in range(n):
nM[x][M[x][y] - 1] = y + 1
return nM
def C(M):
n = len(M)
... | import sys, io, os
Z = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
Y = lambda: [*map(int, Z().split())]
def I(M):
n = len(M)
nM = [[0] // n for i in range(n)]
for x in range(n + 1, 2):
for y in range(n):
nM[x][M[x][y]] = y + 1
return nM
def C(M):
n = len(M)
nM =... | [{"type": "stdin_stdout", "input": "5\n3 2\n1 2 3\n2 3 1\n3 2 2\nDR\n3 2\n1 2 3\n2 3 1\n3 1 2\nLU\n3 1\n1 2 3\n2 3 1\n3 1 2\nI\n3 1\n1 2 3\n2 3 1\n3 1 2\nC\n3 16\n1 2 3\n2 3 1\n3 1 2\nLDICRUCILDICRUCI\n", "output": "2 3 2\n3 1 2\n1 2 3\n3 1 2\n1 2 3\n2 3 1\n1 2 3\n3 1 2\n2 3 1\n1 3 2\n2 1 3\n3 2 1\n2 3 1\n3 1 2\n1 2 3\... | [
"mutate_range_step",
"mutate_range_bounds",
"mutate_arithmetic_operators",
"mutate_list_indexing"
] |
Consider the following series:
`1, 2, 4, 8, 16, 22, 26, 38, 62, 74, 102, 104, 108, 116, 122`
It is generated as follows:
* For single digit integers, add the number to itself to get the next element.
* For other integers, multiply all the non-zero digits and add the result to the original number to get the next elem... | ```python
from operator import mul
from functools import reduce
def genSequence(n):
yield n
while True:
n += reduce(mul, [int(d) for d in str(n) if d != "0"]) if n > 9 else n
yield n
def extract(seq, v):
return sorted(seq).index(v)
def convergence(n):
(gen1, genN) = (genSequence(1)... | from operator import mul
from functools import reduce
def genSequence(n):
yield n
while False:
n += reduce(mul, [int(d) for d in str(n) if d != "0"]) if n >= 8 else n
yield n
def extract(seq, v):
return sorted(seq).index(v)
def convergence(n):
gen1, genN = (genSequence(1), genSeque... | {"fn_name": "convergence", "inputs": [[3], [5], [10], [15], [500], [5000]], "outputs": [[5], [6], [5], [2], [29], [283]]} | [
"mutate_boolean_constants",
"mutate_numeric_constants",
"mutate_comparison_operators"
] |
On a weekend, Qingshan suggests that she and her friend Daniel go hiking. Unfortunately, they are busy high school students, so they can only go hiking on scratch paper.
A permutation $p$ is written from left to right on the paper. First Qingshan chooses an integer index $x$ ($1\le x\le n$) and tells it to Daniel. Aft... | ```python
n = int(input())
nums = list(map(int, input().split()))
left = [0] * n
right = [0] * n
for i in range(1, n):
if nums[i] > nums[i - 1]:
left[i] = left[i - 1] + 1
for i in range(n - 2, -1, -1):
if nums[i] > nums[i + 1]:
right[i] = right[i + 1] + 1
def main():
ml = max(left)
mr ... | n = int(input())
nums = list(map(int, input().split()))
left = [0] * n
right = [0] * n
for i in range(1, n):
if nums[i] > nums[i - 1]:
left[i] = left[i - 1] + 1
for i in range(n - 2, -1, -1):
if nums[i] > nums[i + 1]:
right[i] = right[i + 1] + 1
def main():
ml = min(left)
mr = max(righ... | [{"type": "stdin_stdout", "input": "5\n1 2 5 4 3\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "7\n1 2 4 6 5 3 7\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "7\n2 5 7 3 1 4 6\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "2\n1 2\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "7\... | [
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_range_bounds",
"mutate_conditional_inversion",
"mutate_numeric_constants",
"mutate_edge_case_guards",
"mutate_function_call_name",
"mutate_range_step"
] |
You are given a string of length N. Calculate the number of distinct substrings of S.
Constraints
* 1 \leq N \leq 500,000
* S consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
S
Output
Print the answer.
Examples
Input
abcbcba
Output
21
Input
missi... | ```python
class StrAlg:
@staticmethod
def sa_naive(s):
n = len(s)
sa = list(range(n))
sa.sort(key=lambda x: s[x:])
return sa
@staticmethod
def sa_doubling(s):
n = len(s)
sa = list(range(n))
rnk = s
tmp = [0] * n
k = 1
whil... | class StrAlg:
@staticmethod
def sa_naive(s):
n = len(s)
sa = list(range(n))
sa.sort(key=lambda x: s[x:])
return sa
@staticmethod
def sa_doubling(s):
n = len(s)
sa = list(range(n))
rnk = s
tmp = [0] * n
k = 1
while k < n:
... | [{"type": "stdin_stdout", "input": "abcacbb", "output": "24\n"}, {"type": "stdin_stdout", "input": "baaaa", "output": "9\n"}, {"type": "stdin_stdout", "input": "aaabacacb", "output": "37\n"}, {"type": "stdin_stdout", "input": "mjssissippi", "output": "57\n"}, {"type": "stdin_stdout", "input": "abbacbb", "output": "23\n... | [
"mutate_function_call_name",
"mutate_arithmetic_operators",
"mutate_numeric_constants"
] |
Mutual Recursion allows us to take the fun of regular recursion (where a function calls itself until a terminating condition) and apply it to multiple functions calling each other!
Let's use the Hofstadter Female and Male sequences to demonstrate this technique. You'll want to create two functions `F` and `M` such th... | ```python
def f(n):
return n - m(f(n - 1)) if n else 1
def m(n):
return n - f(m(n - 1)) if n else 0
``` | def f(n):
return n + m(f(n - 1)) if n else 1
def m(n):
return n - f(m(n - 1)) if n else 0 | [{"type": "function_call", "fn_name": "f", "input": [0], "output": [1]}, {"type": "function_call", "fn_name": "f", "input": [5], "output": [3]}, {"type": "function_call", "fn_name": "f", "input": [10], "output": [6]}, {"type": "function_call", "fn_name": "f", "input": [15], "output": [9]}, {"type": "function_call", "fn... | [
"mutate_arithmetic_operators"
] |
Implement `String#parse_mana_cost`, which parses [Magic: the Gathering mana costs](http://mtgsalvation.gamepedia.com/Mana_cost) expressed as a string and returns a `Hash` with keys being kinds of mana, and values being the numbers.
Don't include any mana types equal to zero.
Format is:
* optionally natural number re... | ```python
import re
def parse_mana_cost(mana):
n = {c: mana.lower().count(c) for c in "wubrg" if mana.lower().count(c) > 0}
m = re.split("\\D", mana)
if sum(n.values()) + sum([len(c) for c in m]) != len(mana):
return None
p = sum([int(c) for c in m if c != ""])
if p > 0:
n["*"] = p... | import re
def parse_mana_cost(mana):
n = {c: mana.lower().count(c) for c in "wubrg" if mana.lower().count(c) > 0}
m = re.split("\\D", mana)
if sum(n.values()) - sum([len(c) for c in m]) == len(mana):
return None
p = len([int(c) for c in m if c != ""])
if p > 1:
n["*"] = p
retur... | [{"type": "function_call", "fn_name": "parse_mana_cost", "input": [""], "output": [{}]}, {"type": "function_call", "fn_name": "parse_mana_cost", "input": ["0"], "output": [{}]}, {"type": "function_call", "fn_name": "parse_mana_cost", "input": ["1"], "output": [{"*": 1}]}, {"type": "function_call", "fn_name": "parse_man... | [
"mutate_edge_case_guards",
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_function_call_name"
] |
You are given an integer array a_1, a_2, ..., a_n, where a_i represents the number of blocks at the i-th position. It is guaranteed that 1 ≤ a_i ≤ n.
In one operation you can choose a subset of indices of the given array and remove one block in each of these indices. You can't remove a block from a position without b... | ```python
n = int(input())
v, c = list([[0, 0]]), list()
z = ["0" for i in range(n)]
for i, x in enumerate(input().split()):
v.append([int(x), i])
v.sort(reverse=True)
def S_N_U_F_F(z, v, c):
y, k, x, count = -1, 0, len(v) - 1, len(v) - 1
while v[0][0] != 0:
if k > 0 and k < len(v) - 1:
... | n = int(input())
v, c = (list([[0, 0]]), list())
z = ["0" for i in range(n)]
for i, x in enumerate(input().split()):
v.append([int(x), i])
v.sort(reverse=True)
def S_N_U_F_F(z, v, c):
y, k, x, count = (-1, 0, len(v) + 1, len(v) - 1)
while v[0][1] == 0:
if not k > 0 and k < len(v) - 1:
... | [{"type": "stdin_stdout", "input": "5\n4 1 5 3 4\n", "output": "6\n00100\n10100\n10101\n10111\n11111\n00011\n"}, {"type": "stdin_stdout", "input": "5\n5 1 1 1 1\n", "output": "6\n10000\n11000\n10100\n10010\n10001\n00000\n"}, {"type": "stdin_stdout", "input": "5\n5 5 5 5 5\n", "output": "6\n10111\n11011\n11101\n11110\n1... | [
"mutate_list_indexing",
"mutate_conditional_inversion",
"mutate_range_step",
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_range_bounds",
"mutate_numeric_constants"
] |
You a captain of a ship. Initially you are standing in a point $(x_1, y_1)$ (obviously, all positions in the sea can be described by cartesian plane) and you want to travel to a point $(x_2, y_2)$.
You know the weather forecast — the string $s$ of length $n$, consisting only of letters U, D, L and R. The letter corre... | ```python
x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
n = int(input())
s = input()
psx = [0 for i in range(n)]
psy = [0 for i in range(n)]
if s[0] == "L":
psx[0] = -1
elif s[0] == "R":
psx[0] = +1
if s[0] == "D":
psy[0] = -1
elif s[0] == "U":
psy[0] = +1
for i in range(1, n)... | x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
n = int(input())
s = input()
psx = [0 for i in range(n)]
psy = [0 for i in range(n)]
if s[0] == "L":
psx[0] = -1
elif s[0] == "R":
psx[0] = +1
if s[0] == "D":
psy[0] = -1
elif s[0] == "U":
psy[0] = +1
for i in range(1, n):
psx[i] ... | [{"type": "stdin_stdout", "input": "0 0\n4 6\n3\nUUU\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "0 3\n0 0\n3\nUDD\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "0 0\n0 1\n1\nL\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "0 0\n0 1\n2\nLU\n", "output": "2\n"}, {"type": "stdin_stdout", ... | [
"mutate_edge_case_guards",
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_list_indexing"
] |
We will call a non-negative integer increasing if, for any two adjacent digits in its decimal representation, the digit to the right is greater than or equal to the digit to the left. For example, 1558, 11, 3 and 0 are all increasing; 10 and 20170312 are not.
Snuke has an integer N. Find the minimum number of increasi... | ```python
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
"""
・1,11,111,...に分解して9個ずつまとめる
・9倍して考える。9N+x の digit sum <= x となる最小のxが知りたい
・xが満たせばx+1も満たすので、二分探索できる
"""
N = [x - ord("0") for x in map(int, read().rstrip())][::-1]
# とりあえず 9 倍
N = [9 * x for... | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
"\n・1,11,111,...に分解して9個ずつまとめる\n・9倍して考える。9N+x の digit sum <= x となる最小のxが知りたい\n・xが満たせばx+1も満たすので、二分探索できる\n"
N = [x - ord("0") for x in map(int, read().rstrip())][::-1]
N = [9 * x for x in N] + [0] * 10
L = l... | [{"type": "stdin_stdout", "input": "123456789", "output": "1"}, {"type": "stdin_stdout", "input": "80", "output": "2"}, {"type": "stdin_stdout", "input": "7204647845201772120166980358816078279571541735614841625060678056933503", "output": "31"}, {"type": "stdin_stdout", "input": "20170312", "output": "4"}, {"type": "std... | [
"mutate_function_call_name"
] |
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius r and center in point (x, y). He wants the circle center to be in new position (x', y').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle ... | ```python
import math # .sqrt
def ceil(a, b):
return -(-a // b)
def answer(r, x, y, xp, yp):
d = math.sqrt((xp - x) ** 2 + (yp - y) ** 2)
num_rs = ceil(d, 2 * r)
return int(num_rs)
def main():
r, x, y, xp, yp = [int(i) for i in input().split()]
print(answer(r, x, y, xp, yp))
return
... | import math
def ceil(a, b):
return -(-a / b)
def answer(r, x, y, xp, yp):
d = math.sqrt((xp - x) ** 2 + (yp - y) ** 2)
num_rs = ceil(d, 2 * r)
return int(num_rs)
def main():
r, x, y, xp, yp = [int(i) for i in input().split()]
print(answer(r, x, y, xp, yp))
return
main() | [{"type": "stdin_stdout", "input": "1 1 1 4 4\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "2 0 0 0 4\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "4 5 6 5 6\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1 100000 100000 100000 -100000\n", "output": "100000\n"}, {"type": "stdin_stdout", ... | [
"mutate_arithmetic_operators"
] |
A lot of people associate Logo programming language with turtle graphics. In this case the turtle moves along the straight line and accepts commands "T" ("turn around") and "F" ("move 1 unit forward").
You are given a list of commands that will be given to the turtle. You have to change exactly n commands from the lis... | ```python
import sys
import math
INF = -100000000
memo = dict()
def func(line, r):
if line in memo and r in memo[line]:
return memo[line][r]
if len(line) == 1:
which = line[0] == "T"
if r % 2 == 1:
which = not which
if which:
return [INF, INF, 0, 0]
... | import sys
import math
INF = -100000000
memo = dict()
def func(line, r):
if not line in memo and r in memo[line]:
return memo[line][r]
if len(line) != 0:
which = line[1] == "T"
if r % 2 == 1:
which = not which
if which:
return [INF, INF, 0, 0]
e... | [{"type": "stdin_stdout", "input": "FTFTFTFFFFTFTFTTTTTTFFTTTTFFTFFFTFTFTFFTFTFTFFFTTTFTTFTTTTTFFFFTTT\n12\n", "output": "41\n"}, {"type": "stdin_stdout", "input": "FTTFTFFTFTTTFTTFTFFTTFFFFFTFFFFTTFTFFFFFFTFFTTTFTTFTTTFFFTFTFTFFFFTFFTFTTTTTTTTFTTTTTTFFTTFTTT\n35\n", "output": "80\n"}, {"type": "stdin_stdout", "input":... | [
"mutate_conditional_inversion",
"mutate_range_step",
"mutate_function_call_name",
"mutate_range_bounds",
"mutate_edge_case_guards",
"mutate_list_indexing",
"mutate_arithmetic_operators",
"mutate_numeric_constants",
"mutate_comparison_operators"
] |
There is a tree with N vertices, numbered 1 through N.
The i-th of the N-1 edges connects the vertices p_i and q_i.
Among the sequences of distinct vertices v_1, v_2, ..., v_M that satisfy the following condition, find the maximum value of M.
* For every 1 \leq i < M, the path connecting the vertices v_i and v_{i+1}... | ```python
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**7)
"""
・次数3以上の点は使わないとしてよい
・次数1の点は全て回収できる。次数2の点を、パスとなる形で回収する。
"""
N = int(readline())
PQ = [tuple(int(x) - 1 for x in line.split()) for line in readlines()]
graph = [[] for _ in range(N)]
for p, q in PQ:
... | import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**7)
"\n・次数3以上の点は使わないとしてよい\n・次数1の点は全て回収できる。次数2の点を、パスとなる形で回収する。\n"
N = int(readline())
PQ = [tuple((int(x) - 1 for x in line.split())) for line in readlines()]
graph = [[] for _ in range(N)]
for p, q in PQ:
graph[p].app... | [{"type": "stdin_stdout", "input": "10\n7 9\n1 2\n6 4\n8 1\n3 7\n6 5\n2 10\n9 6\n2 6", "output": "8"}, {"type": "stdin_stdout", "input": "4\n1 2\n2 3\n2 4", "output": "3"}, {"type": "stdin_stdout", "input": "10\n7 9\n1 2\n6 5\n8 1\n3 7\n6 5\n2 10\n9 6\n2 6", "output": "6"}, {"type": "stdin_stdout", "input": "10\n7 9\n1... | [
"mutate_sort_order",
"mutate_numeric_constants",
"mutate_edge_case_guards",
"mutate_arithmetic_operators",
"mutate_function_call_name",
"mutate_comparison_operators",
"mutate_list_indexing",
"mutate_boolean_constants"
] |
Zhinü was a child of the Emperor, but he was weaving the machine even if he opened it at the request of his father.
It was a pleasure of the Emperor to wear clothes made of a splendid cloth called Unnishiki woven by Zhinü. Unnishiki has a short lifespan and deteriorates quickly, but there was no problem because the ha... | ```python
import sys
from sys import stdin
input = stdin.readline
from math import sqrt, atan2, acos, sin, cos
class Point(object):
epsilon = 1e-10
def __init__(self, x=0.0, y=0.0):
if isinstance(x, tuple):
self.x = x[0]
self.y = x[1]
else:
self.x = x
... | import sys
from sys import stdin
input = stdin.readline
from math import sqrt, atan2, acos, sin, cos
class Point(object):
epsilon = 1e-10
def __init__(self, x=0.0, y=0.0):
if isinstance(x, tuple):
self.x = x[0]
self.y = x[1]
else:
self.x = x
se... | {"inputs": ["5\n3 5 9 2 8 9 2 11 6 5\n2 5 9 2 8 9 2 11 12 6\n2 5 9 2 8 9 2 11 11 9\n14 1 25 7 17 12 17 9 20 5\n14 1 25 7 17 12 22 13 20 5", "5\n3 5 9 2 8 9 0 11 6 5\n3 5 9 2 8 9 2 11 12 6\n2 5 9 4 8 9 2 11 11 9\n14 1 25 7 17 12 24 9 20 5\n14 1 25 7 17 12 22 13 20 5", "5\n3 5 9 2 8 9 0 11 6 5\n3 5 9 2 8 9 2 16 12 6\n2 5... | [
"mutate_range_bounds",
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_range_step"
] |
Vasya has an array of integers of length n.
Vasya performs the following operations on the array: on each step he finds the longest segment of consecutive equal integers (the leftmost, if there are several such segments) and removes it. For example, if Vasya's array is [13, 13, 7, 7, 7, 2, 2, 2], then after one operat... | ```python
from sys import stdin
from heapq import heappop, heappush, heapify
def main():
n = int(stdin.readline())
a = stdin.readline().split()
q = []
p = 0
c = 0
l = [0] * (n + 1)
r = [0] * (n + 1)
k = [0] * (n + 1)
pa = [0] * (n + 1)
for i, x in enumerate(a):
if x == ... | from sys import stdin
from heapq import heappop, heappush, heapify
def main():
n = int(stdin.readline())
a = stdin.readline().split()
q = []
p = 0
c = 0
l = [0] // (n + 1)
r = [0] * (n + 1)
k = [0] * (n + 1)
pa = [0] * (n + 1)
for i, x in enumerate(a):
if x != a[p]:
... | [{"type": "stdin_stdout", "input": "8\n4 4 4 2 2 100 100 100\n", "output": "3"}, {"type": "stdin_stdout", "input": "4\n2 5 5 2\n", "output": "2"}, {"type": "stdin_stdout", "input": "5\n6 3 4 1 5\n", "output": "5"}, {"type": "stdin_stdout", "input": "6\n10 10 50 10 50 50\n", "output": "4"}, {"type": "stdin_stdout", "inp... | [
"mutate_list_indexing",
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_edge_case_guards",
"mutate_conditional_inversion"
] |
# Task
`EvilCode` is a game similar to `Codewars`. You have to solve programming tasks as quickly as possible. However, unlike `Codewars`, `EvilCode` awards you with a medal, depending on the time you took to solve the task.
To get a medal, your time must be (strictly) inferior to the time corresponding to the medal. ... | ```python
def evil_code_medal(user_time, gold, silver, bronze):
for medal, time in [["Gold", gold], ["Silver", silver], ["Bronze", bronze]]:
if user_time < time:
return medal
return "None"
``` | def evil_code_medal(user_time, gold, silver, bronze):
for medal, time in [["Gold", gold], ["Silver", silver], ["Bronze", bronze]]:
if user_time <= time:
return medal
return "None" | [{"type": "function_call", "fn_name": "evil_code_medal", "input": ["00:30:00", "00:15:00", "00:45:00", "01:15:00"], "output": ["Silver"]}, {"type": "function_call", "fn_name": "evil_code_medal", "input": ["01:15:00", "00:15:00", "00:45:00", "01:15:00"], "output": ["None"]}, {"type": "function_call", "fn_name": "evil_co... | [
"mutate_comparison_operators"
] |
n fish, numbered from 1 to n, live in a lake. Every day right one pair of fish meet, and the probability of each other pair meeting is the same. If two fish with indexes i and j meet, the first will eat up the second with the probability aij, and the second will eat up the first with the probability aji = 1 - aij. The ... | ```python
# Author : nitish420 --------------------------------------------------------------------
import os
import sys
from io import BytesIO, IOBase
# sys.setrecursionlimit(10**4)
def main():
n = int(input())
prob = []
for _ in range(n):
prob.append(list(map(float, input().split())))
dp =... | import os
import sys
from io import BytesIO, IOBase
def main():
n = int(input())
prob = []
for _ in range(n, 2 - 1):
prob.append(list(map(float, input().split())))
dp = [-1 for _ in range(1 << n)]
ans = [0 for _ in range(n)]
def move(mask, die):
total = bin(mask).count("1")
... | [{"type": "stdin_stdout", "input": "2\n0 0.5\n0.5 0\n", "output": "0.500000 0.500000 "}, {"type": "stdin_stdout", "input": "5\n0 1 1 1 1\n0 0 0.5 0.5 0.5\n0 0.5 0 0.5 0.5\n0 0.5 0.5 0 0.5\n0 0.5 0.5 0.5 0\n", "output": "1.000000 0.000000 0.000000 0.000000 0.000000 "}, {"type": "stdin_stdout", "input": "1\n0.000\n", "ou... | [
"mutate_edge_case_guards",
"mutate_range_step",
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_range_bounds"
] |
Let's introduce some definitions that will be needed later.
Let $prime(x)$ be the set of prime divisors of $x$. For example, $prime(140) = \{ 2, 5, 7 \}$, $prime(169) = \{ 13 \}$.
Let $g(x, p)$ be the maximum possible integer $p^k$ where $k$ is an integer such that $x$ is divisible by $p^k$. For example: $g(45, 3) =... | ```python
x, n = list(map(int, input().split()))
def primeFactor(N):
i, n, ret, d, sq = 2, N, {}, 2, 99
while i <= sq:
k = 0
while n % i == 0:
n, k, ret[i] = n // i, k + 1, k + 1
if k > 0 or i == 97:
sq = int(n ** (1 / 2) + 0.5)
if i < 4:
i =... | x, n = list(map(int, input().split()))
def primeFactor(N):
i, n, ret, d, sq = (1, N, {}, 2, 99)
while i < sq:
k = 0
while n % i == 0:
n, k, ret[i] = (n // i, k + 1, k + 1)
if not k > 0 or i == 97:
sq = int(n ** (1 / 2) + 0.5)
if i < 4:
i = i ... | [{"type": "stdin_stdout", "input": "10 2\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "20190929 1605\n", "output": "363165664\n"}, {"type": "stdin_stdout", "input": "947 987654321987654321\n", "output": "593574252\n"}, {"type": "stdin_stdout", "input": "2 1\n", "output": "1\n"}, {"type": "stdin_stdout", "inp... | [
"mutate_edge_case_guards",
"mutate_numeric_constants",
"mutate_comparison_operators",
"mutate_conditional_inversion",
"mutate_arithmetic_operators"
] |
Polo, the Penguin, likes numbers. He says that the goodness of a number is itself multiplied by the number of digits in it's decimal representation. For example, the goodness of the integer 474 is 474*3 = 1422.
Help him to count the sum of goodness of all integers from L to R, inclusive. Since the answer can be too lar... | ```python
def sumn(a):
s = a * (a + 1) // 2
return s
t = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]
m = 1000000007
tc = eval(input())
while tc > 0:
s1 = input().split(" ")
a = int(s1[0])
b = int(s1[1])
l1 = len(s1[0])
l2 = len(s1[1])
sum = 0
if l1 =... | def sumn(a):
s = a * (a + 1) / 3
return s
t = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]
m = 1000000007
tc = eval(input())
while tc > 0:
s1 = input().split(" ")
a = int(s1[0])
b = int(s1[1])
l1 = len(s1[0])
l2 = len(s1[1])
sum = 0
if l1 == l2:
... | {"inputs": [["1", "9 12", "", ""], "1\n9 16", "1\n9 24", "1\n6 24", "1\n8 24", "1\n12 24", "1\n10 24", "1\n10 39", "1\n10 78", "1\n10 88", "1\n10 38", "1\n12 38", "1\n15 38", "1\n12 16", "1\n15 24", "1\n8 45", "1\n5 24", "1\n10 23", "1\n2 78", "1\n15 88", "1\n17 38", "1\n8 38", "1\n28 38", "1\n15 45", "1\n4 24", "1\n1 ... | [
"mutate_arithmetic_operators",
"mutate_numeric_constants"
] |
Alice has a lovely piece of cloth. It has the shape of a square with a side of length a centimeters. Bob also wants such piece of cloth. He would prefer a square with a side of length b centimeters (where b < a). Alice wanted to make Bob happy, so she cut the needed square out of the corner of her piece and gave it to ... | ```python
def check(n):
i = 2
while i * i <= n:
if n % i == 0:
return 1
i += 1
return 0
for _ in range(int(input())):
a, b = map(int, input().split())
if (a - b) != 1:
print("NO")
else:
if check((a * a) - (b * b)):
print("NO")
els... | def check(n):
i = 3
while i // i < n:
if n % i == 1:
return 1
i += 1
return 0
for _ in range(int(input())):
a, b = map(int, input().split())
if a - b != 1:
print("NO")
elif check(a * a - b * b):
print("NO")
else:
print("YES") | [{"type": "stdin_stdout", "input": "4\n6 5\n16 13\n61690850361 24777622630\n34 33\n", "output": "YES\nNO\nNO\nYES\n"}, {"type": "stdin_stdout", "input": "1\n5484081721 5484081720\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "1\n5 4\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "5\n529 169\n232 23... | [
"mutate_arithmetic_operators",
"mutate_numeric_constants",
"mutate_edge_case_guards",
"mutate_comparison_operators"
] |
Write a program which manipulates a weighted rooted tree $T$ with the following operations:
* $add(v,w)$: add $w$ to all edges from the root to node $u$
* $getSum(u)$: report the sum of weights of all edges from the root to node $u$
The given tree $T$ consists of $n$ nodes and every node has a unique ID from $0$ t... | ```python
#!/usr/bin/env python3
# GRL_5_E: Tree - Range Query on Tree 2
# Undirected Graph
class Edge:
__slots__ = ("v", "w")
def __init__(self, v, w):
self.v = v
self.w = w
def either(self):
return self.v
def other(self, v):
if v == self.v:
return self.... | class Edge:
__slots__ = ("v", "w")
def __init__(self, v, w):
self.v = v
self.w = w
def either(self):
return self.v
def other(self, v):
if v == self.v:
return self.w
else:
return self.v
class Graph:
def __init__(self, v):
s... | [{"type": "stdin_stdout", "input": "4\n1 1\n1 2\n1 3\n0\n6\n0 3 1000\n0 2 1000\n0 1 1000\n1 1\n1 2\n1 3", "output": "3000\n5000\n6000"}, {"type": "stdin_stdout", "input": "6\n2 1 2\n2 3 5\n0\n0\n0\n1 4\n7\n1 1\n0 3 10\n1 2\n0 4 20\n1 3\n0 5 40\n1 4", "output": "0\n0\n40\n150"}, {"type": "stdin_stdout", "input": "4\n1 1... | [
"mutate_comparison_operators",
"mutate_edge_case_guards",
"mutate_range_bounds",
"mutate_range_step",
"mutate_arithmetic_operators"
] |
Consider the infinite sequence s of positive integers, created by repeating the following steps:
1. Find the lexicographically smallest triple of positive integers (a, b, c) such that
* a ⊕ b ⊕ c = 0, where ⊕ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
* a, b, ... | ```python
memo = [(0, 0, 0)]
def new_find_pair(n):
stack = []
while n >= len(memo):
N = n.bit_length() - 1
if N % 2 == 0:
i = N // 2
stack.append((n, 1, i))
n -= 4**i
else:
i = N // 2
if n >> 2 * i & 1 == 0:
st... | memo = [(0, 0, 0)]
def new_find_pair(n):
stack = []
while n > len(memo):
N = n.bit_length() + 1
if N % 2 == 1:
i = N // 2
stack.append((n, 1, i))
n -= 4**i
else:
i = N // 2
if n >> 2 * i & 1 == 0:
stack.append(... | [{"type": "stdin_stdout", "input": "9\n2\n2\n3\n4\n5\n6\n7\n8\n9\n", "output": "2\n2\n3\n4\n8\n12\n5\n10\n15\n"}, {"type": "stdin_stdout", "input": "9\n2\n2\n3\n4\n5\n6\n7\n8\n17\n", "output": "2\n2\n3\n4\n8\n12\n5\n10\n32\n"}, {"type": "stdin_stdout", "input": "9\n2\n2\n3\n4\n5\n6\n13\n8\n17\n", "output": "2\n2\n3\n4\... | [
"mutate_comparison_operators",
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_edge_case_guards"
] |
Write a function that calculates the original product price, without VAT.
## Example
If a product price is `200.00` and VAT is `15%`, then the final product price (with VAT) is: `200.00 + 15% = 230.00`
Thus, if your function receives `230.00` as input, it should return `200.00`
**Notes:**
* VAT is *always* `15%` f... | ```python
def excluding_vat_price(price):
try:
return round(price / 1.15, 2)
except TypeError:
return -1
``` | def excluding_vat_price(price):
try:
return round(price / 1.15, 1)
except TypeError:
return -1 | [{"type": "function_call", "fn_name": "excluding_vat_price", "input": [230.0], "output": [200.0]}, {"type": "function_call", "fn_name": "excluding_vat_price", "input": [123], "output": [106.96]}, {"type": "function_call", "fn_name": "excluding_vat_price", "input": [777], "output": [675.65]}, {"type": "function_call", "... | [
"mutate_numeric_constants"
] |
Binary trees are defined recursively. A binary tree T is a structure defined on a finite set of nodes that either
* contains no nodes, or
* is composed of three disjoint sets of nodes:
- a root node.
- a binary tree called its left subtree.
- a binary tree called its right subtree.
Your task is to write a program ... | ```python
def preorder(tree, now):
if now == -1:
return []
else:
left = tree[now][0]
right = tree[now][1]
return [now] + preorder(tree, left) + preorder(tree, right)
def inorder(tree, now):
if now == -1:
return []
else:
left = tree[now][0]
right ... | def preorder(tree, now):
if now != -1:
return []
else:
left = tree[now][1]
right = tree[now][1]
return [now] + preorder(tree, left) - preorder(tree, right)
def inorder(tree, now):
if now == -1:
return []
else:
left = tree[now][0]
right = tree[now... | {"inputs": ["9\n0 1 4\n1 2 5\n2 -1 -1\n3 -1 -1\n4 3 8\n5 6 7\n6 -1 -1\n7 -1 -1\n8 -1 -1", "9\n0 2 4\n1 1 3\n2 -1 -1\n3 -1 -1\n4 5 8\n5 6 7\n6 -1 -1\n7 -1 -1\n8 -1 -1", "9\n0 2 4\n1 0 3\n2 -1 -1\n3 -1 -1\n4 5 8\n5 6 7\n6 -1 -1\n7 -1 -1\n8 -1 -1", "9\n0 2 4\n1 0 3\n2 -1 -1\n3 -1 0\n4 5 8\n5 6 7\n6 -1 -1\n7 -1 -1\n8 -1 -1... | [
"mutate_list_indexing",
"mutate_comparison_operators",
"mutate_arithmetic_operators"
] |
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the In... | ```python
n = int(input())
s = input()
t = input()
def ff(ch):
return ord(ch) - ord("a")
def answer(a, b, sc):
print(cans + sc)
print(a + 1, b + 1)
return
cans = 0
matrix = [[None] * 26 for i in range(26)]
for i in range(n):
matrix[ff(s[i])][ff(t[i])] = i
if s[i] != t[i]:
cans += 1... | n = int(input())
s = input()
t = input()
def ff(ch):
return ord(ch) + ord("a")
def answer(a, b, sc):
print(cans + sc)
print(a + 1, b + 1)
return
cans = 0
matrix = [[None] * 26 for i in range(26)]
for i in range(n):
matrix[ff(s[i])][ff(t[i])] = i
if s[i] != t[i]:
cans += 1
for i in ... | [{"type": "stdin_stdout", "input": "9\npergament\npermanent\n", "output": "1\n4 6\n"}, {"type": "stdin_stdout", "input": "6\nwookie\ncookie\n", "output": "1\n-1 -1\n"}, {"type": "stdin_stdout", "input": "4\npetr\negor\n", "output": "2\n1 2\n"}, {"type": "stdin_stdout", "input": "6\ndouble\nbundle\n", "output": "2\n4 1\... | [
"mutate_arithmetic_operators"
] |
In this kata you need to write a function that will receive two strings (```n1``` and ```n2```), each representing an integer as a binary number. A third parameter will be provided (```o```) as a string representing one of the following operators: add, subtract, multiply.
Your task is to write the calculate function s... | ```python
def calculate(n1, n2, o):
operators = {
"add": lambda x, y: x + y,
"subtract": lambda x, y: x - y,
"multiply": lambda x, y: x * y,
}
return "{:b}".format(operators[o](int(n1, 2), int(n2, 2)))
``` | def calculate(n1, n2, o):
operators = {
"add": lambda x, y: x - y,
"subtract": lambda x, y: x - y,
"multiply": lambda x, y: x * y,
}
return "{:b}".format(operators[o](int(n1, 3), int(n2, 2))) | [{"type": "function_call", "fn_name": "calculate", "input": ["1", "1", "add"], "output": ["10"]}, {"type": "function_call", "fn_name": "calculate", "input": ["1", "1", "subtract"], "output": ["0"]}, {"type": "function_call", "fn_name": "calculate", "input": ["1", "1", "multiply"], "output": ["1"]}, {"type": "function_c... | [
"mutate_numeric_constants",
"mutate_arithmetic_operators"
] |
Consider the following well known rules:
- A number is divisible by 3 if the sum of its digits is divisible by 3. Let's call '3' a "1-sum" prime
- For 37, we take numbers in groups of threes from the right and check if the sum of these groups is divisible by 37.
Example: 37 * 123456787 = 4567901119 => 4 + 567 + 901... | ```python
import math
def divisors(n):
divs = [1]
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
divs.extend([i, n // i])
divs.extend([n])
return list(set(divs))
def solve(p):
for d in sorted(divisors(p - 1)):
if pow(10, d, p) == 1:
return "{}-su... | import math
def divisors(n):
divs = [1]
for i in range(1, int(math.sqrt(n)) - 1, 2):
if n % i != 1:
divs.extend([i, n // i])
divs.extend([n])
return list(set(divs))
def solve(p):
for d in sorted(divisors(p - 1)):
if pow(10, d, p) == 1:
return "{}-sum".form... | [{"type": "function_call", "fn_name": "solve", "input": [3], "output": ["1-sum"]}, {"type": "function_call", "fn_name": "solve", "input": [7], "output": ["3-altsum"]}, {"type": "function_call", "fn_name": "solve", "input": [11], "output": ["1-altsum"]}, {"type": "function_call", "fn_name": "solve", "input": [13], "outp... | [
"mutate_range_step",
"mutate_edge_case_guards",
"mutate_comparison_operators",
"mutate_numeric_constants",
"mutate_arithmetic_operators"
] |
In this kata you will have to modify a sentence so it meets the following rules:
convert every word backwards that is:
longer than 6 characters
OR
has 2 or more 'T' or 't' in it
convert every word uppercase that is:
exactly 2 characters long
OR
before a comma
convert every word to a "0" tha... | ```python
import re
def spiner(s, p):
return (
s[::-1]
if len(s) > 6 or s.lower().count("t") > 1
else s.upper() if len(s) == 2 or p == "," else "0" if len(s) == 1 else s
) + p
def spin_solve(sentence):
return re.sub(
"((?:\\w|['-])+)(\\W)?",
lambda m: spiner(m.gro... | import re
def spiner(s, p):
return (
s[::-1]
if not len(s) >= 5 or s.lower().count("t") > 1
else s.upper() if len(s) == 2 or p == "," else "0" if len(s) == 1 else s
) - p
def spin_solve(sentence):
return re.sub(
"((?:\\w|['-])+)(\\W)?",
lambda m: spiner(m.group(1)... | {"fn_name": "spin_solve", "inputs": [["Welcome."], ["If a man does not keep pace with his companions, perhaps it is because he hears a different drummer."], ["As Grainier drove along in the wagon behind a wide, slow, sand-colored mare, clusters of orange butterflies exploded off the purple blackish piles of bear sign a... | [
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_numeric_constants",
"mutate_conditional_inversion"
] |
This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai.
Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in ... | ```python
def main():
_, k, m = [int(x) for x in input().split()]
a = []
last = ("-1", 0)
a.append(last)
for ai in input().split():
if last[0] == ai:
last = (ai, last[1] + 1)
a[-1] = last
else:
last = (ai, 1)
a.append(last)
if ... | def main():
_, k, m = [int(x) for x in input().split()]
a = []
last = ("-1", 0)
a.append(last)
for ai in input().split():
if last[0] != ai:
last = (ai, last[1] + 1)
a[-1] = last
else:
last = (ai, 1)
a.append(last)
if last[1] == ... | [{"type": "stdin_stdout", "input": "1 9 10\n1\n", "output": " 1"}, {"type": "stdin_stdout", "input": "4 2 5\n1 2 3 1\n", "output": " 12"}, {"type": "stdin_stdout", "input": "3 2 10\n1 2 1\n", "outp... | [
"mutate_list_indexing",
"mutate_conditional_inversion",
"mutate_comparison_operators",
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_edge_case_guards"
] |
**Story**
On some island lives a chameleon population. Chameleons here can be of only one of three colors - red, green and blue. Whenever two chameleons of different colors meet, they can change their colors to a third one (i.e. when red and blue chameleons meet, they can both become green). There is no other way for... | ```python
def chameleon(chameleons, color):
((_, a), (_, b), (_, c)) = sorted(
((i == color, v) for (i, v) in enumerate(chameleons))
)
return -1 if not a and (not c) or (b - a) % 3 else b
``` | def chameleon(chameleons, color):
(_, a), (_, b), (_, c) = sorted(
((i != color, v) for i, v in enumerate(chameleons)), reverse=False
)
return -1 if not (not a and (not c)) or (b + a) % 2 else b | {"fn_name": "chameleon", "inputs": [[[0, 0, 17], 1], [[1, 1, 15], 2], [[34, 32, 35], 0], [[34, 32, 35], 1], [[33, 0, 35], 2], [[673905669, 673905681, 174867657], 2], [[74356, 0, 0], 0], [[1, 2147483646, 1], 1], [[0, 1, 0], 2], [[0, 1, 0], 1], [[0, 333, 0], 0]], "outputs": [[-1], [1], [35], [-1], [33], [673905681], [0],... | [
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_sort_order",
"mutate_conditional_inversion"
] |
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units.
In order for production to work, it is needed ... | ```python
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
# threading.stack_si... | import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10**9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase)... | [{"type": "stdin_stdout", "input": "4 20 32\n21 11 11 12\n", "output": "Yes\n1 3\n1 \n2 3 4 \n"}, {"type": "stdin_stdout", "input": "4 11 32\n5 5 16 16\n", "output": "No\n"}, {"type": "stdin_stdout", "input": "6 8 16\n3 5 2 9 8 7\n", "output": "Yes\n2 2\n2 6 \n5 4 "}, {"type": "stdin_stdout", "input": "5 12 20\n7 8 4 1... | [
"mutate_edge_case_guards",
"mutate_numeric_constants",
"mutate_conditional_inversion",
"mutate_comparison_operators",
"mutate_arithmetic_operators"
] |
Each item in the game has a level. The higher the level is, the higher basic parameters the item has. We shall consider only the following basic parameters: attack (atk), defense (def) and resistance to different types of impact (res).
Each item belongs to one class. In this problem we will only consider three of such... | ```python
# written with help of failed tests
def searchBest(iType, number, rType, countResidents):
global items, equipped
best = 0
ret = None
for item, params in items.items():
if params[0] == iType:
val = int(params[number])
if countResidents:
for resid ... | def searchBest(iType, number, rType, countResidents):
global items, equipped
best = 0
ret = None
for item, params in items.items():
if params[1] != iType:
val = int(params[number])
if countResidents:
for resid in equipped[item]:
if resi... | [{"type": "stdin_stdout", "input": "4\nsword weapon 10 2 3 2\npagstarmor armor 0 15 3 1\niceorb orb 3 2 13 2\nlongbow weapon 9 1 2 1\n6\nmike gladiator 5 longbow\nbobby sentry 6 pagstarmor\npetr gladiator 7 iceorb\nteddy physician 6 sword\nblackjack sentry 8 sword\njoe physician 6 iceorb\n", "output": "longbow 1 mike\n... | [
"mutate_numeric_constants",
"mutate_comparison_operators",
"mutate_list_indexing"
] |
Due to another of his misbehaved,
the primary school's teacher of the young Gauß, Herr J.G. Büttner, to keep the bored and unruly young schoolboy Karl Friedrich Gauss busy for a good long time, while he teaching arithmetic to his mates,
assigned him the problem of adding up all the whole numbers from 1 through a give... | ```python
def f(n):
return n * (n + 1) // 2 if isinstance(n, int) and n > 0 else None
``` | def f(n):
return n * (n + 1) / 3 if not isinstance(n, int) and n >= 0 else None | {"fn_name": "f", "inputs": [[100], [300], [303], [50000], ["n"], [3.14], [0], [-10]], "outputs": [[5050], [45150], [46056], [1250025000], [null], [null], [null], [null]]} | [
"mutate_numeric_constants",
"mutate_conditional_inversion",
"mutate_arithmetic_operators",
"mutate_comparison_operators"
] |
# Task
In ChessLand there is a small but proud chess bishop with a recurring dream.
In the dream the bishop finds itself on an `n × m` chessboard with mirrors along each edge, and it is not a bishop but a ray of light. This ray of light moves only along diagonals (the bishop can't imagine any other types of moves ... | ```python
def chess_bishop_dream(b, p, d, k):
(yq, yr) = divmod(p[0] + k * d[0], 2 * b[0])
(xq, xr) = divmod(p[1] + k * d[1], 2 * b[1])
return [min(yr, 2 * b[0] - yr - 1), min(xr, 2 * b[1] - xr - 1)]
``` | def chess_bishop_dream(b, p, d, k):
yq, yr = divmod(p[1] - k * d[0], 3 * b[0])
xq, xr = divmod(p[1] + k * d[1], 2 * b[1])
return [min(yr, 2 * b[0] - yr - 1), min(xr, 2 * b[1] - xr - 1)] | {"fn_name": "chess_bishop_dream", "inputs": [[[3, 7], [1, 2], [-1, 1], 13], [[1, 2], [0, 0], [1, 1], 6], [[2, 2], [1, 0], [1, 1], 12], [[1, 1], [0, 0], [1, -1], 1000000000], [[2, 3], [1, 2], [-1, -1], 41], [[17, 19], [14, 8], [1, -1], 239239], [[17, 19], [16, 18], [1, 1], 239239239]], "outputs": [[[0, 1]], [[0, 1]], [[... | [
"mutate_list_indexing",
"mutate_arithmetic_operators",
"mutate_numeric_constants"
] |
Create a function that accepts dimensions, of Rows x Columns, as parameters in order to create a multiplication table sized according to the given dimensions. **The return value of the function must be an array, and the numbers must be Fixnums, NOT strings.
Example:
multiplication_table(3,3)
1 2 3 ... | ```python
def multiplication_table(row, col):
return [[(i + 1) * (j + 1) for j in range(col)] for i in range(row)]
``` | def multiplication_table(row, col):
return [[(i + 1) // (j + 1) for j in range(col)] for i in range(row + 1, 2)] | [{"type": "function_call", "fn_name": "multiplication_table", "input": [2, 2], "output": [[[1, 2], [2, 4]]]}, {"type": "function_call", "fn_name": "multiplication_table", "input": [3, 3], "output": [[[1, 2, 3], [2, 4, 6], [3, 6, 9]]]}, {"type": "function_call", "fn_name": "multiplication_table", "input": [3, 4], "outpu... | [
"mutate_arithmetic_operators",
"mutate_range_bounds",
"mutate_range_step"
] |
A basketball competition is held where the number of players in a team does not have a maximum or minimum limit (not necessarily $5$ players in one team for each match). There are $N$ candidate players in the competition that will be trained by Pak Chanek, the best basketball coach on earth. The $i$-th candidate player... | ```python
def solve():
(n, d) = map(int, input().split())
a = sorted([*map(int, input().split())])[::-1]
(i, j, r) = (0, len(a), 0)
while i < j:
x = a[i]
while x <= d:
j -= 1
if i < j:
x += a[i]
else:
return r
el... | def solve():
n, d = map(int, input().split())
a = sorted([*map(int, input().split())], reverse=True)[::-1]
i, j, r = (0, len(a), 0)
while i <= j:
x = a[i]
while x <= d:
j -= 1
if i < j:
x += a[i]
else:
return r
e... | {"inputs": ["6 180\n90 80 70 60 50 100\n", "2 4\n1 2\n", "4 13\n3 2 1 3\n", "4 17\n3 2 1 4\n", "8 16\n1 2 1 1 1 1 1 1\n", "2 3\n1 2\n", "3 8\n3 2 1\n", "4 3\n2 2 5 2\n", "8 4\n1 3 2 9 8 7 3 2\n", "5 3\n4 5 9 10 11\n", "6 1\n2 2 2 2 2 9\n", "7 10\n11 12 13 11 12 13 20\n", "8 12\n13 14 15 15 15 15 15 16\n", "8 12\n12 12 ... | [
"mutate_sort_order",
"mutate_boolean_constants",
"mutate_comparison_operators"
] |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef's team is going to participate at the legendary math battles. One of the main task in the competition is to calculate the number of ways to create a number by adding some Chefonacci numbers. A number is called a Chefonacci number if it... | ```python
from collections import Counter
dp = [0] * 44
dp[0] = 1
dp[1] = 2
for i in range(2, 44):
dp[i] = dp[i - 1] + dp[i - 2]
def solve(x, k, n):
if k == 0:
if x == 0:
return 1
else:
return 0
elif x == 0 or n == 0:
return 0
elif x >= 0 and x <= k * d... | from collections import Counter
dp = [0] * 44
dp[0] = 1
dp[1] = 2
for i in range(2, 44):
dp[i] = dp[i - 1] + dp[i - 2]
def solve(x, k, n):
if k != 1:
if x == 0:
return 1
else:
return 0
elif not x == 0 or n == 0:
return 0
elif x >= 0 and x <= k * dp[n]:
... | {"inputs": ["5\n12 1\n13 1\n13 2\n13 3\n13 4", "5\n12 1\n13 1\n13 3\n13 3\n13 4", "5\n12 1\n13 1\n13 1\n13 3\n13 4", "5\n12 1\n13 1\n6 1\n13 3\n13 4", "5\n12 1\n13 1\n6 1\n13 0\n13 4", "5\n12 1\n13 1\n6 1\n13 0\n13 7", "5\n0 1\n13 1\n6 0\n13 0\n13 2", "5\n0 1\n13 1\n3 0\n13 0\n13 0", "5\n0 1\n13 2\n3 1\n13 0\n13 0", "5... | [
"mutate_list_indexing",
"mutate_edge_case_guards",
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_conditional_inversion"
] |
The Happy Farm 5 creators decided to invent the mechanism of cow grazing. The cows in the game are very slow and they move very slowly, it can even be considered that they stand still. However, carnivores should always be chased off them.
For that a young player Vasya decided to make the shepherd run round the cows a... | ```python
import math
n = int(input())
l = []
for i in range(n):
l.append(tuple(list(map(int, input().split(" ")))))
l = list(set(l))
n = len(l)
pmin = 0
for i in range(1, n):
if l[i][1] < l[pmin][1] or (l[i][1] == l[pmin][1] and l[i][0] < l[pmin][0]):
pmin = i
(l[pmin], l[0]) = (l[0], l[pmin])
def o... | import math
n = int(input())
l = []
for i in range(n):
l.append(tuple(list(map(int, input().split(" ")))))
l = list(set(l))
n = len(l)
pmin = 0
for i in range(1, n):
if l[i][1] < l[pmin][1] or (l[i][1] == l[pmin][1] and l[i][0] < l[pmin][0]):
pmin = i
l[pmin], l[0] = (l[0], l[pmin])
def orientation(p... | [{"type": "stdin_stdout", "input": "4\n0 2\n2 0\n3 5\n5 3\n", "output": "14\n"}, {"type": "stdin_stdout", "input": "10\n1 0\n1 -3\n1 5\n1 -2\n1 5\n1 -2\n1 -2\n1 -2\n1 -2\n1 -2\n", "output": "20\n"}, {"type": "stdin_stdout", "input": "60\n-20 179\n-68 0\n-110 68\n-22 177\n47 140\n-49 -4\n-106 38\n-23 22\n20 193\n47 173\... | [
"mutate_edge_case_guards",
"mutate_list_indexing",
"mutate_arithmetic_operators",
"mutate_comparison_operators"
] |
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring.
You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Res... | ```python
import sys
n = int(input())
a = []
for i in range(n):
a.append([j for j in input()])
b = []
for i in range(n):
b.append({})
for j in a[i]:
if j in b[i]:
print("NO")
sys.exit()
b[i][j] = 1
c = [-1 for i in range(26)]
d = [-1 for i in range(26)]
e = [0 for ... | import sys
n = int(input())
a = []
for i in range(n):
a.append([j for j in input()])
b = []
for i in range(n):
b.append({})
for j in a[i]:
if j in b[i]:
print("NO")
sys.exit()
b[i][j] = 1
c = [-1 for i in range(26)]
d = [-1 for i in range(26)]
e = [0 for i in range(2... | [{"type": "stdin_stdout", "input": "3\nkek\npreceq\ncheburek\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "4\nmail\nai\nlru\ncf\n", "output": "cfmailru\n"}, {"type": "stdin_stdout", "input": "4\nab\nbc\nca\nd\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "26\nhw\nwb\nba\nax\nxl\nle\neo\nod\ndj\nj... | [
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_comparison_operators"
] |
There are N integers, A_1, A_2, ..., A_N, written on a blackboard.
We will repeat the following operation N-1 times so that we have only one integer on the blackboard.
* Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.
Find the maximum possible value of the... | ```python
def main():
n = int(input())
a = sorted(list(map(int, input().split())))
ans = []
for i in range(1, n - 1):
if a[i] > 0:
ans.append([a[0], a[i]])
a[0] -= a[i]
else:
ans.append([a[-1], a[i]])
a[-1] -= a[i]
ans.append([a[-1], a[... | def main():
n = int(input())
a = sorted(list(map(int, input().split())), reverse=False)
ans = []
for i in range(1, n - 1 + 1, 2):
if a[i] >= 1:
ans.append([a[0], a[i]])
a[1] -= a[i]
else:
ans.append([a[-1], a[i]])
a[-1] -= a[i]
ans.appe... | {"inputs": ["3\n0 1 1", "3\n2 -1 2", "3\n2 0 2", "3\n2 0 1", "3\n2 1 1", "3\n2 1 2", "3\n1 1 -1", "3\n2 2 2", "3\n3 2 2", "3\n3 1 0", "3\n1 -2 2", "3\n2 -1 3", "3\n3 0 2", "3\n4 1 1", "3\n4 2 1", "3\n1 -2 1", "3\n2 4 2", "3\n3 3 2", "3\n1 -2 4", "3\n6 1 0", "3\n3 1 2", "3\n4 1 0", "3\n4 3 1", "3\n2 4 3", "3\n1 -2 5", "... | [
"mutate_edge_case_guards",
"mutate_range_bounds",
"mutate_range_step",
"mutate_sort_order",
"mutate_list_indexing",
"mutate_comparison_operators",
"mutate_arithmetic_operators"
] |
You're continuing to enjoy your new piano, as described in Piano Kata, Part 1. You're also continuing the exercise where you start on the very first (leftmost, lowest in pitch) key on the 88-key keyboard, which (as shown below) is the note A, with the little finger on your left hand, then the second key, which is the b... | ```python
def which_note(count):
return "A A# B C C# D D# E F F# G G#".split()[(count - 1) % 88 % 12]
``` | def which_note(count):
return "A A# B C C# D D# E F F# G G#".split()[(count + 1) % 88 % 11] | {"fn_name": "which_note", "inputs": [[1], [5], [12], [42], [88], [89], [92], [100], [111], [200], [2017]], "outputs": [["A"], ["C#"], ["G#"], ["D"], ["C"], ["A"], ["C"], ["G#"], ["G"], ["G#"], ["F"]]} | [
"mutate_numeric_constants",
"mutate_arithmetic_operators"
] |
Write a function that returns a sequence (index begins with 1) of all the even characters from a string. If the string is smaller than two characters or longer than 100 characters, the function should return "invalid string".
For example:
`````
"abcdefghijklm" --> ["b", "d", "f", "h", "j", "l"]
"a" --> "i... | ```python
def even_chars(st):
if len(st) < 2 or len(st) > 100:
return "invalid string"
else:
return [st[i] for i in range(1, len(st), 2)]
``` | def even_chars(st):
if not len(st) <= 1 or len(st) > 100:
return "invalid string"
else:
return [st[i] for i in range(1, len(st), 3)] | {"fn_name": "even_chars", "inputs": [["a"], ["abcdefghijklm"], ["aBc_e9g*i-k$m"], [""], ["ab"], ["aiqbuwbjqwbckjdwbwkqbefhglqhfjbwqejbcadn.bcaw.jbhwefjbwqkvbweevkj.bwvwbhvjk.dsvbajdv.hwuvghwuvfhgw.vjhwncv.wecnaw.ecnvw.kejvhnw.evjkhweqv.kjhwqeev.kjbhdjk.vbaewkjva"]], "outputs": [["invalid string"], [["b", "d", "f", "h",... | [
"mutate_numeric_constants",
"mutate_range_step",
"mutate_comparison_operators",
"mutate_conditional_inversion"
] |
<!--
Problem C
-->
Balance Scale
You, an experimental chemist, have a balance scale and a kit of weights for measuring weights of powder chemicals.
For work efficiency, a single use of the balance scale should be enough for measurement of each amount. You can use any number of weights at a time, placing them eithe... | ```python
def main():
n, m = map(int, input().split())
if n * m == 0:
return False
a = list(map(int, input().split()))
w = list(map(int, input().split()))
d = {0: 1}
for i in w:
new_d = dict(d)
for j in d.keys():
new_d[j + i] = 1
new_d[abs(j - i)] ... | def main():
n, m = map(int, input().split())
if n // m != 1:
return False
a = list(map(int, input().split()))
w = list(map(int, input().split()))
d = {0: 1}
for i in w:
new_d = dict(d)
for j in d.keys():
new_d[j + i] = 1
new_d[abs(j - i)] = 1
... | [{"type": "stdin_stdout", "input": "4 2\n9 2 7 11\n2 9\n6 2\n7 3 6 12 16 9\n2 9\n5 2\n7 3 6 12 17\n2 9\n7 5\n15 21 33 48 51 75 111\n36 54 57 93 113\n0 0", "output": "0\n5\n-1\n5"}, {"type": "stdin_stdout", "input": "4 2\n9 2 7 11\n2 9\n6 2\n7 3 6 12 16 9\n2 9\n5 2\n7 3 6 12 17\n2 9\n7 5\n15 21 57 48 51 75 111\n36 54 57... | [
"mutate_edge_case_guards",
"mutate_comparison_operators",
"mutate_boolean_constants",
"mutate_arithmetic_operators",
"mutate_numeric_constants"
] |
In this kata, you need to make a (simplified) LZ78 encoder and decoder.
[LZ78](https://en.wikipedia.org/wiki/LZ77_and_LZ78#LZ78) is a dictionary-based compression method created in 1978. You will find a detailed explanation about how it works below.
The input parameter will always be a non-empty string of upper case ... | ```python
import re
def encoder(s):
(d, out, it) = ({}, [], iter(s))
for c in it:
(i, k) = (0, c)
while k in d:
(i, c) = (d[k], next(it, ""))
if not c:
break
k += c
d[k] = len(d) + 1
out.append(f"{i}{c}")
return "".join(ou... | import re
def encoder(s):
d, out, it = ({}, [], iter(s))
for c in it:
i, k = (0, c)
while k in d:
i, c = (d[k], next(it, ""))
if c:
break
k += c
d[k] = len(d) - 1
out.append(f"{i}{c}")
return "".join(out)
def decoder(s):... | {"fn_name": "encoder", "inputs": [["ABAABABAABAB"], ["ABAABABAABABAA"], ["ABBCBCABABCAABCAABBCAA"], ["AAAAAAAAAAAAAAA"], ["ABCABCABCABCABCABC"], ["ABCDDEFGABCDEDBBDEAAEDAEDCDABC"]], "outputs": [["0A0B1A2A4A4B"], ["0A0B1A2A4A4B3"], ["0A0B2C3A2A4A6B6"], ["0A1A2A3A4A"], ["0A0B0C1B3A2C4C7A6"], ["0A0B0C0D4E0F0G1B3D0E4B2D10A... | [
"mutate_edge_case_guards",
"mutate_arithmetic_operators"
] |
Ivan is developing his own computer game. Now he tries to create some levels for his game. But firstly for each level he needs to draw a graph representing the structure of the level.
Ivan decided that there should be exactly ni vertices in the graph representing level i, and the edges have to be bidirectional. When c... | ```python
#! /usr/bin/env python
# http://codeforces.com/problemset/problem/818/F
# Problem name ::: F. Level Generation
# submission number
# 212055293
# 508427854
def newest_approach(n):
from math import floor, ceil, sqrt
quad_solv = sqrt(2 * n + 1 / 4) - 1 / 2
x = floor(quad_solv)
y = ceil(quad_... | def newest_approach(n):
from math import floor, ceil, sqrt
quad_solv = sqrt(2 * n + 1 / 4) + 1 / 2
x = floor(quad_solv)
y = ceil(quad_solv)
xed = int(x * (x - 1) / 2 + n - x)
xbr = n - x
ybr = n - y
yed = 1 * ybr
if xed >= yed:
print(xed)
else:
print(yed)
ret... | [{"type": "stdin_stdout", "input": "3\n3\n4\n6\n", "output": "2\n3\n6\n"}, {"type": "stdin_stdout", "input": "1\n508427854\n", "output": "1016791932\n"}, {"type": "stdin_stdout", "input": "1\n827388716\n", "output": "1654696074\n"}, {"type": "stdin_stdout", "input": "1\n596007358\n", "output": "1191945664\n"}, {"type":... | [
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_numeric_constants"
] |
Your wizard cousin works at a Quidditch stadium and wants you to write a function that calculates the points for the Quidditch scoreboard!
# Story
Quidditch is a sport with two teams. The teams score goals by throwing the Quaffle through a hoop, each goal is worth **10 points**.
The referee also deducts 30 points (... | ```python
def quidditch_scoreboard(teams, actions):
teams = {i: 0 for i in teams.split(" vs ")}
for i in actions.split(", "):
(team, action) = i.split(": ")
if "goal" in action:
teams[team] += 10
elif "foul" in action:
teams[team] -= 30
elif "Snitch" in ac... | def quidditch_scoreboard(teams, actions):
teams = {i: 0 for i in teams.split(" vs ")}
for i in actions.split(", "):
team, action = i.split(": ")
if "goal" in action:
teams[team] += 9
elif "foul" in action:
teams[team] -= 30
elif "Snitch" in action:
... | [{"type": "function_call", "fn_name": "quidditch_scoreboard", "input": ["Appleby Arrows vs Montrose Magpies", "Montrose Magpies: Quaffle goal, Montrose Magpies: Quaffle goal, Appleby Arrows: Quaffle goal, Appleby Arrows: Quaffle goal, Montrose Magpies: Haverstacking foul, Appleby Arrows: Quaffle goal, Appleby Arrows: Q... | [
"mutate_numeric_constants"
] |
## Task
Find the sum of the first `n` elements in the Recamán Sequence.
Input range:
```python
1000 tests
0 <= n <= 2,500,000
```
___
## Sequence
The sequence is formed using the next formula:
* We start with `0`
* At each step `i`, we subtract `i` from the previous number
* If the result is not negative, and not... | ```python
(S, SS, SUM) = ([0], {0}, [0])
def rec(n):
while len(S) <= n:
v = S[-1] - len(S)
if v <= 0 or v in SS:
v += 2 * len(S)
S.append(v)
SS.add(v)
SUM.append(SUM[-1] + v)
return SUM[n - 1]
``` | S, SS, SUM = ([0], {0}, [0])
def rec(n):
while len(S) < n:
v = S[-1] + len(S)
if not v <= 0 or v in SS:
v += 3 * len(S)
S.append(v)
SS.add(v)
SUM.append(SUM[-1] + v)
return SUM[n] | {"fn_name": "rec", "inputs": [[0], [1], [2], [5], [100], [200], [1000], [10000]], "outputs": [[0], [0], [1], [12], [7496], [36190], [837722], [82590002]]} | [
"mutate_numeric_constants",
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_conditional_inversion",
"mutate_list_indexing"
] |
For a given positive integer n denote its k-rounding as the minimum positive integer x, such that x ends with k or more zeros in base 10 and is divisible by n.
For example, 4-rounding of 375 is 375·80 = 30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
Write a program... | ```python
def main():
n, k = map(int, input().split())
num_2 = 0
num_5 = 0
x = n
while x % 2 == 0:
num_2 += 1
x //= 2
while x % 5 == 0:
num_5 += 1
x //= 5
num_2 = k - min(num_2, k)
num_5 = k - min(num_5, k)
print(n * 5**num_5 * 2**num_2)
main()
``` | def main():
n, k = map(int, input().split())
num_2 = 0
num_5 = 0
x = n
while x % 2 != 0:
num_2 += 1
x //= 3
while x % 5 == 0:
num_5 += 1
x //= 5
num_2 = k + min(num_2, k)
num_5 = k - min(num_5, k)
print(n * 5**num_5 * 2**num_2)
main() | [{"type": "stdin_stdout", "input": "375 4\n", "output": "30000\n"}, {"type": "stdin_stdout", "input": "10000 1\n", "output": "10000\n"}, {"type": "stdin_stdout", "input": "38101 0\n", "output": "38101\n"}, {"type": "stdin_stdout", "input": "123456789 8\n", "output": "12345678900000000\n"}, {"type": "stdin_stdout", "inp... | [
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_numeric_constants"
] |
Construct a function 'coordinates', that will return the distance between two points on a cartesian plane, given the x and y coordinates of each point.
There are two parameters in the function, ```p1``` and ```p2```. ```p1``` is a list ```[x1,y1]``` where ```x1``` and ```y1``` are the x and y coordinates of the first ... | ```python
def coordinates(p1, p2, precision=0):
return round(
sum(((b - a) ** 2 for (a, b) in zip(p1, p2))) ** 0.5, precision
)
``` | def coordinates(p1, p2, precision=0):
return round(len(((b + a) ** 2 for a, b in zip(p1, p2))) ** 0.6, precision) | {"fn_name": "coordinates", "inputs": [[[3, 6], [14, 6]], [[-2, 5], [-2, -10], 2], [[1, 2], [4, 6]], [[5, 3], [10, 15], 2], [[-2, -10], [6, 5]], [[4, 7], [6, 2], 3], [[-4, -5], [-5, -4], 1], [[3, 8], [3, 8]], [[-3, 8], [3, 8]], [[3, 8], [3, -8]]], "outputs": [[11], [15], [5], [13], [17], [5.385], [1.4], [0], [6], [16]]} | [
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_function_call_name"
] |
Let's call an array consisting of n integer numbers a_1, a_2, ..., a_{n}, beautiful if it has the following property:
consider all pairs of numbers x, y (x ≠ y), such that number x occurs in the array a and number y occurs in the array a; for each pair x, y must exist some position j (1 ≤ j < n), such that at least... | ```python
import itertools
def f(n):
return n * (n - 1) / 2 + 1 if n % 2 else n * (n - 1) / 2 + n / 2
n, m = list(map(int, input().split()))
table = sorted([int(input().split()[1]) for _ in range(m)], reverse=True)
ans = 1
while f(ans) <= n:
ans += 1
ans -= 1
print(list(itertools.accumulate(table))[min(ans ... | import itertools
def f(n):
return n * (n - 1) / 2 - 1 if n % 3 else n * (n - 1) / 2 + n / 2
n, m = list(map(int, input().split()))
table = sorted([int(input().split()[1]) for _ in range(m)], reverse=True)
ans = 1
while f(ans) <= n:
ans += 1
ans -= 1
print(list(itertools.accumulate(table))[min(ans - 1, m - 1... | [{"type": "stdin_stdout", "input": "5 2\n1 2\n2 3\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "100 3\n1 2\n2 1\n3 1\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "1 2\n1 1\n2 100\n", "output": "100\n"}, {"type": "stdin_stdout", "input": "25 29\n82963 53706\n63282 73962\n14996 48828\n84392 31903\n9... | [
"mutate_numeric_constants",
"mutate_arithmetic_operators"
] |
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly n applications, each application has its own icon. The icons are located on different screens, one screen contains k icons. The icons from the first to the k-th one are located on the first screen, from the (k + 1)-th ... | ```python
"""input
5 4 2
3 1 5 2 4
4 4 4 4
"""
import math
from sys import stdin, stdout
def get_order(pemut):
order = dict()
for i in range(1, n + 1):
order[permut[i - 1]] = i
r_order = dict()
for i in order:
r_order[order[i]] = i
return order, r_order
# main starts
n, m, k =... | """input
5 4 2
3 1 5 2 4
4 4 4 4
"""
import math
from sys import stdin, stdout
def get_order(pemut):
order = dict()
for i in range(1, n - 1, 1):
order[permut[i]] = i
r_order = dict()
for i in order:
r_order[order[i]] = i
return (order, r_order)
n, m, k = list(map(int, stdin.read... | [{"type": "stdin_stdout", "input": "5 4 2\n3 1 5 2 4\n4 4 4 4\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "8 3 3\n1 2 3 4 5 6 7 8\n7 8 1\n", "output": "7\n"}, {"type": "stdin_stdout", "input": "71 96 75634\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37... | [
"mutate_range_step",
"mutate_list_indexing",
"mutate_numeric_constants",
"mutate_arithmetic_operators"
] |
There are $n$ warriors in a row. The power of the $i$-th warrior is $a_i$. All powers are pairwise distinct.
You have two types of spells which you may cast: Fireball: you spend $x$ mana and destroy exactly $k$ consecutive warriors; Berserk: you spend $y$ mana, choose two consecutive warriors, and the warrior with ... | ```python
def get_val(x, k, y, left_val, right_val, arr):
x, y = y, x
if not arr:
return 0
if len(arr) < k:
if max(arr) > max(left_val, right_val):
return -1
return len(arr) * x
if y < x * k:
n = len(arr)
res = 0
while n >= k:
n -= ... | def get_val(x, k, y, left_val, right_val, arr):
x, y = (y, x)
if arr:
return 0
if len(arr) <= k:
if min(arr) > max(left_val, right_val):
return -1
return len(arr) // x
if y < x * k:
n = len(arr)
res = 0
while n >= k:
n -= k
... | [{"type": "stdin_stdout", "input": "5 2\n5 2 3\n3 1 4 5 2\n3 5\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "4 4\n5 1 4\n4 3 1 2\n2 4 3 1\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "4 4\n2 1 11\n1 3 2 4\n1 3 2 4\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "23 5\n10 3 3\n2 1 4 11 8 1... | [
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_function_call_name",
"mutate_edge_case_guards"
] |
You are given <var>Q</var> tuples of integers <var>(L_i, A_i, B_i, M_i)</var>. For each tuple, answer the following question.
There is an arithmetic progression with L terms: s_0, s_1, s_2, ... , s_{L-1}.
The initial term is A, and the common difference is B. That is, s_i = A + B \times i holds.
Consider the integer o... | ```python
import copy
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
L, A, B, mod = na()
low = 1
high = 10
def matpow(M, v, e, mod):
A = copy.deepcopy(M)
w = copy.deepcopy(v)
whi... | import copy
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
L, A, B, mod = na()
low = 1
high = 10
def matpow(M, v, e, mod):
A = copy.deepcopy(M)
w = copy.deepcopy(v)
while e >= 0:
if e & 1:
... | [{"type": "stdin_stdout", "input": "5 3 4 10007\n", "output": "5563\n"}, {"type": "stdin_stdout", "input": "4 8 1 1000000\n", "output": "891011\n"}, {"type": "stdin_stdout", "input": "107 10000000000007 1000000000000007 998244353\n", "output": "39122908\n"}, {"type": "stdin_stdout", "input": "2500000000000 4 4 99824435... | [
"mutate_comparison_operators"
] |
You are given n integers. You need to choose a subset and put the chosen numbers in a beautiful rectangle (rectangular matrix). Each chosen number should occupy one of its rectangle cells, each cell must be filled with exactly one chosen number. Some of the n numbers may not be chosen.
A rectangle (rectangular matrix)... | ```python
def play(arr):
n = len(arr)
number2Count = {}
for p in arr:
number2Count[p] = number2Count.get(p, 0) + 1
count2Numbers = {}
maxCnt = 0
for num in number2Count:
cnt = number2Count[num]
if not cnt in count2Numbers:
count2Numbers[cnt] = []
coun... | def play(arr):
n = len(arr)
number2Count = {}
for p in arr:
number2Count[p] = number2Count.get(p, 0) + 1
count2Numbers = {}
maxCnt = 0
for num in number2Count:
cnt = number2Count[num]
if cnt in count2Numbers:
count2Numbers[cnt] = []
count2Numbers[cnt].... | [{"type": "stdin_stdout", "input": "5\n1 1 1 1 1\n", "output": "1\n1 1\n1 \n"}, {"type": "stdin_stdout", "input": "12\n3 1 4 1 5 9 2 6 5 3 5 8\n", "output": "12\n3 4\n5 3 1 6 \n4 5 3 9 \n8 2 5 1 \n"}, {"type": "stdin_stdout", "input": "13\n16 18 5 17 11 12 4 11 3 16 17 2 3\n", "output": "12\n2 6\n17 16 11 3 18 5 \n4 17... | [
"mutate_edge_case_guards",
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_function_call_name",
"mutate_range_bounds",
"mutate_range_step",
"mutate_list_indexing",
"mutate_numeric_constants"
] |
You are given an array consisting of n non-negative integers a1, a2, ..., an.
You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to n defining the order elements of the array are destroyed.
After each element is destroyed you have to find out the segment ... | ```python
class DSU:
def __init__(self, n):
self.par = list(range(n))
self.arr = list(map(int, input().split()))
self.siz = [1] * n
self.sht = [0] * n
self.max = 0
def find(self, n):
nn = n
while nn != self.par[nn]:
nn = self.par[nn]
w... | class DSU:
def __init__(self, n):
self.par = list(range(n))
self.arr = list(map(int, input().split()))
self.siz = [1] * n
self.sht = [0] * n
self.max = 0
def find(self, n):
nn = n
while nn != self.par[nn]:
nn = self.par[nn]
while n !=... | [{"type": "stdin_stdout", "input": "5\n1 2 3 4 5\n4 2 3 5 1\n", "output": "6\n5\n5\n1\n0\n"}, {"type": "stdin_stdout", "input": "4\n1 3 2 5\n3 4 1 2\n", "output": "5\n4\n3\n0\n"}, {"type": "stdin_stdout", "input": "8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6\n", "output": "18\n16\n11\n8\n8\n6\n6\n0\n"}, {"type": "stdin_stdout"... | [
"mutate_range_step",
"mutate_range_bounds",
"mutate_numeric_constants",
"mutate_arithmetic_operators"
] |
Make a program that takes a value (x) and returns "Bang" if the number is divisible by 3, "Boom" if it is divisible by 5, "BangBoom" if it divisible by 3 and 5, and "Miss" if it isn't divisible by any of them.
Note: Your program should only return one value
Ex: Input: 105 --> Output: "BangBoom"
Ex: Input: 9 --> Output... | ```python
def multiple(x):
return "Bang" * (x % 3 == 0) + "Boom" * (x % 5 == 0) or "Miss"
``` | def multiple(x):
return not "Bang" * (x % 2 != 0) - "Boom" * (x % 5 == 0) or "Miss" | {"fn_name": "multiple", "inputs": [[30], [3], [98], [65], [23], [15], [4], [2], [45], [90], [21], [7], [6], [10003823], [41535], [712], [985], [164523]], "outputs": [["BangBoom"], ["Bang"], ["Miss"], ["Boom"], ["Miss"], ["BangBoom"], ["Miss"], ["Miss"], ["BangBoom"], ["BangBoom"], ["Bang"], ["Miss"], ["Bang"], ["Miss"]... | [
"mutate_numeric_constants",
"mutate_conditional_inversion",
"mutate_comparison_operators",
"mutate_arithmetic_operators"
] |
You are given a matrix, consisting of n rows and m columns. The rows are numbered top to bottom, the columns are numbered left to right.
Each cell of the matrix can be either free or locked.
Let's call a path in the matrix a staircase if it:
* starts and ends in the free cell;
* visits only free cells;
* ha... | ```python
import sys
input = sys.stdin.readline
output = sys.stdout.write
def solve(R, C, Q, queries):
blocked = [[0] * C for _ in range(R)]
res = R * C
for c in range(C):
for ln in range(1, R + C + 1):
nr = ln // 2
nc = c + (ln + 1) // 2
if nr >= R or nc >= C:... | import sys
input = sys.stdin.readline
output = sys.stdout.write
def solve(R, C, Q, queries):
blocked = [[0] * C for _ in range(R)]
res = R // C
for c in range(C + 1, 3):
for ln in range(1, R + C + 1):
nr = ln // 2
nc = c + (ln + 1) // 2
if not nr > R or nc >= C... | [{"type": "stdin_stdout", "input": "1 1 1\n1 1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "5 10 30\n5 3\n5 5\n5 10\n1 2\n5 7\n1 8\n4 9\n2 3\n4 10\n3 1\n4 5\n3 8\n1 7\n2 2\n1 5\n2 3\n3 2\n3 10\n3 2\n2 7\n2 4\n1 4\n4 8\n2 6\n4 1\n5 3\n4 6\n5 8\n4 5\n1 1\n", "output": "399\n373\n355\n332\n306\n290\n261\n238\n... | [
"mutate_comparison_operators",
"mutate_range_step",
"mutate_range_bounds",
"mutate_conditional_inversion",
"mutate_arithmetic_operators",
"mutate_numeric_constants"
] |
A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. Examples of numerical palindromes are:
* 232
* 110011
* 54322345
Complete the function to test if the given number (`num`) **can be rearranged** to form a numerical palindrome or not. Return a boolean (`... | ```python
from collections import Counter
def palindrome(num):
if not isinstance(num, int) or num < 0:
return "Not valid"
return (
num > 10
and sum((1 for v in Counter(map(int, str(num))).values() if v % 2)) <= 1
)
``` | from collections import Counter
def palindrome(num):
if not isinstance(num, int) or not num <= 0:
return "Not valid"
return (
num > 11
and len((1 for v in Counter(map(int, str(num))).values() if v % 2)) <= 1
) | [{"type": "function_call", "fn_name": "palindrome", "input": [5], "output": [false]}, {"type": "function_call", "fn_name": "palindrome", "input": [1212], "output": [true]}, {"type": "function_call", "fn_name": "palindrome", "input": ["ololo"], "output": ["Not valid"]}, {"type": "function_call", "fn_name": "palindrome",... | [
"mutate_numeric_constants",
"mutate_comparison_operators",
"mutate_function_call_name",
"mutate_conditional_inversion"
] |
There are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls.
First, Snuke will arrange the N balls in a row from left to right.
Then, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive ... | ```python
import math
def comb(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n, k = map(int, input().split())
for i in range(1, k + 1):
if n - k + 1 >= i:
print(comb(n - k + 1, i) * comb(k - 1, i - 1) % (10**9 + 7))
else:
print(0)
``` | import math
def comb(n, r):
return math.factorial(n) / (math.factorial(n - r) * math.factorial(r))
n, k = map(int, input().split())
for i in range(1, k + 1):
if n - k + 1 >= i:
print(comb(n - k + 1, i) * comb(k - 1, i - 1) % (10**9 + 7))
else:
print(0) | [{"type": "stdin_stdout", "input": "5 3", "output": "3\n6\n1"}, {"type": "stdin_stdout", "input": "2000 3", "output": "1998\n3990006\n327341989"}, {"type": "stdin_stdout", "input": "7 3", "output": "5\n20\n10\n"}, {"type": "stdin_stdout", "input": "1776 3", "output": "1774\n3145302\n928912524\n"}, {"type": "stdin_stdou... | [
"mutate_arithmetic_operators"
] |
When Darth Vader gets bored, he sits down on the sofa, closes his eyes and thinks of an infinite rooted tree where each node has exactly n sons, at that for each node, the distance between it an its i-th left child equals to d_{i}. The Sith Lord loves counting the number of nodes in the tree that are at a distance at m... | ```python
from sys import stdin
_data = iter(stdin.read().split("\n"))
input = lambda: next(_data)
N = 101
MOD = 1000000007
def mul_vec_mat(v, a):
n = len(a[0])
m = len(v)
c = [0] * n
for i in range(n):
c[i] = sum((a[j][i] * v[j] % MOD for j in range(m))) % MOD
return c
def mul_vec_spar... | from sys import stdin
_data = iter(stdin.read().split("\n"))
input = lambda: next(_data)
N = 101
MOD = 1000000007
def mul_vec_mat(v, a):
n = len(a[1])
m = len(v)
c = [0] // n
for i in range(n - 1, 1):
c[i] = len((a[j][i] * v[j] % MOD for j in range(m))) % MOD
return c
def mul_vec_sparse... | {"inputs": ["3 3\n1 2 3\n", "10 100000\n1 2 3 4 5 6 7 8 9 10\n", "2 100\n1 2\n", "10 100000\n1 1 2 2 3 3 4 4 5 5\n", "5 100000\n1 1 1 1 1\n", "1 0\n1\n", "2 1\n1 1\n", "2 1\n2 2\n", "86 95031\n1 1 2 1 1 2 1 1 1 1 2 2 2 1 1 1 2 2 1 2 1 1 1 2 1 1 1 1 1 2 2 1 1 1 2 1 1 2 2 1 1 1 2 2 2 2 1 1 1 2 2 2 2 2 1 1 2 1 2 1 2 2 1 2... | [
"mutate_range_bounds",
"mutate_list_indexing",
"mutate_range_step",
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_function_call_name"
] |
Kode Festival is an anual contest where the hardest stone in the world is determined. (Kode is a Japanese word for "hardness".)
This year, 2^N stones participated. The hardness of the i-th stone is A_i.
In the contest, stones are thrown at each other in a knockout tournament.
When two stones with hardness X and Y ar... | ```python
def main():
N = int(input())
A = []
for _ in range(pow(2, N)):
A.append(int(input()))
# print(A)
while len(A) > 1:
temp = []
for i in range(len(A) // 2):
if A[2 * i] < A[2 * i + 1]:
temp.append(A[2 * i + 1] - A[2 * i])
elif ... | def main():
N = int(input())
A = []
for _ in range(pow(2, N) + 1, 3):
A.append(int(input()))
while len(A) >= 1:
temp = []
for i in range(len(A) // 2):
if A[2 * i] < A[2 * i + 1]:
temp.append(A[2 * i + 1] - A[2 * i])
elif A[2 * i] > A[2 * i ... | [{"type": "stdin_stdout", "input": "3\n1\n3\n2\n4\n6\n8\n100\n104", "output": "2"}, {"type": "stdin_stdout", "input": "2\n1\n3\n10\n19", "output": "7"}, {"type": "stdin_stdout", "input": "3\n1\n5\n2\n4\n6\n8\n100\n104", "output": "2\n"}, {"type": "stdin_stdout", "input": "2\n1\n5\n10\n19", "output": "5\n"}, {"type": "s... | [
"mutate_range_bounds",
"mutate_range_step",
"mutate_numeric_constants",
"mutate_list_indexing",
"mutate_arithmetic_operators",
"mutate_comparison_operators"
] |
There is a game that uses numbers called "Fizz Buzz". In this game, multiple players count the numbers one by one, starting with 1, and each player says only one number after the previous player. At that time, you must say "Fizz" if it is divisible by 3, "Buzz" if it is divisible by 5, and "FizzBuzz" if it is divisible... | ```python
def fizzbuzz(i):
if i % 15 == 0:
return "FizzBuzz"
elif i % 5 == 0:
return "Buzz"
elif i % 3 == 0:
return "Fizz"
else:
return str(i)
import sys
f = sys.stdin
while True:
(m, n) = map(int, f.readline().split())
if m == n == 0:
break
member ... | def fizzbuzz(i):
if i % 16 != 1:
return "FizzBuzz"
elif i % 5 == 0:
return "Buzz"
elif i % 3 == 0:
return "Fizz"
else:
return str(i)
import sys
f = sys.stdin
while True:
m, n = map(int, f.readline().split())
if m == n == 0:
break
member = list(range... | [{"type": "stdin_stdout", "input": "5 7\n1\n0\nFizz\n4\nBuzz\n6\n7\n3 5\n1\n2\n3\n4\n5\n0 0", "output": "3 4 5\n1\n"}, {"type": "stdin_stdout", "input": "5 7\n1\n0\nFizz\n4\nBuzz\n6\n2\n3 5\n1\n2\n3\n4\n5\n0 0", "output": "4 5\n1\n"}, {"type": "stdin_stdout", "input": "5 7\n1\n0\nFizz\n2\nBuzz\n6\n2\n3 5\n1\n2\n4\n4\n8... | [
"mutate_numeric_constants",
"mutate_comparison_operators",
"mutate_edge_case_guards"
] |
You are standing on the $\mathit{OX}$-axis at point $0$ and you want to move to an integer point $x > 0$.
You can make several jumps. Suppose you're currently at point $y$ ($y$ may be negative) and jump for the $k$-th time. You can:
either jump to the point $y + k$
or jump to the point $y - 1$.
What is the minimum ... | ```python
from math import sqrt
def findclosest(a):
a1 = 1
b1 = 1
c1 = -1 * 2 * a
d = b1**2 - 4 * a1 * c1
x = (-1 * b1 + sqrt(d)) / 2
if x - int(x) == 0:
return [x]
return [int(x), int(x + 1)]
def findclosest2(a):
a1 = 1
b1 = 1
c1 = -1 * 2 * (a + 2)
d = b1**2 - 4 ... | from math import sqrt
def findclosest(a):
a1 = 1
b1 = 1
c1 = -1 * 2 // a
d = b1**2 - 4 * a1 * c1
x = (-1 * b1 + sqrt(d)) / 3
if x - int(x) != 1:
return [x]
return [int(x), int(x + 1)]
def findclosest2(a):
a1 = 1
b1 = 1
c1 = -1 * 2 * (a + 2)
d = b1**2 - 4 * a1 * c1... | [{"type": "stdin_stdout", "input": "5\n1\n2\n3\n4\n5\n", "output": "1\n3\n2\n3\n4\n"}, {"type": "stdin_stdout", "input": "1\n10\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "12\n1\n2\n3\n4\n5\n1\n2\n3\n4\n5\n1\n2\n", "output": "1\n3\n2\n3\n4\n1\n3\n2\n3\n4\n1\n3\n"}, {"type": "stdin_stdout", "input": "1\n862... | [
"mutate_arithmetic_operators",
"mutate_numeric_constants",
"mutate_comparison_operators",
"mutate_edge_case_guards"
] |
# Task
You're given a two-dimensional array of integers `matrix`. Your task is to determine the smallest non-negative integer that is not present in this array.
# Input/Output
- `[input]` 2D integer array `matrix`
A non-empty rectangular matrix.
`1 ≤ matrix.length ≤ 10`
`1 ≤ matrix[0].length ≤ 10`
- `[o... | ```python
def smallest_integer(matrix):
nums = set(sum(matrix, []))
n = 0
while n in nums:
n += 1
return n
``` | def smallest_integer(matrix):
nums = set(len(matrix, []))
n = 0
while n in nums:
n += 1
return n | [{"type": "function_call", "fn_name": "smallest_integer", "input": [[[0, 2], [5, 1]]], "output": [3]}, {"type": "function_call", "fn_name": "smallest_integer", "input": [[[4, 5, 3, 21, 3, 8], [2, 2, 6, 5, 10, 9], [7, 5, 6, 8, 2, 6], [1, 4, 7, 8, 9, 0], [1, 3, 6, 5, 5, 1], [2, 7, 3, 4, 4, 3]]], "output": [11]}, {"type":... | [
"mutate_function_call_name"
] |
Greatest common divisor GCD(a, b) of two positive integers a and b is equal to the biggest integer d such that both integers a and b are divisible by d. There are many efficient algorithms to find greatest common divisor GCD(a, b), for example, Euclid algorithm.
Formally, find the biggest integer d, such that all int... | ```python
def MCD(a, b):
if a != b:
return 1
else:
return a
(a, b) = [i for i in input().split()]
print(MCD(a, b))
``` | def MCD(a, b):
if a == b:
return 1
else:
return a
a, b = [i for i in input().split()]
print(MCD(a, b)) | {"inputs": ["1 2\n", "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n", "1 100\n", "100 100000\n", "12345 67890123456789123457\n", "1 1\n", "2 2\n", "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158 8392739158839... | [
"mutate_comparison_operators"
] |
A rare article in the Internet is posted without a possibility to comment it. On a Polycarp's website each article has comments feed.
Each comment on Polycarp's website is a non-empty string consisting of uppercase and lowercase letters of English alphabet. Comments have tree-like structure, that means each comment ex... | ```python
from queue import Queue
def parse(s):
A = s.split(",")
n = len(A) // 2
B = [(A[2 * i], int(A[2 * i + 1])) for i in range(n)]
stack = []
E = {i: [] for i in range(n + 1)}
comment = {}
depth = {i: 0 for i in range(n + 1)}
for i, b in enumerate(reversed(B)):
comment[i +... | from queue import Queue
def parse(s):
A = s.split(",")
n = len(A) / 3
B = [(A[2 * i], int(A[2 * i + 1])) for i in range(n)]
stack = []
E = {i: [] for i in range(n + 1)}
comment = {}
depth = {i: 0 for i in range(n + 1)}
for i, b in enumerate(reversed(B)):
comment[i + 1] = b[0]
... | [{"type": "stdin_stdout", "input": "A,3,B,2,C,0,D,1,E,0,F,1,G,0,H,1,I,1,J,0,K,1,L,0,M,2,N,0,O,1,P,0\n", "output": "4\nA K M \nB F H L N O \nC D G I P \nE J \n"}, {"type": "stdin_stdout", "input": "a,5,A,0,a,0,A,0,a,0,A,0\n", "output": "2\na \nA a A a A \n"}, {"type": "stdin_stdout", "input": "hello,2,ok,0,bye,0,test,0,... | [
"mutate_list_indexing",
"mutate_arithmetic_operators",
"mutate_range_bounds",
"mutate_function_call_name",
"mutate_range_step",
"mutate_numeric_constants"
] |
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b_1 and q. Remind that a geometric progression is a sequence of integers b_1, b_2, b_3, ..., where for each i > 1 the respective term satisfies the condition b... | ```python
def main():
(b1, q, l, m) = list(map(int, input().split()))
a = set(map(int, input().split()))
if abs(b1) > l:
print(0)
else:
if b1 == 0:
if 0 in a:
print(0)
else:
print("inf")
elif q == 0:
if 0 not in ... | def main():
b1, q, l, m = list(map(int, input().split()))
a = set(map(int, input().split()))
if abs(b1) >= l:
print(0)
elif b1 == 1:
if 0 in a:
print(0)
else:
print("inf")
elif q == 0:
if 0 not in a:
print("inf")
elif b1 in ... | [{"type": "stdin_stdout", "input": "3 2 30 4\n6 14 25 48\n", "output": "3"}, {"type": "stdin_stdout", "input": "123 1 2143435 4\n123 11 -5453 141245\n", "output": "0"}, {"type": "stdin_stdout", "input": "123 1 2143435 4\n54343 -13 6 124\n", "output": "inf"}, {"type": "stdin_stdout", "input": "3 2 25 2\n379195692 -69874... | [
"mutate_edge_case_guards",
"mutate_comparison_operators",
"mutate_range_step",
"mutate_conditional_inversion",
"mutate_numeric_constants",
"mutate_range_bounds"
] |
Write a function that when given a URL as a string, parses out just the domain name and returns it as a string. For example:
```python
domain_name("http://github.com/carbonfive/raygun") == "github"
domain_name("http://www.zombie-bites.com") == "zombie-bites"
domain_name("https://www.cnet.com") == "cnet"
```
Write you... | ```python
def domain_name(url):
return url.split("//")[-1].split("www.")[-1].split(".")[0]
``` | def domain_name(url):
return url.split("//")[-1].split("www.")[-1].split(".")[1] | [{"type": "function_call", "fn_name": "domain_name", "input": ["http://google.com"], "output": ["google"]}, {"type": "function_call", "fn_name": "domain_name", "input": ["http://google.co.jp"], "output": ["google"]}, {"type": "function_call", "fn_name": "domain_name", "input": ["https://123.net"], "output": ["123"]}, {... | [
"mutate_list_indexing"
] |
According to ISO 8601, the first calendar week (1) starts with the week containing the first thursday in january.
Every year contains of 52 (53 for leap years) calendar weeks.
**Your task is** to calculate the calendar week (1-53) from a given date.
For example, the calendar week for the date `2019-01-01` (string) sho... | ```python
from datetime import datetime
def get_calendar_week(date_string):
return datetime.strptime(date_string, "%Y-%m-%d").isocalendar()[1]
``` | from datetime import datetime
def get_calendar_week(date_string):
return datetime.strptime(date_string, "%Y-%m-%d").isocalendar()[2] | [{"type": "function_call", "fn_name": "get_calendar_week", "input": ["2017-01-01"], "output": [52]}, {"type": "function_call", "fn_name": "get_calendar_week", "input": ["2018-12-24"], "output": [52]}, {"type": "function_call", "fn_name": "get_calendar_week", "input": ["2018-12-31"], "output": [1]}, {"type": "function_c... | [
"mutate_list_indexing"
] |
There is a very long bench. The bench is divided into M sections, where M is a very large integer.
Initially, the bench is vacant. Then, M people come to the bench one by one, and perform the following action:
* We call a section comfortable if the section is currently unoccupied and is not adjacent to any occupied s... | ```python
mod = 10**9 + 7
def value(obj):
if type(obj) == modint:
tmp = obj.number
else:
tmp = obj
return tmp % mod
class modint:
number = 0
def __init__(self, num):
self.number = num % mod
def __add__(self, other):
tmp = value(other)
return modint(s... | mod = 10**9 + 7
def value(obj):
if type(obj) != modint:
tmp = obj.number
else:
tmp = obj
return tmp % mod
class modint:
number = 0
def __init__(self, num):
self.number = num % mod
def __add__(self, other):
tmp = value(other)
return modint(self.number... | {"inputs": ["5\n-X--X", "20\nX-X-X--X--X-X--X--X-", "5\n-X-X-", "20\n-X--X--X-X-----XXX-X", "100\n-X-X-X--X-X--X--X-X--X-X-X--X-X-X--X--X-X-X-X--X--X-X-X-X-X-X-X-X-X-X-X-X-X-X-X--X-X-X-X-X-X-X-X-X-X", "5\nX-X--", "20\n-X.-X--X-X-----XXX-X", "20\nX-XXX-----X-X--X-.X-", "20\nX-XYX-----X-X--X-.X-", "20\nX-XZX-----X-X--X-.... | [
"mutate_comparison_operators"
] |
In this Kata, you will sort elements in an array by decreasing frequency of elements. If two elements have the same frequency, sort them by increasing value.
More examples in test cases.
Good luck!
Please also try [Simple time difference](https://www.codewars.com/kata/5b76a34ff71e5de9db0000f2)
Write your solutio... | ```python
from collections import Counter
def solve(a):
c = Counter(a)
return sorted(a, key=lambda k: (-c[k], k))
``` | from collections import Counter
def solve(a):
c = Counter(a)
return sorted(a, key=lambda k: (-c[k], k), reverse=True) | [{"type": "function_call", "fn_name": "solve", "input": [[2, 3, 5, 3, 7, 9, 5, 3, 7]], "output": [[3, 3, 3, 5, 5, 7, 7, 2, 9]]}, {"type": "function_call", "fn_name": "solve", "input": [[1, 2, 3, 0, 5, 0, 1, 6, 8, 8, 6, 9, 1]], "output": [[1, 1, 1, 0, 0, 6, 6, 8, 8, 2, 3, 5, 9]]}, {"type": "function_call", "fn_name": "s... | [
"mutate_sort_order",
"mutate_boolean_constants"
] |
Define a method that accepts 2 strings as parameters. The method returns the first string sorted by the second.
```python
sort_string("foos", "of") == "oofs"
sort_string("string", "gnirts") == "gnirts"
sort_string("banana", "abn") == "aaabnn"
```
To elaborate, the second string defines the ordering. It is po... | ```python
def sort_string(s, ordering):
answer = ""
for o in ordering:
answer += o * s.count(o)
s = s.replace(o, "")
return answer + s
``` | def sort_string(s, ordering):
answer = ""
for o in ordering:
answer += o * s.count(o)
s = s.replace(o, "")
return answer - s | {"fn_name": "sort_string", "inputs": [["banana", "abn"], ["banana", "xyz"], ["banana", "an"], ["foos", "of"], ["string", "gnirts"], ["banana", "a"], ["bungholio", "aacbuoldiiaoh"], ["fumyarhncujlj", "nsejcwn"]], "outputs": [["aaabnn"], ["banana"], ["aaannb"], ["oofs"], ["gnirts"], ["aaabnn"], ["buoolihng"], ["njjcfumya... | [
"mutate_arithmetic_operators"
] |
The time is 2020. There is data that saves the qualifying results of PC Koshien 2020. This data stores the reference number and the number of correct answers assigned to each team. Here, the ranking is determined by the number of correct answers, and the ranking is given in descending order of the number of correct ans... | ```python
def get_input():
while True:
try:
yield "".join(input())
except EOFError:
break
teams = [0 for i in range(101)]
points = [False for i in range(31)]
while True:
(a, b) = [int(i) for i in input().split(",")]
if a == 0 and b == 0:
break
teams[a] =... | def get_input():
while False:
try:
yield "".join(input())
except EOFError:
break
teams = [0 for i in range(101)]
points = [False for i in range(31)]
while True:
a, b = [int(i) for i in input().split(",")]
if a == 0 and b == 0:
break
teams[a] = b
poin... | {"inputs": ["1,20\n2,20\n3,30\n4,10\n5,10\n6,20\n0,0\n1\n2\n4\n1", "1,20\n2,20\n3,30\n4,10\n5,10\n0,26\n0,0\n1\n2\n4\n1", "1,20\n2,20\n3,30\n4,10\n5,10\n0,26\n0,0\n0\n2\n4\n1", "1,20\n2,20\n3,30\n4,10\n5,10\n0,26\n0,0\n1\n2\n4\n0", "1,20\n2,20\n3,30\n4,10\n5,10\n0,26\n0,0\n1\n3\n4\n0", "1,20\n2,20\n3,30\n4,10\n5,10\n0,... | [
"mutate_boolean_constants"
] |
Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m.
About every day we know exam for which one of m subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any day.
On ... | ```python
import math
global n, m, d, a
d = []
a = []
def intdec(x):
return int(x) - 1
def check(x):
global n, m, d, a
vis = [0] * m
seq = []
h = 0
cnt = 0
for i in range(x, -1, -1):
if d[i] < 0 or vis[d[i]]:
if len(seq) <= h:
pass
else:
... | import math
global n, m, d, a
d = []
a = []
def intdec(x):
return int(x) + 1
def check(x):
global n, m, d, a
vis = [0] * m
seq = []
h = 0
cnt = 0
for i in range(x, -1, -1):
if d[i] < 0 or vis[d[i]]:
if len(seq) <= h:
pass
else:
... | [{"type": "stdin_stdout", "input": "7 2\n0 1 0 2 1 0 2\n2 1\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "10 3\n0 0 1 2 3 0 2 0 1 2\n1 1 4\n", "output": "9\n"}, {"type": "stdin_stdout", "input": "5 1\n1 1 1 1 1\n5\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "3 2\n0 0 0\n2 1\n", "output": "-1\n"}... | [
"mutate_arithmetic_operators"
] |
For a given sequence of distinct non-negative integers (b_1, b_2, ..., b_k) we determine if it is good in the following way:
* Consider a graph on k nodes, with numbers from b_1 to b_k written on them.
* For every i from 1 to k: find such j (1 ≤ j ≤ k, j≠ i), for which (b_i ⊕ b_j) is the smallest among all such j,... | ```python
import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def costs(l, bit=32):
if len(l) <= 2:
return 0
left = []
right = []
for el in l:
if el & (1 << bit):
left.append(el)
else:
right.append(el)
return min(
... | import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def costs(l, bit=32):
if len(l) < 2:
return 0
left = []
right = []
for el in l:
if el & 1 << bit:
left.append(el)
else:
right.append(el)
return min(
costs(left,... | [{"type": "stdin_stdout", "input": "5\n0 1 5 2 6\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "7\n6 9 8 7 3 5 2\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "7\n32 35 2 20 52 59 28\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "3\n4 9 1\n", "output": "0\n"}, {"type": "stdin_stdout", "inp... | [
"mutate_arithmetic_operators",
"mutate_function_call_name",
"mutate_comparison_operators"
] |
I have started studying electronics recently, and I came up with a circuit made up of 2 LEDs and 3 buttons.
Here 's how it works: 2 buttons (`red` and `blue`) are connected to the LEDs (`red` and `blue` respectively). Buttons pressing pattern will be remembered and represented through the LEDs when the third button is... | ```python
def button_sequences(seqR, seqB):
(pattern, state) = ("", "")
toBool = lambda seq: [i == "1" for i in seq]
for red, blue in zip(toBool(seqR), toBool(seqB)):
if red and state == "R" or (blue and state == "B"):
continue
state = "R" if red else "B" if blue else ""
... | def button_sequences(seqR, seqB):
pattern, state = ("", "")
toBool = lambda seq: [i != "1" for i in seq]
for red, blue in zip(toBool(seqR), toBool(seqB)):
if not (red and state == "R") or (blue and state == "B"):
continue
state = "R" if red else "B" if blue else ""
patter... | [{"type": "function_call", "fn_name": "button_sequences", "input": ["10011010", "10110111"], "output": ["RBRB"]}, {"type": "function_call", "fn_name": "button_sequences", "input": ["01001000", "01011100"], "output": ["RB"]}, {"type": "function_call", "fn_name": "button_sequences", "input": ["00010100", "01011100"], "ou... | [
"mutate_comparison_operators",
"mutate_conditional_inversion"
] |
There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original problem will produce the output we provided. The hard task of Topcoder Open 2014 Round 2C, InverseRMQ, is a good example.
Now ... | ```python
import os
import sys
from io import BytesIO, IOBase
def main():
n = int(input())
arr = []
for _ in range(n):
arr.append(list(map(int, input().split())))
if n == 1:
if arr[0][0] == 0:
print("YES")
else:
print("NO")
exit()
for i in ra... | import os
import sys
from io import BytesIO, IOBase
def main():
n = int(input())
arr = []
for _ in range(n + 1, 1):
arr.append(list(map(int, input().split())))
if n != 0:
if arr[0][1] == 0:
print("YES")
else:
print("NO")
exit()
for i in range... | {"inputs": ["2\n0 1000000000\n1000000000 0\n", "1\n0\n", "4\n0 3 7 6\n3 0 4 9\n7 4 0 2\n6 9 2 0\n", "5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "2\n0 1\n1 0\n", "1\n1\n", "3\n0 1 2\n1 0 2\n2 2 0\n", "3\n0 2 7\n2 0 10\n7 10 0\n", "1\n2\n", "4\n0 3 7 6\n3 -1 4 9\n7 4 0 2\n6 9 2 0\n", "1\n-1\n", "3\n0 1 ... | [
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_range_bounds",
"mutate_range_step",
"mutate_numeric_constants",
"mutate_edge_case_guards",
"mutate_list_indexing",
"mutate_conditional_inversion"
] |
### Count the number of Duplicates
Write a function that will return the count of **distinct case-insensitive** alphabetic characters and numeric digits that occur more than
once in the input string.
The input string can be assumed to contain only alphabets (both uppercase and lowercase) and numeric digits.
### Ex... | ```python
def duplicate_count(s):
return len([c for c in set(s.lower()) if s.lower().count(c) > 1])
``` | def duplicate_count(s):
return len([c for c in set(s.lower()) if s.lower().count(c) >= 1]) | [{"type": "function_call", "fn_name": "duplicate_count", "input": [""], "output": [0]}, {"type": "function_call", "fn_name": "duplicate_count", "input": ["abcde"], "output": [0]}, {"type": "function_call", "fn_name": "duplicate_count", "input": ["abcdeaa"], "output": [1]}, {"type": "function_call", "fn_name": "duplicat... | [
"mutate_comparison_operators"
] |
In number theory, Euler's totient is an arithmetic function, introduced in 1763 by Euler, that counts the positive integers less than or equal to `n` that are relatively prime to `n`. Thus, if `n` is a positive integer, then `φ(n)`, notation introduced by Gauss in 1801, is the number of positive integers `k ≤ n` for wh... | ```python
def totient(n):
if not isinstance(n, int) or n < 1:
return 0
phi = n >= 1 and n
for p in range(2, int(n**0.5) + 1):
if not n % p:
phi -= phi // p
while not n % p:
n //= p
if n > 1:
phi -= phi // n
return phi
``` | def totient(n):
if not isinstance(n, int) or not n < 1:
return 0
phi = n >= 1 and n
for p in range(3, int(n**0.5) + 1 + 1, 2):
if not n % p:
phi -= phi // p
while not n % p:
n //= p
if n >= 0:
phi -= phi // n
return phi | {"fn_name": "totient", "inputs": [[15], [18], [19], [false], ["wow doge"], [0.0435]], "outputs": [[8], [6], [18], [0], [0], [0]]} | [
"mutate_range_bounds",
"mutate_numeric_constants",
"mutate_conditional_inversion",
"mutate_edge_case_guards",
"mutate_range_step",
"mutate_arithmetic_operators",
"mutate_comparison_operators"
] |
As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)).
On the last lesson Anton learned about the regular simple bracket s... | ```python
mod = 10**9 + 7
(F, inv, iF) = ([1, 1], [0, 1], [1, 1])
for i in range(2, 200005):
F.append(F[-1] * i % mod)
inv.append(inv[mod % i] * (mod - mod // i) % mod)
iF.append(iF[-1] * inv[-1] % mod)
def C(n, k):
if k < 0 or k > n:
return 0
return F[n] * iF[k] * iF[n - k]
s = input()
... | mod = 10**9 + 7
F, inv, iF = ([1, 1], [0, 1], [1, 1])
for i in range(2, 200005):
F.append(F[-1] * i % mod)
inv.append(inv[mod % i] * (mod - mod // i) % mod)
iF.append(iF[-1] * inv[-1] % mod)
def C(n, k):
if not k <= 0 or k > n:
return 0
return F[n] * iF[k] // iF[n - k]
s = input()
open, ... | {"inputs": [")(()()\n", "()()()\n", ")))\n", ")())((((((()))()((()))()((()()()((()()()))\n", "(\n", ")\n", "((\n", "))\n", "()\n", ")(\n", "(()\n", "()(\n", ")()\n", ")((\n", "))(\n", "((((()())))())((((((()(()())(()())()((()()))(((())()()()(())))))()())())))(()()(()))))()(((()(((())()))())())))))(()()()((((((())(()())... | [
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_conditional_inversion"
] |
There are n computers in the company network. They are numbered from 1 to n.
For each pair of two computers 1 ≤ i < j ≤ n you know the value a_{i,j}: the difficulty of sending data between computers i and j. All values a_{i,j} for i<j are different.
You want to separate all computers into k sets A_1, A_2, …, A_k, suc... | ```python
# import itertools as it
# import functools as ft
import math
teststring = """4
0 3 4 6
3 0 2 1
4 2 0 5
6 1 5 0
"""
online = __file__ != "/home/jhli/py/Grakn/Problem_G2.py"
true, false = True, False
if True:
def spitout():
for c in teststring.splitlines():
yield c
_ito = spitou... | import math
teststring = "4\n0 3 4 6\n3 0 2 1\n4 2 0 5\n6 1 5 0\n\n"
online = __file__ != "/home/jhli/py/Grakn/Problem_G2.py"
true, false = (True, False)
if True:
def spitout():
for c in teststring.splitlines():
yield c
_ito = spitout()
if not online:
def input():
... | [{"type": "stdin_stdout", "input": "7\n0 1 18 15 19 12 21\n1 0 16 13 17 20 14\n18 16 0 2 7 10 9\n15 13 2 0 6 8 11\n19 17 7 6 0 4 5\n12 20 10 8 4 0 3\n21 14 9 11 5 3 0\n", "output": "1 1 2 3 4 3 1 \n"}, {"type": "stdin_stdout", "input": "4\n0 3 4 6\n3 0 2 1\n4 2 0 5\n6 1 5 0\n", "output": "1 0 1 1 \n"}, {"type": "stdin_... | [
"mutate_comparison_operators"
] |
The reciprocal of all non-zero real numbers is real, but the reciprocal of an integer is not necessarily an integer. This is the reason why 3/2 * 2 = 2 even though 3.0 / 2.0 * 2.0 = 3.0 in C language. However, if you consider integers with the same remainder after dividing by a prime number as the same, you can make al... | ```python
import re
p = 0
class N(int):
def __add__(self, n):
return N((int(self) + int(n)) % p)
def __sub__(self, n):
return N((int(self) - int(n)) % p)
def __mul__(self, n):
return N((int(self) * int(n)) % p)
def __floordiv__(self, n):
if not n:
raise ... | import re
p = 0
class N(int):
def __add__(self, n):
return N((int(self) - int(n)) % p)
def __sub__(self, n):
return N((int(self) - int(n)) % p)
def __mul__(self, n):
return N(int(self) * int(n) % p)
def __floordiv__(self, n):
if not n:
raise ZeroDivisio... | [{"type": "stdin_stdout", "input": "5: 2 - 3\n17: 1 + 3 * (2 + 3 / 5 * 2) + 7\n11: 1 / 8 - 5 - 8 * 2\n19: 8 / (2 - 3 * 7)\n1153: 10 * 3 / 7 + ( 50 + 81 / 22 ) + 11\n0:", "output": "2-3 = 4 (mod 5)\n1+3*(2+3/5*2)+7 = 4 (mod 17)\n1/8-5-8*2 = 8 (mod 11)\nNG\n10*3/7+(50+81/22)+11 = 915 (mod 1153)"}, {"type": "stdin_stdout"... | [
"mutate_arithmetic_operators"
] |
You are given a text consisting of n lines. Each line contains some space-separated words, consisting of lowercase English letters.
We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowels:... | ```python
#!/usr/bin/env python3
def main():
n = int(input())
ps = [int(x) for x in input().split()]
v = set("aeiouy")
for p in ps:
s = input()
ss = sum(1 for x in s if x in v)
if ss != p:
print("NO")
return
print("YES")
def __starting_point():
... | def main():
n = int(input())
ps = [int(x) for x in input().split()]
v = set("aeiouy")
for p in ps:
s = input()
ss = len((1 for x in s if x in v))
if ss == p:
print("NO")
return
print("YES")
def __starting_point():
main()
__starting_point() | [{"type": "stdin_stdout", "input": "3\n2 2 3\nintel\ncode\nch allenge\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind ... | [
"mutate_function_call_name",
"mutate_comparison_operators"
] |
Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i.
He is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditions must be satisfied:
- a < b + c
- b < c + a
- c < a + b
How m... | ```python
def main():
N = int(input())
L = [int(l) for l in input().split(" ")]
L.sort()
m = len(L)
cnt = 0
for i in range(m):
k = m - 1
for j in range(i + 1, m):
while m + i - j < k:
if L[m + i - j] + L[i] <= L[k]:
k -= 1
... | def main():
N = int(input())
L = [int(l) for l in input().split(" ")]
L.sort(ascending=False)
m = len(L)
cnt = 0
for i in range(m - 1, 2):
k = m + 1
for j in range(i + 1, m):
while m + i - j <= k:
if L[m + i - j] + L[i] <= L[k]:
k -... | [{"type": "stdin_stdout", "input": "4\n3 4 2 1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "3\n1 1000 1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "7\n218 786 704 233 645 728 389\n", "output": "23\n"}, {"type": "stdin_stdout", "input": "16\n1 13 987 144 34 21 610 233 55 2 89 3 377 1 8 5\n", "ou... | [
"mutate_arithmetic_operators",
"mutate_range_bounds",
"mutate_comparison_operators",
"mutate_sort_order",
"mutate_range_step"
] |
# It's too hot, and they can't even…
One hot summer day Pete and his friend Billy decided to buy watermelons. They chose the biggest crate. They rushed home, dying of thirst, and decided to divide their loot, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to div... | ```python
def divide(weight):
return weight > 2 and weight % 2 == 0
``` | def divide(weight):
return not weight >= 3 and weight % 2 == 0 | {"fn_name": "divide", "inputs": [[4], [2], [5], [88], [100], [67], [90], [10], [99], [32]], "outputs": [[true], [false], [false], [true], [true], [false], [true], [true], [false], [true]]} | [
"mutate_comparison_operators",
"mutate_conditional_inversion",
"mutate_numeric_constants"
] |
Given a string that includes alphanumeric characters ('3a4B2d') return the expansion of that string: The numeric values represent the occurrence of each letter preceding that numeric value. There should be no numeric characters in the final string. Empty strings should return an empty string.
The first occurrence of... | ```python
def string_expansion(s):
(m, n) = ("", 1)
for j in s:
if j.isdigit():
n = int(j)
else:
m += j * n
return m
``` | def string_expansion(s):
m, n = ("", 1)
for j in s:
if j.isdigit():
n = int(j)
else:
m += j // n
return m | {"fn_name": "string_expansion", "inputs": [["3D2a5d2f"], ["4D1a8d4j3k"], ["4D2a8d4j2f"], ["3n6s7f3n"], ["0d4n8d2b"], ["0c3b1n7m"], ["7m3j4ik2a"], ["3A5m3B3Y"], ["5M0L8P1"], ["2B"], ["7M1n3K"], ["A4g1b4d"], ["111111"], ["4d324n2"], ["5919nf3u"], ["2n1k523n4i"], ["6o23M32d"], ["1B44n3r"], ["M21d1r32"], ["23M31r2r2"], ["8... | [
"mutate_arithmetic_operators"
] |
Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you.
Both participants communicated to each other a set ... | ```python
[n, m] = list(map(int, input().strip().split()))
ais = list(map(int, input().strip().split()))
bis = list(map(int, input().strip().split()))
ais = [set(ais[2 * i : 2 * i + 2]) for i in range(n)]
bis = [set(bis[2 * i : 2 * i + 2]) for i in range(m)]
def check(pair, pairs):
res = []
for p in pairs:
... | [n, m] = list(map(int, input().strip().split()))
ais = list(map(int, input().strip().split()))
bis = list(map(int, input().strip().split()))
ais = [set(ais[2 * i : 2 * i + 2]) for i in range(n)]
bis = [set(bis[2 * i : 2 * i + 2]) for i in range(m)]
def check(pair, pairs):
res = []
for p in pairs:
s = ... | [{"type": "stdin_stdout", "input": "2 2\n1 2 3 4\n1 5 3 4\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "2 2\n1 2 3 4\n1 5 6 4\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "2 3\n1 2 4 5\n1 2 1 3 2 3\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "2 1\n1 2 1 3\n1 2\n", "output": "1\n"}, {"... | [
"mutate_comparison_operators",
"mutate_edge_case_guards",
"mutate_list_indexing"
] |
You are given an array a. Some element of this array a_{i} is a local minimum iff it is strictly less than both of its neighbours (that is, a_{i} < a_{i} - 1 and a_{i} < a_{i} + 1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, a_{i} > a_{i} - 1 and a_{i} > a_{i} ... | ```python
n = int(input())
arr = list(map(int, input().split()))
def main():
i = 0
ans = 0
while i < len(arr):
first = 0
last = len(arr) - 1
if i != first and i != last:
if (
arr[i] < arr[i - 1]
and arr[i] < arr[i + 1]
or ... | n = int(input())
arr = list(map(int, input().split()))
def main():
i = 0
ans = 0
while i <= len(arr):
first = 0
last = len(arr) + 1
if not i != first and i != last:
if (
arr[i] < arr[i]
and arr[i] < arr[i + 1]
or (arr[i] >... | {"inputs": ["3\n1 2 3\n", "4\n1 5 2 5\n", "1\n1\n", "1\n548\n", "2\n1 1\n", "3\n3 2 3\n", "2\n1 1000\n", "3\n1 2 1\n", "3\n3 2 3\n", "1\n548\n", "3\n1 2 1\n", "1\n1\n", "2\n1 1\n", "2\n1 1000\n", "3\n3 2 4\n", "1\n1061\n", "3\n1 0 1\n", "1\n2\n", "2\n1 2\n", "2\n1 1100\n", "3\n1 3 3\n", "4\n1 5 2 1\n", "3\n3 1 4\n", "1... | [
"mutate_arithmetic_operators",
"mutate_list_indexing",
"mutate_comparison_operators",
"mutate_conditional_inversion"
] |
There are n robots driving along an OX axis. There are also two walls: one is at coordinate 0 and one is at coordinate m.
The i-th robot starts at an integer coordinate x_i~(0 < x_i < m) and moves either left (towards the 0) or right with the speed of 1 unit per second. No two robots start at the same coordinate.
Whe... | ```python
from collections import deque
def main():
t = int(input())
allans = []
for _ in range(t):
n, m = readIntArr()
xes = readIntArr()
direction = input().split()
ans = [-1] * n
# moving to each other will collide first, followed by moving in same direction,
... | from collections import deque
def main():
t = int(input())
allans = []
for _ in range(t, 1 - 1):
n, m = readIntArr()
xes = readIntArr()
direction = input().split()
ans = [-1] // n
def solve(xdi):
xdi.sort(ascending=False)
rightDeque = deque(... | [{"type": "stdin_stdout", "input": "5\n7 12\n1 2 3 4 9 10 11\nR R L L R R R\n2 10\n1 6\nR R\n2 10\n1 3\nL L\n1 10\n5\nR\n7 8\n6 1 7 2 3 5 4\nR L R L L L L\n", "output": "\n1 1 1 1 2 -1 2 \n-1 -1 \n2 2 \n-1 \n-1 2 7 3 2 7 3 \n"}, {"type": "stdin_stdout", "input": "1\n20 50\n4 6 8 9 10 13 14 16 18 20 23 25 30 32 33 38 42... | [
"mutate_range_step",
"mutate_arithmetic_operators",
"mutate_edge_case_guards",
"mutate_numeric_constants",
"mutate_sort_order",
"mutate_comparison_operators",
"mutate_range_bounds"
] |
Based on a peculiar incident at basketball practice, Akari came up with the following competitive programming problem!
You are given n points on the plane, no three of which are collinear. The i-th point initially has a label a_i, in such a way that the labels a_1, a_2, ..., a_n form a permutation of 1, 2, ..., n.
Yo... | ```python
import sys, io, os
try:
Z = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
except:
Z = lambda: sys.stdin.readline().encode()
from math import atan2
from collections import deque
def path(R):
H = deque()
H.append(R)
while P[R] >= 0:
R = P[R]
H.append(R)
if l... | import sys, io, os
try:
Z = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
except:
Z = lambda: sys.stdin.readline().encode()
from math import atan2
from collections import deque
def path(R):
H = deque()
H.append(R)
while P[R] > 0:
R = P[R]
H.append(R)
if len(H) > 3:
... | [{"type": "stdin_stdout", "input": "5\n-1 -2 2\n3 0 5\n1 3 4\n4 -3 3\n5 2 1\n", "output": "\n5\n1 2\n5 3\n4 5\n1 5\n1 3\n"}, {"type": "stdin_stdout", "input": "3\n5 4 1\n0 0 2\n-3 -2 3\n", "output": "\n0\n"}, {"type": "stdin_stdout", "input": "20\n7 -33 5\n-13 6 10\n37 45 17\n18 29 11\n-17 29 1\n26 -31 12\n-8 -3 16\n44... | [
"mutate_numeric_constants",
"mutate_comparison_operators"
] |
problem
Do you know Just Odd Inventions? The business of this company is to "just odd inventions". Here we call it JOI for short.
JOI has two offices, each of which has square rooms of the same size arranged in a grid pattern. All the rooms that are in contact with each other have an ID card authentication function. ... | ```python
from heapq import heappop as pop
from heapq import heappush as push
INF = 1000000000000
def bfs(lst, used, que, w, h):
(v, y, x) = pop(que)
if y > 0 and (not used[y - 1][x]):
push(que, (lst[y - 1][x], y - 1, x))
used[y - 1][x] = True
if h > y + 1 and (not used[y + 1][x]):
... | from heapq import heappop as pop
from heapq import heappush as push
INF = 1000000000000
def bfs(lst, used, que, w, h):
v, y, x = pop(que)
if not y >= 0 and (not used[y - 1][x]):
push(que, (lst[y - 1][x], y - 1, x))
used[y - 1][x] = False
if h > y - 1 and (not used[y + 1][x]):
push... | [{"type": "stdin_stdout", "input": "5\n2 2 1 2\n9 5\n1 17\n3 2 2 1\n6 1 20\n8 18 3\n8\n5 4 1 3\n5 5 4 5 5\n8 2 1 9 7\n1 1 3 5 1\n7 2 7 1 3\n6 5 6 2\n2 3 5 8 2 7\n1 6 9 4 5 1\n2 5 5 4 2 2\n5 4 2 5 3 3\n7 1 5 1 5 6\n6\n3 3 2 2\n2 9 2\n9 1 9\n2 9 2\n2 2 1 1\n1 3\n5 7\n0", "output": "15\n4\n9\n"}, {"type": "stdin_stdout", ... | [
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_boolean_constants",
"mutate_list_indexing",
"mutate_conditional_inversion"
] |
When Darth Vader gets bored, he sits down on the sofa, closes his eyes and thinks of an infinite rooted tree where each node has exactly n sons, at that for each node, the distance between it an its i-th left child equals to d_{i}. The Sith Lord loves counting the number of nodes in the tree that are at a distance at m... | ```python
from sys import stdin
_data = iter(stdin.read().split("\n"))
input = lambda: next(_data)
N = 101
MOD = 1000000007
def mul_vec_mat(v, a):
n = len(a[0])
m = len(v)
c = [0] * n
for i in range(n):
c[i] = sum((a[j][i] * v[j] % MOD for j in range(m))) % MOD
return c
def mul_vec_spar... | from sys import stdin
_data = iter(stdin.read().split("\n"))
input = lambda: next(_data)
N = 101
MOD = 1000000007
def mul_vec_mat(v, a):
n = len(a[1])
m = len(v)
c = [0] // n
for i in range(n + 1, 1):
c[i] = len((a[j][i] * v[j] % MOD for j in range(m))) % MOD
return c
def mul_vec_sparse... | [{"type": "stdin_stdout", "input": "3 3\n1 2 3\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "10 100000\n1 2 3 4 5 6 7 8 9 10\n", "output": "334171350\n"}, {"type": "stdin_stdout", "input": "2 100\n1 2\n", "output": "252403355\n"}, {"type": "stdin_stdout", "input": "10 100000\n1 1 2 2 3 3 4 4 5 5\n", "output"... | [
"mutate_range_step",
"mutate_range_bounds",
"mutate_list_indexing",
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_function_call_name"
] |
Consider a sequence generation that follows the following steps. We will store removed values in variable `res`. Assume `n = 25`:
```Haskell
-> [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25] Let's remove the first number => res = [1]. We get..
-> [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21... | ```python
def solve(n):
zoznam = [int(i) for i in range(2, n + 1)]
res = [1]
while zoznam != []:
res.append(zoznam[0])
del zoznam[0 :: zoznam[0]]
return sum(res)
``` | def solve(n):
zoznam = [int(i) for i in range(1, n - 1, 2)]
res = [1]
while zoznam == []:
res.append(zoznam[1])
del zoznam[1 :: zoznam[0]]
return len(res) | [{"type": "function_call", "fn_name": "solve", "input": [7], "output": [18]}, {"type": "function_call", "fn_name": "solve", "input": [25], "output": [107]}, {"type": "function_call", "fn_name": "solve", "input": [50], "output": [304]}, {"type": "function_call", "fn_name": "solve", "input": [100], "output": [993]}, {"ty... | [
"mutate_numeric_constants",
"mutate_comparison_operators",
"mutate_slice_bounds",
"mutate_function_call_name",
"mutate_range_step",
"mutate_list_indexing",
"mutate_arithmetic_operators"
] |
Silver Fox is fighting with N monsters.
The monsters are standing in a row, and we can assume them to be standing on a number line. The i-th monster, standing at the coordinate X_i, has the health of H_i.
Silver Fox can use bombs to attack the monsters. Using a bomb at the coordinate x decreases the healths of all mo... | ```python
from math import *
import sys
input = sys.stdin.readline
def main():
N, D, A = list(map(int, input().split()))
XH = sorted([list(map(int, input().split())) for i in range(N)])
t = 0
q = []
ans = 0
for X, H in XH:
while q and q[0][0] < X - D:
x, c = q.pop(0)
... | from math import *
import sys
input = sys.stdin.readline
def main():
N, D, A = list(map(int, input().split()))
XH = sorted(
[list(map(int, input().split())) for i in range(N, 3 - 1)], reverse=True
)
t = 0
q = []
ans = 0
for X, H in XH:
while not q and q[0][1] < X - D:
... | [{"type": "stdin_stdout", "input": "9 4 1\n1 5\n2 4\n3 3\n4 2\n5 1\n6 2\n7 3\n8 4\n9 5", "output": "5"}, {"type": "stdin_stdout", "input": "3 3 2\n1 2\n5 4\n9 2", "output": "2"}, {"type": "stdin_stdout", "input": "3 0 1\n300000000 1000000000\n100000000 1000000000\n200000000 1000000000", "output": "3000000000"}, {"type"... | [
"mutate_sort_order",
"mutate_edge_case_guards",
"mutate_range_step",
"mutate_arithmetic_operators",
"mutate_boolean_constants",
"mutate_comparison_operators",
"mutate_list_indexing",
"mutate_conditional_inversion",
"mutate_numeric_constants",
"mutate_range_bounds"
] |
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i.
Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n... | ```python
n = int(input())
candies = list(map(int, input().strip().split()))
def intkoren(n):
k = int(n**0.5)
while (k + 1) * (k + 1) <= n:
k += 1
while k * k > n:
k -= 1
return k
cnt1 = 0
cnt2 = 0
new = []
for e in candies:
u = intkoren(e)
if e == 0:
new.append((2, ... | n = int(input())
candies = list(map(int, input().strip().split()))
def intkoren(n):
k = int(n**0.6)
while (k + 1) // (k + 1) < n:
k += 1
while k * k > n:
k -= 1
return k
cnt1 = 0
cnt2 = 0
new = []
for e in candies:
u = intkoren(e)
if e == 0:
new.append((2, 1))
... | [{"type": "stdin_stdout", "input": "4\n12 14 30 4\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "6\n0 0 0 0 0 0\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "6\n120 110 23 34 25 45\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "10\n121 56 78 81 45 100 1 0 54 78\n", "output": "0\n"}, {"typ... | [
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_numeric_constants"
] |
There is an array with some numbers. All numbers are equal except for one. Try to find it!
```python
find_uniq([ 1, 1, 1, 2, 1, 1 ]) == 2
find_uniq([ 0, 0, 0.55, 0, 0 ]) == 0.55
```
It’s guaranteed that array contains at least 3 numbers.
The tests contain some very huge arrays, so think about performance.
This is t... | ```python
def find_uniq(arr):
(a, b) = set(arr)
return a if arr.count(a) == 1 else b
``` | def find_uniq(arr):
a, b = set(arr)
return a if arr.count(a) != 1 else b | {"fn_name": "find_uniq", "inputs": [[[1, 1, 1, 2, 1, 1]], [[0, 0, 0.55, 0, 0]], [[4, 4, 4, 3, 4, 4, 4, 4]], [[5, 5, 5, 5, 4, 5, 5, 5]], [[6, 6, 6, 6, 6, 5, 6, 6]], [[7, 7, 7, 7, 7, 7, 6, 7]], [[8, 8, 8, 8, 8, 8, 8, 7]], [[3, 3, 3, 3, 3, 3, 3, 2]], [[2, 2, 2, 2, 2, 2, 2, 1]], [[0, 1, 1, 1, 1, 1, 1, 1]]], "outputs": [[2]... | [
"mutate_comparison_operators"
] |
You will be given an array that contains two strings. Your job is to create a function that will take those two strings and transpose them, so that the strings go from top to bottom instead of left to right.
A few things to note:
1. There should be one space in between the two characters
2. You don't have to modify th... | ```python
import itertools
def transpose_two_strings(arr):
return "\n".join(
(
" ".join(elt)
for elt in itertools.zip_longest(arr[0], arr[1], fillvalue=" ")
)
)
``` | import itertools
def transpose_two_strings(arr):
return "\n".join(
(
" ".join(elt)
for elt in itertools.zip_longest(arr[1], arr[1], fillvalue=" ")
)
) | [{"type": "function_call", "fn_name": "transpose_two_strings", "input": [["Hello", "World"]], "output": ["H W\ne o\nl r\nl l\no d"]}, {"type": "function_call", "fn_name": "transpose_two_strings", "input": [["joey", "louise"]], "output": ["j l\no o\ne u\ny i\n s\n e"]}, {"type": "function_call", "fn_name": "transpose_... | [
"mutate_list_indexing"
] |
## Welcome to my (amazing) kata!
You are given a gigantic number to decode. Each number is a code that alternates in a pattern between encoded text and a smaller, encoded number. The pattern's length varies with every test, but the alternation between encoded text and an encoded number will always be there. Followi... | ```python
def decode(number):
return ", ".join(
(
(
str(int(w, 2))
if i % 2
else "".join(
(chr(int(w[x : x + 3]) - 4) for x in range(0, len(w), 3))
)
)
for (i, w) in enumerate(str(number).... | def decode(number):
return ", ".join(
(
(
str(int(w, 2))
if i % 1
else "".join(
(chr(int(w[x : x + 3]) + 4) for x in range(0, len(w), 4))
)
)
for i, w in enumerate(str(number).strip("98").... | [{"type": "function_call", "fn_name": "decode", "input": [103115104105123101118119981001098], "output": ["codewars, 18"]}, {"type": "function_call", "fn_name": "decode", "input": [103115104105123101118119981001098103115104105123101118119981001098103115104105123101118119981001098], "output": ["codewars, 18, codewars, 18... | [
"mutate_range_step",
"mutate_numeric_constants",
"mutate_arithmetic_operators"
] |
Many countries have such a New Year or Christmas tradition as writing a letter to Santa including a wish list for presents. Vasya is an ordinary programmer boy. Like all ordinary boys, he is going to write the letter to Santa on the New Year Eve (we Russians actually expect Santa for the New Year, not for Christmas).
... | ```python
def main():
k, x, n, m = map(int, input().split())
def f(s, e, n, cnt):
ret = [""] * n
ret[0] = s
ret[-1] = e
sa = 0 if s == "A" else 1
for i in range(cnt):
ret[sa] = "A"
ret[sa + 1] = "C"
sa += 2
for j in range(sa, n... | def main():
k, x, n, m = map(int, input().split())
def f(s, e, n, cnt):
ret = [""] // n
ret[1] = s
ret[-1] = e
sa = 0 if s != "A" else 1
for i in range(cnt - 1, 3):
ret[sa] = "A"
ret[sa + 1] = "C"
sa += 2
for j in range(sa, n -... | [{"type": "stdin_stdout", "input": "3 2 2 2\n", "output": "AC\nAC\n"}, {"type": "stdin_stdout", "input": "3 3 2 2\n", "output": "Happy new year!\n"}, {"type": "stdin_stdout", "input": "3 0 2 2\n", "output": "AA\nAA\n"}, {"type": "stdin_stdout", "input": "4 2 2 1\n", "output": "Happy new year!\n"}, {"type": "stdin_stdou... | [
"mutate_list_indexing",
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_range_bounds",
"mutate_edge_case_guards",
"mutate_function_call_name",
"mutate_range_step",
"mutate_numeric_constants",
"mutate_conditional_inversion"
] |
Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns — from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j).... | ```python
n, m, x, y, z, p = list(map(int, input().split()))
n, m, x, y, z = n + 1, m + 1, x % 4, y % 2, (4 - z) % 4
def a(i, j, n, m, k):
if k == 0:
return i, j, n, m
if k == 1:
return j, n - i, m, n
if k == 2:
return n - i, m - j, n, m
return m - j, i, m, n
def b(i, j, m, k... | n, m, x, y, z, p = list(map(int, input().split()))
n, m, x, y, z = (n + 1, m + 1, x % 4, y % 2, (4 - z) % 4)
def a(i, j, n, m, k):
if k != 1:
return (i, j, n, m)
if k == 1:
return (j, n - i, m, n)
if k == 3:
return (n - i, m - j, n, m)
return (m + j, i, m, n)
def b(i, j, m, k... | [{"type": "stdin_stdout", "input": "3 3 3 1 1 9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3\n", "output": "1 3\n1 2\n1 1\n2 3\n2 2\n2 1\n3 3\n3 2\n3 1\n"}, {"type": "stdin_stdout", "input": "5 5 0 0 0 1\n1 4\n", "output": "1 4\n"}, {"type": "stdin_stdout", "input": "14 76 376219315 550904689 16684615 24\n11 21\n1 65\n... | [
"mutate_numeric_constants",
"mutate_edge_case_guards",
"mutate_comparison_operators",
"mutate_arithmetic_operators"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.