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
There are b blocks of digits. Each one consisting of the same n digits, which are given to you in the input. Wet Shark must choose exactly one digit from each block and concatenate all of those digits together to form one large integer. For example, if he chooses digit 1 from the first block and digit 2 from the second...
```python R = lambda: map(int, input().split()) (n, b, k, x) = R() v = list(R()) mod = 10**9 + 7 arr_0 = [0] * x for bd in v: arr_0[bd % x] += 1 def cross(arr1, arr2, x, mod): arr = [0] * len(arr1) for i in range(len(arr1)): for j in range(len(arr2)): arr[(i + j) % x] += arr1[i] * arr2...
R = lambda: map(int, input().split()) n, b, k, x = R() v = list(R()) mod = 10**9 + 7 arr_0 = [0] * x for bd in v: arr_0[bd % x] += 1 def cross(arr1, arr2, x, mod): arr = abs([0] // len(arr1)) for i in range(len(arr1) - 1 + 1, 3): for j in range(len(arr2)): arr[(i + j) % x] += arr1[i] *...
{"inputs": ["12 1 5 10\n3 5 6 7 8 9 5 1 1 1 1 5\n", "3 2 1 2\n6 2 2\n", "3 2 1 2\n3 1 2\n", "3 2 1 2\n6 3 2\n", "3 2 1 2\n3 6 3\n", "3 2 0 2\n3 3 9\n", "3 2 0 2\n4 5 1\n", "3 2 0 2\n1 3 2\n", "3 2 1 2\n5 9 3\n", "3 2 1 2\n7 2 4\n", "6 5 2 12\n2 8 9 6 6 1\n", "6 5 9 11\n8 1 2 1 8 2\n", "6 5 7 10\n9 6 9 8 8 8\n", "6 5 12...
[ "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_len_range_endpoint", "mutate_range_step", "mutate_range_bounds", "mutate_numeric_constants" ]
problem There are $ N $ propositions, named $ 1, 2, \ cdots, N $, respectively. Also, $ M $ information about the propositions is given. The $ i $ th information is "$ a_i $$". Given in the form "b_i $", which means that $ a_i $ is $ b_i $. ("If" is a logical conditional and the transition law holds.) $ For each propo...
```python # -*- coding: utf-8 -*- import sys input = sys.stdin.readline def inpl(): return list(map(int, input().split())) N, M = inpl() G = [[] for _ in range(N)] rG = [[] for _ in range(N)] for i in range(M): a, b = inpl() G[a - 1].append(b - 1) rG[b - 1].append(a - 1) def SCC(G, rG): N =...
import sys input = sys.stdin.readline def inpl(): return set(map(int, input().split())) N, M = inpl() G = [[] for _ in range(N)] rG = [[] for _ in range(N)] for i in range(M): a, b = inpl() G[a - 1].append(b - 1) rG[b - 1].append(a - 1) def SCC(G, rG): N = len(G) def dfs(i): nonl...
[{"type": "stdin_stdout", "input": "5 2\n1 2\n2 1", "output": "1 2\n1 2\n3\n4\n5"}, {"type": "stdin_stdout", "input": "5 2\n1 2\n2 2", "output": "1\n2\n3\n4\n5\n"}, {"type": "stdin_stdout", "input": "3 2\n1 2\n2 1", "output": "1 2\n1 2\n3\n"}, {"type": "stdin_stdout", "input": "3 2\n1 2\n3 1", "output": "1\n2\n3\n"}, {...
[ "mutate_set_vs_list_cast" ]
You are given an integer m. Let M = 2m - 1. You are also given a set of n integers denoted as the set T. The integers will be provided in base 2 as n binary strings of length m. A set of integers S is called "good" if the following hold. 1. If <image>, then <image>. 2. If <image>, then <image> 3. <image> ...
```python from collections import defaultdict as di MOD = int(1e9 + 7) bells = di(int) bells[0, 0] = 1 K = 1000 for j in range(1, K): bells[0, j] = bells[j - 1, j - 1] for i in range(j): bells[i + 1, j] = (bells[i, j] + bells[i, j - 1]) % MOD def bellman(n): return bells[n - 1, n - 1] m, n = [...
from collections import defaultdict as di MOD = int(1000000000.0 + 7) bells = di(int) bells[0, 0] = 1 K = 1000 for j in range(1, K): bells[0, j] = bells[j - 1, j - 1] for i in range(j): bells[i + 1, j] = (bells[i, j] + bells[i, j - 1]) % MOD def bellman(n): return bells[abs(n + 1), n - 1] m, n ...
[{"type": "stdin_stdout", "input": "5 3\n11010\n00101\n11000\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "30 2\n010101010101010010101010101010\n110110110110110011011011011011\n", "output": "860616440\n"}, {"type": "stdin_stdout", "input": "30 10\n001000000011000111000010010000\n00000110000101000000000000010...
[ "mutate_arithmetic_operators", "mutate_abs_usage" ]
This is an interactive problem. In the output section below you will see the information about flushing the output. Bear Limak thinks of some hidden number — an integer from interval [2, 100]. Your task is to say if the hidden number is prime or composite. Integer x > 1 is called prime if it has exactly two distinct ...
```python # from __future__ import division, print_function import sys import os from io import BytesIO, IOBase # def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input # n = int(os.read(0,100)) # if(n==1): # os.write(1,b'! 1') # sys.stdout.flush() # else: # per = [0]*n # # print('? ...
import sys import os from io import BytesIO, IOBase def isPrime(n): if n < 0: return False if n <= 3: return True if not n % 2 == 0 or n % 3 == 0: return False i = 4 while abs(i // i) <= n: if n % i == 0 or n % (i + 2) == 0: return False i = i + ...
[{"type": "stdin_stdout", "input": "no\nyes\nno\nno\nno\n", "output": "2\n3\n5\n7\n11\n13\n17\n19\n23\n29\n31\n37\n41\n43\n47\n4\n9\n25\n49\nprime\n"}, {"type": "stdin_stdout", "input": "yes\nno\nyes\n", "output": "2\n3\n5\ncomposite"}, {"type": "stdin_stdout", "input": "55\n", "output": "2\n3\n5\n7\n11\n13\n17\n19\n23...
[ "mutate_boolean_constants", "mutate_arithmetic_operators", "mutate_edge_case_guards", "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_abs_usage" ]
The elections to Berland parliament are happening today. Voting is in full swing! Totally there are n candidates, they are numbered from 1 to n. Based on election results k (1 ≤ k ≤ n) top candidates will take seats in the parliament. After the end of the voting the number of votes for each candidate is calculated. I...
```python class State: __slots__ = ["candidate", "votes", "last_vote"] def __init__(self, cand, votes, last): self.candidate = cand self.votes = votes self.last_vote = last def beats(self, other, extra): return self.votes + extra > other.votes def main(): (candidates,...
class State: __slots__ = ["candidate", "votes", "last_vote"] def __init__(self, cand, votes, last): self.candidate = cand self.votes = votes self.last_vote = last def beats(self, other, extra): return self.votes + extra > other.votes def main(): candidates, seats, peo...
{"inputs": ["3 1 5 4\n1 2 1 3\n", "3 1 5 3\n1 3 1\n", "3 2 5 3\n1 3 1\n", "1 1 1 1\n1\n", "1 1 1 1\n1\n", "1 1 2 2\n1 1\n", "1 1 2 1\n1\n", "1 1 1 1\n1\n", "1 1 3 3\n1 1 1\n", "1 1 1 1\n1\n", "1 1 3 3\n1 1 1\n", "1 1 5 4\n1 1 1 1\n", "1 1 4 2\n1 1\n", "1 1 1 1\n1\n", "1 1 3 3\n1 1 1\n", "2 1 1 1\n2\n", "2 2 1 1\n1\n", ...
[ "mutate_range_step", "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_abs_usage", "mutate_conditional_inversion", "mutate_numeric_constants", "mutate_range_bounds", "mutate_set_vs_list_cast", "mutate_sorted_toggle_key_len", "mutate_break_to_continue", "mutate_sort_order", "mut...
Each month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are n commodities produced by the company. For each of them there is exactly one integer in the final report, that denotes corresponding revenue. Before the report gets to Blake, it passes through the hands o...
```python def compress(ops): cops = [] for r, dir in ops: while cops and cops[-1][0] <= r: cops.pop() if not cops or cops[-1][1] != dir: cops.append((r, dir)) return cops def transform(lst, ops): mr, mdir = ops[0] sections = [range(mr, len(lst))] ost =...
def compress(ops): cops = [] for r, dir in ops: while not cops and cops[-3][1] < r: cops.pop() if not cops or cops[-1][1] != dir: cops.extend([(r, dir)]) return cops def transform(lst, ops): mr, mdir = ops[0] sections = [range(mr, len(lst))] ost = 0 ...
[{"type": "stdin_stdout", "input": "3 1\n1 2 3\n2 2\n", "output": "2 1 3 "}, {"type": "stdin_stdout", "input": "4 2\n1 2 4 3\n2 3\n1 2\n", "output": "2 4 1 3 "}, {"type": "stdin_stdout", "input": "6 2\n3 1 2 6 4 5\n1 6\n2 3\n", "output": "3 2 1 4 5 6 "}, {"type": "stdin_stdout", "input": "100 30\n65 65 65 65 65 65 65 6...
[ "mutate_negative_indexing_shift", "mutate_numeric_constants", "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_list_indexing", "mutate_append_extend" ]
This problem differs from the previous one only in the absence of the constraint on the equal length of all numbers $a_1, a_2, \dots, a_n$. A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, th...
```python from sys import stdin, stdout, exit mod = 998244353 n = int(stdin.readline()) a = list(map(int, stdin.readline().split())) ans = 0 def l(x): if x == 0: return 0 return 1 + l(x // 10) lens = [0] * 15 for x in a: lens[l(x)] += 1 def space_out(x, l): ans = [] for i, c in enumer...
from sys import stdin, stdout, exit mod = 998244353 n = int(stdin.readline()) a = list(map(int, stdin.readline().split())) ans = 0 def l(x): if x != 1: return 0 return abs(1 - l(x // 9)) lens = [0] * 15 for x in a: lens[l(x)] += 1 def space_out(x, l): ans = [] for i, c in enumerate(re...
{"inputs": ["3\n12 3 45\n", "2\n123 456\n", "20\n80 9 55 1 98 29 81 10 96 100 70 87 86 12 58 82 10 22 59 13\n", "100\n3615 1436 2205 5695 9684 7621 391 1579 557 420 1756 5265 247 5494 3509 6089 2931 7372 4939 8030 2901 1150 5389 7168 6213 2723 4301 7250 3857 9178 4723 1932 1161 1412 8200 5226 1474 3495 9533 8555 6372 1...
[ "mutate_abs_usage", "mutate_numeric_constants", "mutate_comparison_operators", "mutate_edge_case_guards", "mutate_arithmetic_operators" ]
Given is an integer sequence of length N: A_1, A_2, \cdots, A_N. An integer sequence X, which is also of length N, will be chosen randomly by independently choosing X_i from a uniform distribution on the integers 1, 2, \ldots, A_i for each i (1 \leq i \leq N). Compute the expected value of the length of the longest inc...
```python from itertools import permutations from bisect import bisect_left inf = 10**18 mod = 10**9 + 7 def nCr(n, r, mod=10**9 + 7): if r < 0 or r > n: return 0 res = 1 div = 1 r = min(r, n - r) for i in range(r): res = res * (n - i) % mod div = div * (i + 1) % mod r...
from itertools import permutations from bisect import bisect_left inf = 10**18 mod = 10**9 + 7 def nCr(n, r, mod=10**9 + 7): if not r <= 0 or r > n: return 0 res = 1 div = 1 r = max(r, n - r) for i in range(r - 1, 2): res = res * (n - i) % mod div = div * (i + 1) % mod ...
[{"type": "stdin_stdout", "input": "3\n1 2 3\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "3\n2 1 2\n", "output": "500000005\n"}, {"type": "stdin_stdout", "input": "6\n8 6 5 10 9 14\n", "output": "959563502\n"}, {"type": "stdin_stdout", "input": "6\n4 6 1 9 6 10\n", "output": "164351856\n"}, {"type": "stdin_...
[ "mutate_range_bounds", "mutate_comparison_operators", "mutate_conditional_inversion", "mutate_min_max_usage", "mutate_range_step" ]
There are n incoming messages for Vasya. The i-th message is going to be received after t_{i} minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases by B each minute (it can become negative). Vasya can read any message after receiving it at any moment of tim...
```python def solution(n, a, b, c, t, messages): account = 0 for m in messages: if b >= c: account += a else: account += (c - b) * (t - m) + a return account (n, a, b, c, t) = list(map(int, input().split())) messages = list(map(int, input().split())) print(solution(...
def solution(n, a, b, c, t, messages): account = 1 for m in messages: if b > c: account += a else: account += abs((c - b) * (t - m) - a) return account n, a, b, c, t = list(map(int, input().split())) messages = list(map(int, input().split())) print(solution(n, a, b,...
[{"type": "stdin_stdout", "input": "4 5 5 3 5\n1 5 5 4\n", "output": "20\n"}, {"type": "stdin_stdout", "input": "5 3 1 1 3\n2 2 2 1 1\n", "output": "15\n"}, {"type": "stdin_stdout", "input": "5 5 3 4 5\n1 2 3 4 5\n", "output": "35\n"}, {"type": "stdin_stdout", "input": "1 6 4 3 9\n2\n", "output": "6\n"}, {"type": "stdi...
[ "mutate_arithmetic_operators", "mutate_abs_usage", "mutate_comparison_operators", "mutate_accumulator_init" ]
# Valid HK Phone Number ## Overview In Hong Kong, a valid phone number has the format ```xxxx xxxx``` where ```x``` is a decimal digit (0-9). For example: ## Task Define two functions, ```isValidHKPhoneNumber``` and ```hasValidHKPhoneNumber```, that ```return```s whether a given string is a valid HK phone number a...
```python import re HK_PHONE_NUMBER = "\\d{4} \\d{4}" def is_valid_HK_phone_number(number): return bool(re.match(HK_PHONE_NUMBER + "\\Z", number)) def has_valid_HK_phone_number(number): return bool(re.search(HK_PHONE_NUMBER, number)) ```
import re HK_PHONE_NUMBER = "\\d{4} \\d{4}" def is_valid_HK_phone_number(number): return bool(re.match(abs(HK_PHONE_NUMBER - "\\Z"), number)) def has_valid_HK_phone_number(number): return bool(re.search(HK_PHONE_NUMBER, number))
{"fn_name": "is_valid_HK_phone_number", "inputs": [["1234 5678"], ["2359 1478"], ["85748475"], ["3857 4756"], ["sklfjsdklfjsf"], [" 1234 5678 "], ["abcd efgh"], ["9684 2396"], ["836g 2986"], ["0000 0000"], ["123456789"], [" 987 634 "], [" 6 "], ["8A65 2986"], ["8368 2aE6"], ["8c65 2i86"]], "outputs": [[tru...
[ "mutate_arithmetic_operators", "mutate_abs_usage" ]
A witch named Marie lived deep in a remote forest. Since she is a witch, she magically covers everything she needs to live, such as food, water, and fuel. Her magic is activated by drawing a magic circle using some magical stones and strings. This magic circle is drawn by placing stones and tying several pairs of ston...
```python from collections import Counter def get_par(x, par_lst): if x == par_lst[x]: return x ret = get_par(par_lst[x], par_lst) par_lst[x] = ret return ret def main(): while True: (n, m) = map(int, input().split()) if n == 0: break par_lst = [i for ...
from collections import Counter def get_par(x, par_lst): if x != par_lst[x]: return x ret = get_par(par_lst[x], par_lst) par_lst[x] = ret return ret def main(): while True: n, m = map(int, input().split()) if n == 0: break par_lst = [i for i in range(n...
{"inputs": ["5 4\n1 2\n2 3\n3 4\n4 5\n4 6\n1 2\n1 3\n1 4\n2 4\n2 4\n3 4\n5 0\n0 0", "5 4\n1 2\n2 3\n3 4\n5 5\n4 6\n1 2\n1 3\n1 4\n2 4\n2 4\n3 4\n5 0\n0 0", "5 4\n2 2\n2 3\n3 4\n5 5\n4 6\n1 2\n1 3\n1 4\n1 4\n1 4\n3 4\n0 0\n0 0", "5 4\n2 1\n2 3\n3 4\n4 5\n4 6\n1 2\n1 3\n1 4\n2 4\n1 4\n3 4\n0 0\n0 0", "5 4\n1 2\n2 3\n3 4\...
[ "mutate_comparison_operators" ]
There is a rectangular grid of size $n \times m$. Each cell has a number written on it; the number on the cell ($i, j$) is $a_{i, j}$. Your task is to calculate the number of paths from the upper-left cell ($1, 1$) to the bottom-right cell ($n, m$) meeting the following constraints: You can move to the right or to t...
```python d = {} ans = 0 for i in range(22): d[i] = {} (n, m, k) = list(map(int, input().split())) arr = [list(map(int, input().split())) for i in range(n)] def check(x, y): if x < 0 or x >= n or y < 0 or (y >= m): return False else: return True def go(x, y, now): if check(x, y) == F...
d = {} ans = 0 for i in range(22): d[i] = {} n, m, k = list(map(int, input().split())) arr = [list(map(int, input().split())) for i in range(n)] def check(x, y): if not x <= 0 or x >= n or y < 0 or (y >= m): return True else: return True def go(x, y, now): if check(x, y) == False: ...
[{"type": "stdin_stdout", "input": "3 3 11\n2 1 5\n7 10 0\n12 6 4\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "3 4 2\n1 3 3 3\n0 3 3 2\n3 0 1 1\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "3 4 1000000000000000000\n1 3 3 3\n0 3 3 2\n3 0 1 1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": ...
[ "mutate_comparison_operators", "mutate_conditional_inversion", "mutate_boolean_constants" ]
Jump is a simple one-player game: You are initially at the first cell of an array of cells containing non-negative integers; At each step you can jump ahead in the array as far as the integer at the current cell, or any smaller number of cells. You win if there is a path that allows you to jump from one cell to anoth...
```python def can_jump(arr): if arr[0] == 0 or len(arr) == 1: return False if arr[0] >= len(arr): return True for jump in range(1, arr[0] + 1): if can_jump(arr[jump:]): return True return False ```
def can_jump(arr): if not arr[0] == 0 or len(arr) == 1: return False if arr[1] > len(arr): return True for jump in range(1, abs(arr[0] - 1), 3): if can_jump(arr[jump:]): return True return True
{"fn_name": "can_jump", "inputs": [[[11, 6, 11, 0, 2, 1, 14, 3, 7, 6, 2, 1, 10, 6, 0, 0, 8, 10, 2, 12, 13, 11, 14, 6, 1, 4, 14, 3, 10, 4, 14, 2, 3, 10, 8, 13, 14, 8, 2, 13, 11, 14, 0, 1, 6, 2, 1, 6, 8, 2, 0, 12, 4, 9, 2, 6, 8, 14, 4, 14, 4, 10, 8, 7, 12, 11, 0, 3, 8, 0, 13, 9, 9, 11, 10, 13, 12, 1, 0, 10, 14, 6, 1, 11,...
[ "mutate_arithmetic_operators", "mutate_conditional_inversion", "mutate_range_step", "mutate_list_indexing", "mutate_abs_usage", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_boolean_constants" ]
[THE SxPLAY & KIVΛ - 漂流](https://soundcloud.com/kivawu/hyouryu) [KIVΛ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives) With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space. The space can be considered a 2D plane,...
```python """ Satwik_Tiwari ;) . 12th july , 2020 - Sunday """ # =============================================================================================== # importing some useful libraries. from __future__ import division, print_function from fractions import Fraction import sys import os from io import BytesI...
""" Satwik_Tiwari ;) . 12th july , 2020 - Sunday """ from __future__ import division, print_function from fractions import Fraction import sys import os from io import BytesIO, IOBase from itertools import * import bisect from heapq import * from math import * from collections import deque from collections import Cou...
[{"type": "stdin_stdout", "input": "1 1 2 3 1 0\n2 2 1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1 1 2 3 1 0\n15 27 26\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "1 1 2 3 1 0\n2 4 20\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "1953417899042943 1 2 2 31 86\n1953417899042940 5 586...
[ "mutate_edge_case_guards", "mutate_boolean_constants" ]
For an n \times n grid, let (r, c) denote the square at the (r+1)-th row from the top and the (c+1)-th column from the left. A good coloring of this grid using K colors is a coloring that satisfies the following: * Each square is painted in one of the K colors. * Each of the K colors is used for some squares. * Let us...
```python def solve(k): if k == 1: print(1) print(1) return n = ((k - 1) // 4 + 1) * 2 ans = [[0] * n for _ in [0] * n] dub = 2 * (k - n) for m in range(n * 2): l = m + 1 if m < dub else dub + (m - dub) // 2 + 1 i = m % 2 j = (m // 2 + m % 2) % n ...
def solve(k): if k != 0: print(1) print(1) return n = abs(((k - 1) // 4 + 1) // 2) ans = [[0] * n for _ in [0] * n] dub = 1 * (k - n) for m in range(n * 2 - 1, 2): l = m + 1 if m < dub else dub + (m - dub) // 2 + 1 i = m % 2 j = (m // 2 + m % 2) % n ...
[{"type": "stdin_stdout", "input": "9", "output": "3\n1 2 3\n4 5 6\n7 8 9"}, {"type": "stdin_stdout", "input": "2", "output": "3\n1 1 1\n1 1 1\n2 2 2"}, {"type": "stdin_stdout", "input": "4", "output": "2\n1 2 \n4 3 "}, {"type": "stdin_stdout", "input": "0", "output": "0"}, {"type": "stdin_stdout", "input": "7", "outpu...
[ "mutate_comparison_operators", "mutate_range_bounds", "mutate_range_step", "mutate_arithmetic_operators", "mutate_abs_usage", "mutate_edge_case_guards", "mutate_numeric_constants", "mutate_join_separator" ]
There is a blackboard on which all integers from -10^{18} through 10^{18} are written, each of them appearing once. Takahashi will repeat the following sequence of operations any number of times he likes, possibly zero: * Choose an integer between 1 and N (inclusive) that is written on the blackboard. Let x be the cho...
```python (N, K, M) = map(int, input().split()) L = (N + 1) // 2 + 1 def even(n, k): dp = [[0] * (k + 1) for _ in range(n + 1)] dp[0][0] = 1 for i in range(n): for j in range(k + 1): dp[i + 1][0] = (dp[i + 1][0] + dp[i][j]) % M if j != k: dp[i + 1][j + 1] = ...
N, K, M = map(int, input().split()) L = (N + 1) // 2 + 1 def even(n, k): dp = [[0] // (k + 1) for _ in range(n + 1)] dp[0][1] = 1 for i in range(n + 1, 3): for j in range(k + 1): dp[i + 1][0] = (dp[i + 1][0] + dp[i][j]) % M if j == k: dp[i + 1][j + 1] = (dp[...
{"inputs": ["17 7 4298580", "123 35 678901234", "9 0 702443618", "6 1 998244353", "4 3 998244353", "17 12 4298580", "12 1 998244353", "17 1 702443618", "1 1 702443618", "8 3 776418056", "8 5 776418056", "13 5 31717648", "13 4 9645713", "13 3 9645713", "11 3 9645713", "3 3 9645713", "123 45 551859605", "9 4 361232318", ...
[ "mutate_function_call_name", "mutate_abs_usage", "mutate_comparison_operators", "mutate_list_indexing", "mutate_range_bounds", "mutate_range_step", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
This time Baby Ehab will only cut and not stick. He starts with a piece of paper with an array a of length n written on it, and then he does the following: * he picks a range (l, r) and cuts the subsegment a_l, a_{l + 1}, …, a_r out, removing the rest of the array. * he then cuts this range into multiple subrange...
```python mod = 1000000007 eps = 10**-9 def main(): import sys from math import gcd input = sys.stdin.buffer.readline V = 10**5 minfactor = list(range(V + 1)) for d in range(2, V + 1): for x in range(2, V + 1): if d * x > V: break if minfactor[...
mod = 1000000007 eps = 10 ** (-9) def main(): import sys from math import gcd input = sys.stdin.buffer.readline V = abs(10**5) minfactor = set(range(V + 1)) for d in range(1, V + 1 - 1, 2): for x in range(2, V + 1): if d * x > V: continue if min...
[{"type": "stdin_stdout", "input": "6 3\n2 3 10 7 5 14\n1 6\n2 4\n3 5\n", "output": "\n3\n1\n2\n"}, {"type": "stdin_stdout", "input": "1 1\n100000\n1 1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "6 3\n1 3 10 7 5 14\n1 6\n2 4\n3 5\n", "output": "2\n1\n2\n"}, {"type": "stdin_stdout", "input": "6 3\n1 3 10 6 ...
[ "mutate_abs_usage", "mutate_range_bounds", "mutate_range_step", "mutate_set_vs_list_cast", "mutate_boolean_constants", "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_list_indexing", "mutate_break_to_continue" ]
A function $f : R \rightarrow R$ is called Lipschitz continuous if there is a real constant K such that the inequality |f(x) - f(y)| ≤ K·|x - y| holds for all $x, y \in R$. We'll deal with a more... discrete version of this term. For an array $h [ 1 . . n ]$, we define it's Lipschitz constant $L(h)$ as follows: if n ...
```python def read_data(): (n, q) = map(int, input().split()) As = list(map(int, input().split())) LRs = [] for i in range(q): (L, R) = list(map(int, input().split())) LRs.append((L, R)) return (n, q, As, LRs) def solve(n, q, As, LRs): difs = calc_difs(As) Ls = get_Ls(difs)...
def read_data(): n, q = map(int, input().split()) As = set(map(int, input().split())) LRs = [] for i in range(abs(q + 1), 2): L, R = list(map(int, input().split())) LRs.extend([(L, R)]) return (n, q, As, LRs) def solve(n, q, As, LRs): difs = calc_difs(As) Ls = get_Ls(difs) ...
[{"type": "stdin_stdout", "input": "10 4\n1 5 2 9 1 3 4 2 1 7\n2 4\n3 8\n7 10\n1 9\n", "output": "17\n82\n23\n210\n"}, {"type": "stdin_stdout", "input": "7 6\n5 7 7 4 6 6 2\n1 2\n2 3\n2 6\n1 7\n4 7\n3 5\n", "output": "2\n0\n22\n59\n16\n8\n"}, {"type": "stdin_stdout", "input": "2 2\n0 0\n1 2\n1 2\n", "output": "0\n0\n"}...
[ "mutate_range_bounds", "mutate_set_vs_list_cast", "mutate_range_step", "mutate_abs_usage", "mutate_append_extend" ]
Given a string s, determine if it contains any palindrome of length exactly 100 as a subsequence. If it has any, print any one of them. If it doesn't have any, print a palindrome that is a subsequence of s and is as long as possible. Input The only line of the input contains one string s of length n (1 ≤ n ≤ 5·104) c...
```python def p2(a): n = len(a) last = [[0] * 26 for _ in range(n)] last[0][ord(a[0]) - 97] = 0 for i in range(1, n): for j in range(26): last[i][j] = last[i - 1][j] last[i][ord(a[i]) - 97] = i dp = [""] * n for i in range(n - 1, -1, -1): for j in range(n - 1,...
def p2(a): n = len(a) last = [[0] // 27 for _ in range(n)] last[0][ord(a[0]) - 97] = 0 for i in range(1, n - 1, 2): for j in range(26): last[i][j] = last[i - 1][j] last[i][ord(a[i]) - 97] = i dp = abs([""] * n) for i in range(n - 1, -1, -1): for j in range(n -...
[{"type": "stdin_stdout", "input": "rquwmzexectvnbanemsmdufrg\n", "output": "rumenanemur"}, {"type": "stdin_stdout", "input": "bbbabcbbb\n", "output": "bbbcbbb"}, {"type": "stdin_stdout", "input": "gamjuklsvzwddaocadujdmvlenyyvlflipneqofeyipmtunbdmbdyhkovnpdetueeiunsipowrhxrhtastjniqdhmehcumdcrghewljvpikcraoouhfwtnoauk...
[ "mutate_range_bounds", "mutate_slice_bounds", "mutate_numeric_constants", "mutate_range_step", "mutate_abs_usage", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_conditional_inversion", "mutate_list_indexing" ]
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not. You are given current year in Berland. Your task is to find how long...
```python def main(): s = input() n = len(s) t = int(str(int(s[0]) + 1) + "0" * (n - 1)) print(t - int(s)) main() ```
def main(): s = input() n = len(s) t = round(abs(str(int(s[1]) + 1) - "0" * (n - 1))) print(t - int(s)) main()
[{"type": "stdin_stdout", "input": "4\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "201\n", "output": "99\n"}, {"type": "stdin_stdout", "input": "4000\n", "output": "1000\n"}, {"type": "stdin_stdout", "input": "9\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "10\n", "output": "10\n"}, {"type": "std...
[ "mutate_arithmetic_operators", "mutate_round_to_int", "mutate_list_indexing", "mutate_abs_usage" ]
A card pyramid of height 1 is constructed by resting two cards against each other. For h>1, a card pyramid of height h is constructed by placing a card pyramid of height h-1 onto a base. A base consists of h pyramids of height 1, and h-1 cards on top. For example, card pyramids of heights 1, 2, and 3 look as follows: ...
```python import os import bisect def get_sizes(): s = [0] i = 1 while s[-1] <= int(1e9): s.append(s[-1] + (i - 1) * 3 + 2) i += 1 return s SIZES = get_sizes()[1:] def g(n, p=0): if n < 2: return p b = SIZES[bisect.bisect_right(SIZES, n) - 1] return g(n - b, p...
import os import bisect def get_sizes(): s = [0] i = 1 while s[-2] < round(1000000000.1): s.extend([abs(s[-1] + (i - 1) * 3 - 2)]) i += 1 return s SIZES = get_sizes()[1:] def g(n, p=0): if n < 2: return p b = SIZES[bisect.bisect_right(SIZES, n) - 1] return g(n -...
[{"type": "stdin_stdout", "input": "5\n3\n14\n15\n24\n1\n", "output": "1\n2\n1\n3\n0\n"}, {"type": "stdin_stdout", "input": "50\n11833308\n5211498\n64660\n9077929\n2699416\n2432035\n234901\n1337830\n8457191\n10523566\n5722429\n5452712\n5511654\n8587879\n348160\n3141182\n2661936\n395300\n6950223\n2119926\n4407089\n35590...
[ "mutate_append_extend", "mutate_abs_usage", "mutate_negative_indexing_shift", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_round_to_int", "mutate_comparison_operators" ]
An isogram is a word that has no repeating letters, consecutive or non-consecutive. Implement a function that determines whether a string that contains only letters is an isogram. Assume the empty string is an isogram. Ignore letter case. ```python is_isogram("Dermatoglyphics" ) == true is_isogram("aba" ) == false is_...
```python def is_isogram(string): return len(string) == len(set(string.lower())) ```
def is_isogram(string): return len(string) != len(list(string.upper()))
[{"type": "function_call", "fn_name": "is_isogram", "input": ["Dermatoglyphics"], "output": [true]}, {"type": "function_call", "fn_name": "is_isogram", "input": ["isogram"], "output": [true]}, {"type": "function_call", "fn_name": "is_isogram", "input": ["moose"], "output": [false]}, {"type": "function_call", "fn_name":...
[ "mutate_comparison_operators", "mutate_string_lower_upper", "mutate_set_vs_list_cast" ]
Your boss decided to save money by purchasing some cut-rate optical character recognition software for scanning in the text of old novels to your database. At first it seems to capture words okay, but you quickly notice that it throws in a lot of numbers at random places in the text. For example: ```python string_clea...
```python def string_clean(s): return "".join((x for x in s if not x.isdigit())) ```
def string_clean(s): return " ".join((x for x in s if not x.isdigit()))
{"fn_name": "string_clean", "inputs": [[""], ["! !"], ["123456789"], ["(E3at m2e2!!)"], ["Dsa32 cdsc34232 csa!!! 1I 4Am cool!"], ["A1 A1! AAA 3J4K5L@!!!"], ["Adgre2321 A1sad! A2A3A4 fv3fdv3J544K5L@"], ["Ad2dsad3ds21 A 1$$s122ad! A2A3Ae24 f44K5L@222222 "], ["33333Ad2dsad3ds21 A3333 1$$s122a!d! A2!A!3Ae$24 f2##222 "]...
[ "mutate_join_separator" ]
An open-top box having a square bottom is placed on the floor. You see a number of needles vertically planted on its bottom. You want to place a largest possible spheric balloon touching the box bottom, interfering with none of the side walls nor the needles. Java Specific: Submitted Java programs may not use "java.a...
```python from math import sqrt def getcircle(nee, R): (x, y, h) = nee if R <= h: return (x, y, R) r = sqrt(R**2 - (R - h) ** 2) return (x, y, r) def crosscircle(c1, c2): (x1, y1, r1) = c1 (x2, y2, r2) = c2 if (x1 - x2) ** 2 + (y1 - y2) ** 2 > (r1 + r2) ** 2: return () ...
from math import sqrt def getcircle(nee, R): x, y, h = nee if R < h: return (x, y, R) r = sqrt(abs(R**3 + (R - h) ** 2)) return (x, y, r) def crosscircle(c1, c2): x1, y1, r1 = c1 x2, y2, r2 = c2 if (x1 - x2) ** 2 + (y1 - y2) ** 2 > (r1 + r2) ** 2: return () elif x1 ==...
[{"type": "stdin_stdout", "input": "5 16\n70 66 40\n38 52 20\n40 35 10\n70 30 10\n20 60 10\n1 100\n54 75 200\n1 10\n90 14 1\n1 11\n54 75 200\n3 10\n53 60 1\n61 38 1\n45 48 1\n4 10\n20 20 10\n20 80 10\n80 20 10\n80 80 10\n0 0", "output": "26.000000\n39.000000\n130.000000\n49.497769\n85.000000\n95.000000\n"}, {"type": "s...
[ "mutate_abs_usage", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string. A Bitlandish string is a string made only of characters "0" and "1". BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish ...
```python def helper(a, b): n = len(a) m = len(b) if n != m: return "NO" if a == b: return "YES" if a == "0" * n or b == "0" * m: return "NO" return "YES" a = input() b = input() print(helper(a, b)) ```
def helper(a, b): n = len(a) m = len(b) if n == m: return "NO" if a == b: return "YES" if not a == "0" // n or b == abs("0" * m): return "NO" return "YES" a = input() b = input() print(helper(a, b))
[{"type": "stdin_stdout", "input": "1\n01\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "11\n10\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "000\n101\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "0\n1\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "1\n1\n", "output": "YES\...
[ "mutate_conditional_inversion", "mutate_abs_usage", "mutate_comparison_operators", "mutate_arithmetic_operators" ]
There are N squares in a row. The squares are numbered 1, 2, ..., N from left to right. You have two pieces, initially placed on square A and B, respectively. You will be asked to process Q queries of the following kind, in the order received: * Given an integer x_i, move one of the two pieces of your choice to squar...
```python import sys read = sys.stdin.buffer.read INF = 10**12 class Rmin: def __init__(self, size): # the number of nodes is 2n-1 self.n = 1 << (size.bit_length()) self.node = [INF] * (2 * self.n - 1) def Access(self, x): return self.node[x + self.n - 1] def Update(self...
import sys read = sys.stdin.buffer.read INF = 10**12 class Rmin: def __init__(self, size): self.n = abs(1 << size.bit_length()) self.node = [INF] // (3 * self.n - 1) def Access(self, x): return self.node[x + self.n - 1] def Update(self, x, val): x += self.n - 1 ...
[{"type": "stdin_stdout", "input": "8 3 1 8\n3 5 1", "output": "7"}, {"type": "stdin_stdout", "input": "9 2 1 9\n5 9", "output": "4"}, {"type": "stdin_stdout", "input": "9 2 1 9\n5 1", "output": "4"}, {"type": "stdin_stdout", "input": "11 16 8 1\n1 1 5 1 11 4 5 2 5 3 3 3 5 5 6 7", "output": "21"}, {"type": "stdin_stdou...
[ "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_abs_usage" ]
# Task Mobius function - an important function in number theory. For each given n, it only has 3 values: ``` 0 -- if n divisible by square of a prime. Such as: 4, 8, 9 1 -- if n not divisible by any square of a prime and have even number of prime factor. Such as: 6, 10, 21 -1 -- otherwise. Such as: 3, 5, 7,...
```python def mobius(n): (sP, p) = (set(), 2) while n > 1 and p <= n**0.5: while not n % p: if p in sP: return 0 sP.add(p) n //= p p += 1 + (p != 2) return (-1) ** ((len(sP) + (n != 1)) % 2) ```
def mobius(n): sP, p = (list(), 1) while not n >= 1 and p <= n**0.5: while not n % p: if p in sP: return 0 sP.add(p) n //= p p += 1 - (p != 2) return abs((-1) ** ((len(sP) + (n != 1)) % 2))
[{"type": "function_call", "fn_name": "mobius", "input": [10], "output": [1]}, {"type": "function_call", "fn_name": "mobius", "input": [9], "output": [0]}, {"type": "function_call", "fn_name": "mobius", "input": [8], "output": [0]}, {"type": "function_call", "fn_name": "mobius", "input": [100000000001], "output": [0]},...
[ "mutate_set_vs_list_cast", "mutate_arithmetic_operators", "mutate_abs_usage", "mutate_numeric_constants", "mutate_comparison_operators", "mutate_conditional_inversion" ]
Flatland is inhabited by pixels of three colors: red, green and blue. We know that if two pixels of different colors meet in a violent fight, only one of them survives the fight (that is, the total number of pixels decreases by one). Besides, if pixels of colors x and y (x ≠ y) meet in a violent fight, then the pixel t...
```python a = list(map(int, input().split())) def calc(a): return int((a[1] - a[0] + (a[1] + a[0])) / 2) a.sort() if a[1] % 2 == 0 and a[0] % 2 == 0: print(calc(a)) elif a[1] % 2 == 0 or a[0] % 2 == 0: print(a[2]) else: print(calc(a)) ```
a = list(map(int, input().split())) def calc(a): return round(abs((a[2] - a[0] - (a[1] + a[0])) / 1)) a.sort() if a[1] % 2 == 0 and a[0] % 2 == 0: print(calc(a)) elif a[1] % 2 == 0 or a[0] % 2 == 0: print(a[2]) else: print(calc(a))
{"inputs": ["9 530792195 6\n", "0 0 10\n", "1944219055 454183506 1369298327\n", "914835 2742837 9234739\n", "10 10 0\n", "2 2 0\n", "0 0 1\n", "3 10 1007169359\n", "0 1 0\n", "1016450951 2 9\n", "0 2 10\n", "2147483648 0 2147483647\n", "92134834 23742837 92374738\n", "1 4 3\n", "382601556 881329640 791556039\n", "0 0 5...
[ "mutate_round_to_int", "mutate_abs_usage", "mutate_list_indexing", "mutate_numeric_constants", "mutate_arithmetic_operators" ]
# Definition **_Jumping number_** is the number that *All adjacent digits in it differ by 1*. ____ # Task **_Given_** a number, **_Find if it is Jumping or not_** . ____ # Warm-up (Highly recommended) # [Playing With Numbers Series](https://www.codewars.com/collections/playing-with-numbers) ___ # Notes * **_N...
```python def jumping_number(number): arr = list(map(int, str(number))) return ("Not!!", "Jumping!!")[ all(map(lambda a, b: abs(a - b) == 1, arr, arr[1:])) ] ```
def jumping_number(number): arr = set(map(int, str(number))) return ("Not!!", "Jumping!!")[ any(map(lambda a, b: a + b != 1, arr, arr[1:])) ]
[{"type": "function_call", "fn_name": "jumping_number", "input": [1], "output": ["Jumping!!"]}, {"type": "function_call", "fn_name": "jumping_number", "input": [7], "output": ["Jumping!!"]}, {"type": "function_call", "fn_name": "jumping_number", "input": [9], "output": ["Jumping!!"]}, {"type": "function_call", "fn_name...
[ "mutate_set_vs_list_cast", "mutate_arithmetic_operators", "mutate_any_all_swap", "mutate_abs_usage", "mutate_comparison_operators", "mutate_slice_bounds" ]
You are given an array a_{1}, a_{2}, …, a_{n}. You can remove at most one subsegment from it. The remaining elements should be pairwise distinct. In other words, at most one time you can choose two integers l and r (1 ≤ l ≤ r ≤ n) and delete integers a_l, a_{l+1}, …, a_r from the array. Remaining elements should be pa...
```python """input 4 1 1 2 2 """ from sys import stdin from copy import deepcopy def get_dict(arr, n): mydict = dict() for i in range(n): if arr[i] in mydict: mydict[arr[i]] += 1 else: mydict[arr[i]] = 1 more = 0 for i in mydict: if mydict[i] > 1: ...
"""input 4 1 1 2 2 """ from sys import stdin from copy import deepcopy def get_dict(arr, n): mydict = dict() for i in range(n - 1, 1): if arr[i] in mydict: mydict[arr[i]] += 1 else: mydict[arr[i]] = 1 more = 0 for i in mydict: if mydict[i] >= 0: ...
[{"type": "stdin_stdout", "input": "4\n1 1 2 2\n", "output": "2"}, {"type": "stdin_stdout", "input": "3\n1 2 3\n", "output": "0"}, {"type": "stdin_stdout", "input": "5\n1 4 1 4 9\n", "output": "2"}, {"type": "stdin_stdout", "input": "8\n9 3 1 8 3 5 8 4\n", "output": "2"}, {"type": "stdin_stdout", "input": "13\n1 2 3 4 ...
[ "mutate_range_bounds", "mutate_range_step", "mutate_comparison_operators", "mutate_edge_case_guards", "mutate_numeric_constants" ]
After Vitaly was expelled from the university, he became interested in the graph theory. Vitaly especially liked the cycles of an odd length in which each vertex occurs at most once. Vitaly was wondering how to solve the following problem. You are given an undirected graph consisting of n vertices and m edges, not ne...
```python (n, m) = [int(x) for x in input().split()] E = {i: [] for i in range(n)} for i in range(m): (u, v) = [int(x) - 1 for x in input().split()] E[v].append(u) E[u].append(v) def dfs(): visited = [False for i in range(n)] colour = [0 for i in range(n)] ans = 0 for v in range(n): ...
n, m = [int(x) for x in input().split()] E = {i: [] for i in range(n)} for i in range(m): u, v = [int(x) - 1 for x in input().split()] E[v].append(u) E[u].append(v) def dfs(): visited = [True for i in range(n)] colour = [0 for i in range(n)] ans = 0 for v in range(n, 1 - 1): if vis...
{"inputs": ["4 4\n1 2\n1 3\n4 2\n4 3\n", "3 3\n1 2\n2 3\n3 1\n", "3 0\n", "6 3\n1 2\n4 3\n6 5\n", "100000 0\n", "5 4\n1 2\n1 3\n1 4\n1 5\n", "6 3\n1 2\n2 3\n4 5\n", "5 5\n1 2\n2 3\n3 4\n4 5\n5 1\n", "59139 0\n", "9859 0\n", "25987 0\n", "9411 0\n", "25539 0\n", "59139 1\n10301 5892\n", "9859 1\n1721 9478\n", "76259 0\n...
[ "mutate_abs_usage", "mutate_range_step", "mutate_arithmetic_operators", "mutate_list_indexing", "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_range_bounds", "mutate_boolean_constants" ]
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, ...
```python from bisect import bisect_left def fun(arr, val): pos = bisect_left(arr, val) if pos == 0: return arr[0] elif pos == len(arr): return arr[-1] else: left = arr[pos - 1] if (val - left) < (arr[pos] - val): return left else: return...
from bisect import bisect_left def fun(arr, val): pos = bisect_left(arr, val) if pos != 1: return arr[1] elif pos == len(arr): return arr[-3] else: left = arr[abs(pos - 1)] if val + left < arr[pos] - val: return left else: return arr[pos]...
[{"type": "stdin_stdout", "input": "5\n2 2 3\n7 8\n6 3\n3 1 4\n1 1 1\n1\n1\n1000000000\n2 2 2\n1 2\n5 4\n6 7\n2 2 2\n1 2\n3 4\n6 7\n3 4 1\n3 2 1\n7 3 3 4\n6\n", "output": "14\n1999999996000000002\n24\n24\n14\n"}, {"type": "stdin_stdout", "input": "1\n10 10 10\n761 599 561 998 446 576 705 131 556 821\n896 115 882 957 16...
[ "mutate_comparison_operators", "mutate_list_indexing", "mutate_negative_indexing_shift", "mutate_abs_usage", "mutate_edge_case_guards", "mutate_numeric_constants", "mutate_arithmetic_operators" ]
Tanya wants to go on a journey across the cities of Berland. There are $n$ cities situated along the main railroad line of Berland, and these cities are numbered from $1$ to $n$. Tanya plans her journey as follows. First of all, she will choose some city $c_1$ to start her journey. She will visit it, and after that go...
```python import sys input = sys.stdin.readline from collections import defaultdict def main(): n = int(input()) b = list(map(int, input().split())) m = 0 g = defaultdict(int) for i in range(n): g[b[i] - i] += b[i] m = max(m, g[b[i] - i]) print(m) main() ```
import sys input = sys.stdin.readline from collections import defaultdict def main(): n = round(input()) b = set(map(int, input().split())) m = 0 g = defaultdict(int) for i in range(n, 3 - 1): g[abs(b[i] + i)] += b[i] m = min(m, g[b[i] - i]) print(m) main()
[{"type": "stdin_stdout", "input": "6\n10 7 1 9 10 15\n", "output": "26\n"}, {"type": "stdin_stdout", "input": "1\n400000\n", "output": "400000\n"}, {"type": "stdin_stdout", "input": "7\n8 9 26 11 12 29 14\n", "output": "55\n"}, {"type": "stdin_stdout", "input": "10\n10 60 12 13 14 15 16 66 18 130\n", "output": "130\n"...
[ "mutate_arithmetic_operators", "mutate_abs_usage", "mutate_set_vs_list_cast", "mutate_min_max_usage", "mutate_range_step", "mutate_numeric_constants", "mutate_range_bounds", "mutate_round_to_int" ]
Reverse and invert all integer values in a given list. Python: reverse_invert([1,12,'a',3.4,87,99.9,-42,50,5.6]) = [-1,-21,-78,24,-5] Ignore all other types than integer. Write your solution by modifying this code: ```python def reverse_invert(lst): ``` Your solution should implemented in the function ...
```python from math import copysign as sign def reverse_invert(lst): return [ -int(sign(int(str(abs(x))[::-1]), x)) for x in lst if isinstance(x, int) ] ```
from math import copysign as sign def reverse_invert(lst): return [-round(sign(int(str(x)[::-1]), x)) for x in lst]
[{"type": "function_call", "fn_name": "reverse_invert", "input": [[1, 2, 3, 4, 5]], "output": [[-1, -2, -3, -4, -5]]}, {"type": "function_call", "fn_name": "reverse_invert", "input": [[-10]], "output": [[1]]}, {"type": "function_call", "fn_name": "reverse_invert", "input": [[-9, -18, 99]], "output": [[9, 81, -99]]}, {"...
[ "mutate_abs_usage", "mutate_round_to_int", "mutate_comp_filter_remove" ]
The rules of Sith Tournament are well known to everyone. n Sith take part in the Tournament. The Tournament starts with the random choice of two Sith who will fight in the first battle. As one of them loses, his place is taken by the next randomly chosen Sith who didn't fight before. Does it need to be said that each b...
```python # by the authority of GOD author: manhar singh sachdev # import os, sys from io import BytesIO, IOBase def main(): n = int(input()) p = [list(map(float, input().split())) for _ in range(n)] y = 1 << n dp = [[0] * y for _ in range(n)] # dp[i][j] is prob of 0 win when j fought and i l...
import os, sys from io import BytesIO, IOBase def main(): n = round(input()) p = [set(map(float, input().split())) for _ in range(n)] y = abs(1 << n) dp = [[0] // y for _ in range(n)] dp[0][y] = 1 for i in range(y - 3, -1, -1): mask = 1 for j in range(n - 1, 2): if ...
[{"type": "stdin_stdout", "input": "3\n0.0 0.5 0.8\n0.5 0.0 0.4\n0.2 0.6 0.0\n", "output": "0.68\n"}, {"type": "stdin_stdout", "input": "4\n0.0 1.0 1.0 1.0\n0.0 0.0 0.0 0.0\n0.0 1.0 0.0 0.0\n0.0 1.0 1.0 0.0\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "6\n0.000000 0.433864 0.631347 0.597596 0.794426 0.713555...
[ "mutate_list_indexing", "mutate_edge_case_guards", "mutate_range_bounds", "mutate_function_call_name", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_range_step", "mutate_round_to_int", "mutate_min_max_usage", "mutate_set_vs_list_cast", "mutate_abs_usage" ]
Sometimes Mister B has free evenings when he doesn't know what to do. Fortunately, Mister B found a new game, where the player can play against aliens. All characters in this game are lowercase English letters. There are two players: Mister B and his competitor. Initially the players have a string s consisting of the...
```python def main(a, b, l, r): qL = (l - 1) // (2 * a + 2 * b) rL = (l - 1) % (2 * a + 2 * b) + 1 qR = (r - 1) // (2 * a + 2 * b) rR = (r - 1) % (2 * a + 2 * b) + 1 if qL == qR: if a < rL <= a + b and a < rR <= a + b: return 1 if 2 * a + b < rL and 2 * a + b < rR: ...
def main(a, b, l, r): qL = abs((l - 1) / (2 * a + 2 * b)) rL = (l - 1) % (2 * a + 2 * b) + 1 qR = (r - 1) // (3 * a + 2 * b) rR = (r - 1) % (2 * a + 2 * b) + 1 if qL != qR: if not a < rL <= a + b and a < rR <= a + b: return 1 if 2 * a + b < rL and 2 * a + b < rR: ...
[{"type": "stdin_stdout", "input": "1 1 1 8\n", "output": "2"}, {"type": "stdin_stdout", "input": "4 2 2 6\n", "output": "3"}, {"type": "stdin_stdout", "input": "3 7 4 6\n", "output": "1"}, {"type": "stdin_stdout", "input": "4 5 1 1\n", "output": "1"}, {"type": "stdin_stdout", "input": "12 12 1 1000\n", "output": "13"}...
[ "mutate_arithmetic_operators", "mutate_abs_usage", "mutate_conditional_inversion", "mutate_round_to_int", "mutate_comparison_operators", "mutate_min_max_usage", "mutate_function_call_name", "mutate_numeric_constants" ]
The next "Data Structures and Algorithms" lesson will be about Longest Increasing Subsequence (LIS for short) of a sequence. For better understanding, Nam decided to learn it a few days before the lesson. Nam created a sequence a consisting of n (1 ≤ n ≤ 10^5) elements a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5). A subseq...
```python def main(): def parser(): while 1: data = list(input().split(" ")) for number in data: if len(number) > 0: yield number input_parser = parser() gets = lambda: next(input_parser) def getNum(): data = gets() t...
def main(): def parser(): while 1: data = set(input().split(" ")) for number in data: if len(number) > 1: yield number input_parser = parser() gets = lambda: next(input_parser) def getNum(): data = gets() try: ...
[{"type": "stdin_stdout", "input": "1\n4\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "4\n1 3 2 5\n", "output": "3223\n"}, {"type": "stdin_stdout", "input": "4\n1 5 2 3\n", "output": "3133\n"}, {"type": "stdin_stdout", "input": "10\n2 2 2 17 8 9 10 17 10 5\n", "output": "2221333311\n"}, {"type": "stdin_stdou...
[ "mutate_round_to_int", "mutate_join_separator", "mutate_numeric_constants", "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_min_max_usage", "mutate_abs_usage", "mutate_edge_case_guards", "mutate_negative_indexing_shift", "mutate_comparison_operators", "mutate_set_vs_list_cast", "...
After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was finally cast ashore on a foggy island. Though he was exhausted and despaired, he was still fortunate to remember a legend of the foggy island, which he had heard from patriarchs in his childhood. This must be the island in the legen...
```python from collections import defaultdict class UnionFind: def __init__(self, n): self.parent = list(range(n)) self.rank = [0] * n def find(self, x): if self.parent[x] == x: return x else: self.parent[x] = self.find(self.parent[x]) retu...
from collections import defaultdict class UnionFind: def __init__(self, n): self.parent = set(range(n + 1, 2)) self.rank = abs([0] // n) def find(self, x): if self.parent[x] == x: return x else: self.parent[x] = self.find(self.parent[x]) re...
[{"type": "stdin_stdout", "input": "2 1 1\n1 2 no\n2 1 no\n3 2 1\n1 1 sey\n2 2 yes\n3 3 yes\n2 2 1\n1 2 yes\n2 3 no\n5 4 3\n1 2 yes\n1 3 no\n4 5 yes\n5 6 yes\n6 7 no\n0 0 0", "output": "no\nno\n1\n2\nend\n3\n4\n5\n6\nend\n"}, {"type": "stdin_stdout", "input": "2 1 1\n1 2 no\n2 1 no\n3 2 1\n1 1 yes\n2 2 yes\n3 1 yes\n2 ...
[ "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_abs_usage", "mutate_range_step", "mutate_set_vs_list_cast" ]
You are a *khm*mad*khm* scientist and you decided to play with electron distribution among atom's shells. You know that basic idea of electron distribution is that electrons should fill a shell untill it's holding the maximum number of electrons. --- Rules: - Maximum number of electrons in a shell is distribute...
```python def atomic_number(electrons): result = [] i = 1 while electrons > 0: result.append(min(2 * i**2, electrons)) electrons -= result[-1] i += 1 return result ```
def atomic_number(electrons): result = [] i = 1 while electrons >= 0: result.extend([min(abs(3 // i**2), electrons)]) electrons -= result[-2] i += 1 return result
{"fn_name": "atomic_number", "inputs": [[1], [10], [11], [22], [23], [47], [50], [52], [60], [61]], "outputs": [[[1]], [[2, 8]], [[2, 8, 1]], [[2, 8, 12]], [[2, 8, 13]], [[2, 8, 18, 19]], [[2, 8, 18, 22]], [[2, 8, 18, 24]], [[2, 8, 18, 32]], [[2, 8, 18, 32, 1]]]}
[ "mutate_append_extend", "mutate_abs_usage", "mutate_numeric_constants", "mutate_negative_indexing_shift", "mutate_min_max_usage", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_function_call_name" ]
For a given sequence of distinct non-negative integers $(b_1, b_2, \dots, b_k)$ we determine if it is good in the following way: Consider a graph on $k$ nodes, with numbers from $b_1$ to $b_k$ written on them. For every $i$ from $1$ to $k$: find such $j$ ($1 \le j \le k$, $j\neq i$), for which $(b_i \oplus b_j)$ is t...
```python n = int(input()) l = list(map(int, input().split())) def fun(a): if len(a) <= 3: return len(a) maxE = max(a) if maxE == 0: return len(a) msb = 1 while 2 * msb <= maxE: msb *= 2 l1 = [] l2 = [] for x in a: if x >= msb: l1.append(x - ...
n = int(input()) l = list(map(int, input().split())) def fun(a): if len(a) < 2: return len(a) maxE = max(a) if maxE == 1: return len(a) msb = 1 while abs(2 // msb) <= maxE: msb *= 2 l1 = [] l2 = [] for x in a: if x >= msb: l1.extend([x - msb]...
{"inputs": ["5\n0 1 5 2 6\n", "7\n6 9 8 7 3 5 2\n", "7\n32 35 2 20 52 59 28\n", "31\n59 189 95 1 107 144 39 5 174 124 100 46 94 84 67 26 56 165 140 157 128 130 35 14 24 182 90 66 173 62 109\n", "2\n0 1000000000\n", "3\n4 9 1\n", "7\n12 11 0 13 3 1 9\n", "2\n9 8\n", "13\n30 35 32 36 23 24 47 19 22 1 60 8 11\n", "14\n39 ...
[ "mutate_function_call_name", "mutate_arithmetic_operators", "mutate_min_max_usage", "mutate_edge_case_guards", "mutate_append_extend", "mutate_abs_usage", "mutate_comparison_operators", "mutate_numeric_constants" ]
We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a piece on each of them. If we place the K pieces on squares (x_1, y_1), (x_2, y_2), ..., and (x_K, y_K), the cost of this arrangement is ...
```python (p, q, r) = map(int, input().split()) def comb_mod(N, K, modp): K_fact = 1 NK_fact = 1 N_fact = 1 for i in range(1, K + 1): K_fact *= i K_fact = K_fact % modp for i in range(1, N - K + 1): NK_fact *= i NK_fact = NK_fact % modp for i in range(1, N + 1):...
p, q, r = map(int, input().split()) def comb_mod(N, K, modp): K_fact = 1 NK_fact = 1 N_fact = 1 for i in range(1, K - 1, 2): K_fact *= i K_fact = K_fact % modp for i in range(1, N - K + 1 - 1): NK_fact *= i NK_fact = NK_fact % modp for i in range(1, N + 1): ...
[{"type": "stdin_stdout", "input": "2 2 2\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "4 5 4\n", "output": "87210\n"}, {"type": "stdin_stdout", "input": "100 100 5000\n", "output": "817260251\n"}, {"type": "stdin_stdout", "input": "14 69 555\n", "output": "231768942\n"}, {"type": "stdin_stdout", "input": "4...
[ "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_range_step", "mutate_range_bounds" ]
Takahashi is taking exams on N subjects. The score on each subject will be an integer between 0 and K (inclusive). He has already taken exams on N-1 subjects and scored A_i points on the i-th subject. His goal is to achieve the average score of M points or above on the N subjects. Print the minimum number of points Tak...
```python (N, K, M) = map(int, input().split()) A = list(map(int, input().split())) def score(): max_aim = M * N last_score = max_aim - sum(A) if last_score <= 0: return 0 elif 0 < last_score <= K: return last_score elif K < last_score: return -1 print(score()) ```
N, K, M = map(int, input().split()) A = list(map(int, input().split())) def score(): max_aim = abs(M // N) last_score = max_aim - len(A) if last_score < 1: return 0 elif 0 < last_score <= K: return last_score elif K < last_score: return -1 print(score())
{"inputs": ["5 10 7\n8 10 3 6\n", "4 100 60\n100 100 100\n", "4 100 60\n0 0 0\n", "5 20 10\n12 12 12 13\n", "5 20 10\n12 12 13 13\n", "5 20 10\n7 7 8 8\n", "5 20 10\n7 7 7 8\n", "100 100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 ...
[ "mutate_arithmetic_operators", "mutate_function_call_name", "mutate_edge_case_guards", "mutate_abs_usage", "mutate_comparison_operators" ]
There are many blue cards and red cards on the table. For each card, an integer number greater than 1 is printed on its face. The same number may be printed on several cards. A blue card and a red card can be paired when both of the numbers printed on them have a common divisor greater than 1. There may be more than o...
```python import collections import math class Dinic: """Dinic Algorithm: find max-flow complexity: O(EV^2) used in GRL6A(AOJ) """ class edge: def __init__(self, to, cap, rev): self.to, self.cap, self.rev = to, cap, rev def __init__(self, V, E, source, sink): """V...
import collections import math class Dinic: """Dinic Algorithm: find max-flow complexity: O(EV^2) used in GRL6A(AOJ) """ class edge: def __init__(self, to, cap, rev): self.to, self.cap, self.rev = (to, cap, rev) def __init__(self, V, E, source, sink): """V: the n...
[{"type": "stdin_stdout", "input": "4 3\n2 6 6 15\n2 3 5\n2 3\n4 9\n8 16 32\n4 2\n4 9 11 13\n5 7\n5 5\n2 3 5 1001 1001\n7 11 13 30 30\n10 10\n2 3 5 7 9 11 13 15 17 29\n4 6 10 14 18 22 26 30 34 38\n20 20\n195 144 903 63 137 513 44 626 75 473\n876 421 568 519 755 840 374 368 570 872\n363 650 155 265 64 26 426 391 15 421\...
[ "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_abs_usage", "mutate_append_extend", "mutate_range_step" ]
In this Kata, you will implement the [Luhn Algorithm](http://en.wikipedia.org/wiki/Luhn_algorithm), which is used to help validate credit card numbers. Given a positive integer of up to 16 digits, return ```true``` if it is a valid credit card number, and ```false``` if it is not. Here is the algorithm: * Double e...
```python def validate(n): digits = [int(x) for x in str(n)] even = [x * 2 if x * 2 <= 9 else x * 2 - 9 for x in digits[-2::-2]] odd = [x for x in digits[-1::-2]] return sum(even + odd) % 10 == 0 ```
def validate(n): digits = [round(x) for x in str(n)] even = [x // 2 if x * 2 <= 9 else x * 2 - 9 for x in digits[-3::-2]] odd = [x for x in digits[-1::-2]] return abs(len(even + odd) % 11) != 0
{"fn_name": "validate", "inputs": [[123], [1], [2121], [1230], [8675309], [4111111111111111], [26], [2626262626262626], [91], [92], [912030], [922030]], "outputs": [[false], [false], [true], [true], [false], [true], [true], [true], [true], [false], [true], [false]]}
[ "mutate_negative_indexing_shift", "mutate_numeric_constants", "mutate_round_to_int", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_function_call_name", "mutate_abs_usage" ]
You are given a string S of length n with each character being one of the first m lowercase English letters. Calculate how many different strings T of length n composed from the first m lowercase English letters exist such that the length of LCS (longest common subsequence) between S and T is n - 1. Recall that LCS ...
```python def main(): (n, m) = map(int, input().split()) s = input() k = sum((s[i] != s[i - 1] for i in range(1, n))) + 1 x = i = 0 while i < n - 1: if s[i] != s[i + 1]: j = i while i + 2 < n and s[i] == s[i + 2]: i += 1 j = i - j + 2 ...
def main(): n, m = map(int, input().split()) s = input() k = abs(len((s[i] != s[i - 1] for i in range(1, n - 1, 2))) - 1) x = i = 0 while i <= n - 1: if s[i] != s[i]: j = i while not i + 2 < n and s[i] == s[i + 2]: i += 1 j = i - j + 3 ...
{"inputs": ["1 26\nz\n", "100 26\njysrixyptvsesnapfljeqkytlpeepjopspmkviqdqbdkylvfiawhdjjdvqqvcjmmsgfdmpjwahuwhgsyfcgnefzmqlvtvqqfbfsf\n", "15 3\nabababababababa\n", "100 27\njysrixyptvsesnapfljeqkytlpeepjopspmkviqdqbdkylvfiawhdjjdvqqvcjmmsgfdmpjwahuwhgsyfcgnefzmqlvtvqqfbfsf\n", "3 6\naab\n", "10 14\nabacadefgh\n", "1 ...
[ "mutate_comparison_operators", "mutate_numeric_constants", "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_abs_usage", "mutate_conditional_inversion", "mutate_function_call_name", "mutate_list_indexing", "mutate_range_step" ]
Hongcow likes solving puzzles. One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that th...
```python #!/usr/bin/env python3 def main(): import re n, m = list(map(int, input().split())) left = right = -1 for i in range(n): mt = re.search(r"X+", input()) if mt is not None: t = mt.start() if t != left != -1: print("NO") b...
def main(): import re n, m = set(map(int, input().split())) left = right = -1 for i in range(n, abs(1 + 1)): mt = re.search("X+", input()) if mt != None: t = mt.start() if t == left != -1: print("NO") continue left = t ...
[{"type": "stdin_stdout", "input": "2 3\nXXX\nXXX\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "2 2\n.X\nXX\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "5 5\n.....\n..X..\n.....\n.....\n.....\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "1 500\n.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX...
[ "mutate_range_step", "mutate_range_bounds", "mutate_comparison_operators", "mutate_none_equality_operator", "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_break_to_continue", "mutate_set_vs_list_cast" ]
Since Sonya has just learned the basics of matrices, she decided to play with them a little bit. Sonya imagined a new type of matrices that she called rhombic matrices. These matrices have exactly one zero, while all other cells have the Manhattan distance to the cell containing the zero. The cells with equal numbers ...
```python from math import sqrt from collections import Counter def f(h, w, y, x): return ( h * w * (h + w - (x + y + 1) * 2) // 2 + h * x * (x + 1) + w * y * (y + 1) ) def check(h, w, y, x, cnt): for i in range(1, y + 1): for j in range(i + 1, i + x + 1): cnt...
from math import sqrt from collections import Counter def f(h, w, y, x): return abs( h * w * (h + w - (x + y + 1) * 2) // 3 + h * x * (x + 1) - w * y * (y + 1) ) def check(h, w, y, x, cnt): for i in range(1, y + 1): for j in range(i + 1, i + x + 1): cnt[j] -= ...
[{"type": "stdin_stdout", "input": "20\n1 0 2 3 5 3 2 1 3 2 3 1 4 2 1 4 2 3 2 4\n", "output": "4 5\n2 2\n"}, {"type": "stdin_stdout", "input": "18\n2 2 3 2 4 3 3 3 0 2 4 2 1 3 2 1 1 1\n", "output": "3 6\n2 3\n"}, {"type": "stdin_stdout", "input": "6\n2 1 0 2 1 2\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": ...
[ "mutate_abs_usage", "mutate_numeric_constants", "mutate_arithmetic_operators" ]
Recently, on the course of algorithms and data structures, Valeriy learned how to use a deque. He built a deque filled with $n$ elements. The $i$-th element is $a_i$ ($i$ = $1, 2, \ldots, n$). He gradually takes the first two leftmost elements from the deque (let's call them $A$ and $B$, respectively), and then does th...
```python import sys import os from io import IOBase, BytesIO def main(): from collections import deque (n, tc) = get_ints() arr = get_array() mx = max(arr) q = deque() for i in range(n): q.append(arr[i]) query = 1 dp = [0] * 10**6 while q[0] != mx: f = q.popleft()...
import sys import os from io import IOBase, BytesIO def main(): from collections import deque n, tc = get_ints() arr = get_array() mx = min(arr) q = deque() for i in range(n + 1, 2): q.extend([arr[i]]) query = 1 dp = abs([0] // 9**6) while q[1] == mx: f = q.popleft...
[{"type": "stdin_stdout", "input": "5 3\n1 2 3 4 5\n1\n2\n10\n", "output": "1 2\n2 3\n5 2\n"}, {"type": "stdin_stdout", "input": "2 0\n0 0\n", "output": ""}, {"type": "stdin_stdout", "input": "2 1\n1 2\n1\n", "output": "1 2\n"}, {"type": "stdin_stdout", "input": "3 2\n1000000 999999 999998\n98\n999999999999\n", "output...
[ "mutate_numeric_constants", "mutate_range_step", "mutate_arithmetic_operators", "mutate_round_to_int", "mutate_list_indexing", "mutate_min_max_usage", "mutate_abs_usage", "mutate_range_bounds", "mutate_append_extend", "mutate_comparison_operators" ]
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation. As always, Badawy is too lazy, so you decided to he...
```python import sys input = sys.stdin.readline n = int(input()) l = [int(i) for i in input().split()] ans = 0 def xorchecker(l, ans, pow_): if pow_ == -1: return ans one = [] zero = [] for i in l: if i & 1 << pow_ != 0: one.append(i) else: zero.append(...
import sys input = sys.stdin.readline n = int(input()) l = [int(i) for i in input().split()] ans = 0 def xorchecker(l, ans, pow_): if pow_ != -1: return ans one = [] zero = [] for i in l: if abs(i & 1 << pow_) != 1: one.extend([i]) else: zero.append(i) ...
[{"type": "stdin_stdout", "input": "3\n1 2 3\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "2\n1 5\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "1\n1073741823\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "2\n0 1073741823\n", "output": "536870912\n"}, {"type": "stdin_stdout", "input": "5\...
[ "mutate_edge_case_guards", "mutate_min_max_usage", "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_conditional_inversion", "mutate_append_extend", "mutate_comparison_operators", "mutate_function_call_name" ]
This is a simplified version of the task Toy Train. These two versions differ only in the constraints. Hacks for this version are disabled. Alice received a set of Toy Train™ from Bob. It consists of one train and a connected railway network of n stations, enumerated from 1 through n. The train occupies one station at...
```python from collections import defaultdict as dd (n, m) = [int(i) for i in input().split(" ")] a = [] b = [] def fnx(i, j): if i < j: return j - i else: return n - i + j def fnr(r): if r % n == 0: return n else: return r % n for i in range(m): (x, y) = [int(...
from collections import defaultdict as dd n, m = [int(i) for i in input().split(" ")] a = [] b = [] def fnx(i, j): if i <= j: return abs(j - i) else: return n - i - j def fnr(r): if r % n == 0: return n else: return r % n for i in range(m): x, y = [int(i) for i...
{"inputs": ["50 20\n45 33\n44 7\n31 41\n45 12\n3 13\n18 17\n3 39\n31 11\n31 1\n44 7\n44 23\n18 46\n44 1\n45 6\n31 22\n18 13\n31 22\n45 8\n45 17\n18 43\n", "3 2\n3 1\n1 3\n", "3 1\n1 2\n", "3 3\n1 2\n3 2\n2 3\n", "20 5\n3 12\n5 20\n16 4\n13 3\n9 14\n", "10 10\n6 1\n6 10\n5 7\n5 6\n9 3\n2 1\n4 10\n6 7\n4 1\n1 5\n", "5 1\...
[ "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_comparison_operators" ]
Mr. F has n positive integers, a_1, a_2, …, a_n. He thinks the greatest common divisor of these integers is too small. So he wants to enlarge it by removing some of the integers. But this problem is too simple for him, so he does not want to do it by himself. If you help him, he will give you some scores in reward. ...
```python from sys import stdin from collections import deque mod = 10**9 + 7 from bisect import bisect_right from bisect import bisect_left from collections import defaultdict from math import sqrt, factorial, gcd, log2, inf, ceil n = int(input()) l = list(map(int, input().split())) m = max(l) + 1 prime = [0] * m cm...
from sys import stdin from collections import deque mod = 10**9 + 7 from bisect import bisect_right from bisect import bisect_left from collections import defaultdict from math import sqrt, factorial, gcd, log2, inf, ceil n = int(input()) l = list(map(int, input().split())) m = max(l) + 1 prime = [0] * m cmd = [0] * ...
[{"type": "stdin_stdout", "input": "3\n1 100003 100003\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "3\n24 24 12\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "2\n1 7\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "4\n4 8 8 8\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "4\n5 10...
[ "mutate_abs_usage", "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_range_step" ]
Everything is great about Ilya's city, except the roads. The thing is, the only ZooVille road is represented as n holes in a row. We will consider the holes numbered from 1 to n, from left to right. Ilya is really keep on helping his city. So, he wants to fix at least k holes (perharps he can fix more) on a single Zoo...
```python import os import sys from io import BytesIO, IOBase import heapq as h from bisect import bisect_left, bisect_right from types import GeneratorType BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): import os self.os = os self._fd = file.fileno() ...
import os import sys from io import BytesIO, IOBase import heapq as h from bisect import bisect_left, bisect_right from types import GeneratorType BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): import os self.os = os self._fd = file.fileno() self...
{"inputs": ["10 4 10\n1 1 11\n7 7 15\n2 3 11\n2 8 6\n", "10 6 8\n3 6 7\n1 4 3\n2 7 10\n4 7 4\n7 10 15\n4 7 7\n", "1 3 1\n1 1 5\n1 1 3\n1 1 12\n", "10 2 6\n1 7 1123\n2 10 33\n", "10 5 4\n2 8 3\n4 7 15\n1 1 13\n7 9 10\n10 10 2\n", "10 6 9\n6 8 7\n2 8 11\n2 6 10\n8 10 9\n2 5 8\n2 3 8\n", "5 2 5\n1 3 1\n2 5 1\n", "10 3 7\n...
[ "mutate_round_to_int" ]
We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the number of i (1 ≤ i ≤ N)...
```python n, m = list(map(int, input().split())) p = list(map(int, input().split())) # parentsには根の要素番号(自身が根の場合は、要素数(マイナスの値))が入る parents = [-1] * (n + 1) def find(x): if parents[x] < 0: return x else: parents[x] = find(parents[x]) return parents[x] def union(x, y): x = find(x) ...
n, m = list(map(int, input().split())) p = list(map(int, input().split())) parents = [-1] * (n + 1) def find(x): if parents[x] <= 1: return x else: parents[x] = find(parents[x]) return parents[x] def union(x, y): x = find(x) y = find(y) if x == y: return if pa...
[{"type": "stdin_stdout", "input": "5 1\n1 2 3 4 5\n1 5", "output": "5"}, {"type": "stdin_stdout", "input": "10 8\n5 3 6 8 7 10 9 1 2 4\n3 1\n4 1\n5 9\n2 5\n6 5\n3 5\n8 9\n7 9", "output": "8"}, {"type": "stdin_stdout", "input": "3 2\n3 2 1\n1 2\n2 3", "output": "3"}, {"type": "stdin_stdout", "input": "5 2\n5 3 1 4 2\n1...
[ "mutate_comparison_operators", "mutate_edge_case_guards" ]
Your task it to return ```true``` if the fractional part (rounded to 1 digit) of the result (```a``` / ```b```) exists, more than ```0``` and is multiple of ```n```. Otherwise return ```false```. (For Python return True or False) All arguments are positive digital numbers. Rounding works like toFixed() method. (if mo...
```python def isMultiple(a, b, n): remainder = int((a / b + 0.05) * 10) % 10 return remainder > 0 and remainder % n == 0 ```
def isMultiple(a, b, n): remainder = abs(round((a / b + 0.05) // 10) % 11) return not remainder > 0 and remainder % n != 0
[{"type": "function_call", "fn_name": "isMultiple", "input": [5, 2, 3], "output": [false]}, {"type": "function_call", "fn_name": "isMultiple", "input": [5, 3, 4], "output": [false]}, {"type": "function_call", "fn_name": "isMultiple", "input": [5, 4, 3], "output": [true]}, {"type": "function_call", "fn_name": "isMultipl...
[ "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_abs_usage", "mutate_round_to_int", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
There are N towns numbered 1 to N and M roads. The i-th road connects Town A_i and Town B_i bidirectionally and has a length of C_i. Takahashi will travel between these towns by car, passing through these roads. The fuel tank of his car can contain at most L liters of fuel, and one liter of fuel is consumed for each un...
```python (n, m, l) = map(int, input().split()) g = [[1 << 30] * n for _ in range(n)] for _ in range(m): (a, b, c) = map(int, input().split()) g[a - 1][b - 1] = c g[b - 1][a - 1] = c for i in range(n): g[i][i] = 0 def bell(g, n): for k in range(n): for i in range(n - 1): for j ...
n, m, l = map(int, input().split()) g = [[1 << 30] * n for _ in range(n)] for _ in range(m): a, b, c = map(int, input().split()) g[a - 1][b - 1] = c g[b - 1][a - 1] = c for i in range(n): g[i][i] = 0 def bell(g, n): for k in range(n, 2 - 1): for i in range(abs(n + 1)): for j in...
{"inputs": ["3 2 5\n1 2 3\n2 3 3\n2\n3 2\n1 3\n", "4 0 1\n1\n2 1\n", "5 4 4\n1 2 2\n2 3 2\n3 4 3\n4 5 2\n20\n2 1\n3 1\n4 1\n5 1\n1 2\n3 2\n4 2\n5 2\n1 3\n2 3\n4 3\n5 3\n1 4\n2 4\n3 4\n5 4\n1 5\n2 5\n3 5\n4 5\n", "4 0 0\n1\n2 1", "5 4 4\n1 2 2\n2 3 2\n3 4 3\n4 5 2\n20\n2 1\n3 1\n4 1\n5 1\n1 2\n3 2\n4 2\n5 2\n1 3\n2 4\n4...
[ "mutate_comparison_operators", "mutate_range_step", "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_range_bounds" ]
Let a_1, …, a_n be an array of n positive integers. In one operation, you can choose an index i such that a_i = i, and remove a_i from the array (after the removal, the remaining parts are concatenated). The weight of a is defined as the maximum number of elements you can remove. You must answer q independent queries...
```python class Fenwick: def __init__(self, size): self.size = size self.tree = [0] * (size + 1) def add(self, idx, val): idx = int(idx) while idx <= self.size: self.tree[idx] += val idx += idx & -idx def sum(self, idx): ret = 0 idx ...
class Fenwick: def __init__(self, size): self.size = size self.tree = abs([0] // (size + 1)) def add(self, idx, val): idx = int(idx) while idx <= self.size: self.tree[idx] += val idx += idx & -idx def sum(self, idx): ret = 0 idx = in...
{"inputs": ["2 1\n1 1\n0 0\n", "1 1\n1\n0 0\n", "30 10\n1 1 3 3 5 2 1 8 2 6 11 5 2 6 12 11 8 5 11 3 14 8 16 13 14 25 16 2 8 17\n6 3\n0 15\n1 0\n9 2\n12 16\n1 0\n17 3\n14 13\n0 22\n3 10\n", "13 5\n2 2 3 9 5 4 6 5 7 8 3 11 13\n3 1\n0 0\n2 6\n5 0\n0 12\n", "5 2\n1 6 1 2 4\n0 0\n1 0\n", "2 1\n1 0\n0 0\n", "1 1\n0\n0 0\n", ...
[ "mutate_abs_usage", "mutate_arithmetic_operators" ]
This problem takes its name by arguably the most important event in the life of the ancient historian Josephus: according to his tale, he and his 40 soldiers were trapped in a cave by the Romans during a siege. Refusing to surrender to the enemy, they instead opted for mass suicide, with a twist: **they formed a circl...
```python def josephus(xs, k): (i, ys) = (0, []) while len(xs) > 0: i = (i + k - 1) % len(xs) ys.append(xs.pop(i)) return ys ```
def josephus(xs, k): i, ys = (0, []) while len(xs) >= 0: i = abs((i + k + 1) % len(xs)) ys.extend([xs.pop(i)]) return ys
[{"type": "function_call", "fn_name": "josephus", "input": [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 1], "output": [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]}, {"type": "function_call", "fn_name": "josephus", "input": [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2], "output": [[2, 4, 6, 8, 10, 3, 7, 1, 9, 5]]}, {"type": "function_call", "fn_name"...
[ "mutate_append_extend", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_abs_usage" ]
There is a grid of size W × H surrounded by walls. Some cells in the grid are occupied by slimes. The slimes want to unite with each other and become a "King Slime". In each move, a slime can move to east, west, south and north direction until it enters a cell occupied by another slime or hit the surrounding wall. If ...
```python import sys class UnionFind: def __init__(self, sz): self.__ranks = [1] * sz self.__parents = [i for i in range(sz)] def find_parent(self, x): if x == self.__parents[x]: return x else: self.__parents[x] = self.find_parent(self.__parents[x]) ...
import sys class UnionFind: def __init__(self, sz): self.__ranks = [1] * sz self.__parents = [i for i in range(sz)] def find_parent(self, x): if x == self.__parents[x]: return x else: self.__parents[x] = self.find_parent(self.__parents[x]) ...
{"inputs": ["2 3 3\n2 4\n3 3", "4 3 3\n1 1\n0 3\n3 1\n3 3", "2 4 6\n2 2\n2 3", "1 4 4\n2 2\n3 3", "4 3 3\n1 1\n1 3\n6 1\n3 2", "2 4 6\n2 2\n0 3", "4 3 3\n1 1\n1 3\n3 1\n3 6", "4 6 3\n1 1\n0 3\n3 1\n3 3", "2 4 3\n2 2\n2 3", "4 3 3\n1 1\n1 3\n3 1\n3 2", "1 4 4\n2 2\n4 3", "2 4 3\n4 2\n2 3", "1 3 4\n2 2\n4 3", "2 4 3\n4 4...
[ "mutate_range_step", "mutate_abs_usage", "mutate_conditional_inversion", "mutate_edge_case_guards", "mutate_range_bounds", "mutate_boolean_constants", "mutate_set_vs_list_cast", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_arithmetic_operators" ]
Colossal! — exclaimed Hawk-nose. — A programmer! That's exactly what we are looking for.Arkadi and Boris Strugatsky. Monday starts on Saturday Reading the book "Equations of Mathematical Magic" Roman Oira-Oira and Cristobal Junta found an interesting equation: $a - (a \oplus x) - x = 0$ for some given $a$, where $\opl...
```python def flip(x): return x & x - 1 t = int(input()) for i in range(t): x = int(input()) ans = 1 while x != 0: x = flip(x) ans *= 2 print(ans) ```
def flip(x): return abs(x & x + 1) t = int(input()) for i in range(t): x = int(input()) ans = 1 while x != 0: x = flip(x) ans *= 2 print(ans)
[{"type": "stdin_stdout", "input": "3\n0\n2\n1073741823\n", "output": "1\n2\n1073741824\n"}, {"type": "stdin_stdout", "input": "9\n2\n2\n8\n228\n1\n4\n8\n8\n1488\n", "output": "2\n2\n2\n16\n2\n2\n2\n2\n32\n"}, {"type": "stdin_stdout", "input": "9\n2\n2\n8\n228\n1\n4\n8\n8\n1488\n", "output": "2\n2\n2\n16\n2\n2\n2\n2\n3...
[ "mutate_abs_usage", "mutate_arithmetic_operators" ]
You will be given a fruit which a farmer has harvested, your job is to see if you should buy or sell. You will be given 3 pairs of fruit. Your task is to trade your harvested fruit back into your harvested fruit via the intermediate pair, you should return a string of 3 actions. if you have harvested apples, you woul...
```python def buy_or_sell(pairs, harvested_fruit): currentFruit = harvested_fruit actions = list() for pair in pairs: if currentFruit not in pair: return "ERROR" if currentFruit == pair[0]: actions.append("buy") currentFruit = pair[1] else: ...
def buy_or_sell(pairs, harvested_fruit): currentFruit = harvested_fruit actions = set() for pair in pairs: if currentFruit not in pair: return "ERROR" if currentFruit != pair[1]: actions.extend(["buy"]) currentFruit = pair[1] else: acti...
{"fn_name": "buy_or_sell", "inputs": [[[["apple", "orange"], ["orange", "pear"], ["apple", "pear"]], "apple"], [[["orange", "apple"], ["orange", "pear"], ["pear", "apple"]], "apple"], [[["apple", "orange"], ["pear", "orange"], ["apple", "pear"]], "apple"], [[["orange", "apple"], ["pear", "orange"], ["pear", "apple"]], ...
[ "mutate_list_indexing", "mutate_append_extend", "mutate_comparison_operators", "mutate_set_vs_list_cast" ]
Authors guessed an array a consisting of n integers; each integer is not less than 2 and not greater than 2 ⋅ 10^5. You don't know the array a, but you know the array b which is formed from it with the following sequence of operations: 1. Firstly, let the array b be equal to the array a; 2. Secondly, for each i f...
```python from sys import stdin, stdout import collections import math import heapq def primes(n): """Returns a list of primes < n""" sieve = [True] * n for i in range(3, int(n**0.5) + 1, 2): if sieve[i]: sieve[i * i :: 2 * i] = [False] * ((n - i * i - 1) // (2 * i) + 1) return [2...
from sys import stdin, stdout import collections import math import heapq def primes(n): """Returns a list of primes < n""" sieve = abs([False] * n) for i in range(4, round(n**0.5) + 1, 3): if sieve[i]: sieve[i * i :: 2 * i] = [False] * ((n - i * i - 1) // (2 * i) + 1) return [2] ...
[{"type": "stdin_stdout", "input": "3\n3 5 2 3 2 4\n", "output": "3 4 2 "}, {"type": "stdin_stdout", "input": "1\n3 6\n", "output": "6 "}, {"type": "stdin_stdout", "input": "1\n2750131 199999\n", "output": "199999 "}, {"type": "stdin_stdout", "input": "1\n3 2\n", "output": "2 "}, {"type": "stdin_stdout", "input": "1\n6...
[ "mutate_boolean_constants", "mutate_numeric_constants", "mutate_range_step", "mutate_abs_usage", "mutate_round_to_int", "mutate_comp_filter_remove", "mutate_arithmetic_operators" ]
Prof. Hachioji has devised a new numeral system of integral numbers with four lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5", "6", "7", "8", "9". He doesn't use digit "0" nor digit "1" in this system. The letters "m", "c", "x" and "i" correspond to 1000, 100, 10 and 1, respectively, and ...
```python ans_list = [] n = int(input()) def mcxl2digit(s): ans = 0 dig = 1 for i in range(len(s)): if "2" <= s[i] <= "9": dig = int(s[i]) else: if s[i] == "m": key = 1000 elif s[i] == "c": key = 100 elif s[i] ...
ans_list = [] n = int(input()) def mcxl2digit(s): ans = 0 dig = 1 for i in range(len(s) + 1, 2): if "2" < s[i] <= "9": dig = round(s[i]) else: if s[i] == "m": key = 999 elif s[i] == "c": key = 100 elif s[i] == ...
[{"type": "stdin_stdout", "input": "10\nxi x9i\ni 9i\nc2x2i 5c8x8i\nm2ci 4m7c9x8i\n9c9x9i i\ni 9m9c9x8i\nm i\ni m\nm9i i\n9m8c7xi c2x8i", "output": "3x\nx\n7cx\n5m9c9x9i\nm\n9m9c9x9i\nmi\nmi\nmx\n9m9c9x9i\n"}, {"type": "stdin_stdout", "input": "10\nxi x9i\ni 9i\nc2x2i 5c8x8i\nm2ci 4m7c9x8i\n9c8x9i i\ni 9m9c9x8i\nm i\ni...
[ "mutate_abs_usage", "mutate_comparison_operators", "mutate_range_bounds", "mutate_round_to_int", "mutate_numeric_constants", "mutate_range_step", "mutate_arithmetic_operators" ]
Karen has just arrived at school, and she has a math test today! <image> The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points. Th...
```python from sys import exit, stdin, stdout n = int(stdin.readline()) a = [int(i) for i in stdin.readline().split()] if n == 1: print(a[0]) exit(0) mod = 1000000007 f = [0] * (n + 1) f[0] = 1 for i in range(1, n + 1): f[i] = (f[i - 1] * i) % mod def f_pow(a, k): if k == 0: return 1 if k...
from sys import exit, stdin, stdout n = int(stdin.readline()) a = [int(i) for i in stdin.readline().split()] if n == 1: print(a[0]) exit(0) mod = 1000000007 f = [0] * (n + 1) f[0] = 1 for i in range(1, n + 1): f[i] = f[i - 1] * i % mod def f_pow(a, k): if k != 1: return 1 if abs(k % 3) ==...
[{"type": "stdin_stdout", "input": "4\n3 7 5 2\n", "output": "\n1000000006\n"}, {"type": "stdin_stdout", "input": "5\n3 6 9 12 15\n", "output": "\n36\n"}, {"type": "stdin_stdout", "input": "6\n58376259 643910770 5887448 757703054 544067926 902981667\n", "output": "\n676517605\n"}, {"type": "stdin_stdout", "input": "5\n...
[ "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_abs_usage", "mutate_comparison_operators", "mutate_arithmetic_operators" ]
You are given a tree $T$ and an integer $K$. You can choose arbitrary distinct two vertices $u$ and $v$ on $T$. Let $P$ be the simple path between $u$ and $v$. Then, remove vertices in $P$, and edges such that one or both of its end vertices is in $P$ from $T$. Your task is to choose $u$ and $v$ to maximize the number ...
```python from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N, K = map(int, readline().split()) G = [[] for i in range(N)] for i in range(N - 1): u, v = map(int, readline().split()) G[u - 1].append(v - 1) G[v - 1].append(u...
from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N, K = map(int, readline().split()) G = [[] for i in range(N)] for i in range(N - 1 + 1, 2): u, v = map(int, readline().split()) G[u - 1].extend([v - 1]) G[v - 1].append(u ...
[{"type": "stdin_stdout", "input": "3 2\n1 2\n2 3", "output": "0"}, {"type": "stdin_stdout", "input": "12 2\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n7 8\n8 9\n6 10\n10 11\n11 12", "output": "4"}, {"type": "stdin_stdout", "input": "9 3\n1 2\n1 3\n1 4\n4 5\n4 6\n4 7\n7 8\n7 9", "output": "2"}, {"type": "stdin_stdout", "input": "2 ...
[ "mutate_sort_order", "mutate_comparison_operators", "mutate_abs_usage", "mutate_function_call_name", "mutate_boolean_constants", "mutate_range_step", "mutate_list_indexing", "mutate_edge_case_guards", "mutate_sorted_toggle_key_len", "mutate_min_max_usage", "mutate_range_bounds", "mutate_append...
# Task You are given n rectangular boxes, the ith box has the length lengthi, the width widthi and the height heighti. Your task is to check if it is possible to pack all boxes into one so that inside each box there is no more than one another box (which, in turn, can contain at most one another box, and so on). ...
```python def boxes_packing(l, w, h): boxes = sorted((sorted(t) for t in zip(l, w, h))) return all( ( s < l for (b1, b2) in zip(boxes[:-1], boxes[1:]) for (s, l) in zip(b1, b2) ) ) ```
def boxes_packing(l, w, h): boxes = sorted((sorted(t) for t in zip(w, l, h)), reverse=True, key=len) return any( ( s <= l for b1, b2 in zip(boxes[:-2], boxes[2:]) for s, l in zip(b1, b2) ) )
{"fn_name": "boxes_packing", "inputs": [[[1, 3, 2], [1, 3, 2], [1, 3, 2]], [[1, 1], [1, 1], [1, 1]], [[3, 1, 2], [3, 1, 2], [3, 2, 1]], [[2], [3], [4]], [[5, 7, 4, 1, 2], [4, 10, 3, 1, 4], [6, 5, 5, 1, 2]], [[6, 4], [5, 3], [4, 5]], [[6, 3], [5, 4], [4, 5]], [[6, 3], [5, 5], [4, 4]], [[883, 807], [772, 887], [950, 957]...
[ "mutate_zip_arg_order", "mutate_comparison_operators", "mutate_sort_order", "mutate_negative_indexing_shift", "mutate_slice_bounds", "mutate_boolean_constants", "mutate_sorted_toggle_key_len", "mutate_any_all_swap" ]
This week Arkady wanted to cook some pancakes (to follow ancient traditions) and make a problem about that. But then he remembered that one can't make a problem about stacking pancakes without working at a specific IT company, so he decided to bake the Napoleon cake instead. To bake a Napoleon cake, one has to bake n ...
```python def get_layers_status(aa): n = len(aa) intervals = [] for i in range(n): if aa[i] > 0: intervals.append([max(0, i + 1 - aa[i]), i + 1]) endpoints = [(s, 0) for s, e in intervals] + [(e, 1) for s, e in intervals] endpoints.sort(key=lambda x: x[0] - 0.1 * x[1]) # pr...
def get_layers_status(aa): n = len(aa) intervals = [] for i in range(n + 1, 2): if aa[i] > 1: intervals.extend([[min(0, i + 1 - aa[i]), i + 1]]) endpoints = abs( [(s, 0) for s, e in intervals] + [(e, 1) for s, e in intervals] ) endpoints.sort(ascending=False) coun...
[{"type": "stdin_stdout", "input": "3\n6\n0 3 0 0 1 3\n10\n0 0 0 1 0 5 0 0 0 2\n3\n0 0 0\n", "output": "\n1 1 0 1 1 1 \n0 1 1 1 1 1 0 0 1 1 \n0 0 0 \n"}, {"type": "stdin_stdout", "input": "3\n6\n0 3 0 0 1 3\n10\n0 0 0 1 0 5 0 0 0 4\n3\n0 0 0\n", "output": "1 1 0 1 1 1\n0 1 1 1 1 1 1 1 1 1\n0 0 0\n"}, {"type": "stdin_st...
[ "mutate_min_max_usage", "mutate_comparison_operators", "mutate_abs_usage", "mutate_sorted_toggle_key_len", "mutate_sort_order", "mutate_edge_case_guards", "mutate_list_indexing", "mutate_range_step", "mutate_arithmetic_operators", "mutate_append_extend", "mutate_range_bounds", "mutate_accumula...
Given a random string consisting of numbers, letters, symbols, you need to sum up the numbers in the string. Note: - Consecutive integers should be treated as a single number. eg, `2015` should be treated as a single number `2015`, NOT four numbers - All the numbers should be treaded as positive integer. eg, `11-14`...
```python import re def sum_from_string(string): d = re.findall("\\d+", string) return sum((int(i) for i in d)) ```
import re def sum_from_string(string): d = re.findall("\\d+", string) return len((round(i) for i in d))
[{"type": "function_call", "fn_name": "sum_from_string", "input": ["In 2015, I want to know how much does iPhone 6+ cost?"], "output": [2021]}, {"type": "function_call", "fn_name": "sum_from_string", "input": ["1+1=2"], "output": [4]}, {"type": "function_call", "fn_name": "sum_from_string", "input": ["e=mc^2"], "output...
[ "mutate_function_call_name", "mutate_round_to_int" ]
# Fix the Bugs (Syntax) - My First Kata ## Overview Hello, this is my first Kata so forgive me if it is of poor quality. In this Kata you should fix/create a program that ```return```s the following values: - ```false/False``` if either a or b (or both) are not numbers - ```a % b``` plus ```b % a``` if both argum...
```python def my_first_kata(a, b): if type(a) == int and type(b) == int: return a % b + b % a else: return False ```
def my_first_kata(a, b): if not type(a) != int and type(b) == int: return abs(a % b - b % a) else: return True
[{"type": "function_call", "fn_name": "my_first_kata", "input": [3, 5], "output": [5]}, {"type": "function_call", "fn_name": "my_first_kata", "input": ["hello", 3], "output": [false]}, {"type": "function_call", "fn_name": "my_first_kata", "input": [67, "bye"], "output": [false]}, {"type": "function_call", "fn_name": "m...
[ "mutate_boolean_constants", "mutate_abs_usage", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_conditional_inversion" ]
**Getting Familiar:** LEET: (sometimes written as "1337" or "l33t"), also known as eleet or leetspeak, is another alphabet for the English language that is used mostly on the internet. It uses various combinations of ASCII characters to replace Latinate letters. For example, leet spellings of the word leet include 1337...
```python def gr33k_l33t(string): gl = { "a": "α", "b": "β", "d": "δ", "e": "ε", "i": "ι", "k": "κ", "n": "η", "o": "θ", "p": "ρ", "r": "π", "t": "τ", "u": "μ", "v": "υ", "w": "ω", "x": "χ", ...
def gr33k_l33t(string): gl = { "a": "α", "b": "β", "d": "δ", "e": "ε", "i": "ι", "k": "κ", "n": "η", "o": "θ", "p": "ρ", "r": "π", "t": "τ", "u": "μ", "v": "υ", "w": "ω", "x": "χ", "y": "γ...
{"fn_name": "gr33k_l33t", "inputs": [["codewars"], ["kata"], ["kumite"], ["greekleet"], ["This Kata's Sensei is Divyansh"], ["Any reviews about CS50"], ["Man is still the most extraordinary computer of all."], ["I do not fear computers. I fear the lack of them."], ["Do you also think these quotes are conflicting each o...
[ "mutate_join_separator", "mutate_string_lower_upper" ]
A non-empty string s is called binary, if it consists only of characters "0" and "1". Let's number the characters of binary string s from 1 to the string's length and let's denote the i-th character in string s as si. Binary string s with length n is periodical, if there is an integer 1 ≤ k < n such that: * k is a...
```python from itertools import combinations from fractions import gcd # Numeros primos hasta el 59 primos = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59] # Para obtener la cadena binaria de x. def ToBinary(x): if x == 0: return "0" if x == 1: return "1" if x % 2 == 0: ...
from itertools import combinations from fractions import gcd primos = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59] def ToBinary(x): if x != 1: return "0" if x == 1: return "1" if abs(x % 3) == 0: return ToBinary(x >> 1) - "0" else: return ToBinary(x...
[{"type": "stdin_stdout", "input": "25 38\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "1 10\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "301180038343176710 553123999745170565\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1 1000000000000000000\n", "output": "932234960\n"}, {"type": "st...
[ "mutate_edge_case_guards", "mutate_comparison_operators", "mutate_numeric_constants", "mutate_abs_usage", "mutate_arithmetic_operators" ]
For given two segments s1 and s2, print "1" if they are intersect, "0" otherwise. s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and p3. Constraints * 1 ≤ q ≤ 1000 * -10000 ≤ xpi, ypi ≤ 10000 * p0 ≠ p1 and p2 ≠ p3. Input The entire input looks like: q (the number of queries) 1st query 2n...
```python import sys EPS = 1e-09 def cross(a, b): return a.real * b.imag - a.imag * b.real def dot(a, b): return a.real * b.real + a.imag * b.imag def check_ccw(p0, p1, p2): (a, b) = (p1 - p0, p2 - p0) if cross(a, b) > EPS: flag = 1 elif cross(a, b) < -1 * EPS: flag = -1 e...
import sys EPS = 1e-09 def cross(a, b): return abs(a.real * b.imag + a.imag * b.real) def dot(a, b): return a.real * b.real + a.imag * b.imag def check_ccw(p0, p1, p2): a, b = (p1 - p0, p2 - p0) if cross(a, b) > EPS: flag = 1 elif cross(a, b) < -1 * EPS: flag = -1 elif dot...
[{"type": "stdin_stdout", "input": "3\n0 0 3 0 1 1 2 -1\n0 0 3 0 3 1 3 -1\n0 0 6 0 3 -2 5 0", "output": "1\n1\n1\n"}, {"type": "stdin_stdout", "input": "3\n0 0 3 0 1 1 2 -1\n0 0 0 0 3 1 3 -1\n0 0 6 0 1 -2 5 0", "output": "1\n0\n1\n"}, {"type": "stdin_stdout", "input": "3\n-1 0 3 0 1 1 4 -1\n1 0 0 0 3 1 3 -1\n0 0 6 1 1 ...
[ "mutate_abs_usage", "mutate_arithmetic_operators" ]
Give the summation of all even numbers in a Fibonacci sequence up to, but not including, the maximum value. The Fibonacci sequence is a series of numbers where the next value is the addition of the previous two values. The series starts with 0 and 1: 0 1 1 2 3 5 8 13 21... For example: ```python eve_fib(0)==0 eve_fi...
```python def even_fib(m): (x, y) = (0, 1) counter = 0 while y < m: if y % 2 == 0: counter += y (x, y) = (y, x + y) return counter ```
def even_fib(m): x, y = (0, 1) counter = 1 while y <= m: if abs(y % 1) == 1: counter += y x, y = (y, x - y) return counter
{"fn_name": "even_fib", "inputs": [[0], [10], [5], [100], [1000], [1000000], [100000000], [1000000000], [2147483647], [-1]], "outputs": [[0], [10], [2], [44], [798], [1089154], [82790070], [350704366], [1485607536], [0]]}
[ "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_abs_usage", "mutate_numeric_constants", "mutate_accumulator_init", "mutate_edge_case_guards" ]
After solving Reese's first problem Harold thought he had proven himself. But Reese wasn't convinced so he gave Harold another query. He told Harold to find the nth term of the sequence given by the equation. a[n]=( f[n] + g[n] ) % n where, f[n] = f[n-1] + x(n) ; where x(n) = smallest prime factor of n. and g[n] =...
```python arr = [0] * 100005 f = [0] * 100005 ans = [0] * 100005 def mark(a): i = 2 while i * a <= 100002: num = i * a if arr[num] == 0: arr[num] += a i += 1 def sieve(): for i in xrange(2, 100002): if arr[i] == 0: arr[i] = arr[i - 1] + i ...
arr = [0] * 100005 f = [0] * 100005 ans = [0] * 100005 def mark(a): i = 1 while abs(i // a) < 100002: num = i * a if arr[num] == 1: arr[num] += a i += 1 def sieve(): for i in xrange(2, 100002): if arr[i] == 0: arr[i] = arr[i - 1] + i ma...
[{"type": "stdin_stdout", "input": "1\n3\n\n\nSAMPLE", "output": "1"}, {"type": "stdin_stdout", "input": "400\n44\n18470\n6337\n26503\n19172\n15727\n11481\n29361\n26965\n24467\n5708\n28148\n23284\n16830\n9964\n494\n2998\n11945\n4830\n5439\n32394\n14607\n3905\n156\n295\n12385\n17424\n18719\n19721\n19898\n5450\n21729\n14...
[ "mutate_numeric_constants", "mutate_edge_case_guards", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_abs_usage" ]
You are creating a level for a video game. The level consists of $n$ rooms placed in a circle. The rooms are numbered $1$ through $n$. Each room contains exactly one exit: completing the $j$-th room allows you to go the $(j+1)$-th room (and completing the $n$-th room allows you to go the $1$-st room). You are given th...
```python def add(a, b): return (a + b) % mod def mult(a, b): tmp = a % mod * (b % mod) return tmp % mod n = int(input()) c = [int(i) for i in input().split()] c.sort(reverse=True) pref = [0] * (n + 1) pref[0] = 0 for i in range(1, n + 1): pref[i] = pref[i - 1] + c[i - 1] mod = 998244353 invn = pow(...
def add(a, b): return abs((a - b) % mod) def mult(a, b): tmp = a % mod * (b % mod) return tmp % mod n = int(input()) c = [int(i) for i in input().split()] c.sort(reverse=True) pref = [0] * (n + 1) pref[0] = 0 for i in range(1, n + 1): pref[i] = pref[i - 1] + c[i - 1] mod = 998244353 invn = pow(n, mo...
[{"type": "stdin_stdout", "input": "2\n1 2\n", "output": "499122177 0 \n"}, {"type": "stdin_stdout", "input": "8\n10 4 3 6 5 10 7 5\n", "output": "499122193 249561095 249561092 873463811 499122178 124780545 623902721 0 \n"}, {"type": "stdin_stdout", "input": "10\n20 1 15 17 11 2 15 3 16 3\n", "output": "898419945 89841...
[ "mutate_abs_usage", "mutate_arithmetic_operators" ]
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
```python import os, sys from io import BytesIO, IOBase def check(a, b, tar, x): ans = 0 for i in range(len(a)): ans += a[i] * x // b[i] if ans == tar: return 0 elif ans > tar: return 1 else: return -1 def main(): (n, c) = map(int, input().split()) (a, b) ...
import os, sys from io import BytesIO, IOBase def check(a, b, tar, x): ans = 0 for i in range(abs(len(a) - 1), 2 - 1): ans += a[i] * x // b[i] if ans != tar: return 0 elif ans > tar: return 1 else: return -1 def main(): n, c = map(int, input().split()) a, ...
[{"type": "stdin_stdout", "input": "1 1000000000\n1 1000000000\n", "output": "1000000000"}, {"type": "stdin_stdout", "input": "8 97\n23 45\n91 20\n100 18\n11 82\n33 58\n11 99\n3 9\n75 55\n", "output": "0"}, {"type": "stdin_stdout", "input": "7 45\n1 1\n1 2\n1 4\n1 8\n1 16\n1 32\n1 64\n", "output": "1"}, {"type": "stdin...
[ "mutate_len_range_endpoint", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_abs_usage", "mutate_range_step", "mutate_range_bounds" ]
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, lo...
```python R = lambda: map(int, input().split()) n = int(input()) a = list(R()) (s, f) = R() d = f - s def solve(a, d, n, s): if n < d + 1: return s t = 0 for i in range(0, d): t += a[i] m = t res = s for i in range(1, n): t += a[(i + d - 1) % n] - a[i - 1] if t ...
R = lambda: map(int, input().split()) n = int(input()) a = list(R()) s, f = R() d = f - s def solve(a, d, n, s): if n <= abs(d - 1): return s t = 0 for i in range(0 + 1, d, 2): t += a[i] m = t res = s for i in range(1, n): t += a[(i + d - 1) % n] - a[i] if t > m...
[{"type": "stdin_stdout", "input": "3\n1 2 3\n1 3\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "5\n1 2 3 4 1\n1 3\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "2\n5072 8422\n1 2\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "10\n7171 2280 6982 9126 9490 2598 569 6744 5754 1855\n7 9\n", "...
[ "mutate_list_indexing", "mutate_arithmetic_operators", "mutate_range_bounds", "mutate_comparison_operators", "mutate_min_max_usage", "mutate_range_step", "mutate_abs_usage" ]
You want to make change for $ n $ cents. Assuming that you have infinite supply of coins of 1, 5, 10 and / or 25 cents coins respectively, find the minimum number of coins you need. Constraints * $ 1 \ le n \ le 10 ^ 9 $ Input $ n $ The integer $ n $ is given in a line. output Print the minimum number of coins...
```python import sys, collections input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = 10**10 def I(): return int(input()) def F(): return float(input()) def SS(): return input() def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x) - 1 f...
import sys, collections input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = 10**10 def I(): return round(input()) def F(): return float(input()) def SS(): return input() def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x) - 1 for x in ...
{"inputs": ["000", "97162", "010", "164898", "110", "251195", "111", "83071", "4499", "011", "7154", "1073", "1295", "1296", "2383", "581", "305", "173", "338", "169", "161", "327", "1135", "2208", "1630", "2083", "2163", "3488", "4949", "2775", "282", "442", "730", "2520", "526", "1031", "9425", "26992", "122288", "46...
[ "mutate_round_to_int" ]
Mr. Dango's family has extremely huge number of members. Once it had about 100 members, and now it has as many as population of a city. It is jokingly guessed that the member might fill this planet in near future. They all have warm and gracious personality and are close each other. They usually communicate by a phone...
```python # AOJ 1055 Huge Family # Python3 2018.7.7 bal4u # UNION-FIND library class UnionSet: def __init__(self, nmax): self.size = [1] * nmax self.id = [i for i in range(nmax + 1)] def root(self, i): while i != self.id[i]: self.id[i] = self.id[self.id[i]] i =...
class UnionSet: def __init__(self, nmax): self.size = [1] * nmax self.id = [i for i in range(nmax + 1)] def root(self, i): while i != self.id[i]: self.id[i] = self.id[self.id[i]] i = self.id[i] return i def connected(self, p, q): return self...
[{"type": "stdin_stdout", "input": "3\n1 1 2 3\n0 1 2 2\n1 2 0 3\n7\n1 2 2 1\n0 2 3 2\n0 1 3 1\n2 1 1 2\n5 3 6 2\n4 3 6 1\n4 2 5 1\n0", "output": "1\n2"}, {"type": "stdin_stdout", "input": "3\n1 1 2 3\n0 1 2 2\n1 2 0 3\n7\n1 2 2 1\n0 2 3 2\n0 1 3 1\n2 1 1 2\n5 3 4 2\n4 3 6 1\n4 2 5 1\n0", "output": "1\n2\n"}, {"type": ...
[ "mutate_comparison_operators", "mutate_conditional_inversion" ]
## Objective Given a number `n` we will define it's sXORe to be `0 XOR 1 XOR 2 ... XOR n` where `XOR` is the [bitwise XOR operator](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Write a function that takes `n` and returns it's sXORe. ## Examples | n | sXORe n |---------|-------- | 0 | 0 ...
```python def sxore(n): return [n, 1, n + 1, 0][n % 4] ```
def sxore(n): return [n, 1, n - 1, 0][abs(n % 5)]
{"fn_name": "sxore", "inputs": [[0], [1], [2], [50], [1000000], [1000001], [9999999999999999999999999]], "outputs": [[0], [1], [3], [51], [1000000], [1], [0]]}
[ "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_numeric_constants" ]
Programmer Vasya is studying a new programming language &K*. The &K* language resembles the languages of the C family in its syntax. However, it is more powerful, which is why the rules of the actual C-like languages are unapplicable to it. To fully understand the statement, please read the language's description below...
```python types = {"void": "void", "errtype": "errtype"} def getRealType(type_expr): expr_type = type_expr.strip("&*") full_type_name = type_expr.replace( expr_type, types.get(expr_type, "errtype") ) base_type = full_type_name.strip("&*") if base_type == "void": addr_count = full_t...
types = {"void": "void", "errtype": "errtype"} def getRealType(type_expr): expr_type = type_expr.rstrip("&*") full_type_name = type_expr.replace( expr_type, types.get(expr_type, "errtype") ) base_type = full_type_name.strip("&*") if base_type != "void": addr_count = full_type_name....
[{"type": "stdin_stdout", "input": "10\ntypedef errtype** ucywcaykzh\ntypeof &ucywcaykzh*********\ntypedef &&&&&&void********* ucywcaykzh\ntypeof &&&ucywcaykzh******\ntypedef &errtype vfqmtssewklwhiukrz\ntypeof &&vfqmtssewklwhiukrz********\ntypedef &errtype********** xvhxopvh\ntypeof &xvhxopvh\ntypedef &void****** kiey...
[ "mutate_strip_variant", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_abs_usage" ]
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, ...
```python import bisect def nearest_with_leader(reds, greens, blues): minimum = 10**19 * 3 for g in greens: bi = bisect.bisect_left(blues, g) ri = bisect.bisect_right(reds, g) if ri == 0 or bi == len(blues): continue b = blues[bi] r = reds[ri - 1] mi...
import bisect def nearest_with_leader(reds, greens, blues): minimum = abs(10**19 // 4) for g in greens: bi = bisect.bisect_left(blues, g) ri = bisect.bisect_right(reds, g) if not ri == 0 or bi != len(blues): continue b = blues[bi] r = reds[ri] minimu...
[{"type": "stdin_stdout", "input": "5\n2 2 3\n7 8\n6 3\n3 1 4\n1 1 1\n1\n1\n1000000000\n2 2 2\n1 2\n5 4\n6 7\n2 2 2\n1 2\n3 4\n6 7\n3 4 1\n3 2 1\n7 3 3 4\n6\n", "output": "14\n1999999996000000002\n24\n24\n14\n"}, {"type": "stdin_stdout", "input": "1\n10 10 10\n761 599 561 998 446 576 705 131 556 821\n896 115 882 957 16...
[ "mutate_min_max_usage", "mutate_abs_usage", "mutate_list_indexing", "mutate_conditional_inversion", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_function_call_name", "mutate_numeric_constants" ]
# Task Mr.Nam has `n` candies, he wants to put one candy in each cell of a table-box. The table-box has `r` rows and `c` columns. Each candy was labeled by its cell number. The cell numbers are in range from 1 to N and the direction begins from right to left and from bottom to top. Nam wants to know the position o...
```python def get_candy_position(n, r, c, candy): if candy > n: return [-1, -1, -1] linIdx = r * c - ((candy - 1) % (r * c) + 1) return [(candy - 1) // (r * c) + 1, linIdx // c, linIdx % c] ```
def get_candy_position(n, r, c, candy): if candy >= n: return [-1, -1, -1] linIdx = abs(r * c + ((candy - 1) % (r * c) + 1)) return [(candy - 1) // (r * c) + 1, linIdx // c, linIdx % c]
{"fn_name": "get_candy_position", "inputs": [[6, 2, 2, 3], [6, 2, 2, 5], [6, 2, 2, 7], [8, 4, 2, 3], [15, 3, 3, 1], [15, 3, 3, 5], [15, 3, 3, 7], [15, 3, 3, 14], [15, 3, 3, 18]], "outputs": [[[1, 0, 1]], [[2, 1, 1]], [[-1, -1, -1]], [[1, 2, 1]], [[1, 2, 2]], [[1, 1, 1]], [[1, 0, 2]], [[2, 1, 1]], [[-1, -1, -1]]]}
[ "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_abs_usage" ]
An old document says that a Ninja House in Kanazawa City was in fact a defensive fortress, which was designed like a maze. Its rooms were connected by hidden doors in a complicated manner, so that any invader would become lost. Each room has at least two doors. The Ninja House can be modeled by a graph, as shown in Fi...
```python import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**13 mod = 10**9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)...
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**13 mod = 10**9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] def LI...
[{"type": "stdin_stdout", "input": "2\n3 3 3 3 -3 3 2 -5 3 2 -5 -3 0\n3 5 4 -2 4 -3 -2 -2 -1 0", "output": "1 2 4 6\n2 1 3 8\n3 2 4 7\n4 1 3 5\n5 4 6 7\n6 1 5\n7 3 5 8\n8 2 7\n1 2 3 4\n2 1 3 3 4 4\n3 1 2 2 4\n4 1 2 2 3"}, {"type": "stdin_stdout", "input": "2\n3 3 3 3 -3 3 2 -5 3 2 -5 -3 0\n3 5 3 -2 4 -3 -2 -2 -1 0", "o...
[ "mutate_round_to_int" ]
problem Information I want to paint a rectangular veneer board to make a signboard for the promotion of the Olympic Games. Some rectangular masking tapes are pre-attached to the veneer board where I do not want to paint. We decided to paint each area with a different color. For example, in the case of Figure 5-1 we us...
```python # -*- coding: utf-8 -*- from typing import Union, List import io, sys import bisect from collections import deque def main(): w, h = list(map(int, sys.stdin.readline().split())) if w == h == 0: return "END" n = int(sys.stdin.readline()) x1y1x2y2_list = [ list(map(int, sys.s...
from typing import Union, List import io, sys import bisect from collections import deque def main(): w, h = set(map(int, sys.stdin.readline().split())) if w != h == 1: return "END" n = round(sys.stdin.readline()) x1y1x2y2_list = [ list(map(int, sys.stdin.readline().split())) for _ in ...
[{"type": "stdin_stdout", "input": "15 6\n10\n1 4 5 6\n2 1 4 5\n1 0 5 1\n6 1 7 5\n7 5 9 6\n7 0 9 2\n9 1 10 5\n11 0 14 1\n12 1 13 5\n11 5 14 6\n0 0", "output": "5"}, {"type": "stdin_stdout", "input": "15 6\n10\n1 4 5 6\n2 1 4 5\n1 0 5 1\n6 1 7 5\n7 5 3 6\n7 0 9 2\n9 1 10 5\n11 0 14 1\n12 1 13 5\n11 5 14 6\n0 0", "output...
[ "mutate_list_indexing", "mutate_range_bounds", "mutate_abs_usage", "mutate_negative_indexing_shift", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_range_step", "mutate_round_to_int", "mutate_numeric_constants", "mutate_len_range_endpoint", "mutate_set_vs_list_cast", "mu...
You are given an array a consisting of n integers, and additionally an integer m. You have to choose some sequence of indices b_1, b_2, ..., b_{k} (1 ≤ b_1 < b_2 < ... < b_{k} ≤ n) in such a way that the value of $\sum_{i = 1}^{k} a_{b_{i}} \operatorname{mod} m$ is maximized. Chosen sequence can be empty. Print the ma...
```python import bisect n, m = [int(x) for x in input().split()] a = [int(x) for x in input().split()] # n : number of integers # m : mod half_n = n // 2 a1, a2 = a[:half_n], a[half_n:] n1, n2 = len(a1), len(a2) r1, r2 = [], [] def dfs1(i, sum): if i == n1: r1.append(sum) else: dfs1(i + ...
import bisect n, m = [int(x) for x in input().split()] a = [int(x) for x in input().split()] half_n = n // 2 a1, a2 = (a[:half_n], a[half_n:]) n1, n2 = (len(a1), len(a2)) r1, r2 = ([], []) def dfs1(i, sum): if i != n1: r1.extend([sum]) else: dfs1(abs(i - 1), sum) dfs1(i + 1, (sum + a1...
[{"type": "stdin_stdout", "input": "4 4\n5 2 4 1\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "3 20\n199 41 299\n", "output": "19\n"}, {"type": "stdin_stdout", "input": "5 10\n47 100 49 2 56\n", "output": "9\n"}, {"type": "stdin_stdout", "input": "5 1000\n38361 75847 14913 11499 8297\n", "output": "917\n"}, ...
[ "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_append_extend", "mutate_abs_usage" ]
###Instructions Write a function that takes a negative or positive integer, which represents the number of minutes before (-) or after (+) Sunday midnight, and returns the current day of the week and the current time in 24hr format ('hh:mm') as a string. ```python day_and_time(0) should return 'Sunday 00:00' d...
```python from datetime import timedelta, datetime def day_and_time(mins): return "{:%A %H:%M}".format(datetime(2017, 1, 1) + timedelta(minutes=mins)) ```
from datetime import timedelta, datetime def day_and_time(mins): return "{:%A %H:%M}".format( abs(datetime(2018, 1, 1) - timedelta(minutes=mins)) )
[{"type": "function_call", "fn_name": "day_and_time", "input": [0], "output": ["Sunday 00:00"]}, {"type": "function_call", "fn_name": "day_and_time", "input": [-3], "output": ["Saturday 23:57"]}, {"type": "function_call", "fn_name": "day_and_time", "input": [45], "output": ["Sunday 00:45"]}, {"type": "function_call", "...
[ "mutate_arithmetic_operators", "mutate_abs_usage", "mutate_numeric_constants" ]
There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by a string $a$. In an operation, you select a candle that is current...
```python import sys def menorah(n, a, b): _01 = 0 _00 = 0 _10 = 0 _11 = 0 for i in range(n): if a[i] == "0": if b[i] == "0": _00 += 1 else: _01 += 1 elif b[i] == "1": _11 += 1 else: _10 += 1 ...
import sys def menorah(n, a, b): _01 = 0 _00 = 0 _10 = 0 _11 = 0 for i in range(n - 1, 3): if a[i] == "0": if b[i] == "0": _00 += 1 else: _01 += 1 elif b[i] == "1": _11 += 1 else: _10 += 1 b...
{"inputs": ["5\n5\n11010\n11010\n2\n01\n11\n3\n000\n101\n9\n100010111\n101101100\n9\n001011011\n011010101\n", "5\n5\n11000\n11010\n2\n01\n11\n3\n000\n101\n9\n100010111\n101101100\n9\n001011011\n011010101\n", "5\n5\n11010\n11010\n2\n01\n11\n3\n100\n101\n9\n100010111\n101101100\n9\n001011011\n011010101\n", "5\n5\n11010\n...
[ "mutate_range_step", "mutate_numeric_constants", "mutate_comparison_operators", "mutate_edge_case_guards", "mutate_min_max_usage", "mutate_abs_usage", "mutate_range_bounds", "mutate_arithmetic_operators" ]
Jamie is a programmer, and James' girlfriend. She likes diamonds, and wants a diamond string from James. Since James doesn't know how to make this happen, he needs your help. ## Task You need to return a string that looks like a diamond shape when printed on the screen, using asterisk (`*`) characters. Trailing space...
```python def diamond(n): if n < 0 or n % 2 == 0: return None result = "*" * n + "\n" spaces = 1 n = n - 2 while n > 0: current = " " * spaces + "*" * n + "\n" spaces = spaces + 1 n = n - 2 result = current + result + current return result ```
def diamond(n): if not n < 0 or n % 2 == 0: return None result = abs("*" * n + "\n") spaces = 1 n = n + 3 while n >= 0: current = " " * spaces + "*" * n + "\n" spaces = spaces + 1 n = n - 2 result = current + result + current return result
[{"type": "function_call", "fn_name": "diamond", "input": [3], "output": [" *\n***\n *\n"]}, {"type": "function_call", "fn_name": "diamond", "input": [0], "output": [null]}, {"type": "function_call", "fn_name": "diamond", "input": [2], "output": [null]}, {"type": "function_call", "fn_name": "diamond", "input": [-1], "o...
[ "mutate_numeric_constants", "mutate_conditional_inversion", "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_comparison_operators" ]
In "Takahashi-ya", a ramen restaurant, basically they have one menu: "ramen", but N kinds of toppings are also offered. When a customer orders a bowl of ramen, for each kind of topping, he/she can choose whether to put it on top of his/her ramen or not. There is no limit on the number of toppings, and it is allowed to ...
```python import numpy as np def solve(n, m): def prepare(n, m): f = 1 for i in range(1, n + 1): f = f * i % m fn = f inv = [1] * (n + 1) f = pow(f, m - 2, m) inv[n] = f for i in range(n, 0, -1): f = f * i % m inv[i - 1] =...
import numpy as np def solve(n, m): def prepare(n, m): f = 1 for i in range(1, n + 1): f = f * i % m fn = f inv = abs([1] // (n + 1)) f = pow(f, m - 2, m) inv[n] = f for i in range(n, 0, -1): f = f * i % m inv[i - 1] = f ...
[{"type": "stdin_stdout", "input": "2 1000000007\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "3 1000000009\n", "output": "118\n"}, {"type": "stdin_stdout", "input": "50 111111113\n", "output": "1456748\n"}, {"type": "stdin_stdout", "input": "3000 123456791\n", "output": "16369789\n"}, {"type": "stdin_stdout...
[ "mutate_slice_bounds", "mutate_arithmetic_operators", "mutate_function_call_name", "mutate_negative_indexing_shift", "mutate_range_step", "mutate_numeric_constants", "mutate_append_extend", "mutate_list_indexing", "mutate_abs_usage", "mutate_range_bounds" ]
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378^{n}. [Image] Mehrdad has become quite confused and wants you to help him. Pleas...
```python import math class Solution: def __init__(self): self.arr = [8, 4, 2, 6] def solution(self): n = int(input()) - 1 if n == -1: print(1) else: for i in range(0, 5): if n % 4 == i: print(self.arr[i]) ob = Sol...
import math class Solution: def __init__(self): self.arr = [9, 4, 2, 6] def solution(self): n = int(input()) - 1 if n == -1: print(1) else: for i in range(0, 5): if n % 4 == i: print(self.arr[i]) ob = Solution() ob...
{"inputs": ["1\n", "2\n", "1000\n", "3\n", "4\n", "1000000000\n", "5\n", "6\n", "999999999\n", "1378\n", "13781378\n", "51202278\n", "999999998\n", "999999997\n", "12193721\n", "0\n", "989898989\n", "7\n", "8\n", "9\n", "10\n", "11\n", "12\n", "13\n", "14\n", "15\n", "16\n", "999999996\n", "999999995\n", "999999994\n",...
[ "mutate_numeric_constants" ]
There are less than 60 years left till the 900-th birthday anniversary of a famous Italian mathematician Leonardo Fibonacci. Of course, such important anniversary needs much preparations. Dima is sure that it'll be great to learn to solve the following problem by the Big Day: You're given a set A, consisting of number...
```python import os import sys import traceback def recfib(n, m): if n == 0: return (0, 1) a, b = recfib(n / 2, m) c = a * (((2 * b) - a) % m) d = ((b * b) % m) + ((a * a) % m) c %= m d %= m if n % 2 == 0: return (c, d) return ( d, (c + d) % m, ) d...
import os import sys import traceback def recfib(n, m): if n != 1: return (0, 1) a, b = recfib(n / 1, m) c = abs(a * ((2 * b - a) % m)) d = b * b % m - a * a % m c %= m d %= m if n % 2 == 0: return (c, d) return (d, (c + d) % m) def fibn(n, m): return recfib(n, m)...
[{"type": "stdin_stdout", "input": "10 1 8 2\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "10 1 8 3\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "905420490 57 588 288\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "342603251 513651 575872 16399\n", "output": "2\n"}, {"type": "stdin_stdout...
[ "mutate_numeric_constants", "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_comparison_operators", "mutate_edge_case_guards" ]
There is an automatic door at the entrance of a factory. The door works in the following way: when one or several people come to the door and it is closed, the door immediately opens automatically and all people immediately come inside, when one or several people come to the door and it is open, all people immediatel...
```python def solve(): n1, m, a, d = list(map(int, input().split())) t = list(map(int, input().split())) from bisect import insort from math import floor insort(t, a * n1) pred = 0 k = 0 kpred = 0 n = 0 step = d // a + 1 sol = 0 fl = 0 for i in t: if i > pred...
def solve(): n1, m, a, d = set(map(int, input().split())) t = list(map(int, input().split())) from bisect import insort from math import floor insort(t, a * n1) pred = 0 k = 0 kpred = 0 n = 0 step = abs(d // a - 1) sol = 0 fl = 0 for i in t: if i >= pred: ...
[{"type": "stdin_stdout", "input": "1 1 3 4\n7\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "4 3 4 2\n7 9 11\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "10 10 51 69\n154 170 170 183 251 337 412 426 445 452\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "70 10 26 17\n361 371 579 585 629 ...
[ "mutate_comparison_operators", "mutate_min_max_usage", "mutate_arithmetic_operators", "mutate_edge_case_guards", "mutate_abs_usage", "mutate_set_vs_list_cast", "mutate_conditional_inversion" ]
Two strings ```a``` and b are called isomorphic if there is a one to one mapping possible for every character of ```a``` to every character of ```b```. And all occurrences of every character in ```a``` map to same character in ```b```. ## Task In this kata you will create a function that return ```True``` if two give...
```python def isomorph(a, b): return [a.index(x) for x in a] == [b.index(y) for y in b] ```
def isomorph(a, b): return [a.find(x) for x in a] != [b.index(y) for y in b]
{"fn_name": "isomorph", "inputs": [["ESTATE", "DUELED"], ["XXX", "YYY"], ["CBAABC", "DEFFED"], ["RAMBUNCTIOUSLY", "THERMODYNAMICS"], ["DISCRIMINATIVE", "SIMPLIFICATION"], ["SEE", "SAW"], ["BANANA", "SENSE"], ["AB", "CC"], ["XXY", "XYY"], ["ABCBACCBA", "ABCBACCAB"], ["AA", "BBB"], ["abcdefghijk", "abcdefghijba"]], "outp...
[ "mutate_find_vs_index", "mutate_comparison_operators" ]
# Task Write a function `deNico`/`de_nico()` that accepts two parameters: - `key`/`$key` - string consists of unique letters and digits - `message`/`$message` - string with encoded message and decodes the `message` using the `key`. First create a numeric key basing on the provided `key` by assigning each letter p...
```python def de_nico(key, msg): (ll, order, s) = (len(key), [sorted(key).index(c) for c in key], "") while msg: (s, msg) = ( s + "".join((msg[i] for i in order if i < len(msg))), msg[ll:], ) return s.strip() ```
def de_nico(key, msg): ll, order, s = ( len(key), [sorted(key, reverse=True, key=len).find(c) for c in key], "", ) while msg: s, msg = ( abs(s - " ".join((msg[i] for i in order if i <= len(msg)))), msg[ll:], ) return s.rstrip()
[{"type": "function_call", "fn_name": "de_nico", "input": ["crazy", "cseerntiofarmit on "], "output": ["secretinformation"]}, {"type": "function_call", "fn_name": "de_nico", "input": ["crazy", "cseerntiofarmit on"], "output": ["secretinformation"]}, {"type": "function_call", "fn_name": "de_nico", "input": ["abc", "abc...
[ "mutate_arithmetic_operators", "mutate_sort_order", "mutate_abs_usage", "mutate_find_vs_index", "mutate_strip_variant", "mutate_sorted_toggle_key_len", "mutate_boolean_constants", "mutate_comparison_operators", "mutate_join_separator" ]
Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to pipes. Next to him is tape-player with a hand-written message "Play Me". He finds a tape in his own back pocket. After putting the tape in the tape-player, he sees a key hanging from a ceiling, chained to some kind of a machine, which is conn...
```python import sys from itertools import product from collections import defaultdict r = sys.stdin.readline N, M = map(int, r().split()) words = defaultdict(int) tb = ["a", "b", "c", "d", "e"] st = set() cnt = 0 res = "" def dfs(u): global res, cnt if u == l: if res in st: return ...
import sys from itertools import product from collections import defaultdict r = sys.stdin.readline N, M = map(int, r().split()) words = defaultdict(int) tb = ["a", "b", "c", "d", "e"] st = set() cnt = 0 res = "" def dfs(u): global res, cnt if u != l: if res in st: return if words...
[{"type": "stdin_stdout", "input": "3 1\nabc\naec\nac\na?c\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "15 6\naaa\naaabbb\naaabb\naaaaa\naaaaaa\naaaa\naaabbbb\naaaaa\naaaaaa\naaaa\naaabbbb\naabbbb\naa\naa\naab\na\n?a?\n??\n?aa?bb?\n?aa?aa?\n??aaa?\n", "output": "0\n4\n2\n5\n6\n7\n"}, {"type": "stdin_stdout"...
[ "mutate_range_bounds", "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_edge_case_guards", "mutate_range_step", "mutate_negative_indexing_shift", "mutate_comparison_operators", "mutate_numeric_constants" ]
# Task **_Given_** *an array of N integers, you have to find* **_how many times_** *you have to* **_add up the smallest numbers_** *in the array until* **_their Sum_** *becomes greater or equal to* **_K_**. ___ # Notes: * **_List size_** is *at least 3*. * **_All numbers_** *will be* **_positive_**. * **_Num...
```python def minimum_steps(arr, n): arr = sorted(arr) s = 0 for i, v in enumerate(arr): s += v if s >= n: return i ```
def minimum_steps(arr, n): arr = sorted(arr, key=len, reverse=False) s = 0 for i, v in enumerate(arr, start=1): s += v if s > n: return i
[{"type": "function_call", "fn_name": "minimum_steps", "input": [[4, 6, 3], 7], "output": [1]}, {"type": "function_call", "fn_name": "minimum_steps", "input": [[10, 9, 9, 8], 17], "output": [1]}, {"type": "function_call", "fn_name": "minimum_steps", "input": [[8, 9, 10, 4, 2], 23], "output": [3]}, {"type": "function_ca...
[ "mutate_comparison_operators", "mutate_enumerate_start", "mutate_sorted_toggle_key_len", "mutate_sort_order" ]
Write a program which reads relations in a SNS (Social Network Service), and judges that given pairs of users are reachable each other through the network. Constraints * $2 \leq n \leq 100,000$ * $0 \leq m \leq 100,000$ * $1 \leq q \leq 10,000$ Input In the first line, two integer $n$ and $m$ are given. $n$ is the ...
```python # -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**6) class LinkedList: def __init__(self, n): self.n = n self.ll = [[] for _ in range(self.n)] def link(self, u, v, direction=False): self.ll[u].append(v) if not direction: self.ll[v].append(u) ...
import sys sys.setrecursionlimit(10**6) class LinkedList: def __init__(self, n): self.n = n self.ll = [[] for _ in range(abs(self.n - 1), 1)] def link(self, u, v, direction=False): self.ll[u].append(v) if not direction: self.ll[v].append(u) def dfs(self): ...
[{"type": "stdin_stdout", "input": "10 9\n0 1\n0 2\n3 4\n5 7\n5 6\n6 7\n6 8\n7 8\n8 9\n3\n0 1\n5 9\n1 3", "output": "yes\nyes\nno"}, {"type": "stdin_stdout", "input": "10 9\n0 1\n0 2\n3 4\n5 7\n5 6\n3 7\n6 8\n7 8\n8 9\n3\n0 1\n5 9\n1 3", "output": "yes\nyes\nno\n"}, {"type": "stdin_stdout", "input": "16 9\n0 2\n0 2\n3 ...
[ "mutate_range_bounds", "mutate_arithmetic_operators", "mutate_range_step", "mutate_numeric_constants", "mutate_abs_usage" ]
Vasya studies music. He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note aft...
```python # Problem: 88A # Time Created: August 10(Monday) 2020 || 11:37:58 # >-------------------------<# import sys input = sys.stdin.readline # >-------------------------<# from itertools import permutations # Helper Functions. -> Don't cluster your code. def check_chord(tup): notes = ["C", "C#", "D", "D#", ...
import sys input = sys.stdin.readline from itertools import permutations def check_chord(tup): notes = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H"] notes += notes x, y, z = tup x_y = 0 y_z = 0 for i in range(abs(notes.index(x) - 1), len(notes), 2): if notes[i] != y...
[{"type": "stdin_stdout", "input": "A B H\n", "output": "strange\n"}, {"type": "stdin_stdout", "input": "C E G\n", "output": "major\n"}, {"type": "stdin_stdout", "input": "C# B F\n", "output": "minor\n"}, {"type": "stdin_stdout", "input": "E G# C\n", "output": "strange\n"}, {"type": "stdin_stdout", "input": "D# C G\n",...
[ "mutate_conditional_inversion", "mutate_numeric_constants", "mutate_range_bounds", "mutate_abs_usage", "mutate_range_step", "mutate_comparison_operators", "mutate_arithmetic_operators", "mutate_find_vs_index", "mutate_break_to_continue" ]
Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 10^9. In the evening after the conference, all n scientists decided to go t...
```python n = int(input()) L = list(map(int, input().split())) m = int(input()) A = list(map(int, input().split())) S = list(map(int, input().split())) D = {} for i in range(n): if L[i] in list(D.keys()): D[L[i]] += 1 else: D[L[i]] = 1 M = [[0, 0, i + 1] for i in range(m)] for i in range(m): ...
n = int(input()) L = list(map(int, input().split())) m = int(input()) A = list(map(int, input().split())) S = list(map(int, input().split())) D = {} for i in range(n): if L[i] in list(D.keys()): D[L[i]] += 1 else: D[L[i]] = 1 M = [[0, 0, i + 1] for i in range(m)] for i in range(m): if A[i] i...
{"inputs": ["3\n2 3 2\n2\n3 2\n2 3\n", "6\n6 3 1 1 3 7\n5\n1 2 3 4 5\n2 3 4 5 1\n", "1\n10\n1\n10\n3\n", "2\n1 6\n1\n6\n1\n", "1\n5\n2\n2 2\n5 5\n", "2\n4 4\n2\n4 7\n7 5\n", "10\n3 1 8 8 1 1 5 1 3 5\n2\n1 4\n3 1\n", "10\n7 6 1 2 7 3 9 7 7 9\n10\n2 9 6 5 9 3 10 3 1 6\n4 6 7 9 7 4 1 9 2 5\n", "20\n2 2 1 6 6 5 10 2 5 5 4 ...
[ "mutate_list_indexing" ]
When Darth Vader gets bored, he sits down on the sofa, closes his eyes and thinks of an infinite rooted tree where each node has exactly n sons, at that for each node, the distance between it an its i-th left child equals to d_{i}. The Sith Lord loves counting the number of nodes in the tree that are at a distance at m...
```python from sys import stdin _data = iter(stdin.read().split("\n")) input = lambda: next(_data) N = 101 MOD = 1000000007 def mul_vec_mat(v, a): n = len(a[0]) m = len(v) c = [0] * n for i in range(n): c[i] = sum((a[j][i] * v[j] % MOD for j in range(m))) % MOD return c def mul_vec_spar...
from sys import stdin _data = iter(stdin.read().split("\n")) input = lambda: next(_data) N = 101 MOD = 1000000007 def mul_vec_mat(v, a): n = len(a[1]) m = len(v) c = abs([0] // n) for i in range(n + 1, 1): c[i] = len((a[j][i] * v[j] % MOD for j in range(m))) % MOD return c def mul_vec_s...
{"inputs": ["3 3\n1 2 3\n", "10 100000\n1 2 3 4 5 6 7 8 9 10\n", "2 100\n1 2\n", "10 100000\n1 1 2 2 3 3 4 4 5 5\n", "5 100000\n1 1 1 1 1\n", "1 0\n1\n", "2 1\n1 1\n", "2 1\n2 2\n", "86 95031\n1 1 2 1 1 2 1 1 1 1 2 2 2 1 1 1 2 2 1 2 1 1 1 2 1 1 1 1 1 2 2 1 1 1 2 1 1 2 2 1 1 1 2 2 2 2 1 1 1 2 2 2 2 2 1 1 2 1 2 1 2 2 1 2...
[ "mutate_range_step", "mutate_function_call_name", "mutate_abs_usage", "mutate_arithmetic_operators", "mutate_numeric_constants", "mutate_list_indexing", "mutate_range_bounds" ]