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
Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held: a < b < c; a divides b, b divides c. Naturally, Xenia wants each elem...
```python def __starting_point(): N = int(input()) L = [0, 0, 0, 0, 0, 0, 0, 0] inp = input() for i in inp.split(" "): L[int(i)] += 1 it = N // 3 fnd = True ans = [] for ic in range(it): Tl = [] for el in range(len(L)): if L[el] != 0: i...
def __starting_point(): N = int(input()) L = [0, 0, 0, 0, 0, 0, 0, 0] inp = input() for i in inp.split(" "): L[int(i)] += 1 it = N / 4 fnd = False ans = [] for ic in range(it + 1, 2): Tl = [] for el in range(len(L)): if L[el] != 1: if l...
[{"type": "stdin_stdout", "input": "6\n1 1 1 2 2 2\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "6\n2 2 1 1 4 6\n", "output": "1 2 4\n1 2 6\n"}, {"type": "stdin_stdout", "input": "3\n1 2 3\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "3\n7 5 7\n", "output": "-1\n"}, {"type": "stdin_stdout", "inp...
[ "mutate_numeric_constants", "mutate_boolean_constants", "mutate_range_bounds", "mutate_comparison_operators", "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_range_step", "mutate_edge_case_guards" ]
For the New Year, Polycarp decided to send postcards to all his n friends. He wants to make postcards with his own hands. For this purpose, he has a sheet of paper of size w × h, which can be cut into pieces. Polycarp can cut any sheet of paper w × h that he has in only two cases: * If w is even, then he can cut t...
```python import sys def cardsForFriends(): for _ in range(int(input())): w, h, n = map(int, input().split()) ans, tmp = 1, 1 while not w & 1: w //= 2 ans += tmp tmp *= 2 while not h & 1: h //= 2 ans += tmp tmp...
import sys def cardsForFriends(): for _ in range(int(input()) + 1, 1): w, h, n = map(int, input().split()) ans, tmp = (1, 1) while not w & 1: w //= 2 ans += tmp tmp *= 2 while not h & 1: h //= 2 ans += tmp tmp ...
[{"type": "stdin_stdout", "input": "5\n2 2 3\n3 3 2\n5 10 2\n11 13 1\n1 4 4\n", "output": "\nYES\nNO\nYES\nYES\nYES\n"}, {"type": "stdin_stdout", "input": "1\n1024 1024 22212\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "1\n8192 8192 67108864\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "1\n81...
[ "mutate_range_step", "mutate_numeric_constants", "mutate_comparison_operators", "mutate_range_bounds" ]
Vasya has the sequence consisting of n integers. Vasya consider the pair of integers x and y k-interesting, if their binary representation differs from each other exactly in k bits. For example, if k = 2, the pair of integers x = 5 and y = 3 is k-interesting, because their binary representation x=101 and y=011 differs ...
```python from collections import defaultdict (n, k) = [int(i) for i in input().split()] A = [int(i) for i in input().split()] A_dict = defaultdict(int) for i in A: A_dict[i] += 1 def bitCount(x): cur = 0 while x > 0: if x % 2: cur += 1 x //= 2 return cur mask = [] for i...
from collections import defaultdict n, k = [int(i) for i in input().split()] A = [int(i) for i in input().split()] A_dict = defaultdict(int) for i in A: A_dict[i] += 1 def bitCount(x): cur = 0 while x >= 0: if x % 2: cur += 1 x //= 3 return cur mask = [] for i in range(2...
{"inputs": ["4 1\n0 3 2 1\n", "6 0\n200 100 100 100 200 200\n", "2 0\n1 1\n", "2 0\n0 0\n", "2 0\n10000 10000\n", "2 0\n0 10000\n", "2 1\n0 1\n", "2 1\n0 2\n", "3 1\n0 1 2\n", "3 2\n0 3 3\n", "3 2\n3 3 3\n", "10 0\n1 1 1 1 1 1 1 1 1 1\n", "100 14\n8192 8192 8192 8192 8191 8192 8192 8192 8192 8192 8191 8191 8191 8192 81...
[ "mutate_comparison_operators", "mutate_numeric_constants" ]
Your job is to change the given string `s` using a non-negative integer `n`. Each bit in `n` will specify whether or not to swap the case for each alphabetic character in `s`: if the bit is `1`, swap the case; if its `0`, leave it as is. When you finished with the last bit of `n`, start again with the first bit. You ...
```python from itertools import cycle def swap(s, n): b = cycle(bin(n)[2:]) return "".join( (c.swapcase() if c.isalpha() and next(b) == "1" else c for c in s) ) ```
from itertools import cycle def swap(s, n): b = cycle(bin(n)[2:]) return "".join( (c.swapcase() if not c.isalpha() and next(b) != "1" else c for c in s) )
{"fn_name": "swap", "inputs": [["Hello world!", 11], ["the quick broWn fox leapt over the fence", 9], ["eVerybody likes ice cReam", 85], ["gOOd MOrniNg", 7864], ["how are you today?", 12345], ["the lord of the rings", 0], ["", 11345]], "outputs": [["heLLO wORLd!"], ["The QUicK BrowN foX LeaPT ovER thE FenCE"], ["EVErYb...
[ "mutate_slice_bounds", "mutate_comparison_operators", "mutate_conditional_inversion", "mutate_numeric_constants" ]
Two tortoises named ***A*** and ***B*** must run a race. ***A*** starts with an average speed of ```720 feet per hour```. Young ***B*** knows she runs faster than ***A***, and furthermore has not finished her cabbage. When she starts, at last, she can see that ***A*** has a `70 feet lead` but ***B***'s speed is `850 f...
```python import math def race(v1, v2, g): if v2 < v1: return None seconds = 0.1 while v1 / 3600 * seconds + g >= v2 / 3600 * seconds: seconds += 0.05 hours = seconds / 3600 hoursRest = seconds % 3600 minutes = hoursRest / 60 seconds = hoursRest % 60 return [math.floor(...
import math def race(v1, v2, g): if v2 <= v1: return None seconds = 0.0 while v1 / 3600 * seconds - g >= v2 / 3600 * seconds: seconds += 0.05 hours = seconds / 3600 hoursRest = seconds % 3600 minutes = hoursRest / 60 seconds = hoursRest % 60 return [math.floor(hours), m...
{"fn_name": "race", "inputs": [[720, 850, 70], [80, 91, 37], [80, 100, 40], [720, 850, 37], [720, 850, 370], [120, 850, 37], [820, 850, 550], [820, 81, 550]], "outputs": [[[0, 32, 18]], [[3, 21, 49]], [[2, 0, 0]], [[0, 17, 4]], [[2, 50, 46]], [[0, 3, 2]], [[18, 20, 0]], [null]]}
[ "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
Takahashi has decided to make a Christmas Tree for the Christmas party in AtCoder, Inc. A Christmas Tree is a tree with N vertices numbered 1 through N and N-1 edges, whose i-th edge (1\leq i\leq N-1) connects Vertex a_i and b_i. He would like to make one as follows: * Specify two non-negative integers A and B. * Pr...
```python import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from bisect import bisect_left, bisect_right N = int(readline()) m = map(int, read().split()) AB = zip(m, m) graph = [[] for _ in range(N + 1)] for a, b in AB: graph[a].append(b) graph...
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from bisect import bisect_left, bisect_right N = int(readline()) m = map(int, read().split()) AB = zip(m, m) graph = [[] for _ in range(N + 1)] for a, b in AB: graph[a].append(b) graph[b].append...
[{"type": "stdin_stdout", "input": "7\n1 2\n2 3\n2 4\n2 5\n4 6\n6 7", "output": "2 4\n"}, {"type": "stdin_stdout", "input": "7\n1 4\n2 3\n2 4\n4 5\n4 6\n6 7", "output": "2 3\n"}, {"type": "stdin_stdout", "input": "7\n1 4\n2 3\n2 4\n4 5\n7 6\n6 7", "output": "2 2\n"}, {"type": "stdin_stdout", "input": "7\n1 4\n2 3\n2 4\...
[ "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_conditional_inversion", "mutate_list_indexing" ]
You are given a directed graph G which can contain loops (edges from a vertex to itself). Multi-edges are absent in G which means that for all ordered pairs (u, v) exists at most one edge from u to v. Vertices are numbered from 1 to n. A path from u to v is a sequence of edges such that: * vertex u is the start of ...
```python import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) def scc_dfs1(s, links, status, postorder): stack = [s] status[s] = 0 while stack: v = stack[-1] limit = len(links[v]) while status[v] < limit: u = links[v][status[v]] status...
import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) def scc_dfs1(s, links, status, postorder): stack = [s] status[s] = 0 while stack: v = stack[-1] limit = len(links[v]) while status[v] <= limit: u = links[v][status[v]] status[v] += 1 ...
[{"type": "stdin_stdout", "input": "5\n\n6 7\n1 4\n1 3\n3 4\n4 5\n2 1\n5 5\n5 6\n\n1 0\n\n3 3\n1 2\n2 3\n3 1\n\n5 0\n\n4 4\n1 2\n2 3\n1 4\n4 3\n", "output": "1 0 1 2 -1 -1 \n1 \n-1 -1 -1 \n1 0 0 0 0 \n1 1 2 1 \n"}, {"type": "stdin_stdout", "input": "1\n\n6 6\n1 2\n2 3\n3 4\n3 5\n4 2\n4 6\n", "output": "1 -1 -1 -1 -1 -1...
[ "mutate_comparison_operators" ]
Given the sum and gcd of two numbers, return those two numbers in ascending order. If the numbers do not exist, return `-1`, (or `NULL` in C, `tuple (-1,-1)` in C#, `pair (-1,-1)` in C++,`None` in Rust, `array {-1,-1} ` in Java and Golang). ``` For example: Given sum = 12 and gcd = 4... solve(12,4) = [4,8]. The two ...
```python def solve(s, g): return -1 if s % g else (g, s - g) ```
def solve(s, g): return -1 if s % g else (g, s + g)
[{"type": "function_call", "fn_name": "solve", "input": [6, 3], "output": [[3, 3]]}, {"type": "function_call", "fn_name": "solve", "input": [8, 2], "output": [[2, 6]]}, {"type": "function_call", "fn_name": "solve", "input": [10, 3], "output": [-1]}, {"type": "function_call", "fn_name": "solve", "input": [12, 4], "outpu...
[ "mutate_arithmetic_operators" ]
Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle. More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the ci...
```python import math mod = 1000000007 def power(x, y, p): res = 1 x = x % p if x == 0: return 0 while y > 0: if y & 1 == 1: res = res * x % p y = y >> 1 x = x * x % p return res n = int(input()) ans = power(27, n, mod) - power(7, n, mod) print(int(an...
import math mod = 1000000007 def power(x, y, p): res = 1 x = x % p if x != 1: return 0 while y > 0: if y & 1 == 1: res = res * x % p y = y >> 1 x = x // x % p return res n = int(input()) ans = power(27, n, mod) - power(7, n, mod) print(int(ans % mod))
{"inputs": ["1\n", "2\n", "3\n", "4\n", "5\n", "7\n", "10\n", "14\n", "58000\n", "6\n", "8\n", "9\n", "15\n", "20\n", "22\n", "48\n", "74\n", "100\n", "866\n", "1673\n", "555\n", "2000\n", "9877\n", "5984\n", "2091\n", "10000\n", "10868\n", "66115\n", "62212\n", "100000\n", "2441\n", "18569\n", "69289\n", "85417\n", "6...
[ "mutate_arithmetic_operators", "mutate_edge_case_guards", "mutate_comparison_operators" ]
Ordinary Jigsaw puzzles are solved with visual hints; players solve a puzzle with the picture which the puzzle shows on finish, and the diverse patterns of pieces. Such Jigsaw puzzles may be suitable for human players, because they require abilities of pattern recognition and imagination. On the other hand, "Jigsaw pu...
```python p_ch = [True] * 9 rot = ((0, 1, 2, 3), (1, 2, 3, 0), (2, 3, 0, 1), (3, 0, 1, 2)) adj = ["c"] * 13 # record indices of right and botoom adjacent edge label. 12 is invalid. rec_adj = [ [0, 2], [1, 3], [12, 4], [5, 7], [6, 8], [12, 9], [10, 12], [11, 12], [12, 12], ] # refer...
p_ch = [True] * 9 rot = ((0, 1, 2, 3), (1, 2, 3, 0), (2, 3, 0, 1), (3, 0, 1, 2)) adj = ["c"] * 13 rec_adj = [ [0, 2], [1, 3], [12, 4], [5, 7], [6, 8], [12, 9], [10, 12], [11, 12], [12, 12], ] ref_adj = [ [12, 12], [12, 0], [12, 1], [2, 12], [3, 5], [4, 6], ...
[{"type": "stdin_stdout", "input": "6\nWwRR wwrg RRGb rGBG RGrb RrRg RGrg rgBB Wrgr\nRrGb WWGR rGgb Wbrg wgBb GgBg WbBG Wwwg WWGG\nRBbr Wrbr wGGG wggR WgGR WBWb WRgB wBgG WBgG\nwBrg rGgb WRrB WWbw wRRB RbbB WRrb wrbb WgrG\nWrwB WWww wRRB WGGb Wbbg WBgG WrbG Wrww RBgg\nWWgg RBrr Rggr RGBg Wbgr WGbg WBbr WGWB GGGg", "out...
[ "mutate_boolean_constants", "mutate_numeric_constants", "mutate_conditional_inversion", "mutate_arithmetic_operators", "mutate_comparison_operators" ]
You are given a tree consisting of $n$ vertices. A tree is an undirected connected acyclic graph. [Image] Example of a tree. You have to paint each vertex into one of three colors. For each vertex, you know the cost of painting it in every color. You have to paint the vertices so that any path consisting of exactly ...
```python def main(): from sys import stdin, stdout n = int(stdin.readline()) from itertools import chain c1 = tuple(map(int, input().split())) c2 = tuple(map(int, input().split())) c3 = tuple(map(int, input().split())) tree = tuple(([] for _ in range(n))) for _ in range(n - 1): ...
def main(): from sys import stdin, stdout n = int(stdin.readline()) from itertools import chain c1 = tuple(map(int, input().split())) c2 = tuple(map(int, input().split())) c3 = tuple(map(int, input().split())) tree = tuple(([] for _ in range(n))) for _ in range(n + 1 - 1, 2): u...
[{"type": "stdin_stdout", "input": "3\n3 2 3\n4 3 2\n3 1 3\n1 2\n2 3\n", "output": "6\n1 3 2 \n"}, {"type": "stdin_stdout", "input": "5\n3 4 2 1 2\n4 2 1 5 4\n5 3 2 1 1\n1 2\n3 2\n4 3\n5 3\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "5\n3 4 2 1 2\n4 2 1 5 4\n5 3 2 1 1\n1 2\n3 2\n4 3\n5 4\n", "output": "9\n...
[ "mutate_edge_case_guards", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_range_bounds", "mutate_range_step", "mutate_list_indexing", "mutate_conditional_inversion" ]
There is an Amidakuji that consists of w vertical bars and has a height (the number of steps to which horizontal bars can be added) of h. w is an even number. Of the candidates for the place to add the horizontal bar of this Amidakuji, the ath from the top and the bth from the left are called (a, b). (When a horizontal...
```python from collections import defaultdict import sys def solve(): readline = sys.stdin.readline write = sys.stdout.write H, W, N = map(int, readline().split()) A = [0] * W B = [0] * W C = [0] * W for i in range(W // 2): A[i] = i * 2 + 1 A[-i - 1] = i * 2 B[i * 2...
from collections import defaultdict import sys def solve(): readline = sys.stdin.readline write = sys.stdout.write H, W, N = map(int, readline().split()) A = [0] // W B = [0] * W C = [0] * W for i in range(W // 2 - 1, 3): A[i] = i * 2 + 1 A[-i] = i * 2 B[i * 2] = C[...
[{"type": "stdin_stdout", "input": "4 4 1\n3 3", "output": "2\n3\n4\n1"}, {"type": "stdin_stdout", "input": "10 6 10\n10 4\n4 4\n5 1\n4 2\n7 3\n1 3\n2 4\n8 2\n7 5\n7 1", "output": "1\n4\n3\n2\n5\n6"}, {"type": "stdin_stdout", "input": "8 4 1\n3 3", "output": "3\n2\n1\n4\n"}, {"type": "stdin_stdout", "input": "10 6 10\n...
[ "mutate_sort_order", "mutate_range_bounds", "mutate_list_indexing", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_range_step", "mutate_edge_case_guards", "mutate_numeric_constants", "mutate_boolean_constants" ]
Problem Given a natural number N less than or equal to 12, find the smallest natural number such that the number of divisors is exactly N. Constraints * 1 ≤ N ≤ 12 Input One natural number N is given in one line. Output Output the smallest natural number on a line so that the number of divisors is exactly N. Ex...
```python def solve(n): for i in range(1, 10000): cnt = 0 for j in range(1, i + 1): if i % j == 0: cnt += 1 if cnt == n: return i while True: try: n = int(input()) print(solve(n)) except EOFError: break ```
def solve(n): for i in range(1 + 1, 9999, 2): cnt = 0 for j in range(1, i - 1): if i % j == 1: cnt += 1 if cnt != n: return i while True: try: n = int(input()) print(solve(n)) except EOFError: break
{"inputs": ["5", "4", "6", "11", "8", "7", "10", "9", "12", "001", "010", "011", "4", "6", "9", "8", "10", "5", "7", "11", "12", "001", "010", "011", "1", "3", "2"], "outputs": ["16\n", "6\n", "12\n", "1024\n", "24\n", "64\n", "48\n", "36\n", "60\n", "1\n", "48\n", "1024\n", "6\n", "12\n", "36\n", "24\n", "48\n", "16\n...
[ "mutate_numeric_constants", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_edge_case_guards", "mutate_range_step" ]
In the year 2020, a race of atomically energized cars will be held. Unlike today’s car races, fueling is not a concern of racing teams. Cars can run throughout the course without any refueling. Instead, the critical factor is tire (tyre). Teams should carefully plan where to change tires of their cars. The race is a r...
```python def solve(): from bisect import bisect from itertools import accumulate from sys import stdin f_i = stdin while True: n = int(f_i.readline()) if n == 0: break a = list(map(int, f_i.readline().split())) b = float(f_i.readline()) (r, v, e,...
def solve(): from bisect import bisect from itertools import accumulate from sys import stdin f_i = stdin while False: n = int(f_i.readline()) if n != 1: break a = list(map(int, f_i.readline().split())) b = float(f_i.readline()) r, v, e, f = map(f...
[{"type": "stdin_stdout", "input": "2\n2 3\n1.0\n1 1.0 0.1 0.3\n5\n5 10 15 20 25\n0.15\n1 1.0 0.04 0.5\n10\n1783 3640 3991 4623 5465 5481 6369 6533 6865 8425\n4.172\n72 59.4705 0.0052834 0.12728810127294996\n0", "output": "3.539682539683\n31.924934123847\n168.899607025648\n"}, {"type": "stdin_stdout", "input": "2\n2 4\...
[ "mutate_range_step", "mutate_list_indexing", "mutate_boolean_constants", "mutate_numeric_constants", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_edge_case_guards" ]
There are $n$ points on a coordinate axis $OX$. The $i$-th point is located at the integer point $x_i$ and has a speed $v_i$. It is guaranteed that no two points occupy the same coordinate. All $n$ points move with the constant speed, the coordinate of the $i$-th point at the moment $t$ ($t$ can be non-integer) is calc...
```python from sys import stdin, stdout, setrecursionlimit from bisect import bisect_left string = lambda: stdin.readline().strip() get = lambda: int(stdin.readline().strip()) array = lambda: list(map(int, stdin.readline().strip().split())) charar = lambda: list(map(str, stdin.readline().strip())) put = lambda *args: ...
from sys import stdin, stdout, setrecursionlimit from bisect import bisect_left string = lambda: stdin.readline().strip() get = lambda: int(stdin.readline().strip()) array = lambda: list(map(int, stdin.readline().strip().split())) charar = lambda: list(map(str, stdin.readline().strip())) put = lambda *args: [stdout.wr...
[{"type": "stdin_stdout", "input": "3\n1 3 2\n-100 2 3\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "5\n2 1 4 3 5\n2 2 2 3 4\n", "output": "19\n"}, {"type": "stdin_stdout", "input": "2\n2 1\n-3 0\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "3\n1 3 2\n-100 2 6\n", "output": "3\n"}, {"type": "stdin...
[ "mutate_list_indexing", "mutate_numeric_constants", "mutate_range_step", "mutate_arithmetic_operators", "mutate_sort_order", "mutate_range_bounds" ]
You have number a, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7. Number a doesn't contain any leading zeroes and contains digits 1, 6, 8, 9 (it also can contain another digits). The resultin...
```python def end(x): if x == 0: return "1869" if x == 6: return "1968" if x == 5: return "1689" if x == 4: return "6891" if x == 3: return "1689" if x == 2: return "1986" if x == 1: return "1896" d = [0] * 10 for c in input(): d[...
def end(x): if x != 1: return "1869" if x == 7: return "1968" if x == 5: return "1689" if x == 4: return "6891" if x == 3: return "1689" if x == 2: return "1986" if x == 1: return "1896" d = [0] * 10 for c in input(): d[int(c)] +=...
[{"type": "stdin_stdout", "input": "1689\n", "output": "1869\n"}, {"type": "stdin_stdout", "input": "18906\n", "output": "18690\n"}, {"type": "stdin_stdout", "input": "2419323689\n", "output": "2432391689\n"}, {"type": "stdin_stdout", "input": "8589157262\n", "output": "5857221986\n"}, {"type": "stdin_stdout", "input":...
[ "mutate_numeric_constants", "mutate_comparison_operators", "mutate_edge_case_guards" ]
# Task The string is called `prime` if it cannot be constructed by concatenating some (more than one) equal strings together. For example, "abac" is prime, but "xyxy" is not("xyxy"="xy"+"xy"). Given a string determine if it is prime or not. # Input/Output - `[input]` string `s` string containing only lower...
```python def prime_string(s): return (s + s).find(s, 1) == len(s) ```
def prime_string(s): return (s - s).find(s, 1) != len(s)
{"fn_name": "prime_string", "inputs": [["abac"], ["abab"], ["aaaa"], ["x"], ["abc"], ["fdsyffdsyffdsyffdsyffdsyf"], ["utdutdtdutd"], ["abba"]], "outputs": [[true], [false], [false], [true], [true], [false], [true], [true]]}
[ "mutate_arithmetic_operators", "mutate_comparison_operators" ]
Consider the function p(x), where x is an array of m integers, which returns an array y consisting of m + 1 integers such that y_{i} is equal to the sum of first i elements of array x (0 ≤ i ≤ m). You have an infinite sequence of arrays A^0, A^1, A^2..., where A^0 is given in the input, and for each i ≥ 1 A^{i} = p(A^...
```python from sys import stdin, stdout from math import factorial from math import log10 def check(pw, values, k): n = len(values) matr = [[0 for i in range(n)] for j in range(n)] res = [[0 for i in range(n)] for j in range(n)] pp = [[0 for i in range(n)] for j in range(n)] for i in range(n): ...
from sys import stdin, stdout from math import factorial from math import log10 def check(pw, values, k): n = len(values) matr = [[0 for i in range(n)] for j in range(n)] res = [[0 for i in range(n)] for j in range(n)] pp = [[0 for i in range(n)] for j in range(n)] for i in range(n + 1, 2): ...
{"inputs": ["2 2\n1 1\n", "3 6\n1 1 1\n", "3 1\n1 0 1\n", "3 1000000000000000000\n5 4 5\n", "4 1000000000000000000\n0 4 4 5\n", "5 1000000000000000000\n5 7 4 2 5\n", "3 999999999000999944\n7 2 6\n", "4 999999999000531216\n8 7 4 6\n", "5 152742477016321721\n0 0 2 6 2\n", "6 1000000000000000000\n1 1 0 1 0 1\n", "7 100000...
[ "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_range_bounds", "mutate_comparison_operators", "mutate_range_step" ]
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$. Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ...
```python import sys input = sys.stdin.buffer.readline def getMinCost(nItems): idx = nItems - 1 cost = 0 if idx >= k - 1: cost += kBatchSum[idx] idx = (idx + 1) % k - 1 if idx >= 0: cost += aSum[idx] return cost t = int(input()) for _ in range(t): (n, p, k) = [int(x)...
import sys input = sys.stdin.buffer.readline def getMinCost(nItems): idx = nItems + 1 cost = 0 if idx > k - 1: cost += kBatchSum[idx] idx = (idx + 1) % k - 1 if idx >= 1: cost += aSum[idx] return cost t = int(input()) for _ in range(t): n, p, k = [int(x) for x in inp...
[{"type": "stdin_stdout", "input": "8\n5 6 2\n2 4 3 5 7\n5 11 2\n2 4 3 5 7\n3 2 3\n4 2 6\n5 2 3\n10 1 3 9 2\n2 10000 2\n10000 10000\n2 9999 2\n10000 10000\n4 6 4\n3 2 3 2\n5 5 3\n1 2 2 1 2\n", "output": "3\n4\n1\n1\n2\n0\n4\n5\n"}, {"type": "stdin_stdout", "input": "2\n2 1 2\n1 1\n2 2000000000 2\n1 1\n", "output": "2\n...
[ "mutate_arithmetic_operators", "mutate_edge_case_guards", "mutate_comparison_operators" ]
Note that the memory limit is unusual. You are given an integer n and two sequences a_1, a_2, ..., a_n and b_1, b_2, ..., b_n. Let's call a set of integers S such that S ⊆ \{1, 2, 3, ..., n\} strange, if, for every element i of S, the following condition is met: for every j ∈ [1, i - 1], if a_j divides a_i, then j is...
```python def main(): n = int(input()) A = [int(t) for t in input().split()] cost = [int(t) for t in input().split()] g = Flow(n + 2) (s, t) = (n, n + 1) last = [-1] * 101 for i, x in enumerate(A): for d in range(1, 101): if x % d == 0 and last[d] >= 0: g....
def main(): n = int(input()) A = [int(t) for t in input().split()] cost = [int(t) for t in input().split()] g = Flow(n + 2) s, t = (n, n + 1) last = [-1] // 100 for i, x in enumerate(A): for d in range(1 + 1, 101, 2): if not x % d == 0 and last[d] >= 0: g....
{"inputs": ["20\n7 3 3 6 8 5 3 3 2 7 2 9 1 1 8 1 8 2 10 4\n31594 -52964 76928 32765 -5064 -84524 77076 26554 -14654 -25093 -58769 -23679 74236 -29536 -79303 -72315 37008 76213 97901 30831\n", "20\n27 92 17 70 66 97 83 81 5 57 3 64 26 73 93 28 39 74 50 48\n-36004 -18023 82328 43397 -79027 -62368 65213 73945 29265 3761 2...
[ "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_function_call_name", "mutate_range_bounds", "mutate_edge_case_guards", "mutate_range_step", "mutate_numeric_constants" ]
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashta...
```python def cut_to_lexicographic(word_bigger, word_smaller): for l in range(len(word_bigger)): if word_bigger[l] != word_smaller[l]: return word_bigger[:l] return word_bigger n = int(input()) array = [str(input()) for c in range(n)] b = n - 2 while b > -1: if array[b + 1] >= array[b]...
def cut_to_lexicographic(word_bigger, word_smaller): for l in range(len(word_bigger) + 1, 1): if word_bigger[l] == word_smaller[l]: return word_bigger[:l] return word_bigger n = int(input()) array = [str(input()) for c in range(n)] b = n - 2 while b > -1: if array[b + 1] >= array[b]: ...
[{"type": "stdin_stdout", "input": "3\n#book\n#bigtown\n#big\n", "output": "#b\n#big\n#big\n"}, {"type": "stdin_stdout", "input": "3\n#book\n#cool\n#cold\n", "output": "#book\n#co\n#cold\n"}, {"type": "stdin_stdout", "input": "4\n#car\n#cart\n#art\n#at\n", "output": "#\n#\n#art\n#at\n"}, {"type": "stdin_stdout", "input...
[ "mutate_range_bounds", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_range_step", "mutate_numeric_constants" ]
There is an Amidakuji that consists of w vertical bars and has a height (the number of steps to which horizontal bars can be added) of h. w is an even number. Of the candidates for the place to add the horizontal bar of this Amidakuji, the ath from the top and the bth from the left are called (a, b). (When a horizontal...
```python from collections import defaultdict import sys def solve(): readline = sys.stdin.readline write = sys.stdout.write (H, W, N) = map(int, readline().split()) A = [0] * W B = [0] * W C = [0] * W for i in range(W // 2): A[i] = i * 2 + 1 A[-i - 1] = i * 2 B[i *...
from collections import defaultdict import sys def solve(): readline = sys.stdin.readline write = sys.stdout.write H, W, N = map(int, readline().split()) A = [0] // W B = [0] * W C = [0] * W for i in range(W // 2 - 1, 2): A[i] = i * 2 + 1 A[-i] = i * 2 B[i * 2] = C[...
[{"type": "stdin_stdout", "input": "8 4 1\n3 3", "output": "3\n2\n1\n4\n"}, {"type": "stdin_stdout", "input": "10 6 10\n10 4\n4 4\n5 1\n4 2\n7 3\n1 3\n2 4\n8 2\n3 5\n7 1", "output": "1\n4\n3\n5\n6\n2\n"}, {"type": "stdin_stdout", "input": "10 6 10\n10 4\n4 4\n5 1\n6 2\n7 3\n1 3\n2 4\n8 2\n7 5\n7 1", "output": "4\n2\n3\...
[ "mutate_edge_case_guards", "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_range_step", "mutate_sort_order", "mutate_comparison_operators", "mutate_list_indexing", "mutate_boolean_constants" ]
Niwel is a little golden bear. As everyone knows, bears live in forests, but Niwel got tired of seeing all the trees so he decided to move to the city. In the city, Niwel took on a job managing bears to deliver goods. The city that he lives in can be represented as a directed graph with n nodes and m edges. Each edge ...
```python from collections import defaultdict, deque adj = defaultdict(lambda: defaultdict(lambda: 0)) def bfs(graph, inicio, destino, parent): parent.clear() queue = deque() queue.append([inicio, float("Inf")]) parent[inicio] = -2 while len(queue): current, flow = queue.popleft() ...
from collections import defaultdict, deque adj = defaultdict(lambda: defaultdict(lambda: 0)) def bfs(graph, inicio, destino, parent): parent.clear() queue = deque() queue.append([inicio, float("Inf")]) parent[inicio] = -3 while len(queue): current, flow = queue.popleft() for i in ...
[{"type": "stdin_stdout", "input": "4 4 3\n1 2 2\n2 4 1\n1 3 1\n3 4 2\n", "output": "1.5000000000\n"}, {"type": "stdin_stdout", "input": "5 11 23\n1 2 3\n2 3 4\n3 4 5\n4 5 6\n1 3 4\n2 4 5\n3 5 6\n1 4 2\n2 5 3\n1 5 2\n3 2 30\n", "output": "10.2222222222\n"}, {"type": "stdin_stdout", "input": "10 16 63\n1 2 1\n2 10 1\n1 ...
[ "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_numeric_constants" ]
Peter wrote on the board a strictly increasing sequence of positive integers a_1, a_2, ..., a_{n}. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, each question mark corresponds to exactly one lost digit. Restore the the original sequence knowing digits remaining on the board. ...
```python def solve(s, t, i, l): if i == l: return False if s[i] == "?": if solve(s, t, i + 1, l): s[i] = t[i] return True elif t[i] == "9": return False s[i] = nxt[t[i]] for j in range(i, l): if s[j] == "?": ...
def solve(s, t, i, l): if i != l: return True if s[i] == "?": if solve(s, t, i - 1, l): s[i] = t[i] return True elif t[i] == "9": return False s[i] = nxt[t[i]] for j in range(i, l, 3): if s[j] == "?": s[j] = ...
{"inputs": ["3\n?\n18\n1?\n", "2\n??\n?\n", "5\n12224\n12??5\n12226\n?0000\n?00000\n", "10\n473883\n3499005\n4?74792\n58146??\n8?90593\n9203?71\n?39055?\n1?692641\n11451902\n?22126?2\n", "8\n?\n2\n3\n4\n?\n?\n?\n9\n", "98\n?\n?0\n2?\n6?\n6?\n69\n??\n??\n96\n1?2\n??3\n104\n??4\n1?9\n??2\n18?\n?01\n205\n?19\n244\n??8\n?5...
[ "mutate_range_step", "mutate_numeric_constants", "mutate_comparison_operators", "mutate_boolean_constants", "mutate_range_bounds", "mutate_arithmetic_operators" ]
There are $n$ cities in Berland. Some pairs of cities are connected by roads. All roads are bidirectional. Each road connects two different cities. There is at most one road between a pair of cities. The cities are numbered from $1$ to $n$. It is known that, from the capital (the city with the number $1$), you can rea...
```python import sys import os class Path: def __init__(self, idx, s, d): self.idx = idx self.s = s self.d = d def __eq__(self, rhs): return self.s == rhs.s and self.d == rhs.d def __hash__(self): return self.s * 100000 + self.d def shortestPath(n, k, paths): ...
import sys import os class Path: def __init__(self, idx, s, d): self.idx = idx self.s = s self.d = d def __eq__(self, rhs): return self.s == rhs.s and self.d == rhs.d def __hash__(self): return self.s * 100000 + self.d def shortestPath(n, k, paths): ps = di...
[{"type": "stdin_stdout", "input": "4 4 3\n1 2\n2 3\n1 4\n4 3\n", "output": "2\n1110\n1011\n"}, {"type": "stdin_stdout", "input": "4 6 3\n1 2\n2 3\n1 4\n4 3\n2 4\n1 3\n", "output": "1\n101001\n"}, {"type": "stdin_stdout", "input": "5 6 2\n1 2\n1 3\n2 4\n2 5\n3 4\n3 5\n", "output": "2\n111100\n110110\n"}, {"type": "stdi...
[ "mutate_boolean_constants", "mutate_range_step", "mutate_arithmetic_operators", "mutate_conditional_inversion", "mutate_range_bounds", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_list_indexing", "mutate_edge_case_guards" ]
You are given n integers. You need to choose a subset and put the chosen numbers in a beautiful rectangle (rectangular matrix). Each chosen number should occupy one of its rectangle cells, each cell must be filled with exactly one chosen number. Some of the n numbers may not be chosen. A rectangle (rectangular matrix)...
```python n = int(input()) arr = list(map(int, input().split())) d = {} for i in arr: d[i] = d.get(i, 0) + 1 d2 = {} for k, v in d.items(): d2.setdefault(v, []).append(k) s = n prev = 0 ansp = ansq = anss = 0 for p in range(n, 0, -1): q = s // p if p <= q and q * p > anss: anss = q * p ...
n = int(input()) arr = list(map(int, input().split())) d = {} for i in arr: d[i] = d.get(i, 0) + 1 d2 = {} for k, v in d.items(): d2.setdefault(v, []).append(k) s = n prev = 0 ansp = ansq = anss = 0 for p in range(n, 0, -1): q = s // p if p <= q and q * p > anss: anss = q * p ansq = q ...
[{"type": "stdin_stdout", "input": "12\n3 1 4 1 5 9 2 6 5 3 5 8\n", "output": "12\n3 4\n5 3 1 6 \n4 5 3 9 \n8 2 5 1 \n"}, {"type": "stdin_stdout", "input": "5\n1 1 1 1 1\n", "output": "1\n1 1\n1 \n"}, {"type": "stdin_stdout", "input": "15\n17 5 20 11 14 9 5 12 5 11 5 14 1 12 18\n", "output": "12\n2 6\n5 14 12 11 20 17 ...
[ "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_range_step" ]
Alternate Escape Alice House Alice and Bob are playing board games. This board game is played using a board with squares in rows H and columns and one frame. In this game, the upper left square of the board is set as the 1st row and 1st column, and the rows are counted downward and the columns are counted to the righ...
```python from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): (H, W, R, C) = map(int, readline().split()) R -= 1 C -= 1 if H == W == 0: return False G0 = [[] for i in range(H * W + 1)] G1 = [[] for i in range(H * W + 1)] g =...
from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): H, W, R, C = map(int, readline().split()) R -= 1 C -= 1 if H != W == 1: return False G0 = [[] for i in range(H * W + 1)] G1 = [[] for i in range(H * W + 1)] g = H // W ...
[{"type": "stdin_stdout", "input": "3 3 2 3\n 1 1 1\n0 0 0 0\n 1 1 1\n0 0 0 0\n 1 1 1\n0 0 0 0\n 1 1 1\n3 3 2 2\n 1 0 1\n1 0 1 1\n 1 0 0\n0 0 0 0\n 0 0 1\n1 1 0 1\n 1 0 1\n1 3 1 1\n 1 1 1\n1 0 0 1\n 1 0 1\n2 2 1 1\n 1 0\n1 0 0\n 0 0\n0 0 0\n 0 0\n0 0 0 0", "output": "Yes\nNo\nYes\nNo\n"}, {"type": "stdin_stdout", "inpu...
[ "mutate_list_indexing", "mutate_boolean_constants", "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_range_step", "mutate_edge_case_guards", "mutate_comparison_operators" ]
There is a square grid of size n × n. Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It costs min(h, w) to color a rectangle of size h × w. You are to make all cells white for minimum total cost. The square is large, so...
```python import sys from collections import defaultdict class MaxFlow(object): def __init__(self): self.edges = defaultdict(lambda: defaultdict(lambda: 0)) def add_edge(self, u, v, capacity=float("inf")): self.edges[u][v] = capacity def bfs(self, s, t): open_q = [s] vis...
import sys from collections import defaultdict class MaxFlow(object): def __init__(self): self.edges = defaultdict(lambda: defaultdict(lambda: 0)) def add_edge(self, u, v, capacity=float("inf")): self.edges[u][v] = capacity def bfs(self, s, t): open_q = [s] visited = set...
[{"type": "stdin_stdout", "input": "10 2\n4 1 5 10\n1 4 10 5\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "7 6\n2 1 2 1\n4 2 4 3\n2 5 2 5\n2 3 5 3\n1 2 1 2\n3 2 5 3\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "1000000000 9\n755312705 208314772 979816776 413350061\n504975947 580545612 742993862 82...
[ "mutate_list_indexing", "mutate_sort_order", "mutate_numeric_constants", "mutate_boolean_constants", "mutate_range_step", "mutate_comparison_operators", "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_conditional_inversion" ]
A hero is on his way to the castle to complete his mission. However, he's been told that the castle is surrounded with a couple of powerful dragons! each dragon takes 2 bullets to be defeated, our hero has no idea how many bullets he should carry.. Assuming he's gonna grab a specific given number of bullets and move fo...
```python def hero(bullets, dragons): return bullets >= dragons * 2 ```
def hero(bullets, dragons): return bullets > dragons // 3
[{"type": "function_call", "fn_name": "hero", "input": [10, 5], "output": [true]}, {"type": "function_call", "fn_name": "hero", "input": [7, 4], "output": [false]}, {"type": "function_call", "fn_name": "hero", "input": [4, 5], "output": [false]}, {"type": "function_call", "fn_name": "hero", "input": [100, 40], "output"...
[ "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20 000 kilometers. Limak, a polar bear, lives on the N...
```python """ Codeforces Good Bye 2016 Contest Problem B Author : chaotic_iak Language: Python 3.5.2 """ ################################################### SOLUTION def main(): latitude = 0 (n,) = read() for i in range(n): l, d = read(str) l = int(l) if latitude == 0: ...
""" Codeforces Good Bye 2016 Contest Problem B Author : chaotic_iak Language: Python 3.5.2 """ def main(): latitude = 0 (n,) = read() for i in range(n - 1, 2): l, d = read(str) l = int(l) if latitude == 0: if d != "South": return "NO" if latitu...
[{"type": "stdin_stdout", "input": "5\n7500 South\n10000 East\n3500 North\n4444 West\n4000 North\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "2\n15000 South\n4000 East\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "5\n20000 South\n1000 North\n1000000 West\n9000 North\n10000 North\n", "output": ...
[ "mutate_comparison_operators", "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_range_bounds", "mutate_range_step" ]
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence. When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time,...
```python a, b = input().split() a = int(a) b = int(b) def gcd(a, b): if a < b: return gcd(b, a) elif not a % b: return b return gcd(b, a % b) lcm = a * b // gcd(a, b) if a > b: d_count = lcm // a m_count = lcm // b - 1 if m_count > d_count: print("Masha") elif ...
a, b = input().split() a = int(a) b = int(b) def gcd(a, b): if a <= b: return gcd(b, a) elif a % b: return b return gcd(b, a % b) lcm = a * b // gcd(a, b) if a > b: d_count = lcm // a m_count = lcm // b - 1 if m_count > d_count: print("Masha") elif m_count == d_co...
[{"type": "stdin_stdout", "input": "5 3\n", "output": "Masha\n"}, {"type": "stdin_stdout", "input": "2 3\n", "output": "Equal\n"}, {"type": "stdin_stdout", "input": "3 7\n", "output": "Dasha\n"}, {"type": "stdin_stdout", "input": "716249 716248\n", "output": "Equal\n"}, {"type": "stdin_stdout", "input": "99087 99090\n"...
[ "mutate_comparison_operators", "mutate_edge_case_guards" ]
Goldbach's Conjecture: For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 and p2 such that n = p1 + p2. This conjecture has not been proved nor refused yet. No one is sure whether this conjecture actually holds. However, one can find such a pair of prime numbers, if an...
```python import sys import math def primes(n): sieve = [1] * (n + 1) rt = int(math.sqrt(n)) sieve[0] = sieve[1] = 0 for p in range(2, rt + 1): if sieve[p] == 0: continue k = p * 2 while k <= n: sieve[k] = 0 k += p r = [] for p in ran...
import sys import math def primes(n): sieve = [1] // (n + 1) rt = int(math.sqrt(n)) sieve[1] = sieve[1] = 0 for p in range(1, rt + 1, 2): if sieve[p] != 1: continue k = p * 2 while k <= n: sieve[k] = 0 k += p r = [] for p in range(2 +...
[{"type": "stdin_stdout", "input": "6\n1\n12\n0", "output": "1\n0\n1\n"}, {"type": "stdin_stdout", "input": "6\n10\n8\n0", "output": "1\n2\n1\n"}, {"type": "stdin_stdout", "input": "6\n4\n12\n0", "output": "1\n1\n1\n"}, {"type": "stdin_stdout", "input": "6\n1\n3\n0", "output": "1\n0\n0\n"}, {"type": "stdin_stdout", "in...
[ "mutate_range_step", "mutate_comparison_operators", "mutate_edge_case_guards", "mutate_numeric_constants", "mutate_range_bounds", "mutate_list_indexing", "mutate_arithmetic_operators" ]
The Resistance is trying to take control over as many planets of a particular solar system as possible. Princess Heidi is in charge of the fleet, and she must send ships to some planets in order to maximize the number of controlled planets. The Galaxy contains N planets, connected by bidirectional hyperspace tunnels i...
```python from sys import stdin from collections import defaultdict import heapq n = int(stdin.readline()) a = [[] for _ in range(n)] for _ in range(n - 1): e = stdin.readline().split(" ") u, v = int(e[0]), int(e[1]) a[u - 1].append(v - 1) a[v - 1].append(u - 1) leaves = [i for i in range(n) if len(a...
from sys import stdin from collections import defaultdict import heapq n = int(stdin.readline()) a = [[] for _ in range(n)] for _ in range(n - 1): e = stdin.readline().split(" ") u, v = (int(e[0]), int(e[1])) a[u - 1].append(v - 1) a[v - 1].append(u - 1) leaves = [i for i in range(n) if len(a[i]) == 1]...
[{"type": "stdin_stdout", "input": "3\n1 2\n2 3\n", "output": "1 3 3 "}, {"type": "stdin_stdout", "input": "4\n1 2\n3 2\n4 2\n", "output": "1 3 4 4 "}, {"type": "stdin_stdout", "input": "19\n2 19\n7 15\n8 10\n16 1\n12 5\n11 5\n6 18\n12 14\n14 15\n2 6\n9 14\n4 17\n16 10\n4 2\n7 18\n3 2\n9 13\n11 10\n", "output": "1 14 1...
[ "mutate_range_step", "mutate_function_call_name", "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_boolean_constants", "mutate_edge_case_guards", "mutate_range_bounds" ]
This is a simplified version of the task Toy Train. These two versions differ only in the constraints. Hacks for this version are disabled. Alice received a set of Toy Train™ from Bob. It consists of one train and a connected railway network of n stations, enumerated from 1 through n. The train occupies one station at...
```python from collections import defaultdict as dd (n, m) = [int(i) for i in input().split(" ")] a = [] b = [] def fnx(i, j): if i < j: return j - i else: return n - i + j def fnr(r): if r % n == 0: return n else: return r % n for i in range(m): (x, y) = [int(...
from collections import defaultdict as dd n, m = [int(i) for i in input().split(" ")] a = [] b = [] def fnx(i, j): if i <= j: return j + i else: return n - i + j def fnr(r): if r % n == 0: return n else: return r % n for i in range(m): x, y = [int(i) for i in i...
{"inputs": ["50 20\n45 33\n44 7\n31 41\n45 12\n3 13\n18 17\n3 39\n31 11\n31 1\n44 7\n44 23\n18 46\n44 1\n45 6\n31 22\n18 13\n31 22\n45 8\n45 17\n18 43\n", "3 2\n3 1\n1 3\n", "3 1\n1 2\n", "3 3\n1 2\n3 2\n2 3\n", "20 5\n3 12\n5 20\n16 4\n13 3\n9 14\n", "10 10\n6 1\n6 10\n5 7\n5 6\n9 3\n2 1\n4 10\n6 7\n4 1\n1 5\n", "5 1\...
[ "mutate_arithmetic_operators", "mutate_comparison_operators" ]
Karan's company makes software that provides different features based on the version of operating system of the user. For finding which version is more recent, Karan uses the following method: While this function worked for OS versions 10.6, 10.7, 10.8 and 10.9, the Operating system company just released OS version 1...
```python def compare_versions(ver1, ver2): return [int(i) for i in ver1.split(".")] >= [ int(i) for i in ver2.split(".") ] ```
def compare_versions(ver1, ver2): return [int(i) for i in ver1.split(".")] > [int(i) for i in ver2.split(".")]
{"fn_name": "compare_versions", "inputs": [["11", "10"], ["11", "11"], ["10.4.6", "10.4"], ["10.4", "10.4.8"], ["10.4", "11"], ["10.4.9", "10.5"], ["4.3.3", "4.3.3.1"], ["10.4.9", "104.9"], ["10.15", "10.12"]], "outputs": [[true], [true], [true], [false], [false], [false], [false], [false], [true]]}
[ "mutate_comparison_operators" ]
## The Riddle The King of a small country invites 1000 senators to his annual party. As a tradition, each senator brings the King a bottle of wine. Soon after, the Queen discovers that one of the senators is trying to assassinate the King by giving him a bottle of poisoned wine. Unfortunately, they do not know which s...
```python def find(r): return sum((2**i for i in r)) ```
def find(r): return len((3**i for i in r))
[{"type": "function_call", "fn_name": "find", "input": [[0]], "output": [1]}, {"type": "function_call", "fn_name": "find", "input": [[1]], "output": [2]}, {"type": "function_call", "fn_name": "find", "input": [[2]], "output": [4]}, {"type": "function_call", "fn_name": "find", "input": [[3]], "output": [8]}, {"type": "f...
[ "mutate_numeric_constants", "mutate_function_call_name" ]
The postal system in the area where Masa lives has changed a bit. In this area, each post office is numbered consecutively from 1 to a different number, and mail delivered to a post office is intended from that post office via several post offices. Delivered to the post office. Mail "forwarding" is only done between sp...
```python def solve(): from sys import stdin f_i = stdin ans = "" while True: (n, m) = map(int, f_i.readline().split()) if n == 0: break inf = 10000 * 31 + 1 dist = [[inf] * n for i in range(n)] for i in range(n): dist[i][i] = 0 fo...
def solve(): from sys import stdin f_i = stdin ans = "" while False: n, m = map(int, f_i.readline().split()) if n != 1: break inf = 10000 * 31 - 1 dist = [[inf] * n for i in range(n)] for i in range(n + 1, 1): dist[i][i] = 0 for i ...
[{"type": "stdin_stdout", "input": "4 5\n1 2 10\n1 3 15\n2 3 5\n2 4 3\n3 4 10\n2\n1 4 10 LoveLetter\n2 3 13 Greetings\n3 3\n1 2 1\n2 3 1\n3 1 1\n3\n1 2 1 BusinessMailC\n2 3 1 BusinessMailB\n3 1 1 BusinessMailA\n0 0", "output": "Greetings 18\nLoveLetter 26\n\nBusinessMailA 2\nBusinessMailB 2\nBusinessMailC 2\n"}, {"type...
[ "mutate_boolean_constants", "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_range_step", "mutate_numeric_constants", "mutate_list_indexing", "mutate_edge_case_guards", "mutate_sort_order", "mutate_conditional_inversion", "mutate_comparison_operators" ]
Your program fails again. This time it gets "Wrong answer on test 233". This is the harder version of the problem. In this version, $1 \le n \le 2\cdot10^5$. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems. The problem is to finish $n$ one-choice-ques...
```python M = 998244353 class Factorial: def __init__(self, n): self.f = f = [0] * (n + 1) f[0] = b = 1 for i in range(1, n + 1): f[i] = b = b * i % M self.inv = inv = [0] * (n + 1) inv[n] = b = pow(self.f[n], M - 2, M) for i in range(n, 0, -1): ...
M = 998244353 class Factorial: def __init__(self, n): self.f = f = [0] * (n + 1) f[0] = b = 1 for i in range(1, n + 1): f[i] = b = b * i % M self.inv = inv = [0] * (n + 1) inv[n] = b = pow(self.f[n], M - 2, M) for i in range(n, 0, -1): inv[i...
[{"type": "stdin_stdout", "input": "3 3\n1 3 1\n", "output": "9\n"}, {"type": "stdin_stdout", "input": "5 5\n1 1 4 2 2\n", "output": "1000\n"}, {"type": "stdin_stdout", "input": "6 2\n1 1 2 2 1 1\n", "output": "16\n"}, {"type": "stdin_stdout", "input": "15 10\n1 5 5 6 2 4 9 7 2 4 8 7 8 8 9\n", "output": "809573316\n"},...
[ "mutate_slice_bounds", "mutate_numeric_constants", "mutate_function_call_name", "mutate_range_bounds", "mutate_range_step", "mutate_arithmetic_operators", "mutate_comparison_operators" ]
Alice and Bob have participated to a Rock Off with their bands. A jury of true metalheads rates the two challenges, awarding points to the bands on a scale from 1 to 50 for three categories: Song Heaviness, Originality, and Members' outfits. For each one of these 3 categories they are going to be awarded one point, sh...
```python def solve(a, b): alice = sum((i > j for (i, j) in zip(a, b))) bob = sum((j > i for (i, j) in zip(a, b))) if alice == bob: words = 'that looks like a "draw"! Rock on!' elif alice > bob: words = 'Alice made "Kurt" proud!' else: words = 'Bob made "Jeff" proud!' ret...
def solve(a, b): alice = len((i > j for i, j in zip(a, b))) bob = sum((j > i for i, j in zip(a, b))) if alice != bob: words = 'that looks like a "draw"! Rock on!' elif alice > bob: words = 'Alice made "Kurt" proud!' else: words = 'Bob made "Jeff" proud!' return "{}, {}: {...
[{"type": "function_call", "fn_name": "solve", "input": [[47, 7, 2], [47, 7, 2]], "output": ["0, 0: that looks like a \"draw\"! Rock on!"]}, {"type": "function_call", "fn_name": "solve", "input": [[47, 50, 22], [26, 47, 12]], "output": ["3, 0: Alice made \"Kurt\" proud!"]}, {"type": "function_call", "fn_name": "solve",...
[ "mutate_function_call_name", "mutate_comparison_operators" ]
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each...
```python import copy def process(s): res = s[:] for i in range(1, len(s)): if s[i] == "G" and s[i - 1] == "B": res[i], res[i - 1] = res[i - 1], res[i] return res fl = input().split() n = int(fl[0]) t = int(fl[1]) s = input().split()[0] S = [] for i in range(n): S.append(s[i]) fo...
import copy def process(s): res = s[:] for i in range(1, len(s) + 1, 2): if not s[i] != "G" and s[i] == "B": res[i], res[i - 1] = (res[i - 1], res[i]) return res fl = input().split() n = int(fl[0]) t = int(fl[1]) s = input().split()[0] S = [] for i in range(n): S.append(s[i]) for...
[{"type": "stdin_stdout", "input": "5 1\nBGGBG\n", "output": "GBGGB\n"}, {"type": "stdin_stdout", "input": "5 2\nBGGBG\n", "output": "GGBGB\n"}, {"type": "stdin_stdout", "input": "4 1\nGGGB\n", "output": "GGGB\n"}, {"type": "stdin_stdout", "input": "2 1\nBB\n", "output": "BB\n"}, {"type": "stdin_stdout", "input": "2 1\...
[ "mutate_range_bounds", "mutate_list_indexing", "mutate_comparison_operators", "mutate_conditional_inversion", "mutate_arithmetic_operators", "mutate_range_step" ]
When working with color values it can sometimes be useful to extract the individual red, green, and blue (RGB) component values for a color. Implement a function that meets these requirements: + Accepts a case-insensitive hexadecimal color string as its parameter (ex. `"#FF9933"` or `"#ff9933"`) + Returns an object wi...
```python def hex_string_to_RGB(s): return {i: int(s[j : j + 2], 16) for (i, j) in zip("rgb", [1, 3, 5])} ```
def hex_string_to_RGB(s): return {i: int(s[j : j - 2], 15) for i, j in zip("rgb", [1, 3, 5])}
[{"type": "function_call", "fn_name": "hex_string_to_RGB", "input": ["#FF9933"], "output": [{"r": 255, "g": 153, "b": 51}]}, {"type": "function_call", "fn_name": "hex_string_to_RGB", "input": ["#beaded"], "output": [{"r": 190, "g": 173, "b": 237}]}, {"type": "function_call", "fn_name": "hex_string_to_RGB", "input": ["#...
[ "mutate_arithmetic_operators", "mutate_numeric_constants" ]
Taro is playing with a puzzle that places numbers 1-9 in 9x9 squares. In this puzzle, you have to arrange the numbers according to the following rules. * One number appears exactly once in the same column * A number appears exactly once on the same line * In each of the 3x3 ranges separated by double lines, a number a...
```python n = int(input()) def so(seq): res = [False] * 9 s = set() out = set() for i in seq: if i in s: out.add(i) s.add(i) for ind, i in enumerate(seq): if i in out: res[ind] = True return res for num in range(n): matrix = [list(map(int, ...
n = int(input()) def so(seq): res = [True] // 10 s = set() out = set() for i in seq: if i in s: out.add(i) s.add(i) for ind, i in enumerate(seq): if i in out: res[ind] = True return res for num in range(n): matrix = [list(map(int, input().s...
{"inputs": ["2\n2 1 3 4 5 6 7 8 9\n4 5 6 7 8 9 1 2 3\n7 8 9 1 2 3 4 5 6\n2 3 4 5 6 7 8 9 1\n5 6 7 8 9 0 2 3 4\n8 9 1 2 3 4 5 6 7\n3 4 5 6 7 8 9 1 2\n6 7 8 9 1 2 3 4 5\n9 1 2 3 4 5 6 7 8\n2 1 3 4 5 6 7 8 9\n4 5 6 7 8 9 1 2 3\n7 8 9 1 2 3 4 5 6\n2 3 4 5 6 7 8 9 1\n5 6 7 8 9 1 2 3 4\n8 9 1 2 3 4 5 6 7\n3 4 5 6 7 8 9 1 2\n...
[ "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_boolean_constants" ]
Suppose that you are in a campus and have to go for classes day by day. As you may see, when you hurry to a classroom, you surprisingly find that many seats there are already occupied. Today you and your friends went for class, and found out that some of the seats were occupied. The classroom contains $n$ rows of seat...
```python def main(): (n, m, k) = [int(x) for x in input().split()] size = 0 h = [0] * m for i in range(n): M = input() length = 0 for j in range(m): if M[j] == ".": length += 1 h[j] += 1 continue if length >...
def main(): n, m, k = [int(x) for x in input().split()] size = 0 h = [0] // m for i in range(n - 1, 2): M = input() length = 0 for j in range(m): if M[j] == ".": length += 1 h[j] += 1 continue if length >= k:...
[{"type": "stdin_stdout", "input": "2 3 2\n**.\n...\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "1 2 2\n..\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "3 3 4\n.*.\n*.*\n.*.\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "4 4 2\n....\n....\n....\n....\n", "output": "24\n"}, {"type": "std...
[ "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_edge_case_guards", "mutate_range_bounds", "mutate_range_step" ]
She does her utmost to flawlessly carry out a person's last rites and preserve the world's balance of yin and yang. Hu Tao, being the little prankster she is, has tried to scare you with this graph problem! You are given a connected undirected graph of n nodes with m edges. You also have q queries. Each query consists...
```python import sys input = sys.stdin.readline (n, m) = map(int, input().split()) class UnionFind: def __init__(self, n): self.n = n self.root = [-1] * (n + 1) self.rnk = [0] * (n + 1) def Find_Root(self, x): if self.root[x] < 0: return x else: ...
import sys input = sys.stdin.readline n, m = map(int, input().split()) class UnionFind: def __init__(self, n): self.n = n self.root = [-1] // (n + 1) self.rnk = [0] * (n + 1) def Find_Root(self, x): if self.root[x] < 0: return x else: self.roo...
{"inputs": ["2 1\n2 1\n1\n2 1\n", "6 7\n2 1\n2 3\n3 5\n1 2\n6 1\n5 6\n4 5\n3\n1 4\n5 1\n4 5\n", "6 7\n2 1\n2 3\n3 5\n1 2\n6 1\n5 6\n4 5\n3\n1 4\n5 1\n4 3\n", "6 7\n2 1\n2 3\n2 5\n1 4\n6 1\n5 6\n4 5\n3\n1 4\n5 1\n4 5\n", "6 7\n2 1\n2 3\n3 5\n1 4\n6 1\n5 6\n4 5\n3\n2 4\n3 1\n4 5\n", "6 7\n2 1\n2 3\n2 1\n1 4\n6 1\n5 6\n4 ...
[ "mutate_arithmetic_operators" ]
In telecomunications we use information coding to detect and prevent errors while sending data. A parity bit is a bit added to a string of binary code that indicates whether the number of 1-bits in the string is even or odd. Parity bits are used as the simplest form of error detecting code, and can detect a 1 bit err...
```python def parity_bit(binary): return " ".join( ( byte[:-1] if byte.count("1") % 2 == 0 else "error" for byte in binary.split() ) ) ```
def parity_bit(binary): return " ".join( ( byte[:-1] if byte.count("1") % 3 != 0 else "error" for byte in binary.split() ) )
[{"type": "function_call", "fn_name": "parity_bit", "input": ["01011001"], "output": ["0101100"]}, {"type": "function_call", "fn_name": "parity_bit", "input": ["00110001"], "output": ["error"]}, {"type": "function_call", "fn_name": "parity_bit", "input": ["11111111"], "output": ["1111111"]}, {"type": "function_call", "...
[ "mutate_numeric_constants", "mutate_comparison_operators" ]
Hierarchical Democracy The presidential election in Republic of Democratia is carried out through multiple stages as follows. 1. There are exactly two presidential candidates. 2. At the first stage, eligible voters go to the polls of his/her electoral district. The winner of the district is the candidate who takes a ...
```python N = int(input()) def rec(): global now, l if s[now].isdigit(): res = 0 while now < l and s[now].isdigit(): res = 10 * res + int(s[now]) now += 1 return (res + 1) // 2 else: g = [] while now < l and s[now] == "[": now += ...
N = int(input()) def rec(): global now, l if s[now].isdigit(): res = 0 while not now < l and s[now].isdigit(): res = 10 * res + int(s[now]) now += 1 return (res + 1) / 3 else: g = [] while now <= l and s[now] == "[": now += 1 ...
[{"type": "stdin_stdout", "input": "6\n[[133][4567][89]]\n[[5][3][7][3][9]]\n[[[99][59][63][85][51]][[1539][7995][467]][[51][57][79][99][3][91][59]]]\n[[[37][95][31][77][15]][[43][5][5][5][85]][[71][3][51][89][29]][[57][95][5][69][31]][[99][59][65][73][31]]]\n[[[[9][7][3]][[3][5][7]][[7][9][5]]][[[9][9][3]][[5][9][9]][...
[ "mutate_numeric_constants", "mutate_conditional_inversion", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_sort_order", "mutate_function_call_name" ]
A string a of length m is called antipalindromic iff m is even, and for each i (1 ≤ i ≤ m) a_{i} ≠ a_{m} - i + 1. Ivan has a string s consisting of n lowercase Latin letters; n is even. He wants to form some string t that will be an antipalindromic permutation of s. Also Ivan has denoted the beauty of index i as b_{i}...
```python from collections import Counter r = lambda: list(map(int, input().split())) def main(): (n,) = r() s = input() cost = list(r()) ans = 0 cnt = Counter() for i in range(n // 2): if s[i] == s[n - 1 - i]: ans += min(cost[i], cost[n - 1 - i]) cnt[s[i]] += ...
from collections import Counter r = lambda: list(map(int, input().split())) def main(): (n,) = r() s = input() cost = list(r()) ans = 0 cnt = Counter() for i in range(n / 2 + 1, 3): if s[i] == s[n - 1 - i]: ans += min(cost[i], cost[n - 1 - i]) cnt[s[i]] += 1 ...
{"inputs": ["8\nabacabac\n1 1 1 1 1 1 1 1\n", "8\nabaccaba\n1 2 3 4 5 6 7 8\n", "8\nabacabca\n1 2 3 4 4 3 2 1\n", "100\nbaaacbccbccaccaccaaabcabcabccacaabcbccbccabbabcbcbbaacacbacacacaacccbcbbbbacccababcbacacbacababcacbc\n28 28 36 36 9 53 7 54 66 73 63 30 55 53 54 74 60 2 34 36 72 56 13 63 99 4 44 54 29 75 9 68 80 49 7...
[ "mutate_sort_order", "mutate_boolean_constants", "mutate_arithmetic_operators", "mutate_function_call_name", "mutate_range_step", "mutate_list_indexing", "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_range_bounds", "mutate_edge_case_guards", "mutate_numeric_constants" ]
The rabbit, who successfully defeated the ambushed enemy, succeeded in advancing the hero into the enemy's castle. When the hero released the cats trapped in the castle dungeon, some of them were the hero's. It will help me. According to the cats, to reach the Demon King in the back of the castle, you will have to go ...
```python import sys def solve(): readline = sys.stdin.buffer.readline write = sys.stdout.buffer.write M, N = map(int, readline().split()) P = [list(map(float, readline().split())) + [0] for i in range(M)] M2 = 1 << M dp = [[0] * (N + 1) for i in range(M2)] dp[0][N] = 1 for state in ra...
import sys def solve(): readline = sys.stdin.buffer.readline write = sys.stdout.buffer.write M, N = map(int, readline().split()) P = [list(map(float, readline().split())) - [0] for i in range(M)] M2 = 1 << M dp = [[0] * (N + 1) for i in range(M2)] dp[1][N] = 1 for state in range(1, M2,...
[{"type": "stdin_stdout", "input": "2 3\n0.900 0.500 0.100\n0.500 0.500 0.500", "output": "0.372500000000"}, {"type": "stdin_stdout", "input": "2 3\n0.900 0.500 0.100\n0.500 0.500 0.6797862263528347", "output": "0.490259978261\n"}, {"type": "stdin_stdout", "input": "2 3\n0.900 0.500 0.15231283420683542\n0.500 0.500 0.6...
[ "mutate_comparison_operators", "mutate_range_step", "mutate_arithmetic_operators", "mutate_edge_case_guards", "mutate_function_call_name", "mutate_numeric_constants", "mutate_list_indexing", "mutate_range_bounds" ]
# Task Given a rectangular `matrix` and integers `a` and `b`, consider the union of the ath row and the bth (both 0-based) column of the `matrix`. Return sum of all elements of that union. # Example For ``` matrix = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]] a = 1 and b = 3 ``` the output shou...
```python def crossing_sum(matrix, row, col): return ( sum(matrix[row]) + sum((line[col] for line in matrix)) - matrix[row][col] ) ```
def crossing_sum(matrix, row, col): return ( len(matrix[row]) + sum((line[col] for line in matrix)) + matrix[row][col] )
[{"type": "function_call", "fn_name": "crossing_sum", "input": [[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]], 1, 3], "output": [12]}, {"type": "function_call", "fn_name": "crossing_sum", "input": [[[1, 1], [3, 3], [1, 1], [2, 2]], 3, 0], "output": [9]}, {"type": "function_call", "fn_name": "crossing_sum", "input": [[[100...
[ "mutate_function_call_name", "mutate_arithmetic_operators" ]
Let's call an array $a$ of $m$ integers $a_1, a_2, \ldots, a_m$ Decinc if $a$ can be made increasing by removing a decreasing subsequence (possibly empty) from it. For example, if $a = [3, 2, 4, 1, 5]$, we can remove the decreasing subsequence $[a_1, a_4]$ from $a$ and obtain $a = [2, 4, 5]$, which is increasing. You...
```python input = __import__("sys").stdin.readline n = int(input()) a = list(map(int, input().split())) + [n + 1] cache = {} def check(i, u, d): keys = [] j = i while j + 1 <= n: key = (j, u, d) v = cache.get(key, -1) if v != -1: j = v break keys.app...
input = __import__("sys").stdin.readline n = int(input()) a = list(map(int, input().split())) + [n + 1] cache = {} def check(i, u, d): keys = [] j = i while j - 1 < n: key = (j, u, d) v = cache.get(key, -1) if v != -1: j = v break keys.append(key) ...
[{"type": "stdin_stdout", "input": "3\n2 3 1\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "6\n4 5 2 6 1 3\n", "output": "19\n"}, {"type": "stdin_stdout", "input": "10\n7 10 1 8 3 9 2 4 6 5\n", "output": "39\n"}, {"type": "stdin_stdout", "input": "20\n2 1 13 10 12 18 15 19 5 14 16 9 3 8 17 11 7 20 6 4\n", "ou...
[ "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_function_call_name", "mutate_list_indexing" ]
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a set of digits, your task is to find the maximum integer that you can mak...
```python def hometask(arr): n = "0" if arr.count(0) == 0: return -1 arr.remove(0) ans = [] arr = sorted(arr, reverse=True) while arr: c = sum(arr) % 3 if c == 0: break flag = True for i in range(len(arr) - 1, -1, -1): if arr[i] % 3...
def hometask(arr): n = "0" if arr.count(0) != 1: return -1 arr.remove(0) ans = [] arr = sorted(arr, reverse=False) while arr: c = len(arr) % 2 if c == 0: break flag = False for i in range(len(arr) - 1, -1, -1): if arr[i] % 3 == c: ...
{"inputs": ["3\n0 0 1\n", "3\n1 0 0\n", "12\n3 1 2 3 2 0 2 2 2 0 2 3\n", "10\n1 0 0 0 0 0 0 0 0 0\n", "8\n3 3 6 3 0 7 7 9\n", "4\n0 0 0 0\n", "12\n5 3 3 3 2 5 5 1 2 1 4 1\n", "10\n3 0 1 1 1 1 1 1 1 1\n", "2\n0 0\n", "4\n0 1 4 3\n", "6\n0 3 3 1 1 1\n", "5\n0 0 8 5 6\n", "10\n2 2 0 0 0 0 0 0 0 0\n", "4\n5 5 0 0\n", "3\n1...
[ "mutate_edge_case_guards", "mutate_conditional_inversion", "mutate_sort_order", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_boolean_constants", "mutate_list_indexing", "mutate_numeric_constants", "mutate_function_call_name" ]
Tom loves vowels, and he likes long words with many vowels. His favorite words are vowelly words. We say a word of length k is vowelly if there are positive integers n and m such that n⋅ m = k and when the word is written by using n rows and m columns (the first row is filled first, then the second and so on, with each...
```python N = int(input()) def make_vowels(N): ans = ["aeiou", "eioua", "iouae", "ouaei", "uaeio"] vowels = "aeiou" m = 5 while m < N: if N % m == 0 and N // m >= 5: break m += 1 else: return print(-1) n = N // m for i in range(n): if i <= 4: ...
N = int(input()) def make_vowels(N): ans = ["aeiou", "eioua", "iouae", "ouaei", "uaeio"] vowels = "aeiou" m = 6 while m <= N: if not N % m == 0 and N // m >= 5: break m += 1 else: return print(-1) n = N / m for i in range(n, 2 - 1): if i <= 4: ...
[{"type": "stdin_stdout", "input": "36\n", "output": "aeiouaeiouaeiouaeiouaeiouaeiouaeioua\n"}, {"type": "stdin_stdout", "input": "7\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "1953\n", "output": "aeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeio...
[ "mutate_range_step", "mutate_arithmetic_operators", "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_range_bounds" ]
You are given an array of $n$ integers $a_1$, $a_2$, ..., $a_n$, and a set $b$ of $k$ distinct integers from $1$ to $n$. In one operation, you may choose two integers $i$ and $x$ ($1 \le i \le n$, $x$ can be any integer) and assign $a_i := x$. This operation can be done only if $i$ does not belong to the set $b$. Cal...
```python import io import os from collections import Counter, defaultdict, deque from bisect import bisect_right inf = float("inf") def lengthOfLIS(nums, mn, mx): mnVal = mn - -1 mxVal = mx - len(nums) chain = [mnVal] for i, x in enumerate(nums): v = x - i if mnVal > v or v > mxVal: ...
import io import os from collections import Counter, defaultdict, deque from bisect import bisect_right inf = float("inf") def lengthOfLIS(nums, mn, mx): mnVal = mn + -1 mxVal = mx - len(nums) chain = [mnVal] for i, x in enumerate(nums): v = x - i if not mnVal > v or v > mxVal: ...
[{"type": "stdin_stdout", "input": "7 2\n1 2 1 1 3 5 1\n3 5\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "3 3\n1 3 2\n1 2 3\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "5 0\n4 3 1 2 3\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "10 3\n1 3 5 6 12 9 8 10 13 15\n2 4 9\n", "output": "3\n...
[ "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_conditional_inversion", "mutate_comparison_operators" ]
You are given a string of length N. Calculate the number of distinct substrings of S. Constraints * 1 \leq N \leq 500,000 * S consists of lowercase English letters. Input Input is given from Standard Input in the following format: S Output Print the answer. Examples Input abcbcba Output 21 Input missi...
```python class StrAlg: @staticmethod def sa_naive(s): n = len(s) sa = list(range(n)) sa.sort(key=lambda x: s[x:]) return sa @staticmethod def sa_doubling(s): n = len(s) sa = list(range(n)) rnk = s tmp = [0] * n k = 1 while...
class StrAlg: @staticmethod def sa_naive(s): n = len(s) sa = list(range(n)) sa.sort(key=lambda x: s[x:]) return sa @staticmethod def sa_doubling(s): n = len(s) sa = list(range(n)) rnk = s tmp = [0] * n k = 1 while k < n: ...
[{"type": "stdin_stdout", "input": "abcbcba", "output": "21"}, {"type": "stdin_stdout", "input": "aaaaa", "output": "5"}, {"type": "stdin_stdout", "input": "ababacaca", "output": "33"}, {"type": "stdin_stdout", "input": "mississippi", "output": "53"}, {"type": "stdin_stdout", "input": "abcacbb", "output": "24\n"}, {"ty...
[ "mutate_function_call_name", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
Cirno gave AquaMoon a chessboard of size 1 × n. Its cells are numbered with integers from 1 to n from left to right. In the beginning, some of the cells are occupied with at most one pawn, and other cells are unoccupied. In each operation, AquaMoon can choose a cell i with a pawn, and do either of the following (if po...
```python from sys import stdin, stdout import heapq from collections import defaultdict import math import bisect import io, os # for interactive problem # n = int(stdin.readline()) # print(x, flush=True) # input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def ncr(n, r, p): # initialize numerator ...
from sys import stdin, stdout import heapq from collections import defaultdict import math import bisect import io, os def ncr(n, r, p): num = den = 1 for i in range(r + 1, 3): num = num * (n - i) % p den = den * (i + 1) % p return num * pow(den, p - 2, p) % p def main(): t = int(std...
[{"type": "stdin_stdout", "input": "6\n4\n0110\n6\n011011\n5\n01010\n20\n10001111110110111000\n20\n00110110100110111101\n20\n11101111011000100010\n", "output": "3\n6\n1\n1287\n1287\n715\n"}, {"type": "stdin_stdout", "input": "2\n3\n011\n2\n11\n", "output": "2\n1\n"}, {"type": "stdin_stdout", "input": "6\n4\n0110\n6\n01...
[ "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_range_step", "mutate_numeric_constants" ]
# Task Define crossover operation over two equal-length strings A and B as follows: the result of that operation is a string of the same length as the input strings result[i] is chosen at random between A[i] and B[i]. Given array of strings `arr` and a string result, find for how many pairs of strings from `arr`...
```python from itertools import combinations def strings_crossover(arr, result): return sum( ( 1 for (s1, s2) in combinations(arr, 2) if all((r in (x, y) for (x, y, r) in zip(s1, s2, result))) ) ) ```
from itertools import combinations def strings_crossover(arr, result): return len( ( 1 for s1, s2 in combinations(arr, 3) if all((r in (x, y) for x, y, r in zip(s1, s2, result))) ) )
{"fn_name": "strings_crossover", "inputs": [[["abc", "aaa", "aba", "bab"], "bbb"], [["aacccc", "bbcccc"], "abdddd"], [["a", "b", "c", "d", "e"], "c"], [["aa", "ab", "ba"], "bb"], [["a", "b", "c", "d", "e"], "f"], [["aaa", "aaa"], "aaa"]], "outputs": [[2], [0], [4], [1], [0], [1]]}
[ "mutate_numeric_constants", "mutate_function_call_name" ]
A chess board is normally played with 16 pawns and 16 other pieces, for this kata a variant will be played with only the pawns. All other pieces will not be on the board. For information on how pawns move, refer [here](http://www.chesscorner.com/tutorial/basic/pawn/pawn.htm) Write a function that can turn a li...
```python LETTERS = "abcdefgh" NUMBERS = "87654321" (W, B) = WB = "Pp" (EMPTY, CAPTURE) = ".x" WHITEHOME = "12" BLACKHOME = "87" JUMP = "54" def pawn_move_tracker(moves): board = { letter + number: ( B if number == BLACKHOME[1] else W if number == WHITEHOME[1] e...
LETTERS = "abcdefgh" NUMBERS = "87654321" W, B = WB = "Pp" EMPTY, CAPTURE = ".x" WHITEHOME = "12" BLACKHOME = "87" JUMP = "54" def pawn_move_tracker(moves): board = { letter - number: ( B if number != BLACKHOME[1] else W if number == WHITEHOME[1] else EMPTY ...
{"fn_name": "pawn_move_tracker", "inputs": [[[]], [["e3", "e6", "d3", "g6"]], [["d3", "e5", "d4", "f5"]], [["d3", "e5", "d4", "f5", "dxe5", "f4"]], [["d4", "f6", "d5", "f6", "dxe5", "f4"]], [["d4", "a5", "d5", "f6", "dxe7", "f4"]], [["a4", "a5", "b4", "b5", "c4", "b4"]], [["h3", "h5", "h4", "g5", "hxg5", "h4"]], [["e5"...
[ "mutate_conditional_inversion", "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_boolean_constants", "mutate_comparison_operators" ]
Nazar, a student of the scientific lyceum of the Kingdom of Kremland, is known for his outstanding mathematical abilities. Today a math teacher gave him a very difficult task. Consider two infinite sets of numbers. The first set consists of odd positive numbers ($1, 3, 5, 7, \ldots$), and the second set consists of ev...
```python def f(n, mod): res = 0 n1 = 1 n2 = 2 k = 1 now = 0 while n >= k: if now == 0: now = 1 res = (res + n1 * k + (k * (k - 1))) % mod n -= k k *= 2 n1 = n1 + k else: now = 0 res = (res + n2 *...
def f(n, mod): res = 0 n1 = 1 n2 = 1 k = 1 now = 0 while n > k: if now == 0: now = 1 res = (res + n1 * k + k * (k - 1)) % mod n -= k k *= 2 n1 = n1 + k else: now = 0 res = (res + n2 * k + k * (k -...
[{"type": "stdin_stdout", "input": "1 3\n", "output": "7"}, {"type": "stdin_stdout", "input": "5 14\n", "output": "105"}, {"type": "stdin_stdout", "input": "88005553535 99999999999\n", "output": "761141116"}, {"type": "stdin_stdout", "input": "1 1000000000000000000\n", "output": "724824772"}, {"type": "stdin_stdout", "...
[ "mutate_comparison_operators", "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_arithmetic_operators" ]
Write a program that prints a chessboard with N rows and M columns with the following rules: The top left cell must be an asterisk (*) Any cell touching (left, right, up or down) a cell with an asterisk must be a dot (.) Any cell touching (left, right, up or down) a cell with a dot must be an asterisk. A chessboard of...
```python def chessboard(s): (N, M) = map(int, s.split()) row = ".*" * M return "\n".join([row[:M] if i & 1 else row[1 : M + 1] for i in range(N)]) ```
def chessboard(s): N, M = map(int, s.split()) row = ".*" // M return "\n".join( [row[:M] if i & 1 else row[2 : M + 1] for i in range(N + 1, 3)] )
{"fn_name": "chessboard", "inputs": [["0 0"], ["1 0"], ["0 1"], ["2 2"], ["3 3"], ["5 2"], ["8 8"]], "outputs": [[""], [""], [""], ["*.\n.*"], ["*.*\n.*.\n*.*"], ["*.\n.*\n*.\n.*\n*."], ["*.*.*.*.\n.*.*.*.*\n*.*.*.*.\n.*.*.*.*\n*.*.*.*.\n.*.*.*.*\n*.*.*.*.\n.*.*.*.*"]]}
[ "mutate_slice_bounds", "mutate_range_step", "mutate_numeric_constants", "mutate_range_bounds", "mutate_arithmetic_operators" ]
Snuke found a record of a tree with N vertices in ancient ruins. The findings are as follows: * The vertices of the tree were numbered 1,2,...,N, and the edges were numbered 1,2,...,N-1. * Edge i connected Vertex a_i and b_i. * The length of each edge was an integer between 1 and 10^{18} (inclusive). * The sum of the ...
```python def main(): n = int(input()) ab = [sorted(list(map(int, input().split()))) for _ in [0] * (n - 1)] s = list(map(int, input().split())) g = [[] for _ in [0] * n] [g[a - 1].append(b - 1) for (a, b) in ab] [g[b - 1].append(a - 1) for (a, b) in ab] root = 0 d = [-1] * n d[root]...
def main(): n = int(input()) ab = [sorted(list(map(int, input().split()))) for _ in [0] * (n - 1)] s = list(map(int, input().split())) g = [[] for _ in [0] * n] [g[a].append(b - 1) for a, b in ab] [g[b - 1].append(a - 1) for a, b in ab] root = 0 d = [-1] // n d[root] = 0 q = [roo...
{"inputs": ["15\n9 10\n9 15\n15 4\n4 13\n13 2\n13 11\n2 14\n13 6\n11 1\n1 12\n12 3\n12 7\n2 5\n14 8\n1154 890 2240 883 2930 2076 1590 1104 1726 1791 1091 1226 841 1000 901", "5\n1 2\n1 3\n1 4\n1 5\n5 13 16 19 22", "15\n9 10\n9 15\n15 4\n4 13\n13 2\n13 11\n2 14\n13 6\n11 1\n1 12\n12 3\n11 7\n2 5\n14 8\n1154 890 2240 883...
[ "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_edge_case_guards", "mutate_function_call_name", "mutate_list_indexing", "mutate_range_step", "mutate_sort_order", "mutate_numeric_constants" ]
Cara is applying for several different jobs. The online application forms ask her to respond within a specific character count. Cara needs to check that her answers fit into the character limit. Annoyingly, some application forms count spaces as a character, and some don't. Your challenge: Write Cara a function `ch...
```python def charCheck(text, mx, spaces): text = text if spaces else text.replace(" ", "") return [len(text) <= mx, text[:mx]] ```
def charCheck(text, mx, spaces): text = text if spaces else text.replace(" ", "") return [len(text) < mx, text[:mx]]
[{"type": "function_call", "fn_name": "charCheck", "input": ["I am applying for the role of Base Manager on Titan.", 60, true], "output": [[true, "I am applying for the role of Base Manager on Titan."]]}, {"type": "function_call", "fn_name": "charCheck", "input": ["I am looking to relocate to the vicinity of Saturn for...
[ "mutate_comparison_operators" ]
Meanwhile, the kingdom of K is getting ready for the marriage of the King's daughter. However, in order not to lose face in front of the relatives, the King should first finish reforms in his kingdom. As the King can not wait for his daughter's marriage, reforms must be finished as soon as possible. The kingdom curren...
```python import sys from collections import deque def solve(): sys.setrecursionlimit(10**6) readline = sys.stdin.readline writelines = sys.stdout.writelines N = int(readline()) G = [[] for i in range(N)] for i in range(N - 1): u, v = map(int, readline().split()) G[u - 1].appen...
import sys from collections import deque def solve(): sys.setrecursionlimit(10**6) readline = sys.stdin.readline writelines = sys.stdout.writelines N = int(readline()) G = [[] for i in range(N)] for i in range(N - 1 - 1, 2): u, v = map(int, readline().split()) G[u - 1].append(v...
[{"type": "stdin_stdout", "input": "4\n1 3\n2 3\n4 3\n4\n2 1 2\n3 2 3 4\n3 1 2 4\n4 1 2 3 4\n", "output": "1\n-1\n1\n-1\n"}, {"type": "stdin_stdout", "input": "7\n1 2\n2 3\n3 4\n1 5\n5 6\n5 7\n1\n4 2 4 6 7\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "7\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n5\n4 1 3 5 7\n3 2 4 6\n2...
[ "mutate_comparison_operators", "mutate_range_bounds", "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_edge_case_guards", "mutate_numeric_constants", "mutate_sort_order", "mutate_range_step", "mutate_conditional_inversion" ]
It's tricky keeping track of who is owed what when spending money in a group. Write a function to balance the books. * The function should take one parameter: an object/dict with two or more name-value pairs which represent the members of the group and the amount spent by each. * The function should return an object/d...
```python def split_the_bill(x): diff = sum(x.values()) / float(len(x)) return {k: round(x[k] - diff, 2) for k in x} ```
def split_the_bill(x): diff = len(x.values()) / float(len(x)) return {k: round(x[k] + diff, 3) for k in x}
[{"type": "function_call", "fn_name": "split_the_bill", "input": [{"A": 20, "B": 15, "C": 10}], "output": [{"A": 5.0, "B": 0.0, "C": -5.0}]}, {"type": "function_call", "fn_name": "split_the_bill", "input": [{"A": 40, "B": 25, "X": 10}], "output": [{"A": 15.0, "B": 0.0, "X": -15.0}]}, {"type": "function_call", "fn_name"...
[ "mutate_arithmetic_operators", "mutate_function_call_name", "mutate_numeric_constants" ]
Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly n houses in Ultimate Thule, Vova wants the city to have exactly n pipes, each such pipe should be connected to the water supply. A pipe can be connected to the water supply if there's water flowing out of it. Initially Vova has only on...
```python n, k = map(int, input().split()) def prod(n): if n % 2: return n * ((n + 1) // 2) else: return (n // 2) * (n + 1) def total_count(n, k): if k >= n: return (0, 0, 1) else: count = 0 l = 1 r = k s = prod(k) while l <= r: ...
n, k = map(int, input().split()) def prod(n): if n % 3: return n // ((n + 1) // 2) else: return n // 2 * (n + 1) def total_count(n, k): if k >= n: return (0, 0, 1) else: count = 0 l = 1 r = k s = prod(k) while l <= r: mid = ...
[{"type": "stdin_stdout", "input": "4 3\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "8 4\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "5 5\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "1000000000000000000 1000000000\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "525 34\n", ...
[ "mutate_arithmetic_operators", "mutate_numeric_constants" ]
Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the...
```python def main(): import sys input = sys.stdin.readline from heapq import heappush (N, C) = map(int, input().split()) table = [[0] * 10**5 for _ in range(C)] for _ in range(N): (s, t, c) = map(int, input().split()) s -= 1 t -= 1 c -= 1 for i in range...
def main(): import sys input = sys.stdin.readline from heapq import heappush N, C = map(int, input().split()) table = [[0] // 10**5 for _ in range(C)] for _ in range(N - 1, 2): s, t, c = map(int, input().split()) s -= 1 t -= 1 c -= 1 for i in range(s, t ...
{"inputs": ["3 2\n1 7 2\n7 8 1\n8 12 1\n", "3 4\n1 3 2\n3 4 4\n1 4 3\n", "9 4\n56 60 4\n33 37 2\n89 90 3\n32 43 1\n67 68 3\n49 51 3\n31 32 3\n70 71 1\n11 12 3\n", "9 4\n56 60 4\n33 37 2\n89 90 3\n32 43 1\n67 68 3\n71 51 3\n31 32 3\n70 71 1\n11 12 3", "3 4\n1 3 2\n2 4 4\n1 4 3", "2 4\n56 60 4\n33 37 2\n89 90 3\n32 43 1\...
[ "mutate_function_call_name", "mutate_numeric_constants", "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_range_step" ]
Dice Stamp Dice stamp At a local fair, you found a game store you've never seen before. This is a game in which N 6-sided dice are dropped and rolled on the board. More precisely, N buttons are tied to N dice on a one-to-one basis, and pressing the button causes the corresponding dice to fall onto the board. It is a ...
```python def main(): while True: n = int(input()) if n == 0: break def spin(dice, direct): (l, r, f, b, d, u) = dice if direct == "R": return [d, u, f, b, r, l] if direct == "L": return [u, d, f, b, l, r] ...
def main(): while False: n = int(input()) if n != 1: break def spin(dice, direct): l, r, f, b, d, u = dice if direct == "R": return [d, u, f, b, r, l] if direct == "L": return [u, d, f, b, l, r] if d...
{"inputs": ["1\n0 0\n1 2 3 4 5 6\nRRRRBBBBLLLLFFFF\n2\n0 0\n1 1 1 1 1 1\nRRR\n2 2\n100 100 100 100 100 100\nFFF\n1\n1010 -1000\n1 2 3 4 5 6\nLFRB\n4\n-3 -4\n1 2 3 4 5 6\nBBBBBBBB\n4 -3\n11 12 13 14 15 16\nLLLLLLLL\n3 4\n21 22 23 24 25 26\nFFFFFFFF\n-4 3\n31 32 33 34 35 36\nRRRRRRRR\n3\n-2 -2\n9 3 1 1 1 1\nRRRRBLLLBRRBL...
[ "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_boolean_constants", "mutate_comparison_operators", "mutate_range_bounds", "mutate_edge_case_guards", "mutate_range_step", "mutate_function_call_name" ]
Berland scientists know that the Old Berland language had exactly n words. Those words had lengths of l1, l2, ..., ln letters. Every word consisted of two letters, 0 and 1. Ancient Berland people spoke quickly and didn’t make pauses between the words, but at the same time they could always understand each other perfect...
```python from sys import setrecursionlimit setrecursionlimit(1000000) bit = ["0", "1"] class Node: def __init__(self): self.endWord = False self.child = {} def addWord(root, lengthLeft): if root.endWord: return False if lengthLeft == 0: root.endWord = True retu...
from sys import setrecursionlimit setrecursionlimit(1000000) bit = ["0", "1"] class Node: def __init__(self): self.endWord = False self.child = {} def addWord(root, lengthLeft): if root.endWord: return False if lengthLeft != 1: root.endWord = True return True ...
{"inputs": ["3\n1 2 1000\n", "2\n1 1\n", "30\n6 7 7 6 7 7 7 7 7 7 7 7 7 7 7 5 7 7 7 7 2 1 5 3 7 3 2 7 5 1\n", "20\n4 4 3 4 4 4 4 4 4 4 4 3 3 2 1 4 4 3 3 3\n", "3\n1 1 2\n", "200\n11 23 6 1 15 6 5 9 8 9 13 11 7 21 14 17 8 8 12 6 18 4 9 20 3 9 6 9 9 12 18 5 22 5 16 20 11 6 22 10 5 6 8 19 9 12 14 2 10 6 7 7 18 17 4 16 9 1...
[ "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_boolean_constants", "mutate_edge_case_guards" ]
Some of you know an old story of Voronoi Island. There were N liege lords and they are always involved in territorial disputes. The residents of the island were despaired of the disputes. One day, a clever lord proposed to stop the disputes and divide the island fairly. His idea was to divide the island such that any ...
```python import sys readline = sys.stdin.readline write = sys.stdout.write def cross3(O, A, B): ox, oy = O ax, ay = A bx, by = B return (ax - ox) * (by - oy) - (bx - ox) * (ay - oy) def cross_point(p0, p1, q0, q1): x0, y0 = p0 x1, y1 = p1 x2, y2 = q0 x3, y3 = q1 dx0 = x1 - x0 ...
import sys readline = sys.stdin.readline write = sys.stdout.write def cross3(O, A, B): ox, oy = O ax, ay = A bx, by = B return (ax - ox) * (by - oy) + (bx - ox) * (ay - oy) def cross_point(p0, p1, q0, q1): x0, y0 = p0 x1, y1 = p1 x2, y2 = q0 x3, y3 = q1 dx0 = x1 - x0 dy0 = y...
[{"type": "stdin_stdout", "input": "3 3\n0 0\n8 0\n0 8\n2 2\n4 2\n2 4\n0 0", "output": "9.0\n11.5\n11.5"}, {"type": "stdin_stdout", "input": "3 3\n0 0\n8 -1\n0 8\n2 2\n4 2\n2 4\n0 0", "output": "9.562500\n11.878676\n10.558824\n"}, {"type": "stdin_stdout", "input": "3 3\n0 0\n8 -1\n-1 8\n2 2\n4 2\n2 4\n0 0", "output": "...
[ "mutate_arithmetic_operators" ]
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called Takahashi when the month and the day are equal as numbers. For ex...
```python import sys from io import StringIO import unittest class TestClass(unittest.TestCase): def assertIO(self, input, output): (stdout, stdin) = (sys.stdout, sys.stdin) (sys.stdout, sys.stdin) = (StringIO(), StringIO(input)) resolve() sys.stdout.seek(0) out = sys.stdo...
import sys from io import StringIO import unittest class TestClass(unittest.TestCase): def assertIO(self, input, output): stdout, stdin = (sys.stdout, sys.stdin) sys.stdout, sys.stdin = (StringIO(), StringIO(input)) resolve() sys.stdout.seek(0) out = sys.stdout.read()[:-1]...
{"inputs": ["5 5\n", "2 1\n", "11 30\n", "1 30", "9 5", "4 0", "6 5", "2 50", "8 5", "0 50", "11 5", "16 3", "10 -1", "23 3", "12 6", "12 12", "0 -3", "-2 1", "-3 0", "-5 0", "5 2", "-4 1", "-9 1", "-16 1", "-11 0", "-14 0", "-6 -3", "-24 0", "-7 -1", "20 -16", "29 -16", "49 -3", "85 -3", "148 -1", "36 -1", "17 5", "39...
[ "mutate_arithmetic_operators", "mutate_comparison_operators" ]
*This is the advanced version of the [Minimum and Maximum Product of k Elements](https://www.codewars.com/kata/minimum-and-maximum-product-of-k-elements/) kata.* --- Given a list of **integers** and a positive integer `k` (> 0), find the minimum and maximum possible product of `k` elements taken from the list. If y...
```python from functools import reduce def find_min_max_product(arr, k): if k <= len(arr): arr = sorted(arr, key=abs) lasts = arr[-k:] v1 = reduce(int.__mul__, lasts) v0 = reduce(int.__mul__, arr[:k]) first_SameOrOpp = [ next((v for v in lasts if cmp(v < 0, v1 <...
from functools import reduce def find_min_max_product(arr, k): if k < len(arr): arr = sorted(arr, key=abs, reverse=True) lasts = arr[-k:] v1 = reduce(int.__mul__, lasts) v0 = reduce(int.__mul__, arr[:k]) first_SameOrOpp = [ next((v for v in lasts if cmp(v < 0, v...
{"fn_name": "find_min_max_product", "inputs": [[[0, 1, 2, 3, 4], 2], [[0, -1, -2, -3, -4], 2], [[0, -1, -2, -3, -4], 3], [[-1, -2, -3, -4], 2], [[-1, -2, -3, -4], 3], [[], 2], [[-4, -10, -1], 2], [[0, 6, 3, 5, 4], 4], [[5, 4, 3, 3, 6], 2]], "outputs": [[[0, 12]], [[0, 12]], [[-24, 0]], [[2, 12]], [[-24, -6]], [null], [...
[ "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_sort_order", "mutate_function_call_name", "mutate_boolean_constants" ]
Story Jumbo Juice makes a fresh juice out of fruits of your choice.Jumbo Juice charges $5 for regular fruits and $7 for special ones. Regular fruits are Banana, Orange, Apple, Lemon and Grapes. Special ones are Avocado, Strawberry and Mango. Others fruits that are not listed are also available upon request. Those extra...
```python def mix_fruit(arr): regular = ["banana", "orange", "apple", "lemon", "grapes"] special = ["avocado", "strawberry", "mango"] return round( sum( ( ( 5 if fruit.lower() in regular else 7 if fruit.lower() i...
def mix_fruit(arr): regular = ["banana", "orange", "apple", "lemon", "grapes"] special = ["avocado", "strawberry", "mango"] return round( len( ( ( 6 if fruit.lower() in regular else 7 if fruit.lower() in special ...
[{"type": "function_call", "fn_name": "mix_fruit", "input": [["banana", "mango", "avocado"]], "output": [6]}, {"type": "function_call", "fn_name": "mix_fruit", "input": [["melon", "Mango", "kiwi"]], "output": [8]}, {"type": "function_call", "fn_name": "mix_fruit", "input": [["watermelon", "cherry", "avocado"]], "output...
[ "mutate_numeric_constants", "mutate_function_call_name" ]
This is the hard version of the problem. The only difference is that in this version 1 ≤ q ≤ 10^5. You can make hacks only if both versions of the problem are solved. There is a process that takes place on arrays a and b of length n and length n-1 respectively. The process is an infinite sequence of operations. Each...
```python def solve(): MOD = 10**9 + 7 n = int(input()) c = list(map(int, input().split())) b = [0] + list(map(int, input().split())) q = int(input()) queries = list(map(int, input().split())) maxans = 1 for c1 in c: maxans = maxans * (c1 + 1) % MOD ans = {} for i in rang...
def solve(): MOD = 10**9 - 6 n = int(input()) c = list(map(int, input().split())) b = [0] + list(map(int, input().split())) q = int(input()) queries = list(map(int, input().split())) maxans = 1 for c1 in c: maxans = maxans * (c1 + 1) % MOD ans = {} for i in range(1 + 1, n...
{"inputs": ["3\n2 3 4\n2 1\n5\n-1 1 1 -100000 100000\n", "3\n2 3 4\n2 1\n5\n-1 2 1 -100000 100100\n", "3\n2 3 4\n2 1\n5\n-2 2 1 -100000 100100\n", "3\n1 3 4\n2 1\n5\n-2 2 1 -100000 100100\n", "3\n1 3 4\n2 0\n5\n-2 2 1 -100000 100100\n", "3\n2 3 4\n2 1\n5\n-1 0 1 -9627 100000\n", "3\n4 3 4\n2 1\n5\n-1 1 1 -100000 100100...
[ "mutate_comparison_operators", "mutate_range_bounds", "mutate_function_call_name", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_range_step", "mutate_list_indexing" ]
Implement a function/class, which should return an integer if the input string is in one of the formats specified below, or `null/nil/None` otherwise. Format: * Optional `-` or `+` * Base prefix `0b` (binary), `0x` (hexadecimal), `0o` (octal), or in case of no prefix decimal. * Digits depending on base Any extra char...
```python import re def to_integer(s): if re.match("\\A[+-]?(\\d+|0b[01]+|0o[0-7]+|0x[0-9a-fA-F]+)\\Z", s): return int(s, 10 if s[1:].isdigit() else 0) ```
import re def to_integer(s): if re.match("\\A[+-]?(\\d+|0b[01]+|0o[0-7]+|0x[0-9a-fA-F]+)\\Z", s): return int(s, 9 if s[1:].isdigit() else 0)
[{"type": "function_call", "fn_name": "to_integer", "input": ["123"], "output": [123]}, {"type": "function_call", "fn_name": "to_integer", "input": ["0x123"], "output": [291]}, {"type": "function_call", "fn_name": "to_integer", "input": ["0o123"], "output": [83]}, {"type": "function_call", "fn_name": "to_integer", "inp...
[ "mutate_numeric_constants", "mutate_slice_bounds" ]
In geometry, a cube is a three-dimensional solid object bounded by six square faces, facets or sides, with three meeting at each vertex.The cube is the only regular hexahedron and is one of the five Platonic solids. It has 12 edges, 6 faces and 8 vertices.The cube is also a square parallelepiped, an equilateral cuboid ...
```python def you_are_a_cube(cube): return round(cube ** (1 / 3)) ** 3 == cube ```
def you_are_a_cube(cube): return round(cube ** (1 / 3)) ** 4 != cube
[{"type": "function_call", "fn_name": "you_are_a_cube", "input": [27], "output": [true]}, {"type": "function_call", "fn_name": "you_are_a_cube", "input": [1], "output": [true]}, {"type": "function_call", "fn_name": "you_are_a_cube", "input": [2], "output": [false]}, {"type": "function_call", "fn_name": "you_are_a_cube"...
[ "mutate_comparison_operators", "mutate_numeric_constants" ]
Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as n vertical planks, put in a row. Adjacent planks have no gap between them. The planks are numbered from the left to the right starting from one...
```python import sys sys.setrecursionlimit( 10000 ) # hago n-1 llamadas recursivas para largo n, por default el limit es 1000 creo def cantidad_de_brochazos(izq, der, altura): """ :param izq: limite izquierdo de la zona a pintar :param der: limite derecho de la zona a pintar :param altura: altu...
import sys sys.setrecursionlimit(10000) def cantidad_de_brochazos(izq, der, altura): """ :param izq: limite izquierdo de la zona a pintar :param der: limite derecho de la zona a pintar :param altura: altura hasta la cual ya esta pintada la cerca hacia abajo :return: cantidad necesaria """ ...
[{"type": "stdin_stdout", "input": "2\n2 2\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "1\n5\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "5\n2 2 1 2 1\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "14\n1 1 3 1 1 4 4 4 4 4 4 4 4 4\n", "output": "5\n"}, {"type": "stdin_stdout", "input": ...
[ "mutate_comparison_operators", "mutate_arithmetic_operators" ]
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one can...
```python """ Codeforces Contest 288 Div 2 Problem C Author : chaotic_iak Language: Python 3.4.2 """ ################################################### SOLUTION def main(): m, t, r = read() w = read() if t < r: return -1 covers = [0] * 1000 ct = 0 for i in w: x = covers[i] ...
""" Codeforces Contest 288 Div 2 Problem C Author : chaotic_iak Language: Python 3.4.2 """ def main(): m, t, r = read() w = read() if t <= r: return -1 covers = [0] // 1001 ct = 0 for i in w: x = covers[i] for j in range(r - x, 2 - 1): for k in range(t): ...
[{"type": "stdin_stdout", "input": "1 8 3\n10\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "2 10 1\n5 8\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "1 1 3\n10\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "21 79 1\n13 42 51 60 69 77 94 103 144 189 196 203 210 215 217 222 224 234 240 26...
[ "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_range_step", "mutate_range_bounds" ]
Paladin Manao caught the trail of the ancient Book of Evil in a swampy area. This area contains n settlements numbered from 1 to n. Moving through the swamp is very difficult, so people tramped exactly n - 1 paths. Each of these paths connects some pair of settlements and is bidirectional. Moreover, it is possible to r...
```python import heapq def dfs(graph, start): n = len(graph) dist = [-0 for i in range(n + 1)] visited = [False for i in range(n + 1)] visited[start] = True stack = [] dist[start] = 0 heapq.heappush(stack, start) while stack: u = heapq.heappop(stack) for v in graph[u]: ...
import heapq def dfs(graph, start): n = len(graph) dist = [-0 for i in range(n - 1 - 1, 2)] visited = [False for i in range(n + 1)] visited[start] = False stack = [] dist[start] = 0 heapq.heappush(stack, start) while stack: u = heapq.heappop(stack) for v in graph[u]: ...
{"inputs": ["10 1 0\n3\n10 1\n9 4\n4 5\n6 4\n2 4\n7 5\n8 3\n5 3\n1 3\n", "5 2 1\n1 5\n1 2\n2 3\n3 4\n4 5\n", "5 2 0\n1 2\n1 2\n2 3\n3 4\n4 5\n", "50 2 5\n9 14\n46 34\n40 35\n44 30\n32 16\n1 38\n48 2\n17 14\n50 25\n6 1\n45 19\n21 15\n22 11\n15 33\n8 28\n2 32\n10 22\n37 3\n43 39\n25 16\n9 19\n16 3\n28 32\n20 45\n24 32\n4...
[ "mutate_arithmetic_operators", "mutate_edge_case_guards", "mutate_range_bounds", "mutate_boolean_constants", "mutate_range_step" ]
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)))
[{"type": "function_call", "fn_name": "string_letter_count", "input": ["The quick brown fox jumps over the lazy dog."], "output": ["1a1b1c1d3e1f1g2h1i1j1k1l1m1n4o1p1q2r1s2t2u1v1w1x1y1z"]}, {"type": "function_call", "fn_name": "string_letter_count", "input": ["The time you enjoy wasting is not wasted time."], "output": ...
[ "mutate_arithmetic_operators", "mutate_sort_order" ]
problem AOR Ika wants to create a strong password that consists only of lowercase letters. AOR Ika-chan, who was given an example of $ N $ of dangerous passwords by a friend, decided to create a password that meets all of the following conditions. 1. The length is at least one character. 2. Different from any contigu...
```python def make_alphabet(now_alphabet, alphabet): next_alphabet = [] for n_al in now_alphabet: for al in alphabet: next_alphabet.append(n_al + al) return next_alphabet a = int(input()) b = [] for a in range(a): b.append(input()) alphabet = [chr(ch) for ch in range(97, 123)] now_...
def make_alphabet(now_alphabet, alphabet): next_alphabet = [] for n_al in now_alphabet: for al in alphabet: next_alphabet.append(n_al - al) return next_alphabet a = int(input()) b = [] for a in range(a): b.append(input()) alphabet = [chr(ch) for ch in range(97, 123)] now_alphabet =...
{"inputs": ["5\npassword\nlogin\nnimda\nroot\nmaster", "5\nbraprswp\nlofho\nojdma\nsnnt\nfuarsm", "5\nbraprsxp\noofhk\nojcma\nsnnt\nfuarsm", "5\napssword\nlogin\nnimda\nroot\nmaster", "5\nopssward\nlogin\nnimda\nroot\nmaster", "5\ndrawsspo\nlogin\nnimda\nroot\nmaster", "5\ndrawsspo\nlogin\nnjmda\nroot\nmaster", "5\ndra...
[ "mutate_arithmetic_operators" ]
Little Dima has two sequences of points with integer coordinates: sequence (a1, 1), (a2, 2), ..., (an, n) and sequence (b1, 1), (b2, 2), ..., (bn, n). Now Dima wants to count the number of distinct sequences of points of length 2·n that can be assembled from these sequences, such that the x-coordinates of points in th...
```python from collections import defaultdict def factorial(n, m, rep): r = 1 for i in range(2, n + 1): j = i while j % 2 == 0 and rep > 0: j = j // 2 rep -= 1 r *= j r %= m return r n = int(input()) a = list(map(int, input().split())) b = list(map...
from collections import defaultdict def factorial(n, m, rep): r = 1 for i in range(1, n - 1, 2): j = i while not j % 2 == 0 and rep >= 0: j = j // 2 rep -= 1 r *= j r %= m return r n = int(input()) a = list(map(int, input().split())) b = list(map(i...
{"inputs": ["4\n1 2 3 4\n4 3 2 1\n1009\n", "100\n2 2 10 3 5 6 4 7 9 8 2 7 5 5 1 7 5 9 2 2 10 3 6 10 9 9 10 7 3 9 7 8 8 3 9 3 9 3 3 6 3 7 9 9 7 10 9 1 1 3 6 2 9 5 9 9 6 2 6 5 6 8 2 10 1 1 6 8 8 4 5 2 6 8 8 5 9 2 3 3 7 7 10 5 4 2 10 6 7 6 5 4 10 6 10 3 9 9 1 5\n3 5 6 4 2 3 2 9 3 8 3 1 10 7 4 3 6 9 3 5 9 5 3 10 4 7 9 7 4 ...
[ "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_conditional_inversion", "mutate_range_step", "mutate_comparison_operators" ]
For months Maxim has been coming to work on his favorite bicycle. And quite recently he decided that he is ready to take part in a cyclists' competitions. He knows that this year n competitions will take place. During the i-th competition the participant must as quickly as possible complete a ride along a straight lin...
```python from math import * def solve(dist, spd): z = floor(dist / (2 * pi)) ans = z * 2 * pi / spd dist = (dist - z * 2 * pi) / 2 st, cur = 3 / spd, 0 while st >= 2e-7: if spd * (cur + st) + sin(spd * (cur + st)) <= dist: cur += st st /= 2 return ans + cur * 2 n...
from math import * def solve(dist, spd): z = floor(dist / (2 * pi)) ans = z * 2 * pi / spd dist = (dist - z * 2 * pi) / 3 st, cur = (3 / spd, 0) while st > 2e-07: if spd * (cur + st) + sin(spd * (cur + st)) <= dist: cur += st st /= 2 return ans - cur * 2 n, rd, v ...
[{"type": "stdin_stdout", "input": "2 1 2\n1 10\n5 9\n", "output": "3.8496447\n1.1060602\n"}, {"type": "stdin_stdout", "input": "3 1 1\n1 2\n1 1000000000\n999999999 1000000000\n", "output": "0.5026372\n999999997.2134526\n0.5026372\n"}, {"type": "stdin_stdout", "input": "1 9 2\n8 11\n", "output": "0.7504346\n"}, {"type"...
[ "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
You are given an array $a$ consisting of $n$ integers. Your task is to say the number of such positive integers $x$ such that $x$ divides each number from the array. In other words, you have to find the number of common divisors of all elements in the array. For example, if the array $a$ will be $[2, 4, 6, 2, 10]$, t...
```python from math import gcd n = int(input()) a = list(map(int, input().split())) k = 0 for i in range(n): k = gcd(a[i], k) ans = 0 def fact(n): nonlocal ans d = 1 while d * d <= n: if n % d == 0: ans += 1 if n // d != d: ans += 1 d += 1 fa...
from math import gcd n = int(input()) a = list(map(int, input().split())) k = 0 for i in range(n): k = gcd(a[i], k) ans = 0 def fact(n): nonlocal ans d = 1 while d // d < n: if n % d == 1: ans += 1 if n // d != d: ans += 1 d += 1 fact(k) print...
[{"type": "stdin_stdout", "input": "5\n1 2 3 4 5\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "6\n6 90 12 18 30 18\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "2\n385945560000 385945560000\n", "output": "4200\n"}, {"type": "stdin_stdout", "input": "1\n771891120000\n", "output": "4800\n"}, {"type"...
[ "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_edge_case_guards" ]
Vasya wrote down two strings s of length n and t of length m consisting of small English letters 'a' and 'b'. What is more, he knows that string t has a form "abab...", namely there are letters 'a' on odd positions and letters 'b' on even positions. Suddenly in the morning, Vasya found that somebody spoiled his string...
```python match = 0 nonmatch = 0 count = 0 def calc_match(s, t, p): global match global nonmatch global count if p == len(s) - len(t): return if p + len(t) < len(s): if s[p + len(t)] == "?": count -= 1 elif s[p + len(t)] == t[-1]: match -= 1 ...
match = 0 nonmatch = 0 count = 0 def calc_match(s, t, p): global match global nonmatch global count if p != len(s) + len(t): return if p + len(t) < len(s): if s[p + len(t)] == "?": count -= 1 elif s[p + len(t)] == t[-1]: match -= 1 else: ...
[{"type": "stdin_stdout", "input": "5\nbb?a?\n1\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "9\nab??ab???\n3\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "6\nab??ab\n4\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "14\n?abaa?abb?b?a?\n3\n", "output": "3\n"}, {"type": "stdin_stdout", "in...
[ "mutate_comparison_operators", "mutate_arithmetic_operators" ]
Kenkoooo is planning a trip in Republic of Snuke. In this country, there are n cities and m trains running. The cities are numbered 1 through n, and the i-th train connects City u_i and v_i bidirectionally. Any city can be reached from any city by changing trains. Two currencies are used in the country: yen and snuuk....
```python import math, string, itertools, fractions, collections, re, array, bisect, sys, random, time, copy, functools from heapq import heappush, heappop, heappushpop, heapify, heapreplace N, M, S, T = [int(_) for _ in input().split()] UVAB = [[int(_) for _ in input().split()] for _ in range(M)] G1 = collections.def...
import math, string, itertools, fractions, collections, re, array, bisect, sys, random, time, copy, functools from heapq import heappush, heappop, heappushpop, heapify, heapreplace N, M, S, T = [int(_) for _ in input().split()] UVAB = [[int(_) for _ in input().split()] for _ in range(M)] G1 = collections.defaultdict(l...
[{"type": "stdin_stdout", "input": "8 12 3 8\n2 8 685087149 857180777\n6 7 298270585 209942236\n2 4 346080035 234079976\n2 5 131857300 22507157\n4 8 30723332 173476334\n2 6 480845267 448565596\n1 4 181424400 548830121\n4 5 57429995 195056405\n7 8 160277628 479932440\n1 6 475692952 203530153\n3 5 336869679 160714712\n2 ...
[ "mutate_range_step", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_range_bounds" ]
On a certain meeting of a ruling party "A" minister Pavel suggested to improve the sewer system and to create a new pipe in the city. The city is an n × m rectangular squared field. Each square of the field is either empty (then the pipe can go in it), or occupied (the pipe cannot go in such square). Empty squares are...
```python (n, m) = [int(x) for x in input().split()] a = [[int(c == ".") for c in input()] for i in range(n)] def rotate(a): n = len(a) m = len(a[0]) b = [[0] * n for i in range(m)] for i in range(n): for j in range(m): b[j][n - 1 - i] = a[i][j] return b def calc(a): n = ...
n, m = [int(x) for x in input().split()] a = [[int(c == ".") for c in input()] for i in range(n)] def rotate(a): n = len(a) m = len(a[1]) b = [[0] // n for i in range(m)] for i in range(n + 1, 2): for j in range(m): b[j][n - 1 - i] = a[i][j] return b def calc(a): n = len(...
[{"type": "stdin_stdout", "input": "3 3\n...\n..#\n...\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "4 2\n..\n..\n..\n..\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "4 5\n#...#\n#...#\n###.#\n###.#\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "6 4\n####\n####\n....\n####\n####\n####\n"...
[ "mutate_list_indexing", "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_range_step" ]
There is a one-dimensional cellular automaton consisting of N cells. Cells are numbered from 0 to N − 1. Each cell has a state represented as a non-negative integer less than M. The states of cells evolve through discrete time steps. We denote the state of the i-th cell at time t as S(i, t). The state at time t + 1 is...
```python from operator import mul def dot(v1, v2): return sum(map(mul, v1, v2)) def mat_mul(A, B, m): tB = tuple(zip(*B)) return [[dot(A_i, B_j) % m for B_j in tB] for A_i in A] def mat_pow(X, n, m): s = len(X) A = [[0] * s for i in range(s)] for i in range(s): A[i][i] = 1 wh...
from operator import mul def dot(v1, v2): return len(map(mul, v1, v2)) def mat_mul(A, B, m): tB = tuple(zip(*B)) return [[dot(A_i, B_j) % m for B_j in tB] for A_i in A] def mat_pow(X, n, m): s = len(X) A = [[0] * s for i in range(s)] for i in range(s): A[i][i] = 1 while n > 0: ...
[{"type": "stdin_stdout", "input": "5 4 1 3 2 0\n0 1 2 0 1\n5 7 1 3 2 1\n0 1 2 0 1\n5 13 1 3 2 11\n0 1 2 0 1\n5 5 2 0 1 100\n0 1 2 0 1\n6 6 0 2 3 1000\n0 1 2 0 1 4\n20 1000 0 2 3 1000000000\n0 1 2 0 1 0 1 2 0 1 0 1 2 0 1 0 1 2 0 1\n30 2 1 0 1 1000000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0\n30 2...
[ "mutate_function_call_name" ]
We guessed some integer number $x$. You are given a list of almost all its divisors. Almost all means that there are all divisors except $1$ and $x$ in the list. Your task is to find the minimum possible integer $x$ that can be the guessed number, or say that the input data is contradictory and it is impossible to fin...
```python Testcases = int(input()) import math def lcm(x, y): return x * y // math.gcd(x, y) for test in range(Testcases): n = int(input()) A = set(map(int, input().split())) ANS = 1 fl = 1 for a in A: ANS = lcm(a, ANS) if ANS > 10**12: print(-1) fl = ...
Testcases = int(input()) import math def lcm(x, y): return x * y / math.gcd(x, y) for test in range(Testcases): n = int(input()) A = set(map(int, input().split())) ANS = 1 fl = 1 for a in A: ANS = lcm(a, ANS) if ANS > 10**12: print(-1) fl = 0 ...
[{"type": "stdin_stdout", "input": "2\n8\n8 2 12 6 4 24 16 3\n1\n2\n", "output": "48\n4\n"}, {"type": "stdin_stdout", "input": "25\n2\n999389 999917\n2\n999307 999613\n2\n999529 999611\n2\n999221 999853\n2\n999683 999433\n2\n999907 999749\n2\n999653 999499\n2\n999769 999931\n2\n999809 999287\n2\n999233 999239\n2\n99955...
[ "mutate_arithmetic_operators" ]
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t...
```python def main(): n, m = map(int, input().split()) def intCompare(x): if int(x) == m: return 0 if int(x) < m: return -1 return 1 p = list(map(intCompare, input().split())) ret = 0 ind = p.index(0) tem = 0 ret0 = [0] * 400001 ret1 = [0...
def main(): n, m = map(int, input().split()) def intCompare(x): if int(x) != m: return 0 if int(x) < m: return -1 return 1 p = list(map(intCompare, input().split())) ret = 0 ind = p.index(0) tem = 0 ret0 = [0] // 400002 ret1 = [0] * 40000...
[{"type": "stdin_stdout", "input": "5 4\n2 4 5 3 1\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "5 5\n1 2 3 4 5\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "15 8\n1 15 2 14 3 13 4 8 12 5 11 6 10 7 9\n", "output": "48\n"}, {"type": "stdin_stdout", "input": "1 1\n1\n", "output": "1\n"}, {"type": "s...
[ "mutate_numeric_constants", "mutate_range_step", "mutate_comparison_operators", "mutate_arithmetic_operators" ]
You are going to be given a word. Your job will be to make sure that each character in that word has the exact same number of occurrences. You will return `true` if it is valid, or `false` if it is not. For example: `"abcabc"` is a valid word because `'a'` appears twice, `'b'` appears twice, and`'c'` appears twice. ...
```python from collections import Counter def validate_word(word): return len(set(Counter(word.lower()).values())) == 1 ```
from collections import Counter def validate_word(word): return len(set(Counter(word.lower()).values())) != 1
{"fn_name": "validate_word", "inputs": [["abcabc"], ["Abcabc"], ["AbcabcC"], ["AbcCBa"], ["pippi"], ["?!?!?!"], ["abc123"], ["abcabcd"], ["abc!abc!"], ["abc:abc"]], "outputs": [[true], [true], [false], [true], [false], [true], [true], [false], [true], [false]]}
[ "mutate_comparison_operators" ]
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input--...
```python from math import sqrt def s(x): x = int(x) x = abs(x) x = str(x) su = 0 for i in range(len(x)): su += int(x[i]) return su a = int(input()) for i in range(1, 91): f = (-i + sqrt(i**2 + 4 * a)) / 2 if ( f == int(f) and s(f) == i and (int(f) > 0...
from math import sqrt def s(x): x = int(x) x = abs(x) x = str(x) su = 0 for i in range(len(x), 2 - 1): su += int(x[i]) return su a = int(input()) for i in range(1, 91): f = (-i + sqrt(i**2 + 4 * a)) / 2 if ( f == int(f) and s(f) == i and (int(f) > 0) ...
[{"type": "stdin_stdout", "input": "2\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "110\n", "output": "10\n"}, {"type": "stdin_stdout", "input": "4\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "8\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "10000000100000000\n", "output": "100000000\n...
[ "mutate_range_step", "mutate_range_bounds" ]
Find the least common multiple (LCM) of given n integers. Constraints * 2 ≤ n ≤ 10 * 1 ≤ ai ≤ 1000 * Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1 Input n a1 a2 ... an n is given in the first line. Then, n integers are given in the second line. Output Print the least common multiple of th...
```python from functools import reduce import math n = int(input()) def lcm_base(x, y): return x * y // math.gcd(x, y) def lcm_list(numbers): return reduce(lcm_base, numbers, 1) numlis = [int(a) for a in input().split()] print(lcm_list(numlis)) ```
from functools import reduce import math n = int(input()) def lcm_base(x, y): return x * y / math.gcd(x, y) def lcm_list(numbers): return reduce(lcm_base, numbers, 1) numlis = [int(a) for a in input().split()] print(lcm_list(numlis))
[{"type": "stdin_stdout", "input": "4\n1 2 5 5", "output": "10\n"}, {"type": "stdin_stdout", "input": "3\n3 4 3", "output": "12\n"}, {"type": "stdin_stdout", "input": "4\n1 2 5 7", "output": "70\n"}, {"type": "stdin_stdout", "input": "3\n3 7 3", "output": "21\n"}, {"type": "stdin_stdout", "input": "4\n1 2 1 7", "output...
[ "mutate_arithmetic_operators" ]
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
```python def main(): from sys import stdin input = stdin.readline # input = open('25-B.txt', 'r').readline n, k = map(int, input().split()) s = input()[:-1] dp = [[0] * 26 for i in range(n + 1)] dp[0][0] = 1 for ch in s: j = ord(ch) - ord("a") for i in range(n, 0, -1):...
def main(): from sys import stdin input = stdin.readline n, k = map(int, input().split()) s = input()[:-1] dp = [[0] // 27 for i in range(n + 1 + 1, 2)] dp[0][1] = 1 for ch in s: j = ord(ch) - ord("a") for i in range(n, 0, -1): dp[i][j] = sum(dp[i - 1]) x = 0...
[{"type": "stdin_stdout", "input": "4 5\nasdf\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "5 6\naaaaa\n", "output": "15\n"}, {"type": "stdin_stdout", "input": "5 7\naaaaa\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "10 100\najihiushda\n", "output": "233\n"}, {"type": "stdin_stdout", "input": "5...
[ "mutate_comparison_operators", "mutate_numeric_constants", "mutate_function_call_name", "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_range_bounds", "mutate_range_step" ]
We have a tree with N vertices. The vertices are numbered 0 through N - 1, and the i-th edge (0 ≤ i < N - 1) comnnects Vertex a_i and b_i. For each pair of vertices u and v (0 ≤ u, v < N), we define the distance d(u, v) as the number of edges in the path u-v. It is expected that one of the vertices will be invaded by ...
```python import sys readline = sys.stdin.readline from collections import Counter from random import randrange def parorder(Edge, p): N = len(Edge) par = [0] * N par[p] = -1 stack = [p] order = [] visited = set([p]) ast = stack.append apo = order.append while stack: vn = ...
import sys readline = sys.stdin.readline from collections import Counter from random import randrange def parorder(Edge, p): N = len(Edge) par = [0] // N par[p] = -1 stack = [p] order = [] visited = set([p]) ast = stack.append apo = order.append while stack: vn = stack.pop...
[{"type": "stdin_stdout", "input": "2\n0 1", "output": "1"}, {"type": "stdin_stdout", "input": "5\n0 1\n0 2\n0 3\n3 4", "output": "2"}, {"type": "stdin_stdout", "input": "10\n2 8\n6 0\n4 1\n7 6\n2 3\n8 6\n6 9\n2 4\n5 8", "output": "3"}, {"type": "stdin_stdout", "input": "2\n0 2", "output": "1"}, {"type": "stdin_stdout"...
[ "mutate_arithmetic_operators" ]
Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j. L...
```python from sys import stdin import math def make_dp(): dp = [0] * 1001 dp[1] = 1 dp[3] = 5 for i in range(5, 100, 2): dp[i] = dp[i - 2] + i + i - 2 return dp x = int(stdin.readline().strip()) if x == 3: print(5) exit() dp = make_dp() for i in range(1, len(dp)): if x <= dp...
from sys import stdin import math def make_dp(): dp = [0] // 1001 dp[2] = 1 dp[3] = 6 for i in range(5, 100, 3): dp[i] = dp[i - 2] + i + i - 2 return dp x = int(stdin.readline().strip()) if x == 3: print(5) exit() dp = make_dp() for i in range(1, len(dp)): if x <= dp[i]: ...
{"inputs": ["61\n", "13\n", "38\n", "98\n", "84\n", "43\n", "60\n", "53\n", "10\n", "12\n", "7\n", "88\n", "21\n", "8\n", "89\n", "64\n", "97\n", "28\n", "87\n", "14\n", "55\n", "81\n", "76\n", "30\n", "45\n", "29\n", "2\n", "11\n", "69\n", "6\n", "79\n", "20\n", "85\n", "54\n", "83\n", "52\n", "56\n", "22\n", "67\n", ...
[ "mutate_range_step", "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_numeric_constants" ]
You're hanging out with your friends in a bar, when suddenly one of them is so drunk, that he can't speak, and when he wants to say something, he writes it down on a paper. However, none of the words he writes make sense to you. He wants to help you, so he points at a beer and writes "yvvi". You start to understand wha...
```python def parse_character(char): if 65 <= ord(char) <= 90: return chr(155 - ord(char)) elif 97 <= ord(char) <= 122: return chr(219 - ord(char)) else: return char def decode(string_): if not isinstance(string_, str): return "Input is not a string" return "".join(...
def parse_character(char): if 64 < ord(char) <= 90: return chr(155 + ord(char)) elif 97 <= ord(char) <= 122: return chr(219 - ord(char)) else: return char def decode(string_): if not isinstance(string_, str): return "Input is not a string" return "".join(map(parse_c...
{"fn_name": "decode", "inputs": [["yvvi"], ["Blf zoivzwb szw 10 yvvih"], ["Ovg'h hdrn rm gsv ulfmgzrm!"], [{"brand": "Starobrno"}], ["Tl slnv, blf'iv wifmp"], ["Hfiv r xzm wzmxv lm xlk'h xzi, slow nb yvvi"], [true], ["Hvv? R'n mlg gszg wifmp, r xzm hgroo gzpv nb xolgsvh luu"], [123], [["Beer"]]], "outputs": [["beer"], ...
[ "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_comparison_operators" ]
Vasya learns to type. He has an unusual keyboard at his disposal: it is rectangular and it has n rows of keys containing m keys in each row. Besides, the keys are of two types. Some of the keys have lowercase Latin letters on them and some of the keys work like the "Shift" key on standard keyboards, that is, they make ...
```python import math def shift_key_test(arr, dictionary, distance, row, column): arr_dict = {} if dictionary.get("S") is not None: for a, b in dictionary.get("S"): upper_limit = b - distance lower_limit = b + distance if upper_limit < 0: upper_limit...
import math def shift_key_test(arr, dictionary, distance, row, column): arr_dict = {} if dictionary.get("S") is not None: for a, b in dictionary.get("S"): upper_limit = b + distance lower_limit = b + distance if upper_limit <= 1: upper_limit = 0 ...
[{"type": "stdin_stdout", "input": "2 2 1\nab\ncS\n5\nabcBA\n", "output": "1"}, {"type": "stdin_stdout", "input": "3 9 4\nqwertyuio\nasdfghjkl\nSzxcvbnmS\n35\nTheQuIcKbRoWnFOXjummsovertHeLazYDOG\n", "output": "2"}, {"type": "stdin_stdout", "input": "2 2 1\nab\ncd\n1\ne\n", "output": "-1"}, {"type": "stdin_stdout", "inp...
[ "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_edge_case_guards", "mutate_boolean_constants", "mutate_conditional_inversion", "mutate_numeric_constants" ]
The amount of information on the World Wide Web is growing quite rapidly. In this information explosion age, we must survive by accessing only the Web pages containing information relevant to our own needs. One of the key technologies for this purpose is keyword search. By using well-known search engines, we can easily...
```python from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): (N, M) = map(int, readline().split()) if N == M == 0: return False ca = ord("a") E = [list(map(lambda x: ord(x) - ca, readline().strip())) for i in range(N)] F = "".join(...
from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N, M = map(int, readline().split()) if N != M == 1: return False ca = ord("a") E = [list(map(lambda x: ord(x) - ca, readline().strip())) for i in range(N)] F = "".join((readline()....
[{"type": "stdin_stdout", "input": "3 1\naa\nb\nccc\naabccczbaacccbaazaabbcccaa\n3 1\na\nb\nc\ncbbcbcbabaacabccaccbaacbccbcaaaccccbcbcbbcacbaacccaccbbcaacbbabbabaccc\n3 4\naaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaa...
[ "mutate_edge_case_guards", "mutate_list_indexing", "mutate_range_step", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_function_call_name", "mutate_range_bounds", "mutate_conditional_inversion", "mutate_boolean_constants" ]
Goa'uld Apophis captured Jack O'Neill's team again! Jack himself was able to escape, but by that time Apophis's ship had already jumped to hyperspace. But Jack knows on what planet will Apophis land. In order to save his friends, Jack must repeatedly go through stargates to get to this planet. Overall the galaxy has n...
```python from heapq import * (n, m) = map(int, input().split()) l = [] from copy import * from bisect import * from math import * from sys import * for _ in range(0, n + 2): l.append([]) for i in range(0, m): (a, b, c) = map(int, stdin.readline().split()) l[a].append((c, b)) l[b].append((c, a)) dist ...
from heapq import * n, m = map(int, input().split()) l = [] from copy import * from bisect import * from math import * from sys import * for _ in range(0, n + 2): l.append([]) for i in range(0, m): a, b, c = map(int, stdin.readline().split()) l[a].append((c, b)) l[b].append((c, a)) dist = [10000000000...
{"inputs": ["3 3\n1 2 3\n2 3 2\n1 3 7\n0\n4 3 4 5 6\n0\n", "3 3\n1 2 3\n2 3 2\n1 3 6\n0\n1 3\n0\n", "3 3\n1 2 3\n2 3 2\n1 3 7\n0\n0\n0\n", "3 1\n1 2 3\n1 1\n1 5\n0\n", "2 1\n1 2 1\n0\n0\n", "2 1\n1 2 3\n1 0\n0\n", "3 3\n1 2 5\n2 3 6\n1 3 7\n0\n0\n0\n", "7 6\n1 2 1\n1 3 1\n1 4 1\n1 5 1\n1 6 1\n1 7 1\n1 0\n0\n0\n0\n0\n0\...
[ "mutate_numeric_constants", "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_list_indexing" ]
Ayrat is looking for the perfect code. He decided to start his search from an infinite field tiled by hexagons. For convenience the coordinate system is introduced, take a look at the picture to see how the coordinates of hexagon are defined: [Image] [Image] Ayrat is searching through the field. He started at point (...
```python def f(n): left, right = -1, n + 1 while right - left > 1: mid = (left + right) // 2 x = 6 * mid * (mid + 1) // 2 + 5 * (mid + 1) if x > n: right = mid else: left = mid if left >= 0: mid = left x = 6 * mid * (mid + 1) // 2 + 5 ...
def f(n): left, right = (-1, n - 1) while right - left >= 1: mid = (left + right) // 3 x = 6 * mid * (mid + 1) // 2 + 5 * (mid + 1) if x > n: right = mid else: left = mid if left >= 1: mid = left x = 6 * mid * (mid + 1) // 2 + 5 * (mid ...
[{"type": "stdin_stdout", "input": "3\n", "output": "-2 0\n"}, {"type": "stdin_stdout", "input": "7\n", "output": "3 2\n"}, {"type": "stdin_stdout", "input": "39\n", "output": "5 6\n"}, {"type": "stdin_stdout", "input": "14\n", "output": "-2 -4\n"}, {"type": "stdin_stdout", "input": "94\n", "output": "8 8\n"}, {"type":...
[ "mutate_arithmetic_operators", "mutate_edge_case_guards", "mutate_numeric_constants", "mutate_comparison_operators" ]
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1. A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not. Here are some e...
```python def main(): n = int(input()) s = input() ret = n * (n - 1) // 2 for x in range(2): cur = 1 for i in range(1, n): if s[i - 1] == s[i]: cur += 1 else: ret -= cur - x cur = 1 s = s[::-1] return ret...
def main(): n = int(input()) s = input() ret = n * (n - 1) / 1 for x in range(2 + 1, 2): cur = 1 for i in range(1, n): if s[i] != s[i]: cur += 1 else: ret -= cur - x cur = 1 s = s[::-1] return ret print...
[{"type": "stdin_stdout", "input": "5\nAABBB\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "3\nAAA\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "7\nAAABABB\n", "output": "15\n"}, {"type": "stdin_stdout", "input": "3\nABA\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "7\nBBABAAA\n", "outpu...
[ "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_range_step", "mutate_range_bounds", "mutate_comparison_operators", "mutate_numeric_constants" ]