description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
t = int(input()) for _ in range(t): n, k = list(map(int, input().split())) l1, r1 = list(map(int, input().split())) l2, r2 = list(map(int, input().split())) if l1 > l2: l1, r1, l2, r2 = l2, r2, l1, r1 if l2 <= r1: per_interval = abs(l1 - l2) + abs(r1 - r2) already_overlap = m...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ...
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
import sys input = sys.stdin.readline T = int(input()) for testcase in range(1, T + 1): n, k = list(map(int, input().split())) a, b = list(map(int, input().split())) s, t = list(map(int, input().split())) if a > s: a, s = s, a b, t = t, b if s <= b and n * (min(b, t) - s) >= k: ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR...
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
import sys input = sys.stdin.buffer.readline t = int(input()) for _ in range(t): n, k = [int(x) for x in input().split()] l1, r1 = [int(x) for x in input().split()] l2, r2 = [int(x) for x in input().split()] its = min(r1, r2) - max(l1, l2) if its >= 0: k -= n * its if k <= 0: ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL ...
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
for _ in range(int(input())): n, k = map(int, input().split()) l1, r1 = map(int, input().split()) l2, r2 = map(int, input().split()) over = min(r1, r2) - max(l1, l2) moves = 0 if (l1, r1) == (l2, r2): if (r1 - l1) * n >= k: print(0) else: k -= (r1 - l1) * ...
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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR ...
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
import sys input = sys.stdin.readline aaaa = list() for kek in range(int(input())): n, k = map(int, input().split()) al, ar = map(int, input().split()) bl, br = map(int, input().split()) L = n * max(0, min(ar, br) - max(al, bl)) if L >= k: aaaa.append(0) continue if ( al...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR 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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP FU...
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
import sys q = int(input()) for i in range(q): n, k = [int(j) for j in sys.stdin.readline().split()] l1, r1 = [int(j) for j in sys.stdin.readline().split()] l2, r2 = [int(j) for j in sys.stdin.readline().split()] if l2 < l1: l1, r1, l2, r2 = l2, r2, l1, r1 if r1 >= r2: kol = k - (r2...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSI...
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
T = int(input()) for _ in range(0, T): n, k = map(int, input().split()) l1, r1 = map(int, input().split()) l2, r2 = map(int, input().split()) L1 = 0 R1 = 0 L2 = 0 R2 = 0 if l1 <= l2: L1 = l1 R1 = r1 L2 = l2 R2 = r2 else: L1 = l2 R1 = r2...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VA...
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
import sys input = sys.stdin.readline t = int(input()) for tests in range(t): n, k = map(int, input().split()) l1, r1 = map(int, input().split()) l2, r2 = map(int, input().split()) if r2 < r1: l1, r1, l2, r2 = l2, r2, l1, r1 if l1 <= l2 <= r1 <= r2: start = (r1 - l2) * n plu...
IMPORT ASSIGN VAR VAR 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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR V...
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
def profit(l1, r1, l2, r2): if r1 > r2: r1, r2 = r2, r1 l1, l2 = l2, l1 if l2 > r1: return r2 - l1 elif l2 > l1: return r2 - l1 - r1 + l2 else: return r2 - r1 + l1 - l2 def tax(l1, r1, l2, r2): if r1 > r2: r1, r2 = r2, r1 l1, l2 = l2, l1 ...
FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR RETURN BIN_OP VAR VAR IF VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR RETURN BIN_OP VAR VAR RETURN NUMBER FUNC_DEF ...
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
for _ in range(int(input())): n, k = list(map(int, input().split())) l, r = list(map(int, input().split())) u, v = list(map(int, input().split())) if l > u: l, u = u, l r, v = v, r if l == u and v == r: overlap = r - l overlap = overlap * n if overlap >= k: ...
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 VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ...
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
def inter(l1, r1, l2, r2): l = max(l1, l2) r = min(r1, r2) return max(r - l, 0) def solve(): n, k = map(int, input().split()) al, ar = map(int, input().split()) bl, br = map(int, input().split()) res = inter(al, ar, bl, br) * n goodt = max(ar, br) - min(al, bl) - inter(al, ar, bl, br) ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC...
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
t = int(input()) for i in range(t): nk = input().split() n = int(nk[0]) k = int(nk[1]) l1, r1 = map(int, input().split()) l2, r2 = map(int, input().split()) if l1 > l2: l1, r1, l2, r2 = l2, r2, l1, r1 if l2 >= r1: reach = l2 - r1 span = r2 - l1 if k <= span: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ...
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
from sys import stdin, stdout def segment_intersections(n, k, l1, r1, l2, r2): lmx = max(l1, l2) rmn = min(r1, r2) I = max(rmn - lmx, 0) * n if I >= k: return 0 k -= I lmn = min(l1, l2) rmx = max(r1, r2) cov = rmx - lmn - max(rmn - lmx, 0) if cov == 0: return k * 2 ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR IF VAR VAR RETURN NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER RETUR...
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
import sys input = sys.stdin.readline (T,) = map(int, input().split()) for _ in range(T): n, k = map(int, input().split()) l, r = map(int, input().split()) x, y = map(int, input().split()) cost = 0 if r < x or y < l: cost = max(x - r, l - y) if cost: ff = 0 capacity = ma...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR ...
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
t = int(input()) def solve3(n, k, l1, r1, l2, r2): A, B = l2 - r1, r2 - l1 g = min(n, k // B) ans = g * (A + B) k -= g * B if g == n: ans = ans + 2 * k else: ans = min(ans + A + k, ans + 2 * k) print(ans) def solve1(n, k, l1, r1, l2, r2): A, B = l2 - r1, r2 - l1 a...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP NUMBER ...
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
from sys import stdin input = stdin.buffer.readline for _ in range(int(input())): n, k = map(int, input().split()) l1, r1 = map(int, input().split()) l2, r2 = map(int, input().split()) x = max(0, min(r1, r2) - max(l1, l2)) a = max(r1, r2) - min(l1, l2) cnt = x * n if cnt >= k: print...
ASSIGN VAR VAR 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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR A...
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
t = int(input()) for _ in range(t): n, k = [int(x) for x in input().split()] l1, r1 = [int(x) for x in input().split()] l2, r2 = [int(x) for x in input().split()] if l1 > l2: l1, r1, l2, r2 = l2, r2, l1, r1 if l2 < r1: start = (min(r1, r2) - max(l1, l2)) * n if start >= k: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR ...
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n, k = map(int, input().split()) l1, r1 = map(int, input().split()) l2, r2 = map(int, input().split()) if l1 > l2: l1, r1, l2, r2 = l2, r2, l1, r1 ans = 10**18 if r1 < l2: shared = 0 initial_cost =...
IMPORT ASSIGN VAR VAR 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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR B...
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
for _ in range(int(input())): n, k = map(int, input().split()) l1, r1 = map(int, input().split()) l2, r2 = map(int, input().split()) ans = float("inf") if min(r1, r2) < max(l1, l2): i = max(l1, l2) - min(r1, r2) for j in range(1, n + 1): c = i * j m = (max(r1,...
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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FU...
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
for _ in range(int(input())): n, k = map(int, input().split()) l1, r1 = map(int, input().split()) l2, r2 = map(int, input().split()) if l1 > l2: l1, r1, l2, r2 = l2, r2, l1, r1 if l2 > r1: ans = float("inf") for i in range(1, n + 1): temp = i * (l2 - r1) ...
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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VA...
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
for _ in range(int(input())): n, k = map(int, input().split()) s = sorted([[int(i) for i in input().split()] for i in range(2)]) g = s[1][0] - s[0][1] ans = int(1e20) if s[1][0] < s[0][1] and s[0][1] > s[1][1]: k -= (s[1][1] - s[1][0]) * n mX = s[0][1] - s[0][0] - (s[1][1] - s[1][0])...
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 VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER...
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
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") T = ni() for _ in range(T): n, k = nm() a...
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 ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL ...
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
import sys input = sys.stdin.readline for f in range(int(input())): n, k = map(int, input().split()) l1, r1 = map(int, input().split()) l2, r2 = map(int, input().split()) intersect = False if l1 >= l2 and l1 <= r2: intersect = True if r1 >= l2 and r1 <= r2: intersect = True ...
IMPORT ASSIGN VAR VAR 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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR ASS...
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
from sys import gettrace, stdin if gettrace(): inputi = input else: def input(): return next(stdin)[:-1] def inputi(): return stdin.buffer.readline() def solve(): n, k = map(int, inputi().split()) l1, r1 = map(int, inputi().split()) l2, r2 = map(int, inputi().split()) ov...
IF FUNC_CALL VAR ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR V...
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from ...
for _ in range(int(input())): n, k = list(map(int, input().split())) l_1, r1 = list(map(int, input().split())) l_2, r2 = list(map(int, input().split())) if r1 < l_2: pre_steps = l_2 - r1 elif l_1 > r2: pre_steps = l_1 - r2 else: pre_steps = 0 if pre_steps: eas...
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 VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VA...
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
import sys spies, turns, note, final = map(int, input().split()) if note < final: next = 1 else: next = -1 answer = [] def pass_note(current_turn, next_watch, left, right, note): if current_turn == next_watch: if note in range(left, right + 1) or note + next in range(left, right + 1): ...
IMPORT ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR VAR IF VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR STRING IF VAR VAR VAR VAR RETURN VAR STRING VAR VAR RETURN V...
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
def checkKey(dict, key): if key in dict: return True return False n, m, s, f = map(int, input().split()) d = {} for i__ in range(m): t, l, r = map(int, input().split()) d[t] = l, r if f > s: ans = "" cp = s time = 1 while cp != f: if time in d: start = d[tim...
FUNC_DEF IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VA...
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
def checkKey(dict, key): if key in dict: return True return False n, m, s, f = map(int, input().split()) p = s d = -1 c = "L" if s < f: d = 1 c = "R" t = 1 ts = {} ans = "" for _ in range(m): x, y, z = map(int, input().split()) ts[x] = y, z while p != f: if t in ts: l, r = ...
FUNC_DEF IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VA...
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
n, m, s, f = map(int, input().split()) data = {} for _ in range(m): t, l, r = map(int, input().split()) data[t] = l, r k = 1 curr = s while curr != f: if k in data: if data[k][0] <= curr <= data[k][1]: print("X", end="") elif 1 < curr < n: if curr > f: ...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING I...
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
n, m, s, f = map(int, input().split()) ans, p = "", 1 if s < f: for i in range(m): t, l, r = map(int, input().split()) if t > p: if t - p < f - s: ans += "R" * (t - p) s += t - p else: ans += "R" * (f - s) s = f ...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR STRING NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP STRING BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP STRING BIN_OP VAR VAR...
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
R = lambda: list(map(int, input().split())) n, m, s, f = R() if s < f: d = 1 c = "R" else: d = -1 c = "L" res = "" i = 1 j = s t, l, r = R() k = 1 while j != f: if i > t and k < m: t, l, r = R() k += 1 if i == t and (l <= j <= r or l <= j + d <= r): res += "X" else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VA...
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
n, m, s, f = map(int, input().split()) l = [] for i in range(m): t, c, r = map(int, input().split()) l.append([t, c, r]) if s > f: st = "" t = 1 i = 0 while i < m: if t == l[i][0]: if (s < l[i][1] or s > l[i][2]) and (s - 1 < l[i][1] or s - 1 > l[i][2]): s -= ...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR IF VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR ...
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
def __starting_point(): inp = input() arr = inp.split(" ") n = int(arr[0]) m = int(arr[1]) s = int(arr[2]) f = int(arr[3]) ans = "" ch = "L" inc = -1 if s < f: ch = "R" inc = 1 tm = 1 done = False for i in range(m): inp = input() if don...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VA...
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
n, m, s, f = map(int, input().split()) watch = {} for i in range(m): t, l, r = map(int, input().split()) watch[t] = l, r cur = s move, symbol = (1, "R") if s < f else (-1, "L") step = 1 while cur != f: if step in watch: l, r = watch[step] if l <= cur <= r or l <= cur + move <= r: ...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR NUMBER STRING NUMBER STRING ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR ASSIGN VAR VAR VAR V...
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
import sys n, m, s, f = list(map(int, sys.stdin.readline().split())) L = [] R = [] T = [] for i in range(m): t, l, r = list(map(int, sys.stdin.readline().split())) T.append(t) L.append(l) R.append(r) if f > s: i = s step = 1 ind = 0 Ans = "" while i != f: if ind >= m or T[in...
IMPORT ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIG...
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
while True: try: def soln(n, m, s, t, stp): stp.sort() flg = True if s > t: flg = False i = 1 j = 0 ans = [] while True: fund = False while j < m: if stp[j...
WHILE NUMBER FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMB...
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
n, m, s, f = map(int, input().split()) if s < f: step = "R" step_i = 1 else: step = "L" step_i = -1 ans = [] tp = 0 for i in range(m): t, l, r = map(int, input().split()) k = min(t - tp - 1, abs(f - s)) for j in range(k): ans.append(step) s += step_i * k if s == f: pr...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMB...
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
n, m, s, f = list(map(int, input().split())) if s > f: a = "L" c = -1 elif s == f: a = "X" c = 0 else: a = "R" c = 1 l = [] for i in range(m): l.append(list(map(int, input().split()))) ans = "" if l[0][0] != 1: d = l[0][0] - 1 while s != f and d > 0: s = s + c ans = a...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CAL...
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
n, m, s, f = map(int, input().split()) l = [] for i in range(m): k = list(map(int, input().split())) l.append(k) count = 1 ans = "" i = 0 while i < m: if count < l[i][0]: if f > s: ans += "R" * min(l[i][0] - count, f - s) s += min(l[i][0] - count, f - s) count = l...
ASSIGN VAR VAR 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 NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP STRING FUNC...
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
n, m, s, f = map(int, input().split()) t = dict() for i in range(m): t1, l1, r1 = map(int, input().split()) t[t1] = l1, r1 pos = s i = 1 while 1: if pos == f: break if i in t: if t[i][0] <= pos <= t[i][1]: print("X", end="") i += 1 continue eli...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR IF VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL ...
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
n, m, s, f = list(map(int, input().split())) d = {} for i in range(m): t, l, r = list(map(int, input().split())) d[t] = [l, r] ans = "" for i in range(1, n + m): if s == f: print(ans) return t = -1 if f < s: t = s - 1 else: t = s + 1 if i in d: if d[i]...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ...
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
def solve(s, f, t): res = "" step = 1 if s < f else -1 i = current = 0 while s != f: current += 1 ti, l, r = t[i] if i < len(t) else (-1, -1, -1) if ti == current: i += 1 if l <= s <= r or l <= s + step <= r: res += "X" cont...
FUNC_DEF ASSIGN VAR STRING ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR STRING VAR VAR VAR VAR NUMBER STRING STRING RETURN VAR FUNC_DEF ASSIGN VAR FUNC...
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
n, m, s, f = map(int, input().split()) d = {} final = 0 for i in range(m): a = list(map(int, input().split())) d[a[0]] = [a[1], a[2]] final = a[0] z = "" if s < f: i = 0 while s != f: i += 1 if i not in d: s += 1 z += "R" elif s not in range(d[i][0], d...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER LIST VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING IF VAR VAR ASSIGN VAR NUMBER WHILE VAR ...
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
n, m, s, f = [int(x) for x in input().split()] now = 1 d = 1 if f > s else -1 step = "R" if d == 1 else "L" ret = "" for _ in range(m): t, l, r = [int(x) for x in input().split()] if t > now: flag = False while t > now: s += d ret += step now += 1 ...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER STRING STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR ...
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
n, m, s, f = map(int, input().split()) c, t1 = 1, 0 ans = "" t = 1 while s != f and t1 < m: t, l, r = map(int, input().split()) while t != c: if s < f: ans += "R" s += 1 else: ans += "L" s -= 1 if s == f: break c += 1 ...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR WHILE VAR VAR IF VAR VAR VAR STRING VAR NUMBER VAR STRING VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR IF VA...
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
def geto(a, b): return max(0, min(a[1], b[1]) - max(a[0], b[0]) + 1) n, m, s, f = map(int, input().split()) di = {} for _ in range(m): t, l, r = map(int, input().split()) di[t] = [l, r] t = 1 ans = [] while s != f: if f > s: inte = [s, s + 1] if t in di and geto(inte, di[t]): ...
FUNC_DEF RETURN FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST VA...
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
def mi(): return map(int, input().split()) n, m, s, f = mi() t = [0] * m l = [0] * m r = [0] * m for i in range(m): t[i], l[i], r[i] = mi() curp = s curt = 1 i = 0 a = "" if f > s: a = (f - s) * "R" else: a = (s - f) * "L" while i < m and curp != f: if t[i] == curt: if a[0] == "R" and curp...
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER A...
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
import sys input = sys.stdin.readline def print(val): sys.stdout.write(str(val) + "\n") def prog(): n, m, s, f = map(int, input().split()) curr = s step = 1 steps = {} output = [] for i in range(m): t, l, r = map(int, input().split()) steps[t] = [l, r] if f > s: ...
IMPORT ASSIGN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR V...
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
n, m, s, f = list(map(int, input().split())) t = {} step = 1 ans = "" if s < f: sig = "R" else: sig = "L" for i in range(m): t0, l0, r0 = list(map(int, input().split())) t[t0] = [l0, r0] for i in range(1, n + m + 1): if s < f: u = s + 1 else: u = s - 1 if i in t: if t...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR STRING IF VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST VAR VAR FOR VAR FUNC_...
Alice received a set of Toy Train™ from Bob. It consists of one train and a connected railway network of $n$ stations, enumerated from $1$ through $n$. The train occupies one station at a time and travels around the network of stations in a circular manner. More precisely, the immediate station that the train will visi...
import sys input = sys.stdin.readline mii = lambda: map(int, input().split()) n, m = mii() a = [(0) for _ in range(n)] c = [(123456) for _ in range(n)] for _ in range(m): u, v = mii() u %= n v %= n if v < u: v += n a[u] += 1 if c[u] > v: c[u] = v ans = [] for i in list(range(1, ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR V...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
import sys input = sys.stdin.readline t = int(input()) for tests in range(t): n, m = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) OK = [[] for i in range(n + 1)] NG = [[] for i in range(n + 1)] for i in...
IMPORT ASSIGN VAR VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
import sys input = lambda: sys.stdin.buffer.readline() for _ in range(int(input())): n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) last = c[-1] if last in b: idx = -1 for i in range(n)...
IMPORT ASSIGN VAR FUNC_CALL VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
t = int(input()) for test in range(t): n, m = map(int, input().split()) need = [0] * n check = [0] * n a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) d = dict() for i in range(n): if a[i] != b[i]: if b[i] no...
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 BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER 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 ...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
def solve(n, m, a, b, c): weNeedDict = {} for i in range(n): if a[i] != b[i]: if b[i] not in weNeedDict: weNeedDict[b[i]] = [i] else: weNeedDict[b[i]].append(i) avail = {} for i in c: if i not in avail: avail[i] = 1 ...
FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR FUNC_CALL VAR VAR VAR RETURN NUMBER IF VAR BIN_OP VA...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
t = int(input()) for _ in range(t): def main(): n, m = map(int, input().split()) a = [0] + list(map(int, input().split())) b = [0] + list(map(int, input().split())) c = list(map(int, input().split())) need = [[] for _ in range(n + 1)] for i in range(1, n + 1): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_C...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n, m = map(int, input().split()) now = list(map(int, input().split())) goal = list(map(int, input().split())) color = list(map(int, input().split())) same = {} dif = {} for i in range(n): if now[i] != goal[i]:...
IMPORT ASSIGN VAR VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
for _ in range(int(input())): n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) d1 = {} for i in range(n): if a[i] in d1: d1[a[i]].append(i) else: d1[a[i]] = [i] ...
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 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 D...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
def solveTestCase(): nm = [int(i) for i in input().split()] A = [int(i) for i in input().split()] B = [int(i) for i in input().split()] C = [int(i) for i in input().split()] to_change = {} last_couleur = C[-1] for_last = 0 last_mod = 0 to_mod = 0 for i in range(len(A)): i...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VA...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
def solve(n, m, a, b, c): d = {} good = {} cnt = {} for i in range(n): if a[i] == b[i]: good[b[i]] = i elif b[i] not in d: d[b[i]] = [i] cnt[b[i]] = 1 else: d[b[i]].append(i) cnt[b[i]] += 1 fallback = -1 p = [] ...
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NU...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
from sys import gettrace, stdin if gettrace(): def inputi(): return input() else: def input(): return next(stdin)[:-1] def inputi(): return stdin.buffer.readline() def solve(): n, m = map(int, input().split()) aa = [int(a) for a in input().split()] bb = [int(a) for...
IF FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL V...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
import sys input = lambda: sys.stdin.readline().rstrip() T = int(input()) for _ in range(T): N, M = map(int, input().split()) A = [(int(a) - 1) for a in input().split()] B = [(int(a) - 1) for a in input().split()] C = [(int(a) - 1) for a in input().split()][::-1] X = [[] for _ in range(N)] ANS ...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR 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 BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
import sys t = int(input()) while t > 0: n, m = map(int, input().split()) a1 = [[] for i in range(0, n + 1)] a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) for i in range(0, n): if b[i] != a[i]: a1[b[i]].append(i) ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER BIN_OP 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 ...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
for _ in range(int(input())): n, m = map(int, input().split()) initial = list(map(int, input().split())) final = list(map(int, input().split())) painters = list(map(int, input().split())) last = painters[-1] if last in final: x = 0 to_be_painted = {} for i in range(n): ...
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 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 V...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
def find(): n, m = map(int, input().split()) old = list(map(int, input().split())) new = list(map(int, input().split())) worker = list(map(int, input().split())) task = [[] for _ in range(n + 1)] for i in range(len(old)): if old[i] != new[i]: task[new[i]].append(i) last =...
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 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 FUNC_CALL VAR BIN_OP VAR NUMBER F...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
def main(): n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) q = [[] for _ in range(n + 1)] idx = [-1] * (n + 1) for i in range(n): idx[b[i]] = i + 1 if a[i] != b[i]: q[b[i...
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 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 FUNC_CALL VAR BIN_OP VAR NUMBER A...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
t = int(input()) for _ in range(t): n, m = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) finded = {} d = {} z = {} for i in range(n): if b[i] != a[i]: if not b[i] in d: d[b[i]] = 1 z...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT FO...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
for t in range(int(input())): n, m = map(int, input().split()) colors = [[] for i in range(n + 1)] pos = 0 a = list(map(int, input().split())) b = list(map(int, input().split())) for i in range(n): if a[i] == b[i]: colors[b[i]].append(i) for i in range(n): if a[i]...
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 LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER 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 FOR VAR F...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
from sys import stdin t = int(stdin.readline()) for _ in range(t): n, m = map(int, stdin.readline().split()) arra = list(map(int, stdin.readline().split())) arrb = list(map(int, stdin.readline().split())) arrc = list(map(int, stdin.readline().split())) dif = {} so = 0 for i in range(n): ...
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 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 V...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
def solve(): d = dict() pd = dict() o = b.index(c[-1]) for i in range(m): if c[i] in pd: pd[c[i]] += 1 else: pd[c[i]] = 1 for i in range(n): if a[i] != b[i]: if b[i] in d: d[b[i]].append(i) else: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR ASSIGN VAR VAR NUMBE...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
t = int(input()) for _ in range(t): n, k = [int(i) for i in input().split()] a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] c = [int(i) for i in input().split()] d = {} d1 = {} for i in range(n): if a[i] != b[i]: if b[i] not in d: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN ...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
import sys input = sys.stdin.readline for _ in range(int(input())): n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) d = {} r = {} for i in range(len(b)): if a[i] == b[i]: r[b[i]]...
IMPORT ASSIGN VAR VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
p = lambda: list(map(int, input().split())) r = print g = range l = len for _ in "." * p()[0]: N, M = p() L = N + 1 A = p() B = p() C = p()[::-1] X = [[] for i in g(L)] Y = [[] for i in g(L)] for i in g(N): if A[i] == B[i]: X[A[i]].append(i + 1) else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR BIN_OP STRING FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR FUNC_...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
from sys import stdin input = stdin.readline t = int(input()) for _ in range(t): n, m = [int(x) for x in input().split()] a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] c = [int(x) for x in input().split()] x = c[-1] g = -1 d = {} for i in range(n): ...
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN V...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
import sys input = sys.stdin.readline for _ in range(int(input().strip())): n, m = map(int, input().strip().split(" ")) a = list(map(int, input().strip().split(" "))) b = list(map(int, input().strip().split(" "))) c = list(map(int, input().strip().split(" "))) t = {} tp = 0 bd = {} bdc ...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STR...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n, m = map(int, input().split()) a = [int(item) for item in input().split()] b = [int(item) for item in input().split()] c = [int(item) for item in input().split()] color_place = [-1] * n to_recolor = [[] for _ in range(n...
IMPORT ASSIGN VAR VAR 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIG...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
def solve(): n, m = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) req = [(0) for i in range(n + 1)] maxreq = [(0) for i in range(n + 1)] available = [(0) for i in range(n + 1)] last = [(0) for i...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
q = int(input()) while q: q -= 1 f = 1 ri = -1 n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) c.reverse() cntt = 0 cnt = [[] for i in range(n)] res = [] cnt2 = [[] for i in range...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CAL...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
import sys input = sys.stdin.readline for _ in range(int(input())): N, M = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) t = [[] for _ in range(N + 1)] for i in range(N): if a[i] != b[i]: ...
IMPORT ASSIGN VAR VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
import sys input = sys.stdin.readline def inp(): return int(input()) def st(): return input().rstrip("\n") def lis(): return list(map(int, input().split())) def maa(): return map(int, input().split()) t = inp() while t: t -= 1 n, m = maa() a = lis() b = lis() c = lis() ...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR STRING 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 ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR AS...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
from sys import stdin, stdout input = stdin.readline for _ in range(int(input())): n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) dic = {} for i in range(n): if a[i] != b[i]: if b[i...
ASSIGN VAR VAR 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 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 V...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
from sys import stdin t = int(stdin.readline()) for _ in range(t): flag = True n, m = map(int, stdin.readline().split()) prev = list(map(int, stdin.readline().split())) aft = list(map(int, stdin.readline().split())) paints = list(map(int, stdin.readline().split())) diff = [] for i in range(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUN...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
T = int(input()) for _ in range(T): n, m = [int(x) for x in input().split()] a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] c = [int(x) for x in input().split()] needed = [[] for _ in range(n)] cols_at_end = [(-1) for _ in range(n)] total_needed = 0 for i in ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUN...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
t = int(input()) for _ in range(t): a, b = map(int, input().split()) f = list(map(int, input().split())) s = list(map(int, input().split())) an = list(map(int, input().split())) l = [[] for i in range(a + 1)] sa = 0 bsa = 0 amo = 0 for i in range(a): if s[i] == an[-1] and (sa...
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 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 V...
You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it. You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the ...
import sys from sys import stdin tt = int(stdin.readline()) for loop in range(tt): n, m = map(int, stdin.readline().split()) a = list(map(int, stdin.readline().split())) b = list(map(int, stdin.readline().split())) c = list(map(int, stdin.readline().split())) dic = [[] for i in range(n + 1)] fo...
IMPORT 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC...
Vasily the bear has got a sequence of positive integers a_1, a_2, ..., a_{n}. Vasily the Bear wants to write out several numbers on a piece of paper so that the beauty of the numbers he wrote out was maximum. The beauty of the written out numbers b_1, b_2, ..., b_{k} is such maximum non-negative integer v, that numbe...
from sys import stdin, stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int, stdin.readline().split())) for _ in range(1): n = nmbr() a = lst() bits = [[(0) for _ in range(34)] for _ in range(n)] for i in range(n): for j in range(34): bits[i][33 - j] = a[i] >> j & ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ...
Vasily the bear has got a sequence of positive integers a_1, a_2, ..., a_{n}. Vasily the Bear wants to write out several numbers on a piece of paper so that the beauty of the numbers he wrote out was maximum. The beauty of the written out numbers b_1, b_2, ..., b_{k} is such maximum non-negative integer v, that numbe...
n = int(input()) t = list(map(int, input().split())) p = [bin(i) for i in t] p = [("0" * (32 - len(i)) + i[2:]) for i in p] p = ["".join(i) for i in zip(*p)] x = 0 for i in range(30): x = p[i] if "1" in x and not any( all(x[k] == y[k] for k in range(n) if x[k] == "1") for y in p[i + 1 :] ): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ...
Vasily the bear has got a sequence of positive integers a_1, a_2, ..., a_{n}. Vasily the Bear wants to write out several numbers on a piece of paper so that the beauty of the numbers he wrote out was maximum. The beauty of the written out numbers b_1, b_2, ..., b_{k} is such maximum non-negative integer v, that numbe...
x = int(input()) s = list(map(int, input().split())) ans = [] for u in range(0, 30): cur = 1 << u v = (1 << u + 1) - 1 tem = [] for n in s: if n & cur: tem.append(n) for n in tem: v &= n if v % (1 << u) == 0: ans = tem print(len(ans)) print(*ans)
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 NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR...
Vasily the bear has got a sequence of positive integers a_1, a_2, ..., a_{n}. Vasily the Bear wants to write out several numbers on a piece of paper so that the beauty of the numbers he wrote out was maximum. The beauty of the written out numbers b_1, b_2, ..., b_{k} is such maximum non-negative integer v, that numbe...
n = int(input()) a = list(map(int, input().split())) mxa = max(a) v = 1 << 30 while v > mxa: v >>= 1 while True: d = -1 for i in range(n): if a[i] & v: d &= a[i] if d % v == 0: break v >>= 1 b = [i for i in a if i & v] print(len(b)) print(" ".join(map(str, b)))
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 BIN_OP NUMBER NUMBER WHILE VAR VAR VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER A...
As meticulous Gerald sets the table, Alexander finished another post on Codeforces and begins to respond to New Year greetings from friends. Alexander has n friends, and each of them sends to Alexander exactly one e-card. Let us number his friends by numbers from 1 to n in the order in which they send the cards. Let's ...
def f(): t = [0] * n for i, j in enumerate(input().split()): t[int(j) - 1] = i return t n = int(input()) p = [f() for i in range(n)] s = f() for x, t in enumerate(p): i = j = x < 1 for y in range(n): if x != y and s[y] < s[i]: i = y if t[i] < t[j]: j...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FO...
As meticulous Gerald sets the table, Alexander finished another post on Codeforces and begins to respond to New Year greetings from friends. Alexander has n friends, and each of them sends to Alexander exactly one e-card. Let us number his friends by numbers from 1 to n in the order in which they send the cards. Let's ...
n = int(input()) arr = [list(map(int, input().split())) for _ in range(n + 1)] res = [0] * n for i in range(n): p = [0] * (n + 1) for j in range(n): p[arr[i][j]] = j u, t, b = 0, int(100000.0), int(100000.0) for x in arr[n]: if x != i + 1 and x < b: if p[x] < 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 BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VA...
As meticulous Gerald sets the table, Alexander finished another post on Codeforces and begins to respond to New Year greetings from friends. Alexander has n friends, and each of them sends to Alexander exactly one e-card. Let us number his friends by numbers from 1 to n in the order in which they send the cards. Let's ...
n = int(input()) frnd = [list(map(int, input().split())) for _ in range(n)] ara = list(map(int, input().split())) pref = [0] * (n + 1) ans = [0] * n for i in range(n): pref[ara[i]] = i def ok(val, row): for x in ara: if x - 1 == row: continue if x < val: return 0 ...
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VA...
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants. All soldiers in the battalion have different beauty that is represented by a positive integer. The value...
n, k = map(int, input().split()) p = list(map(int, input().split())) p.sort() t = [[i] for i in p] for i in range(1, n): t += [(t[-1] + i) for i in t[: n - i]] print("\n".join(str(len(i)) + " " + " ".join(map(str, i)) for i in t[:k]))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP BIN_OP FUNC_CALL VAR FUN...
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants. All soldiers in the battalion have different beauty that is represented by a positive integer. The value...
n, k = list(map(int, input().split())) a = list(map(int, input().split())) a.sort(reverse=True) cur_len, res = 1, [] while k > 0 and cur_len <= n: for i in range(cur_len, n + 1): print(cur_len, *res, a[i - 1]) k -= 1 if k == 0: break res.append(a[cur_len - 1]) cur_len += ...
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 EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER LIST WHILE VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ...
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants. All soldiers in the battalion have different beauty that is represented by a positive integer. The value...
n, k = list(map(int, input().split())) A = list(map(int, input().split())) C = [] U = len(A) c = 0 g = 0 for i in range(k): print(len(C + [A[g]]), " ".join(map(str, C + [A[g]]))) g += 1 if g == len(A): g = 0 C.append(max(A)) A.remove(max(A))
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 LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR LIST VAR VAR FUNC_CALL STRING F...
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants. All soldiers in the battalion have different beauty that is represented by a positive integer. The value...
n, k = map(int, input().split()) l = [int(i) for i in input().split()] l.sort(reverse=True) elems = [] j = -1 cnt = 0 for i in range(n): if cnt == k: break j += 1 fixed = l[0:j] for z in range(j, n): if cnt == k: continue print(j + 1, *(fixed + [l[z]])) cnt +=...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CAL...
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants. All soldiers in the battalion have different beauty that is represented by a positive integer. The value...
n, k = list(map(int, input().split())) a = sorted(list(map(int, input().split()))) j = 0 c = 0 for i in range(k): b = [a[i - c]] for l in range(n - j, n): b.append(a[l]) print(j + 1, *b) if i - c == n - j - 1: c += n - j j += 1
ASSIGN 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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXP...
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants. All soldiers in the battalion have different beauty that is represented by a positive integer. The value...
n, k = map(int, input().split()) soldiers = list(map(int, input().split())) count = 0 seen = {(0): 0} beauties = [0] while count != k: for beauty in beauties: bits = seen[beauty] for i, x in enumerate(soldiers): if bits & 1 << i != 0 or beauty + x in seen: continue ...
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 DICT NUMBER NUMBER ASSIGN VAR LIST NUMBER WHILE VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR ...
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants. All soldiers in the battalion have different beauty that is represented by a positive integer. The value...
n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() cnt = n while k: for i in range(cnt): print(n - cnt + 1, a[i]) for j in range(cnt, n): print(a[j]) k -= 1 if k == 0: break cnt -= 1
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR WHILE VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF...
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants. All soldiers in the battalion have different beauty that is represented by a positive integer. The value...
from sys import stdin def arr_inp(n): if n == 1: return [int(x) for x in stdin.readline().split()] elif n == 2: return [float(x) for x in stdin.readline().split()] else: return list(stdin.readline()[:-1]) n, k = arr_inp(1) c = sorted(arr_inp(1))[::-1] for i in range(min(n, k)): ...
FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR RETURN FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EX...
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants. All soldiers in the battalion have different beauty that is represented by a positive integer. The value...
n, k = map(int, input().split()) l = sorted(map(int, input().split()), reverse=True) c = 0 for i in range(n): for x in l[i:]: if c == k: exit() c += 1 print(i + 1, end=" ") for y in l[:i]: print(y, end=" ") print(x, end=" ") print()
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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR STRIN...