Christy is interning at HackerRank. One day she has to distribute some chocolates to her colleagues. She is biased towards her friends and plans to give them more than the others. One of the program managers hears of this and tells her to make sure everyone gets the same number.

To make things difficult, she must equalize the number of chocolates in a series of operations. For each operation, she can give $1,2\:\text{or}\:5$ pieces to all but one colleague.  Everyone who gets a piece in a round receives the same number of pieces.  

Given a starting distribution, calculate the minimum number of operations needed so that every colleague has the same number of pieces.    

Example 

$arr=[1,1,5]$    

$\textbf{arr}$ represents the starting numbers of pieces for each colleague.  She can give $2$ pieces to the first two and the distribution is then $[3,3,5]$.  On the next round, she gives the same two $2$ pieces each, and everyone has the same number:  $[5,5,5]$.  Return the number of rounds, $2$.  

Function Description  

Complete the equal function in the editor below.  

equal has the following parameter(s):  

int arr[n]: the integers to equalize   

Returns   

int: the minimum number of operations required

Input Format

The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of test cases.   

Each test case has $2$ lines. 

- The first line contains an integer $n$, the number of colleagues and the size of $\textbf{arr}$. 

- The second line contains $n$ space-separated integers, $arr\left[i\right]$, the numbers of pieces of chocolate each colleague has at the start.  

Constraints

$1\leq t\leq100$ 

$1\leq n\leq10000$ 

The number of chocolates each colleague has initially < $\textbf{1000}$.  

Sample Input
STDIN       Function
-----       --------
1           t = 1
4           arr[] size n = 4
2 2 3 7     arr =[2, 2, 3, 7]

Sample Output
2

Explanation

Start with $[2,2,3,7]$ 

Add $\mbox{I}$ to all but the $3^{rd}$ element $\rightarrow[3,3,3,8]$ 

Add $5$ to all but the $4^{th}$ element $\rightarrow[8,8,8,8]$  

Two operations were required.

Sample Input 1

1
3
10 7 12

Sample Output 1

3

Explanation 1

Start with $[10,7,12]$ 

Add $5$ to the first two elements $\rightarrow[15,12,12]$ 

Add $2$ to the last two elements $\rightarrow[15,14,14]$ 

Add $1$ to the last two elements $\rightarrow[15,15,15]$  

Three operations were required.

Difficulty: MEDIUM
Tags: Dynamic programming
Skill types: Dynamic programming

Starter code:

Solutions:
def steps(number):
	remainder = [0, 1, 1, 2, 2]
	return number // 5 + remainder[number % 5]
T = int(input())
for loop in range(T):
	N = int(input())
	if N == 0:
		input()
		print(0)
		continue
	distribution = list(map(int, input().split()))
	distribution.sort()
	minimum = distribution[0]
	totalsteps = [0, 1, 1, 2, 2]
	for i in range(5):
		for element in distribution[1:]:
			totalsteps[i] += steps(element - minimum + i)
	print(min(totalsteps))


c = int(input())

def move(a):
	(q5, r5) = (a // 5, a % 5)
	(q2, r2) = (r5 // 2, r5 % 2)
	return q5 + q2 + r2
for i in range(c):
	n = int(input())
	if n == 0:
		input()
		print(0)
		continue
	interns = [int(i) for i in input().strip().split()]
	m = min(interns)
	pos = []
	for j in range(5):
		extra = [move(k - (m - j)) for k in interns]
		pos.append(sum(extra))
	print(min(pos))


def solve(A):
	if len(A) <= 1:
		return 0
	m = min(A)
	mc = []
	for i in range(5):
		count = 0
		for a in A:
			d = a - m + i
			(c5, r5) = divmod(d, 5)
			(c2, c1) = divmod(r5, 2)
			count += c5 + c2 + c1
		mc.append(count)
	return min(mc)
T = int(input())
for _ in range(T):
	N = int(input())
	A = [int(_) for _ in input().split()]
	print(solve(A))


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	count = [0, 1, 1, 2, 2]
	for i in range(1, n):
		for j in range(5):
			d = a[i] - a[0] + j
			count[j] += d // 5
			d %= 5
			count[j] += d // 2
			d %= 2
			count[j] += d
	print(min(count))


def condense(coworkers):
	least = min(coworkers)
	coworkers = [worker - least for worker in coworkers]
	overhead = sum((worker // 5 for worker in coworkers))
	counts = [0] * 5
	for coworker in coworkers:
		counts[coworker % 5] += 1
	return (overhead, counts)

def solve_case(coworkers):
	(overhead, counts) = condense(coworkers)
	return overhead + min(raw_cost(counts), one_plus_cost(counts), two_plus_cost(counts))

def one_plus_cost(counts):
	new_counts = [counts[(i - 1) % 5] for i in range(5)]
	overhead = counts[4]
	return overhead + raw_cost(new_counts)

def two_plus_cost(counts):
	new_counts = [counts[(i - 2) % 5] for i in range(5)]
	overhead = counts[3] + counts[4]
	return overhead + raw_cost(new_counts)

def raw_cost(counts):
	return counts[1] + counts[2] + 2 * counts[3] + 2 * counts[4]

def read_case():
	N = int(input())
	coworkers = list(map(int, input().split()))
	return coworkers
num_cases = int(input())
for i in range(num_cases):
	case = read_case()
	output = solve_case(case)
	print(output)


_MAX_VALUE = 10000000000
_MAX_OP = 5

def min_op(chocos):
	min_choco = min(chocos)
	min_op = _MAX_VALUE
	for i in range(_MAX_OP + 1):
		c = 0
		for choco in chocos:
			v = choco - (min_choco - i)
			op1 = v // 5
			op2 = v % 5 // 2
			op3 = v % 5 & 1
			c += op1 + op2 + op3
		min_op = min(min_op, c)
	return min_op
n = int(input())
for _ in range(n):
	input()
	candies = [int(el) for el in input().split()]
	print(min_op(candies))


for case in range(int(input())):
	N = int(input())
	arr = list(map(int, input().rstrip().split()))

	def red(target):
		ans = 0
		for i in arr:
			d = i - target
			if d >= 5:
				ans += d // 5
				d %= 5
			if d >= 2:
				ans += d // 2
				d %= 2
			ans += d
		return ans
	mi = min(arr)
	print(min(red(mi), red(mi - 1), red(mi - 2)))


def main():
	for _ in range(int(input())):
		N = int(input())
		A = [int(x) for x in input().split()]
		minimum = min(A)
		choices = [0, 1, 2, 5]
		operations = [0, 0, 0, 0]
		for num in A:
			for x in range(4):
				temp = abs(num - minimum + choices[x])
				operations[x] += temp // 5
				temp %= 5
				operations[x] += temp // 2
				operations[x] += temp % 2
		print(min(operations))
main()


def operations(N, A):
	M = min(A)
	O = []
	for m in range(M - 4, M + 1):
		C = 0
		for i in range(N):
			T = A[i] - m
			C += T // 5 + T % 5 // 2 + T % 5 % 2
		O.append(C)
	return min(O)

def main():
	T = int(input())
	for _ in range(T):
		N = int(input())
		A = [int(i) for i in input().split()]
		print(operations(N, A))
main()


class Solution(object):

	def __init__(self):
		self.dp = [0, 1, 1, 2, 2, 1]

	def distribute(self, a):
		min_n = min(a)
		max_n = max(a)
		gap = max_n - min_n
		l = len(self.dp)
		if gap + 5 >= l:
			for i in range(l, gap + 5):
				self.dp.append(min(self.dp[i - 1], self.dp[i - 2], self.dp[i - 5]) + 1)
		return min((sum([self.dp[x - min_n + i] for x in a]) for i in range(5)))
sol = Solution()
cases = int(input())
for i in range(cases):
	lenghth = input()
	a = list(map(int, input().split()))
	print(sol.distribute(a))


selection = [1, 2, 5, 0]
num_of_test = int(input().strip())
for i in range(0, num_of_test):
	num_of_item = int(input().strip())
	items = input().strip().split(' ')
	minimum = int(items[0])
	for i in items:
		minimum = min(minimum, int(i))
	c = 0
	for j in selection:
		t_m = minimum - j
		t_c = 0
		for i in items:
			i = int(i)
			t_c += int((i - t_m) / 5)
			if (i - t_m) % 5 != 0:
				if (i - t_m) % 5 <= 2:
					t_c += 1
				else:
					t_c += 2
		if c == 0:
			c = t_c
		c = min(c, t_c)
	print(c)


def numGreedySteps(a):
	return int(a / 5) + int(a % 5 / 2) + a % 5 % 2
T = int(input())
for i in range(0, T):
	N = int(input())
	inp = [int(x) for x in input().split()]
	mini = min(inp)
	diff0 = [x - mini for x in inp]
	diff1 = [x + 1 for x in diff0]
	diff2 = [x + 2 for x in diff0]
	res = min([sum([numGreedySteps(x) for x in diff0]), sum([numGreedySteps(x) for x in diff1]), sum([numGreedySteps(x) for x in diff2])])
	print(res)


def main():
	ncases = int(input())
	for _ in range(ncases):
		n = int(input())
		lst = [int(fld) for fld in input().split()]
		assert n == len(lst)
		print(solve(lst))

def solve(lst):
	least = min(lst)
	loser = lst.index(least)
	ans = nosubloser(lst)
	for subloser in range(1, 5):
		lst[loser] -= 1
		ans = min(ans, nosubloser(lst) + subloser // 3 + 1)
	return ans

def nosubloser(lst):
	least = min(lst)
	lst = [elt - least for elt in lst]
	return sum((elt // 5 + (elt % 5 + 1) // 2 for elt in lst))
main()


import math
lastSteps = [0, 1, 1, 2, 2, 1, 2]
for n in range(int(input())):
	input()
	numbers = sorted(map(int, input().split()))
	base = numbers[0]
	steps = 0
	for i in range(len(numbers) - 1, 0, -1):
		diff = numbers[i] - base
		fives = math.floor(diff / 5)
		steps += fives
		numbers[i] -= fives * 5
	numbers.sort()
	steps = [steps, steps + 1, steps + 1]
	for i in range(len(numbers) - 1, 0, -1):
		diff = numbers[i] - base
		steps[0] += lastSteps[diff]
		steps[1] += lastSteps[diff + 1]
		steps[2] += lastSteps[diff + 2]
	print(min(steps))


from sys import stdin
import heapq

def operations(x):
	val = 0
	val += x // 5
	x %= 5
	val += x // 2
	x %= 2
	val += x // 1
	x %= 1
	return val

def findIt(lis):
	sumi = []
	mini = min(lis)
	for j in range(6):
		sumi.append(0)
		for i in range(len(lis)):
			temp = abs(lis[i] - (mini - j))
			sumi[j] += operations(temp)
	return min(sumi)

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		lis = list(map(int, input().split()))
		print(findIt(lis))
main()


def step(current, desired):
	left = current - desired
	five = int(left / 5)
	left -= five * 5
	two = int(left / 2)
	left -= two * 2
	return five + two + left
nTests = int(input())
for i in range(nTests):
	n = input()
	if n == 0:
		print(0)
		continue
	arr = list(map(int, input().split()))
	m = min(arr)
	arr = list(map(lambda x: x - m, arr))
	arr0 = sum(map(lambda x: step(x, 0), arr))
	arr1 = sum(map(lambda x: step(x, -1), arr))
	arr2 = sum(map(lambda x: step(x, -2), arr))
	arr3 = sum(map(lambda x: step(x, -3), arr))
	arr4 = sum(map(lambda x: step(x, -4), arr))
	print(min(arr0, arr1, arr2, arr3, arr4))


T = int(input())
for t in range(T):
	N = int(input())
	C = [int(i) for i in input().split()]
	m = max(C)
	A = []
	for c in C:
		A.append(m - c)
	result = 999999999999999
	for s in range(max(A), max(A) + 5):
		count = 0
		for a in A:
			r = s - a
			count += int(r / 5)
			r %= 5
			count += int(r / 2)
			r %= 2
			count += r
		result = min(count, result)
	print(result)


def fun(t):
	x = 0
	if t >= 5:
		x = t // 5
		t %= 5
	if t >= 2:
		x += t // 2
		t %= 2
	x += t
	return x
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	u = min(a)
	s = [0] * 10
	for j in range(0, 6):
		s[j] = 0
		for i in range(n):
			t = abs(a[i] - (u - j))
			s[j] += fun(t)
	print(min(s[0:6]))


for _ in range(int(input())):
	n = int(input())
	A = [int(i) for i in input().strip().split()]
	k = min(A)
	for i in range(n):
		A[i] -= k
	ops = sum([a // 5 + a % 5 // 2 + a % 5 % 2 for a in A])
	for i in range(1, 5):
		operations = sum([(a + i) // 5 + (a + i) % 5 // 2 + (a + i) % 5 % 2 for a in A])
		ops = min(ops, operations)
	print(ops)


def subsolve(A, lower_bound):
	ret = 0
	for a in A:
		ret += (a - lower_bound) // 5
		rem5 = (a - lower_bound) % 5
		if rem5 > 0:
			ret += rem5 // 2
			rem2 = rem5 % 2
			if rem2 > 0:
				ret += rem2 // 1
	return ret

def solve(A):
	ret = sum(A)
	minimum = min(A)
	for i in range(minimum, minimum - 5, -1):
		ret = min(ret, subsolve(A, i))
	return ret
T = int(input())
for _ in range(T):
	N = int(input())
	A = [int(x) + 5 for x in input().strip().split()]
	print(solve(A))


t = int(input().strip())
for i_t in range(t):
	n = int(input().strip())
	counts = [int(i) for i in input().strip().split(' ')]
	mincount = min(counts)
	counts = [i - mincount for i in counts]
	minops = n * max(counts)
	for i_bar in range(5):
		count_bar = [i + i_bar for i in counts]
		min_candidate = 0
		for j in range(n):
			min_candidate += count_bar[j] // 5
			count_bar[j] = count_bar[j] % 5
			min_candidate += count_bar[j] // 2
			count_bar[j] = count_bar[j] % 2
			min_candidate += count_bar[j]
		if min_candidate < minops:
			minops = min_candidate
	print(minops)


def operation(l):
	if l == 0:
		return 0
	else:
		a = l // 5
		b = l % 5 // 2
		c = l % 5 % 2
		return a + b + c
t = int(input())
for i in range(t):
	n = int(input())
	ar = input().split()
	ar = [int(e) for e in ar]
	ar.sort()
	m_1 = 0
	l = 1
	while l < n:
		m_1 += operation(ar[l] - ar[0])
		l += 1
	l = 1
	m_2 = 1
	while l < n:
		m_2 += operation(ar[l] - (ar[0] - 1))
		l += 1
	l = 1
	m_3 = 1
	while l < n:
		m_3 += operation(ar[l] - ar[0] + 2)
		l += 1
	l = 1
	m_4 = 1
	while l < n:
		m_4 += operation(ar[l] - ar[0] + 5)
		l += 1
	m = min(m_1, m_2, m_3, m_4)
	print(m)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	ans = []
	for i in range(5):
		m = min(a) - i
		s = 0
		for j in range(n):
			c = a[j] - m
			s += c // 5 + c % 5 // 2 + c % 5 % 2
		ans.append(s)
	print(min(ans))


T = int(input())
for t in range(T):
	N = int(input())
	counts = sorted(map(int, input().split()))
	fives = [(count - counts[0]) // 5 for count in counts]
	nc = [count - counts[0] - 5 * five for (count, five) in zip(counts, fives)]
	req = (0, 1, 1, 2, 2)
	req1s = (1, 1, 2, 2, 1)
	req2s = (1, 2, 2, 1, 2)
	oc0 = sum([req[c] for c in nc])
	oc1 = sum([req1s[c] for c in nc])
	oc2 = sum([req2s[c] for c in nc])
	fin = min(oc0, oc1, oc2)
	print(sum(fives) + fin)


def dist(f, t):
	d5 = divmod(t - f, 5)
	d2 = divmod(d5[1], 2)
	return d5[0] + d2[0] + d2[1]

def solve(a):
	a.sort()
	n = 0
	for x in a:
		n += dist(a[0], x)
	return n
t = int(input())
for i in range(0, t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	s = []
	s.append(solve(a))
	a[0] -= 1
	s.append(solve(a) + 1)
	a[0] -= 1
	s.append(solve(a) + 1)
	print(min(s))


t = int(input())

def countToSolve(n):
	count = n // 5
	n = n % 5
	count += n // 2
	n = n % 2
	count += n
	return count
for _ in range(t):
	n = int(input())
	c = [int(x) for x in input().strip().split()]
	counts = []
	mini = min(c)
	for v in (0, 1, 2, 3, 4):
		counts.append(sum((countToSolve(x - mini + v) for x in c)))
	print(min(counts))


def optimize_ops(difference):
	max_five_coins = difference // 5
	difference = difference - 5 * max_five_coins
	max_two_coins = difference // 2
	difference = difference - 2 * max_two_coins
	return max_five_coins + max_two_coins + difference

def differences(C, bias=0):
	minimum = min(C) - bias
	return [c - minimum for c in C]
T = int(input())
for i in range(T):
	N = int(input())
	if N > 0:
		C = [int(x) for x in input().split(' ')]
		diffs = [differences(C, bias) for bias in [0, 1, 2, 5]]
		solution = min((sum((optimize_ops(x) for x in diff)) for diff in diffs))
		print(solution)
	else:
		print(0)


t = int(input())
num = [202 for i in range(1005)]
coins = [1, 2, 5]
num[0] = 0
for coin in coins:
	for i in range(coin, 1005):
		num[i] = min(num[i], num[i - coin] + 1)
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	m = min(l)
	ans = [0, 0, 0, 0, 0]
	for i in range(5):
		for j in range(n):
			ans[i] += num[l[j] - (m - i)]
	print(min(ans))


import unittest

class ChocolatesEqualizer:

	def __init__(self, values):
		self.values = sorted(values)
		self.count = 0

	def equalize(self):
		for i in range(0, len(self.values) - 1):
			(curr, next) = (self.values[i], self.values[i + 1])
			while curr != next:
				incr = self._get_increment(curr, next)
				self._add_to_all_but(i + 1, incr)
				(curr, next) = (self.values[i], self.values[i + 1])
		return self.count

	def _get_increment(self, curr, next):
		diff = next - curr
		if diff >= 5:
			return 5
		elif diff >= 2:
			return 2
		return 1

	def _add_to_all_but(self, i, incr):
		self.values = [val + incr for val in self.values]
		self.values[i] -= incr
		self.count += 1

class ChocolatesEqualizer2:

	def __init__(self, values):
		self.values = sorted(values)
		self.min = min(values)

	def num_operations_for_value(self, value, min_val):
		num_operations = 0
		diff = value - min_val
		if diff >= 5:
			num_operations += diff // 5
			diff %= 5
		if diff >= 2:
			num_operations += diff // 2
			diff %= 2
		num_operations += diff % 2
		return num_operations

	def equalize(self):
		min_count = float('inf')
		for i in range(0, 5):
			min_val = self.min - i
			count = 0
			for val in self.values:
				count += self.num_operations_for_value(val, min_val)
			if count < min_count:
				min_count = count
		return min_count

class ChocolatesEqualizerTest(unittest.TestCase):

	def test1(self):
		equalizer = ChocolatesEqualizer2(values=[7, 1, 8])
		self.assertEquals(equalizer.equalize(), 4)

	def test2(self):
		equalizer = ChocolatesEqualizer2(values=[2, 7, 4, 1])
		self.assertEquals(equalizer.equalize(), 5)

	def test3(self):
		equalizer = ChocolatesEqualizer2(values=[1, 5, 5])
		self.assertEquals(equalizer.equalize(), 3)

	def test4(self):
		equalizer = ChocolatesEqualizer2(values=[2, 5, 5, 5, 5, 5])
		self.assertEquals(equalizer.equalize(), 6)

def test_run():
	equalizer = ChocolatesEqualizer2(values=[2, 5, 5, 5, 5, 5])
	count = equalizer.equalize()
	print('VALUES:', equalizer.values)
	print('COUNT:', count)

def run_tests():
	suite = unittest.TestLoader().loadTestsFromTestCase(ChocolatesEqualizerTest)
	unittest.TextTestRunner(verbosity=2).run(suite)

def run():
	num_tests = int(input())
	for _ in range(num_tests):
		_ = input()
		values = input()
		values = [int(x) for x in values.split(' ')]
		equalizer = ChocolatesEqualizer2(values=values)
		print(equalizer.equalize())
run()


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	minval = arr[0]
	mincount = 9999999999
	(op, val) = (0, 0)
	for i in range(6):
		op = 0
		for j in range(n):
			(five, two, one) = (0, 0, 0)
			diff = arr[j] - (minval - i)
			if diff % 5 == 0:
				five = diff // 5
			else:
				five = diff // 5
				temp = diff % 5
				if temp % 2 == 0:
					two = temp // 2
				else:
					two = temp // 2
					one = temp % 2
			op += five + two + one
		if op < mincount:
			mincount = op
	print(mincount)


inf = 2 ** 30

def f(x):
	r = 0
	if x >= 5:
		r = r + x // 5
		x = x % 5
	if x >= 2:
		r = r + x // 2
		x = x % 2
	r = r + x
	return r
T = int(input())
while T > 0:
	T = T - 1
	ans = inf
	n = int(input())
	a = list(map(int, input().split()))
	mn = inf
	for x in a:
		if x < mn:
			mn = x
	for j in range(5):
		r = 0
		for x in a:
			r = r + f(x - (mn - j))
		ans = min(ans, r)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	steps = 0
	steps_one_off = 1
	steps_two_off = 1
	(x, *rest) = sorted(map(int, input().split()))
	for y in rest:
		diff = y - x
		(fives, diff) = divmod(diff, 5)
		step_matrix = ((0, 1, 1), (1, 1, 2), (1, 2, 2), (2, 2, 1), (2, 1, 2))
		diff_costs = step_matrix[diff]
		steps += fives + diff_costs[0]
		steps_one_off += fives + diff_costs[1]
		steps_two_off += fives + diff_costs[2]
	print(min(steps, steps_one_off, steps_two_off))


from operator import itemgetter

def chocolates(chocoList):
	(minIdx, origMin) = min(enumerate(chocoList), key=itemgetter(1))
	opsToReduceBy = {0: 0, 1: 1, 2: 1, 3: 2, 4: 2}
	minOps = float('inf')
	for i in range(5):
		minimum = origMin - i
		differences = [chocolates - minimum for chocolates in chocoList]
		ops = sum((i // 5 + i % 5 // 2 + i % 5 % 2 for i in differences)) + opsToReduceBy[i]
		minOps = min(minOps, ops)
		chocoList[minIdx] -= 1
	return minOps
T = int(input())
for testCases in range(T):
	N = int(input())
	chocoList = [int(i) for i in input().split()]
	print(chocolates(chocoList))


T = int(input())
for t0 in range(T):
	N = int(input())
	choc = [int(i) for i in input().split()]
	best = 100000000
	temp = min(choc)
	for target in [temp - 2, temp - 1, temp]:
		operations = 0
		for i in range(N):
			remainder = choc[i] - target
			n5 = remainder // 5
			remainder -= n5 * 5
			n2 = remainder // 2
			remainder -= n2 * 2
			operations += n5 + n2 + remainder
		if operations < best:
			best = operations
	print(best)


sols = [0, 1, 1, 2, 2, 1]
cases = int(input())

def getAnswer(num):
	return sols[num]

def getMinDistributions(minIntern, cointerns):
	total = 0
	for i in cointerns:
		i -= minIntern
		total += int(i / 5)
		total += getAnswer(i % 5)
	return total
for case in range(cases):
	interns = int(input())
	cointerns = [int(i) for i in input().split()]
	minIntern = min(cointerns)
	print(min((getMinDistributions(minIntern - i, cointerns) for i in range(5))))


sols = [0, 1, 1, 2, 2, 1]
cases = int(input())

def getAnswer(num):
	return sols[num]

def getMinDistributions(minIntern, cointerns):
	total = 0
	for i in cointerns:
		i -= minIntern
		total += int(i / 5)
		total += getAnswer(i % 5)
	return total
for case in range(cases):
	interns = int(input())
	cointerns = [int(i) for i in input().split()]
	minIntern = min(cointerns)
	print(min((getMinDistributions(minIntern - i, cointerns) for i in range(5))))


def reduce_to_zero(n):
	steps = 0
	if n >= 5:
		steps += n // 5
		n = n % 5
	if n >= 2:
		steps += n // 2
		n = n % 2
	if n > 0:
		steps += n
	return steps
n_cases = int(input())
for case in range(n_cases):
	n_interns = int(input())
	vals = list(map(int, input().split()))
	min_val = min(vals)
	current_min = float('Inf')
	for i in range(6):
		temp = 0
		for val in vals:
			temp += reduce_to_zero(val - min_val + i)
		if temp < current_min:
			current_min = temp
	print(current_min)


def one_two_five(diff):
	if diff == 0:
		return 0
	else:
		n = int(diff / 5)
		r = 0
		if diff % 5 == 4 or diff % 5 == 3:
			r = 2
		elif diff % 5 == 2 or diff % 5 == 1:
			r = 1
		return n + r
test = int(input())
for _ in range(test):
	n = int(input())
	ar = list(map(int, input().strip().split()))
	min_ar = min(ar)
	result = []
	for i in range(5):
		ans = 0
		for x in ar:
			ans += one_two_five(x - min_ar + i)
		result += [ans]
	print(min(result))


for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	min_c = min(c)
	max_c = max(c) - min_c
	ret = 1000000000.0
	for i in [0, 1, 2, 5]:
		t = [c[j] - min_c + i for j in range(n)]
		dp = [1000000000.0 for _ in range(max_c + i + 1)]
		dp[0] = 0
		for i in range(1, max_c + i + 1):
			min_t = 1000000000.0
			if i - 1 >= 0:
				min_t = min(min_t, dp[i - 1] + 1)
			if i - 2 >= 0:
				min_t = min(min_t, dp[i - 2] + 1)
			if i - 5 >= 0:
				min_t = min(min_t, dp[i - 5] + 1)
			dp[i] = min_t
		ret = min(ret, sum((dp[v] for v in t)))
	print(ret)


def redu(n):
	ans = [0] * n
	ans[1] = ans[2] = ans[5] = 1
	for i in range(1, n):
		for j in [i + 1, i + 2, i + 5]:
			if j < n:
				if ans[j] == 0:
					ans[j] = ans[i] + 1
				else:
					ans[j] = min(ans[j], ans[i] + 1)
	return ans
red = redu(1010)
for _ in range(int(input())):
	input()
	arr = [int(x) for x in input().split()]
	m = min(arr)
	arr = [x - m for x in arr]
	ma = sum([red[x] for x in arr])
	for i in [1, 2, 5]:
		ma = min(ma, sum([red[x + i] for x in arr]))
	print(ma)


import sys

def equalize(min):
	res = 0
	for a in X:
		temp = a - min
		res += int(temp / 5) + int(temp % 5 / 2) + temp % 5 % 2
	return res
T = int(input())
while T > 0:
	T -= 1
	N = int(input())
	X = [int(x) for x in input().strip().split(' ')]
	minArr = sys.maxsize
	for x in X:
		if x < minArr:
			minArr = x
	ans = sys.maxsize
	for y in range(0, 5):
		ans = min(ans, equalize(minArr - y))
	print(ans)


t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	candies = [int(temp) for temp in input().strip().split(' ')]
	min_idx = 0
	for i in range(1, n):
		min_idx = i if candies[i] < candies[min_idx] else min_idx
	min_ops = None
	for j in range(5):
		min_val = candies[min_idx] - j
		ops = 0
		for i in range(n):
			ops += (candies[i] - min_val) // 5
			ops += (candies[i] - min_val) % 5 // 2
			ops += (candies[i] - min_val) % 5 % 2
		if min_ops == None:
			min_ops = ops
		else:
			min_ops = min(ops, min_ops)
	print(min_ops)


def min_day(candy):
	m = min(candy)
	for i in range(len(candy)):
		candy[i] -= m
	return min(cal_step(candy, 0), cal_step(candy, 1), cal_step(candy, 2))

def cal_step(candy, offset):
	step = 0
	for c in candy:
		c += offset
		step += int(c / 5)
		c -= 5 * int(c / 5)
		step += int(c / 2)
		c -= 2 * int(c / 2)
		step += c
	return step

def main():
	total_cases = int(input())
	for c in range(total_cases):
		num_members = int(input())
		temp = input().split(' ')
		candy = []
		for a in temp:
			candy.append(int(a))
		print(min_day(candy))
main()


import sys

def num_ops(val, min):
	diff = abs(val - min)
	return int(diff // 5 + diff % 5 // 2 + diff % 5 % 2)
num_tests = int(sys.stdin.readline())
for i in range(num_tests):
	_n = int(sys.stdin.readline())
	nums = [int(n) for n in sys.stdin.readline().split(' ')]
	possible = [0] * 5
	val_min = min(nums)
	for j in range(5):
		cur_min = val_min - j
		for n in nums:
			possible[j] = possible[j] + num_ops(n, cur_min)
	print(min(possible))


def attempt(m):
	return sum([n // 5 + n % 5 // 2 + n % 5 % 2 for n in [x - m for x in list]])
for _ in range(int(input())):
	input()
	list = [int(x) for x in input().split(' ')]
	minimum = min(list)
	ans = min(attempt(minimum), attempt(minimum - 1), attempt(minimum - 2))
	print(ans)


def calc(ar, i):
	return sum([(j - i) // 5 + (j - i) % 5 // 2 + (j - i) % 5 % 2 for j in ar])
T = int(input())
for i in range(T):
	n = int(input())
	ar = [int(j) for j in input().split()]
	m = min(ar)
	res = min([calc(ar, m - x) for x in range(0, 5)])
	print(res)


def find_operation(sum):
	if sum == 0:
		return 0
	else:
		return sum // 5 + sum % 5 // 2 + sum % 5 % 2
t = int(input())
for i in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	m = min(ar)
	ans1 = 0
	ans2 = 0
	ans3 = 0
	ans4 = 0
	ans5 = 0
	for j in range(n):
		ar[j] -= m
	for j in range(n):
		ans1 += find_operation(ar[j])
	for j in range(n):
		ans2 += find_operation(ar[j] + 1)
	for j in range(n):
		ans3 += find_operation(ar[j] + 2)
	for j in range(n):
		ans4 += find_operation(ar[j] + 3)
	for j in range(n):
		ans5 += find_operation(ar[j] + 4)
	print(min(ans1, ans2, ans3, ans4, ans5))


def V(t):
	N = int(input())
	I = list(map(int, input().split()))
	m = min(I)
	I = list(map(lambda x: x - m, I))
	temps = 0
	for i in I:
		temps += i // 5
	K = list(map(lambda x: x % 5, I))
	cc = K.count
	n4 = cc(4)
	n3 = cc(3)
	n2 = cc(2)
	n1 = cc(1)
	n0 = cc(0)
	temps += min(2 * n4 + 2 * n3 + 1 * n2 + 1 * n1 + 0 * n0, 1 * n4 + 2 * n3 + 2 * n2 + 1 * n1 + 1 * n0, 2 * n4 + 1 * n3 + 2 * n2 + 2 * n1 + 1 * n0, 2 * n4 + 2 * n3 + 1 * n2 + 2 * n1 + 2 * n0, 3 * n4 + 2 * n3 + 2 * n2 + 1 * n1 + 2 * n0)
	return temps
M = [V(x) for x in range(int(input()))]
for m in M:
	print(m)


def getWays(k):
	ways = [0 for x in range(k + 1)]
	for i in range(k + 1):
		if i == 0:
			ways[i] = 0
		else:
			n = i
			count = 0
			if n >= 5:
				count += n // 5
				n = n % 5
			if n >= 2:
				count += n // 2
				n = n % 2
			if n == 1:
				count += 1
			ways[i] = count
	return ways

def findWays(data, minVal, ways, k):
	ans = 0
	for i in range(len(data)):
		if data[i] == minVal:
			ans += 0
		else:
			ans += ways[data[i] - minVal]
	return ans
cases = int(input())
for i in range(cases):
	n = int(input())
	data = list(map(int, input().split(' ')))
	data = sorted(data)
	ways = getWays(data[n - 1] + 5)
	minWays = findWays(data, data[0], ways, 0)
	for i in range(1, 5):
		nWay = findWays(data, data[0] - i, ways, 0)
		if nWay < minWays:
			minWays = nWay
	print(minWays)


def calc(temp):
	x = 0
	if temp >= 5:
		x = int(temp / 5)
		temp = temp % 5
	if temp >= 2:
		x += int(temp / 2)
		temp = temp % 2
	x += temp
	return x
t = int(input())
while t:
	t -= 1
	n = int(input())
	l = [int(x) for x in input().split()]
	m = min(l)
	s = []
	(i, j) = (0, 0)
	for i in range(0, 6):
		s.append(0)
		for j in range(0, n):
			temp = abs(l[j] - m + i)
			s[i] = s[i] + calc(temp)
	print(int(min(s)))


def calc(diff):
	operations = 0
	diff5 = diff // 5
	if diff5 > 0:
		diff %= 5
		operations += diff5
	diff2 = diff // 2
	if diff2 > 0:
		diff %= 2
		operations += diff2
	operations += diff
	return operations

def equal(arr):
	smallest = min(arr)
	answer = float('inf')
	for i in range(3):
		operations = 0
		for num in arr:
			diff = num - (smallest - i)
			operations += calc(diff)
		if operations < answer:
			answer = operations
	print(answer)
n = int(input())
for i in range(n):
	input()
	equal([int(x) for x in input().split(' ')])


import sys
testCases = int(input())
for i in range(testCases):
	n = int(input())
	chocs = [int(x) for x in input().split()]
	if n < 2:
		print('0')
		continue
	mini = min(chocs)
	minCount = sys.maxsize
	for i in range(6):
		count = 0
		for j in range(n):
			v = chocs[j] - (mini - i)
			count += v // 5
			v %= 5
			count += v // 2 + (v & 1)
		if count < minCount:
			minCount = count
	print(minCount)


class Solution:

	def __init__(self, n, arr):
		self.n = n
		self.arr = arr
		self.min_el = min(arr)

	def solution(self):
		possible = []
		for i in range(4):
			possible.append(self.total_operations(i))
		return min(possible)

	def total_operations(self, i):
		reduce_to = self.min_el - i
		retval = 0
		for num in arr:
			retval += self.count_moves(num, reduce_to)
		return retval

	def count_moves(self, num, reduce_to):
		diff = num - reduce_to
		n5 = diff // 5
		n2 = (diff - 5 * n5) // 2
		n1 = diff - 5 * n5 - 2 * n2
		return n5 + n2 + n1
q = int(input())
for i in range(q):
	n = int(input())
	arr = [int(i) for i in input().split(' ')]
	print(Solution(n, arr).solution())


def n_red(n):
	result = n // 5
	rem = n % 5
	result += rem // 2
	rem = rem % 2
	return result + rem
rep = int(input())
for i in range(rep):
	_ = input()
	a = list(map(int, input().split(' ')))
	m = min(a)
	result = float('inf')
	for mi in range(m - 4, m + 1):
		temp_result = 0
		for i in a:
			temp_result += n_red(i - mi)
		result = min(result, temp_result)
	print(result)


from math import floor
t = int(input().strip())

def fun(a, b):
	dif = a - b
	s = floor(dif / 5)
	dif = dif % 5
	s += floor(dif / 2)
	dif = dif % 2
	s += dif
	return s
while t > 0:
	n = int(input().strip())
	arr = [int(x) for x in input().strip().split(' ')]
	me = min(arr)
	dp = [[0 for i in range(n)] for j in range(5)]
	for j in range(5):
		for i in range(n):
			dp[j][i] = fun(arr[i], me - j)
	ans = 1000000000
	for j in range(5):
		s = sum(dp[j])
		ans = min(ans, s)
	print(ans)
	t += -1


T = int(input())
for _ in range(T):
	_ = input()
	choc_counts = [int(i) for i in input().strip().split()]
	min_choc = min(choc_counts)
	diffs = []
	for i in [min_choc, min_choc - 1, min_choc - 2]:
		diffs.append(sum([(x - i) // 5 + (x - i) % 5 // 2 + (x - i) % 5 % 2 if x - i > 0 else 0 for x in choc_counts]))
	print(min(diffs))


N = int(input())
memo = {0: 0}

def min_steps(n):
	if n < 0:
		return 9999999
	if memo.get(n) is None:
		memo[n] = min([min_steps(n - 1), min_steps(n - 2), min_steps(n - 5)]) + 1
	return memo[n]
for n in range(1000):
	min_steps(n)
for _ in range(N):
	n = int(input())
	a = [int(i) for i in input().split()]
	min_a = min(a)
	steps = 0
	for i in a:
		steps += min_steps(i - min_a)
	steps
	min_a -= 1
	newsteps = 0
	for i in a:
		newsteps += min_steps(i - min_a)
	if newsteps < steps:
		steps = newsteps
	min_a -= 1
	newsteps = 0
	for i in a:
		newsteps += min_steps(i - min_a)
	if newsteps < steps:
		steps = newsteps
	print(steps)


from collections import defaultdict

def solution(c):
	min_v = min(c)
	val_cnt = defaultdict(int)
	for val in c:
		val_cnt[val] += 1
	res = []
	for m in [min_v, min_v - 1, min_v - 2]:
		res.append(0)
		for val in val_cnt:
			v = val - m
			res[-1] += val_cnt[val] * (v // 5 + v % 5 // 2 + v % 5 % 2)
	return min(res)
T = int(input())
for _ in range(T):
	n = int(input())
	c = list(map(int, input().split()))
	print(solution(c))


def p(n):
	k = n // 5
	s = n % 5
	return k + [0, 1, 1, 2, 2][s]
for _ in range(int(input())):
	input()
	A = list(map(int, input().split()))
	mi = min(A)
	s1 = sum((p(a - mi) for a in A))
	s2 = sum((p(a - mi + 1) for a in A))
	s3 = sum((p(a - mi + 2) for a in A))
	print(min([s1, s2, s3]))


def minimize(a):
	m = min(a)
	return list(map(lambda x: x - m, a))

def cost(a, b):
	d = a - b
	(ans, d) = (d // 5, d % 5)
	(ans, d) = (ans + d // 2, d % 2)
	return ans + d

def solve_for(a, b):
	return sum([cost(x, b) for x in a])

def solve(a):
	a = minimize(a)
	return min([solve_for(a, b) for b in (-5, -4, -3, -2, -1, 0)])
for _ in range(int(input())):
	n = int(input())
	a = map(int, input().split())
	print(solve(list(a)))


def steps(n):
	ret = n // 5
	t = n % 5
	if t == 0:
		return ret
	if t == 1 or t == 2:
		return ret + 1
	if t == 3 or t == 4:
		return ret + 2

def dist(m, ar):
	return sum((steps(it - m) for it in ar))

def solve():
	input()
	ar = [int(it) for it in input().strip().split()]
	m = min((it for it in ar))
	return min((dist(m - it, ar) for it in range(5)))
for it in range(int(input())):
	print(solve())


t = int(input())
for x in range(t):
	n = int(input())
	c = input().strip().split(' ')
	c = [int(x) for x in c]
	answer = [0, 0, 0]
	tminimum = min(c)
	for j in range(0, 3):
		minimum = tminimum - j
		for i in range(len(c)):
			diff = abs(c[i] - minimum)
			if diff >= 5:
				answer[j] += diff // 5
				diff = diff % 5
			if diff >= 2:
				answer[j] += diff // 2
				diff = diff % 2
			if diff >= 1:
				answer[j] += 1
	print(min(answer))


def equal(n, cs):
	(mn, mx) = (min(cs), max(cs))
	(deltas, costs) = ([1, 2, 5], [0])
	for i in range(1, mx - mn + 3):
		costs.append(1 + min((costs[i - delta] for delta in deltas if i - delta >= 0)))
	return min((sum((costs[c - (mn - i)] for c in cs)) for i in range(3)))
for T in range(int(input())):
	print(equal(int(input()), list(map(int, input().split()))))


def cost(v):
	return v // 5 + (v % 5 + 1) // 2
T = int(input())
for t in range(T):
	input()
	values = list(map(int, input().split(' ')))
	minval = min(values)
	print(min((sum(map(lambda x: cost(x - minval + extra), values)) for extra in range(4))))


def minoperations(A):
	m = min(A)

	def steps(m):
		k = 0
		for i in range(0, len(A)):
			x = A[i] - m
			k += x // 5 + x % 5 // 2 + x % 5 % 2
		return k
	return min(map(steps, list(range(m - 5, m + 1))))
T = int(input())
for i in range(0, T):
	N = int(input())
	A = [int(x) for x in input().strip().split()]
	print(minoperations(A))


T = int(input())
for ii in range(T):
	N = int(input())
	a = list(map(int, input().split()))
	a.sort()
	cnt_min = 10 ** 20
	for i in range(5):
		cnt = 0
		base = a[0] - i
		for aa in a:
			aa = aa - base
			cnt += aa // 5
			aa %= 5
			cnt += aa // 2
			aa %= 2
			cnt += aa // 1
		if cnt_min > cnt:
			cnt_min = cnt
	print(cnt_min)


for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]

	def make_moves(min_val):
		ans = 0
		for e in arr:
			diff = e - min_val
			ans += diff // 5
			diff = diff % 5
			if diff == 1 or diff == 2:
				ans += 1
			elif diff == 3 or diff == 4:
				ans += 2
		return ans
	min_val = min(arr)
	print(min(make_moves(min_val), make_moves(min_val - 1), make_moves(min_val - 2)))


t = int(input())
for _ in range(t):
	n = int(input())
	c = [int(x) for x in input().strip().split()]
	minc = min(c)
	bestcnt = sum(c)
	for base in range(minc - 2, minc + 1):
		cnt = 0
		for cc in c:
			diff = cc - base
			cnt += diff // 5
			diff = diff % 5
			cnt += diff // 2
			diff %= 2
			cnt += diff
		if cnt < bestcnt:
			bestcnt = cnt
	print(bestcnt)


import sys
t = int(input().strip())
for var in range(t):
	n = int(input().strip())
	c = [int(temp) for temp in input().strip().split(' ')]
	min_num = 1000
	max_num = 0
	ops = [0, 0, 0]
	for num in c:
		if num < min_num:
			min_num = num
	d = list(range(n))
	for b in range(3):
		for i in range(n):
			d[i] = c[i] - min_num + b
			ops[b] += d[i] // 5
			k = d[i] % 5
			if k == 1 or k == 2:
				ops[b] += 1
			elif k == 3 or k == 4:
				ops[b] += 2
	print(min(ops))


T = int(input().strip())
sol = []

def solve(n, arr):
	m = min(arr)
	s = 0
	s1 = 0
	s2 = 0
	for i in range(len(arr)):
		arr[i] -= m
	for d in arr:
		s += int(d // 5 + d % 5 // 2 + d % 5 % 2)
	for x in arr:
		d = x + 1
		s1 += int(d // 5 + d % 5 // 2 + d % 5 % 2)
	for x in arr:
		d = x + 2
		s2 += int(d // 5 + d % 5 // 2 + d % 5 % 2)
	return min([s, s1, s2])
for i in range(T):
	n = int(input().strip())
	arr = [int(x) for x in input().strip().split()]
	s = solve(n, arr)
	sol.append(s)
for s in sol:
	print(str(s))


def count(v1, v2):
	diff = v1 - v2
	result = diff // 5
	diff %= 5
	result += diff // 2
	diff %= 2
	result += diff
	return result
t = int(input().strip())
for t1 in range(t):
	n = int(input().strip())
	elements = list(map(int, input().strip().split()))
	if n == 1:
		print(0)
		continue
	base = min(elements)
	counters = [0, 0, 0]
	for i in range(n):
		for c in range(3):
			counters[c] += count(elements[i], base - c)
	print(min(counters))


def minOps(val, options=[5, 2, 1]):
	count = 0
	temp = val
	options = sorted(options)[::-1]
	while temp > 0:
		for op in options:
			if temp >= op:
				temp = temp - op
				count = count + 1
				break
	return count
T = int(input())
for n in range(T):
	N = int(input())
	arr = [int(item) for item in input().split()]
	arr_min = min(arr)
	op_counts = []
	for amin in [arr_min - i for i in range(4)]:
		count = 0
		d = {}
		for val in arr:
			if val not in d:
				d[val] = minOps(val - amin)
			count = count + d[val]
		op_counts.append(count)
	print(min(op_counts))


import sys

def equal(interns):
	interns = sorted(interns)
	a = interns
	b = interns[:]
	b[0] -= 1
	c = interns[:]
	c[0] -= 2
	d = interns[:]
	d[0] -= 5
	return min(diff(a), diff(b) + 1, diff(c) + 1, diff(d) + 1)

def diff(interns):
	count = 0
	base = interns[0]
	for i in range(1, len(interns)):
		v = int((interns[i] - base) / 5)
		count += v
		mod = (interns[i] - base) % 5
		count += int(mod / 2) + 1 if mod % 2 != 0 else int(mod / 2)
	return count
times = int(input())
while times:
	times -= 1
	num_intern = int(input())
	interns = [int(x) for x in input().split(' ')]
	print(equal(interns))


T = int(input())
template = [0] * 1005
for i in range(1005):
	if i >= 5:
		template[i] = min([template[i - 5], template[i - 2], template[i - 1]]) + 1
	elif i >= 2:
		template[i] = min([template[i - 2], template[i - 1]]) + 1
	elif i >= 1:
		template[i] = template[i - 1] + 1
for test in range(T):
	n = int(input())
	numbers = [int(x) for x in input().split()]
	minimum = min(numbers)
	minscore = 10 ** 10
	for tmp in range(5):
		score = 0
		for item in numbers:
			score += template[item - minimum + tmp]
		if score < minscore:
			minscore = score
	print(minscore)


def count_steps(delta):
	fives = delta // 5
	rest = delta % 5
	if rest == 0:
		return fives
	if rest in [1, 2]:
		return fives + 1
	return fives + 2

def get_step_count(a, level):
	return sum([count_steps(x - level) for x in a])
for t in range(int(input())):
	n = int(input())
	a = [int(chs) for chs in input().split()]
	level = min(a)
	print(min([get_step_count(a, level), get_step_count(a, level - 1), get_step_count(a, level - 2)]))


def g(diff):
	ans = {0: 0, 1: 1, 2: 1, 3: 2, 4: 2}
	return diff // 5 + ans[diff % 5]

def f(chocolates, goal):
	return sum((g(chocolate - goal) for chocolate in chocolates))

def get_ans(chocolates):
	min_chocolate = min(chocolates)
	return min((f(chocolates, min_chocolate - dc) for dc in range(4)))
T = int(input(''))
for i in range(T):
	N = int(input(''))
	inp = input('').split()
	chocolates = [int(chocolate) for chocolate in inp]
	print(get_ans(chocolates))


ms = []
ts = [5, 2, 1]

def calc_ms():
	i = len(ms)
	sum = 0
	for t in ts:
		sum += i // t
		i %= t
	ms.append(sum)

def get_min(i):
	while i >= len(ms):
		calc_ms()
	return ms[i]
t = int(input())
for _ in range(t):
	n = int(input())
	ns = [int(a) for a in input().split(' ')]
	min = ns[0]
	for nm in ns:
		if nm < min:
			min = nm
	mi2 = 100000000000
	for i in range(min - 5, min + 1):
		sum = 0
		for nm in ns:
			sum += get_min(nm - i)
		if sum < mi2:
			mi2 = sum
	print(mi2)


import sys
T = int(input().strip())
for t in range(T):
	N = int(input().strip())
	ar = list(map(int, input().strip().split(' ')))
	m = min(ar)
	print(min((sum(((x + y - m) // 5 + ((x + y - m) % 5 + 1) // 2 for x in ar)) for y in range(5))))


import sys

def steps(n):
	sum = n // 5
	rest = n % 5
	if rest == 4 or rest == 3:
		sum += 2
	elif rest == 2 or rest == 1:
		sum += 1
	return sum
samples = int(input())
for _ in range(samples):
	tmp = input()
	array = [int(x) for x in input().split()]
	minimum = min(array)
	zero = sum((steps(x - minimum) for x in array))
	one = sum((steps(x - minimum + 1) for x in array))
	two = sum((steps(x - minimum + 2) for x in array))
	print(min(zero, one, two))


import sys

def diffs(arr):
	a0 = min(arr)
	return tuple((a - a0 for a in arr))

def num_ops(arr):
	d = diffs(arr)
	ops_totals = []
	for i in [0, 1, 2, 3, 4]:
		ops = 0
		for a in d:
			(q5, r) = divmod(a + i, 5)
			(q2, r) = divmod(r, 2)
			ops += q5 + q2 + r
		ops_totals.append(ops)
	return min(ops_totals)
T = int(input().strip())
for i in range(T):
	N = int(input().strip())
	arr = tuple((int(i) for i in input().strip().split(' ')))
	print(num_ops(arr))


arr = [0] * 1100
arr[0] = 0
arr[1] = 1
arr[2] = 1
arr[3] = 2
arr[4] = 2
arr[5] = 1
for i in range(6, 1100):
	arr[i] = min(arr[i - 1], arr[i - 2], arr[i - 5]) + 1
T = int(input().strip())
for i in range(T):
	ans = [0] * 6
	n = input()
	curArr = [int(x) for x in input().strip().split()]
	minCur = min(curArr)
	for x in curArr:
		for j in range(6):
			ans[j] += arr[x - minCur + j]
	print(min(ans))


import sys
C = [5, 2, 1]
T = int(input())
for _ in range(T):
	_ = input()
	N = list(map(int, input().split()))
	smallest = min(N)
	base = [smallest, smallest - 1, smallest - 2, smallest - 3, smallest - 4]
	count = 0
	best = -1
	for b in base:
		for n in N:
			while n > b:
				for c in C:
					d = (n - b) // c
					count += d
					n -= c * d
		if best == -1 or count < best:
			best = count
		count = 0
	print(best)


import logging
logging.basicConfig(level=logging.INFO)
STEPS = (5, 2, 1)
LEVELS = (0, -1, -2, -3, -4)

def read_int():
	return int(input())

def read_int_array():
	return [int(x) for x in input().strip().split(' ')]

class Column:

	def __init__(self, choc_num, persons_qty):
		self.choc_num = choc_num
		self.persons_qty = persons_qty
		self.norm_costs = self.calc_costs()

	def __repr__(self):
		return '(choc_num: {}, qty: {}, costs: {})'.format(self.choc_num, self.persons_qty, self.norm_costs)

	def calc_costs(self):
		result = {}
		for l in LEVELS:
			reminder = self.choc_num - l
			steps_num = 0
			for s in STEPS:
				n = reminder // s
				if n > 0:
					steps_num += n
				reminder = reminder % s
			result[l] = steps_num
		logging.debug('Costs for choc_num {}: {}'.format(self.choc_num, result))
		return result

	def sum_cost_by_level(self, level):
		return self.norm_costs[level] * self.persons_qty

class Testcase:

	def __init__(self, chocolate_number):
		self.data = self.compact(chocolate_number)

	def compact(self, initial_data):
		data = []
		min_num = min(initial_data)
		max_num = max(initial_data) - min_num
		initial_data = [x - min_num for x in initial_data]
		grouped_data = {}
		for val in initial_data:
			if val not in grouped_data:
				grouped_data[val] = 1
			else:
				grouped_data[val] += 1
		for (val, count) in grouped_data.items():
			if count > 0:
				data.append(Column(val, count))
		logging.debug('Testcase compacted data: {}'.format(data))
		return data

	def calc_steps(self):
		min_cost = None
		for l in LEVELS:
			sum_level_cost = 0
			for col in self.data:
				sum_level_cost += col.sum_cost_by_level(l)
			if min_cost is None or sum_level_cost < min_cost:
				min_cost = sum_level_cost
		return min_cost

def main():
	cases_qty = read_int()
	for case in range(cases_qty):
		read_int()
		test_case = Testcase(read_int_array())
		print(test_case.calc_steps())
main()


for _ in range(int(input())):
	(n, arr) = (int(input()), list(map(int, input().split())))
	mi = min(arr)
	s = []
	for j in range(4):
		s1 = 0
		for i in arr:
			d = i - mi + j
			s1 += d // 5
			d %= 5
			s1 += d // 2 + d % 2
		s.append(s1)
	print(min(s))


def minops(c):
	c.sort()
	bottom = c[0]
	out = None
	moves = [5, 2, 1]
	for ii in range(max(moves) - 1):
		base = bottom - ii
		ops = 0
		for ii in range(0, n):
			diff = c[ii] - base
			for move in moves:
				m = diff // move
				ops += m
				diff -= m * move
		if out is None:
			out = ops
		else:
			out = min(out, ops)
	return out
T = int(input())
for ii in range(T):
	n = int(input())
	c = list(map(int, input().split(' ')))
	print(minops(c))


from operator import mul
T = int(input())

def dot(l1, l2):
	return sum([i * j for (i, j) in zip(l1, l2)])
for i in range(T):
	num_coworkers = int(input())
	choclates = [int(x) for x in input().split(' ')]
	min_choc = min(choclates)
	choclates = [x - min_choc for x in choclates]
	choclates_mod = [0, 0, 0, 0, 0]
	for choclate in choclates:
		choclates_mod[choclate % 5] += 1
	shifts = [[0, 1, 1, 2, 2], [1, 1, 2, 2, 1], [1, 2, 2, 1, 2]]
	shift = min(enumerate(shifts), key=lambda x: dot(x[1], choclates_mod))[0]
	choclates = [choclate + shift for choclate in choclates]
	steps = 0
	for choclate in choclates:
		(div, mod) = (int(float(choclate) / 5), choclate % 5)
		if mod == 0:
			steps += div
		if mod == 4 or mod == 3:
			steps += 2 + div
		if mod == 1 or mod == 2:
			steps += 1 + div
	print(steps)


T = int(input())
for _ in range(T):
	N = int(input())
	ns = [int(n) for n in input().split(' ')]
	smallest = min(ns)
	best = 999999999999999999999999999999999999999999999999999999
	for i in range(5):
		new_ns = [n - smallest + i for n in ns]
		count = 0
		for n in new_ns:
			(quotient, rem) = divmod(n, 5)
			count += quotient
			(quotient2, rem2) = divmod(rem, 2)
			count += quotient2
			count += rem2
		best = min(best, count)
	print(best)


def f(x):
	a = x // 5
	b = (x - a * 5) // 2
	c = (x - a * 5) % 2
	return a + b + c
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	z = min(a)
	print(min(sum([f(x - z) for x in a]), sum([f(x - z + 1) for x in a]), sum([f(x - z + 2) for x in a]), sum([f(x - z + 5) for x in a])))


t = int(input())

def calc_ops(crt, ref):
	k = crt - ref
	return k // 5 + k % 5 // 2 + k % 5 % 2

def solve(a):
	a.sort()
	ref = [a[0], a[0] - 1, a[0] - 2]
	ops = [0, 1, 1]
	for i in range(1, len(a)):
		ops[0] += calc_ops(a[i], ref[0])
		ops[1] += calc_ops(a[i], ref[1])
		ops[2] += calc_ops(a[i], ref[2])
	return min(ops)

def read_testcase():
	n = int(input())
	return [int(i) for i in input().split()]
for i in range(t):
	print(solve(read_testcase()))


from math import ceil
num_case = int(input())
rules = [1, 2, 5]

def least_acts(ls):
	if not ls:
		return 0
	poor_guy = min(ls)
	return min([sum(map(lambda x: charge(x - poor_guy + i), ls)) for i in range(5)])

def charge(n):
	return int(n / 5) + ceil(n % 5 / 2)
for i in range(num_case):
	num_colgs = int(input())
	colgs = list(map(int, input().strip().split())) if num_colgs else []
	print(least_acts(colgs))


def change_to_baseline(num, baseline):
	diff = num - baseline
	n_op = diff // 5
	resid = diff % 5
	n_op += resid // 2
	resid = resid % 2
	n_op += resid
	return n_op
t = int(input())
for _ in range(t):
	n = int(input())
	nums = [int(x) for x in input().split()]
	baselines = [min(nums) - x for x in range(5)]
	min_ops = 1000000000.0
	for baseline in baselines:
		res = 0
		for num in nums:
			res += change_to_baseline(num, baseline)
		if res < min_ops:
			min_ops = res
	print(min_ops)


testcases = int(input())
after_five = {0: 0, 1: 1, 2: 1, 3: 2, 4: 2}
for test in range(testcases):
	N = int(input())
	chocs = list(map(int, input().split(' ')))
	minimum = min(chocs)
	offsets = [0, 1, 2, 5]
	tries = {offset: 0 for offset in offsets}
	for offset in offsets:
		for disparity in map(lambda x: x - minimum + offset, chocs):
			fives = disparity // 5
			tries[offset] += fives + after_five[disparity % 5]
	print(min(tries.values()))


t = int(input())
for _ in range(t):
	n = int(input())
	chs = list(map(int, input().split()))
	m = min(chs)
	mops = len(chs) * max(chs)
	for i in range(5):
		chocolates = (ch - m + i for ch in chs)
		ops = 0
		for ch in chocolates:
			ops += ch // 5
			ch %= 5
			ops += ch // 2
			ch %= 2
			ops += ch
		if ops < mops:
			mops = ops
	print(mops)


def count_operation(choco, target):
	count = 0
	memo = {}
	for c in choco:
		if c == target:
			continue
		elif c in memo:
			count += memo[c]
		else:
			key = c
			tmp_count = 0
			while c != target:
				diff = c - target
				if diff >= 5:
					c -= 5
				elif diff >= 2:
					c -= 2
				elif diff >= 1:
					c -= 1
				tmp_count += 1
			memo[key] = tmp_count
			count += tmp_count
	return count
t = int(input())
for _ in range(t):
	input()
	choco = [int(el) for el in input().strip().split(' ')]
	min_n = min(choco)
	mins = (min_n, min_n - 1, min_n - 2, min_n - 3, min_n - 4)
	operations = [count_operation(choco, m) for m in mins]
	print(min(operations))


import sys
data = sys.stdin.read()
data = data.splitlines()
data = [[int(y) for y in x.strip().split(' ')] for x in data]
T = data[0][0]

def num_steps(d):
	if d % 5 == 0:
		return d // 5
	elif d % 5 == 1 or d % 5 == 2:
		return d // 5 + 1
	elif d % 5 == 3 or d % 5 == 4:
		return d // 5 + 2
for i in range(1, T + 1, 1):
	chocs = data[2 * i]
	mi = min(chocs)
	steps = [0] * 5
	for diff in range(5):
		st = 0
		for x in chocs:
			st += num_steps(x + diff - mi)
		steps[diff] = st
	print(min(steps))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	mi = min(a)
	minSteps = float('inf')
	for m in range(mi, mi - 3, -1):
		steps = 0
		target = [m for _ in range(n)]
		delta = [x - y for (x, y) in zip(a, target)]
		for i in delta:
			steps += i // 5 + i % 5 // 2 + i % 5 % 2
		minSteps = min(minSteps, steps)
	print(minSteps)


def solve_one(n):
	total = 0
	for d in [5, 2, 1]:
		total += int(n / d)
		n = n % d
	return total

def try_with_min(l, smallest):
	return sum([solve_one(n - smallest) for n in l])

def solve(l):
	smallest = min(l)
	return min([try_with_min(l, smallest - i) for i in range(3)])
num_tests = int(input())
for t in range(num_tests):
	n = int(input())
	l = [int(tmp) for tmp in input().split(' ')]
	print(solve(l))


import sys
T = int(input().strip())
for t in range(T):
	N = int(input().strip())
	ops = [0] * N
	A = [int(intern) for intern in input().strip().split(' ')]
	choco = [5, 2, 1]
	state = [0] * 5
	for i in range(5):
		target = min(A) - i
		for num in A:
			curr_num = num
			for c in choco:
				temp = (curr_num - target) // c
				curr_num -= temp * c
				state[i] += temp
	print(min(state))


t = int(input())
for _ in range(t):
	(n, ar) = (int(input()), list(map(int, input().split())))
	m = min(ar)
	i = ar.index(m)
	d = [0, 1, 1]
	for el in ar:
		r = (el - m) % 5
		if r == 0:
			d[0] += 1
		elif r == 4:
			d[1] += 1
		elif r == 3:
			d[2] += 1
		elif r == 1:
			d[2] -= 1
		elif r == 2:
			d[0] += 1
	m -= d.index(max(d))
	ar = [ar[j] - m * (j != i) for j in range(n)]
	c = 0
	if m != ar[i]:
		c += 1
	ar[i] = 0
	for el in ar:
		c += el // 5
		c += el % 5 // 2
		c += el % 5 % 2
	print(c)