description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
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...
def get(l): res = [] for i in range(1, n): res.append(l[i] - l[i - 1]) res.sort() return res n, a, b = ( int(input()), [int(_) for _ in input().split()], [int(_) for _ in input().split()], ) ma, mb = get(a), get(b) print("Yes" if ma == mb and a[0] == b[0] and a[-1] == b[-1] else "N...
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC...
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())) def comp(l): out = 0 for v in l: out += v * v for i in range(n - 1): out -= l[i] * l[i + 1] return out if c[0] == t[0] and t[-1] == c[-1] and comp(c) == comp(t): print("Yes") else: print(...
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 FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN 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 = list(map(int, input().split())) b = list(map(int, input().split())) a1 = [(a[i + 1] - a[i]) for i in range(n - 1)] b1 = [(b[i + 1] - b[i]) for i in range(n - 1)] a1.sort() b1.sort() if a[0] != b[0] or a[-1] != b[-1]: print("No") elif a1 == b1: 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 BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR 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 = list(map(int, str(input()).split(" "))) b = list(map(int, str(input()).split(" "))) c = [0] * (n - 1) d = [0] * (n - 1) for i in range(n - 1): c[i] = a[i + 1] - a[i] d[i] = b[i + 1] - b[i] c.sort() d.sort() if c == d and a[0] == b[0] and a[-1] == b[-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 FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR F...
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...
from sys import stdin max_val = int(10000000000000.0) min_val = int(-10000000000000.0) def read_int(): return int(stdin.readline()) def read_ints(): return [int(x) for x in stdin.readline().split()] def read_str(): return input() def read_strs(): return [x for x in stdin.readline().split()] n...
ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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...
cnt_num = int(input()) a_str = input() b_str = input() a_arr = [int(x) for x in a_str.split(" ")] b_arr = [int(x) for x in b_str.split(" ")] if a_arr[0] != b_arr[0] or a_arr[cnt_num - 1] != b_arr[cnt_num - 1]: print("No") exit(0) a_tmp_arr, b_tmp_arr = [], [] for i in range(cnt_num - 1): a_tmp_arr.append(a_...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER AS...
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())) 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)]) print("YNEOS"[a[0] != b[0] or c != d :: 2])
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 BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NU...
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...
M = int(input()) tree1 = [] tree2 = [] numbers1 = input().split() numbers2 = input().split() for x in range(M - 1): tree1 += [int(numbers1[x + 1]) - int(numbers1[x])] tree1 = sorted(tree1) for x in range(M - 1): tree2 += [int(numbers2[x + 1]) - int(numbers2[x])] tree2 = sorted(tree2) if tree1 == tree2 and numbe...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR LIST BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUM...
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...
( lambda N, c, t: print( "Yes" if c[0] == t[0] and c[-1] == t[-1] and sorted(c[i] - c[i + 1] for i in range(N - 1)) == sorted(t[i] - t[i + 1] for i in range(N - 1)) else "No" ) )(int(input()), list(map(int, input().split())), list(map(int, input().split())))
EXPR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING STRING FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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("")) x = list(map(int, input().split())) y = list(map(int, input().split())) dpx = [] dpy = [] flag = 0 if x[0] != y[0] or x[n - 1] != y[n - 1]: flag = 1 for i in range(1, n): dpx.append(x[i] - x[i - 1]) dpy.append(y[i] - y[i - 1]) dpx.sort() dpy.sort() if dpx != dpy: flag = 1 if flag: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING 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 ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR...
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 = input().split() t = input().split() for i in range(n): c[i] = int(c[i]) t[i] = int(t[i]) d = [(0) for i in range(n - 1)] s = [(0) for i in range(n - 1)] for i in range(n - 1): d[i] = c[i + 1] - c[i] s[i] = t[i + 1] - t[i] d.sort() s.sort() index = 0 same = True while same and index ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR...
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()) l = input().split() li = [int(i) for i in l] hashi = dict() l = input().split() li2 = [int(i) for i in l] if li[0] != li2[0]: print("No") quit() diff1 = [(li[i + 1] - li[i]) for i in range(n - 1)] diff2 = [(li2[i + 1] - li2[i]) for i in range(n - 1)] for i in diff1: if i in hashi: h...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER 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()) c = list(map(int, input().split())) t = list(map(int, input().split())) d = lambda x: sorted(x[i + 1] - x[i] for i in range(n - 1)) print("Yes" if c[0] == t[0] and d(c) == d(t) 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 FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CAL...
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(i) for i in input().split()] B = [int(i) for i in input().split()] S = [(A[i] - A[i - 1]) for i in range(1, N)] T = [(B[i] - B[i - 1]) for i in range(1, N)] S.sort() T.sort() if A[0] == B[0] and A[N - 1] == B[N - 1] and S == T: 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 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 NUMBER VAR EXPR FUNC_CAL...
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()) t1 = list(map(int, input().split())) t2 = list(map(int, input().split())) if t1[0] != t2[0] or t2[n - 1] != t1[n - 1]: print("No") exit() l1 = list() l2 = list() for i in range(0, n): if i == 0: l1.append(t1[i]) else: l1.append(t1[i] - t1[i - 1]) if i == n - 1: ...
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 ASSIGN VAR FUNC_CALL VAR ASSIGN 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...
def mp(): return map(int, input().split()) n = int(input()) c = list(mp()) t = list(mp()) a = [abs(c[i] - c[i + 1]) for i in range(n - 1)] b = [abs(t[i] - t[i + 1]) for i in range(n - 1)] if sorted(a) == sorted(b) and c[0] == t[0]: print("Yes") else: print("No")
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN...
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())) v = [] v1 = [] if c[0] != t[0] and c[n - 1] != t[n - 1]: print("No") else: for _ in range(n - 1): v.append(c[_ + 1] - c[_]) v1.append(t[_ + 1] - t[_]) v.sort() v1.sort() if v != v1: print...
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 IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL 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()) GR = list(map(int, input().split())) ANDR = list(map(int, input().split())) h = {} k = {} for y in range(1, n): if GR[y] - GR[y - 1] not in h: h[GR[y] - GR[y - 1]] = 0 h[GR[y] - GR[y - 1]] += 1 for y in range(1, n): if ANDR[y] - ANDR[y - 1] not in k: k[ANDR[y] - ANDR[y - 1]]...
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 DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP 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...
def E(): n = int(input()) c = [int(x) for x in input().split()] t = [int(x) for x in input().split()] c_p = sorted([(c[i + 1] - c[i]) for i in range(n - 1)]) t_p = sorted([(t[i + 1] - t[i]) for i in range(n - 1)]) if c_p != t_p: print("No") return print("Yes") if c[0] == t[0]...
FUNC_DEF 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 FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VA...
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
input() P = list(map(int, input().split())) l = sorted([[P.index(p), i % 2] for i, p in enumerate(sorted(P))]) for a, b in l: print(b)
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
R = lambda: list(map(int, input().split())) n, m = R() a = R() exist = [(False) for i in range(200)] for i in range(m): l, r = R() for j in a: if l <= j <= r: exist[j] = True b = a[:] b.sort() ans = [(0) for i in range(200)] flag = 0 for i in b: if exist[i]: ans[i] = flag ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ...
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
n, m = [int(i) for i in input().split()] p = list(map(int, input().split())) s = [input().split() for _ in range(m)] ps, result = sorted(p), [-1] * n for i in range(n): if i % 2 == 0: c = 1 else: c = 0 result[p.index(ps[i])] = c print(*result)
ASSIGN VAR VAR FUNC_CALL VAR 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 FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN ...
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
import sys read = lambda t=int: list(map(t, sys.stdin.readline().split())) _, M = read() xs = read() for _ in range(M): _ = read() xs = sorted((x, i) for i, x in enumerate(xs)) xs = sorted((i, j) for j, (x, i) in enumerate(xs)) print(" ".join(str(j % 2) for _, j in xs))
IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL ...
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
n, m = map(int, input().split()) t = list(enumerate(list(map(int, input().split())))) t.sort(key=lambda x: x[1]) p = ["0"] * n for i, x in t[::2]: p[i] = "1" print(" ".join(p))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR VAR VAR NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
a, b = map(int, input().split(" ")) pts = list(map(int, input().split(" "))) pts2 = [[pts[i], i, 0] for i in range(len(pts))] pts2.sort() for i in range(1, a, 2): pts2[i][2] = 1 pts2.sort(key=lambda x: x[1]) string = "" for i in pts2: string += str(i[2]) string += " " print(string.strip())
ASSIGN VAR 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 LIST VAR VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ...
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
n, m = map(int, input().split()) a = list(map(int, input().split())) b = [] for i in range(n): b.append((a[i], i)) b.sort() for i in range(n): b[i] = b[i][0], b[i][1], i % 2 c = [] for i in b: c.append((i[1], i[0], i[2])) c.sort() for i in c: print(i[2], end=" ")
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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST...
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
n, m = map(int, input().split()) p = sorted((x[1], x[0]) for x in enumerate(map(int, input().split()))) p = sorted((x[1], str(i % 2)) for i, x in enumerate(p)) print(" ".join(x[1] for x in p))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER VAR VAR
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
n, m = list(map(int, input().split())) points = [(v, i) for i, v in enumerate(map(int, input().split()))] for _ in range(m): input() blue = True ans = [0] * n points = sorted(points) for p in points: v, i = p ans[i] = int(blue) blue = not blue for v in ans: print(v, end=" ") print()
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VA...
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
n, m = map(int, input().split()) xlist = [int(x) for x in input().split()] plist = xlist[:] xlist.sort() for i in range(n): if xlist.index(plist[i]) % 2 == 0: plist[i] = "0" else: plist[i] = "1" print("".join([(plist[i] + " ") for i in range(n)]))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR VAR STRIN...
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
n, m = map(int, input().split()) L = list(map(int, input().split())) for i in range(n): L[i] = L[i], i L.sort() Ans = [0] * n for i in range(n): Ans[L[i][1]] = i % 2 for i in range(n): print(Ans[i], end=" ")
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VA...
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
n, m = map(int, input().split()) xs = list(map(int, input().split())) ys = sorted(range(n), key=xs.__getitem__) zs = sorted((ys[i], i % 2) for i in range(n)) print(*(z[1] for z in zs))
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 FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
n, m = map(int, input().split()) X = [int(x) for x in input().split()] segs = [[int(x) for x in input().split()] for _ in range(m)] D = {e: (i % 2) for i, e in enumerate(sorted(X))} for i in range(n): X[i] = D[X[i]] print(*X)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR E...
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
n, m = map(int, input().split()) a = [int(i) for i in input().split()] b = sorted([[a[i], i] for i in range(n)]) for i in range(m): l, r = map(int, input().split()) for i in range(n): a[b[i][1]] = str(i % 2) print(" ".join(a))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FUNC_CA...
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
n, m = map(int, input().split()) points = list(map(int, input().split())) segments = [input().split() for _ in range(m)] sorted_points = sorted(points) ans = [-1] * n for i in range(n): c = "0" if i % 2 else "1" ans[points.index(sorted_points[i])] = c print(" ".join(ans))
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 FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER STRING STRING ASSIGN ...
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
n, m = map(int, input().split()) c = list(map(int, input().split())) cc = c.copy() d = [] for i in range(m): input() output = [] cc.sort() for i in c: index = cc.index(i) if index % 2 == 0: output.append("0") else: output.append("1") print(" ".join(output))
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 ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR F...
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
n, m = map(int, input().split()) points = list(zip(map(int, input().split()), range(n))) points.sort() res = [] curr = 0 for point in points: res.append((point[1], (curr + 1) % 2)) curr += 1 res.sort() for point in res: print(point[1], end=" ")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR FOR VAR...
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
from sys import stdin, stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int, stdin.readline().split())) for _ in range(1): n, k = lst() mp = {} a = lst() for i in range(n): mp[a[i]] = i b = sorted(a) turn = 0 ans = [0] * n for v in b: ans[mp[v]] = turn ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP L...
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t...
n, m = map(int, input().split()) a = list(map(int, input().split())) d = dict() d[0] = 1 flag = 0 x = 0 ans = 0 for r in range(n): if a[r] < m: x -= 1 elif a[r] > m: x += 1 else: flag = 1 if flag: ans += d.get(x, 0) + d.get(x - 1, 0) else: t = d.get(x, 0) + 1 ...
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 ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUM...
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t...
n, m = map(int, input().split()) p = list(map(int, input().split())) ld = {} rd = {} def push(d, x): if x not in d: d[x] = 0 d[x] += 1 def count(d, m, arr, cnt): b, s = 0, 0 for x in arr: if x > m: b += 1 else: s += 1 if b - s in [0, 1]: ...
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 DICT ASSIGN VAR DICT FUNC_DEF IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR LIST N...
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t...
n, m = list(map(int, input().strip().split())) a = list(map(int, input().strip().split())) for i in range(n): if a[i] == m: pos = i l = 0 r = 0 d = False resLD, resLP, resRD, resRP = {(0): 1}, {}, {(0): 1}, {} for j in range(pos - 1, -1, -1): if a[j] > m: l += 1 elif a[j] < m: l -= 1...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR DICT NUMBER NUMBER DICT DICT ...
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t...
def readints(): return [int(x) for x in input().strip().split()] def main(): n, m = readints() p = readints() sums = {} pivot = p.index(m) diff = 0 sums[0] = 1 for i in range(pivot - 1, -1, -1): if p[i] > m: diff += 1 else: diff -= 1 sums...
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER EXPR F...
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t...
n, m = map(int, input().split()) p = list(map(int, input().split())) cur = 0 while p[cur] != m: cur += 1 pos = cur s = {} cnt, len = 0, 0 while cur >= 0: if p[cur] <= m: cnt += 1 len += 1 if 2 * cnt - len in s: s[2 * cnt - len] += 1 else: s[2 * cnt - len] = 1 cur -= 1 cur...
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 NUMBER WHILE VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR VAR...
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t...
def Yeee(x, v, n): re = 0 pre = 0 sum = 1 cnt = [0] * n + [1] + [0] * n for i in v: if i < x: pre += 1 sum += cnt[pre + n] else: sum -= cnt[pre + n] pre -= 1 cnt[pre + n] += 1 re += sum return re n, x = map(int, in...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST NUMBER VAR LIST NUMBER BIN_OP LIST NUMBER VAR FOR VAR VAR IF VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_...
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t...
n, m = map(int, input().split()) b = list(map(int, input().split())) p = b.index(m) j = p + 1 r = 1 x = 0 y = 0 c = [] d = [] while j < n: if b[j] < m: x += 1 else: y += 1 c.append(y - x) j += 1 j = p - 1 x = 0 y = 0 while j >= 0: if b[j] < m: x += 1 else: y += 1 ...
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 ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER E...
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t...
n, m = map(int, input().split(" ")) aa = list(map(int, input().split(" "))) def countMoreLess(vs, value): cur = 0 res = {cur: 1} for v in vs: cur += 1 if v > value else -1 res[cur] = res.get(cur, 0) + 1 return res pos = aa.index(m) leftCounts = countMoreLess(list(reversed(aa[0:pos]))...
ASSIGN VAR 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 FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT VAR NUMBER FOR VAR VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ...
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t...
n, m = list(map(int, input().split())) p = list(map(int, input().split())) mindex = p.index(m) ldict = {} rdict = {} diff = 0 ans = 0 ldict[0] = 1 rdict[0] = 1 for i in range(mindex - 1, -1, -1): if p[i] < m: diff -= 1 else: diff += 1 if diff in ldict.keys(): ldict[diff] += 1 els...
ASSIGN VAR 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 ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NU...
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t...
L1 = list(map(int, input().split())) numList = list(map(int, input().split())) length = L1[0] targetnumber = L1[1] pos = numList.index(targetnumber) pos_r = pos + 1 rem = 0 right = {(0): 1} left = {(0): 1} while pos_r <= length - 1: if numList[pos_r] > targetnumber: rem += 1 else: rem -= 1 i...
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 NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER WHILE ...
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t...
MAXN = 200001 n, m = list(map(int, input().split(" "))) s = list(map(int, input().split(" "))) f = [(0) for i in range(n + 1)] count = [(0) for i in range(-MAXN, MAXN + 1)] f[0] = 0 last = 0 res = 0 for i in range(1, n + 1): if s[i - 1] == m: for j in range(last, i): count[f[j]] += 1 las...
ASSIGN VAR NUMBER ASSIGN VAR 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 NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NU...
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t...
def main(): n, m = map(int, input().split()) ar = list(map(int, input().split())) dp = [0] start = -1 for index, elm in enumerate(ar): if elm > m: dp.append(dp[-1] + 1) elif elm < m: dp.append(dp[-1] - 1) else: dp.append(dp[-1]) if ...
FUNC_DEF 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 LIST NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR F...
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t...
n, m = list(map(int, input().split())) t = list(map(int, input().split())) mid = t.index(m) lefts = [0] * 600000 lefts[300000] = 1 gt = 0 lt = 0 for i in range(mid - 1, -1, -1): if t[i] < m: lt += 1 else: gt += 1 lefts[300000 + gt - lt] += 1 rights = [0] * 600000 rights[300000] = 1 gt = 0 lt...
ASSIGN VAR 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 ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER I...
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t...
T = input().split(" ") n = int(T[0]) m = int(T[1]) S = input().split(" ") for i in range(n): S[i] = int(S[i]) ind = 0 for k in range(n): if S[k] == m: ind = k k = ind P = [0] * (n + 1) N = [0] * (n + 1) R = [0] * (n - k) L = [0] * (k + 1) for i in range(k): if S[k - 1 - i] < m: L[k - 1 - i] ...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR B...
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t...
n, m = map(int, input().split(" ")) numbers = list(map(int, input().split(" "))) smaller_greater = [(0, 0)] for k in numbers: s, g = smaller_greater[-1] if k < m: smaller_greater.append((s + 1, g)) elif k > m: smaller_greater.append((s, g + 1)) else: smaller_greater.append((s, g)...
ASSIGN VAR 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 LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_...
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t...
n, m = list(map(int, input().split())) nums = list(map(int, input().split())) left = {} right = {} leftl = 0 leftm = 0 rightl = 0 rightm = 0 start = nums.index(m) ans = 1 for i in range(start - 1, -1, -1): if nums[i] > m: leftm += 1 else: leftl += 1 if leftl == leftm: ans += 1 el...
ASSIGN VAR 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 DICT ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VA...
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t...
import sys n, m = map(int, input().split()) s = list(map(int, input().split())) try: ind = s.index(m) except: print(0) sys.exit() dp = [(0) for i in range(n)] for i in range(ind + 1, n): if s[i] < m: dp[i] = dp[i - 1] - 1 elif s[i] > m: dp[i] = dp[i - 1] + 1 for i in range(ind - 1, ...
IMPORT 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 EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR B...
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t...
n, m = [int(i) for i in input().split()] a = [int(i) for i in input().split()] diff = [0] * n for i in range(n): if a[i] < m: diff[i] = -1 if a[i] > m: diff[i] = 1 aim = a.index(m) left = {} right = {} suml = 0 for i in reversed(range(aim + 1)): suml += diff[i] if not suml in left: ...
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 ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN ...
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t...
ma = {(0): 1} n, m = [int(x) for x in input().split()] arr = [int(x) for x in input().split()] s, fla, ans = 0, False, 0 for v in arr: if v == m: fla = True elif v < m: s -= 1 elif v > m: s += 1 if fla: ans += ma.get(s, 0) + ma.get(s - 1, 0) else: ma[s] = ma.g...
ASSIGN VAR DICT NUMBER NUMBER 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 ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC...
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t...
def main(): n, m = map(int, input().split()) def intCompare(x): if int(x) == m: return 0 if int(x) < m: return -1 return 1 p = list(map(intCompare, input().split())) ret = 0 ind = p.index(0) tem = 0 ret0 = [0] * 400001 ret1 = [0] * 400001...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP ...
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t...
n, m = list(map(int, input().split())) arr = list(map(int, input().split())) left = {(0): 0, (1): 0} right = {(0): 0, (1): 0} s = 0 g = 0 if m not in arr: print(0) else: for i in range(arr.index(m) + 1, n): if arr[i] < m: s += 1 elif arr[i] > m: g += 1 if g - s in...
ASSIGN VAR 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 DICT NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
from sys import stdin, stdout n, k = map(int, stdin.readline().split()) no = list(map(int, stdin.readline().split())) yes = list(map(int, stdin.readline().split())) mn = float("inf") for i in range(n): mn = min(mn, yes[i] // no[i]) l = mn r = mn + k + 1 while r > l + 1: m = (l + r) // 2 cnt = k for i i...
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR ASSI...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
I = lambda: list(map(int, input().split())) n, k = I() a = I() b = I() l = 0 r = 2 * 10**9 while l < r: m = (l + r) // 2 + 1 s = sum(max(a[i] * m - b[i], 0) for i in range(n)) if s > k: r = m - 1 else: l = m print(l)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
def distr(amt, k, n, a, b): for i in range(n): k -= max(0, a[i] * amt - b[i]) return k n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [(b[i] // a[i]) for i in range(n)] l = 0 r = 10000000000.0 ans = 0 while l <= r: mid = (l + r) // 2 ...
FUNC_DEF FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR VAR RETURN VAR 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VA...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
n, k = [int(x) for x in input().split()] A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] x, y = 0, max(B) + k + 1 z = (x + y) // 2 while z != x: credit = 0 for i in range(n): credit += max(z * A[i] - B[i], 0) if credit > k: y = z else: x = z z = (x...
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 ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER FOR VAR ...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
read = lambda: list(map(int, input().split())) n, k = read() a = list(read()) b = list(read()) c = [0] * n r = [0] * n for i in range(n): c[i] = b[i] // a[i] r[i] = a[i] - b[i] % a[i] def f(x): k1 = k for i in range(n): if c[i] >= x: continue cnt = (x - c[i] - 1) * a[i] + r...
ASSIGN VAR FUNC_CALL 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 FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
n, k = map(int, input().split()) recipe = list(map(int, input().split())) current = list(map(int, input().split())) high = max(current) + 1 + k low = 0 def canMake(x): magic_needed = 0 for i in range(n): diff = current[i] - recipe[i] * x if diff < 0: magic_needed -= diff return...
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSI...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
import sys n, k = map(int, input().split()) grams = list(map(int, input().split())) has = list(map(int, input().split())) tmp = -1 for i in range(len(grams)): tmp = max(tmp, has[i] // grams[i] + k // grams[i]) def func(grams, has, mid, k): if mid == tmp + 1: return False for i in range(len(grams)...
IMPORT 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_O...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
n, k = input().split(" ") n, k = [int(n), int(k)] list1 = list(map(int, input().split(" "))) list2 = list(map(int, input().split(" "))) low = 0 high = 2 * 10**9 while low < high: if high - low % 2 != 0: mid = low + (high - low) // 2 + 1 else: mid = low + (high - low) // 2 d = k for i in ...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR 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 NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER WHILE ...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
def check(m): need = 0 for ax, bx in zip(a, b): need += max(0, ax * m - bx) return need <= k n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) l = 0 r = 10**10 while r - l > 1: m = (l + r) // 2 if check(m): l = m else: ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR RETURN VAR VAR 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR AS...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
n, k = map(int, input().split()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] l, r = 0, 10**10 ans = 0 found = False def possible(k, c): req = 0 for i in range(n): if b[i] < a[i] * c: req += a[i] * c - b[i] return req <= k while l < r: mid = (l + r)...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) beg = 0 end = 10**10 while beg <= end: cnt = 0 mid = (beg + end) // 2 x = mid flag = 0 for i in range(n): if a[i] * mid > b[i]: cnt += a[i] * mid - b[i] if cnt > k...
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN ...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) l = 0 r = int(10000000000.0) while r - l > 1: mid = (r + l) // 2 fail = False kk = k for i in range(n): if b[i] < a[i] * mid: if kk > 0: kk -= a[i] * mid - b[i] ...
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR ...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
import sys def enough(n, k, a, b, m): for i in range(n): if m * a[i] <= b[i]: continue else: k -= m * a[i] - b[i] if k < 0: return False return True def binary_search(n, k, a, b): left = 0 right = int(2000000000.0) while right -...
IMPORT FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR ASSI...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
def can_make(n, k, one_cake, have, cake): i = 0 while i < n: needed = cake * one_cake[i] - have[i] i += 1 if needed > k: return False elif needed > 0: k -= needed return True def binary_search(n, k, one_cake, have): lo = 0 hi = 2000000000 ...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER IF VAR NUMBER VAR VAR RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VA...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
n, k = [int(f) for f in input().split(" ") if f] a = [int(f) for f in input().split(" ") if f] b = [int(f) for f in input().split(" ") if f] l = 0 r = 100000000000000000 while l + 1 < r: mid = (l + r) // 2 dust = int(k) for i in range(n): dust -= max(0, mid * a[i] - b[i]) if dust < 0: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN V...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
def ok(x): need = 0 for i in range(n): tmp = a[i] * x - b[i] if tmp > 0: need += tmp return need <= k n, k = (int(_) for _ in input().split()) a = [int(_) for _ in input().split()] b = [int(_) for _ in input().split()] lo, hi = 0, 2 * 10**9 while lo <= hi: mid = lo + hi >> ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR RETURN VAR VAR 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 ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
def possible(List1, List2, l, k, n): s = 0 for i in range(l): if n * List2[i] - List1[i] > 0: s += n * List2[i] - List1[i] if s <= k: return True else: return False nk = list(map(int, input().rstrip().split())) n = nk[0] k = nk[1] abc = list(map(int, input().rstrip(...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) low = 0 high = 2 * 10000000000.0 def p(mm): temp = k result = True for i in range(len(b)): s = b[i] f = a[i] rem = s - f * mm if rem < 0: temp += rem ...
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR V...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
no_of_indegrants, no_of_gram_magic = map(int, input().split()) def f(mid1, num): global no_of_indegrants li3 = li2[:] for i in range(no_of_indegrants): if li3[i] < li1[i] * mid: num = num - (li1[i] * mid - li3[i]) if num < 0: return False return True li1 = lis...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CA...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
def main(): n, k = list(map(int, input().split())) l = sorted( ( (a, b) for a, b in zip( list(map(int, input().split())), list(map(int, input().split())) ) ), key=lambda e: (e[1] // e[0], e[1] - e[0] % e[1]), ) lo, hi = l[0][1] ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMB...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
def calculate_cookie(n, k, a, b, mid) -> bool: sum = 0 for i in range(n): x = b[i] - a[i] * mid if x < 0: sum += x if k + sum >= 0: return True else: return False I = lambda: map(int, input().split()) n, k = I() a = list(map(int, input().split())) b = list(m...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER VAR 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 VAR FUNC_CALL FUNC_CAL...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) def check(n, k, c): for i in range(n): k -= max(a[i] * c - b[i], 0) if k < 0: return False return True lower = 0 upper = 2 * 1000000000.0 + 1 while upper - lower > 1: c = ...
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN ...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
n, m = [int(x) for x in input().split()] need = [int(x) for x in input().split()] has = [int(x) for x in input().split()] lo = 0 hi = 10**12 while lo <= hi: mid = int(int(lo + hi) / int(2)) magic = 0 for x in range(len(need)): ineed = mid * need[x] if ineed > has[x]: magic = magi...
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 ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
def check(a, b, midd, k): ans1 = 0 for i in range(n): if a[i] * midd <= b[i]: continue ans1 += midd * a[i] - b[i] if ans1 > k: return False return True n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) l...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER 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 FUNC_CALL V...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
def can_make(a, b, k, n): k2 = k for t, v in zip(a, b): diff = v - t * n if diff < 0: k2 += diff return k2 >= 0 def main(): n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) lo = 0 hi = 3 * 10**9 ...
FUNC_DEF ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR RETURN VAR NUMBER FUNC_DEF ASSIGN VAR 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...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
import sys input = sys.stdin.readline def judge(x): cnt = 0 for ai, bi in zip(a, b): cnt += max(0, ai * x - bi) return cnt <= k def binary_search(): l, r = 0, 10**10 while l <= r: mid = (l + r) // 2 if judge(mid): l = mid + 1 else: r = mid...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) st = 0 end = 10**10 ans = -1 while st <= end: mid = (st + end) // 2 e = 0 s = -k for i in range(n): t = b[i] - a[i] * mid if t < 0: s = s - t if s == 0: ...
ASSIGN VAR 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR ...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
def f(x): L = k for i in range(n): if B[i] // A[i] < x: L = L - (A[i] * x - B[i]) if L < 0: return True return False p = input() p = p.split() n = int(p[0]) k = int(p[1]) A = [int(i) for i in input().split()] B = [int(i) for i in input().split()] left = 0 right = 2 ...
FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
n, k = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) l = 0 r = 10**10 while r - l > 1: m = (r + l) // 2 poroshok = 0 for i in range(n): tr = A[i] * m - B[i] poroshok += max(tr, 0) if poroshok > k: r = m else: l = m p...
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR ...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
n, m = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) def bin_sear(l, h): while h - l > 1: mi = (h + l) // 2 s = sum(max(a[i] * mi - b[i], 0) for i in range(n)) if s <= m: l = mi else: h = mi print...
ASSIGN VAR 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 VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
n, k = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) def check(x): global n, k, A, b yn = 0 a = k for i in range(n): if A[i] * x > B[i]: yn += A[i] * x - B[i] k -= A[i] * x - B[i] if k < 0: k = a ...
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR V...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
import sys n, k = map(int, input().split()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] cookies = sys.maxsize c = [] high = 0 for i in range(n): cookies = min(cookies, b[i] // a[i]) high = max(high, k // a[i]) for i in range(n): c.append(b[i] - cookies * a[i]) def find(coo...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
def ok(m): k2 = k for i in range(n): o = a[i] * m - b[i] if o > 0: k2 -= o if k2 >= 0: return True return False n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) l = 0 r = 2000000001 m = (r + l) // 2 while...
FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR 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 VA...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
def ok(u, a, b, n, k): for i in range(n): if b[i] >= a[i] * u: continue else: k -= a[i] * u - b[i] if k < 0: return False return k >= 0 n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) l...
FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN VAR NUMBER 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 FUNC_CALL VAR VAR FUNC...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
n, m = map(int, input().split()) l = list(map(int, input().split())) l1 = list(map(int, input().split())) l2 = [] l3 = [] su = sum(l) def chek(N): v = 0 for i in range(n): d = max(0, N - l2[i]) if d > 0: d -= 1 v += l[i] - l3[i] v += l[i] * d if v <= m: ...
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
ax = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) def f(a, b, magic, n, mid): y = 0 for x in range(n): if a[x] * mid > b[x]: y += a[x] * mid - b[x] if y > magic: return False return True i = 0 bx =...
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 VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VA...
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence ...
def process(key, a, b, k, n): for i in range(n): y = b[i] - a[i] * key if y < 0: k += y if k < 0: return False if k >= 0: return True else: return False def bin_src(a, b, n, k, lo, hi): while hi - lo > 1: mid = (hi + lo) // 2 ...
FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR V...
Geek is organising a bike race with N bikers. The initial speed of the ith biker is denoted by H_{i} Km/hr and the acceleration of ith biker as A_{i} Km/Hr2. A biker whose speed is 'L' or more, is considered be a fast biker. The total speed on the track for every hour is calculated by adding the speed of each fast bike...
class Solution: def buzzTime(self, N, M, L, H, A): start = 0 end = M while start < end: m = (start + end) // 2 track_speed = 0 for h, a in zip(H, A): speed = h + m * a if speed >= L: track_speed += speed...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Geek is organising a bike race with N bikers. The initial speed of the ith biker is denoted by H_{i} Km/hr and the acceleration of ith biker as A_{i} Km/Hr2. A biker whose speed is 'L' or more, is considered be a fast biker. The total speed on the track for every hour is calculated by adding the speed of each fast bike...
class Solution: def bin_search(self, start, end, N, H, A, M, L): if start < end: mid = (end + start) // 2 sm = 0 for i in range(N): if H[i] + A[i] * mid > L: sm += H[i] + A[i] * mid if sm == M: return mid ...
CLASS_DEF FUNC_DEF IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN VAR IF VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VA...
Geek is organising a bike race with N bikers. The initial speed of the ith biker is denoted by H_{i} Km/hr and the acceleration of ith biker as A_{i} Km/Hr2. A biker whose speed is 'L' or more, is considered be a fast biker. The total speed on the track for every hour is calculated by adding the speed of each fast bike...
class Solution: def buzzTime( self, num_bikers, top_total_safe_speed, fast_total_speed, speeds, accels ): self.top_safe = top_total_safe_speed self.top_fast = fast_total_speed self.initial_speeds = speeds self.accels = accels return self.binarySearch(0, max(top_t...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER RETURN NUMBER IF VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETUR...
Geek is organising a bike race with N bikers. The initial speed of the ith biker is denoted by H_{i} Km/hr and the acceleration of ith biker as A_{i} Km/Hr2. A biker whose speed is 'L' or more, is considered be a fast biker. The total speed on the track for every hour is calculated by adding the speed of each fast bike...
def ceil(b): if b > int(b): return int(b) + 1 return int(b) class Solution: def buzzTime(self, N, M, L, H, A): first_l = min([ceil((L - h) / a) for h, a in zip(H, A)]) if ( M <= L or sum([(a * first_l + h) for a, h in zip(A, H) if a * first_l + h >= L]) ...
FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR V...
Geek is organising a bike race with N bikers. The initial speed of the ith biker is denoted by H_{i} Km/hr and the acceleration of ith biker as A_{i} Km/Hr2. A biker whose speed is 'L' or more, is considered be a fast biker. The total speed on the track for every hour is calculated by adding the speed of each fast bike...
class Solution: def buzzTime(self, N, M, L, H, A): low = 0 high = max(L, M) while low <= high: mid = (low + high) // 2 fast = 0 for i in range(N): if H[i] + A[i] * mid >= L: fast += H[i] + A[i] * mid if fast...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP ...