description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Your classmate, whom you do not like because he is boring, but whom you respect for his intellect, has two strings: $s$ of length $n$ and $t$ of length $m$. A sequence $p_1, p_2, \ldots, p_m$, where $1 \leq p_1 < p_2 < \ldots < p_m \leq n$, is called beautiful, if $s_{p_i} = t_i$ for all $i$ from $1$ to $m$. The width...
from sys import stdin as f def find_good_chain(s, t): x = 0 y = 0 ind = [] while x < len(t): while s[y] != t[x]: y = y + 1 ind.append(y) x = x + 1 y = y + 1 return ind def find_reversed_chain(s, t): x = len(t) - 1 y = len(s) - 1 ind = [] ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR ...
Your classmate, whom you do not like because he is boring, but whom you respect for his intellect, has two strings: $s$ of length $n$ and $t$ of length $m$. A sequence $p_1, p_2, \ldots, p_m$, where $1 \leq p_1 < p_2 < \ldots < p_m \leq n$, is called beautiful, if $s_{p_i} = t_i$ for all $i$ from $1$ to $m$. The width...
def findmax(s, t): l_indexies = [] start = 0 for c in t: idx = s.find(c, start) l_indexies.append(idx) start = idx + 1 r_indexies = [] end = len(s) for c in reversed(t): idx = s.rfind(c, 0, end) r_indexies.append(idx) end = idx r_indexies = r_i...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VA...
Your classmate, whom you do not like because he is boring, but whom you respect for his intellect, has two strings: $s$ of length $n$ and $t$ of length $m$. A sequence $p_1, p_2, \ldots, p_m$, where $1 \leq p_1 < p_2 < \ldots < p_m \leq n$, is called beautiful, if $s_{p_i} = t_i$ for all $i$ from $1$ to $m$. The width...
n, m = map(int, input().split()) s = input() t = input() s1 = [] s2 = [] j = 0 for i in range(m): while t[i] != s[j]: j += 1 s1.append(j) j += 1 j = 0 s = s[::-1] t = t[::-1] for i in range(m): while t[i] != s[j]: j += 1 s2.append(n - j - 1) j += 1 ans = 0 s2 = s2[::-1] for i in ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR ...
Your classmate, whom you do not like because he is boring, but whom you respect for his intellect, has two strings: $s$ of length $n$ and $t$ of length $m$. A sequence $p_1, p_2, \ldots, p_m$, where $1 \leq p_1 < p_2 < \ldots < p_m \leq n$, is called beautiful, if $s_{p_i} = t_i$ for all $i$ from $1$ to $m$. The width...
n, m = map(int, input().split()) s = input() t = input() i = 0 ls = [] for c in t: while s[i] != c: i = i + 1 ls.append(i) i = i + 1 rs = [] i = n - 1 for c in t[::-1]: while s[i] != c: i = i - 1 rs.append(i) i = i - 1 maxi = 0 rs = rs[::-1] for i in range(0, m): maxi = max(m...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR WHILE VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR NUMBER WHIL...
Your classmate, whom you do not like because he is boring, but whom you respect for his intellect, has two strings: $s$ of length $n$ and $t$ of length $m$. A sequence $p_1, p_2, \ldots, p_m$, where $1 \leq p_1 < p_2 < \ldots < p_m \leq n$, is called beautiful, if $s_{p_i} = t_i$ for all $i$ from $1$ to $m$. The width...
n, m = [int(i) for i in input().split()] s, t = [input() for i in range(2)] qw = {} ind = n for i in range(m - 1, -1, -1): for j in range(ind - 1, -1, -1): if s[j] == t[i]: qw[i] = j ind = j break raz = 0 ind = -1 for i in range(1, m): for j in range(ind + 1, n): ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NU...
Your classmate, whom you do not like because he is boring, but whom you respect for his intellect, has two strings: $s$ of length $n$ and $t$ of length $m$. A sequence $p_1, p_2, \ldots, p_m$, where $1 \leq p_1 < p_2 < \ldots < p_m \leq n$, is called beautiful, if $s_{p_i} = t_i$ for all $i$ from $1$ to $m$. The width...
n, m = map(int, input().split()) val1 = input() val2 = input() left = [] right = [] num = m for i in range(n - 1, -1, -1): vari = val1[i] if val2[num - 1] == vari: right.append(i) num = num - 1 if num == 0: break num = 0 for i in range(n): vari = val1[i] if val2[num] == vari:...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBE...
Your classmate, whom you do not like because he is boring, but whom you respect for his intellect, has two strings: $s$ of length $n$ and $t$ of length $m$. A sequence $p_1, p_2, \ldots, p_m$, where $1 \leq p_1 < p_2 < \ldots < p_m \leq n$, is called beautiful, if $s_{p_i} = t_i$ for all $i$ from $1$ to $m$. The width...
def solve(s, t): min_ids = [] i = 0 for ct in t: while True: if s[i] == ct: min_ids.append(i) i += 1 break i += 1 max_ids = [] i = len(s) - 1 for ct in reversed(t): while True: if s[i] == ct: ...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR WHILE NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMB...
Your classmate, whom you do not like because he is boring, but whom you respect for his intellect, has two strings: $s$ of length $n$ and $t$ of length $m$. A sequence $p_1, p_2, \ldots, p_m$, where $1 \leq p_1 < p_2 < \ldots < p_m \leq n$, is called beautiful, if $s_{p_i} = t_i$ for all $i$ from $1$ to $m$. The width...
n = input() s = list(input()) t = list(input()) pref = [0] * (len(s) + 1) for i in range(1, len(s) + 1): if pref[i - 1] == len(t): pref[i] = len(t) elif t[pref[i - 1]] == s[i - 1]: pref[i] = pref[i - 1] + 1 else: pref[i] = pref[i - 1] ss = s[::-1] tt = t[::-1] pref2 = [0] * (len(ss) ...
ASSIGN 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 BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP ...
Your classmate, whom you do not like because he is boring, but whom you respect for his intellect, has two strings: $s$ of length $n$ and $t$ of length $m$. A sequence $p_1, p_2, \ldots, p_m$, where $1 \leq p_1 < p_2 < \ldots < p_m \leq n$, is called beautiful, if $s_{p_i} = t_i$ for all $i$ from $1$ to $m$. The width...
n, m = list(map(int, input().split())) a = list(input()) b = list(input()) poses = [] it = 0 for i in range(m): while a[it] != b[i]: it += 1 poses.append(it) it += 1 last = n - 1 ma = 0 for i in range(1, ma): m = max(poses[i] - poses[i - 1], ma) for i in range(m - 1, 0, -1): while a[last] !=...
ASSIGN VAR VAR FUNC_CALL VAR 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 LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMB...
Your classmate, whom you do not like because he is boring, but whom you respect for his intellect, has two strings: $s$ of length $n$ and $t$ of length $m$. A sequence $p_1, p_2, \ldots, p_m$, where $1 \leq p_1 < p_2 < \ldots < p_m \leq n$, is called beautiful, if $s_{p_i} = t_i$ for all $i$ from $1$ to $m$. The width...
N, M = map(int, input().split()) S = input() T = input() A = [] B = [] si = 0 for t in T: while S[si] != t: si += 1 A.append(si) si += 1 si = N - 1 for t in T[::-1]: while S[si] != t: si -= 1 B.append(si) si -= 1 B.reverse() ans = 0 for a, b in zip(A, B[1:]): ans = max(ans, b...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR WHILE VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR NUMBER WHILE VAR VAR VAR VAR NUMBER EXPR FUNC_C...
Your classmate, whom you do not like because he is boring, but whom you respect for his intellect, has two strings: $s$ of length $n$ and $t$ of length $m$. A sequence $p_1, p_2, \ldots, p_m$, where $1 \leq p_1 < p_2 < \ldots < p_m \leq n$, is called beautiful, if $s_{p_i} = t_i$ for all $i$ from $1$ to $m$. The width...
import sys input = sys.stdin.readline def solve(): n, m = map(int, input().split()) p = [[] for i in range(26)] p1 = [None] * 26 A = ord("a") j = 0 for i in input().strip(): p[ord(i) - A].append(j) j += 1 for i in range(26): p1[i] = p[i].copy() p1[i].revers...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NONE NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUN...
Your classmate, whom you do not like because he is boring, but whom you respect for his intellect, has two strings: $s$ of length $n$ and $t$ of length $m$. A sequence $p_1, p_2, \ldots, p_m$, where $1 \leq p_1 < p_2 < \ldots < p_m \leq n$, is called beautiful, if $s_{p_i} = t_i$ for all $i$ from $1$ to $m$. The width...
import sys input = sys.stdin.readline def main(): N, M = [int(x) for x in input().split()] S = input().strip() T = input().strip() aa = [] current = 0 for i in range(M): for j in range(current, N): if T[i] == S[j]: aa.append(j) current = j +...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMB...
Your classmate, whom you do not like because he is boring, but whom you respect for his intellect, has two strings: $s$ of length $n$ and $t$ of length $m$. A sequence $p_1, p_2, \ldots, p_m$, where $1 \leq p_1 < p_2 < \ldots < p_m \leq n$, is called beautiful, if $s_{p_i} = t_i$ for all $i$ from $1$ to $m$. The width...
n, m = [int(x) for x in input().split()] s = input() t = input() L = 1 R = n - m + 1 head = 0 indices1 = [] indices2 = [] for i in range(n): if s[i] == t[head]: head += 1 indices1.append(i) if head == m: break tail = m - 1 for i in range(n): if s[n - 1 - i] == t[tail]: tail -...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR ...
Your classmate, whom you do not like because he is boring, but whom you respect for his intellect, has two strings: $s$ of length $n$ and $t$ of length $m$. A sequence $p_1, p_2, \ldots, p_m$, where $1 \leq p_1 < p_2 < \ldots < p_m \leq n$, is called beautiful, if $s_{p_i} = t_i$ for all $i$ from $1$ to $m$. The width...
def fill(s, t, f): j = 0 i = 0 l = [0] * len(t) while i < m: while t[i] != s[j]: j += 1 if not f: l[i] = n - 1 - j else: l[i] = j i += 1 j += 1 return l n, m = list(map(int, input().split())) s = input() t = input() forwar...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR WHILE VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER IF VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
t = int(input()) for _ in range(t): n = int(input()) k = list(map(int, input().split())) h = list(map(int, input().split())) inter = [] for i in range(n): inter.append([k[i] - h[i], k[i]]) inter.sort() ans = 0 s = -1 e = -1 for i in inter: if i[0] >= e: ...
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 FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR V...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
t = int(input()) while t: n = int(input()) lt = list(map(int, input().split())) lh = list(map(int, input().split())) li = [] for i in range(n): li.append([lt[i] - lh[i] + 1, lt[i]]) li.sort() i = 0 ele = li[0] while ele[-1] != li[-1][-1]: if li[i + 1][0] <= li[i][1]: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR VAR VAR VAR NU...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
def sum_till(n): return n * (n + 1) // 2 for t in range(int(input())): n = int(input()) k = list(map(int, input().split())) h = list(map(int, input().split())) if True: start = [] end = [] for i in range(1, n + 1): st = k[-i] - h[-i] + 1 ed = k[-i] ...
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF NUMBER ASSIGN VAR LIST ASSIGN VAR L...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
for _ in range(int(input())): n = int(input()) k = list(map(int, input().split())) h = list(map(int, input().split())) st = [] for i in range(n): st.append([k[i] - h[i] + 1, k[i]]) st.sort() l, r = -2, -1 ans = 0 for it in st: if it[0] > r: if l != -2 and ...
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 EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR VAR VAR VAR N...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
for i in range(int(input())): n = int(input()) k = list(map(int, input().split())) h = list(map(int, input().split())) l = [h[n - 1]] c = 0 r = k[n - 1] - h[n - 1] + 1 ks = k[n - 1] hs = h[n - 1] for j in range(n - 2, -1, -1): if r <= k[j] - h[j] + 1: continue ...
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 VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR N...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
import sys def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) testcases = int(input()) for _ in range(testcases): _ = int(input()) spawns = input().split() spawns = [int(x) for x in spawns] health = input().split() health = [int(x) for x in health] mana = 0 monsters...
IMPORT FUNC_DEF EXPR FUNC_CALL VAR VAR VAR VAR 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN ...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
testcases = int(input()) for i in range(testcases): n_monster = int(input()) input_1 = input().split() appear_list = list(map(int, input_1)) input_2 = input().split() health_list = list(map(int, input_2)) mana = int(0) for i in range(1, n_monster): for j in range(i): if a...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VA...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
t = int(input()) for _ in range(t): n = int(input()) ks = [int(x) for x in input().split()] hs = [int(x) for x in input().split()] dct = {} for i in range(n): dct[ks[i] - hs[i]] = max(dct.get(ks[i] - hs[i], -1), ks[i]) ds = sorted(dct.keys()) i = 0 ans = 0 while 1: ri...
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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VA...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
for _ in range(int(input())): m = int(input()) monsters = list(map(int, input().split())) health = list(map(int, input().split())) intervals = [] for idx, monster_location in enumerate(monsters): intervals.append([monster_location - health[idx] + 1, monster_location]) intervals.sort(key=...
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 VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR VAR VAR N...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
def solve(n): return n * (n + 1) // 2 t = int(input()) for _ in range(t): n = int(input()) app = list(map(int, input().split())) hea = list(map(int, input().split())) ran = [] for i in range(n): r = app[i] l = app[i] - hea[i] + 1 ran.append([l, r]) ran.sort(key=lamb...
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER 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 FOR VAR...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
import sys input = sys.stdin.readline ans = [] for _ in range(int(input())): n = int(input()) k = list(map(int, input().split())) h = list(map(int, input().split())) a = 0 p = h[-1] q = k[-1] for i in range(n - 2, -1, -1): d = p - (q - k[i]) if d > 0: if d < h[i]...
IMPORT ASSIGN VAR VAR ASSIGN VAR LIST 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 NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMB...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
def processing(monster, power, n): ans = 0 span = power[-1] tail = monster[-1] for i in reversed(range(n - 1)): if monster[i] <= tail - span: ans += span * (span + 1) // 2 span = power[i] tail = monster[i] elif tail - span + 1 <= monster[i] - power[i]:...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR ...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
t = int(input()) out = "" for _ in range(t): n = int(input()) k = [int(x) for x in input().split()] h = [int(x) for x in input().split()] last = k[-1] value = h[-1] for i in range(n - 2, -1, -1): h[i] = max(h[i], value - (last - k[i])) last = k[i] value = h[i] last = ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR 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 VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
import sys input = sys.stdin.readline def helper(a): return a * (a + 1) // 2 def solve(n, arr): ans = helper(arr[0][1]) curr = arr[0][1] for i in range(1, n): d = arr[i][0] - arr[i - 1][0] if d >= arr[i][1]: ans += helper(arr[i][1]) curr = arr[i][1] e...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN V...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
for iq in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) k = -1 ans = 0 for i in range(n - 2, -1, -1): vz = b[k] + a[i] - a[k] if vz <= 0: ans += b[k] * (b[k] + 1) // 2 k = i elif vz < ...
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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN ...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
for _ in range(int(input())): n = int(input()) time = [int(x) for x in input().split()] damage = [int(x) for x in input().split()] biggesttime = n - 1 biggestdamage = n - 1 for j in range(n - 2, -1, -1): diffoftime = time[biggesttime] - time[j] if diffoftime >= damage[biggestdama...
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 BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIG...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
t = int(input()) while t: t -= 1 n = int(input()) k = list(map(int, input().split())) h = list(map(int, input().split())) l = -1 r = -1 res = 0 for i in range(n - 1, -1, -1): if l == -1: r = k[i] l = k[i] - h[i] + 1 elif k[i] < l: res +...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER 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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR ...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
for _ in range(int(input())): n = int(input()) k = list(map(int, input().split())) h = list(map(int, input().split())) a = [] for i in range(n - 1, -1, -1): a.append((k[i] - h[i] + 1, k[i])) a.sort() stack = [] stack.append(a[0]) for i in range(1, n): if stack[-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 LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP B...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
def solve(s, h): ramps = [] i = len(h) - 1 end_ramp = s[i] start_ramp = s[i] - h[i] i -= 1 while 1: if i < 0: break if s[i] > start_ramp: if h[i] <= s[i] - start_ramp: pass else: start_ramp = s[i] - h[i] ...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR NUMBER WHILE NUMBER IF VAR NUMBER IF VAR VAR VAR IF VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR V...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
for _ in range(int(input())): n = int(input()) time = list(map(int, input().split())) health = list(map(int, input().split())) ans = [] for i in range(n): l = time[i] r = time[i] - health[i] + 1 ans.append([r, l]) def fun(x): return x * (x + 1) // 2 arr = so...
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 BIN_OP BIN_OP VAR VAR VAR...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
def cal(a): return a * (a + 1) // 2 t = int(input()) for _ in range(t): n = int(input()) k = [int(i) for i in input().split(" ")] h = [int(i) for i in input().split(" ")] stack = [] ans = 0 for i in range(n): origin = k[i] - h[i] + 1 while stack: if stack[-1][0]...
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER 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 VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NU...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
import sys inp = sys.stdin.readline def getCost(a: int): return a * (a + 1) // 2 for _ in range(int(inp())): n = int(inp()) k = list(map(int, inp().split())) h = list(map(int, inp().split())) ans = 0 segEnd = len(k) - 1 segMax = len(k) - 1 for i in range(len(k) - 2, -1, -1): ...
IMPORT ASSIGN VAR VAR FUNC_DEF VAR RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR N...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
T = int(input()) while T > 0: T -= 1 n = int(input()) k = input().split() h = input().split() for i in range(n): k[i] = int(k[i]) for i in range(n): h[i] = int(h[i]) for i in range(n - 1, 0, -1): for j in range(i - 1, -1, -1): if h[i] - (k[i] - k[j]) > 0 a...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL ...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
for j in range(int(input())): n = int(input()) ks = list(map(int, input().split())) hs = list(map(int, input().split())) ks.insert(0, 0) hs.insert(0, 0) ind = n curr = hs[ind] su = 0 for i in range(n - 1, -1, -1): if ks[ind] - ks[i] < curr: curr += max(0, hs[i] - ...
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 EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR V...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
for t in range(int(input())): n = int(input()) k = [int(i) for i in input().split()] h = [int(i) for i in input().split()] atleast = h[:] for i in range(n - 2, -1, -1): if k[i + 1] - k[i] < atleast[i + 1]: if atleast[i] < atleast[i + 1] - (k[i + 1] - k[i]): atleas...
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 VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
def tr(n): return n * (n + 1) // 2 tests = int(input()) for test in range(tests): n = int(input()) k = list(map(int, input().split())) h = list(map(int, input().split())) res = 0 curh = 0 curk = 2 * 10**9 for i in range(n - 1, -1, -1): if curk - k[i] >= curh: res +=...
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER 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 NUMBER ASSIG...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
for _ in range(int(input())): n = int(input()) s = input() ks = s.split() s = input() hs = s.split() arr = [] for i in range(n): arr.append([int(ks[i]) - int(hs[i]) + 1, int(ks[i])]) arr.sort() a = [arr[0][0], arr[0][1]] ans = 0 for i in range(1, n): if arr[i]...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
t = int(input()) for _ in range(t): n = int(input()) tm = list(map(int, input().split())) hm = list(map(int, input().split())) lstS = [tm[0] - hm[0] + 1] lstE = [tm[0]] for i in range(1, n): e = tm[i] s = tm[i] - hm[i] + 1 if len(lstS) == 0: lstS.append(s) ...
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 BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR LIST VAR NUM...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
def sum_till(n): return n * (n + 1) // 2 for _ in range(int(input())): n = int(input()) arrivals = list(map(int, input().split())) healths = list(map(int, input().split())) intervals = [] for i, arrival in enumerate(arrivals): this_r = arrival this_l = arrival - healths[i] + 1 ...
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL ...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
def summ(n): return n * (n + 1) // 2 for _ in range(int(input())): n = int(input()) k = list(map(int, input().split())) h = list(map(int, input().split())) s = [] s.append([k[0], h[0]]) for i in range(1, n): while len(s) > 0: prevtime = s[-1][0] prevh = s[-1...
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR LIS...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
for t in range(int(input())): n = int(input()) ls = list(map(int, input().strip().split())) lh = list(map(int, input().strip().split())) lis = [] lis.append((ls[0] - lh[0] + 1, ls[0])) for i in range(1, n): a = ls[i] - lh[i] + 1 if a <= lis[-1][1] and lis[-1][0] <= a: ...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
t = int(input()) ans = [] while t > 0: t -= 1 n = int(input()) otv = 0 time = list(map(int, input().split())) x = list(map(int, input().split())) st = [] for i in range(n): st.append([time[i] - x[i], time[i]]) st.sort() l, r = -1, -1 for it in st: if it[0] >= r: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER 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 EXPR...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
answer = [] for _ in range(int(input())): n = int(input()) k = list(map(int, input().split())) h = list(map(int, input().split())) count = 0 k_r = k[-1] k_l = k[-1] - h[-1] + 1 for i in range(n - 2, -1, -1): if k_l <= k[i]: pass else: count += (k_r - k...
ASSIGN VAR LIST 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 NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR N...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
t = int(input()) for i in range(t): n = int(input()) seconds = [int(el) for el in input().split(" ")] points = [int(el) for el in input().split(" ")] current = points[-1] for z in range(n - 2, -1, -1): h = points[z] diff = seconds[z + 1] - seconds[z] points[z] = max([h, curre...
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 VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR V...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
for _ in range(int(input())): n = int(input()) k = list(map(int, input().split())) h = list(map(int, input().split())) s = [] for i in range(n): s.append((k[i] - h[i] + 1, k[i])) ans = [] i = n - 1 while i != 0: a = s[i] b = s[i - 1] if a[0] <= b[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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
def problemC(n, seconds, health): intervals = [] for i in range(n): intervals.append((seconds[i] - health[i] + 1, seconds[i])) intervals.sort() l, r = -1, -2 ans = 0 for left, right in intervals: if left > r: ans += (r - l + 1) * (r - l + 2) // 2 l, r = le...
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR ASSIGN...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
import sys def solve(): inp = sys.stdin.readline inp() k = list(map(int, inp().split())) h = list(map(int, inp().split())) i = 0 while i < len(h): j = i + 1 while j < len(h): s = k[j] - h[j] + 1 if s <= k[i]: if h[j] < h[i] + (k[j] - k[i]...
IMPORT FUNC_DEF ASSIGN VAR 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 NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR ...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters. The level he's currently on contains $n$ monsters. The $i$-th of them appears $k_i$ seconds after the start of the level and has $h_i$ health points. As an additional c...
T = int(input()) def calc(n): return (n + 1) * n // 2 def solve(): n = int(input()) k = list(map(int, input().split())) h = list(map(int, input().split())) ranges = [] for i in range(n): ranges += [(k[i] - (h[i] - 1), k[i])] ranges = sorted(ranges) cur_l = ranges[0][0] cu...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF 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 VA...
Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence a_1, a_2, ..., a_{n} of n integer numbers β€” saturation of the color of each pencil. Now Mishka want...
n, k, d = list(map(int, input().split())) a = sorted(list(map(int, input().split()))) b = [0] * n i = j = 0 for i in range(n): while a[i] - a[j] > d: j += 1 b[i] = j c = [0] * n for i in range(k - 1, n): c[i] = c[i - 1] + int( i - b[i] + 1 >= k and (b[i] == 0 or c[i - k] > c[b[i] - 2...
ASSIGN VAR VAR 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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP L...
Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence a_1, a_2, ..., a_{n} of n integer numbers β€” saturation of the color of each pencil. Now Mishka want...
def getIntList(): return list(map(int, input().split())) def getTransIntList(n): first = getIntList() m = len(first) result = [([0] * n) for _ in range(m)] for i in range(m): result[i][0] = first[i] for j in range(1, n): curr = getIntList() for i in range(m): ...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CA...
Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence a_1, a_2, ..., a_{n} of n integer numbers β€” saturation of the color of each pencil. Now Mishka want...
def bi_search(a, x): n = len(a) u, l = n, -1 while u - l > 1: md = (u + l) // 2 if x > a[md]: l = md else: u = md return u class Bit: def __init__(self, n): self.bit = [0] * (n + 1) self.n = n def sum_prefix(self, i): s ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VA...
Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence a_1, a_2, ..., a_{n} of n integer numbers β€” saturation of the color of each pencil. Now Mishka want...
n, k, d = map(int, input().split()) A = sorted(map(int, input().split())) can_do = [0] * (n + 1) can_do[0] = 1 l, r = 0, 0 for i, a in enumerate(A, start=1): while a - d > A[l]: l += 1 r = i - k can = 0 if r >= l: s = can_do[r] if l: s -= can_do[l - 1] if s > ...
ASSIGN VAR 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BI...
Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence a_1, a_2, ..., a_{n} of n integer numbers β€” saturation of the color of each pencil. Now Mishka want...
import sys readline = sys.stdin.readline class Segtree: def __init__(self, A, intv, initialize=True, segf=max): self.N = len(A) self.N0 = 2 ** (self.N - 1).bit_length() self.intv = intv self.segf = segf if initialize: self.data = [intv] * self.N0 + A + [intv] ...
IMPORT ASSIGN VAR VAR CLASS_DEF FUNC_DEF NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST VAR VAR VAR BIN_OP LIST VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR ...
Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence a_1, a_2, ..., a_{n} of n integer numbers β€” saturation of the color of each pencil. Now Mishka want...
import sys n, k, d = map(int, input().split()) a = [0] + sorted(map(int, input().split())) dp = [1] + [0] * n j = k for i in range(n): if dp[i] == 0: continue j = max(j, i + k) while j <= n and a[j] - a[i + 1] <= d: dp[j] |= dp[i] j += 1 print("YES" if dp[-1] else "NO")
IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR WHILE VAR ...
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of n rows and m columns. By a_{i}, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted...
from sys import stdin n, m = list(map(int, stdin.readline().rstrip().split())) data = [] for i in range(0, n): data.append(list(map(int, stdin.readline().rstrip().split()))) sorted_data = [0] * n for col in range(0, m): mark_r = 0 cur_r = 1 st = [] while cur_r < n: if data[cur_r][col] < dat...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER AS...
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of n rows and m columns. By a_{i}, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted...
import sys input = sys.stdin.readline n, m = map(int, input().split()) a = [list(map(int, input().split())) for i in range(n)] v = [([1] * m) for i in range(n)] for j in range(m): for i in range(n - 1)[::-1]: if a[i][j] <= a[i + 1][j]: v[i][j] = v[i + 1][j] + 1 max_l = [max(arr) for arr in v] q...
IMPORT ASSIGN 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 VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR BIN_...
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of n rows and m columns. By a_{i}, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted...
def ri(): return map(int, input().split()) n, m = ri() a = [] for i in range(n): a.append(list(ri())) t = [[(0) for i in range(m)] for j in range(n)] T = [(0) for i in range(n)] for i in range(m): for j in range(n - 1): if a[j][i] > a[j + 1][i]: t[j + 1][i] = 0 else: ...
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CAL...
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of n rows and m columns. By a_{i}, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted...
n, m = map(int, input().split()) Table = [] for r in range(n): row = list(map(int, input().split())) Table.append(row) k = int(input()) Tasklist = [] for task in range(k): l, r = map(int, input().split()) Tasklist.append([l, r]) locate = [0] * (n + 1) for c in range(m): start = 0 for r in range(...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CA...
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of n rows and m columns. By a_{i}, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted...
from sys import stdin, stdout def main(): n, m = map(int, stdin.readline().split()) k = [] for i in range(n): k.append(list(map(int, stdin.readline().split()))) ans = [] BASE = [(1) for i in range(m)] ans.append(list(BASE)) for i in range(1, n): ans.append(list(BASE)) ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_C...
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of n rows and m columns. By a_{i}, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted...
import sys input = sys.stdin.readline mod = 1000000007 def gcd(a, b): if a == 0: return b return gcd(b % a, a) def lcm(a, b): return a * b / gcd(a, b) def main(): n, m = map(int, input().split()) a = [] fei = [] maxi = [(1) for i in range(n)] for i in range(n): a.a...
IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR ...
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of n rows and m columns. By a_{i}, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted...
n, m = map(int, input().split()) l = [] ans = [] for i in range(n): k = list(map(int, input().split())) l.append(k) c = [1] * len(k) ans.append(c) hash = {} for j in range(m): count = 0 for i in range(1, n): if l[i][j] >= l[i - 1][j]: ans[i][j] = ans[i - 1][j] else: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR AS...
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of n rows and m columns. By a_{i}, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted...
import sys N, M = list(map(int, input().split())) G = [list(map(int, input().split())) for i in range(N)] rmaxv = [(0) for i in range(N)] for i in range(M): reach = [(0) for j in range(N)] for j in range(N - 1, -1, -1): if j + 1 == N or not G[j][i] <= G[j + 1][i]: reach[j] = 1 else:...
IMPORT 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 VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ...
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of n rows and m columns. By a_{i}, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted...
import sys def debug(x, table): for name, val in table.items(): if x is val: print("DEBUG:{} -> {}".format(name, val), file=sys.stderr) return None def solve(): n, m = map(int, sys.stdin.readline().split()) A = [[int(i) for i in sys.stdin.readline().split()] for j in rang...
IMPORT FUNC_DEF FOR VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR RETURN NONE FUNC_DEF ASSIGN VAR VAR FUNC_CALL 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 FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FU...
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of n rows and m columns. By a_{i}, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted...
from sys import stdin, stdout n, m = map(int, stdin.readline().strip().split()) arr = [list(map(int, stdin.readline().strip().split())) for i in range(n)] dp = [[(1) for i in range(m)] for i in range(n)] for i in range(1, n): for j in range(m): if arr[i][j] >= arr[i - 1][j]: dp[i][j] = dp[i - 1...
ASSIGN VAR 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 VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUM...
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of n rows and m columns. By a_{i}, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted...
from sys import stdin, stdout n, m = map(int, stdin.readline().split()) ans = [float("infinity")] * n cou = [0] * m A = [0] * n A[0] = list(map(int, stdin.readline().split())) ans[0] = 0 for j in range(1, n): A[j] = list(map(int, stdin.readline().split())) for i in range(m): if A[j][i] < A[j - 1][i]: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR ...
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of n rows and m columns. By a_{i}, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted...
from sys import stdin n, m = [int(i) for i in stdin.readline().split()] arr = [[int(i) for i in stdin.readline().split()] for _ in range(n)] temp = [[(1) for i in range(m)] for _ in range(n)] for i in range(m): for j in range(n - 2, -1, -1): if arr[j][i] <= arr[j + 1][i]: temp[j][i] += temp[j +...
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 VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR BIN_OP VAR NUMBER V...
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of n rows and m columns. By a_{i}, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted...
n, m = map(int, input().split()) A = [] for _ in range(n): A.append(list(map(int, input().split()))) dp = [[(1) for _ in range(m)] for _ in range(n)] best = [(1) for _ in range(n)] for i in range(1, n): for j in range(m): if A[i][j] >= A[i - 1][j]: dp[i][j] = dp[i - 1][j] + 1 bes...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUN...
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of n rows and m columns. By a_{i}, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted...
from sys import stdin, stdout n, m = map(int, stdin.readline().split()) values = [] for i in range(n): values.append(list(map(int, stdin.readline().split()))) d = {} questions = [] k = int(stdin.readline()) for i in range(k): l, r = map(int, stdin.readline().split()) questions.append((l, r)) for j in range...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_C...
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of n rows and m columns. By a_{i}, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted...
import sys input = sys.stdin.buffer.readline n, m = map(int, input().split()) arr = [] for i in range(n): arr.append(list(map(int, input().split()))) ans = [n + 3] * n ans[0] = 0 dp = [0] * m for i in range(1, n): for j in range(m): if arr[i][j] < arr[i - 1][j]: dp[j] = i ans[i] = m...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VA...
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of n rows and m columns. By a_{i}, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted...
import sys input = sys.stdin.readline n, m = map(int, input().split()) arr = [] for i in range(n): arr.append(list(map(int, input().split()))) mp = [] for i in range(n): mp.append(i + 1) for i in range(m): pre = -1 st = 0 for j in range(n): if arr[j][i] < pre: pre = arr[j][i] ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL 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 BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER A...
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of n rows and m columns. By a_{i}, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted...
import sys input = sys.stdin.readline n, m = map(int, input().split()) a = [] for i in range(n): a.append(list(map(int, input().split()))) count = [[(1) for i in range(m)] for j in range(n)] for i in range(1, n): for j in range(m): if a[i][j] >= a[i - 1][j]: count[i][j] = count[i - 1][j] + ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF ...
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of n rows and m columns. By a_{i}, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted...
import sys input = sys.stdin.readline n, m = list(map(int, input().split())) M = [[] for i in range(m)] for i in range(n): z = list(map(int, input().split())) for i in range(len(z)): M[i].append(z[i]) dp = [(0) for i in range(n)] dp[-1] = 1 for i in range(len(M)): x = M[i] temp = [(0) for i in ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUN...
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of n rows and m columns. By a_{i}, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted...
from sys import stdin lines = stdin.readlines() n = int(lines[0].split(" ")[0]) m = int(lines[0].split(" ")[1]) base_dict = {(i + 1): (i + 1) for i in range(n)} def yes_or_no(max_array, ll): l = int(ll[0]) r = int(ll[1]) if max_array[l - 1] >= r: return "Yes" return "No" a = [[int(i) for i ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER STRING NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER STRING NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ...
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of n rows and m columns. By a_{i}, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted...
n, m = [int(x) for x in input().split()] arr = [[int(x) for x in input().split()] for i in range(0, n)] p = [i for i in range(0, n + 1)] for j in range(0, m): cur = 0 for i in range(0, n - 1): if arr[i][j] <= arr[i + 1][j]: p[i + 1] = min(cur, p[i + 1]) else: cur = i + 1 ...
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 VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VA...
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of n rows and m columns. By a_{i}, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted...
from sys import stdin input = stdin.readline n, m = map(int, input().split()) arr = list(list(map(int, input().split())) for _ in range(n)) dp = [[(1) for i in range(m)] for j in range(n)] for i in range(1, n): for j in range(m): if arr[i][j] >= arr[i - 1][j]: dp[i][j] = dp[i - 1][j] + 1 dp, al...
ASSIGN VAR VAR 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 VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_O...
This is a hard version of the problem. In this version, the given array can contain equal elements and the constraints on $n$ are greater than in the easy version of the problem. You are given an array $a$ of $n$ integers (the given array can contain equal elements). You can perform the following operations on array e...
import sys int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_numb...
IMPORT ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF...
This is a hard version of the problem. In this version, the given array can contain equal elements and the constraints on $n$ are greater than in the easy version of the problem. You are given an array $a$ of $n$ integers (the given array can contain equal elements). You can perform the following operations on array e...
from sys import stdin, stdout def flying_sort(n, a): b = sorted(a) dic = {} seq = 1 dic[b[0]] = seq num = [(0) for i in range(n + 1)] head = [(0) for i in range(n + 1)] tail = [(-1) for i in range(n + 1)] pos = [(0) for i in range(n + 1)] for i in range(1, len(b)): if b[i] ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VA...
This is a hard version of the problem. In this version, the given array can contain equal elements and the constraints on $n$ are greater than in the easy version of the problem. You are given an array $a$ of $n$ integers (the given array can contain equal elements). You can perform the following operations on array e...
from sys import stdin for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) id = list(zip(l, list(range(n)))) id.sort() val, pos = zip(*id) blok = [] cur = [pos[0]] for i in range(1, n): if val[i] == val[i - 1]: cur.append(pos[i]) ...
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 VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST VAR N...
This is a hard version of the problem. In this version, the given array can contain equal elements and the constraints on $n$ are greater than in the easy version of the problem. You are given an array $a$ of $n$ integers (the given array can contain equal elements). You can perform the following operations on array e...
for t in range(int(input())): n = int(input()) aa = list(map(int, input().split(" "))) asort = sorted([(v, i) for i, v in enumerate(aa)]) inds = {} for a, ai in asort: if a not in inds: inds[a] = [] inds[a] += [ai] def left_eq(b, i): binds = inds[b] l...
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 ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR LIST VAR VAR LIST VAR FUNC_DEF ASSIGN VA...
This is a hard version of the problem. In this version, the given array can contain equal elements and the constraints on $n$ are greater than in the easy version of the problem. You are given an array $a$ of $n$ integers (the given array can contain equal elements). You can perform the following operations on array e...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) p = [] for i in range(n): p.append((a[i], i)) p.sort(key=lambda x: x[0]) aOrder = [-1] * n curIndex = 0 for i in range(n): if i >= 1 and p[i][0] != p[i - 1][0]: curIndex +...
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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR N...
This is a hard version of the problem. In this version, the given array can contain equal elements and the constraints on $n$ are greater than in the easy version of the problem. You are given an array $a$ of $n$ integers (the given array can contain equal elements). You can perform the following operations on array e...
import sys def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) def solve(): n = mint() b = [None] * n i = 0 for v in mints(): b[i] = v, i i += 1 b.sort() c = [0] * n ans = int(10000000...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR B...
There are $n$ cities numbered from $1$ to $n$, and city $i$ has beauty $a_i$. A salesman wants to start at city $1$, visit every city exactly once, and return to city $1$. For all $i\ne j$, a flight from city $i$ to city $j$ costs $\max(c_i,a_j-a_i)$ dollars, where $c_i$ is the price floor enforced by city $i$. Note ...
n = int(input()) a = [[int(s) for s in input().split(" ")] for i in range(n)] a.sort() ans, c = a[0][1], sum(a[0]) for w in a[1:]: ans += w[1] + max(w[0] - c, 0) c = max(c, sum(w)) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_...
There are $n$ cities numbered from $1$ to $n$, and city $i$ has beauty $a_i$. A salesman wants to start at city $1$, visit every city exactly once, and return to city $1$. For all $i\ne j$, a flight from city $i$ to city $j$ costs $\max(c_i,a_j-a_i)$ dollars, where $c_i$ is the price floor enforced by city $i$. Note ...
import sys N = int(input()) lst = [] for n in range(N): l = list(map(int, sys.stdin.readline().split())) lst.append(l) lst.sort() Sum = lst[0][1] c = lst[0][0] + lst[0][1] for i in lst[1:]: Sum += i[1] if i[0] > c: Sum += i[0] - c c = max(c, i[0] + i[1]) print(Sum)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR VAR NUMBER VAR VAR NUMBER IF VAR...
There are $n$ cities numbered from $1$ to $n$, and city $i$ has beauty $a_i$. A salesman wants to start at city $1$, visit every city exactly once, and return to city $1$. For all $i\ne j$, a flight from city $i$ to city $j$ costs $\max(c_i,a_j-a_i)$ dollars, where $c_i$ is the price floor enforced by city $i$. Note ...
n = int(input()) cities = [] ans = 0 for i in range(n): a, c = map(int, input().split()) cities += [(a, c)] ans += c cities = sorted(cities, key=lambda city: city[0]) mx = cities[0][0] + cities[0][1] for i in range(1, n): ans += max(0, cities[i][0] - mx) mx = max(mx, cities[i][0] + cities[i][1]) pri...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR LIST VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CAL...
There are $n$ cities numbered from $1$ to $n$, and city $i$ has beauty $a_i$. A salesman wants to start at city $1$, visit every city exactly once, and return to city $1$. For all $i\ne j$, a flight from city $i$ to city $j$ costs $\max(c_i,a_j-a_i)$ dollars, where $c_i$ is the price floor enforced by city $i$. Note ...
import sys input = sys.stdin.readline n = int(input()) l = [] out = 0 for _ in range(n): a, c = map(int, input().split()) out += c l.append((a, c)) l.sort(key=lambda x: x[0]) curr_best = l[0][0] for a, c in l: if a > curr_best: out += a - curr_best curr_best = max(curr_best, a + c) print(ou...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR AS...
There are $n$ cities numbered from $1$ to $n$, and city $i$ has beauty $a_i$. A salesman wants to start at city $1$, visit every city exactly once, and return to city $1$. For all $i\ne j$, a flight from city $i$ to city $j$ costs $\max(c_i,a_j-a_i)$ dollars, where $c_i$ is the price floor enforced by city $i$. Note ...
from sys import stdin, stdout def travelling_salesman(n, ac_a): ac_a.sort() pre = 0 lmax = ac_a[0][0] + ac_a[0][1] r = ac_a[0][1] for i in range(1, n): if lmax < ac_a[i][0] + ac_a[i][1]: pre = i r += max(0, ac_a[i][0] - lmax) lmax = ac_a[i][0] + ac_a[i][...
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER ...
There are $n$ cities numbered from $1$ to $n$, and city $i$ has beauty $a_i$. A salesman wants to start at city $1$, visit every city exactly once, and return to city $1$. For all $i\ne j$, a flight from city $i$ to city $j$ costs $\max(c_i,a_j-a_i)$ dollars, where $c_i$ is the price floor enforced by city $i$. Note ...
n = int(input()) price = [] total = 0 for i in range(n): a, c = map(int, input().split()) price.append((a, a + c)) total = total + c price.sort() current = price[0][0] for i, j in price: total = total + max(0, i - current) current = max(current, j) print(total)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR ...
There are $n$ cities numbered from $1$ to $n$, and city $i$ has beauty $a_i$. A salesman wants to start at city $1$, visit every city exactly once, and return to city $1$. For all $i\ne j$, a flight from city $i$ to city $j$ costs $\max(c_i,a_j-a_i)$ dollars, where $c_i$ is the price floor enforced by city $i$. Note ...
import sys input = sys.stdin.readline n = int(input()) l = [] ans = 0 for i in range(n): d = input().split() l.append((int(d[0]), int(d[1]))) ans += int(d[1]) l.sort() maxa = l[0][0] + l[0][1] for i in range(1, n): if l[i][0] > maxa: ans += l[i][0] - maxa maxa = max(maxa, l[i][0] + l[i][1])...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ...
There are $n$ cities numbered from $1$ to $n$, and city $i$ has beauty $a_i$. A salesman wants to start at city $1$, visit every city exactly once, and return to city $1$. For all $i\ne j$, a flight from city $i$ to city $j$ costs $\max(c_i,a_j-a_i)$ dollars, where $c_i$ is the price floor enforced by city $i$. Note ...
import sys sys.setrecursionlimit(10**5) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LI1(): return list(map(int1, sys.stdin.buffer.readline().split())) def L...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_D...
There are $n$ cities numbered from $1$ to $n$, and city $i$ has beauty $a_i$. A salesman wants to start at city $1$, visit every city exactly once, and return to city $1$. For all $i\ne j$, a flight from city $i$ to city $j$ costs $\max(c_i,a_j-a_i)$ dollars, where $c_i$ is the price floor enforced by city $i$. Note ...
import sys input = sys.stdin.readline n = int(input()) cit = [] ccost = 0 for i in range(n): a, c = map(int, input().split()) cit.append([a, c]) ccost += c acost = 0 cit.sort() mx = cit[0][0] + cit[0][1] for c in cit: if c[0] > mx: acost += c[0] - mx mx = max(mx, sum(c)) print(acost + ccost...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER 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 VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR VAR...
There are $n$ cities numbered from $1$ to $n$, and city $i$ has beauty $a_i$. A salesman wants to start at city $1$, visit every city exactly once, and return to city $1$. For all $i\ne j$, a flight from city $i$ to city $j$ costs $\max(c_i,a_j-a_i)$ dollars, where $c_i$ is the price floor enforced by city $i$. Note ...
import sys mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.buffer.readline N = int(input()) AC = [] ans = 0 for i in range(N): a, c = map(int, input().split()) AC.append((a, c, i)) ans += c AC.sort(key=lambda x: x[1]) AC.sort(key=lambda ...
IMPORT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FU...
There are $n$ cities numbered from $1$ to $n$, and city $i$ has beauty $a_i$. A salesman wants to start at city $1$, visit every city exactly once, and return to city $1$. For all $i\ne j$, a flight from city $i$ to city $j$ costs $\max(c_i,a_j-a_i)$ dollars, where $c_i$ is the price floor enforced by city $i$. Note ...
import sys input = sys.stdin.readline n = int(input()) keyframes = [] ans = 0 for i in range(n): a, c = map(int, input().split()) ans += c keyframes.append((a, -1)) keyframes.append((a + c, 0)) keyframes.sort() count = 0 a, b = keyframes[0] prev = a for pos, t in keyframes: if t == -1: if c...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER ...
There are $n$ cities numbered from $1$ to $n$, and city $i$ has beauty $a_i$. A salesman wants to start at city $1$, visit every city exactly once, and return to city $1$. For all $i\ne j$, a flight from city $i$ to city $j$ costs $\max(c_i,a_j-a_i)$ dollars, where $c_i$ is the price floor enforced by city $i$. Note ...
n = int(input()) a = sorted([*map(int, input().split())] for i in range(n)) c = sum(a[0]) t = a[0][1] for w in a[1:]: t += w[1] if w == a[-1] or sum(w) > c: t += max(w[0] - c, 0) c = sum(w) print(t)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER A...
There are $n$ cities numbered from $1$ to $n$, and city $i$ has beauty $a_i$. A salesman wants to start at city $1$, visit every city exactly once, and return to city $1$. For all $i\ne j$, a flight from city $i$ to city $j$ costs $\max(c_i,a_j-a_i)$ dollars, where $c_i$ is the price floor enforced by city $i$. Note ...
n = int(input()) l = [list(map(int, input().split())) for _ in range(n)] l.sort() t = [l[0][0], l[0][1] + l[0][0]] ans = 0 for a, c in l: ans += c p = a q = a + c if t[-1] < p: t.append(p) t.append(q) else: t[-1] = max(t[-1], q) for i in range(1, len(t) - 1, 2): ans += t[...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER...
There are $n$ cities numbered from $1$ to $n$, and city $i$ has beauty $a_i$. A salesman wants to start at city $1$, visit every city exactly once, and return to city $1$. For all $i\ne j$, a flight from city $i$ to city $j$ costs $\max(c_i,a_j-a_i)$ dollars, where $c_i$ is the price floor enforced by city $i$. Note ...
import sys from sys import stdin n = int(stdin.readline()) ans = 0 ac = [] LAC = [] RAC = [] for i in range(n): a, c = map(int, stdin.readline().split()) ans += c ac.append((a, c)) LAC.append((a, c)) LAC.sort() nans1 = 0 nmax = LAC[0][0] + LAC[0][1] for ac in LAC: a, c = ac if nmax < a: ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMB...
There are $n$ cities numbered from $1$ to $n$, and city $i$ has beauty $a_i$. A salesman wants to start at city $1$, visit every city exactly once, and return to city $1$. For all $i\ne j$, a flight from city $i$ to city $j$ costs $\max(c_i,a_j-a_i)$ dollars, where $c_i$ is the price floor enforced by city $i$. Note ...
n = int(input()) inps = [] ans = 0 for i in range(n): a, c = map(int, input().split()) ans += c inps.append((a, c)) inps.sort() topcover = inps[0][0] for i in range(len(inps)): if inps[i][0] > topcover: ans += inps[i][0] - topcover topcover = max(topcover, inps[i][0] + inps[i][1]) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR BIN_OP VAR VAR ...