Salem gave you $n$ sticks with integer positive lengths $a_1, a_2, \ldots, a_n$.

For every stick, you can change its length to any other positive integer length (that is, either shrink or stretch it). The cost of changing the stick's length from $a$ to $b$ is $|a - b|$, where $|x|$ means the absolute value of $x$.

A stick length $a_i$ is called almost good for some integer $t$ if $|a_i - t| \le 1$.

Salem asks you to change the lengths of some sticks (possibly all or none), such that all sticks' lengths are almost good for some positive integer $t$ and the total cost of changing is minimum possible. The value of $t$ is not fixed in advance and you can choose it as any positive integer. 

As an answer, print the value of $t$ and the minimum cost. If there are multiple optimal choices for $t$, print any of them.


-----Input-----

The first line contains a single integer $n$ ($1 \le n \le 1000$) — the number of sticks.

The second line contains $n$ integers $a_i$ ($1 \le a_i \le 100$) — the lengths of the sticks.


-----Output-----

Print the value of $t$ and the minimum possible cost. If there are multiple optimal choices for $t$, print any of them.


-----Examples-----
Input
3
10 1 4

Output
3 7

Input
5
1 1 2 2 3

Output
2 0



-----Note-----

In the first example, we can change $1$ into $2$ and $10$ into $4$ with cost $|1 - 2| + |10 - 4| = 1 + 6 = 7$ and the resulting lengths $[2, 4, 4]$ are almost good for $t = 3$.

In the second example, the sticks lengths are already almost good for $t = 2$, so we don't have to do anything.

Difficulty: EASY
Tags: Implementation

Complete search
Skill types: Complete search

Starter code:

Solutions:
n = map(int, input())
a = list(map(int, input().split()))
a.sort()
Max = 1000000000000
ans = 1000000000000
for x in range(1, 101):
	sum = 0
	for y in a:
		k = abs(x - y)
		k = min(k, abs(k - 1))
		sum += k
	if sum < Max:
		ans = x
		Max = sum
print(ans, end=' ')
print(Max)


n = int(input())
a = list(map(int, input().split()))
cost = lambda med: sum((max(0, abs(x - med) - 1) for x in a))
best = min(range(2, 100), key=cost)
print(best, cost(best))


n = int(input())
a = list(map(int, input().split()))
a.sort()
mx = 0
foo = 10000000
k = 0
for i in range(1, max(a) + 1):
	for j in range(n):
		if i != a[j]:
			mx += abs(i - a[j]) - 1
	if foo > mx:
		foo = mx
		k = i
	mx = 0
print(k, foo)


(n, ls) = (int(input()), list(map(int, input().split())))
maxi = max(ls)
mini = min(ls)
if maxi - mini < 3:
	print(mini + 1, 0)
else:
	(bs, v) = (100000, -1)
	for i in range(mini + 1, maxi):
		score = 0
		for l in ls:
			if abs(l - i) > 1:
				score += abs(l - i) - 1
		if score < bs:
			(bs, v) = (score, i)
	print(v, bs)


n = int(input())
arr = list(map(int, input().split()))

def findCost(t):
	ans = 0
	for x in arr:
		li = []
		li.append(abs(t - x))
		li.append(abs(t + 1 - x))
		li.append(abs(t - 1 - x))
		ans += min(li)
	return ans
costs = []
for i in range(1, 100):
	costs.append(findCost(i))
print(costs.index(min(costs)) + 1, min(costs))


n = int(input())
size = input()
size = size.split(' ')
for i in range(n):
	size[i] = int(size[i])
size.sort()
mini = 10000000000000
for i in range(size[0], size[n - 1] + 1):
	cost = 0
	for j in size:
		if j > i:
			cost += j - i - 1
		elif j < i:
			cost += i - j - 1
		elif i == j:
			pass
	if cost < mini:
		mini = cost
		t = i
print(t, mini)


def func(arr, check):
	tot = 0
	for x in range(len(arr)):
		if arr[x] > check + 1:
			tot += arr[x] - check - 1
		elif arr[x] < check - 1:
			tot += check - 1 - arr[x]
	return tot

def main():
	n = int(input())
	arr = input().split()
	tot = 0
	for x in range(n):
		arr[x] = int(arr[x])
		tot += arr[x]
	mini = 10 ** 10
	val = 0
	for x in range(1, 101):
		test = func(arr, x)
		if mini > test:
			mini = test
			val = x
	print(val, mini)
main()


n = [int(i) for i in input().split()][0]
a = [int(i) for i in input().split()]
t = 0
tend = 102
dv = 10000000
for i in range(1, tend):
	d = 0
	for ai in a:
		d += min(min(abs(i - ai), abs(i - 1 - ai)), abs(i + 1 - ai))
	if d < dv:
		dv = d
		t = i
print(t, dv)


n = int(input())
a = [int(x) for x in input().split()]
t_min = 100
r_min = -1
for t in range(1, 100):
	r = 0
	for aa in a:
		if aa > t + 1:
			r += aa - t - 1
		elif aa < t - 1:
			r += t - 1 - aa
	if r < r_min or r_min == -1:
		t_min = t
		r_min = r
print(t_min, r_min)


n = int(input())
a = [int(x) for x in input().split()]
ans = 100000
for i in range(1, 101):
	s = sum([abs(b - i) - 1 * (b != i) for b in a])
	if s < ans:
		ans = s
		t = i
print(t, ans)


n = int(input())
a = list(map(int, input().split()))
t = sum(a) // n
ini = max(1, t - 42)
fi = min(100, t + 42)
temp = 0
ans = 10000000000
for i in range(ini, fi + 1):
	temans = 0
	for j in range(n):
		if abs(i - a[j]) > 1:
			temans += abs(i - a[j]) - 1
	if temans < ans:
		ans = temans
		temp = i
print(temp, ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 9999999999
t = -1
for num in range(1, a[-1] + 1):
	temp = 0
	for b in a:
		if b < num:
			temp += num - b - 1
		elif b > num:
			temp += b - num - 1
	if temp < ans:
		ans = temp
		t = num
print('{} {}'.format(t, ans))


n = int(input())
arr = list(map(int, input().split()))
mx = max(arr)
min_val = 99999999999999
t = -1
for i in range(1, mx + 1):
	val = 0
	for j in range(n):
		val += min(abs(arr[j] - i), abs(arr[j] - (i - 1)), abs(arr[j] - (i + 1)))
	if val < min_val:
		min_val = val
		t = i
print(t, min_val)


import sys
n = int(sys.stdin.readline())
a = [int(tmp) for tmp in sys.stdin.readline().split()]
sa = sum(a)
t = -1
mcoch = 10000000
for ct in range(2, 1000):
	coch = 0
	for el in a:
		coch += min([abs(ct - 1 - el), abs(ct - el), abs(ct + 1 - el)])
	if coch < mcoch:
		t = ct
		mcoch = coch
	elif coch > mcoch:
		break
print(t, mcoch)


import sys
from math import *
from copy import copy
import pdb
import itertools
from pprint import pprint
n = int(input())
dat = [int(i) for i in input().split()]
ansBest = 99999999999
bb = 0
for mid in range(101):
	ans = 0
	for i in dat:
		if i == mid:
			continue
		ans += abs(i - mid) - 1
	ansBest = min(ansBest, ans)
	if ansBest == ans:
		bb = mid
print(bb, ansBest)


def solve(t):
	cnt = 0
	for i in a:
		if abs(i - t) >= 1:
			if i > t:
				cnt += i - t - 1
			else:
				cnt += t - i - 1
	return cnt
n = int(input())
a = list(map(int, input().split()))
t_now = -1
ans = 10000000
for t in range(1, 101):
	now = solve(t)
	if now < ans:
		t_now = t
		ans = now
print(t_now, ans)


import math
n = int(input())
ar = [*map(int, input().split(' '))]
(mint, mincost) = (int(1000000000.0), int(1000000000.0))
for i in range(1, 105):
	cost = sum([min(abs(x - i), abs(x - i - 1), abs(x - i + 1)) for x in ar])
	if cost < mincost:
		mincost = cost
		mint = i
print(int(mint), int(mincost))


n = int(input())
a = list((int(x) for x in input().split()))
res = 9999999999
len = 1
for t in range(1, 101):
	cost = 0
	for x in a:
		cost += min(abs(x - t), min(abs(x - t - 1), abs(x - t + 1)))
	if res > cost:
		res = cost
		len = t
print(len, res)


num = int(input())
arr = [int(x) for x in input().split()]
big = max(arr)
small = min(arr)
record = small
record_cost = 0
for y in arr:
	a = abs(y - (small + 1))
	b = abs(y - (small - 1))
	c = abs(y - small)
	record_cost += min(a, b, c)
for x in range(small + 1, big + 1):
	cost = 0
	for y in arr:
		a = abs(y - (x + 1))
		b = abs(y - (x - 1))
		c = abs(y - x)
		cost += min(a, b, c)
	if cost <= record_cost:
		record_cost = cost
		record = x
print(str(record) + ' ' + str(record_cost))


import math
n = int(input())
arr = list(map(int, input().split()))
mm = 1000000000000000
ft = -1
for t in range(1, 101):
	ans = 0
	for i in range(n):
		if arr[i] > t + 1:
			ans += arr[i] - t - 1
		if arr[i] < t - 1:
			ans += t - 1 - arr[i]
	if ans < mm:
		mm = ans
		ft = t
print(ft, mm)


n = int(input())
l = list(map(int, input().split()))
ans = [0] * 101
for i in range(1, 101):
	for k in range(n):
		ans[i] += max(abs(l[k] - i) - 1, 0)
cnt = [100000000, 100000000]
for i in range(1, 101):
	if cnt[1] > ans[i]:
		cnt[0] = i
		cnt[1] = ans[i]
print(cnt[0], cnt[1])


n = int(input())
a = list(map(int, input().split()))
a.sort()
if len(a) % 2 == 0:
	x = len(a) // 2
	t = int((a[x] + a[x - 1]) // 2)
else:
	x = len(a) // 2
	t = int(a[x])
m = 9999999
for t in range(1, 100 + 1):
	c = 0
	for i in a:
		if i < t:
			c += abs(t - 1 - i)
		elif i > t:
			c += abs(i - t - 1)
		else:
			pass
	if c < m:
		m = c
		nt = t
print(nt, m)


n = int(input())
a = [int(x) for x in input().split()]
(ans, t) = min(((sum([min(abs(b - i), abs(b - i - 1), abs(b - i + 1)) for b in a]), i) for i in range(1, 101)))
print(t, ans)


n = int(input())
a = list(map(int, input().split()))
T = 0
ans = float('inf')
for t in range(1, 101):
	cost = 0
	for i in range(n):
		if a[i] > t:
			cost += a[i] - (t + 1)
		elif a[i] < t:
			cost += t - (a[i] + 1)
	if cost < ans:
		ans = cost
		T = t
print(T, ans)


input()
st = [int(x) for x in input().split()]
(mn, ans) = (99999, min(st))
for t in range(min(st) + 1, max(st)):
	cur = 0
	for j in st:
		cur += abs(t - j) - (abs(t - j) > 0)
	if cur < mn:
		(mn, ans) = (cur, t)
print(ans, mn % 99999)


n = int(input())
a = [int(t) for t in input().split(' ')]
mincost = 1000 * 100 + 1
best_t = None
for t in range(1, 101):
	cost = 0
	for x in a:
		cost += max(0, abs(x - t) - 1)
	if cost < mincost:
		mincost = cost
		best_t = t
print(best_t, mincost)


maxs = 100000000000.0
lens = int(input())
arrs = [int(x) for x in input().split()]
for i in range(1, 101):
	now = sum([abs(i - j) - 1 for j in arrs if i != j])
	if now < maxs:
		diff = i
		cnt = now
		maxs = now
print(diff, cnt)


import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 5)

def li():
	return map(int, stdin.readline().split())

def li_():
	return map(lambda x: int(x) - 1, stdin.readline().split())

def lf():
	return map(float, stdin.readline().split())

def ls():
	return stdin.readline().split()

def ns():
	return stdin.readline().rstrip()

def lc():
	return list(ns())

def ni():
	return int(stdin.readline())

def nf():
	return float(stdin.readline())
n = ni()
a = list(li())
anst = 0
anscost = float('inf')
for t in range(1, 1001):
	cost = 0
	for ai in a:
		if ai < t - 1:
			cost += t - 1 - ai
		elif ai > t + 1:
			cost += ai - (t + 1)
	if cost < anscost:
		anscost = cost
		anst = t
print(anst, anscost)


n = int(input())
a = list(map(int, input().split()))

def f(t):
	d = 0
	for i in a:
		if i > t + 1:
			d += i - t - 1
		elif i < t - 1:
			d += t - 1 - i
	return d
b = 1
d = f(1)
for i in range(1, 101):
	dd = f(i)
	if dd < d:
		d = dd
		b = i
print(b, d)


n = int(input())
arr = [int(x) for x in input().split()]
t = []
for i in range(101):
	s = 0
	for j in arr:
		s += max(0, abs(j - i) - 1)
	t.append(s)
p = t[1:].index(min(t)) + 1
print(p, min(t))


n = int(input())
l = input().split()
l2 = [int(i) for i in l]
l2.sort()
if n % 2 == 0:
	t1 = (l2[n // 2] + l2[n // 2 - 1]) // 2
else:
	t1 = l2[n // 2]
t2 = 0
if t1 > 1:
	t2 = t1 - 1
t3 = t1 + 1
cost1 = sum([abs(t1 - i) - 1 for i in l2 if abs(t1 - i) > 1])
cost2 = sum([abs(t2 - i) - 1 for i in l2 if abs(t2 - i) > 1])
cost3 = sum([abs(t3 - i) - 1 for i in l2 if abs(t3 - i) > 1])
cost = 0
cost = min(cost1, cost2, cost3)
if cost == cost1:
	t = t1
elif cost == cost2:
	t = t2
else:
	t = t3
print(t, cost)


n = int(input())
a = [int(x) for x in input().split()]
ans = 0
anst = 1000000
for i in range(1, max(a) + 1):
	temp = 0
	for j in a:
		if abs(i - j) <= 1:
			continue
		temp += max(0, min(abs(j - (i - 1)), abs(j - (i + 1))))
	if temp < anst:
		ans = i
		anst = temp
print(ans, anst)


n = int(input())
clist = list(map(int, input().rstrip().split()))
clist.sort()
if n % 2 == 0:
	med = (clist[n // 2] + clist[n // 2 - 1]) // 2
if n % 2 == 1:
	med = clist[n // 2]
t1 = med - 1
t2 = med + 1
t3 = med - 2
t4 = med + 2
costs = [max(abs(i - med) - 1, 0) for i in clist]
ctotal = sum(costs)
costs1 = [max(abs(i - t1) - 1, 0) for i in clist]
ctotal1 = sum(costs1)
costs2 = [max(abs(i - t2) - 1, 0) for i in clist]
ctotal2 = sum(costs2)
costs3 = [max(abs(i - t3) - 1, 0) for i in clist]
ctotal3 = sum(costs3)
costs4 = [max(abs(i - t4) - 1, 0) for i in clist]
ctotal4 = sum(costs4)
csort = [[ctotal, med], [ctotal1, t1], [ctotal2, t2], [ctotal3, t3], [ctotal4, t4]]
csort.sort()
print(max(csort[0][1], 1), csort[0][0])


import sys
LI = lambda : list(map(int, sys.stdin.readline().split()))
MI = lambda : map(int, sys.stdin.readline().split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline())
n = II()
a = LI()
cst = 99999999999999
for m in range(min(a), max(a) + 1):
	cur = 0
	for v in a:
		if v > m:
			cur += v - m - 1
		if v < m:
			cur += m - v - 1
	if cur < cst:
		cst = cur
		t = m
print(t, cst)


n = int(input())
a = list(map(int, input().split()))
m = 100000
for t in range(1, 101):
	s = 0
	for x in a:
		if abs(t - x) > 1:
			s += abs(t - x) - 1
	if s < m:
		m = s
		mi = t
print(mi, m)


n = int(input())
list_n = list(map(int, input().split()))
list_n.sort()
x = max(list_n)
y = min(list_n)
answers = []
for t in range(y, x + 1):
	score = 0
	for elements in list_n:
		if elements < t:
			score += t - 1 - elements
		elif elements == t:
			score += 0
		else:
			score += elements - t - 1
	answers.append(score)
a = min(answers)
i = answers.index(a)
print(str(i + y) + ' ' + str(a))


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ap = float('inf')
at = -1
for t in range(1, 101):
	s = 0
	for c in arr:
		s += max(abs(c - t) - 1, 0)
	if s < ap:
		ap = s
		at = t
print(at, ap)


from typing import List
_max_a = 100

def cost(a: List[int], t: int, n: int) -> int:
	return sum((max(abs(a[i] - t) - 1, 0) for i in range(n)))
n = int(input())
a = list(map(int, input().split()))
answers = []
for t in range(1, _max_a + 1):
	answers.append(cost(a, t, n))
optimal_cost = min(answers)
optimal_t = answers.index(optimal_cost) + 1
print(optimal_t, optimal_cost)


def get_optimal_t(val, t):
	arr = [t, t + 1, t - 1]
	if t <= 1:
		arr = [t, t + 1]
	price = abs(t - val)
	opt_t = t
	for i in arr:
		tem_price = abs(i - val)
		if tem_price < price:
			opt_t = i
			price = tem_price
	return opt_t

def calc_price(arr, t):
	price = 0
	for i in arr:
		optimal_t = get_optimal_t(i, t)
		price = price + abs(i - optimal_t)
	return price

def search_t(arr):
	MAX = max(arr)
	min_price = calc_price(arr, 1)
	min_t = 1
	for i in range(2, MAX + 1):
		tem_min_price = calc_price(arr, i)
		if tem_min_price < min_price:
			min_price = tem_min_price
			min_t = i
	print(min_t, min_price)
length = int(input())
array = [int(x) for x in input().split()]
search_t(array)


import os
import heapq
import sys, threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10 ** 5)
from io import BytesIO, IOBase

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def power(x, p, m):
	res = 1
	while p:
		if p & 1:
			res = res * x % m
		x = x * x % m
		p >>= 1
	return res

def inar():
	return [int(k) for k in input().split()]

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def main():
	t = 1
	for _ in range(t):
		n = int(input())
		arr = inar()
		t = 1
		ans = 10 ** 5
		for i in range(1, 101):
			temp = 0
			for j in range(n):
				if abs(arr[j] - i) <= 1:
					continue
				else:
					temp += abs(arr[j] - i) - 1
			if temp < ans:
				ans = temp
				t = i
		print(t, ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
a = list(map(int, input().split()))
t = 0
cost = 10 ** 10
for i in range(min(a), max(a) + 1):
	c = 0
	for j in a:
		if abs(j - i) > 1:
			c += abs(j - i) - 1
	if c < cost:
		cost = c
		t = i
print(t, cost)


a = int(input())
h = list(map(int, input().split()))
minn = []
for i in range(1, 101):
	minn.append(0)
	for u in h:
		p = abs(u - i)
		if p != 0:
			p -= 1
		minn[i - 1] += p
print(minn.index(min(minn)) + 1, min(minn))


n = int(input())
(sum, mini) = (0, 10000000)
pos = 1
a = list(map(int, input().split()))
for i in range(1, 101):
	sum = 0
	for x in a:
		sum += max(0, abs(x - i) - 1)
	if sum < mini:
		mini = sum
		pos = i
print(pos, '', mini)


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

def read_int():
	return int(stdin.readline())

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
nb_sticks = read_int()
sticks = read_ints()
mins = min(sticks)
maxs = max(sticks)
x = int(10000000000000.0)
num = 0
for j in range(mins, maxs + 1):
	curr = 0
	for i in sticks:
		if abs(i - j) > 1:
			curr += abs(i - j) - 1
	if x > curr:
		x = curr
		num = j
print(num, x)


n = int(input())
l = [*map(int, input().split())]

def f(a):
	return [sum((min([abs(e - a), abs(e - (a - 1)), abs(e - (a + 1))]) for e in l)), a]
res = [float('inf'), float('inf')]
for a in range(1, 101):
	res = min(res, f(a))
print(res[1], res[0])


n = int(input())
a = input()
a = [int(x) for x in a.split()]
t1 = int(sum(a) / n)
t2 = t1 + 1
t3 = t1 - 1

def prove(t):
	suma = 0
	for x in a:
		if x > t:
			suma += x - 1 - t
		elif x < t:
			suma += t - x - 1
	return suma
almost = min([(prove(b), b) for b in range(1, 100)])
t = almost[1]
ans = almost[0]
print(str(t) + ' ' + str(ans))


import math

def median(l):
	half = len(l) // 2
	l.sort()
	if not len(l) % 2:
		return round((l[half - 1] + l[half]) / 2.0)
	return l[half]
n = int(input())
L = list(map(int, input().split()))
avg = round(sum(L) / n)
L.sort()
med = median(L)
c = float('inf')
val = 0
for b in range(max(min(avg, med) - 1, 1), max(avg, med) + 2):
	temp = 0
	for a in L:
		if abs(a - b) > 1:
			if a > b:
				temp += a - b - 1
			else:
				temp += b - 1 - a
	if temp < c:
		c = temp
		val = b
print(val, c)


n = int(input())
A = list(map(int, input().split()))
t = 1
maxi = 1000000
ans = 0
f = 1
for t in range(1, 100, 1):
	ans = 0
	for i in range(n):
		if A[i] > t:
			ans = ans + A[i] - t - 1
		if A[i] < t:
			ans = ans + t - 1 - A[i]
	if ans < maxi:
		maxi = ans
		f = t
print(f, maxi)


n = int(input())
l = list(map(int, input().split()))
l.sort()
min = 10 ** 12
for t in range(1, 101):
	cost = 0
	for j in range(n):
		if abs(l[j] - t) > 1:
			if l[j] > t:
				cost += l[j] - (1 + t)
			else:
				cost += t - 1 - l[j]
	if cost < min:
		min = cost
		ans = t
print(ans, min)


n = int(input())
sticks = list(map(int, input().split()))
cost = 1000000000000000
ans = 0
for j in range(min(sticks), max(sticks) + 1):
	cost1 = 0
	ans1 = 0
	for i in sticks:
		if abs(j - i) <= 1:
			continue
		cost1 += min(abs(j - i - 1), abs(j - i + 1))
	if cost > cost1:
		ans = j
		cost = cost1
print(ans, int(cost))


def cost(L, t):
	costt = 0
	for i in L:
		if abs(i - t) > 1:
			costt += abs(i - t) - 1
	return costt
n = int(input(''))
x = input('')
L = [int(i) for i in str(x).split()]
L.sort()
minn = cost(L, min(L))
ind = min(L)
for i in range(min(L) + 1, max(L)):
	if cost(L, i) < minn:
		minn = cost(L, i)
		ind = i
print(ind, minn)


n = int(input())
a = []
a = input().split()
ans = 100000
p = 0
for i in range(100):
	cnt = 0
	for j in range(n):
		cnt += abs(int(a[j]) - i - 1) - 1
		if abs(int(a[j]) - i - 1) == 0:
			cnt += 1
	if cnt < ans:
		ans = cnt
		p = i + 1
print(p, ' ', ans)


def n(a, b):
	z = 0
	for x in range(len(a)):
		c = a[x] * 1
		if c > b:
			c = c - 1
		elif c < b:
			c = c + 1
		z = z + abs(c - b)
	return z

def m(a, b):
	z = 0
	for x in range(len(a)):
		c = a[x] * 1
		if c > b:
			c = c - 1
		elif c < b:
			c = c + 1
		print(a[x], abs(a[x] - b))
		z = z + abs(c - b)
	return z
input()
a = list(map(int, input().split()))
q = min(a)
for x in range(min(a), max(a) + 1):
	if n(a, q) > n(a, x):
		q = x
print(q, n(a, q))


n = int(input())
a = [int(x) for x in input().split()]
m = min(a)
t = max(a)
b = []
for i in range(m, t + 2):
	cost = 0
	for j in range(len(a)):
		if abs(a[j] - i) >= 1:
			cost += abs(a[j] - i) - 1
	b.append([cost, i])
b.sort()
print(*b[0][::-1])


def cost(target, val):
	if target == val:
		return 0
	if target < val:
		return val - target - 1
	if target > val:
		return target - val - 1
n = input()
ints = list(map(int, input().split()))
minsum = 10 ** 99
t = 0
for i in range(min(ints), max(ints) + 1):
	sum1 = sum([cost(j, i) for j in ints])
	if sum1 < minsum:
		t = i
		minsum = sum1
print(t, end=' ')
print(minsum)


n = int(input())
a = [int(i) for i in input().split()]
val = minval = 10000000000.0
t1 = 0
for t in range(101):
	for i in a:
		if i < t - 1:
			val += t - 1 - i
		elif i > t + 1:
			val += i - t - 1
	if minval > val:
		minval = val
		t1 = t
	val = 0
print(t1, minval)


n = int(input())
arr = list(map(int, input().split()))
x = max(arr)
ans = 99999999
for t in range(1, x + 2):
	sum = 0
	for i in arr:
		sum += min(abs(t - i), abs(t - i - 1), abs(t - i + 1))
	if sum < ans:
		ans = sum
		T = t
print(T, ans)


gi = lambda : list(map(int, input().split()))
(n,) = gi()
l = gi()
ans = 1
cost = 1000000
for k in range(1, 101):
	if sum([abs(e - k) - 1 if abs(e - k) > 1 else 0 for e in l]) < cost:
		ans = k
		cost = sum([abs(e - ans) - 1 if abs(e - ans) > 1 else 0 for e in l])
print(ans, cost)


n = int(input())
m = list(map(int, input().split()))
mi = min(m)
ma = max(m)
t = mi
tm = sum([min(abs(mi - j - 1), abs(mi - j + 1), abs(mi - j)) for j in m])
for i in range(mi + 1, ma + 1):
	tmp = sum([min(abs(i - j - 1), abs(i - j + 1), abs(i - j)) for j in m])
	if tmp < tm:
		tm = tmp
		t = i
print(t, tm)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	ret = [0, 100 * 1000]
	for x in range(1, 101):
		total_cost = 0
		for v in a:
			total_cost += min(abs(x + 1 - v), abs(x - v), abs(x - 1 - v))
		if total_cost < ret[1]:
			ret = [x, total_cost]
	print(ret[0], ret[1])
main()


n = int(input())
l = list(map(int, input().split()))
INF = max(l) * n
s = 0
m = []
for t in range(1, max(l) + 1):
	for i in l:
		if t > i + 1:
			s += t - i - 1
		elif t < i - 1:
			s += i - t - 1
	m.append(s)
	s = 0
print(m.index(min(m)) + 1, min(m))


n = int(input())
a = list(map(int, input().split()))
ans = int(1000000000.0)
arg = 0
for t in range(1, 101):
	cost = 0
	for x in a:
		if x > t:
			cost = cost + x - t - 1
		elif x < t:
			cost = cost + t - 1 - x
	if cost < ans:
		ans = cost
		arg = t
print(arg, ans)


import math
from statistics import median
n = int(input())
l = list(map(int, input().split()))
f = 0
x = []
a = int(median(l))
a1 = a + 1
a2 = a - 1
b = 0
b1 = 0
b2 = 0
for i in range(n):
	if abs(l[i] - a) > 1:
		b += abs(l[i] - a) - 1
for i in range(n):
	if abs(l[i] - a1) > 1:
		b1 += abs(l[i] - a1) - 1
for i in range(n):
	if abs(l[i] - a2) > 1:
		b2 += abs(l[i] - a2) - 1
if b == min(b, b1, b2):
	print(a, b)
elif b1 == min(b, b1, b2):
	print(a1, b1)
else:
	print(a2, b2)


n = int(input())
stk = list(map(int, input().split()))
(t, mn) = (0, 1000000)
for i in range(1, 101):
	s = 0
	for j in range(n):
		s += min(abs(stk[j] - i), abs(stk[j] - i - 1), abs(stk[j] - i + 1))
	if mn > s:
		(t, mn) = (i, s)
print(t, mn)


from typing import List
_max_a = 100

def dist(x: int, y: int, w: int=1):
	if x < y - w:
		return y - w - x
	elif x > y + w:
		return x - (y + w)
	else:
		return 0

def cost(a: List[int], t: int, n: int) -> int:
	ans = 0
	for i in range(n):
		ans += dist(a[i], t)
	return ans
n = int(input())
a = list(map(int, input().split()))
answers = []
for t in range(1, _max_a + 1):
	answers.append(cost(a, t, n))
optimal_cost = min(answers)
optimal_t = answers.index(optimal_cost) + 1
print(optimal_t, optimal_cost)


n = int(input())
l = list(map(int, input().split()))
mincost = 100000
ans = 0
for t in range(1, 101):
	curcost = 0
	for i in l:
		if i == t:
			continue
		else:
			curcost += abs(t - i) - 1
	if curcost < mincost:
		mincost = curcost
		ans = t
print(ans, mincost)


_ = int(input())
a = [int(_) for _ in input().split(' ')]
minc = 2000000000
t = 0
for i in range(1, 101):
	c = 0
	for j in a:
		c += max(abs(j - i) - 1, 0)
	if c < minc:
		t = i
		minc = c
print(t, minc)


n = int(input())
L = [int(x) for x in input().split()]
L.sort()
arr = [0, 500500]
for i in range(1, 101):
	Sum = 0
	for x in L:
		if abs(x - i) > 1:
			Sum += abs(x - i) - 1
	if arr[1] > Sum:
		arr[1] = Sum
		arr[0] = i
print(arr[0], arr[1])


n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
for i in range(0, n // 2):
	r = (l[i] + l[n - i - 1]) / 2
	if i == 0:
		maxn = r
		minn = r
	elif r < minn:
		minn = r
	elif r > maxn:
		maxn = r
if n == 1:
	maxn = l[0]
	minn = maxn
if n % 2 == 1:
	if l[n // 2] > maxn:
		maxn = l[n // 2]
	elif l[n // 2] < minn:
		minn = l[n // 2]
maxn = round(maxn)
if round(minn) > minn:
	minn = round(minn) - 1
minn = int(minn)
for i in range(minn, maxn + 1):
	a = 0
	for j in range(0, n):
		a += abs(abs(i - l[j]) - 1)
		if i == l[j]:
			a -= 1
	if i == minn:
		mini = a
		tr = i
	elif a < mini:
		mini = a
		tr = i
print(tr, mini)


n = int(input())
a = [int(x) for x in input().split()]
m = 10000000000
ind = 0
for i in range(min(a), max(a) + 1):
	res = 0
	for x in a:
		if x != i:
			res += abs(x - i) - 1
	if res < m:
		m = res
		ind = i
print(ind, m)


n = int(input())
sticks = list(map(int, input().split()))
smin = 10000000000000000000
tmin = -1
for t in range(1, 102):
	s = 0
	for l in sticks:
		if abs(t - l) <= 1:
			continue
		if l < t:
			s += t - 1 - l
		else:
			s += l - t - 1
	if s < smin:
		smin = s
		tmin = t
print(tmin, smin)


n = int(input())
a = list(map(int, input().split(' ')))
l = [x for x in range(1, max(a) + 1)]
k = []
for i in l:
	x = 0
	for j in a:
		if abs(j - i) > 1:
			if j > i:
				x += abs(j - i - 1)
			else:
				x += abs(i - j - 1)
		else:
			x += 0
	k.append(x)
print(k.index(min(k)) + 1, min(k))


n = int(input())
a = [int(i) for i in input().split()]
b = []
for k in range(1, 105):
	p = 0
	for i in range(n):
		if abs(a[i] - k) >= 1:
			p = p + (abs(a[i] - k) - 1)
	b.append((p, k))
l = min(b)
print(*l[::-1])


n = int(input())
sticks = [int(x) for x in input().split()]
t1 = sum(sticks) // n
t2 = (sum(sticks) + n) // n
cost1 = 0
cost2 = 0
cost = 0
min_ = 1000000000.0
min_t = 101
for t in range(1, 101):
	cost = 0
	for i in sticks:
		if i != t:
			cost += abs(i - t) - 1
	if min_ > cost:
		min_ = cost
		min_t = t
for i in sticks:
	if i != t1:
		cost1 += abs(i - t1) - 1
	if i != t2:
		cost2 += abs(i - t2) - 1
if min(cost1, cost2, min_) == cost1:
	print(t1, cost1)
elif min(cost1, cost2, min_) == cost2:
	print(t2, cost2)
else:
	print(min_t, min_)


n = int(input())
l = list(map(int, input().split()))
c = [0, 1000000007]
x = max(l)
for i in range(1, x + 1):
	y = 0
	for j in range(n):
		if l[j] == i + 1 or l[j] == i - 1 or l[j] == i:
			y = y + 0
		elif l[j] > i:
			y = y + abs(l[j] - i - 1)
		elif l[j] < i:
			y = y + abs(i - l[j] - 1)
	if c[1] >= y:
		c[0] = i
		c[1] = y
print(c[0], c[1])


import re, math, decimal, bisect

def read():
	return input().strip()

def iread():
	return int(input().strip())

def viread():
	return [int(_) for _ in input().strip().split()]
n = iread()
sticks = viread()
best = None
for t in range(1, 101):
	cost = 0
	for s in sticks:
		if s > t + 1:
			cost += s - (t + 1)
		elif s < t - 1:
			cost += t - 1 - s
	if best is None or cost < best[1]:
		best = (t, cost)
print(*best)


n = int(input())
a = list(map(int, input().split()))
num = float('inf')
ans = -1
for t in range(1, 105):
	tmp = 0
	for j in range(n):
		tmp += min(min(abs(a[j] - (t - 1)), abs(a[j] - t)), abs(a[j] - (t + 1)))
	if tmp < num:
		num = tmp
		ans = t
print(ans, num)


n = int(input())
ns = list(map(int, input().split()))
cost = int(1000000000.0)
res = 0
for t in range(1, 101):
	temp = 0
	for i in ns:
		if abs(i - t) > 1:
			temp += abs(i - t) - 1
	if cost > temp:
		cost = temp
		res = t
print(res, cost)


n = int(input())
ar = list(map(int, input().strip().split(' ')))
ar.sort()
m = 10 ** 5
t = 0
i = 1
while i <= 100:
	c = 0
	d = 0
	for j in range(n):
		c += abs(ar[j] - i)
		if ar[j] == i:
			d += 1
	c -= n - d
	if c < m:
		m = c
		t = i
	i += 1
print(t, m, end=' ')


import sys
import math
import bisect

def solve(A):
	n = len(A)
	min_cost = 10 ** 18
	sol = -1
	for i in range(1, 101):
		cost = 0
		for a in A:
			if a > i + 1:
				cost += a - (i + 1)
			elif a < i - 1:
				cost += i - 1 - a
		if min_cost > cost:
			min_cost = cost
			sol = i
	return (sol, min_cost)

def main():
	n = int(input())
	A = list(map(int, input().split()))
	(sol, min_cost) = solve(A)
	print('%d %d' % (sol, min_cost))
main()


n = int(input())
a = [int(a) for a in input().split()]
t = round(sum(a) / len(a))

def cost(t):
	c = 0
	for x in a:
		if x < t - 1:
			c += t - 1 - x
		elif t + 1 < x:
			c += x - t - 1
	return c
best = 0
bestcost = 10 ** 20
for x in range(1, 101):
	c = cost(x)
	if c < bestcost:
		best = x
		bestcost = c
print(best, bestcost)


from itertools import combinations
from sys import stdin
import math

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())
n = intIn()
a = listIn()
a = sorted(a)
b = sorted(set(a))
l = len(b)
cost = float('inf')
for ele in b:
	t = list(range(ele - 1, ele + 2))
	for tt in t:
		if tt > 0:
			c = 0
			for i in range(n):
				d = abs(a[i] - tt)
				if d <= 1:
					c = c
				else:
					c += d - 1
			if c < cost:
				cost = c
				ttt = tt
print(ttt, cost)


t = int(input())
arr = list(map(int, input().split()))
arr2 = []
sum = 0
for x in range(max(arr)):
	sum = 0
	for y in arr:
		if x + 1 < y:
			sum = sum + y - x - 2
		if x + 1 > y:
			sum = sum + x - y
	arr2.append((sum, x + 1))
print('{} {}'.format(min(arr2)[1], min(arr2)[0]))


n = int(input())
arr = list(map(int, input().split()))
f = [0 for it in range(101)]
for it in arr:
	f[it] += 1

def get_t_cost(f, t):
	cost = 0
	for s in range(0, t - 1):
		if f[s] > 0:
			cost += (t - 1 - s) * f[s]
	for d in range(t + 2, 101):
		if f[d] > 0:
			cost += (d - t - 1) * f[d]
	return cost
all_costs = []
min_cost = 100000
final_t = -1
for t in range(2, 100):
	cost = get_t_cost(f, t)
	if cost < min_cost:
		min_cost = cost
		final_t = t
print(final_t, min_cost)


import math

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())
n = int(input())
arr = list_input()
cost = 10 ** 8
ans = 0
for i in range(1, 101):
	temp = 0
	for j in arr:
		if abs(i - j) > 1:
			temp += abs(i - j) - 1
	if cost != min(cost, temp):
		cost = min(cost, temp)
		ans = i
print(ans, cost)


import math
n = input()
a = list(map(int, input().split()))
ans_i = 1
ans_s = 1000000000
for t in range(1, 101):
	sum = 0
	for i in a:
		if abs(i - t) >= 1:
			sum += abs(i - t) - 1
	if sum < ans_s:
		ans_s = sum
		ans_i = t
print(ans_i, ans_s)


input()
A = list(map(int, input().split()))
print(*min(((t, sum((max(0, abs(t - a) - 1) for a in A))) for t in range(1, 101)), key=lambda x: x[1]))


stick_no = int(input().strip())
sticks = [int(x) for x in input().strip().split(' ')]

def cost(x):
	res = 0
	for s in sticks:
		if s > x:
			res += s - x - 1
		elif s < x:
			res += x - s - 1
	return res
c_r = 10000000
c_i = -1
for i in range(1, 100):
	c = cost(i)
	if c < c_r:
		c_r = c
		c_i = i
print(c_i, c_r)


n = int(input())
sticks = [int(i) for i in input().split()]
best = 1000000000
bestt = -1
for t in range(1, 101):
	cost = 0
	for stick in sticks:
		if stick > t:
			cost += abs(stick - (t + 1))
		elif stick < t:
			cost += abs(stick - (t - 1))
	if cost < best:
		best = cost
		bestt = t
print(bestt, best)


def count_cost(a, t):
	res = 0
	for i in a:
		if i > t + 1 or i < t - 1:
			res += abs(i - t) - 1
	return res
n = int(input())
a = list(map(int, input().split()))
sort_a = sorted(a)
mean_a = sort_a[len(sort_a) // 2]
t = mean_a
t_max = mean_a + 1
t_min = mean_a - 1
c_t = count_cost(a, t)
c_t_max = count_cost(a, t_max)
c_t_min = count_cost(a, t_min)
min_c = min(c_t, c_t_max, c_t_min)
for i in [(c_t, t), (c_t_max, t_max), (c_t_min, t_min)]:
	if i[0] == min_c:
		print(i[1], i[0])
		break


n = int(input())
max_tot = 10000000000
total = 0
pal = [int(x) for x in input().split()]
for item in range(min(pal), max(pal) + 1):
	tot = 0
	for i in pal:
		if i != item:
			tot += abs(i - item) - 1
	if tot < max_tot:
		max_tot = tot
		total = item
print(total, max_tot)


n = int(input())
l = []
q = []
p = input().rstrip().split(' ')
x = list(p)
x.sort(key=int, reverse=True)
for i in range(1, int(x[0]) + 1):
	s = 0
	for j in range(0, len(p)):
		t = abs(int(p[j]) - i)
		if t > 1:
			o = i + 1
			O = i - 1
			d = abs(int(p[j]) - O)
			D = abs(int(p[j]) - o)
			s = s + min(d, D)
	l.append(s)
	q.append(i)
print(q[l.index(min(l))], min(l))


n = int(input())
a = list(map(int, input().split()))
ma = 10000000
t = 0
for i in range(1, 101):
	s = 0
	for j in range(n):
		k = min(abs(a[j] - i), abs(abs(a[j] - i) - 1))
		s += abs(k)
	if s < ma:
		ma = s
		t = i
print(t, ma)


n = input()
a = list(map(int, input().split()))
a.sort()
if len(a) % 2 == 1:
	t = a[len(a) // 2]
	x = [t - 1, t, t + 1]
else:
	x = [a[len(a) // 2 - 1] - 1, a[len(a) // 2 - 1], a[len(a) // 2 - 1] + 1, a[len(a) // 2] - 1, a[len(a) // 2], a[len(a) // 2] + 1]
if 0 in x:
	x.remove(0)
res = [0] * len(x)
for i in range(len(a)):
	for z in range(len(x)):
		if a[i] < x[z] - 1:
			res[z] = res[z] + (x[z] - 1) - a[i]
		elif a[i] > x[z] + 1:
			res[z] = res[z] + a[i] - (x[z] + 1)
for z in range(len(x)):
	if res[z] == min(res):
		print(x[z], res[z])
		exit()


class CodeforcesTask1105ASolution:

	def __init__(self):
		self.result = ''
		self.n = 0
		self.sticks = []

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

	def process_task(self):
		mn = 10 ** 9
		ct = -1
		for t in range(1, 101):
			tc = 0
			for stick in self.sticks:
				if stick > t:
					tc += stick - t - 1
				elif stick < t:
					tc += t - stick - 1
			if tc < mn:
				mn = tc
				ct = t
		self.result = '{0} {1}'.format(ct, mn)

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


import math
n = int(input())
A = [int(i) for i in input().split()]
A.sort()
ans = 10 ** 18
val = 0
for mid in range(1, 100):
	cost = 0
	for i in range(n):
		cost += min(abs(A[i] - mid), abs(A[i] - mid + 1), abs(A[i] - mid - 1))
	if cost < ans:
		ans = cost
		val = mid
print(val, ans)


(n, a) = (int(input()), list(map(int, input().split())))
mincost = None
if max(a) - min(a) <= 1:
	mincost = (0, a[0])
else:
	mincost = min([(sum(map(lambda x: 0 if x == k else abs(x - k) - 1, a)), k) for k in range(min(a) + 1, max(a))])
print(mincost[1], mincost[0])


n = int(input())
a = list(map(int, input().split()))
t = 0
mn = 1000000000
for i in range(1, 100):
	cur = 0
	for j in range(n):
		cur += max(0, abs(i - a[j]) - 1)
	if cur < mn:
		mn = cur
		t = i
print(t, mn)


from sys import stdin

def cal_cost(a: int, b: int) -> int:
	if abs(a - b) <= 1:
		return 0
	return abs(a - b) - 1
n = int(input())
l = list(map(int, stdin.readline().split()))
ans = float('inf')
op = 0
for i in range(min(l), max(l) + 1):
	temp = sum((cal_cost(k, i) for k in l))
	if temp < ans:
		ans = temp
		op = i
print(op, ans)


n = int(input())
cost1 = []
flag = 1
k = list(map(int, input().split()))
for i in range(1, 101):
	cost = 0
	for o in k:
		if o < i:
			cost = cost + abs(o - (i - 1))
		elif o > i:
			cost = cost + abs(o - (i + 1))
		else:
			cost += 0
	cost1.append(cost)
t = min(cost1)
print(cost1.index(t) + 1, t)


input()
(*l,) = map(int, input().split())
(m, p) = ([], sum(l))
for i in range(min(l), max(l) + 1):
	c = 0
	for j in l:
		if abs(j - i) > 1:
			c += abs(j - i) - 1
	if p > c:
		p = c
		f = i
print(f, p)


n = int(input())
L = [int(x) for x in input().split()]
S = sum(L)
best = 10 ** 10
ans = None
for i in range(1, 200):
	temp = 0
	for j in L:
		temp += min(abs(j - i - 1), abs(j - i), abs(j - i + 1))
	if best > temp:
		best = temp
		ans = i
print(ans, best)


n = int(input())
a = list(map(int, input().split()))
costs = {}
ed = max(a)

def choose(t, a):
	x = abs(t - a)
	y = abs(t + 1 - a)
	z = abs(t - 1 - a)
	return min(x, y, z)
for t in range(1, 101):
	c = 0
	for i in a:
		c += choose(t, i)
	costs[c] = t
mi = min(costs.keys())
print(costs[mi], mi)


n = int(input())
a = list(map(int, input().split()))
cost = 999999999
tf = 0
for t in range(1, 101):
	count = 0
	for i in range(n):
		count += max(abs(a[i] - t) - 1, 0)
	if count < cost:
		cost = count
		tf = t
print(tf, cost)


import math as ma
import sys
from sys import exit
from decimal import Decimal as dec
from itertools import permutations

def li():
	return list(map(int, input().split()))

def num():
	return map(int, input().split())

def nu():
	return int(input())
mm = 1000000007
t = 1
for it in range(t):
	n = nu()
	a = li()
	mx = 999999999999
	vv = -1
	for i in range(1, 101):
		s = 0
		for j in range(n):
			if a[j] < i:
				if i == 1:
					continue
				s += abs(a[j] - (i - 1))
			elif a[j] > i:
				s += abs(a[j] - (i + 1))
		if s < mx:
			vv = i
			mx = s
	print(vv, mx)


n = int(input())
a = list(map(int, input().split()))
maxi = 100000000
ans = -1
for t in range(1, 101):
	cur = 0
	for i in a:
		cur += min(abs(i - t), abs(i - t - 1), abs(i - t + 1))
	if cur < maxi:
		maxi = cur
		ans = t
print(ans, maxi)


x = input()
lst = list(map(int, input().split()))
lst.sort()
count = 0
ls = []
if int(x) >= 2 and lst[0] != lst[-1]:
	for i in range(lst[0], lst[-1]):
		for j in lst:
			if i != j:
				count += abs(i - j) - 1
		ls.append((i, count))
		count = 0
	(t, Min) = ls[0]
	for (i, j) in ls:
		if Min > j:
			t = i
			Min = j
else:
	t = lst[0]
	Min = 0
print(t, Min)


n = int(input())
a = [int(i) for i in input().split()]
t = 1
mins = 1000000
while t < 100:
	su = 0
	for e in a:
		if e > t:
			su += e - t - 1
		elif e < t:
			su += t - 1 - e
	if su < mins:
		mins = su
		res = t
	t += 1
print(res, mins)


R = lambda : map(int, input().split())
n = int(input())
L = list(R())
(t, res) = (0, 10 ** 5)
for i in range(1, 101):
	s = 0
	for j in L:
		if abs(j - i) > 1:
			s += abs(j - i) - 1
	if s < res:
		res = s
		t = i
print(t, res)


from sys import stdin, stdout
from collections import defaultdict
import math
I = stdin.readline
P = stdout.write
n = int(I())
arr = [int(x) for x in I().split()]
t = 1
ans = math.inf
for i in range(1, max(arr) + 1):
	now = 0
	for j in arr:
		if j < i:
			now += i - 1 - j
		elif j > i:
			now += j - i - 1
	if now < ans:
		ans = now
		t = i
print(t, ans)


n = int(input())
l = list(map(int, input().split()))
m = 9999999
t1 = 0
for t in range(1, 101):
	c = 0
	for i in l:
		if abs(i - t) > 1:
			c += min(abs(t - i), abs(abs(t - i) - 1))
	if c < m:
		t1 = t
		m = c
print(str(t1) + ' ' + str(m))


_max_a = 100
n = int(input())
a = list(map(int, input().split()))
answers = [sum((max(abs(a[i] - t) - 1, 0) for i in range(n))) for t in range(1, _max_a + 1)]
optimal_cost = min(answers)
print(answers.index(optimal_cost) + 1, optimal_cost)


n = int(input())
a = [int(i) for i in input().split()]
count = 1000000
for i in range(1, 101):
	cost = sum((0 if j == i else abs(i - j) - 1 for j in a))
	if cost < count:
		count = cost
		t = i
print(t, count)


n = int(input())
sticks = list(map(int, input().split()))
costs = []
for i in range(1, max(sticks) + 1):
	cost = 0
	for j in range(0, len(sticks)):
		cost += max(abs(i - sticks[j]) - 1, 0)
	costs.append(cost)
min_cost = min(costs)
print(costs.index(min_cost) + 1, min_cost)


n = int(input())
ai = list(map(int, input().split()))
ti = 0
mini = 10 ** 7
for t in range(1, 101):
	num = 0
	for i in ai:
		num += max(abs(i - t) - 1, 0)
	if num < mini:
		ti = t
		mini = num
print(ti, mini)


n = int(input())
a = list(map(int, input().split()))
t = -1
su = 1000 * 100 + 7
for i in range(min(a), max(a) + 1):
	psu = 0
	for j in a:
		if j > i + 1:
			psu += abs(j - i - 1)
		elif j < i - 1:
			psu += abs(j - i + 1)
	if psu < su:
		su = psu
		t = i
print(t, end=' ')
print(su)


n = int(input())
arr = list(map(int, input().split()))
(mn, mx) = (float('inf'), float('-inf'))
for a in arr:
	(mn, mx) = (min(mn, a), max(mx, a))
best_t = None
best_cost = float('inf')
for x in range(mn, mx + 1):
	sm = 0
	for a in arr:
		if abs(x - a) > 1:
			sm += abs(x - a) - 1
	if best_cost > sm:
		best_cost = sm
		best_t = x
print(*(best_t, best_cost))


n = int(input())
a = list(map(int, input().split()))
m = 100000000
k = -1
for i in range(1, 101):
	sum = 0
	for j in range(n):
		if a[j] != i:
			sum = abs(i - a[j]) - 1 + sum
	if sum < m:
		k = i
		m = sum
print(k, m)


n = int(input())
ans = 10 ** 18
val = -1
arr = list(map(int, input().split()))
for i in range(1, 102):
	valx = 0
	for j in arr:
		if abs(j - i) > 1:
			valx += abs(j - i) - 1
	if valx < ans:
		ans = valx
		val = i
print(val, ans)


n = int(input())
a = [int(x) for x in input().split()]
ans = -1
Sum = 999999999
for i in range(1, 100):
	tmp = 0
	for j in a:
		if abs(i - j) > 1:
			tmp += max(0, min(abs(j - (i - 1)), abs(j - (i + 1))))
	if tmp < Sum:
		Sum = tmp
		ans = i
print(ans, Sum)


TN = 1

def solution():
	n = int(input())
	a = list(map(int, input().split()))
	ans = [0 for i in range(100)]
	for t in range(1, 101):
		for i in range(n):
			if a[i] - t > 1:
				ans[t - 1] += a[i] - t - 1
			elif a[i] - t < -1:
				ans[t - 1] += t - 1 - a[i]
	ind = ans.index(min(ans))
	print(ind + 1, ans[ind])
while TN != 0:
	solution()
	TN -= 1


import sys
n = int(input())
a = list(map(int, input().split()))
mi = 0
mis = sys.maxsize
for t in range(1, 101):
	k = 0
	for i in a:
		if abs(i - t) > 1:
			k += abs(i - t) - 1
	if k < mis:
		mis = k
		mi = t
print(mi, mis)


a = int(input())
z = list(map(int, input().split()))
import math
mini = math.inf
inde = 0
for i in range(1, 101):
	count = 0
	for j in range(len(z)):
		if z[j] > i:
			count += z[j] - 1 - i
		elif z[j] < i:
			count += i - 1 - z[j]
	if count < mini:
		mini = count
		inde = i
print(inde, mini)


def main():
	n = int(input())
	arr = list(map(int, input().split()))
	min_t = -1
	min_cost = float('inf')
	for t in range(1, 102):
		cost = 0
		for i in arr:
			if abs(i - t) > 1:
				if i > t:
					cost += i - t - 1
				else:
					cost += t - 1 - i
		if cost < min_cost:
			min_cost = cost
			min_t = t
	print(min_t, min_cost)
main()


n = int(input())
lens = [int(x) for x in input().split()]
num___cost = [100 * 1001]
for i in range(1, 101):
	cost = sum([max(0, abs(i - x) - 1) for x in lens])
	num___cost.append(cost)
ans = min(enumerate(num___cost), key=lambda x: x[1])
print(*ans)


n = int(input())
ar = list(map(int, input().split()))
cl = []
for t in range(1, 101):
	cl.append(0)
	for n in ar:
		p = abs(n - t)
		if p != 0:
			p -= 1
		cl[t - 1] += p
print(cl.index(min(cl)) + 1, min(cl))


from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import defaultdict
from itertools import combinations
import functools
import sys
import math
MAX = sys.maxsize
MAXN = 10 ** 6 + 10
MOD = 10 ** 9 + 7

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def mhd(a, b, x, y):
	return abs(a - x) + abs(b - y)

def numIN():
	return map(int, sys.stdin.readline().strip().split())

def charIN():
	return sys.stdin.readline().strip().split()

def ncr(n, k):
	res = 1
	c = [0] * (k + 1)
	c[0] = 1
	for i in range(1, n + 1):
		for j in range(min(i, k), 0, -1):
			c[j] = (c[j] + c[j - 1]) % MOD
	return c[k]
n = int(input())
l = list(numIN())
mn = MAX
ft = -1
for i in range(1, 102):
	t = i
	ans = 0
	for j in range(n):
		if abs(l[j] - t) > 1:
			if l[j] > t:
				ans += l[j] - (t + 1)
			else:
				ans += t - 1 - l[j]
	if ans < mn:
		mn = ans
		ft = t
print(ft, mn)


n = int(input())
a = list(map(int, input().split()))
(anst, ans) = (0, 1000000)
for t in range(1, 101):
	tmp = 0
	for i in a:
		if i != t:
			tmp += abs(i - t) - 1
	if tmp < ans:
		ans = tmp
		anst = t
print(anst, end=' ')
print(ans)


import sys
n = int(input())
m = list(map(int, input().split(' ')))
m = sorted(m)
avg = m[n // 2]
minsum = 99999999
minavg = 99
for t in range(1, 101):
	su = 0
	for l in m:
		if abs(l - t) <= 1:
			continue
		if l < t:
			su += abs(t - l - 1)
		else:
			su += abs(l - t - 1)
	if su < minsum:
		minsum = su
		minavg = t
print(minavg, ' ', minsum)
pass


n = int(input())
a = list(map(int, input().split()))
m = sum(a) / n
dists = {}
for pm in range(min(a), max(a) + 1):
	c = 0
	for i in a:
		dist = abs(i - pm)
		if dist > 1:
			c += dist - 1
	dists[c] = pm
mk = min(dists.keys())
print(dists[mk], mk)


def cnt(a, t):
	s = 0
	for aa in a:
		if aa < t - 1:
			s += t - 1 - aa
		elif aa > t + 1:
			s += aa - (t + 1)
	return s
n = int(input())
a = list(map(int, input().split()))
mn = 10 ** 19
tt = 0
for t in range(1, 101):
	ss = cnt(a, t)
	if ss < mn:
		mn = ss
		tt = t
print(tt, mn)


n = int(input())
a = list(map(int, input().split()))
cost = 10 ** 10
tt = 0
for t in range(1, 101):
	c = 0
	for i in a:
		if abs(i - t) > 1:
			if i < t:
				c += t - i - 1
			elif i > t:
				c += i - t - 1
	if c < cost:
		tt = t
		cost = min(cost, c)
print(tt, cost)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	r = max(a)
	mini_count = 1000001
	k = -1
	for i in range(1, r + 1):
		temp = 0
		for j in a:
			if j < i:
				temp += abs(i - 1 - j)
			elif j > i:
				temp += abs(i + 1 - j)
		if temp < mini_count:
			mini_count = temp
			k = i
	print(k, mini_count)
main()


n = int(input())
arr = list(map(int, input().split()))

def solve(arr):
	minCost = 10 ** 5
	i = 1
	for mean in range(1, 101):
		cost = 0
		for num in arr:
			val = abs(num - mean)
			if val > 0:
				cost += val - 1
		if minCost > cost:
			minCost = cost
			i = mean
	return (i, minCost)
(mean, cost) = solve(arr)
print(mean, cost)


n = int(input())
a = [*map(int, input().split())]
ans = {}
for i in range(1, 101):
	temp = 0
	for j in a:
		if i == j:
			continue
		temp += min(abs(j - i - 1), abs(j - i + 1))
	ans[i] = temp
print(min(ans, key=ans.get), ans[min(ans, key=ans.get)])


def solve(arr, x):
	cost = 0
	for i in arr:
		if i == x:
			continue
		elif i < x:
			cost += abs(x - i - 1)
		else:
			cost += abs(x - i + 1)
	return cost
n = int(input())
arr = list(map(int, input().split()))
minn = 10 ** 100
index = 0
for i in range(1, 105):
	cost = solve(arr, i)
	if cost < minn:
		minn = cost
		index = i
print(index, minn)


n = int(input())
a = list(map(int, input().split()))
ans = 10000000000.0
for t in range(min(a), max(a) + 1):
	s = 0
	for i in a:
		s += min(abs(i - t), abs(i - t - 1), abs(i - t + 1))
	if s < ans:
		ans = s
		anst = t
print(anst, ans)


n = int(input())
a = [int(o) for o in input().split()]
ans = []
for i in range(1, 101):
	su = 0
	for j in range(n):
		su += min(abs(i - a[j]), abs(i + 1 - a[j]), abs(i - 1 - a[j]))
	ans.append([su, i])
lol = min(ans[:])
print(*lol[::-1])


import sys
import math

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

def read_int_list():
	return list(map(int, input().strip().split()))

def read_string():
	return input().strip()

def read_string_list(delim=' '):
	return input().strip().split(delim)
n = read_int()
sticks = read_int_list()
(min_cost, min_t) = (999999999, -1)
(mini, maxi) = (min(sticks), max(sticks))
for t in range(mini, maxi + 1):
	temp = 0
	for s in sticks:
		if s >= t + 1:
			temp += abs(s - t - 1)
		elif s <= t - 1:
			temp += abs(s - t + 1)
		else:
			temp += 0
	if temp < min_cost:
		min_t = t
		min_cost = temp
print(min_t, min_cost)


def chPathToThis(f=None):
	import os
	f = __file__ if f is None else f
	os.chdir(os.path.dirname(f))
fle = None

def input():
	global fle

	def inner():
		if fle is None:
			from sys import stdin
			for line in stdin:
				yield line
			raise EOFError
		else:
			for line in fle:
				yield line.replace('\r', '').replace('\n', '')
			raise EOFError
	o = inner()
	return next(o)

def main():
	n = int(input())
	a = [int(e) for e in input().split()]
	(at, aa) = (0, 66666666666)
	for t in range(1, 222):
		s = 0
		for i in a:
			s += max(abs(i - t) - 1, 0)
		if aa > s:
			(at, aa) = (t, s)
	print(at, aa)
try:
	import time, numpy
	chPathToThis(__file__)
	(begin, fle) = (time.clock(), open('pytest.txt'))
	main()
	fle.close()
	print(time.clock() - begin)
except ImportError:
	main()


n = int(input())
s = list(map(int, input().split()))
(a, b) = (-1, 188888)
for t in range(1, 101):
	mi = 0
	for i in range(n):
		mi += min(abs(s[i] - t), abs(s[i] - t - 1), abs(s[i] - t + 1))
	if b > mi:
		(a, b) = (t, mi)
print(a, b)


n = int(input())
a = list(map(int, input().split()))
sum_ = 100001
t = 0
for i in range(min(a), min(101, max(a) + 1)):
	sum1 = 0
	for j in a:
		if j > i:
			sum1 += j - i - 1
		elif j != i:
			sum1 += i - j - 1
	if sum1 < sum_:
		sum_ = sum1
		t = i
print('{} {}'.format(t, sum_))


n = int(input())
A = [int(x) for x in input().split()]

def f(A, t):
	S = 0
	for a in A:
		if abs(a - t) == 0:
			S += 0
		else:
			S += abs(a - t) - 1
	return S
t = min(range(1, 101), key=lambda x: f(A, x))
print(t, f(A, t))


n = int(input())
a = [int(s) for s in input().split()]
t = 0
min_s = 1000000
max_el = 0
for i in a:
	if i > max_el:
		max_el = i
for i in range(1, max_el + 1):
	s = 0
	for el in a:
		if el != i:
			s += abs(el - i) - 1
	if s < min_s:
		min_s = s
		t = i
print(t, min_s)


n = int(input())
arr = list(map(int, input().split()))
T = 1
min_value = 100 * 1000
for t in range(1, max(arr) + 1):
	temp = 0
	for i in arr:
		if i < t:
			temp += abs(i - t + 1)
		elif i > t:
			temp += abs(t + 1 - i)
	if temp < min_value:
		min_value = temp
		T = t
print(T, min_value)


n = int(input())
s = input()
s = s.split()
for i in range(n):
	s[i] = int(s[i])
answert = 0
answersum = 100000
for t in range(1, 100):
	sum = 0
	for j in range(n):
		if t - s[j] >= 1:
			sum += t - 1 - s[j]
		elif s[j] - t >= 1:
			sum += s[j] - 1 - t
	if sum < answersum:
		answersum = sum
		answert = t
print(answert, answersum)


n = int(input())
arr = [int(i) for i in input().split()]
m = 10 ** 9
c = 0
for i in range(1, 101):
	ans = 0
	for j in arr:
		if abs(i - j) > 1:
			ans += abs(i - j) - 1
	if ans < m:
		m = ans
		c = i
print(c, m)


n = int(input())
stick = list(map(int, input().split()))
d = []
for i in range(1, max(stick) + 1):
	s = 0
	for j in stick:
		s += min(abs(i - 1 - j), abs(i - j), abs(i + 1 - j))
	d.append((s, i))
d.sort()
print(d[0][1], d[0][0])


n = int(input())
a = list(map(int, input().split()))
b = []
maxi = 1000000
for i in range(max(a) + 1):
	count = 0
	for j in a:
		if j > i + 2:
			count += abs(j - (i + 2))
		elif j < i:
			count += abs(i - j)
	if count < maxi:
		maxi = count
	else:
		print(i, maxi)
		break


n = int(input())
a = list(map(int, input().split()))
q = sorted(a)
x = []
y = 0
z = []
for i in range(q[0], q[n - 1] + 1):
	for j in q:
		if abs(j - i) <= 1:
			continue
		else:
			y = y + abs(j - i) - 1
	z.append(y)
	x.append(i)
	y = 0
qq = z.index(min(z))
print(x[qq], min(z))


n = int(input())
A = list(map(int, input().split()))
m = 100000000000000
t = 1
for i in range(1, 101):
	x = m
	s = 0
	for j in range(0, n):
		if abs(i - A[j]) > 1:
			s += abs(i - A[j]) - 1
		else:
			continue
	m = min(m, s)
	if m != x:
		t = i
print(t, m)


import math

def abs(x):
	return int(math.fabs(x))
n = int(input())
a = list(map(int, input().strip().split()))

def get_cost(a, t):
	cost = 0
	for elem in a:
		if elem < t - 1:
			cost += t - 1 - elem
		elif elem > t + 1:
			cost += elem - t - 1
	return cost
mean = int(sum(a) / len(a))
possible_ts = list()
if mean > 1:
	possible_ts = [mean - 1, mean, mean + 1]
else:
	possible_ts = [mean, mean + 1]
possible_ts = list(range(1, max(a) + 1, 1))
possible_costs = [get_cost(a, t) for t in possible_ts]
min_cost = min(possible_costs)
min_idx = possible_costs.index(min_cost)
min_t = possible_ts[min_idx]
print('{} {}'.format(min_t, min_cost))


n = int(input())
a = [*map(int, input().split())]
mcost = 10 ** 8
ans = 0
for i in range(1, 101):
	tcost = 0
	for j in range(n):
		if a[j] > i:
			d = abs(a[j] - (i + 1))
		elif a[j] < i:
			d = abs(a[j] - (i - 1))
		else:
			d = 0
		tcost += d
	if tcost < mcost:
		(mcost, ans) = (tcost, i)
print(ans, mcost)


n = int(input())
a = [*map(int, input().split())]
a = sorted(a)
m = 100000
t = 0
for i in range(a[n - 1]):
	s = 0
	for b in a:
		if abs(b - i) <= 1:
			continue
		else:
			s += abs(b - i) - 1
	if s < m:
		m = s
		t = i
if t == 0:
	t = 1
print(t, m)


n = int(input())
a = list(map(int, input().split()))
optimal_t = 0
min_changes = 1000000
for t in range(1, 100 + 1):
	changes = 0
	for ai in a:
		if abs(ai - t) > 1:
			changes += abs(ai - t) - 1
	if changes < min_changes:
		min_changes = changes
		optimal_t = t
print(optimal_t, min_changes)


import sys, math, string
input = sys.stdin.readline
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
n = int(input())
l = L()
m = 9999999
a = 0
for i in range(1, 1000):
	t = 0
	for j in range(n):
		if l[j] > i:
			t = t + l[j] - i - 1
		elif l[j] < i:
			t = t + i - l[j] - 1
	if t < m:
		m = t
		a = i
print(a, m)


n = int(input())
s = [int(i) for i in input().split()]
cnt = 0
mini = float('inf')
for i in range(1, max(s) + 1):
	cnt = 0
	for j in range(n):
		if abs(i - s[j]) > 1:
			cnt += abs(i - s[j]) - 1
	if cnt < mini:
		a = i
		mini = cnt
print(a, mini)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
a = []
for t in range(1, 101):
	tot = 0
	for item in arr:
		if abs(item - t) >= 1:
			tot += abs(item - t) - 1
	a.append((tot, t))
a.sort()
print(a[0][1], a[0][0])


n = int(input())
a = list(map(int, input().split()))
minc = 1000000
mt = 0
for t in range(1, 101):
	cnt = 0
	for i in range(n):
		if a[i] != t:
			cnt += abs(a[i] - t) - 1
	if cnt <= minc:
		minc = cnt
		mt = t
print(mt, minc)


n = int(input())
a = list(map(int, input().split()))
ans = 1e+18
ans_t = -1
for t in range(1, 101):
	curr = 0
	for el in a:
		if el > t:
			curr += el - (t + 1)
		elif el < t:
			curr += t - 1 - el
	if curr < ans:
		ans = curr
		ans_t = t
print(ans_t, ans)


n = int(input())
A = list(map(int, input().split()))
(ft, fc) = (None, None)
for t in range(1, 101):
	tc = 0
	for a in A:
		tc += max(0, abs(a - t) - 1)
	if not ft or fc > tc:
		(ft, fc) = (t, tc)
print(str(ft) + ' ' + str(fc))


n = int(input())
a = list(map(int, input().split()))
min1 = 1000001
c = 0
for i in range(1, 101):
	sum1 = 0
	for j in a:
		if abs(j - i) <= 1:
			continue
		sum1 = sum1 + abs(j - i) - 1
	if min1 > sum1:
		min1 = sum1
		c = i
print(c, min1)


import math
n = int(input())
a = list(map(int, input().split()))
mn = min(a)
mx = max(a)
x = []
for i in range(mn, mx + 1):
	cost = 0
	for elem in a:
		if elem == i or elem == i + 1 or elem == i - 1:
			c = 0
		elif elem < i:
			c = i - elem - 1
		else:
			c = elem - i - 1
		cost += c
	x.append((cost, i))
if len(x) == 0:
	print(a[0], 0)
else:
	m = min(x)
	print(m[1], m[0])


m = 1000000
k = 0
s = 0
n = int(input())
L = [int(i) for i in input().split()]
for i in range(1, 101):
	s = 0
	for j in L:
		if i != j:
			s += abs(i - j) - 1
	if s < m:
		k = i
		m = s
print(k, m)


import math
n = int(input())
l = input().split()
l = list(map(int, l))
l.sort()
x = max(l)
c = 0
costs = []
for i in range(1, x + 1):
	c = 0
	for j in l:
		c = c + abs(i - j)
		if abs(i - j) != 0:
			c = c - 1
	costs.append(c)
y = min(costs)
ans = costs.index(y)
print(ans + 1, y)


from math import *
n = int(input())
a = sorted(list(map(int, input().split())))
mt = 1
ms = 0
for i in a:
	if i > mt:
		ms += i - mt - 1
	elif i < mt:
		ms += mt - i - 1
for t in range(2, 101):
	s = 0
	for i in a:
		if i > t:
			s += i - t - 1
		elif i < t:
			s += t - i - 1
	if s < ms:
		ms = s
		mt = t
print(mt, ms)


import time
input()
_inp = list(map(int, input('').split()))
mi = min(_inp) + 1
i = mi
ma = max(_inp)

def find_the_last(_inp):
	result = 0
	for y in _inp:
		if abs(i - y) > 1:
			result += abs(i - y) - 1
	return result
result = find_the_last(_inp)
while i < ma:
	pre_result = find_the_last(_inp)
	if pre_result < result:
		(result, mi) = (pre_result, i)
	i += 1
print(mi, result)


n = int(input())
arr = list(map(int, input().split()))
cost_min = sum(arr)
hold = 0
for t in range(1, max(arr) + 1):
	target = t
	cost = 0
	for j in arr:
		if j < target - 1 or j > target + 1:
			if j > target:
				cost += j - target - 1
			if j < target:
				cost += target - 1 - j
	if cost < cost_min:
		cost_min = cost
		hold = target
print(hold, cost_min)


(MinCost, BestT, N, Sticks) = (10 ** 9, 10 ** 9, int(input()), list(map(int, input().split())))
for i in range(min(Sticks), max(Sticks) + 1):
	Cost = sum((0 if abs(Sticks[j] - i) <= 1 else abs(Sticks[j] - i) - 1 for j in range(N)))
	if Cost < MinCost:
		(MinCost, BestT) = (Cost, i)
print(BestT, MinCost)


n = int(input())
a = list(map(int, input().split()))
a.sort()
t = a[len(a) // 2]
t_min = -1
m_min = -1
for tt in (t - 1, t, t + 1):
	if tt < 1:
		continue
	m = 0
	for x in a:
		m += min(abs(abs(tt - x) - 1), abs(tt - x))
	if m < m_min or m_min == -1:
		t_min = tt
		m_min = m
print(t_min, m_min)


import math
n = int(input())
a = list(map(int, input().split()))
sm = 100000000
t = 100
for x in range(1, 200):
	s = 0
	for i in range(len(a)):
		if abs(a[i] - x) > 1:
			s = s + abs(a[i] - x) - 1
	if sm > s:
		t = x
		sm = s
print(t, sm)


def mergeSort(arr):
	if len(arr) > 1:
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		mergeSort(L)
		mergeSort(R)
		i = j = k = 0
		while i < len(L) and j < len(R):
			if L[i] < R[j]:
				arr[k] = L[i]
				i += 1
			else:
				arr[k] = R[j]
				j += 1
			k += 1
		while i < len(L):
			arr[k] = L[i]
			i += 1
			k += 1
		while j < len(R):
			arr[k] = R[j]
			j += 1
			k += 1
n = int(input())
nums = input().split()
for i in range(n):
	nums[i] = int(nums[i])
MAX_SUM = 100001
mergeSort(nums)
median = (nums[n // 2] + nums[(n - 1) // 2]) // 2
best_num = -1
best_sum = MAX_SUM
for i in range(median - 1, median + 2):
	next_sum = 0
	for j in range(n):
		if nums[j] < i - 1:
			next_sum += i - 1 - nums[j]
		elif nums[j] > i + 1:
			next_sum += nums[j] - i - 1
	if next_sum < best_sum and i > 0:
		best_sum = next_sum
		best_num = i
print(str(best_num) + ' ' + str(best_sum))


n = int(input())
l = [int(i) for i in input().split()]
l.sort()

def dis(i, t):
	return min(abs(i - t), abs(i - t + 1), abs(i - t - 1))

def f(l, t):
	ret = 0
	for i in l:
		ret += dis(i, t)
	return ret
m = [f(l, t) for t in range(l[0], l[-1] + 1)]
t = l[0] + m.index(min(m))
print(t, min(m))


import math
n = int(input())
a = list(map(int, input().split()))
x = min(a)
y = max(a)
ans1 = 10 ** 9
ans2 = 10 ** 9
for j in range(1, 100):
	ans = 0
	for i in range(n):
		if a[i] > j + 1:
			ans = ans + a[i] - j - 1
		elif a[i] < j - 1:
			ans = ans + j - 1 - a[i]
	if ans < ans2:
		ans2 = ans
		ans1 = j
print(ans1, ans2)


n = int(input())
l = list(map(int, input().split()))
min1 = float('inf')
t = 0
for i in range(1, 101):
	sum1 = 0
	for j in l:
		sum1 = sum1 + min(abs(j - i - 1), abs(j - i + 1), abs(j - i))
	if min1 > sum1:
		t = i
		min1 = sum1
print(t, min1)


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(n,) = I()
l = I()
tt = 1
res = MOD
for t in range(1, 101):
	ans = 0
	for i in l:
		if abs(i - t) <= 1:
			continue
		if i < t:
			ans += t - i - 1
		else:
			ans += i - t - 1
	if ans < res:
		res = ans
		tt = t
print(tt, res)


n = int(input())
arr = list(map(int, input().strip().split()))
ans = [0] * 100
for a in range(1, 101):
	s = 0
	for x in range(n):
		curr = abs(arr[x] - a)
		if curr > 1:
			s += curr - 1
	ans[a - 1] = s
res = min(ans)
t = ans.index(res) + 1
print(t, res)


n = int(input())
arr = list(map(int, input().split()))
min1 = 1000
max1 = 0
for ele in arr:
	if ele < min1:
		min1 = ele
	if ele > max1:
		max1 = ele
ans1 = 1000000
diff = ans2 = 0
for i in range(min1, max1 + 1):
	diff = 0
	for ele in arr:
		if abs(ele - i) <= 1:
			diff += 0
		elif i < ele:
			diff += abs(ele - i - 1)
		else:
			diff += abs(ele - i + 1)
	if ans1 > diff:
		ans1 = diff
		ans2 = i
print(ans2, ans1)


n = int(input())
a = [int(x) for x in input().split()]
b = []
for x in range(1, 101):
	c = 0
	for i in range(n):
		c += min(abs(x - a[i] - 1), abs(x - a[i] + 1), abs(x - a[i]))
	b.append(c)
print(b.index(min(b)) + 1, min(b))


def read_nums():
	return [int(x) for x in input().split()]

def compute_min_cost(t, nums):
	res = 0
	for num in nums:
		if abs(t - num) <= 1:
			continue
		res += abs(num - t) - 1
	return res

def main():
	_ = read_nums()
	costs = []
	nums = read_nums()
	for t in range(1, 101):
		min_cost = compute_min_cost(t, nums)
		costs.append((t, min_cost))
	(t, cost) = sorted(costs, key=lambda x: x[1])[0]
	print(t, cost)

def __starting_point():
	main()
__starting_point()


import bisect

def solve(xs):
	xs = sorted(xs)
	sums = [0]
	for x in xs:
		sums.append(sums[-1] + x)
	t = None
	best = float('inf')
	for mid in range(1, 100 + 1):
		lower_end = bisect.bisect_left(xs, mid - 1)
		upper_begin = bisect.bisect_right(xs, mid + 1, lower_end)
		lower_cost = (mid - 1) * lower_end - sums[lower_end]
		upper_cost = sums[-1] - sums[upper_begin] - (mid + 1) * (len(xs) - upper_begin)
		cost = lower_cost + upper_cost
		if cost < best:
			best = cost
			t = mid
	return (t, best)
n = int(input())
xs = list(map(int, input().split()))[:n]
(t, cost) = solve(xs)
print(t, cost)


def sticks(a):
	MIN_VAL = 1000 * 100
	T = 1
	for t in range(1, max(a) + 1):
		temp = 0
		for i in a:
			if i < t:
				temp += abs(t - 1 - i)
			elif i > t:
				temp += abs(i - t - 1)
		if temp < MIN_VAL:
			MIN_VAL = temp
			T = t
	print(T, MIN_VAL)
n = int(input())
a = list(map(int, input().split()))
sticks(a)


n = int(input())
seq = sorted(map(int, input().split()))
ans = (10 ** 8, 0)
for t in range(seq[0], seq[-1] + 1):
	cost = 0
	for j in range(len(seq)):
		cost += abs(seq[j] - t) - 1 if seq[j] != t else 0
	ans = min(ans, (cost, t))
print(' '.join(map(str, ans[::-1])))


n = int(input())
input1 = input().split(' ')
data = []
maximum = -1
for i in range(n):
	data.append(int(input1[i]))
	if data[i] > maximum:
		maximum = data[i]
min_t = -1
min_cost = 100000
for i in range(1, maximum + 1):
	acu = 0
	for j in range(n):
		acu += abs(data[j] - i) - 1 if abs(data[j] - i) > 1 else 0
	if acu < min_cost:
		min_cost = acu
		min_t = i
print('%d %d' % (min_t, min_cost))


a = int(input())
b = list(map(int, input().split()))
b.sort()
t = 0
c = []
for i in range(1, b[a - 1] + 1):
	t = 0
	for j in b:
		if j != i:
			t = t + abs(j - i) - 1
		else:
			t = t + abs(j - i)
	c.append([t, i])
c.sort()
print(c[0][1], c[0][0])


n = int(input())
ain = [int(x) for x in input().split()]
ans = []
for t in range(101):
	sum = 0
	for i in ain:
		sum += max(0, abs(t - i) - 1)
	ans.append(sum)
t = ans[1:].index(min(ans)) + 1
print(t, ans[t])


n = int(input())
mas = list(map(int, input().split()))
ans = []
for t in range(1, 101):
	a = 0
	for i in mas:
		if i > t:
			a += i - t - 1
		elif i < t:
			a += t - i - 1
	ans.append([a, t])
print(min(ans)[1], min(ans)[0])


n = int(input())
m = [int(i) for i in input().split()]
res = 10000000
res1 = 0
for i in range(1, 101):
	bfsm = 0
	for j in range(len(m)):
		if m[j] > i:
			bfsm += m[j] - i - 1
		elif m[j] < i:
			bfsm += i - 1 - m[j]
	if bfsm < res:
		res = bfsm
		res1 = i
print(res1, res)


n = int(input())
nums = [*map(int, input().split())]
mx = max(nums)
mn = min(nums)
mn_t = 0
mn_cost = 100000
for t in range(mn, mx + 1):
	cost = 0
	for num in nums:
		if t > num:
			cost += t - num - 1
		elif t < num:
			cost += num - t - 1
	if mn_cost > cost:
		mn_cost = cost
		mn_t = t
print(mn_t, mn_cost)


n = int(input())
mini = 1000000000000000
p = input().rstrip().split(' ')
for i in range(1, 500):
	ans = 0
	for j in range(0, len(p)):
		A = i
		B = int(p[j])
		if abs(B - A) <= 1:
			continue
		else:
			C = abs(B - A) - 1
			ans += C
	if ans < mini:
		mini = ans
		G = i
print(G, mini)


import math

def minStepsForANumber(arr, n):
	res = 0
	for i in arr:
		if i > n:
			res += i - n - 1
		if i < n:
			res += n - i - 1
	return res
n = int(input())
arr = list(map(int, input().split()))
minT = None
minSteps = math.inf
for i in range(1, 101):
	stepsReq = minStepsForANumber(arr, i)
	if stepsReq < minSteps:
		minT = i
		minSteps = stepsReq
print(minT, minSteps)


from sys import stdin, stdout

def main():
	n = int(stdin.readline())
	vals = [int(i) for i in stdin.readline().split()]
	best_t = 1
	best_c = 1000000
	for t in range(1, 101):
		cost = 0
		for i in range(n):
			v = vals[i]
			if v < t - 1:
				cost += abs(v - (t - 1))
			elif v > t + 1:
				cost += abs(v - (t + 1))
		if cost < best_c:
			best_t = t
			best_c = cost
	stdout.write(str(best_t) + ' ' + str(best_c) + '\n')
main()


n = int(input())
p = list(map(int, input().split()))

def main(guess):
	t = guess
	change = []
	for i in p:
		if t - 1 <= i <= t + 1:
			change.append(0)
		elif i < t - 1:
			change.append(t - 1 - i)
		else:
			change.append(i - (t + 1))
	return sum(change)
array = []
for guess in range(min(p), max(p) + 1):
	array.append([guess, main(guess)])
print(' '.join(map(str, sorted(array, key=lambda t: t[1])[0])))


n = int(input())
a = list(map(int, input().split()))
s = 123454321
for t in range(1, 101):
	res = 0
	for i in range(0, n):
		res += min(abs(t - 1 - a[i]), abs(t + 1 - a[i]), abs(t - a[i]))
	if s > res:
		s = res
		t1 = t
print(t1, s)


def get():
	return list(map(int, input().split()))

def check(a, x):
	f = 0
	for i in a:
		if i > x:
			f += i - x - 1
		elif i < x:
			f += x - i - 1
	return f
n = int(input())
a = get()
f = min(a)
b = []
for i in range(min(a), max(a) + 1):
	b += [check(a, i)]
g = b.index(min(b))
print(g + f, b[g])


n = int(input())
a = list(map(int, input().split()))
ans = 234567891
ind = 0
for i in range(1, 101):
	temp = 0
	for j in range(0, n):
		b = abs(a[j] - i)
		if b > 0:
			temp += b - 1
	if temp < ans:
		ans = temp
		ind = i
print(ind, ans)


(n, arr) = (int(input()), list(map(int, input().split())))

def find_cost(arr, t):
	cost = 0
	for x in arr:
		if x == t:
			continue
		elif x < t:
			cost += t - x - 1
		else:
			cost += x - t - 1
	return cost
(small, big) = (min(arr), max(arr))
cost = [[t, find_cost(arr, t)] for t in range(small, big + 1)]
best = min(cost, key=lambda x: x[1])
print(*best)


def A():
	n = int(input())
	a = [int(x) for x in input().split()]
	cost = float('inf')
	ans = min(a)
	for t in range(min(a), max(a) + 1):
		aux = 0
		for x in a:
			if abs(x - t) <= 1:
				continue
			aux += abs(x - t) - 1
		if aux < cost:
			ans = t
			cost = aux
	print('{} {}'.format(ans, cost))
A()


def solve(n, lengths):
	counters = [0] * 100
	for l in lengths:
		counters[l - 1] += 1
	ptr_l = -1
	ptr_r = 100
	(c_l, c_r) = (0, 0)
	while ptr_r - ptr_l > 2:
		if c_l <= c_r:
			ptr_l += 1
			c_l += counters[ptr_l]
		else:
			ptr_r -= 1
			c_r += counters[ptr_r]
	center_index = ptr_l + 1
	center_length = center_index + 1
	cost = sum(((ptr_l - i) * counters[i] for i in range(ptr_l))) + sum(((i - ptr_r) * counters[i] for i in range(ptr_r + 1, 100)))
	return (center_length, cost)

def main():
	n = int(input())
	lengths = list(map(int, input().split()))
	result = solve(n, lengths)
	print(' '.join(map(str, result)))
main()


from collections import *
n = int(input())
T = [int(x) for x in input().split()]
(Min, Max) = (min(T), max(T))
Cnt = namedtuple('Cnt', ['x', 'y'])
cnt = Cnt(0, 2147483647)
for i in range(Min, Max + 1):
	temp = 0
	for each in T:
		if each > i:
			temp += each - i - 1
		elif each < i:
			temp += i - each - 1
	if temp < cnt.y:
		cnt = Cnt(i, temp)
print(cnt.x, cnt.y)


import sys
n = int(input())
l1 = list(map(int, input().split()))
l2 = [0] * 101
l2[0] = sys.maxsize
for i in range(1, 101):
	cost = 0
	for j in range(n):
		if abs(l1[j] - i) > 1:
			cost += abs(l1[j] - i) - 1
	l2[i] = cost
x = min(l2[1:len(l2)])
print(l2.index(x), x)


n = int(input())
ar = list(map(int, input().split()))

def f(i):
	ans = 0
	for e in ar:
		if e == i:
			continue
		else:
			ans += abs(e - i) - 1
	return ans
a = float('inf')
b = 0
for x in range(1, 1001):
	if f(x) < a:
		a = f(x)
		b = x
print(b, a)


from math import inf

def cost(arr, t):
	c = 0
	for ele in arr:
		if abs(ele - t) > 1:
			if ele > t:
				c += ele - (t + 1)
			else:
				c += t - (ele + 1)
	return c
n = int(input().strip())
arr = list(map(int, input().strip().split()))
maxi = max(arr)
best_t = 0
min_cost = inf
for t in range(1, maxi + 1):
	curr_cost = cost(arr, t)
	if curr_cost < min_cost:
		min_cost = curr_cost
		best_t = t
print(best_t, min_cost)


n = int(input())
l = list(map(int, input().split()))
maxx = 10000000000
cur = 0
for i in range(1, 101):
	now = 0
	for j in range(n):
		if l[j] < i:
			now += i - l[j] - 1
		elif l[j] > i:
			now += l[j] - i - 1
	if now < maxx:
		maxx = now
		cur = i
print(cur, maxx)


n = int(input())
l = input().split()
l = list(map(int, l))
l.sort()
t = l[0] + 1
c = 0
for i in l:
	if i > t + 1:
		c = c + i - t - 1
	elif i < t - 1:
		c = c + t - i - 1
x = t
for t in range(l[0] + 2, l[-1]):
	c1 = 0
	for i in l:
		if i > t + 1:
			c1 = c1 + i - t - 1
		elif i < t - 1:
			c1 = c1 + t - i - 1
	if c1 <= c:
		x = t
		c = c1
	else:
		pass
print(x, c)


n = int(input())
a = [int(s) for s in input().split()]
mi = min(a)
ma = max(a)
s = 1000000
imi = 0
for i in range(mi, ma + 1):
	s1 = 0
	for j in range(n):
		s1 += abs(a[j] - i)
		if a[j] != i:
			s1 -= 1
	if s1 < s:
		s = s1
		imi = i
print(imi, s)


a = int(input())
b = list(map(int, input().split()))
t = sum(b)
x = b[:]
y = b[:]
z = b[:]
j = []
k = []
for u in range(1, 101):
	score_x = 0
	for num in x:
		if abs(num - u) > 1:
			score_x += min(abs(num - u), abs(num - (u + 1)), abs(num - (u - 1)))
	j.append((score_x, u))
j.sort()
k.append(j[0][1])
k.append(j[0][0])
print(*k)


n = int(input())
a = list(map(int, input().split()))
min = 999999
sum = 0
min_t = 0
a.sort()
for i in range(a[0], a[-1] + 1):
	for j in a:
		dis = abs(j - i)
		if dis >= 1:
			dis -= 1
		sum += dis
	if sum < min:
		min = sum
		min_t = i
	sum = 0
print(min_t, min)


n = int(input())
l = [int(x) for x in input().split()]
value = 0
inc = 10 ** 10
for t in range(1, 105):
	g = 0
	for i in range(n):
		g += max(0, abs(l[i] - t) - 1)
	if g < inc:
		inc = g
		value = t
print(value, inc)


n = int(input())
a = list(map(int, input().split()))
m = 102 * (n + 1)
for i in range(1, 101):
	k = i
	ans = 0
	for j in range(n):
		if k < a[j]:
			ans += a[j] - (k + 1)
		elif k == a[j]:
			ans += 0
		else:
			ans += k - 1 - a[j]
	if m > ans:
		m = ans
		t = k
print(t, m)


n = int(input())
a = list(map(int, input().split()))
ans = 10 ** 9
fin = 0
for i in range(1, 101):
	x = 0
	for j in range(n):
		if i > a[j] + 1:
			x += i - (a[j] + 1)
		elif i < a[j] - 1:
			x += a[j] - 1 - i
	if x < ans:
		fin = i
		ans = x
print(fin, ans)


n = int(input())
x = list(map(int, input().split()))
t = 1
min_sum = 10 ** 10
min_t = 0
for i in range(max(x)):
	total_sum = 0
	for j in range(n):
		if abs(x[j] - t) > 1:
			total_sum += abs(x[j] - t) - 1
	if total_sum < min_sum:
		min_t = t
		min_sum = total_sum
	t += 1
print(min_t, min_sum)


import math

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
n = ii()
a = li()
cost = 10000000
index = -1
for i in range(1, 101):
	c = 0
	for j in range(n):
		if i > a[j] + 1:
			c += i - a[j] - 1
		elif i < a[j] - 1:
			c += a[j] - 1 - i
	if cost > c:
		cost = c
		index = i
print(str(index) + ' ' + str(cost))


n = int(input())
a = [int(v) for v in input().split()]
a.sort()

def cost1(v, t):
	if v < t - 1:
		return t - 1 - v
	elif v > t + 1:
		return v - (t + 1)
	else:
		return 0
best_t = None
best_cost = 9999999999999
for t in range(1, 101):
	cost = sum((cost1(v, t) for v in a))
	if cost < best_cost:
		best_cost = cost
		best_t = t
print(best_t, best_cost)


n = int(input())
arr = [int(i) for i in input().split()]
cost = 10000000
tmp = 0
for t in range(1, 101):
	c = 0
	count = 0
	for i in range(len(arr)):
		c += min(min(abs(arr[i] - t), abs(arr[i] - t - 1)), abs(arr[i] - t + 1))
	if c < cost:
		cost = c
		tmp = t
print(tmp, cost, sep=' ')


from sys import stdin, stdout
from math import sin, tan, cos, pi, atan2, sqrt, acos, atan, factorial
from random import randint
n = int(stdin.readline())
vl = list(map(int, stdin.readline().split()))
ans = float('inf')
c = 0
for v in range(1, 101):
	cnt = 0
	for i in range(n):
		if vl[i] >= v:
			cnt += max(vl[i] - v - 1, 0)
		else:
			cnt += max(v - vl[i] - 1, 0)
	if cnt < ans:
		c = v
	ans = min(ans, cnt)
stdout.write(str(c) + ' ' + str(ans))


n = int(input())
a = list(map(int, input().split()))
(t, ans, p) = (1, 1, float('inf'))
while t <= 100:
	summ = 0
	for item in a:
		cur = 0
		if item > t + 1:
			cur = item - (t + 1)
		elif item < t - 1:
			cur = t - 1 - item
		summ += cur
	if summ < p:
		p = summ
		ans = t
	t += 1
print(ans, p)


from sys import stdin
n = int(stdin.readline().strip())
s = list(map(int, stdin.readline().strip().split()))
s.sort()
ans = 10 ** 20
t1 = -1
for t in range(1, 101):
	aux1 = 0
	for j in range(n):
		aux = 102
		aux = min(aux, abs(1 + t - s[j]))
		aux = min(aux, abs(t - 1 - s[j]))
		aux = min(aux, abs(t - s[j]))
		aux1 += aux
	if aux1 < ans:
		ans = aux1
		t1 = t
print(t1, ans)


n = int(input())
l = list(map(int, input().split()))
m = 10000000
ans = 1
for i in range(1, 101):
	s = 0
	for j in l:
		s += max(0, abs(j - i) - 1)
	if s < m:
		m = s
		ans = i
print(ans, m)


input()
(*l,) = map(int, input().split())
(m, p) = ([], [])
for i in range(min(l), max(l) + 1):
	c = 0
	for j in l:
		if abs(j - i) > 1:
			c += abs(j - i) - 1
	m.append(c)
	p.append(i)
print(p[m.index(min(m))], min(m))


import copy
import itertools

def powmod(x, p, m):
	if p <= 0:
		return 1
	if p <= 1:
		return x % m
	return powmod(x * x % m, p // 2, m) * (x % m) ** (p % 2) % m

def to_basex(num, x):
	while num > 0:
		yield (num % x)
		num //= x

def from_basex(it, x):
	ret = 0
	p = 1
	for d in it:
		ret += d * p
		p *= x
	return ret

def core():
	n = int(input())
	a = [int(x) for x in input().split()]
	ans = (None, 10 ** 10)
	for t in range(2, 100):
		cost = 0
		for ai in a:
			if ai != t:
				cost += abs(ai - t) - 1
		if cost < ans[1]:
			ans = (t, cost)
	print(*ans)
core()


import random
import operator
n = map(int, input())
arr = list(map(int, input().split()))
cost_ls = []
(min_arr, max_arr) = (min(arr), max(arr))
found = False
for t in range(min_arr, max_arr + 1):
	cost = 0
	for a in arr:
		if abs(a - t) > 1:
			cost += abs(a - t) - 1
	if cost == 0:
		print(str(t) + ' ' + str(cost))
		found = True
		break
	else:
		cost_ls.append([cost, t])
if not found:
	result = min(cost_ls, key=operator.itemgetter(0))
	print(str(result[1]) + ' ' + str(result[0]))


n = int(input())
s = input()
s = [int(x) for x in s.split()]
ans = 1000000
for t in range(1, 101):
	summ_cost = 0
	for i in range(len(s)):
		if s[i] > t:
			b = s[i] - (t + 1)
		elif s[i] < t:
			b = t - 1 - s[i]
		else:
			b = 0
		summ_cost += b
	if summ_cost < ans:
		ans = summ_cost
		ans_t = t
print(ans_t, ans)


n = int(input())
a = [int(i) for i in input().split()]
mi = 10 ** 8
x = -1
for i in range(1, 111):
	s = 0
	for j in range(n):
		if not i - 1 <= a[j] <= i + 1:
			if a[j] < i - 1:
				z = i - 1 - a[j]
			else:
				z = a[j] - i - 1
			s += z
	if s < mi:
		mi = s
		x = i
print(x, mi)


n = int(input())
a = list(map(int, input().split()))
costs = [sum((max(abs(a[i] - t) - 1, 0) for i in range(n))) for t in range(1, 101)]
optimal_cost = min(costs)
print(costs.index(optimal_cost) + 1, optimal_cost)


import sys
import math
import itertools
import functools
import collections
import operator

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
n = ii()
a = li()
ans = 10 ** 6
t = 0
for i in range(1, 101, 1):
	ts = 0
	for j in range(n):
		if a[j] < i:
			ts += i - 1 - a[j]
		elif a[j] > i:
			ts += a[j] - i - 1
	if ts < ans:
		t = i
		ans = ts
print(t, ans)


n = int(input())
a = [int(i) for i in input().split()]
min_s = 1000000
for t in range(1, 101):
	s = 0
	for i in range(n):
		s += min(abs(a[i] - t - 1), abs(a[i] - t), abs(a[i] - t + 1))
	if s < min_s:
		min_s = s
		min_t = t
print(min_t, min_s)


n = int(input())
l = list(map(int, input().split()))
m = max(l)
min = 100000000
for p in range(1, m + 1):
	sum = 0
	for i in l:
		if i < p:
			sum += p - i - 1
		elif i > p:
			sum += i - p - 1
	if sum < min:
		min = sum
		p1 = p
print(p1, min)


num_sticks = int(input())
stick_lengths = list(map(int, input().split()))
min_t = 0
min_cost = sum(stick_lengths)
for t in range(min(stick_lengths), max(stick_lengths) + 1):
	cost = 0
	for stick_length in stick_lengths:
		if abs(stick_length - t) > 1:
			cost += abs(stick_length - t) - 1
	if cost < min_cost:
		min_cost = cost
		min_t = t
print(min_t, min_cost)


n = int(input())
a = list(map(int, input().split()))
ans = 10 ** 8
ansi = 0
for i in range(1, 101):
	tmp = sum((min(abs(i - t - 1), abs(i - t + 1), abs(i - t)) for t in a))
	if tmp < ans:
		ans = tmp
		ansi = i
print(ansi, ans)


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return len(set(factors))

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def printp(p):
	for i in p:
		print(i)
MOD = 10 ** 9 + 7
T = 1
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	if n == 1:
		print(a[0], 0)
		continue
	a.sort()
	ans = inf
	for t in range(1, 101):
		c = 0
		for i in range(n):
			if a[i] < t - 1:
				c += t - 1 - a[i]
			elif a[i] > t + 1:
				c += a[i] - t - 1
		if c < ans:
			tf = t
			ans = c
	print(tf, ans)


n = int(input())
data = [int(x) for x in input().split()]
data.sort()
pos = len(data) // 2
(val, cost) = (0, 1000000000000)
for q in range(1, 110):
	temp_val = q
	temp_cost = 0
	for w in range(n):
		if data[w] > q + 1:
			temp_cost += data[w] - q - 1
		elif data[w] < q - 1:
			temp_cost += q - 1 - data[w]
	if temp_cost < cost:
		cost = temp_cost
		val = q
print(val, cost)


import math
n = int(input())
a = [int(i) for i in input().split()]
max = 10 ** 9
flag = 0
for i in range(1, 101):
	sum = 0
	for j in range(0, len(a)):
		e = abs(a[j] - i) - 1
		if e <= 0:
			e = 0
		sum = sum + e
	if sum < max:
		max = sum
		flag = i
print(flag, max)


__author__ = 'Esfandiar'
n = int(input())
a = sorted(list(map(int, input().split())))
ans = 0
M = 100000000000.0
for t in range(1, 101):
	Cost = 0
	for j in range(n):
		Cost += max(abs(t - a[j]) - 1, 0)
	if Cost < M:
		M = Cost
		ans = t
print(ans, M)


a = int(input())
sticks = list(map(int, input().split()))
minn = []
for t in range(1, 101):
	minn.append(0)
	for a in sticks:
		p = abs(a - t)
		if p != 0:
			p -= 1
		minn[t - 1] += p
print(minn.index(min(minn)) + 1, min(minn))


n = int(input())
a = list(map(int, input().split()))
ans = None
for t in range(1, 1001):
	anss = 0
	for i in a:
		anss += min(abs(i - t), abs(i - (t - 1)), abs(i - (t + 1)))
	if ans is None:
		ans = [anss, t]
	elif anss < ans[0]:
		ans = [anss, t]
print(*ans[::-1])


import math
from decimal import Decimal
import heapq

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)
(n, a) = na()
mx = 999999999999999999999
ans = 0
for t in range(1, 151):
	tc = 0
	for i in range(n):
		if a[i] == t:
			continue
		else:
			tc += abs(a[i] - t) - 1
	if tc < mx:
		mx = tc
		ans = t
print(ans, mx)


n = int(input())
a = [int(x) for x in input().split()]
min_cost = 10 ** 9
best_t = 10 ** 9
for t in range(1, 101):
	cost = 0
	for l in a:
		cost += max(abs(l - t) - 1, 0)
	if cost < min_cost:
		min_cost = cost
		best_t = t
print(best_t, min_cost)


input()
a = [*map(int, input().split())]
(c, t) = min(((sum((max(0, abs(t - x) - 1) for x in a)), t) for t in range(1, max(a) + 1)))
print(t, c)


n = int(input())
a = list(map(int, input().split()))
mi = min(a)
ma = max(a)
cf = 10000000000
for p in range(mi, ma + 1):
	c = 0
	for i in a:
		if i < p - 1:
			c += abs(p - 1 - i)
		elif i > p + 1:
			c += abs(i - (p + 1))
	if c < cf:
		cf = c
		pf = p
print(pf, cf)


def salem(lst):
	(maximum, t) = (10 ** 9, 0)
	for i in range(1, 100):
		current = 0
		for j in range(len(lst)):
			current += max(0, abs(i - lst[j]) - 1)
		if current < maximum:
			(maximum, t) = (current, i)
	return (t, maximum)
n = int(input())
a = [int(i) for i in input().split()]
print(*salem(a))


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
t = 1
for tt in range(t):
	n = int(input())
	a = list(map(int, sys.stdin.readline().split(' ')))
	cost = mod
	ans = -1
	for i in range(1, 101):
		c = 0
		for j in range(n):
			c += min(abs(a[j] - i), abs(a[j] - i - 1), abs(a[j] - i + 1))
		if c < cost:
			ans = i
			cost = c
	print(ans, cost)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


n = int(input())
s = list(map(int, input().split()))
d = []
for i in range(1, 101):
	c = 0
	for k in s:
		if k > i + 1:
			c = c + k - i - 1
		elif k < i - 1:
			c = c + abs(k - i + 1)
	d.append(c)
l = min(d)
for i in range(len(d)):
	if d[i] == l:
		print(i + 1, l)
		break


n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(min(a), max(a) + 1):
	s = 0
	for j in range(n):
		if i > a[j]:
			s += i - a[j] - 1
		elif i < a[j]:
			s += a[j] - i - 1
	b.append([s, i])
c = min(b)
print(c[1], c[0])


n = int(input())
a = sorted(list(map(int, input().split())))
tempt = 1
t = 1
cost = 9223372036854775807
while tempt <= a[-1]:
	tempCost = 0
	for i in range(n):
		if a[i] == tempt or a[i] == tempt + 1 or a[i] == tempt - 1:
			tempCost += 0
		else:
			tempCost += abs(a[i] - tempt) - 1
	if tempCost < cost:
		cost = tempCost
		t = tempt
	tempt += 1
print(t, cost)


n = int(input())
a = list(map(int, input().split()))
q = 1000000
t = 0
mia = a[0]
maa = a[0]
for i in range(n):
	mia = min(mia, a[i])
	maa = max(maa, a[i])
for i in range(mia, maa + 1):
	a0 = 0
	for j in range(n):
		if abs(i - a[j]) > 1:
			a0 += abs(i - a[j]) - 1
	if q > a0:
		q = a0
		t = i
print(t, q)


def count_dist(li, t):
	dist = 0
	for x in li:
		d = min(abs(x - t), abs(x - t + 1), abs(x - t - 1))
		dist += d
	return dist
input()
a = list(map(int, input().strip().split()))
t2dist = {}
for t in range(min(a), max(a) + 1):
	t2dist[t] = count_dist(a, t)
t_keys = list(t2dist.keys())
t_sorted = sorted(t_keys, key=lambda x: t2dist[x])
print(t_sorted[0], t2dist[t_sorted[0]])


n = int(input())
a = [int(i) for i in input().split()]
mn = -1
mk = 0
for t in range(0, 102):
	mt = 0
	for i in a:
		mt += min(abs(t - i), abs(t + 1 - i), abs(t - 1 - i))
	if mt >= 0 and (mt <= mn or mn == -1):
		mn = mt
		mk = t
print(mk, mn)


n = int(input())
a = list(map(int, input().split()))
min_cost = 9999999999999
new_t = 0
for t in range(1, 101):
	cost = 0
	for j in range(n):
		if abs(a[j] - t) <= 1:
			continue
		else:
			cost += abs(a[j] - t) - 1
	if cost < min_cost:
		min_cost = cost
		new_t = t
print(new_t, min_cost)


n = int(input())
a = list(map(int, input().split()))
m1 = min(a)
m2 = max(a)
t1 = -1
s1 = 10 ** 10
for t in range(m1, m2 + 1):
	s = 0
	for i in range(n):
		if a[i] > t + 1:
			s += a[i] - t - 1
		elif a[i] < t - 1:
			s += t - 1 - a[i]
	if s < s1:
		s1 = s
		t1 = t
print(t1, s1)


n = int(input())
a = list(map(int, input().split()))
a_max = max(a)
a_min = min(a)
ans = 99999999
for i in range(a_min, a_max + 1):
	tmp = 0
	for aa in a:
		if aa > i + 1:
			tmp += abs(aa - i) - 1
		elif aa < i - 1:
			tmp += abs(aa - i) - 1
	if ans > tmp:
		avg = i
		ans = tmp
print('{} {}'.format(avg, ans))


n = int(input())
arr = list(map(int, input().split()))
d = {}
for i in range(1, 100 + 1):
	sm = 0
	for j in range(n):
		if arr[j] == i or abs(arr[j] - i) <= 1:
			continue
		elif arr[j] > i:
			x = abs(arr[j] - i)
			x -= 1
			sm += x
		elif arr[j] < i:
			x = abs(arr[j] - i)
			x -= 1
			sm += x
	d[i] = sm
r1 = min(d.values())
for (i, j) in d.items():
	if j == r1:
		print(i, j)
		break


import sys

def rint():
	return map(int, sys.stdin.readline().split())
n = int(input())
a = []
a = list(rint())
t = 0
ans_min = 10 ** 100
for i in range(2, 101):
	ans = 0
	for j in range(n):
		ans += min(abs(a[j] - (i - 1)), abs(a[j] - i), abs(a[j] - (i + 1)))
	if ans < ans_min:
		t = i
		ans_min = ans
print(t, ans_min)


from sys import stdin, stdout, maxsize

def main():
	stdin.readline()
	lst = [int(x) for x in stdin.readline().split()]
	(min_sum, average) = (maxsize, 0)
	for i in range(1, 101):
		summ = 0
		for item in lst:
			summ += min(abs(item - i + 1), min(abs(item - i - 1), abs(item - i)))
		if summ < min_sum:
			min_sum = summ
			average = i
	stdout.write(str(average) + ' ' + str(min_sum))
main()


n = int(input())
sticks = list(map(int, input().split()))
minimal = 100000
min_len = 100000
for i in range(1, 101):
	m = 0
	for stick in sticks:
		if stick - i < -1 or stick - i > 1:
			m += abs(stick - i) - 1
	if m < minimal:
		minimal = m
		min_len = i
print(min_len, minimal)


import operator as op
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import reduce
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def def_value():
	return 0

def time_lagbe(n, k, t):
	if n == 0:
		return 0
	if k > n:
		return t
	time1 = n // k * t + n % k * t
	return time1
n = inp()
a = inlist()
minCost = 10000000
minT = -1
for t in range(1, 101):
	cost = 0
	for i in range(n):
		if a[i] < t:
			cost += t - (a[i] + 1)
		elif a[i] > t:
			cost += a[i] - (t + 1)
	if cost < minCost:
		minCost = cost
		minT = t
print(minT, minCost)


n = int(input())
a = [int(x) for x in input().strip().split()]

def dist(a, t):
	if abs(a - t) <= 1:
		return 0
	if a > t:
		return a - t - 1
	if a < t:
		return t - 1 - a

def cost(a, t):
	return sum([dist(x, t) for x in a])
min_c = 999999
min_t = 0
for t in range(min(a), max(a) + 1):
	c = cost(a, t)
	if c < min_c:
		min_c = c
		min_t = t
print('{} {}'.format(min_t, min_c))


n = int(input())
l = list(map(int, input().split()))
ka = 10 ** 9
x = 0
for i in range(1, 101):
	s = 0
	for j in range(n):
		s += max(abs(l[j] - i) - 1, 0)
	if s < ka:
		ka = s
		x = i
print(x, ka)


n = int(input())
ch = input()
L1 = ch.split()
L = []
for i in range(n):
	L.append(int(L1[i]))
L.sort()
cost = 0
for i in range(n):
	if abs(L[i]) > 1:
		cost = cost + abs(L[i]) - 1
m = cost
t = L[n - 1]
for j in range(L[n - 1]):
	cost = 0
	for i in range(n):
		if abs(L[i] - j) > 1:
			cost = cost + abs(L[i] - j) - 1
	if cost < m:
		m = cost
		t = j
print(str(t) + ' ' + str(m))


n = int(input())
a = list(map(int, input().split(' ')))
t = 1
m = 10000000000
while t < 105:
	count = 0
	for i in range(n):
		if a[i] > t:
			count += a[i] - 1 - t
		elif a[i] == t:
			count += 0
		else:
			count += t - 1 - a[i]
	if count < m:
		m = count
		k = t
	t += 1
print(k, m)


n = int(input())
arr = list(map(int, input().split()))
min_c = 1000000000.0
tt = -1
for t in range(1, 101):
	new_arr = arr.copy()
	cost = 0
	for i in range(n):
		cost += min(abs(arr[i] - t + 1), abs(arr[i] - t), abs(arr[i] - t - 1))
	if cost < min_c:
		min_c = cost
		tt = t
print(tt, min_c)


def _main():
	ts = input()
	a = input().split(' ')
	mi: int = 10000000000.0
	t: int = 1
	mt: int = 1
	a.sort()
	while mt <= 100:
		sum: int = 0
		for x in a:
			if int(x) < mt:
				sum += abs(int(x) + 1 - mt)
			elif int(x) > mt:
				sum += abs(int(x) - 1 - mt)
		if sum < mi:
			mi = sum
			t = mt
		mt += 1
	print(str(t) + ' ' + str(mi))
_main()


n = int(input())
ar = list(map(int, input().split()))

def min_dist(x, i):
	return min(abs(x - i), abs(x - i - 1), abs(x - i + 1))
res = {}
for i in range(101):
	sd = sum((min_dist(x, i) for x in ar))
	res[sd] = i
min_sd = min(res.keys())
i = res[min_sd]
print(i, min_sd)


n = int(input())
a = list(map(int, input().split()))
s = []
k = 0
for i in range(min(a), max(a) + 1):
	for j in range(n):
		if abs(a[j] - i) > 1:
			k += abs(a[j] - i) - 1
	s.append((i, k))
	k = 0
print(*min(s, key=lambda x: x[1]))


n = int(input())
a = list(map(int, input().split()))
tans = 0
ans = 10 ** 9
for i in range(1, 100):
	t = 0
	for j in a:
		if j <= i + 1 and j >= i - 1:
			continue
		if j < i - 1:
			t += abs(j - (i - 1))
		if j > i + 1:
			t += abs(j - (i + 1))
	if ans > t:
		ans = t
		tans = i
print(tans, ans)


n = int(input())
a = list(map(int, input().split()))
t = max(a)
s = []
for j in range(1, t + 1):
	m = 0
	for i in range(n):
		m += min(abs(a[i] - j), abs(a[i] - 1 - j), abs(j - 1 - a[i]))
	s.append(m)
f = s.index(min(s))
print(f + 1, s[f])


n = int(input())
a = list(map(int, input().strip().split()))
op = [a[0], sum(a)]
m = op[1]
for i in range(min(a), max(a) + 1):
	s = 0
	for j in a:
		xyz = abs(i - j)
		if xyz > 1:
			s = s + xyz - 1
	if s < m:
		m = s
		op = [i, m]
print(' '.join(list(map(str, op))))


a = int(input())
p = [int(i) for i in input().split()]
m = 99999999999999999999
l = 0
for i in range(1, 101):
	t = 0
	for j in p:
		if abs(j - i) > 1:
			t += abs(j - i) - 1
	if t < m:
		m = t
		l = i
print(l, m)


n = int(input())
a = [int(x) for x in input().split(' ')]
x = sum(a) // n
m = float('inf')
for i in range(1, max(a) + 1):
	s = 0
	for c in a:
		s += min(abs(c - (i - 1)), abs(c - i), abs(c - (i + 1)))
	if s < m:
		y = i
		m = min(s, m)
print(y, m)


import math
from statistics import median
n = int(input())
arr = list(map(int, input().split()))
min_changes = math.inf
min_mean = None
for mean in range(2, 100):
	changes = 0
	for a in arr:
		diff = abs(a - mean)
		if diff > 1:
			changes += diff - 1
	if changes < min_changes:
		min_changes = changes
		min_mean = mean
	else:
		break
print(min_mean, min_changes)


n = int(input())
a = list(map(int, input().split()))
res = 0
cost = int(1000000000.0)
for t in range(1, 100 + 1):
	temp = 0
	for i in range(0, n):
		if abs(a[i] - t) > 1:
			temp += abs(a[i] - t) - 1
	if temp < cost:
		cost = temp
		res = t
print(res, ' ', cost)


import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
	return int(input())

def rm():
	return map(int, input().split())

def rl():
	return list(map(int, input().split()))
n = r()
a = rl()
res = 0
maxi = math.inf
for i in range(1, 102):
	cal = 0
	for j in a:
		cal += min([abs(j - i), abs(j - i - 1), abs(j - i + 1)])
	if cal < maxi:
		maxi = cal
		res = i
print(res, maxi)


n = int(input())
l = list(map(int, input().split()))
max1 = 99999
for i in range(1, 101):
	sum1 = 0
	for j in range(len(l)):
		if l[j] > i:
			sum1 = sum1 + abs(l[j] - i - 1)
		elif l[j] < i:
			sum1 = sum1 + abs(l[j] + 1 - i)
		else:
			sum1 = sum1 + 0
	if max1 > sum1:
		max1 = sum1
		k = i
print(k, max1, end=' ')


n = int(input())
ar = list(map(int, input().split()))
_answ = 99999999999999
_t = 0
l = min(ar)
r = max(ar)
for j in range(l, r + 1):
	answ = 0
	for i in ar:
		temp = abs(j - i)
		answ += temp
		if temp > 0:
			answ -= 1
	if answ < _answ:
		_answ = answ
		_t = j
print(_t, _answ)


n = input()
lengths = input()
length_list = [int(s) for s in lengths.split(' ')]
res = [0]
for i in range(max(length_list)):
	if len(res) <= max(length_list) - 1:
		res.append(0)
	for j in range(len(length_list)):
		if length_list[j] < i:
			res[i] += i - 1 - length_list[j]
		elif length_list[j] > i:
			res[i] += length_list[j] - (i + 1)
index_min = res.index(min(res))
if index_min == 0:
	print(1, min(res))
else:
	print(index_min, min(res))


n = int(input())
cl = list(map(int, input().split()))
st = set(cl)
lst = len(st)
st = list(st)
ser = 1
mn = 10 ** 10
for i in range(1, max(cl) + 1):
	sm = 0
	for j in range(lst):
		if abs(st[j] - i) > 1:
			sm += cl.count(st[j]) * (abs(st[j] - i) - 1)
	if sm < mn:
		mn = sm
		ser = i
print(ser, mn)


n = int(input())
a = [int(i) for i in input().split()]
if n == 1:
	print(a[0], 0)
else:
	min_total = -1
	min_t = 0
	for t in range(min(a), max(a) + 1):
		total = 0
		for ai in a:
			total += max(abs(ai - t) - 1, 0)
		if min_total == -1 or total < min_total:
			min_total = total
			min_t = t
	print(min_t, min_total)


n = int(input())
a = [int(v) for v in input().split()]
s = sum(a)
k = 0
ans = 0
minn = 100000000
for i in range(1, 101):
	ans = 0
	for j in range(n):
		if abs(a[j] - i) > 1:
			ans += abs(a[j] - i) - 1
	if ans < minn:
		minn = ans
		k = i
print('{0} {1}'.format(k, minn))


a = int(input())
b = list(map(int, input().split()))
b = sorted(b)
sak = {}
for sr in range(b[0], b[-1] + 1):
	ss = 0
	for i in range(a):
		if abs(sr - b[i]) > 1:
			ss += abs(sr - b[i]) - 1
	sak[ss] = sr
d = list(sak.keys())
print(sak[min(d)], min(d))


n = int(input())
arr = list(map(int, input().split()))
ans = {}

def solve(t):
	cost = 0
	for num in arr:
		if num > t:
			cost += num - (t + 1)
		elif num < t:
			cost += t - 1 - num
	if cost not in ans:
		ans[cost] = [str(t)]
	else:
		ans[cost].append(str(t))
	return cost
mincost = 90000000000
for t in range(1, 101):
	mincost = min(mincost, solve(t))
print(ans[mincost][0], mincost)


n = int(input())
l = [int(s) for s in input().split()]
res = []
for i in range(1, 1001):
	re = 0
	t = i
	for j in range(len(l)):
		if abs(l[j] - t) <= 1:
			continue
		else:
			re += abs(l[j] - t) - 1
	res.append(re)
rt = min(res)
print(res.index(rt) + 1, rt)


n = int(input())
l = list(map(int, input().split()))
cost = None
h = 1
for t in range(1, 101):
	temp = 0
	for i in l:
		temp += min(abs(t - i), abs(t + 1 - i), abs(t - 1 - i))
	if t != 1:
		if cost > temp:
			h = t
			cost = temp
	else:
		cost = temp
print(h, cost)


def st(t, A):
	sum0 = 0
	for i in range(len(A)):
		if A[i] > t:
			sum0 += abs(A[i] - t - 1)
		elif A[i] < t:
			sum0 += abs(A[i] - t + 1)
	return sum0

def main():
	n = int(input())
	A = list(map(int, input().split()))
	A1 = set(A)
	if len(A1) == 1:
		print(A[0], 0)
	else:
		t1 = 0
		sum1 = 10 ** 10
		for i in range(min(A), max(A) + 1):
			t = i
			if st(t, A) < sum1:
				t1 = t
				sum1 = st(t, A)
		print(t1, sum1)
main()


n = input()
a = list(map(int, input().split()))
t = 0
count = 1000000
for i in range(1, 101):
	cost = sum((0 if k == i else abs(i - k) - 1 for k in a))
	if cost < count:
		count = cost
		t = i
print(t, count)


n = int(input())
a = [int(x) for x in input().split()]
l = 1000000
for i in range(1, 100):
	c = 0
	for j in range(len(a)):
		c += max(0, abs(a[j] - i) - 1)
	if c < l:
		l = c
		t = i
print(t, l)


n = int(input())
num = input().split(' ')
for i in range(n):
	num[i] = int(num[i])
m = min(num)
M = max(num)
idx = 0
out = float('Inf')
for med in range(m, M + 1):
	changes = 0
	for i in range(n):
		if abs(num[i] - med) > 1:
			if num[i] > med:
				changes += num[i] - med - 1
			else:
				changes += med - num[i] - 1
	if changes < out:
		out = changes
		idx = med
	if changes == 0:
		break
print(str(idx) + ' ' + str(out))


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
a1 = []
co = []
for t in range(a[0], a[-1] + 1):
	c = 0
	for x in a:
		if x < t:
			c += t - 1 - x
		elif x > t:
			c += x - t - 1
	a1.append(c)
	a1.append(t)
	co.append(a1)
	a1 = []
co = sorted(co)
print(co[0][1], co[0][0])


n = int(input())
a = [int(s) for s in input().split()]
min = 10 ** 10
mint = 1
for t in range(1, 101):
	price = 0
	for j in range(n):
		stick = abs(a[j] - t)
		if stick > 1:
			price = price + stick - 1
	if price < min:
		mint = t
		min = price
print(mint, min)


sl = int(input())
stick = list(map(int, input().split()))
stick.sort()
cost = 0
dem = dict()
for i in range(stick[0], stick[sl - 1] + 1):
	dis = 0
	for j in stick:
		tmp = abs(i - j)
		if tmp > 0:
			dis += tmp - 1
	dem[dis] = i
rs = list(dem.keys())
rs.sort()
print(dem[rs[0]], rs[0])


n = int(input())
a = list(map(int, input().split()))
t_min = 0
v_min = int(1000000000.0)
for t in range(1, 101):
	v = 0
	for i in a:
		if abs(t - i) > 1:
			v += abs(t - i) - 1
	if v < v_min:
		v_min = v
		t_min = t
print(t_min, v_min)


amount = int(input())
array = [int(s) for s in input().split()]
max_ = max(array)
min_ = 10000000000.0
idx = -1
for i in range(1, max_ + 1):
	sum_ = 0
	for elem in array:
		if elem < i - 1:
			sum_ += i - 1 - elem
		elif elem > i + 1:
			sum_ += elem - i - 1
	if sum_ < min_:
		min_ = sum_
		idx = i
print(idx, min_)


n = int(input())
lista = input().split()
lista = [int(x) for x in lista]
lista.sort()
suma = sum(lista)

def costoTotal(t):
	contador = 0
	for i in range(len(lista)):
		if lista[i] < t:
			contador += t - lista[i] - 1
		elif lista[i] > t:
			contador += lista[i] - t - 1
		elif lista[i] == 0:
			contador += 0
	return contador
t = lista[0]
minimo = costoTotal(lista[0])
for i in range(lista[0], lista[len(lista) - 1]):
	if minimo > costoTotal(i):
		minimo = costoTotal(i)
		t = i
print(str(t) + ' ' + str(minimo))


n = int(input())
a = list(map(int, input().split()))
b = min(a)
c = max(a)
m = 98598496854965458
mv = c

def check(q, y):
	if q > y:
		return q - y - 1
	elif q == y:
		return 0
	else:
		return y - q - 1
for t in range(b, c + 1, 1):
	s = 0
	for i in range(n):
		s = s + check(a[i], t)
	if s < m:
		m = s
		mv = t
print(mv, m)


n = int(input())
a = list(map(int, input().split()))
(tt, sol) = (1, sum(a) - n)
for t in range(101):
	tmp = 0
	for i in range(n):
		tmp += min(abs(a[i] - t - 1), abs(a[i] - t + 1), abs(a[i] - t))
	if sol > tmp:
		(tt, sol) = (t, tmp)
print(tt, sol)


import statistics
import sys
costDB = {}

def _calcCost(t, a):
	cost = 0
	for element in a:
		if element == t:
			pass
		if element > t:
			cost += element - t - 1
		if element < t:
			cost += t - element - 1
	return cost

def getCost(t, a):
	if t not in costDB:
		costDB[t] = _calcCost(t, a)
	return costDB[t]
n = int(input())
_a = input()
a = list(map(lambda x: int(x), _a.split(' ')))
median = int(statistics.median(a))
width = 5
costs = []
for i in range(median - width, median + width + 1):
	if i <= 0:
		costs.append(100000)
		continue
	costs.append(getCost(i, a))
best = median - width + costs.index(min(costs))
print(best, getCost(best, a))


def cost(t):
	total_cost = 0
	for ar in arr:
		if abs(ar - t) > 1:
			b = abs(ar - t) - 1
			total_cost += b
	return total_cost
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
low = arr[0]
high = arr[-1]
res = []
if n == 1:
	print(arr[0], 0)
else:
	for num in range(low, high + 1):
		temp = cost(num)
		res.append((temp, num))
		if temp == 0:
			break
	target = res[0][1]
	cost1 = res[0][0]
	for (i, j) in res[1:]:
		if cost1 > i:
			cost1 = i
			target = j
	print(target, cost1)


n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
a.sort()
b = []
for j in range(2, 100):
	ans = 0
	for k in range(n):
		if a[k] - j > 1:
			ans += a[k] - j - 1
		elif a[k] - j < -1:
			ans += j - a[k] - 1
	b.append([ans, j])
ans = 0
for j in range(n):
	if a[j] > 2:
		ans += a[j] - 2
b.append([ans, 1])
b.sort()
print(b[0][1], b[0][0])


n = int(input())
a = tuple(map(int, input().split()))
ans = [0] * 110
count = 0
for t in range(1, 111):
	count = 0
	for i in a:
		if abs(i - t) <= 1:
			continue
		else:
			v = i - t
			f = min(abs(v), min(abs(v + 1), abs(v - 1)))
			count += f
		ans[t - 1] = count
m = min(ans)
print(ans.index(m) + 1, m)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
ans = 99999999999
bestT = 0
for i in range(1, 201):
	total = 0
	for j in a:
		total += min(abs(j - (i + 1)), abs(j - (i - 1)), abs(j - i))
	if total < ans:
		ans = total
		bestT = i
print(str(bestT) + ' ' + str(ans))


n = int(input().strip())
a = list(map(int, input().strip().split()))
anssum = float('inf')
ans = float('inf')
for i in range(1, 102):
	cs = 0
	for j in a:
		if abs(j - i) > 1:
			if j > i + 1:
				cs += j - i - 1
			elif j < i - 1:
				cs += i - 1 - j
			else:
				assert False
	if cs < anssum:
		anssum = cs
		ans = i
print(ans, anssum)


n = int(input())
a = list(map(int, input().split()))
m = 1000 * 1000
x = -1
for i in range(1, 101):
	c = 0
	for j in range(len(a)):
		if a[j] == i or a[j] - 1 == i or a[j] + 1 == i:
			continue
		elif a[j] > i:
			c += abs(a[j] - i - 1)
		elif a[j] < i:
			c += abs(-a[j] + i - 1)
	if c < m:
		m = c
		t = i
else:
	print(t, m)


n = int(input())
l = list(map(int, input().split()))
t = 0
ans = 10 ** 9
for i in range(1, 101):
	val = 0
	for j in l:
		val += max(abs(j - i) - 1, 0)
	if val < ans:
		t = i
		ans = val
print(t, ans)


def salem():
	n = int(input())
	lst = list(map(int, input().split()))
	p = 1000001
	q = 0
	mi = min(lst)
	ma = max(lst)
	for i in range(mi, ma + 1):
		s = 0
		for m in range(n):
			if lst[m] > i:
				s = s + (lst[m] - i - 1)
			elif i > lst[m]:
				s = s + (i - lst[m] - 1)
		if s < p:
			p = s
			q = i
	print(q, end=' ')
	return p
print(salem())


n = int(input())
newlist = []
flist = []
mylist = input().split()
for i in range(len(mylist)):
	newlist.append(int(mylist[i]))
for t in range(1, 101):
	m = 0
	for i in range(len(newlist)):
		if t != newlist[i]:
			m += abs(t - newlist[i]) - 1
	flist.append((m, t))
a = min(flist)
print(a[1], end=' ')
print(a[0])


num = int(input().strip())
nums = [int(i) for i in input().strip().split()]
t = 0
cost = 1000000
for i in range(1, 101):
	c = 0
	for j in nums:
		if j != i:
			c += abs(j - i) - 1
		else:
			pass
	if c < cost:
		cost = c
		t = i
print(t, cost)


def cost(ais, t):
	cost = 0
	for elem in ais:
		if elem <= t - 1:
			cost += t - 1 - elem
		elif elem >= t + 1:
			cost += elem - (t + 1)
	return cost

def solve(n, ais):
	t = int(sum(ais) / n)
	prevCost = None
	costOrigin = cost(ais, t)
	direction = 1
	costPlus = cost(ais, t + direction)
	if costPlus >= costOrigin:
		direction = -1
		costMinus = cost(ais, t + direction)
		if costMinus >= costOrigin:
			return (t, costOrigin)
		else:
			prevCost = costMinus
			t = t + direction
	else:
		prevCost = costPlus
		t = t + direction
	while True:
		currCost = cost(ais, t + direction)
		if currCost >= prevCost:
			return (t, prevCost)
		t = t + direction
		prevCost = currCost

def main():
	n = int(input())
	ais = [int(a) for a in input().split()]
	print(' '.join((str(a) for a in solve(n, ais))))
main()


def cost(l, t):
	c = 0
	for i in l:
		if i < t:
			c += t - i - 1
		elif i > t:
			c += i - t - 1
	return c
n = input()
l = list(map(int, input().strip().split()))
mc = 100000
for i in range(min(l), max(l) + 1):
	mm = cost(l, i)
	if mc > mm:
		mc = mm
		mt = i
print(mt, mc)


import sys
input = sys.stdin.readline
n = int(input())
l = list(map(int, input().split()))
l.sort()
m1 = l[0]
m2 = l[-1]
t = (m1 + m2) // 2
s = 0
m = 1098765
ans = 0
for i in range(1, 100):
	for j in l:
		if j > i:
			s += j - i - 1
		elif j < i:
			s += i - 1 - j
	if s < m:
		m = s
		ans = i
	s = 0
print(ans, m)


n = int(input())
A = list(map(int, input().split()))
A.sort()
m = A[0]
n = A[-1]
t = 0
tmin = 10000000
k = 0
kmin = 0
for i in range(m, n + 1):
	t = 0
	for j in range(len(A)):
		if A[j] < i - 1:
			t = t + i - 1 - A[j]
		if A[j] > i + 1:
			t = t + A[j] - i - 1
	if t < tmin:
		tmin = t
		kmin = i
print(kmin, tmin)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
cost = []
m = 10000000000000000000
t = 0
if n == 1:
	print(a[0], 0)
elif n == 2:
	t = a[0] + 1
	if a[0] == a[1]:
		print(a[0], 0)
	elif a[1] - t == 0:
		print(t, 0)
	else:
		print(t, a[1] - t - 1)
else:
	for j in range(1, 101):
		cost1 = 0
		for i in range(n):
			if j > a[i]:
				cost1 += j - a[i] - 1
			elif j < a[i]:
				cost1 += a[i] - j - 1
		if m > cost1:
			m = cost1
			t = j
	print(t, m)


n = int(input())
lst = list(map(int, input().strip().split(' ')))
lst.sort()
cost = 10000000000
t = 0
for i in range(min(lst), max(lst) + 1):
	s = 0
	for j in range(n):
		if lst[j] < i:
			s += i - lst[j] - 1
		elif lst[j] > i:
			s += lst[j] - 1 - i
		else:
			s += 0
	if s < cost:
		cost = s
		t = i
print(t, cost)


n = int(input())
a = list(map(int, input().split()))
b = [i for i in range(2, 100)]
c = []
for i in b:
	co = 0
	for j in a:
		if j > i + 1:
			co += j - i - 1
		elif j < i - 1:
			co += i - 1 - j
	c.append(co)
print(b[c.index(min(c))], min(c))


t = 1000000
naj = 0
n = int(input())
a = [int(x) for x in input().split()]
for i in range(1, 101):
	temp = 0
	for x in a:
		temp += (abs(i - x) - 1, 0)[abs(i - x) == 0]
	if temp < t:
		t = temp
		naj = i
print(naj, t)


n = int(input())
l = list(map(int, input().split()))
t = min(l)
s = 100000000
for i in range(min(l), max(l) + 1):
	g = 0
	for j in l:
		if abs(j - i) > 1:
			g += abs(j - i) - 1
	if g < s:
		s = g
		t = i
print(t, s)


su = 0
(minx, miny) = (None, 0)
n = int(input())
a = [int(x) for x in input().split()]
for t in range(1, 100):
	su = 0
	for i in range(n):
		if abs(a[i] - t) > 1:
			su += min(abs(a[i] - t - 1), abs(a[i] - t), abs(a[i] - t + 1))
	if minx == None or minx > su:
		minx = su
		miny = t
print(miny, minx)


n = int(input())
a = list(map(int, input().split()))
mas = []
for i in range(1, 1001):
	x = 0
	for j in range(n):
		if abs(a[j] - i) > 1:
			x += abs(a[j] - i) - 1
	mas.append((x, i))
print(min(mas)[1], min(mas)[0])


n = int(input())
a = [int(s) for s in input().split()]
print(*min(((t, sum((max(abs(t - i) - 1, 0) for i in a))) for t in range(1, 101)), key=lambda t: t[1]))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	n = I()
	a = LI()
	mm = inf
	mi = 0
	for i in range(1, 100):
		t = 0
		for c in a:
			if c < i:
				t += i - 1 - c
			elif c > i:
				t += c - 1 - i
		if mm > t:
			mi = i
			mm = t
	return '{} {}'.format(mi, mm)
print(main())


import collections, atexit, math, sys, bisect
sys.setrecursionlimit(1000000)

def getIntList():
	return list(map(int, input().split()))
try:
	import numpy

	def dprint(*args, **kwargs):
		print(*args, file=sys.stderr)
	dprint('debug mode')
except Exception:

	def dprint(*args, **kwargs):
		pass
inId = 0
outId = 0
if inId > 0:
	dprint('use input', inId)
	sys.stdin = open('input' + str(inId) + '.txt', 'r')
if outId > 0:
	dprint('use output', outId)
	sys.stdout = open('stdout' + str(outId) + '.txt', 'w')
	atexit.register(lambda : sys.stdout.close())
(N,) = getIntList()
za = getIntList()
assert len(za) == N
r = 1000000000
for i in range(1, 101):
	t = 0
	for x in za:
		c1 = abs(x - i - 1)
		c2 = abs(x - i)
		c3 = abs(x - i + 1)
		t += min(c1, c2, c3)
	if t < r:
		r = t
		ri = i
print(ri, r)


n = int(input())
al = list(map(int, input().split()))
res = (1e309, 1)
for t in range(1, 101):
	c = 0
	for a in al:
		c += max(abs(a - t) - 1, 0)
	res = min(res, (c, t))
print('{a[1]} {a[0]}'.format(a=res))


n = int(input())
a = list(map(int, input().split()))
mn = min(a)
mx = max(a)
ans = mn + 1
av = 0
for i in a:
	if abs(i - mn - 1) > 1:
		av += abs(i - mn - 1) - 1
for t in range(mn + 2, mx):
	summ = 0
	for i in a:
		if abs(i - t) > 1:
			summ += abs(i - t) - 1
	if summ < av:
		av = summ
		ans = t
print(ans, av)


n = int(input())
li = list(map(int, input().split()))
li2 = []
for i in range(102):
	cn = 0
	for j in range(n):
		cn += abs(i - li[j])
		if li[j] > i or li[j] < i:
			cn -= 1
	li2.append(cn)
	cn = 0
li2[0] = 1000000
ab = min(li2)
ba = li2.index(ab)
print(ba, ab)


n = int(input())
t = list(map(int, input().split()))
g = 0
ans = 999999999
for j in range(1, 101):
	x = 0
	for i in t:
		x += min(abs(i - j), abs(i - (j - 1)), abs(i - (j + 1)))
	if x < ans:
		ans = x
		g = j
print(g, ans)


N = int(input())
number_list = list(map(int, input().split(' ')))
ret = [0, 9999999]
for n in range(1, 101):
	temp = 0
	for number in number_list:
		temp += max(0, abs(number - n) - 1)
	if ret[1] > temp:
		ret[0] = n
		ret[1] = temp
print(ret[0], ret[1])


n = int(input())
l = list(map(int, input().split()))
(ans, mx) = (0, 100000000)
for i in range(1, 101):
	c = 0
	for j in l:
		if abs(i - j) > 1:
			c += abs(i - j) - 1
	if mx > c:
		mx = c
		ans = i
print(ans, mx)


n = int(input())
m = list(map(int, input().split()))
s = 0
mx = 10000000
for j in range(100):
	x = 0
	for i in range(n):
		if abs(m[i] - j - 1) > 0:
			x += abs(m[i] - j - 1) - 1
	if x < mx:
		mx = x
		s = j + 1
print(int(s), int(mx))


n = int(input())
a = list(map(int, input().split()))
m = 100000000
t = 100000000
for i in range(1, 101):
	u = 0
	for j in a:
		if i > j:
			u += i - j - 1
		elif i < j:
			u += j - i - 1
	if m > u:
		m = u
		t = i
print(t, m)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	(ans1, ans2) = (10000000, 0)
	for i in range(1, 101):
		cur = 0
		for j in a:
			if j < i:
				cur += max(0, i - j - 1)
			else:
				cur += max(0, j - i - 1)
		if cur < ans1:
			(ans1, ans2) = (cur, i)
	print(ans2, ans1)
main()


def findCost(s, t):
	r = 0
	for stick in s:
		dif = abs(stick - t)
		if dif > 1:
			r += dif - 1
	return r
input()
sticks = list()
maximun = 0
minimun = float('inf')
min_t = None
for stick in input().split():
	nu = int(stick)
	maximun = max(maximun, nu)
	sticks.append(nu)
for t in range(1, maximun + 1):
	m = findCost(sticks, t)
	if m < minimun:
		minimun = m
		min_t = t
print(min_t, minimun)


def cin():
	n = int(input())
	return n
n = cin()
a = list(map(int, input().split()))
T = 0
ans = 100000
for t in range(1, 100):
	s = 0
	for i in a:
		if abs(t - i) > 1:
			s += abs(t - i) - 1
	if ans > s:
		ans = s
		T = t
print(T, ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
mn = 20000000000000
t = a[len(a) - 1]
amx = t
for i in range(1, amx + 1):
	k = 0
	for j in a:
		if 1 < abs(j - i):
			if j > i:
				k += j - i - 1
			elif j < i:
				k += i - 1 - j
	if mn > k:
		mn = k
		t = i
print(t, mn)


n = int(input())
a = list(map(int, input().split()))

def min_dist(ai, t):
	if ai < t:
		return t - 1 - ai
	if ai > t:
		return ai - (t + 1)
	else:
		return 0
t_min = -1
min_found = float('inf')
for t in range(1, 101):
	min_len = sum((min_dist(ai, t) for ai in a))
	if min_len < min_found:
		min_found = min_len
		t_min = t
print(f'{t_min} {min_found}')