description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
t = int(input()) for _ in range(t): n = int(input()) s = [int(x) for x in input().split()] m = int(input()) L = [] for i in range(m): pi, si = map(int, input().split()) L.append((pi, si)) edu = [0] * (n + 1) for i in range(0, len(L)): edu[L[i][1]] = max(edu[L[i][1]], ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL 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_CALL VAR EXPR FUNC_CALL VAR VA...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
import sys input = sys.stdin.readline T = int(input()) Ans = [] for _ in range(T): N = int(input()) A = list(map(int, input().split())) M = int(input()) PS = [list(map(int, input().split())) for _ in range(M)] L = [0] * (N + 1) for p, s in PS: L[s] = max(L[s], p) for i in range(N - ...
IMPORT ASSIGN VAR VAR 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 ASSIGN 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 VAR FUNC_CALL FUNC_CALL VAR VAR F...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
o = int(input()) for _ in range(0, o): n = int(input()) lis = [0] + list(map(int, input().split())) m = int(input()) l = [0] * (n + 1) for i in range(0, m): p, s = map(int, input().split()) l[s] = max(l[s], p) for i in range(n - 1, -1, -1): l[i] = max(l[i], l[i + 1]) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASS...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
t = int(input()) for r in range(0, t): n = int(input()) a = list(map(int, input().split())) monster = max(a) m = int(input()) h = list(tuple(map(int, input().split())) for i in range(m)) h.sort() if monster > h[m - 1][0]: print(-1) continue i = m - 2 last = h[m - 1][1...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CA...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
from sys import * input = stdin.readline for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) d = [(0) for i in range(n + 1)] for i in range(int(input())): p, e = map(int, input().split()) d[e] = max(d[e], p) for i in range(n - 1, -1, -1): d[i] ...
ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FU...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) m = int(input()) p = [] s = [] for i in range(m): x, y = map(int, input().split()) p.append(x) s.append(y) bst = [(0) for i in range(n + 1)] for i in range(m): bst[s[i]] = m...
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 ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
import sys sin = sys.stdin t = int(sin.readline()) for _ in range(t): n = int(sin.readline()) monpows = [int(x) for x in sin.readline().split()] m = int(sin.readline()) endtopow = dict() maxhero = 0 for _ in range(m): h = [int(x) for x in sin.readline().split()] maxhero = max(ma...
IMPORT ASSIGN 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 VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
import sys input = sys.stdin.readline def init_max(init_max_val): for i in range(n): seg_max[i + num_max - 1] = init_max_val[i] for i in range(num_max - 2, -1, -1): seg_max[i] = max(seg_max[2 * i + 1], seg_max[2 * i + 2]) def update_max(k, x): k += num_max - 1 seg_max[k] = x whi...
IMPORT ASSIGN VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR ...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
import sys readline = sys.stdin.readline mr = lambda: map(int, readline().split()) t = int(readline()) Ans = [] for _ in range(t): n = int(readline()) monsters = list(mr()) m = int(readline()) heroes = [tuple(mr()) for _ in range(m)] tmp = [0] * (n + 1) for x in heroes: tmp[x[1]] = max(...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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 ASSIGN 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...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
import sys for t in range(int(sys.stdin.readline())): mm = int(sys.stdin.readline()) m = [int(i) for i in sys.stdin.readline().split()] hh = int(sys.stdin.readline()) h = [] for j in range(hh): h.append([int(i) for i in sys.stdin.readline().split()]) dp = [-1] * (mm + 1) for hhh in ...
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIS...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
import sys input = sys.stdin.readline class RangeMinimumQuery: def __init__(self, n, func=min, inf=float("inf")): self.n0 = 2 ** (n - 1).bit_length() self.op = func self.inf = inf self.data = [self.inf] * (2 * self.n0 - 1) def query(self, l, r): l += self.n0 ...
IMPORT ASSIGN VAR VAR CLASS_DEF FUNC_DEF VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER FUNC_CALL BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR V...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
import sys input = sys.stdin.readline t = int(input()) ANS = [] for _ in range(t): n = int(input()) a = list(map(int, input().split())) m = int(input()) ps = [list(map(int, input().split())) for _ in range(m)] p = [0] * (n + 1) for i in range(m): p[ps[i][1]] = max(p[ps[i][1]], ps[i][0])...
IMPORT ASSIGN VAR VAR 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 ASSIGN 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 VAR FUNC_CALL FUNC_CALL VAR VAR F...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
import sys input = sys.stdin.readline t = int(input()) while t: t -= 1 n = int(input()) a = list(map(int, input().split())) m = int(input()) heros = [] for _ in range(m): p, e = map(int, input().split()) heros.append((p, e)) bst = [0] * n for p, e in heros: bst[e...
IMPORT ASSIGN VAR VAR 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 ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CAL...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) h = int(input()) he = [] dp = [0] * (n + 2) for _ in range(h): p, s = list(map(int, input().split())) he.append([p, s]) dp[s] = max(dp[s], p) ...
IMPORT ASSIGN 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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VA...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
import sys input = lambda: sys.stdin.readline().strip() print = lambda s: sys.stdout.write(s) t = int(input()) for i in range(t): n = int(input()) ls1 = list(map(int, input().split())) m = int(input()) ls2 = [] for i in range(m): ls2.append(tuple(map(int, input().split()))) if max(ls1) ...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR V...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
import sys input = sys.stdin.readline for nt in range(int(input())): n = int(input()) l = list(map(int, input().split())) m = int(input()) maxx = {} for i in range(m): a, b = map(int, input().split()) if b not in maxx: maxx[b] = a else: maxx[b] = max(...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF V...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) m = int(input()) b = [tuple(map(int, input().split())) for __ in range(m)] ans = 1 mx = [0] * (n + 1) for p, s in b: mx[s] = max(mx[s], p) for i in range(n - 1, -1, -1): mx[i] = max(m...
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASS...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
import sys def I(): return sys.stdin.readline().rstrip() for _ in range(int(I())): n = int(I()) a = list(map(int, I().split())) m = int(I()) pl = sorted([list(map(int, I().split())) for _ in range(m)]) pln, mxs = [], 0 for x in pl[::-1]: if x[1] > mxs: pln.append(x) ...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL V...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) m = int(input()) h = [tuple(map(int, input().split())) for i in range(m)] h.sort(reverse=True) new_h = [] prev = 0 for p, s in h: if s > prev: new_h.append((p, s)) pre...
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NU...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
t = int(input()) for i in range(t): n = int(input()) monsters = list(map(int, input().split())) m = int(input()) dct = {} lst = [] now = 0 index = 0 for j in range(m): a, b = list(map(int, input().split())) if b > now or b == now and dct[index][0] < a: index =...
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 ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR F...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
import sys readline = sys.stdin.readline readlines = sys.stdin.readlines ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep="\n") def solve(): n = ni() a = nl() m = ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN 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 STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VA...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
q = int(input()) for i in range(q): n = int(input()) a = input().split(" ") a = [int(a[k]) for k in range(n)] m = int(input()) p = list() s = list() dp = [(0) for j in range(n + 1)] for j in range(m): l = input().split(" ") l = [int(l[k]) for k in range(0, 2)] p.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 STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CAL...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
import sys class SegmentTree: def __init__(self, arr, func, initialRes=0): self.f = func self.N = len(arr) self.tree = [(0) for _ in range(4 * self.N)] self.initialRes = initialRes for i in range(self.N): self.tree[self.N + i] = arr[i] for i in range(se...
IMPORT CLASS_DEF FUNC_DEF NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_O...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
from sys import stdin t = int(stdin.readline()) for _ in range(t): n = int(stdin.readline()) x = list(map(int, stdin.readline().split())) m = int(stdin.readline()) v, v2 = [], [] for i in range(m): p, s = map(int, stdin.readline().split()) v2.append([p, s]) v2.sort() for i i...
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 ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EX...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
from sys import stdin def iin(): return int(stdin.readline()) def lin(): return list(map(int, stdin.readline().split())) def main(): t = iin() while t: t -= 1 n = iin() a = lin() m = iin() h = [lin()[::-1] for i in range(m)] h.sort(reverse=True) ...
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 ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR N...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
import sys def main(): t = int(input()) allans = [] for _ in range(t): n = int(input()) a = readIntArr() m = int(input()) ps = [] for __ in range(m): ps.append(readIntArr()) maxMonsterPower = max(a) maxHeroPower = 0 for p, s in ps...
IMPORT FUNC_DEF 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 ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBE...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) m = int(input()) heroes = [] bst = [(0) for i in range(n + 1)] for _ in range(m): x, y = map(int, input().split()) bst[y] = max(bst[y], x) for i in range(n - 1, -1, -1): bst[i] = ...
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 ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
from sys import stdin input = stdin.readline q = int(input()) for rew in range(q): n = int(input()) monster = list(map(int, input().split())) m = int(input()) rycerz = [list(map(int, input().split())) for i in range(m)] rycerz.sort() rycerz.reverse() p = [a[0] for a in rycerz] s = [a[1]...
ASSIGN 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 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 VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR F...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
tests = int(input()) for i in range(tests): rez = 0 k = 0 n = int(input()) powers = list(map(int, input().split())) m = int(input()) vect = [] powers = [0] + powers vect = [0] * (n + 1) for j in range(0, m): prop = list(map(int, input().split())) p = prop[0] s...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN 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 ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST N...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
from sys import stdin def input(): return next(stdin) def main(): def solve(): n = int(input()) aa = [int(a) for a in input().split()] m = int(input()) pso = [] for _ in range(m): p, s = map(int, input().split()) pso.append((p, s)) pso...
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF 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 FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FU...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
import sys for _ in range(int(input())): n = int(sys.stdin.readline()) mons = list(map(int, sys.stdin.readline().split())) m = int(sys.stdin.readline()) _heros = sorted( (tuple(map(int, sys.stdin.readline().split())) for _ in range(m)), reverse=True ) max_s = 0 pows = [] endu = ...
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN V...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) mons = tuple(map(int, input().split())) m = int(input()) _heros = sorted( (tuple(map(int, input().split())) for _ in range(m)), reverse=True ) + [(0, 10**9)] heros = [] max_s = 0 for i in range(...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL V...
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
T = int(input()) for t in range(T): N = int(input()) A = list(map(int, input().split())) M = int(input()) heroes = [] for m in range(M): hero = list(map(int, input().split())) heroes.append(hero) best = {} for p, s in heroes: best[s] = max(best.get(s, 0), p) for i...
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 ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR E...
This time Baby Ehab will only cut and not stick. He starts with a piece of paper with an array a of length n written on it, and then he does the following: * he picks a range (l, r) and cuts the subsegment a_l, a_{l + 1}, …, a_r out, removing the rest of the array. * he then cuts this range into multiple subrange...
import sys input = sys.stdin.buffer.readline def LI(): return [int(i) for i in input().split()] def LI_(): return [(int(i) - 1) for i in input().split()] n, q = LI() arr = LI() prime_last_appear_at = dict() dp = [([n] * (n + 1)) for i in range(18)] have_primes = [[] for _ in range(10**5 + 3)] for p in ra...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR ...
This time Baby Ehab will only cut and not stick. He starts with a piece of paper with an array a of length n written on it, and then he does the following: * he picks a range (l, r) and cuts the subsegment a_l, a_{l + 1}, …, a_r out, removing the rest of the array. * he then cuts this range into multiple subrange...
import sys input = sys.stdin.readline MAX = 10**5 pf = list(range(MAX + 1)) p = 2 while p * p <= MAX: if pf[p] == p: for m in range(p * p, MAX + 1, p): pf[m] = p p += 1 def prime_factors(n): while n > 1: p = pf[n] while n % p == 0: n //= p yield p ...
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER FUNC_DEF WHILE VAR NUMBER ASSIGN VAR VAR VAR WHILE BIN_OP VAR ...
This time Baby Ehab will only cut and not stick. He starts with a piece of paper with an array a of length n written on it, and then he does the following: * he picks a range (l, r) and cuts the subsegment a_l, a_{l + 1}, …, a_r out, removing the rest of the array. * he then cuts this range into multiple subrange...
from sys import stdin, stdout def cut(n, a_a): N = max(a_a) p_a = seive_a(N) dic = {} b_a = [[(-1) for j in range(20)] for i in range(n)] b_a[n - 1][0] = n for i in range(n - 1, -1, -1): if i == n - 1: r = n else: r = b_a[i + 1][0] for p in p_a[a...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBE...
This time Baby Ehab will only cut and not stick. He starts with a piece of paper with an array a of length n written on it, and then he does the following: * he picks a range (l, r) and cuts the subsegment a_l, a_{l + 1}, …, a_r out, removing the rest of the array. * he then cuts this range into multiple subrange...
import sys MAXPRIME = 100000 primeFactors = [[] for _ in range(MAXPRIME + 1)] for i in range(2, MAXPRIME + 1): if len(primeFactors[i]) == 0: for j in range(i, MAXPRIME + 1, i): primeFactors[j].append(i) def main(): n, q = readIntArr() arr = readIntArr() elemPrimes = [inf for _ in ...
IMPORT ASSIGN VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CA...
This time Baby Ehab will only cut and not stick. He starts with a piece of paper with an array a of length n written on it, and then he does the following: * he picks a range (l, r) and cuts the subsegment a_l, a_{l + 1}, …, a_r out, removing the rest of the array. * he then cuts this range into multiple subrange...
import sys input = sys.stdin.buffer.readline spf = [0] * (10**5 + 1) primes = [] for i in range(2, 10**5 + 1): if spf[i] == 0: spf[i] = i primes.append(i) j = 0 while j < len(primes) and primes[j] <= spf[i] and primes[j] * i <= 10**5: spf[primes[j] * i] = primes[j] j += 1 n,...
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP NUMBE...
This time Baby Ehab will only cut and not stick. He starts with a piece of paper with an array a of length n written on it, and then he does the following: * he picks a range (l, r) and cuts the subsegment a_l, a_{l + 1}, …, a_r out, removing the rest of the array. * he then cuts this range into multiple subrange...
import sys input_ = lambda: sys.stdin.readline().strip("\r\n") ii = lambda: int(input_()) il = lambda: list(map(int, input_().split())) ilf = lambda: list(map(float, input_().split())) ip = lambda: input_() fi = lambda: float(input_()) ap = lambda ab, bc, cd: ab[bc].append(cd) li = lambda: list(input_()) pr = lambda x...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR A...
This time Baby Ehab will only cut and not stick. He starts with a piece of paper with an array a of length n written on it, and then he does the following: * he picks a range (l, r) and cuts the subsegment a_l, a_{l + 1}, …, a_r out, removing the rest of the array. * he then cuts this range into multiple subrange...
import sys input = sys.stdin.buffer.readline def I(): return int(input()) def LI(): return [int(i) for i in input().split()] def LI_(): return [(int(i) - 1) for i in input().split()] def decompos(num): res = [] if num % 2 == 0: res.append(2) while num % 2 == 0: n...
IMPORT ASSIGN VAR VAR 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 BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NU...
This time Baby Ehab will only cut and not stick. He starts with a piece of paper with an array a of length n written on it, and then he does the following: * he picks a range (l, r) and cuts the subsegment a_l, a_{l + 1}, …, a_r out, removing the rest of the array. * he then cuts this range into multiple subrange...
import sys input = sys.stdin.readline def main(): N, Q = map(int, input().split()) A = list(map(int, input().split())) MX = int(100000.0) primeFactors = [[] for _ in range(MX + 1)] for i in range(2, MX + 1): if len(primeFactors[i]) > 0: continue for j in range(i, MX + ...
IMPORT ASSIGN VAR VAR 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 FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FO...
This time Baby Ehab will only cut and not stick. He starts with a piece of paper with an array a of length n written on it, and then he does the following: * he picks a range (l, r) and cuts the subsegment a_l, a_{l + 1}, …, a_r out, removing the rest of the array. * he then cuts this range into multiple subrange...
import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int, sys.stdin.readline().rstrip().split()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int, sys.stdin.readline().rstrip())) def S(): return sys.stdin.re...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_CALL V...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
from itertools import groupby, repeat def line(): return map(int, input().split()) def num(): return int(input()) def nfunc(f, n, *args, **kwargs): return (f(*args, **kwargs) for _ in repeat(None, n)) def byw(q): return q[1][0] def byh(q): return q[1][1] t = num() for _ in repeat(None, t...
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NONE VAR FUNC_DEF RETURN VAR NUMBER NUMBER FUNC_DEF RETURN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NONE VAR ASSIGN VAR FUNC_CALL VAR ASSI...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
import itertools import sys class RMQ: def __init__(self, n): self.sz = 1 self.inf = (1 << 40) - 1 while self.sz <= n: self.sz = self.sz << 1 self.dat = [self.inf] * (2 * self.sz - 1) def update(self, idx, x): idx += self.sz - 1 self.dat[idx] = x ...
IMPORT IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR ...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
t = int(input()) for i in range(t): n = int(input()) a = [] ans = [(-1) for i in range(n)] for i in range(n): h, w = map(int, input().split()) if w > h: h, w = w, h a.append((h, w, i)) a.sort(key=lambda x: x[1], reverse=True) a.sort(key=lambda x: x[0]) pre...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CA...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
import sys input = sys.stdin.readline def find_num(t, arr, num, find_index): low = 0 high = len(arr) - 1 while low < high: mid = (low + high) // 2 if arr[mid][0] >= t[0]: high = mid - 1 else: low = mid + 1 if arr[low][0] >= t[0]: if low > 0 and ...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER RETU...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
def solve(): n = int(input()) data = [] kek = dict() for i in range(n): a, b = map(int, input().split()) data.append((max(a, b), min(a, b), i)) data_1 = sorted(data, key=lambda x: x[0]) key = 0 kek[0] = [1000000001, -1] for person in data_1: a, b, i = person ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER LIST ...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
t = int(input()) while t: n = int(input()) arr = [] for i in range(n): a, b = list(map(int, input().split())) if a > b: a, b = b, a arr.append((a, -b, i)) arr.append((b, -1, i)) ans = [(-1) for i in range(n)] a = -1 min_height = float("inf") elemen...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER VA...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
t = int(input()) for _ in range(t): n = int(input()) hw = [0] * n for i in range(n): h, w = map(int, input().split()) if h > w: h, w = w, h hw[i] = [i, h, w] hw.sort(key=lambda x: x[2], reverse=True) hw.sort(key=lambda x: x[1]) prev = -1, 10**10 ans = [-1]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUM...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
MOD = 1000000007 def si(): return input() def ii(): return int(input()) def li(): return list(map(int, input().split())) def mi(): return map(int, input().split()) def sout(v): print(v, end=" ") def d2b(n): return bin(n).replace("0b", "") def twod(n, m, num): return [[num for x...
ASSIGN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR 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 VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR STRING STRING F...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
tc = int(input()) for _ in range(tc): n = int(input()) fr = [] for i in range(n): h, w = list(map(int, input().split())) fr.append([min(h, w), max(h, w), i + 1, -1]) fr.sort(key=lambda x: -x[1]) fr.sort(key=lambda x: -x[0]) smallW = {} prev = float("inf"), -1 for i in rev...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
t = int(input()) for i in range(t): n = int(input()) arr = [] lst = [-1] * (n + 1) for j in range(n): h, w = map(int, input().split(" ")) arr.append([min(h, w), max(h, w), j + 1]) arr.sort() index = 0 mnwt = arr[0][1] index2 = 0 mnwt2 = arr[0][1] for i in range(1,...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR VAR FUNC_CALL VAR VA...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
for T in range(int(input())): n = int(input()) res = ["-1" for i in range(n)] images = [] for idx in range(n): w, h = map(int, input().split()) if w < h: w, h = h, w images.append((w, h, idx)) images.sort(key=lambda x: (x[0], x[1]), reverse=True) hmin = [] ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMB...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
def read_int(): return int(input()) def read_ints(): return map(int, input().split(" ")) t = read_int() for case_num in range(t): n = read_int() people = [] for i in range(n): h, w = read_ints() people.append((h, w, i)) people.append((w, h, i)) ans = [-1] * n peop...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR AS...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
import sys zz = 1 sys.setrecursionlimit(10**5) if zz: input = sys.stdin.readline else: sys.stdin = open("input.txt", "r") sys.stdout = open("all.txt", "w") di = [[-1, 0], [1, 0], [0, 1], [0, -1]] def fori(n): return [fi() for i in range(n)] def inc(d, c, x=1): d[c] = d[c] + x if c in d else x ...
IMPORT ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF NU...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
test = int(input()) for faoseufn in range(test): n = int(input()) l = [] for i in range(n): a, b = list(map(int, input().split())) if a < b: a, b = b, a l.append((a, b, i + 1)) l.sort() ans = [-1] * n w = {} ind = {} w[l[0][0]] = l[0][1] ind[l[0][0...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIG...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
for i in range(int(input())): n = int(input()) a = [] arr = [-1] for j in range(n): h, w = map(int, input().split()) if h < w: h, w = w, h a.append([h, w, j + 1]) arr.append(-1) a.sort() width = 1000000000 a.append(a[-1]) j = 0 pos = -1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
for z in range(int(input())): n = int(input()) l = [] ans = [(-1) for i in range(n)] for i in range(n): a, b = map(int, input().split()) l.append((a, 1, b, i)) l.append((a, 0, b, i)) l.append((b, 0, a, i)) l.sort() stack = [] for i in l: if i[1] == 1: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL V...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
def corrPlace(allPoint): n = len(allPoint) ans = [-1] * n allPoint.sort(reverse=True) message = [allPoint[-1]] for i in range(n - 2, -1, -1): if message[-1][0] != allPoint[i][0] and message[-1][1] > allPoint[i][1]: message.append(allPoint[i]) cachePlace = len(message) - 1 ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FO...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
for _ in range(int(input())): n = int(input()) ans = [(-1) for i in range(n)] p, q = [], [] for i in range(n): h, w = map(int, input().split()) p.append((h, w, i)) q.append((w, h, i)) p.sort(key=lambda x: x[0]) q.sort(key=lambda x: x[0]) bstp, bstq = (0, -1), (0, -1) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST LIST 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 EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VA...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
t = int(input()) for _ in range(t): n = int(input()) lst = [] for times in range(n): w, h = map(int, input().split()) if w > h: lst.append([h, w, times]) else: lst.append([w, h, times]) lst = sorted(lst, key=lambda x: (x[0], -x[1])) minn = lst[0][1] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR N...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
mxn = 10**10 for i in range(int(input())): n = int(input()) ls = [] lsr = [] res = [-1] * (n + 1) for i in range(n): a, b = map(int, input().split()) ls.append([a, b, i + 1]) lsr.append([b, a, i + 1]) ls.sort() lsr.sort() mini = [0] * n mini[0] = mxn minir...
ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP 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 BIN_...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
import sys def correctPlacement(n, fren): fren.sort() ans = ["-1"] * n j = 0 k = -1 for i in range(n): while fren[j][0] != fren[i][0]: if k == -1 or fren[j][1] < fren[k][1]: k = j j += 1 if k != -1 and fren[k][1] < fren[i][1]: ans...
IMPORT FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
t = int(input()) for q in range(t): n = int(input()) I = [] for i in range(n): ch = input() L = [int(i) for i in ch.split()] I.append((min(L[0], L[1]), max(L[0], L[1]), i + 1)) I.sort() curr = [I[0]] T = [-1] * n for i in range(1, n): if I[i][0] > I[i - 1][0] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP VAR ...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
t = int(input()) for _ in range(t): n = int(input()) dimensions = [] for i in range(n): h, w = map(int, input().split()) dimensions.append((i, min(h, w), max(h, w))) dimensions = sorted(dimensions, key=lambda item: item[2], reverse=True) dimensions = sorted(dimensions, key=lambda ite...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASS...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
for _ in range(int(input())): n = int(input()) a = [[0, 0, 0] for _ in range(n)] for i, x in enumerate(a): x[0], x[1] = map(int, input().split()) if x[0] > x[1]: x[0], x[1] = x[1], x[0] x[2] = i a.sort() ans = [-1] * n min_w = -1 i, j = 0, 0 while i < ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NU...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
for _ in range(int(input())): n = int(input()) arr = [] for i in range(n): h, w = map(int, input().split()) arr.append((h, -w, i)) arr.append((w, -h, i)) arr.sort() min_height = float("inf") element = -1 ans = [-1] * n for w, h, i in arr: h = -h if...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER A...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
rn = lambda: int(input()) rl = lambda: list(map(int, input().split())) rns = lambda: map(int, input().split()) rs = lambda: input() yn = lambda x: print("Yes") if x else print("No") YN = lambda x: print("YES") if x else print("NO") for _ in range(rn()): n = rn() p = [] for i in range(n): p.append(so...
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR ...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
for _ in range(int(input())): n = int(input()) frds = [(sorted(map(int, input().split(" "))) + [i]) for i in range(n)] overlap = [-1] * n frds = sorted(frds, key=lambda x: x[1], reverse=True) frds = sorted(frds, key=lambda x: x[0]) minh, minw, minfr = frds[0] notsame_frds = [] for hi, wi...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING LIST VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBE...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
t = int(input()) big = 2 * 10**9 for i in range(0, t): n = int(input()) ans = [-1] * n pairs = [] for j in range(0, n): nextStr = list(map(int, input().split(" "))) nextStr.append(j) pairs.append(nextStr) pairs.sort() k = 0 mn = [0] * n ps = [0] * n for j in r...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR F...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
import sys for _ in range(int(input())): n = int(input()) a = [] for i in range(n): h, w = map(int, input().split()) if w > h: h, w = w, h a.append((i, h, w)) a.sort(key=lambda x: (x[1], -x[2])) ans = [-1] * n maxi = sys.maxsize index = -1 for i, h, w...
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP L...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
def binary_search(arr, item): l = 0 r = len(arr) - 1 while r - l > -1: middle = (l + r) // 2 key = arr[middle] if key == item: return middle elif (key[0], -key[1], key[2]) < (item[0], -item[1], item[2]): l = middle + 1 else: r = mid...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR RETURN VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
t = int(input()) for __ in range(t): n = int(input()) arr = [] for i in range(n): h, w = map(int, input().split(" ")) if h > w: h, w = w, h arr.append((h, w, i)) arr.sort() new_list = [] new_sub_list = [] for i in range(n): if not new_sub_list or 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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
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 MI(): return map(int, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LLI(rows_...
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 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...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
import sys data = sys.stdin.read().split("\n")[::-1] def input(): return data.pop() res = [] def solve(hs, ws, n): friends = sorted(range(n), key=lambda i: (hs[i], ws[i])) ans = [-1] * n thinnest_shorter_than_current = ws.index(max(ws)) min_height = min(hs) thinnest = thinnest_shorter_tha...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING NUMBER FUNC_DEF RETURN FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
cases = int(input()) for _ in range(cases): n = int(input()) arr = [] for i in range(n): a, b = [int(i) for i in input().strip().split()] arr.append((a, b, i)) arr.append((b, a, i)) arr.sort() res = {} def solve(arr): n = len(arr) lo = 0 idx = 0 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT FUNC_D...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
for _ in range(int(input())): n = int(input()) a = list() for i in range(n): w, h = map(int, input().split()) a.append((w, h, i)) a.append((h, w, i)) a.sort() mn, mk, mw = [a[0][1]], [0], [-1] for i in range(1, n * 2): if mn[-1] > a[i][1]: mn.append(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 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 EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR LIST VAR NUMBER NUMBER ...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
t = int(input()) for _ in range(t): n = int(input()) a = [] for i in range(1, n + 1): h, w = map(int, input().split()) if h > w: a.append((h, w, i)) else: a.append((w, h, i)) a.sort() ans = ["-1"] * n j = 0 k = -1 for i in range(n): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSI...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
from sys import stdin input = stdin.readline def photo(arr): temp = [] ans = [-1] * len(arr) for i in range(len(arr)): temp.append([arr[i][0], arr[i][1], i]) temp = sorted(temp, key=lambda s: s[1], reverse=True) temp = sorted(temp, key=lambda s: s[0]) mw = [10**10, -1] for i in ra...
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST BIN_OP NUMBER NUMBER NUMBER FOR...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
import sys def main(): res = "" input = sys.stdin.readline print = sys.stdout.write t = int(input()) for _ in range(t): n = int(input()) a = [] origin = [] answer = {} sub_res = "" for i in range(n): w, h = map(int, input().split()) ...
IMPORT FUNC_DEF ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN 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 LIST ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF ...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
import sys t = int(input()) for i in range(0, t): n = int(input()) people = [] for j in range(0, n): h, w = map(int, input().split()) people.append((w, h, j)) people.append((h, w, j)) people.sort(key=lambda x: x[1], reverse=True) people.sort(key=lambda x: x[0]) minHeight...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMB...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
import sys input = sys.stdin.buffer.readline T = int(input()) def solve(): n = int(input()) res = [-1] * n sizes = [] for i in range(n): w, h = map(int, input().split()) if w > h: sizes += ((h, w, i),) else: sizes += ((w, h, i),) sizes.sort(key=lamb...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIG...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n = int(input()) a = [] for i in range(n): w, h = map(int, input().split()) a.append([w, h, i]) a.append([h, w, i]) a.sort(key=lambda x: (x[0], -x[1])) ans = [-1] * n minh = 1000000000.0 mini =...
IMPORT ASSIGN 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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR VAR ...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
cases = int(input()) for _ in range(cases): n = int(input()) arr = [] oarr = [] seen = {} for i in range(n): a, b = [int(i) for i in input().strip().split()] oarr.append((a, b)) if (a, b) not in seen: arr.append((a, b, i)) seen[a, b] = 1 if (b,...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VA...
Polycarp has invited $n$ friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side. Each friend is characterized by two values $h_i$ (their height) and $w_i$ (their width). On the photo the $i$-th friend will occupy a rectan...
def set_p(p, d, i, v): p[d[i][2]] = v if v == -1 else d[v][2] + 1 def solve(n, d): d.sort(key=lambda x: x[0]) p = [0] * n m_c = m_nc = -1 for i in range(n): if i: if d[i][0] > d[i - 1][0]: m_nc = min(m_c, m_nc, key=lambda x: d[x][1]) if m_nc != -1 else m_c ...
FUNC_DEF ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR ASS...
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property: If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme...
t = int(input()) for i in range(t): n, k = map(int, input().split()) nums = [int(i) for i in input().split()] leftMult, rightMult = 1, 2 left = 0 count = 1 ans = 0 for right in range(1, n): cond = nums[right - 1] * leftMult < nums[right] * rightMult if cond: count...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR 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 NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN...
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property: If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme...
for _ in range(int(input())): z, y = map(int, input().split()) x = list(map(int, input().split())) r = 0 prev = x[0] first = 0 last = 0 a = 1 while a < z: if x[a] * 2 > x[a - 1]: last += 1 else: r += max(0, last - first + 1 - y) first, ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VA...
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property: If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme...
def solve(): n, k = map(int, input().split()) n += 1 a = list(map(int, input().split())) + [-1] ans = 0 cnt = 1 for i in range(1, n): if a[i] * 2 > a[i - 1]: cnt += 1 else: ans += max(0, cnt - k) cnt = 1 print(ans) def main(): t = int...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_O...
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property: If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme...
t = int(input()) for _ in range(t): n, k = map(int, input().split()) a = [int(i) for i in input().split()] sum = 0 ans = 0 for i in range(1, n): if a[i] > a[i - 1] / 2: sum += 1 else: sum = 0 if sum >= k: ans += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR 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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUM...
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property: If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme...
for _ in range(int(input())): n, k = map(int, input().split()) l = list(map(int, input().split())) r = [] cnt = 0 for i in range(n - 1): r.append(l[i] < 2 * l[i + 1]) ones = sum(r[:k]) if ones == k: cnt += 1 for i in range(k, n - 1): ones += r[i] ones -= r...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VA...
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property: If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme...
T = int(input()) for _ in range(T): n, k = map(int, input().split()) s = list(map(int, input().split())) ans = 0 start = 0 end = 1 count = 0 while end < n: if s[end] * 2 > s[end - 1]: end += 1 count += 1 if count == k: ans += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBE...
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property: If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme...
for _ in range(int(input())): n, k = map(int, input().split()) nums = list(map(int, input().split())) ans = [1] * n for i in range(1, n): if nums[i - 1] < 2 * nums[i]: ans[i] = 1 + ans[i - 1] count = 0 for i in range(k, n): if ans[i] - ans[i - k] == k: cou...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR...
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property: If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme...
for _ in [0] * int(input()): n, k = map(int, input().split()) (*a,) = map(int, input().split()) t = 0 b = [i for i in range(n - 1) if a[i] >= 2 * a[i + 1]] m = len(b) if m == 0: print(n - k) continue for i in range(m - 1): t += max(0, b[i + 1] - b[i] - k) print(t ...
FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER...
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property: If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme...
for _ in range(int(input())): n, k = map(int, input().split()) arr = list(map(int, input().split())) streak = 1 ans = 0 for i in range(1, n): if arr[i - 1] < arr[i] * 2: streak += 1 else: ans += max(streak - k, 0) streak = 1 ans += max(streak -...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR B...
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property: If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme...
for _ in range(int(input())): n, k = map(int, input().split()) l = list(map(int, input().split())) j = 0 ans = 0 for i in range(1, n): if 2 * l[i] > l[i - 1]: v = 10 else: j = i if i - j == k: ans += 1 j += 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR V...
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property: If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme...
def solve(): n, k = map(int, input().split()) arr = [int(i) for i in input().split()] t = [] for i, v in enumerate(arr[:-1]): if arr[i + 1] * 2 > v: t.append(True) else: t.append(False) res = 0 f = sum(1 if not i else 0 for i in t[:k]) if f == 0: ...
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 ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NU...
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property: If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme...
for _ in range(int(input())): n, k = list(map(int, input().split())) arr = list(map(int, input().split())) prev = arr[0] cnt = 0 ans = 0 for i in range(1, n): if arr[i] > prev // 2: if cnt == k - 1: ans += 1 else: cnt += 1 e...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER IF VAR BIN_O...
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property: If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme...
for _ in range(int(input())): n, k = map(int, input().split()) a = [int(i) for i in input().split()] dp = [(1) for i in range(n)] count = 0 for i in range(1, n): if 2 * a[i] > a[i - 1]: dp[i] = dp[i - 1] + 1 else: dp[i] = 1 if dp[i] > k: co...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN...
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property: If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme...
def solve(): n, k = map(int, input().split()) arr = list(map(int, input().split())) i = 1 x = 1 ans = 0 ct = 1 while i < n: if arr[i - 1] * x < arr[i] * x * 2: ct += 1 else: if ct >= k: ans += ct - k ct = 1 x = 1...
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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP...
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property: If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme...
def p2Arr(): x = int(input()) for __ in range(x): [n, k] = list(map(int, input().split())) arr = list(map(int, input().split())) c = 1 fn = 0 for i in range(1, len(arr)): c += 1 if 2 * arr[i] > arr[i - 1] else -1 * (c - 1) if c >= k + 1: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST 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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP NUMBER VA...