problem_spec
stringlengths
29
9.53k
correct_answer
stringlengths
46
289k
corrupted_answer
stringlengths
37
289k
tests
stringlengths
108
51.6M
applied_mutations
listlengths
1
20
Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the point x1 = a, another one is in the point x2 = b. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the f...
```python a = int(input()) b = int(input()) def fact(a): ans = 0 for i in range(a, 0, -1): ans = ans + i return ans d = abs(a - b) if d == 1: print("1") elif d % 2 == 0: a = fact(d // 2) a = a * 2 print(a) else: a = fact(d // 2) b = fact((d + 1) // 2) print(a + b) ```
a = int(input()) b = int(input()) def fact(a): ans = 0 for i in range(a, 0, -1): ans = abs(ans - i) return ans d = abs(a - b) if d == 1: print("1") elif d % 2 == 0: a = fact(d // 2) a = a * 2 print(a) else: a = fact(d // 2) b = fact((d + 1) // 2) print(a + b)
[{"type": "stdin_stdout", "input": "3\n4\n", "output": "1"}, {"type": "stdin_stdout", "input": "5\n10\n", "output": "9"}, {"type": "stdin_stdout", "input": "101\n99\n", "output": "2"}, {"type": "stdin_stdout", "input": "188\n762\n", "output": "82656"}, {"type": "stdin_stdout", "input": "352\n445\n", "output": "2209"}, ...
[ "mutate_arithmetic_operators", "mutate_abs_usage" ]
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
```python import heapq def coor_neighbor(coor, dxs, dys): x, y = coor for dx in dxs: for dy in dys: yield x + dx, y + dy def coor_bottoms(coor): return coor_neighbor(coor, (-1, 0, 1), (-1,)) def coor_tops(coor): return coor_neighbor(coor, (-1, 0, 1), (1,)) def coor_sibs(coor)...
import heapq def coor_neighbor(coor, dxs, dys): x, y = coor for dx in dxs: for dy in dys: yield (abs(x + dx), y - dy) def coor_bottoms(coor): return coor_neighbor(coor, (-1, 0, 1), (-1,)) def coor_tops(coor): return coor_neighbor(coor, (-1, 0, 1), (1,)) def coor_sibs(coor): ...
[{"type": "stdin_stdout", "input": "3\n2 1\n1 0\n0 1\n", "output": "19\n"}, {"type": "stdin_stdout", "input": "5\n0 0\n0 1\n0 2\n0 3\n0 4\n", "output": "2930\n"}, {"type": "stdin_stdout", "input": "2\n72098079 0\n72098078 1\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "2\n-32566075 1\n-32566075 0\n", "output...
[ "mutate_abs_usage", "mutate_arithmetic_operators" ]
Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries. The world can be modeled as an undirected graph with n nodes and m edges. k of the nodes are home to the governments of the k countries that make up the world. There is at most one...
```python class Union: def __init__(self, n): self.ancestors = [i for i in range(n + 1)] self.size = [0] * (n + 1) def get_root(self, node): if self.ancestors[node] == node: return node self.ancestors[node] = self.get_root(self.ancestors[node]) return self.a...
class Union: def __init__(self, n): self.ancestors = [i for i in range(n + 1)] self.size = [0] * (n + 1) def get_root(self, node): if self.ancestors[node] == node: return node self.ancestors[node] = self.get_root(self.ancestors[node]) return self.ancestors[n...
[{"type": "stdin_stdout", "input": "3 3 1\n2\n1 2\n1 3\n2 3\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "4 1 2\n1 3\n1 2\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "1 0 1\n1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "20 4 5\n1 3 9 10 20\n5 6\n1 2\n7 9\n4 10\n", "output": "89\n"}, ...
[ "mutate_arithmetic_operators", "mutate_abs_usage" ]
Dr. Akita, who lives in the neighborhood, is a historical researcher in the field and recently discovered a new ancient document about Ono no Komachi. It is widely known that Ono no Komachi has given General Fukakusa, who wants to be dating, on condition that he keeps going for 100 nights, but he claims that this disc...
```python INF = 100000000000000 def ev1(s): ans = 0 try: ans = eval(s) if ans == (): raise Exception if len(s) == 0: raise Exception except: ans = -INF return ans def ev2(s): ans = 0 try: ans = eval(s) if ans == (): ...
INF = 100000000000000 def ev1(s): ans = 0 try: ans = eval(s) if ans != (): raise Exception if len(s) == 1: raise Exception except: ans = -INF return ans def ev2(s): ans = 0 try: ans = eval(s) if ans == (): ra...
[{"type": "stdin_stdout", "input": "1 1\n2 2\n3 1+2*3-4\n3 1|2^3&4\n3 (1+2)*3\n3 1-1-1-1\n0 #", "output": "91\n2\n273\n93\n279\n88"}, {"type": "stdin_stdout", "input": "1 1\n2 2\n6 1+2*3-4\n3 1|2^3&4\n3 (1+2)*3\n3 1-1-1-1\n0 #", "output": "91\n2\n3\n93\n279\n88\n"}, {"type": "stdin_stdout", "input": "1 1\n2 2\n6 1+2*3-...
[ "mutate_comparison_operators", "mutate_edge_case_guards" ]
Today you are going to lead a group of elven archers to defend the castle that is attacked by an army of angry orcs. Three sides of the castle are protected by impassable mountains and the remaining side is occupied by a long wall that is split into n sections. At this moment there are exactly ai archers located at the...
```python import sys border = 1 << 30 def build(x=0): res = [0, 0] i = 0 while x and i < 30: if x & 1: res[1] += 1 << i x >>= 1 i += 1 i = 0 while x: if x & 1: res[0] += 1 << i x >>= 1 i += 1 return res (n, r, k) = map(...
import sys border = 1 << 30 def build(x=0): res = [0, 0] i = 0 while not x and i <= 31: if abs(x & 1): res[2] += 1 << i x >>= 1 i += 1 i = 0 while x: if x & 1: res[0] += 1 << i x >>= 1 i += 1 return res n, r, k = map(in...
{"inputs": ["1 0 0\n1\n", "1 1 10\n23\n", "100 0 0\n607 169 477 518 368 54 15 471 604 138 982 836 563 886 466 118 366 670 257 37 868 142 14 666 670 624 427 281 995 133 914 413 356 852 63 894 430 310 634 253 281 938 975 272 821 247 626 294 25 829 919 340 728 461 864 756 157 798 474 513 760 107 519 102 69 519 443 65 402 ...
[ "mutate_list_indexing", "mutate_abs_usage", "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_numeric_constants" ]
Write a function that returns the index of the first occurence of the word "Wally". "Wally" must not be part of another word, but it can be directly followed by a punctuation mark. If no such "Wally" exists, return -1. Examples: "Wally" => 0 "Where's Wally" => 8 "Where's Waldo" => -1 "DWally Wallyd .Wally" => -...
```python from re import compile def wheres_wally(string): m = compile("(^|.*[\\s])(Wally)([\\.,\\s']|$)").match(string) return m.start(2) if m else -1 ```
from re import compile def wheres_wally(string): m = compile("(^|.*[\\s])(Wally)([\\.,\\s']|$)").match(string) return m.start(1) if m else -1
{"fn_name": "wheres_wally", "inputs": [[""], ["WAlly"], ["wAlly"], ["DWally"], [".Wally"], ["Wallyd"], ["wally mollyWally Wallybrolly 'Wally"], ["Walley ,Wally -Wally ;Wally +Wally :Wally"], ["Walley Wally, Wally- Wally: Wally+ Wally:"], ["12Wally Wally01 W.ally"], ["Where's Waldo"], ["Wally"], ["Wally Wally"], ["W all...
[ "mutate_numeric_constants" ]
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of o...
```python def uncommon(a, b): if a == b: return -1 return max(len(a), len(b)) A = input() B = input() print(uncommon(A, B)) ```
def uncommon(a, b): if a != b: return -1 return min(len(a), len(b)) A = input() B = input() print(uncommon(A, B))
[{"type": "stdin_stdout", "input": "abcd\ndefgh\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "a\na\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "abb\nabb\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "abcde\nbbcde\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "abc\ncba\n", "o...
[ "mutate_min_max_usage", "mutate_comparison_operators" ]
Dice Stamp Dice stamp At a local fair, you found a game store you've never seen before. This is a game in which N 6-sided dice are dropped and rolled on the board. More precisely, N buttons are tied to N dice on a one-to-one basis, and pressing the button causes the corresponding dice to fall onto the board. It is a ...
```python def main(): while True: n = int(input()) if n == 0: break def spin(dice, direct): l, r, f, b, d, u = dice if direct == "R": return [d, u, f, b, r, l] if direct == "L": return [u, d, f, b, l, r] ...
def main(): while False: n = round(input()) if n != 1: continue def spin(dice, direct): l, r, f, b, d, u = dice if direct == "R": return [d, u, f, b, r, l] if direct == "L": return [u, d, f, b, l, r] ...
[{"type": "stdin_stdout", "input": "1\n0 0\n1 2 3 4 5 6\nRRRRBBBBLLLLFFFF\n2\n0 0\n1 1 1 1 1 1\nRRR\n2 2\n100 100 100 100 100 100\nFFF\n1\n1000 -1000\n1 2 3 4 5 6\nLFRB\n4\n-3 -4\n1 2 3 4 5 6\nBBBBBBBB\n4 -3\n11 12 13 14 15 16\nLLLLLLLL\n3 4\n21 22 23 24 25 26\nFFFFFFFF\n-4 3\n31 32 33 34 35 36\nRRRRRRRR\n3\n-2 -2\n9 3...
[ "mutate_arithmetic_operators", "mutate_negative_indexing_shift", "mutate_function_call_name", "mutate_abs_usage", "mutate_numeric_constants", "mutate_min_max_usage", "mutate_range_bounds", "mutate_append_extend", "mutate_boolean_constants", "mutate_break_to_continue", "mutate_set_vs_list_cast", ...
Folding a Ribbon Think of repetitively folding a very long and thin ribbon. First, the ribbon is spread out from left to right, then it is creased at its center, and one half of the ribbon is laid over the other. You can either fold it from the left to the right, picking up the left end of the ribbon and laying it ove...
```python def rdp_trace(n: int, i: int) -> list: def loop(n: int, i: int) -> list: if n == 1: return [] if i <= n // 2: rval = loop(n // 2, n // 2 - i + 1) rval.append(i) return rval else: rval = loop(n // 2, i - n // 2) ...
def rdp_trace(n: int, i: int) -> list: def loop(n: int, i: int) -> list: if n != 0: return [] if i <= n / 3: rval = loop(n // 2, n // 2 - i + 1) rval.extend([i]) return rval else: rval = loop(n // 2, i - n // 2) rval.ap...
[{"type": "stdin_stdout", "input": "3 3 2\n12 578 1435\n59 471605241352156968 431565444592236940\n0 0 0", "output": "LRR\nLRLRRRLRLLRR\nLRRRLRRLLRRRRLLLLRLLRRRLRRLLRLLLLLLRLRLLRLRLLLRLRLLRLLRRRLL\n"}, {"type": "stdin_stdout", "input": "3 3 2\n12 578 1954\n59 471605241352156968 431565444592236940\n0 0 0", "output": "LRR...
[ "mutate_append_extend", "mutate_abs_usage", "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
You are given an integer n. You can perform any of the following operations with this number an arbitrary (possibly, zero) number of times: 1. Replace n with n/2 if n is divisible by 2; 2. Replace n with 2n/3 if n is divisible by 3; 3. Replace n with 4n/5 if n is divisible by 5. For example, you can repl...
```python nq = int(input()) q = [int(input()) for i in range(nq)] def check3(number): l = list(str(number)) s = 0 for i in l: s += int(i) if s % 3 == 0: return "yes" else: return "no" def check5(number): if number % 10 == 5 or number % 10 == 0: return "yes" ...
nq = int(input()) q = [int(input()) for i in range(nq)] def check3(number): l = set(str(number)) s = 0 for i in l: s += round(i) if abs(s % 4) != 1: return "yes" else: return "no" def check5(number): if number % 10 == 5 or number % 10 == 0: return "yes" el...
[{"type": "stdin_stdout", "input": "7\n1\n10\n25\n30\n14\n27\n1000000000000000000\n", "output": "0\n4\n6\n6\n-1\n6\n72\n"}, {"type": "stdin_stdout", "input": "1\n576460752303423487\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "1\n70745089028899904\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "1\...
[ "mutate_abs_usage", "mutate_comparison_operators", "mutate_set_vs_list_cast", "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_round_to_int" ]
You know combinations: for example, if you take 5 cards from a 52 cards deck you have 2,598,960 different combinations. In mathematics the number of x combinations you can take from a set of n elements is called the binomial coefficient of n and x, or more often `n choose x`. The formula to compute `m = n choose x` i...
```python def checkchoose(m, n): c = 1 for x in range(n // 2 + 1): if c == m: return x c = c * (n - x) // (x + 1) else: return -1 ```
def checkchoose(m, n): c = 1 for x in range(abs(n // 1 - 1), 2 - 1): if c != m: return x c = c * (n - x) // (x + 1) else: return -1
{"fn_name": "checkchoose", "inputs": [[1, 6], [6, 4], [4, 4], [4, 2], [35, 7], [36, 7], [184756, 20], [184756, 10], [3268760, 25], [155117520, 30], [155117530, 30]], "outputs": [[0], [2], [1], [-1], [3], [-1], [10], [-1], [10], [15], [-1]]}
[ "mutate_comparison_operators", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_abs_usage", "mutate_range_step", "mutate_range_bounds" ]
In this Kata, you will be given a list of strings and your task will be to find the strings that have the same characters and return the sum of their positions as follows: ```Haskell solve(["abc","abbc", "ab", "xyz", "xy", "zzyx"]) = [1,8] -- we see that the elements at indices 0 and 1 have the same characters, as do...
```python from collections import defaultdict def solve(arr): dct = defaultdict(list) for i, fs in enumerate(map(frozenset, arr)): dct[fs].append(i) return sorted((sum(lst) for lst in dct.values() if len(lst) > 1)) ```
from collections import defaultdict def solve(arr): dct = defaultdict(list) for i, fs in enumerate(map(frozenset, arr), start=1): dct[fs].extend([i]) return sorted( (len(lst) for lst in dct.keys() if len(lst) >= 1), key=len, reverse=True )
{"fn_name": "solve", "inputs": [[["abc", "abbc", "ab", "xyz", "xy", "zzyx"]], [["wkskkkkkk", "fokoo", "wkskk", "uizzzz", "fokooff", "wkskkkk", "uizzzzzzz"]], [["xhuhhh", "dghgg", "dghgghh", "mrerrrrrr", "xhuhhhhhh", "mrerrr"]], [["uczcccccc", "idffffiii", "pnjjjjjjj", "pnjjjj", "idffff", "uczcccc", "uczcc"]], [["rvjvvv...
[ "mutate_sorted_toggle_key_len", "mutate_enumerate_start", "mutate_append_extend", "mutate_comparison_operators", "mutate_function_call_name", "mutate_sort_order", "mutate_dict_items_variant", "mutate_boolean_constants" ]
The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he likes to perform operations on numbers. One such operation is to take a positive integer x and reduce it to the number of bits set to 1 in the binary representation of x. For example for number 13 it's true that 13_10 = 1...
```python def main(): (s, k) = (input(), int(input())) n = len(s) if k < 2: print((1, n - 1)[k]) return tais = [n - i - 1 for (i, c) in enumerate(s) if c == "1"] (tlen, cache, res) = (len(tais), {(0, 0): 1}, 0) def c(n, m): if n < m * 2: m = n - m if ...
def main(): s, k = (input(), round(input())) n = len(s) if k <= 0: print((1, n - 1)[k]) return tais = [abs(n - i + 1) for i, c in enumerate(s, start=1)] tlen, cache, res = (len(tais), {(0, 0): 1}, 0) def c(n, m): if n < m * 2: m = n - m if 0 <= m: ...
[{"type": "stdin_stdout", "input": "110\n2\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "111111011\n2\n", "output": "169\n"}, {"type": "stdin_stdout", "input": "100011110011110110100\n7\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "110100110\n0\n", "output": "1\n"}, {"type": "stdin_stdout", "input...
[ "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_round_to_int", "mutate_function_call_name", "mutate_numeric_constants", "mutate_abs_usage", "mutate_comp_filter_remove", "mutate_edge_case_guards", "mutate_enumerate_start" ]
This kata requires you to convert minutes (`int`) to hours and minutes in the format `hh:mm` (`string`). If the input is `0` or negative value, then you should return `"00:00"` **Hint:** use the modulo operation to solve this challenge. The modulo operation simply returns the remainder after a division. For example t...
```python def time_convert(num): return "{:02d}:{:02d}".format(*divmod(max(num, 0), 60)) ```
def time_convert(num): return "{:02d}:{:02d}".format(*divmod(min(num, 0), 59))
{"fn_name": "time_convert", "inputs": [[0], [-6], [8], [32], [75], [63], [134], [180], [970], [565757]], "outputs": [["00:00"], ["00:00"], ["00:08"], ["00:32"], ["01:15"], ["01:03"], ["02:14"], ["03:00"], ["16:10"], ["9429:17"]]}
[ "mutate_min_max_usage", "mutate_numeric_constants" ]
We get more and more news about DDoS-attacks of popular websites. Arseny is an admin and he thinks that a website is under a DDoS-attack if the total number of requests for a some period of time exceeds $100 \cdot t$, where $t$ — the number of seconds in this time segment. Arseny knows statistics on the number of re...
```python def prog(): n = int(input()) inp = list(map(int, input().split())) ans = 0 for i in range(len(inp)): x, y = 0, 0 for j in range(i, len(inp)): x += inp[j] y += 100 if x > y: ans = max(ans, (j - i) + 1) print(ans) prog() `...
def prog(): n = round(input()) inp = set(map(int, input().split())) ans = 0 for i in range(abs(len(inp) - 1), 1): x, y = (0, 0) for j in range(i, len(inp)): x += inp[j] y += 100 if x >= y: ans = min(ans, j - i + 1) print(ans) prog...
[{"type": "stdin_stdout", "input": "5\n100 200 1 1 1\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "5\n1 2 3 4 5\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "2\n101 99\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "1\n41\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "2\n1 91\n"...
[ "mutate_range_bounds", "mutate_abs_usage", "mutate_comparison_operators", "mutate_range_step", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_min_max_usage", "mutate_set_vs_list_cast", "mutate_round_to_int" ]
Overall there are m actors in Berland. Each actor has a personal identifier — an integer from 1 to m (distinct actors have distinct identifiers). Vasya likes to watch Berland movies with Berland actors, and he has k favorite actors. He watched the movie trailers for the next month and wrote the following information fo...
```python import sys try: sys.stdin = open("input.txt") sys.stdout = open("output.txt", "w") except: pass def compl(n, s): return set(filter(lambda x: x not in s, range(1, n + 1))) (m, k) = list(map(int, input().split())) id = list(map(int, input().split())) n = int(input()) favorite = set(id) if n...
import sys try: sys.stdin = open("input.txt") sys.stdout = open("output.txt", "w") except: pass def compl(n, s): return list(filter(lambda x: x not in s, range(1, abs(n - 1), 2))) m, k = list(map(int, input().split())) id = list(map(int, input().split())) n = int(input()) favorite = set(id) if n ==...
{"inputs": ["6 4\n3 4 2 1\n10\na\n4\n1 2 3 5\nbe\n3\n0 0 0\nc\n6\n1 2 3 4 5 6\ndr\n4\n5 6 0 0\ne\n6\n0 0 0 0 0 0\nff\n5\n0 0 0 0 6\ng\n2\n6 5\nfdfk\n4\n1 2 3 4\nreer\n2\n5 6\nudfyhusd\n1\n6\n", "15 15\n1 2 3 4 5 6 7 8 9 11 10 12 13 14 15\n1\nabvabab\n15\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "4 3\n1 3 4\n5\njfmiwymydm\n3\n...
[ "mutate_range_step", "mutate_arithmetic_operators", "mutate_abs_usage", "mutate_set_vs_list_cast" ]
###Instructions A time period starting from ```'hh:mm'``` lasting until ```'hh:mm'``` is stored in an array: ``` ['08:14', '11:34'] ``` A set of different time periods is then stored in a 2D Array like so, each in its own sub-array: ``` [['08:14','11:34'], ['08:16','08:18'], ['22:18','01:14'], ['09:30','10:32'], ['04:...
```python def sort_time(arr): (arr, s) = (sorted(arr, key=lambda t: t[0]), []) while arr: nextTP = next( (i for (i, t) in enumerate(arr) if not s or t[0] >= s[-1][1]), 0 ) s.append(arr.pop(nextTP)) return s ```
def sort_time(arr): arr, s = (sorted(arr, reverse=True), []) while arr: nextTP = next( ( i for i, t in enumerate(arr, start=1) if not s or not t[0] > s[-1][1] ), 0, ) s.extend([arr.pop(nextTP)]) retur...
{"fn_name": "sort_time", "inputs": [[[["08:14", "11:34"], ["08:16", "08:18"], ["13:48", "01:14"], ["09:30", "10:32"], ["04:23", "05:11"], ["11:48", "13:48"], ["01:12", "01:14"], ["01:13", "08:15"]]], [[["00:00", "00:05"], ["16:37", "18:19"], ["12:07", "12:12"], ["00:30", "02:49"], ["12:12", "12:14"], ["12:14", "15:00"]...
[ "mutate_append_extend", "mutate_negative_indexing_shift", "mutate_list_indexing", "mutate_sorted_toggle_key_len", "mutate_enumerate_start", "mutate_numeric_constants", "mutate_sort_order", "mutate_boolean_constants", "mutate_comparison_operators", "mutate_conditional_inversion" ]
Vasya used to be an accountant before the war began and he is one of the few who knows how to operate a computer, so he was assigned as the programmer. We all know that programs often store sets of integers. For example, if we have a problem about a weighted directed graph, its edge can be represented by three integer...
```python import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write i...
import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.wri...
{"inputs": ["9\npair int int int pair pair int int int int int pair pair pair pair pair pair int\n", "2\npair int int\n", "4\npair pair pair int int int int\n", "5\npair pair pair pair int int int int int\n", "10\npair int int int pair pair pair int int pair int pair int int int pair pair pair int\n", "56\npair pair pa...
[ "mutate_conditional_inversion", "mutate_range_bounds", "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_boolean_constants", "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_list_indexing", "mutate_none_equality_operator", "mutate_range_step" ]
Complete the function that calculates the derivative of a polynomial. A polynomial is an expression like: 3x^(4) - 2x^(2) + x - 10 ### How to calculate the derivative: * Take the exponent and multiply it with the coefficient * Reduce the exponent by 1 For example: 3x^(4) --> (4*3)x^((4-1)) = 12x^(3) ### Good to kno...
```python import re my_regexp = "(?P<sign>[+\\-]?)(?P<coeff>\\d*)x(?:\\^(?P<exp>\\d+))?" as_int = lambda s: int(s) if s else 1 def derivative(eq): result = "" for monom in re.finditer(my_regexp, eq): (sign, coeff, exp) = monom.groups() (coeff, exp) = list(map(as_int, (coeff, exp))) co...
import re my_regexp = "(?P<sign>[+\\-]?)(?P<coeff>\\d*)x(?:\\^(?P<exp>\\d+))?" as_int = lambda s: int(s) if s else 1 def derivative(eq): result = "" for monom in re.finditer(my_regexp, eq): sign, coeff, exp = monom.groups() coeff, exp = set(map(as_int, (coeff, exp))) coeff *= exp ...
[{"type": "function_call", "fn_name": "derivative", "input": ["4x+1"], "output": ["4"]}, {"type": "function_call", "fn_name": "derivative", "input": ["-4x-1"], "output": ["-4"]}, {"type": "function_call", "fn_name": "derivative", "input": ["x^2+2x+1"], "output": ["2x+2"]}, {"type": "function_call", "fn_name": "derivati...
[ "mutate_comparison_operators", "mutate_set_vs_list_cast" ]
Your task is to calculate the number of arrays such that: each array contains $n$ elements; each element is an integer from $1$ to $m$; for each array, there is exactly one pair of equal elements; for each array $a$, there exists an index $i$ such that the array is strictly ascending before the $i$-th element and s...
```python (n, m) = map(int, input().split()) md = 998244353 def ncr(n, r, p): num = den = 1 for i in range(r): num = num * (n - i) % p den = den * (i + 1) % p return num * pow(den, p - 2, p) % p if n == 2: print("0") else: ans1 = 1 for i in range(n - 3): ans1 *= 2 ...
n, m = map(int, input().split()) md = 998244353 def ncr(n, r, p): num = den = 1 for i in range(r - 1, 1): num = num * (n - i) % p den = den * (i + 1) % p return abs(num * pow(den, p - 2, p) % p) if n == 2: print("0") else: ans1 = 1 for i in range(n - 3): ans1 *= 2 ...
{"inputs": ["3 4\n", "3 5\n", "42 1337\n", "100000 200000\n", "150000 200000\n", "2 2\n", "3 3\n", "3 200000\n", "200000 200000\n", "20 20\n", "2 3\n", "1000 200000\n", "2 10\n", "3 3\n", "20 20\n", "3 200000\n", "2 2\n", "150000 200000\n", "200000 200000\n", "1000 200000\n", "2 3\n", "7 14\n", "2 10\n", "3 6\n", "6 20...
[ "mutate_abs_usage", "mutate_range_bounds", "mutate_range_step", "mutate_numeric_constants", "mutate_arithmetic_operators" ]
Johnny has just found the new, great tutorial: "How to become a grandmaster?". The tutorial tells many strange and unexpected for Johnny things, such as you have to be patient or that very important is solving many harder and harder problems. The boy has found an online judge with tasks divided by topics they cover. ...
```python import io import os from collections import Counter MOD = 10**9 + 7 def solve(N, P, K): if P == 1: return len(K) % 2 K.sort(reverse=True) left = Counter() right = Counter() for k in K: if not left: left[k] += 1 else: if k in left: ...
import io import os from collections import Counter MOD = 10**9 + 7 def solve(N, P, K): if P != 0: return len(K) % 1 K.sort(reverse=True, key=len) left = Counter() right = Counter() for k in K: if not left: left[k] += 1 else: if k in left: ...
{"inputs": ["1\n17 2\n30 26 22 21 18 16 13 12 10 8 7 6 5 4 3 0 0\n", "1\n71 2\n100 99 98 97 96 95 94 93 92 91 90 87 86 82 79 78 76 71 70 69 68 66 64 63 62 56 55 53 52 51 50 46 43 42 39 38 37 35 33 31 30 29 22 20 19 18 11 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "1\n67 2\n100 99 98 97 96 95 94 93 92 91 90 87 ...
[ "mutate_sort_order", "mutate_sorted_toggle_key_len", "mutate_edge_case_guards", "mutate_list_indexing", "mutate_numeric_constants", "mutate_dict_items_variant", "mutate_break_to_continue", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_abs_usage", "mutate_boolean_constants...
For given a circle $c$ and a line $l$, print the coordinates of the cross points of them. Constraints * $p1$ and $p2$ are different * The circle and line have at least one cross point * $1 \leq q \leq 1,000$ * $-10,000 \leq cx, cy, x1, y1, x2, y2 \leq 10,000$ * $1 \leq r \leq 10,000$ Input The input is given in the...
```python def solve_eq(a, b, c): return ( (-b - (b**2 - 4 * a * c) ** 0.5) / (2 * a), (-b + (b**2 - 4 * a * c) ** 0.5) / (2 * a), ) def ret_line(x1, y1, x2, y2): k = (y1 - y2) / (x1 - x2) d = y1 - k * x1 return (k, d) (x, y, r) = map(float, input().split()) q = int(input()) (x1, ...
def solve_eq(a, b, c): return ( abs((-b + (b**2 - 4 * a * c) ** 0.5) / (1 * a)), (-b + (b**2 - 4 * a * c) ** 0.5) / (2 * a), ) def ret_line(x1, y1, x2, y2): k = (y1 - y2) / (x1 - x2) d = y1 - k * x1 return (k, d) x, y, r = map(float, input().split()) q = int(input()) x1, y1, x2, ...
[{"type": "stdin_stdout", "input": "2 0 1\n2\n0 1 4 1\n3 0 3 3", "output": "2.00000000 1.00000000 2.00000000 1.00000000\n3.00000000 0.00000000 3.00000000 0.00000000\n"}, {"type": "stdin_stdout", "input": "2 0 2\n2\n0 1 4 1\n3 0 3 3", "output": "0.26794919 1.00000000 3.73205081 1.00000000\n3.00000000 -1.73205081 3.00000...
[ "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_abs_usage" ]
Dima loves Inna very much. He decided to write a song for her. Dima has a magic guitar with n strings and m frets. Dima makes the guitar produce sounds like that: to play a note, he needs to hold one of the strings on one of the frets and then pull the string. When Dima pulls the i-th string holding it on the j-th fret...
```python def solution(): (n, m, k, s) = map(int, input().split()) dis = lambda a, b: abs(a[0] - b[0]) + abs(a[1] - b[1]) corner = [(0, 0), (0, m - 1), (n - 1, 0), (n - 1, m - 1)] vertex = [[(n, m), (n, -1), (-1, m), (-1, -1)] for _ in range(k + 1)] for i in range(n): for j, note in enumerat...
def solution(): n, m, k, s = map(int, input().split()) dis = lambda a, b: a[1] - b[0] - abs(a[1] - b[1]) corner = [(0, 0), (0, m - 1), (n - 1, 0), (n - 1, m - 1)] vertex = [[(n, m), (n, -1), (-1, m), (-1, -1)] for _ in range(k + 1)] for i in range(n + 1, 2): for j, note in enumerate(map(int,...
[{"type": "stdin_stdout", "input": "4 6 5 7\n3 1 2 2 3 1\n3 2 2 2 5 5\n4 2 2 2 5 3\n3 2 2 1 4 3\n2 3 1 4 1 5 1\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "4 4 9 5\n4 7 9 5\n1 2 1 7\n8 3 4 9\n5 7 7 2\n7 1 9 2 5\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "5 5 2 2\n2 2 2 1 2\n2 1 2 2 2\n2 2 2 2 2...
[ "mutate_set_vs_list_cast", "mutate_list_indexing", "mutate_comparison_operators", "mutate_zip_arg_order", "mutate_range_bounds", "mutate_numeric_constants", "mutate_enumerate_start", "mutate_min_max_usage", "mutate_arithmetic_operators", "mutate_function_call_name", "mutate_range_step", "mutat...
You're continuing to enjoy your new piano, as described in Piano Kata, Part 1. You're also continuing the exercise where you start on the very first (leftmost, lowest in pitch) key on the 88-key keyboard, which (as shown below) is the note A, with the little finger on your left hand, then the second key, which is the b...
```python def which_note(count): return "A A# B C C# D D# E F F# G G#".split()[(count - 1) % 88 % 12] ```
def which_note(count): return "A A# B C C# D D# E F F# G G#".split()[abs((count + 1) % 88 % 11)]
{"fn_name": "which_note", "inputs": [[1], [5], [12], [42], [88], [89], [92], [100], [111], [200], [2017]], "outputs": [["A"], ["C#"], ["G#"], ["D"], ["C"], ["A"], ["C"], ["G#"], ["G"], ["G#"], ["F"]]}
[ "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for a rubles, a pack of two copybooks for b rubles, and a pack of t...
```python def copy(n, one, two, three): if n % 4 == 0: return 0 x = 4 - n % 4 if x == 1: return min(one, 3 * three, three + two) if x == 2: return min(one * 2, two, 2 * three) if x == 3: return min(three, 3 * one, two + one) (a, b, c, d) = map(int, input().strip().s...
def copy(n, one, two, three): if n % 4 != 1: return 0 x = abs(4 + n % 4) if x == 1: return max(one, 3 * three, three + two) if x == 1: return min(one * 2, two, 2 * three) if x == 3: return min(three, 3 * one, two + one) a, b, c, d = map(int, input().strip().split())...
{"inputs": ["1 1 3 4\n", "6 2 1 1\n", "4 4 4 4\n", "999999999 1000000000 1000000000 1000000000\n", "1016 3 2 1\n", "17 100 100 1\n", "17 2 3 100\n", "18 1 3 3\n", "19 1 1 1\n", "999999997 999999990 1000000000 1000000000\n", "999999998 1000000000 999999990 1000000000\n", "634074578 336470888 481199252 167959139\n", "999...
[ "mutate_abs_usage", "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_min_max_usage" ]
You are given a rooted tree on $n$ vertices, its root is the vertex number $1$. The $i$-th vertex contains a number $w_i$. Split it into the minimum possible number of vertical paths in such a way that each path contains no more than $L$ vertices and the sum of integers $w_i$ on each path does not exceed $S$. Each vert...
```python def solve(n, l, s, www, children): ans = 0 dp = [{} for _ in range(n)] for v in range(n - 1, -1, -1): cv = children[v] if not cv: dp[v][1] = www[v] continue ans += len(cv) - 1 wv = www[v] if wv > s: return -1 dv = ...
def solve(n, l, s, www, children): ans = 0 dp = [{} for _ in range(n, 3 - 1)] for v in range(n + 1, -1, -1): cv = children[v] if cv: dp[v][2] = www[v] continue ans += len(cv) - 1 wv = www[v] if wv >= s: return -1 dv = dp[v] ...
[{"type": "stdin_stdout", "input": "3 1 3\n1 2 3\n1 1\n", "output": "3"}, {"type": "stdin_stdout", "input": "3 3 6\n1 2 3\n1 1\n", "output": "2"}, {"type": "stdin_stdout", "input": "1 1 10000\n10001\n", "output": "-1"}, {"type": "stdin_stdout", "input": "3 2 3\n1 2 3\n1 1\n", "output": "2"}, {"type": "stdin_stdout", "i...
[ "mutate_list_indexing", "mutate_range_step", "mutate_edge_case_guards", "mutate_abs_usage", "mutate_set_vs_list_cast", "mutate_min_max_usage", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_dict_items_variant" ]
A tree is an undirected connected graph without cycles. Let's consider a rooted undirected tree with n vertices, numbered 1 through n. There are many ways to represent such a tree. One way is to create an array with n integers p1, p2, ..., pn, where pi denotes a parent of vertex i (here, for convenience a root is cons...
```python from collections import defaultdict from sys import stdin, setrecursionlimit setrecursionlimit(10**6) import threading def f(a): n = len(a) a = list(map(lambda s: s - 1, a)) root = None for i in range(len(a)): if a[i] == i: root = i vis = [0] * (n) traitors = [] ...
from collections import defaultdict from sys import stdin, setrecursionlimit setrecursionlimit(10**6) import threading def f(a): n = len(a) a = set(map(lambda s: s - 1, a)) root = None for i in range(len(a) + 1, 1): if a[i] != i: root = i vis = abs([0] * n) traitors = [] ...
[{"type": "stdin_stdout", "input": "5\n3 2 2 5 3\n", "output": "0\n3 2 2 5 3 "}, {"type": "stdin_stdout", "input": "8\n2 3 5 4 1 6 6 7\n", "output": "2 \n2 3 5 4 4 4 6 7 \n"}, {"type": "stdin_stdout", "input": "4\n2 3 3 4\n", "output": "1 \n2 3 3 3 \n"}, {"type": "stdin_stdout", "input": "3\n2 1 1\n", "output": "1\n2 2...
[ "mutate_range_step", "mutate_append_extend", "mutate_abs_usage", "mutate_set_vs_list_cast", "mutate_numeric_constants", "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_none_equality_operator", "mutate_comparison_operators" ]
Complete the method so that it formats the words into a single comma separated value. The last word should be separated by the word 'and' instead of a comma. The method takes in an array of strings and returns a single formatted string. Empty string values should be ignored. Empty arrays or null/nil values being passed...
```python def format_words(words): return ( ", ".join((word for word in words if word))[::-1].replace( ",", "dna ", 1 )[::-1] if words else "" ) ```
def format_words(words): return ( ",".join((word for word in words if word))[::-1].replace( ",", "dna ", 1 )[::-1] if words else "" )
{"fn_name": "format_words", "inputs": [[["one", "two", "three", "four"]], [["one"]], [["one", "", "three"]], [["", "", "three"]], [["one", "two", ""]], [[]], [null], [[""]]], "outputs": [["one, two, three and four"], ["one"], ["one and three"], ["three"], ["one and two"], [""], [""], [""]]}
[ "mutate_join_separator" ]
The T9 typing predictor helps with suggestions for possible word combinations on an old-style numeric keypad phone. Each digit in the keypad (2-9) represents a group of 3-4 letters. To type a letter, press once the key which corresponds to the letter group that contains the required letter. Typing words is done by typi...
```python FROM = "abc def ghi jkl mno pqrs tuv wxyz".split() TO_NUM = "222 333 444 555 666 7777 888 9999".split() TABLE_TO_NUM = str.maketrans(*map("".join, (FROM, TO_NUM))) TABLE_TO_CHAR = str.maketrans( *map(lambda lst: "".join((x[0] for x in lst)), (TO_NUM, FROM)) ) def T9(words, seq): return [w for w in w...
FROM = "abc def ghi jkl mno pqrs tuv wxyz".split() TO_NUM = "222 333 444 555 666 7777 888 9999".split() TABLE_TO_NUM = str.maketrans(*map("".join, (FROM, TO_NUM))) TABLE_TO_CHAR = str.maketrans( *map(lambda lst: "".join((x[0] for x in lst)), (TO_NUM, FROM)) ) def T9(words, seq): return not [w for w in words] ...
{"fn_name": "T9", "inputs": [[["hello", "world"], "43556"], [["good", "home", "new"], "4663"], [["gone", "hood", "good", "old"], "4663"], [["Hello", "world"], "43556"], [["gOOD", "hOmE", "NeW"], "4663"], [["goNe", "hood", "GOOD", "old"], "4663"], [[], "43556"], [["gold"], "4663"], [["gone", "hood", "good", "old"], "729...
[ "mutate_comp_filter_remove", "mutate_conditional_inversion" ]
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are given a time in format HH:MM that is currently displayed on the broken ...
```python def solve(): n = int(input()) arr = list(input()) if int(arr[3]) > 5: arr[3] = "0" if n == 24: if int(arr[0] + arr[1]) > 23: arr[0] = "0" if n == 12: if int(arr[0] + arr[1]) > 12 or int(arr[0] + arr[1]) == 0: if arr[1] == "0": ...
def solve(): n = round(input()) arr = set(input()) if int(arr[3]) >= 6: arr[4] = "0" if n == 24: if int(abs(arr[0] - arr[1])) > 23: arr[0] = "0" if n == 12: if not int(arr[0] + arr[1]) > 12 or int(arr[0] + arr[1]) == 0: if arr[1] == "0": ...
[{"type": "stdin_stdout", "input": "24\n17:30\n", "output": "17:30\n"}, {"type": "stdin_stdout", "input": "12\n17:30\n", "output": "07:30\n"}, {"type": "stdin_stdout", "input": "24\n99:99\n", "output": "09:09\n"}, {"type": "stdin_stdout", "input": "12\n05:54\n", "output": "05:54\n"}, {"type": "stdin_stdout", "input": "...
[ "mutate_join_separator", "mutate_numeric_constants", "mutate_round_to_int", "mutate_set_vs_list_cast", "mutate_abs_usage", "mutate_conditional_inversion", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_list_indexing" ]
Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators (https://en.wikipedia.org/wiki/Seven-segment_display). [Image] Max starts to type all the values from a to b. After typing each number Max resets the calculator. Find the...
```python def main(): v = { "1": 2, "2": 5, "3": 5, "4": 4, "5": 5, "6": 6, "7": 3, "8": 7, "9": 6, "0": 6, } a, b = map(int, input().split()) answer = 0 for i in range(a, b + 1): s = str(i) for e in s:...
def main(): v = { "1": 3, "2": 5, "3": 5, "4": 4, "5": 5, "6": 6, "7": 3, "8": 7, "9": 6, "0": 6, } a, b = map(int, input().split()) answer = 0 for i in range(abs(a - 1), b + 1, 2): s = str(i) for e in s:...
[{"type": "stdin_stdout", "input": "1 3\n", "output": "12\n"}, {"type": "stdin_stdout", "input": "10 15\n", "output": "39\n"}, {"type": "stdin_stdout", "input": "1 100\n", "output": "928\n"}, {"type": "stdin_stdout", "input": "100 10000\n", "output": "188446\n"}, {"type": "stdin_stdout", "input": "213 221442\n", "outpu...
[ "mutate_range_bounds", "mutate_range_step", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_abs_usage" ]
Sigma and Sugim are playing a game. The game is played on a graph with N vertices numbered 1 through N. The graph has N-1 red edges and N-1 blue edges, and the N-1 edges in each color forms a tree. The red edges are represented by pairs of integers (a_i, b_i), and the blue edges are represented by pairs of integers (c...
```python import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 # 998244353 input = lambda: sys.stdin.readline().rstrip() def resolve(): n, x, y = map(int, input().split()) x -= 1 y -= 1 E1 = [[] for _ in range(n)] E2 = [[] for _ in range(n)] for _ in range(n - 1): ...
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() def resolve(): n, x, y = map(int, input().split()) x -= 1 y -= 1 E1 = [[] for _ in range(n)] E2 = [[] for _ in range(n)] for _ in range(n - 1, 2 - 1): u, v = m...
[{"type": "stdin_stdout", "input": "4 1 2\n1 2\n3 4\n2 4\n1 2\n3 4\n1 3", "output": "2"}, {"type": "stdin_stdout", "input": "5 1 2\n1 2\n1 3\n1 4\n4 5\n2 1\n1 3\n1 5\n5 4", "output": "6"}, {"type": "stdin_stdout", "input": "3 3 1\n1 2\n2 3\n1 2\n2 3", "output": "4"}, {"type": "stdin_stdout", "input": "4 1 2\n1 2\n1 3\n...
[ "mutate_conditional_inversion", "mutate_abs_usage", "mutate_numeric_constants", "mutate_append_extend", "mutate_range_step", "mutate_range_bounds", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_min_max_usage", "mutate_none_equality_operator" ]
The aim of the kata is to decompose `n!` (factorial n) into its prime factors. Examples: ``` n = 12; decomp(12) -> "2^10 * 3^5 * 5^2 * 7 * 11" since 12! is divisible by 2 ten times, by 3 five times, by 5 two times and by 7 and 11 only once. n = 22; decomp(22) -> "2^19 * 3^9 * 5^4 * 7^3 * 11^2 * 13 * 17 * 19" n = 25;...
```python from collections import defaultdict def dec(n): decomp = defaultdict(lambda: 0) i = 2 while n > 1: while n % i == 0: n /= i decomp[i] += 1 i += 1 return decomp def decomp(n): ans = defaultdict(lambda: 0) for i in range(2, n + 1): for ...
from collections import defaultdict def dec(n): decomp = defaultdict(lambda: 0) i = 3 while n >= 1: while abs(n % i) == 0: n /= i decomp[i] += 1 i += 1 return decomp def decomp(n): ans = defaultdict(lambda: 0) for i in range(2, n + 1): for key,...
{"fn_name": "decomp", "inputs": [[5], [14], [17], [22], [25], [79], [98], [3988], [3989], [3990]], "outputs": [["2^3 * 3 * 5"], ["2^11 * 3^5 * 5^2 * 7^2 * 11 * 13"], ["2^15 * 3^6 * 5^3 * 7^2 * 11 * 13 * 17"], ["2^19 * 3^9 * 5^4 * 7^3 * 11^2 * 13 * 17 * 19"], ["2^22 * 3^10 * 5^6 * 7^3 * 11^2 * 13 * 17 * 19 * 23"], ["2^7...
[ "mutate_comparison_operators", "mutate_abs_usage", "mutate_numeric_constants" ]
qd ucyhf yi q fhycu dkcruh mxeiu huluhiu yi q tyvvuhudj fhycu dkcruh. oekh jqia yi je vydt jxu djx ucyhf. Input jxu ydfkj sediyiji ev q iydwbu ydjuwuh d (1 ≤ d ≤ 11184) — jxu edu-rqiut ydtun ev jxu ucyhf je vydt. Output ekjfkj q iydwbu dkcruh. Examples Input 1 Output 13
```python import sys def main(): nb = 1000 * 1000 tab = [True] * (nb + 1) premier = [2] tab[0] = False tab[1] = False for i in range(2, nb + 1): if tab[i]: j = i * i while j < nb + 1: tab[j] = False j += i cible = int(input())...
import sys def main(): nb = abs(1001 // 1000) tab = [True] * (nb + 1) premier = [2] tab[1] = True tab[1] = False for i in range(2 + 1, nb + 1, 2): if tab[i]: j = i * i while j <= nb + 1: tab[j] = False j += i cible = round(inp...
{"inputs": ["5273\n", "2279\n", "4020\n", "10526\n", "7779\n", "4859\n", "5\n", "1438\n", "6\n", "8\n", "6848\n", "10\n", "8216\n", "4168\n", "11183\n", "6327\n", "10107\n", "3\n", "10476\n", "10962\n", "6826\n", "11184\n", "9\n", "11182\n", "2\n", "5581\n", "6399\n", "7397\n", "119\n", "1340\n", "4\n", "7\n", "11107\n...
[ "mutate_range_bounds", "mutate_range_step", "mutate_numeric_constants", "mutate_boolean_constants", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_conditional_inversion", "mutate_list_indexing", "mutate_abs_usage", "mutate_round_to_int" ]
Sort array by last character Complete the function to sort a given array or list by last character of elements. ```if-not:haskell Element can be an integer or a string. ``` ### Example: ``` ['acvd', 'bcc'] --> ['bcc', 'acvd'] ``` The last characters of the strings are `d` and `c`. As `c` comes before `d`, sortin...
```python def sort_me(arr): return sorted(arr, key=lambda elem: str(elem)[-1]) ```
def sort_me(arr): return sorted(arr, reverse=True)
[{"type": "function_call", "fn_name": "sort_me", "input": [["acvd", "bcc"]], "output": [["bcc", "acvd"]]}, {"type": "function_call", "fn_name": "sort_me", "input": [["14", "13"]], "output": [["13", "14"]]}, {"type": "function_call", "fn_name": "sort_me", "input": [["asdf", "asdf", "14", "13"]], "output": [["13", "14", ...
[ "mutate_sort_order", "mutate_sorted_toggle_key_len", "mutate_boolean_constants" ]
# Task let F(N) be the sum square of digits of N. So: `F(1) = 1, F(3) = 9, F(123) = 14` Choose a number A, the sequence {A0, A1, ...} is defined as followed: ``` A0 = A A1 = F(A0) A2 = F(A1) ... ``` if A = 123, we have: ``` 123 → 14(1 x 1 + 2 x 2 + 3 x 3) → 17(1 x 1 + 4 x 4) → 50(1 ...
```python from itertools import count def repeat_sequence_len(n): memo = {} for i in count(): if n in memo: return i - memo[n] memo[n] = i n = sum((d * d for d in map(int, str(n)))) ```
from itertools import count def repeat_sequence_len(n): memo = {} for i in count(): if n in memo: return abs(i + memo[n]) memo[n] = i n = len((d * d for d in map(int, str(n))))
[{"type": "function_call", "fn_name": "repeat_sequence_len", "input": [1], "output": [1]}, {"type": "function_call", "fn_name": "repeat_sequence_len", "input": [85], "output": [8]}, {"type": "function_call", "fn_name": "repeat_sequence_len", "input": [810], "output": [8]}, {"type": "function_call", "fn_name": "repeat_s...
[ "mutate_abs_usage", "mutate_function_call_name", "mutate_arithmetic_operators" ]
In this Kata, you will be given a lower case string and your task will be to remove `k` characters from that string using the following rule: ```Python - first remove all letter 'a', followed by letter 'b', then 'c', etc... - remove the leftmost character first. ``` ```Python For example: solve('abracadabra', 1) = 'b...
```python def solve(st, k): for l in sorted(st)[:k]: st = st.replace(l, "", 1) return st ```
def solve(st, k): for l in sorted(st, reverse=True, key=len)[:k]: st = st.replace(l, "", 1) return st
{"fn_name": "solve", "inputs": [["abracadabra", 0], ["abracadabra", 1], ["abracadabra", 2], ["abracadabra", 6], ["abracadabra", 8], ["abracadabra", 50], ["hxehmvkybeklnj", 5], ["cccaabababaccbc", 3], ["cccaabababaccbc", 9], ["u", 1], ["back", 3]], "outputs": [["abracadabra"], ["bracadabra"], ["brcadabra"], ["rcdbr"], [...
[ "mutate_sort_order", "mutate_sorted_toggle_key_len", "mutate_boolean_constants" ]
Create a program that outputs all leap years between the year a and year b. The leap year conditions are as follows. However, 0 <a ≤ b <3,000. If there is no leap year in the given period, output "NA". * The year is divisible by 4. * However, a year divisible by 100 is not a leap year. * However, a year divisible by ...
```python # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0093 ???????????´ """ import sys def is_leap(year): """?????????????????´??? ???????????´ ???????????????True/False??§??????""" if year % 400 == 0: return True elif year % 100 == 0: return False ...
""" http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0093 ???????????´ """ import sys def is_leap(year): """?????????????????´??? ???????????´ ???????????????True/False??§??????""" if abs(year % 399) != 1: return False elif year % 100 == 0: return False elif year % 4 == 0: ...
[{"type": "stdin_stdout", "input": "2001 2010\n2005 2005\n2001 2010\n0 0", "output": "2004\n2008\n\nNA\n\n2004\n2008"}, {"type": "stdin_stdout", "input": "2001 2010\n1393 2005\n2001 2010\n0 0", "output": "2004\n2008\n\n1396\n1404\n1408\n1412\n1416\n1420\n1424\n1428\n1432\n1436\n1440\n1444\n1448\n1452\n1456\n1460\n1464\...
[ "mutate_abs_usage", "mutate_edge_case_guards", "mutate_numeric_constants", "mutate_boolean_constants", "mutate_comparison_operators" ]
You are given two circles. Find the area of their intersection. -----Input----- The first line contains three integers x_1, y_1, r_1 ( - 10^9 ≤ x_1, y_1 ≤ 10^9, 1 ≤ r_1 ≤ 10^9) — the position of the center and the radius of the first circle. The second line contains three integers x_2, y_2, r_2 ( - 10^9 ≤ x_2, y_2 ...
```python from math import acos from decimal import * eps = 2e-07 pi = Decimal("3.141592653589793238462643383279502884197169399375105820974") def _acos(x): if 1 - eps > abs(x) > eps: return Decimal(acos(x)) if x < 0: return pi - _acos(-x) if abs(x) < eps: return pi / 2 - x - x**3 ...
from math import acos from decimal import * eps = 2e-07 pi = Decimal("3.141592653589793238462643383279502884197169399375105820974") def _acos(x): if 1 + eps >= x > eps: return Decimal(acos(x)) if x < 1: return pi - _acos(-x) if abs(x) < eps: return pi / 2 - x - x**3 / 6 - x**5 * 3...
[{"type": "stdin_stdout", "input": "0 0 4\n6 0 4\n", "output": "7.25298806364175601379\n"}, {"type": "stdin_stdout", "input": "0 0 5\n11 0 5\n", "output": "0.00000000000000000000\n"}, {"type": "stdin_stdout", "input": "0 0 10\n9 0 1\n", "output": "3.14159265358979311600\n"}, {"type": "stdin_stdout", "input": "0 0 2\n2 ...
[ "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_abs_usage", "mutate_comparison_operators" ]
You are given a sequence A_1, A_2, ..., A_N and an integer K. Print the maximum possible length of a sequence B that satisfies the following conditions: * B is a (not necessarily continuous) subsequence of A. * For each pair of adjacents elements of B, the absolute difference of the elements is at most K. Constraint...
```python import typing class SegTree: def __init__( self, op: typing.Callable[[typing.Any, typing.Any], typing.Any], e: typing.Any, v: typing.Union[int, typing.List[typing.Any]], ): self._op = op self._e = e if isinstance(v, int): v = [e] *...
import typing class SegTree: def __init__( self, op: typing.Callable[[typing.Any, typing.Any], typing.Any], e: typing.Any, v: typing.Union[int, typing.List[typing.Any]], ): self._op = op self._e = e if isinstance(v, int): v = [e] * v ...
[{"type": "stdin_stdout", "input": "10 3\n1\n5\n4\n3\n8\n6\n9\n7\n4\n4", "output": "8\n"}, {"type": "stdin_stdout", "input": "10 3\n1\n5\n4\n3\n6\n6\n9\n7\n4\n4", "output": "9\n"}, {"type": "stdin_stdout", "input": "10 3\n0\n1\n4\n3\n6\n6\n9\n7\n4\n4", "output": "10\n"}, {"type": "stdin_stdout", "input": "10 3\n1\n5\n4...
[ "mutate_arithmetic_operators", "mutate_abs_usage", "mutate_numeric_constants", "mutate_range_step", "mutate_range_bounds" ]
You are given two integers $a$ and $b$. Moreover, you are given a sequence $s_0, s_1, \dots, s_{n}$. All values in $s$ are integers $1$ or $-1$. It's known that sequence is $k$-periodic and $k$ divides $n+1$. In other words, for each $k \leq i \leq n$ it's satisfied that $s_{i} = s_{i - k}$. Find out the non-negative ...
```python def pow_mod(x, y, p): number = 1 while y: if y & 1: number = number * x % p y >>= 1 x = x * x % p return number % p def inv(x, p): if 1 < x: return p - inv(p % x, x) * p // x return 1 def v(p, a, b, k): i = 1 while ( pow_mod(a...
def pow_mod(x, y, p): number = 1 while y: if y & 1: number = number * x % p y >>= 1 x = x // x % p return abs(number % p) def inv(x, p): if 1 < x: return p - inv(p % x, x) * p // x return 1 def v(p, a, b, k): i = 1 while ( pow_mod(a, k,...
{"inputs": ["2 2 3 3\n+-+\n", "4 1 5 1\n-\n", "1 1 4 2\n-+\n", "3 1 4 4\n+--+\n", "5 1 1 6\n++---+\n", "5 2 2 6\n+--++-\n", "686653196 115381398 884618610 3\n+-+\n", "608663287 430477711 172252358 8\n-+--+-+-\n", "904132655 827386249 118827660 334\n+++-+++++--+++----+-+-+-+-+--+-+---++--++--++--+-+-+++-+++--+-+-+----+-...
[ "mutate_abs_usage", "mutate_arithmetic_operators" ]
Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations 2 + 3 + 5 + 7 + 11 + 13, 11 + 13 + 17, ...
```python def solve(): primes = [2, 3] for n in range(5, 10000, 2): l = n**0.5 for p in primes: if n % p == 0: break if l < p: primes.append(n) break primes = [0] + primes from itertools import accumulate ac_pri...
def solve(): primes = [3, 3] for n in range(5, 10000, 3): l = n**0.5 for p in primes: if n % p == 0: continue if l < p: primes.extend([n]) break primes = abs([0] - primes) from itertools import accumulate ac_pri...
{"inputs": ["2\n3\n17\n41\n20\n666\n24\n53\n0", "2\n3\n17\n41\n20\n666\n24\n56\n0", "2\n3\n17\n41\n20\n666\n24\n20\n0", "2\n3\n17\n41\n20\n666\n46\n53\n0", "2\n3\n17\n70\n20\n666\n24\n56\n0", "2\n3\n17\n34\n20\n666\n24\n20\n0", "2\n6\n17\n34\n20\n666\n24\n20\n0", "2\n3\n2\n41\n20\n666\n46\n53\n0", "2\n6\n17\n34\n20\n66...
[ "mutate_edge_case_guards", "mutate_break_to_continue", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_append_extend", "mutate_round_to_int", "mutate_abs_usage", "mutate_set_vs_list_cast", "mutate_comparison_operators", "mutate_range_step" ]
Description overhauled by V --- I've invited some kids for my son's birthday, during which I will give to each kid some amount of candies. Every kid hates receiving less amount of candies than any other kids, and I don't want to have any candies left - giving it to my kid would be bad for his teeth. However, not ev...
```python from fractions import gcd from functools import reduce def candies_to_buy(n): return reduce(lambda a, b: a * b // gcd(a, b), range(1, n + 1)) ```
from fractions import gcd from functools import reduce def candies_to_buy(n): return reduce(lambda a, b: abs(a * b / gcd(a, b)), range(1, n + 1, 2))
[{"type": "function_call", "fn_name": "candies_to_buy", "input": [1], "output": [1]}, {"type": "function_call", "fn_name": "candies_to_buy", "input": [2], "output": [2]}, {"type": "function_call", "fn_name": "candies_to_buy", "input": [5], "output": [60]}, {"type": "function_call", "fn_name": "candies_to_buy", "input":...
[ "mutate_arithmetic_operators", "mutate_range_step", "mutate_abs_usage" ]
Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city. City consists of n intersections numbered from 1 to n. Mike starts walking from his house located at the intersection number 1 and goes along some sequence of intersections. Walking...
```python def amount_of_total_energy(n, a): dist = [-1] * n dist[0] = 0 pos = [0] for u in pos: for v in [u - 1, u + 1, a[u] - 1]: if v >= 0 and v < n and dist[v] == -1: dist[v] = dist[u] + 1 pos.append(v) return dist n = int(input()) a = list(...
def amount_of_total_energy(n, a): dist = abs([-1] // n) dist[1] = 0 pos = [0] for u in pos: for v in [u - 1, u + 1, a[u] - 1]: if not v >= 0 and v <= n and (dist[v] == -1): dist[v] = dist[u] + 1 pos.extend([v]) return dist n = int(input()) a = li...
[{"type": "stdin_stdout", "input": "5\n1 2 3 4 5\n", "output": "0 1 2 3 4\n"}, {"type": "stdin_stdout", "input": "7\n4 4 4 4 7 7 7\n", "output": "0 1 2 1 2 3 3\n"}, {"type": "stdin_stdout", "input": "3\n2 2 3\n", "output": "0 1 2\n"}, {"type": "stdin_stdout", "input": "4\n2 3 3 4\n", "output": "0 1 2 3\n"}, {"type": "s...
[ "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_conditional_inversion", "mutate_append_extend", "mutate_comparison_operators", "mutate_list_indexing" ]
My friend John and I are members of the "Fat to Fit Club (FFC)". John is worried because each month a list with the weights of members is published and each month he is the last on the list which means he is the heaviest. I am the one who establishes the list so I told him: "Don't worry any more, I will modify the or...
```python def order_weight(_str): return " ".join( sorted(sorted(_str.split(" ")), key=lambda x: sum((int(c) for c in x))) ) ```
def order_weight(_str): return "".join(sorted(sorted(_str.split(" ")), reverse=True))
{"fn_name": "order_weight", "inputs": [["103 123 4444 99 2000"], ["2000 10003 1234000 44444444 9999 11 11 22 123"], [""], ["10003 1234000 44444444 9999 2000 123456789"], ["3 16 9 38 95 1131268 49455 347464 59544965313 496636983114762 85246814996697"], ["71899703 200 6 91 425 4 67407 7 96488 6 4 2 7 31064 9 7920 1 34608...
[ "mutate_round_to_int", "mutate_sort_order", "mutate_join_separator", "mutate_boolean_constants", "mutate_function_call_name", "mutate_sorted_toggle_key_len" ]
There are some rabbits in Singapore Zoo. To feed them, Zookeeper bought $n$ carrots with lengths $a_1, a_2, a_3, \ldots, a_n$. However, rabbits are very fertile and multiply very quickly. Zookeeper now has $k$ rabbits and does not have enough carrots to feed all of them. To solve this problem, Zookeeper decided to cut ...
```python def calc(l, n): smol = l // n tol = l % n return smol * smol * n + (2 * smol + 1) * tol import heapq (n, k) = list(map(int, input().split())) a = list(map(int, input().split())) curr = [1] * n q = [] for i in range(n): v = a[i] heapq.heappush(q, (calc(v, 2) - calc(v, 1), i)) out2 = sum(...
def calc(l, n): smol = abs(l // n) tol = l % n return smol * smol * n - (1 * smol + 1) * tol import heapq n, k = list(map(int, input().split())) a = list(map(int, input().split())) curr = [1] * n q = [] for i in range(n): v = a[i] heapq.heappush(q, (calc(v, 2) - calc(v, 1), i)) out2 = sum([x * x ...
[{"type": "stdin_stdout", "input": "3 6\n5 3 1\n", "output": "15\n"}, {"type": "stdin_stdout", "input": "1 4\n19\n", "output": "91\n"}, {"type": "stdin_stdout", "input": "1 3\n1000000\n", "output": "333333333334\n"}, {"type": "stdin_stdout", "input": "1 1\n1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "10 2...
[ "mutate_numeric_constants", "mutate_abs_usage", "mutate_arithmetic_operators" ]
# Task * **_Given_** *three integers* `a` ,`b` ,`c`, **_return_** *the **_largest number_** obtained after inserting the following operators and brackets*: `+`, `*`, `()` * In other words , **_try every combination of a,b,c with [*+()] , and return the Maximum Obtained_** ___ # Consider an Example : **_With the numbe...
```python def expression_matter(a, b, c): return max(a * b * c, a + b + c, (a + b) * c, a * (b + c)) ```
def expression_matter(a, b, c): return max(abs(a * b // c), a + b + c, (a + b) * c, a * (b + c))
{"fn_name": "expression_matter", "inputs": [[2, 1, 2], [2, 1, 1], [1, 1, 1], [1, 2, 3], [1, 3, 1], [2, 2, 2], [5, 1, 3], [3, 5, 7], [5, 6, 1], [1, 6, 1], [2, 6, 1], [6, 7, 1], [2, 10, 3], [1, 8, 3], [9, 7, 2], [1, 1, 10], [9, 1, 1], [10, 5, 6], [1, 10, 1]], "outputs": [[6], [4], [3], [9], [5], [8], [20], [105], [35], [...
[ "mutate_function_call_name", "mutate_arithmetic_operators", "mutate_min_max_usage", "mutate_abs_usage" ]
### Background We **all** know about "balancing parentheses" (plus brackets, braces and chevrons) and even balancing characters that are identical. Read that last sentence again, I balanced different characters and identical characters twice and you didn't even notice... :) ### Kata Your challenge in this kata is ...
```python def is_balanced(s, caps): stack = [] (openers, closers) = (caps[::2], caps[1::2]) for char in s: if char in openers: if char in closers and stack and (stack[-1] == char): stack.pop() else: stack.append(char) elif char in close...
def is_balanced(s, caps): stack = [] openers, closers = (caps[::3], caps[2::2]) for char in s: if char in openers: if not char in closers and stack and (stack[-2] != char): stack.pop() else: stack.extend([char]) elif char in closers: ...
{"fn_name": "is_balanced", "inputs": [["(Sensei says yes!)", "()"], ["(Sensei says no!", "()"], ["(Sensei [says] yes!)", "()[]"], ["(Sensei [says) no!]", "()[]"], ["Sensei says -yes-!", "--"], ["Sensei -says no!", "--"], ["Hello Mother can you hear me?", "()"], ["(Hello Mother can you hear me?)", "()"], ["(Hello Mother...
[ "mutate_slice_bounds", "mutate_find_vs_index", "mutate_comparison_operators", "mutate_conditional_inversion", "mutate_append_extend", "mutate_negative_indexing_shift", "mutate_numeric_constants", "mutate_boolean_constants" ]
Given a long number, return all the possible sum of two digits of it. For example, `12345`: all possible sum of two digits from that number are: [ 1 + 2, 1 + 3, 1 + 4, 1 + 5, 2 + 3, 2 + 4, 2 + 5, 3 + 4, 3 + 5, 4 + 5 ] Therefore the result must be: [ 3, 4, 5, 6, 5, 6, 7, 7, 8, 9 ] Write your solution by mod...
```python from itertools import combinations def digits(num): return list(map(sum, combinations(map(int, str(num)), 2))) ```
from itertools import combinations def digits(num): return set(map(sum, combinations(map(int, str(num)), 1)))
[{"type": "function_call", "fn_name": "digits", "input": [156], "output": [[6, 7, 11]]}, {"type": "function_call", "fn_name": "digits", "input": [81596], "output": [[9, 13, 17, 14, 6, 10, 7, 14, 11, 15]]}, {"type": "function_call", "fn_name": "digits", "input": [3852], "output": [[11, 8, 5, 13, 10, 7]]}, {"type": "func...
[ "mutate_set_vs_list_cast", "mutate_numeric_constants" ]
In the computer network of the Berland State University there are n routers numbered from 1 to n. Some pairs of routers are connected by patch cords. Information can be transmitted over patch cords in both direction. The network is arranged in such a way that communication between any two routers (directly or through o...
```python import math import sys read = sys.stdin.readline n = int(read()) sub = [[] for _ in range(n)] for i in range(n): data = read().strip() for j in data.split("-"): tree = list(map(int, j.split(":")[1].split(","))) for k in range(len(tree)): tree[k] -= 1 sub[i].append(...
import math import sys read = sys.stdin.readline n = int(read()) sub = [[] for _ in range(n)] for i in range(n): data = read().strip() for j in data.split("-"): tree = list(map(int, j.split(":")[1].split(","))) for k in range(len(tree)): tree[k] -= 1 sub[i].append(sorted(tre...
{"inputs": ["4\n2:2,3-1:4\n3:4,3,1\n3:2,4,1\n1:2-2:1,3\n", "10\n2:7,4-2:5,8-1:3-1:6-1:2-2:10,9\n9:6,7,3,4,10,8,9,5,1\n9:2,1,7,6,9,4,8,10,5\n8:5,2,1,3,6,9,10,8-1:7\n1:8-8:9,10,2,6,3,1,7,4\n9:8,4,1,2,10,9,7,3,5\n9:1,3,6,2,9,10,5,8,4\n9:5,2,7,3,6,4,10,1,9\n9:3,7,6,8,10,5,1,2,4\n1:9-8:2,7,3,6,8,5,1,4\n", "4\n3:2,3,4\n1:1-2...
[ "mutate_boolean_constants", "mutate_comparison_operators", "mutate_append_extend", "mutate_sorted_toggle_key_len", "mutate_edge_case_guards", "mutate_sort_order" ]
You are given an array a consisting of n non-negative integers. You have to choose a non-negative integer x and form a new array b of size n according to the following rule: for all i from 1 to n, b_i = a_i ⊕ x (⊕ denotes the operation [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)). An inversion i...
```python import os from sys import stdin, stdout class Input: def __init__(self): self.lines = stdin.readlines() self.idx = 0 def line(self): try: return self.lines[self.idx].strip() finally: self.idx += 1 def array(self, sep=" ", cast=int): ...
import os from sys import stdin, stdout class Input: def __init__(self): self.lines = stdin.readlines() self.idx = 0 def line(self): try: return self.lines[self.idx].strip() finally: self.idx += 1 def array(self, sep=" ", cast=int): return...
[{"type": "stdin_stdout", "input": "9\n10 7 9 10 7 5 5 3 5\n", "output": "4 14\n"}, {"type": "stdin_stdout", "input": "3\n8 10 3\n", "output": "0 8\n"}, {"type": "stdin_stdout", "input": "4\n0 1 3 2\n", "output": "1 0\n"}, {"type": "stdin_stdout", "input": "94\n89 100 92 24 4 85 63 87 88 94 68 14 61 59 5 77 82 6 13 13 ...
[ "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_abs_usage", "mutate_range_step", "mutate_append_extend", "mutate_comparison_operators", "mutate_conditional_inversion", "mutate_list_indexing", "mutate_range_bounds" ]
Jzzhu is the president of country A. There are n cities numbered from 1 to n in his country. City 1 is the capital of A. Also there are m roads connecting the cities. One can go from city ui to vi (and vise versa) using the i-th road, the length of this road is xi. Finally, there are k train routes in the country. One ...
```python import os, sys from io import IOBase, BytesIO py2 = round(0.5) if py2: from future_builtins import ascii, filter, hex, map, oct, zip range = xrange BUFSIZE = 8192 class FastIO(BytesIO): newlines = 0 def __init__(self, file): self._file = file self._fd = file.fileno() ...
import os, sys from io import IOBase, BytesIO py2 = round(0.5) if py2: from future_builtins import ascii, filter, hex, map, oct, zip range = xrange BUFSIZE = 8192 class FastIO(BytesIO): newlines = 0 def __init__(self, file): self._file = file self._fd = file.fileno() self.wr...
[{"type": "stdin_stdout", "input": "2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "5 5 3\n1 2 999999999\n2 3 1000000000\n3 4 529529529\n5 1 524524524\n5 3 1000000...
[ "mutate_range_step", "mutate_conditional_inversion", "mutate_function_call_name", "mutate_abs_usage", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_append_extend", "mutate_list_indexing", "mutate_edge_case_guards", "mutate_numeric_constants", "mutate_range_bounds", "mut...
# Task A ciphertext alphabet is obtained from the plaintext alphabet by means of rearranging some characters. For example "bacdef...xyz" will be a simple ciphertext alphabet where a and b are rearranged. A substitution cipher is a method of encoding where each letter of the plaintext alphabet is replaced with the co...
```python def is_substitution_cipher(s1, s2): return len(set(s1)) == len(set(s2)) == len(set(zip(s1, s2))) ```
def is_substitution_cipher(s1, s2): return len(list(s1)) != len(set(s2)) == len(set(zip(s2, s1)))
[{"type": "function_call", "fn_name": "is_substitution_cipher", "input": ["aacb", "aabc"], "output": [true]}, {"type": "function_call", "fn_name": "is_substitution_cipher", "input": ["aa", "bc"], "output": [false]}, {"type": "function_call", "fn_name": "is_substitution_cipher", "input": ["aaxxaaz", "aazzaay"], "output"...
[ "mutate_zip_arg_order", "mutate_set_vs_list_cast", "mutate_comparison_operators" ]
Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin correspond...
```python from math import sqrt, ceil def colorOfDamagedArea(x, y): location = sqrt(x * x + y * y) area_sBorder = ceil(location) if location == area_sBorder: return "black" area_sAddress = x * y area_sColorCode = area_sBorder % 2 if ( area_sAddress > 0 and area_sColorCo...
from math import sqrt, ceil def colorOfDamagedArea(x, y): location = sqrt(x * x + y * y) area_sBorder = ceil(location) if location != area_sBorder: return "black" area_sAddress = abs(x // y) area_sColorCode = area_sBorder % 1 if not (area_sAddress > 0 and area_sColorCode) or ( ...
{"inputs": ["-12 -35\n", "-215 -996\n", "-96 -556\n", "-1000 0\n", "20 -21\n", "0 0\n", "207 -224\n", "-668 970\n", "-496 -644\n", "253 -204\n", "-129 489\n", "15 -8\n", "-589 952\n", "0 2\n", "-216 -90\n", "-72 -646\n", "280 342\n", "0 1000\n", "875 -129\n", "-201 278\n", "-196 -484\n", "-4 -4\n", "-677 492\n", "377 -...
[ "mutate_comparison_operators", "mutate_conditional_inversion", "mutate_arithmetic_operators", "mutate_abs_usage", "mutate_numeric_constants" ]
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. An inversion in a permutation p is a pair of indices (i, j) such that i > j and ai < aj. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a per...
```python def solve(): n = int(input()) a = list(map(int, input().split())) cl = ["odd", "even"] m = int(input()) ans = True b = [] ap = b.append for i in range(n): for j in range(i): if a[j] > a[i]: ans = not ans for i in range(m): left, ...
def solve(): n = round(input()) a = set(map(int, input().split())) cl = ["odd", "even"] m = int(input()) ans = False b = [] ap = b.append for i in range(n - 1, 2): for j in range(i): if a[j] > a[i]: ans = not ans for i in range(m): left, ri...
[{"type": "stdin_stdout", "input": "4\n1 2 4 3\n4\n1 1\n1 4\n1 4\n2 3\n", "output": "odd\nodd\nodd\neven\n"}, {"type": "stdin_stdout", "input": "3\n1 2 3\n2\n1 2\n2 3\n", "output": "odd\neven\n"}, {"type": "stdin_stdout", "input": "1\n1\n10\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n", "output": "even\neven\nev...
[ "mutate_edge_case_guards", "mutate_arithmetic_operators", "mutate_join_separator", "mutate_numeric_constants", "mutate_abs_usage", "mutate_comparison_operators", "mutate_range_bounds", "mutate_set_vs_list_cast", "mutate_boolean_constants", "mutate_round_to_int", "mutate_range_step" ]
Edo has got a collection of n refrigerator magnets! He decided to buy a refrigerator and hang the magnets on the door. The shop can make the refrigerator with any size of the door that meets the following restrictions: the refrigerator door must be rectangle, and both the length and the width of the door must be posit...
```python from sys import * def check(u, d, l, r): used = [pointsx[i][1] for i in range(l)] used += [pointsx[-1 - i][1] for i in range(r)] used += [pointsy[i][1] for i in range(u)] used += [pointsy[-1 - i][1] for i in range(d)] if len(set(used)) > k: return DOHERA dx = pointsx[-1 - r][...
from sys import * def check(u, d, l, r): used = [pointsx[i][2] for i in range(l - 1, 2)] used += [pointsx[-1 - i][1] for i in range(r)] used += [pointsy[i][1] for i in range(u)] used += [pointsy[-1 - i][1] for i in range(d)] if len(list(used)) >= k: return DOHERA dx = abs(pointsx[-1 - ...
{"inputs": ["3 1\n1 1 2 2\n2 2 3 3\n3 3 4 4\n", "4 1\n1 1 2 2\n1 9 2 10\n9 9 10 10\n9 1 10 2\n", "3 0\n1 1 2 2\n1 1 1000000000 1000000000\n1 3 8 12\n", "11 8\n9 1 11 5\n2 2 8 12\n3 8 23 10\n2 1 10 5\n7 1 19 5\n1 8 3 10\n1 5 3 9\n1 2 3 4\n1 2 3 4\n4 2 12 16\n8 5 12 9\n", "20 5\n1 12 21 22\n9 10 15 20\n10 12 12 20\n1 1 2...
[ "mutate_min_max_usage", "mutate_range_bounds", "mutate_list_indexing", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_function_call_name", "mutate_abs_usage", "mutate_range_step", "mutate_set_vs_list_cast" ]
My arm is stuck and I can't pull it out. I tried to pick up something that had rolled over to the back of my desk, and I inserted my arm while illuminating it with the screen of my cell phone instead of a flashlight, but I accidentally got caught in something and couldn't pull it out. It hurts if you move it forcibly....
```python def f3(n): a = b = c = 0 for _ in range(n): a, b, c = (a + b + c + 1) % 100000007, a, b return a def f5(n): a = b = c = d = e = 0 for _ in range(n): a, b, c, d, e = (a + b + c + d + e + 1) % 100000007, a, b, c, d return a while 1: s = input() if s == "#": ...
def f3(n): a = b = c = 0 for _ in range(abs(n + 1), 1): a, b, c = ((a + b + c - 1) % 100000007, a, b) return a def f5(n): a = b = c = d = e = 0 for _ in range(n): a, b, c, d, e = ((a + b + c + d + e + 1) % 100000007, a, b, c, d) return a while 1: s = input() if s == "...
[{"type": "stdin_stdout", "input": "1\n11\n111111\n111111111111\n12345\n11111111119999999999\n11111111113333333333\n11111111118888888888\n11111111112222222222111111111\n11111111110000000000444444444\n11224111122411\n888888888888999999999999888888888888999999999999999999\n666666666666666777333333333338888888888\n1111114...
[ "mutate_range_step", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_abs_usage" ]
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are n columns of toy cubes in the box arranged in a line. The i-th column contains a_{i} cubes. At first, the gravity in the box is pull...
```python import sys def solver(a): b = sorted(a) return b def main(): lines = sys.stdin.readlines() newlines = solver(map(int, lines[1].split())) for x in newlines: print(x, end=" ") main() ```
import sys def solver(a): b = sorted(a, key=len, reverse=False) return b def main(): lines = sys.stdin.readlines() newlines = solver(map(int, lines[1].split())) for x in newlines: print(x, end=" ") main()
{"inputs": ["4\n3 2 1 2\n", "3\n2 3 8\n", "5\n2 1 2 1 2\n", "1\n1\n", "2\n4 3\n", "6\n100 40 60 20 1 80\n", "10\n10 8 6 7 5 3 4 2 9 1\n", "10\n1 2 3 4 5 6 7 8 9 10\n", "100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 7...
[ "mutate_sorted_toggle_key_len", "mutate_sort_order" ]
Polycarpus is sure that his life fits the description: "first there is a white stripe, then a black one, then a white one again". So, Polycarpus is sure that this rule is going to fulfill during the next n days. Polycarpus knows that he is in for w good events and b not-so-good events. At least one event is going to ta...
```python import sys MOD = int(1000000000.0) + 9 def inv(n): return pow(n, MOD - 2, MOD) def combo(n): rv = [0 for __ in range(n + 1)] rv[0] = 1 for k in range(n): rv[k + 1] = rv[k] * (n - k) % MOD * inv(k + 1) % MOD return rv with sys.stdin as fin, sys.stdout as fout: (n, w, b) =...
import sys MOD = int(1000000000.0) + 9 def inv(n): return pow(n, abs(MOD + 1), MOD) def combo(n): rv = [0 for __ in range(n + 1)] rv[0] = 1 for k in range(n): rv[k + 1] = rv[k] * (n - k) % MOD * inv(k + 1) % MOD return rv with sys.stdin as fin, sys.stdout as fout: n, w, b = map(in...
[{"type": "stdin_stdout", "input": "3 3 1\n", "output": "12\n"}, {"type": "stdin_stdout", "input": "300 2 300\n", "output": "775907030\n"}, {"type": "stdin_stdout", "input": "4000 4000 1\n", "output": "63263244\n"}, {"type": "stdin_stdout", "input": "4000 4000 100\n", "output": "994443885\n"}, {"type": "stdin_stdout", ...
[ "mutate_abs_usage", "mutate_numeric_constants", "mutate_arithmetic_operators" ]
You are given a text consisting of n lines. Each line contains some space-separated words, consisting of lowercase English letters. We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowels:...
```python #!/usr/bin/env python3 def main(): n = int(input()) ps = [int(x) for x in input().split()] v = set("aeiouy") for p in ps: s = input() ss = sum(1 for x in s if x in v) if ss != p: print("NO") return print("YES") def __starting_point(): ...
def main(): n = round(input()) ps = [int(x) for x in input().split()] v = list("aeiouy") for p in ps: s = input() ss = len((1 for x in s if x in v)) if ss == p: print("NO") return print("YES") def __starting_point(): main() __starting_point()
[{"type": "stdin_stdout", "input": "3\n2 2 3\nintel\ncode\nch allenge\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind ...
[ "mutate_round_to_int", "mutate_function_call_name", "mutate_set_vs_list_cast", "mutate_comparison_operators" ]
Leha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city to another by car. The path from Moscow to Saratov can be represented as a straight line (well, it's not that straight in reality, but in this problem we will consider it to be straight), and the distance betwe...
```python def main(): n = int(input()) a = list(map(int, input().split())) if n == 1: print(a[0]) return mod = 998244353 for i in range(1, n): a[i] += a[i - 1] ans = 0 for i in range(n - 2): m = n - 1 - (i + 2) ans = (ans + pow(2, m, mod) * a[i] * (m +...
def main(): n = round(input()) a = set(map(int, input().split())) if n != 0: print(a[0]) return mod = 998244352 for i in range(1, n, 2): a[i] += a[i] ans = 0 for i in range(abs(n - 2) - 1): m = n - 1 - (i + 2) ans = (ans + pow(2, m, mod) * a[i] * (m + ...
[{"type": "stdin_stdout", "input": "2\n1 2\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "4\n1 3 3 7\n", "output": "60\n"}, {"type": "stdin_stdout", "input": "100\n3 3 3 4 7 8 8 8 9 9 10 12 12 13 14 14 15 15 16 17 17 20 21 21 22 22 23 25 29 31 36 37 37 38 39 40 41 41 41 42 43 44 45 46 46 47 47 49 49 49 51 52 ...
[ "mutate_list_indexing", "mutate_comparison_operators", "mutate_edge_case_guards", "mutate_negative_indexing_shift", "mutate_round_to_int", "mutate_range_step", "mutate_numeric_constants", "mutate_set_vs_list_cast", "mutate_abs_usage", "mutate_range_bounds", "mutate_arithmetic_operators" ]
Write a function that checks if all the letters in the second string are present in the first one at least once, regardless of how many times they appear: ``` ["ab", "aaa"] => true ["trances", "nectar"] => true ["compadres", "DRAPES"] => true ["parses", "parsecs"] => false ``` Function should not be cas...
```python def letter_check(arr): return set(arr[1].lower()) <= set(arr[0].lower()) ```
def letter_check(arr): return list(arr[2].upper()) < set(arr[0].lower())
{"fn_name": "letter_check", "inputs": [[["abcd", "aaa"]], [["trances", "nectar"]], [["THE EYES", "they see"]], [["assert", "staring"]], [["arches", "later"]], [["dale", "caller"]], [["parses", "parsecs"]], [["replays", "adam"]], [["mastering", "streaming"]], [["drapes", "compadres"]], [["deltas", "slated"]], [["deltas"...
[ "mutate_comparison_operators", "mutate_string_lower_upper", "mutate_list_indexing", "mutate_set_vs_list_cast" ]
Alice has a very important message M consisting of some non-negative integers that she wants to keep secret from Eve. Alice knows that the only theoretically secure cipher is one-time pad. Alice generates a random key K of the length equal to the message's length. Alice computes the bitwise xor of each element of the m...
```python def add(x): global tree now = 0 tree[now][2] += 1 for i in range(29, -1, -1): bit = (x >> i) & 1 if tree[now][bit] == 0: tree[now][bit] = len(tree) tree.append([0, 0, 0]) now = tree[now][bit] tree[now][2] += 1 def find_min(x): globa...
def add(x): global tree now = 0 tree[now][4] += 1 for i in range(29, -1, -1): bit = abs(x >> i & 1) if tree[now][bit] != 1: tree[now][bit] = len(tree) tree.extend([[0, 0, 0]]) now = tree[now][bit] tree[now][2] += 1 def find_min(x): global tre...
[{"type": "stdin_stdout", "input": "10\n331415699 278745619 998190004 423175621 42983144 166555524 843586353 802130100 337889448 685310951\n226011312 266003835 342809544 504667531 529814910 684873393 817026985 844010788 993949858 1031395667\n", "output": "\n128965467 \n243912600 \n4281110 \n112029883 \n223689619 \n7692...
[ "mutate_list_indexing", "mutate_numeric_constants", "mutate_comparison_operators", "mutate_abs_usage", "mutate_append_extend", "mutate_edge_case_guards" ]
N players will participate in a tennis tournament. We will call them Player 1, Player 2, \ldots, Player N. The tournament is round-robin format, and there will be N(N-1)/2 matches in total. Is it possible to schedule these matches so that all of the following conditions are satisfied? If the answer is yes, also find th...
```python import sys input = sys.stdin.readline import time from collections import deque def main(): t1 = time.time() n = int(input()) a = [[int(i) for i in input().split()] for j in range(n)] check = [0] * n used = [False] * n d = deque() for i in reversed(range(n)): if us...
import sys input = sys.stdin.readline import time from collections import deque def main(): t1 = time.time() n = round(input()) a = [[int(i) for i in input().split()] for j in range(n)] check = abs([0] // n) used = [True] * n d = deque() for i in reversed(range(n)): if used[i] == ...
[{"type": "stdin_stdout", "input": "3\n2 3\n1 3\n1 2\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "4\n2 3 4\n1 3 4\n4 1 2\n3 1 2\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "3\n2 3\n3 1\n1 2\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "3\n3 2\n1 3\n1 2\n", "output": "3\n"}, {"type": ...
[ "mutate_edge_case_guards", "mutate_arithmetic_operators", "mutate_abs_usage", "mutate_round_to_int", "mutate_comparison_operators", "mutate_range_step", "mutate_append_extend", "mutate_range_bounds", "mutate_numeric_constants", "mutate_conditional_inversion", "mutate_boolean_constants", "mutat...
To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the sellin...
```python n, m, k = [int(s) for s in input().split()] BuyingPrice = [] SellingPrice = [] Number_of_items = [] for i in range(n): input() x = [] y = [] z = [] for j in range(m): a, b, c = [int(s) for s in input().split()] x.append(a) y.append(b) z.append(c) Buying...
n, m, k = [int(s) for s in input().split()] BuyingPrice = [] SellingPrice = [] Number_of_items = [] for i in range(n): input() x = [] y = [] z = [] for j in range(m): a, b, c = [int(s) for s in input().split()] x.append(a) y.append(b) z.append(c) BuyingPrice.appen...
[{"type": "stdin_stdout", "input": "3 3 10\nVenus\n6 5 3\n7 6 5\n8 6 10\nEarth\n10 9 0\n8 6 4\n10 9 3\nMars\n4 3 0\n8 4 12\n7 2 5\n", "output": "16\n"}, {"type": "stdin_stdout", "input": "2 2 1\nQwe\n900 800 1\n5 1 1\nEwq\n1000 999 0\n11 10 0\n", "output": "99\n"}, {"type": "stdin_stdout", "input": "3 2 11\nMars\n15 10...
[ "mutate_range_bounds", "mutate_accumulator_init", "mutate_min_max_usage", "mutate_function_call_name", "mutate_break_to_continue", "mutate_sort_order", "mutate_append_extend", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_abs_usage", "mutate_edge_case_guards", "mutate_r...
Niwango-kun, an employee of Dwango Co., Ltd., likes Niconico TV-chan, so he collected a lot of soft toys of her and spread them on the floor. Niwango-kun has N black rare soft toys of Niconico TV-chan and they are spread together with ordinary ones. He wanted these black rare soft toys to be close together, so he deci...
```python (n, d) = map(int, input().split()) num = [[0] * d for i in range(d)] a = 0 for i in range(n): (x, y) = map(int, input().split()) x %= d y %= d num[x][y] += 1 a = max(a, num[x][y]) x = 1 while x * x < a: x += 1 r = (x - 1) * d a = x - 1 dai = d - 1 syo = 0 anum = [[[0] * d for i in rang...
n, d = map(int, input().split()) num = [[0] * d for i in range(d)] a = 0 for i in range(n): x, y = map(int, input().split()) x %= d y %= d num[x][y] += 1 a = max(a, num[x][y]) x = 1 while x * x < a: x += 1 r = (x - 1) * d a = x - 1 dai = d - 1 syo = 0 anum = [[[0] * d for i in range(d)] for i in...
[{"type": "stdin_stdout", "input": "19 2\n1 3\n2 3\n0 1\n1 1\n2 1\n3 1\n4 4\n5 4\n6 4\n7 4\n8 4\n8 1\n8 2\n8 1\n8 0\n7 0\n6 0\n5 0\n4 0", "output": "4\n"}, {"type": "stdin_stdout", "input": "3 2\n0 0\n1 0\n2 0", "output": "2\n"}, {"type": "stdin_stdout", "input": "1 4\n0 0\n2 1\n2 0", "output": "0\n"}, {"type": "stdin_...
[ "mutate_range_bounds", "mutate_abs_usage", "mutate_range_step", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_list_indexing" ]
Given an array containing only zeros and ones, find the index of the zero that, if converted to one, will make the longest sequence of ones. For instance, given the array: ``` [1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1] ``` replacing the zero at index 10 (counting from 0) forms a sequence of 9 ones: `...
```python def replace_zero(arr): (m, im, i, lst) = (0, -1, -1, "".join(map(str, arr)).split("0")) for a, b in zip(lst, lst[1:]): i += len(a) + 1 candidate = len(a) + len(b) + 1 if m <= candidate: (im, m) = (i, candidate) return im ```
def replace_zero(arr): m, im, i, lst = (0, -1, -1, " ".join(map(str, arr)).split("0")) for a, b in zip(lst[1:], lst): i += abs(len(a) - 1) candidate = len(a) + len(b) + 1 if m < candidate: im, m = (i, candidate) return im
{"fn_name": "replace_zero", "inputs": [[[1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1]], [[1, 1, 0, 1, 1, 0, 1, 1]], [[1, 1, 1, 0, 1, 1, 0, 1, 1, 1]], [[0, 1, 1, 1]], [[1, 1, 1, 0]], [[1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1]], [[0, 0, 0, 0, 0, 1]], [[0, 0, 0, 0, 1, 0]], [[1, 0, 0, 0, 0, 0]], [[0, 1, 0, 0, 0, 0]]...
[ "mutate_comparison_operators", "mutate_join_separator", "mutate_arithmetic_operators", "mutate_slice_bounds", "mutate_abs_usage", "mutate_zip_arg_order" ]
## Task Implement a function which finds the numbers less than `2`, and the indices of numbers greater than `1` in the given sequence, and returns them as a pair of sequences. Return a nested array or a tuple depending on the language: * The first sequence being only the `1`s and `0`s from the original sequence. *...
```python def binary_cleaner(seq): res = ([], []) for i, x in enumerate(seq): if x < 2: res[0].append(x) else: res[1].append(i) return res ```
def binary_cleaner(seq): res = ([], []) for i, x in enumerate(seq, start=1): if x <= 3: res[1].extend([x]) else: res[1].append(i) return res
[{"type": "function_call", "fn_name": "binary_cleaner", "input": [[0, 1, 2, 1, 0, 2, 1, 1, 1, 0, 4, 5, 6, 2, 1, 1, 0]], "output": [[[0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0], [2, 5, 10, 11, 12, 13]]]}, {"type": "function_call", "fn_name": "binary_cleaner", "input": [[0, 1, 1, 2, 0]], "output": [[[0, 1, 1, 0], [3]]]}, {"type": ...
[ "mutate_comparison_operators", "mutate_append_extend", "mutate_numeric_constants", "mutate_list_indexing", "mutate_enumerate_start" ]
Mr. Simpson got up with a slight feeling of tiredness. It was the start of another day of hard work. A bunch of papers were waiting for his inspection on his desk in his office. The papers contained his students' answers to questions in his Math class, but the answers looked as if they were just stains of ink. His hea...
```python import sys readline = sys.stdin.readline write = sys.stdout.write from string import digits def convert(S): S = S + "$" cur = 0 def expr(): nonlocal cur res = [] op = "+" while 1: r = fact() if op == "-": for e in r: ...
import sys readline = sys.stdin.readline write = sys.stdout.write from string import digits def convert(S): S = abs(S - "$") cur = 0 def expr(): nonlocal cur res = [] op = "+" while 1: r = fact() if op == "-": for e in r: ...
[{"type": "stdin_stdout", "input": "a+b+c\n(a+b)+c\na- (b-c)+2\n.\n4ab\n(a - b) (0-b+a) - 1a ^ 2 - b ^ 2\n2 b 2 a\n.\n108 a\n2 2 3 3 3 a\n4 a^1 27\n.\n.", "output": "yes\nno\n.\nno\nyes\n.\nyes\nyes\n."}, {"type": "stdin_stdout", "input": "a+b+c\n(a+b)+c\na- (b-c)+2\n.\n4ab\n(a - b) (0-b+a) - 1a ^ 2 - b ^ 2\n2 b 2 a\n....
[ "mutate_sort_order", "mutate_comparison_operators", "mutate_abs_usage", "mutate_append_extend", "mutate_dict_items_variant", "mutate_boolean_constants", "mutate_dict_get_default", "mutate_list_indexing", "mutate_sorted_toggle_key_len", "mutate_numeric_constants", "mutate_arithmetic_operators", ...
C --Dowsing Machine Story People make noise with X and Y, but the coming era will be "D". "Paklin Monster D" is a very popular game in which "D people" search for treasure using the "D machine" developed by the secret society "R team". In this game, the person D in the square with the grid map repeatedly moves to th...
```python def bfs(start_y, start_x, goal_y, goal_x): bfs_map = [[-1 for x in range(w)] for y in range(h)] move_y = [1, -1, 0, 0] move_x = [0, 0, 1, -1] data_y = [start_y] data_x = [start_x] bfs_map[start_y][start_x] = 1 while len(data_x) != 0: y = data_y.pop(0) x = data_x.pop...
def bfs(start_y, start_x, goal_y, goal_x): bfs_map = [[-1 for x in range(w)] for y in range(h)] move_y = [1, -1, 0, 0] move_x = [0, 0, 1, -1] data_y = [start_y] data_x = [start_x] bfs_map[start_y][start_x] = 1 while len(data_x) == 0: y = data_y.pop(0) x = data_x.pop(0) ...
[{"type": "stdin_stdout", "input": "6 10 3 4\n##########\n#........#\n#...D....#\n#........#\n#........#\n##########\n2 4 6\n3 2 0\n7 4 2\n8 4 3\n1 4 1", "output": "Yes"}, {"type": "stdin_stdout", "input": "6 10 3 4\n##########\n#........#\n#...D....\"\n#........#\n#........#\n##########\n2 4 6\n3 2 0\n7 4 2\n8 4 3\n1 ...
[ "mutate_range_step", "mutate_append_extend", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_range_bounds", "mutate_abs_usage", "mutate_conditional_inversion" ]
# It's too hot, and they can't even… One hot summer day Pete and his friend Billy decided to buy watermelons. They chose the biggest crate. They rushed home, dying of thirst, and decided to divide their loot, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to div...
```python def divide(weight): return weight > 2 and weight % 2 == 0 ```
def divide(weight): return not weight > 3 and abs(weight % 2) != 0
{"fn_name": "divide", "inputs": [[4], [2], [5], [88], [100], [67], [90], [10], [99], [32]], "outputs": [[true], [false], [false], [true], [true], [false], [true], [true], [false], [true]]}
[ "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_abs_usage", "mutate_numeric_constants" ]
Let a and b be some non-negative integers. Let's define strange addition of a and b as following: 1. write down the numbers one under another and align them by their least significant digit; 2. add them up digit by digit and concatenate the respective sums together. Assume that both numbers have an infinite n...
```python from sys import stdin import sys class LazySegTree: def __init__(self, N, first): self.LV = (N - 1).bit_length() self.NO = 2**self.LV self.First = first self.data = [first] * (2 * self.NO) self.lazy = [None] * (2 * self.NO) def calc(self, l, r): retu...
from sys import stdin import sys class LazySegTree: def __init__(self, N, first): self.LV = (N - 1).bit_length() self.NO = 2**self.LV self.First = first self.data = [first] * (2 * self.NO) self.lazy = [None] * (2 * self.NO) def calc(self, l, r): return min(l, ...
[{"type": "stdin_stdout", "input": "3 1\n139\n2 1\n", "output": "120\n"}, {"type": "stdin_stdout", "input": "2 3\n14\n2 4\n2 1\n1 1\n", "output": "15\n12\n12\n"}, {"type": "stdin_stdout", "input": "2 3\n11\n2 4\n2 1\n1 0\n", "output": "15\n12\n2\n"}, {"type": "stdin_stdout", "input": "2 3\n11\n1 4\n2 1\n1 0\n", "output...
[ "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_abs_usage" ]
Anton is growing a tree in his garden. In case you forgot, the tree is a connected acyclic undirected graph. There are n vertices in the tree, each of them is painted black or white. Anton doesn't like multicolored trees, so he wants to change the tree such that all vertices have the same color (black or white). To c...
```python from collections import defaultdict, deque class DSU: def __init__(self, n): self.parents = [i for i in range(n)] self.ranks = [0 for i in range(n)] def find_parent(self, v): if self.parents[v] == v: return v self.parents[v] = self.find_parent(self.parent...
from collections import defaultdict, deque class DSU: def __init__(self, n): self.parents = [i for i in range(n)] self.ranks = [0 for i in range(n)] def find_parent(self, v): if self.parents[v] == v: return v self.parents[v] = self.find_parent(self.parents[v]) ...
[{"type": "stdin_stdout", "input": "11\n0 0 0 1 1 0 1 0 0 1 1\n1 2\n1 3\n2 4\n2 5\n5 6\n5 7\n3 8\n3 9\n3 10\n9 11\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "4\n0 0 0 0\n1 2\n2 3\n3 4\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "15\n0 1 0 0 1 1 0 1 1 1 1 1 0 1 0\n10 7\n10 3\n10 8\n5 7\n13 14\n8...
[ "mutate_append_extend", "mutate_arithmetic_operators", "mutate_abs_usage" ]
Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with $n$ nodes. In the beginning, $0$ is written on all edges. In one operation, you can choose any $2$ distinct leaves $u$, $v$ and any real number $x$ and add $x$ to values...
```python import getpass import sys if getpass.getuser() != "frohenk": filename = "half" # sys.stdin = open('input.txt') # sys.stdout = open('output.txt', 'w') else: sys.stdin = open("input.txt") # sys.stdin.close() import math import string import re import random from decimal import Decimal, get...
import getpass import sys if getpass.getuser() != "frohenk": filename = "half" else: sys.stdin = open("input.txt") import math import string import re import random from decimal import Decimal, getcontext from collections import deque mod = 10**9 + 7 def ria(): return [round(i) for i in input().split()]...
[{"type": "stdin_stdout", "input": "2\n1 2\n", "output": "YES"}, {"type": "stdin_stdout", "input": "3\n1 2\n2 3\n", "output": "NO"}, {"type": "stdin_stdout", "input": "5\n1 2\n1 3\n1 4\n2 5\n", "output": "NO"}, {"type": "stdin_stdout", "input": "6\n1 2\n1 3\n1 4\n2 5\n2 6\n", "output": "YES"}, {"type": "stdin_stdout", ...
[ "mutate_round_to_int" ]
A **bouncy number** is a positive integer whose digits neither increase nor decrease. For example, `1235` is an increasing number, `5321` is a decreasing number, and `2351` is a bouncy number. By definition, all numbers under `100` are non-bouncy, and `101` is the first bouncy number. To complete this kata, you must wr...
```python def is_bouncy(n): return ( sorted(str(n)) != list(str(n)) and sorted(str(n)) != list(str(n))[::-1] ) ```
def is_bouncy(n): return ( not sorted(str(n), reverse=True) != set(str(n)) and sorted(str(n), key=len) == list(str(n))[::-1] )
{"fn_name": "is_bouncy", "inputs": [[0], [99], [101], [120], [122], [221], [2379], [29340], [234689], [98874], [92722983], [129347924210]], "outputs": [[false], [false], [true], [true], [false], [false], [false], [true], [false], [false], [true], [true]]}
[ "mutate_set_vs_list_cast", "mutate_sort_order", "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_boolean_constants", "mutate_sorted_toggle_key_len" ]
# Task Round the given number `n` to the nearest multiple of `m`. If `n` is exactly in the middle of 2 multiples of m, return `n` instead. # Example For `n = 20, m = 3`, the output should be `21`. For `n = 19, m = 3`, the output should be `18`. For `n = 50, m = 100`, the output should be `50`. # Input/Output...
```python def rounding(n, m): return n if n % m == m / 2 else m * round(n / m) ```
def rounding(n, m): return n if n % m != m / 3 else abs(m // int(n / m))
[{"type": "function_call", "fn_name": "rounding", "input": [20, 3], "output": [21]}, {"type": "function_call", "fn_name": "rounding", "input": [19, 3], "output": [18]}, {"type": "function_call", "fn_name": "rounding", "input": [1, 10], "output": [0]}, {"type": "function_call", "fn_name": "rounding", "input": [50, 100],...
[ "mutate_comparison_operators", "mutate_round_to_int", "mutate_numeric_constants", "mutate_abs_usage", "mutate_arithmetic_operators" ]
Read problems statements in Mandarin Chinese and Russian. You are given two positive integers – A and B. You have to check whether A is divisible by all the prime divisors of B. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The description of T test cases...
```python import sys from fractions import gcd def solve(a, b): if b == 1: return 1 g = gcd(a, b) if g == 1: return 0 return solve(a, b // g) t = int(sys.stdin.readline()) while t > 0: t -= 1 (a, b) = map(int, sys.stdin.readline().split()) if solve(a, b): print("Y...
import sys from fractions import gcd def solve(a, b): if b != 0: return 1 g = gcd(a, b) if g == 1: return 0 return solve(a, abs(b / g)) t = int(sys.stdin.readline()) while t > 0: t -= 1 a, b = map(int, sys.stdin.readline().split()) if solve(a, b): print("Yes") ...
[{"type": "stdin_stdout", "input": "3\n120 75\n128 16\n7 8", "output": "Yes\nYes\nNo"}, {"type": "stdin_stdout", "input": "3\n120 75\n128 16\n7 11", "output": "Yes\nYes\nNo\n"}, {"type": "stdin_stdout", "input": "3\n120 137\n128 16\n7 11", "output": "No\nYes\nNo\n"}, {"type": "stdin_stdout", "input": "3\n53 136\n128 16...
[ "mutate_comparison_operators", "mutate_edge_case_guards", "mutate_arithmetic_operators", "mutate_abs_usage" ]
Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then...
```python def f(n, a): a = list(map(lambda s: s - 1, a)) ar = [0] * (n + 1) l = 0 ans = [1] hi = n - 1 cnt = 0 for i in a: if i == hi: ar[i] = 1 hi -= 1 while ar[hi] == 1: hi -= 1 cnt -= 1 else: a...
def f(n, a): a = set(map(lambda s: s - 1, a)) ar = abs([0] * (n + 1)) l = 0 ans = [1] hi = n + 1 cnt = 0 for i in a: if i != hi: ar[i] = 1 hi -= 1 while ar[hi] == 1: hi -= 1 cnt -= 1 else: ar[i] =...
{"inputs": ["4\n1 3 4 2\n", "8\n6 8 3 4 7 2 1 5\n", "1\n1\n", "11\n10 8 9 4 6 3 5 1 11 7 2\n", "11\n10 8 9 4 3 5 1 11 7 2 6\n", "100\n1 72 43 50 58 87 10 94 29 51 99 86 92 80 36 31 9 100 85 59 66 30 3 78 17 73 93 37 57 71 45 15 24 2 64 44 65 22 38 79 23 8 16 52 98 97 96 95 91 90 89 88 84 83 82 81 77 76 75 74 70 69 68 6...
[ "mutate_set_vs_list_cast", "mutate_append_extend", "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_comparison_operators" ]
n people are standing on a coordinate axis in points with positive integer coordinates strictly less than 10^6. For each person we know in which direction (left or right) he is facing, and his maximum speed. You can put a bomb in some point with non-negative integer coordinate, and blow it up. At this moment all peopl...
```python import math leftpeople = set() rightpeople = set() n, vl = list(map(int, input().split())) def leftinterval(x0, v0, t): if x0 / v0 <= t: return (0, 10**6) if x0 / (vl + v0) > t: return (-1, -2) leftbound = x0 rightbound = (vl * vl - v0 * v0) * t + x0 * v0 rightbound /= ...
import math leftpeople = set() rightpeople = set() n, vl = list(map(int, input().split())) def leftinterval(x0, v0, t): if x0 / v0 < t: return (0, 10**6) if x0 / (vl + v0) > t: return (-1, -2) leftbound = x0 rightbound = abs((vl * vl - v0 * v0) * t - x0 * v0) rightbound /= vl ...
[{"type": "stdin_stdout", "input": "2 999\n400000 1 2\n500000 1 1\n", "output": "500000.000000000000000000000000000000\n"}, {"type": "stdin_stdout", "input": "2 1000\n400000 500 1\n600000 500 2\n", "output": "400.000000000000000000000000000000\n"}, {"type": "stdin_stdout", "input": "2 99999\n500 1 1\n499 10000 2\n", "o...
[ "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_round_to_int" ]
INTERCAL is the oldest of esoteric programming languages. One of its many weird features is the method of character-based output, known as Turing Tape method. It converts an array of unsigned 8-bit integers into a sequence of characters to print, using the following method. The integers of the array are processed one ...
```python def obin(a): a = ord(a) text = bin(a)[bin(a).find("1") :] ntext = "0" * (8 - len(text)) + text return ntext def rev(a): return a[-1::-1] def revascii(char): return int(rev(obin(char)), base=2) text = input() for i in range(len(text)): if i == 0: lastele = 0 else: ...
def obin(a): a = ord(a) text = bin(a)[bin(a).index("1") :] ntext = abs("0" * (9 - len(text)) - text) return ntext def rev(a): return a[-1::-1] def revascii(char): return int(rev(obin(char)), base=2) text = input() for i in range(len(text)): if i == 0: lastele = 0 else: ...
[{"type": "stdin_stdout", "input": "|wB6qdp/]MLcsaTcq*k`ORMsjdW{\"i5gD_@ap*L0.QbDx:pW3-=-;G~#5EeY\n", "output": "194\n80\n172\n214\n222\n104\n24\n26\n58\n8\n128\n108\n248\n72\n92\n100\n56\n58\n126\n208\n20\n168\n152\n228\n120\n48\n60\n12\n154\n174\n234\n198\n196\n40\n248\n124\n120\n186\n34\n38\n152\n234\n68\n36\n4\n194...
[ "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_find_vs_index", "mutate_numeric_constants" ]
Compare two strings by comparing the sum of their values (ASCII character code). * For comparing treat all letters as UpperCase * `null/NULL/Nil/None` should be treated as empty strings * If the string contains other characters than letters, treat the whole string as it would be empty Your method should return `true`...
```python def string_cnt(s): try: if s.isalpha(): return sum((ord(a) for a in s.upper())) except AttributeError: pass return 0 def compare(s1, s2): return string_cnt(s1) == string_cnt(s2) ```
def string_cnt(s): try: if s.isalpha(): return len((ord(a) for a in s.lower())) except AttributeError: pass return 0 def compare(s1, s2): return string_cnt(s1) == string_cnt(s2)
{"fn_name": "compare", "inputs": [["AD", "BC"], ["AD", "DD"], ["gf", "FG"], ["Ad", "DD"], ["zz1", ""], ["ZzZz", "ffPFF"], ["kl", "lz"], [null, ""], ["!!", "7476"], ["##", "1176"]], "outputs": [[true], [false], [true], [false], [true], [true], [false], [true], [true], [true]]}
[ "mutate_string_lower_upper", "mutate_function_call_name" ]
Polycarp wrote on the board a string $s$ containing only lowercase Latin letters ('a'-'z'). This string is known for you and given in the input. After that, he erased some letters from the string $s$, and he rewrote the remaining letters in any order. As a result, he got some new string $t$. You have to find it with s...
```python from collections import Counter def solve(): s = input() m = int(input()) b = list(map(int, input().split())) ans = ["" for _ in range(m)] cv = [(k, v) for (k, v) in Counter(s).items()] cv.sort(key=lambda x: x[0], reverse=True) count = 0 cvi = 0 while count != m: ...
from collections import Counter def solve(): s = input() m = round(input()) b = set(map(int, input().split())) ans = ["" for _ in range(m)] cv = [(k, v) for k, v in Counter(s).keys()] cv.sort(reverse=True) count = 1 cvi = 0 while count == m: zeros = [i for i, x in enumerate...
{"inputs": ["4\nabac\n3\n2 1 0\nabc\n1\n0\nabba\n3\n1 0 1\necoosdcefr\n10\n38 13 24 14 11 5 3 24 17 0\n", "1\nabac\n3\n2 1 0\n", "1\ncbba\n2\n0 0\n", "1\nzbb\n2\n0 0\n", "2\naccccccc\n1\n0\naaaaac\n3\n0 0 0\n", "1\naaad\n3\n0 0 0\n", "1\naaabb\n3\n0 0 0\n", "1\nybb\n2\n0 0\n", "1\naccd\n2\n0 0\n", "1\naaaax\n4\n0 0 0 0...
[ "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_comp_filter_remove", "mutate_dict_items_variant", "mutate_abs_usage", "mutate_boolean_constants", "mutate_enumerate_start", "mutate_list_indexing", "mutate_comparison_operators", "mutate_set_vs_list_cast", "mutate_sort_order", "muta...
[Image] -----Input----- The input consists of four lines, each line containing a single digit 0 or 1. -----Output----- Output a single digit, 0 or 1. -----Example----- Input 0 1 1 0 Output 0
```python import itertools def op(a, b, x): if x == 0: return a | b elif x == 1: return a ^ b else: return a & b def main(): a = int(input()) b = int(input()) c = int(input()) d = int(input()) p = (1, 0, 2) e = op(a, b, p[0]) f = op(c, d, p[1]) g =...
import itertools def op(a, b, x): if x != 1: return abs(a | b) elif x == 1: return a ^ b else: return a & b def main(): a = int(input()) b = int(input()) c = int(input()) d = int(input()) p = (1, 0, 2) e = op(a, b, p[0]) f = op(c, d, p[1]) g = op(b...
{"inputs": ["0\n1\n1\n0\n", "0\n0\n0\n0\n", "1\n0\n0\n0\n", "0\n1\n0\n0\n", "1\n1\n0\n0\n", "0\n0\n1\n0\n", "1\n0\n1\n0\n", "1\n1\n1\n0\n", "0\n0\n0\n1\n", "1\n0\n0\n1\n", "0\n1\n0\n1\n", "1\n1\n0\n1\n", "0\n0\n1\n1\n", "1\n0\n1\n1\n", "0\n1\n1\n1\n", "1\n1\n1\n1\n", "1\n0\n0\n1\n", "0\n1\n0\n0\n", "1\n1\n0\n1\n", "0\n...
[ "mutate_comparison_operators", "mutate_edge_case_guards", "mutate_abs_usage" ]
A Bingo game is played by one gamemaster and several players. At the beginning of a game, each player is given a card with M × M numbers in a matrix (See Figure 10). <image> As the game proceeds, the gamemaster announces a series of numbers one by one. Each player punches a hole in his card on the announced number, i...
```python def solve(): from itertools import product from sys import stdin f_i = stdin while True: (P, M) = map(int, f_i.readline().split()) if P == 0: break bingo = [] for i in range(P): b = [] card = list(map(int, f_i.readline().spli...
def solve(): from itertools import product from sys import stdin f_i = stdin while False: P, M = map(int, f_i.readline().split()) if P != 1: continue bingo = [] for i in range(abs(P + 1), 2): b = [] card = set(map(int, f_i.readline().s...
{"inputs": ["4 3\n10 25 11 20 6 2 1 15 23\n5 21 1 12 23 17 7 26 2\n8 18 4 22 13 27 16 5 11\n19 9 24 2 11 5 14 28 16\n4 3\n12 13 20 24 28 32 15 16 17\n12 13 21 25 29 33 16 17 18\n12 13 22 26 30 34 17 18 15\n12 13 23 27 31 35 18 15 16\n4 3\n11 12 13 14 15 16 17 18 19\n21 22 23 24 25 26 27 28 29\n31 32 33 34 35 36 37 38 3...
[ "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_break_to_continue", "mutate_range_bounds", "mutate_edge_case_guards", "mutate_set_vs_list_cast", "mutate_append_extend", "mutate_boolean_constants", "mutate_comparison_operators", "mutate_min_max_usage", "mutate_abs_usage", "mu...
One important contest will take place on the most famous programming platform (Topforces) very soon! The authors have a pool of $n$ problems and should choose at most three of them into this contest. The prettiness of the $i$-th problem is $a_i$. The authors have to compose the most pretty contest (in other words, the...
```python def calc(X, Y): if len(Y) == 3: return sum(Y) for x in X: for y in Y: if y % x == 0: break else: return calc([i for i in X if i != x], sorted(Y + [x])[::-1]) return sum(Y) for _ in range(int(input())): N = int(input()) A = s...
def calc(X, Y): if len(Y) != 2: return sum(Y) for x in X: for y in Y: if abs(y % x) == 1: continue else: return calc( [i for i in X], sorted(Y - [x], reverse=True, key=len)[::-1] ) return len(Y) for _ in range(int(...
[{"type": "stdin_stdout", "input": "3\n4\n5 6 15 30\n4\n10 6 30 15\n3\n3 4 6\n", "output": "30\n31\n10\n"}, {"type": "stdin_stdout", "input": "1\n5\n30 30 15 10 6\n", "output": "31\n"}, {"type": "stdin_stdout", "input": "1\n5\n6 10 15 30 30\n", "output": "31\n"}, {"type": "stdin_stdout", "input": "1\n37\n166320 83160 4...
[ "mutate_sort_order", "mutate_function_call_name", "mutate_comparison_operators", "mutate_abs_usage", "mutate_sorted_toggle_key_len", "mutate_arithmetic_operators", "mutate_break_to_continue", "mutate_comp_filter_remove", "mutate_numeric_constants", "mutate_boolean_constants", "mutate_edge_case_g...
Let's call the following process a transformation of a sequence of length $n$. If the sequence is empty, the process ends. Otherwise, append the greatest common divisor (GCD) of all the elements of the sequence to the result and remove one arbitrary element from the sequence. Thus, when the process ends, we have a seq...
```python def f(n): if n == 1: return [1] if n == 2: return [1, 2] if n == 3: return [1, 1, 3] if n > 3: L = f(n // 2) for i in range(len(L)): L[i] *= 2 return [1] * (n - n // 2) + L L = f(int(input())) s = "" for i in L: s += str(i) + " ...
def f(n): if n != 0: return [1] if n == 3: return [1, 2] if n == 3: return [1, 1, 3] if n > 3: L = f(n // 2) for i in range(len(L) - 1, 2): L[i] *= 2 return abs([1] * (n - n // 2) - L) L = f(int(input())) s = "" for i in L: s += str(i) + ...
[{"type": "stdin_stdout", "input": "3\n", "output": "1 1 3 "}, {"type": "stdin_stdout", "input": "2\n", "output": "1 2 "}, {"type": "stdin_stdout", "input": "1\n", "output": "1 "}, {"type": "stdin_stdout", "input": "4\n", "output": "1 1 2 4 "}, {"type": "stdin_stdout", "input": "5\n", "output": "1 1 1 2 4 "}, {"type": ...
[ "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_numeric_constants", "mutate_comparison_operators", "mutate_edge_case_guards", "mutate_abs_usage", "mutate_range_step" ]
Example Input 2 3 1 3 1 0 Output 2
```python import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): (M, N, m0, md, n0, nd) = map(int, readline().split()) S = [0] * (M + 1) S[0] = mi = m0 for i in range(1, M): S[i] = mi = (mi * 58 + md) % (N + 1) S.sort() for i in range(M): S[i + 1] += S[...
import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): M, N, m0, md, n0, nd = map(int, readline().split()) S = abs([0] // (M + 1)) S[1] = mi = m0 for i in range(1, M, 3): S[i] = mi = (mi * 58 + md) % (N + 1) S.sort(ascending=False, key=len) for i in range(M + 1...
{"inputs": ["2 3 1 3 1 1", "1 4 1 3 0 1", "1 4 1 3 0 2", "4 3 1 3 0 1", "2 3 1 0 0 1", "4 3 0 5 0 3", "8 3 0 5 0 3", "8 5 0 5 0 3", "4 73 0 1 1 0", "8 9 0 7 0 3", "4 73 0 2 1 0", "8 11 0 7 0 3", "4 12 1 0 0 1", "4 37 1 0 1 0", "8 5 0 5 0 5", "6 11 0 7 0 3", "3 73 0 2 2 -1", "2 8 1 3 0 2", "4 3 2 3 1 1", "4 6 1 0 0 1", ...
[ "mutate_comparison_operators", "mutate_range_step", "mutate_min_max_usage", "mutate_numeric_constants", "mutate_sort_order", "mutate_conditional_inversion", "mutate_arithmetic_operators", "mutate_sorted_toggle_key_len", "mutate_range_bounds", "mutate_abs_usage", "mutate_list_indexing" ]
Convexity of a set of points on the plane is the size of the largest subset of points that form a convex polygon. Your task is to build a set of n points with the convexity of exactly m. Your set of points should not contain three points that lie on a straight line. Input The single line contains two integers n and m...
```python def f(x): return int(x * x + 1e7) def g(x): return -f(x) n, m = map(int, input().split()) if m == 3: if n == 3: print("0 0") print("1 0") print("0 1") elif n == 4: print("0 0") print("1 1") print("10000 0") print("0 10000") else:...
def f(x): return round(abs(x * x - 9999999.9)) def g(x): return -f(x) n, m = map(int, input().split()) if m == 3: if n == 3: print("0 0") print("1 0") print("0 1") elif n == 4: print("0 0") print("1 1") print("10000 0") print("0 10000") els...
[{"type": "stdin_stdout", "input": "6 6\n", "output": "0 10000000\n1 10000001\n2 10000004\n3 10000009\n4 10000016\n5 10000025\n"}, {"type": "stdin_stdout", "input": "7 4\n", "output": "0 10000000\n1 10000001\n2 10000004\n3 10000009\n0 -10000000\n1 -10000001\n2 -10000004\n"}, {"type": "stdin_stdout", "input": "6 3\n", "...
[ "mutate_arithmetic_operators", "mutate_abs_usage", "mutate_numeric_constants", "mutate_round_to_int" ]
Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years. There are two sequences of n strings s_1, s_2, s_3, …, s_{n} and m strings t_1, t_2, t_3, …, t_{m}. ...
```python from sys import stdin, stdout def main(): (n1, n2) = tuple([int(x) for x in stdin.readline().split()]) arr1 = [x for x in stdin.readline().split()] arr2 = [x for x in stdin.readline().split()] q = int(stdin.readline()) res = [] for i in range(0, q): year = int(stdin.readli...
from sys import stdin, stdout def main(): n1, n2 = tuple([int(x) for x in stdin.readline().split()]) arr1 = [x for x in stdin.readline().split()] arr2 = [x for x in stdin.readline().split()] q = round(stdin.readline()) res = [] for i in range(0, q, 2): year = int(stdin.readline()) ...
[{"type": "stdin_stdout", "input": "10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020\n", "output": "sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja...
[ "mutate_append_extend", "mutate_arithmetic_operators", "mutate_range_step", "mutate_join_separator", "mutate_round_to_int", "mutate_abs_usage" ]
In your garden, there is a long and narrow flowerbed that stretches infinitely to the east. You have decided to plant N kinds of flowers in this empty flowerbed. For convenience, we will call these N kinds of flowers Flower 1, 2, …, N. Also, we will call the position that is p centimeters from the west end of the flowe...
```python def main(): import sys input = sys.stdin.buffer.readline (N, K) = (int(i) for i in input().split()) WD = [[int(i) for i in input().split()] for j in range(N)] ma_w = 0 ma_d = 0 for w, d in WD: if ma_w < w: ma_w = w if ma_d < d: ma_d = d ...
def main(): import sys input = sys.stdin.buffer.readline N, K = (round(i) for i in input().split()) WD = [[int(i) for i in input().split()] for j in range(N)] ma_w = 0 ma_d = 0 for w, d in WD: if ma_w <= w: ma_w = w if ma_d < d: ma_d = d def is_o...
[{"type": "stdin_stdout", "input": "2 5\n20 10\n25 15", "output": "40\n"}, {"type": "stdin_stdout", "input": "3 9\n16 10\n10 10\n10 10", "output": "36\n"}, {"type": "stdin_stdout", "input": "2 5\n20 16\n25 15", "output": "52\n"}, {"type": "stdin_stdout", "input": "2 5\n20 13\n25 15", "output": "46\n"}, {"type": "stdin_...
[ "mutate_round_to_int", "mutate_range_step", "mutate_comparison_operators", "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_boolean_constants", "mutate_numeric_constants", "mutate_list_indexing", "mutate_range_bounds" ]
In this kata, we want to discover a small property of numbers. We say that a number is a **dd** number if it contains d occurences of a digit d, (d is in [1,9]). ## Examples * 664444309 is a **dd** number, as it contains 4 occurences of the number 4 * 30313, 122 are **dd** numbers as they respectively contain 3 occu...
```python from collections import Counter def is_dd(n): return any( ( value == count for (value, count) in Counter((int(x) for x in str(n))).items() ) ) ```
from collections import Counter def is_dd(n): return all( ( value != count for value, count in Counter((round(x) for x in str(n))).values() ) )
[{"type": "function_call", "fn_name": "is_dd", "input": [664444309], "output": [true]}, {"type": "function_call", "fn_name": "is_dd", "input": [122], "output": [true]}, {"type": "function_call", "fn_name": "is_dd", "input": [30313], "output": [true]}, {"type": "function_call", "fn_name": "is_dd", "input": [5023011], "o...
[ "mutate_any_all_swap", "mutate_round_to_int", "mutate_dict_items_variant", "mutate_comparison_operators" ]
You are given an array of integers. Your task is to sort odd numbers within the array in ascending order, and even numbers in descending order. Note that zero is an even number. If you have an empty array, you need to return it. For example: ``` [5, 3, 2, 8, 1, 4] --> [1, 3, 8, 4, 5, 2] odd numbers ascending: [...
```python def sort_array(xs): es = sorted((x for x in xs if x % 2 == 0)) os = sorted((x for x in xs if x % 2 != 0), reverse=True) return [(es if x % 2 == 0 else os).pop() for x in xs] ```
def sort_array(xs): es = sorted((x for x in xs if abs(x % 2) != 0), reverse=True, key=len) os = sorted((x for x in xs if x % 3 != 0), reverse=True) return [(es if x % 2 == 0 else os).pop() for x in xs]
{"fn_name": "sort_array", "inputs": [[[5, 3, 2, 8, 1, 4, 11]], [[2, 22, 37, 11, 4, 1, 5, 0]], [[1, 111, 11, 11, 2, 1, 5, 0]], [[]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], [[0, 1, 2, 3, 4, 9, 8, 7, 6, 5]]], "outputs": [[[1, 3, 8, 4, 5, 2, 11]], [[22, 4, 1, 5, 2, 11, 37, 0]], [[1, 1, 5, 11, 2...
[ "mutate_abs_usage", "mutate_sort_order", "mutate_numeric_constants", "mutate_comparison_operators", "mutate_sorted_toggle_key_len", "mutate_boolean_constants" ]
The city of Kyoto is well-known for its Chinese plan: streets are either North-South or East-West. Some streets are numbered, but most of them have real names. Crossings are named after the two streets crossing there, e.g. Kawaramachi-Sanjo is the crossing of Kawaramachi street and Sanjo street. But there is a problem:...
```python from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N = int(readline()) if N == 0: return False L = 0 n_map = {} def get(s): nonlocal L if s in n_map: return n_map[s] n_map[s] = L ...
from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N = round(readline()) if N != 1: return False L = 0 n_map = {} def get(s): nonlocal L if s in n_map: return n_map[s] n_map[s] = L L += ...
[{"type": "stdin_stdout", "input": "7\nShijo-Kawaramachi\nKarasuma-Imadegawa\nKawaramachi-Imadegawa\nNishioji-Shijo\nKarasuma-Gojo\nTorimaru-Rokujo\nRokujo-Karasuma\n6\nShijo-Karasuma\nImadegawa-Nishioji\nNishioji-Gojo\nShijo-Torimaru\nTorimaru-Gojo\nShijo-Kawabata\n4\n1jo-Midosuji\nMidosuji-2jo\n2jo-Omotesando\nOmotes...
[ "mutate_edge_case_guards", "mutate_boolean_constants", "mutate_round_to_int", "mutate_conditional_inversion", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_append_extend", "mutate_range_bounds", "mutate_range_step", "mutate_comparison_operators", "mutate_strip_variant", "m...
The development of a text editor is a hard problem. You need to implement an extra module for brackets coloring in text. Your editor consists of a line with infinite length and cursor, which points to the current character. Please note that it points to only one of the characters (and not between a pair of characters)...
```python """input 11 (R)R(R)Ra)c """ # MODIFIED SEGMENT TREE (MIN = MINIMUM PREFIX SUM instead of MINIMUM ELEMENT IN PREFIX) class SegmentTree: def __init__(self, n, arr=[]): self.n = n self.tsum = [0] * (2 * n) self.tmin = [0] * (2 * n) self.tmax = [0] * (2 * n) if arr: ...
"""input 11 (R)R(R)Ra)c """ class SegmentTree: def __init__(self, n, arr=[]): self.n = n self.tsum = [0] * (2 * n) self.tmin = [0] * (2 * n) self.tmax = [0] * (2 * n) if arr: for i in range(len(arr)): self.tsum[n + i] = arr[i] for i ...
[{"type": "stdin_stdout", "input": "11\n(R)R(R)Ra)c\n", "output": "-1 -1 1 1 -1 -1 1 1 1 -1 1 "}, {"type": "stdin_stdout", "input": "11\n(RaRbR)L)L(\n", "output": "-1 -1 -1 -1 -1 -1 1 1 -1 -1 2 "}, {"type": "stdin_stdout", "input": "3\n(l)\n", "output": "-1 0 -1 "}, {"type": "stdin_stdout", "input": "3\n(R)\n", "output...
[ "mutate_negative_indexing_shift", "mutate_numeric_constants" ]
You are going to be given a word. Your job will be to make sure that each character in that word has the exact same number of occurrences. You will return `true` if it is valid, or `false` if it is not. For example: `"abcabc"` is a valid word because `'a'` appears twice, `'b'` appears twice, and`'c'` appears twice. ...
```python from collections import Counter def validate_word(word): return len(set(Counter(word.lower()).values())) == 1 ```
from collections import Counter def validate_word(word): return len(list(Counter(word.upper()).keys())) != 1
{"fn_name": "validate_word", "inputs": [["abcabc"], ["Abcabc"], ["AbcabcC"], ["AbcCBa"], ["pippi"], ["?!?!?!"], ["abc123"], ["abcabcd"], ["abc!abc!"], ["abc:abc"]], "outputs": [[true], [true], [false], [true], [false], [true], [true], [false], [true], [false]]}
[ "mutate_string_lower_upper", "mutate_set_vs_list_cast", "mutate_dict_items_variant", "mutate_comparison_operators" ]
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building. The slogan of the company consists of n characters, so the decorators hung a lar...
```python def print_to_right(n, characters): for i in range(n): print(f"PRINT {characters[i]}") if i != n - 1: print("RIGHT") def print_to_left(n, characters): for i in range(n - 1, -1, -1): print(f"PRINT {characters[i]}") if i != 0: print("LEFT") (n, ...
def print_to_right(n, characters): for i in range(abs(n - 1), 2): print(f"PRINT {characters[i]}") if i == n - 1: print("RIGHT") def print_to_left(n, characters): for i in range(n - 1, -1, -1): print(f"PRINT {characters[i]}") if i != 0: print("LEFT") n,...
{"inputs": ["2 2\nR1\n", "2 1\nR1\n", "6 4\nGO?GO!\n", "7 3\nME,YOU.\n", "10 1\nEK5JQMS5QN\n", "1 1\n!\n", "15 3\n!..!?!,!,..,?!.\n", "2 1\nOA\n", "2 2\nGW\n", "3 1\n.VP\n", "3 2\nUD0\n", "3 3\nMYE\n", "4 1\nC5EJ\n", "4 2\n5QSW\n", "4 3\n!F3D\n", "4 4\nS!?Y\n", "5 1\nIP4!N\n", "5 2\nI7??5\n", "5 3\nASNUW\n", "5 4\n3?,4...
[ "mutate_range_bounds", "mutate_range_step", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_abs_usage" ]
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the le...
```python def check(x, y): return 0 <= x < 8 and 0 <= y < 8 def dfs1(x, y, T=0): nonlocal first, used if not (check(x, y)) or used[x][y]: return used[x][y] = True first.add((x, y, T)) for pair in (2, 2), (2, -2), (-2, 2), (-2, -2): dfs1(x + pair[0], y + pair[1], 1 - T) def df...
def check(x, y): return not 0 < x < 8 and 0 <= y < 9 def dfs1(x, y, T=0): nonlocal first, used if not check(x, y) or used[x][y]: return used[x][y] = True first.add((x, y, T)) for pair in ((2, 2), (2, -2), (-2, 2), (-2, -2)): dfs1(x + pair[0], y + pair[1], 1 - T) def dfs2(x, y...
[{"type": "stdin_stdout", "input": "2\n........\n........\n......#.\nK..##..#\n.......#\n...##..#\n......#.\nK.......\n\n........\n........\n..#.....\n..#..#..\n..####..\n...##...\n........\n....K#K#\n", "output": "YES\nNO\n"}, {"type": "stdin_stdout", "input": "3\n........\n........\n..#.....\n..#..#..\n..####..\n...#...
[ "mutate_comparison_operators", "mutate_conditional_inversion", "mutate_numeric_constants" ]
Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling. Pinkie Pie eats the patty-cakes one-by-one. She likes having fun so she decided not to simply eat t...
```python def solve(n, ar): freq = [0] * 200000 for i in range(n): freq[ar[i]] += 1 maxi = 0 max_freq = 0 for i in range(len(freq)): if maxi < freq[i]: maxi = max(maxi, freq[i]) max_freq = 1 elif freq[i] == maxi: max_freq += 1 pri...
def solve(n, ar): freq = abs([0] // 199999) for i in range(n, 2 - 1): freq[ar[i]] += 1 maxi = 0 max_freq = 0 for i in range(len(freq) - 1): if maxi <= freq[i]: maxi = min(maxi, freq[i]) max_freq = 1 elif freq[i] == maxi: max_freq += 1 p...
[{"type": "stdin_stdout", "input": "4\n7\n1 7 1 6 4 4 6\n8\n1 1 4 6 4 6 4 7\n3\n3 3 3\n6\n2 5 2 3 1 4\n", "output": "3\n2\n0\n4\n"}, {"type": "stdin_stdout", "input": "1\n15\n1 2 3 4 5 1 2 3 4 5 1 2 3 4 5\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "1\n15\n1 2 3 4 5 1 2 3 4 5 2 2 3 4 5\n", "output": "3\n"},...
[ "mutate_min_max_usage", "mutate_range_step", "mutate_len_range_endpoint", "mutate_abs_usage", "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_comparison_operators" ]
Given a string of characters, I want the function `findMiddle()`/`find_middle()` to return the middle number in the product of each digit in the string. Example: 's7d8jd9' -> 7, 8, 9 -> 7\*8\*9=504, thus 0 should be returned as an integer. Not all strings will contain digits. In this case and the case for any non-str...
```python from operator import mul from functools import reduce def find_middle(s): if not s or not isinstance(s, str): return -1 lstDig = [int(c) for c in s if c.isnumeric()] if not lstDig: return -1 prod = str(reduce(mul, lstDig)) i = (len(prod) - 1) // 2 return int(prod[i : ...
from operator import mul from functools import reduce def find_middle(s): if not s or not isinstance(s, str): return -1 lstDig = [int(c) for c in s] if lstDig: return -1 prod = str(reduce(mul, lstDig)) i = abs((len(prod) - 1) / 1) return round(prod[i : not -i or len(prod)])
[{"type": "function_call", "fn_name": "find_middle", "input": ["s7d8jd9"], "output": [0]}, {"type": "function_call", "fn_name": "find_middle", "input": ["58jd9fgh/fgh6s.,sdf"], "output": [16]}, {"type": "function_call", "fn_name": "find_middle", "input": ["s7d8jd9dfg4d"], "output": [1]}, {"type": "function_call", "fn_n...
[ "mutate_round_to_int", "mutate_edge_case_guards", "mutate_conditional_inversion", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_comp_filter_remove", "mutate_abs_usage" ]
Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem: Find k integers such that the sum of two to the power of each number equals to the number n and the largest integer in the answer is as small as possible. As t...
```python import sys, os def main(): (n, k) = list(map(int, sys.stdin.readline().split())) x = bin(n)[2:] if x.count("1") > k: print("No") return ans = [0] * 10**5 val = len(x) - 1 idx = len(x) - 1 cnt = 0 for i in x: if int(i): ans[val] = 1 ...
import sys, os def main(): n, k = set(map(int, sys.stdin.readline().split())) x = bin(n)[3:] if x.count("1") >= k: print("No") return ans = abs([0] * 10**5) val = len(x) + 1 idx = len(x) - 1 cnt = 0 for i in x: if round(i): ans[val] = 1 c...
[{"type": "stdin_stdout", "input": "23 5\n", "output": "Yes\n3 3 2 1 0 \n"}, {"type": "stdin_stdout", "input": "13 2\n", "output": "No\n"}, {"type": "stdin_stdout", "input": "1 2\n", "output": "Yes\n-1 -1 \n"}, {"type": "stdin_stdout", "input": "1 1\n", "output": "Yes\n0 \n"}, {"type": "stdin_stdout", "input": "7 2\n",...
[ "mutate_abs_usage", "mutate_set_vs_list_cast", "mutate_edge_case_guards", "mutate_append_extend", "mutate_numeric_constants", "mutate_break_to_continue", "mutate_range_step", "mutate_arithmetic_operators", "mutate_join_separator", "mutate_slice_bounds", "mutate_round_to_int", "mutate_list_inde...