description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() indl = [(-1) for i in range(len(t))] j = 0 for i in range(len(s)): if s[i] == t[j]: indl[j] = i j += 1 if j == len(t): break indr = [(-1) for i in range(len(t))] j = len(t) - 1 for i1 in range(len(s)): i = len(s) - 1 - i1 if s[i] == t[j]: i...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VA...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
string = str(input()) substring = str(input()) len_string = len(string) len_substring = len(substring) minimal_string_pos = [] max_string_pos = [] sub_flag = 0 for i in range(len_string): if string[i] == substring[sub_flag]: minimal_string_pos.append(i) sub_flag += 1 if sub_flag > len_substr...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VA...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
R = lambda: map(int, input().split()) s = input() t = input() ls, lt = len(s), len(t) a = [0] * lt j = ls - 1 for i in reversed(range(lt)): while s[j] != t[i]: j -= 1 a[i] = j j -= 1 res, l = 0, 0 for i in range(ls): rp = ls - 1 if l < lt: rp = a[l] - 1 res = max(res, rp - i + 1)...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
word = input() sub = input() n = len(word) m = len(sub) LR = [] RL = [] ind = 0 for i in range(n): if sub[ind] == word[i]: LR.append(i) ind += 1 if ind == m: break ind = m - 1 for i in range(n - 1, -1, -1): if sub[ind] == word[i]: RL.append(i) ind -= 1 ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUM...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() lefts = [(0) for i in range(len(t))] rights = [(0) for i in range(len(t))] i = 0 j = 0 while i < len(s) and j < len(t): if s[i] == t[j]: lefts[j] = i j += 1 i += 1 i = len(s) - 1 j = len(t) - 1 while i >= 0 and j >= 0: if s[i] == t[j]: rights[j] = i j ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_O...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
def int_multiple(): return [int(c) for c in input().split()] def int_single(): return int(input()) def str_multiple(): return [c for c in input().split()] def str_single(): return input() s = str_single() t = str_single() ti = 0 start = [] for si in range(len(s)): if s[si] == t[ti]: ...
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR V...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input().rstrip() t = input().rstrip() left = [] idx = 0 for i, item in enumerate(s): if item == t[idx]: left.append(i) idx += 1 if idx == len(t): break right = [] idx = len(t) - 1 for i, item in enumerate(s[::-1]): if item == t[idx]: right.append(len(s) - i - 1) i...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR E...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() L1 = [] L2 = [] ptr = 0 for i in range(0, len(s)): if s[i] == t[ptr]: L1.append(i) ptr += 1 if ptr >= len(t): break ptr = len(t) - 1 for i in range(len(s) - 1, -1, -1): if s[i] == t[ptr]: L2.append(i) ptr -= 1 if ptr < 0: break L2 =...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBE...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
s = input() t = input() def search(s, t): indext = 0 pos = [-1] for i in range(len(s)): if indext < len(t) and s[i] == t[indext]: pos += [i] indext += 1 if indext == len(t): return pos pos = search(s, t) right = len(s) - 1 ans = right - pos[-1] for i i...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR LIST VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASS...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
a = list(input()) b = list(input()) l = [(0) for i in range(len(a))] r = [(0) for i in range(len(a))] itr = 0 m = len(b) n = len(a) for i in range(len(a)): if itr < m and b[itr] == a[i]: itr += 1 l[i] = itr itr = 0 for i in range(len(a)): if itr < m and b[m - 1 - itr] == a[n - 1 - i]: itr +=...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
def f(s, t): right = [0] * len(t) for i in reversed(range(len(t))): pos = len(s) - 1 if i + 1 < len(t): pos = right[i + 1] - 1 while s[pos] != t[i]: pos -= 1 right[i] = pos ans = 0 pos = 0 for i in range(len(s)): rpos = len(s) - 1 ...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR...
The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ wit...
S = input() T = input() N, M = len(S), len(T) def calc(s, t): X = [0] * len(s) j = 0 for i in range(len(s)): if j >= len(t): X[i] = j elif s[i] == t[j]: X[i] = j + 1 j += 1 else: X[i] = X[i - 1] return [0] + X A, B = calc(S, T),...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMB...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
import sys (*data,) = sys.stdin.read().split("\n")[::-1] def input(): return data.pop() for _ in range(int(input())): n, l, r = map(int, input().split()) (*socks,) = map(int, input().split()) left_colors = [0] * n right_colors = [0] * n for v in socks[:l]: left_colors[v - 1] += 1 ...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING NUMBER FUNC_DEF RETURN FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FO...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
for _ in range(int(input())): n, l, r = map(int, input().split()) cl = [(0) for _ in range(n)] cr = [(0) for _ in range(n)] socks = list(map(int, input().split())) for x in socks[:l]: cl[x - 1] += 1 if r > 0: for x in socks[l:]: cr[x - 1] += 1 if l > r: cl...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER FOR...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
from sys import stdin, stdout def INI(): return int(stdin.readline()) def INL(): return [int(_) for _ in stdin.readline().split()] def INS(): return stdin.readline() def MOD(): return pow(10, 9) + 7 def OPS(ans): stdout.write(str(ans) + "\n") def OPL(ans): [stdout.write(str(_) + " ")...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING VAR VA...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
for tc in range(int(input())): n, l, r = map(int, input().split()) c = list(map(int, input().split())) if l == r: dic = {} for i in range(l): if c[i] not in dic: dic[c[i]] = 0 dic[c[i]] += 1 left = r for i in range(l, n): if...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_C...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
t = int(input()) for i in range(t): n, l, r = [int(x) for x in input().split()] lis = [int(x) for x in input().split()] dict1 = dict() dict2 = dict() for i in range(l): dict1[lis[i]] = dict1.get(lis[i], 0) + 1 for i in range(l, r + l): if lis[i] in dict1 and dict1[lis[i]] > 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NU...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
T = int(input()) for _ in range(T): N, L, R = map(int, input().split()) C = list(map(int, input().split())) MAX_C = max(C) LC = [(0) for i in range(MAX_C + 1)] RC = [(0) for i in range(MAX_C + 1)] for i in range(L): LC[C[i]] += 1 for i in range(L, N): RC[C[i]] += 1 for i ...
ASSIGN VAR FUNC_CALL 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP V...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
import sys def solve(N, L, R, A): my_dict = {} for a in A: my_dict[a] = [0, 0] for i in range(L): my_dict[A[i]][0] += 1 for i in range(L, N): my_dict[A[i]][1] += 1 mks = list(my_dict.keys()) recolor = 0 for mk in mks: recolor += abs(my_dict[mk][0] - my_dict[...
IMPORT FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
def main(): t = int(input()) for i in range(t): solve() def solve(): n, l, r = map(int, input().split()) a = list(map(int, input().split())) r = a[l:] l = a[:l] r.sort() l.sort() matched = 0 pass pl = len(l) - 1 pr = len(r) - 1 while pr != -1 and pl != -1: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUM...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
def main(): n, l, r = map(int, input().split()) k = n // 2 c = list(map(int, input().split())) c1, c2 = c[:l], c[l:] delta = abs(r - l) // 2 p1, p2 = [0] * n, [0] * n for i in range(l): p1[c1[i] - 1] += 1 for i in range(r): p2[c2[i] - 1] += 1 ans = 0 for i in rang...
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR ...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
for _ in range(int(input())): n, l, r = map(int, input().split()) a = [*map(int, input().split())] b = {} c = {} p, q = l, r for i in range(n): if i < l: b[a[i]] = b.get(a[i], 0) + 1 else: x = b.get(a[i], 0) if x == 1: p -= 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMB...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
import sys input = sys.stdin.readline for _ in range(int(input())): n, l, r = map(int, input().split()) left = [(0) for __ in range(n)] right = [(0) for __ in range(n)] a = list(map(int, input().split())) for i in range(l): left[a[i] - 1] += 1 for i in range(l, n): right[a[i] - ...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
for i in range(int(input())): n, l, r = map(int, input().split()) C = [int(i) for i in input().split()] cost, cost1, cost2 = 0, 0, 0 C1 = C[:l] C2 = C[l:] d1, d2 = dict(), dict() for i in C1: if i in d1: d1[i] += 1 else: d1[i] = 1 for j in C2: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR ...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
import sys input = sys.stdin.buffer.readline def map_int(): return map(int, input().split()) def solve(): n, l, r = map_int() c = list(map_int()) if r > l: c = c[l:n] + c[:l] l, r = r, l color = [0] * (n + 1) for i in range(n): color[c[i]] += 1 if i < l else -1 a...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR V...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
for i in range(int(input())): n, l, r = map(int, input().split()) allsocks = list(map(int, input().split())) leftsocks = sorted(allsocks[:l]) rightsocks = sorted(allsocks[l:]) a = b = 0 while a < l and b < r: if leftsocks[a] < rightsocks[b]: a += 1 elif leftsocks[a] >...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
for _ in range(int(input())): n, l, r = map(int, input().split()) arr = list(map(int, input().split())) dictl = {} for i in range(l): if dictl.get(arr[i]) is None: dictl[arr[i]] = 0 dictl[arr[i]] = dictl[arr[i]] + 1 dictr = {} for i in range(l, n): if dictr.ge...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NONE ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
t = int(input()) for _ in range(t): n, l, r = map(int, input().split()) c = list(map(int, input().split())) colors = [([0] * 2) for _ in range(n)] cost = 0 L = c[:l] R = c[l:] for i in L: if colors[i - 1][1] > 0: colors[i - 1][1] -= 1 else: colors[i - ...
ASSIGN VAR FUNC_CALL 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR ...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ t = int(input()) def makeDict(left): leftMap = {} for item in left: if item not in leftMap: leftMap[item] = 0 leftMap[item] += 1 return leftMap for _ in range(t): n, l, r = map(int, input().split...
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
for _ in range(int(input())): n, left, right = map(int, input().split()) arr1 = [0] * n arr2 = [0] * n for i, x in enumerate(map(int, input().split())): if i < left: arr1[x - 1] += 1 else: arr2[x - 1] += 1 result = abs(left - right) // 2 diff_pairs = resul...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSI...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
import sys input = sys.stdin.readline t = int(input()) for tests in range(t): n, l, r = map(int, input().split()) C = list(map(int, input().split())) L = [0] * n R = [0] * n for i in range(n): if i < l: L[C[i] - 1] += 1 else: R[C[i] - 1] += 1 for i in ran...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
for u in range(int(input())): n, l, r = map(int, input().split()) x = [] x.append([(0) for i in range(n)]) x.append([(0) for i in range(n)]) y = [int(w) for w in input().split()] for i in range(n): t = y[i] if i < l: x[0][t - 1] += 1 else: x[1][t -...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
import sys input = sys.stdin.readline def inp(): return int(input()) def inlt(): return list(map(int, input().split())) def insr(): s = input() return list(s[: len(s) - 1]) def invr(): return map(int, input().split()) tests = inp() for _ in range(tests): n, l, r = invr() c = inlt(...
IMPORT ASSIGN VAR 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 ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR ...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
t = int(input()) for _ in range(t): n, l, r = map(int, input().split()) C = list(map(int, input().split())) d = {} for i in range(1, n + 1): d.update({i: [0, 0]}) for i in range(l): d[C[i]][0] += 1 for i in range(l, n): d[C[i]][1] += 1 c = n // 2 - min(l, r) s = 0...
ASSIGN VAR FUNC_CALL 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR DICT VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
t = int(input()) for tk in range(t): n, l, r = map(int, input().split()) c = list(map(int, input().split())) d1 = {} d2 = {} for i in range(l): d1[c[i]] = d1.get(c[i], 0) + 1 for i in range(l, n): d2[c[i]] = d2.get(c[i], 0) + 1 for i in d1.keys(): x = min(d1[i], d2.ge...
ASSIGN VAR FUNC_CALL 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
import sys In = sys.stdin.readline T = int(In()) for tc in range(1, T + 1): n, l, r = map(int, In().split()) color = [(0) for _ in range(n + 1)] socks = list(map(int, In().split())) visited = {} left, right = {"total": 0, "odd": 0}, {"total": 0, "odd": 0} answer = 0 for i in range(l): ...
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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR VAR...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
for _ in range(int(input())): n, l, r = map(int, input().split()) c = list(map(int, input().split())) cs = set(c) lc = [] rc = [] for i in range(n): if i < l: lc.append(c[i]) else: rc.append(c[i]) ll = [0] * (n + 1) rr = [0] * (n + 1) for i in ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VA...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
t = int(input()) for case in range(1, t + 1): n, le, ri = [int(x) for x in input().split(" ")] socks = [int(x) for x in input().split(" ")] ans = 0 left = {} for sock in socks[:le]: if sock in left: left[sock] += 1 else: left[sock] = 1 right = {} for s...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
def sign(x): return 1 if x > 0 else -1 def main(): t = int(input()) for _ in range(t): n, l, r = map(int, input().split()) c = list(map(int, input().split())) d = {} for i in range(n): if c[i] not in d: if i < l: d[c[i]] = 1 ...
FUNC_DEF RETURN VAR NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR ASSIGN VA...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
import sys input = sys.stdin.buffer.readline for t in range(int(input())): N, L, R = map(int, input().split()) A = list(map(int, input().split())) for i in range(N): A[i] -= 1 if L > R: A = A[L:] + A[:L] L, R = R, L C = [0] * N for i in range(L): C[A[i]] += 1 ...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR ...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
import sys input = sys.stdin.readline def inI(): inputLine = input().split() return int(inputLine[0]) if len(inputLine) == 1 else map(int, inputLine) def inIL(): return list(map(int, input().split())) def inCL(): return list(input())[:-1] def out(*liste): if isinstance(liste[0], list): ...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR RETURN FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR ...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
g = int(input()) while g > 0: g -= 1 n, L, R = map(int, input().split()) a = list(map(int, input().split())) l = {} r = {} for i in range(n): if i < L: if a[i] not in l: l[a[i]] = 0 l[a[i]] += 1 else: if a[i] not in r: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUM...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
from sys import stdin, stdout for _ in range(int(stdin.readline())): n, l, r = map(int, stdin.readline().split()) arr = list(map(int, stdin.readline().split())) color = {} for a in range(l, n): if color.get(arr[a]) != None: color[arr[a]] += 1 else: color[arr[a]] ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR NONE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR DICT FOR V...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
t = int(input()) for f in range(t): n, l, r = map(int, input().split()) p = [int(x) for x in input().split()] le = p[0:l] ri = p[l:] le.sort() ri.sort() i = 0 j = 0 le1 = [] ri1 = [] while i < l and j < r: if le[i] == ri[j]: i += 1 j += 1 ...
ASSIGN VAR FUNC_CALL 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST AS...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
from sys import * ws = lambda: map(int, stdin.readline().strip().split()) li = lambda: list(map(int, stdin.readline().strip().split())) mod = 1000000007 def ncr(n, r, p): num = den = 1 for i in range(r): num = num * (n - i) % p den = den * (i + 1) % p return num * pow(den, p - 2, p) % p ...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
import sys input = sys.stdin.readline (T,) = map(int, input().split()) for _ in range(T): N, L, R = map(int, input().split()) X = list(map(int, input().split())) C1 = [0] * N C2 = [0] * N for i in range(N): if i < L: C1[X[i] - 1] += 1 else: C2[X[i] - 1] += 1 ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR V...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
for _ in range(int(input())): n, l, r = map(int, input().split()) t = list(map(int, input().split())) lc = [0] * (n + 1) rc = [0] * (n + 1) for i in range(1, n + 1): if i <= l: lc[t[i - 1]] += 1 else: rc[t[i - 1]] += 1 for i in range(1, n + 1): mn ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
T = int(input()) t = 1 while t <= T: n, l, r = map(int, input().split()) arr = list(map(int, input().split())) dic1 = {} dic2 = {} for i in range(l): if arr[i] not in dic1: dic1[arr[i]] = 0 dic1[arr[i]] += 1 for j in range(l, n): if arr[j] not in dic2: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
import sys def solve(n, l, r, arr): cnt = [(0) for i in range(n)] if l < r: l, r = r, l arr = arr[r:] + arr[:r] for i, c in enumerate(arr): if i < l: cnt[c - 1] += 1 else: cnt[c - 1] -= 1 a = 0 for c in cnt: if c > 0: a +=...
IMPORT FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR FUN...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
def answer(): rc = [0] * (n + 1) lc = [0] * (n + 1) for i in range(n): if i < l: lc[a[i]] += 1 else: rc[a[i]] += 1 v = n // 2 left = max(0, v - l) + max(0, v - r) for i in range(n + 1): m = min(rc[i], lc[i]) rc[i] -= m lc[i] -= m ...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
t = int(input()) while t: n, l, r = map(int, input().split()) a = list(map(int, input().split())) p = max(a) d1 = {} d2 = {} for i in range(0, p + 1): d1[i] = 0 d2[i] = 0 for i in range(0, l): d1[a[i]] += 1 for i in range(0, r): d2[a[l + i]] += 1 if r ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VA...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
for z in range(int(input())): n, l, r = [int(i) for i in input().split()] arr = [int(i) for i in input().split()] dl = {} dr = {} for i in range(l): if arr[i] not in dl: dl[arr[i]] = [] dl[arr[i]].append(i) for i in range(l, n): if arr[i] not in dr: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VA...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
for _ in range(int(input())): n, l, r = list(map(int, input().split())) ar = list(map(int, input().split())) rem, a, b = n, [0] * (n + 1), [0] * (n + 1) for i in range(l): a[ar[i]] += 1 for i in range(l, n): b[ar[i]] += 1 for i in range(1, n + 1): x = min(a[i], b[i]) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR V...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
from sys import stdin, stdout input = stdin.readline def im(): return map(int, input().split()) def ii(): return int(input()) def il(): return list(map(int, input().split())) def ins(): return input()[:-1] for _ in range(ii()): n, l, r = im() lis = il() left = lis[:l] right = ...
ASSIGN VAR VAR 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
def solve(): n, l, r = map(int, input().split()) c = list(map(int, input().split())) lc = [0] * (n + 1) rc = [0] * (n + 1) res = 0 for i in range(l): lc[c[i]] += 1 for i in range(l, n): rc[c[i]] += 1 for i in range(n): d = min(lc[i], rc[i]) lc[i] -= d ...
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VA...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
t = int(input()) for i in range(t): n, l, r = map(int, input().split()) z = list(map(int, input().split())) left_col = z[:l] right_col = z[l:] d1 = {} d2 = {} for j in range(1, n + 1): d1[j] = 0 d2[j] = 0 for j in range(len(left_col)): d1[left_col[j]] += 1 for...
ASSIGN VAR FUNC_CALL 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
total = 6 left = 3 right = 3 arr = [1, 2, 3, 1, 5, 6] def answer(total, left, right, arr): dp_left = [(0) for i in range(total)] dp_right = [(0) for i in range(total)] i = 0 while i < left: dp_left[arr[i] - 1] += 1 i += 1 while i < len(arr): dp_right[arr[i] - 1] += 1 ...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR BIN_OP VAR ...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
for _ in range(int(input())): n, l, r = map(int, input().split()) c = list(map(int, input().split())) sockc = [0] * (n + 1) cost = 0 for i in range(l): sockc[c[i]] += 1 for i in range(l, n): sockc[c[i]] -= 1 pos = 0 neg = 0 posodd = 0 negodd = 0 for i in range...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR V...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, z = list(map(int, input().split())) x = list(map(int, input().split())) x.sort() count = 0 i = 0 j = n // 2 while i < n // 2 and j < n: if x[j] - x[i] >= z: count += 1 i += 1 j += 1 print(count)
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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
N, Z = list(map(int, input().split())) X = list(map(int, input().split())) X.sort() def compute(x1, x2): count = 0 i = 0 j = 0 while i < len(x1) and j < len(x2): while x2[j] - x1[i] < Z: j += 1 if j == len(x2): return count count += 1 i +...
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 FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF VAR...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() k = n // 2 s = 0 mas = [0] * n for i in range(n): if mas[i] == 1: continue for j in range(k, n): if a[j] - a[i] >= m and mas[j] != 1: mas[i] = 1 mas[j] = 1 k = j + 1 s +=...
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 BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR ...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
_, z = list(map(int, input().split())) p = list(map(int, input().split())) p.sort() pos = -1 for i in range(len(p) // 2, len(p)): if p[i] >= p[0] + z: pos = i break if pos == -1: print(0) else: r = pos l = 0 ctr = 0 while True: if l == pos: break if r ...
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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_C...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
x, y = map(int, input().split()) a = list(map(int, input().split())) a.sort() i = 0 j = len(a) // 2 count = 0 while j < len(a): if abs(a[i] - a[j]) >= y: count += 1 a[i] = -1 a[j] = -1 else: j += 1 while i < len(a) and a[i] == -1: i += 1 while j < len(a) and (a[j]...
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 NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, z = map(int, input().split()) A = list(map(int, input().split())) A.sort() ans = 0 vis = [False] * n j = n // 2 for i in range(n // 2): if vis[i]: continue while j < n and A[j] - A[i] < z: j += 1 if j == n: break vis[j] = True j += 1 ans += 1 print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR ...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
from sys import stdin, stdout def main(): from sys import stdin, stdout def read(): return stdin.readline().rstrip("\n") def read_array(sep=None, maxsplit=-1): return read().split(sep, maxsplit) def read_int(): return int(read()) def read_int_array(sep=None, maxsplit=-1...
FUNC_DEF FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF NONE NUMBER RETURN FUNC_CALL FUNC_CALL VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF NONE NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING E...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, x = [int(i) for i in input().split()] A = [int(i) for i in input().split()] A.sort() taken = [0] * n r = n // 2 ans = 0 for i in range(n): if taken[i]: continue while r < n and A[r] - A[i] < x: r += 1 while r < n and taken[r]: r += 1 if r < n and A[r] - A[i] >= x: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, z = map(int, input().split()) li = sorted(list(map(int, input().split()))) i, j = 0, n // 2 count = 0 n = len(li) while i < n // 2 and j < n: if li[j] - li[i] >= z: count += 1 i += 1 j += 1 else: j += 1 print(count)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUM...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, z = list(map(int, input().split())) arr = list(map(int, input().split())) arr.sort() c = 0 l = 0 r = len(arr) // 2 while r < len(arr) and l < len(arr): if arr[l] == -1: l += 1 continue if arr[r] - arr[l] >= z and arr[r] != -1: arr[r] = -1 c += 1 r += 1 l += 1 ...
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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF BI...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, z = map(int, input().split()) arr = sorted(map(int, input().split())) i, j, count = 0, n // 2, 0 while i < n // 2 and j < n: if arr[i] + z <= arr[j]: count += 1 i += 1 j += 1 print(count)
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 VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, z = [int(x) for x in input().split(" ")] a = [int(x) for x in input().split(" ")] a.sort() res = 0 def can_match(k): if 2 * k > n: return False if k == 0: return True b = a[:] j = k for i in range(n): if b[i] != -1: while j < n and (j <= i or b[j] == -1 or b[...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF IF BIN_OP NUMBER VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER W...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, z = map(int, input().split()) lst = list(map(int, input().split())) lst.sort() beg = n // 2 cnt = 0 for i in range(n // 2): low = beg high = n - 1 while low < high: mid = (low + high) // 2 if lst[mid] - lst[i] >= z: high = mid elif lst[mid] - lst[i] < z: lo...
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 BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, z = map(int, input().split()) a = sorted(list(map(int, input().split()))) b = a[: n // 2] a = a[n // 2 :] i = 0 j = 0 ans = 0 while i < len(b) and j < len(a): if a[j] - b[i] >= z: ans += 1 i += 1 j += 1 else: j += 1 print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VA...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, z = [int(i) for i in input().split(" ")] nums = [int(i) for i in input().split(" ")] nums.sort() if n % 2 == 0: odd = nums[: n // 2] even = nums[n // 2 :] else: odd = nums[: n // 2] even = nums[n // 2 + 1 :] i, j = 0, 0 res = 0 while i < len(odd) and j < len(even): if abs(odd[i] - even[j]) >= z: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NU...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, m = map(int, input().split()) li = [int(k) for k in input().split()] mark = [0] * n i = 0 j = n // 2 li.sort() ans = 0 while i < n and j < n: if i != j and li[j] - li[i] >= m and mark[i] == 0 and mark[j] == 0: ans += 1 mark[i] = 1 mark[j] = 1 i += 1 j += 1 elif li[j] -...
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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBE...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
def li(): return list(map(int, input().split())) def num(): return map(int, input().split()) def nu(): return int(input()) def solve(): t = 1 for _ in range(t): n, z = num() a = li() a.sort() cc = 0 l = 0 end = n // 2 while l <= end: ...
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 RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER AS...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, z = map(int, input().split()) s = sorted(list(map(int, input().split()))) q = [(True) for n in range(n)] rt = 0 i = 0 j = n // 2 while i < n and j < n: while j < n and s[i] + z > s[j]: j += 1 if i < j < n and q[i] and q[j]: q[i] = False q[j] = False rt += 1 i += 1 j +=...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF ...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, z = map(int, input().split()) def can(x, c): for a, b in zip(x[:c], x[-c:]): if a + z > b: return False return True x = [int(x) for x in input().split()] x.sort() l = 0 r = n // 2 + 1 while r - l > 1: mid = (l + r) // 2 if can(x, mid): l = mid else: r = mid...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE BIN_OP VAR VAR NUMB...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, z = list(map(int, input().split())) l = list(map(int, input().split())) l = sorted(l) wyn = 0 maly = 0 duzy = n // 2 zaj = [0] * n while duzy < n: while maly < n: if zaj[maly] == 1: maly += 1 else: break if l[duzy] - l[maly] >= z and zaj[duzy] == 0 and zaj[maly] == 0: ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE VAR VAR WHILE VAR VAR IF VAR VAR NUMBER VAR NUMB...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
N, Z = list(map(int, input().split())) A = sorted([int(a) for a in input().split()]) l, r = 0, N // 2 + 1 while r - l > 1: m = (r + l) // 2 for i in range(m): if A[N - m + i] - A[i] < Z: r = m break else: l = m print(l)
ASSIGN VAR VAR FUNC_CALL 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 ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP BIN_OP VA...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
nzint = input().split() nz = [int(x) for x in nzint] input_string = input().split() intlist = [int(x) for x in input_string] intlist.sort() i, j = nz[0] - 1, nz[0] // 2 - 1 count = 0 while i >= nz[0] // 2 - 1 and j >= 0: if intlist[i] - intlist[j] >= nz[1]: count = count + 1 i = i - 1 j = j - 1 ...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER ...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, x = [int(i) for i in input().split()] nums = [int(i) for i in input().split()] nums.sort() left = 0 right = n + 1 count = 0 while True: if right - left <= 1 or right <= (n + 1) // 2: break c = 0 ok = True mid = int((left + right) / 2) for i in range(n - mid): if nums[mid + i] - nu...
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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN V...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, z = [int(x) for x in input().split()] b = sorted([int(x) for x in input().split()]) a = [] for item in b: a.append([item, 0]) end = n // 2 counter = 0 for i in range(n): if end == i: end += 1 for j in range(end, n): if a[j][0] - a[i][0] >= z and a[j][1] == a[i][1] == 0: end = ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR LIST VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, z = list(map(int, input().split())) X = list(map(int, input().split())) X.sort() l = n // 2 - 1 r = n - 1 m = (l + r) // 2 cnt = 0 for i in range(l, -1, -1): if X[r] - X[l] >= z: cnt += 1 l -= 1 r -= 1 else: l -= 1 print(cnt)
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 ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
def check(num): first = l[0:num] second = l[n - num : n] for i in range(num): if second[i] - first[i] < m: return False return True n, m = map(int, input().split()) l = list(map(int, input().split())) l.sort() low = 0 high = n // 2 while low < high: mid = (low + high) // 2 ...
FUNC_DEF ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
def ans(array, z): array.sort() left = 0 right = n // 2 + 1 while right - left > 1: mid = (left + right) // 2 good = True for i in range(mid): good &= array[n - mid + i] - array[i] >= z if good: left = mid else: right = mid ...
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR FUN...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
import sys readline = sys.stdin.buffer.readline read = sys.stdin.read 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, z = nm() a = sorted(nm()) ...
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 VAR FUNC_CALL VAR ASSIG...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, z = map(int, input().split()) a = [int(x) for x in input().split()] A = sorted(a) A.sort() a = 0 b = n // 2 while a < b: mid = (a + b + 1) // 2 if all(A[-mid + ind] - A[ind] >= z for ind in range(mid)): a = mid else: b = mid - 1 print(a)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR ...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() if len(a) % 2 == 0: x = len(a) // 2 else: x = len(a) // 2 + 1 i = 0 while x < len(a): if a[x] - a[i] >= k: i += 1 x += 1 print(i)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CA...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
def maxpairs(ls, mdiff): cou = 0 ls.sort() id2 = int(len(ls) / 2) for i in range(len(ls) // 2): flag = True cp_i = ls[i] while id2 <= len(ls) - 1: flag = False if cp_i + mdiff <= ls[id2]: cou += 1 id2 += 1 br...
FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR ...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, k = map(int, input().split()) l = [int(i) for i in input().split()] l.sort() def check(mi): try: if 2 * mi > n: return 0 l1 = [l[i] for i in range(mi)] l2 = [l[i] for i in range(n - mi, n)] for i in range(mi): if l1[i] + k > l2[i]: return ...
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 FUNC_DEF IF BIN_OP NUMBER VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VA...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
import sys input = sys.stdin.readline n, z = list(map(int, input().split())) X = list(map(int, input().split())) X.sort() def match(cut): i = 0 j = cut ANS = 0 for i in range(cut): while j < n and X[j] - X[i] < z: j += 1 if j == n: break else: ...
IMPORT ASSIGN 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 EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF ...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
def find(A, z): def check(k, z): L = A[:k] R = A[-k:] for i in range(len(L)): if abs(L[i] - R[i]) >= z: continue else: return False return True A = sorted(A) left = 0 right = len(A) // 2 while right - left > 1:...
FUNC_DEF FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR 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 N...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, x = [int(i) for i in input().split()] A = [int(i) for i in input().split()] A.sort() taken = [0] * n lo = 0 hi = n // 2 + 1 def check(sz): if sz > n // 2: return 0 left = A[:sz] right = A[-sz:] ok = 1 for i in range(len(left)): if right[i] - left[i] >= x: continue ...
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 EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR AS...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, z = map(int, input().split()) arrs = [int(x) for x in input().split()] arrs.sort() def fi(): j = len(arrs) // 2 while arrs[j] - arrs[0] < z and j < len(arrs) - 1: j += 1 l = 0 r = j arr = arrs[:] cnt = 0 while r != len(arr): if arr[l] == 10**10: l += 1 ...
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 FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSI...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
def max_pairs(arr, z): count = 0 N = len(arr) arr.sort() i = 0 mid = N // 2 + (1 if N % 2 else 0) j = mid while i < mid and j < N: while j < N and arr[j] - arr[i] < z: j += 1 if j != N: count += 1 i += 1 j += 1 return count def ma...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, z = list(map(int, input().split())) arr = list(map(int, input().split())) arr = [0] + arr s_arr = sorted(arr) f_arr = [1] * (n + 1) l = 1 r = int((n + 1) / 2) + 1 cnt = 0 while r <= n and l <= r: if s_arr[r] - s_arr[l] >= z: cnt += 1 l += 1 r += 1 print(cnt)
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 BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUM...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, z = map(int, input().split()) lst = list(map(int, input().split())) lst.sort() cnt = 0 begin = len(lst) // 2 for i in range(len(lst) // 2): if begin > len(lst) - 1: break elif lst[begin] - lst[i] >= z: cnt = cnt + 1 begin = begin + 1 continue else: while begin <= l...
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 NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR V...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
n, z = map(int, input().split()) x = sorted(list(map(int, input().split()))) ost = [] number = 0 for i in range(n // 2): ost.append(x[i]) j = 0 length = len(ost) for i in range(n // 2, n): if j < length and x[i] - x[j] >= z: j += 1 number += 1 print(number)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR N...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
def __starting_point(): n, z = map(int, input().split()) a = list(map(int, input().split())) a.sort() mask = [(0) for i in range(n)] start = int((n - 1) / 2) end = n - 1 res = 0 while end >= 0: if abs(a[start] - a[end]) >= z and mask[end] == 0 and mask[start] == 0: ma...
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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF FUNC...
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
def solve(): n, z = [int(s) for s in input().split(" ")] x = [int(s) for s in input().split(" ")] x.sort() def good(k): if 2 * k > n: return False for i in range(k): if x[-(k - i)] - x[i] < z: return False return True l = 0 r = n ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_DEF IF BIN_OP NUMBER VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER...