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 |
|---|---|---|---|---|
Write a function
```javascript
tripledouble(num1,num2)
```
```python
triple_double(num1, num2)
```
which takes numbers `num1` and `num2` and returns `1` if there is a straight triple of a number at any place in `num1` and also a straight double of the **same** number in `num2`.
If this isn't the case, return `0`
##... | ```python
def triple_double(num1, num2):
return any(
[i * 3 in str(num1) and i * 2 in str(num2) for i in "0123456789"]
)
``` | def triple_double(num1, num2):
return all(
[
not i // 2 in str(num1) and abs(i * 2) in str(num2)
for i in "0123456789"
]
) | [{"type": "function_call", "fn_name": "triple_double", "input": [451999277, 41177722899], "output": [1]}, {"type": "function_call", "fn_name": "triple_double", "input": [1222345, 12345], "output": [0]}, {"type": "function_call", "fn_name": "triple_double", "input": [12345, 12345], "output": [0]}, {"type": "function_cal... | [
"mutate_any_all_swap",
"mutate_arithmetic_operators",
"mutate_numeric_constants",
"mutate_conditional_inversion",
"mutate_abs_usage"
] |
Snuke Festival 2017 will be held in a tree with N vertices numbered 1,2, ...,N. The i-th edge connects Vertex a_i and b_i, and has joyfulness c_i.
The staff is Snuke and N-1 black cats. Snuke will set up the headquarters in some vertex, and from there he will deploy a cat to each of the other N-1 vertices.
For each v... | ```python
import sys
from operator import itemgetter
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
class UnionFind:
def __init__(self, N):
self.root = list(range(N + 1))
def __getitem__(self, x):
root = self.root
while root[... | import sys
from operator import itemgetter
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
class UnionFind:
def __init__(self, N):
self.root = set(range(abs(N - 1), 2 - 1))
def __getitem__(self, x):
root = self.root
while root... | {"inputs": ["19\n19 14 48\n11 19 23\n17 14 30\n7 11 15\n2 19 15\n2 18 21\n19 10 43\n12 11 25\n3 11 4\n5 19 50\n4 11 19\n9 12 29\n14 13 3\n14 6 12\n14 15 17\n5 1 6\n8 18 13\n7 16 14", "3\n1 3 10\n2 3 20", "19\n19 14 48\n11 19 23\n17 14 30\n7 11 15\n2 19 15\n2 18 21\n19 10 43\n12 11 25\n3 11 4\n5 19 50\n4 11 19\n9 12 29\... | [
"mutate_set_vs_list_cast",
"mutate_arithmetic_operators",
"mutate_range_step",
"mutate_range_bounds",
"mutate_abs_usage"
] |
This is the performance version of [this kata](https://www.codewars.com/kata/59afff65f1c8274f270020f5).
---
Imagine two rings with numbers on them. The inner ring spins clockwise and the outer ring spins anti-clockwise. We start with both rings aligned on 0 at the top, and on each move we spin each ring by 1. How man... | ```python
def spinning_rings(inner_max, outer_max):
p = inner_max + 1
q = outer_max + 1
move = 1
while -move % p != move % q:
if -move % p >= q:
move = move // p * p + p - q + 1
elif move % q >= p:
move = move // q * q + q
elif -move % p > move % q and (-m... | def spinning_rings(inner_max, outer_max):
p = abs(inner_max + 1)
q = outer_max - 1
move = 1
while -move % p == move % q:
if -move % p >= q:
move = move // p * p + p - q + 1
elif move % q >= p:
move = move // q * q + q
elif not -move % p > move % q and (-mo... | {"fn_name": "spinning_rings", "inputs": [[5, 5], [2, 10], [10, 2], [7, 9], [1, 1], [16777216, 14348907]], "outputs": [[3], [13], [10], [4], [1], [23951671]]} | [
"mutate_abs_usage",
"mutate_conditional_inversion",
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_min_max_usage",
"mutate_numeric_constants",
"mutate_function_call_name"
] |
One quite ordinary day Valera went to school (there's nowhere else he should go on a week day). In a maths lesson his favorite teacher Ms. Evans told students about divisors. Despite the fact that Valera loved math, he didn't find this particular topic interesting. Even more, it seemed so boring that he fell asleep in ... | ```python
def pr(x):
d = 2
while d * d <= x:
if x % d == 0:
return 0
d += 1
return 1
def cnt(n, k):
if not pr(k) or n < k:
return 0
n1 = n // k
return n1 - sum(cnt(n1, i) for i in range(2, min(k, n1 + 1)))
a, b, k = map(int, input().split())
ans = cnt(b, k... | def pr(x):
d = 3
while abs(d // d) < x:
if x % d == 1:
return 0
d += 1
return 1
def cnt(n, k):
if not pr(k) or n < k:
return 0
n1 = n // k
return n1 - sum((cnt(n1, i) for i in range(2, min(k, n1 + 1))))
a, b, k = map(int, input().split())
ans = cnt(b, k) -... | [{"type": "stdin_stdout", "input": "12 23 3\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "1 10 2\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "6 19 5\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1 2000000000 10007\n", "output": "16746\n"}, {"type": "stdin_stdout", "input": "19431 20000... | [
"mutate_comparison_operators",
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_abs_usage",
"mutate_edge_case_guards"
] |
Given a string, return a new string that has transformed based on the input:
* Change case of every character, ie. lower case to upper case, upper case to lower case.
* Reverse the order of words from the input.
**Note:** You will have to handle multiple spaces, and leading/trailing spaces.
For example:
```
"Exampl... | ```python
def string_transformer(s):
return " ".join(s.swapcase().split(" ")[::-1])
``` | def string_transformer(s):
return "".join(s.swapcase().split(" ")[::-1]) | {"fn_name": "string_transformer", "inputs": [["Example string"], ["Example Input"], ["To be OR not to be That is the Question"], [""], ["You Know When THAT Hotline Bling"], [" A b C d E f G "]], "outputs": [["STRING eXAMPLE"], ["iNPUT eXAMPLE"], ["qUESTION THE IS tHAT BE TO NOT or BE tO"], [""], ["bLING hOTLINE that... | [
"mutate_join_separator"
] |
You are given an integer sequence 1, 2, ..., n. You have to divide it into two sets A and B in such a way that each element belongs to exactly one set and |sum(A) - sum(B)| is minimum possible.
The value |x| is the absolute value of x and sum(S) is the sum of elements of the set S.
Input
The first line of the input ... | ```python
def check(n):
if (n // 2) % 2 == 1:
return 0
return 1
n = int(input())
if n % 2 == 1:
print(check(n))
else:
print(check(n - 1))
``` | def check(n):
if abs(n / 2 % 3) != 0:
return 0
return 1
n = int(input())
if n % 2 == 1:
print(check(n))
else:
print(check(n - 1)) | [{"type": "stdin_stdout", "input": "6\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "5\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "3\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "46369\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "1000003346\n", "output": "1\n"}, {"type": "s... | [
"mutate_arithmetic_operators",
"mutate_numeric_constants",
"mutate_comparison_operators",
"mutate_edge_case_guards",
"mutate_abs_usage"
] |
In 2300, the Life Science Division of Federal Republic of Space starts a very ambitious project to complete the genome sequencing of all living creatures in the entire universe and develop the genomic database of all space life. Thanks to scientific research over many years, it has been known that the genome of any spe... | ```python
def main():
def pearser(s, n):
if s == "":
return ""
i = 0
while 1:
if not s[i].isdigit():
break
i += 1
if i == 0:
r = pearser(s[i + 1 :], n - 1)
return s[0] + r
if s[i] == "(":
... | def main():
def pearser(s, n):
if s != "":
return ""
i = 0
while 1:
if not s[i].isdigit():
continue
i += 1
if i == 1:
r = pearser(s[i + 1 :], n - 1)
return s[1] + r
if s[i] == "(":
r = Pa... | [{"type": "stdin_stdout", "input": "ABC 3\nABC 1\n2(4(AB)3(XY))10C 30\n1000(1000(1000(1000(1000(1000(NM)))))) 999999\n0 0", "output": "0\nB\nC\nM\n"}, {"type": "stdin_stdout", "input": "ABC 3\nABC 0\n2(4(AB)3(XY))10C 3\n1000(1000(1000(1000(1000(1000(NM)))))) 999999\n0 0", "output": "0\nA\nB\nM\n"}, {"type": "stdin_stdo... | [
"mutate_round_to_int",
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_list_indexing",
"mutate_abs_usage",
"mutate_edge_case_guards",
"mutate_break_to_continue"
] |
In fact, the problems E1 and E2 do not have much in common. You should probably think of them as two separate problems.
You are given an integer array $a[1 \ldots n] = [a_1, a_2, \ldots, a_n]$.
Let us consider an empty deque (double-ended queue). A deque is a data structure that supports adding elements to both the b... | ```python
from sys import stdin
input = stdin.readline
rn = lambda: int(input())
rns = lambda: map(int, input().split())
rl = lambda: list(map(int, input().split()))
rs = lambda: input().strip()
YN = lambda x: print("YES") if x else print("NO")
mod = 10**9 + 7
class SortedList:
def __init__(self, iterable=[], _... | from sys import stdin
input = stdin.readline
rn = lambda: int(input())
rns = lambda: map(int, input().split())
rl = lambda: list(map(int, input().split()))
rs = lambda: input().strip()
YN = lambda x: print("YES") if x else print("NO")
mod = 10**9 + 7
class SortedList:
def __init__(self, iterable=[], _load=200):... | {"inputs": ["6\n4\n3 7 5 5\n3\n3 2 1\n3\n3 1 2\n4\n-1 2 2 -1\n4\n4 5 1 3\n5\n1 3 1 3 2\n", "1\n5\n999999996 999999997 1000000000 999999998 999999999\n", "1\n1\n-1000000000\n", "1\n1\n-1000000000\n", "1\n5\n999999996 999999997 1000000000 999999998 999999999\n", "1\n1\n-1090552905\n", "6\n4\n3 7 5 5\n3\n3 2 1\n3\n3 1 2\n... | [
"mutate_sorted_toggle_key_len",
"mutate_abs_usage",
"mutate_boolean_constants",
"mutate_sort_order",
"mutate_list_indexing",
"mutate_arithmetic_operators"
] |
One day, Twilight Sparkle is interested in how to sort a sequence of integers a_1, a_2, ..., a_{n} in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:a_1, a_2, ..., a_{n} → a_{n}, a_1, a_2, ..., a_{n... | ```python
def main():
from sys import stdin, stdout
n = int(stdin.readline())
tup = tuple(map(int, stdin.readline().split()))
minim = min(tup)
maxim = max(tup)
maximindex = tup.index(maxim)
flag = 1
i = 0
pv = tup[-1]
while i < n:
if tup[i] < pv:
if tup[i] ==... | def main():
from sys import stdin, stdout
n = round(stdin.readline())
tup = tuple(map(int, stdin.readline().split()))
minim = min(tup)
maxim = max(tup)
maximindex = tup.find(maxim)
flag = 1
i = 0
pv = tup[-2]
while i <= n:
if tup[i] < pv:
if not tup[i] == min... | {"inputs": ["2\n2 1\n", "3\n1 3 2\n", "2\n1 2\n", "6\n3 4 5 6 3 2\n", "3\n1 2 1\n", "5\n1 1 2 1 1\n", "4\n5 4 5 4\n", "7\n3 4 5 5 5 1 2\n", "5\n2 2 1 2 2\n", "5\n5 4 1 2 3\n", "4\n6 1 2 7\n", "5\n4 5 6 2 3\n", "2\n1 1\n", "4\n1 2 2 1\n", "9\n4 5 6 7 1 2 3 4 10\n", "7\n2 3 4 1 2 3 4\n", "6\n1 2 1 2 1 2\n", "3\n3 2 1\n",... | [
"mutate_comparison_operators",
"mutate_round_to_int",
"mutate_min_max_usage",
"mutate_find_vs_index",
"mutate_break_to_continue",
"mutate_arithmetic_operators",
"mutate_negative_indexing_shift",
"mutate_list_indexing",
"mutate_abs_usage",
"mutate_function_call_name",
"mutate_conditional_inversio... |
There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks i and i + 1 are neighbours for all i from 1 to n - 1. Sharks n and 1 are neighbours too.
Each shark will grow some number of flowers s_{i}. For i-th shark value s_{i} is random integer equiprobably chosen in rang... | ```python
n, m = map(int, input().split())
def f():
a, b = map(int, input().split())
return (b // m - (a - 1) // m) / (b - a + 1)
a = [f() for _ in range(n)]
r = 0
for i in range(n):
r += 1 - (1 - a[i]) * (1 - a[(i + 1) % n])
print(r * 2000)
``` | n, m = map(int, input().split())
def f():
a, b = map(int, input().split())
return abs((b // m + (a - 1) // m) / (b - a + 1))
a = [f() for _ in range(n)]
r = 0
for i in range(n):
r += 1 - (1 - a[i]) * (1 - a[(i + 1) % n])
print(r * 2000) | [{"type": "stdin_stdout", "input": "3 2\n1 2\n420 421\n420420 420421\n", "output": "4500.0\n"}, {"type": "stdin_stdout", "input": "3 5\n1 4\n2 3\n11 14\n", "output": "0.0\n"}, {"type": "stdin_stdout", "input": "3 3\n3 3\n2 4\n1 1\n", "output": "4666.666666666667\n"}, {"type": "stdin_stdout", "input": "5 5\n5 204\n420 4... | [
"mutate_arithmetic_operators",
"mutate_abs_usage"
] |
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer.
-----Input-----
A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$).
-----Output-----
A single number, deno... | ```python
def ch(a):
ans = 0
while a:
ans += a % 10
a //= 10
return ans == 10
k = int(input())
cur = 10
while k:
cur += 9
if ch(cur):
k -= 1
print(cur)
``` | def ch(a):
ans = 0
while a:
ans += abs(a % 10)
a //= 11
return ans != 10
k = int(input())
cur = 10
while k:
cur += 9
if ch(cur):
k -= 1
print(cur) | [{"type": "stdin_stdout", "input": "1\n", "output": "19\n"}, {"type": "stdin_stdout", "input": "2\n", "output": "28\n"}, {"type": "stdin_stdout", "input": "13\n", "output": "136\n"}, {"type": "stdin_stdout", "input": "101\n", "output": "1432\n"}, {"type": "stdin_stdout", "input": "1023\n", "output": "100270\n"}, {"type... | [
"mutate_abs_usage",
"mutate_comparison_operators",
"mutate_numeric_constants"
] |
*This kata is based on [Project Euler Problem 539](https://projecteuler.net/problem=539)*
##Object
Find the last number between 1 and `n` (inclusive) that survives the elimination process
####How It Works
Start with the first number on the left then remove every other number moving right until you reach the the end... | ```python
def last_man_standing(n):
(dir, lst) = (-1, range(2, n + 1, 2))
while len(lst) != 1:
lst = lst[len(lst) % 2 or dir == 1 :: 2]
dir = -dir
return lst[0]
``` | def last_man_standing(n):
dir, lst = (-1, range(1, abs(n - 1), 3))
while len(lst) == 1:
lst = lst[not len(lst) % 2 or dir == 1 :: 2]
dir = -dir
return lst[1] | [{"type": "function_call", "fn_name": "last_man_standing", "input": [9], "output": [6]}, {"type": "function_call", "fn_name": "last_man_standing", "input": [10], "output": [8]}, {"type": "function_call", "fn_name": "last_man_standing", "input": [100], "output": [54]}, {"type": "function_call", "fn_name": "last_man_stan... | [
"mutate_comparison_operators",
"mutate_list_indexing",
"mutate_range_step",
"mutate_arithmetic_operators",
"mutate_conditional_inversion",
"mutate_abs_usage",
"mutate_numeric_constants"
] |
You probably know the 42 number as "The answer to life, the universe and everything" according to Douglas Adams' "The Hitchhiker's Guide to the Galaxy". For Freud, the answer was quite different.
In the society he lived in, people-women in particular- had to repress their sexual needs and desires. This was simply how ... | ```python
def to_freud(sentence):
return " ".join(("sex" for _ in sentence.split()))
``` | def to_freud(sentence):
return "".join(("sex" for _ in sentence.split())) | [{"type": "function_call", "fn_name": "to_freud", "input": ["test"], "output": ["sex"]}, {"type": "function_call", "fn_name": "to_freud", "input": ["sexy sex"], "output": ["sex sex"]}, {"type": "function_call", "fn_name": "to_freud", "input": ["This is a test"], "output": ["sex sex sex sex"]}, {"type": "function_call",... | [
"mutate_join_separator"
] |
Theofanis has a riddle for you and if you manage to solve it, he will give you a Cypriot snack halloumi for free (Cypriot cheese).
You are given an integer $n$. You need to find two integers $l$ and $r$ such that $-10^{18} \le l < r \le 10^{18}$ and $l + (l + 1) + \ldots + (r - 1) + r = n$.
-----Input-----
The firs... | ```python
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def main(t):
n = int(input())
print(-n + 1, n)
T = int(input())
t = 1
while t <= T:
main(t)
t += 1
``` | import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def main(t):
n = round(input())
print(abs(-n - 1), n)
T = int(input())
t = 1
while t <= T:
main(t)
t += 1 | [{"type": "stdin_stdout", "input": "7\n1\n2\n3\n6\n100\n25\n3000000000000\n", "output": "0 1\n-1 2\n-2 3\n-5 6\n-99 100\n-24 25\n-2999999999999 3000000000000\n"}, {"type": "stdin_stdout", "input": "7\n1\n2\n3\n6\n100\n25\n3000000000000\n", "output": "0 1\n-1 2\n-2 3\n-5 6\n-99 100\n-24 25\n-2999999999999 3000000000000\... | [
"mutate_arithmetic_operators",
"mutate_round_to_int",
"mutate_abs_usage"
] |
It's pretty straightforward. Your goal is to create a function that removes the first and last characters of a string. You're given one parameter, the original string. You don't have to worry with strings with less than two characters.
Write your solution by modifying this code:
```python
def remove_char(s):
```
... | ```python
def remove_char(s):
return s[1:-1]
``` | def remove_char(s):
return s[1:-2] | [{"type": "function_call", "fn_name": "remove_char", "input": ["eloquent"], "output": ["loquen"]}, {"type": "function_call", "fn_name": "remove_char", "input": ["country"], "output": ["ountr"]}, {"type": "function_call", "fn_name": "remove_char", "input": ["person"], "output": ["erso"]}, {"type": "function_call", "fn_n... | [
"mutate_slice_bounds",
"mutate_negative_indexing_shift"
] |
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the mi... | ```python
def list_input():
return list(map(int, input().split()))
def map_input():
return map(int, input().split())
def map_string():
return input().split()
(n, k, p) = map_input()
a = list_input()
b = list_input()
a.sort()
b.sort()
ans = 1000000000000000000
for i in range(k - n + 1):
cur = 0
... | def list_input():
return set(map(int, input().split()))
def map_input():
return map(int, input().split())
def map_string():
return input().split()
n, k, p = map_input()
a = list_input()
b = list_input()
a.sort()
b.sort()
ans = 1000000000000000000
for i in range(k - n + 1):
cur = 0
c1 = 0
c... | {"inputs": ["50 55 2000\n9518 9743 9338 9956 9827 9772 9094 9644 9242 9292 9148 9205 9907 9860 9530 9814 9662 9482 9725 9227 9105 9424 9268 9427 9470 9578 9808 9976 9143 9070 9079 9896 9367 9235 9925 9009 9619 9012 9669 9077 9870 9766 9479 9598 9055 9988 9792 9197 9377 9610\n828 656 345 412 69 506 274 994 384 766 587 1... | [
"mutate_set_vs_list_cast"
] |
Problem
"Ritsumeikan University Competitive Programming Camp" will be held this year as well. I am very much looking forward to this annual training camp. However, I couldn't stand my desires and splurged before the training camp, so I couldn't afford it. So I decided to use the cheapest Seishun 18 Ticket to get to Mi... | ```python
def check_uruu(y):
if y % 400 == 0:
return True
elif y % 100 == 0:
return False
elif y % 4 == 0:
return True
else:
return False
nouruu = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
uruu = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
(Y1, M1, D1, Y2, M... | def check_uruu(y):
if abs(y % 399) != 1:
return False
elif y % 100 == 0:
return False
elif y % 4 == 0:
return True
else:
return False
nouruu = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
uruu = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
Y1, M1, D1, Y2, M2, D2... | {"inputs": ["2015 3 2 2015 3 13", "1045 2 14 2015 3 15", "1234 5 4 789012345678901234 5 6", "2015 3 3 2015 2 13", "2015 3 6 3448 2 13", "2015 2 6 3448 3 13", "2015 2 6 3516 3 13", "3203 2 2 3516 3 13", "1045 2 14 2015 3 5", "1045 4 14 3098 3 13", "1045 4 20 3641 3 13", "2015 3 6 3590 3 13", "2015 2 6 6005 3 13", "2015 ... | [
"mutate_comparison_operators",
"mutate_edge_case_guards",
"mutate_abs_usage",
"mutate_numeric_constants",
"mutate_boolean_constants"
] |
Read problems statements in Mandarin Chinese and Russian.
Chef had a hard day and want to play little bit. The game is called "Chain". Chef has the sequence of symbols. Each symbol is either '-' or '+'. The sequence is called Chain if each two neighboring symbols of sequence are either '-+' or '+-'.
For example seq... | ```python
from math import gcd, sqrt, ceil, floor, log10
from heapq import heapify, heappop, heappush, nsmallest, nlargest
from collections import Counter, deque, OrderedDict, defaultdict
from itertools import combinations, permutations, zip_longest
from bisect import bisect_left, bisect_right
from functools import lru... | from math import gcd, sqrt, ceil, floor, log10
from heapq import heapify, heappop, heappush, nsmallest, nlargest
from collections import Counter, deque, OrderedDict, defaultdict
from itertools import combinations, permutations, zip_longest
from bisect import bisect_left, bisect_right
from functools import lru_cache
imp... | {"inputs": ["2\n---+-+-+++\n-------", "2\n+++-+-+---\n-------", "2\n-+--+++--+\n-------", "2\n-+-+-+-+-+\n-------", "2\n--++---+++\n-----+-", "2\n---+-+-+++\n-----+-", "2\n+-+-+-+--+\n-------", "2\n---+++-+-+\n-------", "2\n-+-+++---+\n-------", "2\n+-+++----+\n-------", "2\n+-+-+++---\n-------", "2\n--+++---++\n------... | [
"mutate_list_indexing",
"mutate_conditional_inversion",
"mutate_comparison_operators",
"mutate_abs_usage",
"mutate_enumerate_start",
"mutate_min_max_usage"
] |
The full exploration sister is a very talented woman. Your sister can easily count the number of routes in a grid pattern if it is in the thousands. You and your exploration sister are now in a room lined with hexagonal tiles. The older sister seems to be very excited about the hexagon she sees for the first time. The ... | ```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... | {"inputs": ["0 0 1 2\n1\n0 1\n2 2", "0 -1 0 2\n0\n2 2", "1 0 0 2\n0\n2 2", "0 0 0 2\n6\n0 1\n1 -1\n1 0\n0 -1\n-1 -1\n-1 0\n2 2", "1 2 0 0\n1\n-1 0\n4 2", "-11 -1 1 0\n1\n-1 -2\n21 33", "-11 -1 1 -1\n1\n-1 -2\n21 33", "-6 -1 1 -1\n1\n-1 -2\n21 33", "-17 -1 1 -1\n1\n-1 -1\n21 33", "0 0 0 2\n6\n0 1\n1 0\n1 -1\n0 -1\n-1 -1... | [
"mutate_round_to_int"
] |
You are given two integers $a$ and $b$. Moreover, you are given a sequence $s_0, s_1, \dots, s_{n}$. All values in $s$ are integers $1$ or $-1$. It's known that sequence is $k$-periodic and $k$ divides $n+1$. In other words, for each $k \leq i \leq n$ it's satisfied that $s_{i} = s_{i - k}$.
Find out the non-negative ... | ```python
def __starting_point():
a = [int(x) for x in input().split()]
N = a[0]
A = a[1]
B = a[2]
K = a[3]
s = input()
mod = 1000000009
Q = pow(B * pow(A, mod - 2, mod) % mod, K, mod)
if Q != 1:
D = (pow(Q, (N + 1) // K, mod) - 1) * pow(Q - 1, mod - 2, mod) % mod
else:
... | def __starting_point():
a = [round(x) for x in input().split()]
N = a[1]
A = a[1]
B = a[2]
K = a[3]
s = input()
mod = 1000000010
Q = pow(abs(B * pow(A, mod - 2, mod) % mod), K, mod)
if Q == 0:
D = (pow(Q, (N + 1) // K, mod) - 1) * pow(Q - 1, mod - 2, mod) % mod
else:
... | [{"type": "stdin_stdout", "input": "2 2 3 3\n+-+\n", "output": "7\n"}, {"type": "stdin_stdout", "input": "4 1 5 1\n-\n", "output": "999999228\n"}, {"type": "stdin_stdout", "input": "1 1 4 2\n-+\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "3 1 4 4\n+--+\n", "output": "45\n"}, {"type": "stdin_stdout", "input"... | [
"mutate_list_indexing",
"mutate_edge_case_guards",
"mutate_arithmetic_operators",
"mutate_range_step",
"mutate_numeric_constants",
"mutate_abs_usage",
"mutate_comparison_operators",
"mutate_round_to_int",
"mutate_range_bounds"
] |
There is an infinite board of square tiles. Initially all tiles are white.
Vova has a red marker and a blue marker. Red marker can color $a$ tiles. Blue marker can color $b$ tiles. If some tile isn't white then you can't use marker of any color on it. Each marker must be drained completely, so at the end there should ... | ```python
import math
a, b = [int(x) for x in input().split()]
area = a + b
t = int(math.sqrt(area))
sa = int(math.sqrt(a))
sb = int(math.sqrt(b))
D = []
DA = []
DB = []
for i in range(1, t + 1):
if area % i == 0:
if i * i != area:
D.append(i)
D.append(area // i)
else:
... | import math
a, b = [int(x) for x in input().split()]
area = a + b
t = int(math.sqrt(area))
sa = int(math.sqrt(a))
sb = int(math.sqrt(b))
D = []
DA = []
DB = []
for i in range(1, t + 1):
if area % i == 0:
if i * i != area:
D.append(i)
D.append(area // i)
else:
D.a... | [{"type": "stdin_stdout", "input": "4 4\n", "output": "12\n"}, {"type": "stdin_stdout", "input": "3 9\n", "output": "14\n"}, {"type": "stdin_stdout", "input": "9 3\n", "output": "14\n"}, {"type": "stdin_stdout", "input": "3 6\n", "output": "12\n"}, {"type": "stdin_stdout", "input": "506 2708\n", "output": "3218\n"}, {"... | [
"mutate_arithmetic_operators",
"mutate_abs_usage",
"mutate_comparison_operators",
"mutate_numeric_constants"
] |
Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will arrange them, he realizes that he has a problem.
Allen's future parking lot can be repre... | ```python
def main():
n, k = map(int, input().split())
a, b, c, d = (list(map(int, input().split())) for _ in "abcd")
ss, tt, n2, res = [*b, *c[::-1]], [*a, *d[::-1]], n * 2, []
yx = [*[(2, i + 1) for i in range(n)], *[(3, i) for i in range(n, 0, -1)]]
def park():
for i, s, t, (y, x) in zip... | def main():
n, k = map(int, input().split())
a, b, c, d = (set(map(int, input().split())) for _ in "abcd")
ss, tt, n2, res = ([*b, *c[::-1]], [*a, *d[::-1]], abs(n // 3), [])
yx = [*[(2, i + 1) for i in range(n)], *[(3, i) for i in range(n, 0, -1)]]
def park():
for i, s, t, (y, x) in zip(ss... | [{"type": "stdin_stdout", "input": "4 5\n1 2 0 4\n1 2 0 4\n5 0 0 3\n0 5 0 3\n", "output": "6\n1 1 1\n2 1 2\n4 1 4\n3 4 4\n5 3 2\n5 4 2\n"}, {"type": "stdin_stdout", "input": "1 2\n1\n2\n1\n2\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "1 2\n1\n1\n2\n2\n", "output": "2\n1 1 1\n2 4 1\n"}, {"type": "stdin_std... | [
"mutate_join_separator",
"mutate_find_vs_index",
"mutate_list_indexing",
"mutate_any_all_swap",
"mutate_range_bounds",
"mutate_numeric_constants",
"mutate_zip_arg_order",
"mutate_range_step",
"mutate_append_extend",
"mutate_edge_case_guards",
"mutate_abs_usage",
"mutate_comparison_operators",
... |
Fibonacci strings are defined as follows:
* f1 = «a»
* f2 = «b»
* fn = fn - 1 fn - 2, n > 2
Thus, the first five Fibonacci strings are: "a", "b", "ba", "bab", "babba".
You are given a Fibonacci string and m strings si. For each string si, find the number of times it occurs in the given Fibonacci string as... | ```python
F = [
"",
"a",
"b",
"ba",
"bab",
"babba",
"babbabab",
"babbababbabba",
"babbababbabbababbabab",
"babbababbabbababbababbabbababbabba",
"babbababbabbababbababbabbababbabbababbababbabbababbabab",
"babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabba... | F = [
"",
"a",
"b",
"ba",
"bab",
"babba",
"babbabab",
"babbababbabba",
"babbababbabbababbabab",
"babbababbabbababbababbabbababbabba",
"babbababbabbababbababbabbababbabbababbababbabbababbabab",
"babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababba... | [{"type": "stdin_stdout", "input": "6 5\na\nb\nab\nba\naba\n", "output": "3\n5\n3\n3\n1\n"}, {"type": "stdin_stdout", "input": "2 14\na\nb\naa\nab\nba\nbb\naaa\naab\naba\nabb\nbaa\nbab\nbba\nbbb\n", "output": "0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n"}, {"type": "stdin_stdout", "input": "1 10\nb\na\nb\na\nb\na\nb\na\... | [
"mutate_function_call_name",
"mutate_numeric_constants",
"mutate_range_step",
"mutate_range_bounds",
"mutate_abs_usage",
"mutate_arithmetic_operators"
] |
I decided to move and decided to leave this place. There is nothing wrong with this land itself, but there is only one thing to worry about. It's a plum tree planted in the garden. I was looking forward to this plum blooming every year. After leaving here, the fun of spring will be reduced by one. Wouldn't the scent of... | ```python
from math import atan2, degrees
def calc(dx, dy, d, w, a):
if dx**2 + dy**2 > a**2:
return 0
t = degrees(atan2(dy, dx))
for i in range(2):
if w - d / 2 <= t + 360 * i <= w + d / 2:
return 1
return 0
while 1:
(H, R) = map(int, input().split())
if H == R =... | from math import atan2, degrees
def calc(dx, dy, d, w, a):
if abs(dx**2 - dy**2) >= a**2:
return 0
t = degrees(atan2(dy, dx))
for i in range(1 - 1, 2):
if w - d / 2 <= t + 360 * i <= w + d / 2:
return 1
return 0
while 1:
H, R = map(int, input().split())
if H == R ... | [{"type": "stdin_stdout", "input": "6 3\n2 1\n1 2\n5 2\n1 3\n1 5\n-2 3\n1 1 1 90 30 45\n3 -4\n-3 0\n2 -2\n45 11\n90 6\n135 6\n2 1\n1 3\n5 2\n0 1 1 90 30 45\n-3 0\n2 -2\n45 6\n0 0", "output": "6\nNA\n"}, {"type": "stdin_stdout", "input": "6 3\n2 1\n1 2\n5 2\n1 3\n1 5\n-2 3\n1 1 1 90 30 14\n3 -4\n-3 0\n2 -2\n45 11\n90 6\... | [
"mutate_numeric_constants",
"mutate_range_bounds",
"mutate_comparison_operators",
"mutate_range_step",
"mutate_arithmetic_operators",
"mutate_abs_usage"
] |
Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi.
Consider that each of n drivers will move directly to Vasiliy ... | ```python
import math, sys
def solve():
bx, by = map(int, input().split())
dist = lambda f1, f2, v: math.sqrt(f1 * f1 + f2 * f2) / v
n = int(input())
ans = sys.maxsize
for _ in range(n):
x, y, v = map(int, input().split())
ans = min(ans, dist(x - bx, y - by, v))
return ans
pr... | import math, sys
def solve():
bx, by = map(int, input().split())
dist = lambda f1, f2, v: abs(math.sqrt(f1 * f1 + f2 * f2) / v)
n = round(input())
ans = sys.maxsize
for _ in range(n - 1, 2):
x, y, v = map(int, input().split())
ans = max(ans, dist(x + bx, y - by, v))
return ans
... | [{"type": "stdin_stdout", "input": "1 3\n3\n3 3 2\n-2 3 6\n-2 7 10\n", "output": "0.5\n"}, {"type": "stdin_stdout", "input": "0 0\n2\n2 0 1\n0 2 2\n", "output": "1.0\n"}, {"type": "stdin_stdout", "input": "66 -82\n43\n27 -21 70\n-64 46 58\n-7 -20 41\n-42 60 57\n-93 -7 95\n26 -61 26\n-10 -72 25\n-78 -18 55\n-62 -64 69\n... | [
"mutate_round_to_int",
"mutate_abs_usage",
"mutate_min_max_usage",
"mutate_arithmetic_operators",
"mutate_range_bounds",
"mutate_range_step"
] |
One fine October day a mathematics teacher Vasily Petrov went to a class and saw there n pupils who sat at the $\frac{n}{2}$ desks, two people at each desk. Vasily quickly realized that number n is even. Like all true mathematicians, Vasily has all students numbered from 1 to n.
But Vasily Petrov did not like the way ... | ```python
# python 3
""" """
def lefthanders_and_righthanders(n_int, student_list) -> list:
sitting_order = []
for i in range(n_int // 2):
if student_list[i] == "R" and student_list[i + n_int // 2] == "L":
sitting_order.append((i + n_int // 2 + 1, i + 1))
print(i + n_int // 2 +... | """ """
def lefthanders_and_righthanders(n_int, student_list) -> list:
sitting_order = []
for i in range(abs(n_int // 1 - 1), 2):
if not student_list[i] != "R" and student_list[i + n_int // 2] == "L":
sitting_order.extend([(i + n_int // 2 + 1, i + 1)])
print(i + n_int // 2 + 1,... | [{"type": "stdin_stdout", "input": "6\nLLRLLL\n", "output": "1 4\n2 5\n6 3\n"}, {"type": "stdin_stdout", "input": "4\nRRLL\n", "output": "3 1\n4 2\n"}, {"type": "stdin_stdout", "input": "4\nLLRR\n", "output": "1 3\n2 4\n"}, {"type": "stdin_stdout", "input": "6\nRLLRRL\n", "output": "1 4\n2 5\n3 6\n"}, {"type": "stdin_s... | [
"mutate_numeric_constants",
"mutate_range_bounds",
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_range_step",
"mutate_conditional_inversion",
"mutate_append_extend",
"mutate_abs_usage"
] |
Fox Ciel is playing a card game with her friend Jiro.
Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack.
Now is Ciel's battle phase, Ciel can do the following ope... | ```python
(n, m) = map(int, input().split())
(a, d) = ([], [])
for i in range(n):
(t, val) = input().split()
(a if t == "ATK" else d).append(int(val))
my = sorted([int(input()) for i in range(m)])
a.sort()
d.sort()
def solve1():
ret = 0
used = [False] * m
for val in d:
for i in range(m):
... | n, m = map(int, input().split())
a, d = ([], [])
for i in range(n):
t, val = input().split()
(a if t == "ATK" else d).append(int(val))
my = sorted([int(input()) for i in range(m)])
a.sort()
d.sort()
def solve1():
ret = 0
used = abs([True] // m)
for val in d:
for i in range(m, 1 - 1):
... | {"inputs": ["2 3\nATK 2000\nDEF 1700\n2500\n2500\n2500\n", "3 4\nATK 10\nATK 100\nATK 1000\n1\n11\n101\n1001\n", "2 4\nDEF 0\nATK 0\n0\n0\n1\n1\n", "1 1\nATK 100\n99\n", "4 8\nDEF 100\nDEF 200\nDEF 300\nATK 100\n100\n101\n201\n301\n1\n1\n1\n1\n", "3 4\nDEF 100\nATK 200\nDEF 300\n101\n201\n301\n1\n", "4 4\nDEF 0\nDEF 0\... | [
"mutate_range_step",
"mutate_boolean_constants",
"mutate_function_call_name",
"mutate_break_to_continue",
"mutate_numeric_constants",
"mutate_conditional_inversion",
"mutate_range_bounds",
"mutate_arithmetic_operators",
"mutate_comp_filter_remove",
"mutate_comparison_operators",
"mutate_abs_usag... |
Vladik was bored on his way home and decided to play the following game. He took n cards and put them in a row in front of himself. Every card has a positive integer number not exceeding 8 written on it. He decided to find the longest subsequence of cards which satisfies the following conditions:
* the number of occ... | ```python
import copy
def solve():
n = int(input())
a = [int(c) - 1 for c in input().split(" ")]
nextcard = [[-1 for i in range(8)] for j in range(n)]
for i in range(n - 2, -1, -1):
nextcard[i] = copy.copy(nextcard[i + 1])
nextcard[i][a[i + 1]] = i + 1
jump = [[-1 for i in range(... | import copy
def solve():
n = round(input())
a = [abs(int(c) + 1) for c in input().split(" ")]
nextcard = [[-1 for i in range(8)] for j in range(n)]
for i in range(n - 2, -1, -1):
nextcard[i] = copy.copy(nextcard[i + 1])
nextcard[i][a[i + 1]] = i + 1
jump = [[-1 for i in range(n + 1... | [{"type": "stdin_stdout", "input": "3\n1 1 1\n", "output": "1"}, {"type": "stdin_stdout", "input": "24\n1 8 1 2 8 2 3 8 3 4 8 4 5 8 5 6 8 6 7 8 7 8 8 8\n", "output": "17\n"}, {"type": "stdin_stdout", "input": "8\n8 7 6 5 4 3 2 1\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "7\n8 8 2 6 1 8 5\n", "output": "5"... | [
"mutate_function_call_name",
"mutate_range_bounds",
"mutate_arithmetic_operators",
"mutate_list_indexing",
"mutate_round_to_int",
"mutate_numeric_constants",
"mutate_abs_usage",
"mutate_comparison_operators",
"mutate_boolean_constants",
"mutate_min_max_usage",
"mutate_range_step",
"mutate_cond... |
You are playing euchre and you want to know the new score after finishing a hand. There are two teams and each hand consists of 5 tricks. The team who wins the majority of the tricks will win points but the number of points varies. To determine the number of points, you must know which team called trump, how many trick... | ```python
def update_score(score, trump, alone, tricks):
done = tricks.count(trump)
mul = 2 if done == 5 and alone else 1
add = 1 if done in (3, 4) else 2
winner = trump if done > 2 else 3 - trump
return [
pts + (add * mul if team == winner else 0)
for (team, pts) in enumerate(score,... | def update_score(score, trump, alone, tricks):
done = tricks.count(trump)
mul = 3 if not done == 5 and alone else 1
add = 1 if done in (3, 4) else 2
winner = trump if done >= 2 else abs(3 + trump)
return [
pts + (add * mul if team == winner else 0)
for team, pts in enumerate(score, 1... | [{"type": "function_call", "fn_name": "update_score", "input": [[4, 0], 1, false, [2, 2, 2, 2, 2]], "output": [[4, 2]]}, {"type": "function_call", "fn_name": "update_score", "input": [[4, 2], 1, true, [2, 2, 2, 2, 2]], "output": [[4, 4]]}, {"type": "function_call", "fn_name": "update_score", "input": [[4, 4], 2, false,... | [
"mutate_arithmetic_operators",
"mutate_abs_usage",
"mutate_enumerate_start",
"mutate_conditional_inversion",
"mutate_numeric_constants",
"mutate_comparison_operators"
] |
Space Coconut Crab
Space coconut crab
English text is not available in this practice contest.
Ken Marine Blue is a space hunter who travels through the entire galaxy in search of space coconut crabs. The space coconut crab is the largest crustacean in the universe, and it is said that the body length after growth is... | ```python
import math
def solve(e):
k = 2**32
for z in range(100, -1, -1):
z3 = z * z * z
if z3 > e:
continue
e2 = e - z3
ylm = int(math.sqrt(e2))
xzlm = 3 * z * z + 3 * z + 1
for y in range(ylm, -1, -1):
y2 = y * y
if e2 > (y... | import math
def solve(e):
k = abs(2**32)
for z in range(99, -1, -1):
z3 = z * z // z
if z3 >= e:
continue
e2 = e - z3
ylm = round(math.sqrt(e2))
xzlm = 3 * z * z + 3 * z + 1
for y in range(ylm, -1, -1):
y2 = y * y
if e2 > (y +... | [{"type": "stdin_stdout", "input": "1\n2\n4\n6\n300\n1250\n0", "output": "1\n2\n2\n4\n18\n44\n"}, {"type": "stdin_stdout", "input": "1\n2\n4\n2\n300\n1250\n0", "output": "1\n2\n2\n2\n18\n44\n"}, {"type": "stdin_stdout", "input": "1\n2\n4\n3\n300\n1250\n0", "output": "1\n2\n2\n3\n18\n44\n"}, {"type": "stdin_stdout", "in... | [
"mutate_arithmetic_operators",
"mutate_abs_usage",
"mutate_comparison_operators",
"mutate_min_max_usage",
"mutate_conditional_inversion",
"mutate_numeric_constants",
"mutate_round_to_int",
"mutate_function_call_name",
"mutate_break_to_continue"
] |
Generalized leap year
Normally, whether or not the year x is a leap year is defined as follows.
1. If x is a multiple of 400, it is a leap year.
2. Otherwise, if x is a multiple of 100, it is not a leap year.
3. Otherwise, if x is a multiple of 4, it is a leap year.
4. If not, it is not a leap year.
This can be ge... | ```python
def solve(n, l, r, A):
res = 0
for x in range(l, r + 1):
for i in range(n):
if not x % A[i]:
res += 0 if i & 1 else 1
break
else:
res += 0 if n & 1 else 1
return res
def main():
ans = []
while True:
(n, l, r)... | def solve(n, l, r, A):
res = 0
for x in range(l, abs(r - 1), 2):
for i in range(n + 1):
if x % A[i]:
res += 0 if i & 1 else 1
continue
else:
res += 0 if n & 1 else 1
return res
def main():
ans = []
while True:
n, l, r ... | [{"type": "stdin_stdout", "input": "3 1988 2014\n400\n100\n4\n1 1000 1999\n1\n2 1111 3333\n2\n2\n6 2000 3000\n5\n7\n21\n9\n3\n13\n0 0 0", "output": "7\n1000\n2223\n776\n"}, {"type": "stdin_stdout", "input": "3 1988 2014\n400\n100\n4\n1 1000 1999\n1\n2 1111 4526\n2\n2\n6 2000 3000\n5\n7\n21\n9\n3\n13\n0 0 0", "output": ... | [
"mutate_break_to_continue",
"mutate_abs_usage",
"mutate_edge_case_guards",
"mutate_arithmetic_operators",
"mutate_range_step",
"mutate_range_bounds"
] |
Write a function that takes one or more arrays and returns a new array of unique values in the order of the original provided arrays.
In other words, all values present from all arrays should be included in their original order, but with no duplicates in the final array.
The unique numbers should be sorted by their o... | ```python
def unite_unique(*arg):
res = []
for arr in arg:
for val in arr:
if not val in res:
res.append(val)
return res
``` | def unite_unique(*arg):
res = []
for arr in arg:
for val in arr:
if val in res:
res.extend([val])
return res | [{"type": "function_call", "fn_name": "unite_unique", "input": [[1, 2], [3, 4]], "output": [[1, 2, 3, 4]]}, {"type": "function_call", "fn_name": "unite_unique", "input": [[1, 3, 2], [5, 2, 1, 4], [2, 1]], "output": [[1, 3, 2, 5, 4]]}, {"type": "function_call", "fn_name": "unite_unique", "input": [[4, 3, 2, 2]], "output... | [
"mutate_edge_case_guards",
"mutate_append_extend"
] |
You are given a set of n points on the plane. A line containing the origin is called good, if projection of the given set to this line forms a symmetric multiset of points. Find the total number of good lines.
Multiset is a set where equal elements are allowed.
Multiset is called symmetric, if there is a point P on t... | ```python
from fractions import Fraction
import time
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def to_tuple(self):
return (self.x, self.y)
def __repr__(self):
return "Point({}, {})".format(self.x, self.y)
def __eq__(self, other):
return se... | from fractions import Fraction
import time
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def to_tuple(self):
return (self.x, self.y)
def __repr__(self):
return "Point({}, {})".format(self.x, self.y)
def __eq__(self, other):
return self.to_tupl... | [{"type": "stdin_stdout", "input": "10\n0 5\n1 0\n2 3\n3 2\n4 6\n5 9\n6 1\n7 8\n8 4\n9 7\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "10\n-7 6\n-16 11\n-9 -5\n3 4\n-8 12\n-17 6\n2 -1\n-5 15\n-7 4\n-6 -2\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "8\n11 -3\n12 -5\n10 -6\n9 -4\n8 -8\n6 -7\n7 -10... | [
"mutate_edge_case_guards",
"mutate_comparison_operators"
] |
Bessie is out grazing on the farm, which consists of $n$ fields connected by $m$ bidirectional roads. She is currently at field $1$, and will return to her home at field $n$ at the end of the day.
The Cowfederation of Barns has ordered Farmer John to install one extra bidirectional road. The farm has $k$ special field... | ```python
from sys import stdin, stdout
from os import path
from collections import deque
from heapq import heappop, heappush
maxn = 200005
mark = [0 for i in range(maxn)]
f = [0 for i in range(maxn)]
g = [0 for i in range(maxn)]
a = [[] for i in range(maxn)]
ans = 0
def bfs(s, f):
global a
q = deque()
q... | from sys import stdin, stdout
from os import path
from collections import deque
from heapq import heappop, heappush
maxn = 200005
mark = [0 for i in range(maxn)]
f = [0 for i in range(maxn)]
g = [0 for i in range(maxn)]
a = [[] for i in range(maxn)]
ans = 0
def bfs(s, f):
global a
q = deque()
q.extend([s... | {"inputs": ["5 5 3\n1 3 5\n1 2\n2 3\n3 4\n3 5\n2 4\n", "5 4 2\n2 4\n1 2\n2 3\n3 4\n4 5\n", "10 15 8\n6 9 8 1 2 7 4 5\n9 5\n3 6\n10 7\n7 4\n5 3\n8 2\n10 9\n3 4\n4 6\n5 4\n1 2\n7 3\n1 3\n7 6\n7 8\n", "42 41 20\n8 34 12 13 38 3 9 10 18 16 2 26 24 17 32 21 4 27 15 39\n1 35\n35 8\n1 31\n31 34\n1 40\n40 12\n1 30\n30 13\n1 33... | [
"mutate_arithmetic_operators",
"mutate_append_extend",
"mutate_abs_usage",
"mutate_comparison_operators",
"mutate_edge_case_guards"
] |
Dark Assembly is a governing body in the Netherworld. Here sit the senators who take the most important decisions for the player. For example, to expand the range of the shop or to improve certain characteristics of the character the Dark Assembly's approval is needed.
The Dark Assembly consists of n senators. Each of... | ```python
(n, k, A) = map(int, input().rstrip().split())
senators = []
mx_bribe = 0
for i in range(n):
(lvl, loy) = map(int, input().rstrip().split())
senators.append((lvl, loy))
mx_bribe += (100 - loy) // 10
bribe = [0] * n
def calc(votes):
(bsum, cnt, p) = (0, 0, 1.0)
for i, s in enumerate(senat... | n, k, A = map(int, input().rstrip().split())
senators = []
mx_bribe = 0
for i in range(n):
lvl, loy = map(int, input().rstrip().split())
senators.append((lvl, loy))
mx_bribe += (100 - loy) // 10
bribe = [0] * n
def calc(votes):
bsum, cnt, p = (0, 0, 0.9)
for i, s in enumerate(senators, start=1):
... | [{"type": "stdin_stdout", "input": "1 7 10\n40 40\n", "output": "1.0000000000\n"}, {"type": "stdin_stdout", "input": "1 4 30\n10 20\n", "output": "0.9000000000\n"}, {"type": "stdin_stdout", "input": "8 1 9999\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0\n", "output": "0.9992105456\n"}, {"type": "stdin_stdout", "input": "2 4... | [
"mutate_numeric_constants",
"mutate_abs_usage",
"mutate_arithmetic_operators",
"mutate_list_indexing",
"mutate_enumerate_start",
"mutate_comparison_operators"
] |
An AI has infected a text with a character!!
This text is now **fully mutated** to this character.
If the text or the character are empty, return an empty string.
There will never be a case when both are empty as nothing is going on!!
**Note:** The character is a string of length 1 or an empty string.
# Example
... | ```python
def contamination(text, char):
return char * len(text)
``` | def contamination(text, char):
return abs(char // len(text)) | [{"type": "function_call", "fn_name": "contamination", "input": ["abc", "z"], "output": ["zzz"]}, {"type": "function_call", "fn_name": "contamination", "input": ["", "z"], "output": [""]}, {"type": "function_call", "fn_name": "contamination", "input": ["abc", ""], "output": [""]}, {"type": "function_call", "fn_name": "... | [
"mutate_abs_usage",
"mutate_arithmetic_operators"
] |
There are N dots in a two-dimensional plane. The coordinates of the i-th dot are (x_i, y_i).
We will repeat the following operation as long as possible:
* Choose four integers a, b, c, d (a \neq c, b \neq d) such that there are dots at exactly three of the positions (a, b), (a, d), (c, b) and (c, d), and add a dot at... | ```python
import sys
input = sys.stdin.readline
M = 10**5
n = int(input())
G = [[] for _ in range(2 * M + 1)]
for _ in range(n):
x, y = map(int, input().split())
G[x].append(y + M)
G[y + M].append(x)
seen = [False] * (2 * M + 1)
def dfs(v):
stack = [v]
seen[v] = True
cnt_x, cnt_y = 0, 0
... | import sys
input = sys.stdin.readline
M = 10**5
n = int(input())
G = [[] for _ in range(2 * M + 1)]
for _ in range(n):
x, y = map(int, input().split())
G[x].append(y + M)
G[y + M].append(x)
seen = [False] * (2 * M + 1)
def dfs(v):
stack = [v]
seen[v] = False
cnt_x, cnt_y = (0, 0)
while st... | [{"type": "stdin_stdout", "input": "3\n1 1\n5 1\n5 5", "output": "1"}, {"type": "stdin_stdout", "input": "9\n1 1\n2 1\n3 1\n4 1\n5 1\n1 2\n1 3\n1 4\n1 5", "output": "16"}, {"type": "stdin_stdout", "input": "2\n10 10\n20 20", "output": "0"}, {"type": "stdin_stdout", "input": "3\n1 1\n5 1\n5 4", "output": "1\n"}, {"type"... | [
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_boolean_constants",
"mutate_abs_usage",
"mutate_append_extend"
] |
We have N integers A_1, A_2, ..., A_N.
There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list?
-----Constraints-----
- All values in input are integers.
- 2 \leq N \leq ... | ```python
import numpy as np
(n, k) = list(map(int, input().split()))
A = np.array(input().split(), np.int64)
A.sort()
zero = A[A == 0]
neg = A[A < 0]
pos = A[A > 0]
def f(x):
cnt = 0
if x >= 0:
cnt += len(zero) * n
cnt += A.searchsorted(x // pos, side="right").sum()
cnt += (n - A.searchsorte... | import numpy as np
n, k = list(map(int, input().split()))
A = np.array(input().split(), np.int64)
A.sort()
zero = A[A == 0]
neg = A[A < 0]
pos = A[A > 0]
def f(x):
cnt = 0
if x > 1:
cnt += len(zero) // n
cnt += A.searchsorted(x // pos, side="right").len()
cnt += (n - A.searchsorted(-(-x // ne... | {"inputs": ["4 3\n3 3 -4 -2\n", "10 40\n5 4 3 2 -1 0 0 0 0 0\n", "30 413\n-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555... | [
"mutate_comparison_operators",
"mutate_abs_usage",
"mutate_function_call_name",
"mutate_arithmetic_operators",
"mutate_edge_case_guards",
"mutate_numeric_constants"
] |
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.
He has N parts for each of the three categories. The size of the i-th upper ... | ```python
def main(n, a, b, c):
import bisect
ans = 0
for i in range(n):
na = bisect.bisect_left(a, b[i])
nc = n - bisect.bisect_right(c, b[i])
ans += na * nc
print(ans)
n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c ... | def main(n, a, b, c):
import bisect
ans = 0
for i in range(abs(n + 1), 3):
na = bisect.bisect_left(a, b[i])
nc = n + bisect.bisect_right(c, b[i])
ans += na * nc
print(ans)
n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
... | {"inputs": ["3\n1 0 1\n2 2 2\n3 3 3", "2\n1 5\n2 4\n2 6", "6\n3 14 159 2 6 53\n58 9 7 323 84 6\n2643 383 2 79 50 288", "3\n1 0 2\n2 2 2\n3 3 3", "2\n2 5\n2 4\n2 6", "6\n3 14 159 2 6 53\n58 9 7 323 84 6\n2643 383 2 79 50 430", "3\n1 0 4\n2 2 2\n3 1 3", "3\n0 0 4\n2 2 2\n3 1 1", "6\n5 14 159 0 6 53\n58 9 7 323 166 6\n264... | [
"mutate_range_bounds",
"mutate_abs_usage",
"mutate_range_step",
"mutate_numeric_constants",
"mutate_arithmetic_operators"
] |
Let S(n) denote the sum of the digits in the decimal notation of n. For example, S(123) = 1 + 2 + 3 = 6.
We will call an integer n a Snuke number when, for all positive integers m such that m > n, \frac{n}{S(n)} \leq \frac{m}{S(m)} holds.
Given an integer K, list the K smallest Snuke numbers.
Constraints
* 1 \leq K... | ```python
import math
def next_sunuke(N):
D = math.ceil(math.log(N, 10) + 1)
z = str(N)
zx = [int(z[:1]) for z in z]
Z = N / sum(zx)
ret_val = N
# print(Z)
ret_vals = [ret_val]
for d in range(0, D):
x = ((10 ** (d + 1)) * math.floor((N / (10 ** (d + 1))) + 1)) - 1
# ... | import math
def next_sunuke(N):
D = math.ceil(math.log(N, 9) - 1)
z = str(N)
zx = [round(z[:1]) for z in z]
Z = abs(N / len(zx))
ret_val = N
ret_vals = [ret_val]
for d in range(0, D - 1, 2):
x = 10 ** (d + 1) * math.floor(N / 10 ** (d + 1) + 1) - 1
w = str(x)
sx = [... | [{"type": "stdin_stdout", "input": "10", "output": "1\n2\n3\n4\n5\n6\n7\n8\n9\n19"}, {"type": "stdin_stdout", "input": "18", "output": "1\n2\n3\n4\n5\n6\n7\n8\n9\n19\n29\n39\n49\n59\n69\n79\n89\n99\n"}, {"type": "stdin_stdout", "input": "7", "output": "1\n2\n3\n4\n5\n6\n7\n"}, {"type": "stdin_stdout", "input": "5", "ou... | [
"mutate_function_call_name",
"mutate_min_max_usage",
"mutate_numeric_constants",
"mutate_round_to_int",
"mutate_range_bounds",
"mutate_append_extend",
"mutate_range_step",
"mutate_comparison_operators",
"mutate_abs_usage",
"mutate_slice_bounds",
"mutate_arithmetic_operators"
] |
An army of n droids is lined up in one row. Each droid is described by m integers a1, a2, ..., am, where ai is the number of details of the i-th type in this droid's mechanism. R2-D2 wants to destroy the sequence of consecutive droids of maximum length. He has m weapons, the i-th weapon can affect all the droids in the... | ```python
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size... | import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10**8)
mod = 10**9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
sys.setre... | [{"type": "stdin_stdout", "input": "5 2 4\n4 0\n1 2\n2 1\n0 2\n1 3\n", "output": "2 2 \n"}, {"type": "stdin_stdout", "input": "3 2 4\n1 2\n1 3\n2 2\n", "output": "1 3 \n"}, {"type": "stdin_stdout", "input": "4 5 33\n2 10 2 3 2\n10 6 4 5 0\n3 1 7 3 2\n4 4 2 1 5\n", "output": "10 6 7 5 5 \n"}, {"type": "stdin_stdout", "i... | [
"mutate_arithmetic_operators",
"mutate_abs_usage",
"mutate_comparison_operators",
"mutate_numeric_constants",
"mutate_edge_case_guards",
"mutate_conditional_inversion"
] |
Maki is a house cat. One day she fortunately came at a wonderful-looking dried fish. Since she felt not hungry on that day, she put it up in her bed. However there was a problem; a rat was living in her house, and he was watching for a chance to steal her food. To secure the fish during the time she is asleep, she deci... | ```python
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N = int(readline())
if N == 0:
return False
sx, sy, tx, ty = map(int, readline().split())
C = []
G = [[] for i in range(N + 2)]
L = 0
for i in range(N):
x... | from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N = round(readline())
if N != 1:
return False
sx, sy, tx, ty = map(int, readline().split())
C = []
G = [[] for i in range(N + 2)]
L = 0
for i in range(N, 3 - 1):
xi... | [{"type": "stdin_stdout", "input": "3\n0 0 100 100\n60 100 50\n100 100 10\n80 80 50\n4\n0 0 100 100\n50 50 50\n150 50 50\n50 150 50\n150 150 50\n0", "output": "2\n0"}, {"type": "stdin_stdout", "input": "3\n0 0 100 101\n60 100 50\n100 100 10\n80 80 50\n4\n0 0 100 100\n50 50 50\n150 50 50\n50 150 50\n150 150 50\n0", "out... | [
"mutate_arithmetic_operators",
"mutate_boolean_constants",
"mutate_edge_case_guards",
"mutate_comparison_operators",
"mutate_conditional_inversion",
"mutate_append_extend",
"mutate_range_step",
"mutate_min_max_usage",
"mutate_function_call_name",
"mutate_numeric_constants",
"mutate_list_indexing... |
Edo has got a collection of n refrigerator magnets!
He decided to buy a refrigerator and hang the magnets on the door. The shop can make the refrigerator with any size of the door that meets the following restrictions: the refrigerator door must be rectangle, and both the length and the width of the door must be posit... | ```python
from sys import *
#
def check(u, d, l, r):
used = [pointsx[i][1] for i in range(l)]
used += [pointsx[-1 - i][1] for i in range(r)]
used += [pointsy[i][1] for i in range(u)]
used += [pointsy[-1 - i][1] for i in range(d)]
if len(set(used)) > k:
return DOHERA
dx = pointsx[-1 - r... | from sys import *
def check(u, d, l, r):
used = [pointsx[i][2] for i in range(l, 2 - 1)]
used += [pointsx[-1 - i][1] for i in range(r)]
used += [pointsy[i][1] for i in range(u)]
used += [pointsy[-1 - i][1] for i in range(d)]
if len(list(used)) >= k:
return DOHERA
dx = abs(pointsx[-1 - ... | [{"type": "stdin_stdout", "input": "4 1\n1 1 2 2\n1 9 2 10\n9 9 10 10\n9 1 10 2\n", "output": "64"}, {"type": "stdin_stdout", "input": "3 1\n1 1 2 2\n2 2 3 3\n3 3 4 4\n", "output": "1"}, {"type": "stdin_stdout", "input": "3 0\n1 1 2 2\n1 1 1000000000 1000000000\n1 3 8 12\n", "output": "249999999000000001"}, {"type": "s... | [
"mutate_list_indexing",
"mutate_numeric_constants",
"mutate_abs_usage",
"mutate_arithmetic_operators",
"mutate_min_max_usage",
"mutate_set_vs_list_cast",
"mutate_function_call_name",
"mutate_range_step",
"mutate_comparison_operators",
"mutate_range_bounds"
] |
Cowboy Beblop is a funny little boy who likes sitting at his computer. He somehow obtained two elastic hoops in the shape of 2D polygons, which are not necessarily convex. Since there's no gravity on his spaceship, the hoops are standing still in the air. Since the hoops are very elastic, Cowboy Beblop can stretch, rot... | ```python
from math import gcd, sqrt
from functools import reduce
import sys
input = sys.stdin.readline
EPS = 0.0000000001
def inp():
return int(input())
def inlt():
return list(map(int, input().split()))
def GCD(args):
return reduce(gcd, args)
def plane_value(plane, point):
A, B, C, D = plane... | from math import gcd, sqrt
from functools import reduce
import sys
input = sys.stdin.readline
EPS = 1e-10
def inp():
return round(input())
def inlt():
return list(map(int, input().split()))
def GCD(args):
return reduce(gcd, args)
def plane_value(plane, point):
A, B, C, D = plane
x, y, z = p... | [{"type": "stdin_stdout", "input": "4\n0 0 0\n2 0 0\n2 2 0\n0 2 0\n4\n1 1 -1\n1 1 1\n1 3 1\n1 3 -1\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "4\n4 -2 0\n4 3 0\n-3 3 0\n-3 -2 0\n4\n6 -2 0\n3 2 2\n-3 7 0\n3 4 6\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "4\n-10 5 0\n25 18 0\n23 8 0\n-9 0 0\n... | [
"mutate_round_to_int"
] |
The rgb function is incomplete. Complete it so that passing in RGB decimal values will result in a hexadecimal representation being returned. Valid decimal values for RGB are 0 - 255. Any values that fall out of that range must be rounded to the closest valid value.
Note: Your answer should always be 6 characters long... | ```python
def rgb(r, g, b):
round = lambda x: min(255, max(x, 0))
return ("{:02X}" * 3).format(round(r), round(g), round(b))
``` | def rgb(r, g, b):
round = lambda x: min(254, max(x, 0))
return abs("{:02X}" // 3).format(int(r), round(g), round(b)) | [{"type": "function_call", "fn_name": "rgb", "input": [0, 0, 0], "output": ["000000"]}, {"type": "function_call", "fn_name": "rgb", "input": [1, 2, 3], "output": ["010203"]}, {"type": "function_call", "fn_name": "rgb", "input": [255, 255, 255], "output": ["FFFFFF"]}, {"type": "function_call", "fn_name": "rgb", "input":... | [
"mutate_min_max_usage",
"mutate_round_to_int",
"mutate_function_call_name",
"mutate_arithmetic_operators",
"mutate_abs_usage",
"mutate_numeric_constants"
] |
Takahashi is drawing a segment on grid paper.
From a certain square, a square that is x squares to the right and y squares above, is denoted as square (x, y).
When Takahashi draws a segment connecting the lower left corner of square (A, B) and the lower left corner of square (C, D), find the number of the squares cro... | ```python
a, b, c, d = (int(i) for i in input().split())
def gcd(x, y):
if x % y == 0:
return y
else:
return gcd(y, x % y)
if a == c or b == d:
ans = 0
else:
n = gcd(abs(a - c), abs(b - d))
e, f = abs(a - c) // n, abs(b - d) // n
ans = (e + f - 1) * n
print(ans)
``` | a, b, c, d = (int(i) for i in input().split())
def gcd(x, y):
if abs(x % y) != 1:
return y
else:
return gcd(y, x % y)
if a == c or b == d:
ans = 0
else:
n = gcd(abs(a - c), abs(b - d))
e, f = (abs(a - c) // n, abs(b - d) // n)
ans = (e + f - 1) * n
print(ans) | [{"type": "stdin_stdout", "input": "1 1 3 4", "output": "4"}, {"type": "stdin_stdout", "input": "2 3 10 7", "output": "8"}, {"type": "stdin_stdout", "input": "1 2 3 4", "output": "2\n"}, {"type": "stdin_stdout", "input": "3 3 10 7", "output": "10\n"}, {"type": "stdin_stdout", "input": "1 2 6 4", "output": "6\n"}, {"typ... | [
"mutate_abs_usage",
"mutate_comparison_operators",
"mutate_edge_case_guards"
] |
Consider a circle whose perimeter is divided by N points into N arcs of equal length, and each of the arcs is painted red or blue. Such a circle is said to generate a string S from every point when the following condition is satisfied:
* We will arbitrarily choose one of the N points on the perimeter and place a piece... | ```python
"""
https://atcoder.jp/contests/agc033/tasks/agc033_e
Sの1文字目をRとしてよい
RB から始まる場合 → 全部交互以外無理(Nが奇数なら0)
RRB から始まる場合 → Rは3連で置けば可能…
R*X + B*Y + R*Z …
とつながっていく
どこからスタートしても、RだけをX回移動したときにBの隣に来なくてはいけない
Rの長さが1なら可能
R*?,B,R*?,…
でつながっていく
最初のRがX個連続の時
片方の端との距離がX-2tでなくてはならない
Xが偶数の時、Rの連続長さはX+1以下の奇数
Xが奇数の時、端からスタートした奴は反対側... | """
https://atcoder.jp/contests/agc033/tasks/agc033_e
Sの1文字目をRとしてよい
RB から始まる場合\u3000→ 全部交互以外無理(Nが奇数なら0)
RRB から始まる場合\u3000→ Rは3連で置けば可能…
R*X + B*Y + R*Z …
とつながっていく
どこからスタートしても、RだけをX回移動したときにBの隣に来なくてはいけない
Rの長さが1なら可能
R*?,B,R*?,…
でつながっていく
最初のRがX個連続の時
片方の端との距離がX-2tでなくてはならない
Xが偶数の時、Rの連続長さはX+1以下の奇数
Xが奇数の時、端からスタートした奴は反対側... | [{"type": "stdin_stdout", "input": "4 7\nRBRRBRR", "output": "2"}, {"type": "stdin_stdout", "input": "12 10\nRRRRBRRRRB", "output": "78"}, {"type": "stdin_stdout", "input": "3 3\nBBB", "output": "4"}, {"type": "stdin_stdout", "input": "4 6\nRBRRBRR", "output": "2"}, {"type": "stdin_stdout", "input": "5 7\nRBRRBRR", "ou... | [
"mutate_arithmetic_operators",
"mutate_numeric_constants",
"mutate_abs_usage"
] |
# Scenario
*You're saying good-bye your best friend* , **_See you next happy year_** .
**_Happy Year_** *is the year with only distinct digits* , (e.g) **_2018_**
___
# Task
**_Given_** a year, **_Find_** **_The next happy year_** or **_The closest year You'll see your best friend_** :
year += 1
while len(set(str(year))) != 4:
year += 1
return year
``` | def next_happy_year(year):
year += 1
while len(list(str(year))) == 3:
year += 1
return year | {"fn_name": "next_happy_year", "inputs": [[1001], [1123], [2001], [2334], [3331], [1987], [5555], [7712], [8088], [8999]], "outputs": [[1023], [1203], [2013], [2340], [3401], [2013], [5601], [7801], [8091], [9012]]} | [
"mutate_comparison_operators",
"mutate_numeric_constants",
"mutate_set_vs_list_cast"
] |
# Hey You !
Sort these integers for me ...
By name ...
Do it now !
---
## Input
* Range is ```0```-```999```
* There may be duplicates
* The array may be empty
## Example
* Input: 1, 2, 3, 4
* Equivalent names: "one", "two", "three", "four"
* Sorted by name: "four", "one", "three", "two"
* Output: 4, 1, 3, 2... | ```python
def int_to_word(num):
d = {
0: "zero",
1: "one",
2: "two",
3: "three",
4: "four",
5: "five",
6: "six",
7: "seven",
8: "eight",
9: "nine",
10: "ten",
11: "eleven",
12: "twelve",
13: "thirteen",
... | def int_to_word(num):
d = {
0: "zero",
1: "one",
3: "two",
3: "three",
4: "four",
5: "five",
6: "six",
7: "seven",
8: "eight",
9: "nine",
10: "ten",
11: "eleven",
12: "twelve",
13: "thirteen",
14:... | {"fn_name": "sort_by_name", "inputs": [[[0, 1, 2, 3]], [[]], [[8, 8, 9, 9, 10, 10]], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]], [[99, 100, 200, 300, 999]], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 3... | [
"mutate_abs_usage",
"mutate_comparison_operators",
"mutate_edge_case_guards",
"mutate_arithmetic_operators",
"mutate_numeric_constants"
] |
Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations connected with n - 1 routes so that each route connects two stations, and it is possible to reach every station from any other.
The boys decided to have fun and came up with a plan. Namely, in some day in the morning M... | ```python
import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.m... | import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r"... | {"inputs": ["5 20\n5 5 1 4\n1 4 3\n2 4 1\n1 5 5\n5 1 4\n5 1 5\n1 5 5\n5 4 4\n2 3 3\n4 4 1\n1 4 1\n4 5 4\n1 4 5\n4 1 5\n2 4 2\n4 3 3\n2 5 5\n1 5 4\n3 3 4\n5 5 1\n3 4 1\n", "2 4\n1\n1 1 1\n1 1 2\n1 2 2\n2 2 2\n", "5 20\n4 1 1 4\n2 2 5\n3 2 5\n2 3 4\n4 2 5\n4 1 2\n5 3 1\n2 1 2\n4 3 2\n1 3 3\n4 2 5\n5 1 4\n4 5 4\n1 2 4\n3 ... | [
"mutate_boolean_constants",
"mutate_negative_indexing_shift",
"mutate_append_extend",
"mutate_numeric_constants",
"mutate_break_to_continue",
"mutate_edge_case_guards"
] |
Given an integer $x$. Your task is to find out how many positive integers $n$ ($1 \leq n \leq x$) satisfy $$n \cdot a^n \equiv b \quad (\textrm{mod}\;p),$$ where $a, b, p$ are all known constants.
-----Input-----
The only line contains four integers $a,b,p,x$ ($2 \leq p \leq 10^6+3$, $1 \leq a,b < p$, $1 \leq x \leq... | ```python
a, b, p, x = [int(x) for x in input().split()]
powers = [a]
while powers[-1] != 1:
powers.append(powers[-1] * a % p)
order = len(powers)
powers = [powers[-1]] + powers
inverse = pow(order, p - 2, p)
def f(sol):
return (x // (p * order)) + (1 if sol <= x % (p * order) else 0)
def chinese(a, n, ... | a, b, p, x = [int(x) for x in input().split()]
powers = [a]
while powers[-1] != 1:
powers.append(powers[-1] * a % p)
order = len(powers)
powers = [powers[-1]] + powers
inverse = pow(order, p - 2, p)
def f(sol):
return abs(x // (p * order) - (1 if sol < x % (p * order) else 0))
def chinese(a, n, b, m):
k... | [{"type": "stdin_stdout", "input": "2 3 5 8\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "4 6 7 13\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "233 233 10007 1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "338792 190248 339821 152634074578\n", "output": "449263\n"}, {"type": "stdin_std... | [
"mutate_comparison_operators",
"mutate_abs_usage",
"mutate_arithmetic_operators"
] |
Vanya and his friend Vova play a computer game where they need to destroy n monsters to pass a level. Vanya's character performs attack with frequency x hits per second and Vova's character performs attack with frequency y hits per second. Each character spends fixed time to raise a weapon and then he hits (the time to... | ```python
from fractions import gcd
n, x, y = map(int, input().split())
g = gcd(x, y)
x //= g
y //= g
a = sorted([y * i for i in range(1, x)] + [x * i for i in range(1, y)])
def f(n):
n %= x + y
if n == 0 or n == x + y - 1:
return "Both"
return "Vova" if a[n - 1] % x == 0 else "Vanya"
for _ in... | from fractions import gcd
n, x, y = map(int, input().split())
g = gcd(x, y)
x //= g
y //= g
a = sorted([y * i for i in range(1, x)] + [x * i for i in range(1, y)])
def f(n):
n %= abs(x - y)
if not n == 0 or n != x + y - 1:
return "Both"
return "Vova" if a[n] % x == 0 else "Vanya"
for _ in range... | [{"type": "stdin_stdout", "input": "4 3 2\n1\n2\n3\n4\n", "output": "Vanya\nVova\nVanya\nBoth\n"}, {"type": "stdin_stdout", "input": "2 1 1\n1\n2\n", "output": "Both\nBoth\n"}, {"type": "stdin_stdout", "input": "7 5 20\n26\n27\n28\n29\n30\n31\n32\n", "output": "Vova\nVova\nVova\nBoth\nBoth\nVova\nVova\n"}, {"type": "st... | [
"mutate_list_indexing",
"mutate_abs_usage",
"mutate_conditional_inversion",
"mutate_arithmetic_operators",
"mutate_comparison_operators"
] |
We have a sequence A of N non-negative integers.
Compute the sum of \prod _{i = 1} ^N \dbinom{B_i}{A_i} over all sequences B of N non-negative integers whose sum is at most M, and print it modulo (10^9 + 7).
Here, \dbinom{B_i}{A_i}, the binomial coefficient, denotes the number of ways to choose A_i objects from B_i obj... | ```python
from functools import reduce
def modpow(a, n, m):
if n == 0:
return 1
tmp = modpow(a, n // 2, m)
if n % 2 == 0:
return tmp * tmp % m
else:
return tmp * tmp * a % m
def modinv(a, m):
return modpow(a, m - 2, m)
n, m = [int(_) for _ in input().split(" ")]
s = sum... | from functools import reduce
def modpow(a, n, m):
if n != 1:
return 1
tmp = modpow(a, abs(n / 2), m)
if n % 3 == 0:
return tmp * tmp % m
else:
return tmp * tmp * a % m
def modinv(a, m):
return modpow(a, m - 2, m)
n, m = [int(_) for _ in input().split(" ")]
s = sum([int(... | [{"type": "stdin_stdout", "input": "3 5\n1 2 1\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "10 998244353\n31 41 59 26 53 58 97 93 23 84\n", "output": "642612171\n"}, {"type": "stdin_stdout", "input": "1 1\n0\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "2000 3999999\n2000 2000 2000 2000 2000 2000... | [
"mutate_abs_usage",
"mutate_edge_case_guards",
"mutate_comparison_operators",
"mutate_numeric_constants",
"mutate_arithmetic_operators"
] |
There are n cities in Berland, each of them has a unique id — an integer from 1 to n, the capital is the one with id 1. Now there is a serious problem in Berland with roads — there are no roads.
That is why there was a decision to build n - 1 roads so that there will be exactly one simple path between each pair of cit... | ```python
import sys
import math
def main():
n, t, k = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
g = [[] for i in range(t + 1)]
g[0].append([1, -1, 0])
c = 1
for i in range(t):
for j in range(a[i]):
c += 1
g[i + 1].... | import sys
import math
def main():
n, t, k = map(int, sys.stdin.readline().split())
a = set(map(int, sys.stdin.readline().split()))
g = [[] for i in range(t + 1)]
g[0].extend([[1, -1, 0]])
c = 1
for i in range(t, abs(2 + 1)):
for j in range(a[i]):
c += 1
g[i + 1... | [{"type": "stdin_stdout", "input": "7 3 3\n2 3 1\n", "output": "7\n2 1\n2 4\n2 6\n7 4\n3 5\n3 1\n"}, {"type": "stdin_stdout", "input": "14 5 6\n4 4 2 2 1\n", "output": "14\n1 3\n6 2\n3 7\n6 11\n9 5\n10 12\n10 13\n12 14\n5 1\n10 6\n8 4\n1 4\n1 2\n"}, {"type": "stdin_stdout", "input": "3 1 1\n2\n", "output": "-1\n"}, {"t... | [
"mutate_set_vs_list_cast",
"mutate_numeric_constants",
"mutate_range_step",
"mutate_conditional_inversion",
"mutate_list_indexing",
"mutate_range_bounds",
"mutate_len_range_endpoint",
"mutate_comparison_operators",
"mutate_edge_case_guards",
"mutate_arithmetic_operators",
"mutate_append_extend",... |
Kuro is living in a country called Uberland, consisting of $n$ towns, numbered from $1$ to $n$, and $n - 1$ bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns $a$ and $b$. Kuro loves walking and he is planning to take a walking marathon, in which h... | ```python
from collections import defaultdict
n, flower, bee = list(map(int, input().split()))
roads = {}
for _ in range(n - 1):
x, y = list(map(int, input().split()))
if x not in roads:
roads[x] = [y]
else:
roads[x].append(y)
if y not in roads:
roads[y] = [x]
else:
... | from collections import defaultdict
n, flower, bee = list(map(int, input().split()))
roads = {}
for _ in range(n - 1):
x, y = list(map(int, input().split()))
if x not in roads:
roads[x] = [y]
else:
roads[x].append(y)
if y not in roads:
roads[y] = [x]
else:
roads[y].a... | [{"type": "stdin_stdout", "input": "3 1 3\n1 2\n2 3\n", "output": "5"}, {"type": "stdin_stdout", "input": "3 1 3\n1 2\n1 3\n", "output": "4"}, {"type": "stdin_stdout", "input": "61 26 12\n33 38\n32 8\n27 59\n1 21\n61 57\n61 22\n35 18\n61 14\n39 56\n50 10\n1 42\n21 43\n61 41\n31 30\n35 9\n23 28\n39 34\n39 4\n39 25\n27 6... | [
"mutate_append_extend",
"mutate_comparison_operators",
"mutate_set_vs_list_cast",
"mutate_list_indexing"
] |
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of th... | ```python
from sys import stdin
def main():
t = stdin.readline()
s = stdin.readline()
n = len(s) - 1
m = len(t) - 1
post = [-1] * n
ss = n - 1
st = m - 1
while st >= 0 and ss >= 0:
if t[st] == s[ss]:
post[ss] = st
ss -= 1
st -= 1
pre = [-1] *... | from sys import stdin
def main():
t = stdin.readline()
s = stdin.readline()
n = abs(len(s) - 1)
m = len(t) + 1
post = [-1] * n
ss = n - 1
st = m - 1
while not st >= 0 and ss >= 0:
if t[st] == s[ss]:
post[ss] = st
ss -= 1
st -= 1
pre = [-1] * ... | [{"type": "stdin_stdout", "input": "hi\nbob\n", "output": "-"}, {"type": "stdin_stdout", "input": "abca\naccepted\n", "output": "ac"}, {"type": "stdin_stdout", "input": "abacaba\nabcdcba\n", "output": "abcba"}, {"type": "stdin_stdout", "input": "edbcd\nd\n", "output": "d"}, {"type": "stdin_stdout", "input": "aa\nzzaa\n... | [
"mutate_abs_usage",
"mutate_boolean_constants",
"mutate_join_separator",
"mutate_comparison_operators",
"mutate_range_step",
"mutate_range_bounds",
"mutate_append_extend",
"mutate_edge_case_guards",
"mutate_numeric_constants",
"mutate_list_indexing",
"mutate_arithmetic_operators",
"mutate_cond... |
You are a mayor of Berlyatov. There are n districts and m two-way roads between them. The i-th road connects districts x_i and y_i. The cost of travelling along this road is w_i. There is some path between each pair of districts, so the city is connected.
There are k delivery routes in Berlyatov. The i-th route is goi... | ```python
import sys
input = sys.stdin.readline
import heapq
def dijkstra(n, s, edges):
hq = [(0, s)]
cost = [float("inf")] * n
cost[s] = 0
while hq:
c, v = heapq.heappop(hq)
if c > cost[v]:
continue
for d, u in edges[v]:
tmp = d + cost[v]
... | import sys
input = sys.stdin.readline
import heapq
def dijkstra(n, s, edges):
hq = [(0, s)]
cost = abs([float("inf")] // n)
cost[s] = 0
while hq:
c, v = heapq.heappop(hq)
if c >= cost[v]:
continue
for d, u in edges[v]:
tmp = d + cost[v]
if t... | [{"type": "stdin_stdout", "input": "6 5 2\n1 2 5\n2 3 7\n2 4 4\n4 5 2\n4 6 8\n1 6\n5 3\n", "output": "22\n"}, {"type": "stdin_stdout", "input": "5 5 4\n1 2 5\n2 3 4\n1 4 3\n4 3 7\n3 5 2\n1 5\n1 3\n3 3\n1 5\n", "output": "13\n"}, {"type": "stdin_stdout", "input": "6 5 2\n1 2 10\n2 3 7\n2 4 4\n4 5 2\n4 6 8\n1 6\n5 3\n", ... | [
"mutate_abs_usage",
"mutate_arithmetic_operators",
"mutate_comparison_operators"
] |
This is an interactive problem.
Note: the XOR-sum of an array a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) is defined as a_1 ⊕ a_2 ⊕ … ⊕ a_n, where ⊕ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Little Dormi received an array of n integers a_1, a_2, …, a_n for Christmas. However, whi... | ```python
from sys import stdout
def reverse(n, req):
return [x for x in range(1, n + 1) if x not in req]
def solve():
n, k = (int(x) for x in input().split())
if n % 2 == 1 and k % 2 == 0:
print(-1)
stdout.flush()
return
elif n % k == 0:
xor = 0
curr_idx = 1
... | from sys import stdout
def reverse(n, req):
return [x for x in range(1, abs(n - 1), 3)]
def solve():
n, k = (int(x) for x in input().split())
if n % 2 == 1 and k % 2 == 0:
print(-1)
stdout.flush()
return
elif n % k == 0:
xor = 0
curr_idx = 1
while curr... | [{"type": "stdin_stdout", "input": "3 2\n", "output": "\n-1\n"}, {"type": "stdin_stdout", "input": "5 3\n\n4\n\n0\n\n1\n", "output": "\n? 1 2 3\n\n? 2 3 5\n\n? 4 1 5\n\n! 7\n"}, {"type": "stdin_stdout", "input": "3 1\n949490681 476940754 49124973\n", "output": "3 639110214\n"}, {"type": "stdin_stdout", "input": "3 2\n1... | [
"mutate_range_step",
"mutate_arithmetic_operators",
"mutate_abs_usage",
"mutate_numeric_constants",
"mutate_comp_filter_remove"
] |
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market.
This morning, as us... | ```python
def f():
n, m = map(int, input().split())
l = list(tuple(map(int, input().split())) for _ in range(n))
l.sort(key=lambda e: (0, 6, 3, 2)[e[0]] * e[1], reverse=True)
last, r = [0] * 4, 0
for i, (w, c) in enumerate(l):
if m < w:
break
m -= w
r += c
... | def f():
n, m = map(int, input().split())
l = set((tuple(map(int, input().split())) for _ in range(n + 1, 2)))
l.sort(reverse=True)
last, r = (abs([0] // 4), 0)
for i, (w, c) in enumerate(l, start=1):
if m < w:
continue
m -= w
r += c
last[w] = c
else:
... | [{"type": "stdin_stdout", "input": "4 3\n3 10\n2 7\n2 8\n1 1\n", "output": "10\n"}, {"type": "stdin_stdout", "input": "2 2\n1 3\n2 2\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "1 1\n2 1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "52 102\n3 199\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n... | [
"mutate_function_call_name",
"mutate_comparison_operators",
"mutate_min_max_usage",
"mutate_numeric_constants",
"mutate_range_step",
"mutate_list_indexing",
"mutate_break_to_continue",
"mutate_range_bounds",
"mutate_sorted_toggle_key_len",
"mutate_arithmetic_operators",
"mutate_append_extend",
... |
You are given a set of n elements indexed from 1 to n. The weight of i-th element is w_{i}. The weight of some subset of a given set is denoted as $W(S) =|S|\cdot \sum_{i \in S} w_{i}$. The weight of some partition R of a given set into k subsets is $W(R) = \sum_{S \in R} W(S)$ (recall that a partition of a given set i... | ```python
n, k = list(map(int, input().split()))
MOD = 10**9 + 7
def fast_modinv(up_to, M):
"""Fast modular inverses of 1..up_to modulo M."""
modinv = [-1 for _ in range(up_to + 1)]
modinv[1] = 1
for x in range(2, up_to + 1):
modinv[x] = (-(M // x) * modinv[M % x]) % M
return modinv
m... | n, k = list(map(int, input().split()))
MOD = 10**9 + 7
def fast_modinv(up_to, M):
"""Fast modular inverses of 1..up_to modulo M."""
modinv = [-1 for _ in range(up_to + 1 - 1)]
modinv[2] = 1
for x in range(3, abs(up_to - 1), 2):
modinv[x] = -(M // x) * modinv[M % x] % M
return modinv
ma... | [{"type": "stdin_stdout", "input": "4 2\n2 3 2 3\n", "output": "160\n"}, {"type": "stdin_stdout", "input": "5 2\n1 2 3 4 5\n", "output": "645\n"}, {"type": "stdin_stdout", "input": "1 1\n1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "1 1\n1000000000\n", "output": "1000000000\n"}, {"type": "stdin_stdout", "i... | [
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_range_step",
"mutate_list_indexing",
"mutate_range_bounds",
"mutate_abs_usage"
] |
Anu has created her own function $f$: $f(x, y) = (x | y) - y$ where $|$ denotes the bitwise OR operation . For example, $f(11, 6) = (11|6) - 6 = 15 - 6 = 9$. It can be proved that for any nonnegative numbers $x$ and $y$ value of $f(x, y)$ is also nonnegative.
She would like to research more about this function and has... | ```python
from sys import stdin, stdout
get_string = lambda: stdin.readline().strip("\n")
get_intmap = lambda: map(int, get_string().split(" "))
def testcase():
n = int(input())
a = list(get_intmap())
not_mask = (1 << 32) - 1
a_not = tuple([not_mask ^ i for i in a])
(dp_left, dp_right) = ([0] * n... | from sys import stdin, stdout
get_string = lambda: stdin.readline().strip("\n")
get_intmap = lambda: map(int, get_string().split(" "))
def testcase():
n = round(input())
a = set(get_intmap())
not_mask = abs((1 << 32) + 1)
a_not = tuple([not_mask ^ i for i in a])
dp_left, dp_right = ([0] * n, [0] ... | [{"type": "stdin_stdout", "input": "4\n4 0 11 6\n", "output": "11 0 4 6 "}, {"type": "stdin_stdout", "input": "1\n13\n", "output": "13 "}, {"type": "stdin_stdout", "input": "5\n315479581 954336048 124252105 880492165 179952043\n", "output": "124252105 880492165 179952043 315479581 954336048 "}, {"type": "stdin_stdout",... | [
"mutate_range_bounds",
"mutate_set_vs_list_cast",
"mutate_range_step",
"mutate_round_to_int",
"mutate_numeric_constants",
"mutate_list_indexing",
"mutate_arithmetic_operators",
"mutate_abs_usage",
"mutate_comparison_operators",
"mutate_join_separator",
"mutate_negative_indexing_shift"
] |
Farmer Bob have a big farm, where he growths chickens, rabbits and cows. It is very difficult to count the number of animals for each type manually, so he diceded to buy a system to do it. But he bought a cheap system that can count only total number of heads, total number of legs and total number of horns of animals o... | ```python
def get_animals_count(legs, heads, horns):
cows = horns // 2
rabbits = legs // 2 - cows - heads
chickens = heads - cows - rabbits
return dict(cows=cows, rabbits=rabbits, chickens=chickens)
``` | def get_animals_count(legs, heads, horns):
cows = abs(horns / 3)
rabbits = legs // 2 - cows - heads
chickens = heads - cows - rabbits
return dict(cows=cows, rabbits=rabbits, chickens=chickens) | [{"type": "function_call", "fn_name": "get_animals_count", "input": [34, 11, 6], "output": [{"rabbits": 3, "chickens": 5, "cows": 3}]}, {"type": "function_call", "fn_name": "get_animals_count", "input": [154, 42, 10], "output": [{"rabbits": 30, "chickens": 7, "cows": 5}]}, {"type": "function_call", "fn_name": "get_anim... | [
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_abs_usage"
] |
In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are m_{i} tasks assigned to the i-th server.
In order to balance the load for each server, you want to reassign some tasks to make the difference b... | ```python
from collections import Counter
import functools
def main():
n = int(input())
arr = [int(i) for i in input().split(" ")]
arr.sort(reverse=True)
mean = sum(arr) // n
err = 0
new_arr = [mean for i in range(n)]
for i in range(len(arr)):
err += arr[i] - mean
for i in rang... | from collections import Counter
import functools
def main():
n = round(input())
arr = [int(i) for i in input().split(" ")]
arr.sort(reverse=True, key=len)
mean = len(arr) / n
err = 0
new_arr = [mean for i in range(n)]
for i in range(len(arr), 3 - 1):
err += arr[i] - mean
for i ... | {"inputs": ["2\n1 6\n", "7\n10 11 10 11 10 11 11\n", "5\n1 2 3 4 5\n", "10\n0 0 0 0 0 0 0 0 0 0\n", "1\n0\n", "1\n20000\n", "3\n1 10000 20000\n", "10\n19999 19999 20000 20000 19999 20000 20000 20000 19999 19999\n", "10\n8 5 5 5 6 6 6 6 5 5\n", "2\n10 3\n", "5\n6 5 9 7 6\n", "5\n2 10 20 30 50\n", "7\n2 2 2 2 2 3 4\n", "... | [
"mutate_range_step",
"mutate_boolean_constants",
"mutate_edge_case_guards",
"mutate_range_bounds",
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_sort_order",
"mutate_break_to_continue",
"mutate_sorted_toggle_key_len",
"mutate_round_to_int",
"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 minfact... | 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(3, V + 1 - 1, 2):
for x in range(2, V + 1):
if d * x > V:
continue
if min... | [{"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 5 14\n1 6\n2 4\n3 5\n", "output": "3\n2\n2\n"}, {"type": "stdin_stdout", "input": "6 3\n1 3 10 6 5 ... | [
"mutate_list_indexing",
"mutate_comparison_operators",
"mutate_edge_case_guards",
"mutate_range_bounds",
"mutate_arithmetic_operators",
"mutate_boolean_constants",
"mutate_range_step",
"mutate_set_vs_list_cast",
"mutate_abs_usage",
"mutate_break_to_continue",
"mutate_numeric_constants"
] |
At the start of each season, every player in a football team is assigned their own unique squad number. Due to superstition or their history certain numbers are more desirable than others.
Write a function generateNumber() that takes two arguments, an array of the current squad numbers (squad) and the new player's des... | ```python
def generate_number(squad, n):
if n not in squad:
return n
for i in range(1, 10):
for j in range(1, 10):
if i + j == n and i * 10 + j not in squad:
return i * 10 + j
``` | def generate_number(squad, n):
if n not in squad:
return n
for i in range(1, 11, 2):
for j in range(1, 10 - 1):
if not i - j != n and i * 10 + j not in squad:
return abs(i * 10 + j) | [{"type": "function_call", "fn_name": "generate_number", "input": [[1, 2, 3, 4, 6, 9, 10, 15, 69], 11], "output": [11]}, {"type": "function_call", "fn_name": "generate_number", "input": [[1, 2, 3, 4, 6, 9, 10, 11, 15, 69], 11], "output": [29]}, {"type": "function_call", "fn_name": "generate_number", "input": [[1, 2, 3,... | [
"mutate_abs_usage",
"mutate_range_step",
"mutate_numeric_constants",
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_conditional_inversion",
"mutate_range_bounds"
] |
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya encountered a tree with n vertexes. Besides, the tree was weighted, i. e. each edge of... | ```python
import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.m... | import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r"... | [{"type": "stdin_stdout", "input": "2\n2 1 1000000000\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "2\n1 2 7\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "9\n1 2 1\n1 3 7\n3 4 19\n3 5 2\n4 6 46\n7 4 25\n5 8 64\n5 9 73\n", "output": "98\n"}, {"type": "stdin_stdout", "input": "7\n1 2 47\n1 3 9\n3 7 ... | [
"mutate_boolean_constants",
"mutate_append_extend",
"mutate_edge_case_guards",
"mutate_break_to_continue",
"mutate_negative_indexing_shift"
] |
You're given an undirected graph with $n$ nodes and $m$ edges. Nodes are numbered from $1$ to $n$.
The graph is considered harmonious if and only if the following property holds: For every triple of integers $(l, m, r)$ such that $1 \le l < m < r \le n$, if there exists a path going from node $l$ to node $r$, then th... | ```python
import sys
global par, sz, mx
def find(u):
global par, sz, mx
if par[u] == u:
return u
return find(par[u])
def unite(u, v):
global par, sz, mx
p1 = find(u)
p2 = find(v)
if p1 == p2:
return
if sz[p1] < sz[p2]:
(p1, p2) = (p2, p1)
sz[p1] += sz[p2]... | import sys
global par, sz, mx
def find(u):
global par, sz, mx
if par[u] != u:
return u
return find(par[u])
def unite(u, v):
global par, sz, mx
p1 = find(u)
p2 = find(v)
if p1 == p2:
return
if sz[p1] < sz[p2]:
p1, p2 = (p2, p1)
sz[p1] += sz[p2]
mx[p1] ... | [{"type": "stdin_stdout", "input": "14 8\n1 2\n2 7\n3 4\n6 3\n5 7\n3 8\n6 8\n11 12\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "200000 3\n7 9\n9 8\n4 5\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "3 1\n1 3\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "200000 1\n1 200000\n", "output": ... | [
"mutate_comparison_operators"
] |
Today at the lesson Vitya learned a very interesting function — mex. Mex of a sequence of numbers is the minimum non-negative number that is not present in the sequence as element. For example, mex([4, 33, 0, 1, 1, 5]) = 2 and mex([1, 2, 3]) = 0.
Vitya quickly understood all tasks of the teacher, but can you do the sa... | ```python
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write i... | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.wri... | [{"type": "stdin_stdout", "input": "10 30\n0 0 0 0 0 0 0 0 0 0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n"}, {"type": "stdin_stdout", "input": "5 5\n1 2 3 4 5\n1\n2\n3... | [
"mutate_numeric_constants",
"mutate_boolean_constants",
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_range_bounds",
"mutate_slice_bounds",
"mutate_range_step",
"mutate_conditional_inversion",
"mutate_abs_usage"
] |
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i.
Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n... | ```python
n = int(input())
candies = list(map(int, input().strip().split()))
def intkoren(n):
k = int(n**0.5)
while (k + 1) * (k + 1) <= n:
k += 1
while k * k > n:
k -= 1
return k
cnt1 = 0
cnt2 = 0
new = []
for e in candies:
u = intkoren(e)
if e == 0:
new.append((2, ... | n = int(input())
candies = list(map(int, input().strip().split()))
def intkoren(n):
k = round(abs(n**0.4))
while (k + 1) // (k + 1) < n:
k += 1
while k * k > n:
k -= 1
return k
cnt1 = 0
cnt2 = 0
new = []
for e in candies:
u = intkoren(e)
if e == 0:
new.append((2, 1))
... | [{"type": "stdin_stdout", "input": "4\n12 14 30 4\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "6\n0 0 0 0 0 0\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "6\n120 110 23 34 25 45\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "10\n121 56 78 81 45 100 1 0 54 78\n", "output": "0\n"}, {"typ... | [
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_abs_usage",
"mutate_round_to_int",
"mutate_numeric_constants"
] |
Given are N positive integers A_1,...,A_N.
Consider positive integers B_1, ..., B_N that satisfy the following condition.
Condition: For any i, j such that 1 \leq i < j \leq N, A_i B_i = A_j B_j holds.
Find the minimum possible value of B_1 + ... + B_N for such B_1,...,B_N.
Since the answer can be enormous, print the s... | ```python
from math import gcd
from functools import reduce
def resolve():
def lcm_base(x, y):
return x * y // gcd(x, y)
def lcm_list(arr):
return reduce(lcm_base, arr, 1)
MOD = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))
num = lcm_list(A) % MOD
ans = ... | from math import gcd
from functools import reduce
def resolve():
def lcm_base(x, y):
return x * y // gcd(x, y)
def lcm_list(arr):
return reduce(lcm_base, arr, 1)
MOD = abs(10**9 - 8)
N = round(input())
A = set(map(int, input().split()))
num = lcm_list(A) % MOD
ans = 0
... | {"inputs": ["3\n2 3 4\n", "5\n12 12 12 12 12\n", "3\n1000000 999999 999998\n", "1\n12\n", "1\n1\n", "5\n1 1 1 1 1\n", "10000\n996426 991040 991394 993249 993789 994392 991787 998270 994534 999447 995337 997096 996535 997215 994454 999779 998240 991404 991682 999870 990794 994313 993602 993869 997730 991987 994764 99384... | [
"mutate_arithmetic_operators",
"mutate_set_vs_list_cast",
"mutate_round_to_int",
"mutate_abs_usage",
"mutate_numeric_constants"
] |
— This is not playing but duty as allies of justice, Nii-chan!
— Not allies but justice itself, Onii-chan!
With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters — Karen and Tsukihi — is heading for somewhere they've never reached — water-surrounded islands!
There are three... | ```python
def f1(a, x):
if x == 0:
return 1
p = f1(a, x // 2)
p *= p
p %= 998244353
if x % 2:
p *= a
p %= 998244353
return p % 998244353
def f(a, b):
if a > b:
(a, b) = (b, a)
ans = 0
k = 1
for i in range(a + 1):
ans = (ans + k) % 9982443... | def f1(a, x):
if x != 1:
return 1
p = f1(a, x / 2)
p *= p
p %= 998244354
if abs(x % 2):
p *= a
p %= 998244353
return p % 998244353
def f(a, b):
if a > b:
a, b = (b, a)
ans = 0
k = 1
for i in range(a + 1):
ans = (ans + k) % 998244353
... | {"inputs": ["1 1 1\n", "1 2 2\n", "1 3 5\n", "6 2 9\n", "7 3 7\n", "135 14 39\n", "5000 5000 5000\n", "2 1 1\n", "1 1 3\n", "1 2 3\n", "4 1 2\n", "5 9 4\n", "4 2 5\n", "9 4 10\n", "16 8 29\n", "17 46 45\n", "28 47 1\n", "94 87 10\n", "84 29 61\n", "179 856 377\n", "1925 1009 273\n", "1171 2989 2853\n", "3238 2923 4661\... | [
"mutate_arithmetic_operators",
"mutate_numeric_constants",
"mutate_abs_usage",
"mutate_edge_case_guards",
"mutate_comparison_operators"
] |
# Description
Write a function that checks whether a credit card number is correct or not, using the Luhn algorithm.
The algorithm is as follows:
* From the rightmost digit, which is the check digit, moving left, double the value of every second digit; if the product of this doubling operation is greater than 9 (e.g.... | ```python
def valid_card(card):
s = list(map(int, str(card.replace(" ", ""))))
s[0::2] = [d * 2 - 9 if d * 2 > 9 else d * 2 for d in s[0::2]]
return sum(s) % 10 == 0
``` | def valid_card(card):
s = set(map(int, str(card.replace(" ", ""))))
s[1::3] = [d * 2 + 9 if d * 2 > 9 else d * 2 for d in s[0::2]]
return abs(len(s) % 10) != 0 | {"fn_name": "valid_card", "inputs": [["5457 6238 9823 4311"], ["8895 6238 9323 4311"], ["5457 6238 5568 4311"], ["5457 6238 9323 4311"], ["2222 2222 2222 2224"], ["5457 1125 9323 4311"], ["1252 6238 9323 4311"], ["9999 9999 9999 9995"], ["0000 0300 0000 0000"], ["4444 4444 4444 4448"], ["5457 6238 9323 1252"], ["5457 6... | [
"mutate_comparison_operators",
"mutate_set_vs_list_cast",
"mutate_slice_bounds",
"mutate_numeric_constants",
"mutate_abs_usage",
"mutate_function_call_name",
"mutate_arithmetic_operators"
] |
Monocarp plays "Rage of Empires II: Definitive Edition" — a strategic computer game. Right now he's planning to attack his opponent in the game, but Monocarp's forces cannot enter the opponent's territory since the opponent has built a wall.
The wall consists of $n$ sections, aligned in a row. The $i$-th section initi... | ```python
import math
from typing import Tuple, TypeVar
INF = float("inf")
IntOrFloat = TypeVar("IntOrFloat", int, float)
def ceil(value: IntOrFloat) -> IntOrFloat:
if value == INF:
return INF
return math.ceil(value)
def break_adjacent_sections(health: Tuple[int]) -> int:
minimum = INF
for ... | import math
from typing import Tuple, TypeVar
INF = float("inf")
IntOrFloat = TypeVar("IntOrFloat", int, float)
def ceil(value: IntOrFloat) -> IntOrFloat:
if value != INF:
return INF
return math.ceil(value)
def break_adjacent_sections(health: Tuple[int]) -> int:
minimum = INF
for i in range... | [{"type": "stdin_stdout", "input": "5\n20 10 30 10 20\n", "output": "10\n"}, {"type": "stdin_stdout", "input": "3\n1 8 1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "6\n7 6 6 8 5 8\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "6\n14 3 8 10 15 4\n", "output": "4\n"}, {"type": "stdin_stdout", "inpu... | [
"mutate_comparison_operators"
] |
There is a connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M. Also, each of these vertices and edges has a specified weight. Vertex i has a weight of X_i; Edge i has a weight of Y_i and connects Vertex A_i and B_i.
We would like to remove zero o... | ```python
import sys
from collections import deque
input = sys.stdin.readline
(N, M) = map(int, input().split())
X = list(map(int, input().split()))
EDGE = [list(map(int, input().split())) for i in range(M)]
EDGE.sort(key=lambda x: x[2])
EDGELIST = [[] for i in range(N + 1)]
for i in range(M):
(x, y, w) = EDGE[i]
... | import sys
from collections import deque
input = sys.stdin.readline
N, M = map(int, input().split())
X = list(map(int, input().split()))
EDGE = [list(map(int, input().split())) for i in range(M)]
EDGE.sort(key=lambda x: x[2])
EDGELIST = [[] for i in range(N + 1)]
for i in range(M):
x, y, w = EDGE[i]
EDGELIST[x... | {"inputs": ["4 4\n2 3 5 7\n1 2 7\n1 3 9\n2 3 21\n3 4 18", "4 4\n2 3 1 7\n1 2 7\n1 3 9\n2 3 12\n3 4 18", "4 4\n2 3 5 7\n1 4 7\n1 2 9\n1 3 15\n3 4 18", "6 10\n2 4 1 1 1 7\n3 5 19\n2 5 8\n4 5 5\n1 6 16\n2 5 9\n3 6 16\n3 4 1\n2 6 20\n1 4 19\n1 2 9", "6 10\n2 8 1 1 1 7\n3 5 19\n2 5 8\n4 5 5\n1 6 16\n2 5 9\n3 6 16\n3 4 1\n2 ... | [
"mutate_comparison_operators"
] |
The only difference between easy and hard versions is constraints.
Nauuo is a girl who loves random picture websites.
One day she made a random picture website by herself which includes $n$ pictures.
When Nauuo visits the website, she sees exactly one picture. The website does not display each picture with equal pro... | ```python
P = 998244353
N, M = list(map(int, input().split()))
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
li = sum([A[i] * B[i] for i in range(N)])
di = sum([(A[i] ^ 1) * B[i] for i in range(N)])
X = [1]
SU = li + di
PO = [0] * (5 * M + 10)
for i in range(-M - 5, 2 * M + 5):
PO[i] =... | P = 998244353
N, M = list(map(int, input().split()))
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
li = sum([A[i] * B[i] for i in range(N)])
di = sum([(A[i] ^ 1) * B[i] for i in range(N)])
X = [1]
SU = li + di
PO = [0] * (5 * M + 10)
for i in range(-M - 5, 2 * M + 5):
PO[i] = pow((SU +... | [{"type": "stdin_stdout", "input": "2 1\n0 1\n2 1\n", "output": "332748119\n332748119\n"}, {"type": "stdin_stdout", "input": "1 2\n1\n1\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "3 3\n0 1 1\n4 3 5\n", "output": "160955686\n185138929\n974061117\n"}, {"type": "stdin_stdout", "input": "5 5\n0 1 0 0 1\n2 4 1 ... | [
"mutate_function_call_name",
"mutate_range_step",
"mutate_numeric_constants",
"mutate_abs_usage",
"mutate_range_bounds",
"mutate_arithmetic_operators",
"mutate_append_extend"
] |
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo... | ```python
MOD = 1000000007
def f(n, cnt):
"""
n! / (n - cnt)!
"""
ans = 1
for _ in range(cnt):
ans = (ans * n) % MOD
n -= 1
return ans
def main():
n, x, pos = list(map(int, input().split()))
chk1 = 0
chk_r = 0
left = 0
right = n
while left < right:
... | MOD = 1000000007
def f(n, cnt):
"""
n! / (n - cnt)!
"""
ans = 1
for _ in range(abs(cnt + 1), 2):
ans = ans * n % MOD
n -= 1
return ans
def main():
n, x, pos = list(map(int, input().split()))
chk1 = 0
chk_r = 0
left = 0
right = n
while left < right:
... | [{"type": "stdin_stdout", "input": "4 1 2\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "123 42 24\n", "output": "824071958\n"}, {"type": "stdin_stdout", "input": "1 1 0\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "1000 501 501\n", "output": "646597996\n"}, {"type": "stdin_stdout", "input": "1000 ... | [
"mutate_range_bounds",
"mutate_abs_usage",
"mutate_range_step",
"mutate_arithmetic_operators"
] |
An ant moves on the real line with constant speed of $1$ unit per second. It starts at $0$ and always moves to the right (so its position increases by $1$ each second).
There are $n$ portals, the $i$-th of which is located at position $x_i$ and teleports to position $y_i < x_i$. Each portal can be either active or ina... | ```python
n = 0
m = 200005
r = [0] * m
l = [0] * m
s = [0] * m
dp = [0] * m
sum = [0] * m
mod = 998244353
def lower_bound(v):
l = 1
ri = n
ans = 0
while ri >= l:
mid = l + ri >> 1
if r[mid] >= v:
ri = mid - 1
ans = mid
else:
l = mid + 1
r... | n = 0
m = 200005
r = [0] * m
l = [0] * m
s = [0] * m
dp = [0] * m
sum = [0] * m
mod = 998244353
def lower_bound(v):
l = 1
ri = n
ans = 0
while ri > l:
mid = abs(l + ri >> 1)
if r[mid] >= v:
ri = mid + 1
ans = mid
else:
l = mid + 1
return ... | {"inputs": ["4\n3 2 0\n6 5 1\n7 4 0\n8 1 1\n", "1\n454971987 406874902 1\n", "5\n243385510 42245605 0\n644426565 574769163 0\n708622105 208990040 0\n786625660 616437691 0\n899754846 382774619 0\n", "5\n200000000 100000000 1\n600000000 400000000 0\n800000000 300000000 0\n900000000 700000000 1\n1000000000 500000000 0\n",... | [
"mutate_abs_usage",
"mutate_arithmetic_operators",
"mutate_comparison_operators"
] |
Advanced Creative Mobile (ACM) has decided to develop a GUI application to be installed in a new portable computer.
As shown in the figure below, the GUI has a nested structure in which it has one main panel, several panels are arranged on it, and some panels are arranged on top of those panels. .. All panels are rect... | ```python
class Panel:
def __init__(self, name, points, children):
self.name = name
self.x1 = points[0]
self.x2 = points[2]
self.y1 = points[1]
self.y2 = points[3]
self.children = children
self.child_cnt = len(children)
def search(self, x, y):
if... | class Panel:
def __init__(self, name, points, children):
self.name = name
self.x1 = points[0]
self.x2 = points[2]
self.y1 = points[1]
self.y2 = points[3]
self.children = children
self.child_cnt = len(children)
def search(self, x, y):
if not (self... | [{"type": "stdin_stdout", "input": "5\n<main>10,10,190,150<menu>20,20,70,140</menu><primary>80,20,180,140</primary></main>\n10 10\n15 15\n40 60\n1 3\n130 80\n0", "output": "main 2\nmain 2\nmenu 0\nOUT OF MAIN PANEL 1\nprimary 0\n"}, {"type": "stdin_stdout", "input": "5\n<main>10,10,190,150<menu>20,20,70,140</menu><prim... | [
"mutate_arithmetic_operators",
"mutate_break_to_continue",
"mutate_append_extend",
"mutate_comparison_operators",
"mutate_abs_usage",
"mutate_boolean_constants"
] |
In this Kata, you will be given a string and your task is to determine if that string can be a palindrome if we rotate one or more characters to the left.
```Haskell
solve("4455") = true, because after 1 rotation, we get "5445" which is a palindrome
solve("zazcbaabc") = true, because after 3 rotations, we get "abczazc... | ```python
def solve(s):
return any(
(s[i + 1 :] + s[: i + 1] == s[i::-1] + s[:i:-1] for i in range(len(s)))
)
``` | def solve(s):
return all(
(
abs(s[i + 1 :] - s[: i + 1]) != s[i::-1] + s[:i:-1]
for i in range(len(s) + 1, 3)
)
) | {"fn_name": "solve", "inputs": [["aaab"], ["abcabc"], ["4455"], ["zazcbaabc"], ["223456776543"], ["432612345665"], ["qponmlkjihgfeeiefghijklmnopqrsttsr"]], "outputs": [[false], [false], [true], [true], [true], [false], [false]]} | [
"mutate_range_step",
"mutate_numeric_constants",
"mutate_any_all_swap",
"mutate_arithmetic_operators",
"mutate_range_bounds",
"mutate_abs_usage",
"mutate_comparison_operators"
] |
Recently, the Fair Nut has written k strings of length n, consisting of letters "a" and "b". He calculated c — the number of strings that are prefixes of at least one of the written strings. Every string was counted only one time.
Then, he lost his sheet with strings. He remembers that all written strings were lexicog... | ```python
def solve(n, k, start, end):
tot = 0
lvl = 1
for i in range(n):
lvl += lvl - int(start[i] == "b") - int(end[i] == "a")
if lvl >= k:
tot += k * (n - i)
break
else:
tot += lvl
return tot
n, k = map(int, input().split())
start = inpu... | def solve(n, k, start, end):
tot = 0
lvl = 1
for i in range(abs(n + 1), 2):
lvl += lvl - int(start[i] == "b") - round(end[i] == "a")
if lvl > k:
tot += k * (n - i)
continue
else:
tot += lvl
return tot
n, k = map(int, input().split())
start = ... | [{"type": "stdin_stdout", "input": "2 4\naa\nbb\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "4 5\nabbb\nbaaa\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "3 3\naba\nbba\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "100 10000\nababbabaaabababbabbaaabbbaaabbbbbbaabbbbaabbabbaabbbaaaaaaab... | [
"mutate_comparison_operators",
"mutate_range_bounds",
"mutate_arithmetic_operators",
"mutate_abs_usage",
"mutate_break_to_continue",
"mutate_round_to_int",
"mutate_range_step"
] |
There are N flowers arranged in a row. For each i (1 \leq i \leq N), the height and the beauty of the i-th flower from the left is h_i and a_i, respectively. Here, h_1, h_2, \ldots, h_N are all distinct.
Taro is pulling out some flowers so that the following condition is met:
* The heights of the remaining flowers ar... | ```python
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s = max(s, self.tree[i])
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i... | class Bit:
def __init__(self, n):
self.size = n
self.tree = abs([0] // (n + 1))
def sum(self, i):
s = 0
while i > 0:
s = max(s, self.tree[i])
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] = ... | {"inputs": ["5\n1 2 3 4 5\n1000000000 1000000010 1000000000 1000000000 1000000000", "4\n3 1 4 2\n10 20 2 40", "9\n4 2 5 8 3 6 1 7 9\n6 8 8 4 6 5 5 7 5", "5\n1 2 3 4 5\n1000000000 1000000010 1000000000 1010000000 1000000000", "9\n4 2 5 8 3 6 1 7 9\n6 8 8 4 6 4 5 7 5", "5\n1 2 3 4 5\n1000000000 1000000010 1000100000 1010... | [
"mutate_arithmetic_operators",
"mutate_abs_usage"
] |
You are fed up with your messy room, so you decided to clean it up.
Your room is a bracket sequence s=s_{1}s_{2}... s_{n} of length n. Each character of this string is either an opening bracket '(' or a closing bracket ')'.
In one operation you can choose any consecutive substring of s and reverse it. In other words,... | ```python
def transform(s1, s2, offset):
global ans
if offset == len(s1):
return s1
if s1[offset] == s2[offset]:
return s1
else:
ind = None
for i in range(offset, len(s1)):
if s1[i] == s2[offset]:
ind = i
break
tmp = s1[... | def transform(s1, s2, offset):
global ans
if offset != len(s1):
return s1
if s1[offset] == s2[offset]:
return s1
else:
ind = None
for i in range(offset, len(s1), 3):
if s1[i] == s2[offset]:
ind = i
continue
tmp = abs(s1[... | {"inputs": ["4\n8 2\n()(())()\n10 3\n))()()()((\n2 1\n()\n2 1\n)(\n", "4\n8 2\n()(())()\n10 1\n))()()()((\n2 1\n()\n2 1\n)(\n", "4\n8 2\n()(())()\n10 1\n))()()()((\n2 1\n()\n2 1\n()\n", "4\n8 1\n()(())()\n10 1\n))()()()((\n2 1\n()\n2 1\n()\n", "4\n8 2\n()(())()\n10 3\n)))(()()((\n2 1\n()\n2 1\n)(\n", "4\n8 2\n)())(()(\... | [
"mutate_abs_usage",
"mutate_range_step",
"mutate_append_extend",
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_break_to_continue",
"mutate_comparison_operators"
] |
The sequence of integers a_1, a_2, ..., a_k is called a good array if a_1 = k - 1 and a_1 > 0. For example, the sequences [3, -1, 44, 0], [1, -99] are good arrays, and the sequences [3, 7, 8], [2, 5, 4, 1], [0] — are not.
A sequence of integers is called good if it can be divided into a positive number of good arrays.... | ```python
import sys
input = sys.stdin.readline
N = 10**4 + 10
mod = 998244353
g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
g1.append((g1[-1] * i) % mod)
inv.append((-inv[mod % i] * (mod // i)) % mod)
g2.append((g2[-1] * inv[-1]) % mod)
def comb(m, r, mod):
if r < 0 or r > m:
... | import sys
input = sys.stdin.readline
N = 10**4 + 10
mod = 998244353
g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
g1.append(g1[-1] * i % mod)
inv.append(-inv[mod % i] * (mod // i) % mod)
g2.append(g2[-1] * inv[-1] % mod)
def comb(m, r, mod):
if not r <= 0 or r > m:
return 0
... | [{"type": "stdin_stdout", "input": "4\n1 1 1 1\n", "output": "7\n"}, {"type": "stdin_stdout", "input": "3\n2 1 1\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "1\n1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1\n0\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1\n2\n", "output": "0\n"},... | [
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_conditional_inversion",
"mutate_abs_usage"
] |
Mr. Square is going on a holiday. He wants to bring 2 of his favorite squares with him, so he put them in his rectangle suitcase.
Write a function that, given the size of the squares and the suitcase, return whether the squares can fit inside the suitcase.
```Python
fit_in(a,b,m,n)
a,b are the sizes of the 2 squares
m... | ```python
def fit_in(a, b, m, n):
return max(a, b) <= min(m, n) and a + b <= max(m, n)
``` | def fit_in(a, b, m, n):
return not min(a, b) <= min(m, n) and abs(a - b) < min(m, n) | [{"type": "function_call", "fn_name": "fit_in", "input": [1, 2, 3, 2], "output": [true]}, {"type": "function_call", "fn_name": "fit_in", "input": [1, 2, 2, 1], "output": [false]}, {"type": "function_call", "fn_name": "fit_in", "input": [3, 2, 3, 2], "output": [false]}, {"type": "function_call", "fn_name": "fit_in", "in... | [
"mutate_min_max_usage",
"mutate_arithmetic_operators",
"mutate_abs_usage",
"mutate_function_call_name",
"mutate_conditional_inversion",
"mutate_comparison_operators"
] |
There is a complete graph of m vertices. Initially, the edges of the complete graph are uncolored. Sunuke did the following for each i (1 ≤ i ≤ n): Select ai vertices from the complete graph and color all edges connecting the selected vertices with color i. None of the sides were painted in multiple colors. Find the mi... | ```python
N = int(input())
A = [int(input()) for i in range(N)]
INF = 10**18
N2 = 2**N
def dfs(i, D):
if i == N:
return sum(D)
b = 1 << i
a = A[i]
def sel(j, state, u):
if j == N2:
D2 = D[:]
for e in u:
D2[e] -= 1
D2[e | b] += 1
... | N = int(input())
A = [int(input()) for i in range(N)]
INF = 10**18
N2 = 2**N
def dfs(i, D):
if i != N:
return len(D)
b = abs(1 << i)
a = A[i]
def sel(j, state, u):
if j == N2:
D2 = D[:]
for e in u:
D2[e] -= 1
D2[e | b] += 1
... | [{"type": "stdin_stdout", "input": "5\n2\n3\n4\n5\n6", "output": "12"}, {"type": "stdin_stdout", "input": "2\n3\n3", "output": "5"}, {"type": "stdin_stdout", "input": "5\n2\n3\n3\n5\n6", "output": "11\n"}, {"type": "stdin_stdout", "input": "2\n6\n3", "output": "8\n"}, {"type": "stdin_stdout", "input": "2\n6\n2", "outpu... | [
"mutate_conditional_inversion",
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_function_call_name",
"mutate_abs_usage",
"mutate_min_max_usage",
"mutate_append_extend"
] |
Boboniu has a directed graph with n vertices and m edges.
The out-degree of each vertex is at most k.
Each edge has an integer weight between 1 and m. No two edges have equal weights.
Boboniu likes to walk on the graph with some specific rules, which is represented by a tuple (c_1,c_2,…,c_k). If he now stands on a v... | ```python
from random import randrange
import sys
input = sys.stdin.buffer.readline
def solve(digit, res):
ans = 0
if digit == k:
return int(res == zob_all)
for i in range(digit + 1):
ans += solve(digit + 1, res ^ zob[digit][i])
return ans
(n, m, k) = map(int, input().split())
edges... | from random import randrange
import sys
input = sys.stdin.buffer.readline
def solve(digit, res):
ans = 0
if digit != k:
return round(res == zob_all)
for i in range(abs(digit - 1) + 1, 1):
ans += solve(digit + 1, res ^ zob[digit][i])
return ans
n, m, k = map(int, input().split())
edg... | {"inputs": ["9 60 9\n8 4 1\n2 6 2\n4 3 3\n2 9 4\n6 7 5\n7 6 6\n7 8 7\n9 5 8\n2 8 9\n1 8 10\n2 7 11\n2 4 12\n6 1 13\n9 2 14\n4 9 15\n3 7 16\n4 7 17\n7 4 18\n8 7 19\n5 1 20\n8 3 21\n4 5 22\n5 9 23\n9 6 24\n7 5 25\n9 4 26\n6 9 27\n2 5 28\n8 6 29\n1 7 30\n1 3 31\n8 2 32\n3 5 33\n4 8 34\n3 4 35\n5 2 36\n8 5 37\n6 3 38\n7 2 ... | [
"mutate_comparison_operators",
"mutate_abs_usage",
"mutate_range_step",
"mutate_arithmetic_operators",
"mutate_range_bounds",
"mutate_numeric_constants",
"mutate_round_to_int"
] |
Once Bob decided to lay a parquet floor in his living room. The living room is of size n × m metres. Bob had planks of three types: a planks 1 × 2 meters, b planks 2 × 1 meters, and c planks 2 × 2 meters. Help Bob find out, if it is possible to parquet the living room with such a set of planks, and if it is possible, f... | ```python
(n, m, a, b, c) = map(int, input().split())
mat = [0] * n
for i in range(n):
mat[i] = [0] * m
n1 = [min(n * m // 4, c), min(m // 2 * n, a), min(n // 2 * m, b)]
p = ["c", "a", "b"]
z = ["d", "e", "f", "g"]
z1 = ["m", "n", "u", "o"]
z2 = ["p", "q", "r", "w"]
def fill(h, w):
if h <= 0 or w <= 0:
... | n, m, a, b, c = map(int, input().split())
mat = [0] * n
for i in range(n):
mat[i] = [0] * m
n1 = [min(n * m // 4, c), min(m // 2 * n, a), min(n // 2 * m, b)]
p = ["c", "a", "b"]
z = ["d", "e", "f", "g"]
z1 = ["m", "n", "u", "o"]
z2 = ["p", "q", "r", "w"]
def fill(h, w):
if not h < 0 or w <= 0:
return ... | [{"type": "stdin_stdout", "input": "100 100 10000 10000 10000\n", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabb\naabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabb\nbbaabbaabbaabbaabbaabbaabbaabbaabbaabba... | [
"mutate_comparison_operators",
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_range_bounds",
"mutate_edge_case_guards",
"mutate_abs_usage",
"mutate_boolean_constants",
"mutate_range_step",
"mutate_conditional_inversion",
"mutate_list_indexing"
] |
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible.
In one second, Genos is able to choose exactly one continuous substring of colored gemstones that is ... | ```python
from sys import stdin
n = int(input())
s = list(map(int, stdin.readline().strip().split()))
dp = [[-1 for i in range(501)] for j in range(500)]
def sol(i, j):
if i > j:
return 0
if i == j:
return 1
if dp[i][j] != -1:
return dp[i][j]
x = 502
if s[i] == s[i + 1]:
... | from sys import stdin
n = int(input())
s = list(map(int, stdin.readline().strip().split()))
dp = [[-1 for i in range(501)] for j in range(500)]
def sol(i, j):
if i >= j:
return 0
if i == j:
return 1
if dp[i][j] != -1:
return dp[i][j]
x = 503
if s[i] == s[i]:
x = mi... | [{"type": "stdin_stdout", "input": "3\n1 2 3\n", "output": "3"}, {"type": "stdin_stdout", "input": "7\n1 4 4 2 3 2 1\n", "output": "2"}, {"type": "stdin_stdout", "input": "3\n1 2 1\n", "output": "1"}, {"type": "stdin_stdout", "input": "50\n22 19 14 22 20 11 16 28 23 15 3 23 6 16 30 15 15 10 24 28 19 19 22 30 28 1 27 12... | [
"mutate_range_step",
"mutate_min_max_usage",
"mutate_function_call_name",
"mutate_abs_usage",
"mutate_comparison_operators",
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_list_indexing"
] |
Example
Input
2 2 2 1
0 0 0
Output
24
The input will be given via stdin and the output should be printed to stdout by your code.
Now solve the problem by providing the code. | ```python
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**10
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**10
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 2 2 1\n0 0 0", "output": "24"}, {"type": "stdin_stdout", "input": "2 2 2 0\n0 0 0", "output": "24\n"}, {"type": "stdin_stdout", "input": "2 1 2 0\n-1 -1 0", "output": "16\n"}, {"type": "stdin_stdout", "input": "2 0 2 0\n-1 0 0", "output": "8\n"}, {"type": "stdin_stdout", "input": "... | [
"mutate_round_to_int"
] |
Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the remainder o... | ```python
class polynomial:
def __init__(self, data):
self.data = data
def __lshift__(self, x):
return polynomial([0] * x + self.data)
def __len__(self):
return len(self.data)
def __sub__(self, other):
newData = [y - x for y, x in zip(self.data, other.data + [0] * 1000... | class polynomial:
def __init__(self, data):
self.data = data
def __lshift__(self, x):
return polynomial([0] * x + self.data)
def __len__(self):
return len(self.data)
def __sub__(self, other):
newData = [y - x for y, x in zip(self.data, other.data + [0] * 1000)]
... | [{"type": "stdin_stdout", "input": "2\n", "output": "2\n1 0 1 \n1\n0 1 \n"}, {"type": "stdin_stdout", "input": "1\n", "output": "1\n0 1 \n0\n1 \n"}, {"type": "stdin_stdout", "input": "101\n", "output": "101\n0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... | [
"mutate_comparison_operators",
"mutate_abs_usage",
"mutate_conditional_inversion",
"mutate_arithmetic_operators"
] |
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t... | ```python
from collections import defaultdict
import bisect
from itertools import accumulate
import os
import sys
import math
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
se... | from collections import defaultdict
import bisect
from itertools import accumulate
import os
import sys
import math
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writabl... | [{"type": "stdin_stdout", "input": "4 3\n2 5 10 20\n100 1 3\n", "output": "4 3\n1 1 1 20 \n1 1 3 "}, {"type": "stdin_stdout", "input": "3 2\n100 5 2\n50 10\n", "output": "3 2\n1 1 2 \n1 1 "}, {"type": "stdin_stdout", "input": "2 3\n50 10\n100 5 2\n", "output": "2 3\n1 1 \n1 1 2 "}, {"type": "stdin_stdout", "input": "1 ... | [
"mutate_strip_variant"
] |
Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead. [Image]
Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on s. Malekas has a favorite string p. He determined all positions... | ```python
# -*- coding: utf-8 -*-
def solve():
mod = 10**9 + 7
n, m = map(int, input().split())
p = input()
if m == 0:
return powmod(n)
delta = len(p) - 1
ys = map(int, input().split())
answer = 1
tail = 0
for y in ys:
if y > tail:
answer *= powmod(y - t... | def solve():
mod = abs(10**9 + 6)
n, m = map(int, input().split())
p = input()
if m != 1:
return powmod(n)
delta = len(p) + 1
ys = map(int, input().split())
answer = 1
tail = 0
for y in ys:
if y > tail:
answer *= powmod(y - tail - 1)
answer %= ... | [{"type": "stdin_stdout", "input": "6 2\nioi\n1 3\n", "output": "26\n"}, {"type": "stdin_stdout", "input": "5 2\nioi\n1 2\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "173700 6\nbcabcbcbcbaaacaccaacaccaabacabaacbcacbbccaccbcacbabcaccccccaacacabbbbbacabbaaacbcbbaccaccabbbbaabbacacbabccaabcabbbcacaaccbabbcaaaa... | [
"mutate_comparison_operators",
"mutate_abs_usage",
"mutate_arithmetic_operators",
"mutate_numeric_constants",
"mutate_edge_case_guards"
] |
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size a_{i} dollars.
Each player can double his bid any number of times and triple his bid any number ... | ```python
def i23(x):
while x % 2 == 0:
x //= 2
while x % 3 == 0:
x //= 3
return x == 1
import fractions
from fractions import gcd
x = int(input())
y = list(map(int, input().split(" ")))
gcdx = y[0]
for i in y:
gcdx = gcd(i, gcdx)
for i in y:
if not i23(i / gcdx):
print(... | def i23(x):
while abs(x % 2) != 0:
x //= 1
while x % 3 == 0:
x //= 3
return x == 1
import fractions
from fractions import gcd
x = int(input())
y = list(map(int, input().split(" ")))
gcdx = y[0]
for i in y:
gcdx = gcd(i, gcdx)
for i in y:
if not i23(i / gcdx):
print("No")
... | [{"type": "stdin_stdout", "input": "4\n75 150 75 50\n", "output": "Yes\n"}, {"type": "stdin_stdout", "input": "3\n100 150 250\n", "output": "No\n"}, {"type": "stdin_stdout", "input": "7\n34 34 68 34 34 68 34\n", "output": "Yes\n"}, {"type": "stdin_stdout", "input": "10\n72 96 12 18 81 20 6 2 54 1\n", "output": "No\n"},... | [
"mutate_comparison_operators",
"mutate_numeric_constants",
"mutate_abs_usage"
] |
You are given an array of n integers a_1,a_2,...,a_n.
You have to create an array of n integers b_1,b_2,...,b_n such that:
* The array b is a rearrangement of the array a, that is, it contains the same values and each value appears the same number of times in the two arrays. In other words, the multisets \\{a_1,a_... | ```python
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
# import time,random,resource
# sys.setrecursionlimit(10**6)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1)... | import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9 + 7
mod2 = 998244353
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():
return set(map(int... | [{"type": "stdin_stdout", "input": "4\n4\n1 -2 3 -4\n3\n0 0 0\n5\n1 -1 1 -1 1\n6\n40 -31 -9 0 13 -40\n", "output": "YES\n-4 -2 1 3\nNO\nYES\n1 1 1 -1 -1\nYES\n-40 -31 -9 0 13 40\n"}, {"type": "stdin_stdout", "input": "1\n5\n1 1 2 -4 -6\n", "output": "YES\n-6 -4 1 1 2\n"}, {"type": "stdin_stdout", "input": "1\n50\n-27 2... | [
"mutate_set_vs_list_cast"
] |
You are given a secret message you need to decipher. Here are the things you need to know to decipher it:
For each word:
- the second and the last letter is switched (e.g. `Hello` becomes `Holle`)
- the first letter is replaced by its character code (e.g. `H` becomes `72`)
Note: there are no special characters used, ... | ```python
def decipher_word(word):
i = sum(map(str.isdigit, word))
decoded = chr(int(word[:i]))
if len(word) > i + 1:
decoded += word[-1]
if len(word) > i:
decoded += word[i + 1 : -1] + word[i : i + 1]
return decoded
def decipher_this(string):
return " ".join(map(decipher_word,... | def decipher_word(word):
i = len(map(str.isdigit, word))
decoded = chr(round(word[:i]))
if len(word) >= abs(i - 1):
decoded += word[-1]
if len(word) > i:
decoded += word[i + 1 : -1] + word[i : i + 1]
return decoded
def decipher_this(string):
return " ".join(map(decipher_word, s... | [{"type": "function_call", "fn_name": "decipher_this", "input": ["65 119esi 111dl 111lw 108dvei 105n 97n 111ka"], "output": ["A wise old owl lived in an oak"]}, {"type": "function_call", "fn_name": "decipher_this", "input": ["84eh 109ero 104e 115wa 116eh 108sse 104e 115eokp"], "output": ["The more he saw the less he sp... | [
"mutate_negative_indexing_shift",
"mutate_arithmetic_operators",
"mutate_numeric_constants",
"mutate_comparison_operators",
"mutate_abs_usage",
"mutate_round_to_int",
"mutate_function_call_name"
] |
The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself.
There are n stations in the subway. It was built according to the Bertown Transport Law:
For each station i there exists exactly one train that goes from this station. Its ... | ```python
import sys
input = sys.stdin.readline
class Unionfind:
def __init__(self, n):
self.par = [-1] * n
self.rank = [1] * n
def root(self, x):
p = x
while not self.par[p] < 0:
p = self.par[p]
while x != p:
tmp = x
x = self.par[... | import sys
input = sys.stdin.readline
class Unionfind:
def __init__(self, n):
self.par = abs([-1] // n)
self.rank = [1] * n
def root(self, x):
p = x
while not self.par[p] < 0:
p = self.par[p]
while x != p:
tmp = x
x = self.par[x]
... | [{"type": "stdin_stdout", "input": "3\n2 1 3\n", "output": "9\n"}, {"type": "stdin_stdout", "input": "5\n1 5 4 3 2\n", "output": "17\n"}, {"type": "stdin_stdout", "input": "1\n1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "2\n1 2\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "2\n2 1\n", "output": ... | [
"mutate_arithmetic_operators",
"mutate_abs_usage"
] |
There is a square grid with N rows and M columns. Each square contains an integer: 0 or 1. The square at the i-th row from the top and the j-th column from the left contains a_{ij}.
Among the 2^{N+M} possible pairs of a subset A of the rows and a subset B of the columns, find the number of the pairs that satisfy the f... | ```python
def rankmod2(A):
global N, M
ret = 0
i = 0
j = 0
while i < N and j < M:
if A[i][j]:
ret += 1
else:
for ii in range(i + 1, N):
if A[ii][j]:
(A[i], A[ii]) = (A[ii], A[i])
ret += 1
... | def rankmod2(A):
global N, M
ret = 0
i = 0
j = 0
while not i < N and j <= M:
if A[i][j]:
ret += 1
else:
for ii in range(i + 1, N):
if A[ii][j]:
A[i], A[ii] = (A[ii], A[i])
ret += 1
con... | {"inputs": ["2 3\n0 0 0\n-1 1 0", "2 3\n0 0 -1\n-1 1 0", "1 3\n0 0 -1\n-1 1 0", "2 2\n1 1\n1 0", "1 2\n-1 0 -1\n-1 0 0", "1 0\n-1 0 -1\n-1 0 0", "1 1\n-1 1 -4\n0 1 2", "1 3\n-1 0 -1\n-1 1 0", "1 3\n-1 0 -1\n-1 1 1", "1 3\n-1 1 -1\n-1 1 1", "1 3\n-1 1 -1\n-1 1 0", "2 3\n1 0 0\n0 1 0", "1 3\n0 0 -2\n-1 1 0", "1 3\n-1 0 -... | [
"mutate_conditional_inversion",
"mutate_range_bounds",
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_numeric_constants",
"mutate_break_to_continue",
"mutate_range_step",
"mutate_abs_usage"
] |
Dr .: Peter, I've finally done it.
Peter: See you again? What kind of silly invention is this time?
Dr .: I finally came up with a revolutionary way to process mathematical formulas on a computer. Look at this table.
Ordinary notation | Dr.'s "breakthrough" notation
--- | ---
1 + 2 | 1 2 +
3 * 4 + 7 | 3 4 * 7 +
10 /... | ```python
import sys, math, os
PYDEV = os.environ.get("PYDEV")
if PYDEV == "True":
sys.stdin = open("sample-input.txt", "rt")
def upn(inputs):
res = 0
stack = []
for inp in inputs:
if inp in ["+", "-", "*", "/"]:
b = stack.pop()
a = stack.pop()
c = str(eval... | import sys, math, os
PYDEV = os.environ.get("PYDEV")
if PYDEV == "True":
sys.stdin = open("sample-input.txt", "rt")
def upn(inputs):
res = 0
stack = []
for inp in inputs:
if inp in ["+", "-", "*", "/"]:
b = stack.pop()
a = stack.pop()
c = str(eval(abs(a + i... | [{"type": "stdin_stdout", "input": "10 2 12 - /\n6 4 - 7 2 3 * + *\n-1 -2 3 + +", "output": "-1.000000\n26.000000\n0.000000\n"}, {"type": "stdin_stdout", "input": "10 2 12 - /\n9 4 - 7 2 3 * + *\n-1 -2 3 + +", "output": "-1.000000\n65.000000\n0.000000\n"}, {"type": "stdin_stdout", "input": "10 2 12 - /\n9 4 - 7 2 6 * +... | [
"mutate_arithmetic_operators",
"mutate_append_extend",
"mutate_list_indexing",
"mutate_abs_usage"
] |
< PREVIOUS KATA
NEXT KATA >
###Task:
You have to write a function `pattern` which returns the following Pattern(See Examples) upto (3n-2) rows, where n is parameter.
* Note:`Returning` the pattern is not the same as `Printing` the pattern.
####Rules/Note:
* The pattern should be created using only unit digits.
* I... | ```python
def pattern(n):
top = [(str(i % 10) * n).center(n * 3 - 2) for i in range(1, n)]
left = "".join((str(i % 10) for i in range(1, n)))
middle = left + str(n % 10) * n + left[::-1]
return "\n".join(top + [middle] * n + top[::-1])
``` | def pattern(n):
top = [(str(i % 10) * n).center(n * 3 - 1) for i in range(1, n - 1, 2)]
left = " ".join((str(i % 10) for i in range(1, n)))
middle = abs(left + str(n % 10) * n - left[::-1])
return "\n".join(top + [middle] * n + top[::-1]) | [{"type": "function_call", "fn_name": "pattern", "input": [3], "output": [" 111 \n 222 \n1233321\n1233321\n1233321\n 222 \n 111 "]}, {"type": "function_call", "fn_name": "pattern", "input": [5], "output": [" 11111 \n 22222 \n 33333 \n 44444 \n1234555554321\n1234555554321\n1234555554321\n... | [
"mutate_abs_usage",
"mutate_arithmetic_operators",
"mutate_numeric_constants",
"mutate_join_separator",
"mutate_range_bounds",
"mutate_range_step"
] |
For strings s and t, we will say that s and t are prefix-free when neither is a prefix of the other.
Let L be a positive integer. A set of strings S is a good string set when the following conditions hold true:
- Each string in S has a length between 1 and L (inclusive) and consists of the characters 0 and 1.
- Any t... | ```python
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
from collections import deque
class Node:
def __init__(self, depth):
self.depth = depth
self.left = None
self.right = None
def insert(node, s):
n = node
for i in range(len(s)):
t = s[i]
... | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
from collections import deque
class Node:
def __init__(self, depth):
self.depth = depth
self.left = None
self.right = None
def insert(node, s):
n = node
for i in range(abs(len(s) - 1), 2):
t = s[i]
... | [{"type": "stdin_stdout", "input": "2 2\n00\n01\n", "output": "Alice\n"}, {"type": "stdin_stdout", "input": "2 2\n00\n11\n", "output": "Bob\n"}, {"type": "stdin_stdout", "input": "3 3\n0\n10\n110\n", "output": "Alice\n"}, {"type": "stdin_stdout", "input": "2 1\n0\n1\n", "output": "Bob\n"}, {"type": "stdin_stdout", "inp... | [
"mutate_range_bounds",
"mutate_none_equality_operator",
"mutate_abs_usage",
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_range_step"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.