Chef Ada is preparing $N$ dishes (numbered $1$ through $N$). For each valid $i$, it takes $C_i$ minutes to prepare the $i$-th dish. The dishes can be prepared in any order.
Ada has a kitchen with two identical burners. For each valid $i$, to prepare the $i$-th dish, she puts it on one of the burners and after $C_i$ minutes, removes it from this burner; the dish may not be removed from the burner before those $C_i$ minutes pass, because otherwise it cools down and gets spoiled. Any two dishes may be prepared simultaneously, however, no two dishes may be on the same burner at the same time. Ada may remove a dish from a burner and put another dish on the same burner at the same time.
What is the minimum time needed to prepare all dishes, i.e. reach the state where all dishes are prepared?

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains a single integer $N$.
- The second line contains $N$ space-separated integers $C_1, C_2, \ldots, C_N$.

-----Output-----
For each test case, print a single line containing one integer ― the minimum number of minutes needed to prepare all dishes.

-----Constraints-----
- $1 \le T \le 1,000$
- $1 \le N \le 4$
- $1 \le C_i \le 5$ for each valid $i$

-----Subtasks-----
Subtask #1 (1 points): $C_1 = C_2 = \ldots = C_N$
Subtask #2 (99 points): original constraints

-----Example Input-----
3
3
2 2 2
3
1 2 3
4
2 3 4 5

-----Example Output-----
4
3
7

-----Explanation-----
Example case 1: Place the first two dishes on the burners, wait for two minutes, remove both dishes and prepare the last one on one burner.
Example case 2: Place the first and third dish on the burners. When the first dish is prepared, remove it and put the second dish on the same burner.
Example case 3: Place the third and fourth dish on the burners. When the third dish is prepared, remove it and put the second dish on the same burner. Similarly, replace the fourth dish (when it is prepared) by the first dish on the other burner.

Difficulty: EASY

Solutions:
for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	c.sort(reverse=True)
	(f, s) = (0, 0)
	for i in c:
		if f >= s:
			s += i
		else:
			f += i
	print(max(f, s))


t = int(input())
while t:
	n = int(input())
	l = sorted(list(map(int, input().split())), reverse=True)
	a = b = 0
	for i in l:
		if a < b:
			a += i
		else:
			b += i
	print(max(a, b))
	t -= 1


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	len1 = len(l)
	a = l[len1 - 1]
	b = l[len1 - 2]
	len1 -= 2
	sum = 0
	c = 0
	for j in range(n - 1):
		if l[j] != l[j + 1]:
			c = 1
	if c == 0:
		if n % 2 != 0:
			n = n // 2 + 1
			print(n * l[0])
		else:
			n = n // 2
			print(n * l[0])
	else:
		while len1 >= 0:
			if len1 == 0:
				z = max(a, b)
				sum += z
				break
			else:
				z = min(a, b)
			sum += z
			len1 -= 1
			if a < b:
				a = l[len1]
				b = b - z
			else:
				b = l[len1]
				a = a - z
		print(sum)


for _ in range(0, int(input())):
	x = int(input())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	s1 = 0
	s2 = 0
	for i in l:
		if s1 > s2:
			s2 = s2 + i
		else:
			s1 = s1 + i
	x = max(s1, s2)
	print(x)


for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	c.sort(reverse=True)
	c1 = 0
	c2 = 0
	for i in c:
		if c1 < c2:
			c1 = c1 + i
		else:
			c2 = c2 + i
	print(max([c1, c2]))


T = int(input())
for cases in range(T):
	N = int(input())
	C = sorted([int(f) for f in input().split()])
	if N <= 2:
		print(C[-1])
	elif N == 3:
		print(C[-2] + sorted([C[-3], C[-1] - C[-2]])[-1])
	else:
		print(C[-2] + sorted([C[-3], C[-1] - C[-2]], reverse=True)[-1] + sorted([C[-4], abs(C[-3] - C[-1] + C[-2])])[-1])


for i in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	c.sort()
	(x, y) = (0, 0)
	c = c[::-1]
	for i in range(n):
		if x > y:
			y += c[i]
		else:
			x += c[i]
	print(max(x, y))


def decimalToBinary(n, l):
	a = bin(n).replace('0b', '')
	while len(a) < l:
		a = '0' + a
	return a
for _ in range(int(input())):
	n = int(input())
	a = sorted([int(x) for x in input().split()])
	possible_time = set()
	for i in range(2 ** n):
		binary_i = decimalToBinary(i, n)
		current_time = [0, 0]
		for j in range(n):
			current_time[int(binary_i[j])] += a[j]
		possible_time.add(max(current_time))
	print(min(possible_time))


n = int(input())
for i in range(n):
	N = int(input())
	lst = list(map(int, input().split()))
	if N == 1:
		print(lst[0])
	elif N == 2:
		print(lst[1])
	elif N == 3:
		print(lst[1] + max(lst[0], lst[2] - lst[1]))
	elif lst[3] - lst[2] >= lst[1]:
		print(lst[2] + lst[1] + max(lst[0], lst[3] - (lst[1] + lst[2])))
	else:
		print(lst[3] + max(lst[0], lst[1] + lst[2] - lst[3]))


try:
	t = int(input())
	for _ in range(t):
		c = 0
		n = int(input())
		a = list(map(int, input().split()))
		a.sort(reverse=True)
		b = c = 0
		for i in a:
			if b < c:
				b += i
			else:
				c += i
		print(max(b, c))
except:
	pass


t = int(input())
for tc in range(t):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	c = a[::-1]
	x = 0
	y = 0
	for j in c:
		if x > y:
			y += j
		else:
			x += j
	print(max(x, y))


for _ in range(int(input())):
	N = int(input())
	C = list(map(int, input().split()))
	a1 = 0
	a2 = 0
	C.sort(reverse=True)
	for i in C:
		if a1 < a2:
			a1 += i
		else:
			a2 += i
	print(max(a1, a2))


t = int(input())
while t != 0:
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	arr = arr[::-1]
	c = 0
	k = 0
	for i in range(len(arr)):
		if c >= k:
			k += arr[i]
		else:
			c += arr[i]
	print(max(c, k))
	t -= 1


for i in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	if n == 1 or n == 2:
		print(max(li))
	elif n == 3:
		li.sort()
		gre = li[2]
		rem = li[0] + li[1]
		if rem <= gre:
			print(gre)
		else:
			rem = rem - gre
			print(gre + rem)
	else:
		li.sort()
		gre = li[3]
		rem = li[1] + li[2]
		if rem > gre:
			rem = rem - gre
			if rem >= li[0]:
				print(gre + rem)
			else:
				print(gre + li[0])
		elif rem == gre:
			print(gre + li[0])
		elif rem < gre:
			rem = rem + li[0]
			if rem <= gre:
				print(gre)
			else:
				rem = rem - gre
				print(gre + rem)


t = int(input())
while t:
	n = int(input())
	dish = list(map(int, input().split()))
	(b0, b1) = (0, 0)
	mins = 0
	dish.sort(reverse=True)
	for i in dish:
		if b0 <= b1:
			b0 = b0 + i
		else:
			b1 = b1 + i
	print(max(b0, b1))
	t -= 1


t = int(input(''))
for _ in range(t):
	n = int(input(''))
	l = list(map(int, input('').strip().split()))[:n]
	l.sort(reverse=True)
	b1 = b2 = 0
	for i in l:
		if b1 < b2:
			b1 += i
		else:
			b2 += i
	print(max(b1, b2))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	b1 = 0
	b2 = 0
	for el in arr:
		if b1 < b2:
			b1 += el
		else:
			b2 += el
	print(max(b1, b2))


for tc in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	c.sort(reverse=True)
	c1 = []
	c2 = []
	for i in range(n):
		if sum(c1) <= sum(c2):
			c1.append(c[i])
		else:
			c2.append(c[i])
	print(max(sum(c1), sum(c2)))


for _ in range(int(input())):
	N = int(input())
	L = sorted(map(int, input().split()))
	if N == 1:
		print(sum(L))
	else:
		A = L[:-1]
		B = L[-1:]
		while sum(A) - sum(B) > A[0]:
			B.append(A[0])
			del A[0]
		print(max(sum(A), sum(B)))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr = sorted(arr, reverse=True)
	first = 0
	second = 0
	for i in range(n):
		if first >= second:
			second += arr[i]
		else:
			first += arr[i]
	print(max(first, second))


for i in range(int(input())):
	N = int(input())
	C = list(map(int, input().split()))
	C.sort(reverse=True)
	b1 = b2 = 0
	for i in range(N):
		if b1 < b2:
			b1 += C[i]
		else:
			b2 += C[i]
	print(max(b1, b2))


t = int(input())
for i in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	b1 = 0
	b2 = 0
	c.sort(reverse=True)
	for i in range(n):
		if b1 > b2:
			b2 = b2 + c[i]
		else:
			b1 = b1 + c[i]
	ans = max(b1, b2)
	print(ans)


t = int(input())
d = []
for i in range(t):
	n = int(input())
	d.append(list(map(int, input().split())))
output = []
for arr in d:
	arr.sort(reverse=True)
	time = 0
	i = 0
	t = 0
	while i < len(arr):
		if t == 0:
			time += arr[i]
			t = arr[i]
		i += 1
		if i >= len(arr):
			break
		if arr[i] <= t:
			t -= arr[i]
			arr[i] = 0
		else:
			arr[i] -= t
			t = 0
	output.append(time)
for i in output:
	print(i)


def main():
	K = int(input())
	for _ in range(K):
		N = int(input())
		arr = list(map(int, input().split(' ')))[:N]
		a = b = 0
		arr.sort(reverse=True)
		for i in range(N):
			if a < b:
				a += arr[i]
			else:
				b += arr[i]
		print(max(a, b))
main()


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	l1 = []
	for i in reversed(range(n)):
		l1.append(l[i])
	b1 = l1[0]
	b2 = 0
	for i in range(1, n):
		min1 = min(b1, b2)
		if min1 == b1:
			b1 = b1 + l1[i]
		else:
			b2 = b2 + l1[i]
	print(max(b1, b2))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	c = 0
	i = 0
	if len(a) == 1:
		print(a.pop())
	else:
		while i < n - 1:
			a[i] -= a[i + 1]
			c += a[i + 1]
			del a[i + 1]
			a.sort(reverse=True)
			if a.count(0) == 1 and len(a) == 1:
				print(c)
				break
			elif len(a) == 1 and 0 not in a:
				c += a[i]
				print(c)
				break


for _ in range(int(input())):
	N = int(input())
	L = sorted(list(map(int, input().split())))
	s1 = L[N - 1]
	s2 = L[N - 2]
	i = 0
	j = N - 3
	for _ in range(N - 2):
		if s1 <= s2:
			s1 += L[i]
			i += 1
		else:
			s2 += L[j]
			j -= 1
	print(max(s1, s2))


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	time = [0, 0]
	for j in l:
		if time[0] < time[1]:
			time[0] += j
		else:
			time[1] += j
	print(max(time))


t = int(input())
for i in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	c.sort()
	la = c[n - 1]
	c.pop(n - 1)
	tot = sum(c)
	temp = []
	k = 0
	m = 0
	if tot <= la:
		print(la)
	else:
		temp.append(sum(c))
		for j in range(n - 1):
			k = la + c[j]
			m = sum(c) - c[j]
			temp.append(max(k, m))
		temp.sort()
		print(temp[0])


for k in range(int(input())):
	a = int(input())
	l = reversed(sorted(list(map(int, input().split()))))
	even = 0
	odd = 0
	time = 0
	for i in l:
		if even < odd:
			even += i
		else:
			odd += i
		t = min(even, odd)
		time += t
		even -= t
		odd -= t
	print(time + odd + even)


for i in range(int(input())):
	n = int(input())
	l = sorted(list(map(int, input().split(' '))), reverse=True)
	b1 = b2 = 0
	for num in l:
		if b1 < b2:
			b1 += num
		else:
			b2 += num
	print(max(b1, b2))


t = int(input())
for i in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	c.sort(reverse=True)
	b1 = 0
	b2 = 0
	count = 0
	for i in c:
		if b1 < b2:
			b1 += i
		else:
			b2 += i
		m = min(b1, b2)
		count += m
		b1 -= m
		b2 -= m
	count += b1 + b2
	print(count)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	(x, y) = (0, 0)
	for i in range(n):
		if x >= y:
			y += a[i]
		else:
			x += a[i]
	print(max(x, y))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	(one, two) = (0, 0)
	for i in l:
		if one <= two:
			one += i
		else:
			two += i
	print(max(one, two))


for tc in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	st1 = 0
	st2 = 0
	count = 0
	for ele in arr:
		if st1 < st2:
			st1 = ele
		else:
			st2 = ele
		mine = min(st1, st2)
		count += mine
		st1 -= mine
		st2 -= mine
	count += st1 + st2
	print(count)


for i in range(int(input())):
	n = int(input())
	c = [int(z) for z in input().split()]
	c.sort()
	c.reverse()
	(b1, b2) = (0, 0)
	for i in range(n):
		if b1 < b2:
			b1 += c[i]
		elif b2 < b1:
			b2 += c[i]
		else:
			b1 += c[i]
	print(max(b1, b2))


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	b = c = 0
	for i in a:
		if b < c:
			b += i
		else:
			c += i
	print(max(b, c))


t = int(input())
output = []
for _ in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	c.sort(reverse=True)
	burner1 = 0
	burner2 = 0
	for x in range(n):
		if burner1 < burner2:
			burner1 += c[x]
		else:
			burner2 += c[x]
	output.append(str(max(burner1, burner2)))
print('\n'.join(output))


def get_mini(n, ls):
	ls = sorted(ls)[::-1]
	first_burner = 0
	second_burner = 0
	for i in range(n):
		if first_burner <= second_burner:
			first_burner += ls[i]
		else:
			second_burner += ls[i]
	return max(first_burner, second_burner)
t = int(input())
for _ in range(t):
	n = int(input())
	dish = list(map(int, input().split()))
	ans = get_mini(n, dish)
	print(ans)


for _ in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))[:a]
	b.sort(reverse=True)
	(n1, n2) = (0, 0)
	for i in range(a):
		if n1 < n2:
			n1 += b[i]
		else:
			n2 += b[i]
	print(max(n1, n2))


from math import ceil
t = int(input())
for ni in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	if n == l.count(l[0]):
		print(ceil(n / 2) * l[0])
	elif n == 1 or n == 2:
		print(max(l))
	elif n == 3:
		a = max(l)
		if sum(l) - max(l) <= max(l):
			print(max(l))
		else:
			print(sum(l) - max(l))
	elif n == 4:
		l.sort()
		m = l[-1]
		a = l[1] + l[2]
		if a > m:
			a = a - m
			if a >= l[0]:
				print(m + a)
			else:
				print(m + l[0])
		elif m == a:
			print(a + l[0])
		else:
			a = a + l[0]
			if a <= m:
				print(m)
			else:
				print(a)


for i in range(int(input())):
	t = int(input())
	llist = [int(x) for x in input().split()]
	llist.sort(reverse=True)
	a = 0
	b = 0
	for i in range(len(llist)):
		if a > b:
			b += llist[i]
		else:
			a += llist[i]
	print(max(a, b))


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().strip().split()))
	a.sort(reverse=True)
	c1 = 0
	c2 = 0
	for i in a:
		if c1 < c2:
			c1 = c1 + i
		else:
			c2 = c2 + i
	print(max([c1, c2]))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	a = 0
	b = 0
	for i in l:
		if a < b:
			a += i
		else:
			b += i
	print(max(a, b))


from math import ceil
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if len(set(a)) == 1:
		print((n // 2 + n % 2) * a[0])
	else:
		a.sort(reverse=True)
		s = 0
		r = 0
		for i in range(0, n):
			if r < s:
				r += a[i]
			else:
				s += a[i]
		print(max(r, s))


for i in range(int(input())):
	n = int(input())
	x = sorted(list(map(int, input().split())))[::-1]
	(a, b) = (0, 0)
	for i in range(n):
		if a < b:
			a += x[i]
		else:
			b += x[i]
	print(max(a, b))


try:
	t = int(input())
except:
	t = 0
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	b1 = b2 = 0
	for i in l:
		if b1 < b2:
			b1 += i
		else:
			b2 += i
	print(max(b1, b2))


t = int(input())
while t != 0:
	n = int(input())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	tm = l[0]
	r = l[0]
	for k in range(1, n):
		if r == 0:
			r = l[k]
			tm += l[k]
		elif l[k] <= r:
			r -= l[k]
		else:
			r = l[k] - r
			tm += r
	print(tm)
	t -= 1


a = int(input(''))
for i in range(a):
	n = int(input(''))
	v = [int(x) for x in input('').split()]
	k = list(v)
	k.sort()
	h = k[::-1]
	c1 = []
	c2 = []
	for j in range(n):
		if sum(c1) <= sum(c2):
			c1.append(h[j])
		else:
			c2.append(h[j])
	print(max(sum(c1), sum(c2)))


for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	c.sort(reverse=True)
	times = [0, 0]
	for v in c:
		if times[0] < times[1]:
			times[0] += v
		else:
			times[1] += v
	print(max(times))


t = int(input())
for i in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	c.sort(reverse=True)
	burner1 = burner2 = 0
	for i in range(n):
		if burner1 < burner2:
			burner1 += c[i]
		else:
			burner2 += c[i]
	print(max(burner1, burner2))


for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	lst.sort(reverse=True)
	time = [0, 0]
	for i in lst:
		if time[0] < time[1]:
			time[0] += i
		else:
			time[1] += i
	print(max(time))


for case in range(int(input())):
	input()
	dishes = sorted([int(x) for x in input().split()], reverse=True)
	stove1 = 0
	stove2 = 0
	for dish in dishes:
		if stove2 >= stove1:
			stove1 += dish
		else:
			stove2 += dish
	print(max(stove1, stove2))


for I in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	l = l[::-1]
	c = k = 0
	for i in l:
		if k < c:
			k += i
		else:
			c += i
	if k < c:
		print(c)
	else:
		print(k)


t = int(input())
for i in range(t):
	n = int(input())
	lis = list(map(int, input().split()))
	lis.sort(reverse=True)
	even = 0
	odd = 0
	time = 0
	for i in lis:
		if even <= odd:
			even += i
		else:
			odd += i
		m = min(even, odd)
		time += m
		even -= m
		odd -= m
	print(time + even + odd)


for _ in range(int(input())):
	n = int(input())
	c = sorted(list(map(int, input().split())))
	if len(c) == 1:
		print(c[0])
	elif len(c) == 2:
		print(c[-1])
	else:
		(c1, c2) = (c[-1], c[-2])
		for i in range(n - 3, -1, -1):
			if c1 >= c2:
				c2 += c[i]
			elif c2 > c1:
				c1 += c[i]
		if c1 >= c2:
			print(c1)
		else:
			print(c2)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	l = l[::-1]
	c1 = 0
	c2 = 0
	for i in l:
		if c1 < c2:
			c1 += i
		else:
			c2 += i
	print(max(c1, c2))


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	a1 = 0
	a2 = 0
	a.sort(reverse=True)
	for i in a:
		if a1 < a2:
			a1 += i
		else:
			a2 += i
	print(max(a1, a2))
	t -= 1


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	a = sorted(a)[::-1]
	(x, y) = (0, 0)
	for i in range(n):
		if x >= y:
			y += a[i]
		else:
			x += a[i]
	print(max(x, y))
	t -= 1


def main():
	t = int(input())
	while t:
		n = int(input())
		list1 = list(map(int, input().split()))
		list1.sort(reverse=True)
		b0 = 0
		b1 = 0
		for i in list1:
			if b0 <= b1:
				b0 += i
			else:
				b1 += i
		print(max(b0, b1))
		t = t - 1
main()


ti = int(input())
for i in range(ti):
	n = int(input())
	c = list(map(int, input().split()))
	c.sort(reverse=True)
	b = 0
	b2 = 0
	count = 0
	for i in c:
		if b < b2:
			b += i
		else:
			b2 += i
		m = min(b, b2)
		count += m
		b -= m
		b2 -= m
	count += b + b2
	print(count)


def solve(n, lst):
	if n <= 2:
		print(max(lst))
	else:
		lst.sort()
		res = 0
		while True:
			if len(lst) == 2:
				res += max(lst)
				break
			res += lst[-2]
			lst[-1] -= lst[-2]
			lst.remove(lst[-2])
			lst.sort()
		print(res)
for _ in range(int(input())):
	n = int(input())
	solve(n, list(map(int, input().split())))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr = sorted(arr, reverse=True)
	(one, two) = (0, 0)
	for i in arr:
		if one >= two:
			two += i
		else:
			one += i
	print(max(one, two))


n = int(input())
for i in range(n):
	l = int(input())
	m = list(map(int, input().split()))
	m.sort(reverse=True)
	b1 = 0
	b2 = 0
	for i in m:
		if b1 < b2:
			b1 = b1 + i
		else:
			b2 = b2 + i
	if b1 > b2:
		print(b1)
	else:
		print(b2)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	if n == 1:
		print(a[0])
	elif n == 2:
		print(max(a[0], a[1]))
	else:
		b = a[n - 1]
		c = a[n - 2]
		for i in range(n - 3, -1, -1):
			if c < b:
				c += a[i]
			else:
				b += a[i]
		if c < b:
			print(b)
		else:
			print(c)