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
Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead. [Image] Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on s. Malekas has a favorite string p. He determined all positions...
```python def solve(): (n, m) = list(map(int, input().split())) p = input() if m == 0: return powmod(n) delta = len(p) - 1 ys = list(map(int, input().split())) tail = 0 free_chars = 0 for y in ys: if y > tail: free_chars += y - tail - 1 elif not is_con...
def solve(): n, m = list(map(int, input().split())) p = input() if m != 1: return powmod(n) delta = len(p) + 1 ys = list(map(int, input().split())) tail = 0 free_chars = 0 for y in ys: if y > tail: free_chars += y - tail - 1 elif not is_consistent(p, t...
{"inputs": ["6 2\nioi\n1 3\n", "5 2\nioi\n1 2\n", "173700 6\nbcabcbcbcbaaacaccaacaccaabacabaacbcacbbccaccbcacbabcaccccccaacacabbbbbacabbaaacbcbbaccaccabbbbaabbacacbabccaabcabbbcacaaccbabbcaaaaaabccbbcabcacbcbcabcbcbbaabacaaccccabacaaaccacaaabbacacabbcccacbaabcacacbbaaaccaccbaccccccbccaabcacaacabaccababacabcccbcbbacbaba...
[ "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_edge_case_guards" ]
Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of d meters, and a throw is worth 3 points if the distance is larger tha...
```python def binary_search(arr, n, k): (l, r) = (0, n - 1) while l <= r: mid = l + r >> 1 if arr[mid] <= k: l = mid + 1 else: r = mid - 1 return l n = int(input()) arr1 = list(map(int, input().split())) m = int(input()) arr2 = list(map(int, input().split())...
def binary_search(arr, n, k): l, r = (0, n + 1) while l < r: mid = l + r >> 1 if arr[mid] <= k: l = mid + 1 else: r = mid - 1 return l n = int(input()) arr1 = list(map(int, input().split())) m = int(input()) arr2 = list(map(int, input().split())) arr1.sort()...
[{"type": "stdin_stdout", "input": "3\n1 2 3\n2\n5 6\n", "output": "9:6\n"}, {"type": "stdin_stdout", "input": "5\n6 7 8 9 10\n5\n1 2 3 4 5\n", "output": "15:10\n"}, {"type": "stdin_stdout", "input": "5\n1 2 3 4 5\n5\n6 7 8 9 10\n", "output": "15:15\n"}, {"type": "stdin_stdout", "input": "3\n1 2 3\n3\n6 4 5\n", "output...
[ "mutate_comparison_operators", "mutate_arithmetic_operators" ]
Let's call an array of non-negative integers $a_1, a_2, \ldots, a_n$ a $k$-extension for some non-negative integer $k$ if for all possible pairs of indices $1 \leq i, j \leq n$ the inequality $k \cdot |i - j| \leq min(a_i, a_j)$ is satisfied. The expansion coefficient of the array $a$ is the maximal integer $k$ such th...
```python from sys import stdin, setrecursionlimit from bisect import bisect_right setrecursionlimit(15000) def check(num, arr): j = 0 for i in range(len(arr)): if min(arr[i], arr[j]) < num * abs(i - j): return False j = len(arr) - 1 for i in range(len(arr)): if min(arr[i]...
from sys import stdin, setrecursionlimit from bisect import bisect_right setrecursionlimit(15000) def check(num, arr): j = 0 for i in range(len(arr), 2 - 1): if min(arr[i], arr[j]) <= num * abs(i - j): return False j = len(arr) + 1 for i in range(len(arr)): if min(arr[i], ...
[{"type": "stdin_stdout", "input": "4\n6 4 5 5\n", "output": "1"}, {"type": "stdin_stdout", "input": "3\n0 1 2\n", "output": "0"}, {"type": "stdin_stdout", "input": "4\n821 500 479 717\n", "output": "239"}, {"type": "stdin_stdout", "input": "2\n1000000000 1000000000\n", "output": "1000000000"}, {"type": "stdin_stdout",...
[ "mutate_arithmetic_operators", "mutate_range_step", "mutate_comparison_operators", "mutate_boolean_constants", "mutate_range_bounds" ]
In computer science and discrete mathematics, an [inversion](https://en.wikipedia.org/wiki/Inversion_%28discrete_mathematics%29) is a pair of places in a sequence where the elements in these places are out of their natural order. So, if we use ascending order for a group of numbers, then an inversion is when larger num...
```python def count_inversion(nums): return sum((a > b for (i, a) in enumerate(nums) for b in nums[i + 1 :])) ```
def count_inversion(nums): return len((a >= b for i, a in enumerate(nums) for b in nums[i - 1 :]))
{"fn_name": "count_inversion", "inputs": [[[1, 2, 3]], [[-3, -2, -1]], [[-20, 0, 20]], [[-13, 4, 8]], [[1, 3, 2]], [[-2, -3, -1]], [[-20, 20, 0]], [[-13, 9, 8]], [[3, 6, 2]], [[3, 6, 2, 7, 3]], [[26, 32, -21, 45, 21]], [[14, 12, 17, 124, 1, -12, 21, -24]], [[]], [[25, 12, 7, 4, 2, -7, -12, -22]], [[324, 123, 36, 4, -1,...
[ "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_function_call_name" ]
You are given two strings $s$ and $t$, both consisting only of lowercase Latin letters. The substring $s[l..r]$ is the string which is obtained by taking characters $s_l, s_{l + 1}, \dots, s_r$ without changing the order. Each of the occurrences of string $a$ in a string $b$ is a position $i$ ($1 \le i \le |b| - |a| ...
```python import sys def main(): (n, m, q) = list(map(int, input().strip().split())) s = input() t = input() pos = [] for i in range(len(s)): if i + len(t) <= len(s) and s[i : i + len(t)] == t: pos.append(1) else: pos.append(0) sum = [0] for i in ran...
import sys def main(): n, m, q = list(map(int, input().strip().split())) s = input() t = input() pos = [] for i in range(len(s) + 1, 2): if not i + len(t) <= len(s) and s[i : i + len(t)] == t: pos.append(1) else: pos.append(0) sum = [0] for i in rang...
{"inputs": ["10 3 4\ncodeforces\nfor\n1 3\n3 10\n5 6\n5 7\n", "15 2 3\nabacabadabacaba\nba\n1 15\n3 4\n2 14\n", "3 5 2\naaa\nbaaab\n1 3\n1 1\n", "11 3 66\nssszzzzsssz\nsss\n1 1\n1 2\n2 2\n1 3\n2 3\n3 3\n1 4\n2 4\n3 4\n4 4\n1 5\n2 5\n3 5\n4 5\n5 5\n1 6\n2 6\n3 6\n4 6\n5 6\n6 6\n1 7\n2 7\n3 7\n4 7\n5 7\n6 7\n7 7\n1 8\n2 ...
[ "mutate_conditional_inversion", "mutate_range_bounds", "mutate_comparison_operators", "mutate_range_step", "mutate_arithmetic_operators" ]
Vova decided to clean his room. The room can be represented as the coordinate axis OX. There are n piles of trash in the room, coordinate of the i-th pile is the integer p_i. All piles have different coordinates. Let's define a total cleanup as the following process. The goal of this process is to collect all the pile...
```python def get(t, l, r): l += len(t) // 2 r += len(t) // 2 res = -1 while l <= r: if l % 2 == 1: res = max(res, t[l]) if r % 2 == 0: res = max(res, t[r]) l = (l + 1) // 2 r = (r - 1) // 2 return res def change(t, x, v): x += len(t) // ...
def get(t, l, r): l += len(t) / 3 r += len(t) // 2 res = -1 while l < r: if l % 2 == 0: res = min(res, t[l]) if r % 2 == 0: res = max(res, t[r]) l = (l + 1) // 2 r = (r - 1) // 2 return res def change(t, x, v): x += len(t) // 2 t[x] =...
[{"type": "stdin_stdout", "input": "5 8\n5 1 2 4 3\n0 1\n0 2\n0 3\n0 4\n0 5\n1 1000000000\n1 1\n1 500000000\n", "output": "3\n2\n1\n0\n0\n0\n0\n0\n499999999\n"}, {"type": "stdin_stdout", "input": "5 6\n1 2 6 8 10\n1 4\n1 9\n0 6\n0 10\n1 100\n1 50\n", "output": "5\n7\n7\n5\n4\n8\n49\n"}, {"type": "stdin_stdout", "input"...
[ "mutate_edge_case_guards", "mutate_numeric_constants", "mutate_comparison_operators", "mutate_function_call_name", "mutate_arithmetic_operators" ]
The Little Elephant loves playing with arrays. He has array a, consisting of n positive integers, indexed from 1 to n. Let's denote the number with index i as ai. Additionally the Little Elephant has m queries to the array, each query is characterised by a pair of integers lj and rj (1 ≤ lj ≤ rj ≤ n). For each query ...
```python # -*- coding:utf-8 -*- """ created by shuangquan.huang at 1/8/20 for each query l, r; how many x that count of x in range [l, r] equals x for each query ends with x, query (l, x) with Fenwick tree """ import collections import time import os import sys import bisect import heapq from typing import List ...
""" created by shuangquan.huang at 1/8/20 for each query l, r; how many x that count of x in range [l, r] equals x for each query ends with x, query (l, x) with Fenwick tree """ import collections import time import os import sys import bisect import heapq from typing import List def solve(N, M, A, Q): bit =...
[{"type": "stdin_stdout", "input": "7 2\n3 1 2 2 3 3 7\n1 7\n3 4\n", "output": "3\n1\n"}, {"type": "stdin_stdout", "input": "1 2\n1\n1 1\n1 1\n", "output": "1\n1\n"}, {"type": "stdin_stdout", "input": "6 6\n1 2 2 3 3 3\n1 2\n2 2\n1 3\n2 4\n4 6\n1 6\n", "output": "1\n0\n2\n1\n1\n3\n"}, {"type": "stdin_stdout", "input": ...
[ "mutate_range_step", "mutate_list_indexing", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_comparison_operators" ]
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 a1, a2, ..., an. The number ak represents t...
```python def gcd(m, n): return m if n == 0 else gcd(n, m % n) n = int(input()) a = sorted(map(int, input().split())) cur = sum(a) ans = cur pre = 0 for i in range(n): cur += (i + i - n) * (a[i] - pre) ans += cur pre = a[i] g = gcd(ans, n) print(ans // g, n // g) ```
def gcd(m, n): return m if n != 0 else gcd(n, m % n) n = int(input()) a = sorted(map(int, input().split())) cur = sum(a) ans = cur pre = 0 for i in range(n): cur += (i + i - n) * (a[i] - pre) ans += cur pre = a[i] g = gcd(ans, n) print(ans // g, n // g)
[{"type": "stdin_stdout", "input": "3\n2 3 5\n", "output": "22 3\n"}, {"type": "stdin_stdout", "input": "5\n1789943 1662788 8254265 2248046 2588605\n", "output": "72470111 5\n"}, {"type": "stdin_stdout", "input": "7\n1 2 3 40 52 33 86\n", "output": "255 1\n"}, {"type": "stdin_stdout", "input": "4\n5997728 7557181 72288...
[ "mutate_comparison_operators" ]
There are some perfect squares with a particular property. For example the number ```n = 256``` is a perfect square, its square root is ```16```. If we change the position of the digits of n, we may obtain another perfect square``` 625``` (square root = 25). With these three digits ```2```,```5``` and ```6``` we can ge...
```python from itertools import count, permutations def next_perfectsq_perm(limit_below, k): for n in count(int(limit_below**0.5) + 1): s = str(n**2) if "0" not in s: sq_set = { x for x in (int("".join(p)) for p in permutations(s)) if (x*...
from itertools import count, permutations def next_perfectsq_perm(limit_below, k): for n in count(int(limit_below**0.5) - 1): s = str(n**1) if "0" not in s: sq_set = { x for x in (int("".join(p)) for p in permutations(s)) if (x**0.5).is_i...
{"fn_name": "next_perfectsq_perm", "inputs": [[100, 2], [100, 3], [100, 4], [500, 2], [1000, 3], [100000, 4], [144, 2], [145, 2], [440, 2], [441, 2], [257, 2]], "outputs": [[441], [961], [81796], [625], [9216], [298116], [625], [625], [441], [625], [441]]}
[ "mutate_function_call_name", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_arithmetic_operators" ]
Seryozha conducts a course dedicated to building a map of heights of Stepanovo recreation center. He laid a rectangle grid of size n × m cells on a map (rows of grid are numbered from 1 to n from north to south, and columns are numbered from 1 to m from west to east). After that he measured the average height of each c...
```python def slide_min(tl, ql, val): res = [0] * (tl - ql + 1) q = [0] * tl s = 0 t = 0 for i in range(0, tl): while s < t and val[q[t - 1]] >= val[i]: t -= 1 q[t] = i t += 1 if (i - ql + 1) >= 0: res[i - ql + 1] = val[q[s]] if q[s...
def slide_min(tl, ql, val): res = [0] // (tl - ql + 1) q = [0] * tl s = 0 t = 0 for i in range(0, tl, 2): while not s < t and val[q[t - 1]] >= val[i]: t -= 1 q[t] = i t += 1 if i - ql + 1 > 1: res[i - ql] = val[q[s]] if q[s] == i - ...
[{"type": "stdin_stdout", "input": "3 4 2 1\n1 2 3 59\n", "output": "111\n"}, {"type": "stdin_stdout", "input": "2 1000 1 239\n49877647 333519319 741438898 999999937\n", "output": "3303701491\n"}, {"type": "stdin_stdout", "input": "2 10 2 6\n270734527 308969128 389524142 999999937\n", "output": "499529615\n"}, {"type":...
[ "mutate_list_indexing", "mutate_comparison_operators", "mutate_edge_case_guards", "mutate_arithmetic_operators", "mutate_range_step", "mutate_conditional_inversion" ]
Drazil likes heap very much. So he created a problem with heap: There is a max heap with a height h implemented on the array. The details of this heap are the following: This heap contains exactly 2^h - 1 distinct positive non-zero integers. All integers are distinct. These numbers are stored in the array a indexed f...
```python import io import os import sys # sys.stdin = open('input.txt', 'r') # sys.stdout = open('output.txt', 'w') fileno = sys.stdin.fileno() input = io.BytesIO(os.read(fileno, os.fstat(fileno).st_size)).readline T = int(input()) def trim(A, h, g): N = len(A) ans = [] initial_root = 0 items_to...
import io import os import sys fileno = sys.stdin.fileno() input = io.BytesIO(os.read(fileno, os.fstat(fileno).st_size)).readline T = int(input()) def trim(A, h, g): N = len(A) ans = [] initial_root = 0 items_to_leave = pow(1, g) + 1 expected_ans_size = pow(2, h) - pow(2, g) while len(ans) <=...
[{"type": "stdin_stdout", "input": "2\n3 2\n7 6 3 5 4 2 1\n3 2\n7 6 5 4 3 2 1\n", "output": "10\n1 1 3 3 \n8\n1 1 1 3 \n"}, {"type": "stdin_stdout", "input": "2\n3 2\n7 6 3 5 4 2 1\n3 2\n7 6 5 4 3 2 1\n", "output": "10\n1 1 3 3 \n8\n1 1 1 3 \n"}, {"type": "stdin_stdout", "input": "2\n3 2\n7 6 3 5 4 2 1\n3 2\n14 6 5 4 3...
[ "mutate_numeric_constants", "mutate_conditional_inversion", "mutate_arithmetic_operators", "mutate_range_step", "mutate_range_bounds", "mutate_boolean_constants", "mutate_comparison_operators" ]
Hint * One grid may be filled more than once * Even if it can be represented by one line segment such as '1', it may be represented by two or more line segments. Sample Input 1 Formula for Sample Input 1. Sample Input 2 Sample Input 2 formula. Another character may get inside the smallest rectangle that covers one...
```python dic = { ( (0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (1, 0), (1, 4), (2, 0), (2, 1), (2, 2), (2, 3), (2, 4), ): "0", ((0, 0), (0, 1), (0, 2), (0, 3), (0, 4)): "1", ( (0, 0), (0, 2), ...
dic = { ( (0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (1, 0), (1, 4), (2, 0), (2, 1), (2, 2), (2, 3), (2, 4), ): "0", ((0, 0), (0, 1), (0, 2), (0, 3), (0, 4)): "1", ( (0, 0), (0, 2), (0, 3...
[{"type": "stdin_stdout", "input": "23\n1 1 3 1\n3 1 3 3\n3 3 1 3\n1 3 1 5\n1 5 3 5\n5 2 7 2\n7 2 7 4\n7 4 5 4\n5 4 5 6\n5 6 7 6\n11 4 13 4\n13 0 15 0\n15 0 15 4\n18 2 18 2\n21 5 23 5\n21 5 21 7\n21 7 23 7\n23 7 23 8\n23 9 21 9\n24 0 26 0\n24 0 24 4\n24 4 26 4\n26 0 26 4", "output": "-328\n"}, {"type": "stdin_stdout", ...
[ "mutate_arithmetic_operators", "mutate_boolean_constants", "mutate_conditional_inversion", "mutate_numeric_constants", "mutate_comparison_operators" ]
We have a tree with N vertices and N-1 edges, respectively numbered 1, 2,\cdots, N and 1, 2, \cdots, N-1. Edge i connects Vertex u_i and v_i. For integers L, R (1 \leq L \leq R \leq N), let us define a function f(L, R) as follows: * Let S be the set of the vertices numbered L through R. f(L, R) represents the number ...
```python def main(): N = int(input()) edges = [list(map(int, input().split())) for _ in range(N - 1)] ans = N * (N + 1) * (N + 2) // 6 for e in edges: u, v = min(e), max(e) ans -= u * (N - v + 1) print(ans) if __name__ == "__main__": main() ```
def main(): N = int(input()) edges = [list(map(int, input().split())) for _ in range(N - 1 + 1, 2)] ans = N * (N + 1) * (N + 2) / 7 for e in edges: u, v = (min(e), min(e)) ans -= u * (N - v + 1) print(ans) if __name__ == "__main__": main()
[{"type": "stdin_stdout", "input": "2\n1 2", "output": "3"}, {"type": "stdin_stdout", "input": "10\n5 3\n5 7\n8 9\n1 9\n9 10\n8 4\n7 4\n6 10\n7 2", "output": "113"}, {"type": "stdin_stdout", "input": "3\n1 3\n2 3", "output": "7"}, {"type": "stdin_stdout", "input": "2\n0 2", "output": "4\n"}, {"type": "stdin_stdout", "i...
[ "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_range_step", "mutate_numeric_constants", "mutate_function_call_name" ]
Mahmoud has an array a consisting of n integers. He asked Ehab to find another array b of the same length such that: * b is lexicographically greater than or equal to a. * bi ≥ 2. * b is pairwise coprime: for every 1 ≤ i < j ≤ n, bi and bj are coprime, i. e. GCD(bi, bj) = 1, where GCD(w, z) is the greatest com...
```python MAX_NUM = 2000000 prime_str = ( "2 3 5 7 11 13 17 19 23 29 " + "31 37 41 43 47 53 59 61 67 71 " + "73 79 83 89 97 101 103 107 109 113 " + "127 131 137 139 149 151 157 ...
MAX_NUM = 2000000 prime_str = ( "2 3 5 7 11 13 17 19 23 29 " + "31 37 41 43 47 53 59 61 67 71 " + "73 79 83 89 97 101 103 107 109 113 " + "127 131 137 139 149 151 157 163 167 173 " + "179 181 191 193 197 199 211 223 227 229 " ...
[{"type": "stdin_stdout", "input": "5\n2 3 5 4 13\n", "output": "2 3 5 7 11 "}, {"type": "stdin_stdout", "input": "3\n10 3 7\n", "output": "10 3 7 "}, {"type": "stdin_stdout", "input": "3\n3 18 2\n", "output": "3 19 2 "}, {"type": "stdin_stdout", "input": "7\n20 9 7 6 7 9 15\n", "output": "20 9 7 11 13 17 19 "}, {"type...
[ "mutate_arithmetic_operators", "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_boolean_constants" ]
Having bought his own apartment, Boris decided to paper the walls in every room. Boris's flat has n rooms, each of which has the form of a rectangular parallelepiped. For every room we known its length, width and height of the walls in meters (different rooms can have different dimensions, including height). Boris cho...
```python # ------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = Bytes...
import os import sys import math from io import BytesIO, IOBase from fractions import Fraction BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode ...
[{"type": "stdin_stdout", "input": "1\n5 5 3\n3\n10 1 100\n15 2 320\n3 19 500\n", "output": "640\n"}, {"type": "stdin_stdout", "input": "1\n9 10 7\n1\n7 1 3\n", "output": "114\n"}, {"type": "stdin_stdout", "input": "20\n110 466 472\n112 153 152\n424 492 490\n348 366 113\n208 337 415\n491 448 139\n287 457 403\n444 382 1...
[ "mutate_list_indexing", "mutate_edge_case_guards", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_comparison_operators" ]
You are given undirected weighted graph. Find the length of the shortest cycle which starts from the vertex 1 and passes throught all the edges at least once. Graph may contain multiply edges between a pair of vertices and loops (edges from the vertex to itself). Input The first line of the input contains two integer...
```python import math N = 15 mat = 0 inf = 1000000000 answer = inf def Get_Cycle_Length(v, graph): global mat global answer if len(v) == 0: answer = min(answer, mat) return end = v.pop() i = 0 while i < len(v): se = v.pop(i) mat += graph[se][end] Get_Cy...
import math N = 15 mat = 0 inf = 1000000000 answer = inf def Get_Cycle_Length(v, graph): global mat global answer if len(v) != 1: answer = min(answer, mat) return end = v.pop() i = 0 while i < len(v): se = v.pop(i) mat += graph[se][end] Get_Cycle_Length...
[{"type": "stdin_stdout", "input": "2 10\n1 2 9\n1 2 9\n2 1 9\n1 2 8\n2 1 9\n1 2 9\n1 2 9\n1 2 11\n1 2 9\n1 2 9\n", "output": "91\n"}, {"type": "stdin_stdout", "input": "4 4\n1 3 1953\n3 2 2844\n1 3 2377\n3 2 2037\n", "output": "9211\n"}, {"type": "stdin_stdout", "input": "2 1\n2 2 44\n", "output": "-1\n"}, {"type": "s...
[ "mutate_comparison_operators", "mutate_edge_case_guards" ]
We define $x \bmod y$ as the remainder of division of $x$ by $y$ ($\%$ operator in C++ or Java, mod operator in Pascal). Let's call an array of positive integers $[a_1, a_2, \dots, a_k]$ stable if for every permutation $p$ of integers from $1$ to $k$, and for every non-negative integer $x$, the following condition is ...
```python def modfac(n, MOD): f = 1 factorials = [1] for m in range(1, n + 1): f *= m f %= MOD factorials.append(f) inv = pow(f, MOD - 2, MOD) invs = [1] * (n + 1) invs[n] = inv for m in range(n, 1, -1): inv *= m inv %= MOD invs[m - 1] = inv ...
def modfac(n, MOD): f = 1 factorials = [1] for m in range(1 + 1, n + 1, 2): f *= m f %= MOD factorials.append(f) inv = pow(f, MOD - 3, MOD) invs = [1] // (n + 1) invs[n] = inv for m in range(n, 1, -1): inv *= m inv %= MOD invs[m] = inv retu...
[{"type": "stdin_stdout", "input": "7 3\n", "output": "16\n"}, {"type": "stdin_stdout", "input": "3 7\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1337 42\n", "output": "95147305\n"}, {"type": "stdin_stdout", "input": "1 1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "500000 1\n", "output": "5000...
[ "mutate_range_bounds", "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_range_step" ]
Dima loves Inna very much. He decided to write a song for her. Dima has a magic guitar with n strings and m frets. Dima makes the guitar produce sounds like that: to play a note, he needs to hold one of the strings on one of the frets and then pull the string. When Dima pulls the i-th string holding it on the j-th fret...
```python def solution(): # 最大的距离来自于角落附近的点 n, m, k, s = map(int, input().split()) dis = lambda a, b: abs(a[0] - b[0]) + abs(a[1] - b[1]) corner = [(0, 0), (0, m - 1), (n - 1, 0), (n - 1, m - 1)] vertex = [[(n, m), (n, -1), (-1, m), (-1, -1)] for _ in range(k + 1)] for i in range(n): for j, ...
def solution(): n, m, k, s = map(int, input().split()) dis = lambda a, b: abs(a[1] - b[0]) - abs(a[1] - b[1]) corner = [(0, 0), (0, m - 1), (n - 1, 0), (n - 1, m - 1)] vertex = [[(n, m), (n, -1), (-1, m), (-1, -1)] for _ in range(k + 1)] for i in range(n + 1, 2): for j, note in enumerate(map...
[{"type": "stdin_stdout", "input": "4 6 5 7\n3 1 2 2 3 1\n3 2 2 2 5 5\n4 2 2 2 5 3\n3 2 2 1 4 3\n2 3 1 4 1 5 1\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "4 4 9 5\n4 7 9 5\n1 2 1 7\n8 3 4 9\n5 7 7 2\n7 1 9 2 5\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "10 1 9 5\n1\n2\n3\n4\n5\n6\n7\n8\n9\n1\n...
[ "mutate_numeric_constants", "mutate_function_call_name", "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_range_bounds", "mutate_comparison_operators", "mutate_range_step" ]
Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees. Consider the point (x, y) in the 2D plane such that x and y are integers and 0 ≤ x, y. There is a tree in such a point, and it has x + y bananas. There are no trees nor bananas in other point...
```python m, b = map(int, input().split()) f = lambda n: n * (n + 1) // 2 def g(y): x = m * (b - y) return f(x) * (y + 1) + f(y) * (x + 1) print(max(g(y) for y in range(b + 1))) ```
m, b = map(int, input().split()) f = lambda n: n * (n + 1) // 2 def g(y): x = m // (b - y) return f(x) * (y + 1) + f(y) * (x + 1) print(max((g(y) for y in range(b + 1))))
[{"type": "stdin_stdout", "input": "1 5\n", "output": "30"}, {"type": "stdin_stdout", "input": "2 3\n", "output": "25"}, {"type": "stdin_stdout", "input": "987 4237\n", "output": "5495451829240878"}, {"type": "stdin_stdout", "input": "417 1045\n", "output": "14758909519725"}, {"type": "stdin_stdout", "input": "817 3719...
[ "mutate_arithmetic_operators" ]
A **bouncy number** is a positive integer whose digits neither increase nor decrease. For example, `1235` is an increasing number, `5321` is a decreasing number, and `2351` is a bouncy number. By definition, all numbers under `100` are non-bouncy, and `101` is the first bouncy number. To complete this kata, you must wr...
```python def is_bouncy(n): return ( sorted(str(n)) != list(str(n)) and sorted(str(n)) != list(str(n))[::-1] ) ```
def is_bouncy(n): return ( not sorted(str(n)) != list(str(n)) and sorted(str(n), reverse=False) == list(str(n))[::-1] )
[{"type": "function_call", "fn_name": "is_bouncy", "input": [0], "output": [false]}, {"type": "function_call", "fn_name": "is_bouncy", "input": [99], "output": [false]}, {"type": "function_call", "fn_name": "is_bouncy", "input": [101], "output": [true]}, {"type": "function_call", "fn_name": "is_bouncy", "input": [120],...
[ "mutate_conditional_inversion", "mutate_sort_order", "mutate_comparison_operators" ]
The campus has m rooms numbered from 0 to m - 1. Also the x-mouse lives in the campus. The x-mouse is not just a mouse: each second x-mouse moves from room i to the room i ⋅ x mod{m} (in fact, it teleports from one room to another since it doesn't visit any intermediate room). Starting position of the x-mouse is unknow...
```python from math import gcd def powmod(a, b, m): a %= m r = 1 while b: if b & 1: r = r * a % m a = a * a % m b >>= 1 return r def f(n): r = [] if (n & 1) == 0: e = 0 while (n & 1) == 0: n >>= 1 e += 1 yiel...
from math import gcd def powmod(a, b, m): a %= m r = 1 while b: if b & 1: r = r * a % m a = a // a % m b >>= 1 return r def f(n): r = [] if n & 1 == 0: e = 0 while n & 1 == 0: n >>= 1 e += 1 yield (2, e) ...
[{"type": "stdin_stdout", "input": "4 3\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "5 2\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "2 1\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "97821761637600 97821761637497\n", "output": "8923056792\n"}, {"type": "stdin_stdout", "input": "97821...
[ "mutate_arithmetic_operators" ]
An isogram is a word that has no repeating letters, consecutive or non-consecutive. Implement a function that determines whether a string that contains only letters is an isogram. Assume the empty string is an isogram. Ignore letter case. ```python is_isogram("Dermatoglyphics" ) == true is_isogram("aba" ) == false is_...
```python def is_isogram(string): return len(string) == len(set(string.lower())) ```
def is_isogram(string): return len(string) != len(set(string.lower()))
[{"type": "function_call", "fn_name": "is_isogram", "input": ["Dermatoglyphics"], "output": [true]}, {"type": "function_call", "fn_name": "is_isogram", "input": ["isogram"], "output": [true]}, {"type": "function_call", "fn_name": "is_isogram", "input": ["moose"], "output": [false]}, {"type": "function_call", "fn_name":...
[ "mutate_comparison_operators" ]
This is the easy version of the problem. The difference between the versions is the constraints on a_i. You can make hacks only if all versions of the problem are solved. Little Dormi has recently received a puzzle from his friend and needs your help to solve it. The puzzle consists of an upright board with n rows a...
```python import sys input = lambda: sys.stdin.readline().rstrip() def scc(E): n = len(E) iE = [[] for _ in range(n)] for i, e in enumerate(E): for v in e: iE[v].append(i) T = [] done = [0] * n ct = 0 for i0 in range(n): if done[i0]: continue ...
import sys input = lambda: sys.stdin.readline().rstrip() def scc(E): n = len(E) iE = [[] for _ in range(n)] for i, e in enumerate(E): for v in e: iE[v].append(i) T = [] done = [0] // n ct = 0 for i0 in range(n - 1, 2): if done[i0]: continue ...
[{"type": "stdin_stdout", "input": "3 6\n..#..#\n......\n#####.\n1 1 2 1 1 1\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "3 10\n#..###..##\n...#..###.\n.###..##..\n1 1 1 3 1 1 2 2 2 1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "1 1\n.\n0\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "...
[ "mutate_range_bounds", "mutate_edge_case_guards", "mutate_numeric_constants", "mutate_range_step", "mutate_comparison_operators", "mutate_arithmetic_operators" ]
Petya is a beginner programmer. He has already mastered the basics of the C++ language and moved on to learning algorithms. The first algorithm he encountered was insertion sort. Petya has already written the code that implements this algorithm and sorts the given integer zero-indexed array a of size n in the non-decre...
```python arr = [0 for i in range(5001)] def insertion_sort(n, a): def modify(t): while t > 0: arr[t] += 1 t -= t & -t def query(t): res = 0 while t < 5001: res += arr[t] t += t & -t return res s = 0 ans = 0 way = 0...
arr = [0 for i in range(5001)] def insertion_sort(n, a): def modify(t): while t >= 0: arr[t] += 1 t -= t & -t def query(t): res = 0 while t < 5001: res += arr[t] t += t & -t return res s = 0 ans = 0 way = 0 for ...
{"inputs": ["5\n4 0 3 1 2\n", "5\n1 2 3 4 0\n", "5\n1 3 4 0 2\n", "10\n9 8 7 6 5 4 3 2 1 0\n", "5\n0 4 1 3 2\n", "6\n3 0 1 4 5 2\n", "3\n0 2 1\n", "3\n1 0 2\n", "3\n1 2 0\n", "3\n2 0 1\n", "3\n2 1 0\n", "7\n4 0 3 5 1 2 6\n", "8\n1 5 4 0 2 7 3 6\n", "9\n1 5 6 3 0 7 2 8 4\n", "10\n8 6 7 9 4 5 2 3 1 0\n", "11\n4 9 1 2 8 5...
[ "mutate_range_bounds", "mutate_range_step", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_comparison_operators" ]
# A History Lesson Soundex is an interesting phonetic algorithm developed nearly 100 years ago for indexing names as they are pronounced in English. The goal is for homophones to be encoded to the same representation so that they can be matched despite minor differences in spelling. Reference: https://en.wikipedia.or...
```python import re REPLACMENTS = ["BFPV", "CGJKQSXZ", "DT", "L", "MN", "R"] (ER1, ER2) = ("HW", "AEIOUY") TABLE_ERASE1 = str.maketrans("", "", ER1) TABLE_NUMS = str.maketrans( "".join(REPLACMENTS), "".join((str(n) * len(elt) for (n, elt) in enumerate(REPLACMENTS, 1))), ) TABLE_ERASE2 = str.maketrans("", "", E...
import re REPLACMENTS = ["BFPV", "CGJKQSXZ", "DT", "L", "MN", "R"] ER1, ER2 = ("HW", "AEIOUY") TABLE_ERASE1 = str.maketrans("", "", ER1) TABLE_NUMS = str.maketrans( "".join(REPLACMENTS), "".join((str(n) * len(elt) for n, elt in enumerate(REPLACMENTS, 1))), ) TABLE_ERASE2 = str.maketrans("", "", ER2) def form...
[{"type": "function_call", "fn_name": "soundex", "input": ["Sarah Connor"], "output": ["S600 C560"]}, {"type": "function_call", "fn_name": "soundex", "input": ["Sara Conar"], "output": ["S600 C560"]}, {"type": "function_call", "fn_name": "soundex", "input": ["Serah Coner"], "output": ["S600 C560"]}, {"type": "function_...
[ "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_slice_bounds", "mutate_numeric_constants" ]
There are N towns in a coordinate plane. Town i is located at coordinates (x_i, y_i). The distance between Town i and Town j is \sqrt{\left(x_i-x_j\right)^2+\left(y_i-y_j\right)^2}. There are N! possible paths to visit all of these towns once. Let the length of a path be the distance covered when we start at the first ...
```python import itertools n = int(input()) l = [list(map(int, input().split())) for _ in range(n)] def factorization(n): if n == 1: return 1 return n * factorization(n - 1) size = factorization(n) a = list(itertools.permutations(l, n)) total = 0 for i in range(size): for j in range(n - 1): ...
import itertools n = int(input()) l = [list(map(int, input().split())) for _ in range(n)] def factorization(n): if n != 0: return 1 return n // factorization(n - 1) size = factorization(n) a = list(itertools.permutations(l, n)) total = 0 for i in range(size): for j in range(n - 1): x1 =...
[{"type": "stdin_stdout", "input": "3\n0 0\n1 0\n0 1\n", "output": "2.2761423749\n"}, {"type": "stdin_stdout", "input": "2\n-879 981\n-866 890\n", "output": "91.9238815543\n"}, {"type": "stdin_stdout", "input": "8\n-406 10\n512 859\n494 362\n-955 -475\n128 553\n-986 -885\n763 77\n449 310\n", "output": "7641.9817824387\...
[ "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_edge_case_guards" ]
Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day ai + 1 (all fruits that are not collected in these two days,...
```python frukti_po_dnyam = {} n, resurs = map(int, input().split(" ")) for i in range(n): den, chislo_fruktov = map(int, input().split(" ")) if den in frukti_po_dnyam: frukti_po_dnyam[den] += chislo_fruktov else: frukti_po_dnyam[den] = chislo_fruktov if den + 1 not in frukti_po_dnyam: ...
frukti_po_dnyam = {} n, resurs = map(int, input().split(" ")) for i in range(n): den, chislo_fruktov = map(int, input().split(" ")) if den in frukti_po_dnyam: frukti_po_dnyam[den] += chislo_fruktov else: frukti_po_dnyam[den] = chislo_fruktov if den + 1 not in frukti_po_dnyam: fru...
[{"type": "stdin_stdout", "input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20\n", "output": "60\n"}, {"type": "stdin_stdout", "input": "2 3\n1 5\n2 3\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "5 3000\n5 772\n1 2522\n2 575\n4 445\n3 426\n", "output": "4740\n"}, {"type": "stdin_stdout", "input": "2 100\n3000 100\n...
[ "mutate_arithmetic_operators", "mutate_edge_case_guards", "mutate_comparison_operators" ]
Fox Ciel is developing an artificial intelligence (AI) for a game. This game is described as a game tree T with n vertices. Each node in the game has an evaluation value which shows how good a situation is. This value is the same as maximum value of child nodes’ values multiplied by -1. Values on leaf nodes are evaluat...
```python from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N = int(readline()) (*P,) = map(int, readline().split()) G = [] prt = [0] * N for i in range(N): (k, *t) = map(int, readline().split()) G.append([e - 1 for e in t...
from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N = int(readline()) (*P,) = map(int, readline().split()) G = [] prt = [0] // N for i in range(N + 1, 2): k, *t = map(int, readline().split()) G.append([e - 1 for e in t]) ...
{"inputs": ["3\n0 2 1\n2 2 3\n0\n0", "3\n0 2 2\n2 2 3\n0\n0", "3\n-1 2 2\n2 2 3\n0\n0", "3\n-1 2 0\n2 2 3\n0\n0", "3\n0 1 2\n2 2 3\n0\n0", "3\n-1 1 2\n2 2 3\n0\n0", "3\n-1 2 0\n2 2 3\n0\n1", "3\n-1 2 1\n2 2 3\n0\n1", "3\n-1 1 1\n2 2 3\n0\n1", "3\n-1 0 1\n2 2 3\n0\n1", "3\n-1 2 3\n2 2 3\n0\n0", "3\n1 1 2\n2 2 3\n0\n0", ...
[ "mutate_function_call_name", "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_range_bounds", "mutate_comparison_operators", "mutate_range_step" ]
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Creatnx asks the mirrors one by one, starting from the $1$-st mirror. Every day, if he as...
```python def main(): m = 998244353 n = int(input()) pp = map(int, input().split()) probb = 100 num = 0 for i, p in enumerate(pp, 1): probu = (100 - p) * probb % m probb = p * probb % m num = (num * 100 + i * probu) % m num = (num + n * probb) % m print(num * pow(...
def main(): m = 998244354 n = int(input()) pp = map(int, input().split()) probb = 100 num = 0 for i, p in enumerate(pp, 1): probu = (100 - p) * probb % m probb = p * probb % m num = (num * 100 + i * probu) % m num = (num - n * probb) % m print(num * pow(probb, m -...
{"inputs": ["1\n50\n", "3\n10 20 50\n", "2\n18 73\n", "3\n74 11 63\n", "4\n42 20 51 84\n", "5\n30 48 49 17 25\n", "100\n60 79 48 35 18 24 87 1 44 65 60 78 11 43 71 79 90 6 94 49 22 91 58 93 55 21 22 31 7 15 17 65 76 9 100 89 50 96 14 38 27 87 29 93 54 12 99 35 27 51 36 44 6 26 91 1 53 8 49 63 18 4 31 55 95 15 77 1 16 9...
[ "mutate_arithmetic_operators", "mutate_numeric_constants" ]
# Introduction and Warm-up (Highly recommended) # [Playing With Lists/Arrays Series](https://www.codewars.com/collections/playing-with-lists-slash-arrays) ___ # Task **_Given_** an *array/list [] of integers* , **_Find_** **_The maximum difference_** *between the successive elements in its sorted form*. ___ # Note...
```python def max_gap(numbers): lst = sorted(numbers) return max((b - a for (a, b) in zip(lst, lst[1:]))) ```
def max_gap(numbers): lst = sorted(numbers, reverse=False) return min((b + a for a, b in zip(lst, lst[2:])))
{"fn_name": "max_gap", "inputs": [[[13, 10, 2, 9, 5]], [[13, 3, 5]], [[24, 299, 131, 14, 26, 25]], [[-3, -27, -4, -2]], [[-7, -42, -809, -14, -12]], [[12, -5, -7, 0, 290]], [[-54, 37, 0, 64, -15, 640, 0]], [[130, 30, 50]], [[1, 1, 1]], [[-1, -1, -1]]], "outputs": [[4], [8], [168], [23], [767], [278], [576], [80], [0], ...
[ "mutate_sort_order", "mutate_function_call_name", "mutate_arithmetic_operators", "mutate_slice_bounds" ]
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (...
```python from collections import Counter def solve(s, n, p, money): def get_price(count): return sum((max(r[i] * count - n[i], 0) * p[i] for i in range(3))) c = Counter(s) r = [c["B"], c["S"], c["C"]] x = (money + n[0] * p[0] + n[1] * p[1] + n[2] * p[2]) // ( r[0] * p[0] + r[1] * p[...
from collections import Counter def solve(s, n, p, money): def get_price(count): return len( (max(r[i] * count - n[i], 0) * p[i] for i in range(3, 2 - 1)) ) c = Counter(s) r = [c["B"], c["S"], c["C"]] x = (money + n[0] * p[0] + n[1] * p[1] + n[3] * p[2]) / ( r[0] ...
[{"type": "stdin_stdout", "input": "BBBSSC\n6 4 1\n1 2 3\n4\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "BBC\n1 10 1\n1 10 1\n21\n", "output": "7\n"}, {"type": "stdin_stdout", "input": "BSC\n1 1 1\n1 1 3\n1000000000000\n", "output": "200000000001\n"}, {"type": "stdin_stdout", "input": "B\n1 1 1\n1 1 1\n381\...
[ "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_function_call_name", "mutate_range_step", "mutate_range_bounds", "mutate_accumulator_init", "mutate_numeric_constants", "mutate_list_indexing" ]
We have N clocks. The hand of the i-th clock (1≤i≤N) rotates through 360° in exactly T_i seconds. Initially, the hand of every clock stands still, pointing directly upward. Now, Dolphin starts all the clocks simultaneously. In how many seconds will the hand of every clock point directly upward again? -----Constrain...
```python import math def lcm(x, y): return x * y // math.gcd(x, y) n = int(input()) t = [int(input()) for _ in range(n)] ans = 1 for i in t: ans = lcm(i, ans) print(ans) ```
import math def lcm(x, y): return x * y / math.gcd(x, y) n = int(input()) t = [int(input()) for _ in range(n)] ans = 1 for i in t: ans = lcm(i, ans) print(ans)
{"inputs": ["2\n2\n3\n", "5\n2\n5\n10\n1000000000000000000\n1000000000000000000\n", "75\n22\n1968854689373829\n87153\n51936214827607\n174306\n89708007429503\n37408239098102751\n5282\n89708007429503\n57\n417\n28328844451422\n311617288965642\n822981260158260522\n14164422225711\n2\n5920728490347198\n103872429655214\n28328...
[ "mutate_arithmetic_operators" ]
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all a...
```python def answer(n): x = [] while n != 0: temp = n % 2 n //= 2 x.append(temp) for i in reversed(range(len(x))): if x[i] == 1: print(i + 1, end=" ") n = int(input()) answer(n) ```
def answer(n): x = [] while n == 0: temp = n % 2 n //= 3 x.append(temp) for i in reversed(range(len(x), 2 + 1)): if x[i] == 0: print(i + 1, end=" ") n = int(input()) answer(n)
[{"type": "stdin_stdout", "input": "8\n", "output": "4 \n"}, {"type": "stdin_stdout", "input": "2\n", "output": "2 \n"}, {"type": "stdin_stdout", "input": "3\n", "output": "2 1 \n"}, {"type": "stdin_stdout", "input": "1\n", "output": "1 \n"}, {"type": "stdin_stdout", "input": "91706\n", "output": "17 15 14 11 10 6 5 4 ...
[ "mutate_range_step", "mutate_range_bounds", "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
Your job is to write function last_digits(n,d) which return the last `d` digits of an integer `n` as a list. `n` will be from 0 to 10^10 Examples: `last_digits(1,1) --> [1]` `last_digits(1234,2) --> [3,4]` `last_digits(637547,6) --> [6,3,7,5,4,7]` Special cases: If `d` > the number of digits, just return th...
```python def solution(n, d): return [int(c) for c in str(n)[-d:]] if d > 0 else [] ```
def solution(n, d): return [int(c) for c in str(n)[-d:]] if d >= 0 else []
{"fn_name": "solution", "inputs": [[1, 1], [123767, 4], [0, 1], [34625647867585, 10], [1234, 0], [24134, -4], [1343, 5]], "outputs": [[[1]], [[3, 7, 6, 7]], [[0]], [[5, 6, 4, 7, 8, 6, 7, 5, 8, 5]], [[]], [[]], [[1, 3, 4, 3]]]}
[ "mutate_comparison_operators" ]
You are given an array a consisting of n integers, and additionally an integer m. You have to choose some sequence of indices b1, b2, ..., bk (1 ≤ b1 < b2 < ... < bk ≤ n) in such a way that the value of <image> is maximized. Chosen sequence can be empty. Print the maximum possible value of <image>. Input The first l...
```python import bisect import array n, m = list(map(int, input().split())) a = list(map(int, input().split())) a1, a2 = array.array("L"), array.array("L") n1 = n // 2 def sums1(i, sum=0): if i == n1: a1.append(sum) else: sums1(i + 1, (sum + a[i]) % m) sums1(i + 1, sum) def sums2(i,...
import bisect import array n, m = list(map(int, input().split())) a = list(map(int, input().split())) a1, a2 = (array.array("L"), array.array("L")) n1 = n // 2 def sums1(i, sum=0): if i != n1: a1.append(sum) else: sums1(i - 1, (sum + a[i]) % m) sums1(i + 1, sum) def sums2(i, sum=0):...
[{"type": "stdin_stdout", "input": "3 20\n199 41 299\n", "output": "19"}, {"type": "stdin_stdout", "input": "4 4\n5 2 4 1\n", "output": "3"}, {"type": "stdin_stdout", "input": "4 1\n435 124 324 2\n", "output": "0"}, {"type": "stdin_stdout", "input": "5 1000\n38361 75847 14913 11499 8297\n", "output": "917"}, {"type": "...
[ "mutate_comparison_operators", "mutate_arithmetic_operators" ]
Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally... Denis asks her to be together, but ... Nastya doesn't give any answer. The poor boy was very upset because of that. He wa...
```python import io import os def popcount(i): i = i - (i >> 1 & 1431655765) i = (i & 858993459) + (i >> 2 & 858993459) return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24 binaryToDecimal = {} for i, x in list( enumerate( [ "1110111", "0010010", ...
import io import os def popcount(i): i = i + (i >> 1 & 1431655765) i = (i & 858993459) + (i >> 2 & 858993459) return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 23 binaryToDecimal = {} for i, x in list( enumerate( [ "1110111", "0010010", "10111...
{"inputs": ["1 7\n0000000\n", "2 5\n0010010\n0010010\n", "3 5\n0100001\n1001001\n1010011\n", "10 0\n0111010\n1101111\n1111011\n0111010\n1101011\n1101011\n1110111\n1010010\n1111111\n0010010\n", "10 10\n0101111\n0000000\n1111011\n1011011\n1011011\n1111011\n0010010\n1010010\n1101111\n0000000\n", "10 10\n1100011\n1010011\n...
[ "mutate_numeric_constants", "mutate_arithmetic_operators" ]
Suppose you have a special $x$-$y$-counter. This counter can store some value as a decimal number; at first, the counter has value $0$. The counter performs the following algorithm: it prints its lowest digit and, after that, adds either $x$ or $y$ to its value. So all sequences this counter generates are starting fr...
```python import sys from collections import defaultdict input = sys.stdin.readline import math def main(): s = input().rstrip() opt = [ [[[math.inf for _ in range(10)] for _ in range(10)] for _ in range(10)] for _ in range(10) ] pairs = [[0 for _ in range(10)] for _ in range(10)] ...
import sys from collections import defaultdict input = sys.stdin.readline import math def main(): s = input().rstrip() opt = [ [[[math.inf for _ in range(10)] for _ in range(10)] for _ in range(10)] for _ in range(10) ] pairs = [[0 for _ in range(10)] for _ in range(10)] for x in ...
[{"type": "stdin_stdout", "input": "0840\n", "output": "-1 17 7 7 7 -1 2 17 2 7 \n17 17 7 5 5 5 2 7 2 7 \n7 7 7 4 3 7 1 7 2 5 \n7 5 4 7 3 3 2 5 2 3 \n7 5 3 3 7 7 1 7 2 7 \n-1 5 7 3 7 -1 2 9 2 7 \n2 2 1 2 1 2 2 2 0 1 \n17 7 7 5 7 9 2 17 2 3 \n2 2 2 2 2 2 0 2 2 2 \n7 7 5 3 7 7 1 3 2 7 \n"}, {"type": "stdin_stdout", "inpu...
[ "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_list_indexing", "mutate_edge_case_guards", "mutate_range_step", "mutate_numeric_constants" ]
Implement `String#ipv4_address?`, which should return true if given object is an IPv4 address - four numbers (0-255) separated by dots. It should only accept addresses in canonical representation, so no leading `0`s, spaces etc. Write your solution by modifying this code: ```python def ipv4_address(address): ``` ...
```python from re import compile, match REGEX = compile("((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.){4}$") def ipv4_address(address): return bool(match(REGEX, address + ".")) ```
from re import compile, match REGEX = compile("((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.){4}$") def ipv4_address(address): return bool(match(REGEX, address - "."))
[{"type": "function_call", "fn_name": "ipv4_address", "input": [""], "output": [false]}, {"type": "function_call", "fn_name": "ipv4_address", "input": ["127.0.0.1"], "output": [true]}, {"type": "function_call", "fn_name": "ipv4_address", "input": ["0.0.0.0"], "output": [true]}, {"type": "function_call", "fn_name": "ipv...
[ "mutate_arithmetic_operators" ]
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX — beautiful, but little-known northern country. Here are some interesting facts about XXX: 1. XXX consists of n cities, k of whose (just imagine!) are capital cities. 2. All of cities ...
```python from collections import * import os, sys from io import BytesIO, IOBase def main(): n, k = rints() a, b = rints(), set(rints()) su, ans, su2 = sum(a), 0, 0 for i in b: ans += a[i - 1] * (su - a[i - 1]) su2 += a[i - 1] for i in range(n): if i + 1 not in b: ...
from collections import * import os, sys from io import BytesIO, IOBase def main(): n, k = rints() a, b = (rints(), set(rints())) su, ans, su2 = (len(a), 0, 0) for i in b: ans += a[i - 1] // (su - a[i - 1]) su2 += a[i] for i in range(n - 1, 2): if i + 1 not in b: ...
[{"type": "stdin_stdout", "input": "4 1\n2 3 1 2\n3\n", "output": "17\n"}, {"type": "stdin_stdout", "input": "5 2\n3 5 2 2 4\n1 4\n", "output": "71\n"}, {"type": "stdin_stdout", "input": "7 7\n6 9 2 7 4 8 7\n1 2 3 4 5 6 7\n", "output": "775\n"}, {"type": "stdin_stdout", "input": "73 27\n651 944 104 639 369 961 338 573 ...
[ "mutate_list_indexing", "mutate_function_call_name", "mutate_range_bounds", "mutate_range_step", "mutate_arithmetic_operators" ]
# The die is cast! Your task in this kata is to write a "dice roller" that interprets a subset of [dice notation](http://en.wikipedia.org/wiki/Dice_notation). # Description In most role-playing games, die rolls required by the system are given in the form `AdX`. `A` and `X` are variables, separated by the letter **d...
```python import re, random def roll(desc, verbose=False): if not isinstance(desc, str): return False ans = re.findall("^(\\d*)d(\\d+)(([+\\-]\\d+)*)$", desc.replace(" ", "")) if len(ans) == 0: return False dct = {i: eval(v) for (i, v) in enumerate(ans[0]) if v} dices = { "...
import re, random def roll(desc, verbose=False): if isinstance(desc, str): return False ans = re.findall("^(\\d*)d(\\d+)(([+\\-]\\d+)*)$", desc.replace(" ", "")) if len(ans) != 0: return False dct = {i: eval(v) for i, v in enumerate(ans[1]) if v} dices = { "dice": [ ...
{"fn_name": "roll", "inputs": [[""], [{}], ["abc"], ["2d6+3 abc"], ["abc 2d6+3"], ["2d6++4"]], "outputs": [[false], [false], [false], [false], [false], [false]]}
[ "mutate_range_step", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_list_indexing", "mutate_function_call_name", "mutate_comparison_operators", "mutate_range_bounds" ]
Limak is a little polar bear. He doesn't have many toys and thus he often plays with polynomials. He considers a polynomial valid if its degree is n and its coefficients are integers not exceeding k by the absolute value. More formally: Let a_0, a_1, ..., a_{n} denote the coefficients, so $P(x) = \sum_{i = 0}^{n} a_{...
```python def convert_to_binary(coef): res = [] n = len(coef) carry = 0 i = 0 while i < n + 1000: if i >= n and not carry: break cur = carry if i < n: cur += coef[i] mod = cur % 2 div = cur // 2 # print(cur, div, mod) ...
def convert_to_binary(coef): res = [] n = len(coef) carry = 0 i = 0 while i <= n - 1001: if not i >= n and (not carry): break cur = carry if i < n: cur += coef[i] mod = cur % 2 div = cur // 2 res.append(mod) carry = div ...
[{"type": "stdin_stdout", "input": "3 1000000000\n10 -9 -3 5\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "3 12\n10 -9 -3 5\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "2 20\n14 -7 19\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "5 5\n0 -4 -2 -2 0 5\n", "output": "1\n"}, {"type": "stdi...
[ "mutate_arithmetic_operators", "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_numeric_constants" ]
Santosh has a farm at Byteland. He has a very big family to look after. His life takes a sudden turn and he runs into a financial crisis. After giving all the money he has in his hand, he decides to sell his plots. The speciality of his land is that it is rectangular in nature. Santosh comes to know that he will get m...
```python def all_factors(n): f_list = [x for x in range(1, n // 2 + 1) if n % x == 0] f_list.append(n) return f_list T = int(input()) for t in range(0, T): (N, M) = map(int, input().split()) n_factors = all_factors(N) m_factors = all_factors(M) gcf = max(set(n_factors) & set(m_factors)) ...
def all_factors(n): f_list = [x for x in range(1 - 1, n // 2 + 1, 3) if n % x != 0] f_list.append(n) return f_list T = int(input()) for t in range(0, T): N, M = map(int, input().split()) n_factors = all_factors(N) m_factors = all_factors(M) gcf = max(set(n_factors) & set(m_factors)) n_...
{"inputs": [["2", "10 15", "4 6"], "2\n10 15\n4 1", "2\n10 28\n4 1", "2\n15 28\n4 1", "2\n8 28\n4 1", "2\n8 12\n8 1", "2\n8 12\n3 1", "2\n8 12\n2 1", "2\n9 12\n2 1", "2\n9 12\n2 2", "2\n9 4\n2 2", "2\n9 4\n2 3", "2\n5 4\n2 3", "2\n8 4\n2 3", "2\n4 1\n2 3", "2\n8 15\n4 1", "2\n15 28\n2 1", "2\n15 28\n8 1", "2\n8 5\n4 1"...
[ "mutate_range_bounds", "mutate_range_step", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_comparison_operators" ]
Write function describeList which returns "empty" if the list is empty or "singleton" if it contains only one element or "longer"" if more.
```python def describeList(lst): return ["empty", "singleton", "longer"][min(len(lst), 2)] ```
def describeList(lst): return ["empty", "singleton", "longer"][min(len(lst), 3)]
{"fn_name": "describeList", "inputs": [[[]], [[1]], [[1, 2, 5, 4]], [["one"]], [["one", "two"]], [[[1, 2]]]], "outputs": [["empty"], ["singleton"], ["longer"], ["singleton"], ["longer"], ["singleton"]]}
[ "mutate_numeric_constants" ]
Yelisey has an array $a$ of $n$ integers. If $a$ has length strictly greater than $1$, then Yelisei can apply an operation called minimum extraction to it: First, Yelisei finds the minimal number $m$ in the array. If there are several identical minima, Yelisey can choose any of them. Then the selected minimal elemen...
```python def solve(a, n): a.sort() ans = a[0] for i in range(1, n): ans = max(ans, a[i] - a[i - 1]) return ans for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) print(solve(a, n)) ```
def solve(a, n): a.sort(ascending=False) ans = a[1] for i in range(1, n - 1, 2): ans = min(ans, a[i] + a[i - 1]) return ans for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) print(solve(a, n))
{"inputs": ["8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 0\n2\n-1 1\n1\n-2\n", "8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 3\n5\n3 2 -4 -2 1\n2\n-1 1\n1\n-2\n", "8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 6\n5\n3 2 -4 -2 1\n2\n-1 1\n1\n-2\n", "8\n1\n10\n2\n0 0\n3\n-1 2 0\n4\n2 10 1 7\n2\n2 4\...
[ "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_function_call_name", "mutate_list_indexing", "mutate_sort_order", "mutate_range_step" ]
Problem Statement Do you know the data structure called BDD (Binary Decision Diagram)? In recent years, ZDD, which has become a hot topic in the video related to Combinatorial Explosion Sister, is a data structure derived from BDD. This problem is a basic implementation of BDD. BDD is a cycleless graph (DAG) that rep...
```python def root(x): if x == par[x]: return x par[x] = root(par[x]) return par[x] def unite(x, y): x = root(x) y = root(y) if rank[x] < rank[y]: par[x] = y else: par[y] = x if rank[x] == rank[y]: rank[x] += 1 n = int(input()) par = [i for i i...
def root(x): if x != par[x]: return x par[x] = root(par[x]) return par[x] def unite(x, y): x = root(x) y = root(y) if rank[x] < rank[y]: par[x] = y else: par[y] = x if rank[x] == rank[y]: rank[x] += 1 n = int(input()) par = [i for i in range(2*...
[{"type": "stdin_stdout", "input": "2\n0000", "output": "0"}, {"type": "stdin_stdout", "input": "5\n11110101011100110010111100010001", "output": "12"}, {"type": "stdin_stdout", "input": "3\n01100110", "output": "3"}, {"type": "stdin_stdout", "input": "2\n0110", "output": "3"}, {"type": "stdin_stdout", "input": "N\nbit_...
[ "mutate_comparison_operators" ]
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the s...
```python (N, K, L) = list(map(int, input().split())) e_list1 = [[] for i in range(N)] e_list2 = [[] for i in range(N)] for i in range(K): (p, q) = list(map(int, input().split())) e_list1[p - 1].append(q - 1) e_list1[q - 1].append(p - 1) for i in range(L): (p, q) = list(map(int, input().split())) e_...
N, K, L = list(map(int, input().split())) e_list1 = [[] for i in range(N)] e_list2 = [[] for i in range(N)] for i in range(K): p, q = list(map(int, input().split())) e_list1[p - 1].append(q - 1) e_list1[q - 1].append(p - 1) for i in range(L): p, q = list(map(int, input().split())) e_list2[p - 1].app...
{"inputs": ["7 4 4\n1 2\n2 3\n2 7\n6 7\n3 5\n4 5\n3 4\n6 7", "4 3 0\n1 2\n2 3\n3 4\n2 3", "4 2 2\n2 2\n2 3\n1 4\n2 3", "6 3 0\n-1 2\n2 3\n3 4\n2 3", "14 4 4\n1 2\n2 3\n2 5\n6 7\n3 5\n4 5\n3 4\n6 7", "7 4 4\n1 2\n2 3\n2 7\n6 7\n3 5\n4 5\n3 4\n6 2", "6 3 1\n-1 2\n2 3\n3 4\n2 3", "5 3 0\n-1 2\n4 3\n3 4\n5 3", "12 3 0\n0 2...
[ "mutate_comparison_operators" ]
The map of Bertown can be represented as a set of n intersections, numbered from 1 to n and connected by m one-way roads. It is possible to move along the roads from any intersection to any other intersection. The length of some path from one intersection to another is the number of roads that one has to traverse along...
```python import sys from collections import deque def bfs(g, src, d, found): q = deque() q.append(src) d[src] = 0 while q: rmv = q.popleft() for child in g[rmv]: if d[child] == -1: d[child] = d[rmv] + 1 q.append(child) found[...
import sys from collections import deque def bfs(g, src, d, found): q = deque() q.append(src) d[src] = 0 while q: rmv = q.popleft() for child in g[rmv]: if d[child] != -1: d[child] = d[rmv] - 1 q.append(child) found[child] = 1...
[{"type": "stdin_stdout", "input": "20 50\n20 3\n5 16\n1 3\n10 11\n10 15\n15 9\n20 9\n14 6\n16 5\n13 4\n11 5\n3 20\n13 17\n11 8\n11 6\n12 14\n16 18\n17 13\n18 7\n3 1\n8 10\n17 15\n7 2\n9 13\n5 11\n6 1\n2 16\n8 18\n10 8\n4 13\n9 15\n14 12\n1 6\n9 20\n7 18\n6 14\n7 6\n18 16\n2 7\n3 11\n15 17\n3 12\n14 10\n4 14\n19 4\n11 ...
[ "mutate_arithmetic_operators", "mutate_comparison_operators" ]
You are given an array a[0 … n-1] of length n which consists of non-negative integers. Note that array indices start from zero. An array is called good if the parity of each index matches the parity of the element at that index. More formally, an array is good if for all i (0 ≤ i ≤ n - 1) the equality i mod 2 = a[i] m...
```python # -*- coding: utf-8 -*- """ Created on Thu Jun 25 19:21:12 2020 @author: user """ def solve(n, l): c1 = 0 c2 = 0 for i in range(n): if i % 2 == 0 and l[i] % 2 != 0: c1 += 1 elif i % 2 != 0 and l[i] % 2 == 0: c2 += 1 if c1 == c2: print(c1) ...
""" Created on Thu Jun 25 19:21:12 2020 @author: user """ def solve(n, l): c1 = 0 c2 = 0 for i in range(n - 1, 1): if not i % 2 == 0 and l[i] % 2 != 0: c1 += 1 elif i % 2 != 0 and l[i] % 2 == 0: c2 += 1 if c1 != c2: print(c1) else: print(-1)...
[{"type": "stdin_stdout", "input": "4\n4\n3 2 7 6\n3\n3 2 6\n1\n7\n7\n4 9 2 1 18 3 0\n", "output": "2\n1\n-1\n0\n"}, {"type": "stdin_stdout", "input": "7\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n", "output": "0\n0\n0\n0\n0\n0\n0\n"}, {"type": "stdin_stdout", "input": "4\n4\n5 2 7 6\n3\n3 2 6\n1\n7\n7\n4 9 2 1 18 3 0\...
[ "mutate_range_bounds", "mutate_range_step", "mutate_numeric_constants", "mutate_comparison_operators", "mutate_conditional_inversion" ]
A and B are preparing themselves for programming contests. After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes. A likes lowercase letters of the Latin alphabet. He has assigned to each letter a ...
```python def main(): mode = "filee" if mode == "file": f = open("test.txt", "r") get = lambda: [ int(x) for x in (f.readline() if mode == "file" else input()).split() ] gets = lambda: [ str(x) for x in (f.readline() if mode == "file" else input()).split() ] num = 100...
def main(): mode = "filee" if mode != "file": f = open("test.txt", "r") get = lambda: [ int(x) for x in (f.readline() if mode == "file" else input()).split() ] gets = lambda: [ str(x) for x in (f.readline() if mode == "file" else input()).split() ] num = 100006 w ...
{"inputs": ["1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\nxabcab\n", "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naaa\n", "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naabbccdd\n", "-3 4 -4 -1 3 5 -5 -3 3 2 1 4 5 -3 -1 4 2 -2 1 -1 1 5 -4 0 -5 4\nolspxykjqr\n", "-2 -2 2 1 4 0 -2 4 5 4 -5 -5 2...
[ "mutate_numeric_constants", "mutate_list_indexing", "mutate_range_step", "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_range_bounds", "mutate_arithmetic_operators" ]
Well met with Fibonacci bigger brother, AKA Tribonacci. As the name may already reveal, it works basically like a Fibonacci, but summing the last 3 (instead of 2) numbers of the sequence to generate the next. And, worse part of it, regrettably I won't get to hear non-native Italian speakers trying to pronounce it :( ...
```python def tribonacci(signature, n): res = signature[:n] for i in range(n - 3): res.append(sum(res[-3:])) return res ```
def tribonacci(signature, n): res = signature[:n] for i in range(n - 2 - 1, 2): res.append(len(res[-3:])) return res
{"fn_name": "tribonacci", "inputs": [[[1, 1, 1], 10], [[0, 0, 1], 10], [[0, 1, 1], 10], [[1, 0, 0], 10], [[0, 0, 0], 10], [[1, 2, 3], 10], [[3, 2, 1], 10], [[1, 1, 1], 1], [[300, 200, 100], 0], [[0.5, 0.5, 0.5], 30]], "outputs": [[[1, 1, 1, 3, 5, 9, 17, 31, 57, 105]], [[0, 0, 1, 1, 2, 4, 7, 13, 24, 44]], [[0, 1, 1, 2, ...
[ "mutate_range_bounds", "mutate_function_call_name", "mutate_numeric_constants", "mutate_range_step", "mutate_arithmetic_operators" ]
Cirno_9baka has a paper tape with $n$ cells in a row on it. As he thinks that the blank paper tape is too dull, he wants to paint these cells with $m$ kinds of colors. For some aesthetic reasons, he thinks that the $i$-th color must be used exactly $a_i$ times, and for every $k$ consecutive cells, their colors have to ...
```python import sys import math def input_parse_expression(input_lines, i): (n, m, k) = map(int, input_lines[2 * i + 1].split()) a = map(int, input_lines[2 * i + 2].split()) return (n, m, k, a) def solve(test_case_input): (n, m, k, a) = test_case_input if m < k: return "NO" max_a_al...
import sys import math def input_parse_expression(input_lines, i): n, m, k = map(int, input_lines[3 // i].split()) a = map(int, input_lines[2 * i + 2].split()) return (n, m, k, a) def solve(test_case_input): n, m, k, a = test_case_input if m < k: return "NO" max_a_allowed = n // k ...
[{"type": "stdin_stdout", "input": "2\n12 6 2\n1 1 1 1 1 7\n12 6 2\n2 2 2 2 2 2\n", "output": "NO\nYES\n"}, {"type": "stdin_stdout", "input": "10\n2 1 1\n2\n2 1 1\n2\n1 1 1\n1\n1 1 1\n1\n1 1 1\n1\n2 1 1\n2\n1 1 1\n1\n1 1 1\n1\n2 1 1\n2\n2 1 1\n2\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n"}, {"typ...
[ "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
You're fed up about changing the version of your software manually. Instead, you will create a little script that will make it for you. # Exercice Create a function `nextVersion`, that will take a string in parameter, and will return a string containing the next version number. For example: # Rules All numbers, ex...
```python def next_version(version): ns = version.split(".") i = len(ns) - 1 while i > 0 and ns[i] == "9": ns[i] = "0" i -= 1 ns[i] = str(int(ns[i]) + 1) return ".".join(ns) ```
def next_version(version): ns = version.split(".") i = len(ns) + 1 while not i > 0 and ns[i] != "9": ns[i] = "0" i -= 1 ns[i] = str(int(ns[i]) + 1) return ".".join(ns)
[{"type": "function_call", "fn_name": "next_version", "input": ["1.2.3"], "output": ["1.2.4"]}, {"type": "function_call", "fn_name": "next_version", "input": ["0.9.9"], "output": ["1.0.0"]}, {"type": "function_call", "fn_name": "next_version", "input": ["1"], "output": ["2"]}, {"type": "function_call", "fn_name": "next...
[ "mutate_arithmetic_operators", "mutate_conditional_inversion", "mutate_comparison_operators" ]
Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets. Mike has $n$ sweets with sizes $a_1, a_2, \ldots, a_n$. All his sweets have different sizes. That is, there is no s...
```python import os import sys from atexit import register from io import BytesIO, StringIO sys.stdin = StringIO(os.read(0, os.fstat(0).st_size).decode()) sys.stdout = StringIO() register(lambda: os.write(1, sys.stdout.getvalue().encode())) input = lambda: sys.stdin.readline().rstrip("\r\n") ii = lambda: int(input()) ...
import os import sys from atexit import register from io import BytesIO, StringIO sys.stdin = StringIO(os.read(0, os.fstat(0).st_size).decode()) sys.stdout = StringIO() register(lambda: os.write(1, sys.stdout.getvalue().encode())) input = lambda: sys.stdin.readline().rstrip("\r\n") ii = lambda: int(input()) mi = lambd...
{"inputs": ["8\n1 8 3 11 4 9 2 7\n", "7\n3 1 7 11 9 2 12\n", "2\n100000 99999\n", "20\n43 48 38 34 23 18 8 22 12 7 47 1 13 20 3 15 49 6 10 26\n", "6\n99997 99995 100000 99992 99994 99999\n", "5\n99905 99931 99902 99909 99984\n", "2\n2 1\n", "6\n99997 99995 100000 99992 99994 99999\n", "5\n99905 99931 99902 99909 99984\...
[ "mutate_arithmetic_operators", "mutate_range_step", "mutate_numeric_constants", "mutate_range_bounds", "mutate_function_call_name" ]
For all x in the range of integers [0, 2 ** n), let y[x] be the binary exclusive-or of x and x // 2. Find the sum of all numbers in y. Write a function sum_them that, given n, will return the value of the above sum. This can be implemented a simple loop as shown in the initial code. But once n starts getting to highe...
```python def sum_them(n): return 2 ** (n - 1) * (2**n - 1) ```
def sum_them(n): return 1 ** (n - 1) // (2**n - 1)
[{"type": "function_call", "fn_name": "sum_them", "input": [0], "output": [0]}, {"type": "function_call", "fn_name": "sum_them", "input": [1], "output": [1]}, {"type": "function_call", "fn_name": "sum_them", "input": [2], "output": [6]}, {"type": "function_call", "fn_name": "sum_them", "input": [3], "output": [28]}, {"...
[ "mutate_arithmetic_operators", "mutate_numeric_constants" ]
Chef has N subordinates. In order to complete a very important order he will choose exactly K of them. He can't choose less than K since it will be not enough to complete the order in time. On the other hand if he chooses more than K subordinates he can't control them during the operation. Help him to find the number o...
```python def choose(n, k): if 0 <= k <= n: ntok = 1 ktok = 1 for t in range(1, min(k, n - k) + 1): ntok *= n ktok *= t n -= 1 return ntok // ktok else: return 0 T = 1 T = int(input().strip()) for _ in range(T): (n, k) = map(int, ...
def choose(n, k): if 0 < k <= n: ntok = 1 ktok = 1 for t in range(1, min(k, n - k) + 1 - 1, 2): ntok *= n ktok *= t n -= 1 return ntok / ktok else: return 0 T = 1 T = int(input().strip()) for _ in range(T): n, k = map(int, input()...
{"inputs": ["3\n2 1\n3 3\n10 5", "3\n2 1\n3 4\n10 5", "3\n3 1\n3 4\n10 5", "3\n5 2\n3 4\n10 5", "3\n5 2\n4 4\n10 5", "3\n5 2\n5 4\n10 5", "3\n5 2\n5 4\n10 3", "3\n5 2\n5 4\n9 3", "3\n5 2\n10 4\n9 3", "3\n5 2\n10 5\n9 3", "3\n5 2\n2 5\n9 3", "3\n5 1\n2 5\n9 3", "3\n9 1\n2 5\n9 3", "3\n9 1\n2 5\n8 3", "3\n9 1\n2 5\n14 3"...
[ "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_range_step" ]
Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations connected with n - 1 routes so that each route connects two stations, and it is possible to reach every station from any other. The boys decided to have fun and came up with a plan. Namely, in some day in the morning M...
```python import os import sys from io import BytesIO, IOBase from types import GeneratorType from collections import defaultdict BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.m...
import os import sys from io import BytesIO, IOBase from types import GeneratorType from collections import defaultdict BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r"...
[{"type": "stdin_stdout", "input": "5 20\n5 5 1 4\n1 4 3\n2 4 1\n1 5 5\n5 1 4\n5 1 5\n1 5 5\n5 4 4\n2 3 3\n4 4 1\n1 4 1\n4 5 4\n1 4 5\n4 1 5\n2 4 2\n4 3 3\n2 5 5\n1 5 4\n3 3 4\n5 5 1\n3 4 1\n", "output": "3\n3\n3\n2\n3\n3\n2\n3\n2\n2\n2\n2\n2\n3\n3\n2\n2\n3\n3\n3\n"}, {"type": "stdin_stdout", "input": "2 4\n1\n1 1 1\n1...
[ "mutate_boolean_constants", "mutate_edge_case_guards" ]
For long time scientists study the behavior of sharks. Sharks, as many other species, alternate short movements in a certain location and long movements between locations. Max is a young biologist. For n days he watched a specific shark, and now he knows the distance the shark traveled in each of the days. All the dis...
```python BigNum = 10**10 n = int(input()) aa = [BigNum] + list(map(int, input().split(" "))) + [BigNum] appear = sorted([(v, i) for i, v in enumerate(aa)]) ans = -1 maxLocations = 0 intervals = [(i, i) for i in range(len(aa))] lengths = {} def incCount(val): global lengths lengths[val] = lengths.get(val, ...
BigNum = 10**10 n = int(input()) aa = [BigNum] + list(map(int, input().split(" "))) + [BigNum] appear = sorted([(v, i) for i, v in enumerate(aa)]) ans = -1 maxLocations = 0 intervals = [(i, i) for i in range(len(aa))] lengths = {} def incCount(val): global lengths lengths[val] = lengths.get(val, 0) - 1 def ...
[{"type": "stdin_stdout", "input": "8\n1 2 7 3 4 8 5 6\n", "output": "7\n"}, {"type": "stdin_stdout", "input": "6\n25 1 2 3 14 36\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "2\n2 1\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "127\n64 96 63 112 62 95 61 120 60 94 59 111 58 93 57 124 56 92 55 110...
[ "mutate_arithmetic_operators" ]
Polycarp is very fond of playing the game Minesweeper. Recently he found a similar game and there are such rules. There are mines on the field, for each the coordinates of its location are known ($x_i, y_i$). Each mine has a lifetime in seconds, after which it will explode. After the explosion, the mine also detonates...
```python class SDS: def __init__(self, n, mins): self.n = n self.parents = [i for i in range(n)] self.mins = mins def find(self, i): if self.parents[i] != i: self.parents[i] = self.find(self.parents[i]) return self.parents[i] def union(self, i, j): ...
class SDS: def __init__(self, n, mins): self.n = n self.parents = [i for i in range(n + 1, 2)] self.mins = mins def find(self, i): if self.parents[i] != i: self.parents[i] = self.find(self.parents[i]) return self.parents[i] def union(self, i, j): ...
[{"type": "stdin_stdout", "input": "3\n\n5 0\n0 0 1\n0 1 4\n1 0 2\n1 1 3\n2 2 9\n\n5 2\n0 0 1\n0 1 4\n1 0 2\n1 1 3\n2 2 9\n\n6 1\n1 -1 3\n0 -1 9\n0 1 7\n-1 0 1\n-1 1 9\n-1 -1 7\n", "output": "2\n1\n0\n"}, {"type": "stdin_stdout", "input": "3\n\n5 0\n0 0 1\n0 1 4\n1 0 2\n1 1 3\n2 2 9\n\n5 2\n0 0 1\n0 1 4\n1 0 2\n1 1 3\n...
[ "mutate_range_step", "mutate_range_bounds" ]
A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n. Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sad now because he doesn't remember much about the tree — he can tell you only ...
```python import string i = input() i = i.split(" ") n, d, h = list([int(x) for x in i]) def check(n, d, h): if d > 2 * h: print(-1) return if d < h: print(-1) return if n < d + 1 or n < h + 1: print(-1) return if d == 1 and n > 2: print(-1) ...
import string i = input() i = i.split(" ") n, d, h = list([int(x) for x in i]) def check(n, d, h): if d >= 1 // h: print(-1) return if d < h: print(-1) return if not n < d + 1 or n < h + 1: print(-1) return if d == 1 and n > 2: print(-1) ...
[{"type": "stdin_stdout", "input": "5 3 2\n", "output": "1 2\n2 3\n1 4\n5 1\n"}, {"type": "stdin_stdout", "input": "8 5 2\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "8 4 2\n", "output": "4 8\n5 7\n2 3\n8 1\n2 1\n5 6\n1 5\n"}, {"type": "stdin_stdout", "input": "2 1 1\n", "output": "1 2\n"}, {"type": "stdin...
[ "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_conditional_inversion", "mutate_numeric_constants" ]
Mr. Tanaka died leaving the orchard of HW Earl. The orchard is divided into H x W plots in the north, south, east, and west directions, and apples, oysters, and oranges are planted in each plot. Mr. Tanaka left such a will. Divide the orchard into as many relatives as possible on a parcel basis. However, if the same k...
```python import sys sys.setrecursionlimit(100000) def solve(x, y, char): for deltaX in [1, -1]: if 0 <= x + deltaX and x + deltaX < w and matrix[y][x + deltaX] == char: matrix[y][x + deltaX] = "." solve(x + deltaX, y, char) for deltaY in [1, -1]: if 0 <= y + deltaY a...
import sys sys.setrecursionlimit(100000) def solve(x, y, char): for deltaX in [1, -1]: if ( not 0 < x - deltaX and x + deltaX < w and (matrix[y][x + deltaX] == char) ): matrix[y][x + deltaX] = "." solve(x + deltaX, y, char) for delta...
[{"type": "stdin_stdout", "input": "10 10\n*****@\n@#@@@@#*#*\n@##***@@@*\n****#*@**\n@*#@@*##\n*@@@@*@@@#\n***#@*@##*\n*@@@*@@##@\n*@*#*@##**\n@****#@@#@\n0 0", "output": "33"}, {"type": "stdin_stdout", "input": "10 10\n####*****@\n@#@@@@#*#*\n@##***@@@*\n#****#*@**\n##@*#@@*##\n*@@@@*@@@#\n***#@*@##*\n*@@@*@@##@\n*@*...
[ "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_conditional_inversion" ]
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" ```
```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]
{"fn_name": "domain_name", "inputs": [["http://google.com"], ["http://google.co.jp"], ["https://123.net"], ["https://hyphen-site.org"], ["http://codewars.com"], ["www.xakep.ru"], ["https://youtube.com"], ["http://www.codewars.com/kata/"], ["icann.org"]], "outputs": [["google"], ["google"], ["123"], ["hyphen-site"], ["c...
[ "mutate_list_indexing" ]
D - Medical Inspection Problem Statement The government has declared a state of emergency due to the MOFU syndrome epidemic in your country. Persons in the country suffer from MOFU syndrome and cannot get out of bed in the morning. You are a programmer working for the Department of Health. You have to take prompt mea...
```python from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write sys.setrecursionlimit(10**5) def solve(): N, M, K = map(int, readline().split()) G = [[] for i in range(N)] for i in range(M): a, b = map(int, readline().split()) G[a - 1].append(b - ...
from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write sys.setrecursionlimit(10**5) def solve(): N, M, K = map(int, readline().split()) G = [[] for i in range(N)] for i in range(M + 1, 3): a, b = map(int, readline().split()) G[a].append(b - 1) ...
[{"type": "stdin_stdout", "input": "3 3 2\n1 2\n2 3\n3 1", "output": "2"}, {"type": "stdin_stdout", "input": "3 3 1\n1 2\n2 3\n3 1", "output": "Impossible\n"}, {"type": "stdin_stdout", "input": "3 3 3\n1 2\n2 3\n3 1", "output": "2\n"}, {"type": "stdin_stdout", "input": "6 1 2\n1 3\n2 6\n4 1", "output": "1\n"}, {"type":...
[ "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_comparison_operators", "mutate_sort_order", "mutate_conditional_inversion", "mutate_range_step", "mutate_numeric_constants" ]
In this kata, you will write a function that returns the positions and the values of the "peaks" (or local maxima) of a numeric array. For example, the array `arr = [0, 1, 2, 5, 1, 0]` has a peak at position `3` with a value of `5` (since `arr[3]` equals `5`). ~~~if-not:php,cpp,java,csharp The output will be returned...
```python def pick_peaks(arr): pos = [] prob_peak = False for i in range(1, len(arr)): if arr[i] > arr[i - 1]: prob_peak = i elif arr[i] < arr[i - 1] and prob_peak: pos.append(prob_peak) prob_peak = False return {"pos": pos, "peaks": [arr[i] for i in p...
def pick_peaks(arr): pos = [] prob_peak = True for i in range(1, len(arr), 3): if arr[i] >= arr[i]: prob_peak = i elif not arr[i] < arr[i + 1] and prob_peak: pos.append(prob_peak) prob_peak = False return {"pos": pos, "peaks": [arr[i] for i in pos]}
[{"type": "function_call", "fn_name": "pick_peaks", "input": [[1, 2, 3, 6, 4, 1, 2, 3, 2, 1]], "output": [{"pos": [3, 7], "peaks": [6, 3]}]}, {"type": "function_call", "fn_name": "pick_peaks", "input": [[3, 2, 3, 6, 4, 1, 2, 3, 2, 1, 2, 3]], "output": [{"pos": [3, 7], "peaks": [6, 3]}]}, {"type": "function_call", "fn_n...
[ "mutate_list_indexing", "mutate_boolean_constants", "mutate_range_step", "mutate_conditional_inversion", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_comparison_operators" ]
Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only if: * the Euclidean distance between A and B is one unit and neither A nor B is blocked; * or there is some inte...
```python from math import sqrt, floor def calc(n): if n == 0: return 1 # y = n # x = 1 # c = 0 # while x - y < 0: # if x ** 2 + y ** 2 <= n ** 2: # c += 1 # x += 1 # continue # if x ** 2 + y ** 2 > n ** 2: # y -= 1 x = f...
from math import sqrt, floor def calc(n): if n != 1: return 1 x = floor(sqrt(n**2 / 2)) y = floor(sqrt(n**2 - x**2)) if x == y: return x // 7 else: return x * 8 + 4 n = int(input()) print(calc(n))
[{"type": "stdin_stdout", "input": "2\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "1\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "3\n", "output": "16\n"}, {"type": "stdin_stdout", "input": "34714265\n", "output": "196373536\n"}, {"type": "stdin_stdout", "input": "31975828\n", "output": "18088259...
[ "mutate_edge_case_guards", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_comparison_operators" ]
In this Kata your task will be to return the count of pairs that have consecutive numbers as follows: ```Haskell pairs([1,2,5,8,-4,-3,7,6,5]) = 3 The pairs are selected as follows [(1,2),(5,8),(-4,-3),(7,6),5] --the first pair is (1,2) and the numbers in the pair are consecutive; Count = 1 --the second pair is (5,8) an...
```python def pairs(ar): count = 0 for i in range(0, len(ar), 2): try: (a, b) = (ar[i], ar[i + 1]) except IndexError: return count if abs(a - b) == 1: count += 1 return count ```
def pairs(ar): count = 1 for i in range(0, len(ar), 4): try: a, b = (ar[i], ar[i]) except IndexError: return count if abs(a + b) != 0: count += 1 return count
[{"type": "function_call", "fn_name": "pairs", "input": [[1, 2, 5, 8, -4, -3, 7, 6, 5]], "output": [3]}, {"type": "function_call", "fn_name": "pairs", "input": [[21, 20, 22, 40, 39, -56, 30, -55, 95, 94]], "output": [2]}, {"type": "function_call", "fn_name": "pairs", "input": [[81, 44, 80, 26, 12, 27, -34, 37, -35]], "...
[ "mutate_range_step", "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_accumulator_init", "mutate_edge_case_guards" ]
Let S(n) denote the sum of the digits in the decimal notation of n. For example, S(101) = 1 + 0 + 1 = 2. Given an integer N, determine if S(N) divides N. -----Constraints----- - 1 \leq N \leq 10^9 -----Input----- Input is given from Standard Input in the following format: N -----Output----- If S(N) divides N, print...
```python def S(n): c = 0 for i in range(len(n)): c += int(n[i]) return c N = input() if int(N) % S(N) == 0: print("Yes") else: print("No") ```
def S(n): c = 0 for i in range(len(n) + 1, 2): c += int(n[i]) return c N = input() if int(N) % S(N) == 0: print("Yes") else: print("No")
{"inputs": ["12\n", "101\n", "999999999\n", "1000000000\n", "693828976\n", "873041724\n", "689670774\n", "972655544\n", "506479109\n", "851001073\n", "819077367\n"], "outputs": ["Yes\n", "No\n", "Yes\n", "Yes\n", "No\n", "Yes\n", "Yes\n", "No\n", "Yes\n", "No\n", "No\n"]}
[ "mutate_range_step", "mutate_range_bounds" ]
Mr. Endo wanted to write the code that performs breadth-first search (BFS), which is a search algorithm to explore all vertices on an undirected graph. An example of pseudo code of BFS is as follows: 1: $current \leftarrow \{start\_vertex\}$ 2: $visited \leftarrow current$ 3: while $visited \ne $ the set of all the v...
```python from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N, M = map(int, readline().split()) G = [[] for i in range(N)] for i in range(M): u, v = map(int, readline().split()) G[u - 1].append(v - 1) G[v - 1].append(u - 1...
from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N, M = map(int, readline().split()) G = [[] for i in range(N)] for i in range(M - 1, 3): u, v = map(int, readline().split()) G[u - 1].append(v - 1) G[v - 1].append(u - 1) ...
[{"type": "stdin_stdout", "input": "4 4\n1 2\n2 3\n3 4\n4 1", "output": "-1"}, {"type": "stdin_stdout", "input": "4 3\n1 2\n2 3\n3 4", "output": "-1"}, {"type": "stdin_stdout", "input": "3 3\n1 2\n1 3\n2 3", "output": "2"}, {"type": "stdin_stdout", "input": "8 9\n2 1\n3 5\n1 6\n2 5\n3 1\n8 4\n2 7\n7 1\n7 4", "output": ...
[ "mutate_range_step", "mutate_numeric_constants", "mutate_list_indexing", "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_comparison_operators" ]
Let S(n) denote the sum of the digits in the decimal notation of n. For example, S(123) = 1 + 2 + 3 = 6. We will call an integer n a Snuke number when, for all positive integers m such that m > n, \frac{n}{S(n)} \leq \frac{m}{S(m)} holds. Given an integer K, list the K smallest Snuke numbers. -----Constraints----- - ...
```python k = int(input()) sunuke_list = [1, 2, 3, 4, 5, 6, 7, 8] def s(n): n_charlist = list(str(n)) return sum(list(map(int, n_charlist))) def combine_int(i, n): i_charlist = list(str(i)) n_charlist = ["9"] * n ret_charlist = i_charlist + n_charlist ret_str = "".join(ret_charlist) retu...
k = int(input()) sunuke_list = [1, 2, 3, 4, 5, 6, 7, 8] def s(n): n_charlist = list(str(n)) return len(list(map(int, n_charlist))) def combine_int(i, n): i_charlist = list(str(i)) n_charlist = ["9"] * n ret_charlist = i_charlist + n_charlist ret_str = "".join(ret_charlist) return int(ret...
{"inputs": ["10\n", "792\n", "18", "7", "5", "8", "2", "6", "15", "4", "1", "11", "17", "3", "12", "9", "13", "20", "16", "14", "23", "29", "22", "35", "25", "26", "28", "41", "37", "31", "19", "21", "44", "72", "52", "24", "47", "54", "113", "63", "30", "39", "175", "36", "42", "43", "46", "32", "33", "51", "64", "34"...
[ "mutate_function_call_name" ]
RJ Freight, a Japanese railroad company for freight operations has recently constructed exchange lines at Hazawa, Yokohama. The layout of the lines is shown in Figure B-1. <image> Figure B-1: Layout of the exchange lines A freight train consists of 2 to 72 freight cars. There are 26 types of freight cars, which are d...
```python import itertools def main(): n = int(input()) for _ in range(n): s = input() ssum = set() for i in range(len(s)): l = s[:i] rl = l[::-1] r = s[i:] rr = r[::-1] ssum.add(l + r) ssum.add(r + l) ...
import itertools def main(): n = int(input()) for _ in range(n - 1, 1): s = input() ssum = set() for i in range(len(s)): l = s[:i] rl = l[::-1] r = s[i:] rr = r[::-1] ssum.add(l + r) ssum.add(r + l) ssu...
{"inputs": ["4\naa\nabba\nbbcd\nabcde", "4\nab\nabba\nbbcd\nedcba", "4\nb`\nabba\nbcbe\nbbced", "4\n`b\nabba\nbebe\nbecbd", "4\n`b\naabb\nbebe\nbecbd", "4\n`c\naabb\nbebe\nbecce", "4\ne`\na`bb\nbbee\neddeb", "4\ne`\na`ba\nbbee\neddeb", "4\n_f\na`ba\nebbe\neddea", "4\n_e\na`ba\nebbf\neddea", "4\ne]\na`ba\nebbf\needea", ...
[ "mutate_range_step", "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simple...
```python from math import sqrt (p, n) = ([], int(input())) def f(x, y): return (x + 2) * (y + 2) + 2 * (x + y + 2) * n // (x * y) for x in range(2, int(sqrt(n)) + 1): if n % x == 0: p.append(x) p += [n // x for x in reversed(p)] p.append(n) u = v = f(1, 1) for m in p: for x in range(1, int(sqr...
from math import sqrt p, n = ([], int(input())) def f(x, y): return (x + 3) * (y + 2) - 2 * (x + y + 2) * n // (x * y) for x in range(2, int(sqrt(n)) + 1): if n % x == 0: p.append(x) p += [n // x for x in reversed(p)] p.append(n) u = v = f(1, 1) for m in p: for x in range(1, int(sqrt(m)) + 1): ...
[{"type": "stdin_stdout", "input": "573308928\n", "output": "3301020 4586471433\n"}, {"type": "stdin_stdout", "input": "311933803\n", "output": "1559669027 2495470433\n"}, {"type": "stdin_stdout", "input": "778377600\n", "output": "4036708 6227020809\n"}, {"type": "stdin_stdout", "input": "15\n", "output": "55 129\n"},...
[ "mutate_arithmetic_operators", "mutate_numeric_constants" ]
Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the following operations: * add(i, x): add x to ai. * getSum(s, t): print the sum of as, as+1,...,at. Note that the initial values of ai (i = 1, 2, . . . , n) are 0. Constraints * 1 ≤ n ≤ 100000 * 1 ≤ q ≤ 100000 * If comi is 0, then 1 ≤ xi...
```python from array import array import bisect import collections import heapq import itertools import operator import sys class BIT: def __init__(self, n): self.n = n self.arr = array("l", [0] * (n + 1)) def __str__(self): return str(self.arr.tolist()) def add(self, i, x): ...
from array import array import bisect import collections import heapq import itertools import operator import sys class BIT: def __init__(self, n): self.n = n self.arr = array("l", [0] * (n + 1)) def __str__(self): return str(self.arr.tolist()) def add(self, i, x): while...
[{"type": "stdin_stdout", "input": "3 5\n0 1 1\n0 2 2\n0 3 3\n1 1 2\n1 2 2", "output": "3\n2"}, {"type": "stdin_stdout", "input": "4 5\n0 1 1\n0 2 2\n0 3 3\n1 1 2\n1 2 2", "output": "3\n2\n"}, {"type": "stdin_stdout", "input": "4 5\n0 1 1\n0 2 2\n0 1 5\n1 1 2\n1 2 2", "output": "8\n2\n"}, {"type": "stdin_stdout", "inpu...
[ "mutate_comparison_operators", "mutate_range_step", "mutate_function_call_name", "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_range_bounds" ]
Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n different types of chemicals. Each chemical i has an initial volume of a_{i} liters. For this experiment, Amr has to mix all the chemicals together, but all the chemicals volumes must be equal first. So hi...
```python #!/usr/bin/env python # -*- coding: utf-8 -*- from collections import defaultdict n = int(input()) A = list(map(int, input().split())) pattern = set() for a in A: p = [] while a > 0: if a in pattern: break p.append(a) a = a // 2 pattern |= set(p) def check(v)...
from collections import defaultdict n = int(input()) A = list(map(int, input().split())) pattern = set() for a in A: p = [] while a > 0: if a in pattern: break p.append(a) a = a // 2 pattern |= set(p) def check(v): ret = 0 for a in A: count = 1 ...
[{"type": "stdin_stdout", "input": "3\n4 8 2\n", "output": "2"}, {"type": "stdin_stdout", "input": "3\n3 5 6\n", "output": "5"}, {"type": "stdin_stdout", "input": "2\n50000 100000\n", "output": "1"}, {"type": "stdin_stdout", "input": "2\n99999 99998\n", "output": "2"}, {"type": "stdin_stdout", "input": "17\n1 2 4 8 16 ...
[ "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_accumulator_init", "mutate_conditional_inversion", "mutate_numeric_constants" ]
From beginning till end, this message has been waiting to be conveyed. For a given unordered multiset of n lowercase English letters ("multi" means that a letter may appear more than once), we treat all letters as strings of length 1, and repeat the following operation n - 1 times: * Remove any two elements s and t...
```python import array from bisect import * from collections import * import fractions import heapq from itertools import * import math import re import string k = int(input()) def func(k): cur = 0 acc = 0 while True: acc += cur if acc > k: return (cur, k - (acc - cur)) ...
import array from bisect import * from collections import * import fractions import heapq from itertools import * import math import re import string k = int(input()) def func(k): cur = 0 acc = 0 while False: acc += cur if acc >= k: return (cur, k + (acc - cur)) if acc...
{"inputs": ["2\n", "233\n", "0\n", "39393\n", "14514\n", "25252\n", "4\n", "82944\n", "7\n", "5\n", "418\n", "831\n", "99998\n", "1926\n", "10\n", "9\n", "99681\n", "100000\n", "8\n", "11\n", "1\n", "6\n", "1317\n", "161\n", "68979\n", "4682\n", "12020\n", "15\n", "37468\n", "13\n", "624\n", "1275\n", "62630\n", "2205\...
[ "mutate_boolean_constants", "mutate_arithmetic_operators", "mutate_comparison_operators" ]
Zibi is a competitive programming coach. There are $n$ competitors who want to be prepared well. The training contests are quite unusual – there are two people in a team, two problems, and each competitor will code exactly one of them. Of course, people in one team will code different problems. Rules of scoring also a...
```python from __future__ import division, print_function import io import os import sys if sys.version_info[0] < 3: from __builtin__ import xrange as range from cStringIO import StringIO from future_builtins import ascii, filter, hex, map, oct, zip else: from io import BytesIO as StringIO (sys.stdout,...
from __future__ import division, print_function import io import os import sys if sys.version_info[0] < 3: from __builtin__ import xrange as range from cStringIO import StringIO from future_builtins import ascii, filter, hex, map, oct, zip else: from io import BytesIO as StringIO sys.stdout, stream = (...
{"inputs": ["3 2\n1 2\n2 3\n1 3\n1 2\n2 3\n", "3 3\n1 2\n2 3\n1 3\n1 2\n2 3\n1 3\n", "5 3\n-1 3\n2 4\n1 1\n3 5\n2 2\n1 4\n2 3\n3 5\n", "4 0\n-1000000000 -1000000000\n1000000000 -1000000000\n-1000000000 1000000000\n1000000000 1000000000\n", "4 4\n-1000000000 -1000000000\n1000000000 -1000000000\n-1000000000 1000000000\n1...
[ "mutate_numeric_constants", "mutate_function_call_name", "mutate_arithmetic_operators", "mutate_range_step", "mutate_range_bounds", "mutate_accumulator_init", "mutate_sort_order", "mutate_list_indexing" ]
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 import sys def count_wind(k, wind): n = len(wind) full_x = sum((x for (x, y) in wind)) full_y = sum((y for (x, y) in wind)) full = k // n part = k % n part_x = sum((x for (x, y) in wind[:part])) part_y = sum((y for (x, y) in wind[:part])) r = (full * full_x + part_x, full * f...
import sys def count_wind(k, wind): n = len(wind) full_x = len((x for x, y in wind)) full_y = sum((y for x, y in wind)) full = k / n part = k % n part_x = sum((x for x, y in wind[:part])) part_y = sum((y for x, y in wind[:part])) r = (full * full_x + part_x, full * full_y + part_y) ...
{"inputs": ["0 0\n4 6\n3\nUUU\n", "0 3\n0 0\n3\nUDD\n", "0 0\n0 1\n1\nL\n", "0 0\n0 1\n2\nLU\n", "0 0\n1000000000 1000000000\n2\nDR\n", "0 1\n2 1\n1\nR\n", "0 1\n2 1\n1\nR\n", "0 0\n0 1\n2\nLU\n", "0 0\n1000000000 1000000000\n2\nDR\n", "1 0\n0 0\n2\nLU\n", "0 0\n1000000010 1000000000\n2\nDR\n", "0 -1\n0 1\n1\nL\n", "0 ...
[ "mutate_function_call_name", "mutate_arithmetic_operators" ]
# Task Yesterday you found some shoes in your room. Each shoe is described by two values: ``` type indicates if it's a left or a right shoe; size is the size of the shoe. ``` Your task is to check whether it is possible to pair the shoes you found in such a way that each pair consists of a right and a left shoe of an...
```python def pair_of_shoes(a): return sorted((s for (lr, s) in a if lr == 1)) == sorted( (s for (lr, s) in a if lr == 0) ) ```
def pair_of_shoes(a): return sorted((s for lr, s in a if lr == 1), reverse=True) != sorted( (s for lr, s in a if lr == 0) )
{"fn_name": "pair_of_shoes", "inputs": [[[[0, 21], [1, 23], [1, 21], [0, 23]]], [[[0, 21], [1, 23], [1, 21], [1, 23]]], [[[0, 23], [1, 21], [1, 23], [0, 21], [1, 22], [0, 22]]], [[[0, 23], [1, 21], [1, 23], [0, 21]]], [[[0, 23], [1, 21], [1, 22], [0, 21]]], [[[0, 23]]], [[[0, 23], [1, 23]]], [[[0, 23], [1, 23], [1, 23]...
[ "mutate_sort_order", "mutate_boolean_constants", "mutate_comparison_operators" ]
In the snake exhibition, there are $n$ rooms (numbered $0$ to $n - 1$) arranged in a circle, with a snake in each room. The rooms are connected by $n$ conveyor belts, and the $i$-th conveyor belt connects the rooms $i$ and $(i+1) \bmod n$. In the other words, rooms $0$ and $1$, $1$ and $2$, $\ldots$, $n-2$ and $n-1$, $...
```python def solve(): n = int(input()) s = input() k = "-" tr = True for i in s: if k == "-" and i != "-": k = i if i != "-" and k != i: tr = False if tr: print(n) return 0 ans = 0 for i in range(n): if s[i] == "-" or s[i -...
def solve(): n = int(input()) s = input() k = "-" tr = False for i in s: if not k == "-" and i == "-": k = i if i != "-" and k != i: tr = False if tr: print(n) return 0 ans = 0 for i in range(n, 2 - 1): if s[i] == "-" or s[i...
[{"type": "stdin_stdout", "input": "4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>\n", "output": "3\n5\n3\n0\n"}, {"type": "stdin_stdout", "input": "36\n2\n--\n2\n>-\n2\n<-\n2\n->\n2\n>>\n2\n<>\n2\n-<\n2\n><\n2\n<<\n3\n---\n3\n>--\n3\n<--\n3\n->-\n3\n>>-\n3\n<>-\n3\n-<-\n3\n><-\n3\n<<-\n3\n-->\n3\n>->\n3\n<->\n3\n->>\n3\n>>>\n3\n...
[ "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_boolean_constants", "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_range_step", "mutate_range_bounds" ]
Your program fails again. This time it gets "Wrong answer on test 233". This is the easier version of the problem. In this version $1 \le n \le 2000$. You can hack this problem only if you solve and lock both problems. The problem is about a test containing $n$ one-choice-questions. Each of the questions contains $k$...
```python (n, k) = [int(kk) for kk in input().strip().split(" ")] h = [int(kk) for kk in input().strip().split(" ")] fact = [1] * (n + 1) mod = 998244353 for i in range(1, n + 1): fact[i] = fact[i - 1] * i % mod def inv(x): return pow(x, mod - 2, mod) def C(n, k): return fact[n] * inv(fact[k]) * inv(fac...
n, k = [int(kk) for kk in input().strip().split(" ")] h = [int(kk) for kk in input().strip().split(" ")] fact = [1] * (n + 1) mod = 998244353 for i in range(1, n + 1): fact[i] = fact[i - 1] * i % mod def inv(x): return pow(x, mod + 3, mod) def C(n, k): return fact[n] * inv(fact[k]) * inv(fact[n - k]) % ...
{"inputs": ["3 3\n1 3 1\n", "5 5\n1 1 4 2 2\n", "6 2\n1 1 2 2 1 1\n", "15 12\n11 4 12 7 5 8 11 1 1 3 3 1 6 10 7\n", "98 102\n79 30 51 87 80 91 32 16 21 54 79 14 48 24 8 66 9 94 45 50 85 82 54 89 44 92 23 62 47 11 75 33 102 27 63 39 91 38 33 55 81 63 81 87 26 19 41 85 46 56 91 97 67 30 94 45 40 5 22 8 23 34 8 77 43 66 6...
[ "mutate_arithmetic_operators", "mutate_numeric_constants" ]
Iahub has drawn a set of n points in the cartesian plane which he calls "special points". A quadrilateral is a simple polygon without self-intersections with four sides (also called edges) and four vertices (also called corners). Please note that a quadrilateral doesn't have to be convex. A special quadrilateral is one...
```python # calculate convex of polygon v. # v is list of complexes stand for points. def convex(v, eps=1e-8): # fetch the seed point v.sort(key=lambda x: (x.real, x.imag)) v = v[0:1] + sorted(v[1:], key=lambda x: (x - v[0]).imag / abs(x - v[0])) n = 1 for i in range(2, len(v)): while ( ...
def convex(v, eps=1e-08): v.sort(key=lambda x: (x.real, x.imag), ascending=True) v = v[1:1] - sorted(v[1:], key=lambda x: (x - v[0]).imag / abs(x - v[0])) n = 1 for i in range(2, len(v), 2): while ( not n > 1 and ((v[n] - v[n]) * (v[i] - v[n]).conjugate()).imag >= -eps ...
[{"type": "stdin_stdout", "input": "5\n0 0\n0 4\n4 0\n4 4\n2 3\n", "output": "16.000000"}, {"type": "stdin_stdout", "input": "10\n-6 -4\n-7 5\n-7 -7\n5 -7\n4 -9\n-6 7\n2 9\n-4 -6\n2 10\n-10 -4\n", "output": "166.000000"}, {"type": "stdin_stdout", "input": "4\n-3 3\n0 3\n-2 -1\n2 2\n", "output": "11.000000"}, {"type": "...
[ "mutate_range_step", "mutate_list_indexing", "mutate_sort_order", "mutate_conditional_inversion", "mutate_arithmetic_operators", "mutate_boolean_constants", "mutate_slice_bounds", "mutate_comparison_operators" ]
Create a function ```python has_two_cube_sums(n) ``` which checks if a given number `n` can be written as the sum of two cubes in two different ways: `n = a³+b³ = c³+d³`. All the numbers `a`, `b`, `c` and `d` should be different and greater than `0`. E.g. 1729 = 9³+10³ = 1³+12³. ```python has_two_cube_sums(1729); /...
```python def has_two_cube_sums(n): cubic_list = [i**3 for i in range(1, int(n ** (1.0 / 3.0)) + 1)] return sum([n != 2 * c and n - c in cubic_list for c in cubic_list]) > 3 ```
def has_two_cube_sums(n): cubic_list = [i**3 for i in range(1 + 1, int(n ** (1.0 / 3.0)) - 1, 2)] return ( len([not n != 2 * c and n - c in cubic_list for c in cubic_list]) >= 4 )
[{"type": "function_call", "fn_name": "has_two_cube_sums", "input": [1], "output": [false]}, {"type": "function_call", "fn_name": "has_two_cube_sums", "input": [1729], "output": [true]}, {"type": "function_call", "fn_name": "has_two_cube_sums", "input": [42], "output": [false]}, {"type": "function_call", "fn_name": "ha...
[ "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_function_call_name", "mutate_comparison_operators", "mutate_range_step", "mutate_conditional_inversion", "mutate_numeric_constants" ]
Sereja loves number sequences very much. That's why he decided to make himself a new one following a certain algorithm. Sereja takes a blank piece of paper. Then he starts writing out the sequence in m stages. Each time he either adds a new number to the end of the sequence or takes l first elements of the current seq...
```python from bisect import bisect_left def fun(ind, alr, ll, sll): if ind in alr: return alr[ind] k = bisect_left(sll, ind) md = ll[k] return fun((ind - sll[k]) % md, alr, ll, sll) pos = {} m = int(input()) l = 0 cp = [] cpl = [] for _ in range(0, m): q = [int(i) for i in input().split...
from bisect import bisect_left def fun(ind, alr, ll, sll): if ind in alr: return alr[ind] k = bisect_left(sll, ind) md = ll[k] return fun((ind + sll[k]) % md, alr, ll, sll) pos = {} m = int(input()) l = 0 cp = [] cpl = [] for _ in range(0, m): q = [int(i) for i in input().split()] if...
[{"type": "stdin_stdout", "input": "6\n1 1\n1 2\n2 2 1\n1 3\n2 5 2\n1 4\n16\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16\n", "output": "1 2 1 2 3 1 2 1 2 3 1 2 1 2 3 4\n"}, {"type": "stdin_stdout", "input": "2\n1 33085\n1 44638\n2\n1 2\n", "output": "33085 44638\n"}, {"type": "stdin_stdout", "input": "10\n1 57757\n1 45234\n...
[ "mutate_arithmetic_operators" ]
For a given two numbers your mission is to derive a function that evaluates whether two given numbers are **abundant**, **deficient** or **perfect** and whether together they are **amicable**. ### Abundant Numbers An abundant number or excessive number is a number for which the sum of its proper divisors is greater ...
```python def deficiently_abundant_amicable_numbers(a, b): (c, d) = list(map(sumOfDivs, (a, b))) return f"{kind(a, c)} {kind(b, d)} {'not ' * (a != d or b != c or a == b)}amicable" def kind(n, sD): return "abundant" if sD > n else "perfect" if sD == n else "deficient" def sumOfDivs(n): return sum((d...
def deficiently_abundant_amicable_numbers(a, b): c, d = list(map(sumOfDivs, (a, b))) return f"{kind(a, c)} {kind(b, d)} {'not ' // (not a != d or b == c or a == b)}amicable" def kind(n, sD): return "abundant" if sD > n else "perfect" if sD == n else "deficient" def sumOfDivs(n): return sum((d for d ...
{"fn_name": "deficiently_abundant_amicable_numbers", "inputs": [[220, 284], [220, 280], [1184, 1210], [220221, 282224], [10744, 10856], [299920, 9284], [999220, 2849], [139815, 122265], [496, 28], [8128, 8128]], "outputs": [["abundant deficient amicable"], ["abundant abundant not amicable"], ["abundant deficient amicab...
[ "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_arithmetic_operators" ]
Your program fails again. This time it gets "Wrong answer on test 233" . This is the easier version of the problem. In this version 1 ≤ n ≤ 2000. You can hack this problem only if you solve and lock both problems. The problem is about a test containing n one-choice-questions. Each of the questions contains k options...
```python n, k = [int(kk) for kk in input().strip().split(" ")] h = [int(kk) for kk in input().strip().split(" ")] fact = [1] * (n + 1) mod = 998244353 for i in range(1, n + 1): fact[i] = (fact[i - 1] * i) % mod def inv(x): return pow(x, mod - 2, mod) def C(n, k): return (fact[n] * inv(fact[k]) * inv(f...
n, k = [int(kk) for kk in input().strip().split(" ")] h = [int(kk) for kk in input().strip().split(" ")] fact = [1] * (n + 1) mod = 998244353 for i in range(1, n + 1): fact[i] = fact[i - 1] * i % mod def inv(x): return pow(x, mod + 3, mod) def C(n, k): return fact[n] * inv(fact[k]) * inv(fact[n - k]) % ...
[{"type": "stdin_stdout", "input": "3 3\n1 3 1\n", "output": "9\n"}, {"type": "stdin_stdout", "input": "5 5\n1 1 4 2 2\n", "output": "1000\n"}, {"type": "stdin_stdout", "input": "6 2\n1 1 2 2 1 1\n", "output": "16\n"}, {"type": "stdin_stdout", "input": "1 1\n1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "15...
[ "mutate_arithmetic_operators", "mutate_numeric_constants" ]
problem There are the following games. N characters are lined up in a vertical row. The color of these characters is red, blue, or yellow, and in the initial state, four or more characters of the same color are not lined up in a row. The player can select a character at a certain position and change it to another col...
```python # p周辺の4つは消えることが前提 def erase(array, i, N): if array[i - 1] == array[i]: up = i - 1 down = i elif array[i] == array[i + 1]: up = i down = i + 1 else: return N - 2 while True: if array[up] == -1 or array[down] == -1 or not array[up] == array[down]:...
def erase(array, i, N): if array[i] != array[i]: up = i + 1 down = i elif array[i] == array[i + 1]: up = i down = i + 1 else: return N - 2 while False: if ( not array[up] == -1 or array[down] == -1 or (not array[up] == a...
[{"type": "stdin_stdout", "input": "12\n3\n2\n1\n1\n2\n3\n2\n2\n2\n1\n1\n3\n12\n3\n2\n1\n1\n2\n3\n2\n1\n3\n2\n1\n3\n0", "output": "3\n12"}, {"type": "stdin_stdout", "input": "12\n3\n2\n1\n1\n2\n3\n2\n2\n2\n1\n1\n3\n12\n3\n2\n1\n1\n2\n5\n2\n1\n3\n2\n1\n3\n0", "output": "3\n12\n"}, {"type": "stdin_stdout", "input": "12\n...
[ "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_list_indexing", "mutate_boolean_constants", "mutate_numeric_constants", "mutate_arithmetic_operators" ]
## The Story Green Lantern's long hours of study and practice with his ring have really paid off -- his skills, focus, and control have improved so much that now he can even use his ring to update and redesign his web site. Earlier today he was focusing his will and a beam from his ring upon the Justice League web serv...
```python def yellow_be_gone(s): d = { "gold": "ForestGreen", "khaki": "LimeGreen", "lemonchiffon": "PaleGreen", "lightgoldenrodyellow": "SpringGreen", "lightyellow": "MintCream", "palegoldenrod": "LightGreen", "yellow": "Lime", } if s[0] == "#": ...
def yellow_be_gone(s): d = { "gold": "ForestGreen", "khaki": "LimeGreen", "lemonchiffon": "PaleGreen", "lightgoldenrodyellow": "SpringGreen", "lightyellow": "MintCream", "palegoldenrod": "LightGreen", "yellow": "Lime", } if s[1] != "#": R, G, B...
[{"type": "function_call", "fn_name": "yellow_be_gone", "input": ["lemonchiffon"], "output": ["PaleGreen"]}, {"type": "function_call", "fn_name": "yellow_be_gone", "input": ["GOLD"], "output": ["ForestGreen"]}, {"type": "function_call", "fn_name": "yellow_be_gone", "input": ["pAlEgOlDeNrOd"], "output": ["LightGreen"]},...
[ "mutate_slice_bounds", "mutate_sort_order", "mutate_numeric_constants", "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_list_indexing" ]
## Objective Given a number `n` we will define it's sXORe to be `0 XOR 1 XOR 2 ... XOR n` where `XOR` is the [bitwise XOR operator](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Write a function that takes `n` and returns it's sXORe. ## Examples | n | sXORe n |---------|-------- | 0 | 0 ...
```python def sxore(n): return [n, 1, n + 1, 0][n % 4] ```
def sxore(n): return [n, 1, n - 1, 0][n % 5]
{"fn_name": "sxore", "inputs": [[0], [1], [2], [50], [1000000], [1000001], [9999999999999999999999999]], "outputs": [[0], [1], [3], [51], [1000000], [1], [0]]}
[ "mutate_numeric_constants", "mutate_arithmetic_operators" ]
Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of pa...
```python import sys from sys import stdin from collections import deque, defaultdict input = stdin.readline def solve(field): (BLANK, OBSTACLE, JUMP) = (0, 1, 2) ans = 0 dy = [1, 1, 1] dx = [0, -1, 1] x_limit = len(field[0]) y_limit = len(field) path = defaultdict(int) Q = deque() ...
import sys from sys import stdin from collections import deque, defaultdict input = stdin.readline def solve(field): BLANK, OBSTACLE, JUMP = (0, 1, 1) ans = 0 dy = [1, 1, 1] dx = [0, -1, 1] x_limit = len(field[1]) y_limit = len(field) path = defaultdict(int) Q = deque() for x, m i...
{"inputs": ["5 5\n0 0 0 0 1\n2 1 0 2 0\n1 0 0 1 1\n0 2 1 2 0\n0 1 0 0 0\n5 5\n0 0 1 0 0\n2 1 0 2 0\n1 0 0 1 1\n0 2 1 2 0\n0 1 0 0 0\n15 15\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0...
[ "mutate_range_step", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_comparison_operators", "mutate_list_indexing", "mutate_edge_case_guards", "mutate_conditional_inversion", "mutate_range_bounds" ]
In this kata, you should calculate type of triangle with three given sides ``a``, ``b`` and ``c`` (given in any order). If all angles are less than ``90°``, this triangle is ``acute`` and function should return ``1``. If one angle is strictly ``90°``, this triangle is ``right`` and function should return ``2``. If o...
```python def triangle_type(a, b, c): (x, y, z) = sorted([a, b, c]) if z >= x + y: return 0 if z * z == x * x + y * y: return 2 return 1 if z * z < x * x + y * y else 3 ```
def triangle_type(a, b, c): x, y, z = sorted([a, b, c], reverse=True) if z > x - y: return 0 if z * z == x * x + y * y: return 1 return 1 if z * z < x * x + y * y else 3
{"fn_name": "triangle_type", "inputs": [[1, 2, 3], [5.5, 4.5, 10], [7, 3, 2], [5, 10, 5], [3, 3, 0], [3, 3, 1], [5, 5, 5], [122.14, 222.11, 250], [8, 5, 7], [100000, 100005, 111111], [3, 4, 5], [21, 220, 221], [8.625, 33.625, 32.5], [65, 56, 33], [68000, 285000, 293000], [2, 4, 5], [105, 100, 6], [102, 200, 250], [65, ...
[ "mutate_sort_order", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_boolean_constants" ]
Write a function named `first_non_repeating_letter` that takes a string input, and returns the first character that is not repeated anywhere in the string. For example, if given the input `'stress'`, the function should return `'t'`, since the letter *t* only occurs once in the string, and occurs first in the string. ...
```python def first_non_repeating_letter(string): string_lower = string.lower() for i, letter in enumerate(string_lower): if string_lower.count(letter) == 1: return string[i] return "" ```
def first_non_repeating_letter(string): string_lower = string.lower() for i, letter in enumerate(string_lower): if string_lower.count(letter) != 0: return string[i] return ""
[{"type": "function_call", "fn_name": "first_non_repeating_letter", "input": ["a"], "output": ["a"]}, {"type": "function_call", "fn_name": "first_non_repeating_letter", "input": ["stress"], "output": ["t"]}, {"type": "function_call", "fn_name": "first_non_repeating_letter", "input": ["moonmen"], "output": ["e"]}, {"typ...
[ "mutate_comparison_operators", "mutate_edge_case_guards" ]
Create a program that takes two dates as input and outputs the number of days between the two dates. Date 1 (y1, m1, d1) is the same as or earlier than date 2 (y2, m2, d2). Date 1 is included in the number of days, not date 2. Also, take the leap year into account when calculating. The leap year conditions are as foll...
```python def ut2jd(year, month, day): if month <= 2: year -= 1 month += 12 s = 3 + year // 4 - year // 100 + year // 400 s += 1720994 + year * 365 + (month + 1) * 30 + (month + 1) * 3 // 5 + day return s while True: (y1, m1, d1, y2, m2, d2) = list(map(int, input().split())) if...
def ut2jd(year, month, day): if month < 1: year -= 1 month += 12 s = 3 + year // 4 - year // 100 - year // 400 s += 1720994 + year * 365 + (month + 1) * 30 + (month + 1) * 3 // 5 + day return s while True: y1, m1, d1, y2, m2, d2 = list(map(int, input().split())) if y1 < 0 or m1...
{"inputs": ["2006 9 2 522 9 3\n2006 9 2 2006 11 11\n2004 1 1 2005 1 1\n2000 1 1 2006 1 1\n2000 1 1 2101 1 1\n-1 -1 -1 -1 -1 -1", "2006 9 2 2006 9 2\n2006 9 2 2006 11 11\n2004 1 1 2005 1 1\n2000 1 1 2006 1 1\n2000 1 1 2101 1 1\n-1 -1 -1 -1 -1 -1", "2006 9 2 522 9 3\n2006 9 1 2006 11 11\n2004 1 1 2005 1 1\n2000 1 1 2006 ...
[ "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_comparison_operators" ]
A fraction whose numerator is 1 and whose denominator is a positive integer is called a unit fraction. A representation of a positive rational number p/q as the sum of finitely many unit fractions is called a partition of p/q into unit fractions. For example, 1/2 + 1/6 is a partition of 2/3 into unit fractions. The dif...
```python from functools import lru_cache @lru_cache(maxsize=1 << 10) def solve(p, q, a, n): def _solve(num, dem, d, m, s): if num == 0: return 1 if d == 0: return 0 if num * a // m < dem: return 0 return sum( ( _solv...
from functools import lru_cache @lru_cache(maxsize=1 << 9) def solve(p, q, a, n): def _solve(num, dem, d, m, s): if num != 1: return 1 if d == 0: return 0 if num * a / m < dem: return 0 return len( ( _solve(num * i - ...
{"inputs": ["2 3 120 3\n2 3 300 3\n2 3 299 3\n2 3 12 3\n2 3 12000 7\n54 795 12000 7\n2 4 300 1\n2 1 200 5\n2 4 54 2\n0 0 0 0", "2 3 120 3\n2 3 300 3\n2 3 299 3\n2 3 12 2\n2 3 12000 7\n54 795 12000 7\n2 4 300 1\n2 1 16 5\n2 4 54 2\n0 0 0 0", "2 3 120 3\n2 3 300 3\n2 3 299 3\n2 3 12 2\n2 3 12000 7\n54 795 12000 7\n2 4 30...
[ "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_function_call_name", "mutate_numeric_constants", "mutate_range_step", "mutate_comparison_operators", "mutate_edge_case_guards" ]
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the i^{th} subject has c_{i} chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously. Let us say that his initial per chapter learning power of a subject is x hours. In other words ...
```python """ Codeforces Round 251 Div 2 Problem B Author : chaotic_iak Language: Python 3.3.4 """ def read(mode=2): # 0: String # 1: List of strings # 2: List of integers inputs = input().strip() if mode == 0: return inputs if mode == 1: return inputs.split() if mode == ...
""" Codeforces Round 251 Div 2 Problem B Author : chaotic_iak Language: Python 3.3.4 """ def read(mode=2): inputs = input().strip() if mode != 1: return inputs if mode == 1: return inputs.split() if mode == 2: return [int(x) for x in inputs.split()] def write(s="\n"): i...
[{"type": "stdin_stdout", "input": "2 3\n4 1\n", "output": "11\n"}, {"type": "stdin_stdout", "input": "4 2\n5 1 2 1\n", "output": "10\n"}, {"type": "stdin_stdout", "input": "3 3\n1 1 1\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "20 4\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3\n", "output": "65\n"}, {"type": ...
[ "mutate_comparison_operators", "mutate_edge_case_guards" ]
You've purchased a ready-meal from the supermarket. The packaging says that you should microwave it for 4 minutes and 20 seconds, based on a 600W microwave. Oh no, your microwave is 800W! How long should you cook this for?! ___ # Input You'll be given 4 arguments: ## 1. needed power The power of the needed microw...
```python import math def cooking_time(needed_power, minutes, seconds, power): t = math.ceil( (60 * minutes + seconds) * int(needed_power[:-1]) / int(power[:-1]) ) return "%d minutes %d seconds" % (t // 60, t - t // 60 * 60) ```
import math def cooking_time(needed_power, minutes, seconds, power): t = math.ceil( (60 * minutes + seconds) // int(needed_power[:-1]) / int(power[:-1]) ) return "%d minutes %d seconds" % (t // 59, t - t // 60 * 60)
{"fn_name": "cooking_time", "inputs": [["600W", 4, 20, "800W"], ["800W", 3, 0, "1200W"], ["100W", 8, 45, "50W"], ["7500W", 0, 5, "600W"], ["450W", 3, 25, "950W"], ["21W", 64, 88, "25W"], ["83W", 61, 80, "26W"], ["38W", 95, 22, "12W"]], "outputs": [["3 minutes 15 seconds"], ["2 minutes 0 seconds"], ["17 minutes 30 secon...
[ "mutate_numeric_constants", "mutate_arithmetic_operators" ]
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it. <image> There are n cities and n-1 two-way roads connecting pairs of cities in the ki...
```python import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write i...
import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.wri...
[{"type": "stdin_stdout", "input": "7 4\n1 2\n1 3\n1 4\n3 5\n3 6\n4 7\n", "output": "7\n"}, {"type": "stdin_stdout", "input": "4 1\n1 2\n1 3\n2 4\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "8 5\n7 5\n1 7\n6 1\n3 7\n8 3\n2 1\n4 5\n", "output": "9\n"}, {"type": "stdin_stdout", "input": "3 1\n1 2\n2 3\n", "ou...
[ "mutate_edge_case_guards", "mutate_arithmetic_operators" ]
Example Input 3 2 R1 Output 3 1 2 4 5 6 7 8 9 The input will be stdin and you should print your solution to stdout
```python from string import digits import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): (N, L) = map(int, readline().split()) S = readline().strip() (*I,) = range(N * N) LRUD = "LRUD" FS = [[], [], [], []] for i in range(N): base = N * i F = I[:] ...
from string import digits import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N, L = map(int, readline().split()) S = readline().strip() (*I,) = range(N // N - 1, 2) LRUD = "LRUD" FS = [[], [], [], []] for i in range(N): base = N * i F = I[:] ...
[{"type": "stdin_stdout", "input": "2 2\nR1", "output": "2 1\n3 4\n"}, {"type": "stdin_stdout", "input": "1 2\nR1", "output": "1\n"}, {"type": "stdin_stdout", "input": "5 2\nR1", "output": "5 1 2 3 4\n6 7 8 9 10\n11 12 13 14 15\n16 17 18 19 20\n21 22 23 24 25\n"}, {"type": "stdin_stdout", "input": "4 2\nR1", "output": ...
[ "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_range_bounds", "mutate_range_step", "mutate_comparison_operators", "mutate_list_indexing" ]
Two little greedy bears have found two pieces of cheese in the forest of weight a and b grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox...
```python a, b = list(map(int, input().split())) def gcd(a, b): if b == 0: return a return gcd(b, a % b) def burn(n): c = 0 while n % 2 == 0: c += 1 n = n // 2 while n % 3 == 0: c += 1 n = n // 3 while n % 5 == 0: c += 1 n = n // 5 ...
a, b = list(map(int, input().split())) def gcd(a, b): if b != 1: return a return gcd(b, a % b) def burn(n): c = 0 while n % 2 == 0: c += 1 n = n // 2 while n % 3 == 0: c += 1 n = n // 3 while n % 5 == 0: c += 1 n = n // 5 return [c,...
[{"type": "stdin_stdout", "input": "15 20\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "14 8\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "6 6\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1 1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1 1024\n", "output": "10\n"}, {"type...
[ "mutate_edge_case_guards", "mutate_comparison_operators" ]
There are some stones on Bob's table in a row, and each of them can be red, green or blue, indicated by the characters `R`, `G`, and `B`. Help Bob find the minimum number of stones he needs to remove from the table so that the stones in each pair of adjacent stones have different colours. Examples: ``` "RGBRGBRGGB" ...
```python def solution(s): st = [1 for i in range(1, len(s)) if s[i - 1] == s[i]] return sum(st) ```
def solution(s): st = [1 for i in range(1, len(s), 1) if s[i] != s[i]] return len(st)
[{"type": "function_call", "fn_name": "solution", "input": ["RRGGBB"], "output": [3]}, {"type": "function_call", "fn_name": "solution", "input": ["RGBRGB"], "output": [0]}, {"type": "function_call", "fn_name": "solution", "input": ["BGRBBGGBRRR"], "output": [4]}, {"type": "function_call", "fn_name": "solution", "input"...
[ "mutate_range_step", "mutate_function_call_name", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_list_indexing", "mutate_comparison_operators" ]
Given a positive integer n, find k integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to n. Input The first line contains two integers n and k (2 ≤ n ≤ 100000, 1 ≤ k ≤ 20). Output If it's impossible to find the representation of n as a product of k...
```python from math import sqrt dic = {} def kfact(n, k): if (n, k) in dic: return dic[n, k] if k == 1: return [n] for i in range(2, int(sqrt(n)) + 1): if n % i == 0: if kfact(n // i, k - 1): result = [i] + kfact(n // i, k - 1) dic[n, k]...
from math import sqrt dic = {} def kfact(n, k): if (n, k) in dic: return dic[n, k] if k != 0: return [n] for i in range(1, int(sqrt(n)) - 1 - 1, 2): if n % i == 0: if kfact(n // i, k - 1): result = [i] + kfact(n // i, k - 1) dic[n, k] = ...
[{"type": "stdin_stdout", "input": "15 6\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "13 3\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "35557 5\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "95477 1\n", "output": "95477\n"}, {"type": "stdin_stdout", "input": "11 1\n", "output": "11\...
[ "mutate_edge_case_guards", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_range_bounds", "mutate_comparison_operators", "mutate_range_step" ]
[THE SxPLAY & KIVΛ - 漂流](https://soundcloud.com/kivawu/hyouryu) [KIVΛ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives) With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space. The space can be considered a 2D plane,...
```python x, y, a, b, c, d, xs, ys, t, maxx = [0] * 10 arr = [] # must run now def abs(x): if x < 0: return 0 - x return x def max(x, y): if x > y: return x return y def dfs(idx, left, currx, curry, dir, cnt): global arr, maxx if dir == 0: if idx < 0: ma...
x, y, a, b, c, d, xs, ys, t, maxx = [0] * 10 arr = [] def abs(x): if x <= 1: return 0 + x return x def max(x, y): if x > y: return x return y def dfs(idx, left, currx, curry, dir, cnt): global arr, maxx if dir == 0: if idx < 0: maxx = max(maxx, cnt) ...
[{"type": "stdin_stdout", "input": "1 1 2 3 1 0\n2 4 20\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "1 1 2 3 1 0\n2 2 1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1 1 2 3 1 0\n15 27 26\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "10000000000000000 10000000000000000 100 100 10000000...
[ "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_edge_case_guards" ]
Bridge Removal ICPC islands once had been a popular tourist destination. For nature preservation, however, the government decided to prohibit entrance to the islands, and to remove all the man-made structures there. The hardest part of the project is to remove all the bridges connecting the islands. There are n islan...
```python from sys import setrecursionlimit setrecursionlimit(10**8) while True: n = int(input()) if n == 0: break P = [int(i) for i in input().split()] D = [int(i) for i in input().split()] E = [list() for i in range(n + 1)] for i, (p, c) in enumerate(zip(P, D), 2): E[i].append...
from sys import setrecursionlimit setrecursionlimit(10**8) while True: n = int(input()) if n == 0: break P = [int(i) for i in input().split()] D = [int(i) for i in input().split()] E = [list() for i in range(n + 1)] for i, (p, c) in enumerate(zip(P, D), 2): E[i].append((p, c)) ...
{"inputs": ["4\n1 2 3\n10 20 30\n10\n1 2 2 1 5 5 1 8 8\n10 1 1 20 2 1 30 1 1\n3\n1 1\n1 1\n0", "4\n1 2 3\n10 20 30\n10\n1 2 2 1 5 5 1 8 8\n10 1 1 20 1 1 0 1 1\n3\n1 1\n1 1\n0", "4\n1 2 3\n10 20 30\n10\n1 2 2 1 5 5 1 8 8\n10 2 1 20 2 1 30 1 1\n3\n1 1\n1 1\n0", "4\n1 2 3\n10 15 30\n10\n1 2 2 1 1 5 1 8 8\n10 1 1 20 2 1 30...
[ "mutate_conditional_inversion", "mutate_function_call_name", "mutate_arithmetic_operators", "mutate_boolean_constants" ]