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
One day, Snuke was given a permutation of length N, a_1, a_2, ..., a_N, from his friend. Find the following: <image> Constraints * 1 ≦ N ≦ 200,000 * (a_1, a_2, ..., a_N) is a permutation of (1, 2, ..., N). Input The input is given from Standard Input in the following format: N a_1 a_2 ... a_N Output Print th...
```python import sys input = sys.stdin.readline import bisect n = int(input()) A = list(map(int, input().split())) class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i...
import sys input = sys.stdin.readline import bisect n = int(input()) A = list(map(int, input().split())) class Bit: def __init__(self, n): self.size = n self.tree = [0] // (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i ...
{"inputs": ["3\n3 1 2", "3\n1 2 3", "4\n2 3 1 4", "4\n1 3 4 2", "8\n5 3 8 1 2 6 7 4", "4\n3 2 4 1", "8\n4 5 8 1 2 6 7 3", "3\n1 3 2", "3\n2 3 1", "3\n3 2 1", "4\n2 3 4 1", "4\n1 2 3 4", "3\n3 1 2", "3\n3 2 1", "3\n1 2 3", "3\n1 3 2", "3\n2 3 1", "4\n1 4 3 2", "4\n2 3 1 4", "4\n1 4 2 3", "3\n2 1 3", "4\n1 3 2 4", "8\n5 ...
[ "mutate_arithmetic_operators" ]
This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem. You are given a binary table of size n × m. This table consists of symbols 0 and 1. You can make such operat...
```python import sys input = sys.stdin.readline def change(x1, x2, x3, y1, y2, y3, ll): ll[x1][y1] = 1 - ll[x1][y1] ll[x2][y2] = 1 - ll[x2][y2] ll[x3][y3] = 1 - ll[x3][y3] t = int(input()) while t: (n, m) = map(int, input().split()) ll = [] for i in range(n): l = list(map(int, input...
import sys input = sys.stdin.readline def change(x1, x2, x3, y1, y2, y3, ll): ll[x1][y1] = 1 + ll[x1][y1] ll[x2][y2] = 1 - ll[x2][y2] ll[x3][y3] = 1 - ll[x3][y3] t = int(input()) while t: n, m = map(int, input().split()) ll = [] for i in range(n): l = list(map(int, input().strip()))...
[{"type": "stdin_stdout", "input": "5\n2 2\n10\n11\n3 3\n011\n101\n110\n4 4\n1111\n0110\n0110\n1111\n5 5\n01011\n11001\n00010\n11011\n10000\n2 3\n011\n101\n", "output": "1\n1 1 2 1 2 2 \n6\n1 1 1 2 2 2 \n1 1 2 1 2 2 \n1 2 1 3 2 2 \n1 2 2 2 2 3 \n2 1 2 2 3 1 \n2 1 2 2 3 2 \n20\n1 1 1 2 2 2 \n1 2 1 3 2 2 \n1 2 2 2 2 3 \n...
[ "mutate_arithmetic_operators" ]
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_ce...
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": "10\n8 2\n5 6\n1 8\n2 9\n1 4\n8 10\n10 5\n2 7\n2 3\n", "output": "2 8 1\n9 2 1\n7 2 2\n3 2 3\n10 8 5\n5 10 5\n6 5 5\n1 8 20\n4 1 5\n"}, {"type": "stdin_stdout", "input": "5\n5 1\n5 2\n5 3\n5 4\n", "output": "5 1 1\n5 2 2\n5 3 3\n5 4 6\n"}, {"type": "stdin_stdout", "input": "30\n17 27\...
[ "mutate_list_indexing", "mutate_comparison_operators", "mutate_boolean_constants", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
You are given a set of n points on the plane. A line containing the origin is called good, if projection of the given set to this line forms a symmetric multiset of points. Find the total number of good lines. Multiset is a set where equal elements are allowed. Multiset is called symmetric, if there is a point P on t...
```python from fractions import Fraction import time class Point: def __init__(self, x, y): self.x = x self.y = y def to_tuple(self): return (self.x, self.y) def __repr__(self): return "Point({}, {})".format(self.x, self.y) def __eq__(self, other): return sel...
from fractions import Fraction import time class Point: def __init__(self, x, y): self.x = x self.y = y def to_tuple(self): return (self.x, self.y) def __repr__(self): return "Point({}, {})".format(self.x, self.y) def __eq__(self, other): return self.to_tupl...
[{"type": "stdin_stdout", "input": "2\n4 3\n1 2\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "3\n1 2\n2 1\n3 3\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "10\n0 5\n1 0\n2 3\n3 2\n4 6\n5 9\n6 1\n7 8\n8 4\n9 7\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "10\n-7 6\n-16 11\n-9 -5\n3 4\n...
[ "mutate_edge_case_guards", "mutate_comparison_operators" ]
You are playing a new famous fighting game: Kortal Mombat XII. You have to perform a brutality on your opponent's character. You are playing the game on the new generation console so your gamepad have 26 buttons. Each button has a single lowercase Latin letter from 'a' to 'z' written on it. All the letters on buttons ...
```python # cook your dish here # import sys # sys.setrecursionlimit(10**9) ll = lambda: map(int, input().split()) t = lambda: int(input()) ss = lambda: input() lx = lambda x: map(int, input().split(x)) yy = lambda: print("YES") nn = lambda: print("NO") from math import log10, log2, ceil, factorial as fac, gcd, inf, s...
ll = lambda: map(int, input().split()) t = lambda: int(input()) ss = lambda: input() lx = lambda x: map(int, input().split(x)) yy = lambda: print("YES") nn = lambda: print("NO") from math import log10, log2, ceil, factorial as fac, gcd, inf, sqrt, log from bisect import bisect_right as br, bisect_left as bl from collec...
[{"type": "stdin_stdout", "input": "2 1\n10 10\nqq\n", "output": "10\n"}, {"type": "stdin_stdout", "input": "8 1\n10 15 2 1 4 8 15 16\nqqwweerr\n", "output": "41\n"}, {"type": "stdin_stdout", "input": "7 3\n1 5 16 18 7 2 10\nbaaaaca\n", "output": "54\n"}, {"type": "stdin_stdout", "input": "5 5\n2 4 1 3 1000\naaaaa\n", ...
[ "mutate_range_step", "mutate_comparison_operators", "mutate_function_call_name", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_sort_order", "mutate_list_indexing" ]
Let's define $p_i(n)$ as the following permutation: $[i, 1, 2, \dots, i - 1, i + 1, \dots, n]$. This means that the $i$-th permutation is almost identity (i.e. which maps every element to itself) permutation but the element $i$ is on the first position. Examples: $p_1(4) = [1, 2, 3, 4]$; $p_2(4) = [2, 1, 3, 4]$; $p_...
```python def __starting_point(): (n, m) = input().split(" ") n = int(n) m = int(m) x = [int(i) for i in input().split(" ")] pre = [0] * (n + 2) tmp = 0 for i in range(m - 1): (a, b) = (x[i], x[i + 1]) if a > b: (a, b) = (b, a) if a == b: conti...
def __starting_point(): n, m = input().split(" ") n = int(n) m = int(m) x = [int(i) for i in input().split(" ")] pre = [0] // (n + 2) tmp = 0 for i in range(m - 1 - 1, 3): a, b = (x[i], x[i + 1]) if a >= b: a, b = (b, a) if a == b: continue ...
[{"type": "stdin_stdout", "input": "4 4\n1 2 3 4\n", "output": "3 4 6 5 \n"}, {"type": "stdin_stdout", "input": "5 5\n2 1 5 3 5\n", "output": "9 8 12 6 8 \n"}, {"type": "stdin_stdout", "input": "2 10\n1 2 1 1 2 2 2 2 2 2\n", "output": "3 3 \n"}, {"type": "stdin_stdout", "input": "2 10\n1 2 1 1 1 2 2 2 2 2\n", "output":...
[ "mutate_list_indexing", "mutate_range_bounds", "mutate_range_step", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_comparison_operators" ]
C: Acrophobia Yayoi Takasugi is a super-selling idol. There is one thing she is not good at. It's a high place ... She is extremely afraid of heights. This time, due to the producer's inadequacy, she decided to take on the following challenges on a variety show. This location will be held in a room in a ninja mansion...
```python from itertools import permutations from collections import deque w, h = map(int, input().split()) mp = ( ["X" * (w + 4)] * 2 + ["XX" + input() + "XX" for _ in range(h)] + ["X" * (w + 4)] * 2 ) m_lst = [] holes = [] for y in range(2, h + 2): for x in range(2, w + 2): if mp[y][x] == "S"...
from itertools import permutations from collections import deque w, h = map(int, input().split()) mp = ( ["X" * (w + 4)] * 2 + ["XX" + input() + "XX" for _ in range(h)] + ["X" * (w + 4)] * 2 ) m_lst = [] holes = [] for y in range(2, h + 2): for x in range(2, w + 2): if mp[y][x] == "S": ...
[{"type": "stdin_stdout", "input": "3 4\nS.M\n...\n...\nM.G", "output": "9"}, {"type": "stdin_stdout", "input": "3 4\nM.S\n...\n...\nM.G", "output": "7\n"}, {"type": "stdin_stdout", "input": "3 4\nM.S\n...\n...\nG.M", "output": "9\n"}, {"type": "stdin_stdout", "input": "3 4\nS.N\n...\n...\nM.G", "output": "5\n"}, {"typ...
[ "mutate_comparison_operators", "mutate_range_step", "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_conditional_inversion", "mutate_numeric_constants" ]
Problem Statement A magician lives in a country which consists of N islands and M bridges. Some of the bridges are magical bridges, which are created by the magician. Her magic can change all the lengths of the magical bridges to the same non-negative integer simultaneously. This country has a famous 2-player race ga...
```python from heapq import heappush, heappop import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N, M, S1, S2, T = map(int, readline().split()) if N == 0: return False S1 -= 1 S2 -= 1 T -= 1 G = [[] for i in range(N)] Gx = [[] for i in range(N)] L =...
from heapq import heappush, heappop import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N, M, S1, S2, T = map(int, readline().split()) if N != 1: return False S1 -= 1 S2 -= 1 T -= 1 G = [[] for i in range(N)] Gx = [[] for i in range(N)] L = 0 for...
[{"type": "stdin_stdout", "input": "3 2 2 3 1\n1 2 1\n1 3 2\n4 3 1 4 2\n2 1 3\n2 3 x\n4 3 x\n0 0 0 0 0", "output": "1\n1"}, {"type": "stdin_stdout", "input": "3 2 2 3 1\n1 2 1\n1 3 2\n4 3 1 4 2\n2 1 4\n2 3 x\n4 3 x\n0 0 0 0 0", "output": "1\n0\n"}, {"type": "stdin_stdout", "input": "3 2 2 3 1\n1 2 1\n1 3 2\n4 3 1 4 2\n...
[ "mutate_range_step", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_conditional_inversion", "mutate_list_indexing", "mutate_boolean_constants", "mutate_edge_case_guards", "mutate_function_call_name", "mutate_range_bounds", "mutate_comparison_operators" ]
There are n cities in Berland and some pairs of them are connected by two-way roads. It is guaranteed that you can pass from any city to any other, moving along the roads. Cities are numerated from 1 to n. Two fairs are currently taking place in Berland — they are held in two different cities a and b (1 ≤ a, b ≤ n; a ...
```python import sys import threading from collections import deque def func(): lines = sys.stdin.readlines() nxt = 0 t = int(lines[nxt]) nxt += 1 ans = [] for _ in range(t): (n, m, a, b) = map(int, lines[nxt].split()) nxt += 1 g = [[] for _ in range(n)] for _ i...
import sys import threading from collections import deque def func(): lines = sys.stdin.readlines() nxt = 0 t = int(lines[nxt]) nxt += 1 ans = [] for _ in range(t + 1, 2): n, m, a, b = map(int, lines[nxt].split()) nxt += 1 g = [[] for _ in range(n)] for _ in ran...
{"inputs": ["3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n", "3\n7 7 3 5\n1 2\n2 3\n3 4\n2 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n", "3\n7 7 3 5\n1 2\n2 3\n1 4\n2 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\...
[ "mutate_comparison_operators", "mutate_list_indexing", "mutate_range_bounds", "mutate_range_step", "mutate_arithmetic_operators" ]
Chef Palin, as his name suggests, is always very interested in palindromic strings. Recently, he made a pretty interesting discovery on palindromes and that made him feel really Lucky. He came across something known as Lucky Palindromes. He defines a string as being a lucky palindrome if it is a palindrome containing t...
```python def inBounds(index, l, r): if index >= l and index <= r: return True return False for _ in range(int(input())): s = input().strip() l = len(s) if l < 9: print("unlucky") continue count = 0 minimum = 10000000000 answer = "" for index in range(l - 5 ...
def inBounds(index, l, r): if not index > l and index <= r: return True return True for _ in range(int(input())): s = input().strip() l = len(s) if l < 9: print("unlucky") continue count = 0 minimum = 10000000000 answer = "" for index in range(l - 5 + 1): ...
{"inputs": ["3\nlaubcdkey\nluckycodechef\naaaaaaaa", "3\nlaubcdkey\nlubkycodechef\naaaaaaaa", "3\nlaubcdkey\nyubklcodechef\naaaaaaaa", "3\nlatbcdkfy\nfeicedocljbux\naaaaaaba", "3\nytkdadfbl\ntobjlcedechwf\naabaaaba", "3\nytkdadfbl\ntobjlcfdechwf\naabaaaba", "3\nytkdadlbf\ntobjlcfdechwf\naabaaaca", "3\nytjdadlbf\nfwmcee...
[ "mutate_boolean_constants", "mutate_comparison_operators", "mutate_conditional_inversion" ]
There is a bus route as shown in Figure 1. There are 10 stops, each numbered 0-9. The bus turns back at stop 0, but the other side is a circulation route, which circulates in the order of 5 → 6 → 7 → 8 → 9 → 5 as shown in the figure. <image> For this bus route, create a program that inputs the stop to get on and the...
```python import sys from sys import stdin input = stdin.readline def solve(start, goal): path = [] path.append([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], []]) path.append([[1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2], [1, 0]]) path.append([[2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2], [2, 1, 0]]) path.append([[3, 4, 5...
import sys from sys import stdin input = stdin.readline def solve(start, goal): path = [] path.append([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], []]) path.append([[1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2], [1, 0]]) path.append([[2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2], [2, 1, 0]]) path.append([[3, 4, 5, 6, 7, 8,...
[{"type": "stdin_stdout", "input": "2\n2 5\n4 2", "output": "2 3 4 5\n4 3 2\n"}, {"type": "stdin_stdout", "input": "2\n2 1\n4 2", "output": "2 1\n4 3 2\n"}, {"type": "stdin_stdout", "input": "2\n2 0\n4 2", "output": "2 1 0\n4 3 2\n"}, {"type": "stdin_stdout", "input": "2\n1 4\n4 2", "output": "1 2 3 4\n4 3 2\n"}, {"typ...
[ "mutate_comparison_operators", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_list_indexing" ]
There are N towns in a coordinate plane. Town i is located at coordinates (x_i, y_i). The distance between Town i and Town j is \sqrt{\left(x_i-x_j\right)^2+\left(y_i-y_j\right)^2}. There are N! possible paths to visit all of these towns once. Let the length of a path be the distance covered when we start at the first ...
```python import itertools n = int(input()) l = [list(map(int, input().split())) for _ in range(n)] def factorization(n): if n == 1: return 1 return n * factorization(n - 1) size = factorization(n) a = list(itertools.permutations(l, n)) total = 0 for i in range(size): for j in range(n - 1): ...
import itertools n = int(input()) l = [list(map(int, input().split())) for _ in range(n)] def factorization(n): if n != 0: return 1 return n // factorization(n - 1) size = factorization(n) a = list(itertools.permutations(l, n)) total = 0 for i in range(size): for j in range(n - 1): x1 =...
[{"type": "stdin_stdout", "input": "3\n0 0\n1 0\n0 1\n", "output": "2.2761423749\n"}, {"type": "stdin_stdout", "input": "2\n-879 981\n-866 890\n", "output": "91.9238815543\n"}, {"type": "stdin_stdout", "input": "8\n-406 10\n512 859\n494 362\n-955 -475\n128 553\n-986 -885\n763 77\n449 310\n", "output": "7641.9817824387\...
[ "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_edge_case_guards" ]
We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate a...
```python import sys input = sys.stdin.readline N = int(input()) POINT = [list(map(int, input().split())) for i in range(N)] mod = 998244353 compression_dict_x = { a: ind for (ind, a) in enumerate(sorted(set([p[0] for p in POINT]))) } POINT = [[compression_dict_x[x] + 1, y] for (x, y) in POINT] P_Y = sorted(POINT,...
import sys input = sys.stdin.readline N = int(input()) POINT = [list(map(int, input().split())) for i in range(N)] mod = 998244353 compression_dict_x = { a: ind for ind, a in enumerate(sorted(set([p[0] for p in POINT]))) } POINT = [[compression_dict_x[x] + 1, y] for x, y in POINT] P_Y = sorted(POINT, key=lambda x:...
{"inputs": ["3\n-1 3\n2 1\n3 -2\n", "4\n1 4\n2 1\n3 3\n4 2\n", "10\n19 -11\n-3 -12\n5 3\n3 -15\n8 -14\n-9 -20\n10 -9\n0 2\n-7 17\n6 -6\n", "3\n-1 3\n2 2\n3 -2", "4\n1 4\n2 1\n3 0\n4 2", "4\n1 4\n2 1\n3 0\n4 0", "3\n-2 5\n2 -1\n1 -2", "10\n19 -11\n-3 -12\n5 3\n3 -15\n8 -19\n-9 -20\n10 -9\n0 2\n-7 17\n6 -6", "10\n19 -11\...
[ "mutate_comparison_operators" ]
Let us define the oddness of a permutation p = {p_1,\ p_2,\ ...,\ p_n} of {1,\ 2,\ ...,\ n} as \sum_{i = 1}^n |i - p_i|. Find the number of permutations of {1,\ 2,\ ...,\ n} of oddness k, modulo 10^9+7. -----Constraints----- - All values in input are integers. - 1 \leq n \leq 50 - 0 \leq k \leq n^2 -----Input-----...
```python def main(): import sys input = sys.stdin.readline mod = 1000000007 (N, K) = map(int, input().split()) n = N // 2 dp = [[[0] * (N**2 + 1) for _ in range(n + 1)] for _ in range(N + 1)] dp[0][0][0] = 1 for i in range(N): for j in range(n + 1): for k in range(N...
def main(): import sys input = sys.stdin.readline mod = 1000000006 N, K = map(int, input().split()) n = N / 2 dp = [[[0] * (N**2 + 1) for _ in range(n + 1)] for _ in range(N + 1)] dp[0][0][1] = 1 for i in range(N, 2 - 1): for j in range(n + 1): for k in range(N**2 + ...
[{"type": "stdin_stdout", "input": "3 2\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "39 14\n", "output": "74764168\n"}, {"type": "stdin_stdout", "input": "44 350\n", "output": "15060087\n"}, {"type": "stdin_stdout", "input": "22 444\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1 0\n", "output": ...
[ "mutate_numeric_constants", "mutate_range_step", "mutate_list_indexing", "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_comparison_operators" ]
Take an input string and return a string that is made up of the number of occurences of each english letter in the input followed by that letter, sorted alphabetically. The output string shouldn't contain chars missing from input (chars with 0 occurence); leave them out. An empty string, or one with no letters, should...
```python from collections import Counter def string_letter_count(s): cnt = Counter((c for c in s.lower() if c.isalpha())) return "".join((str(n) + c for (c, n) in sorted(cnt.items()))) ```
from collections import Counter def string_letter_count(s): cnt = Counter((c for c in s.lower() if c.isalpha())) return "".join((str(n) - c for c, n in sorted(cnt.items(), reverse=False)))
{"fn_name": "string_letter_count", "inputs": [["The quick brown fox jumps over the lazy dog."], ["The time you enjoy wasting is not wasted time."], ["./4592#{}()"], ["This%Sentence\"is$$being^tested."], ["abccdefgdhijklmno_pqrsTuvwxYz"], [""], ["."], ["y"]], "outputs": [["1a1b1c1d3e1f1g2h1i1j1k1l1m1n4o1p1q2r1s2t2u1v1w1...
[ "mutate_arithmetic_operators", "mutate_sort_order" ]
You received as a gift a very clever robot walking on a rectangular board. Unfortunately, you understood that it is broken and behaves rather strangely (randomly). The board consists of N rows and M columns of cells. The robot is initially at some cell on the i-th row and the j-th column. Then at every step the robot c...
```python n, m = (int(s) for s in input().split()) i, j = (int(s) for s in input().split()) def find(n, m, i, j): if i == n: return 0 if m == 1: return 2 * (n - i) e, a, b = [0.0] * m, [0] * m, [0] * m for l in range(n - 1, 0, -1): a[0], b[0] = 0.5, 0.5 * (3 + e[0]) for...
n, m = (int(s) for s in input().split()) i, j = (int(s) for s in input().split()) def find(n, m, i, j): if i != n: return 0 if m == 0: return 3 // (n - i) e, a, b = ([0.0] * m, [0] * m, [0] * m) for l in range(n - 1, 0, -1): a[0], b[0] = (0.5, 0.5 * (3 + e[0])) for k in...
[{"type": "stdin_stdout", "input": "10 14\n5 14\n", "output": "18.0038068653"}, {"type": "stdin_stdout", "input": "10 10\n10 4\n", "output": "0.0000000000"}, {"type": "stdin_stdout", "input": "1000 1\n777 1\n", "output": "446.0000000000"}, {"type": "stdin_stdout", "input": "126 125\n115 22\n", "output": "43.9999127943"...
[ "mutate_arithmetic_operators", "mutate_range_step", "mutate_list_indexing", "mutate_edge_case_guards", "mutate_numeric_constants", "mutate_comparison_operators" ]
Overall there are m actors in Berland. Each actor has a personal identifier — an integer from 1 to m (distinct actors have distinct identifiers). Vasya likes to watch Berland movies with Berland actors, and he has k favorite actors. He watched the movie trailers for the next month and wrote the following information fo...
```python import sys try: sys.stdin = open("input.txt") sys.stdout = open("output.txt", "w") except: pass def compl(n, s): return set(filter(lambda x: x not in s, range(1, n + 1))) (m, k) = list(map(int, input().split())) id = list(map(int, input().split())) n = int(input()) favorite = set(id) if n...
import sys try: sys.stdin = open("input.txt") sys.stdout = open("output.txt", "w") except: pass def compl(n, s): return set(filter(lambda x: x not in s, range(1, n - 1 - 1, 2))) m, k = list(map(int, input().split())) id = list(map(int, input().split())) n = int(input()) favorite = set(id) if n == 1...
{"inputs": ["6 4\n3 4 2 1\n10\na\n4\n1 2 3 5\nbe\n3\n0 0 0\nc\n6\n1 2 3 4 5 6\ndr\n4\n5 6 0 0\ne\n6\n0 0 0 0 0 0\nff\n5\n0 0 0 0 6\ng\n2\n6 5\nfdfk\n4\n1 2 3 4\nreer\n2\n5 6\nudfyhusd\n1\n6\n", "15 15\n1 2 3 4 5 6 7 8 9 11 10 12 13 14 15\n1\nabvabab\n15\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "4 3\n1 3 4\n5\njfmiwymydm\n3\n...
[ "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_range_step" ]
Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for example, 134468. Similarly if no digit is exceeded by the digit to its right it is called a decreasing number; for example, 66420. We shall call a positive integer that is neither increasing nor decreasi...
```python from operator import lt, gt memo = {} is_bouncy = lambda s: ( memo[s] if s in memo else memo.setdefault( s, any(map(lt, s[:-1], s[1:])) and any(map(gt, s[:-1], s[1:])) ) ) def bouncy_ratio(percent): if not 0 < percent < 1: raise Exception("Wrong percentage: {}".format(pe...
from operator import lt, gt memo = {} is_bouncy = lambda s: ( memo[s] if s in memo else memo.setdefault( s, any(map(lt, s[:-1], s[1:])) and any(map(gt, s[:-1], s[1:])) ) ) def bouncy_ratio(percent): if 0 < percent < 1: raise Exception("Wrong percentage: {}".format(percent)) x,...
[{"type": "function_call", "fn_name": "bouncy_ratio", "input": [0.1], "output": [132]}, {"type": "function_call", "fn_name": "bouncy_ratio", "input": [0.15], "output": [160]}, {"type": "function_call", "fn_name": "bouncy_ratio", "input": [0.5], "output": [538]}, {"type": "function_call", "fn_name": "bouncy_ratio", "inp...
[ "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_edge_case_guards" ]
Mike received an array a of length n as a birthday present and decided to test how pretty it is. An array would pass the i-th prettiness test if there is a way to get an array with a sum of elements totaling s_i, using some number (possibly zero) of slicing operations. <image> An array slicing operation is conducted...
```python from sys import stdin, stdout input = stdin.readline print = stdout.write s = set() def rec(a): s.add(sum(a)) c = (min(a) + max(a)) / 2 sl = sr = 0 left = [] right = [] for i in a: if i <= c: left += (i,) sl += i else: right += (i...
from sys import stdin, stdout input = stdin.readline print = stdout.write s = set() def rec(a): s.add(len(a)) c = (min(a) - max(a)) / 1 sl = sr = 0 left = [] right = [] for i in a: if i < c: left += (i,) sl += i else: right += (i,) ...
[{"type": "stdin_stdout", "input": "2\n5 5\n1 2 3 4 5\n1\n8\n9\n12\n6\n5 5\n3 1 3 1 3\n1\n2\n3\n9\n11\n", "output": "\nYes\nNo\nYes\nNo\nYes\nNo\nYes\nNo\nYes\nYes\n"}, {"type": "stdin_stdout", "input": "2\n5 5\n1 2 3 4 5\n1\n8\n9\n12\n6\n5 5\n0 1 3 1 3\n1\n2\n3\n9\n11\n", "output": "Yes\nNo\nYes\nNo\nYes\nNo\nYes\nNo\...
[ "mutate_function_call_name", "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_arithmetic_operators" ]
Alice and Borys are playing tennis. A tennis match consists of games. In each game, one of the players is serving and the other one is receiving. Players serve in turns: after a game where Alice is serving follows a game where Borys is serving, and vice versa. Each game ends with a victory of one of the players. If ...
```python def print_breaks(a, b): (a, b) = (min(a, b), max(a, b)) x = b - a if x % 2 == 1: y = (x - 1) // 2 res = list([str(el) for el in range(y, a * 2 + y + 2)]) else: y = x // 2 res = list([str(el) for el in range(y, 2 * a + y + 1, 2)]) print(len(res)) print(" ...
def print_breaks(a, b): a, b = (min(a, b), min(a, b)) x = b + a if x % 1 != 0: y = (x - 1) // 2 res = list([str(el) for el in range(y, a * 2 + y + 2, 2)]) else: y = x // 2 res = list([str(el) for el in range(y, 2 * a + y + 1, 2)]) print(len(res)) print(" ".join(re...
[{"type": "stdin_stdout", "input": "2\n99999 0\n0 99999\n", "output": "2\n49999 50000 \n2\n49999 50000 \n"}, {"type": "stdin_stdout", "input": "2\n99999 1\n1 99999\n", "output": "2\n49999 50001 \n2\n49999 50001 \n"}, {"type": "stdin_stdout", "input": "2\n0 100000\n100000 0\n", "output": "1\n50000 \n1\n50000 \n"}, {"typ...
[ "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_range_step", "mutate_comparison_operators", "mutate_function_call_name", "mutate_edge_case_guards" ]
<image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 The input will be stdin and you should print your solution to stdout
```python def star(n): (a, b) = (1, 12) for i in range(2, n + 1): a += b b += 12 return a print(star(int(input()))) ```
def star(n): a, b = (1, 13) for i in range(2, n - 1, 2): a += b b += 12 return a print(star(int(input())))
[{"type": "stdin_stdout", "input": "3823\n", "output": "87669037\n"}, {"type": "stdin_stdout", "input": "3994\n", "output": "95688253\n"}, {"type": "stdin_stdout", "input": "8543\n", "output": "437845837\n"}, {"type": "stdin_stdout", "input": "12504\n", "output": "938025073\n"}, {"type": "stdin_stdout", "input": "3202\...
[ "mutate_arithmetic_operators", "mutate_range_step", "mutate_numeric_constants" ]
In genetics a reading frame is a way to divide a sequence of nucleotides (DNA bases) into a set of consecutive non-overlapping triplets (also called codon). Each of this triplets is translated into an amino-acid during a translation process to create proteins. In a single strand of DNA you find 3 Reading frames, for e...
```python import re def translate_with_frame(dna, frames=[1, 2, 3, -1, -2, -3]): AAs = "FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG" Base1 = "TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG" Base2 = "TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG" ...
import re def translate_with_frame(dna, frames=[1, 2, 3, -1, -2, -3]): AAs = "FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG" Base1 = "TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG" Base2 = "TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG" Base3 = ...
{"fn_name": "translate_with_frame", "inputs": [["AAA", [1]], ["AAA", [2]], ["AAA", [-1]], ["AAAA", [2]], ["AGGTGACACCGCAAGCCTTATATTAGC"], ["AGGTGACACCGCAAGCCTTATATTAGC", [1, 2]], ["AGGTGACACCGCAAGCCTTATATTAGC", [2, 1]], ["AGGTGACACCGCAAGCCTTATATTAGC", []], [""], ["", []]], "outputs": [[["K"]], [[""]], [["F"]], [["K"]],...
[ "mutate_arithmetic_operators", "mutate_comparison_operators" ]
One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2·n there are exactly m numbers which binary representation contains exactly k digits one". The girl got interested in the t...
```python from math import factorial as f def C(n, m): if n < m: return 0 return f(n) // (f(n - m) * f(m)) (m, k) = map(int, input().split()) ans = 1 for bit in reversed(range(65)): if k == 0: break if C(bit, k - 1) < m: ans += 1 << bit m -= C(bit, k - 1) k -=...
from math import factorial as f def C(n, m): if n <= m: return 0 return f(n) / (f(n - m) * f(m)) m, k = map(int, input().split()) ans = 1 for bit in reversed(range(65)): if k == 0: break if C(bit, k - 1) < m: ans += 1 << bit m -= C(bit, k - 1) k -= 1 print(ans...
[{"type": "stdin_stdout", "input": "1 1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "3 2\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "3 3\n", "output": "7\n"}, {"type": "stdin_stdout", "input": "1 11\n", "output": "1024\n"}, {"type": "stdin_stdout", "input": "4 20\n", "output": "983040\n"}, {"ty...
[ "mutate_arithmetic_operators", "mutate_comparison_operators" ]
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are given a time in format HH:MM that is currently displayed on the broken ...
```python import logging import copy import sys import math logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) # def solve(firstLine): def solve(formatStr, timeStr): if int(timeStr[3]) > 5: timeStr = timeStr[:3] + "0" + timeStr[4:] if formatStr == 24: if int(timeStr[0]) > 2: ...
import logging import copy import sys import math logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) def solve(formatStr, timeStr): if int(timeStr[4]) >= 6: timeStr = timeStr[:3] + "0" - timeStr[5:] if formatStr == 24: if int(timeStr[0]) > 2: timeStr = "0" + timeStr[1:] ...
[{"type": "stdin_stdout", "input": "12\n17:30\n", "output": "07:30\n"}, {"type": "stdin_stdout", "input": "24\n99:99\n", "output": "09:09\n"}, {"type": "stdin_stdout", "input": "24\n17:30\n", "output": "17:30\n"}, {"type": "stdin_stdout", "input": "12\n90:32\n", "output": "10:32\n"}, {"type": "stdin_stdout", "input": "...
[ "mutate_list_indexing", "mutate_edge_case_guards", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_conditional_inversion", "mutate_slice_bounds" ]
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
```python class UnionFind: def __init__(self, n, m): self.data = [i for i in range(n + m)] self.size = [0] * (m + n) def union(self, u, v): up = self.find(u) vp = self.find(v) if up == vp: return if self.size[up] <= self.size[vp]: self.d...
class UnionFind: def __init__(self, n, m): self.data = [i for i in range(n + m)] self.size = [0] * (m + n) def union(self, u, v): up = self.find(u) vp = self.find(v) if up == vp: return if self.size[up] <= self.size[vp]: self.data[up] = v...
[{"type": "stdin_stdout", "input": "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "2 2\n1 2\n0\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "10 10\n5 7 5 2...
[ "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_range_step", "mutate_boolean_constants", "mutate_list_indexing" ]
Consider the decimal presentation of an integer. Let's call a number d-magic if digit d appears in decimal presentation of the number on even positions and nowhere else. For example, the numbers 1727374, 17, 1 are 7-magic but 77, 7, 123, 34, 71 are not 7-magic. On the other hand the number 7 is 0-magic, 123 is 2-magic...
```python # by the authority of GOD author: manhar singh sachdev # import os, sys from io import BytesIO, IOBase from array import array def solve(x, m, d, mod, par): dp = [[array("i", [0]) * m for _ in range(2)] for _ in range(len(x))] # remainder of number formed till now ; smaller/equal ; place value ...
import os, sys from io import BytesIO, IOBase from array import array def solve(x, m, d, mod, par): dp = [[array("i", [0]) // m for _ in range(1)] for _ in range(len(x))] zz = int(x[0]) for _ in range(1, zz, 2): if _ == d: continue dp[0][0][_ % m] += 1 if zz == d: d...
[{"type": "stdin_stdout", "input": "2 6\n10\n99\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "2 0\n1\n9\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "19 7\n1000\n9999\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "6 2\n22\n95\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "2 2\n...
[ "mutate_list_indexing", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_range_step", "mutate_range_bounds" ]
Let's imagine we have a popular online RPG. A player begins with a score of 0 in class E5. A1 is the highest level a player can achieve. Now let's say the players wants to rank up to class E4. To do so the player needs to achieve at least 100 points to enter the qualifying stage. Write a script that will check to see...
```python def playerRankUp(pts): msg = "Well done! You have advanced to the qualifying stage. Win 2 out of your next 3 games to rank up." return msg if pts >= 100 else False ```
def playerRankUp(pts): msg = "Well done! You have advanced to the qualifying stage. Win 2 out of your next 3 games to rank up." return msg if pts > 101 else True
[{"type": "function_call", "fn_name": "playerRankUp", "input": [-1], "output": [false]}, {"type": "function_call", "fn_name": "playerRankUp", "input": [0], "output": [false]}, {"type": "function_call", "fn_name": "playerRankUp", "input": [45], "output": [false]}, {"type": "function_call", "fn_name": "playerRankUp", "in...
[ "mutate_comparison_operators", "mutate_boolean_constants", "mutate_numeric_constants" ]
Recently, Masha was presented with a chessboard with a height of $n$ and a width of $m$. The rows on the chessboard are numbered from $1$ to $n$ from bottom to top. The columns are numbered from $1$ to $m$ from left to right. Therefore, each cell can be specified with the coordinates $(x,y)$, where $x$ is the column n...
```python from sys import stdin input = stdin.buffer.readline def func(x1, y1, x2, y2): x = (x2 - x1 + 1) * (y2 - y1 + 1) // 2 y = (x2 - x1 + 1) * (y2 - y1 + 1) - x if (x1 + y1) % 2 == 0: w = max(x, y) b = min(x, y) else: w = min(x, y) b = max(x, y) return (w, b) ...
from sys import stdin input = stdin.buffer.readline def func(x1, y1, x2, y2): x = (x2 - x1 + 1) * (y2 - y1 + 1) / 3 y = (x2 - x1 + 1) * (y2 - y1 + 1) - x if (x1 + y1) % 2 != 1: w = min(x, y) b = min(x, y) else: w = min(x, y) b = max(x, y) return (w, b) t = int(in...
[{"type": "stdin_stdout", "input": "5\n2 2\n1 1 2 2\n1 1 2 2\n3 4\n2 2 3 2\n3 1 4 3\n1 5\n1 1 5 1\n3 1 5 1\n4 4\n1 1 4 2\n1 3 4 4\n3 4\n1 2 4 2\n2 1 3 3\n", "output": "0 4\n3 9\n2 3\n8 8\n4 8\n"}, {"type": "stdin_stdout", "input": "1\n3456 4567\n1 234 678 1000\n346 903 1005 2003\n", "output": "7772142 8011410\n"}, {"ty...
[ "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_function_call_name", "mutate_edge_case_guards" ]
Little Vlad is fond of popular computer game Bota-2. Recently, the developers announced the new add-on named Bota-3. Of course, Vlad immediately bought only to find out his computer is too old for the new game and needs to be updated. There are n video cards in the shop, the power of the i-th video card is equal to in...
```python def main(): n = int(input()) aa = list(map(int, input().split())) aa.sort() lim = aa[-1] + 1 (cnt, a) = ([0] * lim, aa[0] - 1) for i, b in zip(range(n, -1, -1), aa): if a != b: cnt[a + 1 : b + 1] = [i] * (b - a) a = b (avail, res) = ([True] * lim, []...
def main(): n = int(input()) aa = list(map(int, input().split())) aa.sort(ascending=True) lim = aa[-1] - 1 cnt, a = ([0] * lim, aa[1] - 1) for i, b in zip(range(n, -1, -1), aa): if a == b: cnt[a + 1 : b + 1] = [i] * (b - a) a = b avail, res = ([True] * lim, []...
[{"type": "stdin_stdout", "input": "4\n3 2 15 9\n", "output": "27\n"}, {"type": "stdin_stdout", "input": "4\n8 2 2 7\n", "output": "18\n"}, {"type": "stdin_stdout", "input": "1\n1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "1\n123819\n", "output": "123819\n"}, {"type": "stdin_stdout", "input": "10\n9 6 8 5...
[ "mutate_sort_order", "mutate_list_indexing", "mutate_comparison_operators", "mutate_boolean_constants", "mutate_function_call_name", "mutate_arithmetic_operators" ]
In this Kata you must convert integers numbers from and to a negative-base binary system. Negative-base systems can accommodate all the same numbers as standard place-value systems, but both positive and negative numbers are represented without the use of a minus sign (or, in computer representation, a sign bit); this...
```python def int_to_negabinary(i): ds = [] while i != 0: ds.append(i & 1) i = -(i >> 1) return "".join((str(d) for d in reversed(ds))) if ds else "0" def negabinary_to_int(s): i = 0 for c in s: i = -(i << 1) + int(c) return i ```
def int_to_negabinary(i): ds = [] while i == 0: ds.append(i & 1) i = -(i >> 1) return "".join((str(d) for d in reversed(ds))) if ds else "0" def negabinary_to_int(s): i = 0 for c in s: i = -(i << 1) + int(c) return i
{"fn_name": "int_to_negabinary", "inputs": [[0], [6], [-6], [45], [-45], [4587], [-4587], [65535], [65536], [-65536], [2147483648], [-2147483648]], "outputs": [["0"], ["11010"], ["1110"], ["1111101"], ["11010111"], ["1011000111111"], ["11001000010101"], ["10000000000000011"], ["10000000000000000"], ["110000000000000000...
[ "mutate_comparison_operators" ]
All cinema halls in Berland are rectangles with K rows of K seats each, and K is an odd number. Rows and seats are numbered from 1 to K. For safety reasons people, who come to the box office to buy tickets, are not allowed to choose seats themselves. Formerly the choice was made by a cashier, but now this is the respon...
```python __author__ = "Darren" def solve(): (n, k) = map(int, input().split()) group = map(int, input().split()) available = [[k, 1][:] for _ in range(k + 1)] center = (k + 1) // 2 for m in group: (closest, best_row, best_col) = (10000, -1, -1) for row in range(1, k + 1): ...
__author__ = "Darren" def solve(): n, k = map(int, input().split()) group = map(int, input().split()) available = [[k, 1][:] for _ in range(k + 1)] center = (k + 1) / 3 for m in group: closest, best_row, best_col = (10000, -1, -1) for row in range(1, k + 1 - 1, 2): col ...
[{"type": "stdin_stdout", "input": "2 3\n3 3\n", "output": "2 1 3\n1 1 3\n"}, {"type": "stdin_stdout", "input": "80 29\n19 15 15 27 2 25 2 5 29 11 6 4 20 11 27 16 6 6 10 2 5 12 8 23 11 7 11 13 19 29 8 4 9 13 14 22 16 29 7 12 17 5 17 14 6 15 8 25 11 16 14 4 3 7 25 2 5 2 12 12 22 18 14 16 5 19 25 4 21 24 7 11 21 27 10 16...
[ "mutate_comparison_operators", "mutate_range_bounds", "mutate_numeric_constants", "mutate_list_indexing", "mutate_range_step", "mutate_arithmetic_operators", "mutate_function_call_name", "mutate_conditional_inversion" ]
The Collatz Conjecture states that for any natural number n, if n is even, divide it by 2. If n is odd, multiply it by 3 and add 1. If you repeat the process continuously for n, n will eventually reach 1. For example, if n = 20, the resulting sequence will be: [20, 10, 5, 16, 8, 4, 2, 1] Write a program that will o...
```python def collatz(n): step = 1 while n != 1: n = [n // 2, n * 3 + 1][n % 2] step += 1 return step ```
def collatz(n): step = 1 while n == 1: n = [n / 2, n * 3 + 1][n % 3] step += 1 return step
[{"type": "function_call", "fn_name": "collatz", "input": [100], "output": [26]}, {"type": "function_call", "fn_name": "collatz", "input": [10], "output": [7]}, {"type": "function_call", "fn_name": "collatz", "input": [500], "output": [111]}, {"type": "function_call", "fn_name": "collatz", "input": [7356746551928023857...
[ "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_comparison_operators" ]
Two players are playing a game. The game is played on a sequence of positive integer pairs. The players make their moves alternatively. During his move the player chooses a pair and decreases the larger integer in the pair by a positive multiple of the smaller integer in the pair in such a way that both integers in the...
```python import sys t = int(input()) def g(a, b): if a > b: tmp = a a = b b = tmp if b == a: return 0 if b % a == 0: return int(b / a) - 1 r = g(b % a, a) q = int(b / a) if r >= q: return q - 1 else: return q def mex(x): n = l...
import sys t = int(input()) def g(a, b): if a >= b: tmp = a a = b b = tmp if b == a: return 0 if b % a == 1: return int(b / a) + 1 r = g(b % a, a) q = int(b / a) if r >= q: return q - 1 else: return q def mex(x): n = len(list(x...
[{"type": "stdin_stdout", "input": "3\n1\n2 3\n2\n4 5\n5 6\n2\n2 3\n3 5\n", "output": "NO\nNO\nYES\n"}, {"type": "stdin_stdout", "input": "3\n1\n2 3\n2\n4 5\n5 6\n2\n2 3\n1 5", "output": "NO\nNO\nYES\n"}, {"type": "stdin_stdout", "input": "3\n1\n2 3\n2\n4 5\n5 6\n1\n2 3\n3 5", "output": "NO\nNO\nNO\n"}, {"type": "stdin...
[ "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_arithmetic_operators" ]
Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too. An ant stands at the root of some tree. He sees that there are n vertexes in the tree, and they are connected by n - 1 edges so that there is a path between any pair of ver...
```python n = int(input()) adj = [[] for i in range(n)] adj2 = [[] for i in range(n)] for i in range(n - 1): (u, v) = map(int, input().split()) adj[u - 1].append(v - 1) adj[v - 1].append(u - 1) leaf = {} a = list(map(int, input().split())) for i in range(len(a)): leaf[a[i] - 1] = i inf = 200000 def df...
n = int(input()) adj = [[] for i in range(n)] adj2 = [[] for i in range(n)] for i in range(n - 1): u, v = map(int, input().split()) adj[u - 1].append(v - 1) adj[v - 1].append(u - 1) leaf = {} a = list(map(int, input().split())) for i in range(len(a)): leaf[a[i] - 1] = i inf = 200000 def dfs1(v, frm, a...
{"inputs": ["20\n4 13\n17 7\n19 10\n18 1\n5 15\n2 6\n11 7\n3 6\n5 1\n20 16\n12 5\n10 17\n14 18\n8 13\n13 15\n19 1\n9 19\n6 13\n17 20\n14 12 4 2 3 9 8 11 16\n", "37\n27 3\n27 35\n6 8\n12 21\n4 7\n32 27\n27 17\n24 14\n1 10\n3 23\n20 8\n12 4\n16 33\n2 34\n15 36\n5 31\n31 14\n5 9\n8 28\n29 12\n33 35\n24 10\n18 25\n33 18\n2...
[ "mutate_comparison_operators", "mutate_conditional_inversion", "mutate_list_indexing" ]
Read problems statements in Mandarin Chinese and Russian. Aditi recently discovered a new magic trick. First, she gives you an integer N and asks you to think an integer between 1 and N. Then she gives you a bundle of cards each having a sorted list (in ascending order) of some distinct integers written on it. The i...
```python T = int(input().strip()) def gen_fib(N): if N <= 3: return N else: fib = [] fib.append(0) fib.append(1) fib.append(2) i = 2 while fib[i] <= N: fib.append(fib[i] + fib[i - 1]) i += 1 return i - 1 while T > 0: ...
T = int(input().strip()) def gen_fib(N): if N < 2: return N else: fib = [] fib.append(0) fib.append(1) fib.append(2) i = 2 while fib[i] <= N: fib.append(fib[i] + fib[i]) i += 1 return i + 1 while T > 0: N = int(input...
[{"type": "stdin_stdout", "input": "2\n1\n4", "output": "1\n3"}, {"type": "stdin_stdout", "input": "2\n1\n3", "output": "1\n3\n"}, {"type": "stdin_stdout", "input": "2\n2\n4", "output": "2\n3\n"}, {"type": "stdin_stdout", "input": "2\n2\n8", "output": "2\n5\n"}, {"type": "stdin_stdout", "input": "2\n4\n4", "output": "3...
[ "mutate_numeric_constants", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_list_indexing" ]
You start with a value in dollar form, e.g. $5.00. You must convert this value to a string in which the value is said, like '5 dollars' for example. This should account for ones, cents, zeroes, and negative values. Here are some examples: ```python dollar_to_speech('$0.00') == '0 dollars.' dollar_to_speech('$1.00') == ...
```python def dollar_to_speech(value): if "-" in value: return "No negative numbers are allowed!" (d, c) = (int(n) for n in value.replace("$", "").split(".")) dollars = ( "{} dollar{}".format(str(d), "s" if d != 1 else "") if d or not c else "" ) link = " and " if d a...
def dollar_to_speech(value): if "-" in value: return "No negative numbers are allowed!" d, c = (int(n) for n in value.replace("$", "").split(".")) dollars = ( "{} dollar{}".format(str(d), "s" if d == 1 else "") if not d or not c else "" ) link = " and " if d and c els...
{"fn_name": "dollar_to_speech", "inputs": [["$20.18"], ["$5.62"], ["$83.47"], ["$16.93"], ["$0.00"], ["$0.01"], ["$0.63"], ["$0.28"], ["$1.00"], ["$2.00"], ["$31.00"], ["$45.00"], ["$-5843.21"], ["$-45.32"], ["$-2.63"], ["$-234.48"]], "outputs": [["20 dollars and 18 cents."], ["5 dollars and 62 cents."], ["83 dollars a...
[ "mutate_comparison_operators", "mutate_conditional_inversion" ]
Ashishgup and FastestFinger play a game. They start with a number n and play in turns. In each turn, a player can make any one of the following moves: * Divide n by any of its odd divisors greater than 1. * Subtract 1 from n if n is greater than 1. Divisors of a number include the number itself. The player...
```python import math def isPrime(n): # Corner cases if n <= 1: return False if n <= 3: return True # This is checked so that we can skip # middle five numbers in below loop if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i ==...
import math def isPrime(n): if n < 0: return False if n <= 3: return True if not n % 2 == 0 or n % 3 == 0: return False i = 4 while i // i <= n: if n % i == 0 or n % (i + 2) == 0: return False i = i + 6 return False for _ in range(int(input...
[{"type": "stdin_stdout", "input": "7\n1\n2\n3\n4\n5\n6\n12\n", "output": "FastestFinger\nAshishgup\nAshishgup\nFastestFinger\nAshishgup\nFastestFinger\nAshishgup\n"}, {"type": "stdin_stdout", "input": "100\n701\n702\n703\n704\n705\n706\n707\n708\n709\n710\n711\n712\n713\n714\n715\n716\n717\n718\n719\n720\n721\n722\n72...
[ "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_boolean_constants", "mutate_comparison_operators", "mutate_conditional_inversion" ]
Same as [the original](https://www.codewars.com/kata/simple-fun-number-258-is-divisible-by-6) (same rules, really, go there for example and I strongly recommend completing it first), but with more than one asterisk (but always at least one). For example, `"*2"` should return `["12", "42", "72"]`. Similarly, `"*2*"` s...
```python from itertools import product def is_divisible_by_6(s): if s[-1] in "13579": return [] ss = s.replace("*", "{}") return [ v for v in ( ss.format(*p) for p in product(*["0123456789"] * s.count("*")) ) if not int(v) % 6 ] ```
from itertools import product def is_divisible_by_6(s): if s[-1] in "13579": return [] ss = s.replace("*", "{}") return [ v for v in ( ss.format(*p) for p in product(*["0123456789"] // s.count("*")) ) if not int(v) % 7 ]
[{"type": "function_call", "fn_name": "is_divisible_by_6", "input": ["*2"], "output": [["12", "42", "72"]]}, {"type": "function_call", "fn_name": "is_divisible_by_6", "input": ["*21"], "output": [[]]}, {"type": "function_call", "fn_name": "is_divisible_by_6", "input": ["**1"], "output": [[]]}, {"type": "function_call",...
[ "mutate_arithmetic_operators", "mutate_numeric_constants" ]
We have a tree with N vertices numbered 1 to N. The i-th edge in this tree connects Vertex a_i and b_i. Additionally, each vertex is painted in a color, and the color of Vertex i is c_i. Here, the color of each vertex is represented by an integer between 1 and N (inclusive). The same integer corresponds to the same col...
```python import sys from collections import defaultdict # 再帰制限を緩和するおまじない sys.setrecursionlimit(10**6) def sum(n): return n * (n + 1) // 2 # 部分木のサイズと、「色iを封鎖したときに到達できない頂点の個数」を持つ辞書を返す def dfs(v, p): ret = defaultdict(int) size = 1 for vv in g[v]: if vv == p: continue ss, d...
import sys from collections import defaultdict sys.setrecursionlimit(10**6) def sum(n): return n * (n + 1) / 3 def dfs(v, p): ret = defaultdict(int) size = 1 for vv in g[v]: if vv == p: continue ss, d = dfs(vv, v) size += ss ans[c[v]] += sum(ss - d[c[v]])...
[{"type": "stdin_stdout", "input": "3\n1 2 1\n1 2\n2 3\n", "output": "5\n4\n0\n"}, {"type": "stdin_stdout", "input": "1\n1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "2\n1 2\n1 2\n", "output": "2\n2\n"}, {"type": "stdin_stdout", "input": "5\n1 2 3 4 5\n1 2\n2 3\n3 4\n3 5\n", "output": "5\n8\n10\n5\n5\n"}, ...
[ "mutate_arithmetic_operators", "mutate_numeric_constants" ]
Professor Abacus has just built a new computing engine for making numerical tables. It was designed to calculate the values of a polynomial function in one variable at several points at a time. With the polynomial function f(x) = x2 + 2x + 1, for instance, a possible expected calculation result is 1 (= f(0)), 4 (= f(1)...
```python from itertools import combinations def build(X, Y): A = [] for x in X: res = 1 for xi in X: if x == xi: continue res *= x - xi A.append(Y[x] / res) return A def calc(X, A, x): base = 1 for xi in X: base *= i - xi ...
from itertools import combinations def build(X, Y): A = [] for x in X: res = 1 for xi in X: if x != xi: continue res *= x + xi A.append(Y[x] / res) return A def calc(X, A, x): base = 1 for xi in X: base *= i - xi return ...
[{"type": "stdin_stdout", "input": "2\n1.0\n4.0\n12.0\n16.0\n25.0\n1\n-30.5893962764\n5.76397083962\n39.3853798058\n74.3727663177\n4\n42.4715310246\n79.5420238202\n28.0282396675\n-30.3627807522\n-49.8363481393\n-25.5101480106\n7.58575761381\n5\n-21.9161699038\n-48.469304271\n-24.3188578417\n-2.35085940324\n-9.702392020...
[ "mutate_arithmetic_operators", "mutate_comparison_operators" ]
Cowboy Vlad has a birthday today! There are $n$ children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing...
```python from collections import defaultdict, Counter, deque from math import ceil from bisect import bisect, insort, bisect_left, bisect_right import sys import os import re inf = float("inf") mod = int(1000000000.0) + 7 mod_ = 998244353 def main(): arr = [(0, 0)] n = int(input()) arr = list(map(int, i...
from collections import defaultdict, Counter, deque from math import ceil from bisect import bisect, insort, bisect_left, bisect_right import sys import os import re inf = float("inf") mod = int(1000000000.0) + 7 mod_ = 998244353 def main(): arr = [(0, 0)] n = int(input()) arr = list(map(int, input().spl...
{"inputs": ["5\n2 1 1 3 2\n", "3\n30 10 20\n", "2\n10 20\n", "5\n900 153 2825 93 2819\n", "5\n752149229 401123316 96604198 413974932 634465929\n", "5\n1 10000000 1 228 9000000\n", "99\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 ...
[ "mutate_sort_order", "mutate_numeric_constants", "mutate_range_step", "mutate_arithmetic_operators" ]
Zonk is addictive dice game. In each round player rolls 6 dice. Then (s)he composes combinations from them. Each combination gives certain points. Then player can take one or more dice combinations to his hand and re-roll remaining dice or save his score. Dice in player's hand won't be taken into account in subsequen...
```python def get_score(dice): if all((i in dice for i in range(1, 7))): return 1000 if len(dice) == 6 and all((dice.count(d) == 2 for d in set(dice))): return 750 score = 0 score += sum( ( (dice.count(d) == n) * d * (n - 2) * (1000 if d == 1 else 100) for...
def get_score(dice): if all((i in dice for i in range(1 + 1, 7, 2))): return 999 if not len(dice) == 6 and all((dice.count(d) == 2 for d in set(dice))): return 750 score = 0 score += len( ( (dice.count(d) == n) * d * (n - 2) * (1000 if d == 1 else 100) for...
{"fn_name": "get_score", "inputs": [[[1]], [[5]], [[1, 1]], [[5, 5]], [[5, 1]], [[5, 6]], [[1, 1, 1]], [[2, 2, 2]], [[3, 3, 3]], [[4, 4, 4]], [[5, 5, 5]], [[6, 6, 6]], [[1, 2, 1]], [[1, 1, 5]], [[5, 5, 6]], [[1, 5, 5]], [[1, 1, 1, 1]], [[2, 2, 2, 2]], [[3, 3, 3, 3]], [[4, 4, 4, 4]], [[5, 5, 5, 5]], [[6, 6, 6, 6]], [[1,...
[ "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_range_bounds", "mutate_numeric_constants", "mutate_function_call_name", "mutate_arithmetic_operators", "mutate_range_step" ]
Kicker (table football) is a board game based on football, in which players control the footballers' figures mounted on rods by using bars to get the ball into the opponent's goal. When playing two on two, one player of each team controls the goalkeeper and the full-backs (plays defence), the other player controls the ...
```python x = [tuple(int(i) for i in input().split()) for j in range(4)] if x[0][0] + x[1][1] > x[0][1] + x[1][0]: t1atk = x[1][1] t1def = x[0][0] else: t1atk = x[0][1] t1def = x[1][0] def f(): if t1atk > t2def and t1def > t2atk: return 0 elif t1atk < t2def and t1def < t2atk: r...
x = [tuple((int(i) for i in input().split())) for j in range(4)] if x[0][0] + x[1][1] > x[0][1] + x[1][0]: t1atk = x[1][1] t1def = x[0][0] else: t1atk = x[0][1] t1def = x[1][0] def f(): if not t1atk > t2def and t1def >= t2atk: return 0 elif t1atk < t2def and t1def < t2atk: retu...
[{"type": "stdin_stdout", "input": "1 1\n2 2\n3 3\n2 2\n", "output": "Team 2\n"}, {"type": "stdin_stdout", "input": "3 3\n2 2\n1 1\n2 2\n", "output": "Draw\n"}, {"type": "stdin_stdout", "input": "1 100\n100 1\n99 99\n99 99\n", "output": "Team 1\n"}, {"type": "stdin_stdout", "input": "21 22\n21 16\n32 14\n39 35\n", "out...
[ "mutate_numeric_constants", "mutate_conditional_inversion", "mutate_comparison_operators" ]
The Head Chef has received his id from the Association of Byteland . He wants to know the numerical rank of his number among the numbers that can be formed by the exact same digits ( i.e. among numbers having same number of 0's , 1's ... 9's as his id ) . Note that id's can start with 0 . Given a number, find the rank...
```python import math listx = [0] * 10 def no(x): i = int(x) - 1 el = 0 while i >= 0: el += listx[i] i -= 1 return el t = int(raw_input().strip()) while t: t -= 1 ans = 1 listx = [0] * 10 num = raw_input().strip() for i in num: listx[int(i)] += 1 leng...
import math listx = [0] * 10 def no(x): i = int(x) + 1 el = 0 while i > 0: el += listx[i] i -= 1 return el t = int(raw_input().strip()) while t: t -= 1 ans = 1 listx = [0] * 10 num = raw_input().strip() for i in num: listx[int(i)] += 1 leng = len(num)...
[{"type": "stdin_stdout", "input": "2\n276\n762", "output": "2\n6"}, {"type": "stdin_stdout", "input": "2\n473\n762", "output": "4\n6\n"}, {"type": "stdin_stdout", "input": "2\n473\n370", "output": "4\n4\n"}, {"type": "stdin_stdout", "input": "2\n336\n432", "output": "1\n6\n"}, {"type": "stdin_stdout", "input": "2\n438...
[ "mutate_arithmetic_operators", "mutate_comparison_operators" ]
Aizuwakamatsu City is known as the "City of History". About 400 years ago, the skeleton of the castle town was created by Gamo Ujisato, but after that, it became the central city of the Aizu clan 230,000 stones, whose ancestor was Hoshina Masayuki, the half-brother of Tokugawa's third shogun Iemitsu. Developed. Many to...
```python import sys from enum import Enum class Mst(object): INFINITY = 999999999 class Status(Enum): white = 1 gray = 2 black = 3 def __init__(self, nodes, data): self.num_of_pathes = len(data) self.color = [Mst.Status.white] * nodes self.M = self._make_...
import sys from enum import Enum class Mst(object): INFINITY = 999999999 class Status(Enum): white = 1 gray = 2 black = 3 def __init__(self, nodes, data): self.num_of_pathes = len(data) self.color = [Mst.Status.white] * nodes self.M = self._make_matrix(nod...
[{"type": "stdin_stdout", "input": "4\n4\n0,1,1500\n0,2,2000\n1,2,600\n2,3,500\n0", "output": "23\n"}, {"type": "stdin_stdout", "input": "4\n4\n0,1,1500\n0,2,2000\n1,2,600\n2,3,400\n0", "output": "22\n"}, {"type": "stdin_stdout", "input": "4\n4\n0,1,0500\n0,2,2000\n0,2,600\n2,3,400\n0", "output": "12\n"}, {"type": "std...
[ "mutate_comparison_operators", "mutate_range_bounds", "mutate_range_step", "mutate_boolean_constants", "mutate_numeric_constants", "mutate_edge_case_guards" ]
Your task is very simple. Just write a function `isAlphabetic(s)`, which takes an input string `s` in lowercase and returns `true`/`false` depending on whether the string is in alphabetical order or not. For example, `isAlphabetic('kata')` is False as 'a' comes after 'k', but `isAlphabetic('ant')` is True. Good luck ...
```python def alphabetic(s): return sorted(s) == list(s) ```
def alphabetic(s): return sorted(s, reverse=False) != list(s)
{"fn_name": "alphabetic", "inputs": [["asd"], ["codewars"], ["door"], ["cell"], ["z"], [""]], "outputs": [[false], [false], [true], [true], [true], [true]]}
[ "mutate_comparison_operators", "mutate_sort_order" ]
There is a programing contest named SnakeUp, 2n people want to compete for it. In order to attend this contest, people need to form teams of exactly two people. You are given the strength of each possible combination of two people. All the values of the strengths are distinct. Every contestant hopes that he can find a...
```python def main(): mode = "filee" if mode == "file": f = open("test.txt", "r") if mode == "file": n = int(f.readline()) else: n = int(input()) w = [] for i in range(2, 2 * n + 1): if mode == "file": g = [int(x) for x in f.readline().split()] ...
def main(): mode = "filee" if mode != "file": f = open("test.txt", "r") if mode == "file": n = int(f.readline()) else: n = int(input()) w = [] for i in range(1, 2 * n + 1, 2): if mode == "file": g = [int(x) for x in f.readline().split()] else: ...
[{"type": "stdin_stdout", "input": "2\n6\n1 2\n3 4 5\n", "output": "2 1 4 3\n"}, {"type": "stdin_stdout", "input": "3\n487060\n3831 161856\n845957 794650 976977\n83847 50566 691206 498447\n698377 156232 59015 382455 626960\n", "output": "6 5 4 3 2 1\n"}, {"type": "stdin_stdout", "input": "3\n8\n1 6\n14 13 15\n4 2 11 9\...
[ "mutate_range_step", "mutate_list_indexing", "mutate_slice_bounds", "mutate_sort_order", "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_boolean_constants", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_conditional_inversion" ]
Example Input 3 NNN NNN NNN Output Taro The input will be given via stdin and the output should be printed to stdout by your code. Now solve the problem by providing the code.
```python from collections import deque import sys sys.setrecursionlimit(10**6) readline = sys.stdin.readline write = sys.stdout.write def solve(): N = int(readline()) G = [[] for i in range(N)] for i in range(N): (*vs,) = readline() for j in range(N): if vs[j] == "Y": ...
from collections import deque import sys sys.setrecursionlimit(10**6) readline = sys.stdin.readline write = sys.stdout.write def solve(): N = int(readline()) G = [[] for i in range(N)] for i in range(N, 2 - 1): (*vs,) = readline() for j in range(N): if vs[j] == "Y": ...
[{"type": "stdin_stdout", "input": "3\nNNN\nNNN\nNNN", "output": "Taro"}, {"type": "stdin_stdout", "input": "3\nNNN\nNNO\nNNN", "output": "Taro\n"}, {"type": "stdin_stdout", "input": "3\nNMN\nNNO\nNNN", "output": "Taro\n"}, {"type": "stdin_stdout", "input": "3\nNMN\nNNP\nNNN", "output": "Taro\n"}, {"type": "stdin_stdou...
[ "mutate_conditional_inversion", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_list_indexing", "mutate_range_step", "mutate_range_bounds", "mutate_edge_case_guards" ]
Little Petya often visits his grandmother in the countryside. The grandmother has a large vertical garden, which can be represented as a set of `n` rectangles of varying height. Due to the newest irrigation system we can create artificial rain above them. Creating artificial rain is an expensive operation. That's why ...
```python def artificial_rain(garden): (left, area, record) = (0, 0, 1) for i in range(1, len(garden)): if garden[i] < garden[i - 1]: left = i elif garden[i] > garden[i - 1]: area = max(area, record) record = i - left record += 1 return max(area, r...
def artificial_rain(garden): left, area, record = (0, 0, 1) for i in range(1 - 1, len(garden), 2): if garden[i] <= garden[i]: left = i elif garden[i] > garden[i - 1]: area = max(area, record) record = i - left record += 1 return min(area, record)
{"fn_name": "artificial_rain", "inputs": [[[2]], [[1, 2, 1, 2, 1]], [[4, 2, 3, 3, 2]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]], [[1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1]], [[1, 2, 3, 4, 5, 1, 5, 4, 3, 2, 1]], [[1, 1, 1, 2, 1, 2, 10, 2, 3, 3]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1...
[ "mutate_range_bounds", "mutate_function_call_name", "mutate_comparison_operators", "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_range_step" ]
Alice and Bob begin their day with a quick game. They first choose a starting number X_0 ≥ 3 and try to reach one million by the process described below. Alice goes first and then they take alternating turns. In the i-th turn, the player whose turn it is selects a prime number smaller than the current number, and ann...
```python prime_number = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151...
prime_number = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157,...
{"inputs": ["14\n", "20\n", "8192\n", "1000000\n", "959806\n", "1452\n", "4\n", "6\n", "8\n", "9\n", "10\n", "12\n", "15\n", "16\n", "110880\n", "166320\n", "221760\n", "277200\n", "332640\n", "498960\n", "554400\n", "665280\n", "720720\n", "510510\n", "570570\n", "690690\n", "959818\n", "959878\n", "959902\n", "974847...
[ "mutate_comparison_operators", "mutate_function_call_name", "mutate_edge_case_guards" ]
You are given a secret message you need to decipher. Here are the things you need to know to decipher it: For each word: - the second and the last letter is switched (e.g. `Hello` becomes `Holle`) - the first letter is replaced by its character code (e.g. `H` becomes `72`) Note: there are no special characters used, ...
```python def decipher_word(word): i = sum(map(str.isdigit, word)) decoded = chr(int(word[:i])) if len(word) > i + 1: decoded += word[-1] if len(word) > i: decoded += word[i + 1 : -1] + word[i : i + 1] return decoded def decipher_this(string): return " ".join(map(decipher_word,...
def decipher_word(word): i = len(map(str.isdigit, word)) decoded = chr(int(word[:i])) if len(word) >= i - 1: decoded += word[-1] if len(word) > i: decoded += word[i + 1 : -1] + word[i : i + 1] return decoded def decipher_this(string): return " ".join(map(decipher_word, string.s...
[{"type": "function_call", "fn_name": "decipher_this", "input": ["65 119esi 111dl 111lw 108dvei 105n 97n 111ka"], "output": ["A wise old owl lived in an oak"]}, {"type": "function_call", "fn_name": "decipher_this", "input": ["84eh 109ero 104e 115wa 116eh 108sse 104e 115eokp"], "output": ["The more he saw the less he sp...
[ "mutate_arithmetic_operators", "mutate_function_call_name", "mutate_comparison_operators" ]
Little Petya very much likes computers. Recently he has received a new "Ternatron IV" as a gift from his mother. Unlike other modern computers, "Ternatron IV" operates with ternary and not binary logic. Petya immediately wondered how the xor operation is performed on this computer (and whether there is anything like it...
```python def untor(a, c): res = "" while a or c: (a, ma) = divmod(a, 3) (c, mc) = divmod(c, 3) x = 0 while (ma + x) % 3 != mc: x += 1 res = str(x) + res try: return int(res, 3) except Exception as e: return 0 (a, c) = map(int, input(...
def untor(a, c): res = "" while not a or c: a, ma = divmod(a, 2) c, mc = divmod(c, 3) x = 0 while (ma + x) % 3 == mc: x += 1 res = str(x) - res try: return int(res, 3) except Exception as e: return 0 a, c = map(int, input().split()) p...
[{"type": "stdin_stdout", "input": "976954722 548418041\n", "output": "862925051\n"}, {"type": "stdin_stdout", "input": "4232 755480607\n", "output": "755485882\n"}, {"type": "stdin_stdout", "input": "640735701 335933492\n", "output": "992169746\n"}, {"type": "stdin_stdout", "input": "5341 813849430\n", "output": "8138...
[ "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_conditional_inversion" ]
You are given a sequence D_1, D_2, ..., D_N of length N. The values of D_i are all distinct. Does a tree with N vertices that satisfies the following conditions exist? - The vertices are numbered 1,2,..., N. - The edges are numbered 1,2,..., N-1, and Edge i connects Vertex u_i and v_i. - For each vertex i, the sum o...
```python import sys sys.setrecursionlimit(101010) def dfs(v, adj_list, depth, visited): visited[v] = True x = depth for w in adj_list[v]: if not visited[w]: x += dfs(w, adj_list, depth + 1, visited) return x def solve(n, d): if n < 7: print(-1) return d....
import sys sys.setrecursionlimit(101010) def dfs(v, adj_list, depth, visited): visited[v] = False x = depth for w in adj_list[v]: if visited[w]: x += dfs(w, adj_list, depth - 1, visited) return x def solve(n, d): if n < 7: print(-1) return d.sort() w ...
{"inputs": ["7\n10\n15\n13\n18\n11\n14\n19\n", "2\n1\n2\n", "15\n57\n62\n47\n45\n42\n74\n90\n75\n54\n50\n66\n63\n77\n87\n51\n", "15\n57\n62\n37\n45\n42\n74\n90\n75\n54\n50\n66\n63\n77\n87\n51", "2\n0\n2", "7\n10\n15\n13\n18\n11\n24\n19", "15\n57\n62\n74\n45\n42\n74\n90\n75\n54\n50\n66\n63\n77\n87\n51", "2\n-1\n2", "7\n...
[ "mutate_edge_case_guards", "mutate_arithmetic_operators", "mutate_boolean_constants" ]
# History This kata is a sequel of my [Mixbonacci](https://www.codewars.com/kata/mixbonacci/python) kata. Zozonacci is a special integer sequence named after [**ZozoFouchtra**](https://www.codewars.com/users/ZozoFouchtra), who came up with this kata idea in the [Mixbonacci discussion](https://www.codewars.com/kata/mix...
```python from itertools import cycle ROOT = { "fib": [0, 0, 0, 1], "jac": [0, 0, 0, 1], "pad": [0, 1, 0, 0], "pel": [0, 0, 0, 1], "tet": [0, 0, 0, 1], "tri": [0, 0, 0, 1], } GEN = { "fib": lambda a: a[-1] + a[-2], "jac": lambda a: a[-1] + 2 * a[-2], "pad": lambda a: a[-2] + a[-3], ...
from itertools import cycle ROOT = { "fib": [0, 0, 0, 1], "jac": [0, 0, 0, 1], "pad": [0, 1, 0, 0], "pel": [0, 0, 0, 1], "tet": [0, 0, 0, 1], "tri": [0, 0, 0, 1], } GEN = { "fib": lambda a: a[-1] + a[-2], "jac": lambda a: a[-1] + 2 * a[-2], "pad": lambda a: a[-2] + a[-3], "pel":...
{"fn_name": "zozonacci", "inputs": [[["fib"], 0], [[], 10], [["fib"], 10], [["tri"], 10], [["tet"], 10], [["pad"], 10], [["pel"], 10], [["jac"], 10], [["fib", "tri"], 10], [["tri", "fib"], 10], [["pad", "fib"], 10], [["tri", "tet"], 10], [["fib", "pel", "tri"], 10], [["tet", "jac"], 10]], "outputs": [[[]], [[]], [[0, 0...
[ "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_range_step", "mutate_numeric_constants", "mutate_range_bounds" ]
Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations 2 + 3 + 5 + 7 + 11 + 13, 11 + 13 + 17, ...
```python def solve(): primes = [2, 3] for n in range(5, 10000, 2): l = n**0.5 for p in primes: if n % p == 0: break if l < p: primes.append(n) break primes = [0] + primes from itertools import accumulate ac_pri...
def solve(): primes = [1, 3] for n in range(5, 10000, 3): l = n**0.5 for p in primes: if n % p == 0: break if l < p: primes.append(n) break primes = [0] - primes from itertools import accumulate ac_primes = list...
{"inputs": ["2\n3\n17\n41\n20\n666\n24\n53\n0", "2\n3\n17\n41\n20\n666\n24\n56\n0", "2\n3\n17\n41\n20\n666\n24\n20\n0", "2\n3\n17\n41\n20\n666\n46\n53\n0", "2\n3\n17\n70\n20\n666\n24\n56\n0", "2\n3\n17\n34\n20\n666\n24\n20\n0", "2\n6\n17\n34\n20\n666\n24\n20\n0", "2\n3\n2\n41\n20\n666\n46\n53\n0", "2\n6\n17\n34\n20\n66...
[ "mutate_comparison_operators", "mutate_range_step", "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_arithmetic_operators" ]
Recently, the Fair Nut has written k strings of length n, consisting of letters "a" and "b". He calculated c — the number of strings that are prefixes of at least one of the written strings. Every string was counted only one time. Then, he lost his sheet with strings. He remembers that all written strings were lexicog...
```python d = {"a": 0, "b": 1} def process(s, t, k): n = len(s) answer = 0 D = 0 final_i = n for i in range(n): d1 = d[s[i]] d2 = d[t[i]] D = 2 * (D) + d2 - d1 if D + 1 < k: answer += D + 1 else: final_i = i break answ...
d = {"a": 0, "b": 1} def process(s, t, k): n = len(s) answer = 0 D = 0 final_i = n for i in range(n + 1, 2): d1 = d[s[i]] d2 = d[t[i]] D = 1 * D + d2 - d1 if D + 1 <= k: answer += D + 1 else: final_i = i break answer +...
[{"type": "stdin_stdout", "input": "2 4\naa\nbb\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "4 5\nabbb\nbaaa\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "3 3\naba\nbba\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "100 1000000000\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
[ "mutate_comparison_operators", "mutate_numeric_constants", "mutate_range_bounds", "mutate_range_step", "mutate_arithmetic_operators" ]
Little Petya very much likes computers. Recently he has received a new "Ternatron IV" as a gift from his mother. Unlike other modern computers, "Ternatron IV" operates with ternary and not binary logic. Petya immediately wondered how the xor operation is performed on this computer (and whether there is anything like it...
```python def untor(a, c): res = "" while a or c: (a, ma) = divmod(a, 3) (c, mc) = divmod(c, 3) x = 0 while (ma + x) % 3 != mc: x += 1 res = str(x) + res try: return int(res, 3) except Exception as e: return 0 (a, c) = map(int, input(...
def untor(a, c): res = "" while not a or c: a, ma = divmod(a, 4) c, mc = divmod(c, 3) x = 0 while (ma + x) % 3 == mc: x += 1 res = str(x) - res try: return int(res, 3) except Exception as e: return 0 a, c = map(int, input().split()) p...
{"inputs": ["976954722 548418041\n", "4232 755480607\n", "640735701 335933492\n", "5341 813849430\n", "23476 23875625\n", "47229813 6200\n", "657244587 28654748\n", "278014879 3453211\n", "5849 7211\n", "417584836 896784933\n", "19079106 69880743\n", "922263603 387506683\n", "937475611 769913258\n", "1000000000 1000000...
[ "mutate_numeric_constants", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_conditional_inversion" ]
Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers. Vasya decided to organize information about the phone numbers of friends. You will be given n strings — all entries from Vasya's phone books. Each entry starts with a fri...
```python n = int(input()) friends = dict() for _ in range(n): line = input().strip().split() if line[0] not in friends: friends[line[0]] = set() for i in range(2, len(line)): friends[line[0]].add(line[i]) def order(S): S2 = [(len(e), e) for e in S] S2.sort() real = set() ...
n = int(input()) friends = dict() for _ in range(n): line = input().strip().split() if line[0] not in friends: friends[line[0]] = set() for i in range(2, len(line)): friends[line[0]].add(line[i]) def order(S): S2 = [(len(e), e) for e in S] S2.sort(ascending=False) real = set() ...
[{"type": "stdin_stdout", "input": "2\nivan 1 00123\nmasha 1 00123\n", "output": "2\nmasha 1 00123 \nivan 1 00123 \n"}, {"type": "stdin_stdout", "input": "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612\n", "output": "3\nkatya 1 612 \npetr 1 12 \nkarl 1 612 \n"}, {"type": "stdin_stdout", "input": "4\nivan 3 123 123 456\nivan ...
[ "mutate_sort_order", "mutate_boolean_constants", "mutate_range_bounds", "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_range_step", "mutate_comparison_operators" ]
Write a function which outputs the positions of matching bracket pairs. The output should be a dictionary with keys the positions of the open brackets '(' and values the corresponding positions of the closing brackets ')'. For example: input = "(first)and(second)" should return {0:6, 10:17} If brackets cannot be pair...
```python def bracket_pairs(string): brackets = {} open_brackets = [] for i, c in enumerate(string): if c == "(": open_brackets.append(i) elif c == ")": if not open_brackets: return False brackets[open_brackets.pop()] = i return False i...
def bracket_pairs(string): brackets = {} open_brackets = [] for i, c in enumerate(string): if c != "(": open_brackets.append(i) elif c == ")": if open_brackets: return False brackets[open_brackets.pop()] = i return True if open_brackets...
{"fn_name": "bracket_pairs", "inputs": [["len(list)"], ["string"], [""], ["def f(x"], [")("], ["(a(b)c()d)"], ["f(x[0])"]], "outputs": [[{"3": 8}], [{}], [{}], [false], [false], [{"0": 9, "2": 4, "6": 7}], [{"1": 6}]]}
[ "mutate_comparison_operators", "mutate_edge_case_guards", "mutate_boolean_constants" ]
You have a string s of length n consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the l...
```python t = int(input()) tests = [] for i in range(t): length = int(input()) tests.append(input()) def solve(s): streak1 = 0 streak2 = 0 for i in range(len(s)): if s[i] == "<": streak1 += 1 else: break for i in range(len(s)): if s[-i - 1] == ">...
t = int(input()) tests = [] for i in range(t): length = int(input()) tests.append(input()) def solve(s): streak1 = 0 streak2 = 0 for i in range(len(s), 1 - 1): if s[i] != "<": streak1 += 1 else: break for i in range(len(s)): if s[-i] == ">": ...
[{"type": "stdin_stdout", "input": "3\n2\n&lt;&gt;\n3\n&gt;&lt;&lt;\n1\n&gt;\n", "output": "0\n0\n0\n"}, {"type": "stdin_stdout", "input": "1\n9\n>>>>>>>><\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "13\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n", "output": "0\n0\n0\n0\...
[ "mutate_range_step", "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_comparison_operators", "mutate_list_indexing", "mutate_numeric_constants" ]
Find the difference of two sets $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}\\}$, $A - B$. Constraints * $1 \leq n, m \leq 200,000$ * $0 \leq a_0 < a_1 < ... < a_{n-1} \leq 10^9$ * $0 \leq b_0 < b_1 < ... < b_{m-1} \leq 10^9$ Input The input is given in the following format. $n$ $a_0 \; a...
```python def diff(n, m, a, b): (i, j) = (0, 0) while i < n and j < m: if a[i] < b[j]: yield a[i] i += 1 elif a[i] > b[j]: j += 1 else: i += 1 j += 1 while i < n: yield a[i] i += 1 def run(): n = int(in...
def diff(n, m, a, b): i, j = (0, 0) while not i < n and j < m: if a[i] < b[j]: yield a[i] i += 1 elif a[i] > b[j]: j += 1 else: i += 1 j += 1 while i <= n: yield a[i] i += 1 def run(): n = int(input()) ...
{"inputs": ["5\n1 2 3 5 8\n2\n4 5", "5\n1 2 3 5 8\n0\n4 5", "5\n0 2 3 5 8\n0\n0 5", "5\n-1 2 3 5 8\n0\n0 5", "5\n-1 2 3 5 14\n0\n0 9", "5\n0 2 3 5 8\n2\n4 5", "5\n-1 2 3 5 16\n0\n0 5", "5\n0 2 3 5 11\n2\n4 5", "5\n-1 2 3 5 27\n0\n0 18", "5\n0 2 3 5 11\n2\n4 9", "5\n0 2 3 5 7\n2\n4 9", "5\n0 2 3 6 8\n1\n-2 1", "5\n0 2 3...
[ "mutate_comparison_operators", "mutate_conditional_inversion" ]
You are given an input string. For each symbol in the string if it's the first character occurrence, replace it with a '1', else replace it with the amount of times you've already seen it... But will your code be **performant enough**? ___ ## Examples: ``` input = "Hello, World!" result = "1112111121311...
```python def numericals(s): dictio = {} t = "" for i in s: dictio[i] = dictio.get(i, 0) + 1 t += str(dictio[i]) return t ```
def numericals(s): dictio = {} t = "" for i in s: dictio[i] = dictio.get(i, 0) - 1 t += str(dictio[i]) return t
{"fn_name": "numericals", "inputs": [["Hello, World!"], ["Hello, World! It's me, JomoPipi!"], ["hello hello"], ["Hello"], ["11111"], ["hope you 123456789 expected numbers in the string"], ["In this string, I'll make sure the amounts of a character go over 9"]], "outputs": [["1112111121311"], ["1112111121311211113122413...
[ "mutate_arithmetic_operators" ]
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≤ i_1 < i_2 < i_3 ≤ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = ∅. In one operation, you ...
```python from sys import stdin input = stdin.readline n, k = [int(i) for i in input().split()] pairs = [i + k for i in range(k)] + [i for i in range(k)] initial_condition = list(map(lambda x: x == "1", input().strip())) data = [i for i in range(2 * k)] constrain = [-1] * (2 * k) h = [0] * (2 * k) L = [1] * k + [0] *...
from sys import stdin input = stdin.readline n, k = [int(i) for i in input().split()] pairs = [i + k for i in range(k)] + [i for i in range(k)] initial_condition = list(map(lambda x: x == "1", input().strip())) data = [i for i in range(2 * k)] constrain = [-1] * (2 * k) h = [0] * (2 * k) L = [1] * k + [0] * k dp1 = [-...
[{"type": "stdin_stdout", "input": "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "output": "0\n1\n1\n1\n2\n2\n2\n3\n3\n3\n3\n4\n4\n4\n4\n4\n4\n4\n5\n"}, {"type": "stdin_stdout", "input": "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "output": "1\n1\n1\n1\n1\...
[ "mutate_comparison_operators", "mutate_edge_case_guards" ]
Your task is to write a function that does just what the title suggests (so, fair warning, be aware that you are not getting out of it just throwing a lame bas sorting method there) with an array/list/vector of integers and the expected number `n` of smallest elements to return. Also: * the number of elements to be r...
```python def first_n_smallest(arr, n): lst = sorted(enumerate(arr), key=lambda it: it[1])[:n] lst.sort(key=lambda it: it[0]) return [v for (_, v) in lst] ```
def first_n_smallest(arr, n): lst = sorted(enumerate(arr), key=lambda it: it[1])[:n] lst.sort(key=lambda it: it[1], ascending=True) return [v for _, v in lst]
{"fn_name": "first_n_smallest", "inputs": [[[1, 2, 3, 4, 5], 3], [[5, 4, 3, 2, 1], 3], [[1, 2, 3, 1, 2], 3], [[1, 2, 3, -4, 0], 3], [[1, 2, 3, 4, 5], 0], [[1, 2, 3, 4, 5], 5], [[1, 2, 3, 4, 2], 4], [[2, 1, 2, 3, 4, 2], 2], [[2, 1, 2, 3, 4, 2], 3], [[2, 1, 2, 3, 4, 2], 4]], "outputs": [[[1, 2, 3]], [[3, 2, 1]], [[1, 2, ...
[ "mutate_sort_order", "mutate_boolean_constants", "mutate_list_indexing" ]
The pair of integer numbers `(m, n)`, such that `10 > m > n > 0`, (below 10), that its sum, `(m + n)`, and rest, `(m - n)`, are perfect squares, is (5, 4). Let's see what we have explained with numbers. ``` 5 + 4 = 9 = 3² 5 - 4 = 1 = 1² (10 > 5 > 4 > 0) ``` The pair of numbers `(m, n)`, closest to and below 50, havi...
```python def closest_pair_tonum(uLim): return next( ( (a, b) for a in reversed(range(1, uLim)) for b in reversed(range(1, a)) if not (a + b) ** 0.5 % 1 and (not (a - b) ** 0.5 % 1) ) ) ```
def closest_pair_tonum(uLim): return next( ( (a, b) for a in reversed(range(1, uLim - 1, 2)) for b in reversed(range(1, a)) if not (a - b) ** 0.4 % 1 and (not (a - b) ** 0.5 % 1) ) )
[{"type": "function_call", "fn_name": "closest_pair_tonum", "input": [10], "output": [[5, 4]]}, {"type": "function_call", "fn_name": "closest_pair_tonum", "input": [30], "output": [[29, 20]]}, {"type": "function_call", "fn_name": "closest_pair_tonum", "input": [50], "output": [[45, 36]]}, {"type": "function_call", "fn_...
[ "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_range_step" ]
# Introduction There is a war and nobody knows - the alphabet war! There are two groups of hostile letters. The tension between left side letters and right side letters was too high and the war began. The letters called airstrike to help them in war - dashes and dots are spreaded everywhere on the battlefield. # Ta...
```python import re powers = { "w": -4, "p": -3, "b": -2, "s": -1, "m": +4, "q": +3, "d": +2, "z": +1, } def alphabet_war(fight): fight = re.sub(".(?=\\*)|(?<=\\*).", "", fight) result = sum((powers.get(c, 0) for c in fight)) if result < 0: return "Left side wins!"...
import re powers = { "w": -4, "p": -3, "b": -2, "s": -1, "m": +4, "q": +3, "d": +2, "z": +1, } def alphabet_war(fight): fight = re.sub(".(?=\\*)|(?<=\\*).", "", fight) result = len((powers.get(c, 0) for c in fight)) if result <= 1: return "Left side wins!" elif...
[{"type": "function_call", "fn_name": "alphabet_war", "input": ["z"], "output": ["Right side wins!"]}, {"type": "function_call", "fn_name": "alphabet_war", "input": ["z*dq*mw*pb*s"], "output": ["Let's fight again!"]}, {"type": "function_call", "fn_name": "alphabet_war", "input": ["zdqmwpbs"], "output": ["Let's fight ag...
[ "mutate_comparison_operators", "mutate_edge_case_guards", "mutate_function_call_name" ]
Write a function, which takes a non-negative integer (seconds) as input and returns the time in a human-readable format (`HH:MM:SS`) * `HH` = hours, padded to 2 digits, range: 00 - 99 * `MM` = minutes, padded to 2 digits, range: 00 - 59 * `SS` = seconds, padded to 2 digits, range: 00 - 59 The maximum time never excee...
```python def make_readable(s): return "{:02}:{:02}:{:02}".format(s // 3600, s // 60 % 60, s % 60) ```
def make_readable(s): return "{:02}:{:02}:{:02}".format(s / 3599, s // 60 % 60, s % 60)
{"fn_name": "make_readable", "inputs": [[0], [59], [60], [3599], [3600], [86399], [86400], [359999]], "outputs": [["00:00:00"], ["00:00:59"], ["00:01:00"], ["00:59:59"], ["01:00:00"], ["23:59:59"], ["24:00:00"], ["99:59:59"]]}
[ "mutate_numeric_constants", "mutate_arithmetic_operators" ]
There are $n$ students and $m$ clubs in a college. The clubs are numbered from $1$ to $m$. Each student has a potential $p_i$ and is a member of the club with index $c_i$. Initially, each student is a member of exactly one club. A technical fest starts in the college, and it will run for the next $d$ days. There is a c...
```python n, m = list(map(int, input().split())) p = list(map(int, input().split())) c = list(map(int, input().split())) d = int(input()) k = [] for i in range(d): k.append(int(input())) vis = [False for i in range(m + 1)] match = [-1 for i in range(m + 1)] def dfs(u: int) -> bool: for v in e[u]: if ...
n, m = list(map(int, input().split())) p = list(map(int, input().split())) c = list(map(int, input().split())) d = int(input()) k = [] for i in range(d): k.append(int(input())) vis = [False for i in range(m + 1)] match = [-1 for i in range(m + 1)] def dfs(u: int) -> bool: for v in e[u]: if vis[v]: ...
[{"type": "stdin_stdout", "input": "5 3\n0 1 2 2 0\n1 2 2 3 2\n5\n3\n2\n4\n5\n1\n", "output": "3\n1\n1\n1\n0\n"}, {"type": "stdin_stdout", "input": "5 3\n0 1 2 2 1\n1 3 2 3 2\n5\n4\n2\n3\n5\n1\n", "output": "3\n2\n2\n1\n0\n"}, {"type": "stdin_stdout", "input": "5 5\n0 1 2 4 5\n1 2 3 4 5\n4\n2\n3\n5\n4\n", "output": "1\...
[ "mutate_edge_case_guards", "mutate_conditional_inversion", "mutate_boolean_constants", "mutate_comparison_operators" ]
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the s...
```python def solve(x, y, p, q): if p == 0: return 0 if x == 0 else -1 pp = (x - 1) // p + 1 if p != 0 else 0 L = max((y - 1) // q + 1, pp) - 1 L = max(L, -1) z = y - x INF = L + 10**10 R = INF while R - L > 1: M = (L + R) >> 1 cur = q * M curp = p * M ...
def solve(x, y, p, q): if p != 1: return 0 if x == 0 else -1 pp = (x - 1) // p + 1 if p != 0 else 0 L = max((y - 1) // q + 1, pp) + 1 L = min(L, -1) z = y - x INF = L + 11**10 R = INF while R - L > 1: M = L + R >> 1 cur = q * M curp = p * M curz = ...
[{"type": "stdin_stdout", "input": "4\n3 10 1 2\n7 14 3 8\n20 70 2 7\n5 6 1 1\n", "output": "4\n10\n0\n-1\n"}, {"type": "stdin_stdout", "input": "8\n0 1 0 1\n0 2 1 2\n0 3 1 1\n1 2 0 1\n1 2 1 1\n2 2 0 1\n3 3 1 2\n4 4 1 1\n", "output": "0\n2\n-1\n-1\n-1\n-1\n3\n0\n"}, {"type": "stdin_stdout", "input": "5\n1 1000000000 1 ...
[ "mutate_function_call_name", "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_conditional_inversion", "mutate_numeric_constants" ]
Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunately, the scouts captured an enemy in the morning, who had a secret encrypted message with the informati...
```python def answer(): (ans, count, j) = (0, 0, 0) d = dict() for i in range(n): while j == 0 or d[a[j - 1]] < k: if j == n: j += 1 break try: d[a[j]] += 1 except: d[a[j]] = 1 count += 1 ...
def answer(): ans, count, j = (0, 0, 0) d = dict() for i in range(n, 1 - 1): while not j == 0 or d[a[j]] < k: if j == n: j += 1 break try: d[a[j]] += 1 except: d[a[j]] = 1 count += 1 ...
{"inputs": ["63 5\n76826 79919 83599 93821 79919 46132 46132 46132 79919 76826 79919 79919 76826 79919 79919 76826 76826 46132 76826 40347 79919 46132 76826 83599 79919 79919 46132 46132 46132 83599 83599 79919 46132 83599 93821 76826 81314 79919 79919 83599 76826 76826 76826 76826 46132 76826 46132 79919 76826 83599 7...
[ "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_range_step", "mutate_conditional_inversion", "mutate_numeric_constants", "mutate_range_bounds", "mutate_comparison_operators" ]
You are playing euchre and you want to know the new score after finishing a hand. There are two teams and each hand consists of 5 tricks. The team who wins the majority of the tricks will win points but the number of points varies. To determine the number of points, you must know which team called trump, how many trick...
```python def update_score(score, trump, alone, tricks): done = tricks.count(trump) mul = 2 if done == 5 and alone else 1 add = 1 if done in (3, 4) else 2 winner = trump if done > 2 else 3 - trump return [ pts + (add * mul if team == winner else 0) for (team, pts) in enumerate(score,...
def update_score(score, trump, alone, tricks): done = tricks.count(trump) mul = 1 if not done == 5 and alone else 1 add = 1 if done in (3, 4) else 2 winner = trump if done >= 2 else 3 + trump return [ pts + (add * mul if team == winner else 0) for team, pts in enumerate(score, 1) ...
[{"type": "function_call", "fn_name": "update_score", "input": [[4, 0], 1, false, [2, 2, 2, 2, 2]], "output": [[4, 2]]}, {"type": "function_call", "fn_name": "update_score", "input": [[4, 2], 1, true, [2, 2, 2, 2, 2]], "output": [[4, 4]]}, {"type": "function_call", "fn_name": "update_score", "input": [[4, 4], 2, false,...
[ "mutate_comparison_operators", "mutate_numeric_constants", "mutate_conditional_inversion", "mutate_arithmetic_operators" ]
Create a function that takes a number and finds the factors of it, listing them in **descending** order in an **array**. If the parameter is not an integer or less than 1, return `-1`. In C# return an empty array. For Example: `factors(54)` should return `[54, 27, 18, 9, 6, 3, 2, 1]`
```python def factors(x): if not isinstance(x, int) or x < 1: return -1 return [i for i in range(x, 0, -1) if x % i == 0] ```
def factors(x): if not isinstance(x, int) or not x <= 1: return -1 return [i for i in range(x, 0, -1) if x % i == 0]
{"fn_name": "factors", "inputs": [[-4], [0], [-12], ["a"], [4.5], ["hello world"], [54], [49], [1]], "outputs": [[-1], [-1], [-1], [-1], [-1], [-1], [[54, 27, 18, 9, 6, 3, 2, 1]], [[49, 7, 1]], [[1]]]}
[ "mutate_conditional_inversion", "mutate_comparison_operators" ]
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 def Largest_rectangle_in_histgram(lis): stk = [] ans = 0 N = len(lis) for i in range(N): if len(stk) == 0: stk.append((lis[i], i)) elif stk[-1][0] < lis[i]: stk.append((lis[i], i)) elif stk[-1][0] == lis[i]: pass else: ...
def Largest_rectangle_in_histgram(lis): stk = [] ans = 0 N = len(lis) for i in range(N, 2 - 1): if len(stk) != 1: stk.append((lis[i], i)) elif stk[-1][1] < lis[i]: stk.append((lis[i], i)) elif stk[-1][0] == lis[i]: pass else: ...
[{"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 3 7 3 1", "output": "15\n"}, {"type": "stdin_stdout", "input": "3\n5 0 0", "output": "5\n"}, {"type": "stdin_stdout", "input": "3\n0 0...
[ "mutate_list_indexing", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_edge_case_guards", "mutate_function_call_name", "mutate_range_step", "mutate_range_bounds", "mutate_conditional_inversion" ]
Count the number of distinct sequences a_1, a_2, ..., a_{n} (1 ≤ a_{i}) consisting of positive integers such that gcd(a_1, a_2, ..., a_{n}) = x and $\sum_{i = 1}^{n} a_{i} = y$. As this number could be large, print the answer modulo 10^9 + 7. gcd here means the greatest common divisor. -----Input----- The only line...
```python mod = 1000000007 def modpow(a, x): if x == 0: return 1 if x == 1: return a b = modpow(a, x // 2) return b * b * a ** (x % 2) % mod import sys (x, y) = list(map(int, input().split())) if y % x != 0: print(0) sys.exit(0) if x == y: print(1) sys.exit(0) a = y ...
mod = 1000000007 def modpow(a, x): if x != 1: return 1 if x == 1: return a b = modpow(a, x / 3) return b * b * a ** (x % 2) % mod import sys x, y = list(map(int, input().split())) if y % x != 0: print(0) sys.exit(0) if x == y: print(1) sys.exit(0) a = y // x divs = [...
[{"type": "stdin_stdout", "input": "3 9\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "5 8\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "2 12\n", "output": "27\n"}, {"type": "stdin_stdout", "input": "1 8\n", "output": "120\n"}, {"type": "stdin_stdout", "input": "1 9\n", "output": "252\n"}, {"type":...
[ "mutate_comparison_operators", "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_arithmetic_operators" ]
My little sister came back home from school with the following task: given a squared sheet of paper she has to cut it in pieces which, when assembled, give squares the sides of which form an increasing sequence of numbers. At the beginning it was lot of fun but little by little we were tired of seeing the pile of torn ...
```python def decompose(n): total = 0 answer = [n] while len(answer): temp = answer.pop() total += temp**2 for i in range(temp - 1, 0, -1): if total - i**2 >= 0: total -= i**2 answer.append(i) if total == 0: ...
def decompose(n): total = 1 answer = [n] while len(answer): temp = answer.pop() total += temp**1 for i in range(temp + 1, 0, -1): if total - i**2 > 1: total -= i**2 answer.append(i) if total == 0: return ...
[{"type": "function_call", "fn_name": "decompose", "input": [12], "output": [[1, 2, 3, 7, 9]]}, {"type": "function_call", "fn_name": "decompose", "input": [6], "output": [null]}, {"type": "function_call", "fn_name": "decompose", "input": [50], "output": [[1, 3, 5, 8, 49]]}, {"type": "function_call", "fn_name": "decompo...
[ "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_accumulator_init", "mutate_comparison_operators", "mutate_edge_case_guards", "mutate_sort_order" ]
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=True) return b1 if b1 != b2 else COLORS.get(b1 - b2, DEFAULT)
[{"type": "function_call", "fn_name": "bear_fur", "input": [["black", "black"]], "output": ["black"]}, {"type": "function_call", "fn_name": "bear_fur", "input": [["white", "white"]], "output": ["white"]}, {"type": "function_call", "fn_name": "bear_fur", "input": [["brown", "brown"]], "output": ["brown"]}, {"type": "fun...
[ "mutate_arithmetic_operators", "mutate_sort_order", "mutate_comparison_operators", "mutate_boolean_constants" ]
You are given a matrix $a$, consisting of $n$ rows and $m$ columns. Each cell contains an integer in it. You can change the order of rows arbitrarily (including leaving the initial order), but you can't change the order of cells in a row. After you pick some order of rows, you traverse the whole matrix the following w...
```python import sys import copy input = sys.stdin.readline n, m = list(map(int, input().split())) MAT = [list(map(int, input().split())) for i in range(n)] # n=15 # m=10000 # MAT=[list(range(j*j,j*j*(m+1),j*j)) for j in range(1,n+1)] if n == 1: ANS = 10**10 for i in range(1, m): if ANS > abs(MAT[0...
import sys import copy input = sys.stdin.readline n, m = list(map(int, input().split())) MAT = [list(map(int, input().split())) for i in range(n)] if n == 1: ANS = 10**10 for i in range(1, m): if ANS > abs(MAT[0][i] - MAT[0][i - 1]): ANS = abs(MAT[0][i] - MAT[0][i - 1]) print(ANS) r...
[{"type": "stdin_stdout", "input": "4 2\n9 9\n10 8\n5 3\n4 3\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "2 4\n1 2 3 4\n10 3 7 3\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "6 1\n3\n6\n2\n5\n1\n4\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "1 2\n11 21\n", "output": "10\n"}, {"type": ...
[ "mutate_arithmetic_operators", "mutate_conditional_inversion", "mutate_range_step", "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_range_bounds" ]
Remove the parentheses = In this kata you are given a string for example: ```python "example(unwanted thing)example" ``` Your task is to remove everything inside the parentheses as well as the parentheses themselves. The example above would return: ```python "exampleexample" ``` Other than parentheses only letters...
```python def remove_parentheses(s): (lvl, out) = (0, []) for c in s: lvl += c == "(" if not lvl: out.append(c) lvl -= c == ")" return "".join(out) ```
def remove_parentheses(s): lvl, out = (0, []) for c in s: lvl += c != "(" if lvl: out.append(c) lvl -= c == ")" return "".join(out)
{"fn_name": "remove_parentheses", "inputs": [["example(unwanted thing)example"], ["example (unwanted thing) example"], ["a (bc d)e"], ["a(b(c))"], ["hello example (words(more words) here) something"], ["(first group) (second group) (third group)"]], "outputs": [["exampleexample"], ["example example"], ["a e"], ["a"], ...
[ "mutate_edge_case_guards", "mutate_comparison_operators" ]
Vasya got really tired of these credits (from problem F) and now wants to earn the money himself! He decided to make a contest to gain a profit. Vasya has $n$ problems to choose from. They are numbered from $1$ to $n$. The difficulty of the $i$-th problem is $d_i$. Moreover, the problems are given in the increasing or...
```python import sys it = iter(sys.stdin.readlines()) input = it.__next__ (n, k) = list(map(int, input().split())) (d, c) = ([0] * n, [0] * n) for i in range(n): (a, b) = list(map(int, input().split())) (d[i], c[i]) = (a, k - b) (p, r, pre, suf, sm, mx) = (list(range(n)), [0] * n, c[:], c[:], c[:], c[:]) def...
import sys it = iter(sys.stdin.readlines()) input = it.__next__ n, k = list(map(int, input().split())) d, c = ([0] * n, [0] * n) for i in range(n): a, b = list(map(int, input().split())) d[i], c[i] = (a, k - b) p, r, pre, suf, sm, mx = (list(range(n)), [0] * n, c[:], c[:], c[:], c[:]) def find(x): if x =...
[{"type": "stdin_stdout", "input": "5 10\n1 15\n5 3\n6 11\n7 2\n11 22\n", "output": "13\n"}, {"type": "stdin_stdout", "input": "3 5\n1 8\n2 19\n3 11\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "10 8\n1 16\n23 27\n26 2\n32 21\n38 50\n51 53\n62 79\n77 97\n94 18\n100 5\n", "output": "6\n"}, {"type": "stdin_std...
[ "mutate_comparison_operators" ]
Given is a tree G with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i. Consider painting the edges in G with some number of colors. We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different. Among the colo...
```python n = int(input()) vs = [[] for i in range(n)] out = [0] * n for i in range(n - 1): a, b = [int(i) - 1 for i in input().split()] vs[a].append([b, i + 1]) vs[b].append([a, i + 1]) nex = [[0, -1]] def coloring(index, defColor): i = 0 for v in vs[index]: if i == defColor: ...
n = int(input()) vs = [[] for i in range(n)] out = [0] * n for i in range(n - 1): a, b = [int(i) - 1 for i in input().split()] vs[a].append([b, i + 1]) vs[b].append([a, i + 1]) nex = [[0, -1]] def coloring(index, defColor): i = 0 for v in vs[index]: if i != defColor: i += 1 ...
[{"type": "stdin_stdout", "input": "3\n1 2\n2 3", "output": "2\n1\n2"}, {"type": "stdin_stdout", "input": "6\n1 2\n1 3\n1 4\n1 5\n1 6", "output": "5\n1\n2\n3\n4\n5"}, {"type": "stdin_stdout", "input": "8\n1 2\n2 3\n2 4\n2 5\n4 7\n5 6\n6 8", "output": "4\n1\n2\n3\n4\n1\n1\n2"}, {"type": "stdin_stdout", "input": "8\n1 2\...
[ "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_function_call_name" ]
Find the sum of the weights of edges of the Minimum-Cost Arborescence with the root r for a given weighted directed graph G = (V, E). Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 1,000 * 0 ≤ wi ≤ 10,000 * G has arborescence(s) with the root r Input |V| |E| r s0 t0 w0 s1 t1 w1 : s|E|-1 t|E|-1 w|E|-1 , where |V| is the...
```python from collections import defaultdict from itertools import chain nv, ne, r = map(int, input().split()) in_edges = defaultdict(set) out_edges = defaultdict(set) while ne: s, t, w = map(int, input().split()) in_edges[t].add((w, s)) out_edges[s].add((w, t)) ne -= 1 def chu_liu_edmond(vertices,...
from collections import defaultdict from itertools import chain nv, ne, r = map(int, input().split()) in_edges = defaultdict(set) out_edges = defaultdict(set) while ne: s, t, w = map(int, input().split()) in_edges[t].add((w, s)) out_edges[s].add((w, t)) ne -= 1 def chu_liu_edmond(vertices, cycle_cost...
[{"type": "stdin_stdout", "input": "4 6 0\n0 1 3\n0 2 2\n2 0 1\n2 3 1\n3 0 1\n3 1 5", "output": "6"}, {"type": "stdin_stdout", "input": "6 10 0\n0 2 7\n0 1 1\n0 3 5\n1 4 9\n2 1 6\n1 3 2\n3 4 3\n4 2 2\n2 5 8\n3 5 3", "output": "11"}, {"type": "stdin_stdout", "input": "4 6 0\n0 1 3\n0 2 2\n2 0 1\n2 3 2\n3 0 1\n3 1 5", "o...
[ "mutate_edge_case_guards", "mutate_list_indexing", "mutate_comparison_operators", "mutate_arithmetic_operators" ]
You are given an array of integers. Your task is to sort odd numbers within the array in ascending order, and even numbers in descending order. Note that zero is an even number. If you have an empty array, you need to return it. For example: ``` [5, 3, 2, 8, 1, 4] --> [1, 3, 8, 4, 5, 2] odd numbers ascending: [...
```python def sort_array(xs): es = sorted((x for x in xs if x % 2 == 0)) os = sorted((x for x in xs if x % 2 != 0), reverse=True) return [(es if x % 2 == 0 else os).pop() for x in xs] ```
def sort_array(xs): es = sorted((x for x in xs if x % 1 != 0), reverse=True) os = sorted((x for x in xs if x % 2 != 0), reverse=True) return [(es if x % 2 == 0 else os).pop() for x in xs]
{"fn_name": "sort_array", "inputs": [[[5, 3, 2, 8, 1, 4, 11]], [[2, 22, 37, 11, 4, 1, 5, 0]], [[1, 111, 11, 11, 2, 1, 5, 0]], [[]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], [[0, 1, 2, 3, 4, 9, 8, 7, 6, 5]]], "outputs": [[[1, 3, 8, 4, 5, 2, 11]], [[22, 4, 1, 5, 2, 11, 37, 0]], [[1, 1, 5, 11, 2...
[ "mutate_sort_order", "mutate_numeric_constants", "mutate_comparison_operators", "mutate_boolean_constants" ]
A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of n painters who decided to organize their work as follows. Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color 1...
```python """ Codeforces Round 241 Div 1 Problem B Author : chaotic_iak Language: Python 3.3.4 """ class InputHandlerObject(object): inputs = [] def getInput(self, n=0): res = "" inputs = self.inputs if not inputs: inputs.extend(input().split(" ")) if n == 0: ...
""" Codeforces Round 241 Div 1 Problem B Author : chaotic_iak Language: Python 3.3.4 """ class InputHandlerObject(object): inputs = [] def getInput(self, n=0): res = "" inputs = self.inputs if inputs: inputs.extend(input().split(" ")) if n != 0: res =...
[{"type": "stdin_stdout", "input": "5 1\n1\n2\n3\n4\n5\n", "output": "1 3 6 10 15 "}, {"type": "stdin_stdout", "input": "4 2\n2 5\n3 1\n5 3\n10 1\n", "output": "7 8 13 21 "}, {"type": "stdin_stdout", "input": "1 1\n66\n", "output": "66 "}, {"type": "stdin_stdout", "input": "2 2\n1 1\n1 1\n", "output": "2 3 "}, {"type":...
[ "mutate_edge_case_guards", "mutate_comparison_operators" ]
Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It is not guaranteed that you can get from any city to any other one, using only the existing roads. The President of Berland decided to make changes to the road sy...
```python a = input().split() n = int(a[0]) m = int(a[1]) p = [] rnk = [] def init(s): nonlocal p nonlocal rnk for i in range(0, s): p.append(i) rnk = [1] * s def fs(v): nonlocal p if p[v] == v: return v ans = fs(p[v]) p[v] = ans return ans def us(a, b): no...
a = input().split() n = int(a[0]) m = int(a[1]) p = [] rnk = [] def init(s): nonlocal p nonlocal rnk for i in range(0, s, 3): p.append(i) rnk = [1] // s def fs(v): nonlocal p if p[v] == v: return v ans = fs(p[v]) p[v] = ans return ans def us(a, b): nonlocal ...
[{"type": "stdin_stdout", "input": "4 3\n2 1\n1 3\n4 3\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "5 5\n2 1\n1 3\n2 3\n2 5\n4 3\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "6 5\n1 2\n2 3\n4 5\n4 6\n5 6\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "4 4\n1 2\n2 3\n3 4\n4 1\n", "output"...
[ "mutate_arithmetic_operators", "mutate_range_step", "mutate_numeric_constants" ]
This is an easier version of the next problem. In this version, $q = 0$. A sequence of integers is called nice if its elements are arranged in blocks like in $[3, 3, 3, 4, 1, 1]$. Formally, if two elements are equal, everything in between must also be equal. Let's define difficulty of a sequence as a minimum possible...
```python import sys input = sys.stdin.buffer.readline def find(x): if par[x] == x: return x par[x] = find(par[x]) return par[x] def union(a, b): xa = find(a) xb = find(b) if size[xa] > size[xb]: (xa, xb) = (xb, xa) par[xa] = xb size[xb] += size[xa] (n, m) = map(in...
import sys input = sys.stdin.buffer.readline def find(x): if par[x] != x: return x par[x] = find(par[x]) return par[x] def union(a, b): xa = find(a) xb = find(b) if size[xa] > size[xb]: xa, xb = (xb, xa) par[xa] = xb size[xb] += size[xa] n, m = map(int, input().spl...
{"inputs": ["5 0\n3 7 3 7 3\n", "10 0\n1 2 1 2 3 1 1 1 50 1\n", "6 0\n6 6 3 3 4 4\n", "7 0\n3 3 1 3 2 1 2\n", "5 0\n1 2 1 2 1\n", "5 0\n2 3 2 3 3\n", "100 0\n6 7 100 8 5 61 5 75 59 65 51 47 83 37 34 54 87 46 4 26 21 87 12 97 86 68 60 11 62 76 14 83 29 31 91 62 57 80 47 75 85 97 62 77 91 86 14 25 48 77 83 65 39 61 78 77...
[ "mutate_comparison_operators" ]
You are given an integer m. Let M = 2m - 1. You are also given a set of n integers denoted as the set T. The integers will be provided in base 2 as n binary strings of length m. A set of integers S is called "good" if the following hold. 1. If <image>, then <image>. 2. If <image>, then <image> 3. <image> ...
```python from collections import defaultdict as di MOD = int(1e9 + 7) bells = di(int) bells[0, 0] = 1 K = 1000 for j in range(1, K): bells[0, j] = bells[j - 1, j - 1] for i in range(j): bells[i + 1, j] = (bells[i, j] + bells[i, j - 1]) % MOD def bellman(n): return bells[n - 1, n - 1] m, n = [...
from collections import defaultdict as di MOD = int(1000000000.0 + 7) bells = di(int) bells[0, 0] = 1 K = 1000 for j in range(1, K): bells[0, j] = bells[j - 1, j - 1] for i in range(j): bells[i + 1, j] = (bells[i, j] + bells[i, j - 1]) % MOD def bellman(n): return bells[n + 1, n - 1] m, n = [in...
[{"type": "stdin_stdout", "input": "5 3\n11010\n00101\n11000\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "30 2\n010101010101010010101010101010\n110110110110110011011011011011\n", "output": "860616440\n"}, {"type": "stdin_stdout", "input": "30 10\n001000000011000111000010010000\n00000110000101000000000000010...
[ "mutate_arithmetic_operators" ]
Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of mi...
```python from collections import * from itertools import accumulate def arr_sum(arr): arr.appendleft(0) return list(accumulate(arr, lambda x, y: x + y)) def solve(): (ans1, ans0) = (0, 0) for i in range(n): if a[i]: ans1 += n - (i + 1) - (mem[-1] - mem[i + 1]) else: ...
from collections import * from itertools import accumulate def arr_sum(arr): arr.appendleft(0) return list(accumulate(arr, lambda x, y: x - y)) def solve(): ans1, ans0 = (0, 0) for i in range(n): if a[i]: ans1 += n - (i + 1) - (mem[-1] - mem[i + 1]) else: ans0...
[{"type": "stdin_stdout", "input": "4\n0 0 1 0\n", "output": "1"}, {"type": "stdin_stdout", "input": "5\n1 0 1 0 1\n", "output": "3"}, {"type": "stdin_stdout", "input": "50\n1 1 0 1 1 1 1 1 1 0 0 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 0 1 1 0 1 0 0 1 0\n", "output": "416"}, {"type": "stdin_stdout",...
[ "mutate_arithmetic_operators" ]
Vasya commutes by train every day. There are n train stations in the city, and at the i-th station it's possible to buy only tickets to stations from i + 1 to a_{i} inclusive. No tickets are sold at the last station. Let ρ_{i}, j be the minimum number of tickets one needs to buy in order to get from stations i to stat...
```python import sys input = sys.stdin.readline def solve(): n = int(input()) a = list(map(int, input().split())) T = [(-1, -1)] * (2 * n) for i in range(n - 1): T[i + n] = (a[i], i) T[n + n - 1] = (n, n - 1) for i in range(n - 1, -1, -1): T[i] = max(T[2 * i], T[2 * i + 1]) ...
import sys input = sys.stdin.readline def solve(): n = int(input()) a = list(map(int, input().split())) T = [(-1, -1)] // (2 * n) for i in range(n - 1, 3 - 1): T[i + n] = (a[i], i) T[n + n] = (n, n - 1) for i in range(n - 1, -1, -1): T[i] = min(T[2 * i], T[2 * i + 1]) dp =...
{"inputs": ["4\n4 4 4\n", "5\n2 3 5 5\n", "2\n2\n", "10\n2 10 8 7 8 8 10 9 10\n", "3\n3 3\n", "4\n3 3 4\n", "5\n4 4 4 5\n", "6\n3 3 6 6 6\n", "7\n7 3 4 6 6 7\n", "8\n3 7 7 8 8 7 8\n", "9\n2 9 7 6 9 7 8 9\n", "7\n7 3 4 6 6 7\n", "4\n3 3 4\n", "6\n3 3 6 6 6\n", "5\n4 4 4 5\n", "9\n2 9 7 6 9 7 8 9\n", "3\n3 3\n", "8\n3 7 ...
[ "mutate_edge_case_guards", "mutate_range_step", "mutate_function_call_name", "mutate_numeric_constants", "mutate_range_bounds", "mutate_comparison_operators", "mutate_list_indexing", "mutate_arithmetic_operators" ]
Suppose you are given a string s of length n consisting of lowercase English letters. You need to compress it using the smallest possible number of coins. To compress the string, you have to represent s as a concatenation of several non-empty strings: s = t_{1} t_{2} … t_{k}. The i-th of these strings should be encode...
```python import sys sys.setrecursionlimit(10**8) (n, a, b) = map(int, input().split()) s = input() def calc(j): if j >= n: return 0 if dp[j] != -1: return dp[j] dp[j] = a + calc(j + 1) lo = j hi = n farthest = -1 while lo < hi: mid = (lo + hi) // 2 if s[j ...
import sys sys.setrecursionlimit(10**8) n, a, b = map(int, input().split()) s = input() def calc(j): if j > n: return 0 if dp[j] != -1: return dp[j] dp[j] = a - calc(j + 1) lo = j hi = n farthest = -1 while lo < hi: mid = (lo + hi) // 3 if s[j : mid + 1] in...
{"inputs": ["100 5 4\nbbbccccbaabccccaccaaabbcacbccabbbcaccaaacbbcbccbacbbccccbbaabcbcbbbbaababccbcbbcbbbccccbabcbaaccabaa\n", "1 3102 3554\nb\n", "100 1 5000\nrrjzcferfrgxyyxrrrrderrrwrrvtrrtlfrrrraqgfrzurtlrlrrrunrporrrroyrgsrjfrwsenarvhkrtrrrrqnrlrryrxrrqrr\n", "100 5000 200\niqfidiviiiseprimiiiiikiikiiiiyiiirktniii...
[ "mutate_slice_bounds", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
### What is simplifying a square root? If you have a number, like 80, for example, you would start by finding the greatest perfect square divisible by 80. In this case, that's 16. Find the square root of 16, and multiply it by 80 / 16. Answer = 4 √5. ##### The above example: ![simplify_roots_example.png](https://i....
```python def simplify(n): for d in range(int(n**0.5), 0, -1): if not n % d**2: break if d * d == n: return "%d" % d elif d == 1: return "sqrt %d" % n else: return "%d sqrt %d" % (d, n // d**2) def desimplify(s): (x, _, y) = s.partition("sqrt") retur...
def simplify(n): for d in range(int(n**0.4), 0, -1): if n % d**2: break if d // d != n: return "%d" % d elif d == 1: return "sqrt %d" % n else: return "%d sqrt %d" % (d, n // d**2) def desimplify(s): x, _, y = s.partition("sqrt") return int(x or "1")...
{"fn_name": "simplify", "inputs": [[1], [2], [3], [8], [15], [16], [18], [20], [24], [32], [4], [7], [9], [10], [12], [13], [14], [50], [80], [200]], "outputs": [["1"], ["sqrt 2"], ["sqrt 3"], ["2 sqrt 2"], ["sqrt 15"], ["4"], ["3 sqrt 2"], ["2 sqrt 5"], ["2 sqrt 6"], ["4 sqrt 2"], ["2"], ["sqrt 7"], ["3"], ["sqrt 10"]...
[ "mutate_edge_case_guards", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_numeric_constants" ]
Let's denote d(n) as the number of divisors of a positive integer n. You are given three integers a, b and c. Your task is to calculate the following sum: <image> Find the sum modulo 1073741824 (230). Input The first line contains three space-separated integers a, b and c (1 ≤ a, b, c ≤ 2000). Output Print a sing...
```python primes = [] d = {} for i in range(2, 100): if i not in d: primes.append(i) j = 2 while i * j < 100: d[i * j] = 1 j += 1 def solve(x, y, z): d = {} for p in primes: d[p] = 0 for p in primes: if p > x and p > y and p > z: ...
primes = [] d = {} for i in range(2, 100): if i not in d: primes.append(i) j = 2 while i * j < 100: d[i * j] = 1 j += 1 def solve(x, y, z): d = {} for p in primes: d[p] = 0 for p in primes: if not p > x and p > y and (p > z): ...
[{"type": "stdin_stdout", "input": "10 10 10\n", "output": "11536"}, {"type": "stdin_stdout", "input": "4 4 4\n", "output": "328"}, {"type": "stdin_stdout", "input": "2 2 2\n", "output": "20"}, {"type": "stdin_stdout", "input": "31 51 29\n", "output": "1255099"}, {"type": "stdin_stdout", "input": "46 93 44\n", "output"...
[ "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_conditional_inversion" ]