description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = int(input()) answer = 0 sticks = input().split() for i in range(n): sticks[i] = int(sticks[i]) sticks.sort(reverse=True) i = 0 v = [] while i < n - 1: if abs(sticks[i] - sticks[i + 1]) < 2: v.append(min(sticks[i], sticks[i + 1])) i += 2 else: i += 1 v.sort(reverse=True) i = 0 whi...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL V...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = int(input()) c = [0] * 1000001 m = 0 for i in list(map(int, input().split())): c[i] += 1 if i > m: m = i n = m while m != 1: if c[m] % 2 == 1: if c[m - 1]: c[m] -= 1 c[m - 1] += 1 else: c[m] -= 1 m -= 1 pos = 0 s = 0 mem = 0 for pos in rang...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NU...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
import sys def max_square(number_of_sticks, sticks): if number_of_sticks < 4: return 0 else: sticks.sort() sticks.reverse() max_sq = 0 max_stick = 0 i = 1 while i < len(sticks): if sticks[i - 1] - sticks[i] <= 1: if max_stick ...
IMPORT FUNC_DEF IF VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER RE...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = int(input()) l = list(map(int, input().split())) l.sort(reverse=True) ans = 0 count = 0 temp = 1 i = 0 while i < n - 1: if l[i] == l[i + 1]: temp *= l[i] i += 2 count += 1 elif l[i] == l[i + 1] + 1: temp *= l[i + 1] i += 2 count += 1 else: i += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = int(input()) a = [-1] a += [int(x) for x in input().split()] a.sort() l = 0 ans = 0 i = n while i >= 1: if a[i] == a[i - 1] or a[i] == a[i - 1] + 1: if l == 0: l = a[i - 1] else: ans += l * a[i - 1] l = 0 i -= 2 else: i -= 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMB...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
def main(): n = int(input()) a = [int(x) for x in input().split()] b = [] area = 0 a.sort() for i in reversed(range(len(a))): if i > 0 and (a[i] == a[i - 1] or a[i] - 1 == a[i - 1]): b.append(a[i - 1]) a[i - 1] = -1 for i in range(int(len(b) / 2)): are...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR V...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = int(input()) l = list(map(int, input().split())) l = sorted(l) l = l[::-1] k = 0 b = -1 for i in range(n - 1): if l[i] == l[i + 1] and b == -1: b = l[i] l[i + 1] = -1 if l[i] == l[i + 1] and b != -1: k += b * l[i] b = -1 l[i + 1] = -1 if l[i] == l[i + 1] + 1 and b...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NU...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = int(input()) L = [int(x) for x in input().split()] L.sort(reverse=True) i = 0 while i < n - 1: if L[i] - 1 == L[i + 1]: L[i] -= 1 i += 1 elif L[i] == L[i + 1]: i += 1 i += 1 val = [] i = 0 while i < n - 1: if L[i] == L[i + 1]: val.append(L[i]) i += 1 i += ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN V...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = int(input()) ls = list(map(int, input().split())) ls.sort(reverse=True) area = 0 pairs = [] i = 0 while i < len(ls) - 1: if ls[i] - ls[i + 1] > 1: i += 1 else: pairs.append(ls[i + 1]) i += 2 if len(pairs) == 2: area += pairs.pop() * pairs.pop() print(area)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NU...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = int(input()) l = [int(i) for i in input().split()] l.sort(reverse=True) ans = 0 area = 0 ignore_next = False for i in range(n - 1): if ignore_next: ignore_next = False continue l1 = l[i] l2 = l[i + 1] length = 0 if l1 == l2: length = l1 elif l1 == l2 + 1: leng...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VA...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
import sys n = int(input()) a = list(map(int, input().split())) if n == 1: print(0) sys.exit() a.sort(reverse=True) d = {} i = 1 while i < len(a): if a[i] == a[i - 1] or a[i] == a[i - 1] - 1: if a[i] not in d: d[a[i]] = 0 d[a[i]] += 2 a[i] = 0 a[i - 1] = 0 i ...
IMPORT ASSIGN VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP V...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = int(input()) l = [] inline = input().split() for i in range(n): l.append(int(inline[i])) l.sort() right_equal = 1 ans = 0 if len(l) >= 4: for i in range(len(l) - 2, -1, -1): if l[i] != l[i + 1]: if right_equal % 2 != 0: if l[i + 1] - l[i] == 1: l[i + 1...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR V...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = int(input()) s = map(int, input().split()) s = list(reversed(sorted(s))) i = 1 k = [] while i < n: if s[i - 1] - s[i] == 1: k.append(s[i]) i += 1 elif s[i - 1] == s[i]: k.append(s[i]) i += 1 i += 1 ans = 0 for i in range(1, len(k), 2): ans += k[i] * k[i - 1] print(ans...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR EXPR ...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = int(input()) lis = sorted(map(int, input().split())) fi = se = ans = 0 i = n - 1 while i > 0: if fi == 0: if lis[i] == lis[i - 1]: fi = lis[i] i -= 1 elif lis[i] == lis[i - 1] + 1: fi = lis[i - 1] i -= 1 elif se == 0: if lis[i] == lis[i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
from sys import stdin, stdout __author__ = "vks" n = int(stdin.readline()) sticks = [int(i) for i in stdin.readline().split()] sticks.sort() square = 0 n -= 1 while n > 0: a = 0 b = 0 while n > 0 and abs(sticks[n] - sticks[n - 1]) > 1: n -= 1 if n > 0: a = min(sticks[n], sticks[n - 1]) ...
ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER ASSIG...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = int(input()) lst = [] lst.extend(map(int, input().split())) tarea = 0 lst.sort() lst = lst[::-1] lst.append(0) i = 0 mark = 0 ar = [] while i != n: if lst[i] - lst[i + 1] <= 1: ar.append(lst[i + 1]) mark += 1 i += 2 else: i += 1 if mark == 2: tarea = tarea + ar[0]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR F...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
from sys import stdin, stdout def rectangular(n, array): sum = 0 i = n - 2 crutch = 0 if n < 4: return 0 array.sort() while i > -1: if array[i + 1] - array[i] <= 1: if crutch == 0: crutch = array[i] i -= 1 else: ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR WHILE VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_C...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = int(input()) l = [int(i) for i in input().split()] l = sorted(l) rr = [] new = l[::-1] io = 0 f = 0 while io < len(new) - 1: if new[io] - new[io + 1] <= 1: rr.append(new[io]) rr.append(new[io + 1]) io += 2 continue else: io += 1 if len(rr) >= 4: q = len(rr) % 4 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR ...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
sux = 0 two = 0 x = int(input()) s = list(map(int, input().split(" "))) t = [0] * 1000001 for i in s: t[i] += 1 for i in range(len(t) - 1, 0, -1): if t[i] % 2 == 1 and t[i - 1] > 0: t[i] -= 1 t[i - 1] += 1 elif t[i] % 2 == 1 and t[i] > 0: t[i] -= 1 for i in range(len(t) - 1, 0, -1): ...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR BIN...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = int(input()) ai = list(map(int, input().split())) ai.sort() ans = 0 prev = 0 sticks = [] i = n - 2 while i > -1: if ai[i + 1] <= ai[i] + 1: sticks += [ai[i]] i -= 1 i -= 1 for i in range(1, len(sticks), 2): ans += sticks[i] * sticks[i - 1] print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR LIST VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUN...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = int(input()) arr = list(sorted(map(int, input().split()), reverse=True)) dstick = list() idx = 0 while idx + 1 < n: if arr[idx] == arr[idx + 1] or arr[idx] - 1 == arr[idx + 1]: dstick.append(arr[idx + 1]) idx += 2 else: idx += 1 if len(dstick) & 1 == 1: dstick.pop() ans = 0 for i...
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 NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
import sys input = sys.stdin.readline def ceil(x): if x != int(x): x = int(x) + 1 return x def swaparr(arr, a, b): temp = arr[a] arr[a] = arr[b] arr[b] = temp def gcd(a, b): if b == 0: return a return gcd(b, a % b) def nCr(n, k): if k > n - k: k = n - k ...
IMPORT ASSIGN VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VA...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
ans = 0 n = 0 n = int(input("")) l = input("") st = [] for x in l.split(" "): st.append(int(x)) st.sort() i = n - 1 while i >= 3: if st[i] > st[i - 1] + 1: i = i - 1 continue l = st[i - 1] i = i - 2 while i > 0 and st[i] > st[i - 1] + 1: i = i - 1 if i == 0: break...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR B...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = input() l = list(map(int, input().split())) a, b = 0, 0 result = 0 for i in sorted(l, reverse=True): if a == 0 or a > i + 1: a = i elif b == 0: a, b = 0, i else: result += i * b a, b = 0, 0 print(result)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = int(input()) l = list(map(int, input().split())) l.sort(reverse=True) i = 0 ans = [] while i < n: if i < n - 1 and l[i] - l[i + 1] <= 1: ans.append(l[i + 1]) i += 1 i += 1 tem = len(ans) if tem <= 1: print(0) else: i = 0 s = 0 while i < tem - 1: s += ans[i] * ans[i + ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN V...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
def main(): input() res, it = 0, iter(sorted(map(int, input().split()), reverse=True)) try: while True: a, b, c, d = next(it), next(it), next(it), next(it) while a > b + 1: a, b, c, d = b, c, d, next(it) while c > d + 1: c, d = d, n...
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER WHILE NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR WHIL...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
from sys import stdin as inp __author__ = "Dmitry Petrushin" __version__ = "3.4" def rectangles(lengths): n_max = 10**6 + 2 sticks = [(0) for _ in range(n_max)] tmp = list() for length in lengths: sticks[length] += 1 for i in range(n_max - 2, 1, -1): for _ in range((sticks[i + 1] ...
ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUM...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = int(input()) sticks = sorted(map(int, input().split()), key=lambda x: -x) area = 0 pairs = [] pos = 0 while pos < n - 1: a, b = sticks[pos], sticks[pos + 1] if a - b <= 1: if len(pairs) == 0: pairs.append(b) else: area += pairs.pop() * b pos += 1 pos += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_O...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
import sys def otb(l): i = 0 while i < n - 1: if l[i] - 1 == l[i + 1]: l[i] -= 1 i += 1 elif l[i] == l[i + 1]: i += 1 i += 1 znach = [] i = 0 while i < n - 1: if l[i] == l[i + 1]: znach.append(l[i]) i += 1 ...
IMPORT FUNC_DEF ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMB...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
m = {} n = int(input()) data = input().split() for i in data: if -int(i) not in m: m[-int(i)] = 1 else: m[-int(i)] += 1 ant = 0 ans = 0 for i in sorted(m): if m[i] > 1: if ant != 0: ans += ant * i m[i] -= 2 ant = 0 ans += m[i] // 4 * (i * i) ...
ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR VAR VAR VAR NUMBER ...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
x, y = 0, 0 n = int(input()) n -= 1 l = list(map(int, input().split())) l.sort() t = 0 while n > 0: if l[n] - l[n - 1] <= 1: if not x: x = l[n] - l[n] + l[n - 1] n -= 1 else: y = l[n] - l[n] + l[n - 1] t += x * y x, y = 0, 0 n -...
ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
x = int(input()) L = [int(i) for i in input().split()] L.sort() L = L[::-1] a = 0 c = 0 A = [] while len(L) >= 2: if L[0] == L[1] or L[0] == L[1] + 1: A.append(L[1]) L.pop(0) L.pop(0) else: L.pop(0) try: while c < len(A): a += A[c] * A[c + 1] c += 2 print(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
am = int(input()) arr = list(map(int, input().split())) arr.sort() counted = [0] * 1000000 for i in range(am): counted[arr[i] - 1] += 1 fl = True l = 0 lAdded = 0 haveL = [] haveAm = [] for i in range(len(counted) - 1, -1, -1): if counted[i] != 0: if fl: haveL += [i, i - 1] haveA...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = int(input()) rects = [int(s) for s in input().split()] rects.sort() sumsquare = 0 stash = [] i = len(rects) - 1 while i > 0: if rects[i] - rects[i - 1] == 1 or rects[i] == rects[i - 1]: if len(stash) == 2: sumsquare += stash[0] * stash[1] stash.clear() stash.append(rects[...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR BI...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = int(input()) l = list(map(int, input().split())) l.sort() side = [] i = n - 1 while i > 0: s = l[i] if s == l[i - 1]: side.append(s) i -= 2 elif s == l[i - 1] + 1: side.append(s - 1) i -= 2 else: i -= 1 side.sort() i = len(side) - 1 num = 0 while i > 0: nu...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUN...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = int(input()) s = input() a = [] for x in s.split(" "): a.append(int(x)) a.sort() ans = 0 k = 0 flag = 0 for i in range(n - 1, 0, -1): if flag: flag = 0 continue if a[i] == a[i - 1] or a[i] == a[i - 1] + 1: if k != 0: ans += k * a[i - 1] k = 0 else:...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP ...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = int(input()) a = list(map(int, input().split())) a = sorted(a)[::-1] m = 0 total = 0 while True: flag1 = False flag2 = False for i in range(m, n - 1): if (a[i] == a[i + 1] or a[i] - a[i + 1] == 1) and a[i] != -1: flag1 = True x = a[i + 1] m = i + 2 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR V...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = int(input()) l = [int(i) for i in input().split()] l.sort(reverse=True) a = [] i = 0 while i < len(l) - 1: if l[i] == l[i + 1]: a.append(l[i]) i += 2 elif l[i] == l[i + 1] + 1: a.append(l[i] - 1) i += 2 else: i += 1 if len(a) % 2 != 0: a.append(0) s, i = 0, 0 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
def __starting_point(): input() data = sorted(map(int, input().split()), key=lambda x: -x) if len(data) < 4: print(0) return total = 0 i = 0 while i < len(data) - 3: if abs(data[i] - data[i + 1]) > 1: i += 1 continue success = False ...
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = int(input()) lst = [*map(int, input().split())] lst = [*reversed(sorted(lst))] res, first = [], 1 ex = res.extend for i, x in enumerate(lst[1:]): if x != lst[0]: break first += 1 div, mod = first // 2, first % 2 ex([lst[0]] * div) prev, elem = mod, lst[0] count = 1 if n > first: item = lst[first...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST NUMBER ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL V...
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that m...
n = int(input()) l = list(map(int, input().split())) m = {} m2 = set() for i in range(1, 10**6 + 1): m[i] = 0 for i in range(n): m[l[i]] += 1 m2.add(l[i]) if l[i] >= 2: m2.add(l[i] - 1) m1 = [] for i in range(10**6, 1, -1): if m[i] % 2 == 1 and m[i - 1] > 0: m[i] -= 1 m[i - 1...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR NUMB...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
def f(h): numofh = 0 numofl = 0 for i in li: if i < h: numofl += h - i else: numofh += i - h if numofh > numofl: return m * numofl + (numofh - numofl) * r else: return m * numofh + (numofl - numofh) * a def binary_search(low, high): if lo...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR VAR RETURN BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR FUNC_DEF IF VAR VAR RETURN ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VA...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
def calc(h): lo = hi = 0 for cur in arr: if cur < h: lo += h - cur else: hi += cur - h return m * min(lo, hi) + ((hi - lo) * r if hi >= lo else (lo - hi) * a) def solve(): le, ri = 0, 5 + 10**9 while le + 50 < ri: g, h = le + (ri - le) // 3, le + 2 *...
FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP NUMBER BIN_OP NUMBER NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR B...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
def find_cost(a, r, m, heights, x): inc, dec = [0, 0] for h in heights: if h >= x: dec += h - x else: inc += x - h if inc * dec == 0 or a + r <= m: return a * inc + r * dec if inc >= dec: return m * dec + (inc - dec) * a else: return m ...
FUNC_DEF ASSIGN VAR VAR LIST NUMBER NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR RETURN BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR FUNC_DE...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
n, a, r, m = map(int, input().split()) h = list(map(int, input().split())) m = min(m, a + r) def get(M): up = 0 dw = 0 for e in h: if e > M: up += e - M else: dw += M - e ans = m * min(dw, up) if dw > up: ans += (dw - up) * a else: ans +=...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VA...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
def rn(): a = int(input()) return a def rl(): a = list(map(int, input().split())) return a def val(v, h, a, r, m): ls = 0 ms = 0 for i in h: if i < v: ls += v - i else: ms += i - v cost = min(ls, ms) * m if ls > ms: cost += (ls - ms...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR BIN_OP BI...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
import sys def solve(): input = sys.stdin.readline N, A, R, M = map(int, input().split()) H = [int(h) for h in input().split()] H.sort() tB = [0] * (N + 1) for i, h in enumerate(H): tB[i + 1] = tB[i] + h minCost = 10**20 for i in range(N): toAdd = H[i] * i - tB[i] ...
IMPORT FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP NUMB...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
from sys import stdin, stdout N, A, R, M = map(int, stdin.readline().split()) ha = list(map(int, stdin.readline().split())) def calc(v, ha, A, R, M): a = 0 r = 0 for h in ha: a += max(v - h, 0) r += max(h - v, 0) m = min(a, r) return min(a * A + r * R, m * M + (a - m) * A + (r - m...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL V...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
from sys import stdin n, a, r, m = map(int, stdin.readline().split()) he = list(map(int, stdin.readline().split())) st = min(he) en = max(he) ans = 10**20 while st <= en: mid1 = st + (en - st) // 3 mid2 = en - (en - st) // 3 re = ad = 0 for i in he: re += max(0, i - mid1) ad += max(0, m...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
N, A, R, M = map(int, input().split()) h = list(map(int, input().split())) if A * R == 0: print(0) return if M > A + R: def condition(num): test = 0 for i in range(N): if num > h[i]: test += A else: test -= R return 0 >= test ...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER VAR ASSIGN...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
def cost(arr, target, a, r, m): c_add = 0 c_rem = 0 for hi in arr: if hi > target: c_rem += hi - target else: c_add += target - hi move_amount = min(c_add, c_rem) with_m = move_amount * m + (c_add - move_amount) * a + (c_rem - move_amount) * r wout_m = c_a...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR V...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
import sys input = sys.stdin.readline def compress(string): string.append(-1) n = len(string) begin, end, cnt = 0, 1, 1 ans = [] while end < n: if string[begin] == string[end]: end, cnt = end + 1, cnt + 1 else: ans.append((string[begin], cnt)) b...
IMPORT ASSIGN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST WHILE VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER RETURN VAR ASSI...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
n, a, r, m = [int(x) for x in input().split()] height = [int(x) for x in input().split()] hmax = max(height) height.sort() def tellCost(h): cost = 0 add, remove = 0, 0 for i in range(n): if h > height[i]: add += abs(h - height[i]) else: remove += abs(h - height[i]) ...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CAL...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
n, a, r, m = map(int, input().split()) if m > a + r: m = a + r h = [int(i) for i in input().split()] def checker(height): above, below = 0, 0 for i in h: if i > height: above += i - height elif i < height: below += height - i if below > above: return abo...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP VAR VAR IF VAR VAR RETURN BIN_OP BIN_OP VAR VAR ...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
N, A, R, M = map(int, input().split()) H = list(map(int, input().split())) def f(t): a = 0 r = 0 for h in H: r += max(h - t, 0) a += max(t - h, 0) m = min(a, r) return min(a * A + r * R, m * M + A * (a - m) + R * (r - m)) l = min(H) r = max(H) while r - l > 3: m1 = l + (r - l...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL V...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
n, a, r, m = [int(s) for s in input().split()] h = sorted([int(s) for s in input().split()]) add, rem = 0, sum(h) - min(h) * n ans, cur = rem * r, rem * r for i in range(1, n): dadd, drem = i, -(n - i) dcost, dh = dadd * min(m, a + r) + (drem - dadd) * r, h[i] - h[i - 1] if add <= rem and add + dadd * dh > ...
ASSIGN VAR VAR 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 VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP ...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
import sys input = sys.stdin.readline N, A, R, M = map(int, input().split()) H = list(map(int, input().split())) def get(l): over = 0 under = 0 for h in H: if h > l: over += h - l else: under += l - h if A + R <= M: return over * R + under * A elif ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR BIN_OP VA...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
def solve_for_height( n, add_cost, remove_cost, move_cost, current_height, heights, cum_heights ): lo = 1 hi = n while lo <= hi: mid = (lo + hi) // 2 if heights[mid] <= current_height: lo = mid + 1 else: hi = mid - 1 add = (lo - 1) * current_height - c...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VA...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
def check(a, r, m, hhh, w): put = 0 rem = 0 for h in hhh: if w == h: continue if w > h: put += w - h else: rem += h - w ans = put * a + rem * r if put - rem >= 0: ans = min(ans, rem * m + (put - rem) * a) else: ans = min...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BI...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
N, A, R, M = list(map(int, input().split())) if M > A + R: M = A + R h = list(map(int, input().split())) def calc(final): adds = 0 removes = 0 for v in h: if v > final: removes += v - final else: adds += final - v moves = min(adds, removes) return M * mo...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [([c] * b) for i in range(a)] def list3d(a, b, c, d): return [[([d] * c) for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[([e] * d) for j in range(c)] for j in range(b)] for i in ran...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL ...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
import sys def check(t): na, nr = 0, 0 for h in p: if h < t: na += t - h else: nr += h - t m = min(na, nr) return min(m * M + A * (na - m) + R * (nr - m), na * A + nr * R) N, A, R, M = map(int, sys.stdin.readline().split()) p = list(map(int, sys.stdin.readline...
IMPORT FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR F...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
from itertools import accumulate n, a, r, m = map(int, input().split()) m = min(a + r, m) ls = list(map(int, input().split())) ls.sort() acc = [0] + list(accumulate(ls)) ansls = [] sm = acc[-1] less = sm // n more = less + 1 flg = 0 for i in range(n + 1): if i == 0: minus = 0 plus = acc[n] else...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
import sys input = sys.stdin.readline N, A, R, M = map(int, input().split()) al = list(map(int, input().split())) x0 = 0 x1 = 1 x2 = 3 x3 = max(al) def check(x): a = 0 r = 0 for z in al: if x > z: a += x - z else: r += z - x if M < A + R: m = min(a, r) ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR ...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
def read_int(): return int(input()) def read_ints(): return list(map(int, input().split(" "))) n, a, r, m = read_ints() h = list(read_ints()) h.sort() lo = h[0] hi = h[-1] s = [0] for i in h: s.append(s[-1] + i) ans = int(1e20) for i in range(n): target = h[i] inc = i * target - s[i] dec = s...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
def find(h, x): l = 0 r = len(h) - 1 while abs(r - l) > 1: c = (l + r) // 2 if h[c] > x: r = c elif h[c] < x: l = c elif h[c] == x: return c return l + 1 def function(height): global h if h.count(height) == 0: less = f...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR RETURN VAR RETURN BIN_OP VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
n, a, r, m = map(int, input().split(" ")) h = list(map(int, input().split(" "))) def calCost(hi): cnta, cntr = 0, 0 for i in range(len(h)): cnta += max(0, hi - h[i]) cntr += max(0, h[i] - hi) if a + r > m: return ( min(cntr, cnta) * m + (cnta - min(cnta, cnt...
ASSIGN VAR VAR VAR 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 FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR IF BIN_O...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
n, a, r, m = map(int, input().split()) h = list(map(int, input().split())) h.sort() prev = 0 aft = sum(h) mincost = -1 op1 = aft // n ne1 = 0 tm1 = 0 op2 = op1 + 1 ne2 = 0 tm2 = 0 for i in range(n): goal = h[i] if goal < op1: ne1 += op1 ne1 -= goal else: tm1 += goal tm1 -= op...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NU...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
n, add, remove, move = [int(i) for i in input().split()] heights = [int(i) for i in input().split()] def cost_for_this_height(h, heights, n, add, remove, move): above = 0 below = 0 for i in range(n): if heights[i] > h: above += heights[i] - h elif heights[i] < h: be...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BIN...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
n, a, ra, m = map(int, input().split()) h = list(map(int, input().split())) if a + ra < m: l, r = 0, 10**9 + 1 for _ in range(50): c1 = (l * 2 + r) // 3 c2 = (l + r * 2) // 3 p1 = 0 p2 = 0 q1 = 0 q2 = 0 for x in h: if c1 <= x: q...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP V...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
import sys input = sys.stdin.readline def bin(l, r, c): if l == r: return l m = (l + r + 1) // 2 if h[m] <= c: return bin(m, r, c) else: return bin(l, m - 1, c) def cost(c, move): res = 0 i = 0 if c >= h[-1]: i = n - 1 else: i = bin(0, n - 1, ...
IMPORT ASSIGN VAR VAR FUNC_DEF IF VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR N...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
n, m, k = map(int, input().split()) l = list(map(int, input().split())) l1 = [] for i in range(1, n): l1 += [l[i] - l[i - 1]] l1.sort(reverse=True) s = l[-1] - l[0] + 1 i = 0 while k > 1: s -= l1[i] - 1 i += 1 k -= 1 print(s)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR VAR LIST BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
import time m, n, k = (int(i) for i in input().split()) b = [int(i) for i in input().split()] start = time.time() ans = m if m > k: c = sorted([(b[i + 1] - b[i]) for i in range(m - 1)]) ans += sum(c[: m - k]) + k - m print(ans) finish = time.time()
IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
n, m, k = list(map(int, input().split())) b = list(map(int, input().split())) s = sorted([(b[i] - b[i - 1] - 1) for i in range(1, n)], reverse=True) mv = b[-1] - b[0] + 1 - sum(s[: k - 1]) print(mv)
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER FUNC_...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
n, m, k = [int(x) for x in input().split()] L = [int(x) for x in input().split()] L.append(2 * L[-1]) t = n i = 1 Q = [] while i < n: Q.append(L[i] - L[i - 1]) i += 1 Q.sort() for i in range(max(0, len(Q) - k + 1)): t += Q[i] - 1 print(t)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FOR V...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
a = input() bb = input() aa = a.split() n = eval(aa[0]) m = eval(aa[1]) k = eval(aa[2]) b = bb.split() for i in range(len(b)): b[i] = eval(b[i]) if k >= n: print(n) else: x = n - k sub = [] for i in range(len(b) - 1): sub.append(b[i + 1] - b[i]) sub.sort() sum = 0 for i in range(...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR A...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
n, m, k = map(int, input().split()) ar1 = [] ar = [int(i) for i in input().split()] for i in range(1, n): ar1.append(ar[i] - ar[i - 1] - 1) rs = n ar1.sort() for i in range(n - k): rs += ar1[i] print(rs)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
n, m, k = list(map(int, input().split())) a = list(map(int, input().split())) subtract = [] for i in range(n - 1): x = a[i + 1] - a[i] - 1 subtract.append(x) subtract.sort() sum = 0 for i in range(n - k): sum += subtract[i] print(sum + n)
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
nmk = input().split(" ") n = int(nmk[0]) m = int(nmk[1]) k = int(nmk[2]) brokens = list(map(int, input().split(" "))) if n == k: print(n) else: distances = [] for i in range(n - 1): distances.append(brokens[i + 1] - brokens[i] + 1) distances = sorted(distances) l = n j = 0 used = n ...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR F...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
s = input() s = s.split() n = int(s[0]) m = int(s[1]) k = int(s[2]) s = input() s = s.split() b = [int(s[0])] db = [] for i in range(1, n): b.append(int(s[i])) db.append(b[i] - b[i - 1]) r = sorted(db) ans = n for i in range(n - k): ans += r[i] - 1 print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUN...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
n, m, k = map(int, input().split()) b = list(map(int, input().split())) l = n p = n c = [] for i in range(n - 1): c.append(b[i + 1] - b[i] - 1) c = sorted(c) for i in range(n - k): l += c[i] print(l)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
l = [int(i) for i in input().split()] n = l[0] k = l[2] b = [int(i) for i in input().split()] gap = [] for i in range(1, n): gap.append(b[i] - b[i - 1]) gap.sort() print("{}".format(sum(gap[0 : n - k : 1]) + k))
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BI...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
nmk = input().split(" ") n, m, k = int(nmk[0]), int(nmk[1]), int(nmk[2]) b = list(map(int, input().split(" "))) d = [] for i in range(1, n): d.append(b[i] - b[i - 1]) d.sort() temp = n for i in range(n - k): temp += d[i] - 1 print(temp)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR ...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
n, m, k = map(int, input().split()) b = list(map(int, input().split())) gaps = [] for i in range(1, n): gap = b[i] - b[i - 1] gaps.append(gap) gaps.sort() sumgaps = 0 i = n - 2 while i > n - k - 1 and i > -1: sumgaps += gaps[i] i -= 1 print(b[n - 1] - b[0] - sumgaps + k)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE ...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
n, m, k = map(int, input().split()) b = [int(i) for i in input().split()] if k == 1: print(b[-1] - b[0] + 1) else: d = [(b[i] - b[i - 1]) for i in range(1, n)] d.sort() d = d[: -k + 1] print(sum(d) + k)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMB...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
n, m, k = map(int, input().split()) arr = list(map(int, input().split())) arr2 = [] for i in range(1, len(arr)): arr2.append(arr[i] - arr[i - 1]) arr2.sort() arr2 = arr2[: n - k] print(sum(arr2) + k)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_O...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
n, m, k = map(int, input().split()) c = list(map(int, input().split())) l = k - 1 v = [] curr = c[0] for i in range(1, n): v.append(c[i] - curr - 1) curr = c[i] v.sort() tot = n for i in range(n - k): tot += v[i] print(tot)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR AS...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
def lenta(lst, K): differences = [0] * (len(lst) - 1) for i in range(1, len(lst)): differences[i - 1] = lst[i] - lst[i - 1] return sum(sorted(differences)[: len(lst) - K]) + K n, m, k = [int(j) for j in input().split()] a = [int(x) for x in input().split()] print(lenta(a, k))
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_C...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
n, m, k = map(int, input().split()) ls = list(map(int, input().split())) ans = ls[n - 1] - ls[0] ls1 = [] for i in range(1, n): ls1.append(ls[i] - ls[i - 1]) ls1.sort() count = 0 if k != 1: for x in reversed(ls1): ans = ans - x count = count + 1 if count == k - 1: break ans =...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
n, m, k = map(int, input().split()) b = list(map(int, input().split())) l = b[-1] - b[0] + 1 df = [] for i in range(1, n): df.append((b[i] - b[i - 1], b[i - 1], b[i])) df = sorted(df, key=lambda x: x[0]) for i in range(k - 1): rng = df.pop() l -= rng[0] - 1 print(l)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASS...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
l = [int(y) for y in input().split()] a = [int(y) for y in input().split()] temp = [] for key in range(1, len(a)): temp.append(a[key] - a[key - 1]) temp = sorted(temp, reverse=True) pk = a[len(a) - 1] - a[0] + l[2] b = sum(temp[: l[2] - 1]) print(pk - b)
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR V...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
from sys import stdin, stdout def inp(): return int(stdin.readline()) def minp(): return map(int, stdin.readline().rstrip().split()) def linp(): return list(minp()) def main(): n, m, k = minp() l = linp() s = 0 a = [] for i in range(1, n): a.append(l[i] - l[i - 1]) a....
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR ...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
n, m, k = tuple(map(int, input().split())) A = list(map(int, input().split())) rasst = [] ans = n for i in range(1, n): rasst.append((A[i] - A[i - 1] - 1, i)) rasst.sort(key=lambda x: -x[0]) for i in range(n - k): ans += rasst.pop()[0] print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FU...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
R = lambda: map(int, input().split()) n, m, k = R() b = [*R()] print(n + sum(sorted(y - x - 1 for x, y in zip(b, b[1:]))[: n - k]))
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
n, m, k = map(int, input().split()) b = list(map(int, input().split())) d = [(b[i + 1] - b[i] - 1) for i in range(n - 1)] d.sort(reverse=True) print(b[-1] - b[0] + 1 - sum(d[: k - 1]))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
n, m, k = map(int, input().split()) a = [*map(int, input().split())] b = [] for i in range(n - 1): b.append(a[i + 1] - a[i]) b.sort() ans = 0 for i in range(n - k): ans += b[i] print(ans + k)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR EXP...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
n, m, k = map(int, input().split()) p = [int(x) for x in input().split()] if k == n: print(n) else: t = n - k q = [0] * (n - 1) for i in range(0, n - 1): q[i] = p[i + 1] - p[i] q = sorted(q) s = 0 for i in range(0, t): s += q[i] - 1 print(s + n)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
import sys n, m, k = map(int, input().split()) b = list(map(int, input().split())) c = [(b[i + 1] - b[i] - 1) for i in range(n - 1)] c.sort() if k == n: ans = n print(ans) import sys sys.exit(0) else: pass ans = sum(c[: n - k]) + n print(ans)
IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR IMPORT EXPR FUNC_CA...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
I = lambda: map(int, input().split()) n, m, k = I() li = list(I()) diff = [] if k >= n: exit(print(n)) for i in range(1, len(li)): t = li[i] - li[i - 1] diff.append(t) diff.sort() ans = n t = n for i in diff: t = t - 1 ans = ans + i - 1 if t == k: exit(print(ans))
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CAL...
You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise,...
n, m, k = map(int, input().split()) b = list(map(int, input().split())) sab = [(b[i + 1] - b[i]) for i in range(len(b) - 1)] sortsab = sorted(sab) sumtape = 0 for i in range(n - k): sumtape += sortsab[i] sumtape += k print(sumtape)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VA...