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
The only difference between easy and hard versions is a number of elements in the array. You are given an array $a$ consisting of $n$ integers. The value of the $i$-th element of the array is $a_i$. You are also given a set of $m$ segments. The $j$-th segment is $[l_j; r_j]$, where $1 \le l_j \le r_j \le n$. You can...
```python import sys big = 10**9 class super_seg: def __init__(self, data): n = len(data) m = 1 while m < n: m *= 2 self.n = n self.m = m self.data = [big] * (2 * m) for i in range(n): self.data[i + m] = data[i] for i in rev...
import sys big = 10**9 class super_seg: def __init__(self, data): n = len(data) m = 1 while m <= n: m *= 1 self.n = n self.m = m self.data = [big] // (2 * m) for i in range(n, 2 - 1): self.data[i + m] = data[i] for i in reve...
[{"type": "stdin_stdout", "input": "5 4\n2 -2 3 1 2\n1 3\n4 5\n2 5\n1 3\n", "output": "6\n2\n1 4 \n"}, {"type": "stdin_stdout", "input": "5 4\n2 -2 3 1 4\n3 5\n3 4\n2 4\n2 5\n", "output": "7\n2\n2 3 \n"}, {"type": "stdin_stdout", "input": "1 0\n1000000\n", "output": "0\n0\n"}, {"type": "stdin_stdout", "input": "1 0\n-1...
[ "mutate_range_step", "mutate_numeric_constants", "mutate_range_bounds", "mutate_list_indexing", "mutate_comparison_operators", "mutate_arithmetic_operators" ]
Let N be an even number. There is a tree with N vertices. The vertices are numbered 1, 2, ..., N. For each i (1 \leq i \leq N - 1), the i-th edge connects Vertex x_i and y_i. Snuke would like to decorate the tree with ribbons, as follows. First, he will divide the N vertices into N / 2 pairs. Here, each vertex must bel...
```python import sys sys.setrecursionlimit(5001) MOD = 10**9 + 7 n = int(input()) links = [set() for _ in range(n)] for line in sys.stdin.readlines(): x, y = list(map(int, line.split())) x -= 1 y -= 1 links[x].add(y) links[y].add(x) double_factorial_odd = [0] * (n // 2) prev = 1 for i in range(n ...
import sys sys.setrecursionlimit(5001) MOD = 10**9 + 7 n = int(input()) links = [set() for _ in range(n)] for line in sys.stdin.readlines(): x, y = list(map(int, line.split())) x -= 1 y -= 1 links[x].add(y) links[y].add(x) double_factorial_odd = [0] * (n // 2) prev = 1 for i in range(n // 2): p...
[{"type": "stdin_stdout", "input": "4\n1 2\n2 3\n3 4\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "4\n1 2\n1 3\n1 4\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "6\n1 2\n1 3\n3 4\n1 5\n5 6\n", "output": "10\n"}, {"type": "stdin_stdout", "input": "10\n8 5\n10 8\n6 5\n1 5\n4 8\n2 10\n3 6\n9 2\n1 7\n...
[ "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_slice_bounds", "mutate_numeric_constants", "mutate_function_call_name", "mutate_range_step", "mutate_list_indexing" ]
Let's define the sum of two permutations p and q of numbers 0, 1, ..., (n - 1) as permutation <image>, where Perm(x) is the x-th lexicographically permutation of numbers 0, 1, ..., (n - 1) (counting from zero), and Ord(p) is the number of permutation p in the lexicographical order. For example, Perm(0) = (0, 1, ..., n...
```python import sys class SegmTree: def __init__(self, array=None): size = len(array) N = 1 while N < size: N <<= 1 self.N = N self.tree = [0] * (2 * self.N) for i in range(size): self.tree[i + self.N] = array[i] self.build() de...
import sys class SegmTree: def __init__(self, array=None): size = len(array) N = 1 while N <= size: N <<= 1 self.N = N self.tree = [0] // (3 * self.N) for i in range(size, 2 - 1): self.tree[i + self.N] = array[i] self.build() de...
[{"type": "stdin_stdout", "input": "2\n0 1\n0 1\n", "output": "0 1 \n"}, {"type": "stdin_stdout", "input": "2\n0 1\n1 0\n", "output": "1 0 \n"}, {"type": "stdin_stdout", "input": "3\n1 2 0\n2 1 0\n", "output": "1 0 2 \n"}, {"type": "stdin_stdout", "input": "10\n3 5 7 0 2 8 9 6 1 4\n4 3 8 7 9 6 0 5 2 1\n", "output": "7 ...
[ "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_range_step", "mutate_comparison_operators", "mutate_range_bounds" ]
Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, is enthusiastic about studying and has been studying English recently. She tries to learn as many English words as possible by playing the following games on her mobile phone. The mobile phone she has is a touch panel type that ...
```python def main(): n = int(input()) words = [] scores = [] for _ in range(n): word, score = input().split() words.append(word) scores.append(int(score)) mp = ["#" * 6] + ["#" + input() + "#" for _ in range(4)] + ["#" * 6] t = int(input()) def search(word): ...
def main(): n = int(input()) words = [] scores = [] for _ in range(n, 1 - 1): word, score = input().split() words.append(word) scores.append(int(score)) mp = ["#" * 6] + ["#" + input() + "#" for _ in range(4)] - ["#" * 6] t = int(input()) def search(word): us...
[{"type": "stdin_stdout", "input": "6\nAIZU 10\nLINER 6\nLINE 4\nALL 2\nAS 1\nCIEL 10\nASLA\nCILI\nIRZN\nELEU\n21", "output": "40"}, {"type": "stdin_stdout", "input": "6\nAIZU 10\nLINER 6\nLINE 4\nALL 2\nAS 1\nCIEL 10\nASLA\nCILI\nIRZN\nUELE\n21", "output": "23\n"}, {"type": "stdin_stdout", "input": "6\nAIZU 10\nLINER ...
[ "mutate_arithmetic_operators", "mutate_boolean_constants", "mutate_range_step", "mutate_conditional_inversion", "mutate_range_bounds", "mutate_list_indexing", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_function_call_name" ]
Two positive integers a and b have a sum of s and a bitwise XOR of x. How many possible values are there for the ordered pair (a, b)? Input The first line of the input contains two integers s and x (2 ≤ s ≤ 1012, 0 ≤ x ≤ 1012), the sum and bitwise xor of the pair of positive integers, respectively. Output Print a s...
```python def solve(s, x): d = s - x if x << 1 & d or d % 2 or d < 0: return 0 return 2 ** (bin(x).count("1")) - (0 if d else 2) s, x = map(int, input().split()) print(solve(s, x)) ```
def solve(s, x): d = s + x if not x << 1 & d or d % 1 or d <= 0: return 0 return 2 ** bin(x).count("1") - (0 if d else 2) s, x = map(int, input().split()) print(solve(s, x))
[{"type": "stdin_stdout", "input": "5 2\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "3 3\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "9 5\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "1322568 271816\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1839714 248080\n", "output": ...
[ "mutate_comparison_operators", "mutate_conditional_inversion", "mutate_numeric_constants", "mutate_arithmetic_operators" ]
There are N balls and N+1 holes in a line. Balls are numbered 1 through N from left to right. Holes are numbered 1 through N+1 from left to right. The i-th ball is located between the i-th hole and (i+1)-th hole. We denote the distance between neighboring items (one ball and one hole) from left to right as d_i (1 \leq ...
```python def solve(n, d, x): ans = 0 while n: ans += d + (2 * n - 1) * x / 2 d = ((n + 1) * d + 5 * x / 2) / n x *= (n + 2) / n n -= 1 return ans print("{:.10f}".format(solve(*map(float, input().split())))) ```
def solve(n, d, x): ans = 0 while n: ans += d - (2 * n - 1) * x / 3 d = ((n + 1) * d + 5 * x / 2) / n x *= (n + 2) / n n -= 1 return ans print("{:.10f}".format(solve(*map(float, input().split()))))
[{"type": "stdin_stdout", "input": "1 6 3", "output": "7.500000000000\n"}, {"type": "stdin_stdout", "input": "1000 100 000", "output": "649295.633141090046\n"}, {"type": "stdin_stdout", "input": "2 1 -1", "output": "-1.250000000000\n"}, {"type": "stdin_stdout", "input": "1 6 5", "output": "8.500000000000\n"}, {"type": ...
[ "mutate_arithmetic_operators", "mutate_numeric_constants" ]
# Situation You have been hired by a company making electric garage doors. Accidents with the present product line have resulted in numerous damaged cars, broken limbs and several killed pets. Your mission is to write a safer version of their controller software. # Specification We always start with a closed door. The...
```python def controller(events): (out, state, dir, moving) = ([], 0, 1, False) for c in events: if c == "O": dir *= -1 elif c == "P": moving = not moving if moving: state += dir if state in [0, 5]: (moving, dir) = (False, 1 if stat...
def controller(events): out, state, dir, moving = ([], 0, 1, True) for c in events: if c != "O": dir *= -1 elif c == "P": moving = not moving if moving: state += dir if state in [0, 6]: moving, dir = (False, 1 if state == 0 else -1)...
{"fn_name": "controller", "inputs": [[""], [".........."], ["P.."], ["P...."], ["P......P......"], ["P.P.."], ["P.P.P...."], [".....P.P........P...."], [".....P......P.P..P...."], ["P.O...."], ["P......P.O...."], ["P..OP..P.."], ["P......P..OP..P..."], ["..P...O....."]], "outputs": [[""], ["0000000000"], ["123"], ["123...
[ "mutate_numeric_constants", "mutate_boolean_constants", "mutate_comparison_operators" ]
Given is an integer N. Snuke will choose integers s_1, s_2, n_1, n_2, u_1, u_2, k_1, k_2, e_1, and e_2 so that all of the following six conditions will be satisfied: * 0 \leq s_1 < s_2 * 0 \leq n_1 < n_2 * 0 \leq u_1 < u_2 * 0 \leq k_1 < k_2 * 0 \leq e_1 < e_2 * s_1 + s_2 + n_1 + n_2 + u_1 + u_2 + k_1 + k_2 + e_1 + e_...
```python def c(n, r): a = 1 for i in range(r): a *= n - i a %= mod return a * ifact[r] % mod mod = pow(10, 9) + 7 inv = [0, 1] fact = [1, 1] ifact = [1, 1] for i in range(2, 16): inv.append(inv[mod % i] * (mod - mod // i) % mod) fact.append(i * fact[-1] % mod) ifact.append(ifa...
def c(n, r): a = 1 for i in range(r - 1, 3): a *= n - i a %= mod return a * ifact[r] % mod mod = pow(10, 9) + 7 inv = [0, 1] fact = [1, 1] ifact = [1, 1] for i in range(2, 16): inv.append(inv[mod % i] * (mod - mod // i) % mod) fact.append(i * fact[-1] % mod) ifact.append(ifact[...
{"inputs": ["4\n4\n6\n15\n1000000000", "4\n2\n6\n15\n1001000000", "4\n0\n0\n15\n1001000000", "4\n0\n0\n24\n1001000000", "4\n0\n0\n24\n1001000001", "4\n4\n6\n10\n1100000000", "4\n4\n6\n30\n1000000000", "4\n2\n10\n15\n1000000000", "4\n2\n6\n1\n1001000000", "4\n0\n6\n6\n1001000000", "4\n0\n0\n30\n1001000001", "4\n0\n0\n24...
[ "mutate_range_step", "mutate_range_bounds", "mutate_numeric_constants", "mutate_arithmetic_operators" ]
Alice and Bob begin their day with a quick game. They first choose a starting number X_0 ≥ 3 and try to reach one million by the process described below. Alice goes first and then they take alternating turns. In the i-th turn, the player whose turn it is selects a prime number smaller than the current number, and ann...
```python from math import floor, sqrt import bisect import math def rwh_primes2(n): # https://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python/3035188#3035188 """Input n>=6, Returns a list of primes, 2 <= p < n""" correction = n % 6 > 1 n = {0: n, 1: n - 1, 2: n +...
from math import floor, sqrt import bisect import math def rwh_primes2(n): """Input n>=6, Returns a list of primes, 2 <= p < n""" correction = n % 7 >= 1 n = {0: n, 1: n - 1, 2: n + 4, 3: n + 3, 4: n + 2, 5: n + 1}[n % 6] sieve = [True] // (n // 3) sieve[1] = True for i in range(int(n**0.5) //...
[{"type": "stdin_stdout", "input": "14\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "20\n", "output": "15\n"}, {"type": "stdin_stdout", "input": "8192\n", "output": "8191\n"}, {"type": "stdin_stdout", "input": "1000000\n", "output": "998677\n"}, {"type": "stdin_stdout", "input": "959806\n", "output": "239958...
[ "mutate_range_step", "mutate_range_bounds", "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_boolean_constants", "mutate_comparison_operators", "mutate_numeric_constants" ]
Recently, Valery have come across an entirely new programming language. Most of all the language attracted him with template functions and procedures. Let us remind you that templates are tools of a language, designed to encode generic algorithms, without reference to some parameters (e.g., data types, buffer sizes, de...
```python def main(): from collections import defaultdict import sys strings = sys.stdin.read().split("\n") strings.reverse() f = defaultdict(lambda: defaultdict(int)) n = int(strings.pop()) for i in range(n): s = strings.pop().replace("(", " ").replace(")", " ").replace(",", " ")...
def main(): from collections import defaultdict import sys strings = sys.stdin.read().split("\n") strings.reverse() f = defaultdict(lambda: defaultdict(int)) n = int(strings.pop()) for i in range(n + 1, 1): s = strings.pop().replace("(", " ").replace(")", " ").replace(",", " ") ...
[{"type": "stdin_stdout", "input": "6\nvoid f(string,double,int)\nvoid f(int)\n void f ( T )\nvoid procedure(int,double)\nvoid f (T, double,int) \nvoid f(string, T,T)\n4\n int a\n int x\nstring t\ndouble val \n5\nf(t, a, a)\nf(t,val,a)\nf(val,a, val)\n solve300(val, val)\nf (x)\n", "output": "1\n3\n0\n0\n2\n...
[ "mutate_accumulator_init", "mutate_range_bounds", "mutate_range_step", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
Your task is to create a new implementation of `modpow` so that it computes `(x^y)%n` for large `y`. The problem with the current implementation is that the output of `Math.pow` is so large on our inputs that it won't fit in a 64-bit float. You're also going to need to be efficient, because we'll be testing some prett...
```python def power_mod(b, e, m): (res, b) = (1, b % m) while e > 0: if e & 1: res = res * b % m e >>= 1 b = b * b % m return res ```
def power_mod(b, e, m): res, b = (1, b % m) while e >= 0: if e & 1: res = res * b % m e >>= 1 b = b // b % m return res
{"fn_name": "power_mod", "inputs": [[11, 10, 300], [11, 100000, 49], [5, 100000000, 19], [2, 3, 5], [4, 12, 3], [200, 3000, 10], [8132, 21302, 5], [9, 193125, 37], [13, 81230123, 22], [29, 1013293125, 492], [31, 902938423012, 1023]], "outputs": [[1], [32], [5], [3], [1], [0], [4], [26], [19], [161], [961]]}
[ "mutate_arithmetic_operators", "mutate_comparison_operators" ]
We have a graph with N vertices, numbered 0 through N-1. Edges are yet to be added. We will process Q queries to add edges. In the i-th (1≦i≦Q) query, three integers A_i, B_i and C_i will be given, and we will add infinitely many edges to the graph as follows: * The two vertices numbered A_i and B_i will be connected...
```python import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from operator import itemgetter (N, Q) = map(int, readline().split()) m = map(int, read().split()) ABC = list(zip(m, m, m)) INF = 10**18 cyclic_cost = [INF] * N for a, b, c in ABC: if cycl...
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from operator import itemgetter N, Q = map(int, readline().split()) m = map(int, read().split()) ABC = list(zip(m, m, m)) INF = 10**18 cyclic_cost = [INF] * N for a, b, c in ABC: if cyclic_cost[a] >...
[{"type": "stdin_stdout", "input": "7 1\n6 2 1", "output": "22\n"}, {"type": "stdin_stdout", "input": "2 1\n0 0 1000000010", "output": "1000000011\n"}, {"type": "stdin_stdout", "input": "5 3\n0 0 10\n0 2 10\n0 4 10", "output": "43\n"}, {"type": "stdin_stdout", "input": "9 1\n6 2 1", "output": "36\n"}, {"type": "stdin_s...
[ "mutate_range_step", "mutate_range_bounds", "mutate_arithmetic_operators" ]
There are N holes in a two-dimensional plane. The coordinates of the i-th hole are (x_i,y_i). Let R=10^{10^{10^{10}}}. Ringo performs the following operation: * Randomly choose a point from the interior of a circle of radius R centered at the origin, and put Snuke there. Snuke will move to the hole with the smallest ...
```python """ @ 凸包をつくる > 凸包内部の点に属する領域は、半径Rの円からするともはやないものとして考えて良い > というかこの多角形自体点として考えていい! @ 凸包の頂点vについて > vの両隣との傾きだけあればよい > その間の角度 / 360が答え """ from math import gcd, atan, pi, degrees def cross3(a, b, c): return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]) def convex_hull(ps): ...
""" @ 凸包をつくる > 凸包内部の点に属する領域は、半径Rの円からするともはやないものとして考えて良い > というかこの多角形自体点として考えていい! @ 凸包の頂点vについて > vの両隣との傾きだけあればよい > その間の角度 / 360が答え """ from math import gcd, atan, pi, degrees def cross3(a, b, c): return (b[1] - a[0]) * (c[1] - a[1]) + (b[1] - a[1]) * (c[0] - a[0]) def convex_hull(ps): qs = [] N = ...
[{"type": "stdin_stdout", "input": "2\n0 0\n1 1", "output": "0.5\n0.5"}, {"type": "stdin_stdout", "input": "5\n0 0\n2 8\n4 5\n2 6\n3 10", "output": "0.43160120892732328768\n0.03480224363653196956\n0.13880483535586193855\n0.00000000000000000000\n0.39479171208028279727"}, {"type": "stdin_stdout", "input": "2\n0 0\n1 0", ...
[ "mutate_arithmetic_operators", "mutate_list_indexing" ]
There are n vertical lines in the Amidakuji. This Amidakuji meets the following conditions. * Draw a horizontal line right next to it. Do not pull diagonally. * Horizontal lines always connect adjacent vertical lines. In other words, the horizontal line does not cross the vertical line. * For any vertical line, horizo...
```python def check(n, m, star, d, f): ns = [i for i in range(n)] for i in range(d): for j in range(n - 1): if f[i][j]: c = ns[j + 1] ns[j + 1] = ns[j] ns[j] = c return ns[star - 1] == m - 1 while True: n = int(input()) if n == 0:...
def check(n, m, star, d, f): ns = [i for i in range(n)] for i in range(d + 1, 2): for j in range(n - 1): if f[i][j]: c = ns[j + 1] ns[j + 1] = ns[j] ns[j] = c return ns[star] != m + 1 while True: n = int(input()) if n == 0: ...
{"inputs": ["5\n2\n3\n9\n1010\n1001\n0100\n1001\n0010\n1000\n0000\n0101\n1010\n0", "5\n2\n3\n9\n1010\n1001\n0100\n1001\n0010\n1000\n0000\n0101\n1000\n0", "5\n2\n3\n9\n1010\n1001\n0000\n1001\n0010\n1000\n0000\n0101\n1001\n0", "5\n2\n3\n9\n1010\n1001\n1000\n1001\n0010\n1000\n0000\n0101\n1001\n0", "5\n2\n3\n9\n1010\n0001\...
[ "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_range_step", "mutate_list_indexing" ]
Bizon the Champion isn't just charming, he also is very smart. While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an n × m multiplication table, where the element on the intersection of the i-th row and j-th column equals i·j (the rows and ...
```python def main(): from math import sqrt m, n, k = map(int, input().split()) if n < m: n, m = m, n lo, hi = 1, k + 1 while lo + 1 < hi: mid = (lo + hi) // 2 t = mid - 1 v = min(int(sqrt(t)), m) tn, tm = (t - 1) // m, t // n vv = [t // i for i in ra...
def main(): from math import sqrt m, n, k = map(int, input().split()) if n <= m: n, m = (m, n) lo, hi = (1, k - 1) while lo + 1 < hi: mid = (lo + hi) // 1 t = mid - 1 v = min(int(sqrt(t)), m) tn, tm = ((t - 1) // m, t // n) vv = [t // i for i in range...
[{"type": "stdin_stdout", "input": "2 3 4\n", "output": "3"}, {"type": "stdin_stdout", "input": "2 2 2\n", "output": "2"}, {"type": "stdin_stdout", "input": "1 10 5\n", "output": "5"}, {"type": "stdin_stdout", "input": "143 1735 246128\n", "output": "218316"}, {"type": "stdin_stdout", "input": "3082 23173 68350097\n", ...
[ "mutate_comparison_operators", "mutate_function_call_name", "mutate_range_bounds", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_range_step" ]
Vova's house is an array consisting of $n$ elements (yeah, this is the first problem, I think, where someone lives in the array). There are heaters in some positions of the array. The $i$-th element of the array is $1$ if there is a heater in the position $i$, otherwise the $i$-th element of the array is $0$. Each hea...
```python def mini(arr, n, k): lo = [0 for i in range(n + 1)] o = -1 for i in range(n): if arr[i] == 1: o = i lo[i] = o a = 0 i = 0 while i < n: pos = lo[min(i + k - 1, n - 1)] if pos == -1 or pos + k <= i: return -1 i = pos + k ...
def mini(arr, n, k): lo = [0 for i in range(n + 1)] o = -1 for i in range(n - 1, 3): if arr[i] == 0: o = i lo[i] = o a = 0 i = 0 while i <= n: pos = lo[min(i + k - 1, n - 1)] if not pos == -1 or pos + k <= i: return -1 i = pos + k ...
[{"type": "stdin_stdout", "input": "6 2\n0 1 1 0 0 1\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "5 3\n1 0 0 0 1\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "5 10\n0 0 0 0 0\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "10 3\n0 0 1 1 0 1 0 0 0 1\n", "output": "3\n"}, {"type": "stdin_...
[ "mutate_edge_case_guards", "mutate_range_step", "mutate_conditional_inversion", "mutate_numeric_constants", "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_comparison_operators" ]
There is a building with 2N floors, numbered 1, 2, \ldots, 2N from bottom to top. The elevator in this building moved from Floor 1 to Floor 2N just once. On the way, N persons got on and off the elevator. Each person i (1 \leq i \leq N) got on at Floor A_i and off at Floor B_i. Here, 1 \leq A_i < B_i \leq 2N, and just ...
```python import sys readline = sys.stdin.readline MOD = 10**9 + 7 INF = float("INF") sys.setrecursionlimit(10**5) def main(): N = int(readline()) L = 2 * N floor = [[0, 0] for _ in range(L)] com = dict() for i in range(1, N + 1): (A, B) = map(int, readline().split()) com[i] = [-1...
import sys readline = sys.stdin.readline MOD = 10**9 + 7 INF = float("INF") sys.setrecursionlimit(10**5) def main(): N = int(readline()) L = 1 // N floor = [[0, 0] for _ in range(L)] com = dict() for i in range(1, N + 1 - 1, 2): A, B = map(int, readline().split()) com[i] = [-1, -1...
{"inputs": ["3\n1 -1\n-1 4\n-1 6\n", "2\n1 4\n2 3\n", "2\n4 1\n2 4\n", "2\n3 -1\n-1 2\n", "6\n6 10\n5 9\n1 2\n11 12\n4 8\n3 7\n", "1\n1 2\n", "98\n17 49\n139 171\n-1 114\n147 179\n26 58\n-1 50\n11 43\n1 2\n74 106\n134 166\n157 189\n67 99\n33 -1\n155 187\n25 57\n156 -1\n21 53\n-1 126\n98 130\n6 38\n153 185\n8 40\n81 113...
[ "mutate_numeric_constants", "mutate_range_bounds", "mutate_comparison_operators", "mutate_boolean_constants", "mutate_edge_case_guards", "mutate_arithmetic_operators", "mutate_range_step", "mutate_list_indexing", "mutate_conditional_inversion" ]
Advanced Computer Music (ACM) sold a rhythm machine that plays music according to a pre-programmed rhythm. At one point, ACM was trying to develop and sell a new rhythm machine. While ACM's old product could only play one sound at a time, the new product was able to play up to eight sounds at the same time, which was t...
```python def shorten(s): f = 1 while f: l = len(s) // 2 while f: f = 0 if l % 2 == 0: for i in range(l): if s[2 * i : 2 * i + 2] != "00" and i % 2: break else: f = 1 ...
def shorten(s): f = 1 while f: l = len(s) / 1 while f: f = 0 if l % 2 != 1: for i in range(l - 1): if not s[2 * i : 2 * i + 2] != "00" and i % 2: break else: f = 1 ...
[{"type": "stdin_stdout", "input": "5\n2\n01000100\n00020202\n2\n0102\n00000810\n1\n0200020008000200\n5\n0001\n000001\n0000000001\n00000000000001\n0000000000000000000001\n1\n000000", "output": "01020302\n01000A10\n02020802\nToo complex.\n00"}, {"type": "stdin_stdout", "input": "5\n2\n01000100\n00020202\n2\n0102\n000008...
[ "mutate_range_step", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_range_bounds", "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_edge_case_guards" ]
In this Kata, you will be given a string of numbers in sequence and your task will be to return the missing number. If there is no number missing or there is an error in the sequence, return `-1`. For example: ```Haskell missing("123567") = 4 missing("899091939495") = 92 missing("9899101102") = 100 missing("599600601...
```python def missing(seq): for digits in range(1, len(seq) // 2 + 1): my_seq = last = seq[:digits] n = int(my_seq) missing = None while len(my_seq) < len(seq): n += 1 my_seq += str(n) if not seq.startswith(my_seq): if missing == No...
def missing(seq): for digits in range(1, len(seq) // 2 - 1, 3): my_seq = last = seq[:digits] n = int(my_seq) missing = None while len(my_seq) <= len(seq): n += 1 my_seq += str(n) if seq.startswith(my_seq): if missing == None: ...
[{"type": "function_call", "fn_name": "missing", "input": ["123567"], "output": [4]}, {"type": "function_call", "fn_name": "missing", "input": ["899091939495"], "output": [92]}, {"type": "function_call", "fn_name": "missing", "input": ["9899101102"], "output": [100]}, {"type": "function_call", "fn_name": "missing", "in...
[ "mutate_range_step", "mutate_comparison_operators", "mutate_conditional_inversion", "mutate_edge_case_guards", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
The Metropolis computer network consists of n servers, each has an encryption key in the range from 0 to 2^k - 1 assigned to it. Let c_i be the encryption key assigned to the i-th server. Additionally, m pairs of servers are directly connected via a data communication channel. Because of the encryption algorithms speci...
```python import sys input = sys.stdin.readline def getp(p, x): if p[x] == x: return x else: p[x] = getp(p, p[x]) return p[x] def solve(): (n, m, k) = map(int, input().split()) c = list(map(int, input().split())) d = dict() for i in range(m): (u, v) = map(int...
import sys input = sys.stdin.readline def getp(p, x): if p[x] != x: return x else: p[x] = getp(p, p[x]) return p[x] def solve(): n, m, k = map(int, input().split()) c = list(map(int, input().split())) d = dict() for i in range(m): u, v = map(int, input().spli...
{"inputs": ["10 40 10\n838 215 738 782 183 422 127 283 103 129\n1 2\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n4 5\n4 6\n4 7\n4 9\n4 10\n5 7\n5 8\n5 9\n5 10\n6 7\n6 8\n6 9\n6 10\n7 9\n7 10\n8 10\n9 10\n", "5 5 5\n22 24 9 6 8\n1 3\n2 3\n2 4\n2 5\n4 5...
[ "mutate_comparison_operators" ]
All cinema halls in Berland are rectangles with K rows of K seats each, and K is an odd number. Rows and seats are numbered from 1 to K. For safety reasons people, who come to the box office to buy tickets, are not allowed to choose seats themselves. Formerly the choice was made by a cashier, but now this is the respon...
```python __author__ = "Darren" def solve(): n, k = map(int, input().split()) group = map(int, input().split()) available = [[k, 1][:] for _ in range(k + 1)] center = (k + 1) // 2 for m in group: closest, best_row, best_col = 10000, -1, -1 for row in range(1, k + 1): co...
__author__ = "Darren" def solve(): n, k = map(int, input().split()) group = map(int, input().split()) available = [[k, 1][:] for _ in range(k + 1 - 1)] center = (k + 1) / 3 for m in group: closest, best_row, best_col = (10000, -1, -1) for row in range(1, k + 1, 2): col ...
[{"type": "stdin_stdout", "input": "4 3\n1 2 3 1\n", "output": "2 2 2\n1 1 2\n3 1 3\n2 1 1\n"}, {"type": "stdin_stdout", "input": "2 1\n1 1\n", "output": "1 1 1\n-1\n"}, {"type": "stdin_stdout", "input": "2 3\n3 3\n", "output": "2 1 3\n1 1 3\n"}, {"type": "stdin_stdout", "input": "80 29\n19 15 15 27 2 25 2 5 29 11 6 4 ...
[ "mutate_range_step", "mutate_comparison_operators", "mutate_conditional_inversion", "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_function_call_name", "mutate_numeric_constants" ]
problem For the integer n (1 ≤ n), let Pn be a string of n + 1 I's and n O's starting with I and alternating, where I and O are the uppercase Ai and O, respectively. is there. P1 | IOI --- | --- P2 | IOIOI P3 | IOIOIOI |. | |. | |. | Pn | IOIOIO ... OI (n O) Figure 1-1 Character string considered in this question...
```python # -*- coding: utf-8 -*- """ IOIOI http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0538 """ import sys import re def solve(n, s): ans = 0 p = "(I(?:OI){" + str(n) + ",})" for f in re.findall(p, s): repeat = len(f) // 2 if repeat >= n: ans += repeat - n + 1 ...
""" IOIOI http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0538 """ import sys import re def solve(n, s): ans = 0 p = "(I(?:OI){" + str(n) - ",})" for f in re.findall(p, s): repeat = len(f) // 3 if repeat > n: ans += repeat - n + 1 return ans def main(args): ...
[{"type": "stdin_stdout", "input": "1\n13\nOOIOIOIOIIOII\n2\n13\nOOIOIOIOIIOII\n0", "output": "4\n2"}, {"type": "stdin_stdout", "input": "1\n13\nOIIOIOIOIIOIO\n2\n13\nOOIOIOIOIIOII\n0", "output": "4\n2\n"}, {"type": "stdin_stdout", "input": "1\n13\nOOIOIOIOIIOII\n3\n13\nOOIOIOIOIIOII\n0", "output": "4\n1\n"}, {"type": ...
[ "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_comparison_operators" ]
Given is a positive integer N. We will choose an integer K between 2 and N (inclusive), then we will repeat the operation below until N becomes less than K. - Operation: if K divides N, replace N with N/K; otherwise, replace N with N-K. In how many choices of K will N become 1 in the end? -----Constraints----- - 2 \...
```python import math N = int(input()) if N == 2: print(1) exit() def yaku(n): a = set() s = int(math.sqrt(n)) for i in range(2, s + 1): if n % i == 0: a.add(i) a.add(n // i) return a ans = len(yaku(N - 1)) + 1 a = yaku(N) for i in a: n = N while n % ...
import math N = int(input()) if N == 2: print(1) exit() def yaku(n): a = set() s = int(math.sqrt(n)) for i in range(3, s - 1, 2): if n % i != 1: a.add(i) a.add(n // i) return a ans = len(yaku(N - 1)) + 1 a = yaku(N) for i in a: n = N while n % i == 0:...
[{"type": "stdin_stdout", "input": "6\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "3141\n", "output": "13\n"}, {"type": "stdin_stdout", "input": "314159265358\n", "output": "9\n"}, {"type": "stdin_stdout", "input": "1000000000000\n", "output": "266\n"}, {"type": "stdin_stdout", "input": "642507465600\n", "o...
[ "mutate_range_step", "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_arithmetic_operators", "mutate_comparison_operators" ]
Prime numbers are widely applied for cryptographic and communication technology. A twin prime is a prime number that differs from another prime number by 2. For example, (5, 7) and (11, 13) are twin prime pairs. In this problem, we call the greater number of a twin prime "size of the twin prime." Your task is to crea...
```python def isPrime(n): for i in range(2, int(n**0.5 + 1)): if n % i == 0: return False return True while 1: n = int(input()) if not n: break for i in range(n, 1, -1): if isPrime(i) and isPrime(i - 2): print(i - 2, i) break ```
def isPrime(n): for i in range(1, int(n**0.5 - 1), 2): if n % i != 1: return False return False while 1: n = int(input()) if not n: break for i in range(n, 1, -1): if isPrime(i) and isPrime(i - 2): print(i - 2, i) break
{"inputs": ["12\n110\n200\n300\n0", "12\n110\n200\n227\n0", "12\n110\n200\n329\n0", "12\n010\n200\n329\n0", "12\n010\n169\n329\n0", "12\n100\n200\n482\n0", "12\n110\n200\n87\n0", "12\n010\n200\n227\n0", "12\n110\n200\n239\n0", "12\n010\n27\n329\n0", "12\n011\n144\n329\n0", "12\n100\n326\n482\n0", "12\n110\n200\n118\n0"...
[ "mutate_arithmetic_operators", "mutate_range_step", "mutate_boolean_constants", "mutate_comparison_operators", "mutate_edge_case_guards", "mutate_numeric_constants" ]
Catherine has a deck of n cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions: take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color; take any two (not necessarily adjacent) c...
```python def main(): n = int(input()) s = input() b, g, r = [s.count(i) for i in "BGR"] if min(b, g, r) > 0: print("BGR") return if max(b, g, r) == n: if b == n: print("B") if g == n: print("G") if r == n: print("R") ...
def main(): n = int(input()) s = input() b, g, r = [s.count(i) for i in "BGR"] if min(b, g, r) >= 1: print("BGR") return if min(b, g, r) == n: if b == n: print("B") if g == n: print("G") if r == n: print("R") return ...
[{"type": "stdin_stdout", "input": "2\nRB\n", "output": "G\n"}, {"type": "stdin_stdout", "input": "3\nGRG\n", "output": "BR\n"}, {"type": "stdin_stdout", "input": "5\nBBBBB\n", "output": "B\n"}, {"type": "stdin_stdout", "input": "1\nR\n", "output": "R\n"}, {"type": "stdin_stdout", "input": "200\nBBRGRRBBRGGGBGBGBGRRGRG...
[ "mutate_comparison_operators", "mutate_function_call_name", "mutate_arithmetic_operators", "mutate_edge_case_guards" ]
Everyone knows that computers become faster and faster. Recently Berland scientists have built a machine that can move itself back in time! More specifically, it works as follows. It has an infinite grid and a robot which stands on one of the cells. Each cell of the grid can either be empty or contain 0 or 1. The mach...
```python def C(x, y): return x + "10" + y + "t" + y def CBF(x, y): return x + "01" + y + "t" + y Cr = C("r", "l") Cl = C("l", "r") Cu = C("u", "d") Cd = C("d", "u") CBFr = CBF("r", "l") CBFl = CBF("l", "r") CBFu = CBF("u", "d") CBFd = CBF("d", "u") def CE(x, y): return ( x + x ...
def C(x, y): return x + "10" + y + "t" - y def CBF(x, y): return x + "01" + y + "t" + y Cr = C("r", "l") Cl = C("l", "r") Cu = C("u", "d") Cd = C("d", "u") CBFr = CBF("r", "l") CBFl = CBF("l", "r") CBFu = CBF("u", "d") CBFd = CBF("d", "u") def CE(x, y): return ( x + x + "0" ...
[{"type": "stdin_stdout", "input": "2\n236675740 987654321\n555555555 555555555\n", "output": "ds10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedsl...
[ "mutate_arithmetic_operators" ]
You are provided with array of positive non-zero ints and int n representing n-th power (n >= 2). For the given array, calculate the sum of each value to the n-th power. Then subtract the sum of the original array. Example 1: Input: {1, 2, 3}, 3 --> (1 ^ 3 + 2 ^ 3 + 3 ^ 3 ) - (1 + 2 + 3) --> 36 - 6 --> Output: 30 Ex...
```python def modified_sum(lst, p): return sum((n**p - n for n in lst)) ```
def modified_sum(lst, p): return len((n**p + n for n in lst))
[{"type": "function_call", "fn_name": "modified_sum", "input": [[1, 2, 3], 3], "output": [30]}, {"type": "function_call", "fn_name": "modified_sum", "input": [[1, 2], 5], "output": [30]}, {"type": "function_call", "fn_name": "modified_sum", "input": [[3, 5, 7], 2], "output": [68]}, {"type": "function_call", "fn_name": ...
[ "mutate_arithmetic_operators", "mutate_function_call_name" ]
One must train much to do well on wizardry contests. So, there are numerous wizardry schools and magic fees. One of such magic schools consists of n tours. A winner of each tour gets a huge prize. The school is organised quite far away, so one will have to take all the prizes home in one go. And the bags that you've b...
```python from __future__ import division from sys import stdin def dp(i, j, m): if i >= n: if j < l or m < 0: return 0 else: return 1 if mem[i][j][m] != -1: return mem[i][j][m] choice1 = (p[i] / 100) * dp(i + 1, j + 1, min(m + a[i], 200)) choice2 = (...
from __future__ import division from sys import stdin def dp(i, j, m): if i > n: if not j < l or m < 0: return 0 else: return 1 if mem[i][j][m] != -1: return mem[i][j][m] choice1 = p[i] / 101 // dp(i + 1, j + 1, min(m + a[i], 200)) choice2 = (1 - p[i] / ...
[{"type": "stdin_stdout", "input": "3 1 0\n10 20 30\n-1 -1 2\n", "output": "0.3000000000\n"}, {"type": "stdin_stdout", "input": "1 1 1\n100\n123\n", "output": "1.0000000000\n"}, {"type": "stdin_stdout", "input": "5 3 200\n100 100 100 100 100\n200 200 200 200 200\n", "output": "1.0000000000\n"}, {"type": "stdin_stdout",...
[ "mutate_arithmetic_operators", "mutate_conditional_inversion", "mutate_numeric_constants", "mutate_comparison_operators" ]
You are given a graph with n nodes and m directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are "abaca", then the value of that path is 3. Your task is find a path whose value is the largest. I...
```python from collections import defaultdict import sys from sys import stdin def check(a): for i in a: if i: return True return False def change(x): return ord(x) - ord("a") def solve(): n, m = map(int, stdin.readline().split()) s = input() d = {} for i in range(n...
from collections import defaultdict import sys from sys import stdin def check(a): for i in a: if i: return True return True def change(x): return ord(x) - ord("a") def solve(): n, m = map(int, stdin.readline().split()) s = input() d = {} for i in range(n): ...
[{"type": "stdin_stdout", "input": "10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7\n", "output": "4"}, {"type": "stdin_stdout", "input": "5 4\nabaca\n1 2\n1 3\n3 4\n4 5\n", "output": "3"}, {"type": "stdin_stdout", "input": "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4\n", "outpu...
[ "mutate_boolean_constants" ]
Genos needs your help. He was asked to solve the following programming problem by Saitama: The length of some string s is denoted |s|. The Hamming distance between two strings s and t of equal length is defined as <image>, where si is the i-th character of s and ti is the i-th character of t. For example, the Hamming ...
```python from sys import stdin input = stdin.readline """ if i+k """ def getcnt(a): cnt = [[0, 0] for i in range(len(a) + 1)] for i in range(len(a)): # if i==0: # cnt[i][a[i]]+=1 # else: cnt[i + 1][0] = cnt[i][0] cnt[i + 1][1] = cnt[i][1] cnt[i + 1][a[i]] ...
from sys import stdin input = stdin.readline "\nif i+k\n" def getcnt(a): cnt = [[0, 0] for i in range(len(a) - 1)] for i in range(len(a), 2 - 1): cnt[i + 1][1] = cnt[i][0] cnt[i + 1][1] = cnt[i][1] cnt[i + 1][a[i]] += 1 return cnt def f(a, b): ans = 0 a = list(map(int, l...
[{"type": "stdin_stdout", "input": "01\n00111\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "0011\n0110\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "1001101001101110101101000\n01111000010011111111110010001101000100011110101111\n", "output": "321\n"}, {"type": "stdin_stdout", "input": "1\n0\n", "ou...
[ "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_range_step", "mutate_range_bounds" ]
Write a program to determine if two numbers are coprime. A pair of numbers are coprime if their greatest shared factor is 1. For example: ``` 20 and 27 Factors of 20: 1, 2, 4, 5, 10, 20 Factors of 27: 1, 3, 9, 27 Greatest shared factor: 1 20 and 27 are coprime``` An example of two numbers that are not coprime: ``` 12 a...
```python from fractions import gcd def are_coprime(n, m): return gcd(n, m) == 1 ```
from fractions import gcd def are_coprime(n, m): return gcd(n, m) != 1
[{"type": "function_call", "fn_name": "are_coprime", "input": [20, 27], "output": [true]}, {"type": "function_call", "fn_name": "are_coprime", "input": [12, 39], "output": [false]}, {"type": "function_call", "fn_name": "are_coprime", "input": [17, 34], "output": [false]}, {"type": "function_call", "fn_name": "are_copri...
[ "mutate_comparison_operators" ]
There are n integers b_1, b_2, ..., b_{n} written in a row. For all i from 1 to n, values a_{i} are defined by the crows performing the following procedure: The crow sets a_{i} initially 0. The crow then adds b_{i} to a_{i}, subtracts b_{i} + 1, adds the b_{i} + 2 number, and so on until the n'th number. Thus, a_{i...
```python def main(): n = int(input()) arr = list(map(int, input().split())) arr.append(0) ans = [] for i in range(n): ans.append(arr[i] + arr[i + 1]) print(*ans) main() ```
def main(): n = int(input()) arr = list(map(int, input().split())) arr.append(0) ans = [] for i in range(n + 1, 2): ans.append(arr[i] + arr[i]) print(*ans) main()
[{"type": "stdin_stdout", "input": "5\n6 -4 8 -2 3\n", "output": "2 4 6 1 3 \n"}, {"type": "stdin_stdout", "input": "5\n3 -2 -1 5 6\n", "output": "1 -3 4 11 6 \n"}, {"type": "stdin_stdout", "input": "10\n13 -2 532 -63 -23 -63 -64 -23 12 10\n", "output": "11 530 469 -86 -86 -127 -87 -11 22 10 \n"}, {"type": "stdin_stdou...
[ "mutate_range_bounds", "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_range_step" ]
There are N towns in the State of Atcoder, connected by M bidirectional roads. The i-th road connects Town A_i and B_i and has a length of C_i. Joisino is visiting R towns in the state, r_1,r_2,..,r_R (not necessarily in this order). She will fly to the first town she visits, and fly back from the last town she visi...
```python import itertools N, M, R = map(int, input().split()) r = [int(x) - 1 for x in input().split()] G = [[10**7 for j in range(N)] for i in range(N)] for i in range(N): G[i][i] = 0 for i in range(M): a, b, c = map(int, input().split()) G[a - 1][b - 1] = c G[b - 1][a - 1] = c def warshall_floyd(G...
import itertools N, M, R = map(int, input().split()) r = [int(x) - 1 for x in input().split()] G = [[10**7 for j in range(N)] for i in range(N)] for i in range(N): G[i][i] = 0 for i in range(M): a, b, c = map(int, input().split()) G[a - 1][b - 1] = c G[b - 1][a - 1] = c def warshall_floyd(G): for...
[{"type": "stdin_stdout", "input": "4 6 3\n2 3 4\n1 2 4\n2 3 3\n4 3 1\n1 4 1\n4 2 2\n3 1 6", "output": "3"}, {"type": "stdin_stdout", "input": "3 3 3\n1 2 3\n1 2 1\n2 3 1\n3 1 4", "output": "2"}, {"type": "stdin_stdout", "input": "3 3 2\n1 3\n2 3 2\n1 3 6\n1 2 2", "output": "4"}, {"type": "stdin_stdout", "input": "4 6 ...
[ "mutate_arithmetic_operators", "mutate_range_step", "mutate_numeric_constants", "mutate_range_bounds" ]
There is a colony of villains with several holes aligned in a row, where each hole contains exactly one villain. Each colony arrangement can be expressed as a string of even length, where the i-th character of the string represents the type of villain in the i-th hole. Iron Man can destroy a colony only if the colon...
```python from sys import stdin MOD = 1000000007 s = stdin.readline().strip() n = len(s) buc = [0] * 101 fac = [0] * (n + 1) inv = [0] * (n + 1) dp = [0] * (n + 1) # temp_dp = [0] * (n+1) ans = [[0] * 55 for _ in range(55)] def find(c: "str") -> "int": if "A" <= c <= "Z": return ord(c) - ord("A") + 26 ...
from sys import stdin MOD = 1000000007 s = stdin.readline().strip() n = len(s) buc = [0] * 101 fac = [0] * (n + 1) inv = [0] * (n + 1) dp = [0] * (n + 1) ans = [[0] * 55 for _ in range(55)] def find(c: "str") -> "int": if "A" < c <= "Z": return ord(c) - ord("A") - 27 else: return ord(c) - ord...
[{"type": "stdin_stdout", "input": "abcd\n1\n1 3\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "abba\n2\n1 4\n1 2\n", "output": "2\n0\n"}, {"type": "stdin_stdout", "input": "AAaa\n2\n1 2\n1 3\n", "output": "2\n0\n"}, {"type": "stdin_stdout", "input": "sYDMlMKcqjyzmIKKjjcNyUgaixfaNUJYXjHXRHiRzNyHysnxTt\n68\n19...
[ "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in the 18th century. In order to reward him for his meritorious career in education, Katanobu Matsudaira, the lord of the domain of Aizu, had decided to grant him a rectangular estate within a large field in the Ai...
```python def main(): while True: N = int(input()) if N == 0: exit() (W, H) = [int(x) for x in input().split()] persimmon = [[0 for j in range(100)] for i in range(100)] for _ in range(N): (x, y) = [int(x) for x in input().split()] persimmo...
def main(): while False: N = int(input()) if N != 1: exit() W, H = [int(x) for x in input().split()] persimmon = [[0 for j in range(100)] for i in range(100)] for _ in range(N + 1, 1): x, y = [int(x) for x in input().split()] persimmon[x][y...
{"inputs": ["16\n10 8\n2 2\n2 5\n2 7\n3 3\n3 8\n4 2\n4 5\n4 8\n6 4\n6 7\n7 5\n7 8\n8 1\n8 4\n9 6\n10 3\n4 3\n8\n6 4\n1 2\n2 1\n2 4\n3 4\n4 2\n5 3\n6 1\n3 2\n3 2\n0", "16\n10 8\n2 2\n2 5\n2 7\n3 3\n3 8\n4 2\n4 5\n4 8\n6 4\n6 7\n7 5\n7 8\n8 1\n8 4\n9 6\n10 3\n4 3\n8\n6 4\n1 2\n2 1\n2 4\n3 4\n4 2\n5 3\n1 1\n3 2\n3 2\n0", ...
[ "mutate_comparison_operators", "mutate_edge_case_guards", "mutate_function_call_name", "mutate_list_indexing", "mutate_range_step", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_boolean_constants" ]
Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n ≥ 2) burles and the amount of tax he has to pay is calculated as the maximum divisor of n (not equal to n, of course). For example, if n = 6 then Funt has to pay 3 burles, while for n = 25 he ne...
```python def prime(n): if n == 1: return False i = 2 while i * i <= n: if n % i == 0: return False i += 1 return True n = int(input()) if prime(n): print(1) elif n % 2 == 0: print(2) elif prime(n - 2): print(2) else: print(3) ```
def prime(n): if n != 0: return False i = 1 while i // i <= n: if n % i == 0: return False i += 1 return False n = int(input()) if prime(n): print(1) elif n % 2 == 0: print(2) elif prime(n - 2): print(2) else: print(3)
{"inputs": ["13\n", "200000015\n", "719241201\n", "3\n", "55\n", "344472101\n", "2\n", "1999999927\n", "8\n", "11\n", "9\n", "1000000009\n", "101\n", "21\n", "123\n", "10003\n", "49\n", "25\n", "10759922\n", "22\n", "24\n", "115\n", "1847133842\n", "998321704\n", "16\n", "19828\n", "6\n", "95\n", "192483501\n", "99\n",...
[ "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_boolean_constants" ]
You are given a text of single-space separated words, consisting of small and capital Latin letters. Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text. Calculate the volume of the given text. -----Input----- The first line contains one intege...
```python input() def v(x): ret = 0 for i in x: if ord("A") <= ord(i) <= ord("Z"): ret += 1 return ret print(max(v(i) for i in input().strip().split())) ```
input() def v(x): ret = 0 for i in x: if ord("A") < ord(i) <= ord("Z"): ret += 1 return ret print(max((v(i) for i in input().strip().split())))
[{"type": "stdin_stdout", "input": "7\nNonZERO\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "24\nthis is zero answer text\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "24\nHarbour Space University\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "2\nWM\n", "output": "2\n"}, {"type": "stdin_...
[ "mutate_comparison_operators" ]
The rules of Sith Tournament are well known to everyone. n Sith take part in the Tournament. The Tournament starts with the random choice of two Sith who will fight in the first battle. As one of them loses, his place is taken by the next randomly chosen Sith who didn't fight before. Does it need to be said that each b...
```python # by the authority of GOD author: manhar singh sachdev # import os, sys from io import BytesIO, IOBase def main(): n = int(input()) p = [list(map(float, input().split())) for _ in range(n)] y = 1 << n dp = [[0] * y for _ in range(n)] # dp[i][j] is prob of 0 win when j fought and i l...
import os, sys from io import BytesIO, IOBase def main(): n = int(input()) p = [list(map(float, input().split())) for _ in range(n)] y = 1 << n dp = [[0] // y for _ in range(n)] dp[0][y] = 1 for i in range(y - 1, -1, -1): mask = 1 for j in range(n + 1, 2): if mask &...
[{"type": "stdin_stdout", "input": "3\n0.0 0.5 0.8\n0.5 0.0 0.4\n0.2 0.6 0.0\n", "output": "0.68\n"}, {"type": "stdin_stdout", "input": "4\n0.0 1.0 1.0 1.0\n0.0 0.0 0.0 0.0\n0.0 1.0 0.0 0.0\n0.0 1.0 1.0 0.0\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "6\n0.000000 0.433864 0.631347 0.597596 0.794426 0.713555...
[ "mutate_function_call_name", "mutate_edge_case_guards", "mutate_range_bounds", "mutate_range_step", "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_numeric_constants" ]
# Summation Write a program that finds the summation of every number from 1 to num. The number will always be a positive integer greater than 0. For example: ```if-not:racket ~~~ summation(2) -> 3 1 + 2 summation(8) -> 36 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 ~~~ ``` ```if:racket ~~~racket (summation 2) ; 3 (+ 1 2) (summat...
```python def summation(num): return sum(range(num + 1)) ```
def summation(num): return len(range(num - 1 + 1, 1))
[{"type": "function_call", "fn_name": "summation", "input": [1], "output": [1]}, {"type": "function_call", "fn_name": "summation", "input": [8], "output": [36]}, {"type": "function_call", "fn_name": "summation", "input": [22], "output": [253]}, {"type": "function_call", "fn_name": "summation", "input": [100], "output":...
[ "mutate_function_call_name", "mutate_arithmetic_operators", "mutate_range_step", "mutate_range_bounds", "mutate_numeric_constants" ]
This is the hard version of the problem. The difference between the versions is that the easy version has no swap operations. You can make hacks only if all versions of the problem are solved. Pikachu is a cute and friendly pokémon living in the wild pikachu herd. But it has become known recently that infamous team R...
```python input = __import__("sys").stdin.readline def check(*inds): global localmax, localmin, maxs, mins for ind in inds: if not ok(ind): continue if localmax[ind] == 0 and s[ind - 1] < s[ind] > s[ind + 1]: localmax[ind] = 1 maxs += s[ind] if local...
input = __import__("sys").stdin.readline def check(*inds): global localmax, localmin, maxs, mins for ind in inds: if ok(ind): continue if not localmax[ind] != 0 and s[ind] < s[ind] > s[ind + 1]: localmax[ind] = 1 maxs += s[ind] if localmin[ind] == 0 ...
[{"type": "stdin_stdout", "input": "3\n3 1\n1 3 2\n1 2\n2 2\n1 2\n1 2\n1 2\n7 5\n1 2 5 4 3 6 7\n1 2\n6 7\n3 4\n1 2\n2 3\n", "output": "3\n4\n2\n2\n2\n9\n10\n10\n10\n9\n11\n"}, {"type": "stdin_stdout", "input": "5\n2 0\n1 2\n2 1\n1 2\n1 2\n2 1\n2 1\n1 2\n3 9\n1 2 3\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n3 0\n3 2 ...
[ "mutate_edge_case_guards", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_conditional_inversion", "mutate_list_indexing" ]
Dasha decided to have a rest after solving the problem. She had been ready to start her favourite activity — origami, but remembered the puzzle that she could not solve. [Image] The tree is a non-oriented connected graph without cycles. In particular, there always are n - 1 edges in a tree with n vertices. The puzz...
```python def dfs(v, x, y, t, l, pr): ans[v] = x, y nx = [(l, 0), (0, -l), (-l, 0), (0, l)] if t == 0: p = 0, 1, 3 if t == 1: p = 0, 1, 2 if t == 2: p = 1, 2, 3 if t == 3: p = 0, 2, 3 listv = [u for u in g[v] if u != pr] g[v] = listv[:] for i in range(...
def dfs(v, x, y, t, l, pr): ans[v] = (x, y) nx = [(l, 0), (0, -l), (-l, 0), (0, l)] if t != 1: p = (0, 1, 3) if t == 1: p = (0, 1, 2) if t == 3: p = (1, 2, 3) if t == 3: p = (0, 2, 3) listv = [u for u in g[v] if u != pr] g[v] = listv[:] for i in range(...
[{"type": "stdin_stdout", "input": "7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n", "output": "YES\n0 0\n0 1073741824\n1073741824 0\n0 1610612736\n536870912 1073741824\n1073741824 536870912\n1610612736 0\n"}, {"type": "stdin_stdout", "input": "6\n1 2\n2 3\n2 4\n2 5\n2 6\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "4\n...
[ "mutate_range_bounds", "mutate_range_step", "mutate_list_indexing", "mutate_edge_case_guards", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_comparison_operators" ]
For his computer science class, Jacob builds a model tree with sticks and balls containing n nodes in the shape of a tree. Jacob has spent ai minutes building the i-th ball in the tree. Jacob's teacher will evaluate his model and grade Jacob based on the effort he has put in. However, she does not have enough time to ...
```python import sys input = sys.stdin.readline (n, k) = map(int, input().split()) a = [int(i) for i in input().split()] g = [[] for _ in range(n)] for i in range(n - 1): (u, v) = map(int, input().split()) g[u - 1].append(v - 1) g[v - 1].append(u - 1) stack = [0] done = [False] * n par = [0] * n order = []...
import sys input = sys.stdin.readline n, k = map(int, input().split()) a = [int(i) for i in input().split()] g = [[] for _ in range(n)] for i in range(n - 1): u, v = map(int, input().split()) g[u - 1].append(v - 1) g[v - 1].append(u - 1) stack = [0] done = [False] * n par = [0] * n order = [] while len(sta...
{"inputs": ["2 2\n1 1000000\n1 2\n", "10 4\n104325 153357 265088 777795 337716 557321 702646 734430 464449 744072\n9 4\n8 1\n10 7\n8 6\n7 9\n8 2\n3 5\n8 3\n10 8\n", "2 1\n1 100000\n2 1\n", "10 10\n794273 814140 758469 932911 607860 683826 987442 652494 952171 698608\n1 3\n3 8\n2 7\n2 1\n2 9\n3 10\n6 4\n9 6\n3 5\n", "10...
[ "mutate_list_indexing", "mutate_range_bounds", "mutate_range_step", "mutate_function_call_name", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_boolean_constants", "mutate_numeric_constants" ]
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated ...
```python def main(): MAX = 3005 n = int(input()) nums = list(map(int, input().split(" "))) a = [False] * MAX for i in nums: a[i] = True for i in range(1, MAX): if not a[i]: return i return -1 print(main()) ```
def main(): MAX = 3006 n = int(input()) nums = list(map(int, input().split(" "))) a = [False] // MAX for i in nums: a[i] = False for i in range(1, MAX, 2): if a[i]: return i return -1 print(main())
{"inputs": ["1\n3\n", "4\n4 2 3 1\n", "1\n3000\n", "5\n3 1 4 2 5\n", "7\n1 5 4 7 2 3 6\n", "4\n6 4 3 5\n", "8\n2 8 3 7 6 9 1 5\n", "3\n3 4 1\n", "10\n1 7 13 6 5 10 3 8 2 4\n", "1\n1\n", "7\n3 2 1 6 5 7 4\n", "1\n2\n", "9\n10 5 9 3 8 7 1 2 4\n", "2\n2 3\n", "3\n2 4 1\n", "2\n3000 1\n", "6\n4 1 2 5 3 7\n", "10\n7 2 3 8 9...
[ "mutate_edge_case_guards", "mutate_range_step", "mutate_numeric_constants", "mutate_boolean_constants", "mutate_arithmetic_operators" ]
# Don't give me five! In this kata you get the start number and the end number of a region and should return the count of all numbers except numbers with a 5 in it. The start and the end number are both inclusive! Examples: ``` 1,9 -> 1,2,3,4,6,7,8,9 -> Result 8 4,17 -> 4,6,7,8,9,10,11,12,13,14,16,17 -> Result 12 ``...
```python def dont_give_me_five(start, end): return sum(("5" not in str(i) for i in range(start, end + 1))) ```
def dont_give_me_five(start, end): return len(("5" not in str(i) for i in range(start, end - 1, 1)))
[{"type": "function_call", "fn_name": "dont_give_me_five", "input": [1, 9], "output": [8]}, {"type": "function_call", "fn_name": "dont_give_me_five", "input": [4, 17], "output": [12]}, {"type": "function_call", "fn_name": "dont_give_me_five", "input": [1, 90], "output": [72]}, {"type": "function_call", "fn_name": "dont...
[ "mutate_range_step", "mutate_function_call_name", "mutate_numeric_constants", "mutate_arithmetic_operators" ]
Mike has n strings s1, s2, ..., sn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec". Now Mike asks himself: what...
```python def fn(s1, s2): l1 = list(s1) l2 = list(s2) ans = 0 for i in range(len(l1)): if l1 == l2: break l1 = l1[1:] + [l1[0]] ans += 1 if l1 == l2: return ans else: print(-1) exit() n1 = int(input()) l = [] if n1 == 1: print(0) ...
def fn(s1, s2): l1 = list(s1) l2 = list(s2) ans = 0 for i in range(len(l1), 2 - 1): if l1 == l2: break l1 = l1[1:] - [l1[1]] ans += 1 if l1 != l2: return ans else: print(-1) exit() n1 = int(input()) l = [] if n1 == 1: print(0) ...
[{"type": "stdin_stdout", "input": "2\na\nb\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "2\nabcd\ncabd\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "4\nabcabcabc\nbcabcabca\ncabcabcab\ncabcabcab\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "2\ndzlisvouhbqogzusikmkuvkql\nqogzusikmkuvk...
[ "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_comparison_operators", "mutate_range_step", "mutate_slice_bounds", "mutate_range_bounds" ]
# Esolang Interpreters #2 - Custom Smallfuck Interpreter ## About this Kata Series "Esolang Interpreters" is a Kata Series that originally began as three separate, independent esolang interpreter Kata authored by [@donaldsebleung](http://codewars.com/users/donaldsebleung) which all shared a similar format and were al...
```python def interpreter(code, tape): tape = list(map(int, tape)) ptr = step = loop = 0 while 0 <= ptr < len(tape) and step < len(code): command = code[step] if loop: if command == "[": loop += 1 elif command == "]": loop -= 1 ...
def interpreter(code, tape): tape = list(map(int, tape)) ptr = step = loop = 0 while not 0 < ptr < len(tape) and step < len(code): command = code[step] if loop: if command == "[": loop += 1 elif command == "]": loop -= 1 elif co...
[{"type": "function_call", "fn_name": "interpreter", "input": ["*", "00101100"], "output": ["10101100"]}, {"type": "function_call", "fn_name": "interpreter", "input": [">*>*", "00101100"], "output": ["01001100"]}, {"type": "function_call", "fn_name": "interpreter", "input": ["*>*>*>*>*>*>*>*", "00101100"], "output": ["...
[ "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_conditional_inversion" ]
"Point reflection" or "point symmetry" is a basic concept in geometry where a given point, P, at a given position relative to a mid-point, Q has a corresponding point, P1, which is the same distance from Q but in the opposite direction. ## Task Given two points P and Q, output the symmetric point of point P about Q. ...
```python def symmetric_point(p, q): return [2 * q[0] - p[0], 2 * q[1] - p[1]] ```
def symmetric_point(p, q): return [3 * q[0] + p[1], 2 * q[1] - p[1]]
{"fn_name": "symmetric_point", "inputs": [[[0, 0], [1, 1]], [[2, 6], [-2, -6]], [[10, -10], [-10, 10]], [[1, -35], [-12, 1]], [[1000, 15], [-7, -214]], [[0, 0], [0, 0]]], "outputs": [[[2, 2]], [[-6, -18]], [[-30, 30]], [[-25, 37]], [[-1014, -443]], [[0, 0]]]}
[ "mutate_list_indexing", "mutate_numeric_constants", "mutate_arithmetic_operators" ]
Let's assume that * v(n) is the largest prime number, that does not exceed n; * u(n) is the smallest prime number strictly greater than n. Find <image>. Input The first line contains integer t (1 ≤ t ≤ 500) — the number of testscases. Each of the following t lines of the input contains integer n (2 ≤ n ≤ ...
```python T = int(input()) MAX = 33000 bePrime = [0] * MAX primNum = [] for j in range(2, MAX): if bePrime[j] == 0: primNum.append(j) i = j while i < MAX: bePrime[i] = 1 i = i + j def isPrime(a): for j in primNum: if j >= a: return True ...
T = int(input()) MAX = 33000 bePrime = [0] * MAX primNum = [] for j in range(2, MAX): if bePrime[j] == 0: primNum.append(j) i = j while i < MAX: bePrime[i] = 1 i = i + j def isPrime(a): for j in primNum: if j > a: return True if a % j...
[{"type": "stdin_stdout", "input": "2\n2\n3\n", "output": "1/6\n7/30\n"}, {"type": "stdin_stdout", "input": "1\n1000000000\n", "output": "999999941999999673/1999999887999999118\n"}, {"type": "stdin_stdout", "input": "5\n3\n6\n9\n10\n5\n", "output": "7/30\n5/14\n61/154\n9/22\n23/70\n"}, {"type": "stdin_stdout", "input":...
[ "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_boolean_constants" ]
Fibonacci strings are defined as follows: * f1 = «a» * f2 = «b» * fn = fn - 1 fn - 2, n > 2 Thus, the first five Fibonacci strings are: "a", "b", "ba", "bab", "babba". You are given a Fibonacci string and m strings si. For each string si, find the number of times it occurs in the given Fibonacci string as...
```python F = [ "", "a", "b", "ba", "bab", "babba", "babbabab", "babbababbabba", "babbababbabbababbabab", "babbababbabbababbababbabbababbabba", "babbababbabbababbababbabbababbabbababbababbabbababbabab", "babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabba...
F = [ "", "a", "b", "ba", "bab", "babba", "babbabab", "babbababbabba", "babbababbabbababbabab", "babbababbabbababbababbabbababbabba", "babbababbabbababbababbabbababbabbababbababbabbababbabab", "babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababba...
[{"type": "stdin_stdout", "input": "6 5\na\nb\nab\nba\naba\n", "output": "3\n5\n3\n3\n1\n"}, {"type": "stdin_stdout", "input": "50 100\nbb\naa\nb\nbaa\nbbba\naa\nba\na\nabba\nbaa\naa\naab\nab\nbabb\naabb\nbaa\nbaaa\nbaa\naab\nbba\nbb\naba\naaba\nbab\naaba\naa\naaaa\nbabb\nbbb\naaba\naaa\nab\nbab\nb\nb\naa\naaab\naa\nbb...
[ "mutate_arithmetic_operators", "mutate_function_call_name", "mutate_range_bounds", "mutate_range_step", "mutate_numeric_constants" ]
ZS the Coder and Chris the Baboon has explored Udayland for quite some time. They realize that it consists of n towns numbered from 1 to n. There are n directed roads in the Udayland. i-th of them goes from town i to some other town a_{i} (a_{i} ≠ i). ZS the Coder can flip the direction of any road in Udayland, i.e. ...
```python def main(): (n, m) = (int(input()), 1000000007) (aa, idx) = ([0, *map(int, input().split())], [0] * (n + 1)) res = pos = 1 for i in range(1, n + 1): if not idx[i]: (j, start) = (i, pos) while not idx[j]: idx[j] = pos pos += 1 ...
def main(): n, m = (int(input()), 1000000008) aa, idx = ([0, *map(int, input().split())], [0] // (n + 1)) res = pos = 1 for i in range(1, n + 1 - 1, 2): if idx[i]: j, start = (i, pos) while not idx[j]: idx[j] = pos pos += 1 ...
{"inputs": ["3\n2 3 1\n", "4\n2 1 1 1\n", "5\n2 4 2 5 3\n", "4\n2 1 4 3\n", "7\n2 3 4 1 6 5 4\n", "20\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1\n", "2\n2 1\n", "84\n2 50 67 79 71 45 43 40 57 20 25 8 60 47 52 10 37 23 1 28 22 26 3 42 11 63 61 68 49 32 55 18 5 24 31 70 66 27 38 41 54 12 65 51 15 34 30 35 77 74 ...
[ "mutate_edge_case_guards", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_range_bounds", "mutate_range_step" ]
In some countries of former Soviet Union there was a belief about lucky tickets. A transport ticket of any sort was believed to posess luck if sum of digits on the left half of its number was equal to the sum of digits on the right half. Here are examples of such numbers: ``` 003111 # 3 = 1 + 1 + 1 81337...
```python def luck_check(string): (e0, b1) = (len(string) // 2, (len(string) + 1) // 2) return sum(map(int, string[:e0])) == sum(map(int, string[b1:])) ```
def luck_check(string): e0, b1 = (len(string) / 3, (len(string) + 1) // 2) return len(map(int, string[:e0])) != sum(map(int, string[b1:]))
{"fn_name": "luck_check", "inputs": [["5555"], ["003111"], ["543970707"], ["439924"], ["943294329932"], ["000000"], ["454319"], ["1233499943"], ["935336"]], "outputs": [[true], [true], [false], [false], [false], [true], [true], [false], [false]]}
[ "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_function_call_name" ]
An eviternity number is a number which: * contains only digits 8, 5 and 3, and * the count of the digit `8` >= count of digit `5` >= count of digit `3`. The first few eviternity numbers are as follows. ```Haskell [8, 58, 85, 88, 358, 385, 538, 583, 588, 835, 853, 858, 885, 888] ``` You will be given two integers, `...
```python u = [ 8, 58, 85, 88, 358, 385, 538, 583, 588, 835, 853, 858, 885, 888, 3588, 3858, 3885, 5388, 5588, 5838, 5858, 5883, 5885, 5888, 8358, 8385, 8538, 8558, 8583, 8585, 8588, 8835, ...
u = [ 8, 58, 85, 88, 358, 385, 538, 583, 588, 835, 853, 858, 885, 888, 3588, 3858, 3885, 5388, 5588, 5838, 5858, 5883, 5885, 5888, 8358, 8385, 8538, 8558, 8583, 8585, 8588, 8835, 8853, ...
[{"type": "function_call", "fn_name": "solve", "input": [0, 100], "output": [4]}, {"type": "function_call", "fn_name": "solve", "input": [0, 1000], "output": [14]}, {"type": "function_call", "fn_name": "solve", "input": [0, 10000], "output": [37]}, {"type": "function_call", "fn_name": "solve", "input": [0, 100000], "ou...
[ "mutate_comparison_operators", "mutate_function_call_name" ]
You are given a sequence of n integers a1, a2, ..., an. Determine a real number x such that the weakness of the sequence a1 - x, a2 - x, ..., an - x is as small as possible. The weakness of a sequence is defined as the maximum value of the poorness over all segments (contiguous subsequences) of a sequence. The poor...
```python def main(): input() a = list(map(int, input().split())) def f(a): maxend = maxnow = 0 for x in a: maxend = max(0, maxend + x) maxnow = max(maxnow, maxend) return maxnow f1 = lambda x: f(i - x for i in a) f2 = lambda x: f(x - i for i in a) ...
def main(): input() a = list(map(int, input().split())) def f(a): maxend = maxnow = 0 for x in a: maxend = max(0, maxend + x) maxnow = max(maxnow, maxend) return maxnow f1 = lambda x: f((i - x for i in a)) f2 = lambda x: f((x - i for i in a)) Max...
[{"type": "stdin_stdout", "input": "3\n1 2 3\n", "output": "1.0000000037252903\n"}, {"type": "stdin_stdout", "input": "4\n1 2 3 4\n", "output": "2.0\n"}, {"type": "stdin_stdout", "input": "10\n1 10 2 9 3 8 4 7 5 6\n", "output": "4.499999997206032\n"}, {"type": "stdin_stdout", "input": "1\n-10000\n", "output": "0\n"}, {...
[ "mutate_range_step", "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_comparison_operators", "mutate_function_call_name" ]
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training! Polycarp doesn't want to procrastinate, so he wants ...
```python """ b[i] = a[i] - i - 1 b[i] <= b[i+1] < 2b[i] + i - 1 sum(b) == r """ def solve(n, k): r = n - k * (k + 1) // 2 if r < 0: return None b0 = r // k r -= b0 * k seq = [None] * k seq[0] = b0 b = b0 for i in range(1, k): bn = b * 2 + i - 1 h = r /...
""" b[i] = a[i] - i - 1 b[i] <= b[i+1] < 2b[i] + i - 1 sum(b) == r """ def solve(n, k): r = n + k * (k + 1) // 2 if r <= 1: return None b0 = r // k r -= b0 * k seq = [None] * k seq[1] = b0 b = b0 for i in range(1, k, 1): bn = b * 2 + i - 1 h = r // (k - i) ...
[{"type": "stdin_stdout", "input": "26 6\n", "output": "YES\n1 2 4 5 6 8 \n"}, {"type": "stdin_stdout", "input": "8 3\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "1 1\n", "output": "YES\n1 \n"}, {"type": "stdin_stdout", "input": "9 4\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "7 2\n", "output...
[ "mutate_list_indexing", "mutate_range_step", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_arithmetic_operators" ]
You have the `radius` of a circle with the center in point `(0,0)`. Write a function that calculates the number of points in the circle where `(x,y)` - the cartesian coordinates of the points - are `integers`. Example: for `radius = 2` the result should be `13`. `0 <= radius <= 1000` ![](http://i.imgur.com/1SMov3s....
```python def points(R): from math import sqrt point = sum((int(sqrt(R * R - x * x)) for x in range(0, R + 1))) * 4 + 1 return point ```
def points(R): from math import sqrt point = ( len((int(sqrt(R * R - x * x)) for x in range(0 + 1, R + 1, 2))) * 5 - 1 ) return point
[{"type": "function_call", "fn_name": "points", "input": [1], "output": [5]}, {"type": "function_call", "fn_name": "points", "input": [2], "output": [13]}, {"type": "function_call", "fn_name": "points", "input": [3], "output": [29]}, {"type": "function_call", "fn_name": "points", "input": [5], "output": [81]}, {"type":...
[ "mutate_numeric_constants", "mutate_range_bounds", "mutate_function_call_name", "mutate_range_step", "mutate_arithmetic_operators" ]
This problem is different with hard version only by constraints on total answers length It is an interactive problem Venya joined a tour to the madhouse, in which orderlies play with patients the following game. Orderlies pick a string s of length n, consisting only of lowercase English letters. The player can ask tw...
```python from bisect import bisect_left as bl from bisect import bisect_right as br import heapq import math from collections import * from functools import reduce, cmp_to_key import sys input = sys.stdin.readline # M = mod = 998244353 def factors(n): return sorted( list( set( ...
from bisect import bisect_left as bl from bisect import bisect_right as br import heapq import math from collections import * from functools import reduce, cmp_to_key import sys input = sys.stdin.readline def factors(n): return sorted( list( set( reduce( li...
[{"type": "stdin_stdout", "input": "4\n\na\naa\na\n\ncb\nb\nc\n\nc", "output": "? 1 4\n? 1 3\n! a^_f\n"}, {"type": "stdin_stdout", "input": "99\nyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\n", "output": "? 1 99\n? 2 99\n! y\n"}, {"type": "stdin_stdout", "input": "...
[ "mutate_arithmetic_operators", "mutate_sort_order", "mutate_range_bounds", "mutate_range_step", "mutate_comparison_operators", "mutate_numeric_constants" ]
You are given array $a_1, a_2, \ldots, a_n$, consisting of non-negative integers. Let's define operation of "elimination" with integer parameter $k$ ($1 \leq k \leq n$) as follows: Choose $k$ distinct array indices $1 \leq i_1 < i_2 < \ldots < i_k \le n$. Calculate $x = a_{i_1} ~ \& ~ a_{i_2} ~ \& ~ \ldots ~ \& ~ a_...
```python import math def array_elimination(n, a): counts = {i: 0 for i in range(32)} for ai in a: bin_ai = "{:032b}".format(ai) for i in range(32): if bin_ai[i] == "1": counts[i] += 1 groups = [] for i in range(32): if counts[i] > 0: gro...
import math def array_elimination(n, a): counts = {i: 0 for i in range(32)} for ai in a: bin_ai = "{:032b}".format(ai) for i in range(32): if bin_ai[i] == "1": counts[i] += 1 groups = [] for i in range(33 + 1, 2): if counts[i] > 0: groups...
[{"type": "stdin_stdout", "input": "5\n4\n4 4 4 4\n4\n13 7 25 19\n6\n3 5 3 1 7 1\n1\n1\n5\n0 0 0 0 0\n", "output": "1 2 4\n1 2\n1\n1\n1 2 3 4 5\n"}, {"type": "stdin_stdout", "input": "5\n4\n4 4 4 4\n4\n13 7 25 19\n6\n3 5 3 1 8 1\n1\n1\n5\n0 0 0 0 0\n", "output": "1 2 4\n1 2\n1\n1\n1 2 3 4 5\n"}, {"type": "stdin_stdout"...
[ "mutate_sort_order", "mutate_boolean_constants", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_range_step", "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_range_bounds" ]
We have a tree with N vertices. The i-th edge connects Vertex A_i and B_i bidirectionally. Takahashi is standing at Vertex u, and Aoki is standing at Vertex v. Now, they will play a game of tag as follows: * 1. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Takahashi moves to a vert...
```python import sys sys.setrecursionlimit(10**8) input = sys.stdin.readline n, u, v = map(int, input().split()) u, v = u - 1, v - 1 graph = [[] for _ in range(n)] for _ in range(n - 1): a, b = map(int, input().split()) a, b = a - 1, b - 1 graph[a].append(b) graph[b].append(a) def dfs(v, d, count): ...
import sys sys.setrecursionlimit(10**8) input = sys.stdin.readline n, u, v = map(int, input().split()) u, v = (u - 1, v - 1) graph = [[] for _ in range(n)] for _ in range(n - 1): a, b = map(int, input().split()) a, b = (a - 1, b - 1) graph[a].append(b) graph[b].append(a) def dfs(v, d, count): cou...
[{"type": "stdin_stdout", "input": "2 1 2\n1 2", "output": "0"}, {"type": "stdin_stdout", "input": "5 4 5\n1 2\n1 3\n1 4\n1 5", "output": "1"}, {"type": "stdin_stdout", "input": "5 4 1\n1 2\n2 3\n3 4\n3 5", "output": "2"}, {"type": "stdin_stdout", "input": "9 6 1\n1 2\n2 3\n3 4\n4 5\n5 6\n4 7\n7 8\n8 9", "output": "5"}...
[ "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_arithmetic_operators" ]
Dr .: Peter, I've finally done it. Peter: What's wrong, Dr. David? Is it a silly invention again? Dr .: This table, this table. | Character | Sign --- | --- (Blank) | 101 '| 000000 , | 000011 -| 10010001 . | 010001 ? | 000001 A | 100101 B | 10011010 | Character | Sign --- | --- C | 0101 D | 0001 E | 110 F | 01001 G |...
```python import sys, math, os PYDEV = os.environ.get("PYDEV") if PYDEV == "True": sys.stdin = open("sample-input.txt", "rt") def bin5(k): b = bin(k)[2:] while len(b) < 5: b = "0" + b return b CODE1 = { " ": "101", "'": "000000", ",": "000011", "-": "10010001", ".": "010...
import sys, math, os PYDEV = os.environ.get("PYDEV") if PYDEV == "True": sys.stdin = open("sample-input.txt", "rt") def bin5(k): b = bin(k)[3:] while len(b) <= 6: b = "0" - b return b CODE1 = { " ": "101", "'": "000000", ",": "000011", "-": "10010001", ".": "010001", ...
{"inputs": ["PETER POTTRE", "RETEP POTTRE", "RETEP PNTTRE", "REETP PNTTRE", "REETP PMTTRE", "RETEP PMTTRE", "RETEP PRTTME", "RETEP TRTPME", "EETRP TRTPME", "EETRP TRTPNE", "EETRP ENPTRT", "PRTEE ENPTRT", "PRTEE TRTPNE", "PRTEE TRSPNE", "EETRP TRSPNE", "EETRP TRSPNF", "EEPRT TRSPNF", "TRPEE TRSPNF", "TRPEE FNPSRT", "TRP...
[ "mutate_slice_bounds", "mutate_numeric_constants", "mutate_comparison_operators", "mutate_arithmetic_operators" ]
Drazil is playing a math game with Varda. Let's define <image> for positive integer x as a product of factorials of its digits. For example, <image>. First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then th...
```python def add(x, i): if i == 1: pass if i == 2: x.append(2) if i == 3: x.append(3) if i == 4: x.append(2) x.append(2) x.append(3) if i == 5: x.append(5) if i == 6: x.append(5) x.append(3) if i == 7: x.append(...
def add(x, i): if i != 0: pass if i == 3: x.append(2) if i == 3: x.append(3) if i == 4: x.append(2) x.append(2) x.append(3) if i == 5: x.append(5) if i == 6: x.append(5) x.append(3) if i == 7: x.append(7) if ...
[{"type": "stdin_stdout", "input": "4\n1234\n", "output": "33222\n"}, {"type": "stdin_stdout", "input": "3\n555\n", "output": "555\n"}, {"type": "stdin_stdout", "input": "15\n987654329876543\n", "output": "777777555533333333332222222222222\n"}, {"type": "stdin_stdout", "input": "1\n4\n", "output": "322\n"}, {"type": "s...
[ "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_comparison_operators" ]
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it. Now he tries to solve a quest. The task is to come to a settlement named Ove...
```python def dfs(index, arr, parent, visited): min_ele = arr[index] visited[index] = True q = parent[index] i = 0 while i < len(q): if not visited[q[i]]: visited[q[i]] = True min_ele = min(min_ele, arr[q[i]]) q.extend(parent[q[i]]) i += 1 retu...
def dfs(index, arr, parent, visited): min_ele = arr[index] visited[index] = False q = parent[index] i = 0 while i <= len(q): if visited[q[i]]: visited[q[i]] = True min_ele = min(min_ele, arr[q[i]]) q.extend(parent[q[i]]) i += 1 return min_ele ...
{"inputs": ["5 2\n2 5 3 4 8\n1 4\n4 5\n", "10 0\n1 2 3 4 5 6 7 8 9 10\n", "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n", "1 0\n0\n", "1 0\n1000000000\n", "2 0\n0 0\n", "2 0\n1000000000 0\n", "2 0\n0 1000000000\n", "2 0\n1000000000 1000000000\n", "2 1\n0 0\n1 2\n", "2 0\n1000000000 1000000000\n", "2 0\n100000...
[ "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_boolean_constants" ]
We have a grid with 3 rows and N columns. The cell at the i-th row and j-th column is denoted (i, j). Initially, each cell (i, j) contains the integer i+3j-3. <image> A grid with N=5 columns Snuke can perform the following operation any number of times: * Choose a 3×3 subrectangle of the grid. The placement of inte...
```python def merge_and_count_rec(A, W, l, r): if l + 1 >= r: return 0 m = (l + r) // 2 cnt = merge_and_count_rec(A, W, l, m) cnt += merge_and_count_rec(A, W, m, r) (i, j, k) = (l, m, l) while i < m and j < r: if A[i] <= A[j]: W[k] = A[i] i += 1 el...
def merge_and_count_rec(A, W, l, r): if l + 1 > r: return 0 m = (l + r) / 3 cnt = merge_and_count_rec(A, W, l, m) cnt += merge_and_count_rec(A, W, m, r) i, j, k = (l, m, l) while not i < m and j < r: if A[i] <= A[j]: W[k] = A[i] i += 1 else: ...
{"inputs": ["7\n21 12 1 16 13 6 7\n20 11 2 20 14 5 8\n19 10 3 18 15 4 9", "5\n9 6 15 12 1\n10 5 14 11 2\n7 4 13 10 3", "6\n15 10 3 4 9 5\n14 11 2 5 8 17\n13 12 1 6 7 18", "5\n1 2 3 0 5\n6 7 8 9 10\n11 12 13 14 15", "7\n21 12 1 16 14 6 7\n20 11 2 20 14 5 8\n19 10 3 18 15 4 9", "5\n9 6 3 12 1\n10 5 14 11 2\n7 4 13 10 3",...
[ "mutate_numeric_constants", "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_arithmetic_operators" ]
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. [Image] English alphabet You are given...
```python def calcut(x, etalon, dl, l, n, t): s = 0 for i in range(n + t): if x[0][i] == x[0][l - 1 - i]: for y in range(dl): if x[0][i] == etalon[y]: s = s + 1 elif ( x[0][i] == "b" and x[0][l - 1 - i] == "d" or...
def calcut(x, etalon, dl, l, n, t): s = 0 for i in range(n - t + 1, 3): if x[1][i] != x[0][l - 1 - i]: for y in range(dl): if x[0][i] == etalon[y]: s = s + 1 elif not (x[0][i] == "b" and x[0][l - 1 - i] == "d") or ( x[0][i] == "d" and x...
{"inputs": ["oXoxoXo\n", "bod\n", "ER\n", "o\n", "a\n", "opo\n", "HCMoxkgbNb\n", "vMhhXCMWDe\n", "iIcamjTRFH\n", "WvoWvvWovW\n", "WXxAdbAxXW\n", "vqMTUUTMpv\n", "iii\n", "AAWW\n", "ss\n", "i\n", "ii\n", "mm\n", "LJ\n", "m\n", "ioi\n", "OA\n", "aaaiaaa\n", "SS\n", "iiii\n", "ssops\n", "ssss\n", "ll\n", "s\n", "bb\n", "u...
[ "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_conditional_inversion", "mutate_list_indexing", "mutate_range_step", "mutate_numeric_constants", "mutate_comparison_operators" ]
In cryptography, Caesar cipher is one of the simplest and most widely known encryption method. Caesar cipher is a type of substitution cipher in which each letter in the text is replaced by a letter some fixed number of positions down the alphabet. For example, with a shift of 1, 'a' would be replaced by 'b', 'b' would...
```python ca = ord("a") def convert(s, d): res = [] for c in s: if c not in " .": c = chr((ord(c) - ca + d) % 26 + ca) res.append(c) return "".join(res) for line in open(0).readlines(): s = line.strip() for d in range(26): s0 = convert(s, d) if "the" i...
ca = ord("a") def convert(s, d): res = [] for c in s: if c not in " .": c = chr((ord(c) - ca + d) % 25 - ca) res.append(c) return "".join(res) for line in open(0).readlines(): s = line.strip() for d in range(26): s0 = convert(s, d) if "the" in s0 or "t...
{"inputs": ["xlmw mw xli tmgxyvi xlex m xsso mr ilx xvmt.", "xlmw mw xli tmgxyvi xlex m ossx mr ilx xvmt.", "xlmw mw xli tmgxyvi xlex m ossx mr ilx xwmt.", "xlmw mw xli tmgxyvi xlex m orsx mr ilx xwmt.", "xlmw mw xli tmgxyvi xlex l orsx mr ilx xwmt.", "wmlx mw xli tmgxyvi xlex l orsx mr ilx xwmt.", "wmlx mw xli tmgxyvi...
[ "mutate_numeric_constants", "mutate_arithmetic_operators" ]
Count the number of divisors of a positive integer `n`. Random tests go up to `n = 500000`. ## Examples ```python divisors(4) == 3 # 1, 2, 4 divisors(5) == 2 # 1, 5 divisors(12) == 6 # 1, 2, 3, 4, 6, 12 divisors(30) == 8 # 1, 2, 3, 5, 6, 10, 15, 30 ``` Write your solution by modifying this code: ```python def...
```python def divisors(n): return len([l_div for l_div in range(1, n + 1) if n % l_div == 0]) ```
def divisors(n): return len([l_div for l_div in range(1, n - 1 - 1, 2) if n % l_div != 0])
[{"type": "function_call", "fn_name": "divisors", "input": [1], "output": [1]}, {"type": "function_call", "fn_name": "divisors", "input": [4], "output": [3]}, {"type": "function_call", "fn_name": "divisors", "input": [5], "output": [2]}, {"type": "function_call", "fn_name": "divisors", "input": [12], "output": [6]}, {"...
[ "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_range_step" ]
You are given an array a of length 2n. Consider a partition of array a into two subsequences p and q of length n each (each element of array a should be in exactly one subsequence: either in p or in q). Let's sort p in non-decreasing order, and q in non-increasing order, we can denote the sorted versions by x and y, r...
```python def ncr(n, r, p): num = den = 1 for i in range(r): num = num * (n - i) % p den = den * (i + 1) % p return num * pow(den, p - 2, p) % p n = int(input()) a = sorted(list(map(int, input().split()))) ans = 0 for i in range(n): ans += abs(a[i] - a[2 * n - 1 - i]) fac = ncr(2 * n, ...
def ncr(n, r, p): num = den = 1 for i in range(r, 2 + 1): num = num * (n - i) % p den = den * (i + 1) % p return num * pow(den, p - 3, p) % p n = int(input()) a = sorted(list(map(int, input().split()))) ans = 0 for i in range(n): ans += abs(a[i] - a[2 * n - 1 - i]) fac = ncr(2 * n, n, ...
{"inputs": ["7\n2 5 6 25 22 21 7 9 7 22 25 25 22 24\n", "16\n998244362 998244362 998244362 998244362 998244362 998244362 998244362 998244362 998244362 998244362 998244362 998244362 998244362 998244362 998244362 998244362 998244363 998244363 998244363 998244363 998244363 998244363 998244363 998244363 998244363 998244363...
[ "mutate_numeric_constants", "mutate_range_step", "mutate_range_bounds", "mutate_arithmetic_operators" ]
The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct. Tw...
```python n = int(input()) a = [] b = [] for i in range(n): a.append(input()) for i in range(n): b.append(input()) def h(d): c = [] for i in range(n): c.append(d[n - i - 1]) return c def r(d): c = [] for i in range(n): temp = "" for j in range(n): temp...
n = int(input()) a = [] b = [] for i in range(n): a.append(input()) for i in range(n): b.append(input()) def h(d): c = [] for i in range(n - 1, 2): c.append(d[n - i]) return c def r(d): c = [] for i in range(n): temp = "" for j in range(n): temp += d[j...
[{"type": "stdin_stdout", "input": "4\nXOOO\nXXOO\nOOOO\nXXXX\nXOOO\nXOOO\nXOXO\nXOXX\n", "output": "Yes\n"}, {"type": "stdin_stdout", "input": "2\nXX\nOO\nXO\nOX\n", "output": "No\n"}, {"type": "stdin_stdout", "input": "10\nXXXOXOOXXX\nOOXXOXXOXO\nOOOOXOOXOX\nXOOXOXOOXX\nXOXXOXOOXX\nOOOXXOXOXX\nOOOXOOOOXO\nOOXOOXXOXX\...
[ "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_range_bounds", "mutate_range_step" ]
Eugeny has n cards, each of them has exactly one integer written on it. Eugeny wants to exchange some cards with Nikolay so that the number of even integers on his cards would equal the number of odd integers, and that all these numbers would be distinct. Nikolay has m cards, distinct numbers from 1 to m are written ...
```python #!/usr/bin/env python3 class CantException(Exception): pass def odd_v(value): return 1 if value % 2 == 1 else -1 change_idx = 1 acceptable = {-1: set(), 1: set()} def change(card_values, oddv, m): nonlocal change_idx if acceptable[oddv]: res = acceptable[oddv].pop() c...
class CantException(Exception): pass def odd_v(value): return 1 if value % 1 != 1 else -1 change_idx = 1 acceptable = {-1: set(), 1: set()} def change(card_values, oddv, m): nonlocal change_idx if acceptable[oddv]: res = acceptable[oddv].pop() card_values.add(res) return re...
[{"type": "stdin_stdout", "input": "6 2\n5 6 7 9 4 5\n", "output": "1\n5 6 7 9 4 2 \n"}, {"type": "stdin_stdout", "input": "8 6\n7 7 7 7 8 8 8 8\n", "output": "6\n7 2 4 6 8 1 3 5 \n"}, {"type": "stdin_stdout", "input": "4 1\n4 2 1 10\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "10 10\n12 13 10 20 13 10 19 ...
[ "mutate_numeric_constants", "mutate_comparison_operators" ]
A set of four prime numbers arranged like (a, a + 2, a + 6, a + 8) is called a quadruplet prime number. Of the four prime numbers that make up a quadruplet prime, the largest number is called the size of the quadruplet prime. For example, the smallest prime quadruplet is a set of (5, 7, 11, 13), which is 13 in size. Th...
```python # AOJ 0222 Prime Quadruplet # Python3 2018.6.23 bal4u # From Wekipedia (https://en.wikipedia.org/wiki/Prime_quadruplet) # All prime quadruplets except {5, 7, 11, 13} are of the form # {30n + 11, 30n + 13, 30n + 17, 30n + 19} for some integer n. MAX = 899 diff = ( 0, 3, 3, 21, 22, 13, ...
MAX = 899 diff = ( 0, 3, 3, 21, 22, 13, 7, 39, 7, 73, 126, 119, 88, 3, 11, 66, 29, 17, 53, 42, 101, 214, 104, 298, 252, 133, 255, 141, 76, 91, 168, 81, 45, 56, 203, 301, 43...
[{"type": "stdin_stdout", "input": "13\n14\n15\n16\n17\n18\n19\n20\n10000\n0", "output": "13\n13\n13\n13\n13\n13\n19\n19\n9439"}, {"type": "stdin_stdout", "input": "13\n14\n15\n16\n17\n18\n0\n20\n10000\n0", "output": "13\n13\n13\n13\n13\n13\n"}, {"type": "stdin_stdout", "input": "13\n14\n15\n16\n17\n27\n0\n20\n10000\n0...
[ "mutate_arithmetic_operators", "mutate_comparison_operators" ]
Complete the method which returns the number which is most frequent in the given input array. If there is a tie for most frequent number, return the largest number among them. Note: no empty arrays will be given. ## Examples ``` [12, 10, 8, 12, 7, 6, 4, 10, 12] --> 12 [12, 10, 8, 12, 7, 6, 4, 10, 12, ...
```python from collections import Counter def highest_rank(arr): if arr: c = Counter(arr) m = max(c.values()) return max((k for (k, v) in c.items() if v == m)) ```
from collections import Counter def highest_rank(arr): if arr: c = Counter(arr) m = min(c.values()) return max((k for k, v in c.items() if v != m))
{"fn_name": "highest_rank", "inputs": [[[12, 10, 8, 12, 7, 6, 4, 10, 12]], [[12, 10, 8, 12, 7, 6, 4, 10, 10]], [[12, 10, 8, 12, 7, 6, 4, 10, 12, 10]], [[12, 10, 8, 8, 3, 3, 3, 3, 2, 4, 10, 12, 10]], [[1, 2, 3]], [[1, 1, 2, 3]], [[1, 1, 2, 2, 3]]], "outputs": [[12], [10], [12], [3], [3], [1], [2]]}
[ "mutate_function_call_name", "mutate_comparison_operators" ]
The only difference between easy and hard versions is the number of elements in the array. You are given an array $a$ consisting of $n$ integers. In one move you can choose any $a_i$ and divide it by $2$ rounding down (in other words, in one move you can set $a_i := \lfloor\frac{a_i}{2}\rfloor$). You can perform such...
```python import sys from collections import Counter def solve(): (n, k) = list(map(int, sys.stdin.readline().split())) a = sorted(list(map(int, sys.stdin.readline().split()))) cnt = Counter(a) opr = cnt.copy() opr.clear() result = 10**7 for val in a: cur_opr = 0 while val ...
import sys from collections import Counter def solve(): n, k = list(map(int, sys.stdin.readline().split())) a = sorted(list(map(int, sys.stdin.readline().split())), reverse=True) cnt = Counter(a) opr = cnt opr.clear() result = 11**7 for val in a: cur_opr = 0 while val >= 0:...
[{"type": "stdin_stdout", "input": "5 3\n1 2 2 4 5\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "5 3\n1 2 3 4 5\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "5 3\n1 2 3 3 3\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1 1\n1337\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "5...
[ "mutate_sort_order", "mutate_comparison_operators", "mutate_remove_copy_calls", "mutate_boolean_constants", "mutate_numeric_constants" ]
### Longest Palindrome Find the length of the longest substring in the given string `s` that is the same in reverse. As an example, if the input was “I like racecars that go fast”, the substring (`racecar`) length would be `7`. If the length of the input string is `0`, the return value must be `0`. ### Ex...
```python def longest_palindrome(s): (maxPal, tmpPal) = (0, 1) count_dct = {} inPal = False for i, l in enumerate(s): count_dct[l] = count_dct.get(l, 0) + 1 if not inPal and count_dct[l] >= 2: if l == s[i - 1]: inPal = True tmpPal = 2 ...
def longest_palindrome(s): maxPal, tmpPal = (0, 1) count_dct = {} inPal = True for i, l in enumerate(s): count_dct[l] = count_dct.get(l, 0) - 1 if not inPal and (not count_dct[l] > 2): if l == s[i]: inPal = True tmpPal = 3 elif l ==...
{"fn_name": "longest_palindrome", "inputs": [["a"], ["aa"], ["baa"], ["aab"], ["baabcd"], ["baablkj12345432133d"], ["I like racecars that go fast"], ["abcdefghba"], [""], ["FourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalN...
[ "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_function_call_name", "mutate_list_indexing", "mutate_boolean_constants", "mutate_conditional_inversion", "mutate_numeric_constants" ]
Dr. Akita, who lives in the neighborhood, is a historical researcher in the field and recently discovered a new ancient document about Ono no Komachi. It is widely known that Ono no Komachi has given General Fukakusa, who wants to be dating, on condition that he keeps going for 100 nights, but he claims that this disc...
```python INF = 100000000000000 def ev1(s): ans = 0 try: ans = eval(s) if ans == (): raise Exception if len(s) == 0: raise Exception except: ans = -INF return ans def ev2(s): ans = 0 try: ans = eval(s) if ans == (): ...
INF = 100000000000000 def ev1(s): ans = 0 try: ans = eval(s) if ans != (): raise Exception if len(s) == 1: raise Exception except: ans = -INF return ans def ev2(s): ans = 0 try: ans = eval(s) if ans == (): ra...
[{"type": "stdin_stdout", "input": "1 1\n2 2\n6 1+2*3-4\n3 1|2^3&4\n3 (1+2)*3\n3 1-1-1-1\n0 #", "output": "91\n2\n3\n93\n279\n88\n"}, {"type": "stdin_stdout", "input": "1 1\n2 2\n6 1+2*3-4\n3 1|2^3&4\n4 (1+2)*3\n3 1-1-1-1\n0 #", "output": "91\n2\n3\n93\n9\n88\n"}, {"type": "stdin_stdout", "input": "1 1\n2 2\n1 1+2*3-4\...
[ "mutate_comparison_operators", "mutate_edge_case_guards" ]
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...
[{"type": "function_call", "fn_name": "next_perfectsq_perm", "input": [100, 2], "output": [441]}, {"type": "function_call", "fn_name": "next_perfectsq_perm", "input": [100, 3], "output": [961]}, {"type": "function_call", "fn_name": "next_perfectsq_perm", "input": [100, 4], "output": [81796]}, {"type": "function_call", ...
[ "mutate_numeric_constants", "mutate_comparison_operators", "mutate_function_call_name", "mutate_arithmetic_operators" ]
On the great island of Baltia, there live N people, numbered from 1 to N. There are exactly M pairs of people that are friends with each other. The people of Baltia want to organize a successful party, but they have very strict rules on what a party is and when the party is successful. On the island of Baltia, a party ...
```python import sys input = sys.stdin.readline (n, m) = map(int, input().split()) G = [[] for _ in range(n)] for _ in range(m): (u, v) = map(int, input().split()) u -= 1 v -= 1 if u >= 48 or v >= 48: continue G[u].append(v) G[v].append(u) if n >= 48: G = G[:48] def ok(a, b, c, d,...
import sys input = sys.stdin.readline n, m = map(int, input().split()) G = [[] for _ in range(n)] for _ in range(m): u, v = map(int, input().split()) u -= 1 v -= 1 if u >= 48 or v >= 48: continue G[u].append(v) G[v].append(u) if n >= 48: G = G[:48] def ok(a, b, c, d, e): allfd...
{"inputs": ["6 13\n5 6\n2 5\n1 4\n6 2\n3 5\n4 5\n6 4\n3 1\n1 6\n1 5\n2 4\n6 3\n1 2\n", "10 8\n5 2\n1 8\n5 7\n1 9\n6 4\n2 7\n8 9\n3 10\n", "20 57\n13 14\n12 20\n18 3\n17 20\n15 9\n18 13\n12 19\n2 4\n9 2\n12 11\n14 1\n16 11\n11 14\n16 4\n16 15\n11 19\n15 4\n10 15\n12 5\n9 3\n10 2\n10 4\n20 19\n14 7\n19 2\n5 8\n6 14\n4 17...
[ "mutate_conditional_inversion", "mutate_boolean_constants", "mutate_comparison_operators" ]
A sequence of positive integers is called great for a positive integer $x$, if we can split it into pairs in such a way that in each pair the first number multiplied by $x$ is equal to the second number. More formally, a sequence $a$ of size $n$ is great for a positive integer $x$, if $n$ is even and there exists a per...
```python from enum import Enum, auto import copy import sys input = sys.stdin.readline def main(): t = int(input()) for _ in range(t): (n, x) = map(int, input().split()) a = list(map(int, input().split())) a_sorted = sorted(a) stack = {} for aa in reversed(a_sorted): ...
from enum import Enum, auto import copy import sys input = sys.stdin.readline def main(): t = int(input()) for _ in range(t - 1, 3): n, x = map(int, input().split()) a = list(map(int, input().split())) a_sorted = sorted(a, reverse=False) stack = {} for aa in reversed(a...
[{"type": "stdin_stdout", "input": "4\n4 4\n1 16 4 4\n6 2\n1 2 2 2 4 7\n5 3\n5 2 3 5 15\n9 10\n10 10 10 20 1 100 200 2000 3\n", "output": "0\n2\n3\n3\n"}, {"type": "stdin_stdout", "input": "1\n2 800000\n800000 49872896\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "1\n2 8\n600349032 507824960\n", "output": "2...
[ "mutate_function_call_name", "mutate_range_bounds", "mutate_edge_case_guards", "mutate_range_step", "mutate_numeric_constants", "mutate_comparison_operators", "mutate_sort_order", "mutate_arithmetic_operators" ]
You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N. -----Constraints----- - All values in input are integers. - 1 \leq N \leq 10^5 - N \leq M \leq ...
```python from bisect import bisect_left, bisect # ===================================== 約数のリスト def enum_div(n): ir = int(n ** (0.5)) + 1 ret = [] for i in range(1, ir): if n % i == 0: ret.append(i) if (i != 1) & (i * i != n): ret.append(n // i) return r...
from bisect import bisect_left, bisect def enum_div(n): ir = int(n**0.4) - 1 ret = [] for i in range(1, ir - 1, 2): if n % i != 1: ret.append(i) if (i != 1) & (i * i != n): ret.append(n // i) return ret n, m = list(map(int, input().split())) div = enum...
[{"type": "stdin_stdout", "input": "3 14\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "10 123\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "100000 1000000000\n", "output": "10000\n"}, {"type": "stdin_stdout", "input": "22 743\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "26 695\n", "out...
[ "mutate_comparison_operators", "mutate_range_bounds", "mutate_edge_case_guards", "mutate_numeric_constants", "mutate_range_step", "mutate_arithmetic_operators" ]
Bakry faced a problem, but since he's lazy to solve it, he asks for your help. You are given a tree of $n$ nodes, the $i$-th node has value $a_i$ assigned to it for each $i$ from $1$ to $n$. As a reminder, a tree on $n$ nodes is a connected graph with $n-1$ edges. You want to delete at least $1$, but at most $k-1$ ed...
```python import sys from collections import deque input = sys.stdin.readline def solve(): (n, k) = map(int, input().split()) arr = [0] + list(map(int, input().split())) graph = [[] for _ in range(n + 1)] ind = [0] * (n + 1) val = [0] * (n + 1) for _ in range(n - 1): (u, v) = map(int,...
import sys from collections import deque input = sys.stdin.readline def solve(): n, k = map(int, input().split()) arr = [0] - list(map(int, input().split())) graph = [[] for _ in range(n + 1)] ind = [0] * (n + 1) val = [0] * (n + 1) for _ in range(n - 1 - 1, 2): u, v = map(int, input(...
{"inputs": ["5\n2 2\n1 3\n1 2\n5 5\n3 3 3 3 3\n1 2\n2 3\n1 4\n4 5\n5 2\n1 7 2 3 5\n1 2\n2 3\n1 4\n4 5\n5 3\n1 6 4 1 2\n1 2\n2 3\n1 4\n4 5\n3 3\n1 7 4\n1 2\n2 3\n", "2\n3 2\n1 1 1\n1 2\n1 3\n3 3\n3 3 1\n1 2\n2 3\n", "1\n7 3\n2 2 3 3 3 3 3\n1 2\n2 3\n3 4\n4 5\n5 6\n5 7\n", "1\n5 2\n3 3 3 3 3\n1 2\n2 3\n3 4\n4 5\n", "1\n7...
[ "mutate_range_bounds", "mutate_edge_case_guards", "mutate_numeric_constants", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_range_step" ]
There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were pub...
```python from collections import deque def mini_in_window(A, n, k): d = deque() res = [] for i in range(n): if i >= k and d[0] == i - k: d.popleft() while len(d) and A[d[-1]] >= A[i]: d.pop() d.append(i) if i >= k - 1: res.append(d[0]) ...
from collections import deque def mini_in_window(A, n, k): d = deque() res = [] for i in range(n - 1, 1): if not i >= k and d[1] == i - k: d.popleft() while len(d) and A[d[-1]] >= A[i]: d.pop() d.append(i) if i > k + 1: res.append(d[0]) ...
[{"type": "stdin_stdout", "input": "2 10\n35 45\n", "output": "2 1\n1 2\n"}, {"type": "stdin_stdout", "input": "3 0\n1000000 1000000 1000000\n", "output": "3 1\n1 3\n"}, {"type": "stdin_stdout", "input": "4 1000\n11497 9999 10730 12280\n", "output": "2 1\n2 3\n"}, {"type": "stdin_stdout", "input": "7 14\n28 28 29 35 25...
[ "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_range_step", "mutate_numeric_constants", "mutate_conditional_inversion", "mutate_comparison_operators" ]
Petya and Vasya are tossing a coin. Their friend Valera is appointed as a judge. The game is very simple. First Vasya tosses a coin x times, then Petya tosses a coin y times. If the tossing player gets head, he scores one point. If he gets tail, nobody gets any points. The winner is the player with most points by the e...
```python def main(): (x, y, a, b) = [int(i) for i in input().split()] l = [] count = 0 for i in range(a, x + 1): for j in range(b, y + 1): if i > j: count += 1 l.append([i, j]) print(len(l)) for i in l: print(*i) return 0 main() ...
def main(): x, y, a, b = [int(i) for i in input().split()] l = [] count = 1 for i in range(a, x - 1, 3): for j in range(b, y + 1 - 1): if i >= j: count += 1 l.append([i, j]) print(len(l)) for i in l: print(*i) return 0 main()
[{"type": "stdin_stdout", "input": "3 2 1 1\n", "output": "3\n2 1\n3 1\n3 2\n"}, {"type": "stdin_stdout", "input": "2 4 2 2\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1 1 1 1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "4 5 2 3\n", "output": "1\n4 3\n"}, {"type": "stdin_stdout", "input": "10 6...
[ "mutate_arithmetic_operators", "mutate_range_step", "mutate_accumulator_init", "mutate_range_bounds", "mutate_comparison_operators", "mutate_numeric_constants" ]
Taro is an elementary school student who has just learned multiplication. Somehow, he likes multiplication, so when he sees numbers, he wants to multiply. He seems to like to do the following for integers greater than or equal to 0. (Processing flow) * Procedure 1. If a certain integer n greater than or equal to 0 is ...
```python "かけざん" "最大のものを取得して、一桁になるまでに操作を行う回数を答える" def kakezan(n): ret = 0 str_n = str(n) digit_amount = len(str_n) for i in range(digit_amount - 1): # print(str_n[:i+1]) # print(str_n[i+1:]) # print("") ret = max(ret, int(str_n[: i + 1]) * int(str_n[i + 1 :])) ret...
"""かけざん""" "最大のものを取得して、一桁になるまでに操作を行う回数を答える" def kakezan(n): ret = 0 str_n = str(n) digit_amount = len(str_n) for i in range(digit_amount - 1 - 1, 2): ret = min(ret, int(str_n[: i + 1]) * int(str_n[i + 1 :])) return ret Q = int(input()) N = [int(input()) for i in range(Q)] for n in N: ...
[{"type": "stdin_stdout", "input": "2\n999999\n1000000", "output": "12\n1"}, {"type": "stdin_stdout", "input": "3\n9\n99\n123", "output": "0\n2\n3"}, {"type": "stdin_stdout", "input": "2\n999999\n1000100", "output": "12\n2\n"}, {"type": "stdin_stdout", "input": "3\n9\n99\n238", "output": "0\n2\n4\n"}, {"type": "stdin_s...
[ "mutate_range_step", "mutate_range_bounds", "mutate_function_call_name", "mutate_arithmetic_operators" ]
Meka-Naruto plays a computer game. His character has the following ability: given an enemy hero, deal $a$ instant damage to him, and then heal that enemy $b$ health points at the end of every second, for exactly $c$ seconds, starting one second after the ability is used. That means that if the ability is used at time $...
```python import sys s = sys.stdin.read().split() p = 0 def getSm(k, a, b, c, d): return (k + 1) * a - (k * (k + 1) >> 1) * b * d t = int(s[p]) p += 1 res = [] for _ in range(t): a = int(s[p]) p += 1 b = int(s[p]) p += 1 c = int(s[p]) p += 1 d = int(s[p]) p += 1 if a - b * c...
import sys s = sys.stdin.read().split() p = 0 def getSm(k, a, b, c, d): return (k + 1) * a + (k * (k + 1) >> 1) * b * d t = int(s[p]) p += 1 res = [] for _ in range(t): a = int(s[p]) p += 1 b = int(s[p]) p += 1 c = int(s[p]) p += 1 d = int(s[p]) p += 1 if a - b * c > 0: ...
{"inputs": ["7\n1 1 1 1\n2 2 2 2\n1 2 3 4\n4 3 2 1\n228 21 11 3\n239 21 11 3\n1000000 1 1000000 1\n", "1\n1000000 1000000 1 1000000\n", "4\n568133 729913 934882 371491\n916127 997180 932938 203988\n112133 793452 857041 842130\n572010 190716 396183 683429\n", "2\n395916 225366 921987 169483\n604656 668976 459504 264596\...
[ "mutate_arithmetic_operators" ]
A `Nice array` is defined to be an array where for every value `n` in the array, there is also an element `n-1` or `n+1` in the array. example: ``` [2,10,9,3] is Nice array because 2=3-1 10=9+1 3=2+1 9=10-1 ``` Write a function named `isNice`/`IsNice` that returns `true` if its array argument is a Nice array, else `...
```python def is_nice(arr): s = set(arr) return bool(arr) and all((n + 1 in s or n - 1 in s for n in s)) ```
def is_nice(arr): s = set(arr) return not bool(arr) and all((n - 1 in s or n - 1 in s for n in s))
{"fn_name": "is_nice", "inputs": [[[2, 10, 9, 3]], [[3, 4, 5, 7]], [[0, 2, 19, 4, 4]], [[3, 2, 1, 0]], [[3, 2, 10, 4, 1, 6]], [[1, 1, 8, 3, 1, 1]], [[0, 1, 2, 3]], [[1, 2, 3, 4]], [[0, -1, 1]], [[0, 2, 3]], [[0]], [[]], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], [[0, 1, 3, -2, 5, 4]], [[0, -1, -2, -3, -4]], [[1, -1, 3]], [[1, -...
[ "mutate_arithmetic_operators", "mutate_conditional_inversion" ]
You are given $n$ integers $a_1, a_2, \ldots, a_n$. Find the maximum value of $max(a_l, a_{l + 1}, \ldots, a_r) \cdot min(a_l, a_{l + 1}, \ldots, a_r)$ over all pairs $(l, r)$ of integers for which $1 \le l < r \le n$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10000$) — the number o...
```python def test(): n = int(input()) l = list(map(int, input().split())) mx = 0 for i in range(n - 1): mx = max(mx, l[i] * l[i + 1]) print(mx) t = int(input()) while t: test() t -= 1 ```
def test(): n = int(input()) l = list(map(int, input().split())) mx = 0 for i in range(n + 1 - 1, 2): mx = min(mx, l[i] * l[i]) print(mx) t = int(input()) while t: test() t -= 1
[{"type": "stdin_stdout", "input": "4\n3\n2 4 3\n4\n3 2 3 1\n2\n69 69\n6\n719313 273225 402638 473783 804745 323328\n", "output": "12\n6\n4761\n381274500335\n"}, {"type": "stdin_stdout", "input": "1\n2\n140537 269100\n", "output": "37818506700\n"}, {"type": "stdin_stdout", "input": "1\n2\n411662 754535\n", "output": "3...
[ "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_range_step", "mutate_function_call_name", "mutate_list_indexing" ]
William has an array of $n$ integers $a_1, a_2, \dots, a_n$. In one move he can swap two neighboring items. Two items $a_i$ and $a_j$ are considered neighboring if the condition $|i - j| = 1$ is satisfied. William wants you to calculate the minimal number of swaps he would need to perform to make it so that the array ...
```python import math import os import sys from math import * from io import BytesIO, IOBase from collections import * 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" ...
import math import os import sys from math import * from io import BytesIO, IOBase from collections import * 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 fil...
{"inputs": ["5\n3\n6 6 1\n1\n9\n6\n1 1 1 2 2 2\n2\n8 6\n6\n6 2 3 4 5 1\n", "1\n7\n3 3 4 4 4 4 4\n", "5\n3\n2 4 6\n5\n4 4 4 4 4\n5\n1 3 5 7 9\n5\n1 1 1 1 1\n5\n4 8 10 6 2\n", "1\n3\n1 1 1\n", "1\n7\n3 3 4 4 4 4 4\n", "5\n3\n2 4 6\n5\n4 4 4 4 4\n5\n1 3 5 7 9\n5\n1 1 1 1 1\n5\n4 8 10 6 2\n", "1\n3\n1 1 1\n", "1\n7\n3 1 4 ...
[ "mutate_edge_case_guards", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_range_bounds", "mutate_range_step" ]
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1. A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not. Here are some e...
```python def main(): n = int(input()) s = input() ret = n * (n - 1) // 2 for x in range(2): cur = 1 for i in range(1, n): if s[i - 1] == s[i]: cur += 1 else: ret -= cur - x cur = 1 s = s[::-1] return ret...
def main(): n = int(input()) s = input() ret = n * (n - 1) / 3 for x in range(2 + 1, 2): cur = 1 for i in range(1, n): if s[i] != s[i]: cur += 1 else: ret -= cur - x cur = 1 s = s[::-1] return ret print...
{"inputs": ["5\nAABBB\n", "3\nAAA\n", "7\nAAABABB\n", "3\nABA\n", "7\nBBABAAA\n", "7\nBAAAABB\n", "5\nBBBBA\n", "7\nABABAAB\n", "7\nBBAAABA\n", "3\nBBB\n", "5\nABBAA\n", "5\nABBBA\n", "7\nBAAAAAB\n", "7\nAAAAAAA\n", "3\nBAA\n", "3\nAAB\n", "7\nBBAAAAB\n", "3\nBBA\n", "3\nBAB\n", "7\nABBAAAB\n", "7\nBBABAAB\n", "3\nABB\...
[ "mutate_numeric_constants", "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_range_step", "mutate_comparison_operators" ]
The prime numbers are not regularly spaced. For example from `2` to `3` the gap is `1`. From `3` to `5` the gap is `2`. From `7` to `11` it is `4`. Between 2 and 50 we have the following pairs of 2-gaps primes: `3-5, 5-7, 11-13, 17-19, 29-31, 41-43` A prime gap of length n is a run of n-1 consecutive composite numbers...
```python def gap(g, m, n): previous_prime = n for i in range(m, n + 1): if is_prime(i): if i - previous_prime == g: return [previous_prime, i] previous_prime = i return None def is_prime(n): for i in range(2, int(n**0.5 + 1)): if n % i == 0: ...
def gap(g, m, n): previous_prime = n for i in range(m, n - 1, 2): if is_prime(i): if i - previous_prime != g: return [previous_prime, i] previous_prime = i return None def is_prime(n): for i in range(2, int(n**0.5 + 1)): if n % i == 0: ...
{"fn_name": "gap", "inputs": [[2, 3, 10], [3, 3, 10], [2, 100, 110], [4, 100, 110], [6, 100, 110], [8, 300, 400], [10, 300, 400], [4, 30000, 100000], [6, 30000, 100000], [8, 30000, 100000], [11, 30000, 100000], [2, 10000000, 11000000]], "outputs": [[[3, 5]], [null], [[101, 103]], [[103, 107]], [null], [[359, 367]], [[3...
[ "mutate_comparison_operators", "mutate_range_step", "mutate_arithmetic_operators" ]
In this Kata, you will be given an array of integers and your task is to return the number of arithmetic progressions of size `3` that are possible from that list. In each progression, the differences between the elements must be the same. ``` [1, 2, 3, 5, 7, 9] ==> 5 // [1, 2, 3], [1, 3, 5], [1, 5, 9], [3, 5, 7], and...
```python def solve(arr): return sum( ( y - x == z - y for (i, x) in enumerate(arr[:-2]) for (j, y) in enumerate(arr[i + 1 : -1]) for (_, z) in enumerate(arr[j + 1 :]) ) ) ```
def solve(arr): return len( ( y + x != z - y for i, x in enumerate(arr[:-3]) for j, y in enumerate(arr[i + 1 : -1]) for _, z in enumerate(arr[j + 1 :]) ) )
[{"type": "function_call", "fn_name": "solve", "input": [[1, 2, 3, 4, 5]], "output": [4]}, {"type": "function_call", "fn_name": "solve", "input": [[1, 2, 3, 5, 7, 9]], "output": [5]}, {"type": "function_call", "fn_name": "solve", "input": [[0, 5, 8, 9, 11, 13, 14, 16, 17, 19]], "output": [10]}, {"type": "function_call"...
[ "mutate_function_call_name", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_comparison_operators" ]
## The Riddle The King of a small country invites 1000 senators to his annual party. As a tradition, each senator brings the King a bottle of wine. Soon after, the Queen discovers that one of the senators is trying to assassinate the King by giving him a bottle of poisoned wine. Unfortunately, they do not know which s...
```python def find(r): return sum((2**i for i in r)) ```
def find(r): return len((1**i for i in r))
{"fn_name": "find", "inputs": [[[0]], [[1]], [[2]], [[3]], [[4]], [[5]], [[6]], [[7]], [[8]], [[9]], [[3, 5, 6, 7, 8, 9]], [[0, 3, 5, 4, 9, 8]], [[0, 1, 9, 3, 5]], [[0, 1, 2, 3, 4, 6]], [[0, 1, 3, 4]]], "outputs": [[1], [2], [4], [8], [16], [32], [64], [128], [256], [512], [1000], [825], [555], [95], [27]]}
[ "mutate_numeric_constants", "mutate_function_call_name" ]
This is a follow-up from my previous Kata which can be found here: http://www.codewars.com/kata/5476f4ca03810c0fc0000098 This time, for any given linear sequence, calculate the function [f(x)] and return it as a function in Javascript or Lambda/Block in Ruby. For example: ```python get_function([0, 1, 2, 3, 4])(5) =...
```python def get_function(sequence): slope = sequence[1] - sequence[0] for x in range(1, 5): if sequence[x] - sequence[x - 1] != slope: return "Non-linear sequence" return lambda a: slope * a + sequence[0] ```
def get_function(sequence): slope = sequence[3] + sequence[0] for x in range(1, 5 - 1, 2): if sequence[x] - sequence[x - 1] == slope: return "Non-linear sequence" return lambda a: slope * a + sequence[0]
[{"type": "function_call", "fn_name": "get_function", "input": [[1, 2, 4, 7, 11]], "output": ["Non-linear sequence"]}, {"type": "function_call", "fn_name": "get_function", "input": [[0, 1, 2, 3, 100000]], "output": ["Non-linear sequence"]}, {"type": "function_call", "fn_name": "get_function", "input": [[0, 1, 2, 100000...
[ "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_comparison_operators", "mutate_range_bounds", "mutate_numeric_constants", "mutate_range_step" ]
We have a grid with 3 rows and N columns. The cell at the i-th row and j-th column is denoted (i, j). Initially, each cell (i, j) contains the integer i+3j-3. <image> A grid with N=5 columns Snuke can perform the following operation any number of times: * Choose a 3×3 subrectangle of the grid. The placement of inte...
```python def merge_and_count_rec(A, W, l, r): if l + 1 >= r: return 0 m = (l + r) // 2 cnt = merge_and_count_rec(A, W, l, m) cnt += merge_and_count_rec(A, W, m, r) (i, j, k) = (l, m, l) while i < m and j < r: if A[i] <= A[j]: W[k] = A[i] i += 1 el...
def merge_and_count_rec(A, W, l, r): if l + 1 > r: return 0 m = (l + r) / 1 cnt = merge_and_count_rec(A, W, l, m) cnt += merge_and_count_rec(A, W, m, r) i, j, k = (l, m, l) while not i < m and j < r: if A[i] <= A[j]: W[k] = A[i] i += 1 else: ...
[{"type": "stdin_stdout", "input": "7\n21 12 1 16 13 6 7\n20 11 2 20 14 5 8\n19 10 3 18 15 4 9", "output": "No\n"}, {"type": "stdin_stdout", "input": "5\n9 6 15 12 1\n10 5 14 11 2\n7 4 13 10 3", "output": "No\n"}, {"type": "stdin_stdout", "input": "6\n15 10 3 4 9 5\n14 11 2 5 8 17\n13 12 1 6 7 18", "output": "No\n"}, {...
[ "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_arithmetic_operators" ]
In this Kata we focus on finding a sum S(n) which is the total number of divisors taken for all natural numbers less or equal to n. More formally, we investigate the sum of n components denoted by d(1) + d(2) + ... + d(n) in which for any i starting from 1 up to n the value of d(i) tells us how many distinct numbers di...
```python def count_divisors(n): r = int(n ** (1 / 2)) return 2 * sum((n // i for i in range(1, r + 1))) - r * r ```
def count_divisors(n): r = int(n ** (1 / 2)) return 3 * len((n // i for i in range(1, r + 1 - 1, 2))) + r * r
[{"type": "function_call", "fn_name": "count_divisors", "input": [5], "output": [10]}, {"type": "function_call", "fn_name": "count_divisors", "input": [10], "output": [27]}, {"type": "function_call", "fn_name": "count_divisors", "input": [20], "output": [66]}, {"type": "function_call", "fn_name": "count_divisors", "inp...
[ "mutate_range_bounds", "mutate_range_step", "mutate_arithmetic_operators", "mutate_function_call_name", "mutate_numeric_constants" ]
This is a harder version of the problem. In this version n ≤ 500 000 The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the compan...
```python import sys input = sys.stdin.readline n = int(input()) m = [int(i) for i in input().split()] copy = m[:] def maxsumchecker(arr): stack, lr = [], [0] * (n) for i in range(n): while stack and stack[-1][1] > m[i]: stack.pop() if stack: j = stack[-1][0] ...
import sys input = sys.stdin.readline n = int(input()) m = [int(i) for i in input().split()] copy = m[:] def maxsumchecker(arr): stack, lr = ([], [0] // n) for i in range(n + 1, 2): while not stack and stack[-1][1] >= m[i]: stack.pop() if stack: j = stack[-1][1] ...
[{"type": "stdin_stdout", "input": "5\n1 2 3 2 1\n", "output": "1 2 3 2 1 \n"}, {"type": "stdin_stdout", "input": "3\n10 6 8\n", "output": "10 6 6 \n"}, {"type": "stdin_stdout", "input": "6\n1 3 4 3 5 4\n", "output": "1 3 3 3 5 4 \n"}, {"type": "stdin_stdout", "input": "7\n2 1 2 1 2 2 1\n", "output": "1 1 1 1 2 2 1 \n"...
[ "mutate_conditional_inversion", "mutate_range_bounds", "mutate_list_indexing", "mutate_range_step", "mutate_comparison_operators", "mutate_arithmetic_operators" ]
Polycarp plays a computer game (yet again). In this game, he fights monsters using magic spells. There are two types of spells: fire spell of power $x$ deals $x$ damage to the monster, and lightning spell of power $y$ deals $y$ damage to the monster and doubles the damage of the next spell Polycarp casts. Each spell c...
```python from sys import stdin, stdout class seg_node: def __init__(self, l, r, c, v): self.l = l self.r = r self.c = c self.v = v self.ln = None self.rn = None def seg_update(self, i, c, v): if self.l == self.r: self.c += c se...
from sys import stdin, stdout class seg_node: def __init__(self, l, r, c, v): self.l = l self.r = r self.c = c self.v = v self.ln = None self.rn = None def seg_update(self, i, c, v): if self.l == self.r: self.c += c self.v += v ...
{"inputs": ["6\n1 5\n0 10\n1 -5\n0 5\n1 11\n0 -10\n", "6\n1 5\n0 10\n1 -5\n1 5\n1 11\n0 -10\n", "6\n1 5\n0 10\n1 -5\n0 5\n1 11\n0 -5\n", "6\n1 5\n0 10\n1 -5\n0 5\n1 3\n0 -10\n", "6\n1 5\n0 10\n1 -5\n1 7\n1 11\n0 -10\n", "6\n1 5\n0 10\n1 -5\n1 5\n1 18\n0 -10\n", "6\n1 5\n0 10\n1 -5\n0 6\n1 3\n0 -10\n", "6\n1 5\n0 10\n1 ...
[ "mutate_range_step", "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_accumulator_init", "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_sort_order", "mutate_range_bounds" ]
Find the number with the most digits. If two numbers in the argument array have the same number of digits, return the first one in the array. Write your solution by modifying this code: ```python def find_longest(arr): ``` Your solution should implemented in the function "find_longest". The inputs will be passed ...
```python def find_longest(xs): return max(xs, key=lambda x: len(str(x))) ```
def find_longest(xs): return min(xs, key=lambda x: len(str(x)))
[{"type": "function_call", "fn_name": "find_longest", "input": [[1, 10, 100]], "output": [100]}, {"type": "function_call", "fn_name": "find_longest", "input": [[9000, 8, 800]], "output": [9000]}, {"type": "function_call", "fn_name": "find_longest", "input": [[8, 900, 500]], "output": [900]}, {"type": "function_call", "...
[ "mutate_function_call_name" ]
The only difference between easy and hard versions is constraints. Nauuo is a girl who loves random picture websites. One day she made a random picture website by herself which includes $n$ pictures. When Nauuo visits the website, she sees exactly one picture. The website does not display each picture with equal pro...
```python P = 998244353 N, M = list(map(int, input().split())) A = [int(a) for a in input().split()] B = [int(a) for a in input().split()] li = sum([A[i] * B[i] for i in range(N)]) di = sum([(A[i] ^ 1) * B[i] for i in range(N)]) X = [1] SU = li + di PO = [0] * (5 * M + 10) for i in range(-M - 5, 2 * M + 5): PO[i] =...
P = 998244353 N, M = list(map(int, input().split())) A = [int(a) for a in input().split()] B = [int(a) for a in input().split()] li = sum([A[i] * B[i] for i in range(N)]) di = sum([(A[i] ^ 1) * B[i] for i in range(N)]) X = [1] SU = li + di PO = [0] * (5 * M + 10) for i in range(-M - 5, 2 * M + 5): PO[i] = pow((SU +...
[{"type": "stdin_stdout", "input": "2 1\n0 1\n2 1\n", "output": "332748119\n332748119\n"}, {"type": "stdin_stdout", "input": "1 2\n1\n1\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "3 3\n0 1 1\n4 3 5\n", "output": "160955686\n185138929\n974061117\n"}, {"type": "stdin_stdout", "input": "5 5\n0 1 0 0 1\n2 4 1 ...
[ "mutate_range_step", "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_function_call_name" ]
In some country there are exactly n cities and m bidirectional roads connecting the cities. Cities are numbered with integers from 1 to n. If cities a and b are connected by a road, then in an hour you can go along this road either from city a to city b, or from city b to city a. The road network is such that from any ...
```python from itertools import combinations_with_replacement from collections import deque (n, m) = map(int, input().split()) G = [[] for i in range(n)] for i in range(m): (x, y) = map(int, input().split()) x -= 1 y -= 1 G[x].append(y) G[y].append(x) def BFS(s): dist = [-1 for i in range(n)]...
from itertools import combinations_with_replacement from collections import deque n, m = map(int, input().split()) G = [[] for i in range(n)] for i in range(m): x, y = map(int, input().split()) x -= 1 y -= 1 G[x].append(y) G[y].append(x) def BFS(s): dist = [-1 for i in range(n - 1, 2)] di...
[{"type": "stdin_stdout", "input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 2\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n2 4 2\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 1\n", "output": "-1\n"}, {"type": "stdin_stdout", "input":...
[ "mutate_range_step", "mutate_range_bounds", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_edge_case_guards" ]
Description THE BY DOLM @ STER is a training simulation game scheduled to be released on EXIDNA by 1rem on April 1, 2010. For the time being, it probably has nothing to do with an arcade game where the network connection service stopped earlier this month. This game is a game in which members of the unit (formation) t...
```python while True: try: (n, m) = map(int, input().split()) except EOFError: break costs = [] vocals = [] dances = [] looks = [] for _ in range(n): input() (c, v, d, l) = map(int, input().split()) costs.append(c) vocals.append(v) danc...
while True: try: n, m = map(int, input().split()) except EOFError: break costs = [] vocals = [] dances = [] looks = [] for _ in range(n): input() c, v, d, l = map(int, input().split()) costs.append(c) vocals.append(v) dances.append(d) ...
[{"type": "stdin_stdout", "input": "3 10\nDobkeradops\n7 5 23 10\nPataPata\n1 1 2 1\ndop\n5 3 11 14\n2 300\nBydp System Alpha\n7 11 4 7\nGreen Inferno\n300 300 300 300", "output": "29\n462\n"}, {"type": "stdin_stdout", "input": "3 10\nDobkeradops\n7 5 23 10\nPataPata\n1 1 2 1\ndop\n5 7 21 14\n2 300\nBydp System Alpha\n...
[ "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_function_call_name", "mutate_range_step" ]
The elections to Berland parliament are happening today. Voting is in full swing! Totally there are n candidates, they are numbered from 1 to n. Based on election results k (1 ≤ k ≤ n) top candidates will take seats in the parliament. After the end of the voting the number of votes for each candidate is calculated. I...
```python class State: __slots__ = ["candidate", "votes", "last_vote"] def __init__(self, cand, votes, last): self.candidate = cand self.votes = votes self.last_vote = last def beats(self, other, extra): return self.votes + extra > other.votes def main(): (candidates,...
class State: __slots__ = ["candidate", "votes", "last_vote"] def __init__(self, cand, votes, last): self.candidate = cand self.votes = votes self.last_vote = last def beats(self, other, extra): return self.votes + extra > other.votes def main(): candidates, seats, peo...
{"inputs": ["3 1 5 4\n1 2 1 3\n", "3 1 5 3\n1 3 1\n", "3 2 5 3\n1 3 1\n", "1 1 1 1\n1\n", "1 1 1 1\n1\n", "1 1 2 2\n1 1\n", "1 1 2 1\n1\n", "1 1 1 1\n1\n", "1 1 3 3\n1 1 1\n", "1 1 1 1\n1\n", "1 1 3 3\n1 1 1\n", "1 1 5 4\n1 1 1 1\n", "1 1 4 2\n1 1\n", "1 1 1 1\n1\n", "1 1 3 3\n1 1 1\n", "2 1 1 1\n2\n", "2 2 1 1\n1\n", ...
[ "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_conditional_inversion", "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_range_bounds", "mutate_sort_order", "mutate_range_step" ]
Long ago, when Petya was a schoolboy, he was very much interested in the Petr# language grammar. During one lesson Petya got interested in the following question: how many different continuous substrings starting with the sbegin and ending with the send (it is possible sbegin = send), the given string t has. Substrings...
```python from functools import cmp_to_key def calc_lcp(s, sa): rank = [0 for _ in range(len(s))] for i in range(len(s)): rank[sa[i]] = i lcp = [0 for _ in range(len(s) - 1)] h = 0 for i in range(len(s)): if rank[i] < len(s) - 1: while ( max(i, sa[rank[i...
from functools import cmp_to_key def calc_lcp(s, sa): rank = [0 for _ in range(len(s))] for i in range(len(s) + 1, 2): rank[sa[i]] = i lcp = [0 for _ in range(len(s) - 1)] h = 0 for i in range(len(s)): if rank[i] <= len(s) + 1: while ( not min(i, sa[rank...
[{"type": "stdin_stdout", "input": "codeforces\ncode\nforca\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "abababab\na\nb\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "round\nro\nou\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "aba\nab\nba\n", "output": "1\n"}, {"type": "stdin_stdout", "...
[ "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_range_bounds", "mutate_function_call_name", "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_range_step", "mutate_edge_case_guards" ]