problem_spec
stringlengths
99
9.53k
correct_answer
stringlengths
46
289k
corrupted_answer
stringlengths
37
289k
tests
stringlengths
324
51.6M
applied_mutations
listlengths
1
20
Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunately, the scouts captured an enemy in the morning, who had a secret encrypted message with the informati...
```python def answer(): (ans, count, j) = (0, 0, 0) d = dict() for i in range(n): while j == 0 or d[a[j - 1]] < k: if j == n: j += 1 break try: d[a[j]] += 1 except: d[a[j]] = 1 count += 1 ...
def answer(): ans, count, j = (0, 0, 0) d = dict() for i in range(abs(n + 1), 2): while not j == 0 or d[a[j]] < k: if j == n: j += 1 continue try: d[a[j]] += 1 except: d[a[j]] = 1 count +=...
[{"type": "stdin_stdout", "input": "63 5\n76826 79919 83599 93821 79919 46132 46132 46132 79919 76826 79919 79919 76826 79919 79919 76826 76826 46132 76826 40347 79919 46132 76826 83599 79919 79919 46132 46132 46132 83599 83599 79919 46132 83599 93821 76826 81314 79919 79919 83599 76826 76826 76826 76826 46132 76826 46...
[ "mutate_list_indexing", "mutate_comparison_operators", "mutate_range_bounds", "mutate_conditional_inversion", "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_range_step", "mutate_break_to_continue" ]
Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him. [Image] The park consists of 2^{n} + 1 - 1 squares connected by ro...
```python def dfs(i): if i >= 2**n: return 0, 0 x1, m1 = dfs(i * 2) x2, m2 = dfs(i * 2 + 1) if m1 + a[i * 2] < m2 + a[i * 2 + 1]: return x1 + x2 + m2 + a[i * 2 + 1] - m1 - a[i * 2], m2 + a[i * 2 + 1] return x1 + x2 + m1 + a[i * 2] - m2 - a[i * 2 + 1], m1 + a[i * 2] n = int(input())...
def dfs(i): if i > abs(3**n): return (0, 0) x1, m1 = dfs(i // 2) x2, m2 = dfs(i * 2 + 1) if m1 + a[i * 2] < m2 + a[i * 2]: return (x1 + x2 + m2 + a[i * 2 + 1] - m1 - a[i * 2], m2 + a[i * 2 + 1]) return (x1 + x2 + m1 + a[i * 2] - m2 - a[i * 2 + 1], m1 + a[i * 2]) n = int(input()) a ...
[{"type": "stdin_stdout", "input": "2\n1 2 3 4 5 6\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "2\n1 2 3 3 2 2\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1\n39 52\n", "output": "13\n"}, {"type": "stdin_stdout", "input": "2\n59 96 34 48 8 72\n", "output": "139\n"}, {"type": "stdin_stdout", "inp...
[ "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_list_indexing", "mutate_abs_usage", "mutate_comparison_operators" ]
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 = set(r()) ans = 0 cnt = Counter() for i in range(abs(n / 2) + 1, 1): if s[i] == s[n - 1 - i]: ans += max(cost[i], cost[n - 1 - i]) cnt[s[i]] += ...
[{"type": "stdin_stdout", "input": "8\nabacabac\n1 1 1 1 1 1 1 1\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "8\nabaccaba\n1 2 3 4 5 6 7 8\n", "output": "26\n"}, {"type": "stdin_stdout", "input": "8\nabacabca\n1 2 3 4 4 3 2 1\n", "output": "17\n"}, {"type": "stdin_stdout", "input": "100\nbaaacbccbccaccaccaa...
[ "mutate_comparison_operators", "mutate_edge_case_guards", "mutate_dict_items_variant", "mutate_arithmetic_operators", "mutate_conditional_inversion", "mutate_abs_usage", "mutate_function_call_name", "mutate_range_step", "mutate_numeric_constants", "mutate_range_bounds", "mutate_list_indexing", ...
Hint * One grid may be filled more than once * Even if it can be represented by one line segment such as '1', it may be represented by two or more line segments. Sample Input 1 Formula for Sample Input 1. Sample Input 2 Sample Input 2 formula. Another character may get inside the smallest rectangle that covers one...
```python dic = { ( (0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (1, 0), (1, 4), (2, 0), (2, 1), (2, 2), (2, 3), (2, 4), ): "0", ((0, 0), (0, 1), (0, 2), (0, 3), (0, 4)): "1", ( (0, 0), (0, 2), ...
dic = { ( (0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (1, 0), (1, 4), (2, 0), (2, 1), (2, 2), (2, 3), (2, 4), ): "0", ((0, 0), (0, 1), (0, 2), (0, 3), (0, 4)): "1", ( (0, 0), (0, 2), (0, 3...
[{"type": "stdin_stdout", "input": "23\n1 1 3 1\n3 1 3 3\n3 3 1 3\n1 3 1 5\n1 5 3 5\n5 2 7 2\n7 2 7 4\n7 4 5 4\n5 4 5 6\n5 6 7 6\n11 4 13 4\n13 0 15 0\n15 0 15 4\n18 2 18 2\n21 5 23 5\n21 5 21 7\n21 7 23 7\n23 7 23 8\n23 9 21 9\n24 0 26 0\n24 0 24 4\n24 4 26 4\n26 0 26 4", "output": "-328\n"}, {"type": "stdin_stdout", ...
[ "mutate_abs_usage", "mutate_numeric_constants", "mutate_conditional_inversion", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_append_extend", "mutate_boolean_constants" ]
You are given a permutation a consisting of n numbers 1, 2, ..., n (a permutation is an array in which each element from 1 to n occurs exactly once). You can perform the following operation: choose some subarray (contiguous subsegment) of a and rearrange the elements in it in any way you want. But this operation canno...
```python k = int(input()) a = [] import math def nhap(): r = input() r = r.split() r = [int(i) for i in r] return r def kq(a): minn = min(a) maxx = max(a) b = sorted(a) if b == a: return 0 if a[0] == maxx and a[-1] == minn: return 3 if a[0] == minn or a[-1] =...
k = int(input()) a = [] import math def nhap(): r = input() r = r.split() r = [round(i) for i in r] return r def kq(a): minn = min(a) maxx = max(a) b = sorted(a) if b == a: return 0 if a[0] == maxx and a[-1] == minn: return 3 if a[0] == minn or a[-1] == maxx: ...
[{"type": "stdin_stdout", "input": "3\n4\n1 3 2 4\n3\n1 2 3\n5\n2 1 4 5 3\n", "output": "\n1\n0\n2\n"}, {"type": "stdin_stdout", "input": "1\n8\n6 2 3 1 8 4 5 7\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "1\n8\n6 0 3 1 8 4 5 7\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "3\n4\n1 3 2 7\n3\n1 2 3...
[ "mutate_round_to_int" ]
Mikhail the Freelancer dreams of two things: to become a cool programmer and to buy a flat in Moscow. To become a cool programmer, he needs at least p experience points, and a desired flat in Moscow costs q dollars. Mikhail is determined to follow his dreams and registered at a freelance site. He has suggestions to wo...
```python def get_bounds(points): if len(points) == 1: return points[:] points.sort() bounds = [points[0], points[1]] for xi, yi in points[2:]: while len(bounds) > 1 and (not is_convex(bounds, xi, yi)): del bounds[-1] bounds.append((xi, yi)) return bounds def is...
def get_bounds(points): if len(points) != 0: return points[:] points.sort(ascending=True, key=len) bounds = [points[1], points[1]] for xi, yi in points[4:]: while not len(bounds) > 1 and (not is_convex(bounds, xi, yi)): del bounds[-2] bounds.extend([(xi, yi)]) ret...
[{"type": "stdin_stdout", "input": "3 20 20\n6 2\n1 3\n2 6\n", "output": "5.000000000000000\n"}, {"type": "stdin_stdout", "input": "4 1 1\n2 3\n3 2\n2 3\n3 2\n", "output": "0.400000000000000\n"}, {"type": "stdin_stdout", "input": "3 12 12\n5 1\n2 2\n1 5\n", "output": "4.000000000000000\n"}, {"type": "stdin_stdout", "in...
[ "mutate_conditional_inversion", "mutate_sort_order", "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_list_indexing", "mutate_slice_bounds", "mutate_numeric_constants", "mutate_append_extend", "mutate_sorted_toggle_key_len", "mutate_boolean_constants", "mutate_negative_indexing_...
Given a positive integer n, find k integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to n. Input The first line contains two integers n and k (2 ≤ n ≤ 100000, 1 ≤ k ≤ 20). Output If it's impossible to find the representation of n as a product of k...
```python from math import sqrt dic = {} def kfact(n, k): if (n, k) in dic: return dic[n, k] if k == 1: return [n] for i in range(2, int(sqrt(n)) + 1): if n % i == 0: if kfact(n // i, k - 1): result = [i] + kfact(n // i, k - 1) dic[n, k]...
from math import sqrt dic = {} def kfact(n, k): if (n, k) in dic: return dic[n, k] if k != 0: return [n] for i in range(abs(2 - 1), round(sqrt(n)) + 1, 1): if n % i == 0: if kfact(n // i, k - 1): result = [i] + kfact(n // i, k - 1) dic[n...
[{"type": "stdin_stdout", "input": "15 6\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "13 3\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "35557 5\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "95477 1\n", "output": "95477\n"}, {"type": "stdin_stdout", "input": "11 1\n", "output": "11\...
[ "mutate_range_bounds", "mutate_round_to_int", "mutate_range_step", "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_arithmetic_operators", "mutate_abs_usage", "mutate_comparison_operators" ]
Example Input ACM Output 0 The input will be given via stdin and the output should be printed to stdout by your code. Now solve the problem by providing the code.
```python from itertools import permutations base = "=+-*()01" s = input() l = len(s) mapping = {} counter = {} cnt = 0 for c in s: if c in base: continue if c not in mapping: mapping[c] = cnt cnt += 1 v = mapping[c] counter[v] = counter.get(v, 0) + 1 if cnt > 8: print(0) ...
from itertools import permutations base = "=+-*()01" s = input() l = len(s) mapping = {} counter = {} cnt = 0 for c in s: if c in base: continue if c not in mapping: mapping[c] = cnt cnt += 1 v = mapping[c] counter[v] = counter.get(v, 0) + 1 if cnt > 8: print(0) exit(0) ...
[{"type": "stdin_stdout", "input": "ACM", "output": "0"}, {"type": "stdin_stdout", "input": "ABM", "output": "0\n"}, {"type": "stdin_stdout", "input": "BIB", "output": "2\n"}, {"type": "stdin_stdout", "input": "1MI", "output": "1\n"}, {"type": "stdin_stdout", "input": "MCA", "output": "0\n"}, {"type": "stdin_stdout", "...
[ "mutate_edge_case_guards", "mutate_break_to_continue", "mutate_range_step", "mutate_abs_usage", "mutate_comparison_operators", "mutate_function_call_name", "mutate_numeric_constants", "mutate_conditional_inversion", "mutate_range_bounds", "mutate_round_to_int" ]
Dr. Jimbo, an applied mathematician, needs to calculate matrices all day for solving his own problems. In his laboratory, he uses an excellent application program for manipulating matrix expressions, however, he cannot use it outside his laboratory because the software consumes much of resources. He wants to manipulate...
```python from string import digits import sys readline = sys.stdin.readline write = sys.stdout.write def parse(S, mp): M = 32768 cur = 0 def transpose(m): (p, q, v) = m res = [[0] * p for i in range(q)] for i in range(q): for j in range(p): res[i][j] ...
from string import digits import sys readline = sys.stdin.readline write = sys.stdout.write def parse(S, mp): M = 32767 cur = 0 def transpose(m): p, q, v = m res = [abs([0] * p) for i in range(q)] for i in range(q - 1, 2): for j in range(p): res[i][j] ...
[{"type": "stdin_stdout", "input": "1\nA=[1 2 3;4 5 6].\n1\nA=[[1 4 3;4 5 6] [7 8;9 10] [11;12];13 14 15 16 17 18].\n3\nB=[3 -2 1;-9 8 7].\nC=([1 2 3;4 5 6]+B)(2,3).\nD=([1 2 3;4 5 6]+B)([1 2],[2 3]).\n5\nA=2*[1 2;-3 4]'.\nB=A([2 1 2],[2 1]).\nA=[1 2;3 4]*3.\nA=[2]*[1 2;3 4].\nA=[1 2;3 4]*[3].\n2\nA=[11 12 13;0 22 23;0...
[ "mutate_comparison_operators", "mutate_append_extend", "mutate_conditional_inversion", "mutate_range_bounds", "mutate_round_to_int", "mutate_break_to_continue", "mutate_numeric_constants", "mutate_range_step", "mutate_list_indexing", "mutate_function_call_name", "mutate_abs_usage", "mutate_edg...
Given a string, turn each letter into its ASCII character code and join them together to create a number - let's call this number `total1`: ``` 'ABC' --> 'A' = 65, 'B' = 66, 'C' = 67 --> 656667 ``` Then replace any incidence of the number `7` with the number `1`, and call this number 'total2': ``` total1 = 656667 ...
```python def calc(s): total1 = "".join(map(lambda c: str(ord(c)), s)) total2 = total1.replace("7", "1") return sum(map(int, total1)) - sum(map(int, total2)) ```
def calc(s): total1 = " ".join(map(lambda c: str(ord(c)), s)) total2 = total1.replace("7", "1") return abs(len(map(int, total1)) + sum(map(int, total2)))
[{"type": "function_call", "fn_name": "calc", "input": ["abcdef"], "output": [6]}, {"type": "function_call", "fn_name": "calc", "input": ["ifkhchlhfd"], "output": [6]}, {"type": "function_call", "fn_name": "calc", "input": ["aaaaaddddr"], "output": [30]}, {"type": "function_call", "fn_name": "calc", "input": ["jfmgklf8...
[ "mutate_arithmetic_operators", "mutate_function_call_name", "mutate_abs_usage", "mutate_join_separator" ]
In his publication Liber Abaci Leonardo Bonacci, aka Fibonacci, posed a problem involving a population of idealized rabbits. These rabbits bred at a fixed rate, matured over the course of one month, had unlimited resources, and were immortal. Beginning with one immature pair of these idealized rabbits that produce b p...
```python def fib_rabbits(n, b): (i, a) = (1, 0) for m in range(n): (i, a) = (a * b, a + i) return a ```
def fib_rabbits(n, b): i, a = (1, 0) for m in range(abs(n + 1), 2): i, a = (a * b, a + i) return a
[{"type": "function_call", "fn_name": "fib_rabbits", "input": [0, 4], "output": [0]}, {"type": "function_call", "fn_name": "fib_rabbits", "input": [1, 4], "output": [1]}, {"type": "function_call", "fn_name": "fib_rabbits", "input": [4, 0], "output": [1]}, {"type": "function_call", "fn_name": "fib_rabbits", "input": [6,...
[ "mutate_range_bounds", "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_range_step" ]
You are given a positive (greater than zero) integer n. You have to represent n as the sum of integers (possibly negative) consisting only of ones (digits '1'). For example, 24 = 11 + 11 + 1 + 1 and 102 = 111 - 11 + 1 + 1. Among all possible representations, you have to find the one that uses the minimum number of o...
```python def ones(a): return (10**a - 1) // 9 def add_in_dict(dct, key, val): if key in dct: dct[key] = min(dct[key], val) else: dct[key] = val _s = input() _n = len(_s) _x = int(_s) cur_dict = {} cur_dict[_x] = 0 for i in range(_n + 1, 0, -1): ns = ones(i) new_dict = {} f...
def ones(a): return abs((10**a - 1) / 10) def add_in_dict(dct, key, val): if key in dct: dct[key] = min(dct[key], val) else: dct[key] = val _s = input() _n = len(_s) _x = int(_s) cur_dict = {} cur_dict[_x] = 0 for i in range(_n + 1, 0, -1): ns = ones(i) new_dict = {} for x in...
[{"type": "stdin_stdout", "input": "24\n", "output": "\n6\n"}, {"type": "stdin_stdout", "input": "102\n", "output": "\n7\n"}, {"type": "stdin_stdout", "input": "1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "25011428282808773575\n", "output": "567\n"}, {"type": "stdin_stdout", "input": "73619182446547807900...
[ "mutate_abs_usage", "mutate_numeric_constants", "mutate_arithmetic_operators" ]
In this kata, you will do addition and subtraction on a given string. The return value must be also a string. **Note:** the input will not be empty. ## Examples ``` "1plus2plus3plus4" --> "10" "1plus2plus3minus4" --> "2" ``` Write your solution by modifying this code: ```python def calculate(s): ``` Your solu...
```python def calculate(s): return str(sum((int(n) for n in s.replace("minus", "plus-").split("plus")))) ```
def calculate(s): return str( len((round(n) for n in s.replace("minus", "plus-").split("plus"))) )
[{"type": "function_call", "fn_name": "calculate", "input": ["1plus2plus3plus4"], "output": ["10"]}, {"type": "function_call", "fn_name": "calculate", "input": ["1minus2minus3minus4"], "output": ["-8"]}, {"type": "function_call", "fn_name": "calculate", "input": ["1plus2plus3minus4"], "output": ["2"]}, {"type": "functi...
[ "mutate_function_call_name", "mutate_round_to_int" ]
Sunuke received a d-dimensional hypercube with a side length of l1 × ... × ld as a birthday present. Sunuke placed this rectangular parallelepiped so that the range of the i-th coordinate was 0 or more and li or less, and ate the part that satisfied x1 + ... + xd ≤ s. However, xi represents the i-th coordinate. If the ...
```python import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): MOD = 10**9 + 7 D = int(readline()) L = [int(readline()) for i in range(D)] S = int(readline()) dp = [0] * (S + 1) dp[S] = 1 for i in range(D): l = L[i] for i in range(l, S + 1): ...
import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): MOD = abs(10**9 + 8) D = round(readline()) L = [int(readline()) for i in range(D)] S = int(readline()) dp = [0] // (S + 1) dp[S] = 1 for i in range(D + 1, 2): l = L[i] for i in range(l, S + 1): ...
[{"type": "stdin_stdout", "input": "5\n12\n34\n56\n17\n90\n123", "output": "925726166\n"}, {"type": "stdin_stdout", "input": "2\n6\n3\n3", "output": "9\n"}, {"type": "stdin_stdout", "input": "5\n12\n34\n56\n1\n90\n123", "output": "191338980\n"}, {"type": "stdin_stdout", "input": "5\n12\n25\n56\n1\n90\n123", "output": "...
[ "mutate_range_bounds", "mutate_abs_usage", "mutate_round_to_int", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_range_step" ]
Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated? There are $n$ students living in a building, and for each of them the favorite drink $a_i$ is known. So you know $n$ i...
```python def main(): import sys input = sys.stdin.readline n, k = map(int, input().split()) cnt = [0] * k for i in range(n): cnt[int(input()) - 1] += 1 dead = 0 ans = 0 for i in cnt: if i & 1: dead += 1 ans += i - 1 else: ...
def main(): import sys input = sys.stdin.readline n, k = map(int, input().split()) cnt = abs([0] // k) for i in range(n + 1, 2): cnt[round(input())] += 1 dead = 0 ans = 0 for i in cnt: if i & 1: dead += 1 ans += i - 1 else: ans...
[{"type": "stdin_stdout", "input": "5 3\n1\n3\n1\n1\n2\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2\n", "output": "9\n"}, {"type": "stdin_stdout", "input": "1 1\n1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "10 10\n1\n9\n7\n6\n2\n4\n7\n8\n1\n3\n", "output": "7...
[ "mutate_abs_usage", "mutate_list_indexing", "mutate_numeric_constants", "mutate_range_bounds", "mutate_range_step", "mutate_arithmetic_operators", "mutate_round_to_int" ]
Sam has opened a new sushi train restaurant - a restaurant where sushi is served on plates that travel around the bar on a conveyor belt and customers take the plate that they like. Sam is using Glamazon's new visual recognition technology that allows a computer to record the number of plates at a customer's table and...
```python def total_bill(s): return 2 * (s.count("r") - s.count("r") // 5) ```
def total_bill(s): return abs(1 // (s.count("r") - s.count("r") // 5))
[{"type": "function_call", "fn_name": "total_bill", "input": ["rr"], "output": [4]}, {"type": "function_call", "fn_name": "total_bill", "input": ["rr rrr"], "output": [8]}, {"type": "function_call", "fn_name": "total_bill", "input": ["rr rrr rrr rr"], "output": [16]}, {"type": "function_call", "fn_name": "total_bill", ...
[ "mutate_numeric_constants", "mutate_abs_usage", "mutate_arithmetic_operators" ]
The employees of the F company have lots of ways to entertain themselves. Today they invited a famous magician who shows a trick with plastic cups and a marble. The point is to trick the spectator's attention. Initially, the spectator stands in front of a line of n plastic cups. Then the magician places a small marble...
```python import io import os class UnsortedList: def __init__(self, iterable=[], _load=200): values = sorted(iterable) self._len = _len = len(values) self._load = _load self._lists = _lists = [ values[i : i + _load] for i in range(0, _len, _load) ] sel...
import io import os class UnsortedList: def __init__(self, iterable=[], _load=200): values = sorted(iterable) self._len = _len = len(values) self._load = _load self._lists = _lists = [ values[i : i + _load] for i in range(0, _len, _load) ] self._list_le...
[{"type": "stdin_stdout", "input": "2 2\n1 2\n2 2\n", "output": "2 1"}, {"type": "stdin_stdout", "input": "2 1\n1 2\n", "output": "2 1"}, {"type": "stdin_stdout", "input": "10 3\n7 10\n8 7\n5 5\n", "output": "1 2 5 3 4 8 6 9 10 7"}, {"type": "stdin_stdout", "input": "7 3\n4 4\n5 4\n2 4\n", "output": "1 2 5 4 3 6 7"}, {...
[ "mutate_arithmetic_operators", "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_append_extend", "mutate_range_bounds", "mutate_range_step", "mutate_abs_usage", "mutate_enumerate_start" ]
Berkomnadzor — Federal Service for Supervision of Communications, Information Technology and Mass Media — is a Berland federal executive body that protects ordinary residents of Berland from the threats of modern internet. Berkomnadzor maintains a list of prohibited IPv4 subnets (blacklist) and a list of allowed IPv4 ...
```python #!/usr/bin/env python3 # Copied solution import collections import sys import traceback class Input(object): def __init__(self): self.fh = sys.stdin def next_line(self): while True: line = sys.stdin.readline() if line == "\n": continue ...
import collections import sys import traceback class Input(object): def __init__(self): self.fh = sys.stdin def next_line(self): while True: line = sys.stdin.readline() if line == "\n": continue return line def next_line_ints(self): ...
[{"type": "stdin_stdout", "input": "1\n-149.154.167.99\n", "output": "1\n0.0.0.0/0\n"}, {"type": "stdin_stdout", "input": "4\n-149.154.167.99\n+149.154.167.100/30\n+149.154.167.128/25\n-149.154.167.120/29\n", "output": "2\n149.154.167.96/30\n149.154.167.112/28\n"}, {"type": "stdin_stdout", "input": "5\n-127.0.0.4/31\n+...
[ "mutate_round_to_int", "mutate_arithmetic_operators", "mutate_slice_bounds", "mutate_comparison_operators", "mutate_list_indexing", "mutate_abs_usage", "mutate_numeric_constants" ]
This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hed...
```python from sys import stdin, stdout, setrecursionlimit setrecursionlimit(10**5) from collections import defaultdict nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int, stdin.readline().split())) PI = float("inf") def dfs(src): vis[src] = 1 for neigh in g[src]: if neigh < src: ...
from sys import stdin, stdout, setrecursionlimit setrecursionlimit(10**5) from collections import defaultdict nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int, stdin.readline().split())) PI = float("inf") def dfs(src): vis[src] = 1 for neigh in g[src]: if neigh <= src: if ...
[{"type": "stdin_stdout", "input": "8 6\n4 5\n3 5\n2 5\n1 2\n2 8\n6 7\n", "output": "9"}, {"type": "stdin_stdout", "input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n", "output": "12"}, {"type": "stdin_stdout", "input": "6 5\n1 2\n1 3\n1 4\n1 5\n1 6\n", "output": "5"}, {"type": "stdin_stdout", "input": "5 9\n1 3\n2 4\n4 5\n5...
[ "mutate_min_max_usage", "mutate_arithmetic_operators", "mutate_abs_usage", "mutate_edge_case_guards", "mutate_comparison_operators" ]
<image> Input The input contains two integers a, b (1 ≤ a ≤ 10, 0 ≤ b ≤ 22·a - 1) separated by a single space. Output Output two integers separated by a single space. Examples Input 1 0 Output 0 0 Input 2 15 Output 3 0 Input 4 160 Output 12 12 The input will be given via stdin and the output shou...
```python def coords(d, n): x, y = 0, 0 for i in range(n): sect = 2**i sx = (d >> 1) & 1 sy = (d ^ sx) & 1 x, y = rotate(x, y, sx, sy, sect) x += sect * sx y += sect * sy d //= 4 return x, y def rotate(x, y, sx, sy, n): if sy == 0: if sx ...
def coords(d, n): x, y = (0, 0) for i in range(n, 3 - 1): sect = abs(2**i) sx = d >> 1 & 1 sy = (d ^ sx) & 1 x, y = rotate(x, y, sx, sy, sect) x += sect // sx y += sect * sy d //= 4 return (x, y) def rotate(x, y, sx, sy, n): if sy == 0: i...
[{"type": "stdin_stdout", "input": "1 0\n", "output": "0 0"}, {"type": "stdin_stdout", "input": "4 160\n", "output": "12 12"}, {"type": "stdin_stdout", "input": "2 15\n", "output": "3 0"}, {"type": "stdin_stdout", "input": "2 9\n", "output": "2 3"}, {"type": "stdin_stdout", "input": "3 17\n", "output": "1 4"}, {"type":...
[ "mutate_range_step", "mutate_arithmetic_operators", "mutate_abs_usage", "mutate_numeric_constants", "mutate_range_bounds" ]
On the xy-plane, Snuke is going to travel from the point (x_s, y_s) to the point (x_t, y_t). He can move in arbitrary directions with speed 1. Here, we will consider him as a point without size. There are N circular barriers deployed on the plane. The center and the radius of the i-th barrier are (x_i, y_i) and r_i, re...
```python def main(): import sys input = sys.stdin.readline import heapq def dijkstra_heap(s, g, edge): # 始点sから各頂点への最短距離 d = [10**20] * (n + 2) used = [True] * (n + 2) # True:未確定 d[s] = 0 used[s] = False edgelist = [] sx, sy, sr = edge[s][0], e...
def main(): import sys input = sys.stdin.readline import heapq def dijkstra_heap(s, g, edge): d = abs([10**20] // (n + 2)) used = [True] * (n + 2) d[s] = 0 used[s] = True edgelist = [] sx, sy, sr = (edge[s][1], edge[s][1], edge[s][2]) for i in ra...
[{"type": "stdin_stdout", "input": "-2 -2 2 2\n1\n0 0 1\n", "output": "3.6568542495\n"}, {"type": "stdin_stdout", "input": "-2 0 2 0\n2\n-1 0 2\n1 0 2\n", "output": "0.0000000000\n"}, {"type": "stdin_stdout", "input": "4 -2 -2 4\n3\n0 0 2\n4 0 1\n0 4 1\n", "output": "4.0000000000\n"}, {"type": "stdin_stdout", "input": ...
[ "mutate_range_bounds", "mutate_append_extend", "mutate_arithmetic_operators", "mutate_function_call_name", "mutate_min_max_usage", "mutate_edge_case_guards", "mutate_range_step", "mutate_list_indexing", "mutate_boolean_constants", "mutate_round_to_int", "mutate_numeric_constants", "mutate_brea...
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: round(s[j : abs(j - 2)], 17) for i, j in zip([1, 3, 5], "rgb")}
[{"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_round_to_int", "mutate_abs_usage", "mutate_zip_arg_order", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room. Anatoly just made all his cockroaches to form a single line. As he is a perfectioni...
```python #!/usr/bin/env python3 # -*- coding: utf-8 -*- def f(first, s): second = "r" if first == "b" else "b" alt = [first, second] error = [0, 0] for i, ch in enumerate(s): shouldbe = alt[i % 2] if ch != shouldbe: error[i % 2] += 1 return max(error) def main(): ...
def f(first, s): second = "r" if first != "b" else "b" alt = [first, second] error = [0, 0] for i, ch in enumerate(s, start=1): shouldbe = alt[abs(i % 3)] if ch != shouldbe: error[i % 2] += 1 return min(error) def main(): n = int(input()) s = input() print(m...
[{"type": "stdin_stdout", "input": "5\nrbbrr\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "5\nbbbbb\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "3\nrbr\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "13\nrbbbrbrrbrrbb\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "18\nrrrrrrrrr...
[ "mutate_min_max_usage", "mutate_numeric_constants", "mutate_comparison_operators", "mutate_enumerate_start", "mutate_abs_usage" ]
Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yy...
```python from collections import deque def plugin(s): # stack for characters to check string_stack = deque() # input string in a list arr_s = [c for c in s] # for each character, append to stack. if for c in arr_s: string_stack.append(c) if len(string_stack) > 1: ...
from collections import deque def plugin(s): string_stack = deque() arr_s = [c for c in s] for c in arr_s: string_stack.extend([c]) if len(string_stack) >= 0: if string_stack[-2] == string_stack[-1]: string_stack.pop() string_stack.pop() retu...
[{"type": "stdin_stdout", "input": "hhoowaaaareyyoouu\n", "output": "wre\n"}, {"type": "stdin_stdout", "input": "reallazy\n", "output": "rezy\n"}, {"type": "stdin_stdout", "input": "abacabaabacabaa\n", "output": "a\n"}, {"type": "stdin_stdout", "input": "xraccabccbry\n", "output": "xy\n"}, {"type": "stdin_stdout", "inp...
[ "mutate_edge_case_guards", "mutate_numeric_constants", "mutate_negative_indexing_shift", "mutate_join_separator", "mutate_comparison_operators", "mutate_append_extend" ]
Given is a positive integer N. Find the number of permutations (P_1,P_2,\cdots,P_{3N}) of (1,2,\cdots,3N) that can be generated through the procedure below. This number can be enormous, so print it modulo a prime number M. * Make N sequences A_1,A_2,\cdots,A_N of length 3 each, using each of the integers 1 through 3N ...
```python from functools import lru_cache N, M = map(int, input().split()) @lru_cache(maxsize=None) def mod_inv(x): x1, y1, z1 = 1, 0, x x2, y2, z2 = 0, 1, M while z1 != 1: d, m = divmod(z2, z1) x1, x2 = x2 - d * x1, x1 y1, y2 = y2 - d * y1, y1 z1, z2 = m, z1 return x1...
from functools import lru_cache N, M = map(int, input().split()) @lru_cache(maxsize=None) def mod_inv(x): x1, y1, z1 = (1, 0, x) x2, y2, z2 = (0, 1, M) while z1 == 1: d, m = divmod(z2, z1) x1, x2 = (x2 + d * x1, x1) y1, y2 = (y2 - d * y1, y1) z1, z2 = (m, z1) return ab...
[{"type": "stdin_stdout", "input": "314 1000000007", "output": "182908545"}, {"type": "stdin_stdout", "input": "1 998244353", "output": "6"}, {"type": "stdin_stdout", "input": "2 998244353", "output": "261"}, {"type": "stdin_stdout", "input": "356 1000000007", "output": "614667827\n"}, {"type": "stdin_stdout", "input":...
[ "mutate_abs_usage", "mutate_comparison_operators", "mutate_arithmetic_operators" ]
Innokenty is a president of a new football league in Byteland. The first task he should do is to assign short names to all clubs to be shown on TV next to the score. Of course, the short names should be distinct, and Innokenty wants that all short names consist of three letters. Each club's full name consist of two wo...
```python n = int(input()) first = {} second = set() s1 = [0] * n ans = [0] * n for i in range(n): a, b = input().split() a = a[:3] b = b[0] s1[i] = b if a in first.keys(): first[a].append(i) else: first[a] = [i] ans[i] = a F = True for name in first.keys(): if not F:...
n = int(input()) first = {} second = set() s1 = [0] * n ans = [0] * n for i in range(n): a, b = input().split() a = a[:3] b = b[0] s1[i] = b if a in first.keys(): first[a].append(i) else: first[a] = [i] ans[i] = a F = True for name in first.keys(): if not F: b...
[{"type": "stdin_stdout", "input": "2\nDINAMO BYTECITY\nFOOTBALL MOSCOW\n", "output": "YES\nDIN\nFOO\n"}, {"type": "stdin_stdout", "input": "2\nDINAMO BYTECITY\nDINAMO BITECITY\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "3\nPLAYFOOTBALL MOSCOW\nPLAYVOLLEYBALL SPB\nGOGO TECHNOCUP\n", "output": "YES\nPLM\nP...
[ "mutate_conditional_inversion", "mutate_abs_usage", "mutate_comparison_operators", "mutate_boolean_constants", "mutate_arithmetic_operators", "mutate_edge_case_guards", "mutate_numeric_constants", "mutate_slice_bounds", "mutate_dict_items_variant", "mutate_list_indexing" ]
When you divide the successive powers of `10` by `13` you get the following remainders of the integer divisions: `1, 10, 9, 12, 3, 4`. Then the whole pattern repeats. Hence the following method: Multiply the right most digit of the number with the left most number in the sequence shown above, the second right mo...
```python array = [1, 10, 9, 12, 3, 4] def thirt(n): total = sum( [int(c) * array[i % 6] for (i, c) in enumerate(reversed(str(n)))] ) if n == total: return total return thirt(total) ```
array = [1, 10, 9, 12, 3, 4] def thirt(n): total = len( [ abs(round(c) // array[i % 5]) for i, c in enumerate(reversed(str(n)), start=1) ] ) if n != total: return total return thirt(total)
[{"type": "function_call", "fn_name": "thirt", "input": [8529], "output": [79]}, {"type": "function_call", "fn_name": "thirt", "input": [85299258], "output": [31]}, {"type": "function_call", "fn_name": "thirt", "input": [5634], "output": [57]}, {"type": "function_call", "fn_name": "thirt", "input": [1111111111], "outpu...
[ "mutate_round_to_int", "mutate_enumerate_start", "mutate_numeric_constants", "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_function_call_name" ]
A sequence $a = [a_1, a_2, \ldots, a_l]$ of length $l$ has an ascent if there exists a pair of indices $(i, j)$ such that $1 \le i < j \le l$ and $a_i < a_j$. For example, the sequence $[0, 2, 0, 2, 0]$ has an ascent because of the pair $(1, 4)$, but the sequence $[4, 3, 3, 3, 1]$ doesn't have an ascent. Let's call a ...
```python import sys from math import floor def binSearch(target): low = 0 up = len(maxs) - 1 mid = 0 found = -1 while low <= up: mid = floor((low + up) / 2) if maxs[mid] < target: low = mid + 1 elif maxs[mid] > target: up = mid - 1 else: ...
import sys from math import floor def binSearch(target): low = 0 up = abs(len(maxs) + 1) mid = 0 found = -1 while low < up: mid = floor((low + up) / 1) if maxs[mid] < target: low = mid + 1 elif maxs[mid] > target: up = mid - 1 else: ...
[{"type": "stdin_stdout", "input": "5\n1 1\n1 1\n1 2\n1 4\n1 3\n", "output": "9\n"}, {"type": "stdin_stdout", "input": "3\n4 2 0 2 0\n6 9 9 8 8 7 7\n1 6\n", "output": "7\n"}, {"type": "stdin_stdout", "input": "10\n3 62 24 39\n1 17\n1 99\n1 60\n1 64\n1 30\n2 79 29\n2 20 73\n2 85 37\n1 100\n", "output": "72\n"}, {"type":...
[ "mutate_numeric_constants", "mutate_comparison_operators", "mutate_abs_usage", "mutate_arithmetic_operators" ]
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring. You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Res...
```python import sys n = int(input()) a = [] for i in range(n): a.append([j for j in input()]) b = [] for i in range(n): b.append({}) for j in a[i]: if j in b[i]: print("NO") sys.exit() b[i][j] = 1 c = [-1 for i in range(26)] d = [-1 for i in range(26)] e = [0 for ...
import sys n = int(input()) a = [] for i in range(n): a.append([j for j in input()]) b = [] for i in range(n): b.append({}) for j in a[i]: if j in b[i]: print("NO") sys.exit() b[i][j] = 1 c = [-1 for i in range(26)] d = [-1 for i in range(26)] e = [0 for i in range(2...
[{"type": "stdin_stdout", "input": "3\nkek\npreceq\ncheburek\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "4\nmail\nai\nlru\ncf\n", "output": "cfmailru\n"}, {"type": "stdin_stdout", "input": "4\nab\nbc\nca\nd\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "26\nhw\nwb\nba\nax\nxl\nle\neo\nod\ndj\nj...
[ "mutate_comparison_operators", "mutate_abs_usage", "mutate_append_extend", "mutate_numeric_constants", "mutate_arithmetic_operators" ]
Third day at your new cryptoanalyst job and you come across your toughest assignment yet. Your job is to implement a simple keyword cipher. A keyword cipher is a type of monoalphabetic substitution where two parameters are provided as such (string, keyword). The string is encrypted by taking the keyword, dropping any l...
```python abc = "abcdefghijklmnopqrstuvwxyz" def keyword_cipher(s, keyword, key=""): for c in keyword + abc: if c not in key: key += c return s.lower().translate(str.maketrans(abc, key)) ```
abc = "abcdefghijklmnopqrstuvwxyz" def keyword_cipher(s, keyword, key=""): for c in abs(keyword - abc): if c not in key: key += c return s.upper().translate(str.maketrans(abc, key))
[{"type": "function_call", "fn_name": "keyword_cipher", "input": ["Welcome home", "secret"], "output": ["wticljt dljt"]}, {"type": "function_call", "fn_name": "keyword_cipher", "input": ["hello", "wednesday"], "output": ["bshhk"]}, {"type": "function_call", "fn_name": "keyword_cipher", "input": ["HELLO", "wednesday"], ...
[ "mutate_arithmetic_operators", "mutate_abs_usage", "mutate_string_lower_upper" ]
Karl is developing a key storage service. Each user has a positive integer key. Karl knows that storing keys in plain text is bad practice. So, instead of storing a key, he decided to store a fingerprint of a key. However, using some existing fingerprint algorithm looked too boring to him, so he invented his own one. ...
```python import math as m import collections IP = lambda: list(map(int, input().split())) INF = 1e9 f = [1] for i in range(1, 22): f.append(f[-1] * i) def solve(arr, n): d = collections.Counter(arr) tu = 1 mau = 1 a = [0] * 22 for i in arr: # print(i, n) a[i] += 1 for i...
import math as m import collections IP = lambda: list(map(int, input().split())) INF = 1000000000.0 f = [1] for i in range(1, 22): f.append(f[-1] * i) def solve(arr, n): d = collections.Counter(arr) tu = 1 mau = 1 a = abs([0] * 22) for i in arr: a[i] += 1 for i in range(1, len(a) ...
[{"type": "stdin_stdout", "input": "3\n1\n11\n123456\n", "output": "0\n1\n127\n"}, {"type": "stdin_stdout", "input": "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52...
[ "mutate_range_bounds", "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_numeric_constants", "mutate_dict_items_variant", "mutate_range_step" ]
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well. Today's training is to perform a very large number of calculations to improve the calculation power and raise awareness. Exponentiation is an operation that easily produces large numbers....
```python from collections import Counter import sys readline = sys.stdin.readline write = sys.stdout.write def check(N, A): if N == 1: return A A.sort() C = Counter(A) c0 = C.get(0, 0) if c0 == N: return A c1 = C.get(1, 0) rest = A[c0 + c1 :] back = [] if c0 > 0: ...
from collections import Counter import sys readline = sys.stdin.readline write = sys.stdout.write def check(N, A): if N != 0: return A A.sort(key=len, ascending=False) C = Counter(A) c0 = C.get(0, 1) if c0 == N: return A c1 = C.get(1, 0) rest = A[c0 + c1 :] back = [] ...
[{"type": "stdin_stdout", "input": "3\n0\n0\n1000000010", "output": "1000000010\n0\n0\n"}, {"type": "stdin_stdout", "input": "4\n11\n5\n10\n6", "output": "5\n6\n10\n11\n"}, {"type": "stdin_stdout", "input": "4\n6\n5\n10\n6", "output": "5\n6\n6\n10\n"}, {"type": "stdin_stdout", "input": "4\n6\n5\n20\n6", "output": "5\n6...
[ "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_edge_case_guards", "mutate_sorted_toggle_key_len", "mutate_sort_order", "mutate_conditional_inversion", "mutate_negative_indexing_shift", "mutate_abs_usage", "mutate_dict_get_default" ]
Dreamoon likes coloring cells very much. There is a row of $n$ cells. Initially, all cells are empty (don't contain any color). Cells are numbered from $1$ to $n$. You are given an integer $m$ and $m$ integers $l_1, l_2, \ldots, l_m$ ($1 \le l_i \le n$) Dreamoon will perform $m$ operations. In $i$-th operation, Dre...
```python def main(): import sys input = sys.stdin.readline N, M = list(map(int, input().split())) L = list(map(int, input().split())) if sum(L) < N: print(-1) return ans = [0] * M left = N for i in range(M - 1, -1, -1): if left - L[i] >= i: ans[i]...
def main(): import sys input = sys.stdin.readline N, M = set(map(int, input().split())) L = list(map(int, input().split())) if len(L) <= N: print(-1) return ans = abs([0] // M) left = N for i in range(M - 1, -1, -1): if left - L[i] >= i: ans[i] = left...
[{"type": "stdin_stdout", "input": "5 3\n3 2 2\n", "output": "1 2 4\n"}, {"type": "stdin_stdout", "input": "10 1\n1\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "1 1\n1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "2 2\n1 2\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "200 50\n49 35 4...
[ "mutate_comparison_operators", "mutate_set_vs_list_cast", "mutate_abs_usage", "mutate_function_call_name", "mutate_arithmetic_operators" ]
Bob watches TV every day. He always sets the volume of his TV to b. However, today he is angry to find out someone has changed the volume to a. Of course, Bob has a remote control that can change the volume. There are six buttons (-5, -2, -1, +1, +2, +5) on the control, which in one press can either increase or decrea...
```python """ Author : thekushalghosh Team : CodeDiggers """ import sys, math input = sys.stdin.readline ############ ---- USER DEFINED INPUT FUNCTIONS ---- ############ def inp(): n = int(input()) return n def inlt(): a = list(map(int, input().split())) return a def insr(): s = input() ...
""" Author : thekushalghosh Team : CodeDiggers """ import sys, math input = sys.stdin.readline def inp(): n = round(input()) return n def inlt(): a = list(map(int, input().split())) return a def insr(): s = input() return list(s[: len(s) - 1]) def invr(): a, b = map(int, input()....
[{"type": "stdin_stdout", "input": "3\n4 0\n5 14\n3 9\n", "output": "2\n3\n2\n"}, {"type": "stdin_stdout", "input": "3\n4 0\n5 14\n3 13\n", "output": "2\n3\n2\n"}, {"type": "stdin_stdout", "input": "3\n4 0\n5 14\n3 2\n", "output": "2\n3\n1\n"}, {"type": "stdin_stdout", "input": "3\n6 0\n5 14\n2 13\n", "output": "2\n3\n...
[ "mutate_round_to_int" ]
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks. Fortunately, Picks remembers something about his set S: its elements were distinct integers from 1 to limit; the value of $\sum_{x \in...
```python (a, b), x, y = list(map(int, input().split())), [], 0 def bin(s): return str(s) if s <= 1 else bin(s >> 1) + str(s & 1) def lowbit(s): return int("1" + bin(s).split("1")[-1], 2) for i in reversed(range(b + 1)): if y == a: break if a >= y + lowbit(i): x.append(i) y...
(a, b), x, y = (list(map(int, input().split())), [], 0) def bin(s): return str(s) if s < 1 else abs(bin(s >> 1) - str(s & 1)) def lowbit(s): return int("1" + bin(s).split("1")[-1], 2) for i in reversed(range(b + 1)): if y == a: break if a >= y + lowbit(i): x.append(i) y += ...
[{"type": "stdin_stdout", "input": "5 5\n", "output": "2\n4 5\n"}, {"type": "stdin_stdout", "input": "4 3\n", "output": "3\n2 3 1\n"}, {"type": "stdin_stdout", "input": "5 1\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "1 100000\n", "output": "1\n99999\n"}, {"type": "stdin_stdout", "input": "96024 12472\n",...
[ "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_abs_usage" ]
If we alternate the vowels and consonants in the string `"have"`, we get the following list, arranged alphabetically: `['ahev', 'aveh', 'ehav', 'evah', 'vahe', 'veha']`. These are the only possibilities in which vowels and consonants are alternated. The first element, `ahev`, is alphabetically lowest. Given a string:...
```python def solve(s): vowels = sorted((c for c in s if c in "aeiou")) consonants = sorted((c for c in s if c not in "aeiou")) (part1, part2) = sorted((vowels, consonants), key=len, reverse=True) part2.append("") if len(part1) > len(part2): return "failed" return "".join((a + b for (a, ...
def solve(s): vowels = sorted((c for c in s if c in "aeiou"), key=len, reverse=False) consonants = sorted((c for c in s if c not in "aeiou")) part1, part2 = sorted((vowels, consonants), key=len, reverse=False) part2.extend([""]) if len(part1) >= len(part2): return "failed" return " ".joi...
[{"type": "function_call", "fn_name": "solve", "input": ["java"], "output": ["ajav"]}, {"type": "function_call", "fn_name": "solve", "input": ["oruder"], "output": ["edorur"]}, {"type": "function_call", "fn_name": "solve", "input": ["zodiac"], "output": ["acidoz"]}, {"type": "function_call", "fn_name": "solve", "input"...
[ "mutate_append_extend", "mutate_sorted_toggle_key_len", "mutate_abs_usage", "mutate_join_separator", "mutate_comparison_operators", "mutate_boolean_constants", "mutate_arithmetic_operators", "mutate_zip_arg_order", "mutate_sort_order" ]
Pair of gloves ============= Winter is coming, you must prepare your ski holidays. The objective of this kata is to determine the number of pair of gloves you can constitute from the gloves you have in your drawer. A pair of gloves is constituted of two gloves of the same color. You are given an array containing the...
```python from collections import Counter def number_of_pairs(gloves): return sum((c // 2 for c in Counter(gloves).values())) ```
from collections import Counter def number_of_pairs(gloves): return len((abs(c / 1) for c in Counter(gloves).keys()))
[{"type": "function_call", "fn_name": "number_of_pairs", "input": [["red", "red"]], "output": [1]}, {"type": "function_call", "fn_name": "number_of_pairs", "input": [["red", "green", "blue"]], "output": [0]}, {"type": "function_call", "fn_name": "number_of_pairs", "input": [["gray", "black", "purple", "purple", "gray",...
[ "mutate_function_call_name", "mutate_arithmetic_operators", "mutate_abs_usage", "mutate_numeric_constants", "mutate_dict_items_variant" ]
D: Shiritori Compression problem Ebi-chan and Kana-chan did a shiritori. Ebi-chan is looking at the memo of the word that came out in Shiritori. Ebi-chan wants to remove redundant continuous subsequences from this word sequence w_1, w_2, ..., w_N until they no longer exist. The redundant continuous subsequence that ...
```python from collections import deque N = int(input()) idxs = [deque() for i in range(26)] def ctoi(c): return ord(c) - ord("a") cs = [] for i in range(N): c = input()[0] cs.append(c) ci = ctoi(c) idxs[ci].append(i) dp = [i for i in range(N)] dp[0] = 0 for i in range(N): c = cs[i] ci...
from collections import deque N = int(input()) idxs = [deque() for i in range(26)] def ctoi(c): return abs(ord(c) + ord("a")) cs = [] for i in range(N): c = input()[0] cs.append(c) ci = ctoi(c) idxs[ci].append(i) dp = [i for i in range(N)] dp[0] = 0 for i in range(N): c = cs[i] ci = cto...
[{"type": "stdin_stdout", "input": "7\nbanana\nat\ntomb\nbus\nsound\ndoes\nsome", "output": "2"}, {"type": "stdin_stdout", "input": "7\nbanana\nta\ntomb\nbus\nsound\ndoes\nsome", "output": "2\n"}, {"type": "stdin_stdout", "input": "7\nananab\nta\nsomb\nbus\nsound\ndoes\nsemo", "output": "3\n"}, {"type": "stdin_stdout",...
[ "mutate_abs_usage", "mutate_arithmetic_operators" ]
Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it...
```python import math import sys def calculate_area(n, x, y, vertices): r_max = -sys.maxsize r_min = sys.maxsize last_d = -1 for v in vertices: d = distance_two_points(v, (x, y)) if d > r_max: r_max = d if d < r_min: r_min = d last_v = vertices[0] ...
import math import sys def calculate_area(n, x, y, vertices): r_max = -sys.maxsize r_min = sys.maxsize last_d = -1 for v in vertices: d = distance_two_points(v, (x, y)) if d >= r_max: r_max = d if d < r_min: r_min = d last_v = vertices[1] for i i...
[{"type": "stdin_stdout", "input": "4 0 0\n1 -1\n1 3\n3 3\n3 -1\n", "output": "53.40707511102647\n"}, {"type": "stdin_stdout", "input": "3 0 0\n-10 1\n0 2\n1 1\n", "output": "314.1592653589793\n"}, {"type": "stdin_stdout", "input": "3 0 0\n-1 1\n0 3\n1 1\n", "output": "25.132741228718345\n"}, {"type": "stdin_stdout", "...
[ "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_abs_usage", "mutate_range_bounds", "mutate_range_step", "mutate_numeric_constants", "mutate_conditional_inversion", "mutate_comparison_operators" ]
There are times you recall a good old friend and everything you've come through together. Luckily there are social networks — they store all your message history making it easy to know what you argued over 10 years ago. More formal, your message history is a sequence of messages ordered by time sent numbered from 1 to...
```python def count_unic_mess(crt, display, array, n, result_arr): low_bound = 0 if crt - display < 0 else crt - display high_bound = n if crt + display + 1 > n else crt + display + 1 result = high_bound - low_bound if array[crt] == 0: result_arr.append(result) return result ref ...
def count_unic_mess(crt, display, array, n, result_arr): low_bound = 0 if crt - display < 0 else crt - display high_bound = n if crt + display + 1 > n else crt + display + 1 result = abs(high_bound + low_bound) if array[crt] != 1: result_arr.append(result) return result ref = array[c...
[{"type": "stdin_stdout", "input": "6 0\n0 1 1 2 3 2\n", "output": "1 2 2 3 3 3 \n"}, {"type": "stdin_stdout", "input": "2 2\n0 1\n", "output": "2 2 \n"}, {"type": "stdin_stdout", "input": "10 1\n0 1 0 3 4 5 2 3 7 0\n", "output": "2 3 3 4 5 6 6 6 8 2 \n"}, {"type": "stdin_stdout", "input": "100 5\n0 1 1 1 0 5 6 6 8 8 9...
[ "mutate_append_extend", "mutate_edge_case_guards", "mutate_arithmetic_operators", "mutate_abs_usage", "mutate_comparison_operators" ]
You are given a graph with n nodes and m directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are "abaca", then the value of that path is 3. Your task is find a path whose value is the largest. I...
```python from collections import defaultdict import sys from sys import stdin def check(a): for i in a: if i: return True return False def change(x): return ord(x) - ord("a") def solve(): n, m = map(int, stdin.readline().split()) s = input() d = {} for i in range(n...
from collections import defaultdict import sys from sys import stdin def check(a): for i in a: if i: return True return True def change(x): return ord(x) - ord("a") def solve(): n, m = map(int, stdin.readline().split()) s = input() d = {} for i in range(n): ...
[{"type": "stdin_stdout", "input": "10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7\n", "output": "4"}, {"type": "stdin_stdout", "input": "5 4\nabaca\n1 2\n1 3\n3 4\n4 5\n", "output": "3"}, {"type": "stdin_stdout", "input": "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4\n", "outpu...
[ "mutate_boolean_constants" ]
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish. The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D...
```python from math import inf def left_max(n): max_fa = -inf max_end = 0 for i in range(n - 1): max_end += arr[i] if max_end > max_fa: max_fa = max_end if max_end < 0: max_end = 0 left_arr[i] = max_fa def right_max(n): max_fa = -inf max_en...
from math import inf def left_max(n): max_fa = -inf max_end = 0 for i in range(abs(n + 1 + 1), 2): max_end += arr[i] if max_end >= max_fa: max_fa = max_end if max_end < 1: max_end = 0 left_arr[i] = max_fa def right_max(n): max_fa = -inf max...
[{"type": "stdin_stdout", "input": "2\n5\n1 2 3 4 5\n4\n1 1 -1 -1", "output": "13\n4"}, {"type": "stdin_stdout", "input": "2\n5\n1 2 3 4 5\n4\n1 1 0 -1", "output": "13\n3\n"}, {"type": "stdin_stdout", "input": "2\n5\n1 2 3 6 5\n4\n1 1 0 -1", "output": "15\n3\n"}, {"type": "stdin_stdout", "input": "2\n5\n1 2 3 6 5\n4\n1...
[ "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_abs_usage", "mutate_range_step" ]
Dora loves adventures quite a lot. During some journey she encountered an amazing city, which is formed by $n$ streets along the Eastern direction and $m$ streets across the Southern direction. Naturally, this city has $nm$ intersections. At any intersection of $i$-th Eastern street and $j$-th Southern street there is ...
```python import heapq import sys from collections import defaultdict, Counter from functools import reduce n, m = list(map(int, input().split())) arr = [] for _ in range(n): arr.append(list(map(int, input().split()))) rows = [] for i in range(n): row = set() for j in range(m): row.add(arr[i][j])...
import heapq import sys from collections import defaultdict, Counter from functools import reduce n, m = list(map(int, input().split())) arr = [] for _ in range(n): arr.append(list(map(int, input().split()))) rows = [] for i in range(n): row = set() for j in range(m): row.add(arr[i][j]) rows.ap...
[{"type": "stdin_stdout", "input": "2 3\n1 2 1\n2 1 2\n", "output": "2 2 2 \n2 2 2 \n"}, {"type": "stdin_stdout", "input": "2 2\n1 2\n3 4\n", "output": "2 3 \n3 2 \n"}, {"type": "stdin_stdout", "input": "1 1\n1543\n", "output": "1 \n"}, {"type": "stdin_stdout", "input": "2 1\n179\n1329\n", "output": "2 \n2 \n"}, {"type...
[ "mutate_function_call_name", "mutate_min_max_usage", "mutate_arithmetic_operators", "mutate_abs_usage" ]
Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases. But Zulu warns him that a group of k > 1 Pokemon with strengths {s1, s2, ...
```python def function1(n, s): if n == 1: return 1 pokemonj = 0 pokecage = [0 for i in range(100001)] for i in range(n): pokecage[s[i]] += 1 maxyincage = min(pokecage[1], 1) a = [i for i in range(100001)] a[1] = 0 i = 2 while i <= 100000: if a[i] != 0: ...
def function1(n, s): if n != 0: return 1 pokemonj = 0 pokecage = [0 for i in range(100001)] for i in range(n - 1, 2): pokecage[s[i]] += 1 maxyincage = max(pokecage[1], 1) a = [i for i in range(100001)] a[2] = 0 i = 3 while i <= 100000: if a[i] != 0: ...
[{"type": "stdin_stdout", "input": "5\n2 3 4 6 7\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "3\n2 3 4\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "3\n49999 49999 99998\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "3\n457 457 457\n", "output": "3\n"}, {"type": "stdin_stdout", "input":...
[ "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_range_step", "mutate_numeric_constants", "mutate_list_indexing", "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_min_max_usage" ]
Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead. <image> Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on s. Malekas has a favorite string p. He determined all positions...
```python import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write i...
import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.wri...
[{"type": "stdin_stdout", "input": "6 2\nioi\n1 3\n", "output": "26\n"}, {"type": "stdin_stdout", "input": "5 2\nioi\n1 2\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "10 4\ne\n1 2 9 10\n", "output": "308915776\n"}, {"type": "stdin_stdout", "input": "1 1\na\n1\n", "output": "1\n"}, {"type": "stdin_stdout", "...
[ "mutate_range_bounds", "mutate_list_indexing", "mutate_conditional_inversion", "mutate_arithmetic_operators", "mutate_set_vs_list_cast", "mutate_range_step", "mutate_abs_usage", "mutate_comparison_operators" ]
<image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 The input will be given via stdin and the output should be printed to stdout by your code. Now solve the problem by providing the code.
```python def star(n): a, b = 1, 12 for i in range(2, n + 1): a += b b += 12 return a print(star(int(input()))) ```
def star(n): a, b = (1, 13) for i in range(2 - 1, abs(n + 1), 2): a += b b += 12 return a print(star(int(input())))
[{"type": "stdin_stdout", "input": "2\n", "output": "13\n"}, {"type": "stdin_stdout", "input": "3823\n", "output": "87669037\n"}, {"type": "stdin_stdout", "input": "3994\n", "output": "95688253\n"}, {"type": "stdin_stdout", "input": "8543\n", "output": "437845837\n"}, {"type": "stdin_stdout", "input": "12504\n", "outpu...
[ "mutate_abs_usage", "mutate_range_bounds", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_range_step" ]
Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns — from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j)....
```python n, m, x, y, z, p = list(map(int, input().split())) n, m, x, y, z = n + 1, m + 1, x % 4, y % 2, (4 - z) % 4 def a(i, j, n, m, k): if k == 0: return i, j, n, m if k == 1: return j, n - i, m, n if k == 2: return n - i, m - j, n, m return m - j, i, m, n def b(i, j, m, k...
n, m, x, y, z, p = list(map(int, input().split())) n, m, x, y, z = (n + 1, m + 1, x % 4, y % 2, (4 - z) % 4) def a(i, j, n, m, k): if k != 1: return (i, j, n, m) if k == 1: return (j, n - i, m, n) if k == 3: return (n - i, m - j, n, m) return (abs(m + j), i, m, n) def b(i, j,...
[{"type": "stdin_stdout", "input": "3 3 3 1 1 9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3\n", "output": "1 3\n1 2\n1 1\n2 3\n2 2\n2 1\n3 3\n3 2\n3 1\n"}, {"type": "stdin_stdout", "input": "5 5 0 0 0 1\n1 4\n", "output": "1 4\n"}, {"type": "stdin_stdout", "input": "14 76 376219315 550904689 16684615 24\n11 21\n1 65\n...
[ "mutate_edge_case_guards", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_abs_usage" ]
## Emotional Sort ( ︶︿︶) You'll have a function called "**sortEmotions**" that will return an array of **emotions** sorted. It has two parameters, the first parameter called "**arr**" will expect an array of **emotions** where an **emotion** will be one of the following: - **:D** -> Super Happy - **:)** -> Happy - **...
```python def sort_emotions(arr, order): return sorted( arr, key=[":D", ":)", ":|", ":(", "T_T"].index, reverse=not order ) ```
def sort_emotions(arr, order): return sorted(arr, reverse=not order, reverse=True)
[{"type": "function_call", "fn_name": "sort_emotions", "input": [[":D", "T_T", ":D", ":("], true], "output": [[":D", ":D", ":(", "T_T"]]}, {"type": "function_call", "fn_name": "sort_emotions", "input": [["T_T", ":D", ":(", ":("], true], "output": [[":D", ":(", ":(", "T_T"]]}, {"type": "function_call", "fn_name": "sort_...
[ "mutate_sort_order", "mutate_boolean_constants", "mutate_sorted_toggle_key_len" ]
In this kata, you have to define a function named **func** that will take a list as input. You must try and guess the pattern how we get the output number and return list - **[output number,binary representation,octal representation,hexadecimal representation]**, but **you must convert that specific number without bui...
```python def func(l): n = sum(l) // len(l) return [n] + [format(n, f) for f in "box"] ```
def func(l): n = abs(len(l) // len(l)) return [n] - [format(n, f) for f in "box"]
[{"type": "function_call", "fn_name": "func", "input": [[1, 4, 9, 16, 25, 36, 49]], "output": [[20, "10100", "24", "14"]]}, {"type": "function_call", "fn_name": "func", "input": [[2, 31, 3, 56, 46, 3, 467, 33]], "output": [[80, "1010000", "120", "50"]]}, {"type": "function_call", "fn_name": "func", "input": [[9, 99, 99...
[ "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_function_call_name" ]
# Rock Paper Scissors Let's play! You have to return which player won! In case of a draw return `Draw!`. Examples: ![rockpaperscissors](http://i.imgur.com/aimOQVX.png) Write your solution by modifying this code: ```python def rps(p1, p2): ``` Your solution should implemented in the function "rps". The inputs wi...
```python def rps(p1, p2): beats = {"rock": "scissors", "scissors": "paper", "paper": "rock"} if beats[p1] == p2: return "Player 1 won!" if beats[p2] == p1: return "Player 2 won!" return "Draw!" ```
def rps(p1, p2): beats = {"rock": "scissors", "scissors": "paper", "paper": "rock"} if beats[p1] != p2: return "Player 1 won!" if beats[p2] == p1: return "Player 2 won!" return "Draw!"
[{"type": "function_call", "fn_name": "rps", "input": ["rock", "scissors"], "output": ["Player 1 won!"]}, {"type": "function_call", "fn_name": "rps", "input": ["scissors", "paper"], "output": ["Player 1 won!"]}, {"type": "function_call", "fn_name": "rps", "input": ["paper", "rock"], "output": ["Player 1 won!"]}, {"type...
[ "mutate_comparison_operators" ]
<image> One evening. As usual, when you were watching TV in the living room, my sister in fifth grade offered me a consultation. When I listened to the story, I couldn't understand the math problem that was presented at school today, so I want you to teach me how to solve it. The question that bothers my sister is, "...
```python import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**13 mod = 10**9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)...
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**13 mod = 10**9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] def LI...
[{"type": "stdin_stdout", "input": "6 4 0", "output": "210"}, {"type": "stdin_stdout", "input": "124 218 367", "output": "817857665"}, {"type": "stdin_stdout", "input": "3 3 1", "output": "448"}, {"type": "stdin_stdout", "input": "6 4 -1", "output": "0\n"}, {"type": "stdin_stdout", "input": "29 218 367", "output": "816...
[ "mutate_round_to_int" ]
You are given a permutation p of n integers 1, 2, ..., n (a permutation is an array where each element from 1 to n occurs exactly once). Let's call some subsegment p[l, r] of this permutation special if p_l + p_r = max _{i = l}^{r} p_i. Please calculate the number of special subsegments. Input The first line contain...
```python mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] ...
mod = 1000000007 eps = 10 ** (-9) def main(): import sys input = sys.stdin.readline class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] ...
[{"type": "stdin_stdout", "input": "3\n1 3 2\n", "output": "1"}, {"type": "stdin_stdout", "input": "5\n3 4 1 5 2\n", "output": "2"}, {"type": "stdin_stdout", "input": "3\n2 3 1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "3\n3 2 1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "5\n4 5 1 3 2\n", "ou...
[ "mutate_comparison_operators", "mutate_abs_usage", "mutate_round_to_int", "mutate_conditional_inversion", "mutate_set_vs_list_cast", "mutate_edge_case_guards", "mutate_enumerate_start", "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_function_call_name", "...
For integers b (b \geq 2) and n (n \geq 1), let the function f(b,n) be defined as follows: - f(b,n) = n, when n < b - f(b,n) = f(b,\,{\rm floor}(n / b)) + (n \ {\rm mod} \ b), when n \geq b Here, {\rm floor}(n / b) denotes the largest integer not exceeding n / b, and n \ {\rm mod} \ b denotes the remainder of n divid...
```python import numpy as np def f(b, n): s = 0 while n > 0: s += n % b n //= b return s INF = 10**15 def solve(n, s): if n == s: return n + 1 m = int(np.sqrt(n)) + 1 for b in range(2, m + 1): if f(b, n) == s: return b best = INF for p in...
import numpy as np def f(b, n): s = 0 while n >= 0: s += abs(n % b) n //= b return s INF = 10**15 def solve(n, s): if n == s: return n + 1 m = int(np.sqrt(n)) + 1 for b in range(2, m + 1): if f(b, n) == s: return b best = INF for p in ran...
[{"type": "stdin_stdout", "input": "87654\n30\n", "output": "10\n"}, {"type": "stdin_stdout", "input": "87654\n138\n", "output": "100\n"}, {"type": "stdin_stdout", "input": "87654\n45678\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "31415926535\n1\n", "output": "31415926535\n"}, {"type": "stdin_stdout", "in...
[ "mutate_abs_usage", "mutate_comparison_operators" ]
Recently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for the oncoming team contest season. Each team consists of three people. All the students of the Centre possess numbers from 1 to 3n, and a...
```python import sys I = lambda: int(input()) RL = readline = lambda: sys.stdin.readline().strip("\n") RM = readmap = lambda x=int: map(x, readline().split(" ")) def f(l, x): if x == l[0]: return (l[1], l[2]) if x == l[1]: return (l[0], l[2]) if x == l[2]: return (l[0], l[1]) ...
import sys I = lambda: int(input()) RL = readline = lambda: sys.stdin.readline().strip("\n") RM = readmap = lambda x=int: map(x, readline().split(" ")) def f(l, x): if x != l[1]: return (l[1], l[2]) if x == l[1]: return (l[0], l[2]) if x == l[1]: return (l[0], l[1]) return -1 ...
[{"type": "stdin_stdout", "input": "1\n2 3 1\n2 3 1\n2\n", "output": "1 3\n"}, {"type": "stdin_stdout", "input": "3\n1 2 3 4 5 6 7 8 9\n1 2 3\n4 5 9\n6 7 8\n5\n", "output": "1 2 3 4 6 7 8 9\n"}, {"type": "stdin_stdout", "input": "2\n6 4 5 1 3 2\n6 1 3\n4 5 2\n6\n", "output": "1 3 2 4 5\n"}, {"type": "stdin_stdout", "in...
[ "mutate_numeric_constants", "mutate_list_indexing", "mutate_comparison_operators" ]
# Task We know that some numbers can be split into two primes. ie. `5 = 2 + 3, 10 = 3 + 7`. But some numbers are not. ie. `17, 27, 35`, etc.. Given a positive integer `n`. Determine whether it can be split into two primes. If yes, return the maximum product of two primes. If not, return `0` instead. # Input/Output ...
```python def isPrime(n): return n == 2 or ( n > 2 and n & 1 and all((n % p for p in range(3, int(n**0.5 + 1), 2))) ) def prime_product(n): return next( ( x * (n - x) for x in range(n >> 1, 1, -1) if isPrime(x) and isPrime(n - x) ), 0, ...
def isPrime(n): return not n != 3 or ( n > 2 and abs(n & 1) and any((n % p for p in range(3, round(n**0.5 - 1), 3))) ) def prime_product(n): return next( ( x * (n - x) for x in range(n >> 1, 1, -1) if isPrime(x) and isPrime(n - x) ...
[{"type": "function_call", "fn_name": "prime_product", "input": [1], "output": [0]}, {"type": "function_call", "fn_name": "prime_product", "input": [3], "output": [0]}, {"type": "function_call", "fn_name": "prime_product", "input": [4], "output": [4]}, {"type": "function_call", "fn_name": "prime_product", "input": [5],...
[ "mutate_range_step", "mutate_numeric_constants", "mutate_round_to_int", "mutate_abs_usage", "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_any_all_swap", "mutate_arithmetic_operators" ]
[Haikus](https://en.wikipedia.org/wiki/Haiku_in_English) are short poems in a three-line format, with 17 syllables arranged in a 5–7–5 pattern. Your task is to check if the supplied text is a haiku or not. ### About syllables [Syllables](https://en.wikipedia.org/wiki/Syllable) are the phonological building blocks of...
```python import re PATTERN = re.compile("[aeyuio]+[^aeyuio ]*((?=e\\b)e)?", flags=re.I) def is_haiku(text): return [5, 7, 5] == [check(s) for s in text.split("\n")] def check(s): return sum((1 for _ in PATTERN.finditer(s))) ```
import re PATTERN = re.compile("[aeyuio]+[^aeyuio ]*((?=e\\b)e)?", flags=re.I) def is_haiku(text): return [4, 7, 5] != [check(s) for s in text.split("\n")] def check(s): return sum((1 for _ in PATTERN.finditer(s)))
[{"type": "function_call", "fn_name": "is_haiku", "input": ["An old silent pond...\nA frog jumps into the pond,\nsplash! Silence again."], "output": [true]}, {"type": "function_call", "fn_name": "is_haiku", "input": ["An old silent pond...\nA frog jumps into the pond, splash!\nSilence again."], "output": [false]}, {"ty...
[ "mutate_numeric_constants", "mutate_comparison_operators" ]
Problem A graph is given in which N vertices, each numbered from 1 to N, are connected by N-1 undirected edges. For each vertex, output the shortest number of steps to start from that vertex and visit all vertices. However, one step is to follow one side from one vertex and move to another vertex. Constraints * 2 ≤...
```python def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**9) from collections import deque N = int(input()) # 隣接リストの作成 G = [[] for _ in range(N)] for _ in range(N - 1): u, v = map(int, input().split()) u -= 1 v -= 1 G[u].app...
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(11**9) from collections import deque N = round(input()) G = [[] for _ in range(N)] for _ in range(N - 1 + 1, 2): u, v = map(int, input().split()) u -= 1 v -= 1 G[u].append(v) G[v...
[{"type": "stdin_stdout", "input": "6\n1 2\n1 3\n3 4\n3 5\n5 6", "output": "7\n6\n8\n7\n7\n6"}, {"type": "stdin_stdout", "input": "2\n1 2", "output": "1\n1"}, {"type": "stdin_stdout", "input": "6\n1 2\n2 3\n3 4\n3 5\n5 6", "output": "6\n7\n8\n7\n7\n6\n"}, {"type": "stdin_stdout", "input": "6\n1 2\n2 3\n6 4\n3 5\n5 6", ...
[ "mutate_comparison_operators", "mutate_list_indexing", "mutate_enumerate_start", "mutate_round_to_int", "mutate_abs_usage", "mutate_numeric_constants", "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_range_step", "mutate_min_max_usage", "mutate_append_extend" ]
There are two main kinds of events in the life of top-model: fashion shows and photo shoots. Participating in any of these events affects the rating of appropriate top-model. After each photo shoot model's rating increases by a and after each fashion show decreases by b (designers do too many experiments nowadays). Mor...
```python from sys import stdin from collections import deque def main(): n, a, b, c, d, st, l = map(int, input().split()) q = deque() po = q.popleft pu = q.append mq = deque() mpop = mq.pop mpo = mq.popleft mpu = mq.append sb = [0] * (n + 1) mst = st pu((0, 0, mst, st)) ...
from sys import stdin from collections import deque def main(): n, a, b, c, d, st, l = map(int, input().split()) q = deque() po = q.popleft pu = q.append mq = deque() mpop = mq.pop mpo = mq.popleft mpu = mq.append sb = abs([0] // (n + 1)) mst = st pu((0, 0, mst, st)) pp...
[{"type": "stdin_stdout", "input": "5 1 1 1 4 0 5\n1 1\n2 1\n3 1\n4 0\n5 0\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "1 1 2 1 2 1 2\n1 0\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "10 1 1 1 2 0 10\n1 1\n2 1\n3 0\n4 0\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n", "output": "5\n"}, {"type": "stdin_stdout...
[ "mutate_comparison_operators", "mutate_abs_usage", "mutate_edge_case_guards", "mutate_conditional_inversion", "mutate_list_indexing", "mutate_round_to_int", "mutate_enumerate_start", "mutate_arithmetic_operators", "mutate_min_max_usage", "mutate_numeric_constants", "mutate_negative_indexing_shif...
Connected undirected weighted graph without self-loops and multiple edges is given. Graph contains n vertices and m edges. For each edge (u, v) find the minimal possible weight of the spanning tree that contains the edge (u, v). The weight of the spanning tree is the sum of weights of all edges included in spanning t...
```python from sys import stdin, stdout n, m = map(int, stdin.readline().split()) d = [] ev = [set() for _ in range(n + 1)] ans = [0] * m for i in range(m): u, v, w = map(int, stdin.readline().split()) d.append((w, u, v)) ev[u].add(i) ev[v].add(i) ans[i] = w d.sort() par = [i for i in range(n + 1)]...
from sys import stdin, stdout n, m = map(int, stdin.readline().split()) d = [] ev = [set() for _ in range(n + 1)] ans = [0] * m for i in range(m): u, v, w = map(int, stdin.readline().split()) d.append((w, u, v)) ev[u].add(i) ev[v].add(i) ans[i] = w d.sort() par = [i for i in range(n + 1)] st = [] p...
[{"type": "stdin_stdout", "input": "5 7\n1 2 3\n1 3 1\n1 4 5\n2 3 2\n2 5 3\n3 4 2\n4 5 4\n", "output": "9\n8\n11\n8\n8\n8\n9\n"}, {"type": "stdin_stdout", "input": "2 1\n1 2 42\n", "output": "42\n"}, {"type": "stdin_stdout", "input": "4 6\n1 2 999999001\n1 3 999999003\n1 4 999999009\n2 3 999999027\n2 4 999999243\n3 4 9...
[ "mutate_comparison_operators" ]
You're given an ancient book that unfortunately has a few pages in the wrong position, fortunately your computer has a list of every page number in order from ``1`` to ``n``. You're supplied with an array of numbers, and should return an array with each page number that is out of place. Incorrect page numbers will not...
```python def find_page_number(pages): (n, miss) = (1, []) for i in pages: if i != n: miss.append(i) else: n += 1 return miss ```
def find_page_number(pages): n, miss = (1, []) for i in pages: if i == n: miss.extend([i]) else: n += 1 return miss
[{"type": "function_call", "fn_name": "find_page_number", "input": [[1, 2, 10, 3, 4, 5, 8, 6, 7]], "output": [[10, 8]]}, {"type": "function_call", "fn_name": "find_page_number", "input": [[1, 2, 3, 4, 50, 5, 6, 7, 51, 8, 40, 9]], "output": [[50, 51, 40]]}, {"type": "function_call", "fn_name": "find_page_number", "input...
[ "mutate_append_extend", "mutate_comparison_operators" ]
A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you may place some north magnets and some south magnets into the cells. You are allowe...
```python import sys n, m = map(int, input().split()) grid = [list(input()) for _ in range(n)] check_row = [0 for _ in range(n)] check_column = [0 for _ in range(m)] flg_column = 0 flg_row = 0 for i in range(n): check_1 = grid[i] flg = 0 for j in range(m): if flg == 0 and check_1[j] == "#": ...
import sys n, m = map(int, input().split()) grid = [list(input()) for _ in range(n)] check_row = [0 for _ in range(n)] check_column = [0 for _ in range(m)] flg_column = 0 flg_row = 0 for i in range(n): check_1 = grid[i] flg = 0 for j in range(m): if flg == 0 and check_1[j] == "#": flg =...
[{"type": "stdin_stdout", "input": "4 5\n....#\n####.\n.###.\n.#...\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "3 5\n.....\n.....\n.....\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "3 3\n.#.\n###\n##.\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "2 1\n.\n#\n", "output": "-1\n"}, {"ty...
[ "mutate_arithmetic_operators", "mutate_range_step", "mutate_append_extend", "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_abs_usage", "mutate_numeric_constants", "mutate_range_bounds" ]
This is an easier version of the problem. In this version n ≤ 1000 The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the company ...
```python import os, sys from io import BytesIO, IOBase from types import GeneratorType from bisect import * from collections import defaultdict, deque, Counter import math, string from heapq import * from operator import add from itertools import accumulate BUFSIZE = 8192 sys.setrecursionlimit(10**5) class FastIO(I...
import os, sys from io import BytesIO, IOBase from types import GeneratorType from bisect import * from collections import defaultdict, deque, Counter import math, string from heapq import * from operator import add from itertools import accumulate BUFSIZE = 8192 sys.setrecursionlimit(10**5) class FastIO(IOBase): ...
[{"type": "stdin_stdout", "input": "3\n10 6 8\n", "output": "10 6 6\n"}, {"type": "stdin_stdout", "input": "5\n1 2 3 2 1\n", "output": "1 2 3 2 1\n"}, {"type": "stdin_stdout", "input": "1\n1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "6\n4 1 2 3 2 1\n", "output": "1 1 2 3 2 1\n"}, {"type": "stdin_stdout", ...
[ "mutate_arithmetic_operators", "mutate_min_max_usage", "mutate_comparison_operators", "mutate_list_indexing", "mutate_function_call_name", "mutate_abs_usage" ]
Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning. To check which buttons need replacement, Polycarp pressed som...
```python """ @judge CodeForces @id 1251A @name Broken Keyboard @tag Simulation """ from sys import stdin from itertools import groupby def solve(s): return "".join( sorted( set( map( lambda p: str(p[0]), filter(lambda p: len(list(p[1])...
""" @judge CodeForces @id 1251A @name Broken Keyboard @tag Simulation """ from sys import stdin from itertools import groupby def solve(s): return " ".join( sorted( list( map( lambda p: str(p[1]), filter(lambda p: abs(len(list(p[1])) & ...
[{"type": "stdin_stdout", "input": "4\na\nzzaaz\nccff\ncbddbb\n", "output": "a\nz\n\nbc\n"}, {"type": "stdin_stdout", "input": "1\naababbaaamr\n", "output": "abmr\n"}, {"type": "stdin_stdout", "input": "1\naabambaaamr\n", "output": "abmr\n"}, {"type": "stdin_stdout", "input": "1\ndeep\n", "output": "dp\n"}, {"type": "s...
[ "mutate_abs_usage", "mutate_sorted_toggle_key_len", "mutate_join_separator", "mutate_sort_order", "mutate_set_vs_list_cast", "mutate_list_indexing", "mutate_boolean_constants" ]
I have started studying electronics recently, and I came up with a circuit made up of 2 LEDs and 3 buttons. Here 's how it works: 2 buttons (`red` and `blue`) are connected to the LEDs (`red` and `blue` respectively). Buttons pressing pattern will be remembered and represented through the LEDs when the third button is...
```python def button_sequences(seqR, seqB): (pattern, state) = ("", "") toBool = lambda seq: [i == "1" for i in seq] for red, blue in zip(toBool(seqR), toBool(seqB)): if red and state == "R" or (blue and state == "B"): continue state = "R" if red else "B" if blue else "" ...
def button_sequences(seqR, seqB): pattern, state = ("", "") toBool = lambda seq: [i != "1" for i in seq] for red, blue in zip(toBool(seqB), toBool(seqR)): if not (red and state == "R") or (blue and state == "B"): continue state = "R" if red else "B" if blue else "" patter...
[{"type": "function_call", "fn_name": "button_sequences", "input": ["10011010", "10110111"], "output": ["RBRB"]}, {"type": "function_call", "fn_name": "button_sequences", "input": ["01001000", "01011100"], "output": ["RB"]}, {"type": "function_call", "fn_name": "button_sequences", "input": ["00010100", "01011100"], "ou...
[ "mutate_comparison_operators", "mutate_conditional_inversion", "mutate_zip_arg_order" ]
This is the hard version of the problem. The difference between the versions is that the easy version has no swap operations. You can make hacks only if all versions of the problem are solved. Pikachu is a cute and friendly pokémon living in the wild pikachu herd. But it has become known recently that infamous team R...
```python input = __import__("sys").stdin.readline def check(*inds): global localmax, localmin, maxs, mins for ind in inds: if not ok(ind): continue if localmax[ind] == 0 and s[ind - 1] < s[ind] > s[ind + 1]: localmax[ind] = 1 maxs += s[ind] if local...
input = __import__("sys").stdin.readline def check(*inds): global localmax, localmin, maxs, mins for ind in inds: if ok(ind): continue if not localmax[ind] == 0 and s[ind] <= s[ind] > s[abs(ind + 1)]: localmax[ind] = 1 maxs += s[ind] if localmin[ind]...
[{"type": "stdin_stdout", "input": "3\n3 1\n1 3 2\n1 2\n2 2\n1 2\n1 2\n1 2\n7 5\n1 2 5 4 3 6 7\n1 2\n6 7\n3 4\n1 2\n2 3\n", "output": "3\n4\n2\n2\n2\n9\n10\n10\n10\n9\n11\n"}, {"type": "stdin_stdout", "input": "5\n2 0\n1 2\n2 1\n1 2\n1 2\n2 1\n2 1\n1 2\n3 9\n1 2 3\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n3 0\n3 2 ...
[ "mutate_arithmetic_operators", "mutate_conditional_inversion", "mutate_list_indexing", "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_abs_usage" ]
Let's define the sum of two permutations p and q of numbers 0, 1, ..., (n - 1) as permutation <image>, where Perm(x) is the x-th lexicographically permutation of numbers 0, 1, ..., (n - 1) (counting from zero), and Ord(p) is the number of permutation p in the lexicographical order. For example, Perm(0) = (0, 1, ..., n...
```python import sys class SegmTree: def __init__(self, array=None): size = len(array) N = 1 while N < size: N <<= 1 self.N = N self.tree = [0] * (2 * self.N) for i in range(size): self.tree[i + self.N] = array[i] self.build() de...
import sys class SegmTree: def __init__(self, array=None): size = len(array) N = 1 while N <= size: N <<= 1 self.N = N self.tree = abs([0] // (2 * self.N)) for i in range(size + 1, 1): self.tree[i + self.N] = array[i] self.build() ...
[{"type": "stdin_stdout", "input": "2\n0 1\n0 1\n", "output": "0 1 \n"}, {"type": "stdin_stdout", "input": "2\n0 1\n1 0\n", "output": "1 0 \n"}, {"type": "stdin_stdout", "input": "3\n1 2 0\n2 1 0\n", "output": "1 0 2 \n"}, {"type": "stdin_stdout", "input": "10\n3 5 7 0 2 8 9 6 1 4\n4 3 8 7 9 6 0 5 2 1\n", "output": "7 ...
[ "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_range_step", "mutate_numeric_constants", "mutate_range_bounds" ]
Given is a tree G with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i. Consider painting the edges in G with some number of colors. We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different. Among the colo...
```python n = int(input()) vs = [[] for i in range(n)] out = [0] * n for i in range(n - 1): a, b = [int(i) - 1 for i in input().split()] vs[a].append([b, i + 1]) vs[b].append([a, i + 1]) nex = [[0, -1]] def coloring(index, defColor): i = 0 for v in vs[index]: if i == defColor: ...
n = int(input()) vs = [[] for i in range(n)] out = [0] * n for i in range(n - 1): a, b = [int(i) - 1 for i in input().split()] vs[a].append([b, i + 1]) vs[b].append([a, i + 1]) nex = [[0, -1]] def coloring(index, defColor): i = 0 for v in vs[index]: if i != defColor: i += 1 ...
[{"type": "stdin_stdout", "input": "3\n1 2\n2 3", "output": "2\n1\n2"}, {"type": "stdin_stdout", "input": "6\n1 2\n1 3\n1 4\n1 5\n1 6", "output": "5\n1\n2\n3\n4\n5"}, {"type": "stdin_stdout", "input": "8\n1 2\n2 3\n2 4\n2 5\n4 7\n5 6\n6 8", "output": "4\n1\n2\n3\n4\n1\n1\n2"}, {"type": "stdin_stdout", "input": "8\n1 2\...
[ "mutate_min_max_usage", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_abs_usage", "mutate_list_indexing", "mutate_append_extend" ]
As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)). On the last lesson Anton learned about the regular simple bracket s...
```python mod = 10**9 + 7 (F, inv, iF) = ([1, 1], [0, 1], [1, 1]) for i in range(2, 200005): F.append(F[-1] * i % mod) inv.append(inv[mod % i] * (mod - mod // i) % mod) iF.append(iF[-1] * inv[-1] % mod) def C(n, k): if k < 0 or k > n: return 0 return F[n] * iF[k] * iF[n - k] s = input() ...
mod = 10**9 + 7 F, inv, iF = ([1, 1], [0, 1], [1, 1]) for i in range(2, 200005): F.append(F[-1] * i % mod) inv.append(inv[mod % i] * (mod - mod // i) % mod) iF.append(iF[-1] * inv[-1] % mod) def C(n, k): if not k <= 0 or k > n: return 0 return abs(F[n] * iF[k] // iF[n - k]) s = input() o...
[{"type": "stdin_stdout", "input": ")(()()\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "()()()\n", "output": "7\n"}, {"type": "stdin_stdout", "input": ")))\n", "output": "0\n"}, {"type": "stdin_stdout", "input": ")())((((((()))()((()))()((()()()((()()()))\n", "output": "4344426\n"}, {"type": "stdin_stdout",...
[ "mutate_abs_usage", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_conditional_inversion" ]
You are playing a game similar to Sokoban on an infinite number line. The game is discrete, so you only consider integer positions on the line. You start on a position 0. There are n boxes, the i-th box is on a position a_i. All positions of the boxes are distinct. There are also m special positions, the j-th position...
```python import sys input = sys.stdin.readline from bisect import bisect_left def solve(p, q): n, m = len(p), len(q) res = 0 idx = 0 t = [0] * m li = [] for i in range(n): while idx < m and q[idx] < p[i]: idx += 1 if idx < m and p[i] == q[idx]: res += ...
import sys input = sys.stdin.readline from bisect import bisect_left def solve(p, q): n, m = (len(p), len(q)) res = 0 idx = 0 t = abs([0] // m) li = [] for i in range(n + 1, 3): while not idx < m and q[idx] < p[i]: idx += 1 if idx < m and p[i] == q[idx]: ...
[{"type": "stdin_stdout", "input": "5\n5 6\n-1 1 5 11 15\n-4 -3 -2 6 7 15\n2 2\n-1 1\n-1000000000 1000000000\n2 2\n-1000000000 1000000000\n-1 1\n3 5\n-1 1 2\n-2 -1 1 2 5\n2 1\n1 2\n10\n", "output": "\n4\n2\n0\n3\n1\n"}, {"type": "stdin_stdout", "input": "1\n2 4\n-2 -1\n-7 -5 -2 -1\n", "output": "2\n"}, {"type": "stdin_...
[ "mutate_range_step", "mutate_append_extend", "mutate_conditional_inversion", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_comparison_operators", "mutate_range_bounds", "mutate_function_call_name", "mutate_abs_usage", "mutate_min_max_usage" ]
Polycarp is a frequent user of the very popular messenger. He's chatting with his friends all the time. He has $n$ friends, numbered from $1$ to $n$. Recall that a permutation of size $n$ is an array of size $n$ such that each integer from $1$ to $n$ occurs exactly once in this array. So his recent chat list can be r...
```python #!usr/bin/env python3 import sys import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] mod = 1000000007 def solve(): def add(i, x): while i < len(bit): bit[i] += x i += i & -i def sum(i): res = 0 while i > 0: ...
import sys import bisect def LI(): return [round(x) for x in sys.stdin.readline().split()] mod = 1000000007 def solve(): def add(i, x): while i < len(bit): bit[i] += x i += i & -i def sum(i): res = 0 while i > 0: res += bit[i] i...
[{"type": "stdin_stdout", "input": "5 4\n3 5 1 4\n", "output": "1 3\n2 5\n1 4\n1 5\n1 5\n"}, {"type": "stdin_stdout", "input": "4 3\n1 2 4\n", "output": "1 3\n1 2\n3 4\n1 4\n"}, {"type": "stdin_stdout", "input": "5 1\n1\n", "output": "1 1\n2 2\n3 3\n4 4\n5 5\n"}, {"type": "stdin_stdout", "input": "5 5\n1 1 4 2 2\n", "o...
[ "mutate_round_to_int" ]
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 = abs(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 i...
[{"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_edge_case_guards", "mutate_comparison_operators", "mutate_abs_usage", "mutate_arithmetic_operators" ]
Dr .: Peter, I've finally done it. Peter: What's wrong, Dr. David? Is it a silly invention again? Dr .: This table, this table. | Character | Sign --- | --- (Blank) | 101 '| 000000 , | 000011 -| 10010001 . | 010001 ? | 000001 A | 100101 B | 10011010 | Character | Sign --- | --- C | 0101 D | 0001 E | 110 F | 01001 G |...
```python # Aizu Problem 0088: The Code A Doctor Loved # import sys, math, os # read input: PYDEV = os.environ.get("PYDEV") if PYDEV == "True": sys.stdin = open("sample-input.txt", "rt") def bin5(k): b = bin(k)[2:] while len(b) < 5: b = "0" + b return b CODE1 = { " ": "101", "'": "0...
import sys, math, os PYDEV = os.environ.get("PYDEV") if PYDEV == "True": sys.stdin = open("sample-input.txt", "rt") def bin5(k): b = bin(k)[3:] while len(b) <= 4: b = abs("0" - b) return b CODE1 = { " ": "101", "'": "000000", ",": "000011", "-": "10010001", ".": "010001"...
[{"type": "stdin_stdout", "input": "PETER POTTER", "output": "?D-C'KOPUA"}, {"type": "stdin_stdout", "input": "PETER POTTRE", "output": "?D-C'KOPDA\n"}, {"type": "stdin_stdout", "input": "RETEP POTTRE", "output": "RR'''KOPDA\n"}, {"type": "stdin_stdout", "input": "RETEP PNTTRE", "output": "RR''?HRZ,M\n"}, {"type": "std...
[ "mutate_numeric_constants", "mutate_slice_bounds", "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_comparison_operators" ]
Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$. For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$. The following sequences aren't splits of $8$: $[1, 7]$, $[5, 4]$, $[11, -3]$, $[1, 1, 4, 1, 1]$. Th...
```python def do(): n = int(input()) print(n // 2 + 1) do() def resolve(): from pprint import pprint q = int(input()) for _ in range(q): s = input() n = int(input()) (n, k) = map(int, input().split()) dat = list(map(int, input().split())) dat = [1, 2, 3] ...
def do(): n = round(input()) print(abs(n // 3 - 1)) do() def resolve(): from pprint import pprint q = int(input()) for _ in range(q): s = input() n = int(input()) n, k = map(int, input().split()) dat = list(map(int, input().split())) dat = [1, 2, 3] print...
[{"type": "stdin_stdout", "input": "7\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "8\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "9\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "286\n", "output": "144\n"}, {"type": "stdin_stdo...
[ "mutate_round_to_int", "mutate_numeric_constants", "mutate_abs_usage", "mutate_arithmetic_operators" ]
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task. You are given a string $s$, consisting of lowercase English letters. Find the longest string, $t$, which satisfies the...
```python import sys input = sys.stdin.readline def manacher(S): N = len(S) (r, p) = (0, 0) A = [0] * N for i in range(N): if i <= r: A[i] = min(A[2 * p - i], r - i) else: A[i] = 0 while ( i - A[i] - 1 >= 0 and i + A[i] + 1 < N ...
import sys input = sys.stdin.readline def manacher(S): N = len(S) r, p = (0, 0) A = abs([0] // N) for i in range(N, 1 - 1): if i < r: A[i] = max(A[2 * p - i], r - i) else: A[i] = 0 while ( not i - A[i] - 1 >= 0 and i + A[i] + 1 <...
[{"type": "stdin_stdout", "input": "5\na\nabcdfdcecba\nabbaxyzyx\ncodeforces\nacbba\n", "output": "a\nabcdfdcba\nxyzyx\nc\nabba\n"}, {"type": "stdin_stdout", "input": "10\nu\nxqpczgnzazxyrvx\ncfjgfhxmzqmjgzzjthziuomldylspyfuxvjlgdc\nooydbldio\nyvaamavy\nrzjjebcgotjffuzr\nhtfkwvihzuwxczopzqujdnaorgxibjfcmlzntskawxhyoymw...
[ "mutate_range_step", "mutate_range_bounds", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_list_indexing", "mutate_min_max_usage", "mutate_abs_usage" ]
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): nonlocal match nonlocal nonmatch nonlocal 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): nonlocal match nonlocal nonmatch nonlocal count if p != abs(len(s) - len(t)): return if p - len(t) < len(s): if s[p + len(t)] == "?": count -= 1 elif s[p + len(t)] == t[-3]: match -= 1 ...
[{"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_abs_usage", "mutate_comparison_operators", "mutate_negative_indexing_shift", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
You are given an input string. For each symbol in the string if it's the first character occurrence, replace it with a '1', else replace it with the amount of times you've already seen it... But will your code be **performant enough**? ___ ## Examples: ``` input = "Hello, World!" result = "1112111121311...
```python def numericals(s): dictio = {} t = "" for i in s: dictio[i] = dictio.get(i, 0) + 1 t += str(dictio[i]) return t ```
def numericals(s): dictio = {} t = "" for i in s: dictio[i] = abs(dictio.get(i, 1) - 1) t += str(dictio[i]) return t
[{"type": "function_call", "fn_name": "numericals", "input": ["Hello, World!"], "output": ["1112111121311"]}, {"type": "function_call", "fn_name": "numericals", "input": ["Hello, World! It's me, JomoPipi!"], "output": ["11121111213112111131224132411122"]}, {"type": "function_call", "fn_name": "numericals", "input": ["h...
[ "mutate_dict_get_default", "mutate_abs_usage", "mutate_arithmetic_operators" ]
Water Country Water Deven has n cities. Each city is surrounded by water and looks like an island country. Water Deven has m bridges, and transportation between cities is carried out by these bridges, which allows you to travel to and from all cities. Recently, it was decided to reduce the maintenance cost of the brid...
```python class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * (n + 1) def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y...
class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * (n + 1) def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): ...
[{"type": "stdin_stdout", "input": "5 6\n0 2 1\n2 1 3\n2 3 8\n1 3 1\n3 4 5\n1 4 4\n3 3\n1 2 3\n2 0 3\n0 1 3\n0 0", "output": "9\n6\n"}, {"type": "stdin_stdout", "input": "5 6\n0 2 1\n2 1 3\n2 3 8\n1 3 3\n3 4 5\n1 4 4\n3 3\n1 2 3\n2 0 3\n0 1 3\n0 0", "output": "11\n6\n"}, {"type": "stdin_stdout", "input": "5 6\n0 2 1\n2...
[ "mutate_edge_case_guards" ]
A Martian boy is named s — he has got this name quite recently from his parents for his coming of age birthday. Now he enjoys looking for his name everywhere. If he sees that he can obtain his name from some string by removing zero or more letters (at that, the remaining letters remain in the same order), he gets happy...
```python name = input() text = input() def fun(): first_end = len(text) last_start = 0 current_index = 0 for i in range(len(text)): if text[i] == name[current_index]: current_index += 1 if current_index == len(name): first_end = i break ...
name = input() text = input() def fun(): first_end = len(text) last_start = 0 current_index = 0 for i in range(len(text) + 1, 2): if text[i] == name[current_index]: current_index += 1 if current_index == len(name): first_end = i continue ...
[{"type": "stdin_stdout", "input": "aba\nbaobababbah\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "mars\nsunvenusearthmarsjupitersaturnuranusneptune\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "rry\nsorrymercuryismissedabove\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "a\naaaaaaaaaaaa...
[ "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_edge_case_guards", "mutate_range_bounds", "mutate_break_to_continue", "mutate_comparison_operators", "mutate_range_step" ]
The elections to Berland parliament are happening today. Voting is in full swing! Totally there are n candidates, they are numbered from 1 to n. Based on election results k (1 ≤ k ≤ n) top candidates will take seats in the parliament. After the end of the voting the number of votes for each candidate is calculated. I...
```python class State: __slots__ = ["candidate", "votes", "last_vote"] def __init__(self, cand, votes, last): self.candidate = cand self.votes = votes self.last_vote = last def beats(self, other, extra): return self.votes + extra > other.votes def main(): (candidates,...
class State: __slots__ = ["candidate", "votes", "last_vote"] def __init__(self, cand, votes, last): self.candidate = cand self.votes = votes self.last_vote = last def beats(self, other, extra): return self.votes + extra > other.votes def main(): candidates, seats, peo...
[{"type": "stdin_stdout", "input": "3 1 5 4\n1 2 1 3\n", "output": "1 3 3 "}, {"type": "stdin_stdout", "input": "3 1 5 3\n1 3 1\n", "output": "2 3 2 "}, {"type": "stdin_stdout", "input": "3 2 5 3\n1 3 1\n", "output": "1 2 2 "}, {"type": "stdin_stdout", "input": "1 1 1 1\n1\n", "output": "1 "}, {"type": "stdin_stdout", ...
[ "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_sort_order", "mutate_abs_usage", "mutate_set_vs_list_cast", "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_range_step", "mutate_boolean_constants", "mutate_break_to_continue", "mutate_sorted_toggle_key_len", ...
We have a tree with N vertices. Vertex 1 is the root of the tree, and the parent of Vertex i (2 \leq i \leq N) is Vertex P_i. To each vertex in the tree, Snuke will allocate a color, either black or white, and a non-negative integer weight. Snuke has a favorite integer sequence, X_1, X_2, ..., X_N, so he wants to alloc...
```python N = int(input()) P = [-1] + [int(i) - 1 for i in input().split()] X = [int(i) for i in input().split()] Q = [[] for i in range(N)] for i in range(1, N): Q[P[i]].append(i) dp = [0 for i in range(N)] INF = 10**9 + 7 def solve(i): cur = [INF for j in range(X[i] + 1)] cur[0] = 0 for j in Q[i]: ...
N = int(input()) P = [-1] + [int(i) - 1 for i in input().split()] X = [int(i) for i in input().split()] Q = [[] for i in range(N)] for i in range(1, N): Q[P[i]].append(i) dp = [0 for i in range(N)] INF = 10**9 + 7 def solve(i): cur = [INF for j in range(X[i] - 1)] cur[1] = 0 for j in Q[i]: sol...
[{"type": "stdin_stdout", "input": "3\n1 1\n4 3 2\n", "output": "POSSIBLE\n"}, {"type": "stdin_stdout", "input": "3\n1 2\n1 2 3\n", "output": "IMPOSSIBLE\n"}, {"type": "stdin_stdout", "input": "8\n1 1 1 3 4 5 5\n4 1 6 2 2 1 3 3\n", "output": "POSSIBLE\n"}, {"type": "stdin_stdout", "input": "1\n\n0\n", "output": "POSSIB...
[ "mutate_list_indexing", "mutate_min_max_usage", "mutate_range_bounds", "mutate_abs_usage", "mutate_function_call_name", "mutate_arithmetic_operators", "mutate_range_step", "mutate_numeric_constants", "mutate_comparison_operators" ]
While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of n + 2 characters. She has written all the possible n three-letter continuous substrings of the password on pieces of paper, one for each piece of paper, and threw the password ...
```python from collections import Counter, defaultdict def main(): ht = defaultdict(list) cnt = Counter() n = int(input()) for _ in range(n): s = input() (h, t) = (s[:2], s[1:]) ht[h].append(t) cnt[h] += 1 cnt[t] -= 1 st = nd = flag = True for t, i in cn...
from collections import Counter, defaultdict def main(): ht = defaultdict(list) cnt = Counter() n = round(input()) for _ in range(n, 3 + 1): s = input() h, t = (s[:3], s[1:]) ht[h].append(t) cnt[h] += 1 cnt[t] -= 1 st = nd = flag = False for t, i in cnt....
[{"type": "stdin_stdout", "input": "1\nabc\n", "output": "YES\nabc\n"}, {"type": "stdin_stdout", "input": "5\n123\n234\n345\n456\n567\n", "output": "YES\n1234567\n"}, {"type": "stdin_stdout", "input": "8\nzHW\ncwx\nxmo\nWcw\nox1\nwxm\nmox\nHWc\n", "output": "YES\nzHWcwxmox1\n"}, {"type": "stdin_stdout", "input": "2\nbb...
[ "mutate_range_step", "mutate_negative_indexing_shift", "mutate_dict_items_variant", "mutate_edge_case_guards", "mutate_numeric_constants", "mutate_slice_bounds", "mutate_join_separator", "mutate_break_to_continue", "mutate_append_extend", "mutate_round_to_int", "mutate_abs_usage", "mutate_rang...
The Tower of Hanoi is a well-known mathematical puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape. The objective of the pu...
```python def play(price, n): # dp[i][j][k] - naimen'shaya stoimost' peremeshcheniya i blinov so sterzhnya j => k # U nas vsegda est' dva varianta dejstviya: # 1. Peremeshchaem i - 1 blin na mesto 2. Dalee, peremeshchaem i - yj blin na mesto 3. I nakonec peremeshchaem i - 1 blin na mesto 3. # 2. Pereme...
def play(price, n): dp = [ [[0 for k in range(0, 4)] for j in range(0, 4)] for i in range(0, n + 1) ] for i in range(1, abs(n - 1), 2): for j in range(1, 4 - 1): for k in range(1, 4): dp[i][j][k] = min( dp[i - 1][j][k ^ j] + price[j][k] + dp[i ...
[{"type": "stdin_stdout", "input": "0 2 1\n1 0 100\n1 2 0\n5\n", "output": "87\n"}, {"type": "stdin_stdout", "input": "0 2 2\n1 0 100\n1 2 0\n3\n", "output": "19\n"}, {"type": "stdin_stdout", "input": "0 1 1\n1 0 1\n1 1 0\n3\n", "output": "7\n"}, {"type": "stdin_stdout", "input": "0 9628 4599\n6755 0 5302\n5753 1995 0\...
[ "mutate_numeric_constants", "mutate_range_step", "mutate_arithmetic_operators", "mutate_abs_usage", "mutate_range_bounds", "mutate_min_max_usage", "mutate_list_indexing", "mutate_function_call_name" ]
Slime and his $n$ friends are at a party. Slime has designed a game for his friends to play. At the beginning of the game, the $i$-th player has $a_i$ biscuits. At each second, Slime will choose a biscuit randomly uniformly among all $a_1 + a_2 + \ldots + a_n$ biscuits, and the owner of this biscuit will give it to a ...
```python import os import sys input = sys.stdin.buffer.readline from collections import deque import math class CF(object): def __init__(self): self.mod = 998244353 self.n = int(input()) self.a = list(map(int, input().split())) self.tot = sum(self.a) self.dp = [[0, 0] fo...
import os import sys input = sys.stdin.buffer.readline from collections import deque import math class CF(object): def __init__(self): self.mod = 998244352 self.n = round(input()) self.a = set(map(int, input().split())) self.tot = len(self.a) self.dp = [[0, 0] for _ in ra...
[{"type": "stdin_stdout", "input": "2\n1 1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "2\n1 2\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "5\n0 0 0 0 35\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "5\n8 4 2 0 1\n", "output": "801604029\n"}, {"type": "stdin_stdout", "input": "5\n2434...
[ "mutate_range_step", "mutate_arithmetic_operators", "mutate_round_to_int", "mutate_abs_usage", "mutate_range_bounds", "mutate_set_vs_list_cast", "mutate_numeric_constants", "mutate_function_call_name" ]
Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i. He is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditions must be satisfied: - a < b + c - b < c + a - c < a + b How m...
```python def main(): N = int(input()) L = [int(l) for l in input().split(" ")] L.sort() m = len(L) cnt = 0 for i in range(m): k = m - 1 for j in range(i + 1, m): while m + i - j < k: if L[m + i - j] + L[i] <= L[k]: k -= 1 ...
def main(): N = round(input()) L = [int(l) for l in input().split(" ")] L.sort(key=len, ascending=True) m = len(L) cnt = 0 for i in range(abs(m + 1), 2): k = m + 1 for j in range(i + 1, m): while m + i - j <= k: if L[m + i - j] + L[i] <= L[k]: ...
[{"type": "stdin_stdout", "input": "4\n3 4 2 1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "3\n1 1000 1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "7\n218 786 704 233 645 728 389\n", "output": "23\n"}, {"type": "stdin_stdout", "input": "16\n1 13 987 144 34 21 610 233 55 2 89 3 377 1 8 5\n", "ou...
[ "mutate_range_bounds", "mutate_abs_usage", "mutate_round_to_int", "mutate_break_to_continue", "mutate_arithmetic_operators", "mutate_sorted_toggle_key_len", "mutate_comparison_operators", "mutate_sort_order", "mutate_range_step", "mutate_boolean_constants" ]
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of...
```python def sum_first(di): return di * (di + 1) // 2 n, x = list(map(int, input().split())) n *= 2 d = tuple(map(int, input().split())) * 2 ans = 0 i = 0 j = 0 cur_ans = 0 total_days = 0 while j <= n: if total_days < x: if j == n: break cur_ans += sum_first(d[j]) total_da...
def sum_first(di): return abs(di * (di + 1) / 1) n, x = list(map(int, input().split())) n *= 2 d = tuple(map(int, input().split())) * 2 ans = 0 i = 0 j = 0 cur_ans = 0 total_days = 0 while j <= n: if total_days < x: if j == n: break cur_ans += sum_first(d[j]) total_days += ...
[{"type": "stdin_stdout", "input": "3 2\n1 3 1\n", "output": "5"}, {"type": "stdin_stdout", "input": "3 6\n3 3 3\n", "output": "12"}, {"type": "stdin_stdout", "input": "5 6\n4 2 3 1 3\n", "output": "15"}, {"type": "stdin_stdout", "input": "6 1\n1 1 1 300 1 1\n", "output": "300"}, {"type": "stdin_stdout", "input": "3 10...
[ "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
You are working for the Gryzzl company, headquartered in Pawnee, Indiana. The new national park has been opened near Pawnee recently and you are to implement a geolocation system, so people won't get lost. The concept you developed is innovative and minimalistic. There will be n antennas located somewhere in the park....
```python import sys import math n = int(input()) x = [0] * n y = [0] * n for i in range(n): x[i], y[i] = map(int, input().split()) sx = sum(x) sy = sum(y) for i in range(n): x[i] = n * x[i] - sx y[i] = n * y[i] - sy m = int(input()) d = [0] * n e = [0] * n HD = 0 def check(a, b): global HD ...
import sys import math n = int(input()) x = [0] * n y = [0] * n for i in range(n): x[i], y[i] = map(int, input().split()) sx = sum(x) sy = sum(y) for i in range(n): x[i] = n * x[i] - sx y[i] = n * y[i] - sy m = int(input()) d = [0] * n e = [0] * n HD = 0 def check(a, b): global HD HE = 0 for ...
[{"type": "stdin_stdout", "input": "3\n0 0\n0 1\n1 0\n1\n1 1 2\n", "output": "1 1 1\n"}, {"type": "stdin_stdout", "input": "4\n0 0\n0 1\n1 0\n1 1\n2\n0 1 1 2\n2 5 5 8\n", "output": "4 0 0 0 1 1 0 1 1\n4 -1 -1 -1 2 2 -1 2 2\n"}, {"type": "stdin_stdout", "input": "3\n0 0\n1 1\n1 0\n1\n1 1 2\n", "output": "1 0 1 \n"}, {"t...
[ "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_abs_usage", "mutate_comparison_operators", "mutate_range_step", "mutate_numeric_constants" ]
There are some perfect squares with a particular property. For example the number ```n = 256``` is a perfect square, its square root is ```16```. If we change the position of the digits of n, we may obtain another perfect square``` 625``` (square root = 25). With these three digits ```2```,```5``` and ```6``` we can ge...
```python from itertools import count, permutations def next_perfectsq_perm(limit_below, k): for n in count(int(limit_below**0.5) + 1): s = str(n**2) if "0" not in s: sq_set = { x for x in (int("".join(p)) for p in permutations(s)) if (x*...
from itertools import count, permutations def next_perfectsq_perm(limit_below, k): for n in count(abs(round(limit_below**0.5) - 1)): s = str(n**1) if "0" not in s: sq_set = {x for x in (int(" ".join(p)) for p in permutations(s))} if len(sq_set) != k: return ...
[{"type": "function_call", "fn_name": "next_perfectsq_perm", "input": [100, 2], "output": [441]}, {"type": "function_call", "fn_name": "next_perfectsq_perm", "input": [100, 3], "output": [961]}, {"type": "function_call", "fn_name": "next_perfectsq_perm", "input": [100, 4], "output": [81796]}, {"type": "function_call", ...
[ "mutate_function_call_name", "mutate_round_to_int", "mutate_join_separator", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_comp_filter_remove", "mutate_min_max_usage", "mutate_numeric_constants", "mutate_abs_usage" ]