description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For exampl...
def correct(a): n = len(a) for i in range(n): for j in range(len(a[i])): if a[i][j] < len(a[i]) - j - 1: return False return True n = int(input()) a = list(map(int, input().split())) a.sort(reverse=True) ans = n for i in range(n, 0, -1): cur = [] for j in range(...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER 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 V...
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For exampl...
t = [] n = int(input()) a = sorted(list(map(int, input().split()))) for i in range(n): t = sorted(t)[::-1] flg = True for j in range(len(t)): if a[i] >= t[j]: t[j] += 1 flg = False break if flg: t.append(1) print(len(t))
ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR ...
John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly k cycles of length 3. A cycle of length 3 is an unordered group of three distinct graph vertices a, b and c, such that each pair of them is connected by a graph edge. John has been pa...
def f_3(n): return n * (n - 1) * (n - 2) // 6 def f_2(n): return n * (n - 1) // 2 a_3 = [f_3(i) for i in range(100)] a_2 = [f_2(i) for i in range(100)] def find_2(x, a): arr = [] cur = len(a) - 1 while x > 0: while x < a[cur]: cur -= 1 arr.append(cur) x -= a...
FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER W...
John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly k cycles of length 3. A cycle of length 3 is an unordered group of three distinct graph vertices a, b and c, such that each pair of them is connected by a graph edge. John has been pa...
n = 100 g = [set() for i in range(n)] k = int(input()) ans = 0 flag = False for l in range(n): for r in range(l + 1): if l == r or l in g[r]: continue count = 0 for u in range(n): if u == l or u == r: continue if l in g[u] and r in g[u]: ...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR V...
John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly k cycles of length 3. A cycle of length 3 is an unordered group of three distinct graph vertices a, b and c, such that each pair of them is connected by a graph edge. John has been pa...
n, k = 0, int(input()) p = [(["0"] * 100) for i in range(100)] while k: for i in range(n): if i > k: break p[n][i] = p[i][n] = "1" k -= i n += 1 print(n) for i in range(n): print("".join(p[i][:n]))
ASSIGN VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING NUMBER VAR FUNC_CALL VAR NUMBER WHILE VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR STRING VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR
John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly k cycles of length 3. A cycle of length 3 is an unordered group of three distinct graph vertices a, b and c, such that each pair of them is connected by a graph edge. John has been pa...
k = int(input()) p = [(["0"] * 100) for j in range(100)] g = lambda n: n * (n * n - 1) // 6 i = n = 0 while g(n + 1) <= k: n += 1 while i < n + 1: for j in range(i): p[i][j] = p[j][i] = "1" i += 1 k -= g(n) g = lambda n: n * n - n >> 1 while k: n = 0 while g(n + 1) <= k: n += 1 f...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER WHILE FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VA...
John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly k cycles of length 3. A cycle of length 3 is an unordered group of three distinct graph vertices a, b and c, such that each pair of them is connected by a graph edge. John has been pa...
n = int(input()) a = [] MAXN = 100 for i in range(MAXN): a.append([0] * MAXN) for i in range(3): for j in range(3): if i != j: a[i][j] = 1 cycles = 1 if cycles != n: for i in range(3, MAXN): if cycles == n: break a[i][0] = a[0][i] = 1 a[i][1] = a[1][i]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR ...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = [int(i) for i in input().split()] s = [int(i) for i in input().split()] s.sort() t = len(s) - 1 for i in range(n): if s[i] > a: t = i - 1 break if n == 1: print(0) elif t == -1: print(abs(s[-2] - a)) elif t == n - 1: print(abs(a - s[1])) elif t == 0: print( min(abs(s[-...
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 FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL V...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = map(int, input().split()) N = sorted(list(map(int, input().split()))) dist = 0 if n == 1: dist = 0 elif n == 2: dist = min(abs(N[0] - a), abs(N[1] - a)) elif a <= N[0]: dist = abs(N[-2] - a) elif a >= N[-1]: dist = abs(a - N[1]) elif a >= N[-2]: dist = min( abs(a - N[0]), 2 * ...
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 IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER ASS...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
def s(): [n, a] = list(map(int, input().split())) x = list(map(int, input().split())) x.sort() if n == 1: print(0) return print( min( x[-1] - x[1] + min(abs(x[-1] - a), abs(x[1] - a)), x[-2] - x[0] + min(abs(x[-2] - a), abs(x[0] - a)), ) ) ...
FUNC_DEF ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_O...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = map(int, input().split()) ip = list(map(int, input().split())) try: if a not in ip: ip.append(a) n += 1 ip = sorted(ip) k = ip.index(a) l1 = 0 l2 = 0 for i in range(k): l1 += ip[i + 1] - ip[i] for i in range(k, n - 1): l2 += ip[i + 1] - ip[i] n1 = 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 IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBE...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = input().strip().split(" ") n, a = int(n), int(a) l = list(map(int, input().strip().split(" "))) l.sort() if n == 1: print(0) exit() elif n == 2: print(min(abs(l[1] - a), abs(l[0] - a))) exit() elif a < l[0]: print(abs(l[-2] - a)) exit() elif a > l[-1]: print(abs(l[1] - a)) exit() ...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
N, A = list(map(int, input().split())) X = list(map(int, input().split())) X.sort() if N == 1: print(0) return elif N == 2: print(min(abs(X[0] - A), abs(X[1] - A))) return ans = int(1e18) ans = min(ans, abs(X[N - 2] - X[0]) + min(abs(A - X[0]), abs(A - X[N - 2]))) ans = min(ans, abs(X[N - 1] - X[1]) + m...
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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER V...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = list(map(int, input().split())) b = list(map(int, input().split())) b.sort() if len(b) == 1: print(0) elif len(b) == 2: print(min(abs(a - b[0]), abs(a - b[1]))) elif a < b[0]: print(b[-2] - a) elif a > b[-1]: print(a - b[1]) elif a == b[0]: print(b[-2] - a) elif a == b[-1]: print(a - b[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 IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VA...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
from sys import stdin def main(): n, a = stdin_get_ints_from_line() x = stdin_get_ints_list_from_line() x.sort() if n == 1: print(0) exit() print(min(get_result(a, x[1], x[-1]), get_result(a, x[0], x[-2]))) def get_result(a, left, right): if left < a < right: if abs(a...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER FUNC_DEF IF VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL ...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
inp1 = input() inp11 = inp1.split(" ") n = int(inp11[0]) a = int(inp11[1]) inp2 = input() inp21 = inp2.split(" ") x0 = [] for i in inp21: j = int(i) x0.append(j) x = sorted(x0) def f(x): if x > 0: return x else: return 0 if n > 1: len1 = 2 * f(a - x[0]) + f(x[n - 2] - a) len2...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RE...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = map(int, input().split()) L = list(map(int, input().split())) L.sort() if n == 1: print(0) elif a >= L[n - 1]: print(a - L[1]) elif a <= L[0]: print(L[n - 2] - a) else: gauche = min(abs(a - L[0]), abs(L[n - 2] - a)) + L[n - 2] - L[0] droite = min(abs(a - L[1]), abs(L[n - 1] - a)) + L[n - 1] -...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER V...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = [int(i) for i in input().split()] coords = [int(i) for i in input().split()] coords = sorted(coords) if n == 1: print(0) else: var1 = abs(a - coords[0]) + coords[-2] - coords[0] var2 = abs(a - coords[1]) + coords[-1] - coords[1] var3 = abs(a - coords[-2]) + coords[-2] - coords[0] var4 = abs(a...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR ...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
import sys def read_data(): n, x0 = list(map(int, next(sys.stdin).split())) checkpoints = list(map(int, next(sys.stdin).split())) return x0, checkpoints def solve(x0, checkpoints): n = len(checkpoints) checkpoints.sort() if n == 1: return 0 case0 = abs(x0 - checkpoints[1]) + abs(...
IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = map(int, input().split()) x = [*map(int, input().split())] x.sort() if n == 1: print(0) exit(0) ind = 0 dist1 = min(abs(a - x[n - 1]), abs(a - x[1])) + abs(x[n - 1] - x[1]) dist2 = min(abs(a - x[0]), abs(a - x[n - 2])) + abs(x[0] - x[n - 2]) print(min(dist1, dist2))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VA...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
read = lambda: map(int, input().split()) n, a = read() x = sorted(read()) if n == 1: print(0) exit() c = [float("inf")] * 10 c[0] = abs(a - x[1]) + abs(x[-1] - x[1]) c[1] = abs(a - x[0]) + abs(x[-2] - x[0]) c[2] = abs(a - x[-1]) + abs(x[-1] - x[1]) c[3] = abs(a - x[-2]) + abs(x[-2] - x[0]) ans = min(c) print(an...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUM...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
def second_min(x): m = 1000001 sm = 1000001 for elem in x: if elem < m: sm = m m = elem elif elem < sm: sm = elem return m, sm def second_max(x): m = -1000001 sm = -1000001 for elem in x: if elem > m: sm = m ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = map(int, input().split()) x = list(map(int, input().split())) if n == 1: print(0) elif n == 2: if abs(x[0] - a) < abs(x[1] - a): print(abs(x[0] - a)) else: print(abs(x[1] - a)) elif n == 3: x = sorted(x) _min = x[0] _mid = x[1] _max = x[2] ans = abs(_max - a) * 2 +...
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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CA...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = map(int, input().split()) l = input().split() l = [int(i) for i in l] if n == 1: print(0) elif n == 2: if abs(a - l[0]) < abs(a - l[1]): print(abs(a - l[0])) else: print(abs(a - l[1])) else: ma = max(l) mi = min(l) l.remove(ma) max2 = max(l) l.append(ma) l.remo...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FU...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = list(map(int, input().split())) x = list(map(int, input().split())) x.sort() res = 2**30 def solve(a, i, j): if a >= x[j]: return a - x[i] elif a <= x[i]: return x[j] - a else: sumLeft = (a - x[i]) * 2 + x[j] - a sumRight = (x[j] - a) * 2 + a - x[i] return mi...
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 NUMBER NUMBER FUNC_DEF IF VAR VAR VAR RETURN BIN_OP VAR VAR VAR IF VAR VAR VAR RETURN BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP V...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, pos = map(int, input().split()) a = list(map(int, input().split())) a.sort() def solve(left, right): if pos < a[left]: return a[right] - pos if pos > a[right]: return pos - a[left] return min( 2 * (pos - a[left]) + a[right] - pos, 2 * (a[right] - pos) + pos - a[left] ) if ...
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 FUNC_DEF IF VAR VAR VAR RETURN BIN_OP VAR VAR VAR IF VAR VAR VAR RETURN BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
import sys import time startTime = time.time() n, a = map(int, sys.stdin.readline().split()) x = sys.stdin.readline().split() x = [int(num) for num in x] def minDistance(n, a, x): x.sort() ans = 0 if n == 1: ans = 0 elif n == 2: ans = abs(x[0] - a) tmpAns = abs(x[1] - a) ...
IMPORT IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FU...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = list(map(int, input().split())) points = list(map(int, input().split())) points.sort() if n == 1: print(0) exit() ans1 = abs(a - points[0]) + abs(points[0] - points[-2]) ans2 = abs(a - points[1]) + abs(points[1] - points[-1]) ans3 = abs(a - points[-1]) + abs(points[-1] - points[1]) ans4 = abs(a - points[...
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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN ...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
def not_left(a, x): right = abs(x[-1] - a) left = abs(a - min(a, x[1])) return min(left, right) * 2 + max(left, right) def not_right(a, x): right = abs(max(a, x[-2]) - a) left = abs(a - x[0]) return min(left, right) * 2 + max(left, right) n, a = map(int, input().split()) x = sorted(list(map(...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = map(int, input().split()) l = sorted(list(map(int, input().split()))) if len(l) == 1: print(0) exit() m = float("inf") if len(l) == 2: print(min(abs(a - l[0]), abs(a - l[1]))) exit() for i in [0, n - 1]: if i == 0: x = abs(l[-1] - l[1]) + min(abs(a - l[1]), abs(a - l[-1])) else: ...
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 IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BI...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
import sys n, a = map(int, input().split()) x = list(map(int, sys.stdin.read().split())) x.sort() def dist(x, a): assert len(x) >= 2 if x[0] < a < x[-1]: return min(a - x[0], x[-1] - a) + x[-1] - x[0] else: return max(abs(x[0] - a), abs(x[-1] - a)) if n == 1: print(0) elif n == 2: ...
IMPORT 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 FUNC_DEF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = list(map(int, input().split())) x = list(map(int, input().split())) def visit(a, b, c): if a <= b: return c - a if a >= c: return a - b return c - b + min(c - a, a - b) x.sort() if n <= 1: print(0) elif a <= x[0]: print(x[-2] - a) elif a >= x[-1]: print(a - x[1]) else:...
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 FUNC_DEF IF VAR VAR RETURN BIN_OP VAR VAR IF VAR VAR RETURN BIN_OP VAR VAR RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER E...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = map(int, input().split()) l = list(map(int, input().split())) l.sort() if n == 1: print(0) else: x = min(abs(a - l[0]), abs(a - l[-2])) + l[-2] - l[0] y = min(abs(a - l[1]), abs(a - l[-1])) + l[-1] - l[1] ans = min(x, y) 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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSI...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = list(map(int, input().split())) x = list(sorted(map(int, input().split()))) print( min( abs(x[n - 1] - a) + x[n - 1] - x[1], abs(x[n - 2] - a) + x[n - 2] - x[0], abs(x[0] - a) + x[n - 2] - x[0], abs(x[1] - a) + x[n - 1] - x[1], ) if n > 1 else 0 )
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR BI...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = map(int, input().split()) checkpoints = list(map(int, input().split())) checkpoints.append(a) checkpoints.sort() len_new = len(checkpoints) dis_to_first = abs(a - checkpoints[0]) dis_to_first_after = abs(a - checkpoints[1]) dis_to_last = abs(a - checkpoints[len_new - 1]) dis_to_last_before = abs(a - checkpoints[...
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 VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = list(map(int, input().split())) line = list(map(int, input().split())) line.sort() if len(line) == 1: print(0) else: r1 = abs(line[-1] - line[1]) otvet1 = min(abs(a - line[1]), abs(a - line[-1])) + r1 r2 = abs(line[-2] - line[0]) otvet2 = min(abs(a - line[-2]), abs(a - line[0])) + r2 prin...
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 IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VA...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, start = map(int, input().split()) x = list(map(int, input().split())) x = sorted(x) if n == 1: print(0) else: print( min( abs(start - x[0]) + abs(x[len(x) - 2] - x[0]), abs(start - x[1]) + abs(x[len(x) - 1] - x[1]), abs(x[len(x) - 1] - start) + abs(x[len(x) - 1] - ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR N...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
I = lambda: map(int, input().split()) n, a = I() x = sorted(I()) s = abs print( 0 if n == 1 else min( min(s(a - x[1]), s(a - x[-1])) + x[-1] - x[1], min(s(a - x[-2]), s(a - x[0])) + x[-2] - x[0], ) )
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP BIN_...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
def f(a, l, r): dl, dr = a - l, r - a return 2 * max(0, min(dl, dr)) + max(dl, dr) n, a = map(int, input().split()) if n == 1: print(0) exit() x = sorted(map(int, input().split())) print(min(f(a, x[0], x[-2]), f(a, x[1], x[-1])))
FUNC_DEF ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR RETURN BIN_OP BIN_OP NUMBER FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = map(int, input().split()) x = sorted(map(int, input().split())) if n == 1: exit(print(0)) print( min( min(abs(a - x[0]), abs(a - x[-2])) + (x[-2] - x[0]), min(abs(a - x[1]), abs(a - x[-1])) + (x[-1] - x[1]), ) )
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBE...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = map(int, input().split()) x = sorted([int(i) for i in input().split()]) if len(x) == 1: print(0) elif len(x) == 2: print(min(abs(x[0] - a), abs(x[1] - a))) else: print( min( x[-2] - x[0] + min(abs(x[0] - a), abs(x[-2] - a)), x[-1] - x[1] + min(abs(x[1] - a), abs(x[-1] ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR ...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
import sys input = sys.stdin.readline n, m = map(int, input().split()) t = list(map(int, input().split())) t.sort() if n <= 1: print(0) else: ans = 9999999999999999 for j in range(n): if j + (n - 2) < n: ans = min(ans, t[j + n - 2] - t[j] + abs(m - t[j])) x = n - 1 - j i...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, d = map(int, input().split()) a = list(map(int, input().strip().split())) a.sort() ans = 0 if n == 1: ans = 0 elif n <= 2: ans = min(abs(a[0] - d), abs(a[n - 1] - d)) else: ans = a[n - 2] - a[0] + min(abs(a[0] - d), abs(a[n - 2] - d)) ans = min(ans, a[n - 1] - a[1] + min(abs(a[1] - d), abs(a[n - 1] -...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = [int(i) for i in input().split()] points = [int(i) for i in input().split()] right = None right2 = None left = None left2 = None for point in points: if right is None: right = point elif point > right: right2 = right right = point elif right2 is None or point > right2: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NONE FOR VAR VAR IF VAR NONE ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NONE VAR VAR ASSIGN VAR VAR IF VAR NONE ASSIGN VAR ...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
def calc_dist(coords, a): if len(coords) == 0: return 0 if a > coords[-1]: return a - coords[0] if a < coords[0]: return coords[-1] - a return coords[-1] - coords[0] + min(a - coords[0], coords[-1] - a) n, a = list(map(int, input().split())) coords = list(map(int, input().split...
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER RETURN BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER RETURN BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASS...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = map(int, input().split()) x = sorted(map(int, input().split())) if n == 1: print(0) else: status1 = min(abs(a - x[0]), abs(a - x[-2])) + abs(x[-2] - x[0]) status2 = min(abs(a - x[1]), abs(a - x[-1])) + abs(x[-1] - x[1]) print(min(status1, status2))
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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VA...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = map(int, input().split()) X = list(map(int, input().split())) X = [(X[i] - a) for i in range(n)] X.sort() L = [] R = [] for i in X: if i <= 0: L.append(i) else: R.append(i) def minimum(A): if len(A) > 0: return min(A) else: return 0 def maximum(A): if len(A...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
def parser(): while 1: data = list(input().split(" ")) for number in data: if len(number) > 0: yield number input_parser = parser() def get_word(): global input_parser return next(input_parser) def get_number(): data = get_word() try: return ...
FUNC_DEF WHILE NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL ...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
from itertools import permutations def main(): from itertools import permutations n, a = map(int, input().split()) l = sorted(map(int, input().split())) if n > 4: del l[2:-2] res = [ sum(abs(u - v) for u, v in zip(t, [a, *t])) for t in permutations(l, len(l) - 1) ] print(m...
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 IF VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR LIST VAR VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUN...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = map(int, input().split()) x = sorted(list(map(int, input().split()))) c = 0 if n == 1: c = 0 elif n == 2: c = min(abs(x[0] - a), abs(x[1] - a)) elif a <= x[0]: c = abs(x[n - 2] - a) elif a >= x[n - 1]: c = abs(a - x[1]) elif a <= x[1]: d0 = abs(a - x[0]) dn1 = abs(a - x[n - 1]) dn2 = ...
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 IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER ASS...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = map(int, input().split()) x = list(map(int, input().split())) x_left = [xi for xi in x if xi <= a] x_right = [xi for xi in x if xi > a] x_left.sort(key=lambda el: -1 * el) x_right.sort() dist = 1000000000 if n == 1: dist = 0 for i in range(n): if i > len(x_left) or n - i - 2 > len(x_right) - 1 or n - 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 ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = list(map(int, input().split(" "))) x = list(map(int, input().split(" "))) MAX, MIN = 1000000, -1000000 r1, r2, l1, l2 = MIN - 1, MIN - 1, MAX + 1, MAX + 1 for xi in x: if xi <= l1: l2 = l1 l1 = xi elif xi < l2: l2 = xi if xi >= r1: r2 = r1 r1 = xi elif xi >...
ASSIGN VAR 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 VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
read = lambda: map(int, input().split()) n, a = read() x = sorted(read()) result = 0 if n > 1: r1 = abs(a - x[0]) + abs(x[0] - x[n - 2]) r2 = abs(a - x[1]) + abs(x[1] - x[n - 1]) r3 = abs(a - x[n - 2]) + abs(x[n - 2] - x[0]) r4 = abs(a - x[n - 1]) + abs(x[n - 1] - x[1]) result = min(r1, r2, r3, r4) ...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
na = input().split() n = int(na[0]) a = int(na[1]) checkpoints = input().split() checkpoints = [int(check) for check in checkpoints] checkpoints.sort() if len(checkpoints) == 1: print(0) else: value1 = abs(a - checkpoints[1]) + abs(checkpoints[-1] - checkpoints[1]) value2 = abs(a - checkpoints[-1]) + abs(ch...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR ...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = map(int, input().split()) l = [int(x) for x in input().split()] if n == 1: print(0) exit() l.sort() ans1 = l[-2] - l[0] + min(abs(a - l[-2]), abs(a - l[0])) ans2 = l[-1] - l[1] + min(abs(a - l[-1]), abs(a - l[1])) print(min(ans1, ans2))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NU...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = [int(i) for i in input().split()] coords = sorted(int(i) for i in input().split()) dist = [0] * 4 cur = [a] * 4 for i in range(0, n - 1): dist[0] += abs(cur[0] - coords[i]) dist[1] += abs(cur[1] - coords[n - i - 1]) dist[2] += abs(cur[2] - coords[i + 1]) dist[3] += abs(cur[3] - coords[n - i - 2])...
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 BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER FUNC_CAL...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
class CodeforcesTask709BSolution: def __init__(self): self.result = "" self.n_a = [] self.points = [] def read_input(self): self.n_a = [int(x) for x in input().split(" ")] self.points = [int(x) for x in input().split(" ")] def process_task(self): right_poin...
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR ...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = map(int, input().split()) x = sorted(list(map(int, input().split()))) l = len(x) if n == 1: print(0) exit() if n == 2: if a <= x[0]: print(x[0] - a) exit() if a >= x[1]: print(x[1] - a) exit() else: print(min(a - x[0], x[1] - a)) exit() elif x[1...
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 FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR IF...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, p = map(int, input().split()) a = list(map(int, input().split())) a.sort() if n == 1: print(0) elif n == 2: print(min(abs(a[0] - p), abs(a[1] - p))) else: a1 = min(abs(a[0] - p), abs(a[-2] - p)) + abs(a[0] - a[-2]) a2 = min(abs(a[1] - p), abs(a[-1] - p)) + abs(a[1] - a[-1]) print(min(a1, a2))
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 VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP ...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
import sys input = sys.stdin.readline n, a = map(int, input().split()) x = list(map(int, input().split())) x.sort() if n == 1: print(0) exit() ans = abs(a - x[0]) + abs(x[0] - x[n - 2]) ans = min(ans, abs(a - x[n - 2]) + abs(x[n - 2] - x[0])) ans = min(ans, abs(a - x[1]) + abs(x[1] - x[-1])) ans = min(ans, abs...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = map(int, input().split()) x = list(map(int, input().split())) if n == 1: print(0) elif n == 2: print(min(abs(a - x[0]), abs(a - x[1]))) else: num = float("inf") x = sorted(x) if a <= x[0]: num = min(num, abs(a - x[n - 2])) elif x[n - 1] <= a: num = min(num, abs(a - x[1])) ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIG...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = map(int, input().split()) coords = list(map(int, input().split())) coords.sort() def length(a, b): if a >= b: return a - b else: return b - a ans = 0 if n == 1: ans = 0 elif a == coords[0]: ans = length(coords[0], coords[-2]) elif a == coords[-1]: ans = length(coords[-1], ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN BIN_OP VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBE...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, x = [int(i) for i in input().split()] a = [int(i) for i in input().split()] if len(a) <= 1: ans = 0 else: a = sorted([x] + a) ind = a.index(x) if ind == 0: ans = a[-2] - a[0] elif ind == len(a) - 1: ans = a[-1] - a[1] else: ans = min( a[ind] + a[-2] - 2 * a...
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 IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR ...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = map(int, input().split()) p = list(map(int, input().split())) p.sort() if n == 1: print("0") exit() if a < p[0]: print(abs(a - p[-2])) exit() if a > p[-1]: print(abs(a - p[1])) exit() d1 = abs(a - p[-1]) + abs(p[-1] - p[1]) d2 = abs(a - p[-2]) + abs(p[-2] - p[0]) d3 = abs(a - p[1]) + abs(...
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 VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR NUMBER EXPR FUN...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = map(int, input().split()) x = list(map(int, input().split())) x.sort() if n == 1: print(0) exit() if n == 2: print(min(abs(x[0] - a), abs(x[1] - a))) exit() x1 = [[x[1], x[n - 1]], [x[0], x[n - 2]]] ans = 10**10 for i in range(2): if x1[i][0] <= a <= x1[i][1]: ans = min( a...
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 VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
def solve(): n, a = list(map(int, input().split())) x = list(map(int, input().split())) x.append(a) x.sort() bi = 0 for i in range(n + 1): if x[i] == a: bi = i break ans = float("inf") for s in range(2): l = 0 r = 0 ok = x[s] == a ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUN...
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary ...
n, a = [int(x) for x in input().split()] x = [int(x) for x in input().split()] x.sort() def f(l, r): d1 = abs(x[l] - a) d2 = abs(x[r] - a) if l == r: return min(d1, d2) if (x[l] <= a) == (x[r] <= a): return max(d1, d2) return min(d1, d2) * 2 + max(d1, d2) if n == 1: print(0) ...
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 FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR RETURN FUNC_CALL VA...
You like numbers, don't you? Nastia has a lot of numbers and she wants to share them with you! Isn't it amazing? Let a_i be how many numbers i (1 ≤ i ≤ k) you have. An n × n matrix is called beautiful if it contains all the numbers you have, and for each 2 × 2 submatrix of the original matrix is satisfied: 1. The...
def cheak(x): return x**2 - (x // 2) ** 2 >= m and x * (x // 2 + (1 if x % 2 != 0 else 0)) >= mx for test in range(int(input())): m, k = (int(i) for i in input().split()) a = [int(i) for i in input().split()] mx = max(a) z = 0 y = m * 4 while z != y: x = (z + y) // 2 if che...
FUNC_DEF RETURN BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL ...
Meka-Naruto plays a computer game. His character has the following ability: given an enemy hero, deal $a$ instant damage to him, and then heal that enemy $b$ health points at the end of every second, for exactly $c$ seconds, starting one second after the ability is used. That means that if the ability is used at time $...
import sys input = sys.stdin.readline for f in range(int(input())): a, b, c, d = map(int, input().split()) if d >= c: if a > b * c: print(-1) else: print(a) elif a > b * c: print(-1) elif a < b * d: print(a) else: k = a // (b * d) ...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN V...
Meka-Naruto plays a computer game. His character has the following ability: given an enemy hero, deal $a$ instant damage to him, and then heal that enemy $b$ health points at the end of every second, for exactly $c$ seconds, starting one second after the ability is used. That means that if the ability is used at time $...
from sys import stdin t = int(input()) for i_t in range(t): a, b, c, d = map(int, stdin.readline().split()) if b * c < a: result = -1 else: i_hit = (a + b * d - 1) // (b * d) - 1 i_hit = min(i_hit, (c - 1) // d) result = a * (i_hit + 1) - b * d * i_hit * (i_hit + 1) // 2 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIG...
Meka-Naruto plays a computer game. His character has the following ability: given an enemy hero, deal $a$ instant damage to him, and then heal that enemy $b$ health points at the end of every second, for exactly $c$ seconds, starting one second after the ability is used. That means that if the ability is used at time $...
import sys s = sys.stdin.read().split() p = 0 def getSm(k, a, b, c, d): return (k + 1) * a - (k * (k + 1) >> 1) * b * d t = int(s[p]) p += 1 res = [] for _ in range(t): a = int(s[p]) p += 1 b = int(s[p]) p += 1 c = int(s[p]) p += 1 d = int(s[p]) p += 1 if a - b * c > 0: ...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FU...
Meka-Naruto plays a computer game. His character has the following ability: given an enemy hero, deal $a$ instant damage to him, and then heal that enemy $b$ health points at the end of every second, for exactly $c$ seconds, starting one second after the ability is used. That means that if the ability is used at time $...
import sys sys.setrecursionlimit(10**5) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def MI(): return map(int, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LLI(rows_...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC...
Meka-Naruto plays a computer game. His character has the following ability: given an enemy hero, deal $a$ instant damage to him, and then heal that enemy $b$ health points at the end of every second, for exactly $c$ seconds, starting one second after the ability is used. That means that if the ability is used at time $...
import sys mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.buffer.readline for _ in range(int(input())): a, b, c, d = map(int, input().split()) if a > b * c: print(-1) continue if d > c: print(a) continue ...
IMPORT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VA...
Meka-Naruto plays a computer game. His character has the following ability: given an enemy hero, deal $a$ instant damage to him, and then heal that enemy $b$ health points at the end of every second, for exactly $c$ seconds, starting one second after the ability is used. That means that if the ability is used at time $...
def solve(a, b, c, d): if a > b * c: return -1 if c <= d: return a k = a // b // d + 1 return k * a - k * (k - 1) // 2 * d * b def main(): t = int(input()) for _ in range(t): a, b, c, d = map(int, input().split()) print(solve(a, b, c, d)) main()
FUNC_DEF IF VAR BIN_OP VAR VAR RETURN NUMBER IF VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL V...
Meka-Naruto plays a computer game. His character has the following ability: given an enemy hero, deal $a$ instant damage to him, and then heal that enemy $b$ health points at the end of every second, for exactly $c$ seconds, starting one second after the ability is used. That means that if the ability is used at time $...
import sys input = sys.stdin.readline def f(mid): return a * (mid + 1) - mid * (mid + 1) // 2 * db t = int(input()) res = [] for _ in range(t): a, b, c, d = map(int, input().split()) inc = a - b * c if inc > 0: res.append(-1) continue if c < d: res.append(a) cont...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NU...
Meka-Naruto plays a computer game. His character has the following ability: given an enemy hero, deal $a$ instant damage to him, and then heal that enemy $b$ health points at the end of every second, for exactly $c$ seconds, starting one second after the ability is used. That means that if the ability is used at time $...
def solve(a, b, c, d): if a > c * b: return -1 if c <= d: return a rt = a // b // d + 1 p = rt * (rt - 1) db = d * b y = rt * a n = p // 2 * db return y - n def main(): t = int(input()) for _ in range(t): a, b, c, d = map(int, input().split()) pr...
FUNC_DEF IF VAR BIN_OP VAR VAR RETURN NUMBER IF VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ...
Meka-Naruto plays a computer game. His character has the following ability: given an enemy hero, deal $a$ instant damage to him, and then heal that enemy $b$ health points at the end of every second, for exactly $c$ seconds, starting one second after the ability is used. That means that if the ability is used at time $...
import sys input = sys.stdin.buffer.readline for _ in range(int(input())): a, b, c, d = map(int, input().split()) if a - b * c > 0: print(-1) else: const = (-c - 1) // d k = c // d + 1 tmp1 = (k + 1) * (a - b * c) - const * b * c - d * b * const * (const + 1) // 2 tm...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VA...
Meka-Naruto plays a computer game. His character has the following ability: given an enemy hero, deal $a$ instant damage to him, and then heal that enemy $b$ health points at the end of every second, for exactly $c$ seconds, starting one second after the ability is used. That means that if the ability is used at time $...
from sys import stdin, stdout def f(a, b, c, d, i): return d * b * i * (i + 1) // 2 - a * (i + 1) for i in range(int(input())): a, b, c, d = [int(i) for i in stdin.readline().split()] if -a + b * c < 0: stdout.write("-1\n") else: v = a // (b * d) mx = 0 mx = max(mx, -...
FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR ...
Meka-Naruto plays a computer game. His character has the following ability: given an enemy hero, deal $a$ instant damage to him, and then heal that enemy $b$ health points at the end of every second, for exactly $c$ seconds, starting one second after the ability is used. That means that if the ability is used at time $...
import sys input = sys.stdin.readline def solve_case(): a, b, c, d = [int(x) for x in input().split()] if a > b * c: print(-1) else: k = a // (b * d) print(a * (k + 1) - k * (k + 1) // 2 * b * d) def main(): for _ in range(int(input())): solve_case() main()
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_DEF FOR VA...
Meka-Naruto plays a computer game. His character has the following ability: given an enemy hero, deal $a$ instant damage to him, and then heal that enemy $b$ health points at the end of every second, for exactly $c$ seconds, starting one second after the ability is used. That means that if the ability is used at time $...
def f(k, a, b, d): return a * (k + 1) - k * (k + 1) * b * d // 2 def main(): t = int(input()) for _ in range(t): a, b, c, d = [int(s) for s in input().split()] if a > c * b: print(-1) else: k = a // (b * d) print(f(k, a, b, d)) main()
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR B...
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
n, v = map(int, input().split(" ")) a, b = [], [] for i in range(n): t, p = map(int, input().split(" ")) if t == 1: a.append([p, i + 1]) else: b.append([p, i + 1]) a.sort(reverse=True) b.sort(reverse=True) i, j = 0, 0 while v > 0 and i + j < n: if v == 1: if i < len(a): ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC...
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
n, v = map(int, input().split()) temp = {(1): [], (2): []} s = {(1): [0], (2): [0]} for i in range(n): x, y = map(int, input().split()) temp[x].append([y, i + 1]) temp[1].sort(reverse=True) temp[2].sort(reverse=True) for i in range(min(v, len(temp[1]))): s[1].append(s[1][-1] + temp[1][i][0]) for i in range(...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER LIST LIST ASSIGN VAR DICT NUMBER NUMBER LIST NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR LIST VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXP...
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
import sys input = sys.stdin.readline n, v = map(int, input().split()) o, t = [], [] for i in range(n): x, y = map(int, input().split()) if x == 1: o.append((y, i + 1)) else: t.append((y, i + 1)) o.sort(reverse=True) t.sort(reverse=True) if len(o) == 0: ans = 0 f = [] for i in r...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_C...
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
n, v = map(int, input().split()) kayaks = [] catamarans = [] for i in range(n): t, p = map(int, input().split()) waterbone = kayaks if t == 1 else catamarans waterbone.append((p, i + 1)) kayaks.sort(reverse=True) catamarans.sort(reverse=True) capacity = 0 vehicles = [] kayak = 0 catamaran = 0 nb_kayaks = le...
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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN ...
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
import sys n, v = list(map(int, sys.stdin.readline().rstrip().split())) kc_ls = [] kayaks = [] catamaran = [] total_space = 0 total_capacity = 0 for i in range(1, n + 1): kc_ls.append(tuple(map(int, sys.stdin.readline().rstrip().split() + [i]))) kc_ls.sort(key=lambda x: x[1] if x[0] == 1 else x[1] / 2) while v - t...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL FUNC_CALL FUNC_CALL VAR LIST VAR ...
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
kayak = [] catamaran = [] ans = [] line = input() data = line.split() n = int(data[0]) v = int(data[1]) for i in range(1, n + 1): line = input() data = line.split() type = data[0] if type == "1": kayak.append([int(data[1]), i]) else: catamaran.append([int(data[1]), i]) len_k = len(ka...
ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER IF VAR STRING EXPR FUNC_CALL VA...
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
def solve(by_w, b, v): rem = min(v - 2 * b, len(by_w[1])) if rem < 0: return -1, 0, 0 score = 0 if b == 0 else by_w[2][b - 1][0] if rem > 0: score += by_w[1][rem - 1][0] return score, rem, b def main(): n, v = map(int, input().split()) by_w = [[] for _ in range(3)] for ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL ...
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
n, v = map(int, input().split()) p, t = [], [] for i in range(1, n + 1): a, b = map(int, input().split()) t.append((b * (3 - a), a, b, i)) t.sort(reverse=True) a = b = i = 0 while i < n and a < v: a += t[i][1] b += t[i][2] p.append(t[i][3]) i += 1 if a > v: i, j, k = i - 1, i - 2, i whil...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR ...
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
m = lambda: map(int, input().split()) [n, v] = m() fi, se = [], [] for i in range(1, int(n) + 1): [ti, pi] = m() if ti == 1: fi.append([i, pi]) else: se.append([i, pi]) fi.sort(key=lambda x: x[1], reverse=True) se.sort(key=lambda x: x[1], reverse=True) for i in range(1, len(fi)): fi[i][1...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN LIST VAR VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN LIST VAR VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBE...
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
r = lambda: map(int, input().split()) [n, v] = r() t = [] o = [] for i in range(n): [tp, p] = r() if tp == 1: o += [[p, i]] else: t += [[p, i]] t.sort(reverse=True) o.sort(reverse=True) nt = len(t) no = len(o) for i in range(1, nt): t[i][0] += t[i - 1][0] for i in range(1, no): o[i][...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN LIST VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR IF VAR NUMBER VAR LIST LIST VAR VAR VAR LIST LIST VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR AS...
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
n, c = map(int, input().split()) ones = [] twos = [] cnt = 0 for i in range(n): cnt += 1 x, y = map(int, input().split()) if x == 1: ones.append([y, cnt]) else: twos.append([y, cnt]) ones.sort(key=lambda s: -s[0]) twos.sort(key=lambda s: -s[0]) sum = 0 pt_1 = 0 pt_2 = 0 ans = [] m1 = len...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_C...
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
R = lambda: map(int, input().split()) n, v = R() k, c = [], [] for i in range(n): t, a = R() if t == 1: k += [[a, i + 1]] else: c += [[a, i + 1]] k.sort(reverse=True) c.sort(reverse=True) sum = 0 klen = len(k) clen = len(c) y = min(klen, v) for i in range(1, klen): k[i][0] += k[i - 1][0]...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR NUMBER VAR LIST LIST VAR BIN_OP VAR NUMBER VAR LIST LIST VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER AS...
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
n, v = map(int, input().split()) tp = [] for i in range(n): ti, pi = map(int, input().split()) tp.append((ti, pi, i + 1)) tp.sort(key=lambda _: -_[1] / _[0]) numbers, v_current, quality = [], 0, 0 last_ones = -2, -1 for i, tpi in enumerate(tp): if v_current + tpi[0] <= v: v_current += tpi[0] ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR ...
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
import itertools import time KAYAK = 1 CATAMARAN = 2 def get_boats(num_boats): kayaks, catamarans = list(), list() for boat_num in range(1, num_boats + 1): type_boat, cap = map(int, input().strip().split(" ")) if type_boat == KAYAK: kayaks.append((cap, boat_num)) else: ...
IMPORT IMPORT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR F...
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
n, capacity = map(int, input().split()) kayaks, catamarans = [], [] for i in range(n): vehicle_type, vehicle_capacity = map(int, input().split()) l = kayaks if vehicle_type == 1 else catamarans l.append((vehicle_capacity, i + 1)) kayaks.sort(key=lambda item: item[0], reverse=True) catamarans.sort(key=lambda...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR...
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
class Solution(object): def __init__(self): n, v = map(int, input().split()) l1 = [] l2 = [] for i in range(n): x, y = map(int, input().split()) if x == 1: l1.append((y, i + 1)) else: l2.append((y, i + 1)) l...
CLASS_DEF VAR FUNC_DEF 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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXP...
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
n, v = map(int, input().split()) k = [[0, " "], [0, " "]] c = [[0, " "]] sum = 0 vehicles = [] for i in range(n): q = input().split() if q[0] == "1": k += [[int(q[1]), i + 1]] elif q[0] == "2": c += [[int(q[1]), i + 1]] k.sort(key=lambda a: a[0]) c.sort(key=lambda a: a[0]) for i in range(n):...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER STRING LIST NUMBER STRING ASSIGN VAR LIST LIST NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING VAR LIST LIST FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER I...
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
n, p = map(int, input().split()) a = [0] * n for i in range(n): t, v = map(int, input().split()) a[i] = i, t, v a.sort(key=lambda x: x[2] / x[1], reverse=True) ans, index, lst = 0, 0, [] last1 = -1, 0 while p > 0 and index < n: i, t, v = a[index] if t == 1: last1 = i, v p -= t ans += v ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER LIST ASSIGN VAR NUMBER NUMBER W...
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
n, v = map(int, input().split()) selected = [] ones = [] twos = [] ans = 0 for i in range(1, n + 1): t, p = map(int, input().split()) if t == 1: ones.append((p, i)) if t == 2: twos.append((p, i)) ones.sort() twos.sort() num1 = len(ones) num2 = len(twos) last_one = None while num1 + num2 > 0 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_C...
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
n, v = map(int, input().split()) a = [] b = [] for i in range(n): t, p = map(int, input().split()) if t == 1: a.append((i, p)) else: b.append((i, p)) a = sorted(a, key=lambda x: -x[1]) b = sorted(b, key=lambda x: -x[1]) a_pos = -1 b_pos = -1 capacity = 0 while capacity < v: next_a = a[a_...
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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ...