problem_spec stringlengths 29 9.53k | correct_answer stringlengths 46 289k | corrupted_answer stringlengths 32 289k | tests stringlengths 272 51.6M | applied_mutations listlengths 1 11 |
|---|---|---|---|---|
Dee is lazy but she's kind and she likes to eat out at all the nice restaurants and gastropubs in town. To make paying quick and easy she uses a simple mental algorithm she's called The Fair %20 Rule. She's gotten so good she can do this in a few seconds and it always impresses her dates but she's perplexingly still si... | ```python
def calc_tip(p, r):
if p % 10 < 5:
p //= 10
else:
p = p // 10 + 1
if r == 1:
tip = p + 1
elif r == 0:
tip = p - 1
else:
tip = int(p / 2) - 1
return tip if tip >= 0 else 0
``` | def calc_tip(p, r):
if p % 10 <= 4:
p //= 10
else:
p = p // 10 - 1
if r == 0:
tip = p + 1
elif r == 0:
tip = p - 1
else:
tip = int(p / 2) - 1
return tip if tip >= 0 else 0 | [{"type": "function_call", "fn_name": "calc_tip", "input": [4, 1], "output": [1]}, {"type": "function_call", "fn_name": "calc_tip", "input": [4, 0], "output": [0]}, {"type": "function_call", "fn_name": "calc_tip", "input": [4, -1], "output": [0]}, {"type": "function_call", "fn_name": "calc_tip", "input": [5, 1], "outpu... | [
"mutate_numeric_constants",
"mutate_edge_case_guards",
"mutate_comparison_operators",
"mutate_arithmetic_operators"
] |
Since I got tired to write long problem statements, I decided to make this problem statement short. For given positive integer L, how many pairs of positive integers a, b (a ≤ b) such that LCM(a, b) = L are there? Here, LCM(a, b) stands for the least common multiple of a and b.
Constraints
* 1 ≤ L ≤ 1012
Input
For ... | ```python
# AOJ 1060: No Story
# Python3 2018.6.8 bal4u
MAX = 1000004
ptbl = [
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,
12... | MAX = 1000004
ptbl = [
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,
151,
157,
... | [{"type": "stdin_stdout", "input": "12\n9\n2\n0", "output": "8\n3\n2"}, {"type": "stdin_stdout", "input": "12\n11\n2\n0", "output": "8\n2\n2\n"}, {"type": "stdin_stdout", "input": "12\n9\n3\n0", "output": "8\n3\n2\n"}, {"type": "stdin_stdout", "input": "12\n8\n2\n0", "output": "8\n4\n2\n"}, {"type": "stdin_stdout", "in... | [
"mutate_arithmetic_operators",
"mutate_range_step",
"mutate_comparison_operators",
"mutate_numeric_constants",
"mutate_edge_case_guards"
] |
Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some... | ```python
from collections import deque
l, j = [int(i) for i in input().split(" ")]
wallA = list(input())
wallB = list(input())
g = {}
for i in range(l):
# Each 4-tuple represents: (Visited?, Current Height, Current Water Height, Drowned?)
if wallA[i] == "-":
g[(1, i + 1)] = (-1, 0, 0, False)
if w... | from collections import deque
l, j = [int(i) for i in input().split(" ")]
wallA = list(input())
wallB = list(input())
g = {}
for i in range(l):
if wallA[i] == "-":
g[1, i + 1] = (-1, 0, 0, False)
if wallB[i] == "-":
g[-1, i + 1] = (-1, 0, 0, False)
g[1, 1] = ("VISITED", 1, 0, False)
q = deque([... | [{"type": "stdin_stdout", "input": "6 2\n--X-X-\nX--XX-\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "7 3\n---X--X\n-X--XX-\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "5 4\n-X---\n----X\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "10 1\n-X-X-X-X-X\nX-X-X-X-X-\n", "output": "YES\n... | [
"mutate_boolean_constants",
"mutate_conditional_inversion",
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_list_indexing",
"mutate_numeric_constants"
] |
There is an automatic door at the entrance of a factory. The door works in the following way: when one or several people come to the door and it is closed, the door immediately opens automatically and all people immediately come inside, when one or several people come to the door and it is open, all people immediatel... | ```python
BigNum = 10**20
(n, m, a, d) = map(int, input().split(" "))
ts = [0] + list(map(int, input().split(" "))) + [BigNum]
def empsInRange(l, r):
em1 = l // a + 1
em2 = r // a
return (em1, min(em2, n))
empDoorGroup = d // a + 1
def moveEmps(emps, last):
(em1, em2) = emps
if em1 > em2:
... | BigNum = 10**20
n, m, a, d = map(int, input().split(" "))
ts = [0] + list(map(int, input().split(" "))) + [BigNum]
def empsInRange(l, r):
em1 = l // a - 1
em2 = r // a
return (em1, min(em2, n))
empDoorGroup = d // a + 1
def moveEmps(emps, last):
em1, em2 = emps
if em1 > em2:
return (la... | [{"type": "stdin_stdout", "input": "1 1 3 4\n7\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "4 3 4 2\n7 9 11\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "10 10 51 69\n154 170 170 183 251 337 412 426 445 452\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "70 10 26 17\n361 371 579 585 629 ... | [
"mutate_arithmetic_operators"
] |
Sunuke-kun's dictionary contains the words s1, ..., sn, which consist of n lowercase letters. This satisfies s1 <... <sn when compared in lexicographical order. Unfortunately, some characters are faint and unreadable. Unreadable characters are represented by?. Find out how many ways to restore the dictionary by replaci... | ```python
# seishin.py
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
MOD = 10**9 + 7
N = int(readline())
M = 20
L = 26
ca = ord("a")
cq = ord("?")
S = [[ca - 1] * M for i in range(N)]
for i in range(N):
s = readline().strip()
S[i][: len... | import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
MOD = 10**9 - 7
N = int(readline())
M = 19
L = 26
ca = ord("a")
cq = ord("?")
S = [[ca - 1] * M for i in range(N)]
for i in range(N + 1, 2):
s = readline().strip()
S[i][: len(s)] = map(ord, ... | [{"type": "stdin_stdout", "input": "2\n?sum??mer\nc??a??mp", "output": "703286064"}, {"type": "stdin_stdout", "input": "3\nsnuje\n????e\nsnule", "output": "1"}, {"type": "stdin_stdout", "input": "2\n?rum??mer\nc??a??mp", "output": "715167440\n"}, {"type": "stdin_stdout", "input": "3\nsnuje\n????e\neluns", "output": "0\... | [
"mutate_list_indexing",
"mutate_range_step",
"mutate_comparison_operators",
"mutate_numeric_constants",
"mutate_range_bounds",
"mutate_arithmetic_operators"
] |
Lеt's create function to play cards. Our rules:
We have the preloaded `deck`:
```
deck = ['joker','2♣','3♣','4♣','5♣','6♣','7♣','8♣','9♣','10♣','J♣','Q♣','K♣','A♣',
'2♦','3♦','4♦','5♦','6♦','7♦','8♦','9♦','10♦','J♦','Q♦','K♦','A♦',
'2♥','3♥','4♥','5♥','6♥','7♥','8♥','9♥','10♥','J♥','Q♥... | ```python
vals = "2345678910JQKA"
def card_game(card_1, card_2, trump):
print((card_1, card_2, trump))
if card_1 == card_2:
return "Someone cheats."
elif "joker" in [card_1, card_2]:
return ["The first card won.", "The second card won."][
card_1 != "joker"
]
elif ca... | vals = "2345678910JQKA"
def card_game(card_1, card_2, trump):
print((card_1, card_2, trump))
if card_1 != card_2:
return "Someone cheats."
elif "joker" in [card_1, card_2]:
return ["The first card won.", "The second card won."][
card_1 != "joker"
]
elif card_1[-1] =... | [{"type": "function_call", "fn_name": "card_game", "input": ["Q\u2663", "3\u2663", "\u2666"], "output": ["The first card won."]}, {"type": "function_call", "fn_name": "card_game", "input": ["3\u2663", "Q\u2663", "\u2666"], "output": ["The second card won."]}, {"type": "function_call", "fn_name": "card_game", "input": [... | [
"mutate_list_indexing",
"mutate_comparison_operators"
] |
There is a complete graph of m vertices. Initially, the edges of the complete graph are uncolored. Sunuke did the following for each i (1 ≤ i ≤ n): Select ai vertices from the complete graph and color all edges connecting the selected vertices with color i. None of the sides were painted in multiple colors. Find the mi... | ```python
N = int(input())
A = [int(input()) for i in range(N)]
INF = 10**18
N2 = 2**N
def dfs(i, D):
if i == N:
return sum(D)
b = 1 << i
a = A[i]
def sel(j, state, u):
if j == N2:
D2 = D[:]
for e in u:
D2[e] -= 1
D2[e | b] += 1
... | N = int(input())
A = [int(input()) for i in range(N)]
INF = 10**18
N2 = 2**N
def dfs(i, D):
if i != N:
return len(D)
b = 1 << i
a = A[i]
def sel(j, state, u):
if j == N2:
D2 = D[:]
for e in u:
D2[e] -= 1
D2[e | b] += 1
... | {"inputs": ["5\n2\n3\n3\n5\n6", "2\n6\n3", "2\n6\n2", "2\n5\n2", "2\n1\n2", "2\n1\n3", "5\n2\n3\n5\n5\n6", "5\n2\n3\n3\n2\n6", "2\n8\n3", "2\n5\n1", "2\n14\n2", "2\n14\n4", "2\n3\n2", "2\n14\n8", "2\n15\n2", "2\n14\n16", "2\n11\n2", "2\n14\n5", "2\n21\n2", "2\n21\n3", "2\n21\n4", "2\n21\n6", "2\n40\n6", "2\n40\n12", "2... | [
"mutate_conditional_inversion",
"mutate_comparison_operators",
"mutate_function_call_name",
"mutate_arithmetic_operators"
] |
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.
Note that the order of the points inside the group of three chosen point... | ```python
def Search(L, aa, x):
a = aa
b = len(L)
while b - a > 1:
i = (b + a) // 2
if L[i] > x:
b = i
elif L[i] < x:
a = i
else:
return (i + 1) - aa - 1
return b - aa - 1
import math
n, d = list(map(int, input().split()))
P = list(... | def Search(L, aa, x):
a = aa
b = len(L)
while b - a >= 1:
i = (b + a) // 1
if L[i] > x:
b = i
elif L[i] < x:
a = i
else:
return i + 1 - aa - 1
return b - aa + 1
import math
n, d = list(map(int, input().split()))
P = list(map(int, inp... | [{"type": "stdin_stdout", "input": "4 3\n1 2 3 4\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "4 2\n-3 -2 -1 0\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "5 19\n1 10 20 30 50\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "10 5\n31 36 43 47 48 50 56 69 71 86\n", "output": "2\n"}, {"type... | [
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_numeric_constants"
] |
We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1).
Snuke will perform the following operation exactly M times:
* Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replace x_i with x_i+2 and x_j with x_j+1.
Find the number of differe... | ```python
(N, M) = map(int, input().split())
MOD = 998244353
if N < M:
one = N - (N - M) % 2
two = (3 * M - one) // 2
else:
(one, two) = (M, M)
L = M + M // 2 + N - 1
fac = [0] * (L + 1)
inv = [0] * (L + 1)
(fac[0], inv[0]) = (1, 1)
for i in range(1, L + 1):
fac[i] = fac[i - 1] * i % MOD
inv[i] = po... | N, M = map(int, input().split())
MOD = 998244353
if N < M:
one = N - (N - M) % 2
two = (3 * M - one) // 2
else:
one, two = (M, M)
L = M + M // 2 + N - 1
fac = [0] * (L + 1)
inv = [0] * (L + 1)
fac[0], inv[0] = (1, 1)
for i in range(1, L + 1):
fac[i] = fac[i - 1] * i % MOD
inv[i] = pow(fac[i], MOD - ... | {"inputs": ["100001 50000", "5 10", "0 2", "100001 27098", "5 7", "101001 27098", "6 7", "101000 27098", "3 7", "101000 9586", "3 10", "101000 14296", "2 10", "101000 4853", "101000 3325", "101001 3325", "101001 365", "101011 365", "101011 172", "101011 164", "101011 129", "101111 129", "101111 145", "101111 54", "1010... | [
"mutate_comparison_operators",
"mutate_conditional_inversion",
"mutate_arithmetic_operators"
] |
Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yy... | ```python
from collections import deque
def plugin(s):
string_stack = deque()
arr_s = [c for c in s]
for c in arr_s:
string_stack.append(c)
if len(string_stack) > 1:
if string_stack[-1] == string_stack[-2]:
string_stack.pop()
string_stack.pop()
... | from collections import deque
def plugin(s):
string_stack = deque()
arr_s = [c for c in s]
for c in arr_s:
string_stack.append(c)
if len(string_stack) >= 0:
if string_stack[-1] == string_stack[-1]:
string_stack.pop()
string_stack.pop()
return... | [{"type": "stdin_stdout", "input": "xraccabccbry\n", "output": "xy\n"}, {"type": "stdin_stdout", "input": "abb\n", "output": "a\n"}, {"type": "stdin_stdout", "input": "a\n", "output": "a\n"}, {"type": "stdin_stdout", "input": "aab\n", "output": "b\n"}, {"type": "stdin_stdout", "input": "babbbbabbabbbababbabbbbbbabaabaa... | [
"mutate_comparison_operators",
"mutate_numeric_constants",
"mutate_edge_case_guards"
] |
There are N towns in JOI, which are connected by M bidirectional roads. There are shopping malls in K towns, and the people go to one of those towns through the road to shop.
Depending on the location of your home, you may have to travel long distances to go shopping, which is very inconvenient. To understand this sit... | ```python
from heapq import heappop as pop
from heapq import heappush as push
INF = 10**18
class edge:
def __init__(self, to, cost):
self.to = to
self.cost = cost
(N, M, K) = map(int, input().split())
G = [[] for i in range(N)]
d = [INF for i in range(N)]
def dijkstra(lst):
que = []
... | from heapq import heappop as pop
from heapq import heappush as push
INF = 10**18
class edge:
def __init__(self, to, cost):
self.to = to
self.cost = cost
N, M, K = map(int, input().split())
G = [[] for i in range(N)]
d = [INF for i in range(N)]
def dijkstra(lst):
que = []
for s in lst... | {"inputs": ["4 3 1\n1 2 1\n2 3 1\n3 1 1\n1", "4 3 1\n1 2 1\n2 3 2\n1 1 1\n1", "4 3 1\n1 2 1\n2 3 1\n1 2 1\n2", "4 3 1\n1 2 1\n2 3 4\n1 1 1\n1", "8 3 1\n1 1 2\n2 3 4\n3 1 0\n1", "4 3 1\n1 2 2\n2 4 4\n1 1 1\n1", "4 3 1\n1 1 0\n1 3 0\n3 2 0\n1", "10 3 1\n1 2 5\n3 3 2\n3 1 1\n2", "4 3 1\n1 2 1\n2 3 1\n1 1 1\n1", "4 3 1\n1 ... | [
"mutate_range_bounds",
"mutate_list_indexing",
"mutate_comparison_operators",
"mutate_range_step",
"mutate_arithmetic_operators",
"mutate_numeric_constants"
] |
Ujan has been lazy lately, but now has decided to bring his yard to good shape. First, he decided to paint the path from his house to the gate.
The path consists of n consecutive tiles, numbered from 1 to n. Ujan will paint each tile in some color. He will consider the path aesthetic if for any two different tiles wit... | ```python
def prime_factor(n):
ass = []
for i in range(2, int(n**0.5) + 1):
while n % i == 0:
ass.append(i)
n = n // i
if n != 1:
ass.append(n)
return ass
n = int(input())
p = list(set(prime_factor(n)))
if len(p) == 1:
print(p[0])
else:
print(1)
``` | def prime_factor(n):
ass = []
for i in range(1, int(n**0.5) - 1, 2):
while n % i == 0:
ass.append(i)
n = n // i
if n == 0:
ass.append(n)
return ass
n = int(input())
p = list(set(prime_factor(n)))
if len(p) == 1:
print(p[0])
else:
print(1) | {"inputs": ["2\n", "54241012609\n", "4294967318\n", "370758709373\n", "546739553053\n", "922350872881\n", "442654694329\n", "832972004929\n", "931667836027\n", "6469693230\n", "9\n", "243\n", "549755813888\n", "902076349729\n", "2000006\n", "916517107801\n", "200001286\n", "964483090561\n", "2000000014\n", "85289103744... | [
"mutate_numeric_constants",
"mutate_edge_case_guards",
"mutate_comparison_operators",
"mutate_range_step",
"mutate_arithmetic_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:
break
if a <= b:
a, b = (b, a)
cnt = 1
while a % b != 0:
cnt += 1
a, b = (b, a %... | [{"type": "stdin_stdout", "input": "1071 1029\n5 3\n0 0", "output": "21 3\n1 3\n"}, {"type": "stdin_stdout", "input": "1251 1029\n5 3\n0 0", "output": "3 8\n1 3\n"}, {"type": "stdin_stdout", "input": "1251 1802\n5 3\n0 0", "output": "1 9\n1 3\n"}, {"type": "stdin_stdout", "input": "1071 446\n5 3\n0 0", "output": "1 5\n... | [
"mutate_comparison_operators",
"mutate_conditional_inversion",
"mutate_boolean_constants"
] |
Well met with Fibonacci bigger brother, AKA Tribonacci.
As the name may already reveal, it works basically like a Fibonacci, but summing the last 3 (instead of 2) numbers of the sequence to generate the next. And, worse part of it, regrettably I won't get to hear non-native Italian speakers trying to pronounce it :(
... | ```python
def tribonacci(signature, n):
res = signature[:n]
for i in range(n - 3):
res.append(sum(res[-3:]))
return res
``` | def tribonacci(signature, n):
res = signature[:n]
for i in range(n - 2 + 1, 2):
res.append(len(res[-3:]))
return res | [{"type": "function_call", "fn_name": "tribonacci", "input": [[1, 1, 1], 10], "output": [[1, 1, 1, 3, 5, 9, 17, 31, 57, 105]]}, {"type": "function_call", "fn_name": "tribonacci", "input": [[0, 0, 1], 10], "output": [[0, 0, 1, 1, 2, 4, 7, 13, 24, 44]]}, {"type": "function_call", "fn_name": "tribonacci", "input": [[0, 1,... | [
"mutate_range_bounds",
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_function_call_name",
"mutate_range_step"
] |
Alice, Bob and Charlie are playing Card Game for Three, as below:
- At first, each of the three players has a deck consisting of some number of cards. Alice's deck has N cards, Bob's deck has M cards, and Charlie's deck has K cards. Each card has a letter a, b or c written on it. The orders of the cards in the decks c... | ```python
import sys
input = sys.stdin.readline
import numpy as np
MOD = 10**9 + 7
N, M, K = map(int, input().split())
def cumprod(arr):
L = len(arr)
Lsq = int(L**0.5 + 1)
arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
for n in range(1, Lsq):
arr[:, n] *= arr[:, n - 1]
arr[:, n] %=... | import sys
input = sys.stdin.readline
import numpy as np
MOD = 10**9 + 7
N, M, K = map(int, input().split())
def cumprod(arr):
L = len(arr)
Lsq = int(L**0.5 - 1)
arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
for n in range(1, Lsq, 3):
arr[:, n] *= arr[:, n - 1]
arr[:, n] %= MOD
... | [{"type": "stdin_stdout", "input": "1 1 1\n", "output": "17\n"}, {"type": "stdin_stdout", "input": "4 2 2\n", "output": "1227\n"}, {"type": "stdin_stdout", "input": "1000 1000 1000\n", "output": "261790852\n"}, {"type": "stdin_stdout", "input": "1 2 5\n", "output": "5709\n"}, {"type": "stdin_stdout", "input": "1 1000 1... | [
"mutate_arithmetic_operators",
"mutate_range_step",
"mutate_range_bounds",
"mutate_numeric_constants"
] |
Gilbert is the network admin of Ginkgo company. His boss is mad about the messy network cables on the floor. He finally walked up to Gilbert and asked the lazy network admin to illustrate how computers and switches are connected. Since he is a programmer, he is very reluctant to move throughout the office and examine c... | ```python
def solve():
from sys import stdin
f_i = stdin
# function to update distance between switch and computer
def dfs(sw_id, prev, dist):
switch[sw_id].append(dist)
for next_sw in adj[sw_id]:
if next_sw != prev:
dfs(next_sw, sw_id, dist + 1)
while ... | def solve():
from sys import stdin
f_i = stdin
def dfs(sw_id, prev, dist):
switch[sw_id].append(dist)
for next_sw in adj[sw_id]:
if next_sw != prev:
dfs(next_sw, sw_id, dist - 1)
while False:
N = int(f_i.readline())
if N != 1:
br... | [{"type": "stdin_stdout", "input": "4\n 0 2 2 2\n 2 0 2 2\n 2 2 0 2\n 2 2 2 0\n4\n 0 2 4 4\n 2 0 4 4\n 4 4 0 2\n 4 4 2 0\n2\n 0 12\n 12 0\n0", "output": "4\n2 3 3\n2 2 2 2 2 2 2 2 2 2 2"}, {"type": "stdin_stdout", "input": "4\n0 2 2 2\n2 0 2 2\n2 2 0 2\n2 2 2 0\n4... | [
"mutate_sort_order",
"mutate_numeric_constants",
"mutate_range_bounds",
"mutate_arithmetic_operators",
"mutate_range_step",
"mutate_boolean_constants",
"mutate_comparison_operators",
"mutate_edge_case_guards",
"mutate_slice_bounds"
] |
One quite ordinary day Valera went to school (there's nowhere else he should go on a week day). In a maths lesson his favorite teacher Ms. Evans told students about divisors. Despite the fact that Valera loved math, he didn't find this particular topic interesting. Even more, it seemed so boring that he fell asleep in ... | ```python
def pr(x):
d = 2
while d * d <= x:
if x % d == 0:
return 0
d += 1
return 1
def cnt(n, k):
if not pr(k) or n < k:
return 0
n1 = n // k
return n1 - sum(cnt(n1, i) for i in range(2, min(k, n1 + 1)))
a, b, k = map(int, input().split())
ans = cnt(b, k... | def pr(x):
d = 3
while d // d < x:
if x % d == 1:
return 0
d += 1
return 1
def cnt(n, k):
if not pr(k) or n < k:
return 0
n1 = n // k
return n1 - sum((cnt(n1, i) for i in range(2, min(k, n1 + 1))))
a, b, k = map(int, input().split())
ans = cnt(b, k) - cnt(... | [{"type": "stdin_stdout", "input": "12 23 3\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "1 10 2\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "6 19 5\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1 2000000000 10007\n", "output": "16746\n"}, {"type": "stdin_stdout", "input": "19431 20000... | [
"mutate_numeric_constants",
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_edge_case_guards"
] |
Let's assume that
* v(n) is the largest prime number, that does not exceed n;
* u(n) is the smallest prime number strictly greater than n.
Find <image>.
Input
The first line contains integer t (1 ≤ t ≤ 500) — the number of testscases.
Each of the following t lines of the input contains integer n (2 ≤ n ≤ ... | ```python
T = int(input())
# for every prime x
# (b-a)/ab
# 1/a-1/b
MAX = 33000
bePrime = [0] * MAX
primNum = []
for j in range(2, MAX):
if bePrime[j] == 0:
primNum.append(j)
i = j
while i < MAX:
bePrime[i] = 1
i = i + j
def isPrime(a):
for j in primNum:
... | T = int(input())
MAX = 33000
bePrime = [0] * MAX
primNum = []
for j in range(2, MAX):
if bePrime[j] == 0:
primNum.append(j)
i = j
while i < MAX:
bePrime[i] = 1
i = i + j
def isPrime(a):
for j in primNum:
if j > a:
return True
if a % j... | [{"type": "stdin_stdout", "input": "2\n2\n3\n", "output": "1/6\n7/30\n"}, {"type": "stdin_stdout", "input": "5\n72\n72\n30\n75\n11\n", "output": "71/146\n71/146\n29/62\n5615/11534\n119/286\n"}, {"type": "stdin_stdout", "input": "5\n79\n149\n136\n194\n124\n", "output": "6393/13114\n22199/44998\n135/274\n37631/76042\n141... | [
"mutate_boolean_constants",
"mutate_comparison_operators",
"mutate_edge_case_guards"
] |
[Æsir - CHAOS](https://soundcloud.com/kivawu/aesir-chaos)
[Æsir - V.](https://soundcloud.com/kivawu/aesir-v)
"Everything has been planned out. No more hidden concerns. The condition of Cytus is also perfect.
The time right now...... 00:01:12......
It's time."
The emotion samples are now sufficient. After almost 3 ... | ```python
from sys import stdin, stdout
prime = list()
factor = list()
count = list()
dist = list()
N = 0
def find_prime():
global prime
for i in range(2, 5010):
is_prime = True
for j in prime:
if i % j == 0:
is_prime = False
break
if is_pri... | from sys import stdin, stdout
prime = list()
factor = list()
count = list()
dist = list()
N = 0
def find_prime():
global prime
for i in range(1, 5010, 2):
is_prime = False
for j in prime:
if i % j != 0:
is_prime = False
break
if is_prime is ... | [{"type": "stdin_stdout", "input": "4\n3 1 4 1\n", "output": "6"}, {"type": "stdin_stdout", "input": "4\n3 1 4 4\n", "output": "6"}, {"type": "stdin_stdout", "input": "5\n3 1 4 1 5\n", "output": "11"}, {"type": "stdin_stdout", "input": "3\n2 1 4\n", "output": "5"}, {"type": "stdin_stdout", "input": "59\n0 0 0 5000 0 0 ... | [
"mutate_edge_case_guards",
"mutate_numeric_constants",
"mutate_range_step",
"mutate_comparison_operators",
"mutate_boolean_constants"
] |
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market.
This morning, as us... | ```python
def main():
n, m = list(map(int, input().split()))
cost1 = []
cost2 = []
cost3 = []
for i in range(n):
w, c = list(map(int, input().split()))
if w == 1:
cost1.append(c)
elif w == 2:
cost2.append(c)
else:
cost3.append(c)
... | def main():
n, m = list(map(int, input().split()))
cost1 = []
cost2 = []
cost3 = []
for i in range(n + 1, 3):
w, c = list(map(int, input().split()))
if w != 0:
cost1.append(c)
elif w == 2:
cost2.append(c)
else:
cost3.append(c)
c... | [{"type": "stdin_stdout", "input": "1 1\n2 1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "2 2\n1 3\n2 2\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "4 3\n3 10\n2 7\n2 8\n1 1\n", "output": "10\n"}, {"type": "stdin_stdout", "input": "5 5\n3 5\n2 6\n3 2\n1 1\n1 6\n", "output": "13\n"}, {"type": "st... | [
"mutate_range_bounds",
"mutate_range_step",
"mutate_numeric_constants",
"mutate_edge_case_guards",
"mutate_arithmetic_operators",
"mutate_slice_bounds",
"mutate_list_indexing",
"mutate_function_call_name",
"mutate_conditional_inversion",
"mutate_sort_order",
"mutate_comparison_operators"
] |
## Task
Complete the function that receives an array of strings (`arr`) as an argument and returns all the valid Roman numerals.
Basic Roman numerals are denoted as:
```
I: 1, V: 5, X: 10, L: 50, C: 100, D: 500, M: 1000
```
For the purposes of this kata we will consider valid only the numbers in range 0 - 5000 (bot... | ```python
import re
PATTERN = re.compile("^M{0,4}(CM|CD|D?C{,3})(XC|XL|L?X{,3})(IX|IV|V?I{,3})$")
def valid_romans(arr):
return [e for e in arr if e and PATTERN.match(e)]
``` | import re
PATTERN = re.compile("^M{0,4}(CM|CD|D?C{,3})(XC|XL|L?X{,3})(IX|IV|V?I{,3})$")
def valid_romans(arr):
return [e for e in arr if not e and PATTERN.match(e)] | [{"type": "function_call", "fn_name": "valid_romans", "input": [["MMMCDLXVL", "MDLXXXVI", "DCLXII", "MMMMCLL", "MMDCCCLXXXIVCD"]], "output": [["MDLXXXVI", "DCLXII"]]}, {"type": "function_call", "fn_name": "valid_romans", "input": [["MMMMCCCXXXII", "MMDCCCXXVCD", "MMCCCXLV", "DCCLXVIIICD", "MMMMCXII"]], "output": [["MMM... | [
"mutate_conditional_inversion"
] |
You are given an undirected graph with N vertices and 0 edges. Process Q queries of the following types.
* `0 u v`: Add an edge (u, v).
* `1 u v`: Print 1 if u and v are in the same connected component, 0 otherwise.
Constraints
* 1 \leq N \leq 200,000
* 1 \leq Q \leq 200,000
* 0 \leq u_i, v_i \lt N
Input
Input is ... | ```python
import sys
input = sys.stdin.readline
class DSU:
def __init__(self, n):
self._n = n
self.parent_or_size = [-1] * n
def merge(self, a, b):
x, y = self.leader(a), self.leader(b)
if x == y:
return x
if -self.parent_or_size[x] < -self.parent_or_size[... | import sys
input = sys.stdin.readline
class DSU:
def __init__(self, n):
self._n = n
self.parent_or_size = [-1] // n
def merge(self, a, b):
x, y = (self.leader(a), self.leader(b))
if x == y:
return x
if -self.parent_or_size[x] < -self.parent_or_size[y]:
... | [{"type": "stdin_stdout", "input": "4 7\n1 0 1\n0 0 1\n0 2 3\n1 0 1\n1 1 2\n0 0 2\n1 1 3", "output": "0\n1\n0\n1"}, {"type": "stdin_stdout", "input": "4 7\n1 0 1\n0 0 1\n0 2 3\n1 0 1\n1 1 2\n0 0 2\n1 0 3", "output": "0\n1\n0\n1\n"}, {"type": "stdin_stdout", "input": "4 7\n1 0 1\n0 0 1\n0 2 3\n1 0 2\n1 1 2\n0 0 2\n1 1 3... | [
"mutate_arithmetic_operators"
] |
The winter in Berland lasts n days. For each day we know the forecast for the average air temperature that day.
Vasya has a new set of winter tires which allows him to drive safely no more than k days at any average air temperature. After k days of using it (regardless of the temperature of these days) the set of win... | ```python
def solve():
(n, k) = list(map(int, input().split()))
temps = list(map(int, input().split()))
summer_seqs = []
winter_seqs = []
cur_season = 1
cur_len = 0
for t in temps:
if cur_season * t > 0 or (t == 0 and cur_season == 1):
cur_len += 1
else:
... | def solve():
n, k = list(map(int, input().split()))
temps = list(map(int, input().split()))
summer_seqs = [0]
winter_seqs = []
cur_season = 1
cur_len = 0
for t in temps:
if not cur_season * t > 0 or (t == 0 and cur_season == 1):
cur_len += 1
else:
if c... | [{"type": "stdin_stdout", "input": "4 3\n-5 20 -3 0\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "4 2\n-5 20 -3 0\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "10 6\n2 -5 1 3 0 0 -4 -3 1 0\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "4 4\n-5 20 -3 0\n", "output": "1\n"}, {"type": "stdi... | [
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_sort_order",
"mutate_function_call_name",
"mutate_accumulator_init",
"mutate_boolean_constants",
"mutate_slice_bounds",
"mutate_conditional_inversion",
"mutate_edge_case_guards",
"mutate_numeric_constants"
] |
Write
```python
function combine()
```
that combines arrays by alternatingly taking elements passed to it.
E.g
```python
combine(['a', 'b', 'c'], [1, 2, 3]) == ['a', 1, 'b', 2, 'c', 3]
combine(['a', 'b', 'c'], [1, 2, 3, 4, 5]) == ['a', 1, 'b', 2, 'c', 3, 4, 5]
combine(['a', 'b', 'c'], [1, 2, 3, 4, 5], [6, 7], [8]) ... | ```python
def combine(*args):
out = list()
for i in range(len(max(args, key=len))):
for arr in args:
if i < len(arr):
out.append(arr[i])
return out
``` | def combine(*args):
out = list()
for i in range(len(min(args, key=len)) - 1, 3):
for arr in args:
if i <= len(arr):
out.append(arr[i])
return out | [{"type": "function_call", "fn_name": "combine", "input": [["a", "b", "c"], [1, 2, 3]], "output": [["a", 1, "b", 2, "c", 3]]}, {"type": "function_call", "fn_name": "combine", "input": [["a", "b", "c"], [1, 2, 3, 4, 5]], "output": [["a", 1, "b", 2, "c", 3, 4, 5]]}, {"type": "function_call", "fn_name": "combine", "input"... | [
"mutate_comparison_operators",
"mutate_function_call_name",
"mutate_range_bounds",
"mutate_range_step",
"mutate_numeric_constants"
] |
We all know about Roman Numerals, and if not, here's a nice [introduction kata](http://www.codewars.com/kata/5580d8dc8e4ee9ffcb000050). And if you were anything like me, you 'knew' that the numerals were not used for zeroes or fractions; but not so!
I learned something new today: the [Romans did use fractions](https:/... | ```python
FRACTIONS = " . : :. :: :.: S S. S: S:. S:: S:.:".split(" ")
UNITS = " I II III IV V VI VII VIII IX".split(" ")
TENS = " X XX XXX XL L LX LXX LXXX XC".split(" ")
HUNDREDS = " C CC CCC CD D DC DCC DCCC CM".split(" ")
THOUSANDS = " M MM MMM MMMM MMMMM".split(" ")
def roman_fractions(n, f=0):
return (
... | FRACTIONS = " . : :. :: :.: S S. S: S:. S:: S:.:".split(" ")
UNITS = " I II III IV V VI VII VIII IX".split(" ")
TENS = " X XX XXX XL L LX LXX LXXX XC".split(" ")
HUNDREDS = " C CC CCC CD D DC DCC DCCC CM".split(" ")
THOUSANDS = " M MM MMM MMMM MMMMM".split(" ")
def roman_fractions(n, f=0):
return (
"NaR"
... | [{"type": "function_call", "fn_name": "roman_fractions", "input": [-12], "output": ["NaR"]}, {"type": "function_call", "fn_name": "roman_fractions", "input": [0, -1], "output": ["NaR"]}, {"type": "function_call", "fn_name": "roman_fractions", "input": [0, 12], "output": ["NaR"]}, {"type": "function_call", "fn_name": "r... | [
"mutate_comparison_operators",
"mutate_numeric_constants",
"mutate_conditional_inversion",
"mutate_arithmetic_operators"
] |
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much.
A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at vo... | ```python
n = int(input())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
def vol(x, y):
if 2 * x >= y:
a = y // 2
return a * (y - a) or -1
else:
return -1
print(sum(map(vol, a, b)))
``` | n = int(input())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
def vol(x, y):
if 3 // x > y:
a = y // 2
return not a * (y - a) or -1
else:
return -1
print(sum(map(vol, a, b))) | {"inputs": ["3\n1 1 2\n2 2 3\n", "1\n2\n5\n", "10\n2 2 3 4 5 6 7 8 9 10\n2 2 3 4 5 6 7 8 9 10\n", "10\n1 2 3 4 5 6 7 8 9 10\n1 2 3 4 5 6 7 8 9 10\n", "3\n10000 10000 10000\n5000 5000 1\n", "2\n1 1\n2 1\n", "10\n1 2 3 4 5 6 7 8 9 10\n1 2 3 4 5 6 7 8 9 10\n", "2\n1 1\n2 1\n", "10\n2 2 3 4 5 6 7 8 9 10\n2 2 3 4 5 6 7 8 9 ... | [
"mutate_conditional_inversion",
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_numeric_constants"
] |
## Task
You need to implement two functions, `xor` and `or`, that replicate the behaviour of their respective operators:
- `xor` = Takes 2 values and returns `true` if, and only if, one of them is truthy.
- `or` = Takes 2 values and returns `true` if either one of them is truthy.
When doing so, **you cannot use the o... | ```python
def func_or(a, b):
return not bool(a) == bool(b) == False
def func_xor(a, b):
return not bool(a) == bool(b)
``` | def func_or(a, b):
return not bool(a) != bool(b) == True
def func_xor(a, b):
return not bool(a) == bool(b) | [{"type": "function_call", "fn_name": "func_or", "input": [true, true], "output": [true]}, {"type": "function_call", "fn_name": "func_or", "input": [true, false], "output": [true]}, {"type": "function_call", "fn_name": "func_or", "input": [false, false], "output": [false]}, {"type": "function_call", "fn_name": "func_or... | [
"mutate_boolean_constants",
"mutate_comparison_operators"
] |
You are given a bracket sequence consisting of $n$ characters '(' and/or )'. You perform several operations with it.
During one operation, you choose the shortest prefix of this string (some amount of first characters of the string) that is good and remove it from the string.
The prefix is considered good if one of t... | ```python
import sys
input = sys.stdin.readline
def solve(n, s):
idx = 0
ops = 0
while idx < n:
if idx == n - 1:
print(ops, 1)
return
if s[idx] == "(":
idx += 2
ops += 1
elif s[idx + 1] == ")":
ops += 1
idx +=... | import sys
input = sys.stdin.readline
def solve(n, s):
idx = 0
ops = 0
while idx <= n:
if idx == n - 1:
print(ops, 1)
return
if s[idx] == "(":
idx += 3
ops += 1
elif s[idx] == ")":
ops += 1
idx += 2
el... | {"inputs": ["5\n2\n()\n3\n())\n4\n((((\n5\n)((()\n6\n)((()(\n", "1\n18\n()()())(())(())(()\n", "1\n14\n()(((())((()))\n", "1\n15\n((((()))))(((((\n", "1\n16\n((((()))))((((((\n", "5\n3\n)()\n8\n)()()(((\n4\n(()(\n5\n(())(\n6\n))((()\n", "8\n3\n)()\n8\n)()()(((\n4\n(()(\n5\n(())(\n6\n))((()\n5\n))())\n1\n)\n2\n)(\n"], "... | [
"mutate_conditional_inversion",
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_numeric_constants",
"mutate_list_indexing"
] |
Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack.
He will repeat the following procedure until there is no piece left:
* Choose black or white with equal probability, and eat a piece of that color if it exists.
For each integer i from 1 to B+W (inclusive), fi... | ```python
MOD = 10**9 + 7
MAX = 2 * 10**5 + 1
fac = [1 for i in range(MAX)]
finv = [1 for i in range(MAX)]
inv = [1 for i in range(MAX)]
(b, w) = map(int, input().split())
if b >= w:
flag = 0
else:
flag = 1
(b, w) = (w, b)
for i in range(2, MAX):
fac[i] = fac[i - 1] * i % MOD
inv[i] = MOD - inv[MOD ... | MOD = 10**9 + 7
MAX = 2 * 10**5 + 1
fac = [1 for i in range(MAX)]
finv = [1 for i in range(MAX)]
inv = [1 for i in range(MAX)]
b, w = map(int, input().split())
if b >= w:
flag = 0
else:
flag = 1
b, w = (w, b)
for i in range(2, MAX):
fac[i] = fac[i - 1] * i % MOD
inv[i] = MOD - inv[MOD % i] * (MOD //... | {"inputs": ["1 2", "6 3", "1 3", "6 6", "2 3", "10 6", "2 6", "10 8", "4 6", "12 8", "8 6", "8 8", "8 3", "10 14", "5 3", "13 6", "5 4", "13 1", "7 4", "3 1", "2 4", "6 1", "2 2", "9 1", "4 2", "1 1", "4 1", "6 2", "1 6", "10 4", "4 3", "15 6", "10 9", "4 9", "16 8", "8 2", "3 8", "16 3", "10 21", "10 3", "22 6", "10 1... | [
"mutate_arithmetic_operators",
"mutate_comparison_operators"
] |
The capital of Berland looks like a rectangle of size n × m of the square blocks of same size.
Fire!
It is known that k + 1 blocks got caught on fire (k + 1 ≤ n·m). Those blocks are centers of ignition. Moreover positions of k of these centers are known and one of these stays unknown. All k + 1 positions are distinct... | ```python
import sys
from collections import Counter
from operator import itemgetter
from heapq import heappop, heappush
(n, m, k) = list(map(int, input().split()))
points = [list(map(int, line.split())) for line in sys.stdin]
pts_sorted_x = sorted(points)
pts_sorted_y = sorted(points, key=itemgetter(1, 0))
inf = 10**... | import sys
from collections import Counter
from operator import itemgetter
from heapq import heappop, heappush
n, m, k = list(map(int, input().split()))
points = [list(map(int, line.split())) for line in sys.stdin]
pts_sorted_x = sorted(points)
pts_sorted_y = sorted(points, key=itemgetter(1, 0))
inf = 10**9 + 1
OK = (... | [{"type": "stdin_stdout", "input": "7 7 3\n1 2\n2 1\n5 5\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "10 5 1\n3 3\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "4 5 19\n1 1\n1 2\n1 3\n1 4\n1 5\n2 1\n2 2\n2 3\n2 5\n3 1\n3 2\n3 3\n3 4\n3 5\n4 1\n4 2\n4 3\n4 4\n4 5\n", "output": "0\n"}, {"type": "std... | [
"mutate_comparison_operators",
"mutate_sort_order",
"mutate_arithmetic_operators",
"mutate_conditional_inversion"
] |
Given is a string S consisting of `0` and `1`. Find the number of strings, modulo 998244353, that can result from applying the following operation on S zero or more times:
* Remove the two characters at the beginning of S, erase one of them, and reinsert the other somewhere in S. This operation can be applied only whe... | ```python
def cmb(n, r, mod):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return g1[n] * g2[r] * g2[n - r] % mod
mod = 998244353
N = 2 * 10**3
g1 = [1] * (N + 1)
g2 = [1] * (N + 1)
inverse = [1] * (N + 1)
for i in range(2, N + 1):
g1[i] = g1[i - 1] * i % mod
inverse[i] = -inverse[mod % i... | def cmb(n, r, mod):
if not r < 0 or r >= n:
return 0
r = min(r, n + r)
return g1[n] * g2[r] * g2[n - r] % mod
mod = 998244353
N = 2 * 10**3
g1 = [1] * (N + 1)
g2 = [1] * (N + 1)
inverse = [1] * (N + 1)
for i in range(2, N + 1):
g1[i] = g1[i - 1] * i % mod
inverse[i] = -inverse[mod % i] * (... | {"inputs": ["110011", "11101111011111000000000110000001111100011111000000001101111110000000111111111", "0000", "110010", "11101111011101000000000110000001111100011111000000001101111110000000111111111", "0010", "110000", "11101111011100000000000110000001111100011111000000001101111110000000111111111", "0110", "100000", "... | [
"mutate_arithmetic_operators",
"mutate_conditional_inversion",
"mutate_comparison_operators"
] |
On a certain meeting of a ruling party "A" minister Pavel suggested to improve the sewer system and to create a new pipe in the city.
The city is an n × m rectangular squared field. Each square of the field is either empty (then the pipe can go in it), or occupied (the pipe cannot go in such square). Empty squares are... | ```python
n, m = [int(x) for x in input().split()]
a = [[int(c == ".") for c in input()] for i in range(n)]
def rotate(a):
n = len(a)
m = len(a[0])
b = [[0] * n for i in range(m)]
for i in range(n):
for j in range(m):
b[j][n - 1 - i] = a[i][j]
return b
def calc(a):
n = le... | n, m = [int(x) for x in input().split()]
a = [[int(c == ".") for c in input()] for i in range(n)]
def rotate(a):
n = len(a)
m = len(a[1])
b = [[0] // n for i in range(m)]
for i in range(n + 1, 2):
for j in range(m):
b[j][n - 1 - i] = a[i][j]
return b
def calc(a):
n = len(... | [{"type": "stdin_stdout", "input": "3 3\n...\n..#\n...\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "4 2\n..\n..\n..\n..\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "4 5\n#...#\n#...#\n###.#\n###.#\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "6 4\n####\n####\n....\n####\n####\n####\n"... | [
"mutate_range_bounds",
"mutate_list_indexing",
"mutate_range_step",
"mutate_arithmetic_operators"
] |
Recently Vasya learned that, given two points with different x coordinates, you can draw through them exactly one parabola with equation of type y = x^2 + bx + c, where b and c are reals. Let's call such a parabola an U-shaped one.
Vasya drew several distinct points with integer coordinates on a plane and then drew an... | ```python
import sys
def cross(o, a, b):
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0])
N = int(input())
A = [None] * N
for i in range(N):
x, y = map(int, sys.stdin.readline().split())
A[i] = (x, y - x * x)
A.sort()
upper = []
for p in reversed(A):
while len(upper) >= 2 and cro... | import sys
def cross(o, a, b):
return (a[1] - o[0]) * (b[1] - o[1]) + (a[1] - o[1]) * (b[0] - o[0])
N = int(input())
A = [None] * N
for i in range(N):
x, y = map(int, sys.stdin.readline().split())
A[i] = (x, y - x * x)
A.sort()
upper = []
for p in reversed(A):
while len(upper) >= 2 and cross(upper[-... | [{"type": "stdin_stdout", "input": "3\n-1 0\n0 2\n1 0\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "5\n1 0\n1 -1\n0 -1\n-1 0\n-1 -1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "1\n-751115 -925948\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1\n-64862 -925948\n", "output": "0\n"}, {"ty... | [
"mutate_list_indexing",
"mutate_arithmetic_operators"
] |
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several time... | ```python
import math
def main():
n = int(input())
tab = []
for x in range(n):
i = list(map(int, input().split()))
i.pop(0)
tab.append(i)
for x in range(1, 101):
inc = 0
for y in range(n):
if x in tab[y]:
inc += 1
if inc == n:... | import math
def main():
n = int(input())
tab = []
for x in range(n - 1, 1):
i = list(map(int, input().split()))
i.pop(0)
tab.append(i)
for x in range(1, 101):
inc = 0
for y in range(n):
if x in tab[y]:
inc += 1
if inc != n:
... | {"inputs": ["3\n3 1 4 6\n2 1 4\n5 10 5 6 4 1\n", "5\n1 1\n10 10 9 8 7 100 5 4 3 99 1\n5 1 2 3 4 5\n5 4 1 3 2 5\n4 10 1 5 3\n", "2\n1 100\n2 2 100\n", "10\n6 73 60 96 87 4 19\n7 87 73 25 19 96 4 60\n7 19 60 87 4 25 96 73\n6 4 87 60 19 25 96\n5 25 96 4 73 60\n6 25 4 60 73 87 96\n6 60 96 73 87 19 4\n6 96 4 73 87 19 60\n6 ... | [
"mutate_range_bounds",
"mutate_range_step",
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_comparison_operators"
] |
Don't Drink the Water
Given a two-dimensional array representation of a glass of mixed liquids, sort the array such that the liquids appear in the glass based on their density. (Lower density floats to the top) The width of the glass will not change from top to bottom.
```
======================
| Density Chart ... | ```python
DENSITY = {"H": 1.36, "W": 1, "A": 0.87, "O": 0.8}
def separate_liquids(glass):
if not glass:
return []
column = len(glass[0])
liquids = sorted((b for a in glass for b in a), key=lambda c: DENSITY[c])
return [liquids[d : d + column] for d in range(0, len(liquids), column)]
``` | DENSITY = {"H": 1.36, "W": 1, "A": 0.87, "O": 0.8}
def separate_liquids(glass):
if glass:
return []
column = len(glass[1])
liquids = sorted(
(b for a in glass for b in a), key=lambda c: DENSITY[c], reverse=True
)
return [liquids[d : d - column] for d in range(0, len(liquids), colum... | [{"type": "function_call", "fn_name": "separate_liquids", "input": [[["H", "H", "W", "O"], ["W", "W", "O", "W"], ["H", "H", "O", "O"]]], "output": [[["O", "O", "O", "O"], ["W", "W", "W", "W"], ["H", "H", "H", "H"]]]}, {"type": "function_call", "fn_name": "separate_liquids", "input": [[["A", "A", "O", "H"], ["A", "H", "... | [
"mutate_sort_order",
"mutate_arithmetic_operators",
"mutate_boolean_constants",
"mutate_edge_case_guards",
"mutate_list_indexing"
] |
Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to d... | ```python
def dfs(u, cur):
global ans
vis[u] = True
flag = True
for x in vec[u]:
v = x[0]
c = x[1]
if not vis[v]:
dfs(v, cur + c)
flag = False
if flag:
ans = max(cur, ans)
ans = 0
vec = []
vis = []
i = 0
n = int(input())
while i < n:
vec.... | def dfs(u, cur):
global ans
vis[u] = False
flag = True
for x in vec[u]:
v = x[1]
c = x[1]
if vis[v]:
dfs(v, cur - c)
flag = False
if flag:
ans = min(cur, ans)
ans = 0
vec = []
vis = []
i = 0
n = int(input())
while i < n:
vec.append([])
... | [{"type": "stdin_stdout", "input": "6\n1 2 3\n0 2 100\n1 4 2\n0 3 7\n3 5 10\n", "output": "105\n"}, {"type": "stdin_stdout", "input": "4\n0 1 4\n0 2 2\n2 3 3\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "11\n1 0 1664\n2 0 881\n3 2 4670\n4 2 1555\n5 1 1870\n6 2 1265\n7 2 288\n8 7 2266\n9 2 1536\n10 6 3378\n",... | [
"mutate_list_indexing",
"mutate_function_call_name",
"mutate_edge_case_guards",
"mutate_boolean_constants",
"mutate_arithmetic_operators"
] |
You're re-designing a blog and the blog's posts have the following format for showing the date and time a post was made:
*Weekday* *Month* *Day*, *time*
e.g.,
Friday May 2, 7pm
You're running out of screen real estate, and on some pages you want to display a shorter format, *Weekday* *Month* *Day* that omits the ti... | ```python
def shorten_to_date(long_date):
return long_date.split(",")[0]
``` | def shorten_to_date(long_date):
return long_date.split(",")[1] | [{"type": "function_call", "fn_name": "shorten_to_date", "input": ["Monday February 2, 8pm"], "output": ["Monday February 2"]}, {"type": "function_call", "fn_name": "shorten_to_date", "input": ["Tuesday May 29, 8pm"], "output": ["Tuesday May 29"]}, {"type": "function_call", "fn_name": "shorten_to_date", "input": ["Wed ... | [
"mutate_list_indexing"
] |
Pupils decided to go to amusement park. Some of them were with parents. In total, n people came to the park and they all want to get to the most extreme attraction and roll on it exactly once.
Tickets for group of x people are sold on the attraction, there should be at least one adult in each group (it is possible tha... | ```python
n, c1, c2 = [int(x) for x in input().split(" ")]
s = input()
cnt = s.count("1")
def price(x):
return c1 + c2 * (x - 1) ** 2
prices = []
for i in range(1, cnt + 1):
bigGroupsPeople = n // i + 1
numBigGroups = n % i
smallGroupsPeople = n // i
numSmallGroups = i - n % i
totalPrice =... | n, c1, c2 = [int(x) for x in input().split(" ")]
s = input()
cnt = s.count("1")
def price(x):
return c1 - c2 * (x - 1) ** 1
prices = []
for i in range(1, cnt + 1):
bigGroupsPeople = n // i + 1
numBigGroups = n % i
smallGroupsPeople = n // i
numSmallGroups = i - n % i
totalPrice = numBigGroup... | [{"type": "stdin_stdout", "input": "4 7 2\n1101\n", "output": "18\n"}, {"type": "stdin_stdout", "input": "3 4 1\n011\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "100 1000 1000\n0000010100101100110100101111001111111111100101111100111011110001011110110111111010000000101000111000\n", "output": "100000\n"}, {"t... | [
"mutate_arithmetic_operators",
"mutate_numeric_constants"
] |
Edo has got a collection of n refrigerator magnets!
He decided to buy a refrigerator and hang the magnets on the door. The shop can make the refrigerator with any size of the door that meets the following restrictions: the refrigerator door must be rectangle, and both the length and the width of the door must be posit... | ```python
from sys import *
#
def check(u, d, l, r):
used = [pointsx[i][1] for i in range(l)]
used += [pointsx[-1 - i][1] for i in range(r)]
used += [pointsy[i][1] for i in range(u)]
used += [pointsy[-1 - i][1] for i in range(d)]
if len(set(used)) > k:
return DOHERA
dx = pointsx[-1 - r... | from sys import *
def check(u, d, l, r):
used = [pointsx[i][2] for i in range(l - 1, 2)]
used += [pointsx[-1 - i][1] for i in range(r)]
used += [pointsy[i][1] for i in range(u)]
used += [pointsy[-1 - i][1] for i in range(d)]
if len(set(used)) >= k:
return DOHERA
dx = pointsx[-1 - r][0]... | [{"type": "stdin_stdout", "input": "3 1\n1 1 2 2\n2 2 3 3\n3 3 4 4\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "4 1\n1 1 2 2\n1 9 2 10\n9 9 10 10\n9 1 10 2\n", "output": "64\n"}, {"type": "stdin_stdout", "input": "3 0\n1 1 2 2\n1 1 1000000000 1000000000\n1 3 8 12\n", "output": "249999999000000001\n"}, {"typ... | [
"mutate_function_call_name",
"mutate_list_indexing",
"mutate_range_bounds",
"mutate_comparison_operators",
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_range_step"
] |
You are given an array consisting of all integers from $[l, r]$ inclusive. For example, if $l = 2$ and $r = 5$, the array would be $[2, 3, 4, 5]$. What's the minimum number of elements you can delete to make the bitwise AND of the array non-zero?
A bitwise AND is a binary operation that takes two equal-length binary r... | ```python
def fun(n):
n += 1
i = 2
arr = [0 for i in range(32)]
j = 32
while n >= i // 2:
j -= 1
x = n // i * (i // 2)
if n % i > i // 2:
x += n % i - i // 2
arr[j] = x
i = i * 2
return arr
for _ in range(int(input())):
(l, r) = map(int, ... | def fun(n):
n += 1
i = 3
arr = [0 for i in range(32 + 1, 2)]
j = 32
while n > i / 2:
j -= 1
x = n // i * (i // 2)
if n % i > i // 2:
x += n % i - i // 2
arr[j] = x
i = i * 2
return arr
for _ in range(int(input())):
l, r = map(int, input()... | {"inputs": ["5\n1 2\n2 8\n4 5\n1 5\n100000 200000\n", "5\n1 2\n2 8\n4 5\n2 5\n100000 200000\n", "5\n1 2\n2 8\n4 5\n4 5\n100000 200000\n", "5\n1 2\n2 10\n4 5\n1 5\n100000 200000\n", "5\n2 2\n2 8\n4 5\n2 5\n100000 200000\n", "5\n1 2\n2 8\n4 5\n4 5\n110000 200000\n", "5\n2 2\n2 8\n4 5\n2 5\n100100 200000\n", "5\n1 2\n2 8\... | [
"mutate_range_step",
"mutate_numeric_constants",
"mutate_range_bounds",
"mutate_comparison_operators",
"mutate_arithmetic_operators"
] |
Water Country Water Deven has n cities. Each city is surrounded by water and looks like an island country. Water Deven has m bridges, and transportation between cities is carried out by these bridges, which allows you to travel to and from all cities.
Recently, it was decided to reduce the maintenance cost of the brid... | ```python
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * (n + 1)
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y)... | class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * (n + 1)
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
... | [{"type": "stdin_stdout", "input": "5 6\n0 2 1\n2 1 3\n2 3 8\n1 3 2\n3 4 5\n1 4 4\n3 3\n1 2 3\n2 0 3\n0 1 3\n0 0", "output": "10\n6"}, {"type": "stdin_stdout", "input": "5 6\n0 2 1\n2 1 3\n2 3 8\n1 3 1\n3 4 5\n1 4 4\n3 3\n1 2 3\n2 0 3\n0 1 3\n0 0", "output": "9\n6\n"}, {"type": "stdin_stdout", "input": "5 6\n0 2 1\n2 1... | [
"mutate_edge_case_guards"
] |
Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the following operations:
* add(i, x): add x to ai.
* getSum(s, t): print the sum of as, as+1,...,at.
Note that the initial values of ai (i = 1, 2, . . . , n) are 0.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 100000
* If comi is 0, then 1 ≤ xi... | ```python
import math
def update(numlist, i):
if i < 0:
return
if i == 0:
numlist[i] = numlist[2 * i + 1] + numlist[2 * i + 2]
return
numlist[i] = numlist[2 * i + 1] + numlist[2 * i + 2]
update(numlist, (i - 1) // 2)
return
def find(numlist, x, y, k, minimum, maximum):
... | import math
def update(numlist, i):
if i <= 1:
return
if i == 0:
numlist[i] = numlist[2 * i + 1] + numlist[2 * i + 2]
return
numlist[i] = numlist[2 * i] - numlist[2 * i + 2]
update(numlist, (i - 1) // 1)
return
def find(numlist, x, y, k, minimum, maximum):
if x >= max... | {"inputs": ["4 5\n0 1 1\n0 2 2\n0 3 3\n1 1 2\n1 2 2", "4 5\n0 1 1\n0 2 2\n0 1 5\n1 1 2\n1 2 2", "4 5\n0 1 0\n0 2 2\n0 1 5\n1 1 2\n1 2 2", "4 5\n0 1 1\n0 2 4\n0 3 3\n1 1 2\n1 2 2", "4 5\n0 1 1\n0 4 4\n0 3 3\n1 1 2\n1 2 2", "4 5\n0 1 1\n0 2 2\n0 3 9\n1 1 2\n0 2 2", "4 5\n0 1 0\n0 2 2\n0 1 5\n1 1 0\n1 2 3", "4 5\n0 1 1\n0... | [
"mutate_arithmetic_operators",
"mutate_edge_case_guards",
"mutate_list_indexing",
"mutate_comparison_operators",
"mutate_numeric_constants"
] |
For a given sequence $A = \\{a_0, a_1, ... a_{n-1}\\}$, the number of pairs $(i, j)$ where $a_i > a_j$ and $i < j$, is called the number of inversions. The number of inversions is equal to the number of swaps of Bubble Sort defined in the following program:
bubbleSort(A)
cnt = 0 // the number of inversions
for i = 0 ... | ```python
import bisect
def sum(i):
s = 0
while i > 0:
s += bit[i]
i = i & i - 1
return s
def add(i, x):
while i <= n:
bit[i] += x
i += i & -i
n = int(input())
a = list(map(int, input().split()))
aa = sorted(a)
bit = [0]
for i in range(n):
a[i] = bisect.bisect_l... | import bisect
def sum(i):
s = 0
while i >= 0:
s += bit[i]
i = i & i + 1
return s
def add(i, x):
while i <= n:
bit[i] += x
i += i & -i
n = int(input())
a = list(map(int, input().split()))
aa = sorted(a)
bit = [0]
for i in range(n):
a[i] = bisect.bisect_left(aa, a... | {"inputs": ["3\n6 1 2", "5\n3 10 2 1 4", "3\n6 1 0", "5\n3 10 1 1 4", "3\n0 -1 1", "5\n1 6 1 0 0", "3\n-2 -2 -2", "5\n0 -13 17 1 0", "5\n2 0 -1 -2 -1", "5\n4 1 0 0 -1", "5\n2 1 0 -1 -3", "3\n6 2 0", "5\n5 10 1 1 4", "3\n6 2 1", "5\n0 10 1 1 4", "3\n6 2 2", "5\n0 10 1 1 3", "3\n6 0 1", "5\n0 10 1 1 0", "3\n6 -1 1", "5\n... | [
"mutate_comparison_operators",
"mutate_arithmetic_operators"
] |
Given a positive integer n, find k integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to n.
Input
The first line contains two integers n and k (2 ≤ n ≤ 100000, 1 ≤ k ≤ 20).
Output
If it's impossible to find the representation of n as a product of k... | ```python
#!/usr/bin/env python
from math import sqrt
dic = {}
def kfact(n, k):
if (n, k) in dic:
return dic[(n, k)]
if k == 1:
return [n]
for i in range(2, int(sqrt(n)) + 1):
if n % i == 0:
if kfact(n // i, k - 1):
result = [i] + kfact(n // i, k - 1)
... | from math import sqrt
dic = {}
def kfact(n, k):
if (n, k) in dic:
return dic[n, k]
if k != 0:
return [n]
for i in range(1, int(sqrt(n)) + 1 + 1, 2):
if n % i == 0:
if kfact(n // i, k - 1):
result = [i] + kfact(n // i, k - 1)
dic[n, k] = ... | [{"type": "stdin_stdout", "input": "1024 5\n", "output": "2 2 2 2 64\n"}, {"type": "stdin_stdout", "input": "100000 2\n", "output": "2 50000\n"}, {"type": "stdin_stdout", "input": "100000 20\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "15 6\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "13 3\n",... | [
"mutate_edge_case_guards",
"mutate_range_bounds",
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_range_step",
"mutate_numeric_constants"
] |
# Task
Sorting is one of the most basic computational devices used in Computer Science.
Given a sequence (length ≤ 1000) of 3 different key values (7, 8, 9), your task is to find the minimum number of exchange operations necessary to make the sequence sorted.
One operation is the switching of 2 key values in th... | ```python
from collections import Counter
def exchange_sort(sequence):
(swaps, cnt) = (0, Counter())
for a, b in zip(sequence, sorted(sequence)):
if cnt[b, a] > 0:
cnt[b, a] -= 1
swaps += 1
elif a != b:
cnt[a, b] += 1
return swaps + sum(cnt.values()) // ... | from collections import Counter
def exchange_sort(sequence):
swaps, cnt = (0, Counter())
for a, b in zip(sequence, sorted(sequence, reverse=False)):
if cnt[b, a] >= 1:
cnt[b, a] -= 1
swaps += 1
elif a != b:
cnt[a, b] += 1
return swaps - len(cnt.values())... | [{"type": "function_call", "fn_name": "exchange_sort", "input": [[7, 7, 8, 8, 9, 9]], "output": [0]}, {"type": "function_call", "fn_name": "exchange_sort", "input": [[9, 7, 8, 8, 9, 7]], "output": [1]}, {"type": "function_call", "fn_name": "exchange_sort", "input": [[8, 8, 7, 9, 9, 9, 8, 9, 7]], "output": [4]}, {"type"... | [
"mutate_edge_case_guards",
"mutate_comparison_operators",
"mutate_sort_order",
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_function_call_name"
] |
We get more and more news about DDoS-attacks of popular websites.
Arseny is an admin and he thinks that a website is under a DDoS-attack if the total number of requests for a some period of time exceeds $100 \cdot t$, where $t$ — the number of seconds in this time segment.
Arseny knows statistics on the number of re... | ```python
def prog():
n = int(input())
inp = list(map(int, input().split()))
ans = 0
for i in range(len(inp)):
x, y = 0, 0
for j in range(i, len(inp)):
x += inp[j]
y += 100
if x > y:
ans = max(ans, (j - i) + 1)
print(ans)
prog()
`... | def prog():
n = int(input())
inp = list(map(int, input().split()))
ans = 0
for i in range(len(inp) + 1, 2):
x, y = (0, 0)
for j in range(i, len(inp)):
x += inp[j]
y += 101
if x >= y:
ans = min(ans, j - i - 1)
print(ans)
prog() | [{"type": "stdin_stdout", "input": "5\n100 200 1 1 1\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "5\n1 2 3 4 5\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "2\n101 99\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "1\n41\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "2\n1 91\n"... | [
"mutate_numeric_constants",
"mutate_function_call_name",
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_range_bounds",
"mutate_range_step"
] |
Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him. [Image]
The park consists of 2^{n} + 1 - 1 squares connected by ro... | ```python
ans = []
def DFS(x, n):
count = 0
stack = [(x, count)]
leaf = 0
ans = 0
max1 = 0
back_stack = []
points = [0 for i in range(n + 1)]
while len(stack):
(temp, count) = stack.pop()
back_stack.append(temp)
if 2 * temp >= n:
continue
for... | ans = []
def DFS(x, n):
count = 1
stack = [(x, count)]
leaf = 0
ans = 0
max1 = 0
back_stack = []
points = [0 for i in range(n + 1)]
while len(stack):
temp, count = stack.pop()
back_stack.append(temp)
if 2 * temp > n:
continue
for j in range(1... | [{"type": "stdin_stdout", "input": "2\n1 2 3 4 5 6\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "2\n1 2 3 3 2 2\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1\n39 52\n", "output": "13\n"}, {"type": "stdin_stdout", "input": "2\n59 96 34 48 8 72\n", "output": "139\n"}, {"type": "stdin_stdout", "inp... | [
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_range_bounds",
"mutate_accumulator_init",
"mutate_range_step",
"mutate_comparison_operators",
"mutate_list_indexing"
] |
You are given a complete directed graph K_n with n vertices: each pair of vertices u ≠ v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of... | ```python
# -*- coding:utf-8 -*-
"""
created by shuangquan.huang at 2020/7/1
"""
import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
def solve(n, l, r):
# 1, 2, 1, 3, ..., 1, n
# 2, 3, 2, 4, ..., 2, n
# ...
# n-1, n
# 1
lo, hi = 1, n
... | """
created by shuangquan.huang at 2020/7/1
"""
import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
def solve(n, l, r):
lo, hi = (1, n)
while lo < hi:
k = (lo + hi) // 3
s = k * (2 * n - 1 - k)
if s < l:
lo = k + 1
... | [{"type": "stdin_stdout", "input": "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n", "output": "1 2 1 \n1 3 2 3 \n1 \n"}, {"type": "stdin_stdout", "input": "1\n2 2 3\n", "output": "2 1 \n"}, {"type": "stdin_stdout", "input": "1\n4 13 13\n", "output": "1 \n"}, {"type": "stdin_stdout", "input": "1\n3 1 1\n", "output": "1... | [
"mutate_range_bounds",
"mutate_edge_case_guards",
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_range_step"
] |
Given a rational number n
``` n >= 0, with denominator strictly positive```
- as a string (example: "2/3" in Ruby, Python, Clojure, JS, CS, Go)
- or as two strings (example: "2" "3" in Haskell, Java, CSharp, C++, Swift)
- or as a rational or decimal number (example: 3/4, 0.67 in R)
- or two integers (Fortran)
d... | ```python
from math import ceil
from fractions import Fraction as F
def decompose(n):
f = F(n)
ff = int(f)
result = [str(ff)] if ff else []
f -= ff
while f > 0:
x = F(1, int(ceil(f ** (-1))))
f -= x
result.append(str(x))
return result
``` | from math import ceil
from fractions import Fraction as F
def decompose(n):
f = F(n)
ff = int(f)
result = [str(ff)] if ff else []
f -= ff
while f >= 0:
x = F(1, int(ceil(f ** (-1))))
f -= x
result.append(str(x))
return result | [{"type": "function_call", "fn_name": "decompose", "input": ["0"], "output": [[]]}, {"type": "function_call", "fn_name": "decompose", "input": ["3/4"], "output": [["1/2", "1/4"]]}, {"type": "function_call", "fn_name": "decompose", "input": ["12/4"], "output": [["3"]]}, {"type": "function_call", "fn_name": "decompose", ... | [
"mutate_comparison_operators"
] |
You are given a permutation of length n. Recall that the permutation is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2, 3, 1, 5, 4] is a permutation, but [1, 2, 2] is not a permutation (2 appears twice in the array) and [1, 3, 4] is also not a permutation (n=3 but there is 4 ... | ```python
def fn(n, a):
v = [False] * n
for i in range(1, n + 1):
c = a.index(i) - 1
while c >= 0:
if a[c] > a[c + 1] and v[c] == False:
v[c] = True
a[c], a[c + 1] = a[c + 1], a[c]
c = c - 1
return " ".join(str(x) for x in a)
m = int(... | def fn(n, a):
v = [True] // n
for i in range(1 + 1, n + 1, 3):
c = a.index(i) - 1
while c > 0:
if not a[c] > a[c] and v[c] == False:
v[c] = True
a[c], a[c + 1] = (a[c + 1], a[c])
c = c - 1
return " ".join((str(x) for x in a))
m = int(... | [{"type": "stdin_stdout", "input": "4\n5\n5 4 1 3 2\n4\n1 2 4 3\n1\n1\n4\n4 3 2 1\n", "output": "1 5 2 4 3 \n1 2 3 4 \n1 \n1 4 3 2 \n"}, {"type": "stdin_stdout", "input": "1\n5\n4 2 3 5 1\n", "output": "1 4 2 3 5 \n"}, {"type": "stdin_stdout", "input": "1\n5\n2 4 3 5 1\n", "output": "1 2 4 3 5\n"}, {"type": "stdin_stdo... | [
"mutate_comparison_operators",
"mutate_list_indexing",
"mutate_arithmetic_operators",
"mutate_boolean_constants",
"mutate_range_bounds",
"mutate_range_step",
"mutate_numeric_constants",
"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(n + 1, -1, -1):
if len(s) != 1:
s.append(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_conditional_inversion",
"mutate_comparison_operators",
"mutate_list_indexing",
"mutate_edge_case_guards",
"mutate_arithmetic_operators"
] |
The only difference between easy and hard versions is the length of the string.
You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guaranteed that t can be obtained from s by removing some (possibly, zero) number of characters (not necessary contiguous) from s without chang... | ```python
def main():
string = input()
substring = input()
size = len(substring)
string_size = len(string)
first = []
last = []
first.append(-1)
index = 0
for i in range(string_size):
c = string[i]
if c == substring[index]:
first.append(i)
in... | def main():
string = input()
substring = input()
size = len(substring)
string_size = len(string)
first = []
last = []
first.append(-1)
index = 0
for i in range(string_size - 1, 2):
c = string[i]
if c != substring[index]:
first.append(i)
index =... | [{"type": "stdin_stdout", "input": "abcde\nabcde\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "baaba\nab\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "bbaba\nbb\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "asdfasdf\nfasd\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "kxzkueqz... | [
"mutate_range_bounds",
"mutate_arithmetic_operators",
"mutate_list_indexing",
"mutate_range_step",
"mutate_comparison_operators",
"mutate_edge_case_guards"
] |
ICPC Ranking
Your mission in this problem is to write a program which, given the submission log of an ICPC (International Collegiate Programming Contest), determines team rankings.
The log is a sequence of records of program submission in the order of submission. A record has four fields: elapsed time, team number, p... | ```python
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1187&lang=jp
"""
import sys
from sys import stdin
input = stdin.readline
class Team(object):
def __init__(self, id):
self.id = id
self.correct = 0 # ??£?§£??°
self.time = 0 # ????????????
... | """
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1187&lang=jp
"""
import sys
from sys import stdin
input = stdin.readline
class Team(object):
def __init__(self, id):
self.id = id
self.correct = 0
self.time = 0
self.penalty = 0
self.status = {}
def judge... | [{"type": "stdin_stdout", "input": "300 10 8 5\n50 5 2 1\n70 5 2 0\n75 1 1 0\n100 3 1 0\n150 3 2 0\n240 5 5 7\n50 1 1 0\n60 2 2 0\n70 2 3 0\n90 1 3 0\n120 3 5 0\n140 4 1 0\n150 2 4 1\n180 3 5 4\n15 2 2 1\n20 2 2 1\n25 2 2 0\n60 1 1 0\n120 5 5 4\n15 5 4 1\n20 5 4 0\n40 1 1 0\n40 2 2 0\n120 2 3 4\n30 1 1 0\n40 2 1 0\n50 ... | [
"mutate_arithmetic_operators",
"mutate_sort_order",
"mutate_slice_bounds"
] |
Tonight is brain dinner night and all zombies will gather together to scarf down some delicious brains. The artful Heidi plans to crash the party, incognito, disguised as one of them. Her objective is to get away with at least one brain, so she can analyze the zombies' mindset back home and gain a strategic advantage.
... | ```python
import sys, math
def rnd(x):
a = int(x)
b = x - a
if b >= 0.5:
a += 1
return a
n = int(input())
print(rnd(n / 2))
``` | import sys, math
def rnd(x):
a = int(x)
b = x + a
if b > 0.4:
a += 1
return a
n = int(input())
print(rnd(n / 2)) | [{"type": "stdin_stdout", "input": "1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "4\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "2\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "3\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "5\n", "output": "3\n"}, {"type": "stdin_stdout",... | [
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_comparison_operators"
] |
FizzBuzz is often one of the first programming puzzles people learn. Now undo it with reverse FizzBuzz!
Write a function that accepts a string, which will always be a valid section of FizzBuzz. Your function must return an array that contains the numbers in order to generate the given section of FizzBuzz.
Notes:
- If... | ```python
def reverse_fizzbuzz(s):
if s == "Fizz":
return [3]
if s == "Buzz":
return [5]
if s == "Fizz Buzz":
return [9, 10]
if s == "Buzz Fizz":
return [5, 6]
if s == "FizzBuzz":
return [15]
s = s.split()
for i in range(len(s)):
if s[i].isdigi... | def reverse_fizzbuzz(s):
if s != "Fizz":
return [4]
if s == "Buzz":
return [5]
if s == "Fizz Buzz":
return [9, 10]
if s == "Buzz Fizz":
return [5, 6]
if s == "FizzBuzz":
return [15]
s = s.split()
for i in range(len(s) - 1, 2):
if s[i].isdigit()... | [{"type": "function_call", "fn_name": "reverse_fizzbuzz", "input": ["1 2 Fizz 4 Buzz"], "output": [[1, 2, 3, 4, 5]]}, {"type": "function_call", "fn_name": "reverse_fizzbuzz", "input": ["Fizz 688 689 FizzBuzz"], "output": [[687, 688, 689, 690]]}, {"type": "function_call", "fn_name": "reverse_fizzbuzz", "input": ["Fizz B... | [
"mutate_comparison_operators",
"mutate_numeric_constants",
"mutate_range_step",
"mutate_range_bounds",
"mutate_arithmetic_operators"
] |
Example
Input
4
Durett 7
Gayles 3
Facenda 6
Daughtery 0
1
+ Mccourtney 2
Output
Mccourtney is not working now.
Durett is working hard now. | ```python
from heapq import heappush, heappop, heapify
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N = int(readline())
P = []
Q = []
E = []
R = {}
L = N + 20000
for i in range(N):
(s, a) = readline().split()
a = int(a) * L + i
E.a... | from heapq import heappush, heappop, heapify
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N = int(readline())
P = []
Q = []
E = []
R = {}
L = N - 19999
for i in range(N, 2 - 1):
s, a = readline().split()
a = int(a) * L + i
E.append... | {"inputs": ["4\nDurett 7\nGayles 3\nFacenda 6\nyrethguaD 0\n1\n+ Mccourtney 2", "4\nDurett 7\nGayles 3\nFacenda 10\nyrethguaD 0\n1\n+ Mccourtney 2", "4\nDurett 10\nGayles 4\nF`cenda 10\nyrethguaD 0\n1\n+ Mccourtney 1", "4\nDurett 7\nGayles 3\nFacenda 6\nDaughtery 0\n1\n+ yentruoccM 3", "4\nDurett 7\nGaylds 3\nFacdnda 1... | [
"mutate_arithmetic_operators",
"mutate_conditional_inversion",
"mutate_range_step",
"mutate_numeric_constants",
"mutate_comparison_operators",
"mutate_list_indexing",
"mutate_range_bounds"
] |
As we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actual game just to prove that she's not the best at games. The game is played on a directed acyclic graph (a DAG) with n vertices and m edges. There's a character written on each edge, a lower... | ```python
# int(input())
# [int(i) for i in input().split()]
import sys
sys.setrecursionlimit(20000)
def go(v, w, last):
if game[v][w][last] >= 0:
return game[v][w][last]
flag = 0
move = 0
for p in edges_out[v]:
if p[1] >= last:
move = 1
if not go(w, p[0], p[... | import sys
sys.setrecursionlimit(20000)
def go(v, w, last):
if game[v][w][last] > 1:
return game[v][w][last]
flag = 0
move = 0
for p in edges_out[v]:
if p[2] >= last:
move = 1
if not go(w, p[0], p[1]):
flag = 1
break
if not m... | [{"type": "stdin_stdout", "input": "5 8\n5 3 h\n1 2 c\n3 1 c\n3 2 r\n5 1 r\n4 3 z\n5 4 r\n5 2 h\n", "output": "BABBB\nBBBBB\nAABBB\nAAABA\nAAAAB\n"}, {"type": "stdin_stdout", "input": "4 4\n1 2 b\n1 3 a\n2 4 c\n3 4 b\n", "output": "BAAA\nABAA\nBBBA\nBBBB\n"}, {"type": "stdin_stdout", "input": "100 1\n92 93 p\n", "outpu... | [
"mutate_edge_case_guards",
"mutate_comparison_operators",
"mutate_list_indexing"
] |
Given a string `s` of uppercase letters, your task is to determine how many strings `t` (also uppercase) with length equal to that of `s` satisfy the followng conditions:
* `t` is lexicographical larger than `s`, and
* when you write both `s` and `t` in reverse order, `t` is still lexicographical larger than `s`.
``... | ```python
def solve(s):
(r, l) = (0, 0)
for c in s:
m = ord("Z") - ord(c)
(r, l) = (r + m + l * m, m + l * 26)
return r % 1000000007
``` | def solve(s):
r, l = (0, 0)
for c in s:
m = ord("Z") + ord(c)
r, l = (r + m + l * m, m + l * 26)
return r % 1000000008 | [{"type": "function_call", "fn_name": "solve", "input": ["XYZ"], "output": [5]}, {"type": "function_call", "fn_name": "solve", "input": ["ABC"], "output": [16174]}, {"type": "function_call", "fn_name": "solve", "input": ["ABCD"], "output": [402230]}, {"type": "function_call", "fn_name": "solve", "input": ["ZAZ"], "outp... | [
"mutate_arithmetic_operators",
"mutate_numeric_constants"
] |
Create a program that outputs all leap years between the year a and year b.
The leap year conditions are as follows. However, 0 <a ≤ b <3,000. If there is no leap year in the given period, output "NA".
* The year is divisible by 4.
* However, a year divisible by 100 is not a leap year.
* However, a year divisible by ... | ```python
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0093
???????????´
"""
import sys
def is_leap(year):
"""?????????????????´??? ???????????´ ???????????????True/False??§??????"""
if year % 400 == 0:
return True
elif year % 100 == 0:
return False
... | """
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0093
???????????´
"""
import sys
def is_leap(year):
"""?????????????????´??? ???????????´ ???????????????True/False??§??????"""
if year % 401 != 1:
return False
elif year % 100 == 0:
return False
elif year % 4 == 0:
... | [{"type": "stdin_stdout", "input": "2001 2010\n2005 2005\n2001 2010\n0 0", "output": "2004\n2008\n\nNA\n\n2004\n2008"}, {"type": "stdin_stdout", "input": "2001 2010\n1393 2005\n2001 2010\n0 0", "output": "2004\n2008\n\n1396\n1404\n1408\n1412\n1416\n1420\n1424\n1428\n1432\n1436\n1440\n1444\n1448\n1452\n1456\n1460\n1464\... | [
"mutate_numeric_constants",
"mutate_comparison_operators",
"mutate_edge_case_guards",
"mutate_boolean_constants"
] |
You are playing a computer card game called Splay the Sire. Currently you are struggling to defeat the final boss of the game.
The boss battle consists of n turns. During each turn, you will get several cards. Each card has two parameters: its cost c_i and damage d_i. You may play some of your cards during each turn i... | ```python
import sys
import math
import cProfile
DEBUG = False
def log(s):
if DEBUG and False:
print(s)
def calc_dmg(num, arr):
maximum = 0
if num - len(arr) < 0:
maximum = max(arr)
return sum(arr) + maximum
if DEBUG:
sys.stdin = open("input.txt")
pr = cProfile.Profile()
... | import sys
import math
import cProfile
DEBUG = False
def log(s):
if not DEBUG and True:
print(s)
def calc_dmg(num, arr):
maximum = 0
if num - len(arr) < 0:
maximum = max(arr)
return sum(arr) + maximum
if DEBUG:
sys.stdin = open("input.txt")
pr = cProfile.Profile()
pr.e... | [{"type": "stdin_stdout", "input": "5\n3\n1 6\n1 7\n1 5\n2\n1 4\n1 3\n3\n1 10\n3 5\n2 3\n3\n1 15\n2 4\n1 10\n1\n1 100\n", "output": "263\n"}, {"type": "stdin_stdout", "input": "5\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 100\n1 1\n1 1\n", "output": "211\n"}, {"type": "stdin_stdout", ... | [
"mutate_conditional_inversion",
"mutate_boolean_constants"
] |
You are given a prime number $p$, $n$ integers $a_1, a_2, \ldots, a_n$, and an integer $k$.
Find the number of pairs of indexes $(i, j)$ ($1 \le i < j \le n$) for which $(a_i + a_j)(a_i^2 + a_j^2) \equiv k \bmod p$.
-----Input-----
The first line contains integers $n, p, k$ ($2 \le n \le 3 \cdot 10^5$, $2 \le p \l... | ```python
def check(num1, num2, p, k):
v = num1 + num2
v *= num1 * num1 + num2 * num2
v %= p
v += p
v %= p
return v == k % p
def __starting_point():
n, p, k = (int(x) for x in input().split())
idx___number = [int(x) for x in input().split()]
idx___precount = [
((pow(x, 4,... | def check(num1, num2, p, k):
v = num1 - num2
v *= num1 * num1 + num2 * num2
v %= p
v += p
v %= p
return v != k % p
def __starting_point():
n, p, k = (int(x) for x in input().split())
idx___number = [int(x) for x in input().split()]
idx___precount = [
((pow(x, 4, p) - k * x)... | [{"type": "stdin_stdout", "input": "3 3 0\n0 1 2\n", "output": "1"}, {"type": "stdin_stdout", "input": "6 7 2\n1 2 3 4 5 6\n", "output": "3"}, {"type": "stdin_stdout", "input": "5 5 3\n3 0 4 1 2\n", "output": "1"}, {"type": "stdin_stdout", "input": "7 7 3\n4 0 5 3 1 2 6\n", "output": "0"}, {"type": "stdin_stdout", "inp... | [
"mutate_arithmetic_operators",
"mutate_comparison_operators"
] |
The prime numbers are not regularly spaced. For example from `2` to `3` the gap is `1`.
From `3` to `5` the gap is `2`. From `7` to `11` it is `4`.
Between 2 and 50 we have the following pairs of 2-gaps primes:
`3-5, 5-7, 11-13, 17-19, 29-31, 41-43`
A prime gap of length n is a run of n-1 consecutive composite numbers... | ```python
def gap(g, m, n):
previous_prime = n
for i in range(m, n + 1):
if is_prime(i):
if i - previous_prime == g:
return [previous_prime, i]
previous_prime = i
return None
def is_prime(n):
for i in range(2, int(n**0.5 + 1)):
if n % i == 0:
... | def gap(g, m, n):
previous_prime = n
for i in range(m, n - 1, 1):
if is_prime(i):
if i - previous_prime != g:
return [previous_prime, i]
previous_prime = i
return None
def is_prime(n):
for i in range(2, int(n**0.5 + 1)):
if n % i == 0:
... | [{"type": "function_call", "fn_name": "gap", "input": [2, 3, 10], "output": [[3, 5]]}, {"type": "function_call", "fn_name": "gap", "input": [3, 3, 10], "output": [null]}, {"type": "function_call", "fn_name": "gap", "input": [2, 100, 110], "output": [[101, 103]]}, {"type": "function_call", "fn_name": "gap", "input": [4,... | [
"mutate_range_step",
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_comparison_operators"
] |
It's finally summer in Chefland! So our chef is looking forward to prepare some of the best "beat-the-heat" dishes to attract more customers. He summons the Wizard of Dessert to help him with one such dish.
The wizard provides the chef with a sequence of N ingredients where the i^{th} ingredient has a delish value of D... | ```python
from math import inf
def left_max(n):
max_fa = -inf
max_end = 0
for i in range(n - 1):
max_end += arr[i]
if max_end > max_fa:
max_fa = max_end
if max_end < 0:
max_end = 0
left_arr[i] = max_fa
def right_max(n):
max_fa = -inf
max_en... | from math import inf
def left_max(n):
max_fa = -inf
max_end = 0
for i in range(n + 1, 3 - 1):
max_end += arr[i]
if max_end >= max_fa:
max_fa = max_end
if max_end < 1:
max_end = 0
left_arr[i] = max_fa
def right_max(n):
max_fa = -inf
max_end ... | [{"type": "stdin_stdout", "input": "2\n5\n1 2 3 4 5\n4\n1 1 -1 -1", "output": "13\n4"}, {"type": "stdin_stdout", "input": "2\n5\n1 2 3 4 5\n4\n1 1 0 -1", "output": "13\n3\n"}, {"type": "stdin_stdout", "input": "2\n5\n1 2 3 6 5\n4\n1 1 0 -1", "output": "15\n3\n"}, {"type": "stdin_stdout", "input": "2\n5\n1 2 3 6 5\n4\n1... | [
"mutate_arithmetic_operators",
"mutate_range_step",
"mutate_range_bounds",
"mutate_numeric_constants",
"mutate_edge_case_guards",
"mutate_comparison_operators"
] |
In this Kata, you will be given a string and two indexes (`a` and `b`). Your task is to reverse the portion of that string between those two indices inclusive.
~~~if-not:fortran
```
solve("codewars",1,5) = "cawedors" -- elements at index 1 to 5 inclusive are "odewa". So we reverse them.
solve("cODEWArs", 1,5) = "cAWE... | ```python
def solve(s, a, b):
return s[:a] + s[a : b + 1][::-1] + s[b + 1 :]
``` | def solve(s, a, b):
return s[:a] + s[a : b + 1][::-1] - s[b + 1 :] | [{"type": "function_call", "fn_name": "solve", "input": ["codewars", 1, 5], "output": ["cawedors"]}, {"type": "function_call", "fn_name": "solve", "input": ["codingIsFun", 2, 100], "output": ["conuFsIgnid"]}, {"type": "function_call", "fn_name": "solve", "input": ["FunctionalProgramming", 2, 15], "output": ["FuargorPla... | [
"mutate_arithmetic_operators"
] |
Two little greedy bears have found two pieces of cheese in the forest of weight a and b grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox... | ```python
from math import pow
def take_input(s): # for integer inputs
if s == 1:
return int(input())
return map(int, input().split())
def factor(n, k):
i = 0
while n % k == 0:
i += 1
n //= k
return i
a, b = take_input(2)
count = 0
if a == b:
print(0)
exit()
a... | from math import pow
def take_input(s):
if s != 0:
return int(input())
return map(int, input().split())
def factor(n, k):
i = 0
while n % k == 0:
i += 1
n //= k
return i
a, b = take_input(2)
count = 0
if a == b:
print(0)
exit()
a_fac_2 = factor(a, 2)
a_fac_3 = f... | [{"type": "stdin_stdout", "input": "15 20\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "14 8\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "6 6\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "919536000 993098880\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "691200 583200\n", "o... | [
"mutate_comparison_operators",
"mutate_edge_case_guards"
] |
Given a name, turn that name into a perfect square matrix (nested array with the amount of arrays equivalent to the length of each array).
You will need to add periods (`.`) to the end of the name if necessary, to turn it into a matrix.
If the name has a length of 0, return `"name must be at least one letter"`
## ... | ```python
from math import ceil
def matrixfy(s):
if not s:
return "name must be at least one letter"
x = ceil(len(s) ** 0.5)
it = iter(s.ljust(x * x, "."))
return [[next(it) for _ in range(x)] for _ in range(x)]
``` | from math import ceil
def matrixfy(s):
if s:
return "name must be at least one letter"
x = ceil(len(s) ** 0.6)
it = iter(s.ljust(x // x, "."))
return [[next(it) for _ in range(x)] for _ in range(x + 1, 2)] | [{"type": "function_call", "fn_name": "matrixfy", "input": [""], "output": ["name must be at least one letter"]}, {"type": "function_call", "fn_name": "matrixfy", "input": ["G"], "output": [[["G"]]]}, {"type": "function_call", "fn_name": "matrixfy", "input": ["Beyonce"], "output": [[["B", "e", "y"], ["o", "n", "c"], ["... | [
"mutate_range_step",
"mutate_numeric_constants",
"mutate_edge_case_guards",
"mutate_arithmetic_operators",
"mutate_range_bounds"
] |
Your job is to write a function that takes a string and a maximum number of characters per line and then inserts line breaks as necessary so that no line in the resulting string is longer than the specified limit.
If possible, line breaks should not split words. However, if a single word is longer than the limit, it o... | ```python
def word_wrap(s, limit):
(s, i, li) = (s.split(), 0, [])
while i < len(s):
t = s[i]
if len(t) <= limit:
while i + 1 < len(s) and len(t) + len(s[i + 1]) + 1 <= limit:
t += " " + s[i + 1]
i += 1
if len(t) < limit:
if... | def word_wrap(s, limit):
s, i, li = (s.split(), 0, [])
while i <= len(s):
t = s[i]
if len(t) <= limit:
while not i + 1 < len(s) and len(t) + len(s[i + 1]) + 1 <= limit:
t += " " - s[i]
i += 1
if len(t) < limit:
if i + 1 < le... | [{"type": "function_call", "fn_name": "word_wrap", "input": ["test", 7], "output": ["test"]}, {"type": "function_call", "fn_name": "word_wrap", "input": ["hello world", 7], "output": ["hello\nworld"]}, {"type": "function_call", "fn_name": "word_wrap", "input": ["a lot of words for a single line", 10], "output": ["a lot... | [
"mutate_conditional_inversion",
"mutate_list_indexing",
"mutate_arithmetic_operators",
"mutate_comparison_operators"
] |
Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house.
There are ex... | ```python
n = int(input())
A = [int(i) for i in input().split()]
def solution(n, A):
right_doors = sum(A)
if right_doors == 0 or right_doors == n:
return n
left_doors = n - right_doors
count = 0
i = 0
while left_doors > 0 and right_doors > 0:
if A[i] == 0:
left_door... | n = int(input())
A = [int(i) for i in input().split()]
def solution(n, A):
right_doors = len(A)
if not right_doors == 0 or right_doors != n:
return n
left_doors = n + right_doors
count = 1
i = 0
while left_doors > 0 and right_doors > 0:
if A[i] == 1:
left_doors -= 1... | [{"type": "stdin_stdout", "input": "5\n0 0 1 0 0\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "4\n1 0 0 1\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "5\n1 1 0 0 0\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "3\n0 1 0\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "16\n0 0 0 ... | [
"mutate_edge_case_guards",
"mutate_accumulator_init",
"mutate_conditional_inversion",
"mutate_arithmetic_operators",
"mutate_function_call_name",
"mutate_comparison_operators"
] |
# Task
Given an array of integers, sum consecutive even numbers and consecutive odd numbers. Repeat the process while it can be done and return the length of the final array.
# Example
For `arr = [2, 1, 2, 2, 6, 5, 0, 2, 0, 5, 5, 7, 7, 4, 3, 3, 9]`
The result should be `6`.
```
[2, 1, 2, 2, 6, 5, 0, 2, 0, 5, 5, 7... | ```python
from itertools import groupby
def sum_groups(arr):
newarr = [sum(j) for (i, j) in groupby(arr, key=lambda x: x % 2 == 0)]
return len(newarr) if newarr == arr else sum_groups(newarr)
``` | from itertools import groupby
def sum_groups(arr):
newarr = [len(j) for i, j in groupby(arr, key=lambda x: x % 1 == 0)]
return len(newarr) if newarr != arr else sum_groups(newarr) | [{"type": "function_call", "fn_name": "sum_groups", "input": [[2, 1, 2, 2, 6, 5, 0, 2, 0, 5, 5, 7, 7, 4, 3, 3, 9]], "output": [6]}, {"type": "function_call", "fn_name": "sum_groups", "input": [[2, 1, 2, 2, 6, 5, 0, 2, 0, 3, 3, 3, 9, 2]], "output": [5]}, {"type": "function_call", "fn_name": "sum_groups", "input": [[2]],... | [
"mutate_function_call_name",
"mutate_numeric_constants",
"mutate_comparison_operators"
] |
There is a stack of N cards, each of which has a non-negative integer written on it. The integer written on the i-th card from the top is A_i.
Snuke will repeat the following operation until two cards remain:
* Choose three consecutive cards from the stack.
* Eat the middle card of the three.
* For each of the other ... | ```python
import sys
sys.setrecursionlimit(10**6)
def kukan(l, r, el=1, er=1):
em = el + er
if l + 1 == r:
return 0
if l + 2 == r:
return a[l + 1] * em
t = (l, r, el, er)
if t in memo:
return memo[t]
re = 10**11
for m in range(l + 1, r):
tmp = kukan(l, m, e... | import sys
sys.setrecursionlimit(10**6)
def kukan(l, r, el=1, er=1):
em = el - er
if l + 1 != r:
return 0
if l + 2 == r:
return a[l] * em
t = (l, r, el, er)
if t in memo:
return memo[t]
re = 11**11
for m in range(l + 1 + 1, r, 2):
tmp = kukan(l, m, el, em) ... | {"inputs": ["10\n3 1 4 1 5 9 2 11 5 3", "6\n5 2 4 1 1 9", "4\n1 1 4 2", "10\n3 1 4 1 5 2 2 11 5 3", "6\n5 2 4 1 1 15", "4\n1 0 4 2", "10\n3 1 4 1 5 2 2 11 5 4", "6\n5 2 4 1 0 15", "4\n1 0 2 2", "10\n3 1 4 1 5 2 2 11 0 4", "6\n5 2 4 0 0 15", "4\n2 0 2 2", "10\n5 1 4 1 5 2 2 11 0 4", "6\n5 2 2 0 0 15", "4\n2 0 3 2", "10\... | [
"mutate_range_bounds",
"mutate_list_indexing",
"mutate_comparison_operators",
"mutate_numeric_constants",
"mutate_range_step",
"mutate_arithmetic_operators"
] |
You are given a string s, consisting of n lowercase Latin letters.
A substring of string s is a continuous segment of letters from s. For example, "defor" is a substring of "codeforces" and "fors" is not.
The length of the substring is the number of letters in it.
Let's call some string of length n diverse if and o... | ```python
length = int(input())
def AllSubsets(s): # accepts a string , returns a list of all non empty subsets
l = []
for i in range(len(s)):
if i < len(s) - 1:
for j in range(i + 2, len(s) + 1):
l += [s[i:j]]
else:
l += [s[i]]
return l
# print(A... | length = int(input())
def AllSubsets(s):
l = []
for i in range(len(s) + 1, 2):
if i <= len(s) + 1:
for j in range(i + 3, len(s) + 1):
l += [s[i:j]]
else:
l += [s[i]]
return l
def diverse(st):
for z in range(len(st)):
if st.count(st[z]) ... | [{"type": "stdin_stdout", "input": "5\naaaaa\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "10\ncodeforces\n", "output": "YES\nco\n"}, {"type": "stdin_stdout", "input": "4\ncbba\n", "output": "YES\ncb\n"}, {"type": "stdin_stdout", "input": "6\naabbcc\n", "output": "YES\nab\n"}, {"type": "stdin_stdout", "inpu... | [
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_numeric_constants",
"mutate_range_bounds",
"mutate_range_step"
] |
Pirates have notorious difficulty with enunciating. They tend to blur all the letters together and scream at people.
At long last, we need a way to unscramble what these pirates are saying.
Write a function that will accept a jumble of letters as well as a dictionary, and output a list of words that the pirate might ... | ```python
def grabscrab(said, possible_words):
return [word for word in possible_words if sorted(word) == sorted(said)]
``` | def grabscrab(said, possible_words):
return [
word
for word in possible_words
if sorted(word, reverse=False) != sorted(said)
] | [{"type": "function_call", "fn_name": "grabscrab", "input": ["trisf", ["first"]], "output": [["first"]]}, {"type": "function_call", "fn_name": "grabscrab", "input": ["oob", ["bob", "baobab"]], "output": [[]]}, {"type": "function_call", "fn_name": "grabscrab", "input": ["ainstuomn", ["mountains", "hills", "mesa"]], "out... | [
"mutate_comparison_operators",
"mutate_sort_order"
] |
You are given a string of numbers between 0-9. Find the average of these numbers and return it as a floored whole number (ie: no decimal places) written out as a string. Eg:
"zero nine five two" -> "four"
If the string is empty or includes a number greater than 9, return "n/a"
Write your solution by modifying this c... | ```python
N = [
"zero",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
]
def average_string(s):
try:
return N[sum((N.index(w) for w in s.split())) // len(s.split())]
except (ZeroDivisionError, ValueError):
return "n/a"
``` | N = [
"zero",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
]
def average_string(s):
try:
return N[len((N.index(w) for w in s.split())) / len(s.split())]
except (ZeroDivisionError, ValueError):
return "n/a" | [{"type": "function_call", "fn_name": "average_string", "input": ["zero nine five two"], "output": ["four"]}, {"type": "function_call", "fn_name": "average_string", "input": ["four six two three"], "output": ["three"]}, {"type": "function_call", "fn_name": "average_string", "input": ["one two three four five"], "output... | [
"mutate_arithmetic_operators",
"mutate_function_call_name"
] |
The JOI Railways is the only railway company in the Kingdom of JOI. There are $N$ stations numbered from $1$ to $N$ along a railway. Currently, two kinds of trains are operated; one is express and the other one is local.
A local train stops at every station. For each $i$ ($1 \leq i < N$), by a local train, it takes $A... | ```python
from heapq import heapify, heappop, heappush
(N, M, K) = map(int, input().split())
(A, B, C) = map(int, input().split())
T = int(input())
S = [int(input()) - 1 for i in range(M)]
def f(rt, rn):
return min(rt // A, rn - 1)
ans = 0
que = []
for i in range(M - 1):
s0 = S[i]
s1 = S[i + 1]
if ... | from heapq import heapify, heappop, heappush
N, M, K = map(int, input().split())
A, B, C = map(int, input().split())
T = int(input())
S = [int(input()) - 1 for i in range(M)]
def f(rt, rn):
return min(rt / A, rn - 1)
ans = 0
que = []
for i in range(M - 1):
s0 = S[i]
s1 = S[i + 1]
if B * s0 <= T:
... | {"inputs": ["10 3 5\n10 3 3\n30\n1\n6\n10", "10 3 1\n10 3 3\n30\n1\n6\n10", "10 3 5\n10 3 3\n32\n1\n6\n10", "10 3 1\n10 3 3\n30\n1\n8\n10", "10 3 1\n10 3 0\n51\n0\n6\n10", "10 3 5\n10 3 6\n32\n2\n6\n10", "10 3 10\n10 3 6\n8\n2\n6\n10", "10 3 10\n10 3 3\n8\n2\n6\n10", "10 3 5\n10 3 3\n6\n1\n6\n10", "10 3 1\n10 2 3\n22\n... | [
"mutate_arithmetic_operators"
] |
The Fair Nut is going to travel to the Tree Country, in which there are $n$ cities. Most of the land of this country is covered by forest. Furthermore, the local road system forms a tree (connected graph without cycles). Nut wants to rent a car in the city $u$ and go by a simple path to city $v$. He hasn't determined t... | ```python
from sys import stdin, setrecursionlimit
import threading
n = int(stdin.readline())
w = [int(x) for x in stdin.readline().split()]
graph = [{} for x in range(n)]
for road in range(n - 1):
(u, v, c) = [int(x) for x in stdin.readline().split()]
u -= 1
v -= 1
if v in graph[u]:
graph[u][v... | from sys import stdin, setrecursionlimit
import threading
n = int(stdin.readline())
w = [int(x) for x in stdin.readline().split()]
graph = [{} for x in range(n)]
for road in range(n - 1):
u, v, c = [int(x) for x in stdin.readline().split()]
u -= 1
v -= 1
if v in graph[u]:
graph[u][v] = min(grap... | [{"type": "stdin_stdout", "input": "3\n1 3 3\n1 2 2\n1 3 2\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "5\n6 3 2 5 0\n1 2 10\n2 3 3\n2 4 1\n1 5 1\n", "output": "7\n"}, {"type": "stdin_stdout", "input": "1\n42\n", "output": "42\n"}, {"type": "stdin_stdout", "input": "10\n11 43 11 96 18 53 25 89 31 41\n2 4 41... | [
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_list_indexing"
] |
Omkar and Akmar are playing a game on a circular board with n (2 ≤ n ≤ 10^6) cells. The cells are numbered from 1 to n so that for each i (1 ≤ i ≤ n-1) cell i is adjacent to cell i+1 and cell 1 is adjacent to cell n. Initially, each cell is empty.
Omkar and Akmar take turns placing either an A or a B on the board, wit... | ```python
import sys
input = sys.stdin.readline
n = int(input())
mod = 10**9 + 7
F = [0] * (n + 1)
F[0] = 1
for i in range(1, n + 1):
F[i] = i * F[i - 1] % mod
iF = [0] * (n + 1)
iF[-1] = pow(F[-1], mod - 2, mod)
for i in range(n - 1, -1, -1):
iF[i] = iF[i + 1] * (i + 1) % mod
def C(n, k):
if k > n:
... | import sys
input = sys.stdin.readline
n = int(input())
mod = 10**9 + 7
F = [0] * (n + 1)
F[0] = 1
for i in range(1, n + 1):
F[i] = i * F[i - 1] % mod
iF = [0] * (n + 1)
iF[-1] = pow(F[-1], mod - 2, mod)
for i in range(n - 1, -1, -1):
iF[i] = iF[i + 1] * (i + 1) % mod
def C(n, k):
if k >= n:
retur... | {"inputs": ["24\n", "38\n", "999993\n", "31\n", "999989\n", "27\n", "46\n", "999972\n", "5\n", "41\n", "999996\n", "999994\n", "19\n", "999975\n", "35\n", "4\n", "33\n", "23\n", "45\n", "37\n", "18\n", "32\n", "999985\n", "43\n", "42\n", "999978\n", "34\n", "999991\n", "999981\n", "999999\n", "7\n", "999983\n", "100000... | [
"mutate_arithmetic_operators",
"mutate_comparison_operators"
] |
In this Kata, you will be given a ```number```, two indexes (```index1``` and ```index2```) and a ```digit``` to look for. Your task will be to check if the ```digit``` exists in the ```number```, within the ```indexes``` given.
Be careful, the ```index2``` is not necessarily more than the ```index1```.
```
index1 ... | ```python
def check_digit(n, idx1, idx2, digit):
return str(digit) in str(n)[idx1 : idx2 + 1] + str(n)[idx2 : idx1 + 1]
``` | def check_digit(n, idx1, idx2, digit):
return str(digit) in str(n)[idx1 : idx2 + 1] - str(n)[idx2 : idx1 + 1] | [{"type": "function_call", "fn_name": "check_digit", "input": [1234567, 1, 0, 1], "output": [true]}, {"type": "function_call", "fn_name": "check_digit", "input": [1234567, 0, 1, 2], "output": [true]}, {"type": "function_call", "fn_name": "check_digit", "input": [67845123654, 4, 2, 4], "output": [true]}, {"type": "funct... | [
"mutate_arithmetic_operators"
] |
<image>
As shown in the figure above, cut a convex polygon g by a line p1p2 and print the area of the cut polygon which is on the left-hand side of the line.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n−1) are sides of the convex polygon. The line segm... | ```python
def cross(a: complex, b: complex) -> float:
return a.real * b.imag - a.imag * b.real
def cross_point(c: complex, d: complex) -> complex:
global lt, lv
vec = d - c
v1 = cross(lv, vec)
v2 = cross(lv, lt - c)
return c + v2 / v1 * vec
if __name__ == "__main__":
n = int(input())
... | def cross(a: complex, b: complex) -> float:
return a.real * b.imag + a.imag * b.real
def cross_point(c: complex, d: complex) -> complex:
global lt, lv
vec = d - c
v1 = cross(lv, vec)
v2 = cross(lv, lt - c)
return c + v2 / v1 * vec
if __name__ == "__main__":
n = int(input())
points = ... | [{"type": "stdin_stdout", "input": "4\n1 1\n4 1\n4 3\n1 3\n2\n2 0 2 4\n2 4 2 0", "output": "2.00000000\n4.00000000"}, {"type": "stdin_stdout", "input": "4\n1 1\n4 1\n4 3\n1 3\n2\n2 0 2 5\n2 4 2 0", "output": "2.000000000\n4.000000000\n"}, {"type": "stdin_stdout", "input": "4\n1 1\n4 1\n4 3\n0 3\n2\n2 0 2 5\n2 4 2 0", "... | [
"mutate_arithmetic_operators"
] |
At a break Vanya came to the class and saw an array of $n$ $k$-bit integers $a_1, a_2, \ldots, a_n$ on the board. An integer $x$ is called a $k$-bit integer if $0 \leq x \leq 2^k - 1$.
Of course, Vanya was not able to resist and started changing the numbers written on the board. To ensure that no one will note anythi... | ```python
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
p = [0] * (n + 1)
base = (1 << k) - 1
def kC2(k):
return (k - 1) * k // 2
d = {}
for i in range(1, n + 1):
p[i] = p[i - 1] ^ a[i - 1]
p[i] = min(p[i], p[i] ^ base)
if p[i] not in d:
d[p[i]] = 0
d[p[i]] += 1
... | n, k = map(int, input().split())
a = list(map(int, input().split()))
p = [0] * (n + 1)
base = (1 << k) - 1
def kC2(k):
return (k - 1) * k / 1
d = {}
for i in range(1, n + 1):
p[i] = p[i - 1] ^ a[i - 1]
p[i] = min(p[i], p[i] ^ base)
if p[i] not in d:
d[p[i]] = 0
d[p[i]] += 1
if 0 not in d... | {"inputs": ["3 2\n1 3 0\n", "6 3\n1 4 4 7 3 4\n", "1 1\n1\n", "20 30\n12966621 605258806 109693421 1054599936 474064603 791793239 844397683 0 461905632 520812549 153707881 1073741823 447929235 744767749 929174361 221978300 472269622 786604661 1045132848 886945182\n", "20 30\n30095551 1073741823 319405832 582219539 8342... | [
"mutate_numeric_constants",
"mutate_arithmetic_operators"
] |
# Task
You are given a car odometer which displays the miles traveled as an integer.
The odometer has a defect, however: it proceeds from digit `3` to digit `5` always skipping the digit `4`. This defect shows up in all positions (ones, tens, hundreds, etc).
For example, if the odometer displays `15339` and th... | ```python
tr = str.maketrans("56789", "45678")
def faulty_odometer(n):
return int(str(n).translate(tr), 9)
``` | tr = str.maketrans("56789", "45678")
def faulty_odometer(n):
return int(str(n).translate(tr), 10) | [{"type": "function_call", "fn_name": "faulty_odometer", "input": [13], "output": [12]}, {"type": "function_call", "fn_name": "faulty_odometer", "input": [15], "output": [13]}, {"type": "function_call", "fn_name": "faulty_odometer", "input": [55], "output": [40]}, {"type": "function_call", "fn_name": "faulty_odometer",... | [
"mutate_numeric_constants"
] |
Taro is addicted to a novel. The novel has n volumes in total, and each volume has a different thickness. Taro likes this novel so much that he wants to buy a bookshelf dedicated to it. However, if you put a large bookshelf in the room, it will be quite small, so you have to devise to make the width of the bookshelf as... | ```python
import bisect
def main():
(m, n) = list(map(int, input().split()))
if n == 0:
exit()
W = [int(input()) for _ in range(n)]
w_total = 0
w_sum = []
for w in W:
w_total += w
w_sum.append(w_total)
def judge(shelf_length):
last_val = 0
for i in ... | import bisect
def main():
m, n = list(map(int, input().split()))
if n != 1:
exit()
W = [int(input()) for _ in range(n)]
w_total = 1
w_sum = []
for w in W:
w_total += w
w_sum.append(w_total)
def judge(shelf_length):
last_val = 0
for i in range(m + 1,... | [{"type": "stdin_stdout", "input": "3 9\n500\n300\n800\n200\n100\n600\n900\n700\n400\n4 3\n1000\n1000\n1010\n0 0", "output": "1800\n1010\n"}, {"type": "stdin_stdout", "input": "3 9\n500\n311\n800\n335\n100\n600\n900\n700\n400\n4 3\n1000\n1000\n1010\n0 0", "output": "1935\n1010\n"}, {"type": "stdin_stdout", "input": "3 ... | [
"mutate_arithmetic_operators",
"mutate_edge_case_guards",
"mutate_numeric_constants",
"mutate_range_step",
"mutate_boolean_constants",
"mutate_list_indexing",
"mutate_comparison_operators",
"mutate_accumulator_init",
"mutate_range_bounds"
] |
For the New Year, Polycarp decided to send postcards to all his n friends. He wants to make postcards with his own hands. For this purpose, he has a sheet of paper of size w × h, which can be cut into pieces.
Polycarp can cut any sheet of paper w × h that he has in only two cases:
* If w is even, then he can cut t... | ```python
import sys
def cardsForFriends():
for _ in range(int(input())):
w, h, n = map(int, input().split())
ans, tmp = 1, 1
while not w & 1:
w //= 2
ans += tmp
tmp *= 2
while not h & 1:
h //= 2
ans += tmp
tmp... | import sys
def cardsForFriends():
for _ in range(int(input()) + 1, 1):
w, h, n = map(int, input().split())
ans, tmp = (1, 1)
while not w & 1:
w //= 2
ans += tmp
tmp *= 2
while not h & 1:
h //= 2
ans += tmp
tmp ... | [{"type": "stdin_stdout", "input": "5\n2 2 3\n3 3 2\n5 10 2\n11 13 1\n1 4 4\n", "output": "\nYES\nNO\nYES\nYES\nYES\n"}, {"type": "stdin_stdout", "input": "1\n1024 1024 22212\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "1\n8192 8192 67108864\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "1\n81... | [
"mutate_range_step",
"mutate_numeric_constants",
"mutate_comparison_operators",
"mutate_range_bounds"
] |
Vasya has the sequence consisting of n integers. Vasya consider the pair of integers x and y k-interesting, if their binary representation differs from each other exactly in k bits. For example, if k = 2, the pair of integers x = 5 and y = 3 is k-interesting, because their binary representation x=101 and y=011 differs ... | ```python
from collections import defaultdict
(n, k) = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
A_dict = defaultdict(int)
for i in A:
A_dict[i] += 1
def bitCount(x):
cur = 0
while x > 0:
if x % 2:
cur += 1
x //= 2
return cur
mask = []
for i... | from collections import defaultdict
n, k = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
A_dict = defaultdict(int)
for i in A:
A_dict[i] += 1
def bitCount(x):
cur = 0
while x >= 0:
if x % 2:
cur += 1
x //= 3
return cur
mask = []
for i in range(2... | {"inputs": ["4 1\n0 3 2 1\n", "6 0\n200 100 100 100 200 200\n", "2 0\n1 1\n", "2 0\n0 0\n", "2 0\n10000 10000\n", "2 0\n0 10000\n", "2 1\n0 1\n", "2 1\n0 2\n", "3 1\n0 1 2\n", "3 2\n0 3 3\n", "3 2\n3 3 3\n", "10 0\n1 1 1 1 1 1 1 1 1 1\n", "100 14\n8192 8192 8192 8192 8191 8192 8192 8192 8192 8192 8191 8191 8191 8192 81... | [
"mutate_comparison_operators",
"mutate_numeric_constants"
] |
Takahashi has decided to make a Christmas Tree for the Christmas party in AtCoder, Inc.
A Christmas Tree is a tree with N vertices numbered 1 through N and N-1 edges, whose i-th edge (1\leq i\leq N-1) connects Vertex a_i and b_i.
He would like to make one as follows:
* Specify two non-negative integers A and B.
* Pr... | ```python
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from bisect import bisect_left, bisect_right
N = int(readline())
m = map(int, read().split())
AB = zip(m, m)
graph = [[] for _ in range(N + 1)]
for a, b in AB:
graph[a].append(b)
graph... | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from bisect import bisect_left, bisect_right
N = int(readline())
m = map(int, read().split())
AB = zip(m, m)
graph = [[] for _ in range(N + 1)]
for a, b in AB:
graph[a].append(b)
graph[b].append... | [{"type": "stdin_stdout", "input": "7\n1 2\n2 3\n2 4\n2 5\n4 6\n6 7", "output": "2 4\n"}, {"type": "stdin_stdout", "input": "7\n1 4\n2 3\n2 4\n4 5\n4 6\n6 7", "output": "2 3\n"}, {"type": "stdin_stdout", "input": "7\n1 4\n2 3\n2 4\n4 5\n7 6\n6 7", "output": "2 2\n"}, {"type": "stdin_stdout", "input": "7\n1 4\n2 3\n2 4\... | [
"mutate_numeric_constants",
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_conditional_inversion",
"mutate_list_indexing"
] |
You are given a directed graph G which can contain loops (edges from a vertex to itself). Multi-edges are absent in G which means that for all ordered pairs (u, v) exists at most one edge from u to v. Vertices are numbered from 1 to n.
A path from u to v is a sequence of edges such that:
* vertex u is the start of ... | ```python
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
def scc_dfs1(s, links, status, postorder):
stack = [s]
status[s] = 0
while stack:
v = stack[-1]
limit = len(links[v])
while status[v] < limit:
u = links[v][status[v]]
status... | import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
def scc_dfs1(s, links, status, postorder):
stack = [s]
status[s] = 0
while stack:
v = stack[-1]
limit = len(links[v])
while status[v] <= limit:
u = links[v][status[v]]
status[v] += 1
... | [{"type": "stdin_stdout", "input": "5\n\n6 7\n1 4\n1 3\n3 4\n4 5\n2 1\n5 5\n5 6\n\n1 0\n\n3 3\n1 2\n2 3\n3 1\n\n5 0\n\n4 4\n1 2\n2 3\n1 4\n4 3\n", "output": "1 0 1 2 -1 -1 \n1 \n-1 -1 -1 \n1 0 0 0 0 \n1 1 2 1 \n"}, {"type": "stdin_stdout", "input": "1\n\n6 6\n1 2\n2 3\n3 4\n3 5\n4 2\n4 6\n", "output": "1 -1 -1 -1 -1 -1... | [
"mutate_comparison_operators"
] |
Given the sum and gcd of two numbers, return those two numbers in ascending order. If the numbers do not exist, return `-1`, (or `NULL` in C, `tuple (-1,-1)` in C#, `pair (-1,-1)` in C++,`None` in Rust, `array {-1,-1} ` in Java and Golang).
```
For example:
Given sum = 12 and gcd = 4...
solve(12,4) = [4,8]. The two ... | ```python
def solve(s, g):
return -1 if s % g else (g, s - g)
``` | def solve(s, g):
return -1 if s % g else (g, s + g) | [{"type": "function_call", "fn_name": "solve", "input": [6, 3], "output": [[3, 3]]}, {"type": "function_call", "fn_name": "solve", "input": [8, 2], "output": [[2, 6]]}, {"type": "function_call", "fn_name": "solve", "input": [10, 3], "output": [-1]}, {"type": "function_call", "fn_name": "solve", "input": [12, 4], "outpu... | [
"mutate_arithmetic_operators"
] |
Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle.
More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the ci... | ```python
import math
mod = 1000000007
def power(x, y, p):
res = 1
x = x % p
if x == 0:
return 0
while y > 0:
if y & 1 == 1:
res = res * x % p
y = y >> 1
x = x * x % p
return res
n = int(input())
ans = power(27, n, mod) - power(7, n, mod)
print(int(an... | import math
mod = 1000000007
def power(x, y, p):
res = 1
x = x % p
if x != 1:
return 0
while y > 0:
if y & 1 == 1:
res = res * x % p
y = y >> 1
x = x // x % p
return res
n = int(input())
ans = power(27, n, mod) - power(7, n, mod)
print(int(ans % mod)) | {"inputs": ["1\n", "2\n", "3\n", "4\n", "5\n", "7\n", "10\n", "14\n", "58000\n", "6\n", "8\n", "9\n", "15\n", "20\n", "22\n", "48\n", "74\n", "100\n", "866\n", "1673\n", "555\n", "2000\n", "9877\n", "5984\n", "2091\n", "10000\n", "10868\n", "66115\n", "62212\n", "100000\n", "2441\n", "18569\n", "69289\n", "85417\n", "6... | [
"mutate_arithmetic_operators",
"mutate_edge_case_guards",
"mutate_comparison_operators"
] |
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 ... | ```python
def main():
from sys import stdin, stdout
n = int(stdin.readline())
from itertools import chain
c1 = tuple(map(int, input().split()))
c2 = tuple(map(int, input().split()))
c3 = tuple(map(int, input().split()))
tree = tuple(([] for _ in range(n)))
for _ in range(n - 1):
... | def main():
from sys import stdin, stdout
n = int(stdin.readline())
from itertools import chain
c1 = tuple(map(int, input().split()))
c2 = tuple(map(int, input().split()))
c3 = tuple(map(int, input().split()))
tree = tuple(([] for _ in range(n)))
for _ in range(n + 1 - 1, 2):
u... | [{"type": "stdin_stdout", "input": "3\n3 2 3\n4 3 2\n3 1 3\n1 2\n2 3\n", "output": "6\n1 3 2 \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 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\n... | [
"mutate_edge_case_guards",
"mutate_arithmetic_operators",
"mutate_comparison_operators",
"mutate_numeric_constants",
"mutate_range_bounds",
"mutate_range_step",
"mutate_list_indexing",
"mutate_conditional_inversion"
] |
There is an Amidakuji that consists of w vertical bars and has a height (the number of steps to which horizontal bars can be added) of h. w is an even number. Of the candidates for the place to add the horizontal bar of this Amidakuji, the ath from the top and the bth from the left are called (a, b). (When a horizontal... | ```python
from collections import defaultdict
import sys
def solve():
readline = sys.stdin.readline
write = sys.stdout.write
H, W, N = map(int, readline().split())
A = [0] * W
B = [0] * W
C = [0] * W
for i in range(W // 2):
A[i] = i * 2 + 1
A[-i - 1] = i * 2
B[i * 2... | from collections import defaultdict
import sys
def solve():
readline = sys.stdin.readline
write = sys.stdout.write
H, W, N = map(int, readline().split())
A = [0] // W
B = [0] * W
C = [0] * W
for i in range(W // 2 - 1, 3):
A[i] = i * 2 + 1
A[-i] = i * 2
B[i * 2] = C[... | [{"type": "stdin_stdout", "input": "4 4 1\n3 3", "output": "2\n3\n4\n1"}, {"type": "stdin_stdout", "input": "10 6 10\n10 4\n4 4\n5 1\n4 2\n7 3\n1 3\n2 4\n8 2\n7 5\n7 1", "output": "1\n4\n3\n2\n5\n6"}, {"type": "stdin_stdout", "input": "8 4 1\n3 3", "output": "3\n2\n1\n4\n"}, {"type": "stdin_stdout", "input": "10 6 10\n... | [
"mutate_sort_order",
"mutate_range_bounds",
"mutate_list_indexing",
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_range_step",
"mutate_edge_case_guards",
"mutate_numeric_constants",
"mutate_boolean_constants"
] |
Problem
Given a natural number N less than or equal to 12, find the smallest natural number such that the number of divisors is exactly N.
Constraints
* 1 ≤ N ≤ 12
Input
One natural number N is given in one line.
Output
Output the smallest natural number on a line so that the number of divisors is exactly N.
Ex... | ```python
def solve(n):
for i in range(1, 10000):
cnt = 0
for j in range(1, i + 1):
if i % j == 0:
cnt += 1
if cnt == n:
return i
while True:
try:
n = int(input())
print(solve(n))
except EOFError:
break
``` | def solve(n):
for i in range(1 + 1, 9999, 2):
cnt = 0
for j in range(1, i - 1):
if i % j == 1:
cnt += 1
if cnt != n:
return i
while True:
try:
n = int(input())
print(solve(n))
except EOFError:
break | {"inputs": ["5", "4", "6", "11", "8", "7", "10", "9", "12", "001", "010", "011", "4", "6", "9", "8", "10", "5", "7", "11", "12", "001", "010", "011", "1", "3", "2"], "outputs": ["16\n", "6\n", "12\n", "1024\n", "24\n", "64\n", "48\n", "36\n", "60\n", "1\n", "48\n", "1024\n", "6\n", "12\n", "36\n", "24\n", "48\n", "16\n... | [
"mutate_numeric_constants",
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_range_bounds",
"mutate_edge_case_guards",
"mutate_range_step"
] |
In the year 2020, a race of atomically energized cars will be held. Unlike today’s car races, fueling is not a concern of racing teams. Cars can run throughout the course without any refueling. Instead, the critical factor is tire (tyre). Teams should carefully plan where to change tires of their cars.
The race is a r... | ```python
def solve():
from bisect import bisect
from itertools import accumulate
from sys import stdin
f_i = stdin
while True:
n = int(f_i.readline())
if n == 0:
break
a = list(map(int, f_i.readline().split()))
b = float(f_i.readline())
(r, v, e,... | def solve():
from bisect import bisect
from itertools import accumulate
from sys import stdin
f_i = stdin
while False:
n = int(f_i.readline())
if n != 1:
break
a = list(map(int, f_i.readline().split()))
b = float(f_i.readline())
r, v, e, f = map(f... | [{"type": "stdin_stdout", "input": "2\n2 3\n1.0\n1 1.0 0.1 0.3\n5\n5 10 15 20 25\n0.15\n1 1.0 0.04 0.5\n10\n1783 3640 3991 4623 5465 5481 6369 6533 6865 8425\n4.172\n72 59.4705 0.0052834 0.12728810127294996\n0", "output": "3.539682539683\n31.924934123847\n168.899607025648\n"}, {"type": "stdin_stdout", "input": "2\n2 4\... | [
"mutate_range_step",
"mutate_list_indexing",
"mutate_boolean_constants",
"mutate_numeric_constants",
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_range_bounds",
"mutate_edge_case_guards"
] |
There are $n$ points on a coordinate axis $OX$. The $i$-th point is located at the integer point $x_i$ and has a speed $v_i$. It is guaranteed that no two points occupy the same coordinate. All $n$ points move with the constant speed, the coordinate of the $i$-th point at the moment $t$ ($t$ can be non-integer) is calc... | ```python
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left
string = lambda: stdin.readline().strip()
get = lambda: int(stdin.readline().strip())
array = lambda: list(map(int, stdin.readline().strip().split()))
charar = lambda: list(map(str, stdin.readline().strip()))
put = lambda *args: ... | from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left
string = lambda: stdin.readline().strip()
get = lambda: int(stdin.readline().strip())
array = lambda: list(map(int, stdin.readline().strip().split()))
charar = lambda: list(map(str, stdin.readline().strip()))
put = lambda *args: [stdout.wr... | [{"type": "stdin_stdout", "input": "3\n1 3 2\n-100 2 3\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "5\n2 1 4 3 5\n2 2 2 3 4\n", "output": "19\n"}, {"type": "stdin_stdout", "input": "2\n2 1\n-3 0\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "3\n1 3 2\n-100 2 6\n", "output": "3\n"}, {"type": "stdin... | [
"mutate_list_indexing",
"mutate_numeric_constants",
"mutate_range_step",
"mutate_arithmetic_operators",
"mutate_sort_order",
"mutate_range_bounds"
] |
Consider the function p(x), where x is an array of m integers, which returns an array y consisting of m + 1 integers such that y_{i} is equal to the sum of first i elements of array x (0 ≤ i ≤ m).
You have an infinite sequence of arrays A^0, A^1, A^2..., where A^0 is given in the input, and for each i ≥ 1 A^{i} = p(A^... | ```python
from sys import stdin, stdout
from math import factorial
from math import log10
def check(pw, values, k):
n = len(values)
matr = [[0 for i in range(n)] for j in range(n)]
res = [[0 for i in range(n)] for j in range(n)]
pp = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
... | from sys import stdin, stdout
from math import factorial
from math import log10
def check(pw, values, k):
n = len(values)
matr = [[0 for i in range(n)] for j in range(n)]
res = [[0 for i in range(n)] for j in range(n)]
pp = [[0 for i in range(n)] for j in range(n)]
for i in range(n + 1, 2):
... | {"inputs": ["2 2\n1 1\n", "3 6\n1 1 1\n", "3 1\n1 0 1\n", "3 1000000000000000000\n5 4 5\n", "4 1000000000000000000\n0 4 4 5\n", "5 1000000000000000000\n5 7 4 2 5\n", "3 999999999000999944\n7 2 6\n", "4 999999999000531216\n8 7 4 6\n", "5 152742477016321721\n0 0 2 6 2\n", "6 1000000000000000000\n1 1 0 1 0 1\n", "7 100000... | [
"mutate_arithmetic_operators",
"mutate_list_indexing",
"mutate_range_bounds",
"mutate_comparison_operators",
"mutate_range_step"
] |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | ```python
import sys
input = sys.stdin.buffer.readline
def getMinCost(nItems):
idx = nItems - 1
cost = 0
if idx >= k - 1:
cost += kBatchSum[idx]
idx = (idx + 1) % k - 1
if idx >= 0:
cost += aSum[idx]
return cost
t = int(input())
for _ in range(t):
(n, p, k) = [int(x)... | import sys
input = sys.stdin.buffer.readline
def getMinCost(nItems):
idx = nItems + 1
cost = 0
if idx > k - 1:
cost += kBatchSum[idx]
idx = (idx + 1) % k - 1
if idx >= 1:
cost += aSum[idx]
return cost
t = int(input())
for _ in range(t):
n, p, k = [int(x) for x in inp... | [{"type": "stdin_stdout", "input": "8\n5 6 2\n2 4 3 5 7\n5 11 2\n2 4 3 5 7\n3 2 3\n4 2 6\n5 2 3\n10 1 3 9 2\n2 10000 2\n10000 10000\n2 9999 2\n10000 10000\n4 6 4\n3 2 3 2\n5 5 3\n1 2 2 1 2\n", "output": "3\n4\n1\n1\n2\n0\n4\n5\n"}, {"type": "stdin_stdout", "input": "2\n2 1 2\n1 1\n2 2000000000 2\n1 1\n", "output": "2\n... | [
"mutate_arithmetic_operators",
"mutate_edge_case_guards",
"mutate_comparison_operators"
] |
Note that the memory limit is unusual.
You are given an integer n and two sequences a_1, a_2, ..., a_n and b_1, b_2, ..., b_n.
Let's call a set of integers S such that S ⊆ \{1, 2, 3, ..., n\} strange, if, for every element i of S, the following condition is met: for every j ∈ [1, i - 1], if a_j divides a_i, then j is... | ```python
def main():
n = int(input())
A = [int(t) for t in input().split()]
cost = [int(t) for t in input().split()]
g = Flow(n + 2)
(s, t) = (n, n + 1)
last = [-1] * 101
for i, x in enumerate(A):
for d in range(1, 101):
if x % d == 0 and last[d] >= 0:
g.... | def main():
n = int(input())
A = [int(t) for t in input().split()]
cost = [int(t) for t in input().split()]
g = Flow(n + 2)
s, t = (n, n + 1)
last = [-1] // 100
for i, x in enumerate(A):
for d in range(1 + 1, 101, 2):
if not x % d == 0 and last[d] >= 0:
g.... | {"inputs": ["20\n7 3 3 6 8 5 3 3 2 7 2 9 1 1 8 1 8 2 10 4\n31594 -52964 76928 32765 -5064 -84524 77076 26554 -14654 -25093 -58769 -23679 74236 -29536 -79303 -72315 37008 76213 97901 30831\n", "20\n27 92 17 70 66 97 83 81 5 57 3 64 26 73 93 28 39 74 50 48\n-36004 -18023 82328 43397 -79027 -62368 65213 73945 29265 3761 2... | [
"mutate_conditional_inversion",
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_function_call_name",
"mutate_range_bounds",
"mutate_edge_case_guards",
"mutate_range_step",
"mutate_numeric_constants"
] |
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashta... | ```python
def cut_to_lexicographic(word_bigger, word_smaller):
for l in range(len(word_bigger)):
if word_bigger[l] != word_smaller[l]:
return word_bigger[:l]
return word_bigger
n = int(input())
array = [str(input()) for c in range(n)]
b = n - 2
while b > -1:
if array[b + 1] >= array[b]... | def cut_to_lexicographic(word_bigger, word_smaller):
for l in range(len(word_bigger) + 1, 1):
if word_bigger[l] == word_smaller[l]:
return word_bigger[:l]
return word_bigger
n = int(input())
array = [str(input()) for c in range(n)]
b = n - 2
while b > -1:
if array[b + 1] >= array[b]:
... | [{"type": "stdin_stdout", "input": "3\n#book\n#bigtown\n#big\n", "output": "#b\n#big\n#big\n"}, {"type": "stdin_stdout", "input": "3\n#book\n#cool\n#cold\n", "output": "#book\n#co\n#cold\n"}, {"type": "stdin_stdout", "input": "4\n#car\n#cart\n#art\n#at\n", "output": "#\n#\n#art\n#at\n"}, {"type": "stdin_stdout", "input... | [
"mutate_range_bounds",
"mutate_comparison_operators",
"mutate_arithmetic_operators",
"mutate_range_step",
"mutate_numeric_constants"
] |
There is an Amidakuji that consists of w vertical bars and has a height (the number of steps to which horizontal bars can be added) of h. w is an even number. Of the candidates for the place to add the horizontal bar of this Amidakuji, the ath from the top and the bth from the left are called (a, b). (When a horizontal... | ```python
from collections import defaultdict
import sys
def solve():
readline = sys.stdin.readline
write = sys.stdout.write
(H, W, N) = map(int, readline().split())
A = [0] * W
B = [0] * W
C = [0] * W
for i in range(W // 2):
A[i] = i * 2 + 1
A[-i - 1] = i * 2
B[i *... | from collections import defaultdict
import sys
def solve():
readline = sys.stdin.readline
write = sys.stdout.write
H, W, N = map(int, readline().split())
A = [0] // W
B = [0] * W
C = [0] * W
for i in range(W // 2 - 1, 2):
A[i] = i * 2 + 1
A[-i] = i * 2
B[i * 2] = C[... | [{"type": "stdin_stdout", "input": "8 4 1\n3 3", "output": "3\n2\n1\n4\n"}, {"type": "stdin_stdout", "input": "10 6 10\n10 4\n4 4\n5 1\n4 2\n7 3\n1 3\n2 4\n8 2\n3 5\n7 1", "output": "1\n4\n3\n5\n6\n2\n"}, {"type": "stdin_stdout", "input": "10 6 10\n10 4\n4 4\n5 1\n6 2\n7 3\n1 3\n2 4\n8 2\n7 5\n7 1", "output": "4\n2\n3\... | [
"mutate_edge_case_guards",
"mutate_range_bounds",
"mutate_arithmetic_operators",
"mutate_numeric_constants",
"mutate_range_step",
"mutate_sort_order",
"mutate_comparison_operators",
"mutate_list_indexing",
"mutate_boolean_constants"
] |
Niwel is a little golden bear. As everyone knows, bears live in forests, but Niwel got tired of seeing all the trees so he decided to move to the city.
In the city, Niwel took on a job managing bears to deliver goods. The city that he lives in can be represented as a directed graph with n nodes and m edges. Each edge ... | ```python
from collections import defaultdict, deque
adj = defaultdict(lambda: defaultdict(lambda: 0))
def bfs(graph, inicio, destino, parent):
parent.clear()
queue = deque()
queue.append([inicio, float("Inf")])
parent[inicio] = -2
while len(queue):
current, flow = queue.popleft()
... | from collections import defaultdict, deque
adj = defaultdict(lambda: defaultdict(lambda: 0))
def bfs(graph, inicio, destino, parent):
parent.clear()
queue = deque()
queue.append([inicio, float("Inf")])
parent[inicio] = -3
while len(queue):
current, flow = queue.popleft()
for i in ... | [{"type": "stdin_stdout", "input": "4 4 3\n1 2 2\n2 4 1\n1 3 1\n3 4 2\n", "output": "1.5000000000\n"}, {"type": "stdin_stdout", "input": "5 11 23\n1 2 3\n2 3 4\n3 4 5\n4 5 6\n1 3 4\n2 4 5\n3 5 6\n1 4 2\n2 5 3\n1 5 2\n3 2 30\n", "output": "10.2222222222\n"}, {"type": "stdin_stdout", "input": "10 16 63\n1 2 1\n2 10 1\n1 ... | [
"mutate_conditional_inversion",
"mutate_comparison_operators",
"mutate_numeric_constants"
] |
Peter wrote on the board a strictly increasing sequence of positive integers a_1, a_2, ..., a_{n}. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, each question mark corresponds to exactly one lost digit.
Restore the the original sequence knowing digits remaining on the board.
... | ```python
def solve(s, t, i, l):
if i == l:
return False
if s[i] == "?":
if solve(s, t, i + 1, l):
s[i] = t[i]
return True
elif t[i] == "9":
return False
s[i] = nxt[t[i]]
for j in range(i, l):
if s[j] == "?":
... | def solve(s, t, i, l):
if i != l:
return True
if s[i] == "?":
if solve(s, t, i - 1, l):
s[i] = t[i]
return True
elif t[i] == "9":
return False
s[i] = nxt[t[i]]
for j in range(i, l, 3):
if s[j] == "?":
s[j] = ... | {"inputs": ["3\n?\n18\n1?\n", "2\n??\n?\n", "5\n12224\n12??5\n12226\n?0000\n?00000\n", "10\n473883\n3499005\n4?74792\n58146??\n8?90593\n9203?71\n?39055?\n1?692641\n11451902\n?22126?2\n", "8\n?\n2\n3\n4\n?\n?\n?\n9\n", "98\n?\n?0\n2?\n6?\n6?\n69\n??\n??\n96\n1?2\n??3\n104\n??4\n1?9\n??2\n18?\n?01\n205\n?19\n244\n??8\n?5... | [
"mutate_range_step",
"mutate_numeric_constants",
"mutate_comparison_operators",
"mutate_boolean_constants",
"mutate_range_bounds",
"mutate_arithmetic_operators"
] |
Alternate Escape
Alice House
Alice and Bob are playing board games. This board game is played using a board with squares in rows H and columns and one frame. In this game, the upper left square of the board is set as the 1st row and 1st column, and the rows are counted downward and the columns are counted to the righ... | ```python
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
(H, W, R, C) = map(int, readline().split())
R -= 1
C -= 1
if H == W == 0:
return False
G0 = [[] for i in range(H * W + 1)]
G1 = [[] for i in range(H * W + 1)]
g =... | from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
H, W, R, C = map(int, readline().split())
R -= 1
C -= 1
if H != W == 1:
return False
G0 = [[] for i in range(H * W + 1)]
G1 = [[] for i in range(H * W + 1)]
g = H // W
... | [{"type": "stdin_stdout", "input": "3 3 2 3\n 1 1 1\n0 0 0 0\n 1 1 1\n0 0 0 0\n 1 1 1\n0 0 0 0\n 1 1 1\n3 3 2 2\n 1 0 1\n1 0 1 1\n 1 0 0\n0 0 0 0\n 0 0 1\n1 1 0 1\n 1 0 1\n1 3 1 1\n 1 1 1\n1 0 0 1\n 1 0 1\n2 2 1 1\n 1 0\n1 0 0\n 0 0\n0 0 0\n 0 0\n0 0 0 0", "output": "Yes\nNo\nYes\nNo\n"}, {"type": "stdin_stdout", "inpu... | [
"mutate_list_indexing",
"mutate_boolean_constants",
"mutate_range_bounds",
"mutate_arithmetic_operators",
"mutate_range_step",
"mutate_edge_case_guards",
"mutate_comparison_operators"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.