description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The $k$-th layer of the triangle contains $k$ points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers $(r, c)$ ($1 \le c \le r... | for _ in range(int(input())):
input()
r = list(map(int, input().split()))
c = list(map(int, input().split()))
a = sorted((x, x + 1 - y) for x, y in zip(r, c))
if a[0] != (1, 1):
a = [(1, 1)] + a
ans = 0
for (x, y), (nx, ny) in zip(a, a[1:]):
assert x < nx and y <= ny and ny -... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER NUMBER NUMBER A... |
Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The $k$-th layer of the triangle contains $k$ points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers $(r, c)$ ($1 \le c \le r... | from sys import stdin, stdout
def triangular_paths(n, r_a, c_a):
rc_a = [[1, 1]]
for i in range(n):
rc_a.append([r_a[i], c_a[i]])
rc_a.sort(key=lambda x: x[0])
res = 0
for i in range(1, n + 1):
r1 = rc_a[i - 1][0]
c1 = rc_a[i - 1][1]
r2 = rc_a[i][0]
c2 = rc_... | FUNC_DEF ASSIGN VAR LIST LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VA... |
Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The $k$-th layer of the triangle contains $k$ points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers $(r, c)$ ($1 \le c \le r... | import sys
input = sys.stdin.readline
def cost(a, b):
rdiff = b[0] - a[0]
cdiff = b[1] - a[1]
if (a[0] + a[1]) % 2 == 0:
if rdiff == cdiff:
return rdiff
if rdiff == cdiff + 1:
return 0
if rdiff % 2 == 0:
return rdiff // 2 - (cdiff + 1) // 2
... | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER NUMBER IF VAR VAR RETURN VAR IF VAR BIN_OP VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF ... |
Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The $k$-th layer of the triangle contains $k$ points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers $(r, c)$ ($1 \le c \le r... | t = int(input())
for i in range(t):
n = int(input())
r = list(map(int, input().split()))
c = list(map(int, input().split()))
z = []
z.append((1, 1))
for i in range(n):
z.append((r[i], c[i]))
z.sort()
node = z
res = 0
for i in range(n):
r, c = node[i]
nr, n... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FU... |
Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The $k$-th layer of the triangle contains $k$ points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers $(r, c)$ ($1 \le c \le r... | for case in range(int(input())):
n = int(input())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
li = []
for i in range(n):
x = X[i]
y = Y[i]
li.append((abs(x - y + 1), min(x, y)))
li.sort()
prvblk = 1
prvplc = 1
cost = 0
for blk, ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VA... |
Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The $k$-th layer of the triangle contains $k$ points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers $(r, c)$ ($1 \le c \le r... | import sys
for _ in range(int(input())):
n = int(input())
f = lambda: map(int, sys.stdin.readline().split())
node = [(1, 1)] + sorted(zip(f(), f()))
res = 0
for i in range(n):
r, c = node[i]
nr, nc = node[i + 1]
res += (
(nr - nc) // 2
- (r - c) // 2
... | IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR ... |
Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The $k$-th layer of the triangle contains $k$ points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers $(r, c)$ ($1 \le c \le r... | import sys
input = sys.stdin.readline
def main():
t = int(input())
for _ in range(t):
n = int(input())
r = list(map(int, input().split()))
c = list(map(int, input().split()))
points = [(r[i], c[i]) for i in range(n)]
points.sort(key=lambda x: x[0])
if points[0]... | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EX... |
Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The $k$-th layer of the triangle contains $k$ points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers $(r, c)$ ($1 \le c \le r... | import sys
def get_ints():
return list(map(int, sys.stdin.readline().strip().split()))
def solve(N, R, C):
ans = 0
sorted_idx = sorted(range(N), key=lambda i: (R[i], C[i]))
r, c = 1, 1
for i in sorted_idx:
diff = r - c
next_r, next_c = R[i], C[i]
next_diff = next_r - next... | IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR IF... |
Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The $k$-th layer of the triangle contains $k$ points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers $(r, c)$ ($1 \le c \le r... | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
r = list(map(int, input().split()))
c = list(map(int, input().split()))
ps = [(r[i], c[i]) for i in range(n)]
ps.sort()
y = 1
x = 1
res = 0
for i in range(n):
u, v = ps[i]
if y == u ... | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN ... |
Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The $k$-th layer of the triangle contains $k$ points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers $(r, c)$ ($1 \le c \le r... | def get_input():
l = [int(e) for e in input().split()]
return l
def band(p):
d = p[0] - p[1]
return d // 2
def cost_path(p1, p2):
b1 = band(p2)
b2 = band(p1)
if b1 > b2:
return b1 - b2
elif p1[0] - p1[1] == p2[0] - p2[1]:
if (p1[0] - p1[1]) % 2:
return 0
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN BIN_OP VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF BIN_O... |
Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The $k$-th layer of the triangle contains $k$ points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers $(r, c)$ ($1 \le c \le r... | def seal(a, b):
return (a + b - 1) // b
for _ in range(int(input())):
n = int(input())
r = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
arr = [[r[i], c[i]] for i in range(n)]
arr.sort()
ans = 0
if arr[0] != [1, 1]:
arr.insert(0, [1, 1])
n = len(ar... | FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FU... |
Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The $k$-th layer of the triangle contains $k$ points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers $(r, c)$ ($1 \le c \le r... | for _ in range(int(input())):
n = int(input())
r = list(map(int, input().split()))
c = list(map(int, input().split()))
arr = sorted(list(zip(r, c)))
correction = 1, 1
ans = 0
check = True
for point in arr:
r, c = point[0] - correction[0] + 1, point[1] - correction[1] + 1
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR ... |
An array is called *interesting* if no subarray of length greater than 2 is non-increasing or non-decreasing.
Chef has an array A of length N. He wants to make the array interesting by rearranging the elements in any order.
If there exist multiple such arrays, output any one.
If no such array exists, print -1 inst... | def check(ans, n):
inc = int(ans[0] < ans[1])
i = 1
while i < n:
if ans[i] == ans[i - 1]:
return False
if int(ans[i] > ans[i - 1]) == inc:
inc = int(ans[i] < ans[i - 1])
else:
return False
i += 1
return True
for _ in range(int(input()... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC... |
An array is called *interesting* if no subarray of length greater than 2 is non-increasing or non-decreasing.
Chef has an array A of length N. He wants to make the array interesting by rearranging the elements in any order.
If there exist multiple such arrays, output any one.
If no such array exists, print -1 inst... | def check(ar):
n = len(ar)
for i in range(n - 2):
if ar[i] >= ar[i + 1] >= ar[i + 2]:
return 0
if ar[i] <= ar[i + 1] <= ar[i + 2]:
return 0
return 1
for _ in range(int(input())):
n = int(input())
a = sorted(list(map(int, input().split())))
b, c = [0] * n... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR A... |
An array is called *interesting* if no subarray of length greater than 2 is non-increasing or non-decreasing.
Chef has an array A of length N. He wants to make the array interesting by rearranging the elements in any order.
If there exist multiple such arrays, output any one.
If no such array exists, print -1 inst... | def N():
return int(input())
def A():
return [int(x) for x in input().split()]
def S():
return input()
def decimalToBinary(n):
return bin(n).replace("0b", "")
def factors(n: int) -> list:
s = set()
step = 2 if n % 2 else 1
for i in range(1, n**0.5 + 1, step):
if n % i == 0:
... | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR STRING STRING FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VA... |
An array is called *interesting* if no subarray of length greater than 2 is non-increasing or non-decreasing.
Chef has an array A of length N. He wants to make the array interesting by rearranging the elements in any order.
If there exist multiple such arrays, output any one.
If no such array exists, print -1 inst... | for t in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = []
for i in range(0, n // 2):
b += [a[n // 2 + i]]
b += [a[i]]
if n % 2 != 0:
b += [a[-1]]
f = 0
for i in range(0, len(b) - 1):
if b[i] == b[i + 1]:
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR LIST VAR BIN_OP BIN_OP VAR NUMBER VAR VAR LIST VAR VAR IF BIN_OP VAR NUMBER NU... |
An array is called *interesting* if no subarray of length greater than 2 is non-increasing or non-decreasing.
Chef has an array A of length N. He wants to make the array interesting by rearranging the elements in any order.
If there exist multiple such arrays, output any one.
If no such array exists, print -1 inst... | def check(ar):
n = len(ar)
for i in range(n - 2):
if ar[i] >= ar[i + 1] >= ar[i + 2]:
return 0
if ar[i] <= ar[i + 1] <= ar[i + 2]:
return 0
return 1
def interesting_array(n, a):
a.sort()
b, c = [0] * n, [0] * n
b[::2], b[1::2] = a[: (n + 1) // 2], a[(n +... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR A... |
An array is called *interesting* if no subarray of length greater than 2 is non-increasing or non-decreasing.
Chef has an array A of length N. He wants to make the array interesting by rearranging the elements in any order.
If there exist multiple such arrays, output any one.
If no such array exists, print -1 inst... | t = int(input())
for _ in range(t):
n = int(input())
L = list(map(int, input().split()))
d = {}
for i in range(n):
if L[i] in d:
d[L[i]] += 1
else:
d[L[i]] = 1
M = []
for i in d:
M.append((i, d[i]))
M.sort()
if n == 1 or n == 2:
pri... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR ... |
An array is called *interesting* if no subarray of length greater than 2 is non-increasing or non-decreasing.
Chef has an array A of length N. He wants to make the array interesting by rearranging the elements in any order.
If there exist multiple such arrays, output any one.
If no such array exists, print -1 inst... | from sys import stdin
input = stdin.readline
def interesting(A):
for i in range(N - 2):
if A[i] <= A[i + 1] <= A[i + 2] or A[i] >= A[i + 1] >= A[i + 2]:
return False
return True
def construct(A1, A2):
B = []
for i in range(max(len(A1), len(A2))):
if i < len(A1):
... | ASSIGN VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR... |
An array is called *interesting* if no subarray of length greater than 2 is non-increasing or non-decreasing.
Chef has an array A of length N. He wants to make the array interesting by rearranging the elements in any order.
If there exist multiple such arrays, output any one.
If no such array exists, print -1 inst... | def maximum_subarray_with_same_value(arr):
n = len(arr)
max_len = 0
i = 0
while i < n:
j = i + 1
while j < n and arr[j] == arr[i]:
j += 1
max_len = max(max_len, j - i)
i = j
return max_len
t = int(input())
for _ in range(t):
(n,) = map(int, input().s... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VA... |
An array is called *interesting* if no subarray of length greater than 2 is non-increasing or non-decreasing.
Chef has an array A of length N. He wants to make the array interesting by rearranging the elements in any order.
If there exist multiple such arrays, output any one.
If no such array exists, print -1 inst... | def impossible(arr):
for i in range(len(arr) - 2):
if len(set(arr[i : i + 3])) == 1:
return True
return False
for i in range(int(input())):
n = int(input())
arr = list(map(int, input().split(" ")))
arr.sort()
a1 = arr[: len(arr) // 2]
a2 = arr[len(arr) // 2 :]
sol =... | FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EX... |
An array is called *interesting* if no subarray of length greater than 2 is non-increasing or non-decreasing.
Chef has an array A of length N. He wants to make the array interesting by rearranging the elements in any order.
If there exist multiple such arrays, output any one.
If no such array exists, print -1 inst... | t = int(input())
for tt in range(t):
n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
ans1 = [0] * n
a.sort()
i = 0
j = n - 1
for r in range(1, n, 2):
ans[r] = a[i]
ans1[r] = a[j]
j -= 1
i += 1
for r in range(0, n, 2):
ans[r] ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CA... |
An array is called *interesting* if no subarray of length greater than 2 is non-increasing or non-decreasing.
Chef has an array A of length N. He wants to make the array interesting by rearranging the elements in any order.
If there exist multiple such arrays, output any one.
If no such array exists, print -1 inst... | def fun(l):
x = len(l) // 2
pos = len(l) // 2
while x > 0:
l.insert(pos, l.pop(0))
x -= 1
pos += 1
for i in range(n - 2):
if (
l[i] >= l[i + 1]
and l[i + 1] >= l[i + 2]
or l[i] <= l[i + 1]
and l[i + 1] <= l[i + 2]
):... | FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NU... |
An array is called *interesting* if no subarray of length greater than 2 is non-increasing or non-decreasing.
Chef has an array A of length N. He wants to make the array interesting by rearranging the elements in any order.
If there exist multiple such arrays, output any one.
If no such array exists, print -1 inst... | def solve(a, d, f):
a1 = a[0:d]
a2 = a[d:]
b = []
d = min(len(a1), len(a2))
if f == 0:
for i in range(d):
b.append(a2[i])
b.append(a1[i])
b.append(a2[-1])
else:
for i in range(d):
b.append(a1[i])
b.append(a2[i])
b.ap... | FUNC_DEF ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CA... |
An array is called *interesting* if no subarray of length greater than 2 is non-increasing or non-decreasing.
Chef has an array A of length N. He wants to make the array interesting by rearranging the elements in any order.
If there exist multiple such arrays, output any one.
If no such array exists, print -1 inst... | def check(lst):
for i in range(1, len(lst) - 1):
if lst[i + 1] >= lst[i] >= lst[i - 1]:
return False
if lst[i + 1] <= lst[i] <= lst[i - 1]:
return False
return True
T = int(input())
for _ in range(T):
N = int(input())
arr = list(map(int, input().split()))
ar... | FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CAL... |
An array is called *interesting* if no subarray of length greater than 2 is non-increasing or non-decreasing.
Chef has an array A of length N. He wants to make the array interesting by rearranging the elements in any order.
If there exist multiple such arrays, output any one.
If no such array exists, print -1 inst... | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
a.sort()
greater = a[n // 2 :]
lesser = a[: n // 2]
valid = []
for i in range(n // 2):
valid.append(greater[i])
valid.append(lesser[i])
if n % 2 == 1:
valid.append(greater[-1]... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUN... |
An array is called *interesting* if no subarray of length greater than 2 is non-increasing or non-decreasing.
Chef has an array A of length N. He wants to make the array interesting by rearranging the elements in any order.
If there exist multiple such arrays, output any one.
If no such array exists, print -1 inst... | for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
arr2 = arr.copy()
arr.sort(reverse=True)
mid = n // 2
arr[1::2], arr[0::2] = arr[:mid], arr[mid:]
flag = False
for i in range(n - 2):
if arr[i] == arr[i + 1] or arr[i + 1] == arr[i + 2]:
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR... |
An array is called *interesting* if no subarray of length greater than 2 is non-increasing or non-decreasing.
Chef has an array A of length N. He wants to make the array interesting by rearranging the elements in any order.
If there exist multiple such arrays, output any one.
If no such array exists, print -1 inst... | for _ in range(int(input())):
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
if n == 1:
print(a[0])
elif n == 2:
print(a[0], a[1])
else:
new = [-1] * n
ind = 1
while ind < n:
new[ind] = a.pop()
ind += 2
ind ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHIL... |
An array is called *interesting* if no subarray of length greater than 2 is non-increasing or non-decreasing.
Chef has an array A of length N. He wants to make the array interesting by rearranging the elements in any order.
If there exist multiple such arrays, output any one.
If no such array exists, print -1 inst... | t = int(input())
for t0 in range(t):
n = int(input())
a_i = list(map(int, input().split()))
max_valid_count = int(n / 2) + 1
num_count = {}
for num in a_i:
if not num_count.__contains__(num):
num_count[num] = 0
num_count[num] += 1
max_occurred_item = max(num_count.ite... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR DICT FOR VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN... |
An array is called *interesting* if no subarray of length greater than 2 is non-increasing or non-decreasing.
Chef has an array A of length N. He wants to make the array interesting by rearranging the elements in any order.
If there exist multiple such arrays, output any one.
If no such array exists, print -1 inst... | def interesting(a):
n = len(a)
return n < 3 or all(
a[i] < min(a[i - 1], a[i + 1]) or a[i] > max(a[i - 1], a[i + 1])
for i in range(1, n - 1)
)
for tcase in range(int(input())):
n = int(input())
a = sorted(map(int, input().split()))
b, c = [], []
h = n // 2
d = h + n % ... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ... |
An array is called *interesting* if no subarray of length greater than 2 is non-increasing or non-decreasing.
Chef has an array A of length N. He wants to make the array interesting by rearranging the elements in any order.
If there exist multiple such arrays, output any one.
If no such array exists, print -1 inst... | def solve(n, arr):
if n <= 2:
return arr
arr_b = arr[:]
arr_b.sort()
arr_c = arr_b[: len(arr_b) // 2]
arr_d = arr_b[len(arr_b) // 2 :]
arr_e = []
i = 0
j = 0
while i < len(arr_c) and j < len(arr_d):
arr_e.append(arr_d[j])
arr_e.append(arr_c[i])
i += 1
... | FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VA... |
An array is called *interesting* if no subarray of length greater than 2 is non-increasing or non-decreasing.
Chef has an array A of length N. He wants to make the array interesting by rearranging the elements in any order.
If there exist multiple such arrays, output any one.
If no such array exists, print -1 inst... | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [0] * n
c = [0] * n
for i in range(0, n, 2):
b[i] = a[i // 2]
for i in range(1, n, 2):
b[i] = a[(n + i) // 2]
for i in range(0, n, 2):
c[i] = a[(n + i) // 2]
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN... |
A positive integer is magical if it is divisible by either A or B.
Return the N-th magical number. Since the answer may be very large, return it modulo 10^9 + 7.
Example 1:
Input: N = 1, A = 2, B = 3
Output: 2
Example 2:
Input: N = 4, A = 2, B = 3
Output: 6
Example 3:
Input: N = 5, A = 2, B = 4
Output: 10
E... | class Solution:
def NOD(self, a, b):
if a == b:
return a
c = max(a, b)
d = a + b - c
c = c % d
c = c if c > 0 else d
return self.NOD(c, d)
def nthMagicalNumber(self, N: int, A: int, B: int) -> int:
const = 10**9 + 7
nod = self.NOD(A, ... | CLASS_DEF FUNC_DEF IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER VAR VAR RETURN FUNC_CALL VAR VAR VAR FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR... |
A positive integer is magical if it is divisible by either A or B.
Return the N-th magical number. Since the answer may be very large, return it modulo 10^9 + 7.
Example 1:
Input: N = 1, A = 2, B = 3
Output: 2
Example 2:
Input: N = 4, A = 2, B = 3
Output: 6
Example 3:
Input: N = 5, A = 2, B = 4
Output: 10
E... | class Solution:
def nthMagicalNumber(self, N: int, A: int, B: int) -> int:
lcm = A * B // math.gcd(A, B)
cnt = lcm // A + lcm // B - 1
i = N // cnt
j = N % cnt
def count(x, lcm):
return x // A + x // B - x // lcm
l, r = 0, A * B
while l < r:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR VAR WHILE VA... |
A positive integer is magical if it is divisible by either A or B.
Return the N-th magical number. Since the answer may be very large, return it modulo 10^9 + 7.
Example 1:
Input: N = 1, A = 2, B = 3
Output: 2
Example 2:
Input: N = 4, A = 2, B = 3
Output: 6
Example 3:
Input: N = 5, A = 2, B = 4
Output: 10
E... | class Solution:
def nthMagicalNumber(self, N: int, A: int, B: int) -> int:
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd(a, b)
val = lcm(A, B)
magicals = set()
for i in range(1, val ... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CA... |
A positive integer is magical if it is divisible by either A or B.
Return the N-th magical number. Since the answer may be very large, return it modulo 10^9 + 7.
Example 1:
Input: N = 1, A = 2, B = 3
Output: 2
Example 2:
Input: N = 4, A = 2, B = 3
Output: 6
Example 3:
Input: N = 5, A = 2, B = 4
Output: 10
E... | class Solution:
def nthMagicalNumber(self, N: int, A: int, B: int) -> int:
def gcd(x, y):
if y == 0:
return x
return gcd(y, x % y)
MOD = 10**9 + 7
L = A // gcd(A, B) * B
M = L // A + L // B - 1
q, r = divmod(N, M)
if r == 0:
... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER R... |
A positive integer is magical if it is divisible by either A or B.
Return the N-th magical number. Since the answer may be very large, return it modulo 10^9 + 7.
Example 1:
Input: N = 1, A = 2, B = 3
Output: 2
Example 2:
Input: N = 4, A = 2, B = 3
Output: 6
Example 3:
Input: N = 5, A = 2, B = 4
Output: 10
E... | class Solution:
def nthMagicalNumber(self, N: int, A: int, B: int) -> int:
def min_common_divisor(a, b):
less = min(a, b)
more = max(a, b)
for i in range(1, less + 1):
if more * i % less == 0:
return more * i
return a * b
... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER RETURN BIN_OP VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BI... |
A positive integer is magical if it is divisible by either A or B.
Return the N-th magical number. Since the answer may be very large, return it modulo 10^9 + 7.
Example 1:
Input: N = 1, A = 2, B = 3
Output: 2
Example 2:
Input: N = 4, A = 2, B = 3
Output: 6
Example 3:
Input: N = 5, A = 2, B = 4
Output: 10
E... | class Solution:
modulo = 10**9 + 7
def getMaxCommonFactor(self, A, B):
while B > 0:
A = A % B
A, B = B, A
return A
def nthMagicalNumber(self, N: int, A: int, B: int) -> int:
mcf = self.getMaxCommonFactor(A, B)
period = A * B // mcf % self.modulo
... | CLASS_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR... |
A positive integer is magical if it is divisible by either A or B.
Return the N-th magical number. Since the answer may be very large, return it modulo 10^9 + 7.
Example 1:
Input: N = 1, A = 2, B = 3
Output: 2
Example 2:
Input: N = 4, A = 2, B = 3
Output: 6
Example 3:
Input: N = 5, A = 2, B = 4
Output: 10
E... | class Solution:
def nthMagicalNumber(self, N: int, A: int, B: int) -> int:
x, y = min(A, B), max(A, B)
print(x, y)
hcf = x
while (y % hcf != 0 or x % hcf != 0) and hcf > 1:
hcf -= 1
print(hcf)
gcd = int(x * y / hcf)
print(gcd)
start, end =... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ... |
A positive integer is magical if it is divisible by either A or B.
Return the N-th magical number. Since the answer may be very large, return it modulo 10^9 + 7.
Example 1:
Input: N = 1, A = 2, B = 3
Output: 2
Example 2:
Input: N = 4, A = 2, B = 3
Output: 6
Example 3:
Input: N = 5, A = 2, B = 4
Output: 10
E... | def nww(a, b):
bigger = max(a, b)
smaller = min(a, b)
result = bigger
i = 2
while result % smaller != 0:
result = bigger * i
i += 1
return result
class Solution:
def nthMagicalNumber(self, N: int, A: int, B: int) -> int:
nw = nww(A, B)
la = list([(A * x) fo... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP ... |
A positive integer is magical if it is divisible by either A or B.
Return the N-th magical number. Since the answer may be very large, return it modulo 10^9 + 7.
Example 1:
Input: N = 1, A = 2, B = 3
Output: 2
Example 2:
Input: N = 4, A = 2, B = 3
Output: 6
Example 3:
Input: N = 5, A = 2, B = 4
Output: 10
E... | class Solution:
def nthMagicalNumber(self, N: int, A: int, B: int) -> int:
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd(a, b)
val = lcm(A, B)
def number_magic_below(x):
return ... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FU... |
A positive integer is magical if it is divisible by either A or B.
Return the N-th magical number. Since the answer may be very large, return it modulo 10^9 + 7.
Example 1:
Input: N = 1, A = 2, B = 3
Output: 2
Example 2:
Input: N = 4, A = 2, B = 3
Output: 6
Example 3:
Input: N = 5, A = 2, B = 4
Output: 10
E... | class Solution:
def gcd(self, x, y):
while y > 0:
x, y = y, x % y
return x
def lcm(self, x, y):
return x * y // self.gcd(x, y)
def nthMagicalNumber(self, N: int, A: int, B: int) -> int:
AB = self.lcm(A, B)
def check(mid):
ans = mid // A + m... | CLASS_DEF FUNC_DEF WHILE VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR RETURN VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VA... |
A positive integer is magical if it is divisible by either A or B.
Return the N-th magical number. Since the answer may be very large, return it modulo 10^9 + 7.
Example 1:
Input: N = 1, A = 2, B = 3
Output: 2
Example 2:
Input: N = 4, A = 2, B = 3
Output: 6
Example 3:
Input: N = 5, A = 2, B = 4
Output: 10
E... | def LCM(x, y):
if x == y:
return x
bigger = max([x, y])
smaller = min([x, y])
res = bigger
while res % smaller != 0:
res += bigger
return res
class Solution:
def nthMagicalNumber(self, N: int, A: int, B: int) -> int:
lcm = LCM(A, B)
div = [0, lcm]
f... | FUNC_DEF IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR RETURN VAR CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST NUMBER VAR FOR VAR LIST VAR VAR ASSIGN VAR VAR WHILE VAR VAR EXPR FUNC_... |
A positive integer is magical if it is divisible by either A or B.
Return the N-th magical number. Since the answer may be very large, return it modulo 10^9 + 7.
Example 1:
Input: N = 1, A = 2, B = 3
Output: 2
Example 2:
Input: N = 4, A = 2, B = 3
Output: 6
Example 3:
Input: N = 5, A = 2, B = 4
Output: 10
E... | class Solution:
def nthMagicalNumber(self, N: int, A: int, B: int) -> int:
def compute_gcd(x, y):
if y == 0:
return x
return compute_gcd(y, x % y)
def compute_lcm(x, y):
lcm = x * y // compute_gcd(x, y)
return lcm
C = comput... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_O... |
A positive integer is magical if it is divisible by either A or B.
Return the N-th magical number. Since the answer may be very large, return it modulo 10^9 + 7.
Example 1:
Input: N = 1, A = 2, B = 3
Output: 2
Example 2:
Input: N = 4, A = 2, B = 3
Output: 6
Example 3:
Input: N = 5, A = 2, B = 4
Output: 10
E... | class Solution:
def nthMagicalNumber(self, N: int, A: int, B: int) -> int:
def gcd(a, b):
while b:
a, b = b, a % b
return a
LCM = A * B // gcd(A, B)
m = LCM // A + LCM // B - 1
q, r = divmod(N, m)
if r == 0:
return q * LC... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER ... |
A positive integer is magical if it is divisible by either A or B.
Return the N-th magical number. Since the answer may be very large, return it modulo 10^9 + 7.
Example 1:
Input: N = 1, A = 2, B = 3
Output: 2
Example 2:
Input: N = 4, A = 2, B = 3
Output: 6
Example 3:
Input: N = 5, A = 2, B = 4
Output: 10
E... | class Solution:
def _lcm(self, a, b):
return a * b // math.gcd(a, b)
def _nth_magical_number_slow(self, n: int, a: int, b: int) -> int:
if n == 0:
return 0
else:
i, j = a, b
count = 1
while count < n:
if i <= j:
... | CLASS_DEF FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF VAR VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBE... |
A positive integer is magical if it is divisible by either A or B.
Return the N-th magical number. Since the answer may be very large, return it modulo 10^9 + 7.
Example 1:
Input: N = 1, A = 2, B = 3
Output: 2
Example 2:
Input: N = 4, A = 2, B = 3
Output: 6
Example 3:
Input: N = 5, A = 2, B = 4
Output: 10
E... | class Solution:
def nthMagicalNumber(self, N: int, A: int, B: int) -> int:
if A > B:
A, B = B, A
if B % A == 0:
return A * N % 1000000007
for i in range(1, A + 1):
if B * i % A == 0:
break
LCM = B * i
nAB = LCM // A + i - 1... | CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ... |
A positive integer is magical if it is divisible by either A or B.
Return the N-th magical number. Since the answer may be very large, return it modulo 10^9 + 7.
Example 1:
Input: N = 1, A = 2, B = 3
Output: 2
Example 2:
Input: N = 4, A = 2, B = 3
Output: 6
Example 3:
Input: N = 5, A = 2, B = 4
Output: 10
E... | class Solution:
def nthMagicalNumber(self, N: int, A: int, B: int) -> int:
d = gcd(A, B)
A //= d
B //= d
def how_many_below(n):
return n // A + n // B - n // (A * B)
lo = N - 1
hi = min(A, B) * N
while hi - lo > 1:
h = (hi + lo) // 2... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL ... |
A positive integer is magical if it is divisible by either A or B.
Return the N-th magical number. Since the answer may be very large, return it modulo 10^9 + 7.
Example 1:
Input: N = 1, A = 2, B = 3
Output: 2
Example 2:
Input: N = 4, A = 2, B = 3
Output: 6
Example 3:
Input: N = 5, A = 2, B = 4
Output: 10
E... | class Solution:
def nthMagicalNumber(self, N: int, A: int, B: int) -> int:
a_t = A
b_t = B
col = []
low_anc = a_t
while a_t != b_t:
if a_t < b_t:
col.append(a_t)
a_t = a_t + A
else:
col.append(b_t)
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BI... |
There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number i in the queue will have to visit his... | from sys import stdin, stdout
n, k = map(int, stdin.readline().split())
values = list(map(int, stdin.readline().split()))
if sum(values) < k:
stdout.write("-1")
elif sum(values) > k:
l = 0
r = k + 1
while r - l > 1:
m = (r + l) // 2
cnt = 0
for i in range(n):
cnt += ... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIG... |
There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number i in the queue will have to visit his... | read = lambda: map(int, input().split())
n, k = read()
a = list(read())
b = sorted([(a[i], i) for i in range(n)])
if sum(a) < k:
print(-1)
exit()
j = 0
x2 = 0
for i in range(n):
x = b[i][0]
cur = (n - j) * (x - x2)
if cur > k:
break
x2 = x
k -= cur
j += 1
if n == j:
print()
... | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN V... |
There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number i in the queue will have to visit his... | n, k = map(int, input().split())
a = list(map(int, input().split()))
c = len(a)
while c and k // c:
t = k // c
v = 0
for i in range(len(a)):
if a[i] == 0:
continue
v += a[i] - max(0, a[i] - t)
a[i] = max(0, a[i] - t)
if a[i] == 0:
c -= 1
k -= v
for... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER ... |
There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number i in the queue will have to visit his... | from sys import stdin
n, k = [int(x) for x in stdin.readline().split()]
a = [int(x) for x in stdin.readline().split()]
if sum(a) < k:
print(-1)
elif sum(a) == k:
pass
else:
diff = 0
kCopy = k
sortA = sorted(a, reverse=True)
while sortA:
nxt = sortA[-1]
nxt -= diff
if len... | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER WHILE VAR ASSIGN VAR VAR NUMBER VAR VAR IF BIN_OP FUNC_CA... |
There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number i in the queue will have to visit his... | def chtoetodvoichnyupoisk(a, c):
r = len(a)
l = 0
while r - l > 1:
s = (l + r) // 2
if s == len(a):
if a[s - 1] >= c:
r = s
else:
l = s
if a[s] >= c:
r = s
else:
l = s
if r == 1 and a[0] >= c:... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER RETURN VAR FUNC_DEF ... |
Lucy had recently learned the game, called Natural Numbers.
The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smallest unique number (that is, the smallest number that was not said b... | for _ in range(int(input())):
dic = {}
for i in range(int(input())):
s, i = input().split()
e = int(i)
if dic.get(e) == None:
dic[e] = ["", 0]
dic[e][0] = s
dic[e][1] += 1
q = "Nobody wins."
mi = 10**10
for i in dic:
if dic[i][1] == 1:
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR LIST STRING NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR... |
Lucy had recently learned the game, called Natural Numbers.
The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smallest unique number (that is, the smallest number that was not said b... | t = int(input())
while t:
re = []
st = {}
m = {}
for _ in range(int(input())):
a, b = input().split()
b = int(b)
if b in list(st.keys()):
st[b] += 1
else:
st[b] = 1
m[b] = a
re.append(int(b))
count = 0
re = list(set(re))... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL... |
Lucy had recently learned the game, called Natural Numbers.
The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smallest unique number (that is, the smallest number that was not said b... | for _ in range(int(input())):
n = int(input())
goes = []
for u in range(n):
z = input().split()
goes.append((int(z[1]), z[0]))
goes.sort()
res = "Nobody wins."
last = goes[0][0] - 1
win = False
for val, nm in goes:
if val == last:
win = False
e... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER F... |
Lucy had recently learned the game, called Natural Numbers.
The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smallest unique number (that is, the smallest number that was not said b... | s = int(input())
for i in range(s):
n = int(input())
m = dict()
for i in range(n):
sum = input().split()
if int(sum[1]) in m:
m[int(sum[1])].append(sum[0])
else:
m[int(sum[1])] = [sum[0]]
l = sorted(m.keys())
s1 = "Nobody wins."
for i in l:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER LIST VA... |
Lucy had recently learned the game, called Natural Numbers.
The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smallest unique number (that is, the smallest number that was not said b... | t = int(input())
list1 = []
list2 = []
newlist = []
for i in range(t):
p = int(input())
list1 = []
list2 = []
list3 = []
newlist = []
for j in range(p):
s = input()
name, number = s.split()
number = int(number)
list1.append(number)
list2.append(name)
f... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR... |
Lucy had recently learned the game, called Natural Numbers.
The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smallest unique number (that is, the smallest number that was not said b... | try:
t = int(input())
while t:
t -= 1
n = int(input())
arr = []
obj = {}
for i in range(n):
x, y = input().split()
y = int(y)
arr.append([x, y])
if y in obj:
obj[y].append(x)
else:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR E... |
Lucy had recently learned the game, called Natural Numbers.
The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smallest unique number (that is, the smallest number that was not said b... | for _ in range(int(input())):
np = int(input())
dict = {}
for i in range(np):
name, num = input().split()
num = int(num)
if dict.get(num, -1) == -1:
dict[num] = name
else:
dict[num] = 0
arr = []
for key in dict:
arr.append(key)
arr.... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VA... |
Lucy had recently learned the game, called Natural Numbers.
The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smallest unique number (that is, the smallest number that was not said b... | t = int(input())
for _ in range(t):
n = int(input())
players = {}
for i in range(n):
name, number = input().split()
number = int(number)
if number in players:
players[number].append(name)
else:
players[number] = [name]
smallest_unique = float("inf"... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR ... |
Lucy had recently learned the game, called Natural Numbers.
The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smallest unique number (that is, the smallest number that was not said b... | for _ in range(int(input())):
q = []
for __ in range(int(input())):
a, b = list(input().split())
b = int(b)
q.append((a, b))
q = sorted(q, key=lambda x: x[1])
i = 0
win = ""
if len(q) == 1:
continue
while i < len(q):
t = q[i][1]
if i == len(q) ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING IF FUNC_CALL VAR VA... |
Lucy had recently learned the game, called Natural Numbers.
The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smallest unique number (that is, the smallest number that was not said b... | def comp(a, b):
if len(a) > len(b):
return b
elif len(b) > len(a):
return a
else:
i = 0
while True:
if a[i] > b[i]:
return b
elif b[i] > a[i]:
return a
i += 1
for _ in range(int(input())):
n = int(input... | FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR VAR VAR RETURN VAR IF VAR VAR VAR VAR RETURN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSI... |
Lucy had recently learned the game, called Natural Numbers.
The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smallest unique number (that is, the smallest number that was not said b... | t = int(input())
for i in range(t):
n = int(input())
d = {}
c = 0
for j in range(n):
a, b = input().split()
b = int(b)
if b not in d.keys():
d[b] = a
else:
d[b] = ""
for k in sorted(d.keys()):
if d[k] != "":
print(d[k])
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC... |
Lucy had recently learned the game, called Natural Numbers.
The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smallest unique number (that is, the smallest number that was not said b... | t = int(input())
for _ in range(t):
n = int(input())
l = []
hash = {}
for i in range(n):
a, b = map(str, input().split())
l.append([a, b])
try:
hash[b]
except:
hash[b] = 1
else:
hash[b] += 1
ans = []
for i in l:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST FOR... |
Lucy had recently learned the game, called Natural Numbers.
The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smallest unique number (that is, the smallest number that was not said b... | for _ in range(int(input())):
n = int(input())
a = []
b = []
for i in range(n):
name, score = map(str, input().split())
a.append([name, score])
b.append(score)
a.sort(key=lambda x: x[1])
b.sort()
i = 0
while True:
p = b.count(b[i])
if p == 1:
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR N... |
Lucy had recently learned the game, called Natural Numbers.
The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smallest unique number (that is, the smallest number that was not said b... | for i in range(int(input())):
n = int(input())
x = {}
for i in range(n):
s, a = input().split()
a = int(a)
if a not in x.keys():
x[a] = s
else:
x[a] = "-1"
ans = "Nobody wins."
m = 200000000001
for i in x.keys():
if i < m and x[i] !... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR I... |
Lucy had recently learned the game, called Natural Numbers.
The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smallest unique number (that is, the smallest number that was not said b... | t = int(input())
while t:
t -= 1
n = int(input())
a = []
d = {}
while n:
n -= 1
l = input().split()
v = int(l[1])
if d.get(v) == None:
d[v] = ["", 0]
d[v][0] = l[0]
d[v][1] += 1
mini = float("inf")
s = "Nobody wins."
for i in d:... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR LIST STRING NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR ... |
Lucy had recently learned the game, called Natural Numbers.
The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smallest unique number (that is, the smallest number that was not said b... | import sys
from itertools import groupby
input = sys.stdin.readline
def rii():
return range(int(input().strip()))
def ii():
return int(input().strip())
def mii():
return map(int, input().strip().split(" "))
def lmii():
return list(map(int, input().strip().split(" ")))
def si():
return str... | IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RET... |
Lucy had recently learned the game, called Natural Numbers.
The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smallest unique number (that is, the smallest number that was not said b... | for _ in range(int(input())):
n = int(input())
a = {}
b = {}
c = {}
for _ in range(n):
x, y = input().split()
y = int(y)
a[x] = y
b[y] = x
try:
c[y] += 1
except:
c[y] = 1
ans = 1000000000000000000
for i in c:
if ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUM... |
Lucy had recently learned the game, called Natural Numbers.
The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smallest unique number (that is, the smallest number that was not said b... | T = int(input())
for t in range(0, T):
n = int(input())
s = [0] * n
np = [0] * n
for i in range(0, n):
s[i], np[i] = input().split()
np[i] = int(np[i])
no = np[:]
no.sort()
ans = "-1"
if no[0] != no[1]:
ans = no[0]
else:
for i in range(1, n - 1):
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC... |
Lucy had recently learned the game, called Natural Numbers.
The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smallest unique number (that is, the smallest number that was not said b... | t = int(input())
for tc in range(t):
n = int(input())
players = dict()
for i in range(n):
inputTmp = input().split(" ")
name = inputTmp[0]
num = int(inputTmp[1])
if num not in players:
players[num] = name
else:
players[num] = 0
winner = Fal... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NU... |
Lucy had recently learned the game, called Natural Numbers.
The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smallest unique number (that is, the smallest number that was not said b... | def unique_number(arr):
n = len(arr)
if n == 1:
return arr[0]
if arr[0] != arr[1]:
return arr[0]
for i in range(1, n - 1):
if arr[i - 1] != arr[i] and arr[i] != arr[i + 1]:
return arr[i]
if arr[-2] != arr[-1]:
return arr[-1]
return 0
t = int(input())... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR IF VAR NUMBER VAR NUMBER RETURN VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ... |
Lucy had recently learned the game, called Natural Numbers.
The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smallest unique number (that is, the smallest number that was not said b... | for t in range(int(input())):
n = int(input())
s = input().split()
num = int(s[1])
s = s[0]
d = dict()
d1 = dict()
d[num] = s
d1[num] = s
for i in range(1, n):
s = input().split()
num = int(s[1])
s = s[0]
if num in d:
d[num] = None
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_C... |
Lucy had recently learned the game, called Natural Numbers.
The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smallest unique number (that is, the smallest number that was not said b... | t = int(input())
while t:
n = int(input())
d = {}
c = {}
for i in range(n):
a, b = input().split()
d[a] = int(b)
c[int(b)] = c.get(int(b), 0) + 1
l = []
for i in c:
if c[i] == 1:
l.append(i)
if len(l) == 0:
print("Nobody wins.")
else:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR ... |
For an integer n, we call k>=2 a good base of n, if all digits of n base k are 1.
Now given a string representing n, you should return the smallest good base of n in string format.
Example 1:
Input: "13"
Output: "3"
Explanation: 13 base 3 is 111.
Example 2:
Input: "4681"
Output: "8"
Explanation: 4681 base 8 is 1... | class Solution:
def smallestGoodBase(self, n):
return self.use_binary_search(n)
def use_math(self, n):
n = int(n)
max_m = int(math.log(n, 2))
for m in range(max_m, 1, -1):
k = int(n**m**-1)
if (k ** (m + 1) - 1) // (k - 1) == n:
return st... | CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VA... |
For an integer n, we call k>=2 a good base of n, if all digits of n base k are 1.
Now given a string representing n, you should return the smallest good base of n in string format.
Example 1:
Input: "13"
Output: "3"
Explanation: 13 base 3 is 111.
Example 2:
Input: "4681"
Output: "8"
Explanation: 4681 base 8 is 1... | class Solution(object):
def smallestGoodBase(self, n):
num = int(n)
thisLen = int(math.log(num, 2)) + 1
while thisLen > 2:
thisBase = int(num ** (1.0 / (thisLen - 1)))
if num * (thisBase - 1) == thisBase**thisLen - 1:
return str(thisBase)
... | CLASS_DEF VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR NUMBER RETURN FUNC_CALL VAR B... |
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line and n is the number of students in the line... | n = int(input())
target = list(map(int, input().split()))
got = list(map(int, input().split()))
swaps = []
for i in range(n - 1, -1, -1):
for j in range(i + 1):
if got[j] == target[i] and j != i:
swaps.append((j + 1, j + 1 + 1))
got[j], got[j + 1] = got[j + 1], got[j]
print(len(swaps... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR EXPR FUNC_... |
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line and n is the number of students in the line... | number = int(input())
origin = list(input().split())
array = list(input().split())
positions = {}
pre = []
last = []
result = 0
for i in range(number):
if origin[i] == array[i]:
continue
else:
j = i + 1
index = len(pre)
for j in range(i + 1, number):
pre.insert(index,... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_C... |
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line and n is the number of students in the line... | import sys
n = int(sys.stdin.readline())
a = [int(x) for x in sys.stdin.readline().split()]
assert len(a) == n
b = [int(x) for x in sys.stdin.readline().split()]
assert len(b) == n
ans = []
for i in range(n):
j = i
while b[j] != a[i]:
j += 1
while j > i:
ans += [(j, j + 1)]
b[j - 1]... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR LIST VAR... |
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line and n is the number of students in the line... | n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
ans = []
i = 0
while i < n - 1:
for j in range(i, n):
if l2[j] == l1[i]:
for k in range(j, i, -1):
ans.append([k, k + 1])
l2[k], l2[k - 1] = l2[k - 1], l2[k]
bre... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER... |
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line and n is the number of students in the line... | n = int(input())
(*a,) = map(int, input().split())
(*b,) = map(int, input().split())
ans, s, k = [], 0, 0
while b:
x = b.index(a[k])
b.remove(a[k])
ans.append((x + k + 1, k + 1))
s += x
k += 1
print(s)
for i in ans:
for j in range(i[0], i[1], -1):
print(j - 1, j) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR LIST NUMBER NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER V... |
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line and n is the number of students in the line... | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
moves = []
for i in range(n):
for j in range(i, n):
if a[i] == b[j]:
for k in range(j - i):
moves.append((j + 1 - k, j - k))
b = [b[j]] + b[:j] + b[j + 1 :]
break
prin... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ... |
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line and n is the number of students in the line... | def rangtolist(dv, l, r):
mv = []
for c in range(r, l, -1):
mv.append((c - 1, c))
return mv, left(dv, l, r)
def left(dv, l, r):
nv = dv[:l]
nv += dv[r : r + 1]
nv += dv[l:r]
nv += dv[r + 1 :]
return nv
def pr(v):
print("***")
for c in v:
print(c, end=" ")
... | FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR... |
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line and n is the number of students in the line... | def sor(t):
f = []
for i in range(n):
for j in range(n - i - 1):
if t[j] > t[j + 1]:
t[j], t[j + 1] = t[j + 1], t[j]
f.append([j + 1, j + 2])
return f
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a == b:
... | FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN V... |
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line and n is the number of students in the line... | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
num = 0
swap = []
for i in range(n - 1, -1, -1):
if b[i] != a[i]:
right = a[i]
ind = b.index(right)
s = b[i]
b[i] = a[i]
b[ind] = s
num += 2 * (i - ind) - 1
for j in range... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL ... |
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line and n is the number of students in the line... | import sys
n = int(input())
arr2 = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
ans = []
ans2 = []
for i in range(n - 1):
for j in range(0, n - i - 1):
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]
ans.append((j, j + 1))
for i in range(... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMB... |
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line and n is the number of students in the line... | n = int(input())
start = []
end = []
s1 = input().split(" ")
s2 = input().split(" ")
for i in range(n):
start.append(int(s1[i]))
end.append(int(s2[i]))
q = 0
string = ""
for i in range(n):
if start[i] != end[i]:
for j in range(i + 1, n):
if end[j] == start[i]:
for k in ra... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR... |
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line and n is the number of students in the line... | n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
cnt = 0
ans = []
for i in range(n):
if a[i] == b[i]:
continue
j = i
while j < n and b[j] != a[i]:
j += 1
while j > i:
b[j], b[j - 1] = b[j - 1], b[j]
ans.append([j, j + 1])
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR... |
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$.
Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chose... | n = int(input())
y = lambda l: sorted(list(l[i + 1] - l[i] for i in range(len(l) - 1)))
z = lambda: list(map(int, input().split()))
c = z()
t = z()
print(["No", "Yes"][c[0] == t[0] and y(c) == y(t)]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST STRING STRING ... |
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$.
Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chose... | n = int(input())
c = list(map(int, input().split(" ")))
t = list(map(int, input().split(" ")))
check = c[0] == t[0]
c_diff = [(c[i] - c[i - 1]) for i in range(1, n)]
t_diff = [(t[i] - t[i - 1]) for i in range(1, n)]
c_diff.sort()
t_diff.sort()
if check and c_diff == t_diff:
print("Yes")
else:
print("No") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR V... |
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$.
Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chose... | number = int(input())
gregory = list(map(int, input().split()))
andrew = list(map(int, input().split()))
glen, alen = len(gregory), len(andrew)
def canSync(g, a):
gdiffs, adiffs = [], []
for i in range(1, len(g)):
gdiffs.append(g[i] - g[i - 1])
adiffs.append(a[i] - a[i - 1])
gdiffs.sort()
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL ... |
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$.
Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chose... | n = int(input())
c = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
new1 = []
new2 = []
for i in range(n - 1):
new1.append(c[i + 1] - c[i])
new2.append(t[i + 1] - t[i])
if c[0] == t[0] and c[-1] == t[-1] and sorted(new1) == sorted(new2):
print("Yes")
else:
print("No") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VA... |
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$.
Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chose... | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = []
y = []
for i in range(n - 1):
x.append(a[i + 1] - a[i])
for i in range(n - 1):
y.append(b[i + 1] - b[i])
x.sort()
y.sort()
if x == y and a[0] == b[0] and a[n - 1] == b[n - 1]:
print("Yes")
else:
print("No") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL V... |
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$.
Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chose... | n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
if a[0] == b[0] and a[-1] == b[-1]:
c = []
d = []
for i in range(1, n):
c.append(a[i] - a[i - 1])
d.append(b[i] - b[i - 1])
c.sort()
d.sort()
if c == d:
print("Yes")
else:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER... |
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$.
Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chose... | n = int(input())
c = list(map(int, input().split()))
t = list(map(int, input().split()))
c_diffs = [(c[i] - c[i - 1]) for i in range(1, n)]
t_diffs = [(t[i] - t[i - 1]) for i in range(1, n)]
print(
"Yes"
if c[0] == t[0] and c[-1] == t[-1] and sorted(c_diffs) == sorted(t_diffs)
else "No"
) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMB... |
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$.
Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chose... | n = int(input().strip())
x = [int(tmp) for tmp in input().strip().split(" ")]
y = [int(tmp) for tmp in input().strip().split(" ")]
def solve(x, y):
if x[0] != y[0] or x[-1] != y[-1]:
return False
cha_dict = {}
for i in range(n - 1):
cha = x[i + 1] - x[i]
if cha not in cha_dict:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMB... |
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$.
Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chose... | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] != b[0]:
print("NO")
else:
c = sorted(a[i + 1] - a[i] for i in range(n - 1))
d = sorted(b[i + 1] - b[i] for i in range(n - 1))
if c == d:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBE... |
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$.
Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chose... | import sys
n = int(input())
c = list(map(int, input().split()))
t = list(map(int, input().split()))
if c[0] != t[0] or c[n - 1] != t[n - 1]:
print("No")
sys.exit()
if n == 2:
print("Yes")
sys.exit()
g1 = [(c[i + 1] - c[i]) for i in range(n - 1)]
g2 = [(t[i + 1] - t[i]) for i in range(n - 1)]
if sorted(... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CA... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.