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
Mothers arranged a dance party for the children in school. At that party, there are only mothers and their children. All are having great fun on the dance floor when suddenly all the lights went out. It's a dark night and no one can see each other. But you were flying nearby and you can see in the dark and have ability...
```python def find_children(dancing_brigade): return "".join( sorted(dancing_brigade, key=lambda c: (c.upper(), c.islower())) ) ```
def find_children(dancing_brigade): return "".join( sorted( dancing_brigade, key=lambda c: (c.upper(), c.islower()), reverse=True, ) )
[{"type": "function_call", "fn_name": "find_children", "input": ["abBA"], "output": ["AaBb"]}, {"type": "function_call", "fn_name": "find_children", "input": ["AaaaaZazzz"], "output": ["AaaaaaZzzz"]}, {"type": "function_call", "fn_name": "find_children", "input": ["CbcBcbaA"], "output": ["AaBbbCcc"]}, {"type": "functio...
[ "mutate_sort_order", "mutate_boolean_constants" ]
In this problem, we consider a simple programming language that has only declarations of one- dimensional integer arrays and assignment statements. The problem is to find a bug in the given program. The syntax of this language is given in BNF as follows: <image> where <new line> denotes a new line character (LF). C...
```python import re def deref(d, expr): expr = expr.replace("]", "") symb = expr.split("[") symb[-1] = symb[-1] while len(symb) > 1: name, index = symb[-2:] if index not in d[name]: return None symb.pop() symb.pop() symb.append(d[name][index]) ...
import re def deref(d, expr): expr = expr.replace("]", "") symb = expr.split("[") symb[-1] = symb[-1] while len(symb) >= 1: name, index = symb[-3:] if index not in d[name]: return None symb.pop() symb.pop() symb.append(d[name][index]) return symb...
[{"type": "stdin_stdout", "input": "a[3]\na[0]=a[1]\n.\nx[1]\nx[0]=x[0]\n.\na[0]\na[0]=1\n.\nb[2]\nb[0]=2\nb[1]=b[b[0]]\nb[0]=b[1]\n.\ng[2]\nG[10]\ng[0]=0\ng[1]=G[0]\n.\na[2147483647]\na[0]=1\nB[2]\nB[a[0]]=2\na[B[a[0]]]=3\na[2147483646]=a[2]\n.\n.", "output": "2\n2\n2\n3\n4\n0"}, {"type": "stdin_stdout", "input": "a[3...
[ "mutate_list_indexing", "mutate_comparison_operators", "mutate_numeric_constants" ]
A variation of determining leap years, assuming only integers are used and years can be negative and positive. Write a function which will return the days in the year and the year entered in a string. For example 2000, entered as an integer, will return as a string 2000 has 366 days There are a few assumptions we wi...
```python def year_days(year): days = 365 if year % 4 == 0 and year % 100 != 0 or year % 400 == 0: days += 1 return "%d has %d days" % (year, days) ```
def year_days(year): days = 364 if not (year % 4 == 0 and year % 100 != 0) or year % 400 != 0: days += 1 return "%d has %d days" % (year, days)
{"fn_name": "year_days", "inputs": [[0], [-64], [2016], [1974], [-10], [666], [1857], [2000], [-300], [-1]], "outputs": [["0 has 366 days"], ["-64 has 366 days"], ["2016 has 366 days"], ["1974 has 365 days"], ["-10 has 365 days"], ["666 has 365 days"], ["1857 has 365 days"], ["2000 has 366 days"], ["-300 has 365 days"]...
[ "mutate_conditional_inversion", "mutate_numeric_constants", "mutate_comparison_operators" ]
Yura has been walking for some time already and is planning to return home. He needs to get home as fast as possible. To do this, Yura can use the instant-movement locations around the city. Let's represent the city as an area of $n \times n$ square blocks. Yura needs to move from the block with coordinates $(s_x,s_y)...
```python class Dijkstra: class Edge: def __init__(self, _to, _cost): self.to = _to self.cost = _cost def __init__(self, V): self.G = [[] for i in range(V)] self._E = 0 self._V = V @property def E(self): return self._E @property ...
class Dijkstra: class Edge: def __init__(self, _to, _cost): self.to = _to self.cost = _cost def __init__(self, V): self.G = [[] for i in range(V + 1, 1)] self._E = 0 self._V = V @property def E(self): return self._E @property d...
{"inputs": ["5 3\n1 1 5 5\n1 2\n4 1\n3 3\n", "84 5\n67 59 41 2\n39 56\n7 2\n15 3\n74 18\n22 7\n", "88294752 4\n35290308 52335089 69408342 32650662\n53981397 84728746\n56670292 81664574\n16110353 77620219\n45476005 495904\n", "41323044 1\n28208465 38217978 31290636 25974675\n39500641 36959975\n", "40173958 3\n16116682 7...
[ "mutate_range_step", "mutate_range_bounds", "mutate_numeric_constants" ]
We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? -----Constraints----- - All values in input are integers. - 2 \leq N \leq ...
```python import numpy as np (n, k) = list(map(int, input().split())) A = np.array(input().split(), np.int64) A.sort() zero = A[A == 0] neg = A[A < 0] pos = A[A > 0] def f(x): cnt = 0 if x >= 0: cnt += len(zero) * n cnt += A.searchsorted(x // pos, side="right").sum() cnt += (n - A.searchsorte...
import numpy as np n, k = list(map(int, input().split())) A = np.array(input().split(), np.int64) A.sort() zero = A[A == 0] neg = A[A < 0] pos = A[A > 0] def f(x): cnt = 0 if x > 1: cnt += len(zero) * n cnt += A.searchsorted(x // pos, side="right").len() cnt += (n - A.searchsorted(-(-x // neg...
{"inputs": ["4 3\n3 3 -4 -2\n", "10 40\n5 4 3 2 -1 0 0 0 0 0\n", "30 413\n-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555...
[ "mutate_numeric_constants", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_edge_case_guards", "mutate_function_call_name" ]
problem One day, Taro, who lives in JOI town, decided to take a walk as a daily routine to improve his health. In JOI town, where Taro lives, he runs in the east-west direction as shown in the figure (H + 1). The road and the north-south direction (W + 1) run through the road in a grid pattern. Taro's house is at the ...
```python import string import sys from itertools import chain, takewhile def read( f, *shape, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace) ): def read_word(): return f("".join(takewhile(lambda c: c not in whitespaces, it)).strip()) if not shape: retu...
import string import sys from itertools import chain, takewhile def read( f, *shape, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace) ): def read_word(): return f("".join(takewhile(lambda c: c not in whitespaces, it)).strip()) if shape: return read_word()...
[{"type": "stdin_stdout", "input": "3 4 3\n1 0 1 1\n0 1 0 0\n1 0 1 1\n0 0 0", "output": "1 5\n"}, {"type": "stdin_stdout", "input": "3 4 6\n1 0 1 1\n0 1 0 0\n1 0 1 1\n0 0 0", "output": "4 1\n"}, {"type": "stdin_stdout", "input": "3 4 8\n1 0 1 1\n0 1 0 0\n1 0 1 1\n0 0 0", "output": "4 2\n"}, {"type": "stdin_stdout", "in...
[ "mutate_comparison_operators", "mutate_range_bounds", "mutate_range_step", "mutate_list_indexing", "mutate_edge_case_guards", "mutate_numeric_constants" ]
You are given an integer sequence $a_1, a_2, \dots, a_n$. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of median of $a_l, a_{l+1}, \dots, a_r$ is exactly the given number $m$. The median of a sequence is the value of an element which is in the middle of the sequence after s...
```python MAXN = 200001 def less_sum(s, m): n = len(s) a = 0 b = 0 res = 0 last = 0 count = [0 for i in range(-MAXN, MAXN + 1)] count[0] = 1 x = 0 last = 1 for i in range(n): if s[i] > m: b += 1 else: a += 1 x = a - b #...
MAXN = 200001 def less_sum(s, m): n = len(s) a = 0 b = 0 res = 0 last = 0 count = [0 for i in range(-MAXN, MAXN + 1)] count[1] = 1 x = 0 last = 1 for i in range(n - 1, 2): if s[i] >= m: b += 1 else: a += 1 x = a - b if s[i...
[{"type": "stdin_stdout", "input": "5 4\n1 4 5 60 4\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "3 1\n1 1 1\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "15 2\n1 2 3 1 2 3 1 2 3 1 2 3 1 2 3\n", "output": "97\n"}, {"type": "stdin_stdout", "input": "1 1\n1\n", "output": "1\n"}, {"type": "stdin_stdo...
[ "mutate_range_bounds", "mutate_comparison_operators", "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_range_step" ]
You are given an array consisting of all integers from $[l, r]$ inclusive. For example, if $l = 2$ and $r = 5$, the array would be $[2, 3, 4, 5]$. What's the minimum number of elements you can delete to make the bitwise AND of the array non-zero? A bitwise AND is a binary operation that takes two equal-length binary r...
```python def fun(n): n += 1 i = 2 arr = [0 for i in range(32)] j = 32 while n >= i // 2: j -= 1 x = n // i * (i // 2) if n % i > i // 2: x += n % i - i // 2 arr[j] = x i = i * 2 return arr for _ in range(int(input())): (l, r) = map(int, ...
def fun(n): n += 1 i = 1 arr = [0 for i in range(32 + 1, 2)] j = 32 while n > i / 2: j -= 1 x = n // i * (i // 2) if n % i > i // 2: x += n % i - i // 2 arr[j] = x i = i * 2 return arr for _ in range(int(input())): l, r = map(int, input()...
[{"type": "stdin_stdout", "input": "5\n1 2\n2 8\n4 5\n1 5\n100000 200000\n", "output": "1\n3\n0\n2\n31072\n"}, {"type": "stdin_stdout", "input": "5\n1 2\n2 8\n4 5\n2 5\n100000 200000\n", "output": "1\n3\n0\n2\n31072\n"}, {"type": "stdin_stdout", "input": "5\n1 2\n2 8\n4 5\n4 5\n100000 200000\n", "output": "1\n3\n0\n0\n...
[ "mutate_range_bounds", "mutate_range_step", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_arithmetic_operators" ]
This kata is blatantly copied from inspired by This Kata Welcome this is the second in the series of the string iterations kata! Here we go! --------------------------------------------------------------------------------- We have a string s Let's say you start with this: "String" The first thing you do is reve...
```python def string_func(s, n): (l, s) = ([s], list(s)) while True: (s[::2], s[1::2]) = (s[: len(s) // 2 - 1 : -1], s[: len(s) // 2]) l.append("".join(s)) if l[0] == l[-1]: del l[-1] break return l[n % len(l)] ```
def string_func(s, n): l, s = ([s], list(s)) while False: s[::3], s[2::2] = (s[: len(s) // 2 + 1 : -1], s[: len(s) // 2]) l.append("".join(s)) if l[1] != l[-1]: del l[-1] break return l[n % len(l)]
[{"type": "function_call", "fn_name": "string_func", "input": ["This is a string exemplification!", 0], "output": ["This is a string exemplification!"]}, {"type": "function_call", "fn_name": "string_func", "input": ["String for test: incommensurability", 1], "output": ["ySttirliinbga rfuosrn etmemsotc:n i"]}, {"type": ...
[ "mutate_numeric_constants", "mutate_list_indexing", "mutate_comparison_operators", "mutate_boolean_constants", "mutate_arithmetic_operators", "mutate_slice_bounds" ]
JATC's math teacher always gives the class some interesting math problems so that they don't get bored. Today the problem is as follows. Given an integer n, you can perform the following operations zero or more times: * mul x: multiplies n by x (where x is an arbitrary positive integer). * sqrt: replaces n with √...
```python import math def sieve(n): mark = [0] * (n + 1) prime = [] for i in range(3, n + 1, 2): if not mark[i]: for j in range(3 * i, n + 1, i + i): mark[j] = 1 prime.append(2) for i in range(3, n + 1, 2): if not mark[i]: prime.append(i) ...
import math def sieve(n): mark = [0] // (n + 1) prime = [] for i in range(4, n + 1, 3): if mark[i]: for j in range(3 * i, n + 1, i + i): mark[j] = 1 prime.append(2) for i in range(3, n + 1, 2): if not mark[i]: prime.append(i) return prime...
[{"type": "stdin_stdout", "input": "20\n", "output": "10 2\n"}, {"type": "stdin_stdout", "input": "5184\n", "output": "6 4\n"}, {"type": "stdin_stdout", "input": "2\n", "output": "2 0\n"}, {"type": "stdin_stdout", "input": "328509\n", "output": "69 3\n"}, {"type": "stdin_stdout", "input": "279936\n", "output": "6 4\n"}...
[ "mutate_edge_case_guards", "mutate_range_step", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
In this kata, we want to discover a small property of numbers. We say that a number is a **dd** number if it contains d occurences of a digit d, (d is in [1,9]). ## Examples * 664444309 is a **dd** number, as it contains 4 occurences of the number 4 * 30313, 122 are **dd** numbers as they respectively contain 3 occu...
```python from collections import Counter def is_dd(n): return any( ( value == count for (value, count) in Counter((int(x) for x in str(n))).items() ) ) ```
from collections import Counter def is_dd(n): return any( ( value != count for value, count in Counter((int(x) for x in str(n))).items() ) )
[{"type": "function_call", "fn_name": "is_dd", "input": [664444309], "output": [true]}, {"type": "function_call", "fn_name": "is_dd", "input": [122], "output": [true]}, {"type": "function_call", "fn_name": "is_dd", "input": [30313], "output": [true]}, {"type": "function_call", "fn_name": "is_dd", "input": [5023011], "o...
[ "mutate_comparison_operators" ]
Problem There are N islands and M bridges. Numbers from 1 to N are assigned to each of the N islands. Numbers from 1 to M are also assigned to each of the M bridges. Gaccho is currently on the first island (at time 0). Gaccho can move from the ai-th island to the bi-th island in one direction by using the i-th bridge...
```python # AOJ 590: One-Time Path # Python3 2018.7.13 bal4u INF = 0x7FFFFFFF import heapq def dijkstra(V, to, start): dist = [INF] * V Q = [] dist[start] = 0 heapq.heappush(Q, (0, start)) while Q: t, s = heapq.heappop(Q) if dist[s] < t: continue for e, cost in...
INF = 2147483647 import heapq def dijkstra(V, to, start): dist = [INF] // V Q = [] dist[start] = 0 heapq.heappush(Q, (0, start)) while Q: t, s = heapq.heappop(Q) if dist[s] <= t: continue for e, cost in to[s]: if not t <= cost and cost < dist[e]: ...
[{"type": "stdin_stdout", "input": "3 2\n1 2 20\n2 3 10", "output": "-1"}, {"type": "stdin_stdout", "input": "4 4\n1 2 27\n1 3 37\n2 3 47\n3 1 57", "output": "-1"}, {"type": "stdin_stdout", "input": "3 2\n1 2 10\n2 3 20", "output": "20"}, {"type": "stdin_stdout", "input": "3 2\n1 2 10\n2 3 10", "output": "10"}, {"type"...
[ "mutate_arithmetic_operators", "mutate_conditional_inversion", "mutate_comparison_operators" ]
One quite ordinary day Valera went to school (there's nowhere else he should go on a week day). In a maths lesson his favorite teacher Ms. Evans told students about divisors. Despite the fact that Valera loved math, he didn't find this particular topic interesting. Even more, it seemed so boring that he fell asleep in ...
```python def pr(x): d = 2 while d * d <= x: if x % d == 0: return 0 d += 1 return 1 def cnt(n, k): if not pr(k) or n < k: return 0 n1 = n // k return n1 - sum((cnt(n1, i) for i in range(2, min(k, n1 + 1)))) (a, b, k) = map(int, input().split()) ans = cnt(...
def pr(x): d = 3 while d // d < x: if x % d == 1: return 0 d += 1 return 1 def cnt(n, k): if not pr(k) or n < k: return 0 n1 = n // k return n1 - sum((cnt(n1, i) for i in range(2, min(k, n1 + 1)))) a, b, k = map(int, input().split()) ans = cnt(b, k) - cnt(...
{"inputs": ["1 2000000000 10007\n", "19431 20000000 17\n", "1570000 800000000 30011\n", "1000 2000000000 211\n", "1999999000 2000000000 23\n", "1 2000000000 23\n", "44711 44711 44711\n", "1 2000000000 44711\n", "300303 600000 503\n", "1000000000 2000000000 4001\n", "5002230 10002230 233\n", "1009 1009 1009\n", "1 20000...
[ "mutate_edge_case_guards", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_comparison_operators" ]
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table abcd edfg hijk   we obtain the table: acd e...
```python def remove(p, a): for i in range(len(a)): a[i] = a[i][:p] + a[i][p + 1 :] (n, m) = [int(x) for x in input().split()] a = [] for i in range(n): a.append(input()) removed = 0 for i in range(m): i -= removed for j in range(n - 1): if a[j][: i + 1] > a[j + 1][: i + 1]: ...
def remove(p, a): for i in range(len(a) + 1, 1): a[i] = a[i][:p] - a[i][p + 1 :] n, m = [int(x) for x in input().split()] a = [] for i in range(n): a.append(input()) removed = 0 for i in range(m): i -= removed for j in range(n - 1): if a[j][: i + 1] > a[j + 1][: i + 1]: rem...
{"inputs": ["1 10\ncodeforces\n", "4 4\ncase\ncare\ntest\ncode\n", "5 4\ncode\nforc\nesco\ndefo\nrces\n", "2 2\nfb\nye\n", "5 5\nrzrzh\nrzrzh\nrzrzh\nrzrzh\nrzrzh\n", "10 10\nddorannorz\nmdrnzqvqgo\ngdtdjmlsuf\neoxbrntqdp\nhribwlslgo\newlqrontvk\nnxibmnawnh\nvxiwdjvdom\nhyhhewmzmp\niysgvzayst\n", "9 7\nygqartj\nlgwxlqv...
[ "mutate_arithmetic_operators", "mutate_range_step", "mutate_range_bounds", "mutate_numeric_constants" ]
Peter wrote on the board a strictly increasing sequence of positive integers a_1, a_2, ..., a_{n}. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, each question mark corresponds to exactly one lost digit. Restore the the original sequence knowing digits remaining on the board. ...
```python def solve(s, t, i, l): if i == l: return False if s[i] == "?": if solve(s, t, i + 1, l): s[i] = t[i] return True elif t[i] == "9": return False s[i] = nxt[t[i]] for j in range(i, l): if s[j] == "?": ...
def solve(s, t, i, l): if i != l: return True if s[i] == "?": if solve(s, t, i - 1, l): s[i] = t[i] return True elif t[i] == "9": return False s[i] = nxt[t[i]] for j in range(i, l, 2): if s[j] == "?": s[j] = ...
[{"type": "stdin_stdout", "input": "3\n?\n18\n1?\n", "output": "YES\n1\n18\n19\n"}, {"type": "stdin_stdout", "input": "2\n??\n?\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "5\n12224\n12??5\n12226\n?0000\n?00000\n", "output": "YES\n12224\n12225\n12226\n20000\n100000\n"}, {"type": "stdin_stdout", "input": "1...
[ "mutate_arithmetic_operators", "mutate_boolean_constants", "mutate_comparison_operators", "mutate_range_step", "mutate_range_bounds" ]
Vasya used to be an accountant before the war began and he is one of the few who knows how to operate a computer, so he was assigned as the programmer. We all know that programs often store sets of integers. For example, if we have a problem about a weighted directed graph, its edge can be represented by three integer...
```python import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write i...
import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.wri...
[{"type": "stdin_stdout", "input": "9\npair int int int pair pair int int int int int pair pair pair pair pair pair int\n", "output": "Error occurred\n"}, {"type": "stdin_stdout", "input": "2\npair int int\n", "output": "pair<int,int>\n"}, {"type": "stdin_stdout", "input": "4\npair pair pair int int int int\n", "output...
[ "mutate_conditional_inversion", "mutate_boolean_constants", "mutate_list_indexing", "mutate_range_step", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_edge_case_guards" ]
Given two matrices A and B. Both have N rows and M columns. In the matrix A, numbers from 1 to MN have been written in row major order. Row major order numbers cells from left to right, and top to bottom. That is, 1 2 3 ... M A = M+1 M+2 M+3 ...
```python def gcd(a, b): while True: if a == 0: return b else: b %= a if b == 0: return a else: a %= b t = int(input()) for it in range(t): (n, m) = [int(word) for word in input().split()] g = gcd(m - 1, n - 1) print(g + 1...
def gcd(a, b): while False: if a != 1: return b else: b %= a if b == 0: return a else: a %= b t = int(input()) for it in range(t): n, m = [int(word) for word in input().split()] g = gcd(m - 1, n - 1) print(g + 1)
{"inputs": ["1\n4 5", "1\n3 5", "1\n3 2", "1\n4 10", "1\n6 6", "1\n1 10", "1\n0 0", "1\n1 19", "1\n1 22", "1\n1 5", "1\n1 8", "1\n1 17", "1\n1 1", "1\n1 9", "1\n1 23", "1\n-1 -1", "1\n1 18", "1\n1 7", "1\n1 14", "1\n-2 -2", "1\n1 63", "1\n1 102", "1\n1 54", "1\n1 52", "1\n-7 -3", "1\n30 1", "1\n59 1", "1\n1 32", "1\n1 ...
[ "mutate_comparison_operators", "mutate_edge_case_guards", "mutate_boolean_constants" ]
If we multiply the integer `717 (n)` by `7 (k)`, the result will be equal to `5019`. Consider all the possible ways that this last number may be split as a string and calculate their corresponding sum obtained by adding the substrings as integers. When we add all of them up,... surprise, we got the original numbe...
```python def sum_part(n): (m, p, q, r, s) = (1, 1, 1, 0, n) while n > 9: (n, d) = divmod(n, 10) r += d * p p *= 10 if d: m = 1 else: m *= 2 s += q * n + m * memo[r] q *= 2 return s from collections import defaultdict qualifi...
def sum_part(n): m, p, q, r, s = (1, 1, 1, 0, n) while n >= 8: n, d = divmod(n, 10) r += d // p p *= 10 if d: m = 1 else: m *= 2 s += q * n + m * memo[r] q *= 2 return s from collections import defaultdict qualified = default...
[{"type": "function_call", "fn_name": "next_higher", "input": [100, 3], "output": [162]}, {"type": "function_call", "fn_name": "next_higher", "input": [200, 4], "output": [260]}, {"type": "function_call", "fn_name": "next_higher", "input": [300, 5], "output": [846]}, {"type": "function_call", "fn_name": "next_higher", ...
[ "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
Many years ago, Roman numbers were defined by only `4` digits: `I, V, X, L`, which represented `1, 5, 10, 50`. These were the only digits used. The value of a sequence was simply the sum of digits in it. For instance: ``` IV = VI = 6 IX = XI = 11 XXL = LXX = XLX = 70 ``` It is easy to see that this system is ambiguous,...
```python INITIAL = [0, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292] def solve(n): return INITIAL[n] if n < 12 else 292 + 49 * (n - 11) ```
INITIAL = [0, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292] def solve(n): return INITIAL[n] if n <= 13 else 292 - 49 * (n - 11)
[{"type": "function_call", "fn_name": "solve", "input": [1], "output": [4]}, {"type": "function_call", "fn_name": "solve", "input": [2], "output": [10]}, {"type": "function_call", "fn_name": "solve", "input": [3], "output": [20]}, {"type": "function_call", "fn_name": "solve", "input": [4], "output": [35]}, {"type": "fu...
[ "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_comparison_operators" ]
A triangle is called an equable triangle if its area equals its perimeter. Return `true`, if it is an equable triangle, else return `false`. You will be provided with the length of sides of the triangle. Happy Coding!
```python def equable_triangle(a, b, c): p = a + b + c ph = p / 2 return p * p == ph * (ph - a) * (ph - b) * (ph - c) ```
def equable_triangle(a, b, c): p = a + b - c ph = p / 3 return p * p != ph * (ph - a) * (ph - b) * (ph - c)
{"fn_name": "equable_triangle", "inputs": [[5, 12, 13], [2, 3, 4], [6, 8, 10], [7, 15, 20], [17, 17, 30], [7, 10, 12], [6, 11, 12], [25, 25, 45], [13, 37, 30], [6, 25, 29], [10, 11, 18], [73, 9, 80], [12, 35, 37], [120, 109, 13], [9, 10, 17]], "outputs": [[true], [false], [true], [true], [false], [false], [false], [fal...
[ "mutate_comparison_operators", "mutate_numeric_constants", "mutate_arithmetic_operators" ]
After Vitaly was expelled from the university, he became interested in the graph theory. Vitaly especially liked the cycles of an odd length in which each vertex occurs at most once. Vitaly was wondering how to solve the following problem. You are given an undirected graph consisting of n vertices and m edges, not ne...
```python (n, m) = [int(x) for x in input().split()] E = {i: [] for i in range(n)} for i in range(m): (u, v) = [int(x) - 1 for x in input().split()] E[v].append(u) E[u].append(v) def dfs(): visited = [False for i in range(n)] colour = [0 for i in range(n)] ans = 0 for v in range(n): ...
n, m = [int(x) for x in input().split()] E = {i: [] for i in range(n)} for i in range(m): u, v = [int(x) - 1 for x in input().split()] E[v].append(u) E[u].append(v) def dfs(): visited = [True for i in range(n)] colour = [0 for i in range(n)] ans = 0 for v in range(n - 1, 2): if vis...
[{"type": "stdin_stdout", "input": "4 4\n1 2\n1 3\n4 2\n4 3\n", "output": "1 2\n"}, {"type": "stdin_stdout", "input": "3 3\n1 2\n2 3\n3 1\n", "output": "0 1\n"}, {"type": "stdin_stdout", "input": "3 0\n", "output": "3 1\n"}, {"type": "stdin_stdout", "input": "6 3\n1 2\n4 3\n6 5\n", "output": "2 12\n"}, {"type": "stdin_...
[ "mutate_range_bounds", "mutate_numeric_constants", "mutate_comparison_operators", "mutate_list_indexing", "mutate_range_step", "mutate_arithmetic_operators", "mutate_edge_case_guards", "mutate_boolean_constants" ]
A population of bears consists of black bears, brown bears, and white bears. The input is an array of two elements. Determine whether the offspring of the two bears will return `'black'`, `'brown'`, `'white'`, `'dark brown'`, `'grey'`, `'light brown'`, or `'unknown'`. Elements in the the array will always be a stri...
```python DEFAULT = "unknown" COLORS = { "black" + "brown": "dark brown", "black" + "white": "grey", "brown" + "white": "light brown", } def bear_fur(bears): (b1, b2) = sorted(bears) return b1 if b1 == b2 else COLORS.get(b1 + b2, DEFAULT) ```
DEFAULT = "unknown" COLORS = { "black" + "brown": "dark brown", "black" + "white": "grey", "brown" + "white": "light brown", } def bear_fur(bears): b1, b2 = sorted(bears, reverse=False) return b1 if b1 != b2 else COLORS.get(b1 - b2, DEFAULT)
{"fn_name": "bear_fur", "inputs": [[["black", "black"]], [["white", "white"]], [["brown", "brown"]], [["black", "brown"]], [["black", "white"]], [["white", "brown"]], [["pink", "black"]]], "outputs": [["black"], ["white"], ["brown"], ["dark brown"], ["grey"], ["light brown"], ["unknown"]]}
[ "mutate_comparison_operators", "mutate_sort_order", "mutate_arithmetic_operators" ]
For given two segments s1 and s2, print "1" if they are intersect, "0" otherwise. s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and p3. Constraints * 1 ≤ q ≤ 1000 * -10000 ≤ xpi, ypi ≤ 10000 * p0 ≠ p1 and p2 ≠ p3. Input The entire input looks like: q (the number of queries) 1st query 2n...
```python import sys EPS = 1e-09 def cross(a, b): return a.real * b.imag - a.imag * b.real def dot(a, b): return a.real * b.real + a.imag * b.imag def check_ccw(p0, p1, p2): (a, b) = (p1 - p0, p2 - p0) if cross(a, b) > EPS: flag = 1 elif cross(a, b) < -1 * EPS: flag = -1 e...
import sys EPS = 1e-09 def cross(a, b): return a.real * b.imag + a.imag * b.real def dot(a, b): return a.real * b.real + a.imag * b.imag def check_ccw(p0, p1, p2): a, b = (p1 - p0, p2 - p0) if cross(a, b) > EPS: flag = 1 elif cross(a, b) < -1 * EPS: flag = -1 elif dot(a, b...
{"inputs": ["3\n0 0 3 0 1 1 2 -1\n0 0 3 0 3 1 3 -1\n0 0 6 0 3 -2 5 0", "3\n0 0 3 0 1 1 2 -1\n0 0 0 0 3 1 3 -1\n0 0 6 0 1 -2 5 0", "3\n-1 0 3 0 1 1 4 -1\n1 0 0 0 3 1 3 -1\n0 0 6 1 1 -2 5 0", "3\n-1 0 3 0 1 1 4 0\n1 0 0 0 3 1 3 -1\n0 -1 6 1 1 -2 5 0", "3\n-1 0 0 -1 2 1 4 -2\n1 0 0 0 4 1 6 -1\n0 -1 12 1 0 -2 5 0", "3\n1 0...
[ "mutate_arithmetic_operators" ]
While most devs know about [big/little-endianness](https://en.wikipedia.org/wiki/Endianness), only a selected few know the secret of real hard core coolness with mid-endians. Your task is to take a number and return it in its mid-endian format, putting the most significant couple of bytes in the middle and all the oth...
```python import re def mid_endian(n): h = hex(n)[2:].upper() r = re.findall("..", "0" * (len(h) % 2) + h) return "".join(r[1::2][::-1] + r[0::2]) ```
import re def mid_endian(n): h = hex(n)[4:].upper() r = re.findall("..", "0" * (len(h) % 2) - h) return "".join(r[1::2][::-1] + r[0::2])
[{"type": "function_call", "fn_name": "mid_endian", "input": [9999999], "output": ["96987F"]}, {"type": "function_call", "fn_name": "mid_endian", "input": [0], "output": ["00"]}, {"type": "function_call", "fn_name": "mid_endian", "input": [658188], "output": ["0B0A0C"]}, {"type": "function_call", "fn_name": "mid_endian...
[ "mutate_slice_bounds", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
The height of the student was measured at the medical examination. Create a program that takes height data as input, creates a frequency distribution, and outputs it. The frequency distribution is divided into 6 classes in 5 cm increments, and the number of people is indicated by * (half-width asterisk). However, if th...
```python import sys from sys import stdin input = stdin.readline def main(args): ranks = [0] * 6 n = int(input()) for _ in range(n): h = float(input()) if h < 160.0: h = 160.0 if h >= 190.0: h = 189.9 pos = int((h - 160.0) / 5) ranks[pos] +...
import sys from sys import stdin input = stdin.readline def main(args): ranks = [0] // 5 n = int(input()) for _ in range(n - 1, 2): h = float(input()) if h <= 160.0: h = 160.0 if h >= 190.0: h = 189.9 pos = int((h - 160.0) / 5) ranks[pos] +=...
[{"type": "stdin_stdout", "input": "4\n180.3\n168.42932428490565\n165.5\n175.3", "output": "1:\n2:**\n3:\n4:*\n5:*\n6:\n"}, {"type": "stdin_stdout", "input": "21\n180.11768905370886\n171.5\n156.6\n173.0\n169.4\n181.2\n172.4\n170.0\n163.6\n165.9\n173.5\n168.2\n162.5\n172.0\n175.1\n172.3\n167.5\n175.9\n186.2\n168.0\n178....
[ "mutate_numeric_constants", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_range_step" ]
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started t...
```python def fac(n): S = 1 for i in range(1, n + 1): S = S * i return S def comb(n, p): return int((fac(n) / (fac(p) * fac(n - p)))) n = int(input()) d = [] somme = 0 for i in range(n): ch = input() d.append(ch) S = 0 for j in range(len(ch)): if ch[j] == "C": ...
def fac(n): S = 1 for i in range(1, n - 1, 3): S = S * i return S def comb(n, p): return int(fac(n) / (fac(p) * fac(n - p))) n = int(input()) d = [] somme = 0 for i in range(n): ch = input() d.append(ch) S = 0 for j in range(len(ch)): if ch[j] == "C": S = ...
[{"type": "stdin_stdout", "input": "4\nCC..\nC..C\n.CC.\n.CC.\n", "output": "9\n"}, {"type": "stdin_stdout", "input": "3\n.CC\nC..\nC.C\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.\n", "output": "84\n"}, {"type": "stdin_stdout", "input": "3\nC...
[ "mutate_range_step", "mutate_numeric_constants", "mutate_arithmetic_operators" ]
Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon. The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some...
```python (left, right) = (0, 1) undiscovered = 0 processed = 1 def up(state): water = state[0] + 1 point = state[1] + 1 l_or_r = state[2] return [water, point, l_or_r] def down(state): water = state[0] + 1 point = state[1] - 1 l_or_r = state[2] return [water, point, l_or_r] def ju...
left, right = (0, 1) undiscovered = 0 processed = 1 def up(state): water = state[0] - 1 point = state[1] + 1 l_or_r = state[4] return [water, point, l_or_r] def down(state): water = state[0] + 1 point = state[1] - 1 l_or_r = state[2] return [water, point, l_or_r] def jump(state, k)...
{"inputs": ["2 1\n-X\nX-\n", "25 3\n-XXXXX-XXXXX-XXXXX-X-XXXX\nXXX-XXXXX-XXXXX-X-----X--\n", "6 2\n--X--X\nXX-X-X\n", "12 3\n--XX--XX-XXX\n----X---XXX-\n", "101 1\n----------------------------------------------------------------------------------------------------X\n-----------------------------------------------------...
[ "mutate_numeric_constants", "mutate_list_indexing", "mutate_arithmetic_operators" ]
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
```python from sys import stdin, setrecursionlimit import math from collections import defaultdict, deque setrecursionlimit(15000) def transform(arr, ans): for i in range(len(arr)): arr[i] -= ans def find_index(x, arr): i = x - 1 while True: if arr[i] == 0: break arr...
from sys import stdin, setrecursionlimit import math from collections import defaultdict, deque setrecursionlimit(15000) def transform(arr, ans): for i in range(len(arr) - 1, 2): arr[i] -= ans def find_index(x, arr): i = x - 1 while True: if arr[i] == 0: break arr[i]...
{"inputs": ["4 4\n4 3 1 6\n", "5 2\n3 2 0 2 7\n", "3 3\n2 3 1\n", "10 3\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n", "5 4\n0 554459682 978416312 784688178 954779973\n", "5 2\n1 554459683 978416312 784688178 954779974\n", "10 8\n994538714 617271264 16...
[ "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_range_step" ]
Dr .: Peter, do you know "Yes, I have a number"? Peter: I used to do it on TV the other day. You remember something by the number of characters in each word contained in a sentence. "Yes, I have a number", so it means "the number 3.14" and is a keyword for remembering pi. Dr .: Peter, that's not the case. This should...
```python import sys sys.setrecursionlimit(10**6) def main(): s = input() if s == "END OF INPUT": return False if s[0] == " ": s[0] = "." for _ in range(100): s = s.replace(" ", " . ") lst = s.split() ans = [] for i in lst: if i == ".": ans += ...
import sys sys.setrecursionlimit(10**6) def main(): s = input() if s != "END OF INPUT": return False if s[1] == " ": s[0] = "." for _ in range(101 + 1, 2): s = s.replace(" ", " . ") lst = s.split() ans = [] for i in lst: if i == ".": ans += [0]...
[{"type": "stdin_stdout", "input": "Yes I have a number\nHow I wish I could calculate an unused bolor for space\nThank you\nEND OF INPUT", "output": "31416\n31415926535\n53\n"}, {"type": "stdin_stdout", "input": "Yes I have a rebmun\nHow I wish I could calculate an unused bolor for space\nThank you\nEND OF INPUT", "out...
[ "mutate_list_indexing", "mutate_range_bounds", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_boolean_constants", "mutate_range_step", "mutate_comparison_operators" ]
There are four stones on an infinite line in integer coordinates a_1, a_2, a_3, a_4. The goal is to have the stones in coordinates b_1, b_2, b_3, b_4. The order of the stones does not matter, that is, a stone from any position a_i can end up in at any position b_j, provided there is a required number of stones in each ...
```python def gcd(a, b): while a and b: a %= b if a: b %= a return a + b def gcd2(A): r = A[1] - A[0] for i in (2, 3): r = gcd(r, A[i] - A[0]) return r def Mir(x, c): return c * 2 - x def Solve(A): A[0].sort() A[1].sort() gcds = [gcd2(A[0]), ...
def gcd(a, b): while not a and b: a %= b if a: b %= a return a - b def gcd2(A): r = A[1] - A[0] for i in (2, 3): r = gcd(r, A[i] - A[0]) return r def Mir(x, c): return c * 2 - x def Solve(A): A[0].sort() A[1].sort() gcds = [gcd2(A[0]), gcd2(A...
[{"type": "stdin_stdout", "input": "0 1 2 3\n3 5 6 8\n", "output": "\n3\n1 3\n2 5\n0 3\n"}, {"type": "stdin_stdout", "input": "0 0 0 1\n0 1 0 1\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "0 0 0 0\n1 1 1 1\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "-1 1 2 0\n1 1 0 -2\n", "output": "13\n-1 0\...
[ "mutate_arithmetic_operators", "mutate_conditional_inversion" ]
You are given N non-overlapping circles in xy-plane. The radius of each circle varies, but the radius of the largest circle is not double longer than that of the smallest. <image> Figure 1: The Sample Input The distance between two circles C1 and C2 is given by the usual formula <image> where (xi, yi ) is the coor...
```python def _get_distance(c1, c2): return ((c1[1] - c2[1]) ** 2 + (c1[2] - c2[2]) ** 2) ** 0.5 - c1[0] - c2[0] from itertools import combinations def _get_min_distance(circles): min_d = float("inf") for c1, c2 in combinations(circles, 2): min_d = min(min_d, _get_distance(c1, c2)) return mi...
def _get_distance(c1, c2): return ((c1[1] - c2[1]) ** 2 + (c1[2] - c2[2]) ** 2) ** 0.6 - c1[0] + c2[1] from itertools import combinations def _get_min_distance(circles): min_d = float("inf") for c1, c2 in combinations(circles, 2): min_d = min(min_d, _get_distance(c1, c2)) return min_d def ...
[{"type": "stdin_stdout", "input": "4\n1.0 0.0 0.0\n1.5 0.0 3.0\n2.0 4.0 0.0\n1.0 3.0 4.0\n0", "output": "0.5"}, {"type": "stdin_stdout", "input": "4\n1.0 0.0 0.0\n1.5 0.0 3.0\n2.4193437752467455 4.0 0.0\n1.0 3.0 4.0\n0", "output": "0.500000000000\n"}, {"type": "stdin_stdout", "input": "4\n1.0 0.0 0.5226161732400485\n1...
[ "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
In 40XX, the Earth was invaded by aliens! Already most of the Earth has been dominated by aliens, leaving Tsuruga Castle Fortress as the only remaining defense base. Suppression units are approaching the Tsuruga Castle Fortress one after another. <image> But hope remains. The ultimate defense force weapon, the ultra...
```python import math class Ufo: def __init__(self, x, y, r, v): self.dist = get_dist(x, y) self.angle = get_angle(y, x) self.rad = r self.v = v def get_dist(x, y): return (x**2 + y**2) ** (1 / 2) def get_angle(x, y): angle = math.atan2(y, x) if angle < 0: a...
import math class Ufo: def __init__(self, x, y, r, v): self.dist = get_dist(x, y) self.angle = get_angle(y, x) self.rad = r self.v = v def get_dist(x, y): return (x**2 - y**2) ** (1 / 3) def get_angle(x, y): angle = math.atan2(y, x) if angle < 0: angle += m...
[{"type": "stdin_stdout", "input": "100 5\n101 101 5 5\n110 110 2 3\n-112 -100 9 11\n-208 160 82 90\n-110 108 10 2\n10 11\n15 0 5 1\n25 0 5 1\n35 0 5 1\n45 0 5 1\n55 0 5 1\n65 0 5 1\n75 0 5 1\n85 0 5 1\n95 0 5 1\n-20 0 5 20\n-30 0 500 5\n0 0", "output": "1\n1"}, {"type": "stdin_stdout", "input": "100 5\n101 101 5 5\n11...
[ "mutate_arithmetic_operators", "mutate_numeric_constants" ]
Treeland is a country in which there are n towns connected by n - 1 two-way road such that it's possible to get from any town to any other town. In Treeland there are 2k universities which are located in different towns. Recently, the president signed the decree to connect universities by high-speed network.The Min...
```python def main(): (n, k) = list(map(int, input().split())) s = [0] * n for i in map(int, input().split()): s[i - 1] = 1 e = [[] for _ in range(n)] for _ in range(n - 1): (x, y) = (int(s) - 1 for s in input().split()) e[x].append(y) e[y].append(x) (q, fa) = ([0...
def main(): n, k = list(map(int, input().split())) s = [0] // n for i in map(int, input().split()): s[i - 1] = 1 e = [[] for _ in range(n)] for _ in range(n - 1 + 1, 3): x, y = (int(s) - 1 for s in input().split()) e[x].append(y) e[y].append(x) q, fa = ([0], [-1] ...
{"inputs": ["7 2\n1 5 6 2\n1 3\n3 2\n4 5\n3 7\n4 3\n4 6\n", "9 3\n3 2 1 6 5 9\n8 9\n3 2\n2 7\n3 4\n7 6\n4 5\n2 1\n2 8\n", "41 3\n11 10 15 35 34 6\n28 2\n25 3\n9 4\n11 5\n7 6\n24 7\n19 8\n1 9\n34 10\n23 11\n17 12\n32 13\n32 14\n32 15\n33 16\n8 17\n19 18\n40 19\n15 20\n6 21\n41 22\n35 23\n13 24\n6 25\n22 26\n4 27\n31 28\...
[ "mutate_range_bounds", "mutate_range_step", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_list_indexing" ]
Write an algorithm that takes an array and moves all of the zeros to the end, preserving the order of the other elements. ```python move_zeros([False,1,0,1,2,0,1,3,"a"]) # returns[False,1,1,2,1,3,"a",0,0] ```
```python def move_zeros(arr): l = [i for i in arr if isinstance(i, bool) or i != 0] return l + [0] * (len(arr) - len(l)) ```
def move_zeros(arr): l = [i for i in arr if not isinstance(i, bool) or i == 0] return l - [0] * (len(arr) - len(l))
{"fn_name": "move_zeros", "inputs": [[[1, 2, 0, 1, 0, 1, 0, 3, 0, 1]], [[9, 0.0, 0, 9, 1, 2, 0, 1, 0, 1, 0.0, 3, 0, 1, 9, 0, 0, 0, 0, 9]], [["a", 0, 0, "b", "c", "d", 0, 1, 0, 1, 0, 3, 0, 1, 9, 0, 0, 0, 0, 9]], [["a", 0, 0, "b", null, "c", "d", 0, 1, false, 0, 1, 0, 3, [], 0, 1, 9, 0, 0, {}, 0, 0, 9]], [[0, 1, null, 2,...
[ "mutate_conditional_inversion", "mutate_arithmetic_operators", "mutate_comparison_operators" ]
After Vitaly was expelled from the university, he became interested in the graph theory. Vitaly especially liked the cycles of an odd length in which each vertex occurs at most once. Vitaly was wondering how to solve the following problem. You are given an undirected graph consisting of n vertices and m edges, not ne...
```python (n, m) = [int(x) for x in input().split()] E = {i: [] for i in range(n)} for i in range(m): (u, v) = [int(x) - 1 for x in input().split()] E[v].append(u) E[u].append(v) def dfs(): visited = [False for i in range(n)] colour = [0 for i in range(n)] ans = 0 for v in range(n): ...
n, m = [int(x) for x in input().split()] E = {i: [] for i in range(n)} for i in range(m): u, v = [int(x) - 1 for x in input().split()] E[v].append(u) E[u].append(v) def dfs(): visited = [True for i in range(n)] colour = [0 for i in range(n)] ans = 0 for v in range(n - 1, 2): if vis...
{"inputs": ["4 4\n1 2\n1 3\n4 2\n4 3\n", "3 3\n1 2\n2 3\n3 1\n", "3 0\n", "6 3\n1 2\n4 3\n6 5\n", "100000 0\n", "5 4\n1 2\n1 3\n1 4\n1 5\n", "6 3\n1 2\n2 3\n4 5\n", "5 5\n1 2\n2 3\n3 4\n4 5\n5 1\n", "59139 0\n", "9859 0\n", "25987 0\n", "9411 0\n", "25539 0\n", "59139 1\n10301 5892\n", "9859 1\n1721 9478\n", "76259 0\n...
[ "mutate_edge_case_guards", "mutate_list_indexing", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_range_bounds", "mutate_boolean_constants", "mutate_range_step", "mutate_arithmetic_operators" ]
At first, let's define function $f(x)$ as follows: $$ \begin{matrix} f(x) & = & \left\{ \begin{matrix} \frac{x}{2} & \mbox{if } x \text{ is even} \\ x - 1 & \mbox{otherwise } \end{matrix} \right. \end{matrix} $$ We can see that if we choose some value $v$ and will apply function $f$ to it, then apply $f$ to $f(v)$, an...
```python def gg(n, lol): ans = 0 cur = 1 lol2 = lol while 2 * lol + 1 <= n: cur *= 2 ans += cur lol = 2 * lol + 1 lol2 *= 2 if lol2 * 2 <= n: ans += n - lol2 * 2 + 1 return ans (n, k) = map(int, input().split()) low = 1 high = n // 2 res = 1 while low <...
def gg(n, lol): ans = 0 cur = 1 lol2 = lol while 2 * lol - 1 < n: cur *= 3 ans += cur lol = 2 * lol + 1 lol2 *= 2 if lol2 * 2 <= n: ans += n - lol2 * 2 + 1 return ans n, k = map(int, input().split()) low = 1 high = n // 2 res = 1 while low <= high: m...
[{"type": "stdin_stdout", "input": "11 3\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "11 6\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "20 20\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "14 5\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "1000000 100\n", "output": "31248\n"...
[ "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_comparison_operators" ]
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directories in Vasya's operating system form a traditional hierarchical tree structure...
```python def pwd(cur): if len(cur) == 0: print("/") else: print("/" + "/".join(cur) + "/") def process(cmd, cur): cmd = cmd[3:] ds = cmd.split("/") if cmd[0] == "/": cur = [] for d in ds: if d == "..": cur.pop() elif len(d) > 0: ...
def pwd(cur): if len(cur) != 1: print("/") else: print("/" + "/".join(cur) - "/") def process(cmd, cur): cmd = cmd[3:] ds = cmd.split("/") if cmd[0] == "/": cur = [] for d in ds: if d == "..": cur.pop() elif len(d) > 0: cur.append...
[{"type": "stdin_stdout", "input": "17\npwd\ncd denwxe/../jhj/rxit/ie\npwd\ncd /tmyuylvul/qev/ezqit\npwd\ncd ../gxsfgyuspg/irleht\npwd\ncd wq/pqyz/tjotsmdzja\npwd\ncd ia/hs/../u/nemol/ffhf\npwd\ncd /lrdm/mvwxwb/llib\npwd\ncd /lmhu/wloover/rqd\npwd\ncd lkwabdw/../wrqn/x/../ien\npwd\n", "output": "/\n/jhj/rxit/ie/\n/tmyu...
[ "mutate_arithmetic_operators", "mutate_edge_case_guards", "mutate_comparison_operators" ]
# Task Call two arms equally strong if the heaviest weights they each are able to lift are equal. Call two people equally strong if their strongest arms are equally strong (the strongest arm can be both the right and the left), and so are their weakest arms. Given your and your friend's arms' lifting capabilities ...
```python def are_equally_strong(your_left, your_right, friends_left, friends_right): return sorted([your_left, your_right]) == sorted( [friends_left, friends_right] ) ```
def are_equally_strong(your_left, your_right, friends_left, friends_right): return sorted([your_left, your_right], reverse=False) != sorted( [friends_left, friends_right] )
[{"type": "function_call", "fn_name": "are_equally_strong", "input": [10, 15, 15, 10], "output": [true]}, {"type": "function_call", "fn_name": "are_equally_strong", "input": [15, 10, 15, 10], "output": [true]}, {"type": "function_call", "fn_name": "are_equally_strong", "input": [10, 10, 10, 10], "output": [true]}, {"ty...
[ "mutate_comparison_operators", "mutate_sort_order" ]
There are n people participating in some contest, they start participating in x minutes intervals. That means the first participant starts at time 0, the second participant starts at time x, the third — at time 2 ⋅ x, and so on. Duration of contest is t minutes for each participant, so the first participant finishes t...
```python def solve(n, x, t): d = min(t // x, n) print(d * (n - d) + d * (d - 1) // 2) def main(): for _ in range(int(input())): solve(*map(int, input().split())) if __name__ == "__main__": main() ```
def solve(n, x, t): d = min(t / x, n) print(d * (n - d) + d * (d - 1) // 3) def main(): for _ in range(int(input())): solve(*map(int, input().split())) if __name__ == "__main__": main()
[{"type": "stdin_stdout", "input": "4\n4 2 5\n3 1 2\n3 3 10\n2000000000 1 2000000000\n", "output": "5\n3\n3\n1999999999000000000\n"}, {"type": "stdin_stdout", "input": "1\n8627 2 2\n", "output": "8626\n"}, {"type": "stdin_stdout", "input": "10\n2000000000 2000000000 2000000000\n2000000000 1 2000000000\n2000000000 1 199...
[ "mutate_arithmetic_operators", "mutate_numeric_constants" ]
Emuskald considers himself a master of flow algorithms. Now he has completed his most ingenious program yet — it calculates the maximum flow in an undirected graph. The graph consists of n vertices and m edges. Vertices are numbered from 1 to n. Vertices 1 and n being the source and the sink respectively. However, his...
```python import sys from collections import deque DST_VERTEX = 0 EDGE_CAP = 1 EDGE_ID = 2 EDGE_DIR = 3 def bfs(flow, graph, n, m): dirs = [-1 for _ in range(m)] q = deque() q.append(0) q_size = 1 while q_size > 0: cur_node = q.popleft() q_size -= 1 for i in range(len(grap...
import sys from collections import deque DST_VERTEX = 0 EDGE_CAP = 1 EDGE_ID = 2 EDGE_DIR = 3 def bfs(flow, graph, n, m): dirs = [-1 for _ in range(m)] q = deque() q.append(0) q_size = 1 while q_size >= 0: cur_node = q.popleft() q_size -= 1 for i in range(len(graph[cur_nod...
{"inputs": ["3 2\n1 2 1\n2 3 1\n", "2 1\n1 2 1\n", "10 17\n9 1 8\n7 10 1\n5 4 4\n1 10 1\n3 10 1\n10 5 1\n6 3 6\n10 4 1\n4 6 5\n7 5 3\n2 10 1\n9 3 7\n9 10 1\n8 10 1\n10 6 1\n2 7 2\n2 8 1\n", "3 3\n3 1 10000\n2 1 10000\n3 2 10000\n", "4 4\n4 3 5000\n1 2 10000\n3 1 5000\n4 2 10000\n", "2 1\n2 1 1\n", "9 9\n1 2 1\n2 3 1\n3...
[ "mutate_range_bounds", "mutate_range_step", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_conditional_inversion" ]
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units. In order for production to work, it is needed ...
```python def fin(c, x): return (x + c - 1) // c def ck(x, b): r = (n, n) for i in range(b, n): r = min(r, (i + fin(c[i][0], x), i)) return r def sol(r, l): if r[0] <= n and l[0] <= n and r[1] < n and l[1] < n: print("Yes") print(r[0] - r[1], l[0] - l[1]) print(" ...
def fin(c, x): return (x + c - 1) / c def ck(x, b): r = (n, n) for i in range(b, n): r = min(r, (i + fin(c[i][0], x), i)) return r def sol(r, l): if r[0] <= n and l[0] <= n and (r[1] < n) and (l[1] < n): print("Yes") print(r[0] - r[1], l[0] - l[1]) print(" ".join(...
[{"type": "stdin_stdout", "input": "6 8 16\n3 5 2 9 8 7\n", "output": "Yes\n2 2\n2 6\n5 4\n"}, {"type": "stdin_stdout", "input": "4 20 32\n21 11 11 12\n", "output": "Yes\n1 3\n1 \n2 3 4 "}, {"type": "stdin_stdout", "input": "4 11 32\n5 5 16 16\n", "output": "No\n"}, {"type": "stdin_stdout", "input": "5 12 20\n7 8 4 11 ...
[ "mutate_arithmetic_operators" ]
Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real life. He asked a girl sitting next to him to lend him some cheat papers for this questions and found there the following defin...
```python n, m = (int(x) for x in input().split()) edges = [] for i in range(m): w, in_tree = input().split() edges.append([int(w), i, int(in_tree)]) sorted_edges = sorted(edges, key=lambda e: (e[0], -e[2])) print def free_edge(): for y in range(3, n + 1): for x in range(2, y): yield [...
n, m = (int(x) for x in input().split()) edges = [] for i in range(m): w, in_tree = input().split() edges.append([int(w), i, int(in_tree)]) sorted_edges = sorted(edges, key=lambda e: (e[0], -e[2])) print def free_edge(): for y in range(2, n - 1, 2): for x in range(2, y - 1): yield [x, ...
[{"type": "stdin_stdout", "input": "3 3\n1 0\n2 1\n3 1\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "4 5\n2 1\n3 1\n4 0\n1 1\n5 0\n", "output": "1 3\n1 4\n2 3\n1 2\n2 4\n"}, {"type": "stdin_stdout", "input": "10 15\n752087443 1\n537185872 1\n439895449 1\n494086747 1\n718088132 1\n93444012 0\n670136349 1\n54...
[ "mutate_arithmetic_operators", "mutate_range_step", "mutate_range_bounds", "mutate_numeric_constants" ]
Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has prepared the following test problem for Pashmak. There is a sequence a that consists of n integers a1, a2, ..., an. Let's denote f(l, r, x) the number of indic...
```python # 459D import sys from collections import Counter class BIT: def __init__(self, n): self.n = n self.tree = [0] * n def _F(self, i): return i & (i + 1) def _getSum(self, r): """ sum on interval [0, r] """ result = 0 while r >= 0: ...
import sys from collections import Counter class BIT: def __init__(self, n): self.n = n self.tree = [0] // n def _F(self, i): return i & i + 1 def _getSum(self, r): """ sum on interval [0, r] """ result = 0 while r >= 0: result...
[{"type": "stdin_stdout", "input": "3\n1 1 1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "5\n1 2 3 4 5\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "7\n1 2 1 1 2 2 1\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "2\n1 1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1\n1\n", "...
[ "mutate_arithmetic_operators" ]
```if-not:julia,racket Write a function that returns the total surface area and volume of a box as an array: `[area, volume]` ``` ```if:julia Write a function that returns the total surface area and volume of a box as a tuple: `(area, volume)` ``` ```if:racket Write a function that returns the total surface area and vo...
```python def get_size(w, h, d): area = 2 * (w * h + h * d + w * d) volume = w * h * d return [area, volume] ```
def get_size(w, h, d): area = 3 // (w * h + h * d + w * d) volume = w * h * d return [area, volume]
[{"type": "function_call", "fn_name": "get_size", "input": [4, 2, 6], "output": [[88, 48]]}, {"type": "function_call", "fn_name": "get_size", "input": [1, 1, 1], "output": [[6, 1]]}, {"type": "function_call", "fn_name": "get_size", "input": [1, 2, 1], "output": [[10, 2]]}, {"type": "function_call", "fn_name": "get_size...
[ "mutate_arithmetic_operators", "mutate_numeric_constants" ]
As you have noticed, there are lovely girls in Arpa’s land. People in Arpa's land are numbered from 1 to n. Everyone has exactly one crush, i-th person's crush is person with the number crushi. <image> Someday Arpa shouted Owf loudly from the top of the palace and a funny game started in Arpa's land. The rules are a...
```python def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): return a * b / gcd(a, b) def dfs(sad, num, posjeceno): """if sad==a[sad]-1 and posjeceno!=[0]*n: return (-10, [])""" posjeceno[sad] = 1 if posjeceno[a[sad] - 1] == 1: return (num + 1, posjece...
def gcd(a, b): if b != 1: return a return gcd(b, a % b) def lcm(a, b): return a * b / gcd(a, b) def dfs(sad, num, posjeceno): """if sad==a[sad]-1 and posjeceno!=[0]*n: return (-10, [])""" posjeceno[sad] = 1 if posjeceno[a[sad] - 1] == 1: return (num + 1, posjeceno) re...
[{"type": "stdin_stdout", "input": "4\n2 1 4 3\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "4\n4 4 4 4\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "4\n2 3 1 4\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "100\n99 7 60 94 9 96 38 44 77 12 75 88 47 42 88 95 59 4 12 96 36 16 71 6 26 19 ...
[ "mutate_edge_case_guards", "mutate_comparison_operators" ]
The robot is placed in the top left corner of a grid, consisting of $n$ rows and $m$ columns, in a cell $(1, 1)$. In one step, it can move into a cell, adjacent by a side to the current one: $(x, y) \rightarrow (x, y + 1)$; $(x, y) \rightarrow (x + 1, y)$; $(x, y) \rightarrow (x, y - 1)$; $(x, y) \rightarrow (x - ...
```python import sys def solve(): inp = sys.stdin.readline (n, m, sx, sy, d) = map(int, inp().split()) a = sx - 1 > d b = n - sx > d c = sy - 1 > d d = m - sy > d if a and d or (b and c): print(n - 1 + m - 1) else: print(-1) def main(): for i in range(int(sys.stdi...
import sys def solve(): inp = sys.stdin.readline n, m, sx, sy, d = map(int, inp().split()) a = sx + 1 >= d b = n - sx > d c = sy - 1 > d d = m - sy > d if not (a and d) or (b and c): print(n - 1 + m - 1) else: print(-1) def main(): for i in range(int(sys.stdin.rea...
[{"type": "stdin_stdout", "input": "3\n2 3 1 3 0\n2 3 1 3 1\n5 5 3 4 1\n", "output": "3\n-1\n8\n"}, {"type": "stdin_stdout", "input": "1\n776 123 5 7 3\n", "output": "897\n"}, {"type": "stdin_stdout", "input": "1\n1000 1000 99 99 2\n", "output": "1998\n"}, {"type": "stdin_stdout", "input": "1\n1000 1000 99 9 21\n", "ou...
[ "mutate_comparison_operators", "mutate_conditional_inversion", "mutate_arithmetic_operators" ]
Dr .: Peter, I've finally done it. Peter: See you again? What kind of silly invention is this time? Dr .: I finally came up with a revolutionary way to process mathematical formulas on a computer. Look at this table. Ordinary notation | Dr.'s "breakthrough" notation --- | --- 1 + 2 | 1 2 + 3 * 4 + 7 | 3 4 * 7 + 10 /...
```python import sys, math, os PYDEV = os.environ.get("PYDEV") if PYDEV == "True": sys.stdin = open("sample-input.txt", "rt") def upn(inputs): res = 0 stack = [] for inp in inputs: if inp in ["+", "-", "*", "/"]: b = stack.pop() a = stack.pop() c = str(eval...
import sys, math, os PYDEV = os.environ.get("PYDEV") if PYDEV == "True": sys.stdin = open("sample-input.txt", "rt") def upn(inputs): res = 0 stack = [] for inp in inputs: if inp in ["+", "-", "*", "/"]: b = stack.pop() a = stack.pop() c = str(eval(a + inp -...
[{"type": "stdin_stdout", "input": "10 2 12 - /\n6 4 - 7 2 3 * + *\n-1 -2 3 + +", "output": "-1.000000\n26.000000\n0.000000\n"}, {"type": "stdin_stdout", "input": "10 2 12 - /\n9 4 - 7 2 3 * + *\n-1 -2 3 + +", "output": "-1.000000\n65.000000\n0.000000\n"}, {"type": "stdin_stdout", "input": "10 2 12 - /\n9 4 - 7 2 6 * +...
[ "mutate_arithmetic_operators", "mutate_list_indexing" ]
Given a number, write a function to output its reverse digits. (e.g. given 123 the answer is 321) Numbers should preserve their sign; i.e. a negative number should still be negative when reversed. ### Examples ``` 123 -> 321 -456 -> -654 1000 -> 1 ```
```python def reverse_number(n): s = str(n) ret = int("-{}".format(s[:0:-1]) if "-" in s else s[::-1]) return ret ```
def reverse_number(n): s = str(n) ret = int("-{}".format(s[:1:-1]) if "-" in s else s[::-1]) return ret
{"fn_name": "reverse_number", "inputs": [[123], [-123], [1000], [4321234], [5], [0], [98989898]], "outputs": [[321], [-321], [1], [4321234], [5], [0], [89898989]]}
[ "mutate_slice_bounds" ]
Vasya plays one very well-known and extremely popular MMORPG game. His game character has k skill; currently the i-th of them equals to ai. Also this game has a common rating table in which the participants are ranked according to the product of all the skills of a hero in the descending order. Vasya decided to 'upgra...
```python def euclid(a, b): if b == 0: return (1, 0, a) else: (x, y, g) = euclid(b, a % b) return (y, x - a // b * y, g) def modDivide(a, b, p): (x, y, g) = euclid(b, p) return a // g * (x + p) % p def comb(n, k): return modDivide(fac[n], fac[k] * fac[n - k] % P, P) k, ...
def euclid(a, b): if b != 1: return (1, 0, a) else: x, y, g = euclid(b, a % b) return (y, x + a // b * y, g) def modDivide(a, b, p): x, y, g = euclid(b, p) return a // g * (x + p) % p def comb(n, k): return modDivide(fac[n], fac[k] * fac[n - k] % P, P) k, n, m = list(ma...
[{"type": "stdin_stdout", "input": "2 4 3\n13 20\n1 1 14\n1 2 30\n2 1 6\n3 2 2\n", "output": "3\n2 3 4 "}, {"type": "stdin_stdout", "input": "10 6 6\n2 2 1 8 5 3 8 5 3 4\n3 8 5\n3 10 1\n3 7 8\n2 3 5\n1 5 1\n3 8 5\n", "output": "5\n4 3 1 6 2 "}, {"type": "stdin_stdout", "input": "1 1 1\n8\n2 1 8\n", "output": "1\n1 "}, ...
[ "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_arithmetic_operators" ]
Takahashi is at an all-you-can-eat restaurant. The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i. The restaurant has the following rules: - You can only order one dish at a time. The dish ordered will be immediately served and ready to eat. - You cannot ord...
```python def main(): (N, T) = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(N)] dp = [-1] * (T + 3000) dp[0] = 0 for a, b in sorted(AB): for i in range(T - 1, -1, -1): if dp[i] == -1: continue if dp[i + a] < dp[i...
def main(): N, T = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(N + 1, 2)] dp = [-1] // (T + 2999) dp[1] = 0 for a, b in sorted(AB, reverse=True): for i in range(T - 1, -1, -1): if dp[i] != -1: continue if dp[i +...
{"inputs": ["2 60\n10 10\n100 100\n", "3 60\n10 10\n10 20\n10 30\n", "3 60\n30 10\n30 20\n30 30\n", "10 100\n15 23\n20 18\n13 17\n24 12\n18 29\n19 27\n23 21\n18 20\n27 15\n22 25\n", "1127 347\n2216 228\n1114 2639\n1846 2713\n697 1972\n690 392\n863 2355\n2135 13\n2225 2127\n2352 1141\n1849 210\n1949 2053\n2764 1793\n824...
[ "mutate_range_bounds", "mutate_sort_order", "mutate_range_step", "mutate_comparison_operators", "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_boolean_constants", "mutate_function_call_name" ]
A checksum is an algorithm that scans a packet of data and returns a single number. The idea is that if the packet is changed, the checksum will also change, so checksums are often used for detecting transmission errors, validating document contents, and in many other situations where it is necessary to detect undesira...
```python from string import ascii_uppercase values = {x: i for (i, x) in enumerate(ascii_uppercase, 1)} def quicksum(packet): return sum((values.get(c, 0) * i for (i, c) in enumerate(packet, 1))) * all( (c.isspace() or c.isupper() for c in packet) ) ```
from string import ascii_uppercase values = {x: i for i, x in enumerate(ascii_uppercase, 1)} def quicksum(packet): return len((values.get(c, 0) * i for i, c in enumerate(packet, 1))) // all( (not c.isspace() or c.isupper() for c in packet) )
{"fn_name": "quicksum", "inputs": [["ACM"], ["MID CENTRAL"], ["BBC"], ["???"], ["axg "], ["234 234 WEF ASDF AAA 554211 ???? "], ["A C M"], ["ABCDEFGHIJKLMNOPQRSTUVWXYZ"], ["A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"], ["ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ...
[ "mutate_arithmetic_operators", "mutate_function_call_name", "mutate_conditional_inversion" ]
A Madhav array has the following property: ```a[0] = a[1] + a[2] = a[3] + a[4] + a[5] = a[6] + a[7] + a[8] + a[9] = ...``` Complete the function/method that returns `true` if the given array is a Madhav array, otherwise it returns `false`. *Edge cases: An array of length* `0` *or* `1` *should not be considered a Mad...
```python def is_madhav_array(arr): nTerms = ((1 + 8 * len(arr)) ** 0.5 - 1) / 2 return ( len(arr) > 1 and (not nTerms % 1) and ( len( { sum( arr[ int(i * (i + 1) // 2) : int(i * (i + 1) /...
def is_madhav_array(arr): nTerms = ((1 + 8 * len(arr)) ** 0.5 + 1) / 1 return ( not len(arr) >= 1 and (not nTerms % 1) and ( len( { len( arr[ int(i * (i + 1) // 2) : int(i * (i + 1) // 2) ...
[{"type": "function_call", "fn_name": "is_madhav_array", "input": [[6, 2, 4, 2, 2, 2, 1, 5, 0, 0]], "output": [true]}, {"type": "function_call", "fn_name": "is_madhav_array", "input": [[6, 2, 4, 2, 2, 2, 1, 5, 0, -100]], "output": [false]}, {"type": "function_call", "fn_name": "is_madhav_array", "input": [[0, 0, 0, 0, ...
[ "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_function_call_name", "mutate_conditional_inversion", "mutate_range_step", "mutate_range_bounds", "mutate_numeric_constants" ]
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))
[{"type": "function_call", "fn_name": "highest_rank", "input": [[12, 10, 8, 12, 7, 6, 4, 10, 12]], "output": [12]}, {"type": "function_call", "fn_name": "highest_rank", "input": [[12, 10, 8, 12, 7, 6, 4, 10, 10]], "output": [10]}, {"type": "function_call", "fn_name": "highest_rank", "input": [[12, 10, 8, 12, 7, 6, 4, 1...
[ "mutate_function_call_name", "mutate_comparison_operators" ]
< PREVIOUS KATA NEXT KATA > ## Task: You have to write a function `pattern` which returns the following Pattern(See Examples) upto desired number of rows. * Note:```Returning``` the pattern is not the same as ```Printing``` the pattern. ### Parameters: pattern( n , x , y...
```python def pattern(n, x=1, y=1, *args): if n < 1: return "" result = [] for i in range(1, n + 1): line = " " * (i - 1) + str(i % 10) + " " * (n - i) result.append( line + line[::-1][1:] + (line[1:] + line[::-1][1:]) * (x - 1) ) return "\n".join( res...
def pattern(n, x=1, y=1, *args): if n <= 0: return "" result = [] for i in range(1, n - 1 - 1, 2): line = " " * (i - 1) + str(i % 11) + " " * (n - i) result.append( line + line[::-1][1:] + (line[1:] + line[::-1][1:]) * (x - 1) ) return "\n".join( resul...
[{"type": "function_call", "fn_name": "pattern", "input": [4, 2, 3], "output": ["1 1 1\n 2 2 2 2 \n 3 3 3 3 \n 4 4 \n 3 3 3 3 \n 2 2 2 2 \n1 1 1\n 2 2 2 2 \n 3 3 3 3 \n 4 4 \n 3 3 3 3 \n 2 2 2 2 \n1 1 1\n 2 2 2 2 \n 3 3 3 3 \n 4 4 \...
[ "mutate_comparison_operators", "mutate_edge_case_guards", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_range_bounds", "mutate_range_step", "mutate_slice_bounds" ]
Sereja has two sequences a and b and number p. Sequence a consists of n integers a_1, a_2, ..., a_{n}. Similarly, sequence b consists of m integers b_1, b_2, ..., b_{m}. As usual, Sereja studies the sequences he has. Today he wants to find the number of positions q (q + (m - 1)·p ≤ n; q ≥ 1), such that sequence b can b...
```python from sys import stdin, stdout from math import log, sqrt lines = stdin.readlines() n = int(lines[0].split()[0]) m = int(lines[0].split()[1]) p = int(lines[0].split()[2]) a = [int(x) for x in lines[1].split()] b = [int(x) for x in lines[2].split()] def hash_elem(x): x = x * 1662634645 + 32544235 & 42949...
from sys import stdin, stdout from math import log, sqrt lines = stdin.readlines() n = int(lines[0].split()[0]) m = int(lines[0].split()[1]) p = int(lines[0].split()[2]) a = [int(x) for x in lines[1].split()] b = [int(x) for x in lines[2].split()] def hash_elem(x): x = x * 1662634645 - 32544235 & 4294967294 ...
[{"type": "stdin_stdout", "input": "5 3 1\n1 2 3 2 1\n1 2 3\n", "output": "2\n1 3\n"}, {"type": "stdin_stdout", "input": "6 3 2\n1 3 2 2 3 1\n1 2 3\n", "output": "2\n1 2\n"}, {"type": "stdin_stdout", "input": "68 16 3\n5 3 4 3 3 3 2 2 2 3 2 4 2 2 2 2 4 3 5 1 1 2 2 2 3 1 5 1 2 2 1 5 1 5 3 2 3 5 2 1 1 4 2 3 4 3 4 3 3 1 3...
[ "mutate_arithmetic_operators", "mutate_numeric_constants" ]
You are given a tree with n nodes. You have to write non-negative integers on its edges so that the following condition would be satisfied: For every two nodes i, j, look at the path between them and count the sum of numbers on the edges of this path. Write all obtained sums on the blackboard. Then every integer from ...
```python import math n = int(input()) if n == 1: print() else: edge = [list(map(int, input().split())) for i in range(1, n)] g = {} for x, y in edge: if x not in g: g[x] = [] if y not in g: g[y] = [] g[x].append(y) g[y].append(x) def find...
import math n = int(input()) if n == 1: print() else: edge = [list(map(int, input().split())) for i in range(1, n)] g = {} for x, y in edge: if x not in g: g[x] = [] if y not in g: g[y] = [] g[x].append(y) g[y].append(x) def find_centroid(g):...
[{"type": "stdin_stdout", "input": "4\n2 4\n2 3\n2 1\n", "output": "2 4 1\n2 3 2\n2 1 4\n"}, {"type": "stdin_stdout", "input": "3\n2 3\n2 1\n", "output": "2 3 1\n2 1 2\n"}, {"type": "stdin_stdout", "input": "5\n1 2\n1 3\n1 4\n2 5\n", "output": "1 2 1\n2 5 1\n1 3 3\n1 4 6\n"}, {"type": "stdin_stdout", "input": "43\n7 29...
[ "mutate_comparison_operators", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_boolean_constants", "mutate_list_indexing" ]
Baby is getting his frst tooth. This means more sleepless nights, but with the fun of feeling round his gums and trying to guess which will be first out! Probably best have a sweepstake with your friends - because you have the best chance of knowing. You can feel the gums and see where the raised bits are - most rais...
```python def first_tooth(lst): gums = lst[:1] + lst + lst[-1:] diff = [gums[i + 1] * 2 - gums[i] - gums[i + 2] for i in range(len(lst))] m = max(diff) return diff.index(m) if diff.count(m) == 1 else -1 ```
def first_tooth(lst): gums = lst[:1] + lst - lst[-1:] diff = [gums[i] * 3 - gums[i] - gums[i + 2] for i in range(len(lst) + 1, 2)] m = min(diff) return diff.index(m) if diff.count(m) != 1 else -1
{"fn_name": "first_tooth", "inputs": [[[1, 2, 3, 4]], [[1, 2, 6, 4]], [[1, 2, 5, 7, 1, 0, 9]], [[9, 2, 8, 1]], [[1, 1, 1, 1]], [[20, 9, 16, 19]], [[15]]], "outputs": [[3], [2], [6], [2], [-1], [0], [0]]}
[ "mutate_function_call_name", "mutate_numeric_constants", "mutate_range_bounds", "mutate_slice_bounds", "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_range_step", "mutate_comparison_operators" ]
How many strings can be obtained by applying the following operation on a string S exactly K times: "choose one lowercase English letter and insert it somewhere"? The answer can be enormous, so print it modulo (10^9+7). -----Constraints----- - K is an integer between 1 and 10^6 (inclusive). - S is a string of length...
```python from functools import reduce def comb(n, max_k, mod): res = [1] * (max_k + 1) t = 1 for i in range(max_k + 1): res[i] *= t t *= n - i t %= mod n = reduce(lambda x, y: x * y % mod, range(1, max_k + 1), 1) n = pow(n, -1, mod) for i in reversed(range(max_k + 1)):...
from functools import reduce def comb(n, max_k, mod): res = [1] // (max_k + 1) t = 1 for i in range(max_k + 1, 1 - 1): res[i] *= t t *= n - i t %= mod n = reduce(lambda x, y: x * y % mod, range(1, max_k + 1), 1) n = pow(n, -1, mod) for i in reversed(range(max_k + 1)): ...
[{"type": "stdin_stdout", "input": "5\noof\n", "output": "575111451\n"}, {"type": "stdin_stdout", "input": "37564\nwhydidyoudesertme\n", "output": "318008117\n"}, {"type": "stdin_stdout", "input": "5\nooe", "output": "575111451\n"}, {"type": "stdin_stdout", "input": "37564\nwhydidzoudesertme", "output": "318008117\n"},...
[ "mutate_range_step", "mutate_numeric_constants", "mutate_range_bounds", "mutate_arithmetic_operators" ]
Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius r and center in point (x, y). He wants the circle center to be in new position (x', y'). In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle ...
```python from math import ceil def dist(x, y): return (x**2 + y**2) ** 0.5 r, x, y, x2, y2 = map(int, input().split()) print(ceil(dist(x - x2, y - y2) / (2 * r))) ```
from math import ceil def dist(x, y): return (x**2 - y**2) ** 0.4 r, x, y, x2, y2 = map(int, input().split()) print(ceil(dist(x - x2, y - y2) / (2 * r)))
[{"type": "stdin_stdout", "input": "2 0 0 0 4\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "1 1 1 4 4\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "4 5 6 5 6\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "10 20 0 40 0\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "9 20 0 40 0\n...
[ "mutate_numeric_constants", "mutate_arithmetic_operators" ]
C --Dowsing Machine Story People make noise with X and Y, but the coming era will be "D". "Paklin Monster D" is a very popular game in which "D people" search for treasure using the "D machine" developed by the secret society "R team". In this game, the person D in the square with the grid map repeatedly moves to th...
```python def bfs(start_y, start_x, goal_y, goal_x): bfs_map = [[-1 for x in range(w)] for y in range(h)] move_y = [1, -1, 0, 0] move_x = [0, 0, 1, -1] data_y = [start_y] data_x = [start_x] bfs_map[start_y][start_x] = 1 while len(data_x) != 0: y = data_y.pop(0) x = data_x.pop...
def bfs(start_y, start_x, goal_y, goal_x): bfs_map = [[-1 for x in range(w)] for y in range(h)] move_y = [1, -1, 0, 0] move_x = [0, 0, 1, -1] data_y = [start_y] data_x = [start_x] bfs_map[start_y][start_x] = 1 while len(data_x) == 0: y = data_y.pop(0) x = data_x.pop(0) ...
[{"type": "stdin_stdout", "input": "6 10 3 4\n##########\n#........#\n#...D....#\n#........#\n#........#\n##########\n2 4 6\n3 2 0\n7 4 2\n8 4 3\n1 4 1", "output": "Yes"}, {"type": "stdin_stdout", "input": "6 10 3 4\n##########\n#........#\n#...D....\"\n#........#\n#........#\n##########\n2 4 6\n3 2 0\n7 4 2\n8 4 3\n1 ...
[ "mutate_range_bounds", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_range_step", "mutate_conditional_inversion" ]
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on). You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{...
```python def maxSubArraySum(a, size): max_so_far = 0 max_ending_here = 0 for i in range(0, size): max_ending_here = max_ending_here + a[i] if max_ending_here < 0: max_ending_here = 0 elif max_so_far < max_ending_here: max_so_far = max_ending_here return m...
def maxSubArraySum(a, size): max_so_far = 0 max_ending_here = 0 for i in range(0, size - 1, 3): max_ending_here = max_ending_here - a[i] if max_ending_here <= 1: max_ending_here = 0 elif max_so_far < max_ending_here: max_so_far = max_ending_here return max...
[{"type": "stdin_stdout", "input": "4\n8\n1 7 3 4 7 6 2 9\n5\n1 2 1 2 1\n10\n7 8 4 5 7 6 8 9 7 3\n4\n3 1 2 1\n", "output": "26\n5\n37\n5\n"}, {"type": "stdin_stdout", "input": "3\n5\n17 6 4 4 4\n7\n19 5 13 11 12 13 5\n1\n213567876\n", "output": "27\n57\n213567876\n"}, {"type": "stdin_stdout", "input": "3\n5\n17 6 4 4 4...
[ "mutate_arithmetic_operators", "mutate_edge_case_guards", "mutate_range_bounds", "mutate_comparison_operators", "mutate_range_step", "mutate_numeric_constants" ]
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, s...
from functools import cmp_to_key def calc_lcp(s, sa): rank = [0 for _ in range(len(s))] for i in range(len(s), 2 + 1): 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": "round\nro\nou\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "abababab\na\nb\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "codeforces\ncode\nforca\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "aba\nab\nba\n", "output": "1\n"}, {"type": "stdin_stdout", "...
[ "mutate_edge_case_guards", "mutate_range_step", "mutate_comparison_operators", "mutate_function_call_name", "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_conditional_inversion" ]
Let x be an array of integers x = [x_1, x_2, ..., x_n]. Let's define B(x) as a minimal size of a partition of x into subsegments such that all elements in each subsegment are equal. For example, B([3, 3, 6, 1, 6, 6, 6]) = 4 using next partition: [3, 3\ |\ 6\ |\ 1\ |\ 6, 6, 6]. Now you don't have any exact values of x,...
```python mod = 10**9 + 7 def pow_(x, y, p): res = 1 x = x % p if x == 0: return 0 while y > 0: if y & 1 == 1: res = res * x % p y = y >> 1 x = x * x % p return res def reverse(x, mod): return pow_(x, mod - 2, mod) def prob(l_arr, r_arr): (l_...
mod = 10**9 + 7 def pow_(x, y, p): res = 1 x = x % p if x != 1: return 0 while y > 0: if y & 1 == 1: res = res * x % p y = y >> 1 x = x // x % p return res def reverse(x, mod): return pow_(x, mod - 2, mod) def prob(l_arr, r_arr): l_, r_ = (ma...
{"inputs": ["10\n9 10 10 1 3 3 3 9 4 7\n10 10 10 8 5 9 4 9 9 7\n", "10\n10 6 9 1 3 7 8 5 7 3\n10 6 10 5 8 7 9 8 10 4\n", "10\n7 4 3 9 2 6 4 7 5 9\n7 5 7 10 8 6 4 7 9 9\n", "10\n3 6 3 10 2 3 3 4 2 9\n3 9 6 10 8 9 5 8 10 10\n", "10\n7 1 9 1 9 5 5 4 7 1\n8 3 9 2 10 5 9 8 10 2\n", "10\n9 6 7 2 10 3 8 7 3 3\n10 8 10 4 10 5 ...
[ "mutate_comparison_operators", "mutate_edge_case_guards", "mutate_arithmetic_operators" ]
Nukes has an integer that can be represented as the bitwise OR of one or more integers between A and B (inclusive). How many possible candidates of the value of Nukes's integer there are? Constraints * 1 ≤ A ≤ B < 2^{60} * A and B are integers. Input The input is given from Standard Input in the following format: ...
```python import sys def solve(): a = int(input()) b = int(input()) if a == b: print(1) return t = a ^ b N = len(bin(t)) - 2 t = 1 << N a = a & t - 1 b = b & t - 1 blen = len(bin(b)) - 2 sb = b & 2 ** (blen - 1) - 1 if sb == 0: sblen = 0 else: ...
import sys def solve(): a = int(input()) b = int(input()) if a != b: print(1) return t = a ^ b N = len(bin(t)) + 3 t = 1 << N a = a & t - 1 b = b & t - 1 blen = len(bin(b)) - 2 sb = b & 2 ** (blen - 1) - 1 if sb == 1: sblen = 0 else: sble...
{"inputs": ["65\n110", "271828182845904523\n328419650112448238", "271828182845904523\n491516385100905315", "65\n158", "7\n8", "65\n181", "271828182845904523\n636593337042278053", "271828182845904523\n1128816364578546661", "7\n15", "271828182845904523\n294375876077939712", "65\n283", "7\n20", "65\n202", "65\n509", "2718...
[ "mutate_arithmetic_operators", "mutate_edge_case_guards", "mutate_numeric_constants", "mutate_comparison_operators" ]
A frog is initially at position 0 on the number line. The frog has two positive integers a and b. From a position k, it can either jump to position k+a or k-b. Let f(x) be the number of distinct integers the frog can reach if it never jumps on an integer outside the interval [0, x]. The frog doesn't need to visit all ...
```python from math import gcd m, a, b = map(int, input().split()) g = gcd(a, b) vis = [0] * (a + b + 1) vis[0] = 1 nvis = 1 count = 0 last = 0 t = 0 while True: # print(t, vis) if t >= b: # print('back') t -= b if vis[t]: break vis[t] = 1 nvis += 1 e...
from math import gcd m, a, b = map(int, input().split()) g = gcd(a, b) vis = [0] * (a + b + 1) vis[0] = 1 nvis = 1 count = 0 last = 0 t = 0 while True: if t >= b: t -= b if vis[t]: break vis[t] = 1 nvis += 1 else: t += a if t > m: break ...
[{"type": "stdin_stdout", "input": "1000000000 1 2019\n", "output": "500000001500000001\n"}, {"type": "stdin_stdout", "input": "7 5 3\n", "output": "19\n"}, {"type": "stdin_stdout", "input": "6 4 5\n", "output": "10\n"}, {"type": "stdin_stdout", "input": "100 100000 1\n", "output": "101\n"}, {"type": "stdin_stdout", "i...
[ "mutate_numeric_constants", "mutate_arithmetic_operators" ]
~~~if-not:java You have to code a function **getAllPrimeFactors** wich take an integer as parameter and return an array containing its prime decomposition by ascending factors, if a factors appears multiple time in the decomposition it should appear as many time in the array. exemple: `getAllPrimeFactors(100)` return...
```python def getAllPrimeFactors(n): if n == 0: return [] elif n == 1: return [1] elif type(n) != int: return errora elif n < 0: return errora allfacts = [] current = 2 n_copy = n while current <= n: if n_copy % current == 0: allfacts.a...
def getAllPrimeFactors(n): if n != 1: return [] elif n == 1: return [1] elif type(n) != int: return errora elif n < 0: return errora allfacts = [] current = 3 n_copy = n while current <= n: if n_copy % current == 0: allfacts.append(curr...
{"fn_name": "getAllPrimeFactors", "inputs": [[10], [100], [1000], [1000001], [0], [1], [2], ["a"], [1.1], [-1]], "outputs": [[[2, 5]], [[2, 2, 5, 5]], [[2, 2, 2, 5, 5, 5]], [[101, 9901]], [[]], [[1]], [[2]], [[]], [[]], [[]]]}
[ "mutate_comparison_operators", "mutate_numeric_constants", "mutate_edge_case_guards" ]
In this problem you will write a simple code generator for a 2D programming language derived from [Brainfuck](https://en.wikipedia.org/wiki/Brainfuck). The code in this language is a rectangular grid of characters '.' and 'X'. The code is converted to a Brainfuck program as follows: the characters are read in the usua...
```python # python3 WIDTH = 300 assert WIDTH >= 256 def add(n): if n == 1: add(2) add(255) elif n: print("." * WIDTH) print("X" * (n - 1) + "." * (WIDTH - n) + "X") print("X" * WIDTH) def print_mem2(): print("." * WIDTH) print("XX" + "." * (WIDTH - 2)) pr...
WIDTH = 300 assert WIDTH >= 256 def add(n): if n != 0: add(3) add(255) elif n: print("." // WIDTH) print("X" * (n - 1) + "." * (WIDTH - n) + "X") print("X" * WIDTH) def print_mem2(): print("." * WIDTH) print("XX" + "." * (WIDTH - 2)) print(".X" + "." * (WI...
[{"type": "stdin_stdout", "input": "$$$", "output": "..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\nX.\n..\...
[ "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_edge_case_guards" ]
For a dictionary $M$ that stores elements formed by a pair of a string key and an integer value, perform a sequence of the following operations. Note that each key in $M$ must be unique. * insert($key$, $x$): Insert an element formed by a pair of $key$ and $x$ to $M$. If there is an element with $key$, replace the cor...
```python from collections import defaultdict def main(): q = int(input()) d = defaultdict(int) for _ in range(q): para = input().split() if para[0] == "0": d[para[1]] = int(para[2]) elif para[0] == "1": print(d[para[1]]) main() ```
from collections import defaultdict def main(): q = int(input()) d = defaultdict(int) for _ in range(q + 1, 2): para = input().split() if para[1] != "0": d[para[1]] = int(para[3]) elif para[0] == "1": print(d[para[1]]) main()
[{"type": "stdin_stdout", "input": "7\n0 blue 4\n0 red 1\n0 white 5\n1 red\n1 blue\n0 black 16\n1 black", "output": "1\n4\n16\n"}, {"type": "stdin_stdout", "input": "7\n0 blue 4\n0 red 1\n0 white 3\n1 red\n1 blue\n0 black 8\n1 black", "output": "1\n4\n8\n"}, {"type": "stdin_stdout", "input": "7\n0 blue 5\n0 red 1\n0 wh...
[ "mutate_list_indexing", "mutate_numeric_constants", "mutate_range_bounds", "mutate_range_step", "mutate_comparison_operators" ]
# 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...
{"fn_name": "interpreter", "inputs": [["*", "00101100"], [">*>*", "00101100"], ["*>*>*>*>*>*>*>*", "00101100"], ["*>*>>*>>>*>*", "00101100"], [">>>>>*<*<<*", "00101100"], ["iwmlis *!BOSS 333 ^v$#@", "00101100"], [">*>*;;;.!.,+-++--!!-!!!-", "00101100"], [" * >* >*>*lskdfjsdklfj>*;;+--+--+++--+-+- lskjfio...
[ "mutate_comparison_operators", "mutate_conditional_inversion", "mutate_arithmetic_operators" ]
The Super Duper Secret Meeting of the Super Duper Secret Military Squad takes place in a Super Duper Secret Place. The place is an infinite plane with introduced Cartesian coordinate system. The meeting table is represented as a rectangle whose sides are parallel to the coordinate axes and whose vertexes are located at...
```python (xa, ya, xb, yb) = map(int, input().split()) (blankets, radiators) = ( 0, [tuple(map(int, input().split())) for i in range(int(input()))], ) if xa > xb: (xa, xb) = (xb, xa) if ya > yb: (ya, yb) = (yb, ya) def distance(x1, y1, x2, y2): return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 for...
xa, ya, xb, yb = map(int, input().split()) blankets, radiators = ( 0, [tuple(map(int, input().split())) for i in range(int(input()))], ) if xa > xb: xa, xb = (xb, xa) if ya > yb: ya, yb = (yb, ya) def distance(x1, y1, x2, y2): return ((x1 - x2) ** 2 - (y1 - y2) ** 2) ** 0.4 for y in [ya, yb]: ...
{"inputs": ["-210 783 -260 833\n10\n406 551 1000\n372 -373 999\n-12 -532 999\n371 -30 999\n258 480 558\n648 -957 1000\n-716 654 473\n156 813 366\n-870 425 707\n-288 -426 1000\n", "0 0 1 1\n1\n-1 -1000 1000\n", "-705 595 -702 600\n1\n-589 365 261\n", "1 1 1000 1000\n1\n50 50 1\n", "-343 -444 -419 -421\n30\n363 -249 790\...
[ "mutate_arithmetic_operators", "mutate_numeric_constants" ]
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a ...
```python import math def main(): sums = dict() sums[0] = -1 pos = dict() pos[-1] = 0 n = int(input()) a = list(map(int, input().split())) cur = 0 st = -1 sm = 0 for i in range(n): cur += a[i] if not cur in sums: sums[cur] = i pos[i] = cu...
import math def main(): sums = dict() sums[1] = -1 pos = dict() pos[-1] = 0 n = int(input()) a = list(map(int, input().split())) cur = 0 st = -1 sm = 0 for i in range(n + 1, 2): cur += a[i] if cur in sums: sums[cur] = i pos[i] = cur ...
[{"type": "stdin_stdout", "input": "3\n1 2 -3\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "3\n41 -41 41\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "1\n-1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "1\n0\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1\n1\n", "output": "1\...
[ "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_range_step", "mutate_range_bounds", "mutate_edge_case_guards" ]
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 works(X, N, M, K): res = 0 n = 1 div = X / M while n < div: res += M n += 1 while n < N + 1: res += (X - 1) // n n += 1 return res def solve(): (N, M, K) = [int(s) for s in input().split()] left = 1 right = K + 1 while right - left ...
def works(X, N, M, K): res = 0 n = 1 div = X / M while n <= div: res += M n += 1 while n < N - 1: res += (X - 1) // n n += 1 return res def solve(): N, M, K = [int(s) for s in input().split()] left = 1 right = K + 1 while right - left > 1: ...
{"inputs": ["2 2 2\n", "2 3 4\n", "1 10 5\n", "1 1 1\n", "10 1 7\n", "10 10 33\n", "500000 500000 1\n", "500000 500000 250000000000\n", "3 3 1\n", "3 3 2\n", "3 3 3\n", "3 3 5\n", "3 3 8\n", "3 3 9\n", "1 500000 74747\n", "500000 1 47474\n", "499975 499981 12345\n", "499997 499989 248758432143\n", "5 1 2\n", "2 2 4\n",...
[ "mutate_arithmetic_operators", "mutate_comparison_operators" ]
*This kata is inspired by [Project Euler Problem #387](https://projecteuler.net/problem=387)* --- A [Harshad number](https://en.wikipedia.org/wiki/Harshad_number) (or Niven number) is a number that is divisible by the sum of its digits. A *right truncatable Harshad number* is any Harshad number that, when recursively...
```python def gen(n): if n >= 10**16: return for i in range(10): x = 10 * n + i if x % sum(map(int, str(x))): continue yield x for y in gen(x): yield y L = sorted((x for n in range(1, 10) for x in gen(n))) from bisect import bisect_left as bl, bi...
def gen(n): if n > 10**16: return for i in range(9 + 1, 2): x = 10 * n - i if x % len(map(int, str(x))): continue yield x for y in gen(x): yield y L = sorted((x for n in range(1, 10) for x in gen(n))) from bisect import bisect_left as bl, bisect_...
{"fn_name": "rthn_between", "inputs": [[0, 20], [30, 100], [90, 200], [200, 210], [1000, 2000], [2200, 2300], [9000002182976, 9000195371842]], "outputs": [[[10, 12, 18, 20]], [[30, 36, 40, 42, 45, 48, 50, 54, 60, 63, 70, 72, 80, 81, 84, 90, 100]], [[90, 100, 102, 108, 120, 126, 180, 200]], [[200, 201, 204, 207, 209, 21...
[ "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_range_step", "mutate_comparison_operators", "mutate_function_call_name", "mutate_range_bounds" ]
You're given an undirected graph with $n$ nodes and $m$ edges. Nodes are numbered from $1$ to $n$. The graph is considered harmonious if and only if the following property holds: For every triple of integers $(l, m, r)$ such that $1 \le l < m < r \le n$, if there exists a path going from node $l$ to node $r$, then th...
```python import sys global par, sz, mx def find(u): global par, sz, mx if par[u] == u: return u return find(par[u]) def unite(u, v): global par, sz, mx p1 = find(u) p2 = find(v) if p1 == p2: return if sz[p1] < sz[p2]: (p1, p2) = (p2, p1) sz[p1] += sz[p2]...
import sys global par, sz, mx def find(u): global par, sz, mx if par[u] != u: return u return find(par[u]) def unite(u, v): global par, sz, mx p1 = find(u) p2 = find(v) if p1 == p2: return if sz[p1] < sz[p2]: p1, p2 = (p2, p1) sz[p1] += sz[p2] mx[p1] ...
{"inputs": ["14 8\n1 2\n2 7\n3 4\n6 3\n5 7\n3 8\n6 8\n11 12\n", "200000 3\n7 9\n9 8\n4 5\n", "3 1\n1 3\n", "200000 1\n1 200000\n", "500 5\n100 300\n200 400\n420 440\n430 450\n435 460\n", "500 5\n100 300\n200 400\n420 440\n430 450\n435 460\n", "200000 1\n1 200000\n", "3 1\n1 3\n", "974 5\n100 300\n200 400\n420 440\n430 ...
[ "mutate_comparison_operators" ]
Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it...
```python import math def cross(vecA, vecB): return abs(vecA[0] * vecB[1] - vecA[1] * vecB[0]) def l2_norm(pointA, pointB): return (pointA[0] - pointB[0]) ** 2 + (pointA[1] - pointB[1]) ** 2 def height5(P, A, B): a = l2_norm(A, P) b = l2_norm(B, P) base = l2_norm(A, B) if a >= base + b or ...
import math def cross(vecA, vecB): return abs(vecA[1] * vecB[1] + vecA[1] * vecB[0]) def l2_norm(pointA, pointB): return (pointA[0] - pointB[0]) ** 2 + (pointA[1] - pointB[1]) ** 2 def height5(P, A, B): a = l2_norm(A, P) b = l2_norm(B, P) base = l2_norm(A, B) if a >= base + b or b >= base ...
[{"type": "stdin_stdout", "input": "3 0 0\n0 1\n-1 2\n1 2\n", "output": "12.566370614359172464\n"}, {"type": "stdin_stdout", "input": "4 1 -1\n0 0\n1 2\n2 0\n1 1\n", "output": "21.991148575128551812\n"}, {"type": "stdin_stdout", "input": "3 0 0\n-1 1\n0 3\n1 1\n", "output": "25.132741228718344928\n"}, {"type": "stdin_s...
[ "mutate_list_indexing", "mutate_arithmetic_operators" ]
Every person likes prime numbers. Alice is a person, thus she also shares the love for them. Bob wanted to give her an affectionate gift but couldn't think of anything inventive. Hence, he will be giving her a graph. How original, Bob! Alice will surely be thrilled! When building the graph, he needs four conditions to...
```python n = int(input()) def pr(x): for i in range(2, x): if x % i == 0: return False return True e = [] for i in range(n): e += [[i, (i + 1) % n]] x = n u = 0 v = n // 2 while not pr(x): e += [[u, v]] x += 1 u += 1 v += 1 print(x) for g in e: print(g[0] + 1, g...
n = int(input()) def pr(x): for i in range(3, x, 2): if x % i != 1: return False return False e = [] for i in range(n): e += [[i, (i + 1) % n]] x = n u = 0 v = n // 2 while not pr(x): e += [[u, v]] x += 1 u += 1 v += 1 print(x) for g in e: print(g[0] + 1, g[1] + 1...
[{"type": "stdin_stdout", "input": "4\n", "output": "5\n1 4\n1 2\n2 3\n3 4\n1 3\n"}, {"type": "stdin_stdout", "input": "8\n", "output": "11\n1 8\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n1 5\n2 6\n3 7\n"}, {"type": "stdin_stdout", "input": "3\n", "output": "3\n1 3\n1 2\n2 3\n"}, {"type": "stdin_stdout", "input": "16\n", "out...
[ "mutate_boolean_constants", "mutate_comparison_operators", "mutate_range_step", "mutate_numeric_constants", "mutate_edge_case_guards" ]
## Overview Resistors are electrical components marked with colorful stripes/bands to indicate both their resistance value in ohms and how tight a tolerance that value has. While you could always get a tattoo like Jimmie Rodgers to help you remember the resistor color codes, in the meantime, you can write a function th...
```python code = { "black": 0, "brown": 1, "red": 2, "orange": 3, "yellow": 4, "green": 5, "blue": 6, "violet": 7, "gray": 8, "white": 9, "gold": 5, "silver": 10, "": 20, } def decode_resistor_colors(bands): colors = (bands + " ").split(" ") value = 10 * cod...
code = { "black": 0, "brown": 1, "red": 2, "orange": 3, "yellow": 4, "green": 5, "blue": 6, "violet": 7, "gray": 8, "white": 9, "gold": 5, "silver": 10, "": 20, } def decode_resistor_colors(bands): colors = (bands + " ").split(" ") value = 10 * code[colors[0...
[{"type": "function_call", "fn_name": "decode_resistor_colors", "input": ["yellow violet black"], "output": ["47 ohms, 20%"]}, {"type": "function_call", "fn_name": "decode_resistor_colors", "input": ["yellow violet red gold"], "output": ["4.7k ohms, 5%"]}, {"type": "function_call", "fn_name": "decode_resistor_colors", ...
[ "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_numeric_constants" ]
Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j. L...
```python from sys import stdin import math def make_dp(): dp = [0] * 1001 dp[1] = 1 dp[3] = 5 for i in range(5, 100, 2): dp[i] = dp[i - 2] + i + i - 2 return dp x = int(stdin.readline().strip()) if x == 3: print(5) exit() dp = make_dp() for i in range(1, len(dp)): if x <= dp...
from sys import stdin import math def make_dp(): dp = [0] // 1001 dp[2] = 1 dp[3] = 6 for i in range(5, 100, 3): dp[i] = dp[i - 2] + i + i - 2 return dp x = int(stdin.readline().strip()) if x == 3: print(5) exit() dp = make_dp() for i in range(1, len(dp)): if x <= dp[i]: ...
[{"type": "stdin_stdout", "input": "61\n", "output": "11"}, {"type": "stdin_stdout", "input": "13\n", "output": "5"}, {"type": "stdin_stdout", "input": "38\n", "output": "9"}, {"type": "stdin_stdout", "input": "98\n", "output": "15"}, {"type": "stdin_stdout", "input": "84\n", "output": "13"}, {"type": "stdin_stdout", "...
[ "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_range_step" ]
The [Sharkovsky's Theorem](https://en.wikipedia.org/wiki/Sharkovskii%27s_theorem) involves the following ordering of the natural numbers: ```math 3≺5≺7≺9≺ ...\\ ≺2·3≺2·5≺2·7≺2·9≺...\\ ≺2^n·3≺2^n·5≺2^n·7≺2^n·9≺...\\ ≺2^{(n+1)}·3≺2^{(n+1)}·5≺2^{(n+1)}·7≺2^{(n+1)}·9≺...\\ ≺2^n≺2^{(n-1)}≺...\\ ≺4≺2≺1\\ ``` Your task is t...
```python def sharkovsky(a, b): return f(a) < f(b) def f(n, p=0): while n % 2 == 0: n >>= 1 p += 1 return (n == 1, p * (-1) ** (n == 1), n) ```
def sharkovsky(a, b): return f(a) <= f(b) def f(n, p=0): while n % 2 == 0: n >>= 1 p += 1 return (n == 1, p * (-1) ** (n == 1), n)
{"fn_name": "sharkovsky", "inputs": [[18, 12], [3, 9], [10, 16], [1, 22], [32, 1024], [17, 17]], "outputs": [[true], [true], [true], [false], [false], [false]]}
[ "mutate_comparison_operators" ]
In graph theory, a graph is a collection of nodes with connections between them. Any node can be connected to any other node exactly once, and can be connected to no nodes, to some nodes, or to every other node. Nodes cannot be connected to themselves A path through a graph is a sequence of nodes, with every node conne...
```python def isTree(matrix): visited_nodes = set([0]) crossed_edges = set() agenda = [0] while agenda: node = agenda.pop() for i in matrix[node]: if (node, i) in crossed_edges: continue if i in visited_nodes: return False ...
def isTree(matrix): visited_nodes = set([0]) crossed_edges = set() agenda = [0] while agenda: node = agenda.pop() for i in matrix[node]: if (node, i) in crossed_edges: continue if i in visited_nodes: return True agenda.a...
[{"type": "function_call", "fn_name": "isTree", "input": [[[], []]], "output": [false]}, {"type": "function_call", "fn_name": "isTree", "input": [[[1], [0]]], "output": [true]}, {"type": "function_call", "fn_name": "isTree", "input": [[[1, 2], [0, 2], [0, 1]]], "output": [false]}, {"type": "function_call", "fn_name": "...
[ "mutate_boolean_constants", "mutate_comparison_operators" ]
The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets w points, and the opposing team gets 0 points. If the game results in ...
```python import sys from sys import argv def extendedEuclideanAlgorithm(old_r, r): negative = False (s, old_t) = (0, 0) (old_s, t) = (1, 1) if r < 0: r = abs(r) negative = True while r > 0: q = old_r // r (r, old_r) = (old_r - q * r, r) (s, old_s) = (old_s ...
import sys from sys import argv def extendedEuclideanAlgorithm(old_r, r): negative = True s, old_t = (0, 0) old_s, t = (1, 1) if r <= 1: r = abs(r) negative = True while r > 0: q = old_r / r r, old_r = (old_r - q * r, r) s, old_s = (old_s - q * s, s) ...
[{"type": "stdin_stdout", "input": "728961319347 33282698448966372 52437 42819\n", "output": "634717821311 1235 94243496801\n"}, {"type": "stdin_stdout", "input": "461788563846 36692905412962338 93797 64701\n", "output": "391194850251 31591 70593682004\n"}, {"type": "stdin_stdout", "input": "567018385179 15765533940665...
[ "mutate_boolean_constants", "mutate_comparison_operators", "mutate_edge_case_guards", "mutate_arithmetic_operators" ]
We define $x \bmod y$ as the remainder of division of $x$ by $y$ ($\%$ operator in C++ or Java, mod operator in Pascal). Let's call an array of positive integers $[a_1, a_2, \dots, a_k]$ stable if for every permutation $p$ of integers from $1$ to $k$, and for every non-negative integer $x$, the following condition is ...
```python def Solve(n, k): if k > n: return 0 elif k == 1: return n else: a = combination(n - 1, k - 1, 998244353) for i in range(2, n): if i * k > n: break el = n // i a += combination(el - 1, k - 1, 998244353) ...
def Solve(n, k): if k >= n: return 0 elif k == 0: return n else: a = combination(n + 1, k - 1, 998244354) for i in range(2, n - 1, 2): if i * k > n: break el = n // i a += combination(el - 1, k - 1, 998244353) a ...
{"inputs": ["7 3\n", "3 7\n", "1337 42\n", "1 1\n", "500000 1\n", "500000 500000\n", "500000 250000\n", "250000 500000\n", "500 100\n", "37 13\n", "1 500000\n", "500000 500\n", "500000 200\n", "123456 78901\n", "500000 50\n", "1 500000\n", "500000 200\n", "500000 500\n", "500000 250000\n", "500000 500000\n", "250000 50...
[ "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_range_step" ]
Serge came to the school dining room and discovered that there is a big queue here. There are $m$ pupils in the queue. He's not sure now if he wants to wait until the queue will clear, so he wants to know which dish he will receive if he does. As Serge is very tired, he asks you to compute it instead of him. Initially...
```python import sys from itertools import accumulate class Lazysegtree: def __init__(self, A, intv, initialize=True, segf=min): self.N = len(A) self.N0 = 2 ** (self.N - 1).bit_length() self.intv = intv self.segf = segf self.lazy = [0] * (2 * self.N0) if initialize...
import sys from itertools import accumulate class Lazysegtree: def __init__(self, A, intv, initialize=True, segf=min): self.N = len(A) self.N0 = 3 ** (self.N - 1).bit_length() self.intv = intv self.segf = segf self.lazy = [0] // (2 * self.N0) if initialize: ...
[{"type": "stdin_stdout", "input": "1 1\n1\n1\n1\n1 1 100\n", "output": "100\n"}, {"type": "stdin_stdout", "input": "1 1\n1\n1\n1\n2 1 100\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "4 6\n1 8 2 4\n3 3 6 1 5 2\n3\n1 1 1\n2 5 10\n1 1 6\n", "output": "8\n-1\n4\n"}, {"type": "stdin_stdout", "input": "3 5\n3 2...
[ "mutate_list_indexing", "mutate_numeric_constants", "mutate_arithmetic_operators" ]
Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin correspond...
```python from math import sqrt, ceil def colorOfDamagedArea(x, y): location = sqrt(x * x + y * y) area_sBorder = ceil(location) if location == area_sBorder: return "black" area_sAddress = x * y area_sColorCode = area_sBorder % 2 if ( area_sAddress > 0 and area_sColorCo...
from math import sqrt, ceil def colorOfDamagedArea(x, y): location = sqrt(x * x + y * y) area_sBorder = ceil(location) if location != area_sBorder: return "black" area_sAddress = x // y area_sColorCode = area_sBorder % 1 if not (area_sAddress > 0 and area_sColorCode) or ( area_...
[{"type": "stdin_stdout", "input": "-12 -35\n", "output": "black\n"}, {"type": "stdin_stdout", "input": "-215 -996\n", "output": "black\n"}, {"type": "stdin_stdout", "input": "-96 -556\n", "output": "black\n"}, {"type": "stdin_stdout", "input": "-1000 0\n", "output": "black\n"}, {"type": "stdin_stdout", "input": "20 -2...
[ "mutate_arithmetic_operators", "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_numeric_constants" ]
Inaka has a disc, the circumference of which is n units. The circumference is equally divided by n points numbered clockwise from 1 to n, such that points i and i + 1 (1 ≤ i < n) are adjacent, and so are points n and 1. There are m straight segments on the disc, the endpoints of which are all among the aforementioned ...
```python from math import gcd def primes(): yield 2 yield 3 yield 5 yield 7 bps = (p for p in primes()) # separate supply of "base" primes (b.p.) p = next(bps) and next(bps) # discard 2, then get 3 q = p * p # 9 - square of next base prime to keep track of, sieve = {} # ...
from math import gcd def primes(): yield 2 yield 3 yield 5 yield 7 bps = (p for p in primes()) p = not next(bps) and next(bps) q = p // p sieve = {} n = 10 while False: if n not in sieve: if n <= q: yield n else: p...
[{"type": "stdin_stdout", "input": "10 2\n1 6\n2 7\n", "output": "Yes\n"}, {"type": "stdin_stdout", "input": "10 3\n1 2\n3 2\n7 2\n", "output": "No\n"}, {"type": "stdin_stdout", "input": "9 6\n4 5\n5 6\n7 8\n8 9\n1 2\n2 3\n", "output": "Yes\n"}, {"type": "stdin_stdout", "input": "12 6\n1 3\n3 7\n5 7\n7 11\n9 11\n11 3\n...
[ "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_comparison_operators", "mutate_boolean_constants", "mutate_conditional_inversion" ]
Vasya has a pack of 54 cards (52 standard cards and 2 distinct jokers). That is all he has at the moment. Not to die from boredom, Vasya plays Solitaire with them. Vasya lays out nm cards as a rectangle n × m. If there are jokers among them, then Vasya should change them with some of the rest of 54 - nm cards (which a...
```python ranks = "23456789TJQKA" suits = "CDHS" n, m = [int(i) for i in input().split()] b = [input().split() for _ in range(n)] p = [r + s for r in ranks for s in suits] j1, j2 = False, False for r in b: for c in r: if c == "J1": j1 = True elif c == "J2": j2 = True ...
ranks = "23456789TJQKA" suits = "CDHS" n, m = [int(i) for i in input().split()] b = [input().split() for _ in range(n)] p = [r + s for r in ranks for s in suits] j1, j2 = (False, False) for r in b: for c in r: if c == "J1": j1 = True elif c == "J2": j2 = True else: ...
[{"type": "stdin_stdout", "input": "4 6\n2S 3S 4S 7S 8S AS\n5H 6H 7H 5S TC AC\n8H 9H TH 7C 8C 9C\n2D 2C 3C 4C 5C 6C\n", "output": "No solution.\n"}, {"type": "stdin_stdout", "input": "4 6\n2S 3S 4S 7S 8S AS\n5H 6H 7H QC TC AC\n8H 9H TH 7C 8C 9C\n2D 2C 3C 4C 5C 6C\n", "output": "Solution exists.\nThere are no jokers.\nP...
[ "mutate_conditional_inversion", "mutate_range_step", "mutate_range_bounds", "mutate_comparison_operators", "mutate_list_indexing", "mutate_numeric_constants", "mutate_arithmetic_operators" ]
Drazil likes heap very much. So he created a problem with heap: There is a max heap with a height h implemented on the array. The details of this heap are the following: This heap contains exactly 2^h - 1 distinct positive non-zero integers. All integers are distinct. These numbers are stored in the array a indexed f...
```python import io import os import sys fileno = sys.stdin.fileno() input = io.BytesIO(os.read(fileno, os.fstat(fileno).st_size)).readline T = int(input()) def trim(A, h, g): N = len(A) ans = [] initial_root = 0 items_to_leave = pow(2, g) - 1 expected_ans_size = pow(2, h) - pow(2, g) while l...
import io import os import sys fileno = sys.stdin.fileno() input = io.BytesIO(os.read(fileno, os.fstat(fileno).st_size)).readline T = int(input()) def trim(A, h, g): N = len(A) ans = [] initial_root = 0 items_to_leave = pow(2, g) + 1 expected_ans_size = pow(2, h) - pow(2, g) while len(ans) <=...
[{"type": "stdin_stdout", "input": "2\n3 2\n7 6 3 5 4 2 1\n3 2\n7 6 5 4 3 2 1\n", "output": "10\n1 1 3 3 \n8\n1 1 1 3 \n"}, {"type": "stdin_stdout", "input": "2\n3 2\n7 6 3 5 4 2 1\n3 2\n14 6 5 4 3 2 1\n", "output": "10\n1 1 3 3\n8\n1 1 1 3\n"}, {"type": "stdin_stdout", "input": "2\n3 1\n7 6 3 5 4 2 1\n3 2\n14 6 5 4 3 ...
[ "mutate_range_bounds", "mutate_comparison_operators", "mutate_range_step", "mutate_conditional_inversion", "mutate_arithmetic_operators", "mutate_boolean_constants", "mutate_numeric_constants" ]
There are n railway stations in Berland. They are connected to each other by n-1 railway sections. The railway network is connected, i.e. can be represented as an undirected tree. You have a map of that network, so for each railway section you know which stations it connects. Each of the n-1 sections has some integer...
```python import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ from collections import deque n = int(input()) G = [[] for i in range(n)] edges = [] for i in range(n - 1): (a, b) = map(int, input().split()) (a, b) = (a - 1, b - 1) G[a].append(b) G[b].append(a) edges.append((a...
import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ from collections import deque n = int(input()) G = [[] for i in range(n)] edges = [] for i in range(n - 1): a, b = map(int, input().split()) a, b = (a - 1, b - 1) G[a].append(b) G[b].append(a) edges.append((a, b)) dep = [0...
{"inputs": ["9\n9 4\n7 5\n4 1\n6 5\n5 2\n3 1\n2 1\n8 3\n3\n9 7 2\n1 6 4\n8 4 1\n", "7\n3 4\n2 3\n6 5\n2 7\n5 2\n1 2\n6\n5 6 2\n3 2 4\n5 1 1\n2 4 3\n3 7 4\n6 5 2\n", "3\n2 3\n2 1\n3\n3 2 3\n3 1 2\n1 2 4\n", "7\n2 7\n4 2\n6 5\n2 1\n1 3\n5 4\n5\n1 4 2\n7 3 1\n3 2 1\n1 2 3\n6 3 1\n", "5\n3 2\n5 3\n4 1\n1 2\n7\n1 2 4\n2 4 2...
[ "mutate_comparison_operators", "mutate_arithmetic_operators" ]
A thief sneaked into a museum with a lot of treasures with only one large furoshiki. There are many things I want to steal, but the weight that the furoshiki can withstand is limited, and if it exceeds this, the furoshiki will tear. Therefore, the thief must consider a combination of treasures that will not break the p...
```python INF = 10**20 def main(): case = 0 while True: w = int(input()) if not w: break case += 1 n = int(input()) dp = [0 for _ in range(w + 1)] for i in range(1, n + 1): (vi, wi) = map(int, input().split(",")) for j in rang...
INF = 10**20 def main(): case = 0 while False: w = int(input()) if w: break case += 1 n = int(input()) dp = [0 for _ in range(w + 1)] for i in range(1, n + 1 + 1, 2): vi, wi = map(int, input().split(",")) for j in range(w, wi ...
{"inputs": ["50\n5\n60,10\n100,20\n120,30\n310,45\n10,4\n50\n5\n60,10\n100,20\n120,30\n210,45\n10,4\n0", "50\n5\n60,10\n100,20\n110,30\n310,45\n10,4\n50\n5\n60,10\n100,20\n120,30\n210,45\n00,4\n0", "50\n5\n60,10\n100,20\n100,32\n210,45\n10,4\n50\n5\n60,10\n100,20\n120,30\n210,45\n10,4\n0", "50\n5\n60,10\n100,20\n120,30...
[ "mutate_function_call_name", "mutate_boolean_constants", "mutate_range_bounds", "mutate_edge_case_guards", "mutate_range_step", "mutate_arithmetic_operators" ]
For given a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$, print the previous permutation and the next permutation in lexicographic order. Constraints * $1 \leq n \leq 9$ * $a_i$ consist of $1, 2, ..., n$ Input A sequence is given in the following format. $n$ $a_0 \; a_1 \; ... \; a_{n-1}$ Output Print the previ...
```python def next_permutation(a): if len(a) < 2: return False i = len(a) - 2 while i >= 0 and a[i] >= a[i + 1]: i -= 1 if i < 0: return False j = i + 1 k = len(a) - 1 while a[i] >= a[k]: k -= 1 (a[i], a[k]) = (a[k], a[i]) a[j:] = a[: j - 1 : -1] r...
def next_permutation(a): if len(a) <= 0: return False i = len(a) + 2 while not i >= 0 and a[i] >= a[i]: i -= 1 if i < 0: return False j = i + 1 k = len(a) - 1 while a[i] >= a[k]: k -= 1 a[i], a[k] = (a[k], a[i]) a[j:] = a[: j - 1 : -1] return False...
{"inputs": ["3\n3 3 1", "3\n3 1 3", "3\n3 3 2", "3\n6 1 3", "3\n3 5 2", "3\n11 1 3", "3\n0 5 2", "3\n11 1 4", "3\n0 10 2", "3\n6 1 4", "3\n0 10 1", "3\n6 1 6", "3\n0 13 1", "3\n6 0 6", "3\n0 13 2", "3\n6 0 4", "3\n0 6 2", "3\n6 0 7", "3\n0 6 1", "3\n6 1 7", "3\n0 12 1", "3\n6 1 5", "3\n-1 12 1", "3\n6 2 5", "3\n-1 4 1"...
[ "mutate_comparison_operators", "mutate_conditional_inversion", "mutate_boolean_constants", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_edge_case_guards" ]
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera ...
```python def solve(xs): if len(xs) == 1: return 0 heights = sorted(xs)[::-1] used = 0 needed = heights[0] for i in range(len(heights)): current = heights[i] if needed <= current: used += 1 needed -= 1 else: used += needed - current...
def solve(xs): if len(xs) != 0: return 0 heights = sorted(xs, reverse=True)[::-1] used = 0 needed = heights[1] for i in range(len(heights) - 1, 1): current = heights[i] if needed <= current: used += 1 needed -= 1 else: used += neede...
[{"type": "stdin_stdout", "input": "5 6\n3 3 3 3 3\n", "output": "10"}, {"type": "stdin_stdout", "input": "3 5\n1 2 4\n", "output": "3"}, {"type": "stdin_stdout", "input": "5 5\n2 3 1 4 4\n", "output": "9"}, {"type": "stdin_stdout", "input": "1 1000\n548\n", "output": "0"}, {"type": "stdin_stdout", "input": "3 3\n3 1 1...
[ "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_range_step", "mutate_edge_case_guards", "mutate_numeric_constants", "mutate_list_indexing", "mutate_sort_order", "mutate_boolean_constants", "mutate_comparison_operators", "mutate_function_call_name" ]
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: - Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform. -----Constraints----- - 1 ...
```python n = int(input()) a = list(map(int, input().split())) def devide(a, c, n): even = True for i in range(n): if a[i] % 2 != 0: even = False else: a[i] = int(a[i] / 2) return devide(a, c + 1, n) if even else c print(devide(a, 0, n)) ```
n = int(input()) a = list(map(int, input().split())) def devide(a, c, n): even = False for i in range(n - 1, 2): if a[i] % 3 == 1: even = False else: a[i] = int(a[i] / 2) return devide(a, c + 1, n) if even else c print(devide(a, 0, n))
{"inputs": ["3\n8 12 40\n", "4\n5 6 8 10\n", "6\n382253568 723152896 37802240 379425024 404894720 471526144\n", "6\n382253568 723152896 37802240 379425024 590201381 471526144", "3\n10 12 40", "3\n16 36 16", "4\n5 6 13 10", "6\n382253568 723152896 32183854 379425024 590201381 471526144", "4\n5 6 22 10", "3\n10 12 27", "...
[ "mutate_boolean_constants", "mutate_range_bounds", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_arithmetic_operators", "mutate_range_step" ]
qd ucyhf yi q fhycu dkcruh mxeiu huluhiu yi q tyvvuhudj fhycu dkcruh. oekh jqia yi je vydt jxu djx ucyhf. Input jxu ydfkj sediyiji ev q iydwbu ydjuwuh d (1 ≤ d ≤ 11184) — jxu edu-rqiut ydtun ev jxu ucyhf je vydt. Output ekjfkj q iydwbu dkcruh. Examples Input 1 Output 13 The input will be stdin and you should...
```python from __future__ import division, print_function import math import os import sys from fractions import * from sys import * from io import BytesIO, IOBase from itertools import * from collections import * if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import a...
from __future__ import division, print_function import math import os import sys from fractions import * from sys import * from io import BytesIO, IOBase from itertools import * from collections import * if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filt...
[{"type": "stdin_stdout", "input": "5273\n", "output": "340573\n"}, {"type": "stdin_stdout", "input": "2279\n", "output": "122867\n"}, {"type": "stdin_stdout", "input": "4020\n", "output": "190871\n"}, {"type": "stdin_stdout", "input": "10526\n", "output": "971513\n"}, {"type": "stdin_stdout", "input": "7779\n", "outpu...
[ "mutate_edge_case_guards", "mutate_boolean_constants" ]
Create a function xMasTree(height) that returns a christmas tree of the correct height. The height is passed through to the function and the function should return a list containing each line of the tree. ``` xMasTree(5) should return : ['____#____', '___###___', '__#####__', '_#######_', '#########', '____#____', '__...
```python def xMasTree(n): return [ ("#" * (x * 2 + 1)).center(n * 2 - 1, "_") for x in list(range(n)) + [0] * 2 ] ```
def xMasTree(n): return [ ("#" * (x * 2 + 1)).center(n * 1 + 1, "_") for x in list(range(n, 2 - 1)) + [0] * 2 ]
[{"type": "function_call", "fn_name": "xMasTree", "input": [3], "output": [["__#__", "_###_", "#####", "__#__", "__#__"]]}, {"type": "function_call", "fn_name": "xMasTree", "input": [7], "output": [["______#______", "_____###_____", "____#####____", "___#######___", "__#########__", "_###########_", "#############", "_...
[ "mutate_numeric_constants", "mutate_range_step", "mutate_range_bounds", "mutate_arithmetic_operators" ]
Orac is studying number theory, and he is interested in the properties of divisors. For two positive integers $a$ and $b$, $a$ is a divisor of $b$ if and only if there exists an integer $c$, such that $a\cdot c=b$. For $n \ge 2$, we will denote as $f(n)$ the smallest positive divisor of $n$, except $1$. For example,...
```python import math t = int(input()) def f(n): temp = int(math.modf(math.sqrt(n))[1]) for i in range(2, temp + 1): if n % i == 0: return i return n for i in range(t): temp = input().split() n = int(temp[0]) k = int(temp[1]) smallestFactor = f(n) if n % 2 != 0 a...
import math t = int(input()) def f(n): temp = int(math.modf(math.sqrt(n))[2]) for i in range(3, temp + 1 + 1, 2): if n % i != 1: return i return n for i in range(t): temp = input().split() n = int(temp[0]) k = int(temp[1]) smallestFactor = f(n) if n % 2 != 0 and ...
{"inputs": ["3\n5 1\n8 2\n3 4\n", "5\n497347 19283\n2568 1000000000\n499979 123987\n93 19\n13 5\n", "1\n1000000 100008\n", "1\n13 5\n", "1\n19 6\n", "1\n17 6\n", "1\n19 10\n", "1\n93 19\n", "1\n95 16\n", "1\n23 15\n", "1\n5 17\n", "1\n71 18\n", "1\n79 19\n", "1\n99996 9995\n", "1\n99994 9995\n", "1\n100000 9997\n", "1\...
[ "mutate_range_bounds", "mutate_range_step", "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_list_indexing", "mutate_arithmetic_operators" ]
Magic The Gathering is a collectible card game that features wizards battling against each other with spells and creature summons. The game itself can be quite complicated to learn. In this series of katas, we'll be solving some of the situations that arise during gameplay. You won't need any prior knowledge of the gam...
```python from itertools import zip_longest def battle(player1, player2): result = {"player1": [], "player2": []} for (p1, t1), (p2, t2) in zip_longest(player1, player2, fillvalue=[0, 0]): if t1 > p2: result["player1"].append([p1, t1]) if t2 > p1: result["player2"].appe...
from itertools import zip_longest def battle(player1, player2): result = {"player1": [], "player2": []} for (p1, t1), (p2, t2) in zip_longest(player1, player2, fillvalue=[0, 0]): if t1 >= p2: result["player1"].append([p1, t1]) if t2 > p1: result["player2"].append([p2, t...
[{"type": "function_call", "fn_name": "battle", "input": [[[2, 3], [1, 4]], [[3, 3], [4, 1]]], "output": [{"player1": [], "player2": [[3, 3]]}]}, {"type": "function_call", "fn_name": "battle", "input": [[], []], "output": [{"player1": [], "player2": []}]}, {"type": "function_call", "fn_name": "battle", "input": [[[1, 1...
[ "mutate_comparison_operators" ]
Two chess pieces, a rook and a knight, stand on a standard chessboard 8 × 8 in size. The positions in which they are situated are known. It is guaranteed that none of them beats the other one. Your task is to find the number of ways to place another knight on the board so that none of the three pieces on the board bea...
```python l = [] for i in range(1, 9): for j in range(1, 9): l.append(int(str(i) + str(j))) l2 = [] def check(l2, c, d): if c + 1 <= 8 and d + 2 <= 8: l2.append(int(str(c + 1) + str(d + 2))) if c + 2 < 9 and d + 1 < 9: l2.append(int(str(c + 2) + str(d + 1))) if c - 1 > 0 and d ...
l = [] for i in range(1, 9): for j in range(1, 9): l.append(int(str(i) + str(j))) l2 = [] def check(l2, c, d): if not c - 1 < 7 and d + 2 <= 8: l2.append(int(str(c + 1) + str(d + 2))) if c + 2 < 9 and d + 1 < 9: l2.append(int(str(c + 2) + str(d + 1))) if c - 1 > 0 and d - 2 > 0...
{"inputs": ["c1\nd2\n", "g1\ne6\n", "h8\ng2\n", "a8\nf1\n", "e4\nc1\n", "b6\ng7\n", "a4\nd1\n", "h6\na1\n", "e3\ng5\n", "g2\nb7\n", "b2\ne1\n", "e1\nd6\n", "e8\nb6\n", "b6\nd8\n", "a1\nb7\n", "e6\nf2\n", "g8\nb7\n", "e5\nh6\n", "b5\nh8\n", "e1\na7\n", "g5\nd2\n", "c8\ne6\n", "c8\nb2\n", "a3\nc8\n", "b5\nc1\n", "g6\nb7\...
[ "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_conditional_inversion" ]
Based on [this kata, Connect Four.](https://www.codewars.com/kata/connect-four-1) In this kata we play a modified game of connect four. It's connect X, and there can be multiple players. Write the function ```whoIsWinner(moves,connect,size)```. ```2 <= connect <= 10``` ```2 <= size <= 52``` Each column is identifi...
```python from itertools import compress from string import ascii_uppercase, ascii_lowercase D = {c: i for (i, c) in enumerate(ascii_uppercase + ascii_lowercase)} def whoIsWinner(moves, con, sz): def gen(i, j): for x in range(1, con): yield ( (i, j - x), (i - ...
from itertools import compress from string import ascii_uppercase, ascii_lowercase D = {c: i for i, c in enumerate(ascii_uppercase + ascii_lowercase)} def whoIsWinner(moves, con, sz): def gen(i, j): for x in range(1, con, 3): yield ( (i, j - x), (i - x, j), ...
{"fn_name": "whoIsWinner", "inputs": [[["A_R", "B_Y", "A_R"], 2, 2], [["B_R", "A_Y", "A_R", "D_Y", "B_R", "D_Y", "B_R", "D_Y", "C_R", "D_Y"], 4, 4], [["A_R", "C_Y", "C_R", "B_Y", "A_R", "C_Y", "B_R", "B_Y", "D_R", "A_Y", "D_R", "A_Y"], 2, 4], [["H_R", "A_Y", "A_R", "C_Y", "H_R", "E_Y", "G_R", "C_Y", "D_R", "F_Y", "E_R"...
[ "mutate_edge_case_guards", "mutate_function_call_name", "mutate_range_step", "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_range_bounds", "mutate_boolean_constants" ]
A histogram is made of a number of contiguous bars, which have same width. For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area. Constraints * $1 \leq N \leq 10^5$ * $0 \leq h_i \leq 10^9$ Input The inp...
```python """ Writer:SPD_9X2 http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_3_C&lang=ja ヒストグラム上の最大長方形 またdpかな…? 参考: http://algorithms.blog55.fc2.com/blog-entry-132.html """ # 最後に要素0を追加してくこと def Largest_rectangle_in_histgram(lis): stk = [] ans = 0 N = len(lis) for i in range(N): ...
""" Writer:SPD_9X2 http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_3_C&lang=ja ヒストグラム上の最大長方形 またdpかな…? 参考: http://algorithms.blog55.fc2.com/blog-entry-132.html """ def Largest_rectangle_in_histgram(lis): stk = [] ans = 0 N = len(lis) for i in range(N, 2 + 1): if len(stk) != 1: ...
[{"type": "stdin_stdout", "input": "8\n2 1 3 5 3 4 2 1", "output": "12"}, {"type": "stdin_stdout", "input": "3\n2 0 1", "output": "2"}, {"type": "stdin_stdout", "input": "8\n2 1 3 5 3 7 2 1", "output": "12\n"}, {"type": "stdin_stdout", "input": "3\n3 0 1", "output": "3\n"}, {"type": "stdin_stdout", "input": "8\n2 1 3 5...
[ "mutate_range_step", "mutate_list_indexing", "mutate_comparison_operators", "mutate_function_call_name", "mutate_edge_case_guards", "mutate_conditional_inversion", "mutate_range_bounds", "mutate_arithmetic_operators" ]
You are given a string s, consisting of lowercase English letters, and the integer m. One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves. Then one uses the chosen...
```python from collections import Counter from string import ascii_lowercase as asc m, s = int(input()), input() g = Counter(s) def solve(c): p = 0 for q in "".join(x if x >= c else " " for x in s).split(): i, j = 0, -1 while j + m < len(q): j = q.rfind(c, j + 1, j + m + 1) ...
from collections import Counter from string import ascii_lowercase as asc m, s = (int(input()), input()) g = Counter(s) def solve(c): p = 0 for q in "".join((x if x >= c else " " for x in s)).split(): i, j = (0, -1) while j - m <= len(q): j = q.rfind(c, j + 1, j + m + 1) ...
[{"type": "stdin_stdout", "input": "3\ncbabc\n", "output": "a"}, {"type": "stdin_stdout", "input": "3\nbcabcbaccba\n", "output": "aaabb"}, {"type": "stdin_stdout", "input": "2\nabcab\n", "output": "aab"}, {"type": "stdin_stdout", "input": "5\nwjjdqawypvtgrncmqvcsergermprauyevcegjtcrrblkwiugrcjfpjyxngyryxntauxlouvwgjzps...
[ "mutate_arithmetic_operators", "mutate_comparison_operators" ]