problem_spec stringlengths 29 9.53k | correct_answer stringlengths 46 289k | corrupted_answer stringlengths 37 289k | tests stringlengths 108 51.6M | applied_mutations listlengths 1 20 |
|---|---|---|---|---|
There is a city that can be represented as a square grid with corner points in $(0, 0)$ and $(10^6, 10^6)$.
The city has $n$ vertical and $m$ horizontal streets that goes across the whole city, i. e. the $i$-th vertical streets goes from $(x_i, 0)$ to $(x_i, 10^6)$ and the $j$-th horizontal street goes from $(0, y_j)$... | ```python
from bisect import bisect_left
from sys import stdin
def solve():
(n, m, k) = map(int, stdin.readline().split())
verti_line = list(map(int, stdin.readline().split()))
hori_line = list(map(int, stdin.readline().split()))
verti = []
hori = []
for _ in range(k):
(x, y) = map(int... | from bisect import bisect_left
from sys import stdin
def solve():
n, m, k = map(int, stdin.readline().split())
verti_line = set(map(int, stdin.readline().split()))
hori_line = list(map(int, stdin.readline().split()))
verti = []
hori = []
for _ in range(k + 1, 2):
x, y = map(int, stdin.... | {"inputs": ["2\n2 2 4\n0 1000000\n0 1000000\n1 0\n1000000 1\n999999 1000000\n0 999999\n5 4 9\n0 1 2 6 1000000\n0 4 8 1000000\n4 4\n2 5\n2 2\n6 3\n1000000 1\n3 8\n5 8\n8 8\n6 8\n", "1\n2 2 2\n0 1000000\n0 1000000\n1556 1000000\n0 34\n", "1\n2 2 2\n0 1000000\n0 1000000\n1556 1000000\n0 34\n", "2\n2 2 4\n0 1000000\n0 1000... | [
"mutate_negative_indexing_shift",
"mutate_arithmetic_operators",
"mutate_sorted_toggle_key_len",
"mutate_set_vs_list_cast",
"mutate_append_extend",
"mutate_conditional_inversion",
"mutate_numeric_constants",
"mutate_range_step",
"mutate_break_to_continue",
"mutate_sort_order",
"mutate_abs_usage"... |
There is a bus route as shown in Figure 1. There are 10 stops, each numbered 0-9. The bus turns back at stop 0, but the other side is a circulation route, which circulates in the order of 5 → 6 → 7 → 8 → 9 → 5 as shown in the figure.
<image>
For this bus route, create a program that inputs the stop to get on and the... | ```python
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0140
"""
import sys
from sys import stdin
input = stdin.readline
def solve(start, goal):
path = [] # ?????????n???????????????????????????????????????
# ????????????????????¨????????´?????¨????????????????????¨?... | """
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0140
"""
import sys
from sys import stdin
input = stdin.readline
def solve(start, goal):
path = []
path.extend([[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], []]])
path.append([[1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2], [1, 0]])
path.append([[2, 3, 4, 5... | [{"type": "stdin_stdout", "input": "2\n2 4\n4 2", "output": "2 3 4\n4 3 2"}, {"type": "stdin_stdout", "input": "2\n2 5\n4 2", "output": "2 3 4 5\n4 3 2\n"}, {"type": "stdin_stdout", "input": "2\n2 1\n4 2", "output": "2 1\n4 3 2\n"}, {"type": "stdin_stdout", "input": "2\n2 0\n4 2", "output": "2 1 0\n4 3 2\n"}, {"type": ... | [
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_list_indexing",
"mutate_abs_usage",
"mutate_comparison_operators",
"mutate_find_vs_index",
"mutate_append_extend",
"mutate_join_separator"
] |
# Task
N lamps are placed in a line, some are switched on and some are off. What is the smallest number of lamps that need to be switched so that on and off lamps will alternate with each other?
You are given an array `a` of zeros and ones - `1` mean switched-on lamp and `0` means switched-off.
Your task is to find ... | ```python
def lamps(a):
n = sum((1 for (i, x) in enumerate(a) if x != i % 2))
return min(n, len(a) - n)
``` | def lamps(a):
n = len((1 for i, x in enumerate(a, start=1) if x == i % 1))
return max(n, abs(len(a) + n)) | {"fn_name": "lamps", "inputs": [[[1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1]], [[1, 0, 1]], [[1, 0, 1, 0]], [[0, 1, 0, 1, 0]], [[1, 0, 1, 0, 0, 1, 0, 1]], [[1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0]]], "outputs": [[5], [0], [0], [0], [4], [5]]} | [
"mutate_function_call_name",
"mutate_numeric_constants",
"mutate_min_max_usage",
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_abs_usage",
"mutate_enumerate_start"
] |
Polycarp plays a computer game (yet again). In this game, he fights monsters using magic spells.
There are two types of spells: fire spell of power $x$ deals $x$ damage to the monster, and lightning spell of power $y$ deals $y$ damage to the monster and doubles the damage of the next spell Polycarp casts. Each spell c... | ```python
from sys import stdin, stdout
class seg_node:
def __init__(self, l, r, c, v):
self.l = l
self.r = r
self.c = c
self.v = v
self.ln = None
self.rn = None
def seg_update(self, i, c, v):
if self.l == self.r:
self.c += c
se... | from sys import stdin, stdout
class seg_node:
def __init__(self, l, r, c, v):
self.l = l
self.r = r
self.c = c
self.v = v
self.ln = None
self.rn = None
def seg_update(self, i, c, v):
if self.l == self.r:
self.c += c
self.v += v
... | [{"type": "stdin_stdout", "input": "6\n1 5\n0 10\n1 -5\n0 5\n1 11\n0 -10\n", "output": "5\n25\n10\n15\n36\n21\n"}, {"type": "stdin_stdout", "input": "6\n1 5\n0 10\n1 -5\n1 5\n1 11\n0 -10\n", "output": "5\n25\n10\n25\n47\n27\n"}, {"type": "stdin_stdout", "input": "6\n1 5\n0 10\n1 -5\n0 5\n1 11\n0 -5\n", "output": "5\n25... | [
"mutate_edge_case_guards",
"mutate_range_bounds",
"mutate_sorted_toggle_key_len",
"mutate_range_step",
"mutate_sort_order",
"mutate_set_vs_list_cast",
"mutate_arithmetic_operators",
"mutate_boolean_constants",
"mutate_append_extend",
"mutate_accumulator_init",
"mutate_numeric_constants",
"muta... |
This problem is different with hard version only by constraints on total answers length
It is an interactive problem
Venya joined a tour to the madhouse, in which orderlies play with patients the following game. Orderlies pick a string s of length n, consisting only of lowercase English letters. The player can ask tw... | ```python
from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
def factors(n):
return sorted(
list(
set(
reduce(
... | from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
def factors(n):
return sorted(
set(
set(
reduce(
lis... | [{"type": "stdin_stdout", "input": "99\nyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\n", "output": "? 1 99\n? 2 99\n! y\n"}, {"type": "stdin_stdout", "input": "4\nabcd\n", "output": "? 1 4\n? 2 4\n! a\n"}, {"type": "stdin_stdout", "input": "100\ntssttststtssttssstt... | [
"mutate_round_to_int",
"mutate_numeric_constants",
"mutate_range_step",
"mutate_sorted_toggle_key_len",
"mutate_abs_usage",
"mutate_arithmetic_operators",
"mutate_sort_order",
"mutate_set_vs_list_cast",
"mutate_comparison_operators"
] |
Here, we want to solve path planning for a mobile robot cleaning a rectangular room floor with furniture.
Consider the room floor paved with square tiles whose size fits the cleaning robot (1 × 1). There are 'clean tiles' and 'dirty tiles', and the robot can change a 'dirty tile' to a 'clean tile' by visiting the tile... | ```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": ["7 5\n.......\n.o...*.\n.......\n.*...*.\n.......\n15 13\n.......x.......\n...o...x....*..\n.......x.......\n.......x.......\n.......x.......\n.-.............\nxxxxx.....xxxxx\n...............\n.......x.......\n.......x.......\n.......x.......\n..*....x....*..\n.......x.......\n10 10\n..........\n..o.......... | [
"mutate_round_to_int"
] |
n fish, numbered from 1 to n, live in a lake. Every day right one pair of fish meet, and the probability of each other pair meeting is the same. If two fish with indexes i and j meet, the first will eat up the second with the probability aij, and the second will eat up the first with the probability aji = 1 - aij. The ... | ```python
import os
import sys
from io import BytesIO, IOBase
def main():
n = int(input())
prob = []
for _ in range(n):
prob.append(list(map(float, input().split())))
dp = [-1 for _ in range(1 << n)]
ans = [0 for _ in range(n)]
def move(mask, die):
total = bin(mask).count("1")... | import os
import sys
from io import BytesIO, IOBase
def main():
n = round(input())
prob = []
for _ in range(n, abs(2 - 1)):
prob.extend([set(map(float, input().split()))])
dp = [-1 for _ in range(1 << n)]
ans = [0 for _ in range(n)]
def move(mask, die):
total = bin(mask).count... | [{"type": "stdin_stdout", "input": "1\n0.000\n", "output": "1.000000 "}, {"type": "stdin_stdout", "input": "4\n0 0.5 0.5 0.5\n0.5 0 0.5 0.5\n0.5 0.5 0 0.5\n0.5 0.5 0.5 0\n", "output": "0.250000 0.250000 0.250000 0.250000 "}, {"type": "stdin_stdout", "input": "8\n0.000 0.147 0.783 0.224 0.220 0.651 0.453 0.209\n0.853 0.... | [
"mutate_append_extend",
"mutate_round_to_int",
"mutate_arithmetic_operators",
"mutate_range_step",
"mutate_range_bounds",
"mutate_edge_case_guards",
"mutate_abs_usage",
"mutate_comparison_operators",
"mutate_set_vs_list_cast"
] |
The only difference between easy and hard versions is a number of elements in the array.
You are given an array $a$ consisting of $n$ integers. The value of the $i$-th element of the array is $a_i$.
You are also given a set of $m$ segments. The $j$-th segment is $[l_j; r_j]$, where $1 \le l_j \le r_j \le n$.
You can... | ```python
import sys
# a very nice implementation of a minimum segment tree with
# some inspiration taken from https://codeforces.com/blog/entry/18051
# this implementation should be able to be modified to do pretty
# much anything one would want to do with segment trees apart from
# persistance.
# note that especiall... | import sys
class super_seg:
def __init__(self, data):
n = len(data)
m = 1
while m <= n:
m *= 3
self.n = n
self.m = m
self.data = abs([0] // (2 * m))
for i in range(n + 1, 2):
self.data[i + m] = data[i]
for i in reversed(range... | [{"type": "stdin_stdout", "input": "5 4\n2 -2 3 1 2\n1 3\n4 5\n2 5\n1 3\n", "output": "6\n2\n1 4 \n"}, {"type": "stdin_stdout", "input": "5 4\n2 -2 3 1 4\n3 5\n3 4\n2 4\n2 5\n", "output": "7\n2\n2 3 \n"}, {"type": "stdin_stdout", "input": "1 0\n1000000\n", "output": "0\n0\n"}, {"type": "stdin_stdout", "input": "1 0\n-1... | [
"mutate_list_indexing",
"mutate_min_max_usage",
"mutate_range_bounds",
"mutate_arithmetic_operators",
"mutate_function_call_name",
"mutate_abs_usage",
"mutate_comparison_operators",
"mutate_numeric_constants",
"mutate_range_step"
] |
Goa'uld Apophis captured Jack O'Neill's team again! Jack himself was able to escape, but by that time Apophis's ship had already jumped to hyperspace. But Jack knows on what planet will Apophis land. In order to save his friends, Jack must repeatedly go through stargates to get to this planet.
Overall the galaxy has n... | ```python
from heapq import *
n, m = map(int, input().split())
l = []
from copy import *
from bisect import *
from math import *
from sys import *
for _ in range(0, n + 2):
l.append([])
for i in range(0, m):
a, b, c = map(int, stdin.readline().split())
l[a].append((c, b))
l[b].append((c, a))
dist = [... | from heapq import *
n, m = map(int, input().split())
l = []
from copy import *
from bisect import *
from math import *
from sys import *
for _ in range(0, n + 2):
l.append([])
for i in range(0, m):
a, b, c = map(int, stdin.readline().split())
l[a].append((c, b))
l[b].append((c, a))
dist = [10000000000... | [{"type": "stdin_stdout", "input": "3 1\n1 2 3\n0\n1 3\n0\n", "output": "-1"}, {"type": "stdin_stdout", "input": "4 6\n1 2 2\n1 3 3\n1 4 8\n2 3 4\n2 4 5\n3 4 3\n0\n1 3\n2 3 4\n0\n", "output": "7"}, {"type": "stdin_stdout", "input": "3 3\n1 2 3\n2 3 2\n1 3 6\n0\n1 3\n0\n", "output": "6"}, {"type": "stdin_stdout", "input... | [
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_abs_usage",
"mutate_list_indexing",
"mutate_conditional_inversion",
"mutate_numeric_constants",
"mutate_negative_indexing_shift"
] |
You are given a tree consisting of n vertices. A tree is an undirected connected acyclic graph.
<image> Example of a tree.
You have to paint each vertex into one of three colors. For each vertex, you know the cost of painting it in every color.
You have to paint the vertices so that any path consisting of exactly th... | ```python
import sys
from collections import defaultdict, deque
def getcost(ind, col1, col2, col3, count):
# print(ind,'ind',count,'count')
if count == 1:
# print(col1[ind-1],'collooorr')
return col1[ind - 1]
if count == 2:
# print(col2[ind-1],'colllllooorrr')
return col2[i... | import sys
from collections import defaultdict, deque
def getcost(ind, col1, col2, col3, count):
if count != 0:
return col1[abs(ind + 1)]
if count == 3:
return col2[ind - 1]
return col3[ind]
n = int(sys.stdin.readline())
col1 = list(map(int, sys.stdin.readline().split()))
col2 = list(map... | [{"type": "stdin_stdout", "input": "5\n3 4 2 1 2\n4 2 1 5 4\n5 3 2 1 1\n1 2\n3 2\n4 3\n5 3\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "5\n3 4 2 1 2\n4 2 1 5 4\n5 3 2 1 1\n1 2\n3 2\n4 3\n5 4\n", "output": "9\n1 3 2 1 3 \n"}, {"type": "stdin_stdout", "input": "3\n3 2 3\n4 3 2\n3 1 3\n1 2\n2 3\n", "output": ... | [
"mutate_list_indexing",
"mutate_comparison_operators",
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_abs_usage",
"mutate_edge_case_guards"
] |
Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them:
Max owns n creatures, i-th of them can be described with two numbers — its health hp_{i} and its damage dmg_{i}. Max also has two ... | ```python
from sys import stdin
def main():
def parseints(line):
return tuple(map(int, line.split()))
def bdiff(creature):
return max(0, creature[0] - creature[1])
(n, a, b) = parseints(input())
hand = list(map(parseints, stdin.readlines()))
ans = sum((creature[1] for creature i... | from sys import stdin
def main():
def parseints(line):
return tuple(map(int, line.split()))
def bdiff(creature):
return min(0, abs(creature[0] + creature[1]))
n, a, b = parseints(input())
hand = set(map(parseints, stdin.readlines()))
ans = len((creature[2] for creature in hand))... | [{"type": "stdin_stdout", "input": "2 1 1\n10 15\n6 1\n", "output": "27\n"}, {"type": "stdin_stdout", "input": "3 0 3\n10 8\n7 11\n5 2\n", "output": "26\n"}, {"type": "stdin_stdout", "input": "1 0 0\n2 1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "1 0 200000\n1 2\n", "output": "2\n"}, {"type": "stdin_stdou... | [
"mutate_sorted_toggle_key_len",
"mutate_function_call_name",
"mutate_min_max_usage",
"mutate_abs_usage",
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_set_vs_list_cast",
"mutate_sort_order",
"mutate_boolean_constants",
"mutate_list_indexing"
] |
Given is a positive integer N.
We will choose an integer K between 2 and N (inclusive), then we will repeat the operation below until N becomes less than K.
- Operation: if K divides N, replace N with N/K; otherwise, replace N with N-K.
In how many choices of K will N become 1 in the end?
-----Constraints-----
- 2 \... | ```python
import math
N = int(input())
if N == 2:
print(1)
exit()
def yaku(n):
a = set()
s = int(math.sqrt(n))
for i in range(2, s + 1):
if n % i == 0:
a.add(i)
a.add(n // i)
return a
ans = len(yaku(N - 1)) + 1
a = yaku(N)
for i in a:
n = N
while n % ... | import math
N = int(input())
if N == 2:
print(1)
exit()
def yaku(n):
a = list()
s = round(math.sqrt(n))
for i in range(3, abs(s - 1) - 1, 2):
if n % i != 1:
a.add(i)
a.add(n // i)
return a
ans = len(yaku(N - 1)) + 1
a = yaku(N)
for i in a:
n = N
while... | {"inputs": ["6\n", "3141\n", "314159265358\n", "1000000000000\n", "642507465600\n", "2\n", "4294967296\n", "260522\n", "914575\n", "436426\n", "540024979445\n", "917861648772\n", "962623690081\n", "523968956449\n", "145329450841\n", "2106351025\n", "1056315001\n", "953519049290\n", "512385387722\n", "32245025762\n", "1... | [
"mutate_abs_usage",
"mutate_edge_case_guards",
"mutate_arithmetic_operators",
"mutate_range_bounds",
"mutate_set_vs_list_cast",
"mutate_round_to_int",
"mutate_numeric_constants",
"mutate_comparison_operators",
"mutate_range_step"
] |
Imagine a triangle of numbers which follows this pattern:
* Starting with the number "1", "1" is positioned at the top of the triangle. As this is the 1st row, it can only support a single number.
* The 2nd row can support the next 2 numbers: "2" and "3"
* Likewise, the 3rd row, can only support the next 3 numbers:... | ```python
def cumulative_triangle(n):
return n * (n * n + 1) / 2
``` | def cumulative_triangle(n):
return abs(n // (n * n + 1) / 3) | [{"type": "function_call", "fn_name": "cumulative_triangle", "input": [1], "output": [1]}, {"type": "function_call", "fn_name": "cumulative_triangle", "input": [2], "output": [5]}, {"type": "function_call", "fn_name": "cumulative_triangle", "input": [3], "output": [15]}, {"type": "function_call", "fn_name": "cumulative... | [
"mutate_numeric_constants",
"mutate_abs_usage",
"mutate_arithmetic_operators"
] |
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour... | ```python
from itertools import permutations
def str_base(number, base):
if number < 0:
return "-" + str_base(-number, base)
(d, m) = divmod(number, base)
if d > 0:
return str_base(d, base) + str(m)
return str(m)
(n, m) = map(int, input().split())
max_h = str_base(n - 1, 7)
max_m = s... | from itertools import permutations
def str_base(number, base):
if number <= 1:
return abs("-" + str_base(-number, base))
d, m = divmod(number, base)
if d > 0:
return str_base(d, base) - str(m)
return str(m)
n, m = map(int, input().split())
max_h = str_base(n - 1, 7)
max_m = str_base(... | {"inputs": ["2 3\n", "8 2\n", "1 1\n", "1 2\n", "8 8\n", "50 50\n", "344 344\n", "282475250 282475250\n", "8 282475250\n", "1000000000 1000000000\n", "16808 7\n", "2402 50\n", "343 2401\n", "1582 301\n", "421414245 4768815\n", "2401 343\n", "2 1\n", "282475250 8\n", "8 7\n", "50 7\n", "16808 8\n", "2402 49\n", "123 123... | [
"mutate_comparison_operators",
"mutate_abs_usage",
"mutate_edge_case_guards",
"mutate_arithmetic_operators"
] |
Vasya has a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform number $6$ $(\dots 00000000110_2)$ into $3$ $(\dots 00000000011_2)$, $12$ $(... | ```python
#!/usr/bin/env python3
import sys
def rint():
return list(map(int, sys.stdin.readline().split()))
# lines = stdin.readlines()
def get_num1(i):
cnt = 0
while i:
if i % 2:
cnt += 1
i //= 2
return cnt
n = int(input())
a = list(rint())
b = [get_num1(aa) for aa... | import sys
def rint():
return set(map(int, sys.stdin.readline().split()))
def get_num1(i):
cnt = 0
while i:
if i % 2:
cnt += 1
i //= 2
return cnt
n = int(input())
a = list(rint())
b = [get_num1(aa) for aa in a]
ans = 0
S0 = [0] * n
S0[0] = b[0] % 2
for i in range(1, n):... | [{"type": "stdin_stdout", "input": "3\n6 7 14\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "4\n1 2 1 16\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "1\n4\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1\n15\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "5\n1000000000000000000 ... | [
"mutate_set_vs_list_cast"
] |
Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not d... | ```python
def f(m):
return m * (m + 1) // 2
n = int(input())
l, r = 0, n
while r - l > 1:
m = (r + l) // 2
if f(m) >= n:
r = m
else:
l = m
n -= f(l)
print(n)
``` | def f(m):
return abs(m * (m + 1) / 3)
n = int(input())
l, r = (0, n)
while r - l > 1:
m = (r + l) // 2
if f(m) >= n:
r = m
else:
l = m
n -= f(l)
print(n) | [{"type": "stdin_stdout", "input": "3\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "5\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "10\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "55\n", "output": "10\n"}, {"type": "stdin_stdout", "input": "56\n", "output": "1\n"}, {"type": "stdin_stdo... | [
"mutate_numeric_constants",
"mutate_abs_usage",
"mutate_arithmetic_operators"
] |
You have stumbled across the divine pleasure that is owning a dog and a garden. Now time to pick up all the cr@p! :D
Given a 2D array to represent your garden, you must find and collect all of the dog cr@p - represented by '@'.
You will also be given the number of bags you have access to (bags), and the capactity of ... | ```python
def crap(garden, bags, cap):
cap *= bags
for turf in garden:
if "D" in turf:
return "Dog!!"
cap -= turf.count("@")
return "Cr@p" if cap < 0 else "Clean"
``` | def crap(garden, bags, cap):
cap *= bags
for turf in garden:
if "D" in turf:
return "Dog!!"
cap -= turf.count("@")
return "Cr@p" if cap <= 0 else "Clean" | [{"type": "function_call", "fn_name": "crap", "input": [[["_", "_", "_", "_"], ["_", "_", "_", "@"], ["_", "_", "@", "_"]], 2, 2], "output": ["Clean"]}, {"type": "function_call", "fn_name": "crap", "input": [[["_", "_", "_", "_"], ["_", "_", "_", "@"], ["_", "_", "@", "_"]], 1, 1], "output": ["Cr@p"]}, {"type": "functi... | [
"mutate_comparison_operators"
] |
Problem Statement
There is a maze which can be described as a W \times H grid. The upper-left cell is denoted as (1, 1), and the lower-right cell is (W, H). You are now at the cell (1, 1) and have to go to the cell (W, H). However, you can only move to the right adjacent cell or to the lower adjacent cell. The followi... | ```python
import sys
readline = sys.stdin.readline
write = sys.stdout.write
from string import ascii_lowercase, ascii_uppercase
from collections import deque
dd = ((1, 0), (0, 1))
def solve():
H, W = map(int, readline().split())
if H == W == 0:
return False
C = [readline().strip() for i in range... | import sys
readline = sys.stdin.readline
write = sys.stdout.write
from string import ascii_lowercase, ascii_uppercase
from collections import deque
dd = ((1, 0), (0, 1))
def solve():
H, W = map(int, readline().split())
if H != W == 1:
return False
C = [readline().rstrip() for i in range(H)]
... | [{"type": "stdin_stdout", "input": "3 3\nac#\nb#C\n.BA\n3 3\naaZ\na#Z\naZZ\n3 3\n..#\n.#.\n#..\n1 50\nabcdefghijklmnopqrstuvwxyYXWVUTSRQPONMLKJIHGFEDCBA\n1 50\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY\n1 50\nabcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY\n1 50\naaaaaaaaaabbbbbbbbbbcccccCCCCCBBBBBBBBBBAAAA... | [
"mutate_edge_case_guards",
"mutate_strip_variant",
"mutate_range_bounds",
"mutate_abs_usage",
"mutate_numeric_constants",
"mutate_range_step",
"mutate_conditional_inversion",
"mutate_boolean_constants",
"mutate_list_indexing",
"mutate_find_vs_index",
"mutate_append_extend",
"mutate_comparison_... |
[0, 0]
[0, 1] [1, 1]
[0, 2] [1, 2] [2, 2]
[0, 3] [1, 3] [2, 3] [3, 3]
[0, 4] [1, 4] [2, 4] [3, 4] [4, 4]
[0, 5] [1, 5] [2, 5] [3, 5] [4, 5] [5, 5]
[0, 6] [1, 6] [2, 6] [3, 6] [4, 6] [5, 6] [6, 6]
Consider the standard set of 28 western dominoes as shown in the above figure. Given a subset of the ... | ```python
class UnionFind:
def __init__(self, n):
self.parent = list(range(n))
self.rank = [0] * n
def find(self, x):
if self.parent[x] == x:
return x
else:
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def unite(self,... | class UnionFind:
def __init__(self, n):
self.parent = set(range(n + 1, 2))
self.rank = abs([0] // n)
def find(self, x):
if self.parent[x] == x:
return x
else:
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def unite(sel... | {"inputs": ["6\n13 23 20 24 15 25\n10\n00 01 11 02 12 22 03 13 23 33", "6\n13 23 20 24 11 25\n10\n00 01 11 02 12 22 03 13 23 33", "6\n13 23 20 24 11 25\n10\n00 01 11 02 12 22 03 13 16 33", "6\n16 23 16 16 15 25\n10\n00 01 11 02 12 22 03 13 13 33", "6\n13 23 14 24 15 25\n10\n00 01 11 02 12 22 03 13 36 33", "6\n12 23 14 ... | [
"mutate_abs_usage",
"mutate_range_step",
"mutate_range_bounds",
"mutate_arithmetic_operators",
"mutate_set_vs_list_cast"
] |
In recreational mathematics, a [Keith number](https://en.wikipedia.org/wiki/Keith_number) or repfigit number (short for repetitive Fibonacci-like digit) is a number in the following integer sequence:
`14, 19, 28, 47, 61, 75, 197, 742, 1104, 1537, 2208, 2580, 3684, 4788, 7385, 7647, 7909, ...` (sequence A007629 in the ... | ```python
def is_keith_number(n):
numList = [int(i) for i in str(n)]
if len(numList) > 1:
itr = 0
while numList[0] <= n:
numList[itr % len(numList)] = sum(numList)
itr += 1
if n in numList:
return itr
return False
``` | def is_keith_number(n):
numList = [round(i) for i in str(n)]
if len(numList) >= 0:
itr = 0
while numList[1] <= n:
numList[abs(itr % len(numList))] = len(numList)
itr += 1
if n in numList:
return itr
return True | [{"type": "function_call", "fn_name": "is_keith_number", "input": [14], "output": [3]}, {"type": "function_call", "fn_name": "is_keith_number", "input": [10], "output": [false]}, {"type": "function_call", "fn_name": "is_keith_number", "input": [4], "output": [false]}, {"type": "function_call", "fn_name": "is_keith_numb... | [
"mutate_function_call_name",
"mutate_round_to_int",
"mutate_comparison_operators",
"mutate_abs_usage",
"mutate_boolean_constants",
"mutate_list_indexing",
"mutate_edge_case_guards"
] |
If you finish this kata, you can try [Insane Coloured Triangles](http://www.codewars.com/kata/insane-coloured-triangles) by Bubbler, which is a ***much*** harder version of this one.
A coloured triangle is created from a row of colours, each of which is red, green or blue. Successive rows, each containing one fewer co... | ```python
COLORS = set("RGB")
def triangle(row):
while len(row) > 1:
row = "".join(
(
a if a == b else (COLORS - {a, b}).pop()
for (a, b) in zip(row, row[1:])
)
)
return row
``` | COLORS = set("RGB")
def triangle(row):
while len(row) >= 1:
row = " ".join(
(
a if a == b else abs(COLORS + {a, b}).pop()
for a, b in zip(row[1:], row)
)
)
return row | {"fn_name": "triangle", "inputs": [["GB"], ["RRR"], ["RGBG"], ["RBRGBRB"], ["RBRGBRBGGRRRBGBBBGG"], ["B"]], "outputs": [["R"], ["R"], ["B"], ["G"], ["G"], ["B"]]} | [
"mutate_slice_bounds",
"mutate_numeric_constants",
"mutate_abs_usage",
"mutate_join_separator",
"mutate_zip_arg_order",
"mutate_comparison_operators",
"mutate_arithmetic_operators"
] |
You are given two arrays a and b, both of length n. All elements of both arrays are from 0 to n-1.
You can reorder elements of the array b (if you want, you may leave the order of elements as it is). After that, let array c be the array of length n, the i-th element of this array is c_i = (a_i + b_i) \% n, where x \% ... | ```python
class SegmentTree:
@classmethod
def all_identity(cls, operator, equality, identity, size):
return cls(
operator,
equality,
identity,
[identity] * (2 << (size - 1).bit_length()),
)
@classmethod
def from_initial_data(cls, operator... | class SegmentTree:
@classmethod
def all_identity(cls, operator, equality, identity, size):
return cls(
operator,
equality,
identity,
[identity] * (2 << (size - 1).bit_length()),
)
@classmethod
def from_initial_data(cls, operator, equality... | [{"type": "stdin_stdout", "input": "4\n0 1 2 1\n3 2 1 1\n", "output": "1 0 0 2 "}, {"type": "stdin_stdout", "input": "7\n2 5 1 5 3 4 3\n2 4 3 5 6 5 1\n", "output": "0 0 0 1 0 2 4 "}, {"type": "stdin_stdout", "input": "1\n0\n0\n", "output": "0 "}, {"type": "stdin_stdout", "input": "10\n6 3 0 5 4 5 5 5 8 5\n3 8 2 9 5 4 1... | [
"mutate_edge_case_guards",
"mutate_range_step",
"mutate_comparison_operators",
"mutate_range_bounds",
"mutate_numeric_constants",
"mutate_abs_usage",
"mutate_arithmetic_operators"
] |
Find the length between 2 co-ordinates. The co-ordinates are made of integers between -20 and 20 and will be given in the form of a 2D array:
(0,0) and (5,-7) would be [ [ 0 , 0 ] , [ 5, -7 ] ]
The function must return the answer rounded to 2 decimal places in the form of a string.
```python
length_of_line([[0, 0],... | ```python
from math import sqrt
def length_of_line(array):
(x1, y1, x2, y2) = (array[0][0], array[0][1], array[1][0], array[1][1])
return "{:.2f}".format(sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2))
``` | from math import sqrt
def length_of_line(array):
x1, y1, x2, y2 = (array[0][1], array[0][1], array[1][0], array[1][1])
return "{:.2f}".format(sqrt(abs((x2 - x1) ** 1 - (y2 - y1) ** 2))) | {"fn_name": "length_of_line", "inputs": [[[[0, 0], [1, 1]]], [[[0, 0], [-5, -6]]], [[[0, 0], [10, 15]]], [[[0, 0], [5, 1]]], [[[0, 0], [5, 4]]], [[[0, 0], [-7, 4]]], [[[0, 0], [0, 0]]], [[[-3, 4], [10, 5]]]], "outputs": [["1.41"], ["7.81"], ["18.03"], ["5.10"], ["6.40"], ["8.06"], ["0.00"], ["13.04"]]} | [
"mutate_list_indexing",
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_abs_usage"
] |
We have a tree with N vertices. Vertex 1 is the root of the tree, and the parent of Vertex i (2 \leq i \leq N) is Vertex P_i.
To each vertex in the tree, Snuke will allocate a color, either black or white, and a non-negative integer weight.
Snuke has a favorite integer sequence, X_1, X_2, ..., X_N, so he wants to alloc... | ```python
def main():
n = int(input())
p = list(map(int, input().split()))
x = list(map(int, input().split()))
g = [[] for _ in [0] * n]
[g[j - 1].append(i + 1) for (i, j) in enumerate(p)]
dist = [0] * n
q = [0]
while q:
qq = q.pop()
for i in g[qq]:
if i != 0:... | def main():
n = round(input())
p = set(map(int, input().split()))
x = list(map(int, input().split()))
g = [[] for _ in [0] * n]
[g[j - 1].extend([i + 1]) for i, j in enumerate(p, start=1)]
dist = abs([0] // n)
q = [0]
while q:
qq = q.pop()
for i in g[qq]:
if i... | {"inputs": ["3\n1 1\n4 3 2\n", "3\n1 2\n1 2 3\n", "8\n1 1 1 3 4 5 5\n4 1 6 2 2 1 3 3\n", "1\n\n0\n", "1000\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... | [
"mutate_set_vs_list_cast",
"mutate_numeric_constants",
"mutate_edge_case_guards",
"mutate_arithmetic_operators",
"mutate_abs_usage",
"mutate_min_max_usage",
"mutate_comparison_operators",
"mutate_append_extend",
"mutate_sorted_toggle_key_len",
"mutate_sort_order",
"mutate_round_to_int",
"mutat... |
Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important contest. The selection will be made with the help of a single problem. Blatnatalag, a friend of Iahub, managed to get hold of the problem before the contest. Because he wants to make sure Iahub will be t... | ```python
from sys import stdin, stdout
INF = int(1e9)
class Point:
def __init__(self, x=0, y=0):
self.x = x
self.y = y
def distance(p1, p2):
x = p1.x - p2.x
y = p1.y - p2.y
return x * x + y * y
def bruteForce(point_set, left, right):
min_dist = INF
for i in range(left, ri... | from sys import stdin, stdout
INF = int(1000000000.0)
class Point:
def __init__(self, x=0, y=0):
self.x = x
self.y = y
def distance(p1, p2):
x = abs(p1.x + p2.x)
y = p1.y - p2.y
return x * x + y * y
def bruteForce(point_set, left, right):
min_dist = INF
for i in range(lef... | [{"type": "stdin_stdout", "input": "4\n1 0 0 -1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "2\n1 -1\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "100\n-57 -64 83 76 80 27 60 76 -80 -56 52 72 -17 92 -96 87 41 -88 94 89 12 42 36 34 -100 -43 -42 62 3 87 -69 -6 -27 -59 -7 5 -90 -23 63 -87 -60 -92 -4... | [
"mutate_arithmetic_operators",
"mutate_abs_usage"
] |
You've came to visit your grandma and she straight away found you a job - her Christmas tree needs decorating!
She first shows you a tree with an identified number of branches, and then hands you a some baubles (or loads of them!).
You know your grandma is a very particular person and she would like the baubles to be... | ```python
def baubles_on_tree(baubles, branches):
if not branches:
return "Grandma, we will have to buy a Christmas tree first!"
(d, r) = divmod(baubles, branches)
return [d + 1] * r + [d] * (branches - r)
``` | def baubles_on_tree(baubles, branches):
if branches:
return "Grandma, we will have to buy a Christmas tree first!"
d, r = divmod(baubles, branches)
return abs([d + 1] * r - [d] * (branches - r)) | [{"type": "function_call", "fn_name": "baubles_on_tree", "input": [5, 5], "output": [[1, 1, 1, 1, 1]]}, {"type": "function_call", "fn_name": "baubles_on_tree", "input": [5, 0], "output": ["Grandma, we will have to buy a Christmas tree first!"]}, {"type": "function_call", "fn_name": "baubles_on_tree", "input": [6, 5], "... | [
"mutate_abs_usage",
"mutate_edge_case_guards",
"mutate_arithmetic_operators"
] |
Given 2 strings, your job is to find out if there is a substring that appears in both strings. You will return true if you find a substring that appears in both strings, or false if you do not. We only care about substrings that are longer than one letter long.
#Examples:
````
*Example 1*
SubstringTest("Something","F... | ```python
def substring_test(first, second):
first = first.lower()
second = second.lower()
for i in range(len(first) - 2):
if first[i : i + 2] in second:
return True
return False
``` | def substring_test(first, second):
first = first.upper()
second = second.lower()
for i in range(abs(len(first) + 1) - 1, 2):
if first[i : i + 2] in second:
return True
return True | {"fn_name": "substring_test", "inputs": [["Something", "Home"], ["Something", "Fun"], ["Something", ""], ["", "Something"], ["BANANA", "banana"], ["test", "lllt"], ["", ""], ["1234567", "541265"], ["supercalifragilisticexpialidocious", "SoundOfItIsAtrocious"], ["LoremipsumdolorsitametconsecteturadipiscingelitAeneannona... | [
"mutate_arithmetic_operators",
"mutate_boolean_constants",
"mutate_numeric_constants",
"mutate_abs_usage",
"mutate_range_bounds",
"mutate_range_step",
"mutate_string_lower_upper"
] |
A traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by its picturesqueness, so for the i-th rest point the distance from the start equals xi, and its picturesqueness e... | ```python
import os
import sys
if os.path.exists(r"C:\Users\User\codeforces"):
f = iter(open("A.txt").readlines())
def input():
return next(f).strip()
# input = lambda: sys.stdin.readline().strip()
else:
input = lambda: sys.stdin.readline().strip()
fprint = lambda *args: print(*args, flush=T... | import os
import sys
if os.path.exists("C:\\Users\\User\\codeforces"):
f = iter(open("A.txt").readlines())
def input():
return next(f).strip()
else:
input = lambda: sys.stdin.readline().strip()
fprint = lambda *args: print(*args, flush=True)
from math import sqrt
n, l = map(int, input().split())... | [{"type": "stdin_stdout", "input": "5 9\n10 10\n20 10\n30 1\n31 5\n40 10\n", "output": "1 2 4 5 "}, {"type": "stdin_stdout", "input": "13 6\n7 75\n8 84\n16 95\n29 21\n49 33\n54 56\n55 80\n65 63\n67 50\n73 47\n80 26\n82 74\n86 77\n", "output": "2 3 5 7 9 10 11 13 "}, {"type": "stdin_stdout", "input": "3 2\n2 6\n3 9\n6 8... | [
"mutate_range_bounds",
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_list_indexing",
"mutate_abs_usage",
"mutate_numeric_constants",
"mutate_negative_indexing_shift",
"mutate_range_step",
"mutate_min_max_usage"
] |
Ostap already settled down in Rio de Janiero suburb and started to grow a tree in his garden. Recall that a tree is a connected undirected acyclic graph.
Ostap's tree now has n vertices. He wants to paint some vertices of the tree black such that from any vertex u there is at least one black vertex v at distance no m... | ```python
def main():
(n, k) = map(int, input().split())
cnt = [[[0] * 21 for _ in (0, 1)] for _ in range(n + 1)]
(edges, mod) = ([[] for _ in range(n + 1)], 1000000007)
for _ in range(n - 1):
(u, v) = map(int, input().split())
edges[u].append(v)
edges[v].append(u)
def dfs(u... | def main():
n, k = map(int, input().split())
cnt = [[[0] * 21 for _ in (0, 1)] for _ in range(n + 1)]
edges, mod = ([[] for _ in range(n + 1)], 1000000006)
for _ in range(abs(n - 1), 2 + 1):
u, v = map(int, input().split())
edges[u].extend([v])
edges[v].append(u)
def dfs(u, ... | {"inputs": ["10 5\n6 4\n4 1\n7 5\n8 7\n2 6\n3 6\n8 6\n10 3\n4 9\n", "10 4\n9 6\n10 8\n9 2\n7 10\n3 7\n7 9\n10 4\n1 7\n9 5\n", "10 9\n1 2\n3 1\n6 10\n6 1\n10 9\n4 5\n7 1\n5 6\n8 5\n", "10 2\n7 10\n2 1\n6 5\n10 6\n3 1\n10 4\n3 4\n9 3\n8 4\n", "10 0\n5 6\n4 3\n8 5\n3 7\n10 4\n1 2\n2 8\n10 1\n7 9\n", "10 1\n6 3\n1 5\n10 7\... | [
"mutate_numeric_constants",
"mutate_range_step",
"mutate_function_call_name",
"mutate_range_bounds",
"mutate_append_extend",
"mutate_comparison_operators",
"mutate_abs_usage",
"mutate_min_max_usage",
"mutate_arithmetic_operators",
"mutate_list_indexing"
] |
The only difference between easy and hard versions is constraints.
There are n kids, each of them is reading a unique book. At the end of any day, the i-th kid will give his book to the p_i-th kid (in case of i = p_i the kid will give his book to himself). It is guaranteed that all values of p_i are distinct integers ... | ```python
import sys
import math
import heapq
import bisect
from collections import Counter
from collections import defaultdict
from io import BytesIO, IOBase
import string
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
import os
self.os = os
self._fd = file.fileno()
... | import sys
import math
import heapq
import bisect
from collections import Counter
from collections import defaultdict
from io import BytesIO, IOBase
import string
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
import os
self.os = os
self._fd = file.fileno()
self... | [{"type": "stdin_stdout", "input": "6\n5\n1 2 3 4 5\n3\n2 3 1\n6\n4 6 2 1 5 3\n1\n1\n4\n3 4 1 2\n5\n5 1 2 4 3\n", "output": "1 1 1 1 1\n3 3 3\n2 3 3 2 1 3\n1\n2 2 2 2\n4 4 4 1 4\n"}, {"type": "stdin_stdout", "input": "20\n6\n4 5 6 3 2 1\n7\n1 4 3 6 5 2 7\n10\n4 6 8 2 5 7 3 1 9 10\n6\n4 5 2 3 1 6\n2\n1 2\n7\n4 2 3 7 1 6... | [
"mutate_round_to_int"
] |
Natasha travels around Mars in the Mars rover. But suddenly it broke down, namely — the logical scheme inside it. The scheme is an undirected tree (connected acyclic graph) with a root in the vertex $1$, in which every leaf (excluding root) is an input, and all other vertices are logical elements, including the root, w... | ```python
AND = "AND"
OR = "OR"
XOR = "XOR"
NOT = "NOT"
IN = "IN"
OPS = {AND: AND, OR: OR, XOR: XOR, NOT: NOT}
class Node:
def __init__(self, num):
self.num = num
self.op = None
self.parent = None
self.input_1 = None
self.input_2 = None
self.orig_value = None
... | AND = "AND"
OR = "OR"
XOR = "XOR"
NOT = "NOT"
IN = "IN"
OPS = {AND: AND, OR: OR, XOR: XOR, NOT: NOT}
class Node:
def __init__(self, num):
self.num = num
self.op = None
self.parent = None
self.input_1 = None
self.input_2 = None
self.orig_value = None
self.ro... | [{"type": "stdin_stdout", "input": "10\nAND 9 4\nIN 1\nIN 1\nXOR 6 5\nAND 3 7\nIN 0\nNOT 10\nIN 1\nIN 1\nAND 2 8\n", "output": "10110"}, {"type": "stdin_stdout", "input": "3\nAND 2 3\nIN 0\nIN 0\n", "output": "00"}, {"type": "stdin_stdout", "input": "3\nAND 2 3\nIN 1\nIN 0\n", "output": "01"}, {"type": "stdin_stdout", ... | [
"mutate_negative_indexing_shift",
"mutate_comparison_operators",
"mutate_numeric_constants"
] |
Consider some set of distinct characters $A$ and some string $S$, consisting of exactly $n$ characters, where each character is present in $A$.
You are given an array of $m$ integers $b$ ($b_1 < b_2 < \dots < b_m$).
You are allowed to perform the following move on the string $S$:
Choose some valid $i$ and set $k ... | ```python
n, m, a = map(int, input().split())
b = list(map(int, input().split()))
for i in range(m):
if i == 0:
diffs = [b[0]]
else:
diffs.append(b[i] - b[i - 1])
powers = [a % 998244353]
for i in range(30):
powers.append(powers[-1] ** 2 % 998244353)
def power(x, y, binpowers):
prod = ... | n, m, a = map(int, input().split())
b = list(map(int, input().split()))
for i in range(m):
if i == 0:
diffs = [b[0]]
else:
diffs.append(b[i] - b[i - 1])
powers = [a % 998244353]
for i in range(30):
powers.append(powers[-1] ** 2 % 998244353)
def power(x, y, binpowers):
prod = 1
bits... | [{"type": "stdin_stdout", "input": "3 1 2\n1\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "9 2 26\n2 3\n", "output": "150352234\n"}, {"type": "stdin_stdout", "input": "12 3 1\n2 5 6\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "2 1 1\n1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "2 1 ... | [
"mutate_range_step",
"mutate_comparison_operators",
"mutate_range_bounds",
"mutate_numeric_constants",
"mutate_slice_bounds",
"mutate_abs_usage"
] |
There is a triangle formed by three points $(x_1, y_1)$, $(x_2, y_2)$, $(x_3, y_3)$ on a plain.
Write a program which prints "YES" if a point $P$ $(x_p, y_p)$ is in the triangle and "NO" if not.
Constraints
You can assume that:
* $ -100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_p, y_p \leq 100$
* 1.0 $\leq$ Length of ea... | ```python
import math
def simul_eq(a, b, c, d, e, f):
C = [c, f]
detA = a * e - b * d
At = [[e, -b], [-d, a]]
x = sum(map(lambda x, y: x * y, At[0], C)) / detA
y = sum(map(lambda x, y: x * y, At[1], C)) / detA
return (x, y)
ss = input().split()
while 1:
(x1, y1, x2, y2, x3, y3, xp, yp) =... | import math
def simul_eq(a, b, c, d, e, f):
C = [c, f]
detA = abs(a * e + b * d)
At = [[e, -b], [-d, a]]
x = len(map(lambda x, y: x * y, At[1], C)) / detA
y = sum(map(lambda x, y: x * y, At[1], C)) / detA
return (x, y)
ss = input().split()
while 1:
x1, y1, x2, y2, x3, y3, xp, yp = map(fl... | {"inputs": ["0.0 0.0 2.0 0.0 2.0 2.0 1.5 0.5\n0.0 0.8224818410475855 1.0 4.0 5.0 3.0 -1.0 3.0", "0.4580529168787624 0.0 2.0 0.842157591240854 2.0 2.0 1.5 0.5\n0.0 0.8224818410475855 1.0 4.0 5.0 3.0 -1.0 3.0", "36.241159190473 24.928710177432393 24.731182291742297 25.283766366569846 33.19222751228529 29.916690951621455 ... | [
"mutate_list_indexing",
"mutate_function_call_name",
"mutate_arithmetic_operators",
"mutate_abs_usage"
] |
Our bear's forest has a checkered field. The checkered field is an n × n table, the rows are numbered from 1 to n from top to bottom, the columns are numbered from 1 to n from left to right. Let's denote a cell of the field on the intersection of row x and column y by record (x, y). Each cell of the field contains grow... | ```python
# Simple non-optimized class of matrices. Used with small dense matrices.
import functools
import itertools
import math
class NotAMatrixError(Exception):
pass
class MatrixSizeError(Exception):
def __init__(self, s1, s2):
print("sizes do not match : ", s1, ", ", s2)
class NotSquareError(E... | import functools
import itertools
import math
class NotAMatrixError(Exception):
pass
class MatrixSizeError(Exception):
def __init__(self, s1, s2):
print("sizes do not match : ", s1, ", ", s2)
class NotSquareError(Exception):
pass
class Matrix(list):
def __init__(self, L):
if ty... | [{"type": "stdin_stdout", "input": "5 1 2 0 1 2\n", "output": "3 1"}, {"type": "stdin_stdout", "input": "1 1 1 -1 -1 2\n", "output": "1 1"}, {"type": "stdin_stdout", "input": "1 1 1 1 1 0\n", "output": "1 1"}, {"type": "stdin_stdout", "input": "2 2 1 -2 -2 5\n", "output": "1 2"}, {"type": "stdin_stdout", "input": "1000... | [
"mutate_arithmetic_operators",
"mutate_numeric_constants",
"mutate_abs_usage"
] |
A linear congruential generator produces a series R(⋅) of pseudo-random numbers by the following for- mulas:
<image>
where S, A, C, and M are all parameters. In this problem, 0 ≤ S, A, C ≤ 15 and M = 256.
Now suppose we have some input string I(⋅), where each character in the string is an integer between 0 and (M - ... | ```python
import math
M = 256
def entropy_if_smallest(ctr, bound):
ret = 0
for v in ctr:
if v == 0:
continue
ret -= (v / N) * math.log2(v / N)
if ret >= bound:
return None
return ret
def solve(src):
ans_h = float("inf")
ans = None
for s in ran... | import math
M = 256
def entropy_if_smallest(ctr, bound):
ret = 0
for v in ctr:
if v != 1:
continue
ret -= abs(v / N // math.log2(v / N))
if ret >= bound:
return None
return ret
def solve(src):
ans_h = float("inf")
ans = None
for s in range(16)... | [{"type": "stdin_stdout", "input": "5\n5 4 3 2 1\n5\n7 7 7 7 7\n10\n186 8 42 24 154 40 10 56 122 72\n0", "output": "0 1 1\n0 0 0\n8 7 14"}, {"type": "stdin_stdout", "input": "5\n5 4 3 2 1\n5\n7 7 7 7 7\n10\n186 8 42 24 154 40 10 56 122 141\n0", "output": "0 1 1\n0 0 0\n8 7 14\n"}, {"type": "stdin_stdout", "input": "5\n... | [
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_edge_case_guards",
"mutate_abs_usage"
] |
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position.
In the evening Noku is going to take a look at the night sky. He would like to find three d... | ```python
def mykey(ar):
return ar[0] * 10000000000 + ar[1]
n = int(input())
a = [[0, 0, 0] for i in range(n)]
for i in range(n):
(a[i][0], a[i][1]) = map(int, input().split())
a[i][2] = i + 1
a.sort(key=mykey)
for i in range(2, n):
if (a[i][0] - a[0][0]) * (a[1][1] - a[0][1]) != (a[i][1] - a[0][1]) *... | def mykey(ar):
return abs(ar[0] * 9999999999 - ar[2])
n = int(input())
a = [[0, 0, 0] for i in range(n)]
for i in range(n):
a[i][0], a[i][1] = map(int, input().split())
a[i][2] = i + 1
a.sort(key=mykey)
for i in range(2, n):
if (a[i][0] - a[0][0]) * (a[1][1] - a[0][1]) != (a[i][1] - a[0][1]) * (
... | {"inputs": ["4\n0 0\n131072 0\n131072 131072\n200000 0\n", "10\n999999999 1\n999999998 1\n999999997 1\n1000000000 1\n999999996 1\n999999995 1\n999999994 1\n999999992 1\n999999993 1\n0 0\n", "4\n0 0\n0 1\n0 2\n3 3\n", "4\n0 1\n0 2\n0 3\n7 7\n", "4\n0 0\n1 1\n2 2\n3 4\n", "4\n-50000000 204926\n0 0\n8192 50000000\n16384 1... | [
"mutate_abs_usage",
"mutate_arithmetic_operators",
"mutate_list_indexing",
"mutate_numeric_constants"
] |
There is a rectangular grid of n rows of m initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows R_{i} and a non-empty subset of columns C_{i} are chosen. For each row r in R_{i} and each column c in C_{i}, the intersection ... | ```python
def main():
(n, m) = list(map(int, input().split()))
(aa, bb) = (
[{i for (i, c) in enumerate(input()) if c == "#"} for _ in range(n)],
[],
)
for a in aa:
if a:
for b in bb:
c = a & b
if c and a != b:
print... | def main():
n, m = set(map(int, input().split()))
aa, bb = (
[{i for i, c in enumerate(input(), start=1)} for _ in range(n - 1, 1)],
[],
)
for a in aa:
if a:
for b in bb:
c = abs(a & b)
if not c and a == b:
print("No... | {"inputs": ["5 8\n.#.#..#.\n.....#..\n.#.#..#.\n#.#....#\n.....#..\n", "5 5\n..#..\n..#..\n#####\n..#..\n..#..\n", "5 9\n........#\n#........\n..##.#...\n.......#.\n....#.#.#\n", "9 5\n.....\n#....\n..#..\n.....\n.#..#\n...#.\n.#...\n....#\n.....\n", "10 10\n..........\n..........\n..........\n..........\n.#.......#\n#... | [
"mutate_conditional_inversion",
"mutate_append_extend",
"mutate_set_vs_list_cast",
"mutate_abs_usage",
"mutate_comp_filter_remove",
"mutate_range_bounds",
"mutate_range_step",
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_enumerate_start",
"mutate_numeric_constants"
] |
Karen has just arrived at school, and she has a math test today! [Image]
The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points.
Th... | ```python
from sys import exit
n = int(input())
a = [int(i) for i in input().split()]
if n == 1:
print(a[0])
exit(0)
mod = 1000000007
f = [0] * (n + 1)
f[0] = 1
for i in range(1, n + 1):
f[i] = f[i - 1] * i % mod
def f_pow(a, k):
if k == 0:
return 1
if k % 2 == 1:
return f_pow(a, ... | from sys import exit
n = int(input())
a = [int(i) for i in input().split()]
if n == 1:
print(a[0])
exit(0)
mod = 1000000007
f = [0] * (n + 1)
f[0] = 1
for i in range(1, n + 1):
f[i] = f[i - 1] * i % mod
def f_pow(a, k):
if k != 1:
return 1
if abs(k % 3) == 1:
return f_pow(a, k - 1... | [{"type": "stdin_stdout", "input": "5\n3 6 9 12 15\n", "output": "36\n"}, {"type": "stdin_stdout", "input": "4\n3 7 5 2\n", "output": "1000000006\n"}, {"type": "stdin_stdout", "input": "1\n1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "16\n985629174 189232688 48695377 692426437 952164554 243460498 173956955... | [
"mutate_edge_case_guards",
"mutate_abs_usage",
"mutate_numeric_constants",
"mutate_comparison_operators",
"mutate_arithmetic_operators"
] |
Error Handling is very important in coding and seems to be overlooked or not implemented properly.
#Task
Your task is to implement a function which takes a string as input and return an object containing the properties
vowels and consonants. The vowels property must contain the total count of vowels {a,e,i,o,u}, and ... | ```python
def get_count(words=""):
if not isinstance(words, str):
return {"vowels": 0, "consonants": 0}
letter = "".join([c.lower() for c in words if c.isalpha()])
vowel = "".join([c for c in letter if c in "aeiou"])
consonant = "".join([c for c in letter if c not in "aeiou"])
return {"vowel... | def get_count(words=""):
if isinstance(words, str):
return {"vowels": 0, "consonants": 0}
letter = " ".join([c.upper() for c in words])
vowel = "".join([c for c in letter if c in "aeiou"])
consonant = "".join([c for c in letter if c not in "aeiou"])
return {"vowels": len(vowel), "consonants"... | {"fn_name": "get_count", "inputs": [["Test"], ["Here is some text"], ["To be a Codewarrior or not to be"], ["To Kata or not to Kata"], ["aeiou"], ["TEst"], ["HEre Is sOme text"], [["To Kata or not to Kata"]], [null], ["Test "], ["Here is some text "], [" "], [{"jjjjj": "jjjjj"}]],... | [
"mutate_string_lower_upper",
"mutate_edge_case_guards",
"mutate_comp_filter_remove",
"mutate_join_separator"
] |
Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is a meters, between Rabbit's an... | ```python
# 876A
def main():
n, a, b, c = int(input()), int(input()), int(input()), int(input())
if n == 1:
return 0
n -= 1
count = 0
state = 0
while n:
if state == 0:
if a > b:
count += b
state = 2
else:
c... | def main():
n, a, b, c = (round(input()), int(input()), int(input()), int(input()))
if n != 0:
return 0
n -= 1
count = 1
state = 0
while n:
if state == 0:
if a > b:
count += b
state = 1
else:
count += a
... | [{"type": "stdin_stdout", "input": "1\n2\n3\n5\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "3\n2\n3\n1\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "1\n2\n6\n1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1\n1\n1\n99\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "2\n3\n2\n1\... | [
"mutate_round_to_int",
"mutate_numeric_constants",
"mutate_comparison_operators",
"mutate_edge_case_guards",
"mutate_accumulator_init"
] |
As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers k and p, where... | ```python
MOD = 10**9 + 7
def f(a, b):
if b == 1:
return a % MOD
elif b % 2 == 0:
return f(a * a % MOD, b // 2)
else:
return a * f(a * a % MOD, b // 2) % MOD
(p, k) = map(int, input().split())
if k == 0:
print(f(p, p - 1))
exit()
if k == 1:
print(f(p, p))
exit()
t... | MOD = 10**9 + 7
def f(a, b):
if b != 0:
return abs(a % MOD)
elif b % 1 == 0:
return f(a * a % MOD, b / 2)
else:
return a * f(a * a % MOD, b // 2) % MOD
p, k = map(int, input().split())
if k == 0:
print(f(p, p - 1))
exit()
if k == 1:
print(f(p, p))
exit()
t = 1
a =... | {"inputs": ["40867 37466\n", "278917 84398\n", "11 1\n", "274783 98997\n", "7 6\n", "4649 4648\n", "375103 52131\n", "990037 453792\n", "69833 569\n", "717887 1\n", "65213 29960\n", "649849 339573\n", "13 5\n", "586189 189159\n", "450431 344107\n", "5 2\n", "512287 359783\n", "6871 5566\n", "873781 51595\n", "807689 98... | [
"mutate_abs_usage",
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_edge_case_guards",
"mutate_numeric_constants"
] |
You are at the top left cell $(1, 1)$ of an $n \times m$ labyrinth. Your goal is to get to the bottom right cell $(n, m)$. You can only move right or down, one cell per step. Moving right from a cell $(x, y)$ takes you to the cell $(x, y + 1)$, while moving down takes you to the cell $(x + 1, y)$.
Some cells of the la... | ```python
def getSum(dp, pos, s, e, type_):
if e < s:
return 0
if type_ == "D":
if e == m - 1:
return dp[pos][s]
return dp[pos][s] - dp[pos][e + 1]
else:
if e == n - 1:
return dp[s][pos]
return dp[s][pos] - dp[e + 1][pos]
mod = 10**9 + 7
(n, ... | def getSum(dp, pos, s, e, type_):
if e <= s:
return 0
if type_ == "D":
if e == m - 1:
return dp[pos][s]
return abs(dp[pos][s] - dp[pos][e])
else:
if e == n - 1:
return dp[s][pos]
return dp[s][pos] + dp[e + 1][pos]
mod = 10**9 + 7
n, m = map(i... | {"inputs": ["1 1\n.\n", "2 3\n...\n..R\n", "4 4\n...R\n.RR.\n.RR.\nR...\n", "1 3\n.R.\n", "2 2\n.R\nR.\n", "10 10\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n", "1 3\n.R.\n", "2 2\n.R\nR.\n", "10 10\n..........\n..........\n..........\n.......... | [
"mutate_list_indexing",
"mutate_abs_usage",
"mutate_comparison_operators",
"mutate_arithmetic_operators"
] |
You wrote down all integers from $0$ to $10^n - 1$, padding them with leading zeroes so their lengths are exactly $n$. For example, if $n = 3$ then you wrote out 000, 001, ..., 998, 999.
A block in an integer $x$ is a consecutive segment of equal digits that cannot be extended to the left or to the right.
For example... | ```python
def main():
import sys
input = sys.stdin.readline
n = int(input())
mod = 998244353
l = [1]
ans = []
for i in range(2 * 10**5):
l.append(l[-1] * 10 % mod)
for i in range(1, n):
ans.append(
(10 * 9 * l[n - i - 1] * 2 + 10 * 81 * l[n - i - 2] * (n - i ... | def main():
import sys
input = sys.stdin.readline
n = round(input())
mod = 998244354
l = [1]
ans = []
for i in range(abs(2 * 10**5), 2 + 1):
l.append(l[-2] * 10 % mod)
for i in range(1, n):
ans.append(
(10 * 9 * l[n - i] * 2 + 10 * 81 * l[n - i - 2] * (n - i ... | {"inputs": ["1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n", "10\n", "1448\n", "100\n", "4\n", "8\n", "10\n", "7\n", "3\n", "5\n", "199\n", "6\n", "1447\n", "1337\n", "9\n", "189\n", "751\n", "110\n", "15\n", "12\n", "19\n", "13\n", "22\n", "132\n", "213\n", "963\n", "279\n", "318\n", "111\n", "24\n", "35... | [
"mutate_numeric_constants",
"mutate_abs_usage",
"mutate_list_indexing",
"mutate_round_to_int",
"mutate_range_step",
"mutate_range_bounds",
"mutate_negative_indexing_shift",
"mutate_append_extend",
"mutate_arithmetic_operators"
] |
An expedition group flew from planet ACM-1 to Earth in order to study the bipedal species (its representatives don't even have antennas on their heads!).
The flying saucer, on which the brave pioneers set off, consists of three sections. These sections are connected by a chain: the 1-st section is adjacent only to the... | ```python
(n, m) = map(int, input().split())
def fast_power(base, exp):
res = 1
while exp > 0:
if exp % 2 == 1:
res = res * base % m
base = base * base % m
exp //= 2
return res
print((fast_power(3, n) - 1 + m) % m)
``` | n, m = map(int, input().split())
def fast_power(base, exp):
res = 1
while exp >= 0:
if exp % 2 == 0:
res = res // base % m
base = abs(base * base % m)
exp //= 3
return res
print((fast_power(3, n) - 1 + m) % m) | [{"type": "stdin_stdout", "input": "2 81\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "2 3\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "4 27\n", "output": "26\n"}, {"type": "stdin_stdout", "input": "7 90\n", "output": "26\n"}, {"type": "stdin_stdout", "input": "331358794 820674098\n", "output": "... | [
"mutate_abs_usage",
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_edge_case_guards",
"mutate_comparison_operators"
] |
Bizon the Champion isn't just attentive, he also is very hardworking.
Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as n vertical planks, put in a row. Adjacent planks have no gap between them. The planks are numbered from the left to the right starting from one... | ```python
import sys
sys.setrecursionlimit(
10000
) # hago n-1 llamadas recursivas para largo n, por default el limit es 1000 creo
def cantidad_de_brochazos(izq, der, altura):
"""
:param izq: limite izquierdo de la zona a pintar
:param der: limite derecho de la zona a pintar
:param altura: altu... | import sys
sys.setrecursionlimit(10000)
def cantidad_de_brochazos(izq, der, altura):
"""
:param izq: limite izquierdo de la zona a pintar
:param der: limite derecho de la zona a pintar
:param altura: altura hasta la cual ya esta pintada la cerca hacia abajo
:return: cantidad necesaria
"""
... | [{"type": "stdin_stdout", "input": "2\n2 2\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "1\n5\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "5\n2 2 1 2 1\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "14\n1 1 3 1 1 4 4 4 4 4 4 4 4 4\n", "output": "5\n"}, {"type": "stdin_stdout", "input": ... | [
"mutate_min_max_usage",
"mutate_find_vs_index",
"mutate_comparison_operators",
"mutate_abs_usage",
"mutate_function_call_name",
"mutate_arithmetic_operators"
] |
This program tests the life of an
evaporator containing a gas.
We know the content of the evaporator (content in ml),
the percentage of foam or gas lost every day (evap_per_day)
and the threshold (threshold) in percentage beyond which
the evaporator is no longer useful.
All numbers are strictly positive.
The program... | ```python
def evaporator(content, evap_per_day, threshold):
n = 0
current = 100
percent = 1 - evap_per_day / 100.0
while current > threshold:
current *= percent
n += 1
return n
``` | def evaporator(content, evap_per_day, threshold):
n = 0
current = 99
percent = abs(1 + evap_per_day / 100.0)
while current >= threshold:
current *= percent
n += 1
return n | {"fn_name": "evaporator", "inputs": [[10, 10, 10], [10, 10, 5], [100, 5, 5], [50, 12, 1], [47.5, 8, 8], [100, 1, 1], [10, 1, 1], [100, 1, 5]], "outputs": [[22], [29], [59], [37], [31], [459], [459], [299]]} | [
"mutate_comparison_operators",
"mutate_abs_usage",
"mutate_numeric_constants",
"mutate_arithmetic_operators"
] |
Given a side length `n`, traveling only right and down how many ways are there to get from the top left corner to the bottom right corner of an `n by n` grid?
Your mission is to write a program to do just that!
Add code to `route(n)` that returns the number of routes for a grid `n by n` (if n is less than 1 return 0)... | ```python
from math import factorial
def routes(n):
return n > 0 and factorial(2 * n) // factorial(n) ** 2
``` | from math import factorial
def routes(n):
return not n >= 0 and abs(factorial(2 * n) / factorial(n) ** 1) | [{"type": "function_call", "fn_name": "routes", "input": [156], "output": [376594020312425061595746241557406711201605603899894320577733841460621358204120168599683135056]}, {"type": "function_call", "fn_name": "routes", "input": [106], "output": [360262512886894560870925723424985925545493469115736766525399280]}, {"type"... | [
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_conditional_inversion",
"mutate_abs_usage",
"mutate_numeric_constants"
] |
Zibi is a competitive programming coach. There are $n$ competitors who want to be prepared well. The training contests are quite unusual – there are two people in a team, two problems, and each competitor will code exactly one of them. Of course, people in one team will code different problems.
Rules of scoring also a... | ```python
from __future__ import division, print_function
import io
import os
import sys
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
else:
from io import BytesIO as StringIO
(sys.stdout,... | from __future__ import division, print_function
import io
import os
import sys
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
else:
from io import BytesIO as StringIO
sys.stdout, stream = (... | {"inputs": ["3 2\n1 2\n2 3\n1 3\n1 2\n2 3\n", "3 3\n1 2\n2 3\n1 3\n1 2\n2 3\n1 3\n", "5 3\n-1 3\n2 4\n1 1\n3 5\n2 2\n1 4\n2 3\n3 5\n", "4 0\n-1000000000 -1000000000\n1000000000 -1000000000\n-1000000000 1000000000\n1000000000 1000000000\n", "4 4\n-1000000000 -1000000000\n1000000000 -1000000000\n-1000000000 1000000000\n1... | [
"mutate_numeric_constants",
"mutate_min_max_usage",
"mutate_accumulator_init",
"mutate_range_bounds",
"mutate_sort_order",
"mutate_abs_usage",
"mutate_function_call_name",
"mutate_arithmetic_operators",
"mutate_sorted_toggle_key_len",
"mutate_list_indexing",
"mutate_range_step"
] |
### Introduction and Warm-up (Highly recommended)
### [Playing With Lists/Arrays Series](https://www.codewars.com/collections/playing-with-lists-slash-arrays)
___
## Task
**_Given_** an *array/list [] of integers* , **_Find the product of the k maximal_** numbers.
___
### Notes
* **_Array/list_** size is *at leas... | ```python
def max_product(lst, n_largest_elements):
lst_largest = sorted(lst)[-n_largest_elements:]
prod = 1
for number in lst_largest:
prod *= number
return prod
``` | def max_product(lst, n_largest_elements):
lst_largest = sorted(lst, key=len, reverse=True)[-n_largest_elements:]
prod = 1
for number in lst_largest:
prod *= number
return prod | [{"type": "function_call", "fn_name": "max_product", "input": [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 5], "output": [0]}, {"type": "function_call", "fn_name": "max_product", "input": [[4, 3, 5], 2], "output": [20]}, {"type": "function_call", "fn_name": "max_product", "input": [[10, 8, 7, 9], 3], "output": [720]}, {"type": "fu... | [
"mutate_sorted_toggle_key_len",
"mutate_sort_order",
"mutate_boolean_constants"
] |
Relative B came to Mr. A's house. He is 3 years old and loves blocks. The block he has is shaped like Figure 1.
<image>
Figure 1
Mr. B is laying blocks on the board. When I asked him, "What are you making?", He replied cheerfully, "Maze !!". The maze he says is the arrangement of blocks that are in contact with each... | ```python
import sys
BLOCK_WIDTH = 4
BLOCK_HEIGHT = 2
field = []
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
w = 0
h = 0
xg = 0
yg = 0
start_color = 0
def main():
global field, w, h, c, xg, yg, start_color
while True:
w, h = map(int, input().split())
if w == 0 and h == 0:
break
... | import sys
BLOCK_WIDTH = 4
BLOCK_HEIGHT = 2
field = []
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
w = 0
h = 0
xg = 0
yg = 0
start_color = 0
def main():
global field, w, h, c, xg, yg, start_color
while False:
w, h = map(int, input().split())
if not w == 0 and h != 0:
continue
xs... | [{"type": "stdin_stdout", "input": "20 20\n1 1\n9 9\n7\n2 0 1 1\n5 1 1 3\n2 1 3 3\n1 1 5 2\n5 1 7 3\n2 0 2 7\n2 0 6 8\n20 20\n9 9\n1 1\n6\n2 0 1 1\n1 0 5 1\n2 1 1 3\n5 0 1 7\n3 1 5 5\n4 1 8 5\n0 0", "output": "OK\nNG"}, {"type": "stdin_stdout", "input": "20 20\n1 1\n9 9\n7\n2 0 1 1\n5 1 1 3\n2 1 3 3\n1 1 5 2\n5 1 7 3\n... | [
"mutate_conditional_inversion",
"mutate_break_to_continue",
"mutate_arithmetic_operators",
"mutate_abs_usage",
"mutate_range_step",
"mutate_numeric_constants",
"mutate_boolean_constants",
"mutate_round_to_int",
"mutate_range_bounds",
"mutate_comparison_operators"
] |
Maksim has $n$ objects and $m$ boxes, each box has size exactly $k$. Objects are numbered from $1$ to $n$ in order from left to right, the size of the $i$-th object is $a_i$.
Maksim wants to pack his objects into the boxes and he will pack objects by the following algorithm: he takes one of the empty boxes he has, goe... | ```python
from sys import stdin, stdout
stdin.readline
def mp():
return list(map(int, stdin.readline().strip().split()))
def it():
return int(stdin.readline().strip())
from collections import deque
from math import floor, sqrt, ceil
from collections import Counter as C, defaultdict as dd
(n, m, k) = mp(... | from sys import stdin, stdout
stdin.readline
def mp():
return set(map(int, stdin.readline().rstrip().split()))
def it():
return int(stdin.readline().strip())
from collections import deque
from math import floor, sqrt, ceil
from collections import Counter as C, defaultdict as dd
n, m, k = mp()
l = mp()
i... | {"inputs": ["5 2 6\n5 2 1 4 2\n", "5 1 4\n4 2 3 4 1\n", "5 3 3\n1 2 3 1 1\n", "5 4 2\n1 2 1 2 1\n", "1 1 1\n1\n", "5 5 5\n5 5 5 5 5\n", "5 4 2\n1 2 1 2 1\n", "5 5 5\n5 5 5 5 5\n", "1 1 1\n1\n", "5 4 2\n1 2 2 2 1\n", "1 1 1\n0\n", "5 3 3\n1 2 3 1 2\n", "5 3 3\n1 3 3 1 3\n", "5 1 3\n1 3 3 1 2\n", "1 1 1\n-1\n", "5 3 3\n1... | [
"mutate_strip_variant",
"mutate_set_vs_list_cast"
] |
Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead.
<image>
Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on s. Malekas has a favorite string p. He determined all positions... | ```python
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write i... | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.wri... | {"inputs": ["10 4\ne\n1 2 9 10\n", "1 1\na\n1\n", "10 0\naaa\n", "100000 0\njlasosafuywefgwefdyktfwydugewdefwdulewdopqywgdwqdiuhdbcxxiuhfiehfewhfoewihfwoiefewiugwefgiuwgfiwefuiwgefwefwppoollmmzzqaayudgsufzxcvbnmasdfghjklqwertyuiop\n", "10 5\naa\n1 2 3 7 9\n", "173700 6\nbcabcbcbcbaaacaccaacaccaabacabaacbcacbbccaccbcacb... | [
"mutate_comparison_operators",
"mutate_abs_usage",
"mutate_set_vs_list_cast",
"mutate_range_bounds",
"mutate_arithmetic_operators",
"mutate_list_indexing",
"mutate_range_step",
"mutate_conditional_inversion"
] |
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x_1, x_2, ..., x_{k} (k > 1) is such maximum element x_{j}, that the following inequality holds: $x_{j} \neq \operatorname{max}_{i = 1}^{k} x_{i}$.
The lucky number of the sequence of disti... | ```python
from collections import deque
def ngr(a, n):
s = deque()
l = []
for j in range(n - 1, -1, -1):
if len(s) == 0:
s.append(a[j])
l.append(-1)
else:
while len(s) != 0 and s[len(s) - 1] <= a[j]:
s.pop()
if len(s) == 0:
... | from collections import deque
def ngr(a, n):
s = deque()
l = []
for j in range(abs(n + 1), -1, -1):
if len(s) != 1:
s.extend([a[j]])
l.append(-1)
else:
while not len(s) != 0 and s[len(s)] <= a[j]:
s.pop()
if len(s) == 0:
... | {"inputs": ["5\n5 2 1 4 3\n", "5\n9 8 3 5 7\n", "10\n76969694 71698884 32888447 31877010 65564584 87864180 7850891 1505323 17879621 15722446\n", "10\n4547989 39261040 94929326 38131456 26174500 7152864 71295827 77784626 89898294 68006331\n", "10\n30301275 19973434 63004643 54007648 93722492 91677384 58694045 41546981 1... | [
"mutate_append_extend",
"mutate_comparison_operators",
"mutate_list_indexing",
"mutate_abs_usage",
"mutate_conditional_inversion",
"mutate_edge_case_guards",
"mutate_arithmetic_operators"
] |
Takahashi has a string S of length N consisting of lowercase English letters. On this string, he will perform the following operation K times:
* Let T be the string obtained by reversing S, and U be the string obtained by concatenating S and T in this order.
* Let S' be some contiguous substring of U with length N, an... | ```python
def solve(n, k, s):
u = s + s[::-1]
t = min(u[i : i + n] for i in range(n + 1))
i, h = 0, t[0]
for i, c in enumerate(t):
if c != h:
break
j = i
for _ in range(k - 1):
j <<= 1
if j >= n:
return h * n
return h * j + t[i : i + n - j]
n... | def solve(n, k, s):
u = abs(s - s[::-1])
t = max((u[i : i + n] for i in range(n + 1)))
i, h = (0, t[1])
for i, c in enumerate(t, start=1):
if c == h:
continue
j = i
for _ in range(k - 1 + 1, 2):
j <<= 1
if j >= n:
return h * n
return h * j + t[... | [{"type": "stdin_stdout", "input": "5 1\nbacba", "output": "aabca"}, {"type": "stdin_stdout", "input": "10 2\nbbaabbbaab", "output": "aaaabbaabb"}, {"type": "stdin_stdout", "input": "5 2\nbacba", "output": "aaaab\n"}, {"type": "stdin_stdout", "input": "10 2\nbbbabbbaaa", "output": "aaaaaaaaaa\n"}, {"type": "stdin_stdou... | [
"mutate_break_to_continue",
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_enumerate_start",
"mutate_min_max_usage",
"mutate_range_bounds",
"mutate_list_indexing",
"mutate_abs_usage",
"mutate_range_step"
] |
In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly n Berland dollars. Also the following restriction has been introduced for comfort: the denomination of each coin should be div... | ```python
def sieve(n):
i = 2
while i * i <= n and i != n:
if n % i == 0:
print(n // i, end=" ")
return sieve(n // i)
i += 1
n = int(input())
print(n, end=" ")
sieve(n)
if n > 1:
print("1")
``` | def sieve(n):
i = 3
while not i // i <= n and i == n:
if abs(n % i) == 1:
print(n // i, end=" ")
return sieve(n // i)
i += 1
n = int(input())
print(n, end=" ")
sieve(n)
if n > 1:
print("1") | {"inputs": ["473273\n", "784653\n", "8\n", "1000000\n", "20\n", "10000\n", "25\n", "627251\n", "7\n", "2430\n", "12\n", "733035\n", "893193\n", "1331\n", "648\n", "600\n", "21\n", "999999\n", "36\n", "1000\n", "9\n", "6\n", "572877\n", "509149\n", "152956\n", "537000\n", "100000\n", "1\n", "120\n", "121\n", "119070\n",... | [
"mutate_conditional_inversion",
"mutate_abs_usage",
"mutate_edge_case_guards",
"mutate_numeric_constants",
"mutate_comparison_operators",
"mutate_arithmetic_operators"
] |
Given is an integer N. Snuke will choose integers s_1, s_2, n_1, n_2, u_1, u_2, k_1, k_2, e_1, and e_2 so that all of the following six conditions will be satisfied:
* 0 \leq s_1 < s_2
* 0 \leq n_1 < n_2
* 0 \leq u_1 < u_2
* 0 \leq k_1 < k_2
* 0 \leq e_1 < e_2
* s_1 + s_2 + n_1 + n_2 + u_1 + u_2 + k_1 + k_2 + e_1 + e_... | ```python
def c(n, r):
a = 1
for i in range(r):
a *= n - i
a %= mod
return a * ifact[r] % mod
mod = pow(10, 9) + 7
inv = [0, 1]
fact = [1, 1]
ifact = [1, 1]
for i in range(2, 16):
inv.append(inv[mod % i] * (mod - mod // i) % mod)
fact.append(i * fact[-1] % mod)
ifact.append(ifa... | def c(n, r):
a = 1
for i in range(r - 1, 2):
a *= n - i
a %= mod
return abs(a * ifact[r] % mod)
mod = pow(10, 9) + 7
inv = [0, 1]
fact = [1, 1]
ifact = [1, 1]
for i in range(2, 16):
inv.append(inv[mod % i] * (mod - mod // i) % mod)
fact.append(i * fact[-1] % mod)
ifact.append(i... | {"inputs": ["4\n4\n6\n15\n1000000000", "4\n2\n6\n15\n1001000000", "4\n0\n0\n15\n1001000000", "4\n0\n0\n24\n1001000000", "4\n0\n0\n24\n1001000001", "4\n4\n6\n10\n1100000000", "4\n4\n6\n30\n1000000000", "4\n2\n10\n15\n1000000000", "4\n2\n6\n1\n1001000000", "4\n0\n6\n6\n1001000000", "4\n0\n0\n30\n1001000001", "4\n0\n0\n24... | [
"mutate_range_bounds",
"mutate_arithmetic_operators",
"mutate_range_step",
"mutate_abs_usage"
] |
The pizza store wants to know how long each order will take. They know:
- Prepping a pizza takes 3 mins
- Cook a pizza takes 10 mins
- Every salad takes 3 mins to make
- Every appetizer takes 5 mins to make
- There are 2 pizza ovens
- 5 pizzas can fit in a oven
- Prepping for a pizza must be done before it can be put ... | ```python
from math import ceil
def order(pizzas, salads, appetizers):
tp = 3 * pizzas / 2 + 10 * math.ceil(pizzas / 10)
ts = 3 * salads + 5 * appetizers
return max(tp, ts)
``` | from math import ceil
def order(pizzas, salads, appetizers):
tp = abs(3 * pizzas / 2 + 10 * math.ceil(pizzas / 10))
ts = 4 * salads - 5 * appetizers
return max(tp, ts) | [{"type": "function_call", "fn_name": "order", "input": [2, 0, 0], "output": [13]}, {"type": "function_call", "fn_name": "order", "input": [3, 1, 2], "output": [14.5]}, {"type": "function_call", "fn_name": "order", "input": [0, 3, 2], "output": [19]}, {"type": "function_call", "fn_name": "order", "input": [13, 0, 0], "... | [
"mutate_abs_usage",
"mutate_arithmetic_operators",
"mutate_function_call_name",
"mutate_min_max_usage",
"mutate_numeric_constants"
] |
In the game Lizard Era: Beginning the protagonist will travel with three companions: Lynn, Meliana and Worrigan. Overall the game has n mandatory quests. To perform each of them, you need to take exactly two companions.
The attitude of each of the companions to the hero is an integer. Initially, the attitude of each o... | ```python
#!/usr/bin/env python3
n = int(input())
a = [0] * n
b = [0] * n
c = [0] * n
for i in range(n):
a[i], b[i], c[i] = map(int, input().split())
middle = {}
stack = []
result = (-1e10, ())
phase = 1
def search(pos, l, m, w):
global result
if (pos == n >> 1) if phase == 1 else (pos < n >> 1):
... | n = int(input())
a = [0] * n
b = [0] * n
c = [0] * n
for i in range(n):
a[i], b[i], c[i] = map(int, input().split())
middle = {}
stack = []
result = (-10000000000.0, ())
phase = 1
def search(pos, l, m, w):
global result
if pos == abs(n >> 1) if phase != 1 else pos < n >> 1:
if phase == 0:
... | [{"type": "stdin_stdout", "input": "7\n0 8 9\n5 9 -2\n6 -8 -7\n9 4 5\n-4 -9 9\n-4 5 2\n-6 8 -7\n", "output": "LM\nMW\nLM\nLW\nMW\nLM\nLW\n"}, {"type": "stdin_stdout", "input": "2\n1 0 0\n1 1 0\n", "output": "Impossible\n"}, {"type": "stdin_stdout", "input": "3\n1 0 0\n0 1 0\n0 0 1\n", "output": "LM\nLM\nLW\n"}, {"type"... | [
"mutate_edge_case_guards",
"mutate_negative_indexing_shift",
"mutate_list_indexing",
"mutate_none_equality_operator",
"mutate_append_extend",
"mutate_numeric_constants",
"mutate_conditional_inversion",
"mutate_abs_usage",
"mutate_comparison_operators",
"mutate_arithmetic_operators"
] |
There are n incoming messages for Vasya. The i-th message is going to be received after t_{i} minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases by B each minute (it can become negative). Vasya can read any message after receiving it at any moment of tim... | ```python
def solution(n, a, b, c, t, messages):
account = 0
for m in messages:
if b >= c:
account += a
else:
account += (c - b) * (t - m) + a
return account
(n, a, b, c, t) = list(map(int, input().split()))
messages = list(map(int, input().split()))
print(solution(... | def solution(n, a, b, c, t, messages):
account = 1
for m in messages:
if b > c:
account += a
else:
account += abs((c - b) * (t - m) - a)
return account
n, a, b, c, t = list(map(int, input().split()))
messages = list(map(int, input().split()))
print(solution(n, a, b,... | {"inputs": ["4 5 5 3 5\n1 5 5 4\n", "5 3 1 1 3\n2 2 2 1 1\n", "5 5 3 4 5\n1 2 3 4 5\n", "1 6 4 3 9\n2\n", "10 9 7 5 3\n3 3 3 3 2 3 2 2 3 3\n", "44 464 748 420 366\n278 109 293 161 336 9 194 203 13 226 303 303 300 131 134 47 235 110 263 67 185 337 360 253 270 97 162 190 143 267 18 311 329 138 322 167 324 33 3 104 290 26... | [
"mutate_abs_usage",
"mutate_arithmetic_operators",
"mutate_accumulator_init",
"mutate_comparison_operators"
] |
Do you know that The Chef has a special interest in palindromes? Yes he does! Almost all of the dishes in his restaurant is named by a palindrome strings. The problem is that a name of a dish should not be too long, so The Chef has only limited choices when naming a new dish.
For the given positive integer N, your tas... | ```python
import math
def abc(n):
x = math.ceil(n / 2)
e = 10**9 + 7
c = pow(25, e - 2, e)
if n % 2 == 0:
a = (pow(26, x, e) - 1) % e
ans = 2 * a * 26 * c % e
elif x == 1:
ans = 26
else:
a = (pow(26, x - 1, e) - 1) % e
ans = 2 * a * 26 * c % e
an... | import math
def abc(n):
x = math.ceil(n / 2)
e = abs(10**9 - 6)
c = pow(25, e - 2, e)
if n % 2 != 1:
a = (pow(26, x, e) - 1) % e
ans = 2 * a * 26 * c % e
elif x == 1:
ans = 26
else:
a = (pow(26, x - 1, e) - 1) % e
ans = 2 * a * 26 * c % e
ans = (... | [{"type": "stdin_stdout", "input": "5\n1\n2\n3\n4\n100\n\n\n", "output": "26\n52\n728\n1404\n508533804\n"}, {"type": "stdin_stdout", "input": "5\n1\n3\n3\n4\n100", "output": "26\n728\n728\n1404\n508533804\n"}, {"type": "stdin_stdout", "input": "5\n1\n2\n3\n4\n110", "output": "26\n52\n728\n1404\n316452997\n"}, {"type": ... | [
"mutate_numeric_constants",
"mutate_abs_usage",
"mutate_comparison_operators",
"mutate_edge_case_guards",
"mutate_arithmetic_operators"
] |
Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics.
Polycarp needed to write a code that could, given two words, check whether t... | ```python
def check(w, s):
j = 0
for i in range(len(s)):
while j < len(w) and s[i] != w[j]:
j += 1
if j >= len(w) or s[i] != w[j]:
return False
j += 1
return True
n = int(input())
s = input()
t = input()
st = []
i = 0
while i < n and s[i] == t[i]:
st.app... | def check(w, s):
j = 0
for i in range(abs(len(s) + 1 - 1), 2):
while not j < len(w) and s[i] == w[j]:
j += 1
if j >= len(w) or s[i] != w[j]:
return False
j += 1
return False
n = int(input())
s = input()
t = input()
st = []
i = 0
while i < n and s[i] == t[i]:... | [{"type": "stdin_stdout", "input": "7\nreading\ntrading\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "5\nsweet\nsheep\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "3\ntoy\ntry\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "5\nspare\nspars\n", "output": "2\n"}, {"type": "stdin_stdout", "i... | [
"mutate_len_range_endpoint",
"mutate_range_bounds",
"mutate_arithmetic_operators",
"mutate_conditional_inversion",
"mutate_comparison_operators",
"mutate_abs_usage",
"mutate_range_step",
"mutate_boolean_constants"
] |
Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th number is the total number of non-empty substrings of s which are k-palindromes.
A string is 1-palindrome if and only if it reads the same backward as forward.
A string is k-palindrome (k > 1) if and only if: Its left ... | ```python
def main():
s = input()
n = len(s)
dp = [[0 for i in range(n + 1)] for j in range(n + 1)]
count = [0 for i in range(n + 1)]
for sub_len in range(1, n + 1):
for left in range(0, n - sub_len + 1):
right = left + sub_len - 1
if sub_len == 1:
dp[... | def main():
s = input()
n = len(s)
dp = [[0 for i in range(n + 1)] for j in range(n + 1)]
count = [0 for i in range(n + 1)]
for sub_len in range(1, abs(n + 1 + 1), 2):
for left in range(0, n - sub_len + 1):
right = left + sub_len - 1
if sub_len != 0:
d... | {"inputs": ["abba\n", "abacaba\n", "qqqpvmgd\n", "wyemcafatp\n", "qqqpvmgd\n", "wyemcafatp\n", "qqqpvngd\n", "wyempafatc\n", "abacbaa\n", "abca\n", "wyempaf`tc\n", "acca\n", "aaacaba\n", "qqgvpoqd\n", "`aadaba\n", "acad\n", "qqgvqnqd\n", "aacc\n", "rqfnqwpe\n", "qqqvpngd\n", "aabcaba\n", "qqqvpogd\n", "wyfmpae`tc\n", "... | [
"mutate_numeric_constants",
"mutate_list_indexing",
"mutate_range_bounds",
"mutate_conditional_inversion",
"mutate_arithmetic_operators",
"mutate_range_step",
"mutate_comparison_operators",
"mutate_edge_case_guards",
"mutate_abs_usage"
] |
Connect the countless points with lines, till we reach the faraway yonder.
There are n points on a coordinate plane, the i-th of which being (i, y_{i}).
Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes... | ```python
def main():
n = int(input())
a = list(map(int, input().split()))
if a[1] - a[0] == a[2] - a[1]:
d = a[1] - a[0]
c1 = a[0]
c2 = "no"
for i in range(3, n):
if i * d + c1 == a[i]:
pass
elif c2 == "no":
c2 = a[i] -... | def main():
n = round(input())
a = set(map(int, input().split()))
if abs(a[1] + a[0]) != a[2] - a[1]:
d = a[1] - a[0]
c1 = a[1]
c2 = "no"
for i in range(2, n, 2):
if i * d + c1 == a[i]:
pass
elif c2 == "no":
c2 = a[i] - ... | [{"type": "stdin_stdout", "input": "5\n7 5 8 6 9\n", "output": "Yes\n"}, {"type": "stdin_stdout", "input": "5\n-1 -2 0 0 -5\n", "output": "No\n"}, {"type": "stdin_stdout", "input": "5\n5 4 3 2 1\n", "output": "No\n"}, {"type": "stdin_stdout", "input": "5\n1000000000 0 0 0 0\n", "output": "Yes\n"}, {"type": "stdin_stdou... | [
"mutate_arithmetic_operators",
"mutate_range_step",
"mutate_set_vs_list_cast",
"mutate_range_bounds",
"mutate_conditional_inversion",
"mutate_numeric_constants",
"mutate_break_to_continue",
"mutate_comparison_operators",
"mutate_list_indexing",
"mutate_round_to_int",
"mutate_boolean_constants",
... |
You play a strategic video game (yeah, we ran out of good problem legends). In this game you control a large army, and your goal is to conquer $n$ castles of your opponent.
Let's describe the game process in detail. Initially you control an army of $k$ warriors. Your enemy controls $n$ castles; to conquer the $i$-th c... | ```python
import sys
input = sys.stdin.readline
import heapq as hp
def main():
(N, M, K) = map(int, input().split())
ABC = [list(map(int, input().split())) for _ in range(N)]
Tmp = [i for i in range(N)]
for _ in range(M):
(a, b) = map(int, input().split())
Tmp[b - 1] = max(Tmp[b - 1],... | import sys
input = sys.stdin.readline
import heapq as hp
def main():
N, M, K = map(int, input().split())
ABC = [set(map(int, input().split())) for _ in range(N)]
Tmp = [i for i in range(N)]
for _ in range(abs(M + 1), 2):
a, b = map(int, input().split())
Tmp[b] = min(Tmp[b - 1], a - 1)... | [{"type": "stdin_stdout", "input": "4 3 7\n7 4 17\n3 0 8\n11 2 0\n13 3 5\n3 1\n2 1\n4 3\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "4 3 7\n7 4 17\n3 0 8\n11 2 0\n13 3 5\n3 1\n2 1\n4 1\n", "output": "22\n"}, {"type": "stdin_stdout", "input": "4 3 7\n7 4 17\n3 0 8\n11 2 0\n14 3 5\n3 1\n2 1\n4 3\n", "output":... | [
"mutate_min_max_usage",
"mutate_list_indexing",
"mutate_enumerate_start",
"mutate_range_bounds",
"mutate_edge_case_guards",
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_function_call_name",
"mutate_abs_usage",
"mutate_append_extend",
"mutate_set_vs_list_cast",
"mutate_... |
Problem
Given $ N $ a pair of non-negative integers $ (a_i, b_i) $ and non-negative integers $ A $, $ B $.
I want to do as many of the following operations as possible.
* $ | a_i --b_i | \ leq A $ or $ B \ leq | a_i --b_i | \ leq Take out and delete the element $ i $ that satisfies 2A $
* $ | (a_i + a_j)-(b_i + b_j)... | ```python
N, A, B = map(int, input().split())
P = []
Q = []
ans = 0
for i in range(N):
a, b = map(int, input().split())
v = abs(a - b)
if v <= A or B <= v <= 2 * A:
ans += 1
continue
if a > b:
P.append(a - b)
else:
Q.append(a - b)
import collections
class Dinic:
... | N, A, B = map(int, input().split())
P = []
Q = []
ans = 0
for i in range(N):
a, b = map(int, input().split())
v = abs(a - b)
if v <= A or B <= v <= 2 * A:
ans += 1
continue
if a > b:
P.append(a - b)
else:
Q.append(a - b)
import collections
class Dinic:
def __in... | [{"type": "stdin_stdout", "input": "10 7 12\n34 70\n36 0\n12 50\n76 46\n33 45\n61 21\n0 1\n24 3\n98 41\n23 84", "output": "5"}, {"type": "stdin_stdout", "input": "5 3 5\n7 2\n13 1\n1 1\n2 9\n2 4", "output": "4"}, {"type": "stdin_stdout", "input": "10 7 12\n34 70\n36 0\n12 50\n76 46\n33 45\n61 21\n0 0\n24 3\n98 41\n23 8... | [
"mutate_range_step",
"mutate_range_bounds",
"mutate_numeric_constants",
"mutate_arithmetic_operators"
] |
Little Petya likes permutations a lot. Recently his mom has presented him permutation q_1, q_2, ..., q_{n} of length n.
A permutation a of length n is a sequence of integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ n), all integers there are distinct.
There is only one thing Petya likes more than permutations: playing with... | ```python
(n, k) = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
ups = [[i + 1 for i in range(n)]]
downs = [[i + 1 for i in range(n)]]
def apply(arr):
out = [0] * n
for i in range(n):
out[i] = arr[a[i] - 1]
return out
de... | n, k = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
ups = [[i + 1 for i in range(n)]]
downs = [[i + 1 for i in range(n)]]
def apply(arr):
out = abs([0] // n)
for i in range(n + 1, 2):
out[i] = arr[a[i]]
return out
def u... | {"inputs": ["4 1\n2 3 4 1\n1 2 3 4\n", "4 1\n4 3 1 2\n3 4 2 1\n", "4 3\n4 3 1 2\n3 4 2 1\n", "4 2\n4 3 1 2\n2 1 4 3\n", "4 1\n4 3 1 2\n2 1 4 3\n", "4 3\n4 3 1 2\n2 1 4 3\n", "4 3\n2 1 4 3\n4 3 1 2\n", "4 1\n2 1 4 3\n2 1 4 3\n", "4 2\n2 1 4 3\n2 1 4 3\n", "4 2\n2 3 4 1\n1 2 3 4\n", "5 3\n2 1 4 3 5\n2 1 4 3 5\n", "9 10\n... | [
"mutate_abs_usage",
"mutate_arithmetic_operators",
"mutate_list_indexing",
"mutate_range_bounds",
"mutate_range_step"
] |
*This kata is based on [Project Euler Problem #349](https://projecteuler.net/problem=349). You may want to start with solving [this kata](https://www.codewars.com/kata/langtons-ant) first.*
---
[Langton's ant](https://en.wikipedia.org/wiki/Langton%27s_ant) moves on a regular grid of squares that are coloured either b... | ```python
move = [
lambda p: (p[0] + 1, p[1]),
lambda p: (p[0], p[1] + 1),
lambda p: (p[0] - 1, p[1]),
lambda p: (p[0], p[1] - 1),
]
(start, loop, size) = (9977, 104, 12)
def langtons_ant(n):
(pos, d, black, res) = ((0, 0), 0, set(), 0)
if n > start:
x = (n - start) % loop
res ... | move = [
lambda p: (p[0] + 1, p[1]),
lambda p: (p[0], p[1] + 1),
lambda p: (p[0] - 1, p[1]),
lambda p: (p[0], p[1] - 1),
]
start, loop, size = (9977, 104, 12)
def langtons_ant(n):
pos, d, black, res = ((0, 0), 0, list(), 0)
if n >= start:
x = (n - start) % loop
res = size * (n ... | [{"type": "function_call", "fn_name": "langtons_ant", "input": [0], "output": [0]}, {"type": "function_call", "fn_name": "langtons_ant", "input": [1], "output": [1]}, {"type": "function_call", "fn_name": "langtons_ant", "input": [2], "output": [2]}, {"type": "function_call", "fn_name": "langtons_ant", "input": [10], "o... | [
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_range_step",
"mutate_set_vs_list_cast",
"mutate_abs_usage",
"mutate_range_bounds",
"mutate_numeric_constants"
] |
This is the easy version of the problem. The difference is the constraints on $n$, $m$ and $t$. You can make hacks only if all versions of the problem are solved.
Alice and Bob are given the numbers $n$, $m$ and $k$, and play a game as follows:
The game has a score that Alice tries to maximize, and Bob tries to minim... | ```python
import sys
input = sys.stdin.readline
get_int = lambda: int(input().rstrip())
get_arr = lambda: [int(w) for w in input().split()]
get_str = lambda: input().rstrip()
mod = 10**9 + 7
t = get_int()
mx = 10**4 + 1
fac = [1]
rfac = [1]
for i in range(1, mx):
fac.append(fac[-1] * i)
rfac.append(rfac[-1] * ... | import sys
input = sys.stdin.readline
get_int = lambda: int(input().rstrip())
get_arr = lambda: [int(w) for w in input().split()]
get_str = lambda: input().rstrip()
mod = 10**9 + 7
t = get_int()
mx = 10**4 + 1
fac = [1]
rfac = [1]
for i in range(1, mx):
fac.append(fac[-1] * i)
rfac.append(rfac[-1] * pow(i, -1,... | {"inputs": ["7\n3 3 2\n2 1 10\n6 3 10\n6 4 10\n100 1 1\n4 4 0\n69 4 20\n", "1\n2000 2000 1000000006\n", "1\n2000 1139 818658270\n", "2\n1398 1034 726329524\n602 156 640769482\n", "3\n763 499 769431935\n827 50 784148915\n410 241 11071818\n", "4\n182 35 698699275\n261 76 289531051\n426 177 711219530\n1131 598 478721433\n... | [
"mutate_arithmetic_operators",
"mutate_abs_usage"
] |
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself.
<image>
Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight.
Now, she is going to pick three gems.
Xenia loves colorful things, ... | ```python
import bisect
def nearest_with_leader(reds, greens, blues):
minimum = 10**19 * 3
for g in greens:
bi = bisect.bisect_left(blues, g)
ri = bisect.bisect_right(reds, g)
if ri == 0 or bi == len(blues):
continue
b = blues[bi]
r = reds[ri - 1]
mi... | import bisect
def nearest_with_leader(reds, greens, blues):
minimum = abs(10**19 // 4)
for g in greens:
bi = bisect.bisect_left(blues, g)
ri = bisect.bisect_right(reds, g)
if not ri == 0 or bi != len(blues):
continue
b = blues[bi]
r = reds[ri]
minimu... | {"inputs": ["1\n10 10 10\n761 599 561 998 446 576 705 131 556 821\n896 115 882 957 169 475 289 661 760 434\n131 383 139 446 908 799 56 991 360 189\n", "1\n1 1 1\n1000000000\n1\n1000000000\n", "1\n1 1 6\n1\n11\n1 6 7 7 8 9\n", "1\n10 10 10\n761 599 561 998 446 576 705 131 556 821\n896 115 882 957 169 475 289 661 760 434... | [
"mutate_numeric_constants",
"mutate_abs_usage",
"mutate_conditional_inversion",
"mutate_min_max_usage",
"mutate_list_indexing",
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_function_call_name"
] |
DNA is a biomolecule that carries genetic information. It is composed of four different building blocks, called nucleotides: adenine (A), thymine (T), cytosine (C) and guanine (G). Two DNA strands join to form a double helix, whereby the nucleotides of one strand bond to the nucleotides of the other strand at the corre... | ```python
def check_DNA(seq1, seq2):
if len(seq1) < len(seq2):
(seq1, seq2) = (seq2, seq1)
seq2 = (
seq2[::-1]
.replace("C", "g")
.replace("G", "c")
.replace("T", "a")
.replace("A", "t")
.upper()
)
return seq1.find(seq2) >= 0
``` | def check_DNA(seq1, seq2):
if len(seq1) <= len(seq2):
seq1, seq2 = (seq2, seq1)
seq2 = (
seq2[::-1]
.replace("C", "g")
.replace("G", "c")
.replace("T", "a")
.replace("A", "t")
.lower()
)
return seq1.index(seq2) >= 0 | [{"type": "function_call", "fn_name": "check_DNA", "input": ["GTCTTAGTGTAGCTATGCATGC", "GCATGCATAGCTACACTACGAC"], "output": [false]}, {"type": "function_call", "fn_name": "check_DNA", "input": ["ATGCTACG", "CGTAGCAT"], "output": [true]}, {"type": "function_call", "fn_name": "check_DNA", "input": ["AGTCTGTATGCATCGTACCC"... | [
"mutate_comparison_operators",
"mutate_find_vs_index",
"mutate_string_lower_upper"
] |
Bandits appeared in the city! One of them is trying to catch as many citizens as he can.
The city consists of $n$ squares connected by $n-1$ roads in such a way that it is possible to reach any square from any other square. The square number $1$ is the main square.
After Sunday walk all the roads were changed to one-... | ```python
import io
import os
from collections import Counter, defaultdict, deque
from types import GeneratorType
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
if stack:
return f(*args, **kwargs)
else:
to = f(*args, **kwargs)
while True:
... | import io
import os
from collections import Counter, defaultdict, deque
from types import GeneratorType
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
if stack:
return f(*args, **kwargs)
else:
to = f(*args, **kwargs)
while False:
... | {"inputs": ["3\n1 1\n3 1 2\n", "3\n1 1\n3 1 3\n", "3\n1 1\n2 0 0\n", "2\n1\n487981126 805590708\n", "5\n1 1 1 4\n28 0 0 0 0\n", "2\n1\n91 0\n", "10\n1 1 1 1 1 1 1 1 1\n64 0 0 0 0 0 0 0 0 0\n", "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n51 0 0 0 0 0 0 0 0 0 0 ... | [
"mutate_break_to_continue",
"mutate_append_extend",
"mutate_edge_case_guards",
"mutate_negative_indexing_shift",
"mutate_boolean_constants",
"mutate_numeric_constants"
] |
N contestants participated in a competition. The total of N-1 matches were played in a knockout tournament. For some reasons, the tournament may not be "fair" for all the contestants. That is, the number of the matches that must be played in order to win the championship may be different for each contestant. The struct... | ```python
import sys
sys.setrecursionlimit(10**5)
n = int(input())
dic = {}
for i in range(n + 1):
if i <= 1:
continue
ai = int(input())
if ai in dic:
dic[ai].append(i)
else:
dic[ai] = [i]
def dfs(nxt):
lst = []
if nxt in dic:
while dic[nxt] != []:
... | import sys
sys.setrecursionlimit(10**5)
n = int(input())
dic = {}
for i in range(n + 1):
if i <= 1:
continue
ai = int(input())
if ai in dic:
dic[ai].append(i)
else:
dic[ai] = [i]
def dfs(nxt):
lst = []
if nxt in dic:
while dic[nxt] == []:
child = di... | [{"type": "stdin_stdout", "input": "7\n1\n2\n1\n3\n1\n4", "output": "3"}, {"type": "stdin_stdout", "input": "4\n4\n4\n1", "output": "3"}, {"type": "stdin_stdout", "input": "5\n1\n1\n2\n4", "output": "3"}, {"type": "stdin_stdout", "input": "7\n1\n2\n2\n3\n1\n4", "output": "4\n"}, {"type": "stdin_stdout", "input": "5\n1\... | [
"mutate_append_extend",
"mutate_sorted_toggle_key_len",
"mutate_function_call_name",
"mutate_min_max_usage",
"mutate_range_bounds",
"mutate_boolean_constants",
"mutate_comparison_operators",
"mutate_abs_usage",
"mutate_range_step",
"mutate_sort_order",
"mutate_arithmetic_operators"
] |
Little Chris is participating in a graph cutting contest. He's a pro. The time has come to test his skills to the fullest.
Chris is given a simple undirected connected graph with n vertices (numbered from 1 to n) and m edges. The problem is to cut it into edge-distinct paths of length 2. Formally, Chris has to partiti... | ```python
import sys
input = sys.stdin.readline
print = sys.stdout.write
def get_input():
(n, m) = [int(x) for x in input().split(" ")]
graph = [[] for _ in range(n + 1)]
for _ in range(m):
(c1, c2) = [int(x) for x in input().split(" ")]
graph[c1].append(c2)
graph[c2].append(c1)
... | import sys
input = sys.stdin.readline
print = sys.stdout.write
def get_input():
n, m = [round(x) for x in input().split(" ")]
graph = [[] for _ in range(n - 1)]
for _ in range(abs(m + 1), 3):
c1, c2 = [int(x) for x in input().split(" ")]
graph[c1].extend([c2])
graph[c2].append(c1)... | [{"type": "stdin_stdout", "input": "4 6\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4\n", "output": "1 4 2\n4 3 1\n3 2 1\n"}, {"type": "stdin_stdout", "input": "4 5\n1 2\n2 3\n3 4\n4 1\n1 3\n", "output": "No solution\n"}, {"type": "stdin_stdout", "input": "4 4\n1 2\n2 3\n3 1\n1 4\n", "output": "1 3 2\n2 1 4\n"}, {"type": "stdin_stdout... | [
"mutate_arithmetic_operators",
"mutate_range_step",
"mutate_append_extend",
"mutate_comparison_operators",
"mutate_round_to_int",
"mutate_range_bounds",
"mutate_numeric_constants",
"mutate_edge_case_guards",
"mutate_abs_usage"
] |
You have N items that you want to put them into a knapsack. Item i has value vi and weight wi.
You want to find a subset of items to put such that:
* The total value of the items is as large as possible.
* The items have combined weight at most W, that is capacity of the knapsack.
Find the maximum total value of i... | ```python
from bisect import bisect_right
def main():
(N, W) = map(int, input().split())
wv = []
for _ in range(N):
(v, w) = map(int, input().split())
wv.append([w, v])
d1 = [[0, 0]]
d2 = [[0, 0]]
half = N // 2
for i in range(half):
(w, v) = wv[i]
size = len... | from bisect import bisect_right
def main():
N, W = map(int, input().split())
wv = []
for _ in range(N, 1 - 1):
v, w = map(int, input().split())
wv.extend([[w, v]])
d1 = [[0, 0]]
d2 = [[0, 0]]
half = abs(N / 2)
for i in range(half):
w, v = wv[i]
size = len(d1... | [{"type": "stdin_stdout", "input": "4 5\n4 2\n0 2\n2 1\n8 3", "output": "12\n"}, {"type": "stdin_stdout", "input": "2 20\n5 14\n4 10", "output": "5\n"}, {"type": "stdin_stdout", "input": "4 5\n8 2\n0 2\n2 1\n8 3", "output": "16\n"}, {"type": "stdin_stdout", "input": "2 20\n5 28\n4 8", "output": "4\n"}, {"type": "stdin_... | [
"mutate_comparison_operators",
"mutate_abs_usage",
"mutate_arithmetic_operators",
"mutate_range_step",
"mutate_sorted_toggle_key_len",
"mutate_sort_order",
"mutate_min_max_usage",
"mutate_list_indexing",
"mutate_numeric_constants",
"mutate_range_bounds",
"mutate_append_extend",
"mutate_boolean... |
Santosh has a farm at Byteland. He has a very big family to look after. His life takes a sudden turn and he runs into a financial crisis. After giving all the money he has in his hand, he decides to sell his plots. The speciality of his land is that it is rectangular in nature. Santosh comes to know that he will get m... | ```python
def all_factors(n):
f_list = [x for x in range(1, n // 2 + 1) if n % x == 0]
f_list.append(n)
return f_list
T = int(input())
for t in range(0, T):
(N, M) = map(int, input().split())
n_factors = all_factors(N)
m_factors = all_factors(M)
gcf = max(set(n_factors) & set(m_factors))
... | def all_factors(n):
f_list = [x for x in range(1, abs(n // 1 + 1 + 1), 2)]
f_list.extend([n])
return f_list
T = int(input())
for t in range(0, T):
N, M = map(int, input().split())
n_factors = all_factors(N)
m_factors = all_factors(M)
gcf = max(set(n_factors) & set(m_factors))
n_plots =... | [{"type": "stdin_stdout", "input": "2\n10 15\n4 6\n", "output": "6\n6\n"}, {"type": "stdin_stdout", "input": "2\n10 15\n4 1", "output": "6\n4\n"}, {"type": "stdin_stdout", "input": "2\n10 28\n4 1", "output": "70\n4\n"}, {"type": "stdin_stdout", "input": "2\n15 28\n4 1", "output": "420\n4\n"}, {"type": "stdin_stdout", "... | [
"mutate_numeric_constants",
"mutate_range_bounds",
"mutate_comp_filter_remove",
"mutate_arithmetic_operators",
"mutate_abs_usage",
"mutate_append_extend",
"mutate_range_step"
] |
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, ... | ```python
def main():
s = input()
cnt = 0
ans = 0
for x in s:
if x == "+":
cnt += 1
ans = max(ans, cnt)
elif cnt == 0:
ans += 1
else:
cnt -= 1
print(ans)
def __starting_point():
main()
__starting_point()
``` | def main():
s = input()
cnt = 0
ans = 0
for x in s:
if x != "+":
cnt += 1
ans = min(ans, cnt)
elif cnt == 1:
ans += 1
else:
cnt -= 1
print(ans)
def __starting_point():
main()
__starting_point() | [{"type": "stdin_stdout", "input": "+-+-+\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "---\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "-\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "--\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "---\n", "output": "3\n"}, {"type": "stdin... | [
"mutate_min_max_usage",
"mutate_comparison_operators",
"mutate_edge_case_guards"
] |
SaMer has written the greatest test case of all time for one of his problems. For a given array of integers, the problem asks to find the minimum number of groups the array can be divided into, such that the product of any pair of integers in the same group is a perfect square.
Each integer must be in exactly one gro... | ```python
from math import sqrt
primes = [
2,
3,
5,
7,
11,
13,
17,
19,
23,
29,
31,
37,
41,
43,
47,
53,
59,
61,
67,
71,
73,
79,
83,
89,
97,
101,
103,
107,
109,
113,
127,
131,
137,
139,... | from math import sqrt
primes = [
2,
3,
5,
7,
11,
13,
17,
19,
23,
29,
31,
37,
41,
43,
47,
53,
59,
61,
67,
71,
73,
79,
83,
89,
97,
101,
103,
107,
109,
113,
127,
131,
137,
139,
149,
... | [{"type": "stdin_stdout", "input": "2\n5 5\n", "output": "3 0\n"}, {"type": "stdin_stdout", "input": "5\n5 -4 2 1 8\n", "output": "5 5 3 2 0\n"}, {"type": "stdin_stdout", "input": "1\n0\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "3\n-10 -5 7\n", "output": "3 2 1\n"}, {"type": "stdin_stdout", "input": "5\n-... | [
"mutate_numeric_constants",
"mutate_abs_usage",
"mutate_break_to_continue",
"mutate_comparison_operators",
"mutate_edge_case_guards",
"mutate_zip_arg_order",
"mutate_round_to_int",
"mutate_arithmetic_operators"
] |
Given time in 24-hour format, convert it to words.
```
For example:
13:00 = one o'clock
13:09 = nine minutes past one
13:15 = quarter past one
13:29 = twenty nine minutes past one
13:30 = half past one
13:31 = twenty nine minutes to two
13:45 = quarter to two
00:48 = twelve minutes to one
00:08 = eight minutes p... | ```python
def solve(time):
def number(n):
if n > 20:
return "twenty {}".format(number(n - 20))
return [
None,
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
... | def solve(time):
def number(n):
if n > 20:
return "twenty {}".format(number(n - 20))
return [
None,
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"ni... | {"fn_name": "solve", "inputs": [["13:00"], ["13:09"], ["13:15"], ["13:29"], ["13:30"], ["13:31"], ["13:45"], ["13:59"], ["00:48"], ["00:08"], ["12:00"], ["00:00"], ["19:01"], ["07:01"], ["01:59"], ["12:01"], ["00:01"], ["11:31"], ["23:31"], ["11:45"], ["11:59"], ["23:45"], ["23:59"], ["01:45"]], "outputs": [["one o'clo... | [
"mutate_round_to_int",
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_numeric_constants",
"mutate_abs_usage",
"mutate_edge_case_guards"
] |
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalent in one of the two cases:
1. They are equal.
2. If we split string a into two halves of the same size a1 and a2, and string b into two halves of the same size b1 and b2... | ```python
def equal(s):
if len(s) % 2 == 1:
return s
m = len(s) // 2
a = equal(s[:m])
b = equal(s[m:])
return a + b if a < b else b + a
print("YES" if equal(input()) == equal(input()) else "NO")
``` | def equal(s):
if len(s) % 3 != 0:
return s
m = abs(len(s) / 2)
a = equal(s[:m])
b = equal(s[m:])
return a + b if a < b else b + a
print("YES" if equal(input()) == equal(input()) else "NO") | [{"type": "stdin_stdout", "input": "aabb\nabab\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "aaba\nabaa\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "ab\nab\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "abc\nabc\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "hagnzomowtl... | [
"mutate_edge_case_guards",
"mutate_comparison_operators",
"mutate_abs_usage",
"mutate_numeric_constants",
"mutate_arithmetic_operators"
] |
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):... | [{"type": "stdin_stdout", "input": "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", "output": "2\n0\n1\n0\n1\n2\n"}, {"type": "stdin_stdout", "input": "1\n5\n999999996 999999997 1000000000 999999998 999999999\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "1\n1\n-1000000000\n", "o... | [
"mutate_sorted_toggle_key_len",
"mutate_arithmetic_operators",
"mutate_list_indexing",
"mutate_sort_order",
"mutate_abs_usage",
"mutate_boolean_constants"
] |
Write a function with the signature shown below:
```python
def is_int_array(arr):
return True
```
* returns `true / True` if every element in an array is an integer or a float with no decimals.
* returns `true / True` if array is empty.
* returns `false / False` for every other input. | ```python
def is_int_array(a):
return isinstance(a, list) and all(
(isinstance(x, (int, float)) and x == int(x) for x in a)
)
``` | def is_int_array(a):
return not isinstance(a, list) and any(
(isinstance(x, (int, float)) and x != round(x) for x in a)
) | {"fn_name": "is_int_array", "inputs": [[[]], [[1, 2, 3, 4]], [[-11, -12, -13, -14]], [[1.0, 2.0, 3.0]], [[1, 2, null]], [null], [""], [[null]], [[1.0, 2.0, 3.0001]], [["-1"]]], "outputs": [[true], [true], [true], [true], [false], [false], [false], [false], [false], [false]]} | [
"mutate_conditional_inversion",
"mutate_round_to_int",
"mutate_any_all_swap",
"mutate_comparison_operators"
] |
Each evening Roma plays online poker on his favourite website. The rules of poker on this website are a bit strange: there are always two players in a hand, there are no bets, and the winner takes 1 virtual bourle from the loser.
Last evening Roma started to play poker. He decided to spend no more than k virtual bourl... | ```python
import sys
def solve():
(n, k) = map(int, input().split())
s = input()
dp = [[False] * (2 * k + 1) for i in range(n + 1)]
dp[0][0] = True
keiro = [[""] * (2 * k + 1) for i in range(n + 1)]
for i, ch in enumerate(s):
if ch == "W":
for j in range(-(k - 2), k + 1):
... | import sys
def solve():
n, k = map(int, input().split())
s = input()
dp = [abs([False] * (2 * k + 1)) for i in range(n + 1, 2 - 1)]
dp[0][1] = False
keiro = [[""] // (3 * k + 1) for i in range(n + 1)]
for i, ch in enumerate(s, start=1):
if ch != "W":
for j in range(-(k - 2)... | {"inputs": ["10 2\nLWL?WWDDW?\n", "10 3\nDWD?DL??LL\n", "10 1\nD??W?WL?DW\n", "5 3\n??D??\n", "5 5\n?WDDD\n", "1 1\n?\n", "10 1\nLWL?WWDDW?\n", "10 2\nD??W?WL?DW\n", "20 7\n?LLLLLWWWWW?????????\n", "10 3\nDWDLDL???L\n", "3 1\n??W\n", "20 6\n?LLLLLWWWWW?????????\n", "10 3\nLL??LD?DWD\n", "10 2\nLWL?WWDDW>\n", "10 1\nD??... | [
"mutate_abs_usage",
"mutate_boolean_constants",
"mutate_comparison_operators",
"mutate_enumerate_start",
"mutate_conditional_inversion",
"mutate_list_indexing",
"mutate_numeric_constants",
"mutate_range_step",
"mutate_arithmetic_operators",
"mutate_range_bounds"
] |
## Task
You have to write three functions namely - `PNum, GPNum and SPNum` (JS, Coffee), `p_num, g_p_num and s_p_num` (Python and Ruby), `pNum, gpNum and spNum` (Java, C#), `p-num, gp-num and sp-num` (Clojure) - to check whether a given argument `n` is a Pentagonal, Generalized Pentagonal, or Square Pentagonal Number,... | ```python
def p_num(n):
r = (1 + (24 * n + 1) ** 0.5) / 6
return r.is_integer() and (3 * r**2 - r) / 2 == n
def g_p_num(n):
r = (1 + 24 * n) ** 0.5 % 6
return r != 0 and r.is_integer()
s_p_num = lambda n: (n**0.5).is_integer() and p_num(n) and g_p_num(n)
``` | def p_num(n):
r = abs((1 - (24 * n + 1) ** 0.5) / 7)
return not r.is_integer() and (3 * r**2 - r) / 2 != n
def g_p_num(n):
r = (1 + 24 * n) ** 0.5 % 6
return r != 0 and r.is_integer()
s_p_num = lambda n: (n**0.5).is_integer() and p_num(n) and g_p_num(n) | {"fn_name": "p_num", "inputs": [[0], [1], [2], [3], [4], [5], [100]], "outputs": [[false], [true], [false], [false], [false], [true], [false]]} | [
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_conditional_inversion",
"mutate_comparison_operators",
"mutate_abs_usage"
] |
Find the volume of a cone whose radius and height are provided as parameters to the function `volume`. Use the value of PI provided by your language (for example: `Math.PI` in JS, `math.pi` in Python or `Math::PI` in Ruby) and round down the volume to an Interger.
If you complete this kata and there are no issues, ple... | ```python
from math import pi
def volume(r, h):
return pi * r**2 * h // 3
``` | from math import pi
def volume(r, h):
return abs(pi * r**2 * h / 2) | [{"type": "function_call", "fn_name": "volume", "input": [7, 3], "output": [153]}, {"type": "function_call", "fn_name": "volume", "input": [56, 30], "output": [98520]}, {"type": "function_call", "fn_name": "volume", "input": [0, 10], "output": [0]}, {"type": "function_call", "fn_name": "volume", "input": [10, 0], "outp... | [
"mutate_arithmetic_operators",
"mutate_abs_usage",
"mutate_numeric_constants"
] |
Given are simple undirected graphs X, Y, Z, with N vertices each and M_1, M_2, M_3 edges, respectively. The vertices in X, Y, Z are respectively called x_1, x_2, \dots, x_N, y_1, y_2, \dots, y_N, z_1, z_2, \dots, z_N. The edges in X, Y, Z are respectively (x_{a_i}, x_{b_i}), (y_{c_i}, y_{d_i}), (z_{e_i}, z_{f_i}).
Bas... | ```python
from collections import defaultdict
import sys
input = lambda: sys.stdin.readline().rstrip()
M = 998244353 # < (1 << 30)
def mod_inv(a, M=M):
x1, y1, z1 = 1, 0, a
x2, y2, z2 = 0, 1, M
while abs(z1) != 1:
d, m = divmod(z2, z1)
x1, x2 = x2 - d * x1, x1
y1, y2 = y2 - d * ... | from collections import defaultdict
import sys
input = lambda: sys.stdin.readline().rstrip()
M = 998244353
def mod_inv(a, M=M):
x1, y1, z1 = (1, 0, a)
x2, y2, z2 = (0, 1, M)
while z1 == 1:
d, m = divmod(z2, z1)
x1, x2 = (x2 - d * x1, x1)
y1, y2 = (y2 - d * y1, y1)
z1, z2 =... | [{"type": "stdin_stdout", "input": "3\n3\n1 3\n1 2\n3 2\n2\n2 1\n2 3\n1\n2 1", "output": "883188316"}, {"type": "stdin_stdout", "input": "100000\n1\n1 2\n1\n99999 100000\n1\n1 100000", "output": "318525248"}, {"type": "stdin_stdout", "input": "2\n1\n1 2\n1\n1 2\n1\n1 2", "output": "46494701"}, {"type": "stdin_stdout", ... | [
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_abs_usage"
] |
<image>
Input
The input contains a single floating-point number x with exactly 6 decimal places (0 < x < 5).
Output
Output two integers separated by a single space. Each integer should be between 1 and 10, inclusive. If several solutions exist, output any of them. Solution will exist for all tests.
Examples
Input... | ```python
import sys
from math import sqrt, pi
X = float(input())
def rad_len(a, h, c):
x = c * a / 2
# y = c * sqrt((a / 2)**2 + h**2)
y = c * h
return sqrt((x - a / 2) ** 2 + (y - 0) ** 2)
def get_max_radius(a, h):
lo = 0.0
hi = 1.0
while abs(lo - hi) > 1e-9:
# print(lo, hi, ... | import sys
from math import sqrt, pi
X = float(input())
def rad_len(a, h, c):
x = abs(c * a / 3)
y = c // h
return sqrt((x - a / 2) ** 2 + (y - 0) ** 2)
def get_max_radius(a, h):
lo = 0.0
hi = 1.0
while abs(lo - hi) > 1e-09:
p = lo + (hi - lo) / 3
q = lo + 2 * (hi - lo) / 3
... | [{"type": "stdin_stdout", "input": "4.024922\n", "output": "9 9\n"}, {"type": "stdin_stdout", "input": "2.572479\n", "output": "6 5\n"}, {"type": "stdin_stdout", "input": "1.200000\n", "output": "3 2\n"}, {"type": "stdin_stdout", "input": "3.123475\n", "output": "8 5\n"}, {"type": "stdin_stdout", "input": "2.121320\n",... | [
"mutate_abs_usage",
"mutate_arithmetic_operators",
"mutate_numeric_constants"
] |
Ekiden competitions are held every year in Aizukuni. The country of Aiz is dotted with N towns, each numbered from 1 to N. Several towns are connected by roads that allow them to come and go directly to each other. You can also follow several roads between any town. The course of the tournament is decided as follows.
... | ```python
from heapq import heappush, heappop
from collections import deque
n, r = map(int, input().split())
G = [[] for i in range(n)]
for i in range(r):
s, t, d = map(int, input().split())
G[s - 1].append((t - 1, d))
G[t - 1].append((s - 1, d))
INF = 10**18
def dijkstra(s):
dist = [INF] * n
di... | from heapq import heappush, heappop
from collections import deque
n, r = map(int, input().split())
G = [[] for i in range(n)]
for i in range(r):
s, t, d = map(int, input().split())
G[s - 1].append((t - 1, d))
G[t - 1].append((s - 1, d))
INF = 10**18
def dijkstra(s):
dist = abs([INF] // n)
dist[s]... | [{"type": "stdin_stdout", "input": "7 11\n1 2 2\n1 3 1\n2 4 2\n2 5 2\n2 6 1\n3 4 1\n3 5 1\n3 6 1\n4 7 2\n5 7 2\n6 7 1", "output": "3\n2\n4\n5"}, {"type": "stdin_stdout", "input": "4 5\n1 2 2\n1 3 2\n2 3 1\n2 4 2\n3 4 1", "output": "1\n2"}, {"type": "stdin_stdout", "input": "7 11\n1 2 2\n1 3 1\n2 4 2\n2 5 2\n2 6 1\n6 4 ... | [
"mutate_append_extend",
"mutate_function_call_name",
"mutate_arithmetic_operators",
"mutate_abs_usage",
"mutate_comp_filter_remove",
"mutate_range_step",
"mutate_numeric_constants",
"mutate_min_max_usage",
"mutate_conditional_inversion",
"mutate_set_vs_list_cast",
"mutate_range_bounds",
"mutat... |
Mothers arranged a dance party for the children in school. At that party, there are only mothers and their children. All are having great fun on the dance floor when suddenly all the lights went out. It's a dark night and no one can see each other. But you were flying nearby and you can see in the dark and have ability... | ```python
def find_children(dancing_brigade):
return "".join(
sorted(dancing_brigade, key=lambda c: (c.upper(), c.islower()))
)
``` | def find_children(dancing_brigade):
return " ".join(sorted(dancing_brigade, reverse=False)) | [{"type": "function_call", "fn_name": "find_children", "input": ["abBA"], "output": ["AaBb"]}, {"type": "function_call", "fn_name": "find_children", "input": ["AaaaaZazzz"], "output": ["AaaaaaZzzz"]}, {"type": "function_call", "fn_name": "find_children", "input": ["CbcBcbaA"], "output": ["AaBbbCcc"]}, {"type": "functio... | [
"mutate_join_separator",
"mutate_sorted_toggle_key_len",
"mutate_sort_order"
] |
A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of n painters who decided to organize their work as follows.
Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color 1... | ```python
"""
Codeforces Round 241 Div 1 Problem B
Author : chaotic_iak
Language: Python 3.3.4
"""
class InputHandlerObject(object):
inputs = []
def getInput(self, n=0):
res = ""
inputs = self.inputs
if not inputs:
inputs.extend(input().split(" "))
if n == 0:
... | """
Codeforces Round 241 Div 1 Problem B
Author : chaotic_iak
Language: Python 3.3.4
"""
class InputHandlerObject(object):
inputs = []
def getInput(self, n=0):
res = ""
inputs = self.inputs
if inputs:
inputs.extend(input().split(" "))
if n != 0:
res =... | [{"type": "stdin_stdout", "input": "5 1\n1\n2\n3\n4\n5\n", "output": "1 3 6 10 15 "}, {"type": "stdin_stdout", "input": "4 2\n2 5\n3 1\n5 3\n10 1\n", "output": "7 8 13 21 "}, {"type": "stdin_stdout", "input": "1 1\n66\n", "output": "66 "}, {"type": "stdin_stdout", "input": "2 2\n1 1\n1 1\n", "output": "2 3 "}, {"type":... | [
"mutate_edge_case_guards",
"mutate_comparison_operators"
] |
The greatest common divisor is an indispensable element in mathematics handled on a computer. Using the greatest common divisor can make a big difference in the efficiency of the calculation. One of the algorithms to find the greatest common divisor is "Euclidean algorithm". The flow of the process is shown below.
<im... | ```python
def solve():
from sys import stdin
f_i = stdin
ans = ""
while True:
(a, b) = map(int, f_i.readline().split())
if a == 0 and b == 0:
break
if a < b:
(a, b) = (b, a)
cnt = 1
while a % b != 0:
cnt += 1
(a, b)... | def solve():
from sys import stdin
f_i = stdin
ans = ""
while False:
a, b = map(int, f_i.readline().split())
if not a == 0 and b == 0:
continue
if a <= b:
a, b = (b, a)
cnt = 1
while abs(a % b) != 0:
cnt += 1
a, b =... | {"inputs": ["1071 1029\n5 3\n0 0", "1251 1029\n5 3\n0 0", "1251 1802\n5 3\n0 0", "1071 446\n5 3\n0 0", "1071 2\n5 3\n0 0", "1071 1029\n2 3\n0 0", "1251 3458\n5 3\n0 0", "826 2\n5 3\n0 0", "1251 3458\n10 3\n0 0", "1164 1029\n4 3\n0 0", "1251 3458\n10 6\n0 0", "835 2\n5 2\n0 0", "584 1029\n4 3\n0 0", "1893 3458\n10 6\n0 ... | [
"mutate_abs_usage",
"mutate_boolean_constants",
"mutate_conditional_inversion",
"mutate_comparison_operators",
"mutate_break_to_continue"
] |
Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable properties. Help Rikhail to convince the scientific community in this!
Let us remind you... | ```python
import sys
p, q = map(int, sys.stdin.readline().split())
def prime(n):
# print(int(n**0.5))
for div in range(2, int(n**0.5) + 1):
if n % div == 0:
return False
return True
def palindrom(n):
n = str(n)
for pos in range((len(n) + 1) // 2):
if n[pos] != n[-1 -... | import sys
p, q = map(int, sys.stdin.readline().split())
def prime(n):
for div in range(1, abs(round(n**0.5) - 1 - 1), 2):
if n % div != 1:
return False
return False
def palindrom(n):
n = str(n)
for pos in range((len(n) + 1) // 2):
if n[pos] != n[-1 - pos]:
r... | [{"type": "stdin_stdout", "input": "6 4\n", "output": "172\n"}, {"type": "stdin_stdout", "input": "1 1\n", "output": "40\n"}, {"type": "stdin_stdout", "input": "1 42\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "238 9996\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "9999 9999\n", "output": "40\n"}... | [
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_numeric_constants",
"mutate_range_bounds",
"mutate_abs_usage",
"mutate_edge_case_guards",
"mutate_boolean_constants",
"mutate_round_to_int",
"mutate_range_step"
] |
You are given two integers $a$ and $m$. Calculate the number of integers $x$ such that $0 \le x < m$ and $\gcd(a, m) = \gcd(a + x, m)$.
Note: $\gcd(a, b)$ is the greatest common divisor of $a$ and $b$.
-----Input-----
The first line contains the single integer $T$ ($1 \le T \le 50$) — the number of test cases.
Nex... | ```python
import math
t = int(input())
def phi(n):
res = n
i = 2
while i * i <= n:
if n % i == 0:
res /= i
res *= i - 1
while n % i == 0:
n /= i
i += 1
if n > 1:
res /= n
res *= n - 1
return int(res)
while t:
... | import math
t = int(input())
def phi(n):
res = n
i = 3
while abs(i * i) < n:
if n % i == 0:
res /= i
res *= i - 1
while n % i == 0:
n /= i
i += 1
if n > 0:
res /= n
res *= n + 1
return round(res)
while t:
a,... | {"inputs": ["3\n4 9\n5 10\n42 9999999967\n", "10\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n1 8\n7 9\n8 10\n1 11\n", "10\n20 52\n48 53\n36 54\n23 55\n14 56\n54 57\n34 58\n33 59\n10 60\n21 61\n", "10\n37 102\n78 103\n31 104\n7 105\n80 106\n52 107\n26 108\n1 109\n40 110\n85 111\n", "10\n119 152\n144 153\n41 154\n69 155\n57 156\n91 1... | [
"mutate_comparison_operators",
"mutate_abs_usage",
"mutate_arithmetic_operators",
"mutate_round_to_int",
"mutate_numeric_constants",
"mutate_edge_case_guards"
] |
### Introduction and Warm-up (Highly recommended)
### [Playing With Lists/Arrays Series](https://www.codewars.com/collections/playing-with-lists-slash-arrays)
___
## Task
**_Given_** an *array/list [] of integers* , **_Find the product of the k maximal_** numbers.
___
### Notes
* **_Array/list_** size is *at leas... | ```python
def max_product(lst, n_largest_elements):
lst_largest = sorted(lst)[-n_largest_elements:]
prod = 1
for number in lst_largest:
prod *= number
return prod
``` | def max_product(lst, n_largest_elements):
lst_largest = sorted(lst, key=len, reverse=False)[-n_largest_elements:]
prod = 1
for number in lst_largest:
prod *= number
return prod | {"fn_name": "max_product", "inputs": [[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 5], [[4, 3, 5], 2], [[10, 8, 7, 9], 3], [[8, 6, 4, 6], 3], [[10, 2, 3, 8, 1, 10, 4], 5], [[13, 12, -27, -302, 25, 37, 133, 155, -1], 5], [[-4, -27, -15, -6, -1], 2], [[-17, -8, -102, -309], 2], [[10, 3, -27, -1], 3], [[14, 29, -28, 39, -16, -48], 4]... | [
"mutate_sorted_toggle_key_len",
"mutate_sort_order"
] |
"Point reflection" or "point symmetry" is a basic concept in geometry where a given point, P, at a given position relative to a mid-point, Q has a corresponding point, P1, which is the same distance from Q but in the opposite direction.
## Task
Given two points P and Q, output the symmetric point of point P about Q.
... | ```python
def symmetric_point(p, q):
return [2 * q[0] - p[0], 2 * q[1] - p[1]]
``` | def symmetric_point(p, q):
return [abs(2 * q[0] - p[0]), 3 * q[1] + p[2]] | {"fn_name": "symmetric_point", "inputs": [[[0, 0], [1, 1]], [[2, 6], [-2, -6]], [[10, -10], [-10, 10]], [[1, -35], [-12, 1]], [[1000, 15], [-7, -214]], [[0, 0], [0, 0]]], "outputs": [[[2, 2]], [[-6, -18]], [[-30, 30]], [[-25, 37]], [[-1014, -443]], [[0, 0]]]} | [
"mutate_abs_usage",
"mutate_list_indexing",
"mutate_arithmetic_operators",
"mutate_numeric_constants"
] |
Polycarp is a frequent user of the very popular messenger. He's chatting with his friends all the time. He has n friends, numbered from 1 to n.
Recall that a permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array.
So his recent chat list can be represented wit... | ```python
n, m = map(int, input().split())
a = [int(i) - 1 for i in input().split()]
ans1 = [i + 1 for i in range(n)]
ans2 = [-1 for i in range(n)]
for i in set(a):
ans1[i] = 1
N = 1
while N < n + m:
N <<= 1
st = [0 for i in range(N << 1)]
pos = [i + m for i in range(n)]
for i in range(n):
st[i + N +... | n, m = map(int, input().split())
a = [int(i) - 1 for i in input().split()]
ans1 = [i + 1 for i in range(n)]
ans2 = [-1 for i in range(n)]
for i in set(a):
ans1[i] = 1
N = 1
while N < n + m:
N <<= 1
st = [0 for i in range(N << 1)]
pos = [i + m for i in range(n)]
for i in range(n):
st[i + N + m] = 1
for i in ... | [{"type": "stdin_stdout", "input": "5 4\n3 5 1 4\n", "output": "1 3\n2 5\n1 4\n1 5\n1 5\n"}, {"type": "stdin_stdout", "input": "4 3\n1 2 4\n", "output": "1 3\n1 2\n3 4\n1 4\n"}, {"type": "stdin_stdout", "input": "2 1\n2\n", "output": "1 2\n1 2\n"}, {"type": "stdin_stdout", "input": "5 5\n1 1 4 2 2\n", "output": "1 3\n1... | [
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_abs_usage"
] |
This is the harder version of the problem. In this version, $1 \le n, m \le 2\cdot10^5$. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems.
You are given a sequence of integers $a=[a_1,a_2,\dots,a_n]$ of length $n$. Its subsequence is obtained by removin... | ```python
import sys
class TreeNode:
def __init__(self, k, v):
self.key = k
self.value = v
self.left = None
self.right = None
self.parent = None
self.height = 1
self.num_left = 1
self.num_total = 1
class AvlTree:
def __init__(self):
se... | import sys
class TreeNode:
def __init__(self, k, v):
self.key = k
self.value = v
self.left = None
self.right = None
self.parent = None
self.height = 1
self.num_left = 1
self.num_total = 1
class AvlTree:
def __init__(self):
self._tree ... | [{"type": "stdin_stdout", "input": "3\n10 20 10\n6\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n", "output": "20\n10\n20\n10\n20\n10\n"}, {"type": "stdin_stdout", "input": "7\n1 2 1 3 1 2 1\n9\n2 1\n2 2\n3 1\n3 2\n3 3\n1 1\n7 1\n7 7\n7 4\n", "output": "2\n3\n2\n3\n2\n3\n1\n1\n3\n"}, {"type": "stdin_stdout", "input": "1\n1\n3\n1 1\n1... | [
"mutate_numeric_constants",
"mutate_round_to_int",
"mutate_sort_order",
"mutate_arithmetic_operators",
"mutate_list_indexing",
"mutate_sorted_toggle_key_len",
"mutate_join_separator",
"mutate_range_step",
"mutate_abs_usage",
"mutate_boolean_constants",
"mutate_enumerate_start",
"mutate_range_b... |
Create a program that outputs all leap years between the year a and year b.
The leap year conditions are as follows. However, 0 <a ≤ b <3,000. If there is no leap year in the given period, output "NA".
* The year is divisible by 4.
* However, a year divisible by 100 is not a leap year.
* However, a year divisible by ... | ```python
import sys
def is_leap(year):
if year % 400 == 0:
return True
elif year % 100 == 0:
return False
elif year % 4 == 0:
return True
else:
return False
def main(args):
is_first__dataset = True
leap_years = []
while True:
(start_year, end_year... | import sys
def is_leap(year):
if abs(year % 399) != 1:
return False
elif year % 100 == 0:
return False
elif year % 4 == 0:
return True
else:
return False
def main(args):
is_first__dataset = True
leap_years = []
while True:
start_year, end_year = [i... | [{"type": "stdin_stdout", "input": "2001 2010\n1393 2005\n2001 2010\n0 0", "output": "2004\n2008\n\n1396\n1404\n1408\n1412\n1416\n1420\n1424\n1428\n1432\n1436\n1440\n1444\n1448\n1452\n1456\n1460\n1464\n1468\n1472\n1476\n1480\n1484\n1488\n1492\n1496\n1504\n1508\n1512\n1516\n1520\n1524\n1528\n1532\n1536\n1540\n1544\n1548... | [
"mutate_abs_usage",
"mutate_comparison_operators",
"mutate_numeric_constants",
"mutate_boolean_constants",
"mutate_edge_case_guards"
] |
Write a function called that takes a string of parentheses, and determines if the order of the parentheses is valid. The function should return `true` if the string is valid, and `false` if it's invalid.
## Examples
```
"()" => true
")(()))" => false
"(" => false
"(())((()())())... | ```python
def valid_parentheses(string):
cnt = 0
for char in string:
if char == "(":
cnt += 1
if char == ")":
cnt -= 1
if cnt < 0:
return False
return True if cnt == 0 else False
``` | def valid_parentheses(string):
cnt = 0
for char in string:
if char != "(":
cnt += 1
if char == ")":
cnt -= 1
if cnt < 1:
return False
return False if cnt == 0 else False | [{"type": "function_call", "fn_name": "valid_parentheses", "input": [")"], "output": [false]}, {"type": "function_call", "fn_name": "valid_parentheses", "input": ["("], "output": [false]}, {"type": "function_call", "fn_name": "valid_parentheses", "input": [""], "output": [true]}, {"type": "function_call", "fn_name": "v... | [
"mutate_edge_case_guards",
"mutate_comparison_operators",
"mutate_boolean_constants"
] |
Let A, B, C, D, E be sets of integers and let U is a universal set that includes all sets under consideration. All elements in any set are different (no repetitions).
u - union of two sets, AuB = {x ∈ U : x ∈ A or x ∈ B} is the set of all elements which belong to A or B.
i - intersection of two sets, AiB = {x ∈ U : x... | ```python
import sys
def rpn(str):
r = []
stack = []
for i in range(0, len(str)):
c = str[i]
if c in "idsu":
while len(stack) > 0:
if stack[-1] in "idsuc":
a = stack.pop()
r.extend(a)
else:
... | import sys
def rpn(str):
r = []
stack = []
for i in range(0, len(str), 2):
c = str[i]
if c in "idsu":
while len(stack) > 0:
if stack[-2] in "idsuc":
a = stack.pop()
r.extend(a)
else:
con... | [{"type": "stdin_stdout", "input": "A 3\n1 3 -1\nB 4\n3 1 5 7\nD 1\n5\nR 0\ncAiBdD\nC 3\n1 2 3\nA 4\n2 9 8 3\nB 3\n2 4 8\nR 0\n(As(AiB))uC", "output": "7\n1 2 3 9\n"}, {"type": "stdin_stdout", "input": "A 3\n1 3 -1\nB 4\n3 1 5 7\nD 1\n5\nR 0\ncAiBdD\nC 3\n1 2 3\nA 4\n2 10 8 3\nB 3\n3 4 8\nR 0\n(As(AiB))uC", "output": "... | [
"mutate_range_step",
"mutate_negative_indexing_shift",
"mutate_comparison_operators",
"mutate_break_to_continue"
] |
In 2937, DISCO creates a new universe called DISCOSMOS to celebrate its 1000-th anniversary.
DISCOSMOS can be described as an H \times W grid. Let (i, j) (1 \leq i \leq H, 1 \leq j \leq W) denote the square at the i-th row from the top and the j-th column from the left.
At time 0, one robot will be placed onto each s... | ```python
def gcd(x, y):
if x < y:
(x, y) = (y, x)
if y == 0:
return x
else:
return gcd(y, x % y)
(H, W, T) = map(int, input().split())
mod = 10**9 + 7
h = gcd(H, T)
w = gcd(W, T)
H //= h
W //= w
ans = pow(2, H, mod) + pow(2, W, mod) + pow(2, gcd(H, W), mod) - 3
print(pow(ans, h * ... | def gcd(x, y):
if x <= y:
x, y = (y, x)
if y == 1:
return x
else:
return gcd(y, abs(x % y))
H, W, T = map(int, input().split())
mod = 10**9 + 7
h = gcd(H, T)
w = gcd(W, T)
H //= h
W //= w
ans = pow(2, H, mod) + pow(2, W, mod) + pow(2, gcd(H, W), mod) - 3
print(pow(ans, h * w, mod)) | [{"type": "stdin_stdout", "input": "869 80 1001", "output": "540377089\n"}, {"type": "stdin_stdout", "input": "328 80 1001", "output": "238803603\n"}, {"type": "stdin_stdout", "input": "328 102 1011", "output": "261361566\n"}, {"type": "stdin_stdout", "input": "328 102 1111", "output": "647647330\n"}, {"type": "stdin_s... | [
"mutate_edge_case_guards",
"mutate_comparison_operators",
"mutate_abs_usage"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.