description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
p, s = map(int, input().split()) dic = {} for i in range(p): l1 = list(map(int, input().split())) l2 = list(map(int, input().split())) l2 = zip(l1, l2) l2 = sorted(l2, key=lambda x: x[0]) cnt = 0 for j in range(s - 1): if l2[j][1] > l2[j + 1][1]: cnt += 1 if cnt not in di...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR 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 VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUM...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
p, s = map(int, input().split(" ")) res = [] for _ in range(p): sc = list(map(int, input().split(" "))) ns = list(map(int, input().split(" "))) arr = [[sc[i], ns[i]] for i in range(s)] arr.sort(key=lambda x: x[0]) n = 0 for i in range(1, s): if arr[i - 1][1] > arr[i][1]: n +=...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CA...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
p, s = map(int, input().split()) tasks = [] def _difficulty(i, subtasks): subtasks = sorted(subtasks, key=lambda e: e[1]) n = 0 for k in range(len(subtasks) - 1): if subtasks[k][2] > subtasks[k + 1][2]: n += 1 return n, i for k in range(p): sc = list(map(int, input().split())...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FU...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
p, s = map(int, input().split()) difficulty = [] for i in range(p): sc = list(map(int, input().split())) ns = list(map(int, input().split())) sc, ns = zip(*sorted(zip(sc, ns))) n = 0 for j in range(1, s): if ns[j - 1] > ns[j]: n += 1 difficulty.append((n, i)) difficulty.sort(...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR ...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
p, s = map(int, input().split()) l = [] for i in range(1, p + 1): sc = list(map(int, input().split())) ns = list(map(int, input().split())) lr = [] for j in range(s): lr.append([sc[j], ns[j]]) lr.sort() cnt = 0 for k in range(s - 1): if lr[k][1] > lr[k + 1][1]: cn...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR 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 VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST ...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
p, sb = map(int, input().split()) ans = list() for i in range(p): s, n = list(map(int, input().split())), list(map(int, input().split())) lis = list() cnt = 0 for j in range(sb): lis.append([s[j], n[j]]) lis.sort() for j in range(sb - 1): if lis[j][1] > lis[j + 1][1]: ...
ASSIGN 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL V...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
p, s = map(int, input().split()) lst = [] for prob in range(p): score = list(map(int, input().split())) number = list(map(int, input().split())) order = {} for i in range(s): order[score[i]] = i score.sort() order1 = [number[order[score[i]]] for i in range(s)] val = 0 for i in ra...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN 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 VAR EXPR FUNC_CALL VAR ASS...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
p, s = map(int, input().rstrip().split()) res = [] for _ in range(p): a = list(map(int, input().rstrip().split())) b = list(map(int, input().rstrip().split())) arr = [] for i in range(s): arr.append([a[i], b[i]]) n = 0 arr.sort(key=lambda x: x[0]) for i in range(1, s): if arr...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL ...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
p, s = map(int, input().split()) l = [] for u in range(p): s1 = list(map(int, input().split())) n1 = list(map(int, input().split())) d = [[0, 0] for dd in range(s)] for w in range(s): d[w][0] = s1[w] d[w][1] = n1[w] d.sort() c = 0 for ss in range(s - 1): if d[ss][1] >...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VA...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
p1, n1 = list(map(int, input().split(" "))) x1 = list() j = "0" for i in range(p1): a1 = list(map(int, input().split(" "))) b1 = list(map(int, input().split(" "))) c = list() cx = 0 al = len(a1) for z in range(al): c.append((a1[z], b1[z])) c = sorted(c, key=lambda x: x[0]) ab = l...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
p, s = list(map(int, input().split())) nvalues = [] for i in range(p): difficult = [0, 0] n = 0 sc = list(map(int, input().split())) ns = list(map(int, input().split())) a = list(zip(sc, ns)) a.sort() for j in range(s - 1): if a[j][1] > a[j + 1][1]: n = n + 1 difficul...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER 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 ASSIGN VAR FUNC_CALL VAR ...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
p, s = map(int, input().split()) diff = {i: (0) for i in range(p)} for i in range(p): score = list(map(int, input().split())) arr = list(map(int, input().split())) a = [(score[i], arr[i]) for i in range(s)] a.sort() arr = [a[i][1] for i in range(s)] for j in range(s - 1): if arr[j] > arr...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
def calc(s, arr): count = 0 for i in range(s - 1): if arr[i][1] > arr[i + 1][1]: count += 1 return count p, s = map(int, input().split()) res = [] for i in range(p): sc = list(map(int, input().split())) ns = list(map(int, input().split())) arr = sorted([(sc[i], ns[i]) for i...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CA...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
P, S = list(map(int, input().split())) COUNT = [0] * 101010 A = [] B = [] for i in range(P): A = list(map(int, input().split())) B = list(map(int, input().split())) A, B = list(zip(*sorted(zip(A, B)))) for X in range(S - 1): if B[X] > B[X + 1]: COUNT[i] += 1 for i in range(31): f...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
p, s = [int(i) for i in input().split()] scores = {} for j in range(1, p + 1): sc = [int(i) for i in input().split()] ns = [int(i) for i in input().split()] nsc = dict(zip(sc, ns)) ssc = sorted(sc) score = 0 for a, b in zip(ssc[:-1], ssc[1:]): if nsc[a] > nsc[b]: score += 1 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER 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 FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
p, s = map(int, input().split()) diff = list() for i in range(s): diff.append([]) for i in range(p): n = 0 c = list(map(int, input().split())) sc = list(map(int, input().split())) dictionary = dict(zip(c, sc)) c.sort() for j in range(s - 1): if dictionary[c[j]] > dictionary[c[j + 1]]...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
P, S = list(map(int, input().split(" "))) d = [] for p in range(0, P): ST = list(map(int, input().split(" "))) N = list(map(int, input().split(" "))) c = 0 L = sorted(list(zip(ST, N))) for i in range(0, S - 1): if L[i][1] > L[i + 1][1]: c = c + 1 dd = () dd = c, p + 1 ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FU...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
p, s = map(int, input().split()) ans = [] for j in range(p): sc = list(map(int, input().split())) ns = list(map(int, input().split())) n = 0 a = [] for i in range(s): a.append((sc[i], ns[i])) a.sort() for i in range(s - 1): if a[i][1] > a[i + 1][1]: n += 1 k =...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
p, n = map(int, input().split()) diffs = [] for i in range(p): scores = [int(_) for _ in input().split()] subs = [int(_) for _ in input().split()] pairs = [[scores[i], subs[i]] for i in range(n)] pairs.sort(key=lambda x: x[0]) count = 0 for j in range(1, n): if pairs[j][1] < pairs[j - 1]...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR V...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
P, S = map(int, input().split()) scores = [[] for _ in range(P)] num_contestants = [[] for _ in range(P)] for i in range(P): scores[i] = list(map(int, input().split())) num_contestants[i] = list(map(int, input().split())) difficulties = [] for i in range(P): scores[i], num_contestants[i] = zip(*sorted(zip(s...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR 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 LIST FOR...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
t = [int(a) for a in input().split()] p = t[0] s = t[1] sc = [] ns = [] pair = [] ans = [] for x in range(2 * p): k = [int(a) for a in input().split()] if x % 2 == 0: sc.append(k) else: ns.append(k) for x in range(p): l = [] for y in range(s): l.append((sc[x][y], ns[x][y])) ...
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FU...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
P, S = map(int, input().split(" ")) difficulties = [] for p in range(P): scores = list(map(int, input().split(" "))) contestants = list(map(int, input().split(" "))) score_indices = sorted(list(range(S)), key=scores.__getitem__) n = 0 for s in range(S - 1): if contestants[score_indices[s]] >...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIG...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
l = input().split() l[0] = int(l[0]) l[1] = int(l[1]) d = {} kool = [] c = 0 for forbid in range(l[0]): l, n = input().split(), input().split() for i in range(len(l)): l[i] = int(l[i]) n[i] = int(n[i]) d[l[i]] = n[i] l.sort() for i in range(len(l) - 1): x, y = d[l[i]], d[...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VA...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
l_inp = input().split(" ") p = int(l_inp[0]) sub = int(l_inp[1]) diff = [] for i in range(p): score = [int(i) for i in input().split(" ")] ctr = 0 att = [int(i) for i in input().split(" ")] final = list(zip(score, att)) final.sort(key=lambda x: x[0]) j = 0 while j < sub - 1: if final...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CA...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
p, s = list(map(int, input().split())) sub = [] pro = [] t = [] for i in range(p): sub.append(list(map(int, input().split()))) pro.append(list(map(int, input().split()))) for i in range(p): t.append(list(zip(sub[i], pro[i]))) indices = [] for a in t: a.sort(key=lambda x: x[0]) m = 0 n = 0 wh...
ASSIGN 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 EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
P, S = list(map(int, input().split())) ans = [] for index in range(P): SC = list(map(int, input().split())) NS = list(map(int, input().split())) mlist = [] for i in zip(SC, NS): mlist.append(i) mlist = sorted(mlist, key=lambda z: (z[0], z[1]), reverse=False) counter = 0 for i in rang...
ASSIGN VAR VAR FUNC_CALL 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSI...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
p, s = list(map(int, input().split())) D = dict() index = 1 for _ in range(p): S = list(map(int, input().split())) N = list(map(int, input().split())) T = [(S[i], N[i]) for i in range(s)] T = sorted(T) N = [T[i][1] for i in range(s)] score = 0 for i in range(len(N) - 1): if N[i] > N[...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR V...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
ps = list(map(int, input().split())) p = ps[0] s = ps[1] pn = [] for i in range(p): sn = [] sl = list(map(int, input().split())) nl = list(map(int, input().split())) for j in range(s): sn.append((sl[j], nl[j])) sn.sort(key=lambda x: x[0]) c = 0 for k in range(s - 1): if sn[k]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST 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 FUNC_CALL...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
p, s = [int(x) for x in input().split()] difficulty = {} for i in range(p): problem = list( zip([int(x) for x in input().split()], [int(x) for x in input().split()]) ) problem.sort(key=lambda p: p[0]) n = 0 for j in range(1, s): if problem[j - 1][1] > problem[j][1]: n += ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VA...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
p, s = map(int, input().split()) l = [] din = [] for i in range(p): cnt = 0 Cs = list(map(int, input().split())) Ns = list(map(int, input().split())) for j in range(s): din.append((Cs[j], Ns[j])) din.sort() for j in range(s - 1): if din[j][1] > din[j + 1][1]: cnt += 1...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
p, s = input().split() p = int(p) s = int(s) n = [(0) for i in range(p)] for prob in range(p): points = list(map(int, input().split())) nop = list(map(int, input().split())) for i in range(s): nop[i] = [points[i], nop[i]] nop.sort() for i in range(s - 1): if nop[i][1] > nop[i + 1][1]...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR V...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
m, n = map(int, input().split()) a = [] b = [] for i in range(m): a.append(list(map(int, input().split()))) b.append(list(map(int, input().split()))) c = [] n2 = [] for j in range(m): for k in range(n): c.append([a[j][k], b[j][k]]) c.sort() n1 = 0 for r in range(n - 1): if c[r][1...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR V...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
res = [] n, s = map(int, input().split()) for _ in range(n): (*sub,) = map(int, input().split()) (*stud,) = map(int, input().split()) req = sorted(list(zip(sub, stud)), key=lambda x: x[0]) count = 0 prev = req[0][1] for i, j in req[1:]: if prev > j: count += 1 pre...
ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUM...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
prob, s = list(map(int, input().split())) p = [] for i in range(prob): temp = [] temp.append(list(map(int, input().split()))) temp.append(list(map(int, input().split()))) temp = [[temp[0][i], temp[1][i]] for i in range(s)] temp.sort() p.append(temp) ans = [] for i in range(prob): n = 0 f...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER VAR VAR NUMBER...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
import sys input = sys.stdin.readline def inp(): return int(input()) def inlt(): return list(map(int, input().split())) def insr(): return input().strip() def invr(): return map(int, input().split()) def outp(n): sys.stdout.write(str(n) + "\n") def outlt(lst): sys.stdout.write(" ".j...
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 RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF EXPR FUNC_CALL ...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
def difficulty(SC, NS): n = 0 zipped = sorted(zip(SC, NS)) for i in range(len(zipped) - 1): if zipped[i][1] > zipped[i + 1][1]: n += 1 return n P, S = map(int, input().split()) difficulties = [] for i in range(P): SC = list(map(int, input().split())) NS = list(map(int, inpu...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR...
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and t...
P, S = map(int, input().split(" ")) ans = [] for i in range(0, P): sc = list(map(int, input().split(" "))) ns = list(map(int, input().split(" "))) temp = {} for j in range(0, len(ns)): temp[sc[j]] = ns[j] key = temp.keys() key = sorted(key) n = 0 for k in range(0, len(key) - 1): ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR ...
You're given Q queries of the form (L, R). For each query you have to find the number of such x that L ≀ x ≀ R and there exist integer numbers a > 0, p > 1 such that x = a^{p}. -----Input----- The first line contains the number of queries Q (1 ≀ Q ≀ 10^5). The next Q lines contains two integers L, R each (1 ≀ L ≀...
import sys readline = sys.stdin.buffer.readline J = set() for i in range(2000): J.add(i**2) J.add(i**3) Ri = set() for p in range(5, 61, 2): if p % 3 == 0: continue for base in range(2, 10**9): if base in J: continue bp = pow(base, p) if bp > 10**18: ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER IF VAR VAR ASSIGN VAR FU...
You are given an array A of N integers A_{1}, A_{2}, \ldots, A_{N}. Determine if there are two [permutations] B and C of this array, for which the following condition is satisfied: * There doesn't exist a pair of integers (i, j) such that 1 ≀ i ≀ j ≀ N and (i, j) \neq (1, N), for which the subarray B[i:j] is a permuta...
for i in range(int(input())): n = int(input()) l = list(map(int, input().split())) lc = [] l.sort() for i in set(l): lc.append(l.count(i)) lc.sort(reverse=True) if lc[0] > n // 2: print("NO") continue if lc[0] + lc[1] == n: print("NO") continue ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER EXPR FUN...
You are given an array A of N integers A_{1}, A_{2}, \ldots, A_{N}. Determine if there are two [permutations] B and C of this array, for which the following condition is satisfied: * There doesn't exist a pair of integers (i, j) such that 1 ≀ i ≀ j ≀ N and (i, j) \neq (1, N), for which the subarray B[i:j] is a permuta...
tc = int(input()) for t in range(0, tc): length = int(input()) nums = list(map(int, input().split())) Map = {} for n in nums: Map[n] = Map.setdefault(n, 0) + 1 if Map[n] > length // 2: print("NO") break else: if len(Map) == 2 and length % 2 == 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF FU...
You are given an array A of N integers A_{1}, A_{2}, \ldots, A_{N}. Determine if there are two [permutations] B and C of this array, for which the following condition is satisfied: * There doesn't exist a pair of integers (i, j) such that 1 ≀ i ≀ j ≀ N and (i, j) \neq (1, N), for which the subarray B[i:j] is a permuta...
T = int(input()) for _ in range(T): N = int(input()) A = list(map(int, input().split())) A.sort() L = A[N // 2 :] L.extend(A[: N // 2]) f = False for i in range(N - 1): if A[i] == L[i]: f = True break if A[i] == L[i + 1] and A[i + 1] == L[i]: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBE...
You are given an array A of N integers A_{1}, A_{2}, \ldots, A_{N}. Determine if there are two [permutations] B and C of this array, for which the following condition is satisfied: * There doesn't exist a pair of integers (i, j) such that 1 ≀ i ≀ j ≀ N and (i, j) \neq (1, N), for which the subarray B[i:j] is a permuta...
t = int(input()) for _ in range(t): n = int(input()) arr = list(map(int, input().split())) arr.sort() x = list(set(arr)) flag = True for i in x: if arr.count(i) > n // 2: flag = False break if flag == True: if len(x) == 2 and arr.count(x[0]) == arr.cou...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ...
You are given an array A of N integers A_{1}, A_{2}, \ldots, A_{N}. Determine if there are two [permutations] B and C of this array, for which the following condition is satisfied: * There doesn't exist a pair of integers (i, j) such that 1 ≀ i ≀ j ≀ N and (i, j) \neq (1, N), for which the subarray B[i:j] is a permuta...
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) l.sort() pre = 0 xx = 0 d = dict() flag = False c = 0 for x in set(l): d[x] = l.count(x) if d[x] > pre: xx = x pre = d[x] if d[x] > n - d[x]: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CA...
You are given an array A of N integers A_{1}, A_{2}, \ldots, A_{N}. Determine if there are two [permutations] B and C of this array, for which the following condition is satisfied: * There doesn't exist a pair of integers (i, j) such that 1 ≀ i ≀ j ≀ N and (i, j) \neq (1, N), for which the subarray B[i:j] is a permuta...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) d = {} for i in a: if i in d: d[i] += 1 else: d[i] = 1 if max(d.values()) > n // 2: print("NO") continue if len(d) == 2: print("NO") continue...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL ...
You are given an array A of N integers A_{1}, A_{2}, \ldots, A_{N}. Determine if there are two [permutations] B and C of this array, for which the following condition is satisfied: * There doesn't exist a pair of integers (i, j) such that 1 ≀ i ≀ j ≀ N and (i, j) \neq (1, N), for which the subarray B[i:j] is a permuta...
for _ in range(int(input())): n = int(input()) l = input().split() d = {} for i in l: i = int(i) if i in d: d[i] += 1 else: d[i] = 1 l = [] for i in d: l.append([i, d[i]]) if len(l) == 1: print("NO") elif len(l) == 2: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER...
You are given an array A of N integers A_{1}, A_{2}, \ldots, A_{N}. Determine if there are two [permutations] B and C of this array, for which the following condition is satisfied: * There doesn't exist a pair of integers (i, j) such that 1 ≀ i ≀ j ≀ N and (i, j) \neq (1, N), for which the subarray B[i:j] is a permuta...
t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) d = {} for i in l: d[i] = d.get(i, 0) + 1 mx = 0 for i in d.values(): if i >= mx: mx = i if len(d) == 2: print("NO") elif n % 2 == 0: if mx <= n // 2: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR I...
You are given an array A of N integers A_{1}, A_{2}, \ldots, A_{N}. Determine if there are two [permutations] B and C of this array, for which the following condition is satisfied: * There doesn't exist a pair of integers (i, j) such that 1 ≀ i ≀ j ≀ N and (i, j) \neq (1, N), for which the subarray B[i:j] is a permuta...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) count = {} for i in range(n): if a[i] in count: count[a[i]] += 1 else: count[a[i]] = 1 if len(count.keys()) <= 2: print("NO") elif max(count.values()) > n // 2...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC...
You are given an array A of N integers A_{1}, A_{2}, \ldots, A_{N}. Determine if there are two [permutations] B and C of this array, for which the following condition is satisfied: * There doesn't exist a pair of integers (i, j) such that 1 ≀ i ≀ j ≀ N and (i, j) \neq (1, N), for which the subarray B[i:j] is a permuta...
def solution(): N = int(input()) A = list(map(int, input().split())) A.sort() stat = 1 for i in range((N + 1) // 2): if A[i] == A[i + N // 2]: print("NO") stat = 0 return if stat and N % 2 == 0 and A[0] == A[N // 2 - 1] and A[N // 2] == A[N - 1]: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR 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 BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER RETURN IF VAR BIN_OP VAR N...
You are given an array A of N integers A_{1}, A_{2}, \ldots, A_{N}. Determine if there are two [permutations] B and C of this array, for which the following condition is satisfied: * There doesn't exist a pair of integers (i, j) such that 1 ≀ i ≀ j ≀ N and (i, j) \neq (1, N), for which the subarray B[i:j] is a permuta...
def Print(arr): for ele in arr: print(ele, end=" ") print() t = int(input()) for _ in range(t): n = int(input()) arr = list(map(int, input().split())) arr.sort() ar = arr[n // 2 :] for i in range(n // 2): ar.append(arr[i]) ans = True for i in range(n): if ar...
FUNC_DEF FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_O...
You are given an array A of N integers A_{1}, A_{2}, \ldots, A_{N}. Determine if there are two [permutations] B and C of this array, for which the following condition is satisfied: * There doesn't exist a pair of integers (i, j) such that 1 ≀ i ≀ j ≀ N and (i, j) \neq (1, N), for which the subarray B[i:j] is a permuta...
def fi(): return int(input()) def li(): return list(map(int, input().split())) t = fi() for i in range(t): n = fi() a = li() m = {} for e in a: if e not in m: m[e] = 1 else: m[e] += 1 pos = True firstrot = 0 m = dict(sorted(m.items(), key=l...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VA...
You are given an array A of N integers A_{1}, A_{2}, \ldots, A_{N}. Determine if there are two [permutations] B and C of this array, for which the following condition is satisfied: * There doesn't exist a pair of integers (i, j) such that 1 ≀ i ≀ j ≀ N and (i, j) \neq (1, N), for which the subarray B[i:j] is a permuta...
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) arr.sort() flag = False mp = {} for i in arr: if i not in mp: mp[i] = 1 else: mp[i] += 1 if mp[i] > n // 2: flag = True if flag: print("NO"...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF V...
You are given an array A of N integers A_{1}, A_{2}, \ldots, A_{N}. Determine if there are two [permutations] B and C of this array, for which the following condition is satisfied: * There doesn't exist a pair of integers (i, j) such that 1 ≀ i ≀ j ≀ N and (i, j) \neq (1, N), for which the subarray B[i:j] is a permuta...
for cas in range(int(input())): n = int(input()) l = list(map(int, input().split())) l.sort() if len(set(l)) == 1: print("NO") continue if len(set(l)) == 2 and n % 2 == 0: i = 0 j = n - 1 flag = 0 while i < j: if l[i] == l[j]: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR...
You are given an array A of N integers A_{1}, A_{2}, \ldots, A_{N}. Determine if there are two [permutations] B and C of this array, for which the following condition is satisfied: * There doesn't exist a pair of integers (i, j) such that 1 ≀ i ≀ j ≀ N and (i, j) \neq (1, N), for which the subarray B[i:j] is a permuta...
t = int(input()) for _ in range(t): n = int(input()) line = input() a = list(map(int, line.split())) a.sort() counts = [[a[0], 1]] curr_value = a[0] for i in range(1, n): if a[i] == curr_value: counts[-1][1] += 1 else: curr_value = a[i] cou...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST LIST VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR NU...
You are given an array A of N integers A_{1}, A_{2}, \ldots, A_{N}. Determine if there are two [permutations] B and C of this array, for which the following condition is satisfied: * There doesn't exist a pair of integers (i, j) such that 1 ≀ i ≀ j ≀ N and (i, j) \neq (1, N), for which the subarray B[i:j] is a permuta...
def go(): for i in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = a b.sort() f = 0 for j in range((n + 1) // 2): if b[j] == b[j + n // 2]: print("NO") f = 1 break if f =...
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR ...
You are given an array A of N integers A_{1}, A_{2}, \ldots, A_{N}. Determine if there are two [permutations] B and C of this array, for which the following condition is satisfied: * There doesn't exist a pair of integers (i, j) such that 1 ≀ i ≀ j ≀ N and (i, j) \neq (1, N), for which the subarray B[i:j] is a permuta...
tt = int(input()) for _ in range(tt): n = int(input()) a = list(map(int, input().split())) d = {} for i in a: try: d[i] += 1 except KeyError: d[i] = 1 m = max(list(d.values())) k = len(list(d.keys())) if m > n // 2 or k <= 2: print("NO") ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FU...
You are given an array A of N integers A_{1}, A_{2}, \ldots, A_{N}. Determine if there are two [permutations] B and C of this array, for which the following condition is satisfied: * There doesn't exist a pair of integers (i, j) such that 1 ≀ i ≀ j ≀ N and (i, j) \neq (1, N), for which the subarray B[i:j] is a permuta...
t = int(input()) for test in range(t): n = int(input()) lst = list(map(int, input().split())) lst.sort() lst2 = lst[n // 2 :] + lst[: n // 2] ans = "YES" for i in range(n): if lst[i] == lst2[i]: ans = "NO" break p1 = 1 p2 = n - 2 while p1 < p2: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIG...
You are given an array A of N integers A_{1}, A_{2}, \ldots, A_{N}. Determine if there are two [permutations] B and C of this array, for which the following condition is satisfied: * There doesn't exist a pair of integers (i, j) such that 1 ≀ i ≀ j ≀ N and (i, j) \neq (1, N), for which the subarray B[i:j] is a permuta...
T = int(input()) for ts in range(T): N = int(input()) A = list(map(int, input().split(" "))) A.sort() C = A.copy() C = C[(N + 1) // 2 : N] + C[: (N + 1) // 2] check = True for i in range(N): if A[i] == C[i]: check = False break if N % 2 == 0 and A[N // 2 -...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSI...
You are given an array A of N integers A_{1}, A_{2}, \ldots, A_{N}. Determine if there are two [permutations] B and C of this array, for which the following condition is satisfied: * There doesn't exist a pair of integers (i, j) such that 1 ≀ i ≀ j ≀ N and (i, j) \neq (1, N), for which the subarray B[i:j] is a permuta...
for _ in range(int(input())): size = int(input()) L = list(map(int, input().split())) L.sort() s = set(L) c = 0 for i in s: if L.count(i) > size // 2: print("NO") c = 1 break if c == 1: continue if len(s) == 2: print("NO") ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF ...
Reca company makes monitors, the most popular of their models is AB999 with the screen size a Γ— b centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio x: y became popular with users. That's why the company wants to reduce monitor AB999 size so th...
def gcd(a, b): return a if b == 0 else gcd(b, a % b) def main(): width, height, x, y = map(int, input().split()) g = gcd(x, y) x, y = x // g, y // g mx_factor_width = width // x mx_factor_height = height // y common_factor = min(mx_factor_height, mx_factor_width) print("{} {}".format(x...
FUNC_DEF RETURN VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ...
Reca company makes monitors, the most popular of their models is AB999 with the screen size a Γ— b centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio x: y became popular with users. That's why the company wants to reduce monitor AB999 size so th...
__author__ = "Darren" def solve(): a, b, x, y = map(int, input().split()) g = gcd(x, y) x, y = x // g, y // g ans, the_a, the_b = 0, 0, 0 na, nb = a // x * x, a // x * y if nb > b: nb = 0 if na * nb > ans: ans, the_a, the_b = na * nb, na, nb nb, na = b // y * y, b // y ...
ASSIGN VAR STRING FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR ...
Reca company makes monitors, the most popular of their models is AB999 with the screen size a Γ— b centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio x: y became popular with users. That's why the company wants to reduce monitor AB999 size so th...
def gcd(a, b): return a if b == 0 else gcd(b, a % b) a, b, x, y = map(int, input().split()) g = gcd(x, y) x, y = x // g, y // g lo = 0 hi = 2000000000 while lo != hi: mid = (lo + hi + 1) // 2 if mid * x <= a and mid * y <= b: lo = mid else: hi = mid - 1 print(lo * x, lo * y)
FUNC_DEF RETURN VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP...
Reca company makes monitors, the most popular of their models is AB999 with the screen size a Γ— b centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio x: y became popular with users. That's why the company wants to reduce monitor AB999 size so th...
def gcd(x, y): while y: x, y = y, x % y return x a, b, x, y = input().split() a = int(a) b = int(b) x = int(x) y = int(y) pig = gcd(x, y) x //= pig y //= pig lav = min(a // x, b // y) print(lav * x, lav * y)
FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_...
Reca company makes monitors, the most popular of their models is AB999 with the screen size a Γ— b centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio x: y became popular with users. That's why the company wants to reduce monitor AB999 size so th...
def GCD(x, y): while y: x, y = y, x % y return x n, m, x, y = map(int, input().split()) q = GCD(x, y) x = x // q y = y // q n1 = n // x n11 = n1 * x m1 = n1 * y m2 = m // y m21 = m2 * y n2 = m2 * x c1 = n11 * m1 c2 = m21 * n2 c = n * m if c >= c1 and c >= c2: if c1 >= c2: print(n11, m1) ...
FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR AS...
Reca company makes monitors, the most popular of their models is AB999 with the screen size a Γ— b centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio x: y became popular with users. That's why the company wants to reduce monitor AB999 size so th...
def greatest_common_divisor(m, n): while n != 0: m, n = n, m % n return m def reca(a, b, x, y): gcd = greatest_common_divisor(x, y) x //= gcd y //= gcd if a < x or b < y: print(0, 0) return min_a = a // x min_b = b // y max_factor = min(min_a, min_b) a =...
FUNC_DEF WHILE VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER RETURN ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR...
Reca company makes monitors, the most popular of their models is AB999 with the screen size a Γ— b centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio x: y became popular with users. That's why the company wants to reduce monitor AB999 size so th...
def gcd(a, b): if a % b == 0: return b return gcd(b, a % b) a, b, x, y = map(int, input().split()) t = gcd(x, y) x, y = x // t, y // t k = min(a // x, b // y) print(k * x, k * y)
FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN...
Reca company makes monitors, the most popular of their models is AB999 with the screen size a Γ— b centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio x: y became popular with users. That's why the company wants to reduce monitor AB999 size so th...
def dt(a, b): while b != 0: a, b = b, a % b return a a1, b1, x, y = map(int, input().split()) t = dt(x, y) x1 = x // t y1 = y // t d = min(a1 // x1, b1 // y1) print("{} {}".format(d * x1, d * y1))
FUNC_DEF WHILE VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP V...
Reca company makes monitors, the most popular of their models is AB999 with the screen size a Γ— b centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio x: y became popular with users. That's why the company wants to reduce monitor AB999 size so th...
a, b, x, y = [int(x) for x in input().split()] def gcd(r, s): if r == 0 or s == 0: return r + s elif r > s: return gcd(r % s, s) else: return gcd(r, s % r) g = gcd(x, y) x1 = int(x / g) y1 = int(y / g) if x1 <= a and y1 <= b: c = 0 while x1 * c <= a and y1 * c <= b: ...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN BIN_OP VAR VAR IF VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP...
Reca company makes monitors, the most popular of their models is AB999 with the screen size a Γ— b centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio x: y became popular with users. That's why the company wants to reduce monitor AB999 size so th...
f = lambda x, y: f(y % x, x) if x else y a, b, x, y = map(int, input().split()) z = f(x, y) x //= z y //= z m = min(a // x, b // y) print(m * x, m * y)
ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def countTriplets(self, Arr, N, L, R): Arr.sort() counti1 = 0 counti2 = 0 for i in range(N): j = i + 1 k = N - 1 while j < k: if Arr[i] + Arr[j] + Arr[k] <= R: counti1 += k - j ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN ...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def solve(self, arr, target): count = 0 n = len(arr) for i in range(n): j = i + 1 k = n - 1 while j < k: _sum = arr[i] + arr[j] + arr[k] if _sum <= target: count += k - j ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def countTriplets(self, Arr, N, L, R): Arr.sort() ans = 0 for i in range(N): j = i + 1 k = N - 1 while j < k: if Arr[i] + Arr[j] + Arr[k] <= R: ans += k - j j += 1 eli...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def count(self, Arr, N, val): Arr.sort() ans = 0 j = 0 k = 0 sum = 0 for i in range(0, N - 2): j = i + 1 k = N - 1 while j != k: sum = Arr[i] + Arr[j] + Arr[k] if sum > val: ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR BIN_OP VAR VAR V...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def countTriplets(self, Arr, N, L, R): Arr.sort() lower = 0 upper = 0 for i in range(len(Arr)): start = i + 1 end = len(Arr) - 1 while start < end: summ = Arr[start] + Arr[end] if summ < L - Arr[i]: ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL V...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def countTriplets(self, Arr, N, L, R): Arr.sort() c = 0 for i in range(N - 2): j = i + 1 k = N - 1 while j < k: g = Arr[i] + Arr[j] + Arr[k] if g >= L and g <= R: h = j + 1 ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def countTriplets(self, Arr, N, L, R): Arr.sort() c = 0 c1 = 0 for i in range(len(Arr) - 2): j = i + 1 k = N - 1 while j < k: s = Arr[i] + Arr[j] + Arr[k] if s < L: c += k - j ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER FOR VAR ...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def countLessOrEqual(self, arr, n, k): c = 0 for i in range(n - 1): l, r = i + 1, n - 1 while l < r: sum = arr[i] + arr[l] + arr[r] if sum <= k: c += r - l l += 1 else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR VA...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def countTriplets(self, Arr, N, L, R): Arr.sort() result = self.find_count(Arr, N, R) - self.find_count(Arr, N, L - 1) return result def find_count(self, nums, n, target): count = 0 for i in range(0, n - 2): low = i + 1 high = n -...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR ...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def countTriplets(self, arr, n, l, r): arr.sort() countLessL = 0 countGreaterR = 0 totalTriplets = n * (n - 1) * (n - 2) // 6 for i in range(n - 2): start = i + 1 end = n - 1 target = l - arr[i] while start < en...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def countTriplets(self, Arr, N, L, R): Arr.sort() count1 = 0 count2 = 0 triplets = 0 i = 0 while i < N - 2: low = i + 1 high = N - 1 while low < high: if Arr[i] + Arr[low] + Arr[high] <= R: ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NU...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def countTriplets(self, arr, N, a, b): def sol(nums, X): res = [] nums.sort() ans = 0 for i, a in enumerate(nums): l, r = i + 1, len(nums) - 1 while l < r: threeSum = a + nums[l] + nums[r] ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSI...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def countTriplets(self, Arr, N, L, R): Arr.sort() count1 = 0 for i in range(N - 2): l = i + 1 r = N - 1 while l < r: suma = Arr[i] + Arr[l] + Arr[r] if suma < L: count1 += r - l ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR ...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def countTriplets(self, Arr, N, L, R): count = 0 Arr.sort() for ele in range(N): i = ele + 1 j = N - 1 while i < j: a = Arr[ele] + Arr[i] + Arr[j] if a >= L and a <= R: e = i ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR WHILE VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NU...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def cnt_less_than(self, arr, n, maxi): cnt = j = k = 0 for i in range(0, n - 2): j = i + 1 k = n - 1 while j != k: if arr[i] + arr[j] + arr[k] <= maxi: cnt += k - j j += 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR RETURN...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def helper(self, arr, N, K): res = 0 for i in range(N - 1): j = i + 1 k = N - 1 while j < k: if arr[i] + arr[j] + arr[k] > K: k -= 1 else: res += k - j j +...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NU...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def countTriplets(self, a, n, L, R): if n < 3: return 0 a = sorted(a) c1 = 0 for curr in range(n - 2): l = curr + 1 r = n - 1 while l < r: val = a[curr] + a[l] + a[r] if val > R: ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NU...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def countTriplets(self, a, n, l, r): return rt(a, n, l, r) def rt(a, n, l, r): c = 0 c1 = 0 a.sort() l = l - 1 for i in range(0, len(a) - 2): l1 = i + 1 h1 = len(a) - 1 while l1 < h1: if a[i] + a[l1] + a[h1] <= l: c =...
CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def countTriplets(self, arr, n, L, R): def rpair(first, target, start, end, arr): count = 0 while start < end: sm = first + arr[start] + arr[end] if sm <= target: count += end - start start += 1...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASS...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def countTriplets(self, Arr, N, L, R): def findPairCount(arr, curr, start, range): end = len(arr) - 1 count = 0 while start < end: if arr[curr] + arr[start] + arr[end] < range: count += end - start ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VA...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def countTriplets(self, arr, n, L, R): arr = sorted(arr) greater = self.countsum(arr, R, True) smaller = self.countsum(arr, L, False) return greater - smaller def countsum(self, arr, val, equal): k = len(arr) - 1 count = 0 while k >= 2: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def countTriplets(self, A, N, L, R): if N < 3: return 0 def twopointer(A, N, tar): ans = 0 for i in range(N - 2): j = i + 1 k = N - 1 while k > j: sm = A[i] + A[j] + A[k] ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR RET...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def countTriplets(self, Arr, N, L, R): Arr = sorted(Arr) left_count = 0 right_count = 0 for i in range(N - 2): left_count += self.target_pair(Arr, i + 1, L - 1, N, Arr[i]) right_count += self.target_pair(Arr, i + 1, R, N, Arr[i]) ans =...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NU...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def count(self, a, N, K): ans = 0 a.sort() for i in range(N - 1): j = i + 1 k = N - 1 while j < k: if a[i] + a[j] + a[k] > K: k -= 1 else: ans += k - j ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FU...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def solve(self, a, n, k): ans = 0 for i in range(n): x = a[i] low = i + 1 high = n - 1 while low < high: s = x + a[low] + a[high] if s > k: high -= 1 else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR RETURN BIN_OP FUNC_CALL VAR VA...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def countTriplets(self, Arr, N, L, R): def findpair(arr, target): start = 0 nonlocal count end = len(arr) - 1 while start < end: if arr[start] + arr[end] <= target: count += end - start ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VA...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def countTriplets(self, arr, n, l, r): arr.sort() def countLesserEqual(x): count = 0 for i in range(n - 2): start = i + 1 end = n - 1 target = x - arr[i] while start < end: s...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR RETURN BIN_OP FU...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def countTriplets(self, Arr, N, L, R): def helper(Arr, N, target): count = 0 for i in range(0, N - 2): start = i + 1 end = N - 1 s = 0 while start != end: s = Arr[i] + Arr[start] + A...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR NUMBER EXPR FU...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def countTriplets(self, Arr, N, L, R): if N < 3: return 0 return self.countTripletsBoundary(Arr, N, R) - self.countTripletsBoundary( Arr, N, L - 1 ) def countTripletsBoundary(self, Arr, N, T): Arr.sort() vCount = 0 vLoopSu...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASS...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
def findCount(nums, target): count = 0 for i in range(len(nums)): low, high = i + 1, len(nums) - 1 while low < high: if nums[i] + nums[high] + nums[low] > target: high -= 1 else: count += high - low low += 1 return count...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
def findTriplets(arr, n, sum): arr.sort() ans = 0 for i in range(0, n - 1): l = i + 1 r = n - 1 x = arr[i] while l < r: if x + arr[l] + arr[r] <= sum: ans += r - l l += 1 else: r = r - 1 return ans ...
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR CLASS_DEF FUNC_DEF RETURN...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
class Solution: def countTriplets(self, arr, N, L, R): arr.sort() ans = 0 s = 0 lt = [] for i in range(N - 1, 0, -1): k = 0 j = i - 1 while k < j: t = arr[i] + arr[k] + arr[j] if t >= L: ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUM...