One way to create a task is to learn from life. You can choose some experience in real life, formalize it and then you will get a new task.

Let's think about a scene in real life: there are lots of people waiting in front of the elevator, each person wants to go to a certain floor. We can formalize it in the following way. We have n people standing on the first floor, the i-th person wants to go to the f_{i}-th floor. Unfortunately, there is only one elevator and its capacity equal to k (that is at most k people can use it simultaneously). Initially the elevator is located on the first floor. The elevator needs |a - b| seconds to move from the a-th floor to the b-th floor (we don't count the time the people need to get on and off the elevator).

What is the minimal number of seconds that is needed to transport all the people to the corresponding floors and then return the elevator to the first floor?


-----Input-----

The first line contains two integers n and k (1 ≤ n, k ≤ 2000) — the number of people and the maximal capacity of the elevator.

The next line contains n integers: f_1, f_2, ..., f_{n} (2 ≤ f_{i} ≤ 2000), where f_{i} denotes the target floor of the i-th person.


-----Output-----

Output a single integer — the minimal time needed to achieve the goal.


-----Examples-----
Input
3 2
2 3 4

Output
8

Input
4 2
50 100 50 100

Output
296

Input
10 3
2 2 2 2 2 2 2 2 2 2

Output
8



-----Note-----

In first sample, an optimal solution is:   The elevator takes up person #1 and person #2.  It goes to the 2nd floor.  Both people go out of the elevator.  The elevator goes back to the 1st floor.  Then the elevator takes up person #3.  And it goes to the 2nd floor.  It picks up person #2.  Then it goes to the 3rd floor.  Person #2 goes out.  Then it goes to the 4th floor, where person #3 goes out.  The elevator goes back to the 1st floor.

Difficulty: EASY

Starter code:

Solutions:
(n, k) = [int(x) for x in input().split()]
L = [int(x) for x in input().split()]
L.sort()
m = 0
while len(L) > k:
	m += L[-1] - 1
	for i in range(k):
		L.pop()
else:
	m += L[-1] - 1
print(2 * m)


from sys import stdin, stdout
input = stdin.readline
from math import ceil
(n, k) = map(int, input().split())
p = sorted(list(map(int, input().split())))
ans = 0
for i in p[n::-k]:
	ans += i - 1
stdout.write(str(ans * 2))


(n, k) = map(int, input().split())
mass = sorted(map(int, input().split()), reverse=1)
time = 0
for i in range(0, n, k):
	time += (mass[i] - 1) * 2
print(time)


(nP, nC) = map(int, input().split())
f = [-int(k) for k in input().split()]
f.sort()
res = 0
for i in range(0, nP, nC):
	res += 2 * (-f[i] - 1)
print(res)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
prev = 1
ans = 0
for (i, x) in enumerate(a):
	t = n - i
	c = (t + k - 1) // k
	v = 2 * c * (x - prev)
	ans += v
	prev = x
print(ans)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
l = sorted(l)[::-1]
ans = 0
cur = 0
while cur < n:
	ans += (l[cur] - 1) * 2
	cur += k
print(ans)


(n, k) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
rem = n % k
m = n // k
cost = 0
if rem:
	cost = (f[:rem][-1] - 1) * 2
for i in range(1, m + 1):
	cost += (f[rem + i * k - 1] - 1) * 2
print(cost)


def main():
	(n, k) = map(int, input().split())
	ff = list(map(int, input().split()))
	l = [0] * (max(ff) + 1)
	for f in ff:
		l[f] += 1
	l = [(f - 1, x) for (f, x) in enumerate(l) if x]
	l.reverse()
	tot = 0
	it = iter(l)
	try:
		v = 0
		while True:
			(f1, n) = next(it)
			if not v:
				f = f1
			if v + n >= k:
				n -= k - v
				tot += f
				f = f1
				tot += n // k * f
				v = n % k
			else:
				v += n
	except StopIteration:
		tot += (v + k - 1) // k * f
		print(tot * 2)
main()


import math

class CodeforcesTask472BSolution:

	def __init__(self):
		self.result = ''
		self.n_k = []
		self.people = []

	def read_input(self):
		self.n_k = [int(x) for x in input().split(' ')]
		self.people = [int(x) for x in input().split(' ')]

	def process_task(self):
		self.people.sort(reverse=True)
		time = 0
		for x in range(int(math.ceil(self.n_k[0] / self.n_k[1]))):
			time += 2 * (max(self.people[x * self.n_k[1]:(x + 1) * self.n_k[1]]) - 1)
		self.result = str(time)

	def get_result(self):
		return self.result
Solution = CodeforcesTask472BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


(n, k) = (int(x) for x in input().split())
print(sum(sorted((int(x) - 1 for x in input().split()))[::-k]) * 2)


(n, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr.sort()
ans = 0
p = 1
i = 0
while n != 0:
	tp = arr[i]
	ans += 2 * (tp - p) * round(n / k + 0.49999999999999)
	while n != 0 and arr[i] == tp:
		n -= 1
		i += 1
	p = tp
print(ans)


first = input().split()
n = int(first[0])
k = int(first[1])
second = input().split()
second = list(map(int, second))
second.sort()
second.reverse()
second = second[::k]
need = 0
for i in second:
	need += 2 * (i - 1)
print(need)


(n, k) = map(int, input().split())
L = list(map(int, input().split()))
L.sort(reverse=True)
ans = 0
cnt = k
for i in range(n):
	if cnt == k:
		ans += 2 * (L[i] - 1)
		cnt = 1
	else:
		cnt += 1
print(ans)


n = [int(p) for p in input().split()]
m = [int(p) for p in input().split()]
t = 0
m = sorted(m, reverse=True)
while n[0] > n[1]:
	t += 2 * (m[0] - 1)
	m = m[n[1]:]
	n[0] = n[0] - n[1]
t += 2 * int(m[0] - 1)
print(t)


(n, k) = map(int, input().split())
line = list(map(int, input().split()))
line.sort()
m = (n - 1) % k
res = 0
for i in range(m, n, k):
	res += line[i] - 1
print(2 * res)


(n, k) = input().split(' ')
str_in = input('')
a = [int(x) for x in str_in.split()]
a.sort(reverse=True)
i = 0
ans = 0
while i < int(n):
	ans = ans + a[i] * 2 - 2
	i = i + int(k)
print(str(ans) + '\n')


import math
(n, k) = map(int, input().split())
flist = [int(x) for x in input().split()]
time = 0
flist.sort()
flist.reverse()
if n <= k:
	print(2 * flist[0] - 2)
	quit()
for i in range(math.ceil(n / k)):
	time += 2 * flist[k * i] - 2
print(time)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
ans = 0
st = 0
while st < len(arr):
	ans += (arr[st] - 1) * 2
	st += k
print(ans)


(n, k) = map(int, input().split())
f = sorted(list(map(int, input().split())), reverse=True)
ans = 0
for i in range(0, n, k):
	ans += 2 * (f[i] - 1)
print(ans)


l = input().split()
n = int(l[0])
k = int(l[1])
l1 = input().split()
for x in range(n):
	l1[x] = int(l1[x])
l1 = sorted(l1, reverse=True)
c = 0
for x in range(0, n, k):
	c += 2 * (l1[x] - 1)
print(c)


import itertools as ittls
from collections import Counter
import re
import math

def sqr(x):
	return x * x

def inputarray(func=int):
	return map(func, input().split())
(n, k) = inputarray()
A = [1] + sorted(inputarray())
s = 0
for i in range(1, n + 1):
	s = s + 2 * (A[i] - A[i - 1]) * ((n - i + 1 + k - 1) // k)
print(s)


def read():
	return list(map(int, input().split()))
(n, k) = read()
a = sorted(read(), reverse=True)
ans = 0
for i in range((n + k - 1) // k):
	ans += a[i * k] - 1
print(2 * ans)


def solve(n, k, f):
	result = 0
	f.sort(reverse=True)
	for i in range(0, n, k):
		result += 2 * (f[i] - 1)
	return result
(n, k) = map(int, input().split())
f = list(map(int, input().split()))
assert len(f) == n
print(solve(n, k, f))


(n, k) = map(int, input().split())
f = sorted(map(int, input().split()), reverse=True)
print(sum((2 * (max(f[i * k:(i + 1) * k]) - 1) for i in range((n + k - 1) // k))))


(n, k) = map(int, input().split())
people = list(sorted(map(int, input().split())))
res = 0
while len(people) != 0:
	x = people[-1]
	i = 0
	while len(people) != 0 and i != k:
		i += 1
		people.pop()
	res += x - 1
	res += x - 1
print(res)


def func(l):
	s = 0
	i = 0
	n = len(l) - 1
	while i < n:
		s += l[i] - l[i + 1]
		i += 1
	s += l[n] - 1
	return 2 * s
m = [int(i) for i in input().split()]
c = m[1]
l = [int(i) for i in input().split()]
l.sort()
l.reverse()
k = [l[i:i + c] for i in range(0, m[0], c)]
s = 0
for i in k:
	s += func(i)
print(s)


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
s = 0
for i in range(len(A) - 1, -1, -k):
	elems = [A[j] for j in range(i, max(-1, i - k), -1)]
	s += 2 * (max(elems) - 1)
print(s)


numbers = [int(n) for n in input().split()]
capacity = numbers[1]
people = [int(n) for n in input().split()]
people.sort()
total = 0
pos = len(people) - 1
while pos >= 0:
	total += 2 * people[pos] - 2
	pos -= capacity
print(total)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
t = 0
for i in range(0, n, k):
	try:
		t += (max(a[i:i + k]) - 1) * 2
	except:
		t += (max(a[i:]) - 1) * 2
print(t)


(n, k) = map(int, input().split())
a = sorted(map(int, input().split()))
t = 0
if n % k == 0:
	for x in range(0, n, k):
		t += 2 * max(a[x:x + k]) - 2
else:
	t += (max(a[0:n % k]) - 1) * 2
	a = a[n % k:]
	for y in range(0, n - k, k):
		t += 2 * max(a[y:y + k]) - 2
print(t)


from sys import stdin
from collections import defaultdict
input = stdin.readline
T = 1
for t in range(1, T + 1):
	(n, k) = map(int, input().split())
	_input = list(map(int, input().split()))
	_input.sort(reverse=True)
	total_cost = 0
	for i in range(0, len(_input), k):
		total_cost += (_input[i] - 1) * 2
	print(total_cost)


def main():
	(n, k) = read()
	a = [i - 1 for i in read()]
	a.sort()
	a.reverse()
	print(sum(a[::k]) * 2)

def read(mode=2):
	inputs = input().strip()
	if mode == 0:
		return inputs
	if mode == 1:
		return inputs.split()
	if mode == 2:
		return list(map(int, inputs.split()))

def write(s='\n'):
	if s is None:
		s = ''
	if isinstance(s, list):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s, end='')
write(main())


(n, k) = map(int, input().split())
l = sorted(map(int, input().split()))[::-1]
ans = 0
for i in range(0, n, k):
	ans += (l[i] - 1) * 2
print(ans)


([n, k], a, i, ans, t) = (list(map(int, input().split())), sorted(map(int, input().split())), 0, 0, 1)
while i < len(a):
	ans += ((n + k - 1) // k * 2 - 1) * (a[i] - t)
	t = a[i]
	while i < len(a) and a[i] == t:
		i += 1
		n -= 1
print(ans + t - 1)


(n, k) = list(map(int, input().split()))
e = 1
ans = 0
p = sorted(list(map(int, input().split())), reverse=True)
for i in range(0, n, k):
	ans += max(p[i:i + k]) * 2 - 2
print(ans)


(a, b) = map(int, input().split())
z = list(map(int, input().split()))
s = 0
for i in set(z):
	r = z.count(i)
	s += 2 * (i - 1) * (r // b)
	for j in range(b * (r // b)):
		z.remove(i)
z.sort(reverse=True)
print(s + sum((2 * (i - 1) for i in z[::b])))


(a, b) = map(int, input().split(' '))
floors = list(map(int, input().split(' ')))
floors.sort()
floors.reverse()
total = 0
while floors != []:
	if len(floors) >= b:
		dist = floors[0] - 1
		goto = floors[b - 1]
		total += dist + goto - 1 + abs(floors[0] - goto)
		floors = floors[b:]
	else:
		dist = floors[0] - 1
		total += 2 * dist
		floors = []
print(total)


(n, k) = map(int, input().split())
t = []
t = list(map(int, input().split()))
t.sort()
s = 0
l = n - 1
while l >= 0:
	s += 2 * (t[l] - 1)
	l -= k
print(s)


(n, k) = tuple(map(int, input().split(' ')))
floors = list(map(int, input().split(' ')))
floors.sort(reverse=True)
result = 0
for i in range(0, len(floors), k):
	tmp_floors = floors[i:i + k]
	high = tmp_floors[0]
	result += high - 1
	for tmp_high in tmp_floors[1:]:
		result += high - tmp_high
		high = tmp_high
	result += tmp_floors[-1] - 1
print(result)


input_to_list = lambda : [int(i) for i in input().split()]
(n, k) = input_to_list()
values = input_to_list()
values.sort()
n -= 1
min_time = 0
while n >= 0:
	min_time += (values[n] - 1) * 2
	n -= k
print(min_time)


import math
(n, k) = map(int, input().split())
l = sorted(list(map(int, input().split())))
total = 0
for i in range(math.ceil(n / k)):
	total += 2 * (l[n - i * k - 1] - 1)
print(total)


(n, k) = input().strip().split()
n = int(n)
k = int(k)
f = input().strip().split()
for (index, item) in enumerate(f):
	f[index] = int(item)
f.sort(reverse=True)
i = 0
ans = 0
while i < n:
	ans += (f[i] - 1) * 2
	i += k
print(ans)


(nop, max_capacity) = [int(x) for x in input().split()]
lip = sorted([int(x) for x in input().split()])
ans = 0
for i in range(len(lip) - 1, -1, -max_capacity):
	ans += 2 * (lip[i] - 1)
print(ans)


(n, k) = map(int, input().split())
t = {}
for i in map(int, input().split()):
	t[i] = t.get(i, 0) + 1
t = list(t.items())
t.sort()
t.reverse()
d = s = 0
for (i, j) in t:
	if j > d:
		s += (i - 1) * ((j - d - 1) // k + 1)
		d = (d - j) % k
	else:
		d -= j
print(2 * s)


(n, k) = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]
current = 1
ans = 0
f.sort()
while f:
	length = len(f)
	if length % k == 0:
		ans += (f[0] - current) * (length // k * 2 - 1)
	else:
		ans += (f[0] - current) * (length // k * 2 + 1)
	current = f[0]
	while f and f[0] == current:
		del f[0]
print(ans + current - 1)


(N, K) = map(int, input().split())
F = list(reversed(sorted(map(int, input().split()))))
res = 0
for i in range((N + K - 1) // K):
	res += 2 * (F[i * K] - 1)
print(res)


(n, k) = map(int, input().split())
f = list(map(int, input().split()))
l = map
f.sort(reverse=True)
time = 0
while len(f) > k:
	time += 2 * (max(f[:k]) - 1)
	f = f[k:]
time += 2 * (max(f) - 1)
print(time)


(n, k) = map(int, input().split())
floors = list(map(int, input().split()))
floors.sort()
time = 0
while floors:
	max_floor = floors[len(floors) - 1]
	time += (max_floor - 1) * 2
	del floors[-k:]
print(time)


(n, k) = (int(x) for x in input().split())
f = list(map(int, input().split()))
g = sorted((x - 1 for x in f))[::-k]
print(sum(g) * 2)


def lift(k, lst):
	result = 0
	for i in range(len(lst) - 1, -1, -k):
		result += 2 * (sorted(lst)[i] - 1)
	return result
(N, K) = [int(j) for j in input().split()]
a = [int(z) for z in input().split()]
print(lift(K, a))


import math

def main():
	(n, k) = map(int, input().split())
	floors = list(map(int, input().split()))
	floors.sort()
	time = floors[-1] - 1
	count = 0
	floor = floors[0]
	while floors:
		time += 2 * (floor - 1) * int(math.ceil(len(floors) / k))
		time -= floor - 1
		for i in range(len(floors)):
			floors[i] -= floor - 1
		while floors and floors[0] == 1:
			floors.pop(0)
		if floors:
			floor = floors[0]
	print(time)
main()


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
res = 0
while len(arr) > 0:
	res += (arr[-1] - 1) * 2
	arr = arr[:-k]
print(res)


(n, k) = (int(x) for x in input().split())
f = sorted(map(int, input().split()))
v = [el - 1 for el in f[n::-k]]
print(sum(v) * 2)


(n, k) = map(int, input().split())
arr = [int(x) for x in input().split()]
ans = 0
arr = sorted(arr, reverse=True)
_list = arr[::k]
for i in _list:
	ans += (i - 1) * 2
print(str(ans))


import sys
(n, k) = map(int, sys.stdin.readline().split())
f = list(map(int, sys.stdin.readline().split()))
f = [i - 1 for i in f]
ans = 0
while f:
	ans += (len(f) + k - 1) // k * 2
	f = [i - 1 for i in f if i > 1]
print(ans)


import math
(n, k) = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
p.reverse()
ans = 0
for i in range(math.ceil(n / k)):
	ans += 2 * (p[k * i] - 1)
print(ans)


(n, k) = map(int, input().split())
(c, i) = (0, 0)
lst = sorted(list(map(int, input().split())), reverse=True)
while i < n:
	c = c + (lst[i] - 1) * 2
	i = i + k
print(c)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
a = a[::-1]
ans = 0
for i in range((n - 1) // k + 1):
	ans += a[i * k] - 1
print(ans * 2)


(n, k) = map(int, input().split())
F = list(map(int, input().split()))
F.sort(reverse=True)
ans = 0
for i in range(0, n, k):
	ans += (F[i] - 1) * 2
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
i = 0
ans = 0
while i < n:
	ans += (a[i] - 1) * 2
	i += k
print(ans)


(n, k) = list(map(int, input().split(' ')))
tgt = list(map(int, input().split(' ')))
tgt = sorted(tgt)[::-1]
count = 0
i = 0
cap = k
while i < n:
	ref = tgt[i:i + cap]
	if i + cap >= n:
		count += 2 * max(ref) - 2
		break
	i += cap
	count += 2 * max(ref) - 2
print(count)


def sol():
	(n, cap) = [int(x) for x in input().split(' ')]
	vec = sorted([int(x) for x in input().split(' ')])
	freq = {}
	for i in vec:
		freq[i] = 0
	for i in vec:
		freq[i] += 1
	ans = 0
	while n > 0:
		temp_c = cap
		n -= temp_c
		visited_floors = []
		while temp_c > 0:
			floor = 0
			for (key, val) in freq.items():
				if val > 0 and floor <= key:
					floor = key
			if floor == 0:
				break
			dropoff = min(temp_c, freq[floor])
			temp_c -= dropoff
			freq[floor] -= dropoff
			visited_floors.append(floor)
		max_floor_visited = max(visited_floors)
		for i in vec:
			if freq[i] == 0:
				freq[i] = -1
		ans += 2 * (max_floor_visited - 1)
	print(ans)
	return ans
sol()


(n, k) = map(int, input().split())
f = list(map(int, input().split()))
f.sort(reverse=True)
ans = 0
places = 0
for fl in f:
	places += 1
	if places == 1:
		ans += 2 * (fl - 1)
	if places == k:
		places = 0
print(ans)


(n, k) = map(int, input().split())
f = sorted(map(int, input().split()))
print(sum(((i - 1) * 2 for i in f[-1::-k])))


(n, k) = list(map(int, input().split()))
t = list(map(int, input().split()))
t.sort(reverse=True)
r = 0
i = 0
while i < n:
	r += (t[i] - 1) * 2
	i += k
print(r)


from collections import Counter
from math import ceil
(n, k) = map(int, input().split())
fs = Counter(map(int, input().split()))
left = n
t = 0
floor = 1
while left:
	t_floor = 2 * ceil(left / k)
	t += t_floor
	floor += 1
	left -= fs[floor]
print(t)


(n, k) = map(int, input().split())
L = list(map(int, input().split()))
r = 0
i = n - 1
L.sort()
while i >= 0:
	r += L[i] - 1
	i -= k
print(2 * r)


(n, k) = list(map(int, input().split()))
c = 0
a = list(map(int, input().split()))
a.sort()
while a:
	t = []
	for i in range(k):
		if a:
			t.append(a.pop())
	c += (max(t) - 1) * 2
	t.clear()
print(c)


from sys import *
from math import *
import sys

def main():
	(n, k) = [int(i) for i in input().split()]
	f = [int(i) for i in input().split()]
	f = sorted(f, reverse=True)
	s = 0
	for i in range(0, len(f)):
		if i % k == 0:
			s += f[i] - 1
	print(2 * s)
main()


(n, k) = [int(a) for a in input().split()]
f = [int(a) for a in input().split()]
f.sort()
time = 0
while len(f) > 0:
	time += 2 * (f[-1] - 1)
	f = f[:-k]
print(time)


(n, k) = map(int, input().split())
f = list(map(int, input().split()))
f.sort(reverse=True)
s = 0
for i in range(0, n, k):
	s += 2 * (f[i] - 1)
print(s)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
l.sort(reverse=True)
res = 0
for i in range(0, n, k):
	res += l[i] * 2 - 2
print(res)


(n, k) = map(int, input().split())
floors = list(sorted(list(map(int, input().split())), reverse=True))
print(sum((2 * x - 2 for x in floors[::k])))


(n, k) = list(map(int, input().split()))
s = 0
f = sorted([int(i) - 1 for i in input().split()])
while f:
	for i in range(k):
		if i == 0:
			s += f.pop() * 2
		elif f:
			f.pop()
print(s)


import math
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
su = 0
for i in range(math.ceil(n / k)):
	su += a[i * k] - 1
print(su * 2)


(n, k) = list(map(int, input().split()))
arr = [int(i) for i in input().split()]
ans = [0] * 2001
for i in arr:
	ans[i] += 1
r = 0
j = 2000
while j >= 0:
	z = k
	m = 0
	while z > 0 and j > 0:
		if ans[j] >= z:
			m = max(m, j)
			ans[j] -= z
			z = 0
			break
		z -= ans[j]
		if ans[j] > 0:
			m = max(j, m)
		ans[j] = 0
		j -= 1
	if ans[j] == 0:
		j -= 1
	if m > 1:
		r += 2 * (m - 1)
print(r)


(n, k) = list(map(int, input().split()))
f = list(map(int, input().split()))
f = sorted(f)
i = 0
cnt = 0
for i in range(1, n + 1, k):
	cnt += (f[-i] - 1) * 2
print(cnt)


def main():
	(n, k) = map(int, input().split())
	a = sorted(map(int, input().split()), reverse=True)
	print(sum(map(lambda x: x - 1, a[::k])) * 2)
main()


(n, k) = map(int, input().split())
f = list(map(int, input().split()))
down = max(f) - 1
count = 0
lastFloor = 1
while len(f) != 0:
	destination = min(f)
	l = f.count(destination)
	count += ((n + k - 1) // k * 2 - 1) * (destination - lastFloor)
	lastFloor = destination
	for i in range(l):
		f.remove(destination)
	n = n - l
	for i in f:
		i -= lastFloor
count += down
print(count)


(n, k) = [int(i) for i in input().split()]
ppl = sorted([int(i) for i in input().split()], reverse=True)
time = 0
for i in range(0, n + k, k):
	try:
		time += (ppl[i] - 1) * 2
	except:
		break
print(time)


from sys import exit
(n, t) = input().split()
n = int(n)
t = int(t)
a = []
test_case = input()
for w in test_case.split():
	a.append(int(w))
a.sort()
ans = 0
while n >= 1:
	ans += 2 * (a[n - 1] - 1)
	n = n - t
print(ans)
exit()


(n, k) = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
p.reverse()
ans = 0
while p:
	ans += 2 * (p[0] - 1)
	if len(p) <= k:
		break
	else:
		p = p[k:]
print(ans)


(n, k) = map(int, input().split())
A = sorted(map(int, input().split()))
ans = 0
while len(A):
	ans += 2 * (A.pop() - 1)
	for i in range(k - 1):
		if len(A):
			A.pop()
print(ans)


(n, k) = [int(x) for x in input().split()]
f = [int(x) - 1 for x in input().split()]
f.sort()
assert len(f) == n
print(2 * sum(f[-1::-k]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
print((sum(a[::k]) - n // k - (1 if n % k != 0 else 0)) * 2)


(n, k) = map(int, input().split())
s = list(map(int, input().split()))
s = sorted(s)
m = 0
if len(s) % k != 0:
	m = 2 * (max(s[:len(s) % k]) - 1)
	s = s[len(s) % k:]
while s != []:
	l = len(s)
	m += (s[l - 1] - 1) * 2
	s = s[:l - k]
print(m)


(n, k) = list(map(int, input().split()))
f = list(map(int, input().split()))
f.sort()
res = 0
while len(f) > 0:
	res += 2 * f[-1] - 2
	for i in range(k):
		if len(f) > 0:
			f.pop()
print(res)


f = lambda : map(int, input().split())
(n, k) = f()
a = sorted(list(f()))
ans = 0
i = n - 1
while i >= 0:
	ans += 2 * a[i] - 2
	i -= k
print(ans)


a = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
x.sort(reverse=True)
sum = 0
for i in range(0, len(x), a[1]):
	sum += x[i] - 1
sum *= 2
print(sum)


(o, k) = input().split()
n = int(o)
f = [int(x) for x in input().split()]
p = sorted(f)
p.reverse()
c = 0
while n > 0:
	c += 2 * p[0] - 2
	if n > int(k):
		p = p[int(k):]
	n -= int(k)
print(c)


import math
import sys
import os
(n, k) = map(int, input().split())
step = list(map(int, input().split()))
step.sort()
step.reverse()
if n > k:
	z = int(round(n / k + 0.5))
	res = 0
	for i in range(z):
		if k < len(step):
			res += 2 * (step[0] - 1)
			del step[:k]
		else:
			res += 2 * (step[0] - 1)
else:
	res = 2 * (step[0] - 1)
print(res)


(n, k) = map(int, input().strip().split(' '))
lst = list(map(int, input().strip().split(' ')))
c = 0
lst.sort(reverse=True)
k1 = 0
l = 0
j = 0
while j < n:
	if k1 < k:
		k1 += 1
		if k1 == 1:
			l = lst[j]
		if j == n - 1:
			c += (l - 1) * 2
	else:
		k1 = 1
		c += (l - 1) * 2
		l = lst[j]
		if j == n - 1:
			c += (l - 1) * 2
	j += 1
print(c)


inp = lambda : [*map(int, input().split())]
(n, k) = inp()
f = sorted(inp(), reverse=True)
i = 0
ans = 0
while i < n:
	ans += (max(f[i:min(n, i + k + 1)]) - 1) * 2
	i += k
print(ans)


(n, k) = input().split()
n = int(n)
k = int(k)
l = input().split()
for i in range(n):
	l[i] = int(l[i])
l.sort()
r = 0
if k != 1:
	i = 1
	while i <= n:
		if i % k == 1:
			r += 2 * (l[-i] - 1)
		i += 1
	if i != n + 1:
		r += 2 * (l[-i] - 1)
else:
	for i in range(n):
		r += 2 * (l[i] - 1)
print(r)


import sys
import queue
first = sys.stdin.readline().split()
n = int(first[0])
k = int(first[1])
data = [int(x) for x in sys.stdin.readline().split()]
data.sort()
data.reverse()
i = 0
result = 0
while i < n:
	result += (data[i] - 1) * 2
	i += k
print(result)


(n, c) = [int(i) for i in input().split()]
arr = sorted((int(i) for i in input().split()), reverse=True)
print(sum((2 * i - 2 for i in arr[::c])))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
i = n - 1
s = 0
while i >= 0:
	s += (a[i] - 1) * 2
	i -= k
print(s)


(n, m) = input().split()
n = int(n)
m = int(m)

def inp(s):
	j = 0
	a = []
	for i in range(len(s)):
		if s[i] == ' ':
			a.append(int(s[j:i]))
			j = i + 1
		if i == len(s) - 1:
			a.append(int(s[j:]))
	return a
s = input()
a = inp(s)
a = sorted(a, reverse=True)
i = 0
r = 0
j = n
while i < n:
	r = r + 2 * (a[i] - 1)
	i = i + m
print(r)