Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$.

Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to:  Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$), then  Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$) with a cost of $1$. 

Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence.


-----Input-----

The first line contains an integer $n$ ($3 \le n \le 10^5$).

The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ($1 \le a_i \le 10^9$).


-----Output-----

Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence.


-----Examples-----
Input
3
1 3 2

Output
1

Input
3
1000000000 1000000000 1000000000

Output
1999982505



-----Note-----

In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$, then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$.

Source: codeforces | Difficulty: MEDIUM
Tags: Number theory

Sorting

Mathematics

Complete search


Solutions:
n = int(input())
l = list(map(int, input().split()))
l.sort()
c = 0
for i in range(1, 100000):
	if i ** (n - 1) >= l[n - 1]:
		c = i
		break
l1 = []
cm = 100000000000000
for i in range(1, c + 1):
	c1 = 0
	for j in range(n):
		c2 = abs(i ** j - l[j])
		c1 += c2
		if cm < c1:
			break
	if cm > c1:
		cm = c1
print(cm)


n = int(input())
a = list(map(int, input().split()))
a.sort()
res = int(1000000000.0 * n)
lim = res + int(1000000000.0 + 5)
for c in range(1, int(1000000000.0)):
	r = 0
	z = 1
	ok = True
	for i in range(n):
		if z > lim:
			ok = False
			break
		r += abs(a[i] - z)
		z *= c
	if not ok:
		break
	res = min(res, r)
print(res)


from math import *
from collections import *
from random import *
from decimal import Decimal
from heapq import *
from bisect import *
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 5)

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

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

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

def st1():
	return input().rstrip('\n')
t = 1

def lo(n, x):
	z = 0
	while n:
		n = n // x
		z += 1
	return z
while t:
	t -= 1
	n = inp()
	a = lis()
	a.sort()
	co = 1
	ref = 10 ** 14
	z = 0
	re = float('inf')
	for i in range(1, 100000):
		if i ** n > ref:
			break
		z = 0
		co = 1
		for j in range(n):
			z += abs(co - a[j])
			co = co * i
		re = min(re, z)
	print(re)


n = int(input())
arr = list(map(int, input().split()))
if len(arr) == 1:
	print(arr[0] - 1)
elif len(arr) <= 50:
	arr.sort()
	ans = pow(10, 15)
	num = 1
	prev = pow(10, 15)
	while 1:
		curr = 0
		for i in range(n):
			curr += abs(arr[i] - pow(num, i))
		if curr > prev:
			break
		if curr < ans:
			ans = curr
		prev = curr
		num += 1
	print(ans)
else:
	print(sum(arr) - n)


import math

def powerMod(x, y):
	res = 1
	while y > 0:
		if y & 1:
			res = res * x
		y = y >> 1
		x = x * x
	return res
n = int(input())
a = list(map(int, input().split()))
(c1, c2) = (0, 0)
a.sort()
x = a[n - 1] ** (1 / (n - 1))
x1 = math.ceil(x)
x2 = math.floor(x)
for i in range(n):
	d1 = abs(a[i] - pow(x1, i))
	c1 += d1
	d2 = abs(a[i] - pow(x2, i))
	c2 += d2
print(min(c1, c2))


(_, s) = open(0)
a = sorted(map(int, s.split()))
n = len(a)
r = sum(a) - n
c = 2
while c ** (n - 1) < a[-1] * (n + 1):
	r = min(r, sum((abs(x - c ** i) for (i, x) in enumerate(a))))
	c += 1
print(r)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = sum(a) - n
for i in range(1, 10 ** 9):
	curpow = 1
	curcost = 0
	for j in range(n):
		curcost += abs(a[j] - curpow)
		curpow *= i
		if curpow > 10 ** 18:
			break
	if curpow > 10 ** 18:
		break
	if curpow / i > ans + a[n - 1]:
		break
	ans = min(ans, curcost)
print(ans)


import sys
import math
n = int(input())
n_list = list(map(int, sys.stdin.readline().split()))
n_list = sorted(n_list)
loged = n_list[n - 1] ** (1 / (n - 1))
if loged >= 1:
	lmax = math.ceil(loged)
	lmin = math.floor(loged)
	minans = 0
	maxans = 0
	for i in range(n):
		maxans += abs(n_list[i] - lmax ** i)
	for i in range(n):
		minans += abs(n_list[i] - lmin ** i)
	print(min(minans, maxans))


import os
import sys
from io import BytesIO, IOBase
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')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

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

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
from math import inf
for _ in range(int(input()) if not True else 1):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	if n == 1 or n == 2:
		print(a[0] - 1)
		continue
	ans = inf
	lim = 100000 if n <= 6 else 100
	for v in range(1, lim):
		i = 0
		anss = 0
		while i < n:
			if v ** i >= 10 ** 13:
				break
			anss += abs(a[i] - v ** i)
			i += 1
		if i == n:
			ans = min(ans, anss)
	print(ans)


import sys
input = sys.stdin.readline

def nth_element(c, k):
	return c ** k
for _ in range(1):
	n = int(input())
	arr = [int(j) for j in input().split()]
	res = []
	if n <= 50:
		arr.sort()
		cmax = (10 ** 9) ** (1 / (n - 1))
		for i in range(1, int(cmax) + 3):
			temp = 0
			for j in range(n):
				temp += abs(arr[j] - nth_element(i, j))
			res.append(temp)
		print(min(res))
	else:
		print(abs(sum(arr) - n))


n = int(input())
a = list(map(int, input().split()))
a.sort()
m = sum(a) - n
if 2 ** n > 4000000000 * n:
	print(m)
else:
	b = p = 2
	while b >= 0:
		q = 1
		b = c = 0
		for i in range(n):
			b += a[i] - q
			c += abs(a[i] - q)
			q *= p
		if c < m:
			m = c
		p += 1
	print(m)


import copy
import math
n = int(input())
nums = list(map(int, input().split()))
nums.sort()
f_1 = 0
for i in range(n):
	f_1 += math.fabs(1 - nums[i])
term = f_1 + nums[-1]
max_c = math.floor(math.pow(term, 1 / (n - 1)))
cost2 = float('inf')
prev_cost = 0
for c in range(1, max_c + 1):
	cost = 0
	for i in range(n):
		cost += math.fabs(c ** i - nums[i])
	cost2 = min(cost, cost2)
print(int(cost2))


from math import ceil, floor
n = int(input())
l = sorted(map(int, input().split()))
(ans1, ans2) = (0, 0)
bor = l[-1] ** (1 / (n - 1))
(c1, c2) = (ceil(bor), floor(bor))
for i in range(n):
	ans1 += abs(c1 ** i - l[i])
	ans2 += abs(c2 ** i - l[i])
print(min(ans1, ans2))


from math import ceil
MAX = 1e+19
n = int(input())
a = list(map(int, input().split()))
a.sort()
val = ceil(pow(a[n - 1], 1 / (n - 1)))
ans = MAX
for i in range(1, val + 1):
	temp = 0
	for j in range(len(a)):
		temp += abs(a[j] - pow(i, j))
	ans = min(ans, temp)
print(ans)


def powSeq():
	n = int(input())
	a = sorted(list(map(int, input().split())))
	y = a[-1]
	ans = 0
	x = y = int(pow(y, 1 / (n - 1)))
	for i in range(n):
		ans += abs(y ** i - a[i])
	ans1 = 0
	y = x + 1
	for i in range(n):
		if y ** i > 10 ** 13:
			break
		ans1 += abs(y ** i - a[i])
	return min(ans, ans1)
print(powSeq())


n = int(input())
a = []
a = sorted([int(tt) for tt in input().split()])
ans = 1 << 100
flag = 0
for c in range(1, 1 << 50):
	temp = 1
	t = 0
	for i in range(n):
		t = t + abs(a[i] - temp)
		temp = temp * c
		if temp > 1 << 55:
			flag = 1
			break
	if flag:
		break
	ans = min(ans, t)
print(ans)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
p = arr[-1] ** (1 / (n - 1))
p = int(p)
q = p + 1
a = 0
b = 0
for (i, j) in enumerate(arr):
	a += abs(j - p ** i)
	b += abs(j - q ** i)
print(min(a, b))


from math import *
n = int(input())
l = list(map(int, input().split()))
l.sort()
d = 0
k = 0
f = l[-1] ** (1 / (n - 1))
for i in range(n):
	d += abs(ceil(f) ** i - l[i])
	k += abs(int(f) ** i - l[i])
print(min(k, d))


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def solve():
	n = int(inp())
	ar = lis()
	ar.sort()
	m = ar[-1]
	c = 1
	while c ** (n - 1) <= m:
		c += 1
	ans1 = 0
	ans2 = 0
	ans3 = 0
	k = c - 1
	for i in range(n):
		ans1 += abs(k ** i - ar[i])
	k = c
	for i in range(n):
		ans2 += abs(k ** i - ar[i])
	print(min(ans1, ans2))
solve()


n = int(input())
a = list(map(int, input().split()))
a.sort()
if n >= 35:
	sum0 = 0
	for j in range(n):
		sum0 = sum0 + a[j] - 1
	print(sum0)
else:
	c = 1
	while c ** (n - 1) < a[n - 1]:
		c = c + 1
	if c == 1:
		sum0 = 0
		b = 1
		for j in range(n):
			if a[j] - b > 0:
				k = a[j] - b
			else:
				k = b - a[j]
			sum0 = sum0 + k
			print(sum0)
	else:
		sum1 = 0
		b = 1
		for j in range(n):
			if a[j] - b > 0:
				k = a[j] - b
			else:
				k = b - a[j]
			sum1 = sum1 + k
			b = b * c
		sum2 = 0
		b = 1
		for j in range(n):
			if a[j] - b > 0:
				k = a[j] - b
			else:
				k = b - a[j]
			sum2 = sum2 + k
			b = b * (c - 1)
		if sum1 > sum2:
			print(sum2)
		else:
			print(sum1)


from sys import stdin
n = int(stdin.readline())
array = list(map(int, stdin.readline().split()))
sorts = sorted(array)
end = sorts[-1]
ans = float('inf')
buff = 0
cur = 1
while cur ** (n - 1) <= end:
	buff = 0
	for i in range(n):
		buff += abs(sorts[i] - cur ** i)
	ans = min(buff, ans)
	cur += 1
buff = 0
for i in range(n):
	buff += abs(sorts[i] - cur ** i)
ans = min(buff, ans)
print(ans)


n = int(input())
l = list(map(int, input().split()))
l.sort()
x = l[n - 1]
y = 1
p = []
s = 0
for i in range(2, 100000):
	if i ** (n - 1) <= x:
		y = i
	else:
		break
for i in range(n):
	s = s + l[i] - 1
p.append(s)
s = 0
for i in range(0, n):
	s = s + abs(y ** i - l[i])
p.append(s)
s = 0
for i in range(0, n):
	s = s + abs((y + 1) ** i - l[i])
p.append(s)
p.sort()
print(p[0])


from collections import Counter
import string
import math

def array_int():
	return [int(i) for i in input().split()]

def vary(number_of_variables):
	if number_of_variables == 1:
		return int(input())
	if number_of_variables >= 2:
		return map(int, input().split())

def makedict(var):
	return dict(Counter(var))
mod = 1000000007
n = vary(1)
num = array_int()
num.sort()
cou = []
nt = max(num)
maxi = 10 ** 18
maxi2 = maxi
for i in range(1, 10 ** 9):
	c = 0
	for j in range(n):
		c += abs(num[j] - pow(i, j))
	if c > maxi2:
		break
	else:
		maxi = min(maxi, c)
		maxi2 = c
print(maxi)


n = int(input())
l = list(map(int, input().split()))
l.sort()
s = sum(l)
c = 1
o = float('inf')
a = t = 0
while t < s:
	t = sum((abs(c ** i - l[i]) for i in range(n)))
	if t < o:
		a = c
		o = t
	c += 1
print(o)


import sys
import math

def readStr():
	return sys.stdin.readline().rstrip()

def readInts():
	return list(map(int, readStr().split(' ')))

def readLatins():
	return [ord(c) - 97 for c in readStr()]

def diff(n, a, c):
	d = 0
	for i in range(n):
		d += abs(a[i] - pow(c, i))
	return d

def main(n, a):
	a.sort()
	c = 0
	d = diff(n, a, c)
	while True:
		d1 = diff(n, a, c + 1)
		if d1 > d:
			break
		c += 1
		d = d1
	return d
(n,) = readInts()
a = readInts()
x = main(n, a)
print(x)


n = int(input())
l = list(map(int, input().strip().split()))[:n]
l.sort()
f = sum(l) - n
cost = f
x = 2
while x ** (n - 1) < f + l[-1]:
	(currCost, p) = (0, 1)
	for i in range(n):
		currCost += abs(l[i] - p)
		p *= x
	cost = min(cost, currCost)
	x += 1
print(cost)


n = int(input())
l = list(map(int, input().split()))
l.sort()
benchmark = sum([abs(x - 1) for x in l])

def f(num):
	err = 0
	for (i, x) in enumerate(l):
		err += abs(x - num ** i)
		if err > benchmark:
			return float('inf')
	return err
x = 10000000000.0 + 1
ans = 0
while x > 0:
	while f(ans + x) > f(ans + x + 1):
		ans += x
	x //= 2
ans += 1
total = sum([int(abs(x - ans ** i)) for (i, x) in enumerate(l)])
print(total)


from math import log
import sys
input = sys.stdin.readline

def solution():
	n = int(input())
	A = list(map(int, input().split()))
	A.sort()
	ans = sum(A) - n
	if n <= 2:
		print(A[0] - 1)
		return
	for i in range(2, 1000000):
		if i ** (n - 1) > A[-1] * (n + 1):
			break
		S = 0
		t = 1
		for j in range(n):
			S += abs(A[j] - t)
			t *= i
		ans = min(ans, S)
	print(ans)
solution()


n = int(input())
l = sorted(list(map(int, input().split())))
a = sum((i - 1 for i in l))
if n < 34:
	x = int(1000000000 ** (1 / (n - 1)))
	for r in range(2, x + 2):
		a = min(a, sum([abs(l[i] - r ** i) for i in range(n)]))
print(a)


import math
n = int(input())
a = [int(x) for x in input().split()]
if n > 33:
	print(sum(a) - n)
	exit(0)
a.sort()
c = int(1 + math.pow(10, math.log10(a[-1]) / (n - 1)))
if n > 10:
	2 ^ n - 1 >= 10 < 100 / 3
(sumo, pc) = (0, 1)
for x in a:
	sumo += abs(x - pc)
	pc *= c
(sumo1, pc) = (0, 1)
c -= 1
for x in a:
	sumo1 += abs(x - pc)
	pc *= c
sumo1 = min(sumo, sumo1)
print(sumo1)


n = int(input())
a = list(map(int, input().split()))
a.sort()
c = 1
mx = 10 ** 11 + 9
res = 1152921504606846975
while c ** (n - 1) < mx:
	sum = 0
	for i in range(len(a) - 1, -1, -1):
		sum += abs(c ** i - a[i])
	res = min(res, sum)
	c += 1
print(res)


n = int(input())
A = sorted([int(_) for _ in input().split()])
m = int(pow(A[-1], 1 / (n - 1)))
_ = 0
(x, y) = (0, 0)
for _ in range(n):
	u = pow(m, _)
	x += abs(u - A[_])
for _ in range(n):
	v = pow(m + 1, _)
	y += abs(v - A[_])
print(min(x, y))


n = int(input())
nums = list(map(int, input().split()))
nums.sort()
if n > 50:
	print(sum(nums) - n)
	exit(0)

def cal(x):
	cur = 1
	ans = 0
	for i in range(n):
		ans += abs(cur - nums[i])
		cur *= x
	return ans
out = 10000000000000000
for j in range(1, int(nums[-1] ** (1 / (n - 1))) + 1000):
	c = cal(j)
	if c < out:
		out = c
print(out)


n = int(input())
arr = [int(i) for i in input().split()]
c = 2
cutoff_cost = 0
arr = sorted(arr)
for i in arr:
	cutoff_cost += abs(i - 1)
ans = cutoff_cost
while c ** (n - 1) < cutoff_cost + arr[-1]:
	tmpans = 0
	for j in range(n):
		tmpans += abs(c ** j - arr[j])
	ans = min(ans, tmpans)
	c += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
c = int(a[-1] ** (1 / (n - 1)))
res1 = sum((abs(c ** i - a[i]) for i in range(n)))
res2 = sum((abs((c + 1) ** i - a[i]) for i in range(n)))
print(res1 if res1 < res2 else res2)


import math
from sys import stdin
n = int(stdin.readline().rstrip())
a = list(map(int, stdin.readline().rstrip().split(' ')))
a.sort()
res1 = 0
res2 = 0
c = int(math.exp(math.log(a[-1]) / (n - 1)))
c2 = c + 1
if n > 32:
	c = 1
	c2 = 1
for i in range(n):
	res1 += abs(a[i] - c ** i)
	res2 += abs(a[i] - c2 ** i)
print(min(res1, res2))


N = int(input())
A = list(map(int, input().split()))
A.sort()
mav = A[N - 1]
r = 0
m = 99999999999999
h = 99999999999999999999
for j in range(1, h):
	k = 1
	r = 0
	for i in range(N):
		r = r + abs(k - A[i])
		k = k * j
		if k > 100000000000000:
			break
	if k > 100000000000000:
		break
	m = min(m, r)
print(m)


def main():
	length = int(input())
	l = input().split()
	lint = [int(n) for n in l]
	lint.sort()
	mini = 0
	val = int(lint[length - 1] ** (1 / (length - 1)))
	for j in range(val - 1, val + 2):
		s = lint[0] - 1
		for i in range(1, length):
			s += abs(j ** i - lint[i])
		if s < mini or mini == 0:
			mini = s
	print(mini)
main()


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
fun = a[n - 1]
f = fun ** (1 / (n - 1))
b = math.ceil(f)
c = int(f)
s = 0
s1 = 0
for i in range(n):
	s = s + abs(a[i] - b ** i)
	s1 = s1 + abs(a[i] - c ** i)
print(min(s, s1))


def diff(arr, n, exp):
	suma = 0
	for i in range(n):
		suma += abs(arr[i] - exp ** i)
	return suma
n = int(input())
arr = sorted([int(i) for i in input().split()])
exp = int(arr[-1] ** (1 / (n - 1)))
mini = diff(arr, n, exp)
exp += 1
while True:
	temp = diff(arr, n, exp)
	if mini > temp:
		mini = temp
		exp += 1
	else:
		print(mini)
		break


n = int(input())
s = [int(x) for x in input().split()]
s.sort()
tot = 0
for i in range(0, len(s)):
	tot += s[i]
diff = tot - n
ans = tot - n
for i in range(2, 100005):
	tt = abs(pow(i, n - 1) - s[-1])
	if tt > diff:
		break
	sumu = 0
	for j in range(0, n):
		sumu += abs(pow(i, j) - s[j])
	ans = min(ans, sumu)
print(ans)


n = int(input())
ai = list(map(int, input().split()))
ai.sort()
summ = 1e+19
val = []
li = []
ct = 0
c = ai[-1] ** (1.0 / float(n - 1))
c = int(c)
d = c + 1
for i in range(0, n):
	ct += abs(ai[i] - c ** i)
summ = min(summ, ct)
ct = 0
for i in range(0, n):
	ct += abs(ai[i] - d ** i)
summ = min(summ, ct)
print(summ)


from sys import stdin, stdout
input = stdin.readline

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

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

def gets():
	return input('')

def geta():
	return int(input())

def print_s(s):
	stdout.write(s + '\n')

def solve():
	n = geta()
	a = getl()
	ans = float('inf')
	a.sort()
	if n > 32:
		print(sum(a) - n)
		return
	r = 1
	while True:
		temp = 0
		prefix = [1]
		for i in range(n):
			temp += abs(prefix[-1] - a[i])
			prefix.append(prefix[-1] * r)
		ans = min(ans, temp)
		if r ** (n - 1) > a[-1]:
			break
		r += 1
	print(ans)
solve()


INF = int(1e+18)
n = int(input())
a = list(map(int, input().split()))
a.sort()
res = 0
for i in a:
	res += i
i = 1
while True:
	(val, prod) = (0, 1)
	for j in range(n):
		val += abs(a[j] - prod)
		prod *= i
		if val > INF:
			val = -1
			break
	if val > res or val == -1:
		break
	res = val
	i += 1
print(res)


n = int(input())
l = [int(i) for i in input().split()]
l.sort()
inf = 10 ** 18
if n <= 2:
	print(l[0] - 1)
else:
	ans = sum(l) - n
	for p in range(1, 10 ** 9):
		current_power = 1
		current_cost = 0
		for i in range(n):
			current_cost += abs(l[i] - current_power)
			current_power *= p
			if current_power > inf:
				break
		if current_power > inf:
			break
		if current_power / p > ans + l[n - 1]:
			break
		ans = min(current_cost, ans)
	print(ans)


import sys
from sys import stdin
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
if n >= 100:
	print(sum(a) - n)
	sys.exit()
a.sort()
nans = sum(a) - n
c = 1
while c ** 2 <= 2 * 10 ** 9:
	if c ** (n - 1) >= 10 ** 12:
		break
	now = 0
	for i in range(n):
		now += abs(a[i] - c ** i)
	nans = min(now, nans)
	c += 1
print(nans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
mx = a[n - 1]
x = pow(mx, 1 / (n - 1))
x = int(x)
y = x + 1
m = k = 0
for i in range(n):
	t = pow(x, i)
	m += abs(a[i] - t)
	t = pow(y, i)
	k += abs(a[i] - t)
ans = min(m, k)
print(ans)


def f(mas, x):
	out = 0
	t = 1
	for i in range(len(mas)):
		out += abs(mas[i] - t)
		t *= x
	return out
n = int(input())
mas = list(map(int, input().split()))
mas.sort()
a_max = mas[-1]
d = f(mas, 1)
w = 1
out = d
while w ** (n - 1) <= d + a_max:
	out = min(out, f(mas, w))
	w += 1
print(out)


mod = 10 ** 9 + 7

def f(x):
	n = len(a)
	s = 0
	p = 1
	for i in range(n):
		s += abs(a[i] - p)
		p *= x
		if s > 10 ** 30:
			break
	return s

def solve():
	n = int(input())
	global a
	a = list(map(int, input().split()))
	a.sort()
	ans = 10 ** 30
	for i in range(1, 1000):
		ans = min(ans, f(i))
	if n < 1000:
		for i in range(1000, 100000):
			ans = min(ans, f(i))
	print(ans)
t = 1
while t > 0:
	solve()
	t -= 1


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
temp = round(a[-1] ** (1 / (n - 1)))
final = 10 ** 20
for j in range(temp - 3, temp + 3):
	ans = 0
	curr = 1
	for i in range(n):
		ans += abs(a[i] - curr)
		if ans > final:
			break
		curr *= j
	final = min(final, ans)
print(final)


import math
n = int(input())
arr = [int(a) for a in input().split()]
arr.sort()
rt = arr[-1] ** (1.0 / (n - 1))
rtA = int(rt)
rtB = rtA + 1
ansA = 0
ansB = 0
for i in range(n):
	ansA += abs(arr[i] - rtA ** i)
	ansB += abs(arr[i] - rtB ** i)
if ansA < ansB:
	print(int(ansA))
else:
	print(int(ansB))


import sys

def i():
	return sys.stdin.readline()[:-1]
n = int(i())
nums = sorted(list(map(int, i().split())))
s = sum(nums) - n
minCost = s
x = 2
while x ** (n - 1) <= s + nums[-1]:
	cost = 0
	power = 1
	for num in nums:
		cost += abs(power - num)
		power *= x
	minCost = min(cost, minCost)
	x += 1
print(minCost)


n = int(input())
li = list(map(int, input().split()))
li.sort()
t = li[-1]
m = t ** (1 / (n - 1))
m = int(m)
s = 0
for i in range(0, n):
	s += abs(m ** i - li[i])
m = int(m) + 1
s1 = s
s = 0
for i in range(0, n):
	s += abs(m ** i - li[i])
print(min(s, s1))


n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
a.sort()
cost = 0
for i in range(n):
	a.append(a[i])
	cost += a[i] - 1
if n > 50:
	print(cost)
else:
	cost = -1
	for i in range(1, 1000000000):
		curr = 0
		c = 1
		for j in range(n):
			curr += abs(a[j] - c)
			c *= i
		if cost == -1:
			cost = curr
		elif cost < curr:
			break
		elif cost >= curr:
			cost = curr
	print(cost)


import math
n = int(input())
s = [int(i) for i in input().split()]
cnt = 0
s.sort()
l = math.floor(pow(s[n - 1], 1 / (n - 1)))
m = math.ceil(pow(s[n - 1], 1 / (n - 1)))
for i in range(n):
	cnt += abs(s[i] - pow(m, i))
p = 0
for i in range(n):
	p += abs(s[i] - pow(l, i))
print(min(p, cnt))


n = int(input())
import math
a = list(map(int, input().split()))
a.sort()
c = n - 1
z = int(a[-1] ** (1 / c))
ans = 0
for i in range(n - 1, -1, -1):
	ans = ans + abs(z ** i - a[i])
z = math.ceil(a[-1] ** (1 / c))
ans1 = 0
for i in range(n - 1, -1, -1):
	ans1 = ans1 + abs(z ** i - a[i])
print(min(ans, ans1))


def p(a, n):
	c = 0
	mc = 999999999999999999999999
	lc = mc
	for i in range(max(a)):
		c += 1
		tc = 0
		for j in range(n):
			tc += abs(c ** j - a[j])
		if tc < mc:
			mc = tc
		if lc <= tc:
			break
		lc = tc
	return mc
n = int(input())
a = list(map(int, input().split()))
a.sort()
print(p(a, n))


import math
n = int(input())
a = list(map(int, input().split(' ')))
a.sort()
M = math.floor(a[-1] ** (1 / (n - 1)))
m = [M, M + 1]
mx = a[-1] * n
for i in m:
	count = 0
	for j in range(n):
		count += abs(a[j] - i ** j)
	if count < mx:
		mx = count
print(mx)


n = int(input())
l = list(map(int, input().split()))
i0 = 0
l.sort()
while i0 ** (n - 1) < max(l):
	i0 += 1
sum = 0
sum1 = 0
for i in range(n):
	sum += abs(l[i] - i0 ** i)
	sum1 += abs(l[i] - (i0 - 1) ** i)
print(min(sum, sum1))


from sys import stdin, stdout
input = stdin.readline
from math import ceil
n = int(input())
a = sorted(list(map(int, input().split())))
if n <= 1000:
	(f, c) = (int(a[-1] ** (1 / (n - 1))), ceil(a[-1] ** (1 / (n - 1))))
	if f:
		(ansf, ansc) = (0, 0)
		(currf, currc) = (1, 1)
		for i in range(n):
			ansf += abs(a[i] - currf)
			currf *= f
			ansc += abs(a[i] - currc)
			currc *= c
		print(min(ansf, ansc))
	else:
		ansc = 0
		curr = 1
		for i in range(n):
			ansc += abs(a[i] - curr)
			curr *= c
		print(min(ansf, ansc))
else:
	r = round(a[-1] ** (1 / (n - 1)))
	ansr = 0
	curr = 1
	for i in range(n):
		ansr += abs(a[i] - curr)
		curr *= r
	print(ansr)


import math
n = int(input())
values = list(map(int, input().split()))
values.sort()
min = 1000000000000000007
i = 1
while True:
	c = 1
	count = 0
	for j in range(n):
		count += abs(values[j] - c)
		if count > min:
			break
		c *= i
	if count < min:
		min = count
	else:
		break
	i += 1
print(min)


import sys
from math import ceil, factorial, gcd
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify
MOD = 10 ** 9 + 7
INF = float('inf')
rl = lambda : list(map(int, sys.stdin.readline().split()))
rs = lambda : sys.stdin.readline().strip()
n = int(input())
A = rl()
A.sort()
(ans1, ans2) = (0, 0)
base = A[-1] ** (1 / (n - 1))
for (i, a) in enumerate(A):
	ans1 += abs(a - ceil(base) ** i)
	ans2 += abs(a - int(base) ** i)
print(min(ans1, ans2))


import sys
input = sys.stdin.readline

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

def inlt(n):
	return list(map(int, input().split()))[:n]

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
n = inp()
a = inlt(n)
a.sort()
sumt = 0
for i in range(n):
	sumt = sumt + a[i]
c = 1
ans = sumt - n
while pow(c, n - 1) - a[n - 1] <= sumt - n:
	curr = 0
	for i in range(n):
		tmp = pow(c, i) - a[i]
		if tmp < 0:
			tmp = -tmp
		curr = curr + tmp
	ans = min(ans, curr)
	c += 1
print(ans, end='\n')


n = int(input())
arr = list(map(lambda x: int(x), input().split()))
arr.sort()
max_ans = sum(arr) - n
ans = max_ans
inf = 10 ** 18
c = 1
while True:
	c += 1
	c_pow_i = 1
	temp_ans = 0
	diff = 0
	for i in range(0, n):
		diff = abs(arr[i] - c_pow_i)
		temp_ans += diff
		c_pow_i *= c
		if c_pow_i > inf:
			break
	if c_pow_i > inf:
		break
	if diff > max_ans:
		break
	else:
		ans = min(ans, temp_ans)
print(ans)


import math
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
big = math.ceil(max(arr) ** (1 / (n - 1)))
small = big - 1
ans1 = 0
ans2 = 0
for (i, x) in enumerate(arr):
	ans1 += abs(pow(big, i) - x)
	ans2 += abs(pow(small, i) - x)
print(min(ans1, ans2))


def power(x, y):
	res = 1
	while y > 0:
		if y & 1:
			res *= x
		y = y // 2
		x = x * x
	return res
n = int(input())
li = [int(x) for x in input().split()]
li.sort()
Sum = 0
for x in li:
	Sum += x - 1
if n > 60:
	print(Sum)
elif n <= 5:
	cnt = Sum
	for i in range(1, 100001):
		Sum = 0
		for j in range(n):
			Sum += abs(li[j] - pow(i, j))
		cnt = min(cnt, Sum)
	print(cnt)
else:
	cnt = Sum
	for i in range(1, 10001):
		Sum = 0
		for j in range(n):
			Sum += abs(li[j] - power(i, j))
		cnt = min(cnt, Sum)
	print(cnt)


n = int(input())
s = list(map(int, input().split()))
s.sort()
c = 1
ans = float('inf')
while c ** (n - 1) <= 10 ** 12:
	tmp = 0
	for i in range(n):
		tmp += abs(c ** i - s[i])
	ans = min(ans, tmp)
	c += 1
print(ans)


from math import log, floor
N = int(input())
List = [int(x) for x in input().split()]
List.sort()
Ans = 10 ** 20
i = 1
while i < 10 ** 5:
	if i ** (N - 1) > 10 ** 18:
		break
	count = 0
	for j in range(N):
		count += abs(List[j] - i ** j)
	Ans = min(Ans, count)
	i += 1
print(Ans)


import math

def method(a, v, n):
	s = 0
	for i in range(n):
		s += abs(a[i] - v ** i)
	return s
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
v = a[-1]
v = math.pow(v, 1 / (n - 1))
v1 = math.floor(v)
v2 = math.ceil(v)
if v1 == v2:
	print(method(a, v1, n))
else:
	val = min(method(a, v1, n), method(a, v2, n))
	print(val)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
base_less = int(a[-1] ** (1 / (n - 1)))
base_more = base_less + 1
difference_less = sum((abs(a_i - base_less ** i) for (i, a_i) in enumerate(a)))
difference_more = sum((abs(a_i - base_more ** i) for (i, a_i) in enumerate(a)))
print(min(difference_less, difference_more))


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.buffer.readline().rstrip()
q = int(input())
w = sorted(list(map(int, input().split())))
e = sum(w)
l = 10000000000000000000
r = int(10 ** ((math.log(q, 10) + 9) / (q - 1)))
t = 0
if q == 3:
	for i in range(100000):
		k = 0
		for j in range(q):
			k += abs(w[j] - i ** j)
		l = min(l, k)
	print(l)
else:
	for i in range(r + 1):
		k = 0
		for j in range(q):
			k += abs(w[j] - i ** j)
			t += i ** j
		l = min(l, k)
	print(l)


n = int(input())
l = list(map(int, input().split()))
l.sort()
maxi = 10 ** 14
ans = maxi
for c in range(1, maxi):
	cur = 0
	p = 1
	for j in range(n):
		cur += abs(l[j] - p)
		p = p * c
		if cur >= maxi:
			break
	if cur >= ans:
		break
	ans = min(ans, cur)
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
b = pow(a[-1], 1 / (n - 1))
base1 = int(b)
base2 = int(b) + 1
ans1 = 0
ans2 = 0
for i in range(0, n):
	ans1 += abs(pow(base1, i) - a[i])
	ans2 += abs(pow(base2, i) - a[i])
print(min(ans1, ans2))


n = int(input())
s = sorted(map(int, input().split()))
c = 1
mx = 10 * 10 ** 9 + 9
ans = float('inf')
while c ** (n - 1) < mx:
	cur = 0
	for i in range(n):
		cur += abs(s[i] - c ** i)
	c += 1
	ans = min(ans, cur)
print(ans)


n = int(input())
arr = list(map(int, input().split()))
sol = -1
arr.sort()
bnd = int(1000000.0 - n)
c = 1
while c ** (n - 1) < arr[-1] * (n + 1):
	curr = 0
	for i in range(len(arr)):
		curr += abs(arr[i] - c ** i)
	if sol == -1 or curr < sol:
		sol = curr
	c += 1
print(sol)


n = int(input())
s = map(int, input().split())
s = sorted(s)
i = 1
while i ** (n - 1) < s[-1]:
	i += 1
mi = float('inf')
for k in range(1, i + 1):
	a = 0
	for j in range(n):
		a += abs(k ** j - s[j])
	if a < mi:
		mi = a
print(mi)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 99999999999999999999999999999999999999999999999999999999999
for c in range(0, 100000):
	tec = 0
	for i in range(n):
		if c ** i > int(1e+18):
			break
		tec += abs(a[i] - c ** i)
	ans = min(ans, tec)
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
c = int(a[-1] ** (1 / (n - 1)))
count1 = 0
count2 = 0
_sum = 0
for i in range(n):
	count1 += abs(c ** i - a[i])
	count2 += abs((c + 1) ** i - a[i])
print(min(count1, count2))


a = int(input())
arr = list(map(int, input().split()))
arr.sort()
n = 0
k = 0
prevans = float('inf')
while True:
	ans = 0
	for i in range(0, len(arr)):
		ans = ans + abs(pow(n, i) - arr[i])
		if ans > prevans:
			k = 1
			break
	n = n + 1
	if k == 1:
		break
	prevans = ans
print(prevans)


import sys
input = sys.stdin.readline

def print(val):
	sys.stdout.write(str(val) + '\n')

def prog():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	c = 1
	mn_cost = 10 ** 9 * (n + 1)
	while c ** (n - 1) < 10 ** 9 * (n + 1):
		cost = 0
		curr = 1
		for i in range(n):
			cost += abs(a[i] - curr)
			curr *= c
		mn_cost = min(mn_cost, cost)
		c += 1
	print(mn_cost)
prog()


import math

def calc(a, b):
	s = 0
	for i in range(len(a)):
		s += abs(a[i] - b ** i)
	return s
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = int(a[-1] ** (1 / (n - 1)))
m = calc(a, b)
for i in range(1, 10000):
	mt = calc(a, b + i)
	if mt <= m:
		m = mt
	else:
		break
for i in range(b, 0, -1):
	mt = calc(a, i)
	if mt <= m:
		m = mt
	else:
		break
print(m)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
n = int(input())
arry = list(map(int, input().split()))
maxNum = max(arry)
maxRecur = maxNum ** (1 / (n - 1))
currMin = float('inf')
arry.sort()
for i in range(int(maxRecur) + 2):
	curr = 0
	for j in range(n):
		curr += abs(i ** j - arry[j])
	currMin = min(currMin, curr)
print(currMin)


n = int(input())
inp = list(map(int, input().split()))
inp.sort()
i = 0
j = 0
while i ** (n - 1) <= inp[-1]:
	i += 1
while (j + 1) ** (n - 1) <= inp[-1]:
	j += 1
sm = 0
sm2 = 0
for z in range(n):
	sm += abs(inp[z] - i ** z)
	sm2 += abs(inp[z] - j ** z)
print(min(sm, sm2))


import math

def isSorted(l):
	return all((l[i] <= l[i + 1] for i in range(len(l) - 1)))

def numStepsTo(n, sortedArr, c):
	result = 0
	for (a, b) in zip(sortedArr, (c ** i for i in range(n))):
		result += abs(a - b)
	return result

def getC(arr, n):
	return round(max(arr) ** (1 / (n - 1)))

def fast(n, arr):
	result = float('inf')
	C = getC(arr, n)
	sortedArr = sorted(arr)
	cAns = -1
	for c in [C - 1, C, C + 1]:
		if c > 0:
			currSteps = numStepsTo(n, sortedArr, c)
			result = min(result, currSteps)
	return result

def main():
	n = int(input())
	arr = [int(x) for x in input().split()]
	result = fast(n, arr)
	print(result)
main()


import math
n = int(input())
A = list(map(int, input().split()))
A.sort()
c = A[-1] ** (1 / (n - 1))
c1 = math.ceil(c)
c2 = math.floor(c)
if c2 == 0:
	c2 = c1
(a1, a2) = (0, 0)
for i in range(n):
	a1 += abs(A[i] - pow(c1, i))
	a2 += abs(A[i] - pow(c2, i))
print(min(a1, a2))


import sys
for _ in range(1):
	n = int(input())
	a = [int(x) for x in input().split()]
	a.sort()
	best = 1e+18
	for c in range(100000):
		good = True
		x = 1
		for i in range(n - 1):
			x *= c
			if x > 1000000000000.0:
				good = False
				break
		if good:
			cur = 0
			x = 1
			for i in range(0, n):
				cur += abs(a[i] - x)
				x *= c
			best = min(best, cur)
	print(best)


def power(n, seq):
	seq.sort()
	res = float('inf')
	c = 1
	while True:
		ans = 0
		for i in range(n):
			ans += abs(c ** i - seq[i])
		if res > ans:
			res = ans
			c += 1
			if c ** (n - 1) >= 10 ** 18:
				break
		else:
			break
	return res
res = []
n = int(input())
par = list(map(int, input().split()))
print(power(n, par))


(N, A) = open(0)
A = sorted(map(int, A.split()))
N = int(N)
print(min((sum((abs(v - c ** i) for (i, v) in enumerate(A))) for c in range(1, [2, 9 ** 6 // N][N < 50]))))


import math
n = int(input())
num = list(map(int, input().split()))
count1 = 0
count2 = 0
num.sort()
r = num[n - 1] ** (1 / (n - 1))
c1 = math.floor(r)
c2 = math.ceil(r)
for j in range(n):
	count1 += abs(c1 ** j - num[j])
	count2 += abs(c2 ** j - num[j])
print(min(count1, count2))


n = int(input())
line = input()
arr = [int(val) for val in line.split()]
arr.sort()
mx = arr[n - 1]
root = int(mx ** (1 / (n - 1)))
ans = 10 ** 20
for i in range(-1000, 1000):
	curr = root + i
	if curr <= 0:
		continue
	if curr == 1:
		continue
	val = 0
	counter = 0
	temp = 1
	while temp <= 10 ** 10:
		counter += 1
		temp *= curr
	if counter < n:
		continue
	temp = 1
	for x in arr:
		val += abs(x - temp)
		temp *= curr
	ans = min(ans, val)
val = 0
for x in arr:
	val += abs(x - 1)
ans = min(ans, val)
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
mxN = 10 ** 20
ans = 10 ** 20
for i in range(1, 10 ** 5):
	(val, res) = (1, 0)
	for j in range(n):
		if val * i > mxN:
			print(ans)
			exit()
		else:
			res += abs(val - a[j])
			val *= i
	ans = min(ans, res)
print(ans)


import math
n = int(input())
l = [int(x) for x in input().split()]
l.sort()
x = sum(l)
if n < 60:
	num = l[-1] ** (1 / (n - 1))
	a = int(num)
	b = math.ceil(num)
	a1 = 0
	a2 = 0
	v1 = 1
	v2 = 1
	for i in range(n):
		a1 += abs(l[i] - v1)
		a2 += abs(l[i] - v2)
		v1 *= a
		v2 *= b
	print(min(a1, a2))
else:
	s = 0
	for i in l:
		s += i - 1
	print(s)


from math import *
n = int(input())
res = [int(x) for x in input().split(' ')]
res.sort()
cost = res[0] - 1
res[0] = 1
c = pow(res[-1], 1 / (n - 1))
lowCost = sum((abs(x - pow(floor(c), k)) for (k, x) in enumerate(res)))
try:
	upCost = sum((abs(x - pow(ceil(c), k)) for (k, x) in enumerate(res)))
	print(cost + int(min(lowCost, upCost)))
except:
	print(cost + int(lowCost))


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
ans = 100000000000000000000
MaxN = int((10 ** 13) ** (1 / (n - 1))) + 1
for i in range(1, MaxN + 1):
	sum = abs(a[0] - 1)
	for j in range(1, n):
		sum = sum + abs(i ** j - a[j])
	if sum < ans:
		ans = sum
		p = i
	else:
		break
	if ans == 0:
		break
print(ans)


import sys
import math
input = sys.stdin.readline

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

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

def get_char_list():
	return list(input().strip())
n = get_int()
ints = get_int_list()
ints.sort()
result = None
c = 1
while True:
	a = 1
	tv = 0
	finished = False
	for (i, v) in enumerate(ints):
		tv += abs(v - a)
		if result is not None and tv > result:
			finished = True
			break
		a *= c
	if finished:
		break
	if result is None or tv < result:
		result = tv
	c += 1
print(result)


import sys
input = sys.stdin.readline
from math import log
n = int(input())
a = list(map(int, input().split()))
a.sort()
mx = 1
while mx ** (n - 1) <= 1000000000.0:
	mx += 1
if mx ** (n - 1) > 1e+20:
	mx = 1
ans = float('inf')
for i in range(1, mx + 1):
	mn = 0
	p = 1
	for j in a:
		mn += abs(p - j)
		p *= i
	ans = min(ans, mn)
print(ans)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
sys.setrecursionlimit(100000000)
ii = lambda : int(input())
si = lambda : input()
jn = lambda x, l: x.join(map(str, l))
sl = lambda : list(map(str, input().strip()))
mi = lambda : map(int, input().split())
mif = lambda : map(float, input().split())
lii = lambda : list(map(int, input().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
mod = 1000000007
n = ii()
arr = lii()
arr.sort()
step = 0
b = int(arr[n - 1] ** (1 / (n - 1)))
a = b + 1
for i in range(n):
	step += abs(arr[i] - b ** i)
stepa = 0
for i in range(n):
	if a ** i > 10 ** 15:
		break
	stepa += abs(arr[i] - a ** i)
sol = min(stepa, step)
print(sol)


def solve(arr):
	arr.sort()
	c = 2
	ans = sum((v - 1 for v in arr))
	while True:
		cur = 1
		cur_ans = 0
		for v in arr:
			if cur - arr[-1] > ans:
				return ans
			cur_ans += abs(v - cur)
			cur *= c
		ans = min(ans, cur_ans)
		c += 1
n = int(input())
(*arr,) = list(map(int, input().split()))
print(solve(arr))


import math
n = int(input())
l = list(map(int, input().split()))
l.sort()
one = math.floor(l[n - 1] ** (1 / (n - 1)))
two = math.ceil(l[n - 1] ** (1 / (n - 1)))
ans = 10 ** 18
for value in [one, two]:
	cost = 0
	for i in range(len(l)):
		cost += abs(value ** i - l[i])
	ans = min(ans, cost)
print(ans)


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
su = sum(a) - n
if n >= 60:
	print(su)
	exit(0)

def comp(po, lis):
	polis = [po ** i for i in range(len(lis))]
	su = 0
	for i in range(len(lis)):
		su += abs(lis[i] - polis[i])
	return su
maxval = math.ceil(max(a) ** (1 / (n - 1)))
pows = [maxval - 1, maxval, maxval + 1]
ans = su
for p in pows:
	ans = min(ans, comp(p, a))
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
if n > 40:
	ans = 0
	for i in range(n):
		ans += abs(a[i] - 1)
	print(ans)
	exit(0)

def get(x):
	(cur, res) = (1, 0)
	for i in range(n):
		res += abs(a[i] - cur)
		cur *= x
	return res
(l, r) = (1, 40000)
while r - l >= 3:
	d = (r - l) // 3
	(m1, m2) = (l + d, r - d)
	if get(m1) > get(m2):
		l = m1
	else:
		r = m2
ans = get(l)
for i in range(l + 1, r + 1):
	ans = min(ans, get(i))
print(ans)


import math
n = int(input())
number = sorted(list(map(int, input().split())))
floor = math.floor(number[-1] ** (1 / (n - 1)))
ceil = math.ceil(number[-1] ** (1 / (n - 1)))
ans = 0
if abs(number[-1] - floor ** (n - 1)) + abs(number[-2] - floor ** (n - 2)) + abs(number[-3] - floor ** (n - 3)) > abs(number[-1] - ceil ** (n - 1)) + abs(number[-2] - ceil ** (n - 2)) + abs(number[-3] - ceil ** (n - 3)):
	hey = ceil
else:
	hey = floor
for i in range(len(number)):
	ans += abs(number[i] - hey ** i)
print(ans)


import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
A.sort()
k = 10 ** 9
if n > 3:
	k = 10 ** 5
m = 10 ** 18
a = m
for i in range(1, k):
	b = 0
	for j in range(n):
		b += abs(A[j] - i ** j)
	if b > a:
		break
	else:
		m = min(b, m)
		a = b
print(m)


def findNthRoot(x, n):
	x = float(x)
	n = int(n)
	if x >= 0 and x <= 1:
		low = x
		high = 1
	else:
		low = 1
		high = x
	epsilon = 0.1
	guess = (low + high) / 2
	while abs(guess ** n - x) >= epsilon:
		if guess ** n > x:
			high = guess
		else:
			low = guess
		guess = (low + high) / 2
	return guess
n = int(input())
arr = sorted(list(map(int, input().split())))
cost1 = 0
cost2 = 0
if 1 < n < 35:
	let = findNthRoot(arr[-1], n - 1) // 1
	for i in range(n):
		cost1 += abs(arr[i] - let ** i)
		cost2 += abs(arr[i] - (let + 1) ** i)
	print(int(min(cost1, cost2)))
elif n <= 1:
	print(int(abs(arr[0] - 1)))
else:
	for i in range(n):
		cost1 += abs(arr[i] - 1)
	print(cost1)


from math import log
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = sum(a) - n
w = 2
while n * log(w) <= log(a[-1]) + 20:
	sum = 0
	for (i, x) in enumerate(a):
		sum += abs(x - w ** i)
	ans = min(sum, ans)
	if sum > ans:
		break
	w += 1
print(ans)


from sys import stdin, stdout

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

def read_ints():
	return map(int, stdin.readline().strip().split(' '))
n = read_int()
a = list(read_ints())
a.sort()
s = sum(a)
cost = s - n
j = 2
while pow(j, n - 1) <= s * 2:
	b = [1]
	for k in range(n - 1):
		b.append(b[-1] * j)
	tot = sum([abs(a[i] - b[i]) for i in range(n)])
	cost = min(cost, tot)
	j += 1
print(cost)


from typing import List
import math

def powerSequence(N: int, inputs: List[int]) -> int:
	inputs.sort()
	max_base = math.ceil(inputs[-1] ** (1 / (N - 1)))
	if N > 60:
		max_base = 1
	min_cost = float('inf')
	for i in range(1, max_base + 1):
		cost = 0
		for j in range(len(inputs)):
			cost += abs(inputs[j] - i ** j)
		min_cost = min(min_cost, cost)
	return min_cost
N = int(input())
inputs = list(map(int, input().split(' ')))
print(powerSequence(N, inputs))


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

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

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

def li():
	return [int(i) for i in input().split()]

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

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=2):
	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):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True

def main():
	n = ii()
	arr = li()
	arr = sorted(arr)
	f1 = 0
	for i in range(n):
		f1 += abs(arr[i] - 1)
	k = 2
	ans = f1
	while True:
		m = 0
		for i in range(n):
			m += abs(arr[i] - pow(k, i))
		ans = min(ans, m)
		k += 1
		if m > f1:
			break
	print(ans)
main()


n = int(input())
A = sorted(list(map(int, input().split())))
ans = sum(A) - n
if n > 47:
	print(ans)
else:
	p = 2
	while p ** (n - 1) < A[-1]:
		p += 1
	ans2 = min(sum((abs((p - 1) ** i - A[i]) for i in range(n))), sum((abs(p ** i - A[i]) for i in range(n))))
	print(min(ans, ans2))


n = int(input())
l = list(map(int, input().split()))
temp = max(l)
c = int(temp ** (1 / float(n - 1)))
l.sort()
(res1, res2, res3) = (0, 0, 0)
for i in range(n):
	res1 += abs(c ** i - l[i])
	res2 += abs((c + 1) ** i - l[i])
	res3 += abs((c - 1) ** i - l[i])
print(min(res1, res2, res3))


from sys import stdin, stdout
input = stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
ans = sum(a) - n
if n < 100:
	c = 2
	while c ** (n - 1) < 2 * sum(a):
		cur = 0
		for i in range(n):
			cur += abs(a[i] - c ** i)
		ans = min(cur, ans)
		c += 1
stdout.write(str(ans) + '\n')


n = int(input())
ar = list(map(int, input().split()))
ar.sort()
last = ar[-1]
pot = int(pow(last, 1 / (n - 1)))
ans1 = 0
ans2 = 0
for i in range(n):
	ans1 += abs(ar[i] - pow(pot, i))
	ans2 += abs(ar[i] - pow(pot + 1, i))
print(min(ans1, ans2))


n = int(input())
lis = []
lis = list(map(int, input().split()))
list.sort(lis)
i = max(1, int(lis[-1] ** (1 / float(n - 1))))
ans = -1
inf = 1e+19
for j in range(i, i + 2):
	sum = 0
	p = 1
	for k in range(n):
		sum += abs(lis[k] - p)
		p *= j
		if p > inf:
			sum = inf + 10
			break
	if ans == -1:
		ans = sum
	else:
		ans = min(ans, sum)
print(ans)


n = int(input())
x = list(map(int, input().split()))
x.sort()
inf = 10 ** 18
if n <= 2:
	print(x[0] - 1)
else:
	ans = sum(x) - n
	for i in range(1, 10 ** 9):
		curPow = 1
		curCost = 0
		for j in range(n):
			curCost += abs(x[j] - curPow)
			curPow *= i
			if curPow > inf:
				break
		if curPow > inf:
			break
		if curPow / i > ans + x[n - 1]:
			break
		ans = min(ans, curCost)
	print(ans)


from math import ceil, floor
a = int(input())
arr = [int(x) for x in input().split()]
m = sorted(arr)
u = a - 1
t = floor(m[a - 1] ** (1 / u))
c = ceil(m[a - 1] ** (1 / u))
ans1 = 0
ans2 = 0
for i in range(a):
	q = c ** i
	ans1 += abs(q - m[i])
for i in range(a):
	q = t ** i
	ans2 += abs(q - m[i])
if ans1 < ans2:
	print(ans1)
else:
	print(ans2)


import math
n = int(input())
arr = list(map(int, input().split()))
if n <= 35:
	arr.sort()
	m = int(max(arr) ** (1 / (n - 1)))
	sMin = float('inf')
	for k in range(1, m + 2):
		s = 0
		for p in range(n):
			s += abs(arr[p] - k ** p)
		sMin = min(sMin, s)
	print(sMin)
else:
	print(sum(arr) - n)


n = int(input())
mas = [int(i) for i in input().split()]
mas.sort()
q = 1000 * 1000 * 1000 * 1000 * 1000
best = 1000 * 1000 * 1000 * 1000 * 1000
for a in range(100000):
	c = 1
	now = 0
	for i in range(n):
		now = now + abs(c - mas[i])
		c *= a
		if now > q or c > q:
			now = q
			break
	best = min(now, best)
print(best)


import math
n = int(input())
ar = [int(k) for k in input().split()]
ar.sort()
mx = max(ar)
c = int(pow(mx, 1 / (n - 1))) + 1
ans = None
tsm = sum(ar)
for i in range(1, c + 1):
	sm = 0
	for k in range(n):
		sm += abs(i ** k - ar[k])
	if ans == None or sm < ans:
		ans = sm
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
c = 1
big = 10 ** 10
ans = float('inf')
while c ** (n - 1) < big:
	s = 0
	for j in range(n):
		s += abs(a[j] - c ** j)
	ans = min(s, ans)
	c += 1
print(ans)


n = int(input())
A = [0 for i in range(n)]
S = input()
A = S.split()
for i in range(n):
	A[i] = int(A[i])
A.sort()
diff = 10000000000000000000000000000000000
for p in range(1, 100000):
	tot = 0
	for i in range(n):
		tot += abs(p ** i - A[i])
	if tot <= diff:
		diff = tot
	else:
		break
print(diff)


n = int(input())
l = list(map(int, input().split()))
l.sort()
m = l[-1]
r = 1
for i in range(m + 1):
	if i ** (n - 1) >= m:
		r = i
		break
(a1, a2, a3) = (0, 0, 0)
for i in range(n):
	a1 += abs(r ** i - l[i])
r -= 1
for i in range(n):
	a3 += abs(r ** i - l[i])
print(min(a1, a3))


import math
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
a.sort()
for i in range(n):
	ans += a[i] - 1
for i in range(2, 10 ** 5):
	k = 0
	l = math.log(10 ** 10, i)
	l = math.ceil(l)
	if l < n:
		continue
	else:
		l = i
		for j in range(n):
			k += abs(a[j] - l ** j)
		ans = min(k, ans)
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
shita = int(a[-1] ** (1 / (n - 1)))
ue = shita + 1
sumshita = 0
sumue = 0
for i in range(n):
	targetshita = shita ** i
	sumshita += abs(targetshita - a[i])
	targetue = ue ** i
	sumue += abs(targetue - a[i])
print(min(sumshita, sumue))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
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 list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

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 pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = 1
	rr = []
	for _ in range(t):
		n = I()
		a = LI()
		a.sort()
		r = inf
		for i in range(1, 10 ** 5):
			t = 0
			for j in range(n):
				t += abs(a[j] - i ** j)
			if t > r:
				break
			r = t
		rr.append(r)
	return JA(rr, '\n')
print(main())


from sys import stdin, stdout
import math
n = int(input())
diff = []
a = list(map(int, stdin.readline().split()))
a.sort()
c = math.ceil(pow(a[n - 1], 1 / (n - 1)))
diff1 = abs(a[n - 1] - pow(c, n - 1))
for i in range(n - 2, -1, -1):
	diff1 += abs(a[i] - pow(c, i))
c -= 1
diff2 = abs(a[n - 1] - pow(c, n - 1))
for i in range(n - 2, -1, -1):
	diff2 += abs(a[i] - pow(c, i))
print(min(diff1, diff2))


n = int(input())
l = list(map(int, input().split()))
l.sort()
mini = float('inf')
if n < 34:
	for i in range(1, 32000):
		ans = 0
		for j in range(n):
			ans += abs(i ** j - l[j])
		if mini > ans:
			mini = ans
			ch = i
	print(mini)
else:
	ans = 0
	for i in range(n):
		ans += l[i] - 1
	print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
z = a[-1] ** (1 / (n - 1))
z1 = int(z)
z2 = z1 + 1
c1 = 0
c2 = 0
for i in range(n):
	c1 += abs(a[i] - z1 ** i)
	c2 += abs(a[i] - z2 ** i)
c = min(c1, c2)
print(c)


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
n = int(z())
l = szzz()
val = l[-1] ** (1 / (n - 1))
pos1 = int(val)
pos2 = ceil(val)
(val1, val2) = (0, 0)
for (i, j) in enumerate(l):
	val1 += abs(j - pos1 ** i)
	val2 += abs(j - pos2 ** i)
print(min(val1, val2))


n = int(input())
a = list(map(int, input().split()))
a.sort()
if n <= 35:
	ans = 10 ** 18
	for x in range(1, 40000):
		cur_ans = 0
		pw = 1
		for i in range(0, n):
			if pw >= a[i]:
				cur_ans += pw - a[i]
			else:
				cur_ans += a[i] - pw
			pw *= x
		ans = min(ans, cur_ans)
	print(ans)
else:
	ans = 10 ** 18
	for x in range(1, 2):
		pw = 1
		cur_ans = 0
		for i in range(0, n):
			if pw >= a[i]:
				cur_ans += pw - a[i]
			else:
				cur_ans += a[i] - pw
			pw *= x
		ans = min(ans, cur_ans)
	print(ans)


import sys
import math

def main():
	N = int(sys.stdin.readline())
	B = sorted([int(i) for i in sys.stdin.readline().split()])
	soln = math.inf
	limit = pow(2, 63)
	X = 1
	stop = False
	while not stop:
		local_soln = 0
		P = 1
		for b in B:
			local_soln += abs(b - P)
			if local_soln > soln:
				stop = True
				break
			P *= X
			if P > limit:
				stop = True
				break
		X += 1
		if not stop:
			soln = min(soln, local_soln)
	print(soln)
main()


def check(x):
	ans = 0
	k = 1
	for i in range(n):
		ans += abs(u[i] - k)
		if ans > INF:
			return INF
		k *= x
	return ans
INF = 10 ** 14
n = int(input())
u = list(map(int, input().split()))
if u[0] == 1:
	k = u[1] * u[1]
	for i in range(2, n):
		if u[i] == k:
			k *= u[1]
		else:
			break
	else:
		print(0)
		exit()
u.sort()
if n == 2:
	print(1)
	exit()
L = 1
R = 10 ** 7
cL = check(L)
cR = check(R)
cnt = 0
while R - L > 2:
	cnt += 1
	cur = (R - L) // 3
	M = L + cur
	N = L + 2 * cur
	cM = check(M)
	cN = check(N)
	if cM <= cN:
		R = N
		cR = cN
	else:
		L = M
		cL = cM
ans = [check(L), check(L + 1), check(L + 2)]
print(min(ans))


import math
n = int(input())
s = list(map(int, input().split()))
s.sort()
x = n - 1
p = 1 / x
c = int(s[-1] ** p)
c1 = c + 1
min1 = 0
min2 = 0
for i in range(n):
	min1 += abs(s[i] - c ** i)
	min2 += abs(s[i] - c1 ** i)
print(min(min1, min2))


def f(arr1, arr2):
	sum = 0
	for i in range(len(arr1)):
		sum += abs(arr1[i] - arr2[i])
	return sum
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
seq = []
const = 31624
for i in range(2, const):
	seq.append([])
	for j in range(40):
		if i ** j > 10 ** 11:
			break
		seq[i - 2].append(i ** j)
if len(arr) > 40:
	print(sum(arr) - len(arr))
elif len(arr) == 2:
	x = arr[0] - 1
	y = arr[1] ** 0.5
	y = round(y)
	y = abs(y ** 2 - arr[1])
	print(x + y)
else:
	my_min = sum(arr) - len(arr)
	for i in seq:
		if len(i) < n:
			continue
		x = f(arr, i)
		if my_min > x:
			my_min = x
	print(my_min)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
if n > 65:
	print(sum(a) - n)
elif n == 1 or n == 2:
	print(a[0] - 1)
else:
	ans = 10 ** 20
	for i in range(1, 50000):
		now = 1
		ta = 0
		for j in a:
			ta += abs(now - j)
			now *= i
		ans = min(ans, ta)
	print(ans)


n = int(input())
l = [int(i) for i in input().split()]
l.sort()
import math
m = pow(n - 1, 1.0 / (n - 1) * (math.log(l[n - 1]) / math.log(n - 1)))
(x, y) = (math.ceil(m), math.floor(m))
(q, S1, S2) = (0, 0, 0)
for i in l:
	S1 += abs(i - pow(x, q))
	S2 += abs(i - pow(y, q))
	q += 1
print(min(S1, S2))


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 10 ** 20
for c in range(1, 4 * 10 ** 4):
	tmp = 0
	for i in range(n):
		tmp += abs(a[i] - c ** i)
	if tmp <= ans:
		ans = tmp
	else:
		print(ans)
		exit()


n = int(input())
a = input().split(' ')
for i in range(n):
	a[i] = int(a[i])
a.sort()
ans = 4557430888798830399
mx = (n + 1) * a[n - 1]
b = 1
while b ** (n - 1) <= mx:
	t = 0
	for i in range(n):
		t += abs(a[i] - b ** i)
	ans = min(ans, t)
	b += 1
print(ans)


import math
L = math.log
n = int(input())
l1 = sorted(list(map(int, input().split())))
high = l1[-1] ** (1 / n)
ans = 0

def difsum(l1, i):
	sumo = 0
	for x in range(len(l1)):
		sumo += abs(l1[x] - i ** x)
	return sumo
for i in range(1, l1[-1]):
	if i == 1:
		targ = difsum(l1, i)
	elif targ > difsum(l1, i):
		targ = difsum(l1, i)
	else:
		break
print(targ)


import math
maxim = 10 ** 15
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
max_power_allowed = n - 1
max_ele = arr[-1]
number = max_ele ** (1 / max_power_allowed)
number = math.ceil(number)
ans = []
for j in range(1, number + 1):
	count = 0
	for i in range(n):
		ele = arr[i]
		power = j ** i
		if power > maxim:
			break
		to_add = abs(power - ele)
		count += to_add
	ans.append(count)
print(min(ans))


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 1 << 63
sqrt = int(math.sqrt(1000000000))
for i in range(1, sqrt + 10):
	p = 1
	cnt = 0
	for v in a:
		cnt += abs(p - v)
		p *= i
		if cnt > ans:
			break
	if cnt > ans:
		break
	ans = min(cnt, ans)
print(ans)


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
maxm = a[len(a) - 1]
val = maxm ** (1 / (len(a) - 1))
a1 = int(val)
a2 = math.ceil(val)
sum1 = 0
sum2 = 0
for i in range(len(a)):
	sum1 += abs(a[i] - a1 ** i)
	sum2 += abs(a[i] - a2 ** i)
print(min(sum1, sum2))


from math import ceil
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
ans = 100000000000000000000000
for i in range(1, ceil(pow(a[-1], 1 / (n - 1))) + 1):
	cur = 0
	for j in range(n):
		cur += abs(a[j] - i ** j)
	ans = min(ans, cur)
print(ans)


n = int(input())
mas = list(map(int, input().split()))
mas.sort()
mini = 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
for m in range(max(2, int(10000000000 ** (1 / (n - 1))) + 1)):
	kol = 1
	otv = 0
	for i in range(0, n):
		otv += abs(mas[i] - kol)
		kol *= m
	mini = min(mini, otv)
print(mini)


import math
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
t3 = 0
m = pow(10, 20)
for i in a:
	t3 += i
if n > 64:
	print(min(abs(t3 - n), t3))
else:
	for i in range(0, math.floor(math.sqrt(max(a))) + 3):
		t2 = 0
		for j in range(n):
			t2 += abs(pow(i, j) - a[j])
		m = min(m, t2)
	print(m)


n = int(input())
a = list(map(int, input().split()))
a.sort()
diff = 10 ** 30
ndiff = 0
i = 0
flag = False
while diff > ndiff:
	if flag:
		diff = ndiff
	flag = True
	ndiff = 0
	for j in range(n):
		ndiff += abs(a[j] - i ** j)
	i += 1
print(diff)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
inf = 10 ** 18
if n <= 2:
	print(a[0] - 1)
else:
	ans = sum(a) - n
	for x in range(1, 10 ** 5):
		curPow = 1
		curCost = 0
		for i in range(n):
			curCost += abs(a[i] - curPow)
			curPow *= x
			if curPow > inf:
				break
		if curPow / x > ans + a[n - 1]:
			break
		ans = min(ans, curCost)
	print(ans)


n = int(input())
nums = sorted(list(map(int, input().split())))
max_int = 10 * 10 ** 9 + 9
c = 1
min_cost = float('inf')
while c ** (n - 1) < max_int:
	curr_cost = 0
	for j in range(n):
		curr_cost += abs(nums[j] - c ** j)
	min_cost = min(min_cost, curr_cost)
	c += 1
print(min_cost)


import sys, threading
from collections import defaultdict, Counter
input = sys.stdin.readline

def rl(type):
	return [type(w) for w in input().split()]

def reverse(arr):
	return arr[-1::-1]

def mod(a, m):
	return (a % m + m) % m

def create_graph(n):
	graph = {}
	for _ in range(n):
		(x, y) = map(int, input().split())
		graph[x].append(y)
		graph[y].append(x)
	return graph

def main():
	n = int(input())
	arr = rl(int)
	arr.sort()
	c = 1
	gresult = sum([i - 1 for i in arr])
	maxInt = 4294967296
	for c in range(2, 10 ** 5):
		flag = False
		result = 0
		for (idx, ele) in enumerate(arr):
			temp = c ** idx
			if temp > maxInt:
				flag = True
				break
			result += abs(ele - temp)
		if not flag:
			gresult = min(result, gresult)
		else:
			break
	print(gresult)
sys.setrecursionlimit(10 ** 6)
threading.stack_size(10 ** 8)
t = threading.Thread(target=main)
t.start()
t.join()


import math
n = int(input())
data = [int(x) for x in input().split()]
data.sort()
temp = data[-1]
temp = int(math.pow(temp, 1 / (n - 1)))
ans1 = 0
ans2 = 0
for q in range(n):
	ans1 += abs(data[q] - pow(temp, q))
for q in range(n):
	ans2 += abs(data[q] - pow(temp + 1, q))
print(min(ans1, ans2))


from math import *
n = int(input())
l = list(map(int, input().split()))
l.sort()
if n > 32:
	print(sum(l) - n)
else:
	x = log2(l[n - 1]) / (n - 1)
	x = 2 ** x
	c1 = ceil(x)
	c2 = floor(x)
	curr1 = 1
	curr2 = 1
	t1 = 0
	t2 = 0
	for i in range(n):
		t1 += abs(l[i] - curr1)
		t2 += abs(l[i] - curr2)
		curr1 *= c1
		curr2 *= c2
	print(min(t1, t2))


from collections import Counter
from typing import *
(n, a) = (int(input()), [int(x) for x in input().split()])
a.sort()
(ans, temp, c) = (float('inf'), 0, 1)
while c:
	(temp, ci) = (0, 1)
	for i in range(n):
		temp += abs(a[i] - ci)
		if temp > ans:
			break
		ci *= c
	if temp > ans:
		break
	ans = temp
	c += 1
print(ans)


import math
import sys

def inp():
	p = int(sys.stdin.readline())
	return p

def line():
	p = list(map(int, sys.stdin.readline().split()))
	return p
n = inp()
a = line()
a.sort()
p = pow(a[-1], 1 / (n - 1))
p = round(p)
q = p - 1
r = p + 1
ans = 0
ans2 = 0
ans3 = 0
for i in range(n):
	ans3 += abs(a[i] - pow(r, i))
	ans2 += abs(a[i] - pow(q, i))
	ans += abs(a[i] - pow(p, i))
print(min(ans, ans2, ans3))


import sys
import math
import collections
from sys import stdin, stdout, setrecursionlimit
import bisect as bs
setrecursionlimit(2 ** 20)
M = 10 ** 9 + 7
T = 1
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	c = 1
	a.sort()
	ans = sum(a) - n
	while 1:
		if n <= 2:
			break
		tmp = 0
		res = True
		for i in range(n):
			ci = c ** i
			tmp += abs(a[i] - ci)
			if ci > 10 ** 10:
				res = False
				break
		if res:
			ans = min(ans, tmp)
			c += 1
		else:
			break
	print(ans)


import sys
n = int(input())
a = [int(o) for o in input().split()]
c = 1
ans = float('inf')
a.sort()
while True:
	if c ** (n - 1) > 3 * 10 ** 9:
		break
	ans = min(ans, sum([abs(a[i] - c ** i) for i in range(n)]))
	c += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = -1
c = 1
small = True
while small:
	current_ans = 0
	pw = 1
	for idx in range(n):
		current_ans += abs(a[idx] - pw)
		pw *= c
		if pw >= 10000000000.0 and idx + 1 < n:
			small = False
			break
	if small:
		if ans == -1 or current_ans < ans:
			ans = current_ans
		c += 1
	else:
		break
print(ans)


import math, sys
input = sys.stdin.readline

def fA(c, A, n):
	v = 0
	for i in range(n):
		v = v + abs(A[i] - pow(c, i))
	return v

def main():
	n = int(input())
	A = list(map(int, input().split()))
	s = sum(A)
	ans = fA(1, A, n)
	v = math.floor(pow(max(A), 1 / (n - 1)))
	A.sort()
	ans = fA(v + 1, A, n)
	while True:
		val = fA(v, A, n)
		if val <= ans:
			v = v - 1
			ans = val
		else:
			break
	print(ans)
main()


n = int(input())
a = sorted(list(map(int, input().split())))
ans = 1e+18
for i in range(10 ** 5):
	cost = 0
	for j in range(n):
		cost += abs(i ** j - a[j])
		if cost > ans:
			break
	ans = min(ans, cost)
print(ans)


n = int(input())
arr = sorted(list(map(int, input().split())))
ans = sum(arr) - n
for i in range(2, 10 ** 9):
	if abs(i ** (n - 1) - arr[-1]) > ans:
		break
	ans2 = 0
	for j in range(0, n):
		ans2 += abs(i ** j - arr[j])
	ans = min(ans, ans2)
print(ans)


import math
N = int(input())
A = list(map(int, input().split()))
A.sort()
t = math.ceil(A[N - 1] ** (1 / (N - 1)))
p = math.floor(A[N - 1] ** (1 / (N - 1)))
if t >= 2:
	if N <= 50:
		dp1 = [1]
		dp2 = [1]
		for i in range(N):
			dp1.append(dp1[-1] * t)
			dp2.append(dp2[-1] * p)
		ans = 0
		for i in range(N):
			ans += abs(A[i] - dp1[i])
		ans2 = 0
		for i in range(N):
			ans2 += abs(A[i] - dp2[i])
		print(min(ans, ans2))
	else:
		dp2 = [1]
		for i in range(N):
			dp2.append(dp2[-1] * p)
		ans2 = 0
		for i in range(N):
			ans2 += abs(A[i] - dp2[i])
		ans = 0
		for i in range(N):
			ans += abs(A[i] - 1)
		print(min(ans, ans2))
else:
	dp1 = [1]
	dp2 = [1]
	for i in range(N):
		dp1.append(dp1[-1] * t)
		dp2.append(dp2[-1] * p)
	ans = 0
	for i in range(N):
		ans += abs(A[i] - dp1[i])
	ans2 = 0
	for i in range(N):
		ans2 += abs(A[i] - dp2[i])
	print(min(ans, ans2))


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = []
for j in range(1, 31624):
	cost = a[0] - 1
	for i in range(1, n):
		res = j ** i
		cost += abs(a[i] - res)
	ans.append(cost)
	if res > a[n - 1]:
		break
print(min(ans))


import math
t = int(input())
nums = [int(n) for n in input().split()]
minimum = 10 ** 9 + 1
nums.sort()
maximum = nums[len(nums) - 1]
c1 = 1
log_max = math.log(maximum, 10)
divider = len(nums) - 1
c2 = math.ceil(pow(10, log_max / divider))
flag = 0
for i in range(c1, c2 + 1, 1):
	temp_cost = 0
	for j in range(0, len(nums), 1):
		temp_cost += abs(nums[j] - pow(i, j))
	if flag == 0:
		minimum = temp_cost
		flag = 1
	elif temp_cost < minimum:
		minimum = temp_cost
print(minimum)


import math
n = int(input())
l = list(map(int, input().split()))
l.sort()
maa = l[n - 1]
i = 1
if n <= 100:
	while True:
		k = int(math.pow(i, n - 1))
		if k >= maa:
			break
		i += 1
	p = i
	s = 0
else:
	p = 1
	s = 0
for i in range(n):
	s += abs(l[i] - pow(p, i))
mn = s
s = 0
p = p - 1
if p != 0:
	for i in range(n):
		s += abs(l[i] - pow(p, i))
	print(min(mn, s))
else:
	print(mn)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
ans = float('inf')
for i in range(1, 31624):
	ans1 = 0
	for j in range(n):
		ans1 += abs(i ** j - a[j])
	if ans1 > ans:
		break
	ans = min(ans, ans1)
print(ans)


n = int(input())
l = list(map(int, input().split()))
l.sort()
we = pow(l[-1], 1 / (n - 1))
chk = l[-1] - pow(int(we), n - 1)
chk1 = pow(int(we + 1), n - 1) - l[-1]
sm = sm1 = 0
we = int(we)
for i in range(n):
	sm += abs(l[i] - pow(we, i))
we = int(we + 1)
for i in range(n):
	sm1 += abs(pow(we, i) - l[i])
print(min(sm1, sm))


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
ans = 0
for x in a:
	if x != 1:
		ans += x - 1
for i in range(1, int(100000.0)):
	tsum = 0
	c = 1
	for j in range(n):
		tsum += abs(c - a[j])
		c *= i
		if tsum > ans or c > int(1e+20):
			break
	else:
		ans = min(ans, tsum)
print(ans)


n = int(input())
arr = list(map(int, input().split()))
OO = 10 ** 15
ans = OO
arr = sorted(arr)
for c in range(1, 10 ** 5):
	s = 0
	for i in range(n):
		p = c ** i
		if p > OO:
			s = OO
			break
		s += abs(p - arr[i])
	if s < ans:
		ans = s
print(ans)


n = int(input())
A = list(map(int, input().split()))
A.sort()
inf = 10 ** 18
ans = sum(A)
for x in range(1, 10 ** 9):
	curcost = 0
	curpow = 1
	for i in range(n):
		curcost += abs(A[i] - curpow)
		curpow *= x
		if curpow > inf:
			break
	if curpow > inf:
		break
	if curpow / x > ans + A[-1]:
		break
	ans = min(ans, curcost)
print(ans)


n = int(input())
a = map(int, input().split())
a = list(sorted(a))
if n >= 60:
	print(sum(a) - n)
else:
	min_dif = -1
	for c in range(1, 10 ** 6):
		dif = 0
		for i in range(len(a)):
			dif += abs(c ** i - a[i])
		if dif < min_dif or min_dif == -1:
			min_dif = dif
		else:
			break
	print(min_dif)


import sys

def main():
	n = int(input())
	A = sorted([int(a) for a in input().split()])
	ans = sum(A) - len(A)
	for c in range(2, 1000000001):
		(s, p) = (0, 1)
		for a in A:
			s += abs(a - p)
			if s > ans:
				break
			p *= c
		if s > ans:
			break
		ans = s
	print(ans)
main()


import sys
input = lambda : sys.stdin.readline().rstrip()
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 10 ** 14
for i in range(10 ** 5):
	if i ** (n - 1) > 10 ** 14:
		break
	tmp = 0
	for j in range(n):
		tmp += abs(i ** j - a[j])
	ans = min(tmp, ans)
print(ans)


n = int(input())
nums = list(map(int, input().split()))
if len(nums) > 34:
	result = 0
	for num in nums:
		result += num - 1
	print(result)
else:
	nums.sort()
	sum_of_elements = 0
	for element in nums:
		sum_of_elements += element
	right_bound = 35000
	(best_c, min_loss) = (None, float('inf'))
	for current_c in range(1, right_bound + 1):
		this_c_loss = 0
		current_c_in_pow = 1
		for power in range(len(nums)):
			current_loss = abs(current_c_in_pow - nums[power])
			current_c_in_pow *= current_c
			this_c_loss += current_loss
		if this_c_loss < min_loss:
			min_loss = this_c_loss
			best_c = current_c
	print(min_loss)


from math import floor, ceil
n = int(input())
l = list(map(int, input().split()))
l.sort()
x = l[-1]
a = n - 1
prev = floor(x ** (1 / a))
c = ceil(x ** (1 / a))
ans1 = 0
ans2 = 0
for i in range(n):
	ans1 += abs(l[i] - pow(prev, i))
	ans2 += abs(l[i] - pow(c, i))
print(min(ans1, ans2))


n = int(input())
a = map(int, input().split())
a = list(a)
a.sort()
ans = 100000000000000000000
base = 1
while True:
	tmp = 0
	tcp = 1
	for i in range(n):
		tmp += abs(a[i] - tcp)
		tcp *= base
	base += 1
	if ans >= tmp:
		ans = tmp
	else:
		break
	if base ** (n - 1) >= 1000000000000000000:
		break
print(ans)


import math

def powerseq(c, n):
	add = 0
	for i in range(n):
		add += c ** i
	return add
n = int(input())
a = list(map(int, input().split()))
a.sort()
c1 = int(math.floor(pow(a[-1], 1 / (n - 1))))
c2 = int(math.ceil(pow(a[-1], 1 / (n - 1))))
s1 = 0
for i in range(n):
	s1 += abs(a[i] - c1 ** i)
s2 = 0
for i in range(n):
	s2 += abs(a[i] - c2 ** i)
if s1 < s2:
	print(s1)
else:
	print(s2)


n = int(input())
input_array = input().split()
array = []
for i in input_array:
	array.append(int(i))
array.sort()
sum_var = sum(array)
temp = 1
result_var = sum_var - n
while pow(temp, n - 1) - array[n - 1] <= sum_var - n:
	position = 0
	for i in range(n):
		temp_var = pow(temp, i) - array[i]
		if temp_var < 0:
			temp_var *= -1
		position += temp_var
	result_var = min(result_var, position)
	temp += 1
print(result_var)


import math
n = int(input())
a = [int(s) for s in input().split(' ')]
a.sort()
min_cost = float('inf')
x = round(a[-1] ** (1 / (n - 1)))
for i in range(x * 2):
	min_cost = min(min_cost, sum([abs(c - d) for (c, d) in zip(a, [i ** j for j in range(n)])]))
print(min_cost)


from math import ceil

def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	cost1 = arr[0] - 1
	c1 = int(ceil(arr[-1] ** (1 / (n - 1))))
	for i in range(1, n):
		cost1 += abs(arr[i] - c1 ** i)
	cost2 = arr[0] - 1
	c2 = int(arr[-1] ** (1 / (n - 1)))
	for i in range(1, n):
		cost2 += abs(arr[i] - c2 ** i)
	print(min(cost1, cost2))

def main():
	solve()
main()


from math import ceil
n = int(input())
a = sorted([*map(int, input().split())])
(ans, ans1) = (0, 0)
(c, c1) = (int(pow(a[n - 1], 1 / (n - 1))), ceil(pow(a[n - 1], 1 / (n - 1))))
for i in range(n):
	ans += abs(a[i] - pow(c, i))
	ans1 += abs(a[i] - pow(c1, i))
print(min(ans, ans1))


n = int(input())
x = sorted(list(map(int, input().split())))
a = int(x[n - 1] ** (1 / (n - 1)))
d = lambda t: sum((abs(x[i] - t ** i) for i in range(n)))
print(min(d(a), d(a + 1)))


def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = mpos(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum
from math import *
for _ in range(1):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	if n == 1:
		print(abs(1 - a[0]))
	else:
		start = int(a[-1] ** (1 / (n - 1)))
		(ans, ans1) = (0, 0)
		for i in range(n):
			ans += abs(a[i] - start ** i)
		start += 1
		for i in range(n):
			ans1 += abs(a[i] - start ** i)
		print(min(ans, ans1))


import sys
import math

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

def LI():
	return list(map(int, sys.stdin.readline().split()))

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

def SI():
	return sys.stdin.readline().strip()
n = II()
a = sorted(LI())
ma = 0
for i in a:
	ma += abs(1 - i)
for i in range(2, ma + 1):
	temp = 0
	boo = True
	for j in range(n):
		temp += abs(i ** j - a[j])
		if temp > ma:
			boo = False
			break
	if boo:
		ma = temp
	else:
		break
print(ma)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 10 ** 18
for c in range(2, int((2 * sum(a) - n) ** (1 / (n - 1))) + 1):
	x = 1
	ans_sub = abs(a[0] - x)
	for i in range(n - 1):
		x *= c
		ans_sub += abs(a[i + 1] - x)
	ans = min(ans, ans_sub)
print(min(ans, sum(a) - n))


import os
from sys import stdin, stdout

def solve(tc):
	n = int(stdin.readline().strip())
	seq = list(map(int, stdin.readline().split()))
	seq = sorted(seq)
	tot = 0
	for num in seq:
		tot += num
	MAXNUM = int(1000000000.0)
	lo = 1
	hi = 100000
	mincnt = int(1000000000.0) * n
	for bound in range(1, hi + 1):
		cnt = 0
		p = 1
		ok = True
		for j in range(n):
			cnt += abs(seq[j] - p)
			if mincnt < cnt:
				print(mincnt)
				return
			p *= bound
		mincnt = cnt
tcs = 1
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


n = int(input())
al = list(map(int, input().split()))
if n > 50:
	ans = 0
	for a in al:
		ans += abs(a - 1)
	print(ans)
	exit()
ans = 0
for a in al:
	ans += abs(a - 1)
al.sort()
c = 2
while True:
	cp = 1
	curr_ans = 0
	for (i, a) in enumerate(al):
		curr_ans += abs(a - cp)
		cp *= c
	if ans < curr_ans:
		print(ans)
		exit()
	else:
		ans = curr_ans
		c += 1


n = int(input())
a = sorted(list(map(int, input().split())))
c = 1
cost = float('inf')
while 1:
	y = 0
	for i in range(n):
		y += abs(c ** i - a[i])
	if y < cost:
		cost = y
		c += 1
		if c ** (n - 1) > 10 ** 18:
			break
	else:
		break
print(cost)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
a.sort()
c = 1
b = []
e = 0
for i in range(1, 10 ** 9 + 2):
	s = 0
	for j in range(len(a)):
		if i ** j > 10 ** 10:
			e = 1
			break
		s += abs(i ** j - a[j])
	if e == 0:
		b.append(s)
	if e == 1:
		break
print(min(b))


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
k = math.floor(pow(a[-1], 1 / (len(a) - 1)))
a1 = 0
for i in range(0, n):
	a1 += abs(k ** i - a[i])
k += 1
a2 = a1
if n < 40:
	a2 = 0
	for i in range(0, n):
		a2 += abs(k ** i - a[i])
print(min(a1, a2))


import sys
import math
input = sys.stdin.readline

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

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
n = inp()
ara = inara()
ara.sort()
if n > 100:
	ans = 0
	for i in range(n):
		ans += abs(ara[i] - 1)
	print(ans)
elif n == 1 or n == 2:
	print(ara[0] - 1)
else:
	ans = 10000000000000000000000000000
	for i in range(1, 32000):
		now = 1
		temp = 0
		flag = False
		for j in range(n):
			if len(str(now)) > 20:
				flag = True
				break
			temp += abs(ara[j] - now)
			now *= i
		if flag:
			break
		else:
			ans = min(ans, temp)
	print(ans)


import sys
import math
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
MAX_COST = 10 ** 15
answer = 10 ** 15
c = 1
if n >= 4:
	while True:
		cost = 0
		pow = 1
		did_break = False
		for i in range(n):
			if pow >= MAX_COST:
				did_break = True
				break
			cost += abs(a[i] - pow)
			pow *= c
		if answer > cost:
			answer = cost
		c += 1
		if did_break:
			break
else:
	c = min(a[1], math.floor(math.sqrt(a[2])))
	answer = min(answer, abs(a[0] - 1) + abs(a[1] - c) + abs(a[2] - c * c))
	c = math.ceil(math.sqrt(a[2]))
	answer = min(answer, abs(a[0] - 1) + abs(a[1] - c) + abs(a[2] - c * c))
	c = math.floor(math.sqrt(a[2]))
	answer = min(answer, abs(a[0] - 1) + abs(a[1] - c) + abs(a[2] - c * c))
	c = max(a[1], math.ceil(math.sqrt(a[2])))
	answer = min(answer, abs(a[0] - 1) + abs(a[1] - c) + abs(a[2] - c * c))
print(answer)


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
last = a[-1]
first = a[0]
ans = 9999999999999999
c = 1
if n <= 10:
	c = 55555
elif n <= 100:
	c = 5555
elif n <= 10 ** 3:
	c = 555
elif n <= 10 ** 4:
	c = 55
elif n <= 10 ** 5:
	c = 5
for ratio in range(1, c + 10):
	temp = 0
	for i in range(n):
		poww = pow(ratio, i)
		if poww > 10 ** 15:
			break
		temp += abs(a[i] - poww)
	if temp < ans:
		ans = temp
	if temp == 0:
		break
print(ans)


import math as m
n = int(input())
v = list(map(int, input().split()))
v.sort()
ans = 0
base = m.ceil(v[-1] ** (1 / (n - 1)))
base2 = m.floor(v[-1] ** (1 / (n - 1)))
ans2 = 0
ans = 0
for i in range(n):
	ans += abs(v[i] - base ** i)
for j in range(n):
	ans2 += abs(v[j] - base2 ** j)
print(min(ans2, ans))


import math
n = int(input())
l = list(map(int, input().split()))
l.sort()
m = 1000000000000000
k = 1
s = 0
sq = int(math.sqrt(l[n - 1]))
for i in range(sq + 2, 0, -1):
	s = 0
	k = 1
	for j in range(n):
		s = s + abs(l[j] - k)
		k = k * (sq + 3 - i)
		if k > 1000000000000000:
			break
	if m >= s:
		m = s
	else:
		break
print(m)


n = int(input())
arr = [int(k) for k in input().split()]
arr.sort()
init = int(arr[-1] ** (1 / (n - 1)))
if n > 32:
	ans = 0
	for i in range(n):
		ans += arr[i]
	print(ans - n)
else:
	ans1 = 0
	ans2 = 0
	ans3 = 0
	for i in range(n):
		ans1 += abs(arr[i] - init ** i)
		ans2 += abs(arr[i] - (init - 1) ** i)
		ans3 += abs(arr[i] - (init + 1) ** i)
	print(min(ans1, ans2, ans3))


def problem(A, c):
	ans = 0
	k = 1
	for i in range(len(A)):
		ans += abs(k - A[i])
		k = k * c
		if k > 1e+18:
			return 10000000000000000000
	return ans
n = int(input())
A = list(map(int, input().split()))
A.sort()
cmax = int(A[n - 1] ** (1 / (n - 1))) + 2
ans = 10000000000000000000
for c in range(1, cmax):
	pro = problem(A, c)
	ans = min(pro, ans)
print(ans)


n = int(input())
l1 = list(map(int, input().split()))
l1.sort()
count = abs(l1[0] - 1)
power = 1
while pow(power, n - 1) < l1[n - 1]:
	power += 1
sum1 = 0
sum2 = 0
for i in range(n):
	sum1 += abs(l1[i] - pow(power, i))
	sum2 += abs(l1[i] - pow(power - 1, i))
print(min(sum1, sum2))


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

def f(x):
	p = 1
	re = 0
	for i in range(n):
		re += abs(p - a[i])
		p *= x
	return re

def g():
	re = 0
	for i in range(n):
		re += a[i] - 1
	return re
a.sort()
if n > 32:
	print(g())
	exit(0)
i = 1
ans = 10 ** 18
while 1:
	tmp = f(i)
	if ans < tmp:
		break
	ans = tmp
	i += 1
print(ans)


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
mod = 10 ** 9 + 7
mod1 = 998244353
sys.setrecursionlimit(300000)
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
sys.setrecursionlimit(300000)

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')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
n = int(input())
l = list(map(int, input().split()))
l.sort()
if n >= 36:
	print(sum(l) - n)
else:
	t = 1
	cur = sum(l) - n
	while t <= 100000 // n:
		su = 0
		for i in range(n):
			su += abs(pow(t, i) - l[i])
		cur = min(cur, su)
		t += 1
	print(cur)


import sys
from math import ceil
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

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

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')
for _ in range(1):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	c1 = ceil(pow(l[-1], 1 / (n - 1)))
	c2 = int(pow(l[-1], 1 / (n - 1)))
	ans1 = 0
	ans2 = 0
	for i in range(n):
		ans1 += abs(l[i] - pow(c1, i))
		ans2 += abs(l[i] - pow(c2, i))
	print(min(ans1, ans2))


import math
n = int(input())
list1 = list(map(int, input().split()))
list1.sort()
c = 1
mins = -1
while 1:
	res = 0
	for i in range(n):
		res += abs(pow(c, i) - list1[i])
	if mins == -1:
		mins = res
	elif mins < res:
		break
	else:
		mins = res
	c += 1
print(mins)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(n):
	ans += a[i] - 1
for i in range(1, 100000):
	b = [1]
	curr = 1
	flag = 0
	for j in range(n - 1):
		curr = curr * i
		if curr > 10 ** 10:
			flag = 1
			break
		b.append(curr)
	if flag == 1:
		continue
	tmp = 0
	for j in range(n):
		tmp += abs(a[j] - b[j])
	ans = min(ans, tmp)
print(ans)


n = int(input())
arr = [int(x) for x in input().split()]
best = int(1e+18 + 5)
arr = sorted(arr)
j = 1
go = True
while go:
	curr = 0
	for k in range(n):
		p = int(j ** k)
		curr += abs(p - arr[k])
		if p > arr[n - 1]:
			go = False
	j += 1
	best = min(best, curr)
print(best)


input = __import__('sys').stdin.readline
n = int(input())
a = sorted(map(int, input().split()))
if n <= 2:
	print(a[0] - 1)
	exit(0)
ans = 10 ** 100
c = 0
fl = 0
while 1:
	c += 1
	(k, cnt) = (1, 0)
	for j in range(n):
		cnt += abs(k - a[j])
		k *= c
		if k >= 10 ** 20:
			break
	if k >= 10 ** 20:
		break
	ans = min(ans, cnt)
	if k / c >= a[-1]:
		break
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = int(a[-1] ** (1 / (n - 1)))
print(min(sum((abs(pow(ans, i) - a[i]) for i in range(n))), sum((abs(pow(ans + 1, i) - a[i]) for i in range(n)))))


import sys
from math import ceil, floor

def input():
	a = sys.stdin.readline()
	if a[-1] == '\n':
		a = a[:-1]
	return a

def print(*argv):
	n = len(argv)
	for i in range(n):
		if i == n - 1:
			sys.stdout.write(str(argv[i]) + '\n')
		else:
			sys.stdout.write(str(argv[i]) + ' ')

def lcm(x, y):
	from math import gcd
	return x * y / gcd(x, y)

def solve(n, lst):
	lst = sorted(lst)
	c = lst[-1] ** (1 / (n - 1))
	(c1, c2) = (ceil(c), floor(c))
	(cnt1, cnt2) = (0, 0)
	for i in range(n):
		cnt1 += abs(c1 ** i - lst[i])
		cnt2 += abs(c2 ** i - lst[i])
	return min(cnt1, cnt2)
n = int(input())
lst = list(map(int, input().split()))
print(solve(n, lst))


import sys
from math import sqrt
from collections import defaultdict
inpt = sys.stdin.readline

def inp():
	return int(inpt())

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

def instr():
	s = inpt()
	return list(s[:len(s) - 1])

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

class Graph:

	def __init__(self, n):
		self.n = n
		self.graph = defaultdict(list)
		self.marked = defaultdict(int)

	def addEdge(self, u, v):
		self.graph[u].append(v)
		self.graph[v].append(u)

	def dfs(self, u):
		self.marked[u] = 1
		for i in self.graph[u]:
			if self.marked[i] == 0:
				self.dfs(i)

def main():
	n = inp()
	a = inlist()
	(sum1, sum2) = (0, 0)
	a = sorted(a)
	pw = int(a[n - 1] ** (1 / (n - 1)))
	for i in range(n):
		sum1 += abs(a[i] - pw ** i)
		sum2 += abs(a[i] - (pw + 1) ** i)
	if sum1 < sum2:
		print(sum1)
	else:
		print(sum2)
main()


import math
mod = 10 ** 9 + 7
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
r1 = math.floor(math.pow(arr[-1], 1 / (n - 1)))
r2 = r1 + 1
cost3 = 0
cost4 = 0
for i in range(n):
	cost3 += abs(arr[i] - pow(r1, i))
	cost4 += abs(arr[i] - pow(r2, i))
print(min(cost3, cost4))


import os
import sys
from io import BytesIO, IOBase
import math
from collections import Counter

def main():
	n = int(input())
	a = list(map(int, input().split(' ')))
	ans = 99999999999999999999999999999999999999999
	a.sort()
	for x in range(0, 99999):
		aa = 0
		for xx in range(n):
			aa += abs(a[xx] - x ** xx)
		if ans > aa:
			ans = aa
		else:
			break
	print(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()


import math
n = int(input())
arr = map(int, input().split())
arr = sorted(arr)
ret = 10 ** 18
o_value = 0
ans = sum(arr) - n
for i in range(1, 10 ** 9):
	p = 1
	a = 0
	for j in range(n):
		a = a + abs(p - arr[j])
		p *= i
		if p > ret:
			break
	if p > ret:
		break
	if p / i > ans + arr[n - 1]:
		break
	ans = min(ans, a)
print(ans)


n = int(input())
A = list(map(int, input().split()))
A.sort()
ANS = 1 << 60
for C in range(1, 1000000):
	if abs(pow(C, n - 1) - A[-1]) > ANS:
		break
	SCORE = 0
	for i in range(n):
		SCORE += abs(A[i] - pow(C, i))
		if SCORE > ANS:
			break
	ANS = min(ANS, SCORE)
print(ANS)


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop, heapify
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
from itertools import accumulate
from functools import lru_cache
M = mod = 998244353

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

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
n = val()
l = sorted(li())
if n <= 36:
	ans = float('inf')
	for i in range(1, 10 ** 5):
		curr = 0
		for j in range(n):
			curr += abs(l[j] - i ** j)
			if i ** j > 10 ** 10:
				curr = float('inf')
				break
		ans = min(ans, curr)
else:
	ans = 0
	for j in l:
		ans += abs(j - 1)
print(ans)


def check(a, c):
	return sum([abs(a[i] - c ** i) for i in range(len(a))])
n = int(input())
a = list(map(int, input().split()))
a.sort()
r = 0
for i in range(1, n):
	r = max(r, a[i] ** (1 / i))
r = min(int(r + 1), int(9e+18 ** (1 / n)))
r = max(r, 1)
l = 1
while l < r:
	c1 = l + (r - l) // 3
	c2 = l + (r - l) * 2 // 3
	if c1 == l or c2 == r or c1 == c2:
		break
	ans1 = check(a, c1)
	ans2 = check(a, c2)
	if ans1 == ans2:
		break
	if ans1 > ans2:
		l = c1
	else:
		r = c2
res = int(9e+18)
for i in range(l, r + 1):
	res = min(res, check(a, i))
print(res)


n = int(input())
arr = sorted(list(map(int, input().split())))
cost1 = 0
cost2 = 0
z = arr[-1] ** (1 / (n - 1))
z1 = int(z)
z2 = z1 + 1
for i in range(n):
	cost1 += abs(arr[i] - z1 ** i)
	cost2 += abs(arr[i] - z2 ** i)
print(int(min(cost1, cost2)))


n = int(input())
a = [int(i) for i in input().split(' ')]
a.sort()
ans = 10 ** 18
upper_bound = int(10 ** (10 / (n - 1)))
for c in range(1, upper_bound + 1):
	m = 0
	for i in range(0, n):
		m += abs(a[i] - c ** i)
		if c ** i > 10 ** 20:
			m = 10 ** 18
			break
	ans = min(ans, m)
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
s = max(a)
a.sort()
dp = [0, 1]
i = 2
while i ** (n - 1) < s:
	i += 1
s = 0
for j in range(n):
	s += abs(a[j] - i ** j)
ans = s
s = 0
for j in range(n):
	s += abs(a[j] - (i - 1) ** j)
ans = min(ans, s)
print(ans)


def readInt():
	return int(input())

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

def readMap():
	return map(int, input().split())
inf = float('inf')
import math

def solve(n, A):
	A.sort()
	m = inf
	for c in range(1, 10 ** 9 + 1):
		cost = 0
		for i in range(len(A)):
			cost += abs(c ** i - A[i])
		m = min(m, cost)
		if cost > m:
			break
	return m
n = readInt()
A = readList()
print(solve(n, A))


n = int(input())
a = list(map(int, input().split()))
a.sort()
b = set()
for i in range(1, n):
	x = int(a[i] ** (1 / i))
	b.add(x)
	b.add(x + 1)
ans = sum((abs(a[i] - 1) for i in range(n)))
for elem in b:
	ans = min(ans, sum((abs(a[i] - elem ** i) for i in range(n))))
print(ans)


def find(b, e):
	res = 1
	while e > 0:
		if e & 1:
			res *= b
		b *= b
		e = e >> 1
	return res
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
mxrange = arr[-1]
cx = 1
if n == pow(10, 5):
	cx = 1
else:
	while 1:
		if find(cx, n - 1) > mxrange:
			break
		cx += 1
ans = pow(10, 15)
for c in range(1, cx + 1):
	diff = 0
	curr = 1
	for i in range(n):
		diff += abs(curr - arr[i])
		curr *= c
	ans = min(ans, diff)
print(ans)


n = int(input())
m = list(map(int, input().split()))
m.sort()
k = int(m[n - 1] ** (1 / float(n - 1)))
c = 0
for i in range(n):
	c += abs(k ** i - m[i])
b = 0
for i in range(n):
	b += abs((k + 1) ** i - m[i])
print(min(b, c))


import os, sys
from io import BytesIO, IOBase
from math import inf

def main():
	n = int(input())
	x = sorted(list(map(int, input().split())))
	ans = inf
	if n < 50:
		(st, en) = (1, 10 ** 5)
		while st <= en:
			mid1 = st + (en - st) // 3
			mid2 = en - (en - st) // 3
			(cost1, cost2) = (0, 0)
			for (ind, val) in enumerate(x):
				cost1 += abs(val - pow(mid1, ind))
			for (ind, val) in enumerate(x):
				cost2 += abs(val - pow(mid2, ind))
			if cost1 > cost2:
				st = mid1 + 1
			elif cost1 < cost2:
				en = mid2 - 1
			else:
				st = mid1 + 1
				en = mid2 - 1
			ans = min(ans, cost1, cost2)
		print(ans)
	else:
		ans = 0
		for i in x:
			ans += abs(i - 1)
		print(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()


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
import math as mh
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

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

def si():
	return input()

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

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

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

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r))

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	n = int(input())
	a = list(map(int, input().strip().split()))
	tot = 0
	for i in a:
		tot = tot + i
	a.sort()
	k = int(mh.ceil(a[n - 1] ** (1 / (n - 1))))
	ans = 10000000000000000000000000000
	for i in range(1, k + 1):
		cur = 0
		for j in range(n):
			cur = cur + abs(a[j] - i ** j)
		ans = min(ans, cur)
	print(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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(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(' ')))
a.sort()
INF = 10 ** 18
if n < 2:
	print(abs(a[0] - 1))
else:
	f1 = sum(a) - n
	for i in range(1, 10 ** 9):
		cost = 0
		p = 1
		for j in range(n):
			cost += abs(a[j] - p)
			p *= i
			if p > INF:
				break
		if p > INF:
			break
		if p / i > f1 + a[n - 1]:
			break
		f1 = min(f1, cost)
	print(f1)


n = int(input())
l = map(int, input().split())
l = list(sorted(l))
ans = 0
if n >= 60:
	print(sum(map(lambda x: x - 1, l)))
	exit()
k = 1
while True:
	if k ** (n - 1) > 10 * l[-1]:
		break
	k += 1
ans = 1000000000000000000
for i in range(1, k):
	pans = 0
	for j in range(n):
		pans += abs(l[j] - int(i ** j))
	ans = min(ans, pans)
print(ans)


n = int(input())
a = list(map(int, input().split()))
if n > 35 or n < 2:
	ans = 0
	for i in a:
		ans += i - 1
	print(ans)
	quit()
a.sort()
ans = 10 ** 14
c = 1
while True:
	local_ans = 0
	for (i, elem) in enumerate(a):
		local_ans += abs(elem - c ** i)
	if local_ans > ans:
		break
	ans = min(local_ans, ans)
	c += 1
print(ans)


n = int(input())
lst = [int(i) for i in input().split()]
lst.sort()
res = [0, 0]
for i in lst:
	res[1] += abs(i - 1)
x = 2
while x ** (n - 1) <= res[1] + lst[-1]:
	res.append(0)
	for i in range(len(lst)):
		res[x] += abs(lst[i] - x ** i)
	x += 1
print(min(res[1:]))


n = int(input())
arr = list(map(int, input().strip().split()))[:n]
arr.sort()
ans = float('inf')
c = 1
while True:
	power = 1
	val = 0
	for i in range(n):
		if power > 10 ** 10:
			val = -1
			break
		val += abs(power - arr[i])
		power *= c
	if val == -1:
		break
	ans = min(ans, val)
	c += 1
print(ans)


n = int(input())
s = list(sorted(list(map(int, input().split()))))
cost = float('INF')
c = 1
while c ** (n - 1) < s[-1] * (n + 1):
	cost = min(cost, sum((abs(x - c ** i) for (i, x) in enumerate(s))))
	c += 1
print(int(cost))


n = int(input())
arr = sorted([int(p) for p in input().split()])
total = float('inf')
for i in range(1, int(arr[-1] ** (1 / (n - 1))) + 2):
	temp = 0
	for j in range(len(arr)):
		temp += abs(arr[j] - i ** j)
	total = min(total, temp)
print(total)


import sys

def f(a, m1, n):
	res = 0
	pw = 1
	for i in range(0, n):
		res += abs(a[i] - pw)
		pw *= m1
		if res >= 10 ** 14:
			break
	return res
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
l = 0
r = 10 ** 5 + 1
while r - l > 1:
	m = (l + r) // 2
	if f(a, m, n) >= f(a, m + 1, n):
		l = m
	else:
		r = m
print(min(f(a, l, n), f(a, r, n)))


n = int(input())
arr = list(map(int, input().split()))
arr2 = sorted(arr)
total = float('inf')
f = 1
c = 1
while f and pow(c, n - 1) < 10 * arr2[n - 1]:
	f = 0
	temp = 0
	for x in range(n):
		p = pow(c, x)
		x_x = pow(c, x) - arr2[x]
		temp += abs(x_x)
		if x_x < 0:
			f = 1
	if temp < total:
		total = temp
	c += 1
print(total)


n = int(input())
seq = sorted(list(map(int, input().split())))
from math import log, ceil
min_sum = 1e+16
if n > 65:
	print(sum(seq) - n)
else:
	for k in range(1, 100000):
		if k ** (n - 1) > 10 ** 11:
			break
		vals = [k ** j for j in range(n)]
		min_sum = min(min_sum, sum((abs(seq[i] - vals[i]) for i in range(n))))
	print(min_sum)


n = int(input())
arr = list(map(int, input().split()))
cost = 10 ** 100
arr.sort()
for c in range(99999):
	ans = 0
	for i in range(len(arr)):
		ans += abs(c ** i - arr[i])
	if ans < cost:
		cost = ans
	else:
		break
print(cost)


n = int(input())
sequence = sorted(map(int, input().split()))
sol = sum(sequence) - n
if n >= 50:
	print(sol)
	exit()
max_c = 33000 if n == 3 else 2000
for c in range(2, max_c):
	c_power_sequence = [c ** i for i in range(n)]
	curr = 0
	for i in range(n):
		curr += abs(sequence[i] - c_power_sequence[i])
	if curr < sol:
		sol = curr
print(sol)


import math

def get_cost(x):
	a = sorted(x)
	n = len(a)
	sum = 0
	for i in range(n):
		sum += a[i]
	cost = abs(sum - n)
	c = 1
	while c > 0:
		c = c + 1
		s = 0
		for i in range(n):
			s += abs(c ** i - a[i])
		if s < cost:
			cost = s
		if s > sum:
			c = 0
	return cost
n = int(input())
a = list(map(int, input().split()))
print(get_cost(a))


import io
import os
import sys
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def printd(*args, **kwargs):
	pass

def get_str():
	return input().decode().strip()

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

def oint():
	return int(input())
n = oint()
a = list(rint())
a.sort()
ans = 10 ** 1000
flag = 0
for c in range(1, 10 ** 100):
	diff = 0
	for i in range(n):
		diff += abs(c ** i - a[i])
		if ans < diff:
			print(ans)
			exit()
	ans = min(ans, diff)
print(ans)


n = int(input())
import math
l = list(map(int, input().split(' ')))
l.sort()
an = 0
nan = 0
k = math.floor(10 ** (math.log(l[-1], 10) / (n - 1))) + 1
for j in range(n):
	an = an + abs(k ** j - l[j])
	nan = nan + abs((k - 1) ** j - l[j])
print(min(an, nan))


import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
letters = ascii_letters
input = stdin.readline

def calc(m):
	bfres = 0
	have = 1
	for i in range(n):
		bfres += abs(have - arr[i])
		have *= m
	return bfres
n = int(input())
arr = sorted(map(int, input().split()))
right = math.ceil(1000000000 ** (1 / (n - 1))) if n < 100 else 1
rs = 99999999999999999
for i in range(1, right + 1):
	rs = min(rs, calc(i))
print(rs)


n = int(input())
l = list(map(int, input().split()))
l.sort()
cost = sum([i - 1 for i in l])
c = 2
con = True
while con:
	tmp = 0
	cc = 1
	for i in range(n):
		tmp += abs(l[i] - cc)
		if cost < tmp:
			con = False
			break
		cc *= c
	if con:
		cost = tmp
	c += 1
print(cost)


n = int(input())
a = sorted(list(map(int, input().split())))
l = int(pow(a[-1], 1 / (n - 1)))
(x, y) = (0, 0)
for i in range(n):
	item = pow(l, i)
	x += abs(item - a[i])
for j in range(n):
	item1 = pow(l + 1, j)
	y += abs(item1 - a[j])
print(min(x, y))


from math import ceil

def find(a, n, num):
	ans = 0
	for i in range(n):
		ans += abs(a[i] - num ** i)
	return ans

def main():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	maxx = ceil(a[n - 1] ** (1.0 / (n - 1)))
	val = find(a, n, 1)
	for i in range(2, maxx + 1):
		val = min(val, find(a, n, i))
	print(val)
main()


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

def solve(cur):
	ans = 0
	tot = cur
	cur = 1
	for aa in a:
		ans += abs(aa - cur)
		cur *= tot
	return ans
ans = solve(1)
tmp = int(pow(a[-1], 1 / (n - 1)))
if n <= 32:
	for i in range(tmp - 1, tmp + 2):
		ans = min(ans, solve(i))
print(ans)


def cost(v, now):
	ai = 1
	res = 0
	for a in v:
		res += abs(ai - a)
		ai *= now
	return res
N = int(input())
v = list(map(int, input().split()))
v.sort()
mn = 100000000000001
last = mn
i = 1
while True:
	if i ** (len(v) - 1) > 100000000000000001:
		break
	res = cost(v, i)
	if res < mn:
		mn = res
	if last < res:
		break
	last = res
	i += 1
print(mn)


import math
for _ in range(1):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	s = 0
	s2 = 0
	a = math.ceil(l[-1] ** (1 / (n - 1)))
	b = math.floor(l[-1] ** (1 / (n - 1)))
	for i in range(n):
		s = s + abs(l[i] - a ** i)
		s2 = s2 + abs(l[i] - b ** i)
	print(min(s, s2))


n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
c = 2
ans = sum(l) - n
while True:
	currPw = 1
	currCost = 0
	done = 0
	for i in l:
		if currPw - l[-1] > ans:
			done = 1
			break
		currCost += abs(currPw - i)
		currPw *= c
	if done:
		break
	ans = min(ans, currCost)
	c += 1
print(ans)


from sys import stdin, stdout
n = int(input())
arr = sorted(list(map(int, input().split())))
big = 10 ** 10
c = 1
ans = 10 ** 15
flag = 0
while 1:
	val = 0
	for i in range(n):
		if pow(c, i) > big:
			flag = 1
			break
		else:
			val += abs(pow(c, i) - arr[i])
	if flag == 1:
		break
	ans = min(ans, val)
	c += 1
print(ans)


import collections
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
min_cost = 10 ** 99
inf = 10 ** 18
for c in range(1, 10 ** 9):
	cost = 0
	cur_pow = 1
	for i in range(n):
		cost += abs(cur_pow - a[i])
		cur_pow *= c
		if cur_pow > inf:
			break
	if cur_pow / c > min_cost + a[n - 1]:
		break
	min_cost = min(min_cost, cost)
print(min_cost)


from collections import *
import sys
import math

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))
n = ri()
aa = rl()
zz = aa.copy()
aa.sort()
c = aa[1]
test = 1
for i in range(n):
	if c ** i != aa[i]:
		test = 0
		break
else:
	for i in range(n):
		if aa[i] != zz[i]:
			print('2')
			break
	else:
		print('0')
		sys.exit()
c1 = int(aa[-1] ** (1 / (n - 1)))
c2 = c1 + 1
ans1 = 0
ans2 = 0
for i in range(n):
	ans1 += abs(c1 ** i - aa[i])
	ans2 += abs(c2 ** i - aa[i])
print(min(ans1, ans2))


from collections import deque
from collections import OrderedDict
import math
import sys
import os
import threading
import bisect
import operator
import heapq
from atexit import register
from io import BytesIO
import io
from sys import stdin, stdout
import os
import sys
from io import BytesIO, IOBase
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')
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
lis = list(map(int, input().split()))
answer = 0
for i in range(n):
	answer += lis[i] - 1
if n == 1:
	print(n - 1)
elif n > 32:
	print(answer)
	sys.exit(0)
lis.sort()
for i in range(2, 50000):
	localMin = 0
	for j in range(n):
		needVal = i ** j
		localMin += abs(lis[j] - needVal)
		if localMin > answer:
			break
	else:
		answer = min(localMin, answer)
print(answer)
sys.exit(0)

class Person:

	def __init__(self, name, age):
		self.name = name
		self.age = age
p1 = Person('heelo', 27)
print(help(Person))
age = 26
name = 'Swaroop'
print('Возрас {} -- {} лет'.format(name, age))
print(help(object))


MAX = 9223372036854775807
n = int(input())
v = sorted(list(map(int, input().split())))
gsum = sum(v)
if n < 52:
	ans = MAX
	mod = 51 * int(1000000000.0)
	m = 1
	i = 1
	while True:
		temp = pow(i, n - 1)
		if temp <= mod:
			m = i
		else:
			break
		i += 1
	for i in range(1, m + 1):
		s = 0
		for j in range(n):
			s += abs(pow(i, j) - v[j])
		ans = min(ans, s)
	print(ans)
else:
	k = 0
	for i in v:
		k += abs(i - 1)
	print(k)


import math
n = int(input())
l = list(map(int, input().split()))
l.sort()
c1 = math.ceil(l[-1] ** (1 / (n - 1)))
c2 = math.floor(l[-1] ** (1 / (n - 1)))
(dif1, dif2) = (0, 0)
for i in range(n):
	dif1 += abs(c1 ** i - l[i])
for i in range(n):
	dif2 += abs(c2 ** i - l[i])
print(min(dif1, dif2))


from sys import stdin, stdout, setrecursionlimit
from math import gcd, ceil, sqrt
from collections import Counter, deque
from bisect import bisect_left, bisect_right
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
setrecursionlimit(100000)
mod = 1000000007

def get(one, two):
	res = 0
	for (i, j) in zip(one, two):
		res += abs(i - j)
	return res

def check(arr):
	res = float('inf')
	old = res
	for i in range(1, 1000000):
		temp = []
		temp1 = arr[:]
		for j in range(len(arr)):
			temp.append(pow(i, j))
		res = min(res, get(temp, temp1))
		if res >= old:
			res = old
			break
		else:
			old = res
	return res
n = ii1()
arr = sorted(iia())
if n < 100:
	print(check(arr))
else:
	res = 0
	for i in arr:
		res += abs(i - 1)
	print(res)


def chk(arr, x):
	ml = 1
	ans = 0
	for i in arr:
		ans += abs(i - ml)
		ml *= x
		if ml > 10000000000000000000:
			return ml
	return ans
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = 100000000000000000000
for i in range(1, 100010):
	x = chk(arr, i)
	ans = min(ans, x)
print(ans)


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
from collections import deque
n = int(input())
l = list(map(int, input().split()))
l.sort()
count = float('infinity')
ans = 1
t = int(pow(l[-1], 1 / (n - 1)))
for i in [t, t - 1, t + 1]:
	if i <= 0:
		continue
	x = 0
	for j in range(n):
		x += abs(i ** j - l[j])
	count = min(count, x)
print(count)


def iin():
	return int(input())

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

def main():
	T = 1
	for t in range(T):
		n = iin()
		a = lin()
		a.sort()
		ans = sum(a) - n
		for val in range(1, 100001):
			sm = 0
			ch = 1
			br = 0
			for i in a:
				sm += abs(ch - i)
				ch *= val
				if sm > ans:
					br = 1
					break
			else:
				ans = min(ans, sm)
			if br:
				break
		print(ans)
main()


def cost(l, d):
	val = abs(l[0] - 1)
	p = 1
	for i in range(1, len(l)):
		p *= d
		val += abs(l[i] - p)
	return val
n = int(input())
arr = sorted(map(int, input().split()))
mn = sum(arr) - n
c = 2
while c ** (n - 1) - arr[-1] <= mn:
	mn = min(mn, cost(arr, c))
	c += 1
print(mn)


import sys
input = sys.stdin.buffer.readline
n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
cLower = 1
cUpper = int(arr[n - 1] ** (1 / (n - 1))) + 1
minCost = float('inf')
for c in range(cLower, cUpper + 1):
	cost = 0
	for i in range(n):
		cost += abs(c ** i - arr[i])
	minCost = min(minCost, cost)
print(minCost)


import sys
ll = lambda : list(map(int, input().split()))
lls = lambda : list(map(str, input().split()))
fin = lambda : list(map(float, input().split()))
st = lambda : input()
v = lambda : map(int, input().split())
ii = lambda : int(input())
mod = 10 ** 9 + 7
from math import *
from datetime import datetime
from collections import *
import math
x = ii()
l = ll()
l.sort()
m = l[-1]
p = m ** (1 / (x - 1))
ans = ceil(p)
ans2 = int(p)
c1 = 0
c2 = 0
for i in range(x):
	if ans ** i != l[i]:
		c1 += abs(ans ** i - l[i])
for i in range(x):
	if ans2 ** i != l[i]:
		c2 += abs(ans2 ** i - l[i])
print(min(c1, c2))


n = int(input())
lis = sorted(map(int, input().split()))
if n == 1:
	print(0)
else:
	ans = sum(lis) - n
	for i in range(1, max(lis)):
		if i ** (n - 1) > 20 ** 9:
			break
		tmp = 0
		for j in range(n):
			tmp += abs(lis[j] - i ** j)
		ans = min(ans, tmp)
	print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
mini = 1e+40
for c in range(1, int(100000.0)):
	(sum, p, check) = (0, 1, False)
	for a_i in a:
		sum += abs(a_i - p)
		p = p * c
		if p >= 1e+20:
			check = True
			break
	if check:
		break
	mini = min(mini, sum)
print(int(mini))


from math import log
n = int(input())
a = list(map(int, input().split()))
a.sort()

def search(t):
	m = sum(a) - n
	for i in range(2, t):
		N = 0
		k = 1
		for j in range(len(a)):
			N += abs(a[j] - k)
			k *= i
		m = min(m, N)
	return m
if n > 50:
	print(sum(a) - n)
elif n == 1 or n == 2:
	print(a[0] - 1)
else:
	print(search(int(10 ** (11 / (n - 1))) + 1))


n = int(input())
arr = [*map(int, input().split())]
arr.sort()
x = int(arr[-1] ** (1 / (n - 1)))
y = x + 1
ans = res = 0
for (i, j) in zip(arr, range(n)):
	ans += abs(i - x ** j)
	res += abs(i - y ** j)
print(min(ans, res))


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left
from bisect import bisect_right

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

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

def I():
	return int(stdin.readline())
P = 1000000007

def main():
	n = I()
	arr = L()
	arr.sort()
	z1 = int(arr[-1] ** (1 / (n - 1)))
	z2 = z1 + 1
	(val1, val2) = (0, 0)
	for i in range(n):
		val1 += abs(arr[i] - z1 ** i)
		val2 += abs(arr[i] - z2 ** i)
	print(min(val1, val2))
main()


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = float('inf')
flag = 0
for c in range(1, 100001):
	temp = 0
	for i in range(n):
		temp += abs(c ** i - arr[i])
	ans = min(ans, temp)
	if c ** (n - 1) > 1000000000:
		break
print(ans)


n = int(input())
a = list(map(int, input().split()))
ans = 0
a.sort()
t = 1
while True:
	t1 = 0
	for i in range(n):
		t2 = t ** i
		t1 += abs(t2 - a[i])
	if t == 1:
		ans = t1
	elif t1 > ans:
		print(ans)
		break
	else:
		ans = t1
	t += 1


import math

def main():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	c = math.ceil(a[-1] ** (1 / (n - 1)))
	(cost, cost2) = (0, 0)
	for (i, elem) in enumerate(a):
		cost += abs(elem - c ** i)
		cost2 += abs(elem - max(1, c - 1) ** i)
	print(min(cost, cost2))
main()


def checker(mid, arr, n):
	ansm = 0
	ansf = 0
	for i in range(n):
		am = mid ** i
		af = (mid - 1) ** i
		ansm += abs(arr[i] - am)
		ansf += abs(arr[i] - af)
	return (ansm, ansf)
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = 0
l = 0
r = int(arr[-1] ** (1 / (n - 2))) + 1
ans = 2 ** 31
a = 0
while l <= r:
	mid = (l + r) // 2
	(ansm, ansf) = checker(mid, arr, n)
	if ansm < ansf:
		l = mid + 1
		ans = ansm
	else:
		ans = ansf
		r = mid - 1
	a = mid
print(ans)


import math
n = int(input())
l = sorted([int(i) for i in input().split()])
c1 = 0
c2 = 0
k = pow(l[-1], 1 / (n - 1))
if k == int(k):
	s = 0
	k = int(k)
	for i in range(n):
		s += abs(l[i] - pow(k, i))
	print(s)
else:
	k1 = int(k)
	k2 = k1 + 1
	for i in range(n):
		c1 += abs(l[i] - pow(k1, i))
	for i in range(n):
		c2 += abs(l[i] - pow(k2, i))
	print(min(c1, c2))


def PowerSequence(n, sequence):
	sequence.sort()
	base = 1
	LIMIT = 10 ** 15
	Cost = LIMIT
	while True:
		NewCost = 0
		value = 1
		for i in range(n):
			if value >= LIMIT:
				value = -1
				break
			NewCost = NewCost + abs(value - sequence[i])
			value = value * base
		if value == -1 or Cost < NewCost:
			break
		Cost = NewCost
		base += 1
	return Cost
n = int(input())
listnum = [int(x) for x in input().split()]
print(PowerSequence(n, listnum))


import math

def solve(n, a):
	a.sort()
	c1 = math.floor(a[-1] ** (1 / float(n - 1)))
	c2 = math.ceil(a[-1] ** (1 / float(n - 1)))
	res1 = res2 = 0
	for i in range(len(a)):
		res1 += abs(a[i] - c1 ** i)
	for i in range(len(a)):
		res2 += abs(a[i] - c2 ** i)
	return min(res1, res2)
n = int(input())
a = [int(s) for s in input().split()]
result = solve(n, a)
print(result)


n = int(input())
a = list(map(int, input().split()))
ans = 10 ** 15
a.sort()
c = 1
while True:
	if pow(c, n - 1) > pow(10, 10):
		break
	temp = 0
	for i in range(n):
		temp += abs(pow(c, i) - a[i])
	ans = min(ans, temp)
	c += 1
print(ans)


n = int(input())
arr = list(map(int, input().split()))
arr = [-1] + arr
arr.sort()
mex = 10 ** 5 + 10
brr = [0 for i in range(mex)]
ans = 10 ** 18
i = 1
res = 0
s = 0
for i in range(1, 32111):
	res = 0
	brr[1] = 1
	s = 1
	for j in range(2, n + 1):
		brr[j] = brr[j - 1] * i
		s += brr[j]
		res += abs(arr[j] - brr[j])
		if s > 10 ** 14:
			break
	ans = min(ans, res + abs(arr[1] - 1))
print(ans)


n = int(input())
b = list(map(int, input().split()))
b.sort()
val = b[-1] ** (1 / (n - 1))
pos1 = int(val)
pos2 = int(val) + 1
val1 = 0
val2 = 0
for i in range(n):
	val1 += abs(b[i] - pos1 ** i)
	val2 += abs(b[i] - pos2 ** i)
print(min(val1, val2))


from sys import stdin, stdout

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

def LI():
	return list(map(int, stdin.readline().split()))
n = II()
a = LI()
a.sort()
ans = 10 ** 18
ma = a[-1]
cmax = 10 ** 9
for c in range(1, cmax + 1):
	(cost, k) = (abs(a[0] - 1), 1)
	for i in range(1, n):
		k *= c
		cost += abs(a[i] - k)
		if cost >= ans:
			break
	if cost >= ans:
		break
	else:
		ans = min(ans, cost)
stdout.write(str(ans) + '\n')


import sys
import math
n = int(input())
a = list(map(int, input().strip().split()))[:n]
a.sort()
res = math.inf
k = 1
while pow(k, n - 1) <= pow(10, 10):
	k += 1
k -= 1
for i in range(1, k + 1):
	temp = 0
	for j in range(n):
		temp += math.fabs(a[j] - pow(i, j))
	res = min(res, temp)
print(int(res))


import math
import random
import sys

def nthRoot(A, N):
	xPre = random.randint(1, 101) % 10
	eps = 0.001
	delX = 2147483647
	xK = 0.0
	while delX > eps:
		xK = ((N - 1.0) * xPre + A / pow(xPre, N - 1)) / N
		delX = abs(xK - xPre)
		xPre = xK
	return xK
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
if n >= 64:
	sum = 0
	for i in range(n):
		sum += abs(l[i] - 1)
	print(sum)
	sys.exit()
q = nthRoot(l[n - 1], n - 1)
p = math.floor(q)
temp = p
sum1 = abs(l[0] - 1)
for i in range(1, n):
	sum1 += abs(l[i] - p)
	p = p * temp
sum2 = abs(l[0] - 1)
p = math.ceil(q)
temp = p
for i in range(1, n):
	sum2 += abs(l[i] - p)
	p = p * temp
print(min(sum1, sum2))


n = int(input())
a = [int(o) for o in input().split()]
a = sorted(a)
ans = sum(a) - n
for i in range(1, max(a)):
	if i ** (n - 1) > 20 ** 9:
		break
	diff = 0
	for j in range(n):
		diff += abs(i ** j - a[j])
	ans = min(ans, diff)
print(ans)


(n, s) = open(0)
arr = sorted(map(int, s.split()))
n = int(n)

def mys(x):
	s = 0
	for i in range(n):
		s += abs(arr[i] - x ** i)
	return s
mmax = mys(1)
mmin = mys(1)
t = 2
while t ** (n - 1) <= mmax + arr[n - 1]:
	mmin = min(mmin, mys(t))
	t += 1
print(mmin)


import sys

def get_ints():
	return list(map(int, sys.stdin.readline().strip().split()))
n = int(input())
A = get_ints()
A.sort()
ans = 0
i = 0
while i < n:
	ans += A[i] - 1
	i += 1
if n <= 60:
	base = 1
	while base <= 10 ** 5:
		flag = True
		while flag:
			i = 0
			cur = 0
			while i < n:
				cur += abs(A[i] - base ** i)
				if cur >= ans:
					flag = False
					break
				i += 1
			ans = min(ans, cur)
		base += 1
print(ans)


n = int(input())
a = list(map(int, input().strip().split()))
ans = 10 ** 18
c = 1
a.sort()
while True:
	cur = 0
	now = 1
	flag = False
	for i in a:
		if now > 10 ** 12:
			flag = True
			break
		cur = cur + abs(i - now)
		now = c * now
	if flag == True:
		break
	ans = min(ans, cur)
	c = c + 1
print(ans)


from sys import stdin
from math import ceil, floor
inp = lambda : stdin.readline().strip()
n = int(inp())
a = [int(x) for x in inp().split()]
a.sort()
ans = a[0] - 1
ans2 = ans
c = floor(a[-1] ** (1 / (n - 1)))
c2 = ceil(a[-1] ** (1 / (n - 1)))
cnt = 1
for i in a[1:]:
	ans += abs(i - c ** cnt)
	cnt += 1
cnt = 1
for i in a[1:]:
	ans2 += abs(i - c2 ** cnt)
	cnt += 1
print(min(ans, ans2))


from math import log
n = int(input())
a = sorted([int(x) for x in input().split()])
c = 2
result = sum([abs(x - 1) for x in a])
MAX = a[-1]
if (n - 1) * log(2) > log(MAX + result):
	print(result)
else:
	while True:
		cost = 0
		p = 1
		for i in range(n):
			cost += abs(p - a[i])
			p *= c
		result = min(result, cost)
		if p // c > a[-1]:
			break
		c += 1
	print(result)


import math
mod = 10 ** 9 + 7
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
r1 = math.ceil(math.pow(arr[-1], 1 / (n - 1)))
r2 = r1 - 1
cost1 = 0
cost3 = 0
cost4 = 0
a1 = 1
a2 = 1
for i in range(n):
	cost3 += abs(arr[i] - pow(r1, i))
	cost4 += abs(arr[i] - pow(r2, i))
print(min(cost3, cost4))


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

def list_input():
	return list(map(int, input().split()))
big = int(1000000000000000.0)
n = int(input())
a = list_input()
a.sort()
flag = 0
m = big
for i in range(1, big):
	s = 0
	for j in range(n):
		if pow(i, j) > big:
			flag = 1
			break
		s += abs(a[j] - pow(i, j))
	if s > m or flag == 1:
		break
	m = min(m, s)
print(m)


import sys
input = sys.stdin.readline
N = int(input())
arr = list(map(int, input().split()))
arr.sort()
p = int(arr[-1] ** (1 / (N - 1))) - 1
seq = 1
while True:
	diff = 0
	for i in range(N):
		diff += abs(arr[i] - p ** i)
	if seq < 2:
		ans = diff
	elif ans > diff:
		ans = diff
	else:
		break
	p += 1
	seq += 1
print(ans)


n = int(input())
l = list(map(int, input().split()))
l.sort()
a = sum(l)
ans = 0
for i in l:
	ans += abs(i - 1)
from math import log
for i in range(2, 10 ** 9 + 1):
	if log(10 ** 18, i) < n:
		break
	c = 0
	d = 1
	for j in l:
		c += abs(j - d)
		d *= i
	ans = min(ans, c)
print(ans)


N = int(input())
a = list(map(int, input().split()))
a.sort()
c = 1
l = int(a[N - 1] ** (1 / (N - 1)))
r = l + 1
scorel = 0
for i in range(N):
	scorel += abs(a[i] - l ** i)
scorer = 0
for i in range(N):
	if r ** i > 10 ** 15:
		break
	scorer += abs(a[i] - r ** i)
print(min(scorer, scorel))


import sys
input = sys.stdin.buffer.readline
n = int(input())
A = list(map(int, input().split()))
A.sort()
base = A[-1] ** (1 / (n - 1))
base1 = int(base)
base2 = base1 + 1
sum1 = sum2 = 0
for (i, a) in enumerate(A):
	sum1 += abs(a - base1 ** i)
	sum2 += abs(a - base2 ** i)
print(min(sum1, sum2))


n = int(input())
A = list(map(int, input().split()))
A.sort()
if n >= 100:
	print(sum(A) - n)
else:
	ans = sum(A) - n
	M = 10 ** 12
	for i in range(2, max(A)):
		x = 0
		y = 1
		for a in A:
			if y > 10 ** 11:
				y = -1
				break
			x += abs(a - y)
			y *= i
		if y == -1:
			break
		ans = min(ans, x)
	print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
mxN = 10 ** 20
ans = 10 ** 20
overflow = False
for i in range(1, 10 ** 5):
	(val, res) = (1, 0)
	for j in range(n):
		if val * i > mxN:
			overflow = True
			break
		else:
			res += abs(val - a[j])
			val *= i
	if overflow:
		break
	ans = min(ans, res)
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = float('inf')
if n <= 2:
	ans = abs(1 - a[0])
else:
	big = False
	c = 1
	while c <= 100000 and (not big):
		now = c
		candidate = abs(1 - a[0])
		i = 1
		while i < n and (not big):
			big = now > 10000000000
			candidate += abs(now - a[i])
			now *= c
			i += 1
		if not big:
			ans = min(ans, candidate)
		c += 1
print(ans)


n = int(input())
s = list(map(int, input().split()))
s.sort()
ans = 1e+100
for c in range(1, 100000):
	sum = 0
	for i in range(n):
		sum += abs(s[i] - c ** i)
	if ans < sum:
		break
	ans = min(sum, ans)
print(ans)


n = int(input())
numbers = input()
spin = numbers.split()
new = []
for i in range(n):
	new.append(int(spin[i]))
new = sorted(new)
sum = sum(new)
k = 1
while pow(k, n - 1) < pow(10, 10):
	k += 1
counta = sum - n
for x in range(2, k):
	count = 0
	z = 0
	for i in range(n):
		z = int(x) ** i - int(new[i])
		count = count + abs(z)
	counta = min(count, counta)
print(counta)


n = int(input())
a = list(map(int, input().split()))
a.sort()
up = int(pow(10 ** 9, 1 / (n - 1))) + 1
ans = 10 ** 18
for i in range(1, up + 1, 1):
	now = 0
	for j in range(n):
		num = pow(i, j)
		now += abs(a[j] - num)
	ans = min(ans, now)
print(ans)


import os
import sys
from io import BytesIO, IOBase
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')
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
if n == 1:
	print(0 if arr[0] == 1 else arr[0] - 1)
elif n == 2:
	print(abs(arr[0] - 1))
else:
	ans = 10 ** 18
	c = 2
	while True:
		cnt = 0
		f = 0
		for j in range(n):
			var = c ** j
			if var > 10 ** 10:
				f = 1
				break
			cnt += abs(arr[j] - var)
		if f == 1:
			break
		else:
			ans = min(ans, cnt)
		c += 1
	print(min(ans, sum(arr) - n))


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
l = 1
r = int(arr[-1] ** (1 / (n - 1))) + 2
ans = float('inf')
for c in range(r):
	temp = 0
	for i in range(n):
		temp += abs(c ** i - arr[i])
	ans = min(ans, temp)
print(ans)


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
n = I()
a = sorted(R())
inf = 10 ** 18
if n <= 2:
	print(a[0] - 1)
else:
	ans = sum(a) - n
	for x in range(1, 10 ** 9):
		c = 0
		p = 1
		for i in range(n):
			c += abs(a[i] - p)
			p *= x
			if p > inf:
				break
		if p > inf:
			break
		if c > ans:
			break
		ans = min(ans, c)
	print(ans)


def getCost(a, c):
	cur = 1
	result = 0
	for i in range(len(a)):
		result += abs(a[i] - cur)
		cur *= c
	return result
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
result = float('inf')
baseline = getCost(a, 1)
for cand in range(10 ** 7):
	if cand ** (n - 1) >= 5 * baseline:
		break
	result = min(result, getCost(a, cand))
print(result if result != float('inf') else 0)


n = int(input())
a = list(map(int, input().split()))
a.sort()
x = 100000
ans = []
for i in range(1, x + 1):
	t = 1
	r = 0
	f = 1
	for j in range(n):
		r += abs(t - a[j])
		t = t * i
		if t > 10 ** 18:
			f = 0
			break
	if f and r >= 0:
		ans.append(r)
	else:
		break
print(min(ans))


import os
import sys
from io import BytesIO, IOBase
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')
import math
n = int(input())
vals = list(map(int, input().split()))
if n <= 33:
	vals.sort()
	power = math.ceil(9 / (n - 1))
	k = 10 ** power
	minans = 10 ** 18
	for s in range(1, k + 1):
		ans = 0
		for i in range(n):
			ans += abs(s ** i - vals[i])
		minans = min(ans, minans)
else:
	minans = 0
	for s in range(n):
		minans += vals[s] - 1
print(minans)


import sys
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(buff_readline())

def read_int_n():
	return list(map(int, buff_readline().split()))

def read_float():
	return float(buff_readline())

def read_float_n():
	return list(map(float, buff_readline().split()))

def read_str():
	return readline().strip()

def read_str_n():
	return readline().strip().split()

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap
from collections import Counter

@mt
def slv(N, A):
	A.sort()
	ans = INF
	for c in range(1, 31623 + 1):
		t = 0
		for (i, a) in enumerate(A):
			v = c ** i
			if v > 10 ** 10:
				t = INF
				break
			t += abs(v - a)
		ans = min(ans, t)
	return ans

def main():
	N = read_int()
	A = read_int_n()
	print(slv(N, A))
main()


n = int(input())
a = list(map(int, input().strip().split()))[:n]
a.sort()
sum = 0
for i in range(n):
	sum = sum + a[i]
c = 1
ans = sum - n
while pow(c, n - 1) - a[n - 1] <= sum - n:
	curr = 0
	for i in range(n):
		tmp = pow(c, i) - a[i]
		if tmp < 0:
			tmp = -tmp
		curr = curr + tmp
	ans = min(ans, curr)
	c += 1
print(ans)


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

def aux(nu):
	ee = 0
	sue = 1
	for i in range(len(li)):
		ee += abs(sue - li[i])
		sue *= nu
	return ee

def aux2(nu, limi):
	ee = 0
	sue = 1
	for i in range(len(li)):
		ee += abs(sue - li[i])
		if ee > limi:
			return True
		sue *= nu
	return ee > limi

def tata(n):
	return aux(n + 1) > aux(n)
if n > 32:
	(n0, n1) = (sum(li), aux(1))
	if aux2(2, n1):
		print(min(n0, n1))
	else:
		print(2)
else:
	(lo, hi) = (0, 1)
	while not tata(hi):
		hi *= 2
	while lo < hi:
		mid = (lo + hi) // 2
		if tata(mid):
			hi = mid
		else:
			lo = mid + 1
	print(aux(lo))


def powerSequence():
	n = int(input())
	a = sorted([int(x) for x in input().split()])
	mx = 10 ** 10
	c = 1
	ans = float('inf')
	while c ** (n - 1) < mx:
		cur = 0
		for i in range(n):
			cur += abs(a[i] - c ** i)
		c += 1
		ans = min(ans, cur)
	print(ans)
powerSequence()


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 100000000000000.0
c = 1
bound = 1000000000000000.0
if n == 3:
	bound = 10000000000.0
while c ** (n - 1) <= bound:
	sf = 0
	for i in range(n):
		sf += abs(a[i] - c ** i)
	ans = min(ans, sf)
	c += 1
print(ans)


import sys
input = sys.stdin.readline
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
if n > 40:
	ans = 0
	for i in range(n):
		ans += abs(arr[i] - 1)
	print(ans)
else:
	best = 10 ** 99
	for c in range(1, 10 ** 5):
		ans = 0
		for i in range(n):
			ans += abs(arr[i] - c ** i)
			if c ** i > 10 ** 15:
				break
		best = min(best, ans)
		if c ** i > 10 ** 15:
			break
	print(best)


n = int(input())
a = [int(u) for u in input().split()]
a.sort()
f = [0, 0]
for i in a:
	f[1] += abs(i - 1)
x = 2
while x ** (n - 1) <= f[1] + a[-1]:
	f.append(0)
	for i in range(len(a)):
		f[x] += abs(a[i] - x ** i)
	x += 1
print(min(f[1:]))


import math
n = int(input())
a = list(map(int, input().split()))
aset = set(a)
ma = 10 ** 9
if aset == {1}:
	print(0)
else:
	a.sort()
	val = a[len(a) - 1]
	s = 0
	ch = val ** (1 / (n - 1))
	an = math.floor(ch)
	bn = math.ceil(ch)
	su = 0
	for i in range(n):
		su = su + abs(a[i] - pow(an, i))
	if an != bn:
		st = 0
		for i in range(n):
			st = st + abs(a[i] - pow(bn, i))
		print(min(su, st))
	else:
		print(su)


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
count1 = 0
count2 = 0
c1 = math.floor(a[n - 1] ** (1 / (n - 1)))
c2 = math.ceil(a[n - 1] ** (1 / (n - 1)))
for i in range(0, n):
	newAi1 = pow(c1, i)
	newAi2 = pow(c2, i)
	count1 += abs(newAi1 - a[i])
	count2 += abs(newAi2 - a[i])
	a[i] = min(newAi1, newAi2)
print(min(count1, count2))


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
x = int(arr[-1] ** (1 / n))
ans = [1e+30]
if n < 35:
	for i in range(1, 100000):
		su = 0
		for j in range(n):
			su += abs(i ** j - arr[j])
		if su > ans[-1]:
			break
		ans.append(su)
	print(min(ans))
else:
	su = 0
	for j in range(n):
		su += abs(1 - arr[j])
	print(su)


n = int(input())
arr = list(map(int, input().split()))
cost = sum(arr) - n
if n <= 10:
	up = 10 ** (9 // (n - 1) + 1) + 1
	arr.sort()
elif n >= 60:
	up = 1
elif n >= 30:
	up = 2
	arr.sort()
elif n >= 20:
	up = 3
	arr.sort()
else:
	up = 10
	arr.sort()
for c in range(2, up + 1):
	val = 0
	for i in range(n):
		val += abs(arr[i] - c ** i)
	cost = min(cost, val)
print(cost)


import math
n = int(input())
lis = list(map(int, input().strip().split()))[:n]
lis.sort()
x = math.ceil(lis[n - 1] ** (1 / float(n - 1)))
y = math.floor(lis[n - 1] ** (1 / float(n - 1)))
ans1 = 0
ans2 = 0
for i in range(0, n):
	p = pow(x, i)
	q = pow(y, i)
	ans1 += abs(lis[i] - p)
	ans2 += abs(lis[i] - q)
print(min(ans1, ans2))


import math
N = int(input())
A = list(map(int, input().split()))
A.sort()
mn = 10 ** 13
if N == 2:
	mn = A[1]
else:
	for i in range(1, 10 ** 5):
		if i ** (N - 1) > 10 ** 10:
			break
		dif = 0
		for j in range(N):
			dif += abs(i ** j - A[j])
		if dif > mn:
			break
		else:
			mn = dif
print(mn)


import math
res = []
lengths = []
for i in range(2, 31624):
	temp = []
	num = 0
	length = 0
	while i ** num <= 10 ** 10:
		temp.append(i ** num)
		num += 1
		length += 1
	lengths.append(length)
	res.append(temp)
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
costs = math.inf
for i in range(31622):
	len1 = lengths[i]
	if len1 >= n:
		arr1 = res[i][:n]
		temp_cost = 0
		for (j, k) in zip(arr1, arr):
			temp_cost += abs(j - k)
		costs = min(temp_cost, costs)
	else:
		arr1 = [1 for i in range(n)]
		temp_cost = 0
		for (j, k) in zip(arr1, arr):
			temp_cost += abs(j - k)
		costs = min(temp_cost, costs)
		break
print(costs)


from functools import lru_cache
from sys import stdin, stdout
import sys
from math import *
n = int(input())
ar = list(map(int, input().split()))
ar.sort()
l = 0
r = 100000

def func(ar, c):
	ans = 0
	for i in range(len(ar)):
		ans += abs(c ** i - ar[i])
	return ans
ans = inf
for i in range(50000):
	if i ** (n - 1) >= 10000000000.0:
		break
	ans = min(ans, func(ar, i))
print(ans)


def main():
	import sys
	input = sys.stdin.buffer.readline
	n = int(input())
	alst = list(map(int, input().split()))
	alst.sort()
	one = sum(alst) - n
	ans = one
	num = 1
	while 1:
		cnt = 0
		num2 = 1
		for i in range(n):
			tmp = abs(num2 - alst[i])
			if tmp > ans:
				break
			cnt += tmp
			num2 *= num
		else:
			num += 1
			ans = min(ans, cnt)
			continue
		break
	print(ans)
main()


from sys import stdin
input = stdin.readline

def A():
	t = int(input())
	for _ in range(t):
		d = [0] * 26
		n = int(input())
		for j in range(n):
			for i in input().rstrip():
				d[ord(i) - ord('a')] += 1
		truth = True
		for i in range(26):
			if d[i] % n != 0:
				truth = False
				break
		if truth:
			print('YES')
		else:
			print('NO')

def B():
	n = int(input())
	a = sorted(list(map(int, input().split())))
	baseCost = sum(a) - n
	c = 2
	cost = 0
	while True:
		cost = 0
		for i in range(n):
			cost += abs(a[i] - c ** i)
		if cost < baseCost:
			c += 1
			baseCost = cost
		else:
			break
	print(baseCost)
B()


n = int(input())
a = list(map(int, input().split()))
a.sort()
c = 1
big = 10 ** 18
ans = big
while 1:
	val = 0
	for i in range(n):
		val += abs(c ** i - a[i])
	if val < ans:
		ans = val
		c += 1
		if c ** (n - 1) >= big:
			break
	else:
		break
print(ans)


def fastPow(a, n):
	if n == 0:
		return 1
	ans = fastPow(a, n // 2)
	ans = ans * ans
	if n % 2 == 1:
		ans = ans * a
	return ans
n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
limit = fastPow(10, 24)
i = 1
answer = fastPow(10, 24)
limit2 = 1000000
while fastPow(i, n) <= limit and i <= limit2:
	b = 0
	val = 1
	for j in range(0, n):
		a1 = arr[j]
		a2 = val
		if a1 > a2:
			b += a1 - a2
		else:
			b += a2 - a1
		val = val * i
	if answer > b:
		answer = b
	i = i + 1
print(answer)


def main():
	n = int(input())
	a = tuple(map(int, input().split()))
	result = how_much_costs_transformation_to_powers_sequence(a)
	print(result)

def how_much_costs_transformation_to_powers_sequence(seq):
	seq = sorted(seq)
	seq_length = len(seq)
	if seq_length == 0:
		return 0
	elif seq_length == 1:
		return abs(1 - seq[0])
	elif seq_length == 2:
		(a1, a2) = seq
		return abs(1 - a1) + abs(max(a2, 1) - a2)
	assert seq_length >= 3
	base = 1
	curr_cost = _how_much_cost_powers_seq_with_base(seq, base)
	next_cost = _how_much_cost_powers_seq_with_base(seq, base + 1)
	while next_cost <= curr_cost:
		base += 1
		curr_cost = next_cost
		next_cost = _how_much_cost_powers_seq_with_base(seq, base + 1)
	return curr_cost

def _how_much_cost_powers_seq_with_base(sorted_seq, base):
	result = 0
	for i in range(len(sorted_seq)):
		result += abs(base ** i - sorted_seq[i])
	return result
main()


from sys import stdin, stdout
from math import gcd, log2, log10, floor
import math
from collections import defaultdict
input = stdin.readline
inf = float('inf')

def finddiff(a, power):
	number = 1
	diff = 0
	for i in range(len(a)):
		diff += abs(a[i] - number)
		number *= power
		if number > 10 ** 18:
			return -1
	return diff
n = int(input())
a = list(map(int, input().split()))
a.sort()
mina = inf
maxa = inf
if n <= 2:
	print(a[0] - 1)
else:
	power = 1
	while mina != -1:
		mina = finddiff(a, power)
		if maxa > mina and mina != -1:
			maxa = mina
		if power > pow(10, 5):
			break
		power += 1
	print(maxa)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
if n == 3:
	ans = 10 ** 18
	for i in range(1, 40000):
		if i ** n > 10 ** 20:
			break
		tmp = 0
		tmp += abs(arr[0] - 1)
		tmp += abs(arr[1] - i)
		tmp += abs(arr[2] - i ** 2)
		ans = min(ans, tmp)
	print(ans)
elif n == 4:
	ans = 10 ** 18
	for i in range(1, 2000):
		if i ** n > 10 ** 20:
			break
		tmp = 0
		tmp += abs(arr[0] - 1)
		tmp += abs(arr[1] - i)
		tmp += abs(arr[2] - i ** 2)
		tmp += abs(arr[3] - i ** 3)
		ans = min(ans, tmp)
	print(ans)
else:
	ans = 10 ** 18
	for i in range(1, 200):
		if i ** n > 10 ** 20:
			break
		tmp = 0
		t2 = 1
		for x in arr:
			tmp += abs(x - t2)
			t2 *= i
		ans = min(ans, tmp)
	print(ans)


import math

def main():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	w = 10 ** 18
	for i in range(1, math.ceil(pow(10, 9 / (n - 1))) + 1):
		x = 0
		for j in range(n):
			x += abs(pow(i, j) - a[j])
		w = min(w, x)
	print(w)
main()


n = int(input())
a_list = list(map(int, input().split()))
a_list = sorted(a_list)
if n <= 2:
	print(a_list[0] - 1)
else:
	result = sum(a_list) - n
	for i in range(1, 10 ** 9):
		power = 1
		cost = 0
		for k in range(len(a_list)):
			cost += abs(a_list[k] - power)
			power *= i
			if power > 10 ** 18:
				break
		if power > 10 ** 18:
			break
		if power // i > result + a_list[n - 1]:
			break
		result = min(result, cost)
	print(result)


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write('\n'.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
from decimal import Decimal
mod = int(1000000000.0) + 7
INF = 2 ** 32
n = int(data())
a = mdata()
a.sort()
ans = sum(a) - n
k = int(10 ** (math.log10(a[-1]) / (n - 1)))
if n <= 32:
	i = 2
	while True:
		if i > k + 1:
			break
		t = 1
		val = 0
		for j in range(n):
			val += abs(t - a[j])
			t *= i
		i += 1
		ans = min(ans, val)
out(ans)


def f():
	n = int(input())
	arr = list(map(int, input().split(' ')))
	arr.sort()

	def comp(arr, c):
		ans = 0
		for i in range(len(arr)):
			ans += abs(arr[i] - c ** i)
		return ans
	if comp(arr, 1) <= comp(arr, 2):
		print(comp(arr, 1))
		return
	rbound = 1
	while rbound ** (n - 1) < arr[-1]:
		rbound += 1
	(lo, hi) = (1, rbound)
	while lo <= hi:
		mid = (lo + hi) // 2
		(l, m, r) = (comp(arr, mid - 1), comp(arr, mid), comp(arr, mid + 1))
		if l > m < r or l == m or r == m:
			print(m)
			return
		elif l > m > r:
			lo = mid + 1
		elif l < m < r:
			hi = mid - 1
f()


def all_same(a):
	return all([x == 1 for x in a])
N = int(input())
array = sorted([int(x) for x in input().split()])
total = sum(array)
previous = 10 ** 20
for i in range(10 ** 5 + 1):
	counter = 0
	for j in range(N):
		counter += abs(array[j] - i ** j)
	if counter > previous:
		print(previous)
		exit()
	else:
		previous = counter


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
p = 99999999999999999
l = 999999999999999999999
for i in range(1, 100000000):
	t = 0
	for g in range(n):
		t += abs(arr[g] - i ** g)
	p = min(p, t)
	if p >= l:
		print(p)
		break
	l = p


import math
n = int(input())
a = list(map(int, input().split(' ')))
a.sort()
res1 = 0
res2 = 0
c = math.floor(a[n - 1] ** (1 / (n - 1)))
for i in range(n):
	res1 += abs(a[i] - c ** i)
	res2 += abs(a[i] - (c + 1) ** i)
print(min(res1, res2))


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.buffer.readline().rstrip()
q = int(input())
w = sorted(list(map(int, input().split())))
e = sum(w)
l = 10000000000000000
k = 0
for i in w:
	k += abs(i - 1)
i = 1
while i ** (q - 1) <= k + w[-1]:
	t = 0
	for j in range(q):
		t += abs(w[j] - i ** j)
	l = min(l, t)
	i += 1
print(l)


def binary_search(l, r, a, best):
	if l >= r:
		return best
	mid = (l + r) // 2
	currl = 0
	currr = 0
	for i in range(n):
		currl += abs(a[i] - mid ** i)
		currr += abs(a[i] - (mid + 1) ** i)
	if currl > currr:
		best = currr
		return binary_search(mid + 1, r, a, best)
	else:
		best = currl
		return binary_search(l, mid, a, best)
	return best
n = int(input().split()[0])
a = list(map(int, input().split()))
a.sort()
ans = 0
maxr = a[1]
for i in range(2, n):
	if int(a[i] ** (1 / i)) + 1 > maxr:
		maxr = int(a[i] ** (1 / i)) + 1
if n >= 100:
	maxr = 2
(l, r) = (1, maxr)
ans = binary_search(l, r, a, -1)
print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	ans = float('inf')
	(max_limit, maxx) = (1, a[-1])
	while True:
		if pow(max_limit, n - 1) > maxx:
			break
		max_limit += 1
	(first, second) = (0, 0)
	for i in range(n):
		first += abs(a[i] - pow(max_limit, i))
	max_limit -= 1
	for i in range(n):
		second += abs(a[i] - pow(max_limit, i))
	print(min(first, second))
solve()


from sys import stdin, stdout

def fn(near):
	power = 1
	ans = 0
	for i in range(n):
		ans += abs(a[i] - power)
		if ans > aa:
			return float('inf')
		power *= near
	return ans
for _ in range(1):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	a.sort()
	near = 1
	aa = float('inf')
	end = 10 ** 6 // n
	for c in range(1, min(55555, end)):
		aa = min(aa, fn(c))
	print(aa)


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

def process():
	_ = int(readline())
	arr = list(map(int, readline().strip().split()))
	arr.sort()
	(ans, mx) = (10 ** 20, 10 ** 20)
	overflow = False
	for i in range(1, 10 ** 5):
		(val, diff) = (1, 0)
		for num in arr:
			if val * i > mx:
				overflow = True
				break
			else:
				diff += abs(val - num)
				val *= i
		ans = min(ans, diff)
		if overflow:
			break
	print(ans)
process()


import math
from collections import Counter, defaultdict, deque

def int1():
	return int(input())

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

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

def solve():
	n = int1()
	l1 = list1()
	l1.sort()
	x = l1[-1]
	v = int(x ** (1 / (n - 1)))
	g = v + 1
	sum1 = 0
	sum2 = 0
	c = 0
	for i in l1:
		v1 = v ** c
		v2 = g ** c
		sum1 += abs(v1 - i)
		sum2 += abs(v2 - i)
		c = c + 1
	print(min(sum1, sum2))
solve()


n = int(input())
l = list(map(int, input().split()))
l.sort()
inf = 10 ** 18
ans = sum(l) - n
for i in range(1, 10 ** 9):
	cur_cost = 0
	cur_pow = 1
	for j in range(n):
		cur_cost += abs(l[j] - cur_pow)
		cur_pow *= i
		if cur_pow > inf:
			break
	if cur_pow > inf:
		break
	if cur_pow / i > ans + l[n - 1]:
		break
	ans = min(ans, cur_cost)
print(ans)


def scanInt():
	return int(input())

def scanList():
	return [i for i in input().split(' ')]

def scanIntList():
	return [int(i) for i in scanList()]
n = scanInt()
a = scanIntList()

def count(l, a):
	cost = 0
	c = 1
	for i in l:
		cost += abs(c - i)
		if c > 1e+18:
			return 1e+18
		c *= a
	return cost
a.sort()
ans = count(a, 1)
for i in range(1, int(pow(1000000000000000.0, 1 / n)) + 10):
	ans = min(ans, count(a, i))
print(ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
n = int(data())
arr = l()
arr.sort()
if n <= 2:
	out(arr[0] - 1)
	exit()
if n == 3:
	temp = 31623
elif n == 4:
	temp = 10000
elif n == 5:
	temp = 200
elif n == 6:
	temp = 70
elif n == 7:
	temp = 35
elif n == 8:
	temp = 20
elif n == 9:
	temp = 14
elif n == 10:
	temp = 10
elif n == 11:
	temp = 8
elif n == 12:
	temp = 7
elif n == 13:
	temp = 6
elif n <= 15:
	temp = 5
elif n <= 19:
	temp = 4
elif n <= 30:
	temp = 3
elif n <= 32:
	temp = 2
else:
	temp = 1
answer = inf
for i in range(1, temp + 1):
	new = 0
	f = 1
	for j in arr:
		new += abs(j - f)
		f *= i
	answer = min(answer, new)
print(answer)


n = int(input())
a = [int(i) for i in input().split()]
if n > 60:
	print(sum(a) - n)
else:
	ans = 4557430888798830399
	a.sort()
	nlen = int(pow(max(a), 1 / (len(a) - 1))) + 1
	i = 1
	while i <= nlen:
		t = 0
		for j in range(len(a)):
			t += abs(a[j] - i ** j)
		ans = min(ans, t)
		i += 1
	print(ans)


import math as m
n = int(input())
a = input().split()
a = [int(x) for x in a]
a.sort()
b = a[n - 1]
e = b ** (1 / (n - 1))
c = m.ceil(e)
d = m.floor(e)
l = 0
r = 0
for i in range(n):
	l = l + abs(a[i] - c ** i)
	r = r + abs(a[i] - d ** i)
print(min(int(l), int(r)))


from __future__ import division, print_function
from sys import stdin, stdout
import bisect
import math
import heapq
i_m = 9223372036854775807

def inin():
	return int(input())

def stin():
	return input()

def spin():
	return map(int, stin().split())

def lin():
	return list(map(int, stin().split()))

def matrix(n):
	return [list(map(int, input().split())) for i in range(n)]

def string2intlist(s):
	return list(map(int, s))

def calculate_sum(a, N):
	m = N / a
	sum = m * (m + 1) / 2
	ans = a * sum
	return ans

def series(N):
	return N * (N + 1) // 2

def count2Dmatrix(i, list):
	return sum((c.count(i) for c in list))

def modinv(n, p):
	return pow(n, p - 2, p)

def GCD(x, y):
	x = abs(x)
	y = abs(y)
	if min(x, y) == 0:
		return max(x, y)
	while y:
		(x, y) = (y, x % y)
	return x

def LCM(x, y):
	return x * y // GCD(x, y)

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

def isprime(n):
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True
prime = []

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j
n = inin()
a = lin()
a = sorted(a)
m = max(a)
(c1, c2, c3) = (0, 0, 0)
r1 = math.floor(math.pow(m, 1 / (n - 1)))
r2 = r1 + 1
r3 = r1 - 1
for i in range(len(a)):
	if a[i] == r1 ** i:
		pass
	elif a[i] > r1 ** i:
		c1 += a[i] - r1 ** i
	else:
		c1 += r1 ** i - a[i]
	if a[i] == r2 ** i:
		pass
	elif a[i] > r2 ** i:
		c2 += a[i] - r2 ** i
	else:
		c2 += r2 ** i - a[i]
	if a[i] == r3 ** i:
		pass
	elif a[i] > r3 ** i:
		c3 += a[i] - r3 ** i
	else:
		c3 += r3 ** i - a[i]
print(min(min(c1, c2), c3))


thres = 1000000000000000000

def power(a, b):
	result = 1
	while b > 0:
		if b % 2 == 1:
			result = result * a
			if result > thres:
				return -1
		a = a * a
		b = b // 2
	return result

def bin_search():
	low = 2
	high = last
	while low < high:
		mid = (low + high) // 2
		temp = power(mid, n - 1)
		if temp > last or temp == -1:
			high = mid - 1
		else:
			low = mid + 1
	return (low, high)

def calculate(num):
	res = 0
	for i in range(n):
		temp = abs(a[i] - power(num, i))
		res += temp
	return res
n = int(input())
a = list(map(int, input().split()))
a.sort()
last = a[-1]
(first, second) = bin_search()
result = thres
for i in range(second - 1, first + 2):
	temp = calculate(i)
	result = min(result, temp)
print(result)


n = int(input())
mn = 10 ** (16 // (n - 1))
liStr = input().split()
arr = []
for i in liStr:
	arr.append(int(i))
arr.sort()
ctr = 0
a = 1
minMoves = 10 ** 20
while ctr <= 10 ** 5:
	moves = 0
	p = 0
	for i in arr:
		moves += abs(i - pow(a, p))
		p += 1
		ctr += 1
	if moves < minMoves:
		minMoves = moves
	a += 1
print(minMoves)


n = int(input())
l = sorted(list(map(int, input().split())))
mx = 10 * 10 ** 9 + 9
min_cost = float('inf')
c = 1
while c ** (n - 1) < mx:
	s = 0
	for i in range(n):
		s += abs(l[i] - c ** i)
	c += 1
	min_cost = min(s, min_cost)
print(min_cost)


n = int(input())
l = list(map(int, input().split()))
if n >= 50:
	s = sum(l)
	print(s - n)
else:
	l.sort()
	mi = 1000000000000000
	for i in range(1, 100001):
		ans = 0
		x = 1
		for j in range(n):
			ans += abs(x - l[j])
			x = x * i
		mi = min(ans, mi)
	print(mi)


n = int(input())
a = list(map(int, input().split()))
a.sort()
k = 1
minDiff = 10 ** 14
while True:
	if k ** (n - 1) - a[n - 1] > n * 10 ** 9:
		break
	diff = 0
	for i in range(n):
		diff += abs(k ** i - a[i])
	if diff < minDiff:
		minDiff = diff
	k += 1
print(minDiff)


from math import floor, ceil

def main():
	n = int(input())
	A = [int(x) for x in input().split()]
	A.sort()
	c = A[n - 1] ** (1 / (n - 1))
	(c_l, c_h) = (floor(c), ceil(c))
	(cost_l, cost_h) = (0, 0)
	for i in range(n):
		cost_l += abs(c_l ** i - A[i])
		cost_h += abs(c_h ** i - A[i])
	print(min(cost_l, cost_h))
main()


n = int(input())
s = sorted([int(i) for i in input().split()])
cnt = 0
l = int(s[n - 1] ** (1 / (n - 1)))
m = l + 1
p = 0
for i in range(n):
	cnt += abs(s[i] - m ** i)
	p += abs(s[i] - l ** i)
print(min(p, cnt))


import sys
import time
FIO = 10

def I():
	return input()

def Iint():
	return int(input())

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

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

def Plist(li, s=' '):
	print(s.join(map(str, li)))
en = enumerate

def answer_debug(*args):
	print('\x1b[31m', *args, '\x1b[0m', file=sys.stderr)

def debug(*args):
	print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)
if not FIO:
	if __name__ == '__main__':
		main()
		exit()
else:
	from io import BytesIO, IOBase
	import os
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))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def main():
	n = int(input())
	l = sorted(Ilist())
	ans = sum(l) - n
	for i in range(2, 10 ** 5):
		nn = 0
		for j in range(n):
			nn += abs(l[j] - i ** j)
			if nn >= ans:
				break
		if nn < ans:
			ans = nn
	print(ans)
main()


from math import ceil, floor, sqrt
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = sum(a) - 1
inf = 10 ** 18
for x in range(1, 10 ** 9):
	cp = 1
	cc = 0
	for i in range(n):
		cc += abs(a[i] - cp)
		cp *= x
		if cp > inf:
			break
	if cp > inf:
		break
	if cp / x > ans + a[n - 1]:
		break
	ans = min(ans, cc)
print(ans)


from sys import stdin
input = stdin.readline
n = int(input())
a = list(map(int, input().rstrip().split()))
a = sorted(a)
answer = 10 ** 18
c = 0
flag = True
while flag:
	c += 1
	newAns = 0
	for i in range(n):
		newAns += abs(a[i] - c ** i)
		if newAns > answer:
			flag = False
			break
	answer = min(answer, newAns)
print(answer)


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
cost = float('inf')
c = 1
while True:
	currCost = a[0] - 1
	for i in range(1, n):
		currCost += abs(a[i] - math.pow(c, i))
		if currCost > cost:
			break
	if currCost <= cost:
		cost = currCost
		c += 1
	else:
		break
print(int(cost))


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = sum(a) - len(a)
for c in range(2, 10 ** 9 + 1):
	(s, p) = (0, 1)
	for v in a:
		s += abs(v - p)
		if s > ans:
			break
		p *= c
	if s > ans:
		break
	ans = s
print(ans)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
if n == 1 or n == 2:
	print(abs(a[0] - 1))
	sys.exit(0)
a.sort()
bound = 1
while pow(bound, n - 1) <= 10000000000.0:
	bound += 1
	if pow(bound, n - 1) > 19237982374980273849:
		bound = 1
		break
ans = 999999999999999
for b in range(1, bound + 1):
	cur = 0
	mul = 1
	for v in a:
		cur += abs(mul - v)
		mul *= b
	ans = min(ans, cur)
print(ans)


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
last = a[-1]
c1 = math.ceil(math.exp(math.log(last) / (n - 1)))
c2 = math.floor(math.exp(math.log(last) / (n - 1)))
v1 = 0
v2 = 0
for i in range(len(a)):
	v1 += abs(a[i] - c1 ** i)
	v2 += abs(a[i] - c2 ** i)
print(min(v1, v2))


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 10 ** 18
i = 1
while i ** (n - 1) < 10 ** 12:
	count = 0
	for j in range(n):
		count += abs(a[j] - i ** j)
	i += 1
	ans = min(ans, count)
print(ans)


n = int(input())
ls = list(map(int, input().split()))
sorted_ls = sorted(ls)
c = int(sorted_ls[-1] ** (1 / (n - 1)))
ans = 0
ans_add = 0
for (idx, item) in enumerate(sorted_ls):
	ans += abs(item - c ** idx)
	ans_add += abs(item - (c + 1) ** idx)
if ans > ans_add:
	print(ans_add)
else:
	print(ans)


n = int(input())
a = sorted(list(map(int, input().split())))
min_cost = None
k = 1
while 1:
	cost = 0
	for i in range(len(a)):
		cost += abs(k ** i - a[i])
	if min_cost == None:
		min_cost = cost
		k += 1
		continue
	if cost > min_cost:
		print(min_cost)
		break
	else:
		min_cost = cost
		k += 1


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

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

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

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]
inf = 10 ** 16
n = II()
aa = LI()
aa.sort()
lim = sum(aa) - n
l = 1
r = 10 ** 9

def val(m):
	res = 0
	mp = 1
	for (i, a) in enumerate(aa):
		res += abs(a - mp)
		if res > lim:
			return inf
		mp *= m
	return res
while l + 2 < r:
	ml = (2 * l + r) // 3
	mr = (l + 2 * r) // 3
	vl = val(ml)
	vr = val(mr)
	if vl == vr == inf:
		r = ml
	elif vl < vr:
		r = mr
	else:
		l = ml
m = (l + r) // 2
print(min(val(l), val(m), val(r)))


import math
n = int(input())
A = list(map(int, input().split()))
A.sort()
temp = math.floor(pow(A[n - 1], 1 / (n - 1)))
z = temp
temp2 = temp + 1
z2 = temp2
ans = 0
ans2 = 0
for x in range(n):
	ss = pow(temp, x)
	ans = ans + abs(A[x] - ss)
for x in range(n):
	s = pow(temp2, x)
	ans2 = ans2 + abs(A[x] - s)
if ans > ans2:
	print(ans2)
else:
	print(ans)


n = int(input())
NUM = list(map(int, input().split()))
NUM.sort()
c = 1
answer = 0
ans = 0
index = 0
while index < n:
	answer += abs(c ** index - NUM[index])
	index += 1
c = 2
while True:
	index = 0
	ans = 0
	while index < n:
		ans += abs(c ** index - NUM[index])
		index += 1
	if answer > ans:
		answer = ans
	else:
		break
	c += 1
print(answer)


n = int(input())
a = sorted(list(map(int, input().split())))
v = sum(a) - n
if n > 47:
	print(v)
	quit()
k = 2
while k ** (n - 1) < a[-1]:
	k += 1
s = min(sum((abs((k - 1) ** i - a[i]) for i in range(n))), sum((abs(k ** i - a[i]) for i in range(n))))
print(min(v, s))


n = int(input())
an = list(sorted(map(int, input().split())))
ans = sum(an) - n
for i in range(2, 10 ** 5):
	newa = 0
	for j in range(n):
		newa += abs(an[j] - i ** j)
		if newa >= ans:
			break
	if newa < ans:
		ans = newa
print(ans)


n = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 0
for a in A:
	ans += a - 1
for c in range(1, 10 ** 9 + 1):
	temp = 0
	p = 1
	for i in range(n):
		temp += abs(p - A[i])
		p *= c
		if p > 10 ** 18:
			break
	if p > 10 ** 18:
		break
	if p / c - A[n - 1] > ans:
		break
	ans = min(ans, temp)
print(ans)


from math import *
from collections import Counter, defaultdict
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
n = I()
l = LI()
l.sort()
d = 0
k = 0
f = l[-1] ** (1 / (n - 1))
for i in range(n):
	d += abs(ceil(f) ** i - l[i])
	k += abs(floor(f) ** i - l[i])
print(min(k, d))


n = int(input())
a = list(map(int, input().split(' ')))
a.sort()
answer = 1e+18
flag = True
for i in range(1, 500000):
	ans = 0
	for (j, val) in enumerate(a):
		x = pow(i, j)
		ans += abs(x - val)
		if x > 1e+18:
			flag = False
			break
	answer = min(ans, answer)
	if not flag:
		break
print(answer)


n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = []
k = int(l[n - 1] ** (1 / (n - 1)))
ans1 = 0
for i in range(n):
	ans1 += abs(k ** i - l[i])
ans.append(ans1)
k += 1
ans2 = 0
for i in range(n):
	ans2 += abs(k ** i - l[i])
ans.append(ans2)
k -= 2
ans3 = 0
for i in range(n):
	ans3 += abs(k ** i - l[i])
ans.append(ans3)
print(min(ans))


n = int(input())
arr = [int(i) for i in input().split()]
arr = sorted(arr)
cost = -1
for c in range(1, max(n, 40000)):
	cur = 0
	p = 1
	for i in range(len(arr)):
		cur += abs(arr[i] - c ** i)
		if c ** i > 100000000000000000000:
			p = 0
			break
	if not p:
		break
	if cost == -1 or cost > cur:
		cost = cur
print(cost)


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

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

def pw(a, b):
	result = 1
	while b > 0:
		if b % 2 == 1:
			result *= a
		a *= a
		b //= 2
	return result

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

def main():
	n = int(input())
	ar = inpt()
	ar.sort()
	sm = sum(ar)
	ans = sm - n
	if n <= 32:
		ct = 0
		for i in range(1, 100000):
			temp = 0
			ct = 0
			for j in range(n):
				if pw(i, j) > 2 * 10 ** 18:
					ct = 1
					break
				temp += abs(ar[j] - pw(i, j))
			if ct == 0:
				ans = min(ans, temp)
	print(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()))
a.sort()
temp = int(pow(a[n - 1], 1 / (n - 1)))
top = temp + 1
if n < 33:
	(p1, p2) = (1, 1)
	(temp1, temp2) = (abs(p1 - a[0]), abs(p2 - a[0]))
	for i in range(1, n):
		p1 = p1 * top
		p2 = p2 * (top - 1)
		temp1 += abs(p1 - a[i])
		temp2 += abs(p2 - a[i])
	print(min(temp1, temp2))
else:
	sum = 0
	for i in range(n):
		sum += a[i] - 1
	print(sum)


import math
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
c = 1
mini = 1000000000000000000
while 1:
	ans = 0
	for i in range(n):
		ans += abs(pow(c, i) - arr[i])
	if mini > ans:
		mini = ans
	else:
		break
	c = c + 1
print(mini)


n = int(input())
a = sorted(list(map(int, input().split())))
x = 1
c = 10 ** 18
f = 0
while x ** (n - 1) <= f + a[-1]:
	m = 0
	for i in range(n):
		m += abs(a[i] - x ** i)
	if m < c:
		c = m
	if x == 1:
		f = m
	x += 1
print(c)


import math
n = int(input())
data = list(map(int, input().split()))
data = sorted(data)
m = data[-1]
y = math.ceil(m ** (1 / (n - 1)))
min = 100000000000000000000000000
for i in range(1, y + 1):
	loss = 0
	for j in range(n):
		loss += abs(i ** j - data[j])
	if loss < min:
		min = loss
print(min)


n = int(input())
lst = list(map(int, input().split()))
lst.sort()
s = lst[-1] ** (1 / (n - 1))
v1 = int(s)
v2 = int(s) + 1
(ans, ans2) = (0, 0)
for i in range(n):
	ans += abs(lst[i] - v1 ** i)
	ans2 += abs(lst[i] - v2 ** i)
print(min(ans, ans2))


n = int(input())
s = list(map(int, input().split()))
s.sort()
c = int(pow(s[-1], 1 / (n - 1)))
mini = 0
mina = 0
for i in range(n):
	mini += abs(s[i] - c ** i)
	mina += abs(s[i] - (c + 1) ** i)
print(min(mina, mini))


import math as m
n = int(input())
x = list(map(int, input().split()))
x.sort()
a = m.floor(x[n - 1] ** (1 / (n - 1)))
b = 0
c = 0
for i in range(len(x)):
	b += abs(x[i] - a ** i)
for i in range(len(x)):
	c += abs(x[i] - (a + 1) ** i)
print(min(c, b))


n = int(input())
a = sorted(list(map(int, input().split())))
inf = 10 ** 18
if n < 3:
	print(a[0] - 1)
	exit()
ans = sum(a) - n
for j in range(10 ** 9):
	c_p = 1
	c_c = 0
	for i in range(n):
		c_c += abs(a[i] - c_p)
		c_p *= j + 1
		if c_p > inf:
			break
	if c_p > inf:
		break
	if c_p / (j + 1) > ans + a[n - 1]:
		break
	ans = min(ans, c_c)
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
ans = int(100000000000000.0)
if n <= 2:
	print(a[0] - 1)
	exit(0)
e = int(max(a)) ** (1.0 / (n - 1))
for i in range(int(e + 2)):
	c = 0
	for j in range(n):
		c += abs(pow(i, j) - a[j])
	ans = min(ans, c)
print(ans)


n = int(input())
arr = [int(i) for i in input().split()]
arr.sort()
max1 = (10 ** 18) ** (1 / (n - 1))
ans = 10 ** 18
c = 1
j = 1
while j <= max1:
	val = 0
	ind = 1
	for i in range(n):
		val += abs(ind - arr[i])
		ind *= j
	if min(ans, val) == ans:
		break
	else:
		ans = val
	j += 1
print(ans)


from math import *
n = int(input())
a = list(map(int, input().split()))
a.sort()
big = 10 ** 13
ans = big
c = 1
while 1:
	m = 0
	p = 1
	for i in range(n):
		if p >= big:
			m = -1
			break
		m += abs(a[i] - p)
		p *= c
	if m == -1:
		break
	else:
		ans = min(ans, m)
		c += 1
print(ans)


n = int(input())
(*a,) = map(int, input().split())
a.sort()
ans = 10 ** 40
if n >= 60:
	ans = sum(a)
	ans -= n
	print(ans)
	exit()
mx = int(a[-1] ** (1 / (n - 1))) * n
ee = 0
for i in range(1, mx):
	tmp = 0
	for j in range(n):
		tmp += abs(pow(i, j) - a[j])
	if ans > tmp:
		ee = i
		ans = min(ans, tmp)
print(ans)


try:
	n = int(input())
	a = [int(x) for x in input().split()]
	a.sort()
	inf = 10 ** 18
	if n <= 2:
		print(a[0] - 1)
	else:
		ans = sum(a) - n
		for x in range(1, 10 ** 9):
			curPow = 1
			curCost = 0
			for i in range(n):
				curCost += abs(a[i] - curPow)
				curPow *= x
				if curPow > inf:
					break
			if curPow > inf:
				break
			if curPow / x > ans + a[n - 1]:
				break
			ans = min(ans, curCost)
	print(ans)
except:
	pass


n = int(input())
nums = list(map(int, input().split()))
nums.sort()
minval = abs(sum(nums) - n)
for c in range(2, int(100000.0)):
	diff = nums[0] - 1
	val = 1
	for i in range(1, n):
		val = val * c
		diff += abs(nums[i] - val)
		if diff > minval:
			break
	minval = min(minval, diff)
print(minval)


from math import log2, floor, ceil
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
s = 0
if n > 60:
	for i in l:
		s += i - 1
	print(s)
else:
	x = [9999999999999999]
	for c in range(1, 100000):
		s = 0
		for i in range(n):
			s += abs(l[i] - pow(c, i))
		if s > x[-1]:
			print(x[-1])
			break
		else:
			x.append(s)
			continue


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = float('inf')
mx = max(arr)
ind = 0
for i in range(n):
	if arr[i] == mx:
		ind = i
fl = math.floor(mx ** (1 / ind))
ce = math.ceil(mx ** (1 / ind))
a1 = 0
a2 = 0
for i in range(n):
	a1 += abs(fl ** i - arr[i])
	a2 += abs(ce ** i - arr[i])
print(min(a1, a2))


import sys
readline = sys.stdin.buffer.readline

def i1():
	return int(readline())

def nl():
	return [int(i) for i in readline().split()]

def redir(s):
	global readline
	import os
	fn = sys.argv[0] + f'/../in-{s}.txt'
	readline = open(fn).readline if os.path.exists(fn) else readline
redir('b')
n = i1()
arr = sorted(nl())
total = 0
total = sum(arr) - n
ret = total
if n < 50:
	c = max(int(arr[0] ** (1 / n)), 2)
	while True:
		cost = 0
		power = 1
		for x in arr:
			cost += abs(power - x)
			power *= c
		if ret > cost:
			ret = cost
		else:
			break
		c += 1
print(ret)


n = int(input())
Arr = sorted(list(map(int, input().split())))
minDiff = 10 ** 18
c = 1
while c ** (n - 1) < 10 ** 10:
	result = 0
	for i in reversed(range(n)):
		result += abs(c ** i - Arr[i])
	minDiff = min(minDiff, result)
	c += 1
print(minDiff)


n = int(input())
a = list(map(int, input().split()))
a.sort()
c1 = a[0] - 1
c2 = a[0] - 1
ll = a[n - 1]
last = pow(ll, 1 / (n - 1))
llp = int(last)
lls = int(last) + 1
for i in range(1, n):
	v = pow(lls, i)
	w = pow(llp, i)
	c1 = c1 + abs(v - a[i])
	c2 = c2 + abs(w - a[i])
print(min(c1, c2))


def solve():
	ans = float('inf')
	N = int(input())
	A = list(map(int, input().split()))
	A.sort()
	if N == 2:
		return A[0] - 1
	p = 1
	while True:
		cost = 0
		q = 1
		for i in range(N):
			cost += abs(q - A[i])
			if cost > ans:
				break
			q *= p
		else:
			ans = cost
			p += 1
			continue
		break
	return ans
print(solve())


from math import ceil, floor
n = int(input())
ar = list(map(int, input().split()))
ar.sort()
sc = sf = 0
c = ceil(ar[-1] ** (1 / (n - 1)))
f = floor(ar[-1] ** (1 / (n - 1)))
for i in range(n):
	sc += abs(ar[i] - c ** i)
	sf += abs(ar[i] - f ** i)
print(min(sc, sf))


import math, sys
from collections import defaultdict, Counter, deque
INF = float('inf')
MOD = 10 ** 9 + 7

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactors(n):
	factors = defaultdict(int)
	i = 2
	while i ** 2 <= n:
		while n % i == 0:
			factors[i] += 1
			n //= i
		i += 1
	if n > 1:
		factors[n] += 1
	return factors

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

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

def a():
	n = int(input())
	m = defaultdict(int)
	for i in range(n):
		s = input()
		for c in s:
			m[c] += 1
	res = 'YES'
	for c in m:
		if m[c] % n != 0:
			res = 'NO'
			break
	print(res)

def b():
	n = int(input())
	arr = array()
	arr.sort()
	maxi = arr[-1]
	res1 = math.floor(maxi ** (1 / (n - 1)))
	res2 = math.ceil(maxi ** (1 / (n - 1)))
	ans1 = ans2 = 0
	for i in range(n):
		ans1 += abs(arr[i] - res1 ** i)
	for i in range(n):
		ans2 += abs(arr[i] - res2 ** i)
	print(min(ans1, ans2))
t = 1
for _ in range(t):
	b()


import math

def main():
	n = int(input())
	arr = list(sorted(map(int, input().split())))
	differences = [0] * n
	for i in range(n):
		if i == 0:
			differences[0] = arr[i] - 1
			continue
		c = 0
		floor = math.floor(arr[i] ** (1.0 / i))
		if arr[i] - floor ** i < (floor + 1) ** i - arr[i]:
			c = floor
		else:
			c = floor + 1
		differences[i] = c
	ans = 10 ** 30
	for j in range(n - 1, n - 4, -1):
		if j < 0:
			break
		c = differences[j]
		d = 0
		for i in range(n):
			element = c ** i
			d += abs(arr[i] - element)
		ans = min(d, ans)
	print(ans)
main()


import sys
t = 1
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	ans = []
	for i in range(1, 100000 + 5):
		ta = 1
		cur = 0
		fuck = 1
		for j in range(n):
			cur += abs(ta - arr[j])
			ta = ta * i
			if ta > 10 ** 18:
				fuck = 0
				break
		if fuck:
			ans.append(cur)
		else:
			break
	print(min(ans))


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
N = INT()
A = LIST()
A.sort()
ans = INF
for c in range(100007):
	cur = 0
	for i in range(N):
		if c ** i > INF:
			break
		cur += abs(A[i] - c ** i)
	ans = min(ans, cur)
print(ans)


import math
n = int(input())
s = list(map(int, input().split()))
s.sort()
x = math.ceil(s[-1] ** (1 / (n - 1)))
m = 1000000000000000000
final = 10 ** 15
curr = 0
for c in range(x - 10, x + 10):
	curr = 0
	cl = 1
	for i in range(n):
		curr += abs(cl - s[i])
		cl = cl * c
		if curr > final:
			break
	m = min(m, curr)
print(m)


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, A):
	A.sort()
	best = float('inf')
	for c in range(1, 10 ** 9):
		cost = 0
		for i in range(N):
			x = A[i]
			cost += abs(x - c ** i)
		if cost < best:
			best = min(best, cost)
		else:
			return best
	return best
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(N,) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = solve(N, A)
print(ans)


import math
from sys import stdin
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(n,) = gil()
a = gil()
a.sort()

def cal(c):
	c = max(c, 0)
	cst = 0
	for i in range(n):
		cst += abs(a[i] - c ** i)
	return cst
(l, r) = (0, int(a[-1] ** (1 / (n - 2))) + 1)
ans = None
while l <= r:
	mid = (l + r) // 2
	(la, ra) = (cal(mid), cal(mid - 1))
	if la > ra:
		r = mid - 1
	else:
		l = mid + 1
		ans = la
print(ans)


import sys
from time import time
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = list(map(int, input().split()))
a.sort()
if n >= 58:
	print(sum(a) - n)
else:
	t = int(a[-1] ** (1 / (n - 1)))
	ck = t
	ck1 = t + 1
	ak = b = abs(a[0] - 1)
	for j in range(1, n):
		ak += abs(a[j] - ck)
		ck *= t
		b += abs(a[j] - ck1)
		ck1 *= t + 1
	print(min(ak, b))


n = int(input())
a = sorted(list(map(int, input().split())))
res = sum(a) - len(a)
if n == 2:
	res = a[0] - 1
if n > 2:
	i = 2
	while abs(i ** (n - 1) - a[-1]) < res:
		r = 0
		for (j, el) in enumerate(a):
			r += abs(el - i ** j)
		res = min(res, r)
		i += 1
print(res)


import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

def solve(lst):
	lst = sorted(lst)
	console('----- solving ------')
	console(lst)
	if len(lst) > 40:
		return sum(lst) - len(lst)
	base = 0
	minres = 10 ** 11
	while base ** len(lst) < 10 ** 15:
		req = [base ** i for i in range(len(lst))]
		diff = [abs(r - x) for (r, x) in zip(req, lst)]
		minres = min(minres, sum(diff))
		base += 1
	return minres

def console(*args):
	print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)
	return
for _ in range(1):
	_ = int(input())
	lst = list(map(int, input().split()))
	res = solve(lst)
	print(res)


import sys
(_ord, inp, num, neg, _Index) = (lambda x: x, [], 0, False, 0)
(i, s) = (0, sys.stdin.buffer.read())
try:
	while True:
		if s[i] >= b'0'[0]:
			num = 10 * num + _ord(s[i]) - 48
		elif s[i] == b'-'[0]:
			neg = True
		elif s[i] != b'\r'[0]:
			inp.append(-num if neg else num)
			(num, neg) = (0, False)
		i += 1
except IndexError:
	pass
if s and s[-1] >= b'0'[0]:
	inp.append(-num if neg else num)

def fin(size=None):
	global _Index
	if size == None:
		ni = _Index
		_Index += 1
		return inp[ni]
	else:
		ni = _Index
		_Index += size
		return inp[ni:ni + size]
_T_ = 1
for _t_ in range(_T_):
	n = fin()
	a = fin(n)
	a.sort()
	ma = a[-1]
	p = 1
	while True:
		if p ** (n - 1) > ma:
			break
		p += 1
	ans1 = 0
	ans2 = 0
	for i in range(n):
		ans1 += abs(a[i] - p ** i)
	p -= 1
	for i in range(n):
		ans2 += abs(a[i] - p ** i)
	print(min(ans1, ans2))


import math
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
cf = math.floor(pow(arr[-1], 1 / (len(arr) - 1)))
ansf = abs(arr[0] - 1)
for i in range(1, n):
	ansf += abs(cf ** i - arr[i])
cc = math.ceil(pow(arr[-1], 1 / (len(arr) - 1)))
ansc = abs(arr[0] - 1)
for i in range(1, n):
	ansc += abs(cc ** i - arr[i])
print(min(ansc, ansf))


import sys
import os

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

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

def array_1D(length, value=0):
	data = [value for _ in range(length)]
	return data

def array_2D(row, col, value=0):
	data = [[value for c in range(col)] for r in range(row)]
	return data

def vector_2D(nodes):
	data = dict()
	for n in range(nodes):
		data[n] = list()
	return data

def str_replacer(old_str, new_str, index):
	if index in range(len(old_str)):
		return old_str[:index] + new_str + old_str[index + 1:]
	else:
		return old_str
if os.environ.get('DEBUGSTER_PYTHON'):
	sys.stdin = open('in.txt', 'r')
	sys.stdout = open('out.txt', 'w')
n = int(input())
num = get_array()
num.sort()
limit = num[n - 1] ** (1 / float(n - 1))
limit = int(limit + 1)
ans = 10000000000000000000
for c in range(1, limit + 1):
	cnt = 0
	for i in range(n):
		cnt += abs(num[i] - c ** i)
	ans = min(ans, cnt)
print(ans)


import math
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
a.sort()
i = 1
while not (i ** (n - 1) <= a[n - 1] and a[n - 1] <= (i + 1) ** (n - 1)):
	i += 1
(ans1, ans2) = (0, 0)
tmp = 1
for e in a:
	ans1 += abs(tmp - e)
	tmp *= i
tmp = 1
for e in a:
	ans2 += abs(tmp - e)
	if ans2 >= ans1:
		break
	tmp *= i + 1
print(min(ans1, ans2))


import math
n = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 0
for i in range(len(A)):
	if i != 0:
		val = int(pow(A[i], 1.0 / i))
		ans = val
x1 = int(ans)
x2 = int(ans) + 1
min1 = 0
min2 = 0
res = 0
for i in range(len(A)):
	if i == 0:
		res = res + abs(A[0] - 1)
	else:
		val1 = int(pow(x1, i))
		val2 = int(pow(x2, i))
		min1 = min1 + abs(val1 - A[i])
		min2 = min2 + abs(val2 - A[i])
res = res + min(min1, min2)
print(res)


n = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 0
i = 0
while i < n:
	ans += A[i] - 1
	i += 1
if n <= 60:
	base = 1
	while base <= 10 ** 5:
		flag = True
		while flag:
			i = 0
			cur = 0
			while i < n:
				cur += abs(A[i] - base ** i)
				if cur >= ans:
					flag = False
					break
				i += 1
			ans = min(ans, cur)
		base += 1
print(ans)


from bisect import bisect_left
import os
import sys
from io import BytesIO, IOBase
from collections import Counter, defaultdict
from collections import deque
from functools import cmp_to_key
import math

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

def sain():
	return input().split()

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	s = set()
	for p in range(2, n + 1):
		if prime[p]:
			s.add(p)
	return s

def readTree(n, m):
	adj = [deque([]) for _ in range(n + 1)]
	for _ in range(m):
		(u, v) = ain()
		adj[u].append(v)
		adj[v].append(u)
	return adj

def main():
	n = iin()
	l = ain()
	l.sort()
	ans = MAX
	c = 1
	while 1:
		x = 1
		val = 0
		for i in range(0, n):
			if x > 1000000000000.0:
				val = -1
				break
			val += abs(l[i] - x)
			x *= c
		if val == -1:
			break
		ans = min(ans, val)
		c += 1
	print(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')
if os.getcwd() == 'D:\\code':
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
max_r = int(math.ceil(pow(10, 9 / (n - 1))))
lst = []
for r in range(1, max_r + 1):
	cost = 0
	for i in range(n):
		if a[i] != pow(r, i):
			cost += abs(pow(r, i) - a[i])
	lst.append(cost)
print(min(lst))


from math import gcd, ceil, floor, sqrt
n = int(input())
a = list(map(int, input().split()))
a.sort()
val = a[-1]
g = ceil(val ** (1 / (n - 1)))
f = g - 1
a1 = 0
a2 = 0
for i in range(n):
	a1 += abs(a[i] - pow(g, i))
	a2 += abs(a[i] - pow(f, i))
dd = min(a1, a2)
print(dd)


import sys
input = sys.stdin.readline
n = int(input())
a = sorted(list(map(int, input().split())))
c = 1
prev = int(1000000000.0) * n
while True:
	ans = 0
	pow = 1
	for A in a:
		ans += abs(A - pow)
		pow *= c
		if ans > prev:
			break
	if ans > prev:
		break
	prev = ans
	c += 1
print(prev)


n = int(input())
arr = [int(j) for j in input().split()]
arr.sort()
if n == 2:
	arr.pop()
	n -= 1
if n <= 35:
	ans = 99999999999999999999
	for base in range(1, 40000):
		temp = []
		tempans = 0
		for j in range(n):
			temp += [base ** j]
		for j in range(n):
			tempans += abs(arr[j] - temp[j])
		ans = min(ans, tempans)
	print(ans)
else:
	final = [1] * n
	ans = 0
	for j in range(n):
		ans += abs(arr[j] - final[j])
	print(ans)


import sys, os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
t = 1
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	inf = 10 ** 18
	if n <= 2:
		print(a[0] - 1)
	else:
		ans = sum(a) - n
		for i in range(1, 10 ** 9):
			r = 1
			sum1 = 0
			for j in range(n):
				sum1 += abs(a[j] - r)
				r *= i
				if r > inf:
					break
			if r / i > ans + a[n - 1]:
				break
			ans = min(ans, sum1)
		print(ans)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
maximo = a[-1]
e1 = int(maximo ** (1 / (n - 1)))
e2 = e1 + 1
acumulado1 = 0
acumulado2 = 0
for i in range(n):
	acumulado1 = acumulado1 + abs(a[i] - e1 ** i)
	acumulado2 = acumulado2 + abs(a[i] - e2 ** i)
print(min(acumulado1, acumulado2))


import sys
import math
readline = lambda : sys.stdin.readline().strip()
N = int(readline())
A = [int(x) for x in readline().split()]
A.sort()

def find_cost(c):
	cost = 0
	for i in range(N):
		cost += abs(A[i] - c ** i)
	return cost
pivot = A[-1] ** (1 / (N - 1))
lb = math.floor(pivot)
ub = math.ceil(pivot)
cost1 = find_cost(lb)
cost2 = find_cost(ub)
print(min(cost1, cost2))


def check(num, power):
	for i in range(2, 1000000000):
		if i ** power >= num:
			break
	return i
num = int(input())
a = list(map(int, input().split()))
a.sort()
ans1 = a[0] - 1
ans2 = a[0] - 1
ans3 = a[0] - 1
val = check(a[-1], num - 1)
for i in range(1, num):
	ans1 += abs(a[i] - val ** i)
	ans2 += abs(a[i] - 1)
	ans3 += abs(a[i] - (val - 1) ** i)
print(min(ans1, ans2, ans3))


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = 10 ** 18
MAX = 10 ** 15
flag1 = False
i = 0
while True:
	p = 0
	curr = 0
	for j in range(n):
		p = pow(i, j)
		if p > arr[-1]:
			flag1 = True
		curr += abs(p - arr[j])
	ans = min(ans, curr)
	i += 1
	if flag1:
		break
print(ans)


import math
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
c1 = int(math.ceil(pow(l[n - 1], 1 / (n - 1))))
c2 = int(math.floor(pow(l[n - 1], 1 / (n - 1))))
(cst1, cst2) = (0, 0)
for i in range(n):
	cst1 += abs(l[i] - pow(c1, i))
	cst2 += abs(l[i] - pow(c2, i))
print(min(cst1, cst2))


import sys
import math
import bisect

def solve(A):
	n = len(A)
	min_val = 10 ** 18
	p = 1
	while True:
		tmp = 1
		val = 0
		for i in range(n):
			val += abs(tmp - A[i])
			tmp *= p
			if val >= min_val:
				break
		if min_val > val:
			min_val = val
		else:
			break
		p += 1
	return min_val

def main():
	n = int(input())
	A = sorted(list(map(int, input().split())))
	print(solve(A))
main()


from math import sqrt
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ele = int(arr[-1] ** (1 / (n - 1)))
(sm1, sm2) = (0, 0)
for i in range(n - 1, -1, -1):
	sm1 += abs(ele ** i - arr[i])
	sm2 += abs((ele + 1) ** i - arr[i])
print(min(sm1, sm2))


from math import gcd, ceil, floor, sqrt

def solve():
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	x = l[-1]
	a = n - 1
	c = 1
	b = 1
	prev = 1
	while b < x:
		prev = c
		c += 1
		b = pow(c, a)
	ans1 = 0
	ans2 = 0
	for i in range(n):
		ans1 += abs(l[i] - pow(prev, i))
		ans2 += abs(l[i] - pow(c, i))
	print(min(ans1, ans2))
for _ in range(1):
	solve()


import sys
input = sys.stdin.readline
from bisect import bisect_left
from bisect import bisect_right
from math import ceil, factorial

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

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

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

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

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')

def check(x):
	this = 0
	for i in range(n):
		this += abs(x ** i - a[i])
	return this
n = int(input())
a = sorted(int_array())
last = a[-1]
final = int(last ** (1 / (n - 1))) + 2
lo = 1
hi = final
ans = INF
for i in range(lo, hi):
	ans = min(ans, check(i))
print(ans)


n = int(input())
z = [int(x) for x in input().split(' ')]
z.sort()
(ans, b) = (abs(z[0] - 1), abs(z[0] - 1))
c = int(pow(z[-1], 1 / (n - 1)))
for i in range(1, n):
	b += abs(pow(c, i) - z[i])
c += 1
for i in range(1, n):
	ans += abs(pow(c, i) - z[i])
print(min(ans, b))


n = int(input())
line = input().split(' ')
numbers = []
largest = 0
for i in line:
	numbers.append(int(i))
	largest = max(int(i), largest)
numbers = sorted(numbers)
if n == 1:
	print(numbers[0] - 1)
	exit()
pi = 0
result = 2 ** 64
besti = 0
limit = 10 ** 10
for i in range(1, 10 ** 9):
	sum = 0
	if pow(i, n - 1) > limit:
		break
	for j in range(0, n):
		sum += abs(numbers[j] - pow(i, j))
	result = min(sum, result)
print(result)


import math
n = int(input())
array = list(map(int, input().split()))
array.sort()
li = array[-1] ** (1 / (n - 1))
cmax = math.ceil(li)
result = 100000000000000000
for c in range(1, cmax + 1):
	p = 0
	for i in range(n):
		p += abs(array[i] - c ** i)
		if p > result:
			break
	result = min(p, result)
print(result)


from math import floor, inf
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = sum((c - 1 for c in a))
answer = inf
for i in range(1, floor((b + a[-1]) ** (1 / (n - 1))) + 1):
	d = 0
	e = 1
	for c in a:
		d += abs(c - e)
		e *= i
	answer = min(answer, d)
print(answer)


import sys, threading
sys.setrecursionlimit(10 ** 8)
threading.stack_size(10 ** 8)
from collections import defaultdict
import math

def main():
	n = int(input())
	maxVal = int(math.ceil((10 ** 9) ** (1 / (n - 1))))
	vals = sorted(map(int, input().split()))
	minCost = float('inf')
	for base in range(1, maxVal + 1):
		expec = 1
		cost = 0
		for val in vals:
			cost += abs(expec - val)
			expec *= base
			if cost > minCost:
				break
		minCost = min(minCost, cost)
	print(minCost)
threading.Thread(target=main).start()


(n, lst, ans, c) = (int(input()), sorted(map(int, input().split(' '))), 999999999999999, 1)
while True:
	(pw, br, temp, big) = (1, 0, 0, 999999999999999)
	for i in range(n):
		if pw > big:
			br = 1
			break
		temp += abs(pw - lst[i])
		pw = pw * c
	if br:
		break
	if temp < ans:
		ans = temp
		c = c + 1
	else:
		break
print(ans)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
mini = sum(arr) - n
lis = [mini]
for i in range(2, 100000):
	s = 0
	p = 0
	for j in range(n):
		x = i ** j
		s += abs(x - arr[j])
		if s > lis[-1]:
			p += 1
			break
	if p == 1:
		break
	else:
		lis.append(s)
print(min(lis))


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(n,) = I()
l = sorted(I())
an = sum(l) - n
i = 2
mx = max(l)
if n == 2:
	an = min(an, l[0] - 1)
while n > 2:
	po = 1
	cr = 0
	if i > 40000:
		break
	for j in range(n):
		cr += abs(l[j] - po)
		po *= i
		if cr > an:
			break
	an = min(cr, an)
	i += 1
print(an)


import math
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
last = pow(arr[-1], 1 / (n - 1))
c1 = int(last)
c2 = c1 + 1
(cost1, cost2) = (0, 0)
for i in range(n):
	cost1 += abs(c1 ** i - arr[i])
	cost2 += abs(c2 ** i - arr[i])
print(min(cost1, cost2))


(n, s) = open(0)
print(min((sum((abs(x - c ** i) for (i, x) in enumerate(sorted(map(int, s.split()))))) for c in range(2 + 9 ** 6 // int(n) ** 2))))


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

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

def si():
	return input().rstrip()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')
file = 1

def solve():
	n = ii()
	a = li()
	a.sort()
	if n > 40:
		print(sum(a) - n)
		return
	ans = inf
	for i in range(1, 31625):
		x = 1
		s = 0
		for j in a:
			s += abs(x - j)
			x *= i
			if x > 1e+18:
				print(ans)
				exit(0)
		ans = min(ans, s)
	print(ans)
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


import sys
import math as m

def main():
	pass

def binary(n):
	return bin(n).replace('0b', ' ')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def sinp():
	return sys.stdin.readline().strip()

def iinp():
	return int(input())

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

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

def p(a):
	print(a)
n = iinp()
a = linp()
a.sort()
most = max(a)
cost = 23049203948029384
for i in range(32000):
	cost1 = 0
	ind = 0
	for j in a:
		cost1 = cost1 + abs(j - i ** ind)
		ind += 1
	if cost1 <= cost:
		cost = cost1
	else:
		break
print(cost)


n = int(input())
l = list(map(int, input().split()))
l.sort()
v = l[-1] ** (1 / (len(l) - 1))
v1 = int(v)
v2 = v1 + 1
cost = 0
for i in range(len(l)):
	cost += abs(v1 ** i - l[i])
cost2 = 0
for i in range(len(l)):
	cost2 += abs(v2 ** i - l[i])
print(min(cost, cost2))


from sys import stdin

def inp():
	return stdin.buffer.readline().rstrip().decode('utf8')

def itg():
	return int(stdin.buffer.readline())

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

def discrete_binary_search(func, lo, hi):
	while lo < hi:
		mi = lo + hi >> 1
		if func(mi):
			hi = mi
		else:
			lo = mi + 1
	return lo
n = itg()
arr = list(mpint())
ans = sum(arr) - n
if n > 100:
	print(ans)
	exit()

def fun(x):
	return (x + 1) ** (n - 1) >= mx
arr.sort()
mx = arr[-1]
best_c = discrete_binary_search(fun, 1, 32000)
for c in range(max(1, best_c - 2), best_c + 2):
	power = 1
	count = 0
	for i in range(n):
		count += abs(power - arr[i])
		power *= c
	ans = min(ans, count)
print(ans)


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
cost = 10 ** 9 * n
to = math.log(a[-1], 10) / (n - 1)
to = pow(10, int(to) + 1)
ssum = sum(a)
for curbase in range(1, to):
	tmpcost = 0
	for i in range(n):
		tmpcost += abs(a[i] - pow(curbase, i))
	if tmpcost > cost:
		break
	cost = min(tmpcost, cost)
print(cost)


import math
n = int(input())
A = list(map(int, input().split()))
A.sort()
mx = A[len(A) - 1]
mn = 10000000000000000000000
for k in range(1, int(math.pow(mx, 1 / (n - 1))) + 2):
	sm = 0
	for i in range(n):
		cor = pow(k, i)
		sm += abs(A[i] - cor)
	mn = min(mn, sm)
print(mn)


n = int(input())
a = list(map(int, input().split()))
a.sort()
i = 1
while i ** (n - 1) < a[n - 1]:
	i = i + 1
if abs(i ** (n - 1) - a[n - 1]) > abs((i - 1) ** (n - 1) - a[n - 1]):
	i = i - 1
minimum = 0
minimum1 = 0
minimum2 = 0
for j in range(n):
	minimum += abs(i ** j - a[j])
	minimum1 += abs((i - 1) ** j - a[j])
	minimum2 += abs((i + 1) ** j - a[j])
print(min(minimum, minimum1, minimum2))


from sys import stdin
input = stdin.readline
n = int(input())
(*a,) = map(int, input().split())
a.sort()
ans = 10 ** 20
c = 1
while pow(c, n - 1) <= 10 ** 10:
	x = 0
	for i in range(n):
		x += abs(a[i] - pow(c, i))
	ans = min(x, ans)
	c += 1
print(ans)


n = int(input())
a = list(sorted(map(int, input().split())))
ans = 0
for it in a:
	ans += it - 1
c = 1
while True:
	cnt = 0
	for i in range(n):
		cnt += abs(c ** i - a[i])
		if cnt > ans:
			break
	if cnt > ans:
		break
	ans = cnt
	c += 1
print(ans)


n = int(input())
arr = [int(num) for num in input().split(' ')]
arr.sort()
ans = arr[0] - 1
ans1 = arr[0] - 1
b = arr[-1]
x = int(b ** (1 / (n - 1)))
for i in range(1, n):
	ans = ans + abs(arr[i] - x ** i)
	ans1 = ans1 + abs(arr[i] - (x + 1) ** i)
print(min(ans, ans1))


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

def c(x):
	now = 1
	res = 0
	for i in range(n):
		if now > 10 ** 18:
			return 10 ** 18
		res += abs(now - a[i])
		now *= x
	return res
l = 0
r = 10 ** 9
while r - l > 10:
	llr = (l + l + r) // 3
	lrr = (l + r + r) // 3
	v1 = c(llr)
	v2 = c(lrr)
	if v1 > v2:
		l = llr
	else:
		r = lrr
ans = 10 ** 18
for i in range(l, l + 100):
	ans = min(ans, c(i))
print(ans)


import math
n = int(input())
l = list(map(int, input().split()))
(cost1, cost2) = (0, 0)
l.sort()
cost1 += abs(1 - l[0])
cost2 += abs(1 - l[0])
c1 = math.ceil(l[-1] ** (1.0 / (n - 1)))
c2 = math.floor(l[-1] ** (1.0 / (n - 1)))
for i in range(1, len(l)):
	cost1 += abs(l[i] - c1 ** i)
for i in range(1, len(l)):
	cost2 += abs(l[i] - c2 ** i)
print(min(cost1, cost2))


n = int(input())
a = [int(x) for x in input().split(' ')[:n]]
a.sort()
result = 10000000000000
k = 1
while k ** (n - 1) <= 10 ** 10:
	k += 1
for i in range(1, k):
	temp = 0
	for j in range(0, len(a)):
		d = i ** j
		temp += abs(a[j] - d)
	result = min(result, temp)
print(result)


n = int(input())
a = list(map(int, input().split()))
min_cost = sum(a) - n
a.sort()
max_power = 2
while max_power ** (n - 1) < 2 * 10 ** 9:
	max_power += 1
for i in range(2, max_power + 1):
	cur_cost = 0
	for j in range(n):
		cur_cost += abs(i ** j - a[j])
	min_cost = min(cur_cost, min_cost)
print(min_cost)


import math
n = int(input())
l = list(map(int, input().split()))
l.sort()
m = l[-1]
m = m ** (1 / (n - 1))
c = math.ceil(m)
f = math.floor(m)
c1 = 0
c2 = 0
for i in range(n):
	c1 += abs(c ** i - l[i])
	c2 += abs(f ** i - l[i])
print(min(c1, c2))


def solve():
	p = 1
	n = int(input())
	arr = sorted((int(v) for v in input().split()))
	while p ** (n - 1) < arr[-1]:
		p += 1
	(ans1, ans2) = (0, 0)
	for i in range(n):
		ans1 += abs(p ** i - arr[i])
		ans2 += abs((p - 1) ** i - arr[i])
	print(min(ans1, ans2))
t = 1
for _ in range(t):
	solve()


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

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

def si():
	return input().rstrip()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')
file = 1

def solve():
	n = ii()
	a = li()
	a.sort()

	def f(m):
		x = 1
		s = 0
		for i in a:
			s += abs(x - i)
			x *= m
			if x > 1e+18:
				return inf
		return s
	mx = a[-1]
	r = 1
	while pow(r, n - 1) <= mx:
		r += 1
	l = 1
	while l <= r:
		m1 = l + (r - l) // 3
		m2 = r - (r - l) // 3
		m = (m1 + m2) // 2
		x1 = f(m1)
		x2 = f(m2)
		x = f(m)
		if x1 < x:
			ans = x1
			r = m - 1
		elif x2 < x:
			ans = x2
			l = m + 1
		else:
			ans = x
			l = m1 + 1
			r = m2 - 1
	print(ans)
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


n = int(input())
s = sorted(map(int, input().split()))
mx = 100 * 10 ** 9 + 1
c = 1
mn = float('inf')
while c ** (n - 1) < mx:
	p = 0
	for i in range(n):
		p += abs(s[i] - c ** i)
	c += 1
	mn = min(mn, p)
print(mn)


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = float('inf')
y = math.ceil(a[-1] ** (1 / (n - 1)))
for i in range(1, y + 1):
	ref = i
	cur = 0
	for j in range(n):
		cur += abs(ref ** j - a[j])
	ans = min(ans, cur)
print(ans)


from sys import stdin, stdout
from bisect import bisect_left
from math import log10, log2

def dif(arr, c):
	r = 0
	for i in range(len(arr)):
		r += abs(arr[i] - c ** i)
	return r

def find(arr, N):
	arr.sort()
	K = int(pow(10 ** 19, 1 / N)) + 1
	m = float('inf')
	x = float('inf')
	for i in range(K):
		a = dif(arr, i)
		m = min(m, a)
		if x < a:
			break
		x = a
	return m

def main():
	N = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	print(find(arr, N))
main()


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
mn = int(1e+18)

def check(v):
	global mn
	sm = 0
	p = 1
	for i in range(n):
		sm += abs(a[i] - p)
		p *= v
		if sm > mn:
			return
	mn = min(mn, sm)
check(1)
if n > 50:
	print(mn)
else:
	for i in range(2, 100000):
		check(i)
	print(mn)


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 10 ** 50
if n > 63:
	ans = 0
	for i in a:
		ans += i - 1
else:
	for i in range(1, n):
		val = int(math.floor(a[i] ** (1 / i)))
		cur = 0
		for j in range(n):
			cur += int(abs(a[j] - val ** j))
		ans = min(ans, cur)
		val = int(math.ceil(a[i] ** (1 / i)))
		cur = 0
		for j in range(n):
			cur += int(abs(a[j] - val ** j))
		ans = min(ans, cur)
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
x = 1 / (n - 1)
c = int(a[-1] ** x)
d = c + 1
(m, mini) = (0, 0)
for i in range(n):
	m += abs(c ** i - a[i])
	mini += abs(d ** i - a[i])
print(min(m, mini))


n = int(input())
a = list(map(int, input().split()))
a.sort()
c = sum(a)
i = 0
ans = 10 ** 13
if n >= 47:
	ans = 0
	for j in a:
		ans = ans + abs(j - 1)
	print(ans)
	exit(0)
while True:
	i += 1
	if i ** n - 10 ** 9 - 10 ** 14 <= 0:
		k = 1
		now = 0
		for j in a:
			now = now + abs(j - k)
			k = k * i
		ans = min(ans, now)
	else:
		break
print(ans)


def find_c(len_list, max_num):
	tmp = max_num ** (1 / (len_list - 1))
	floor_tmp = int(tmp)
	ceil_tmp = int(tmp + 1)
	return [i for i in range(floor_tmp, ceil_tmp + 1, 1)]

def solve_problem(power_sequence):
	steps = []
	if len(power_sequence) == 1:
		return power_sequence[0] - 1
	power_sequence = sorted(power_sequence)
	cs = find_c(len(power_sequence), power_sequence[-1])
	for c in cs:
		step = 0
		for (i, num) in enumerate(power_sequence):
			if num - c ** i > 0:
				step = step + (num - c ** i)
			else:
				step = step + (c ** i - num)
		steps.append(step)
	return min(steps)
n = int(input().strip())
if 3 <= n <= 10 ** 5:
	check_conditions = True
	power_sequence_str = input().strip().split(' ')
	power_sequence = [int(i) for i in power_sequence_str]
	for i in power_sequence:
		if i < 1 or i > 10 ** 9:
			check_conditions = False
	if check_conditions:
		result = solve_problem(power_sequence)
	else:
		result = 0
else:
	result = 0
print(result)


import math
n = input()
n = int(n)
a = input()
a = [int(i) for i in a.split()]
a = sorted(a)
ans = 0
ans = sum(a) - n
for c in range(2, int(math.sqrt(sum(a) * 2))):
	if c ** (n - 1) > sum(a) * 2:
		break
	cost = sum([abs(a[i] - c ** i) for i in range(n)])
	ans = min(cost, ans)
print(ans)


import sys
from math import ceil
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = list(map(int, input().split()))
ans = float('inf')
if n < 50:
	a.sort()
	for i in range(1, 10 ** ceil(len(str(a[-1])) / (n - 1))):
		ck = 0
		v = 1
		for j in range(n):
			ck += abs(a[j] - v)
			v = v * i
		ans = min(ck, ans)
else:
	ans = 0
	for i in a:
		ans += abs(i - 1)
print(ans)


import math

def getCost(arr, c):
	power_val = 1
	err = 0
	for e in arr:
		err += abs(power_val - e)
		power_val *= c
	return err

def findCost(arr):
	c_max = int(round(math.pow(10, 9 / (len(arr) - 1))))
	minCost = None
	for option in range(1, c_max + 1):
		this_cost = getCost(arr, option)
		if minCost == None or this_cost < minCost:
			minCost = this_cost
	return minCost

def main():
	_ = int(input())
	a = [int(x) for x in input().strip().split()]
	cost = findCost(sorted(a))
	print(cost)
main()


N = int(input())
A = list(map(int, input().split()))
A.sort()
z = A[-1] ** (1 / (N - 1))
z1 = int(z)
z2 = z1 + 1
c1 = 0
c2 = 0
for i in range(N):
	c1 += abs(A[i] - z1 ** i)
	c2 += abs(A[i] - z2 ** i)
c = min(c1, c2)
print(c)


N = int(input())
arrays = list(map(int, input().split()))
arrays.sort()
floor = int(sum(arrays) ** (1 / (N - 1))) + 1
count = 0
max = 1000000000000000
while floor > 0:
	count = 0
	for i in range(0, N):
		count += abs(arrays[i] - floor ** i)
	if count < max:
		max = count
	floor -= 1
print(max)


N = int(input())
arr = [int(x) for x in input().split()]
arr = sorted(arr)
MAX_NUM = 1e+18
ans = 1e+18
for i in range(1, 32000):
	curr = 0
	num = 1
	for j in range(N):
		curr += abs(arr[j] - num)
		num *= i
		if curr > MAX_NUM:
			break
	if curr > MAX_NUM:
		break
	ans = min(ans, curr)
print(ans)


from sys import stdin

class Input:

	def __init__(self):
		self.next = self.readline()

	def readline(self):
		return stdin.readline().strip()

	def line(self):
		try:
			return self.next
		finally:
			self.next = self.readline()

	def array(self, sep=' ', cast=int):
		return list(map(cast, self.line().split(sep=sep)))

	def known_tests(self):
		(num_of_cases,) = self.array()
		for case in range(num_of_cases):
			yield self

	def unknown_tests(self):
		while self.next:
			yield self

class Problem:

	def __init__(self, input):
		(n,) = input.array()
		a = input.array()
		a.sort()
		ans = sum(a) - n
		for b in range(2, 10 ** 5):
			ok = True
			cost = 0
			for (i, p) in self.pow(b):
				if i == n:
					break
				if cost > ans:
					ok = False
					break
				cost += abs(p - a[i])
			if not ok:
				break
			ans = min(ans, cost)
		print(ans)

	def pow(self, base):
		p = 1
		i = 0
		while True:
			yield (i, p)
			p *= base
			i += 1
for tc in Input().unknown_tests():
	Problem(tc)


n = int(input())
a = list(map(int, input().split()))
a.sort()
approx = a[-1] ** (1 / (n - 1))
const1 = int(approx)
const2 = const1 + 1
(ans1, ans2) = (0, 0)
for i in range(n):
	ans1 += abs(const1 ** i - a[i])
	ans2 += abs(const2 ** i - a[i])
print(min(ans1, ans2))


n = int(input())
l = input()
k = l.split()
arr = [int(k[i]) for i in range(len(k))]
arr.sort()
s = 0
for i in range(len(arr)):
	s = s + arr[i]
ans = s - n
val = 2
while val ** (n - 1) <= 2 * s:
	v = 0
	a = 1
	for i in range(n):
		temp = abs(a - arr[i])
		v = v + temp
		a = a * val
	ans = min(ans, v)
	val += 1
print(ans)


n = int(input())
a = sorted(list(map(int, input().split())))
sm = a[-1] ** (1 / (n - 1))
fl = int(sm)
cl = fl + 1
ansfl = 0
anscl = 0
for i in range(n):
	ansfl += abs(fl ** i - a[i])
	anscl += abs(cl ** i - a[i])
print(min(ansfl, anscl))


from collections import Counter
from math import log, e, inf
t = 1
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split(' ')))
	a.sort()
	res = sum(a) - n
	for i in range(2, 10 ** 9 + 1):
		(s, p) = (0, 1)
		for j in a:
			s += abs(j - p)
			if s > res:
				break
			p *= i
		if s > res:
			break
		res = s
	print(res)


import math
n = int(input().rstrip())
in_arr = [int(x) for x in input().rstrip().split()]

def get_error(arr, b):
	total_err = 0
	for i in range(len(arr)):
		a = arr[i]
		pow_res = math.pow(b, i)
		if pow_res > 10000000000.0:
			return float('inf')
		total_err += abs(a - int(math.pow(b, i)))
	return total_err

def solve(n, arr):
	largest_elem = arr[-1]
	sqrt_lelem = math.pow(largest_elem, 1.0 / (n - 1))
	lb = int(math.floor(sqrt_lelem))
	ub = int(math.ceil(sqrt_lelem))
	if ub == lb:
		lb -= 1
	if lb == 0:
		lb += 1
		ub += 1
	lb_err = get_error(arr, lb)
	ub_err = get_error(arr, ub)
	if ub_err == float('inf'):
		return lb_err
	if lb_err < ub_err:
		return lb_err
	return ub_err
in_arr.sort()
ans = solve(n, in_arr)
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
sum = sum(a)
cost = sum - n
c = 2
while c ** (n - 1) <= 2 * sum:
	t = [-1 * c ** i for i in range(n)]
	cost1 = 0
	for i in range(n):
		cost1 += abs(t[i] + a[i])
	cost = min(cost, cost1)
	c += 1
print(cost)


import math
num = int(input())
lst = [int(x) for x in input().split()]
ans = 0
for i in lst:
	ans += i - 1
lst.sort()
for c in range(2, 200000):
	jj = math.log(10000000000) // math.log(c)
	if num - 1 <= jj:
		a2 = 0
		for jj in range(0, num):
			a2 += abs(lst[jj] - pow(c, jj))
		ans = min(ans, a2)
if num == 1:
	ans = 0
print(ans)


import sys
import math
n = int(sys.stdin.readline().strip())
vals = sorted(map(int, sys.stdin.readline().strip().split()))
limit = math.ceil((10 ** 14) ** (1 / n))
res = float('inf')
for i in range(1, limit):
	run = 0
	cur = 1
	for n in vals:
		run += abs(n - cur)
		cur *= i
	res = min(res, run)
print(res)


import sys
input = sys.stdin.readline

def inInt():
	return int(input())

def inStr():
	return input().strip('\n')

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

def inSList():
	return input().split()

def bsearch(nums, target):
	N = len(nums or [])
	l = 0
	r = N - 1
	while l <= r:
		mid = (l + r) // 2
		if nums[mid] < target:
			l = mid + 1
		elif nums[mid] > target:
			r = mid - 1
		else:
			return (None, mid, None)
	return (r if r >= 0 else None, None, l if l <= N - 1 else None)

def yesOrNo(val):
	print('YES' if val else 'NO')

def solve():
	n = inInt()
	a = inIList()
	a.sort()
	m = None
	for c in range(1, 10 ** 9 + 1):
		cost = 0
		for i in range(len(a)):
			cost += abs(c ** i - a[i])
		m = min(m, cost) if m != None else cost
		if cost > m:
			break
	return m
print(solve())


import sys
import math
from collections import Counter, defaultdict
LI = lambda : list(map(int, input().split()))
MAP = lambda : map(int, input().split())
IN = lambda : int(input())
S = lambda : input()

def case():
	n = IN()
	a = LI()
	a.sort()
	x = pow(a[-1], 1 / (n - 1))
	p = int(x)
	q = p + 1
	ans1 = ans2 = 0
	for i in range(n):
		ans1 += abs(pow(p, i) - a[i])
		ans2 += abs(pow(q, i) - a[i])
	print(min(ans1, ans2))
for _ in range(1):
	case()


N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
prev = float('inf')
c = 1
while True:
	tmp = sum((abs(v - pow(c, i)) for (i, v) in enumerate(A)))
	if tmp < prev:
		prev = tmp
	else:
		print(prev)
		exit()
	c += 1


n = int(input())
t = list(map(int, input().split()))
t.sort()
maa = 10 ** 18
ans = maa
c = 1
h = 0
while True:
	temp = 0
	for i in range(n):
		temp += abs(c ** i - t[i])
		if temp >= ans:
			print(ans)
			h += 1
			break
	if h > 0:
		break
	ans = min(ans, temp)
	c += 1


import sys
import collections as cc
import random as rd
import math as mt
input = sys.stdin.readline
I = lambda : cc.deque(map(int, input().split()))
(n,) = I()
l = sorted(I())
if n == 2:
	print(l[0] - 1)
	sys.exit()
ans = sum(l) - n
for i in range(2, 40000):
	now = 0
	mul = 1
	for j in range(n):
		now += abs(mul - l[j])
		if now > ans:
			break
		mul *= i
	ans = min(now, ans)
print(ans)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
maximum = 0
for i in arr:
	maximum += i - 1
prev = maximum
for c in range(2, 100000):
	ans = 0
	for i in range(n):
		ans += abs(arr[i] - c ** i)
	if ans > maximum:
		break
	else:
		prev = min(ans, prev)
print(prev)


import math as m

def kthRoot(n, k):
	return m.ceil(pow(k, 1.0 / k * (m.log(n) / m.log(k))))
n = int(input())
num = list(map(int, input().split()))
num.sort()
ans = pow(n - 1, 1.0 / (n - 1) * (m.log(num[n - 1]) / m.log(n - 1)))
ansc = m.ceil(ans)
ansf = m.floor(ans)
(resc, resf) = (0, 0)
for i in range(len(num)):
	resc += abs(num[i] - ansc ** i)
	resf += abs(num[i] - ansf ** i)
if resc > resf:
	print(resf)
else:
	print(resc)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
res = sum(a) - n
a.sort()
for x in range(2, 100000):
	t = 0
	for i in range(n):
		t += abs(pow(x, i) - a[i])
		if t > res:
			break
	else:
		res = min(res, t)
print(res)


import sys
input = sys.stdin.readline
from collections import defaultdict
from math import sqrt
n = int(input())
lis = list(map(int, input().split()))
lis.sort()
x = int(sqrt(lis[-1])) + 10
c = sum(lis) - n
if n > 50:
	print(c)
	exit()
for i in range(1, x):
	d = 0
	y = 1
	for j in range(n):
		d += abs(y - lis[j])
		y *= i
	c = min(c, d)
print(c)


n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
if n == 1:
	print(0)
else:
	ans = 0
	for i in arr:
		ans = ans + abs(i - 1)
	for i in range(2, 100000):
		cur = 0
		(idx, j) = (0, 1)
		while idx < n:
			cur += abs(arr[idx] - j)
			idx += 1
			j = j * i
			if j > 1e+20:
				cur = 1e+20
				break
		ans = min(ans, cur)
	print(ans)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
sumi = sum(arr)
req = [abs(n - sumi)]
for i in range(2, 100000):
	s = 0
	temp = True
	for j in range(n):
		s += abs(arr[j] - i ** j)
		if s > req[-1]:
			temp = False
			break
	if temp:
		req.append(s)
	else:
		break
print(str(req[-1]))


n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
ans = 10 ** 20
for num in range(1, 10 ** 6):
	if num ** (n - 1) > 10 ** 15:
		break
	temp = 0
	c = 1
	for item in arr:
		if item > c:
			temp += item - c
		else:
			temp += c - item
		c *= num
	ans = min(ans, temp)
print(ans)


import sys
import math
readline = lambda : sys.stdin.readline().strip()
N = int(readline())
A = [int(x) for x in readline().split()]
A.sort()
S = sum(A)

def find_cost(c):
	cost = 0
	for i in range(N):
		cost += abs(A[i] - pow(c, i))
	return cost
(lb, ub) = (0, 10 ** 6)
while ub - lb > 1:
	m = (lb + ub) // 2
	check1 = (S * (m - 1) + 1) ** (1 / N) < m
	check2 = A[-1] ** (1 / (N - 1)) < m
	if check2 or check2:
		ub = m
	else:
		lb = m
cost1 = find_cost(lb)
cost2 = find_cost(ub)
print(min(cost1, cost2))


import sys
input = sys.stdin.readline

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

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

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

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0, hi=None):
	if hi == None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

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

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

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

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math
from bisect import bisect_left

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	s = INF
	x = int(a[-1] ** (1 / (n - 1))) + 1
	if n > 32:
		print(abs(n - sum(a)))
		return
	for c in range(1, x + 1):
		summ = 0
		for i in range(n):
			summ += abs(c ** i - a[i])
		s = min(s, summ)
	print(s)
for _ in range(1):
	solve()


N = int(input())
A = list(map(int, input().split()))
A.sort()
inf = 10 ** 19
result = inf
c = 1
while True:
	t = 0
	r = 1
	for a in A:
		t += abs(r - a)
		r *= c
		if t > inf:
			break
	if t > result:
		break
	result = t
	c += 1
print(result)


n = int(input())
sequence = list(map(int, input().split()))
c = 1
sequence.sort()
done = False
min = sum(sequence)
while not done:
	sum = 0
	exp = 1
	for i in range(n):
		sum += abs(sequence[i] - exp)
		exp *= c
		if sum > min:
			break
	if sum < min:
		min = sum
	else:
		done = True
	c += 1
print(min)


n = int(input())
e_arr = [int(el) for el in input().split(' ')]
e_arr.sort()

def find_a(e, i):
	for j in range(1, e + 1):
		if pow(j, i) >= e:
			break
	return j

def get_max_a(e_arr):
	a_new = 0
	for i in range(2, len(e_arr)):
		a = find_a(e_arr[i], i)
		if a >= a_new:
			a_new = a
	return a

def get_cost(e_arr, a):
	cost = 0
	for i in range(0, len(e_arr)):
		cost += abs(e_arr[i] - pow(a, i))
	return cost

def solve(e_arr):
	a = get_max_a(e_arr)
	cost = get_cost(e_arr, 1)
	for i in range(2, a + 1):
		cost_new = get_cost(e_arr, i)
		if cost >= cost_new:
			cost = cost_new
	return cost
print(solve(e_arr))


import sys

def input():
	return sys.stdin.readline().rstrip()

def input_split():
	return [int(i) for i in input().split()]

def cost(c, arr):
	if c == 0:
		return sum(arr)
	else:
		return sum([int(abs(c ** i - arr[i])) for i in range(len(arr))])
n = int(input())
arr = input_split()
if n > 35 or n == 1:
	ans = sum(arr) - n
else:
	arr.sort()
	if n == 2:
		ans = min(arr) - 1
	else:
		ans = 10 ** 12
		for c in range(1, 4 * 10 ** 4):
			pot = cost(c, arr)
			ans = min(ans, pot)
print(ans)


def solve():
	limit = 10 ** 10
	ans = 10 ** 15
	j = 1
	while True:
		val = 0
		power = 1
		for i in range(N):
			if power > limit:
				val = -1
				break
			val += abs(power - A[i])
			power *= j
		if val == -1:
			break
		ans = min(ans, val)
		j += 1
	return ans
N = int(input())
A = [int(s) for s in input().split()]
A.sort()
print(solve())


def cost(a, b):
	ans = 0
	for (i, j) in enumerate(a):
		ans += abs(j - pow(b, i))
	return ans
while True:
	try:
		n = int(input())
		a = list(map(int, input().split()))
		a.sort()
		c1 = int(pow(a[-1], 1 / (n - 1)))
		print(min(cost(a, c1), cost(a, c1 + 1)))
	except Exception as e:
		break


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

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

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions
from collections import deque, defaultdict, OrderedDict
from fractions import Fraction
from decimal import Decimal

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(1):
		n = ri()
		a = ria()
		a = sorted(a)
		mc = 9999999999999999999999999
		for i in range(1, 31624):
			f = 1
			t = 0
			c = 0
			while t < n:
				k = abs(a[t] - f)
				c += k
				f = f * i
				if k > 100000000000000:
					break
				t += 1
			mc = min(c, mc)
		print(mc)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
m = 10 ** 18
t = 1
for _ in range(t):
	n = ip()
	a = list(inp())
	a.sort()
	final = float('inf')
	dic = {}
	if n <= 2:
		ans = a[0] - 1
	else:
		ans = sum(a) - n
		for x in range(1, 10 ** 9):
			cur = 1
			cost = 0
			for i in range(n):
				cost += abs(a[i] - cur)
				cur *= x
				if cur > m:
					break
			if cur > m:
				break
			if cur / x > ans + a[n - 1]:
				break
			ans = min(ans, cost)
	out(ans)


import sys
import bisect
import math as mt
input = sys.stdin.readline
t = 1
mod = 10 ** 9 + 7
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	ans = 0
	for i in range(n):
		ans += abs(1 - l[i])
	for i in range(1, 100001):
		mul = 1
		ch = 1
		for j in range(n - 1):
			mul *= i
			if mul > 10 ** 14:
				ch = 0
				break
		if ch == 1:
			(mul, ans2) = (1, 0)
			for j in range(n):
				ans2 += abs(mul - l[j])
				mul *= i
			ans = min(ans, ans2)
	print(ans)


import os
from io import BytesIO, IOBase
import sys

def main():
	n = int(input())
	a = list(map(int, input().split()))
	mi = sum(a) - n
	j = 2
	a.sort()
	infinite = 200000000000000
	while 1:
		(su, k) = (0, 1)
		for i in range(n):
			su += abs(a[i] - k)
			k = k * j
			if k > infinite:
				break
		if k < infinite:
			mi = min(mi, su)
		else:
			break
		j += 1
	print(mi)
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()


from __future__ import division, print_function
import os, sys
import math
import collections
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

class my_dictionary(dict):

	def __init__(self):
		self = dict()

	def add(self, key, value):
		self[key] = value

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

def si():
	return input()

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

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

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

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r))

def binary_search(arr, low, high, x):
	if high >= low:
		mid = (high + low) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binary_search(arr, low, mid - 1, x)
		else:
			return binary_search(arr, mid + 1, high, x)
	else:
		return -1

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def padded_bin_with_complement(x):
	if x < 0:
		return bin(2 ** 16 - abs(x))[2:].zfill(16)
	else:
		return bin(x)[2:].zfill(16)

def binaryToDecimal(binary):
	binary1 = binary
	(decimal, i, n) = (0, 0, 0)
	while binary != 0:
		dec = binary % 10
		decimal = decimal + dec * pow(2, i)
		binary = binary // 10
		i += 1
	print(decimal)

def CountFrequency(my_list):
	freq = {}
	for item in my_list:
		if item in freq:
			freq[item] += 1
		else:
			freq[item] = 1
	return freq

def pos(a):
	b = [0] * len(a)
	c = sorted(a)
	for i in range(len(a)):
		for j in range(len(a)):
			if c[j] == a[i]:
				b[i] = j
				break
	return b

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def commonn(a, b, n):
	c = []
	for i in range(n):
		if a[i] == b[i]:
			c.append('-1')
		else:
			c.append(b[i])
	return c

def primeFactors(n):
	j = []
	while n % 2 == 0:
		j.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			j.append(int(n))
			n = n / i
	if n > 2:
		j.append(int(n))
	return j

def sumdigit(n):
	n = str(n)
	k = 0
	for i in range(len(n)):
		k += int(n[i])
	return k

def main():
	n = ii()
	a = li()
	b = [0] * n
	a.sort()
	res = 0
	ress = 0
	kl = n - 1
	j = math.floor(a[n - 1] ** (1 / kl))
	for i in range(n):
		res += abs(a[i] - j ** i)
	for i in range(n):
		ress += abs(a[i] - (j + 1) ** i)
	print(min(res, ress))
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
a = []
ans = 0
ansp = 0
for num in input().split():
	a.append(int(num))
a = sorted(a)
last_root = a[-1] ** (1 / (len(a) - 1))
last_root = int(last_root)
for i in range(len(a)):
	ans += abs(a[i] - last_root ** i)
	ansp += abs(a[i] - (last_root + 1) ** i)
if ansp < ans:
	ans = ansp
print(ans)


from sys import stdin, stdout
n = int(input())
arr = sorted(list(map(int, stdin.readline().strip().split())))
big = 10 ** 10
c = 1
ans = 10 ** 15
flag = 0
while 1:
	val = 0
	for i in range(n):
		p = pow(c, i)
		if p > big:
			flag = 1
			break
		else:
			val += abs(p - arr[i])
	if flag == 1:
		break
	ans = min(ans, val)
	c += 1
stdout.write(str(ans))


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
INF = 10 ** 18
if n <= 2:
	print(a[0] - 1)
else:
	ans = INF
	for x in range(1, 10 ** 9):
		pow = 1
		cost = 0
		for i in range(n):
			cost += abs(a[i] - pow)
			pow *= x
			if pow > INF:
				break
		if pow > INF:
			break
		ans = min(ans, cost)
	print(ans)


from math import ceil
from sys import stdin

def main():
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split(' ')))
	a.sort()
	result = how_much_costs_transformation_to_powers_sequence(a)
	print(result)

def how_much_costs_transformation_to_powers_sequence(sorted_seq):
	seq_length = len(sorted_seq)
	if seq_length == 0:
		return 0
	elif seq_length == 1:
		return abs(sorted_seq[0] - 1)
	elif seq_length == 2:
		return abs(sorted_seq[0] - 1)
	elif seq_length == 3:
		result = abs(sorted_seq[0] - 1)
		min_yz_cost = float('inf')
		(x, y, z) = sorted_seq
		base = 1
		while (base - 1) ** 2 <= z:
			yz_cost = abs(base - y) + abs(base ** 2 - z)
			min_yz_cost = min(min_yz_cost, yz_cost)
			base += 1
		result += min_yz_cost
		return result
	assert seq_length >= 4
	max_base = _ceil_root(sorted_seq[-1], seq_length - 1)
	min_cost = float('inf')
	for base in range(max_base + 1):
		cost = _how_much_cost_powers_seq_with_base(sorted_seq, base)
		if cost < min_cost:
			min_cost = cost
	return min_cost

def _ceil_root(x, n):
	assert n >= 1
	assert x >= 0
	return ceil(x ** (1 / n))

def _how_much_cost_powers_seq_with_base(sorted_seq, base):
	result = 0
	for i in range(len(sorted_seq)):
		result += abs(base ** i - sorted_seq[i])
	return result
main()


from math import ceil, log, floor
n = int(input())
c = sorted(list(map(int, input().split())))
l1 = float(c[-1])
l2 = float(n - 1)
l3 = log(l1)
l3 = log(l1) / l2
m = float(pow(2.718281828, l3))
r1 = floor(m)
r2 = ceil(m)
tot = 0
if r1 != r2:
	for i in range(len(c)):
		tot += abs(pow(r1, i) - c[i])
	tot1 = 0
	for i in range(len(c)):
		tot1 += abs(pow(r2, i) - c[i])
	print(min(tot, tot1))
else:
	for i in range(len(c)):
		tot += abs(pow(r1, c[i]) - c[i])
	print(tot)


n = int(input())
l = list(map(int, input().split()))
l.sort()
sum = l[0] - 1
l[0] = 1
k = [1 for j in range(n)]
for i in range(1, n):
	k[i] = int(l[i] ** (1 / i))
mini = -1
s = set()
for i in range(n):
	s.add(k[i])
	s.add(k[i] + 1)
for c in s:
	temp = 0
	for i in range(n):
		temp += abs(l[i] - c ** i)
	if mini == -1:
		mini = temp
	if temp < mini:
		mini = temp
print(sum + mini)


import math
n = int(input())
arr = list(map(int, input().split()))
if len(arr) == 1:
	print(abs(arr[0] - 1))
else:
	arr.sort()
	val = pow(arr[-1], 1 / (n - 1))
	num1 = int(math.ceil(val))
	num2 = int(math.floor(val))
	ans1 = 0
	for i in range(0, n):
		ans1 += abs(arr[i] - pow(num1, i))
	ans2 = 0
	for i in range(n):
		ans2 += abs(arr[i] - pow(num2, i))
	if ans1 < ans2:
		print(ans1)
	else:
		print(ans2)


import sys
input = lambda : sys.stdin.readline().rstrip()
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
total = sum(arr)
ret = total - n
c = 2
while c ** (n - 1) <= 2 * total:
	tmp = [-1 * c ** i for i in range(n)]
	cand = 0
	for i in range(n):
		cand += abs(tmp[i] + arr[i])
	ret = min(ret, cand)
	c += 1
print(ret)


import math
n = int(input())
arr = [int(x) for x in input().split(' ')]
arr.sort()
x = pow(arr[n - 1], float(1 / float(n - 1)))
x_1 = math.floor(x)
x_2 = math.ceil(x)
rem1 = 0
rem2 = 0
for i in range(n):
	rem1 = rem1 + abs(int(pow(x_1, i) - arr[i]))
for i in range(n):
	rem2 = rem2 + abs(int(pow(x_2, i) - arr[i]))
print(int(min(rem1, rem2)))


count = int(input())
numbers = list(map(int, input().split()))
numbers.sort()
c = int(sum(numbers) ** (1 / (count - 1))) + 1
best = 1000000000000000
counter = 0
while c > 0:
	counter = 0
	for i in range(0, count):
		counter += abs(numbers[i] - c ** i)
	if counter < best:
		best = counter
	c -= 1
print(best)


from collections import Counter
from math import log
n = int(input())
a = sorted([int(x) for x in input().split()])
result = sum((abs(x - 1) for x in a))
if log(result + a[-1]) < (n - 1) * log(2):
	print(result)
else:
	c = 2
	while True:
		cost = 0
		S = 1
		for i in range(n):
			cost += abs(a[i] - S)
			S *= c
		if result is None or cost < result:
			result = cost
		c += 1
		if S // c > a[-1]:
			break
	print(result)


def check(m):
	global a, n
	ans = 0
	cm = 1
	for i in range(n):
		ans += abs(a[i] - cm)
		cm *= m
	return ans
n = int(input())
a = list(map(int, input().split()))
a.sort()
if n > 200:
	print(check(1))
	exit(0)
l = 1
r = 10000000
while r - l != 1:
	s = (l + r) // 2
	if check(s) - check(s + 1) > 0:
		l = s
	else:
		r = s
print(min(check(r), check(l)))


n = int(input())
l = list(map(int, input().split()))
l.sort()
s = [0 for i in range(100001)]
for j in range(100001):
	su = 0
	for k in range(n):
		if j ** k > 10 ** 18:
			break
		su += abs(l[k] - j ** k)
	s[j] = su
print(min(s))


n = int(input())
p = list(map(int, input().split()))
p.sort()
ans = n * 10 ** 9
c = 1
while True:
	sol = 0
	for i in range(n):
		sol += abs(p[i] - c ** i)
	if sol < ans:
		ans = sol
	else:
		break
	c += 1
print(ans)


def order(l):
	length = len(l)
	if length == 2:
		if l[0] > l[1]:
			return [l[1], l[0]]
		else:
			return l
	elif length == 1:
		return l
	elif length % 2 == 1:
		mid = (length + 1) // 2
		return merge(order(l[0:mid]), order(l[mid:length + 1]))
	else:
		mid = length // 2
		return merge(order(l[0:mid]), order(l[mid:length + 1]))

def merge(l1, l2):
	l1c = 0
	l2c = 0
	end1 = len(l1)
	end2 = len(l2)
	ans = []
	while True:
		if l1c == end1:
			return ans + l2[l2c:end2 + 1]
		elif l2c == end2:
			return ans + l1[l1c:end1 + 1]
		if l1[l1c] < l2[l2c]:
			ans.append(l1[l1c])
			l1c += 1
		else:
			ans.append(l2[l2c])
			l2c += 1
num = int(input())
num_l = list(map(int, input().split()))
num_l = order(num_l)
m = num_l[num - 1]
count = 0
c_list = []
while True:
	if m == count ** (num - 1):
		c_list.append(count)
		break
	elif m > count ** (num - 1):
		count += 1
	else:
		c_list.append(count)
		c_list.append(count - 1)
		break
min_cost = []
for c in c_list:
	cost = 0
	for x in range(num):
		cost += abs(c ** x - num_l[x])
	min_cost.append(cost)
print(min(min_cost))


n = int(input())
arr = list(map(int, input().split()))
arr = sorted(arr)
a = int(arr[-1] ** (1 / (n - 1))) + 1
cost = -1
ans = -1
for j in range(1, a + 1):
	cost1 = 0
	for i in range(n):
		cost1 += abs(j ** i - arr[i])
	if cost == -1:
		cost = cost1
		ans = 1
	elif cost1 < cost:
		ans = j
		cost = cost1
print(cost)


n = int(input())
a = sorted(list(map(int, input().split())))
cost = 0
cost += a[0] - 1
a[0] = 1
max_range = int(a[-1] ** (1 / (n - 1))) * 2
min_val = sum(a)
for i in range(1, max_range + 1):
	cur_cost = 0
	for j in range(1, n):
		cur_cost += abs(a[j] - i ** j)
	min_val = min(min_val, cur_cost)
cost += min_val
print(cost)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
k = pow(a[-1], 1 / (n - 1))
x = int(k)
y = int(k) + 1
(s1, s2) = (0, 0)
for i in range(n):
	j = pow(x, i)
	m = pow(y, i)
	if j > a[i]:
		s1 += j - a[i]
	elif j <= a[i]:
		s1 += a[i] - j
	if m > a[i]:
		s2 += m - a[i]
	elif m <= a[i]:
		s2 += a[i] - m
print(min(s1, s2))


from sys import stdin
from math import ceil
a = int(stdin.readline())
b = sorted(map(int, stdin.readline().split()))
if a > 33:
	s = 0
	for i in range(a):
		if b[i] != 1:
			s += b[i] - 1
	exit(print(s))
r = ceil(1000000000 ** (1 / (a - 1)))
k = [0] * (r + 1)
k[0] = 10000000000000
for i in range(a):
	for j in range(1, r + 1):
		k[j] += abs(j ** i - b[i])
print(min(k))


n = int(input())
a = sorted([*map(int, input().split())])
i = 1
while i ** (n - 1) < a[-1]:
	i += 1
(s, ss) = (0, 0)
for (j, k) in enumerate(a):
	s += abs(k - i ** j)
	ss += abs(k - (i - 1) ** j)
print(min(s, ss))


n = int(input())
a = map(int, input().split())
a = sorted(a)
k = 1
while k ** (n - 1) < a[-1]:
	k += 1
b = 0
c = 0
for (j, x) in enumerate(a):
	b += abs(x - k ** j)
	c += abs(x - (k - 1) ** j)
print(min(c, b))


import math
n = int(input())
val = [int(i) for i in input().split()[:n]]
val.sort()
temp = val[n - 1] ** (1 / (n - 1))
a = math.ceil(temp)
b = math.floor(temp)
s1 = 0
s2 = 0
for i in range(0, n):
	s1 = s1 + abs(val[i] - a ** i)
	s2 = s2 + abs(val[i] - b ** i)
print(min(s1, s2))


import sys
input = sys.stdin.readline
n = int(input())
(cost, ans) = (0, 1000000000000000000000000)
a = [int(x) for x in input().split()]
a.sort()
(l, r) = (-1, -1)
if n > 32:
	(l, r) = (1, 1)
elif 32 >= n > 20:
	(l, r) = (1, 2)
elif 20 >= n >= 15:
	(l, r) = (1, 10)
elif 15 > n >= 10:
	(l, r) = (1, 14)
elif 10 > n >= 7:
	(l, r) = (1, 25)
elif 7 > n >= 5:
	(l, r) = (1, 1000)
elif n == 4:
	(l, r) = (1, 1200)
elif n == 3:
	(l, r) = (1, 100000)
elif n == 2:
	(l, r) = (1, 10000000)
elif n == 1:
	(l, r) = (1, 10000000)
for q in range(l, r + 1):
	cost = 0
	for i in range(n):
		cost += abs(a[i] - q ** i)
	ans = min(ans, cost)
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
(cans, oans) = (0, 1e+100)
for c in range(1, 100000):
	if c ** n > 10 ** 15:
		break
	cans = 0
	for i in range(n):
		cans += abs(a[i] - c ** i)
	oans = min(cans, oans)
print(oans)


n = int(input())
l = list(map(int, input().split()))
l.sort()
if n >= 40:
	ans = 0
	for j in l:
		ans += j - 1
	print(int(ans))
else:
	ans = 1e+18
	lim = int(1000000.0)
	for i in range(1, lim + 1):
		diff = 0
		num = 1
		f = 1
		for j in range(len(l)):
			diff += abs(l[j] - num)
			if num > 10000000000.0:
				f = 0
				break
			num *= i
		if f == 0:
			break
		ans = min(ans, diff)
	print(int(ans))


n = int(input())
a = list(map(int, input().split()))
a.sort()
p = int(pow(a[n - 1], 1.0 / (n - 1)))
ans = 100000000000000000

def qmi(a, b):
	res = 1
	while b != 0:
		if b % 2:
			res = res * a
		a = a * a
		b //= 2
	return res
if n > 32:
	ans = 0
	for i in range(n):
		ans += a[i] - 1
	print(ans)
else:
	for i in range(max(1, p - 10), p + 10):
		res = 0
		for j in range(n):
			res += abs(a[j] - qmi(i, j))
		ans = min(ans, res)
	print(ans)


import math
import time
t = time.time()

def f(x, a):
	sum = 0
	for i in range(len(a)):
		sum += math.fabs(x ** i - a[i])
	return int(sum)
n = int(input())
a = [int(i) for i in input().split()]
a = sorted(a)
x = 1
ans = 10 ** 15
while x ** (n - 1) <= a[-1] + f(1, a):
	buf = f(x, a)
	if buf < ans:
		ans = buf
	x += 1
print(ans)


import sys
import math
from collections import defaultdict, Counter
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
if n > 32:
	for j in a:
		ans += j - 1
elif n == 2:
	ans += a[0] - 1
else:
	ans = 10 ** 18
	prev = 10 ** 18
	for i in range(1, 100000):
		cur = 0
		for k in range(n):
			cur += abs(a[k] - pow(i, k))
		if cur > prev:
			break
		prev = cur
		ans = min(ans, cur)
print(ans)


import sys
import math
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
a.sort()
p = a[-1] ** (1 / (n - 1))
p1 = math.ceil(p)
p2 = math.floor(p)
res1 = 0
res2 = 0
for i in range(n):
	res1 += abs(a[i] - pow(p1, i))
	res2 += abs(a[i] - pow(p2, i))
print(min(res1, res2))


res = []
for i in range(1, 31624):
	temp = [1]
	while temp[-1] * i <= 10 ** 10 and len(temp) <= 10 ** 5:
		temp.append(temp[-1] * i)
	res.append(temp)
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
cost = 10 ** 40
for i in range(len(res)):
	sub = 0
	if len(res[i]) < len(arr):
		break
	for j in range(len(arr)):
		sub += abs(res[i][j] - arr[j])
	if sub < cost:
		cost = sub
print(cost)


import sys
input = sys.stdin.readline
n = int(input())
nList = list(map(int, input().split()))
nList.sort()
cost1 = nList[0] - 1
cost2 = nList[0] - 1
l = len(nList) - 1
maxc = int(nList[-1] ** (1 / l))
max1 = maxc + 1
cost1 += abs(nList[1] - maxc)
cost1 += abs(nList[2] - maxc ** 2)
for i in range(3, n):
	cost1 += abs(nList[i] - maxc ** i)
cost2 += abs(nList[1] - max1)
cost2 += abs(nList[2] - max1 ** 2)
for i in range(3, n):
	cost2 += abs(nList[i] - max1 ** i)
print(min(cost1, cost2))


import math
t = int(input())
list1 = list(map(int, input().split()))
list1.sort()
l = list1[-1]
s = 0
j = 1
mini = -1
while 1:
	s = 0
	for i in range(t):
		s += abs(list1[i] - pow(j, i))
	if mini == -1:
		mini = s
	elif mini < s:
		break
	else:
		mini = s
	j += 1
print(mini)


n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
ans1 = 0
ans2 = 0
ans3 = 0
po = int(arr[n - 1] ** (1 / (n - 1)))
for i in range(n):
	ans1 += abs(arr[i] - pow(po, i))
	ans2 += abs(arr[i] - pow(po + 1, i))
print(min(ans1, ans2))


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
initial_base = int(arr[-1] ** (1 / (n - 1)))

def compute_cost(arr, base, prev_cost):
	cur = 1
	cost = 0
	for a in arr:
		cost += abs(a - cur)
		if prev_cost != -1 and cost > prev_cost:
			return prev_cost
		cur *= base
	return cost
cur_min_cost = compute_cost(arr, initial_base, -1)
base = initial_base + 1
while True:
	new_cost = compute_cost(arr, base, cur_min_cost)
	if new_cost >= cur_min_cost:
		break
	cur_min_cost = new_cost
	base += 1
print(cur_min_cost)


n = int(input())
s = input()
s = s.split()
a = []
for e in s:
	a.append(int(e))
a.sort()
ans = 0
for e in a:
	ans += e - 1
for i in range(2, 100000):
	temp = 0
	flag = 1
	for j in range(n):
		if j == 0:
			temp += a[j] - 1
			continue
		z = i ** j
		if z > 100000000000000:
			flag = 0
			break
		temp += abs(a[j] - z)
	if flag == 1 and temp < ans:
		ans = temp
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
c = 100000 // n
c = int(c)
ans = 10 ** 18
c = min(10 ** 5, c)
for r in range(1, c + 1, 1):
	tempans = 0
	for i in range(n):
		tempans += abs(a[i] - pow(r, i))
	ans = min(ans, tempans)
print(ans)


n = int(input())
A = list(map(int, input().split()))
A.sort()
mx = 2 ** 63
ans = mx
cval = -1
for c in range(1, 100000):
	P = [1]
	while P[-1] < mx and len(P) < n:
		P.append(P[-1] * c)
	if len(P) != n:
		break
	cost = 0
	for i in range(n):
		cost += abs(A[i] - P[i])
	if cost < ans:
		ans = cost
		cval = c
	else:
		break
print(ans)


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
cost = 0
b = max(a)
c = b ** (1 / (n - 1))
e = math.ceil(c)
cost = 0
for i in range(len(a)):
	cost += abs(a[i] - e ** i)
cost1 = 0
d = math.floor(c)
for i in range(len(a)):
	cost1 += abs(a[i] - d ** i)
print(min(cost, cost1))


from sys import stdin
from math import ceil, gcd
n = int(stdin.readline())
arr = sorted(list(map(int, stdin.readline().split())))
cost = 0
for ele in arr:
	cost += ele - 1
if n > 64:
	print(cost)
else:
	l = 2
	r = ceil(arr[-1] ** (1 / float(n - 1)))
	for j in range(l, r + 1):
		c = 0
		for i in range(n):
			c += abs(j ** i - arr[i])
		if c < cost:
			cost = c
	print(cost)


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math

def get_int():
	return int(stdin.readline().strip())

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

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

def solve():
	n = get_int()
	ls = get_list()
	ls.sort()
	mini = float('inf')
	for c in range(1, 10 ** 5 + 1):
		temp = 0
		for i in range(n):
			temp += abs(c ** i - ls[i])
			if c ** i > 10 ** 15:
				return mini
		mini = min(mini, temp)
	return mini

def main():
	print(solve())
TestCases = False
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


(n, a) = (int(input()), [int(x) for x in input().split()])
a.sort()
(ans, temp, c) = (float('inf'), 0, 1)
while c:
	(temp, mj) = (a[0] - 1, c)
	for i in range(1, n):
		temp += abs(a[i] - mj)
		if temp > ans:
			break
		mj *= c
	if temp > ans:
		break
	ans = temp
	c += 1
print(ans)


n = int(input())
a = sorted([int(r) for r in input().split()])
ans = 10 ** 14 + 9
lim = 10 ** 11
c = 1
while c ** (n - 1) <= lim:
	sum = 0
	for i in range(0, n):
		sum += abs(c ** i - a[i])
	if sum <= ans:
		ans = sum
	c = c + 1
print(ans)


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
codechef = 0
codeforces = 0
p = int(a[-1] ** (1 / (n - 1)))
q = p + 1
for i in range(n):
	codechef += abs(a[i] - p ** i)
for i in range(n):
	codeforces += abs(a[i] - q ** i)
print(min(codeforces, codechef))


import sys
input = sys.stdin.readline

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

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
n = inp()
l = list(invr())
l.sort()
min_cost = None
i = 0
while True:
	i += 1
	cost = 0
	for (j, num) in enumerate(l):
		power = i ** j
		cost += abs(power - num)
	if min_cost is not None and cost > min_cost:
		print(min_cost)
		break
	min_cost = cost


def cost(a, x):
	ans = 0
	cr = 1
	for i in a:
		ans += abs(i - cr)
		cr *= x
	return ans
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = cost(a, 1)
if n > 33:
	print(ans)
else:
	for i in range(2, 1000000000):
		cr = cost(a, i)
		ans = min(ans, cr)
		if cr >= 4 * ans:
			break
	print(ans)


from math import *
import sys
large = 1000000000000000000
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = sum(a) - n
for i in range(1, 1000000000):
	c = 1
	tmp = 0
	for j in range(n):
		x = abs(c - a[j])
		c *= i
		if c > large:
			break
		tmp += x
	if c > large:
		break
	if c / i > ans + a[-1]:
		break
	ans = min(ans, tmp)
print(int(ans))


from math import log
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
limit = int((2 * sum(a)) ** (1 / (n - 1)))
best = sum(a) - n
for c in range(2, limit + 1):
	cost = 0
	for i in range(n):
		cost += abs(c ** i - a[i])
		if cost >= best:
			break
	best = min(best, cost)
print(best)


from math import pow

def rn_value(n):
	p = 9 // n
	if p == 0:
		return 10
	if p == 1:
		return 100
	if p == 2:
		return 1000
	if p == 3:
		return 10000
	if p == 4:
		return 100000
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
if n > 36:
	su = sum(arr)
	ans = su - n
	print(ans)
else:
	mn = 1e+18
	p = 18 // n
	rn = 10
	rn = rn_value(n - 1)
	for i in range(1, rn):
		mul = 1
		add = 0
		for j in range(n):
			add += abs(arr[j] - mul)
			mul *= i
		if mn > add:
			mn = add
		if mul > arr[n - 1] * i:
			break
	print(mn)


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range
R = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

def I():
	return int(input())

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

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

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def NLI(n):
	return [[int(i) for i in input().split()] for i in range(n)]

def NLI_(n):
	return [[int(i) - 1 for i in input().split()] for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RA():
	return map(int, open(0).read().split())

def RLI(n=8, a=1, b=10):
	return [random.randint(a, b) for i in range(n)]

def RI(a=1, b=10):
	return random.randint(a, b)

def Rtest(T):
	(case, err) = (0, 0)
	for i in range(T):
		inp = INP()
		(a1, ls) = naive(*inp)
		a2 = solve(*inp)
		if a1 != a2:
			print((a1, a2), inp)
			err += 1
		case += 1
	print('Tested', case, 'case with', err, 'errors')

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in R(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in R(base ** n):
		s = [tb // base ** bt % base for bt in R(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def YN(x):
	print(['NO', 'YES'][x])

def Yn(x):
	print(['No', 'Yes'][x])

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()
show_flg = False
show_flg = True
ans = 0

def solve(a, c):
	d = 1
	rt = 0
	limit = 10 ** 30
	for i in range(n):
		if a[i] > d:
			rt += a[i] - d
		else:
			rt += d - a[i]
		d *= c
		if d > limit:
			return inf
	return rt
T = 1
ans = 0
n = I()
a = sorted(LI())
b = sum(a)
ans = inf
can = int(a[-1] ** (1 / (n - 1)))
(s, t) = (0, 2)
if n < 10 ** 2:
	0
ans = min(solve(a, can), solve(a, can + 1))
print(ans)


import os
import sys
from io import BytesIO, IOBase
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')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
from math import ceil, floor, sqrt, pow
from collections import defaultdict as dc
n = N()
a = RLL()
a.sort()
ans = sum(a) - n
for c in range(2, 10 ** 9 + 1):
	tmp = 0
	now = 1
	flag = True
	for i in range(n):
		tmp += abs(now - a[i])
		if tmp >= ans:
			flag = False
			break
		now *= c
	if not flag:
		break
	ans = tmp
print(ans)


import sys
from functools import reduce
from collections import Counter
import time
import datetime
from math import sqrt, gcd

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

def sip():
	return sys.stdin.readline()

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

def mips():
	return map(str, sys.stdin.readline().split())

def lip():
	return list(map(int, sys.stdin.readline().split()))

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.append(arr)
	return lst

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 minJumps(arr, n):
	jumps = [0 for i in range(n)]
	if n == 0 or arr[0] == 0:
		return float('inf')
	jumps[0] = 0
	for i in range(1, n):
		jumps[i] = float('inf')
		for j in range(i):
			if i <= j + arr[j] and jumps[j] != float('inf'):
				jumps[i] = min(jumps[i], jumps[j] + 1)
				break
	return jumps[n - 1]

def dic(arr):
	return Counter(arr)

def check_prime(n):
	if n < 2:
		return False
	for i in range(2, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True
n = ip()
arr = lip()
arr.sort()
infinite = 10 ** 18
if n <= 2:
	print(arr[0] - 1)
else:
	ans = sum(arr) - n
	for i in range(1, 10 ** 9):
		Pow = 1
		Cost = 0
		for j in range(n):
			Cost += abs(arr[j] - Pow)
			Pow *= i
			if Pow > infinite:
				break
		if Pow > infinite:
			break
		if Pow / i > ans + arr[n - 1]:
			break
		ans = min(ans, Cost)
	print(ans)


n = int(input())
l = list(map(int, input().split()))
l.sort()

def dist(a, b):
	return sum(map(lambda x: abs(x[0] - x[1]), zip(a, b)))
last = 1e+40
c = 1
while True:
	diff = 0
	for i in range(n):
		diff += abs(l[i] - c ** i)
	if diff < last:
		last = diff
	else:
		print(last)
		break
	c += 1


n = int(input())
a = list(map(int, input().split()))
a.sort()
ma = a[-1]
p = 1
while True:
	if p ** (n - 1) > ma:
		break
	p += 1
ans1 = 0
ans2 = 0
for i in range(n):
	ans1 += abs(a[i] - p ** i)
p -= 1
for i in range(n):
	ans2 += abs(a[i] - p ** i)
print(min(ans1, ans2))


import os
import sys
from io import BytesIO, IOBase
import threading
from collections import defaultdict, Counter, deque
from math import factorial as fac

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	limit = int(100000.0)
	prev = [float('inf')]
	for c in range(limit):
		temp_ans = 0
		for i in range(n):
			temp_ans += abs(c ** i - arr[i])
		if temp_ans < prev[-1]:
			prev.append(temp_ans)
		else:
			break
	print(prev[-1])
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()


t = int(input())
x = list(map(int, input().split()))
x.sort()
n = len(x)
c = 1
big = 10 ** 10
while c ** (n - 1) <= big:
	c += 1
c -= 1
ans = float('inf')
for i in range(1, c + 1):
	tmp = 0
	for j in range(n):
		tmp += abs(x[j] - i ** j)
	ans = min(ans, tmp)
print(ans)


n = int(input())
arr = list(map(int, input().split()))
s = 0
for i in arr:
	s += i
ans = sum(arr) - n
arr.sort()
for i in range(2, 32011):
	cost = 0
	for j in range(n):
		cur = pow(i, j)
		cost += abs(cur - arr[j])
	ans = min(ans, cost)
	if cost > ans:
		break
print(ans)


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = math.inf
k = 1
while pow(k, n - 1) <= pow(10, 10):
	k += 1
k -= 1
for num in range(1, k + 1):
	temp = 0
	for j in range(n):
		temp += abs(a[j] - pow(num, j))
	ans = min(ans, temp)
print(ans)


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


n = int(input())
nums = sorted((int(x) for x in input().split()))
cost_1 = sum((abs(x - 1) for x in nums))
best = cost_1
for i in range(2, 33000):
	cost = 0
	pot = 1
	for x in nums:
		cost += abs(x - pot)
		if cost > best:
			break
		pot *= i
	best = min(cost, best)
print(best)


import time, math as mt, bisect as bs, sys
from sys import stdin, stdout
from collections import defaultdict
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

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

def IO():
	return stdin.readline()

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

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

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

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

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

def readTree():
	v = int(input())
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return (adj, v)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 7
spf = [mx] * (mx + 1)

def SPF():
	spf[1] = 1
	for i in range(2, mx + 1):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx + 1, i):
				if i < spf[j]:
					spf[j] = i
	return
mod = 10 ** 9 + 7

def solve():
	n = II()
	a = L()
	a.sort()
	ans = 1000000000000000.0
	for i in range(1, int(100000.0)):
		k = 1
		diff = 0
		ok = True
		for j in range(n):
			if k > 10000000000.0:
				ok = False
				break
			diff += abs(k - a[j])
			k = k * i
		if ok:
			ans = min(ans, diff)
		else:
			break
	P(ans)
	return
t = 1
for i in range(t):
	solve()


n = int(input())
b = list(map(int, input().split()))
b.sort()
ans = float('inf')
j = 1
while j ** (n - 1) <= 10 ** 10:
	s = 0
	for p in range(n):
		s += abs(j ** p - b[p])
	ans = min(ans, s)
	j += 1
print(ans)


from math import log10
N = int(input())
l = list(map(int, input().split()))
l.sort()
x = round(pow(10, log10(l[-1]) / (N - 1)))
minm = pow(10, 15)
for b in range(max(1, x - 3), x + 2):
	n = 0
	for i in range(N):
		n += abs(pow(b, i) - l[i])
	minm = min(minm, n)
print(minm)


n = int(input())
a = list(map(int, input().split()))
a.sort()
d = 1
best = None
while d ** n <= 10 ** 15:
	cost = 0
	p = 1
	for e in a:
		cost += abs(e - p)
		p *= d
	if best == None or cost < best:
		best = cost
	d += 1
print(best)


n = int(input())
a = list(map(int, input().split()))
ans = 1000000000000000000000
a.sort()
for base in range(1, 100000):
	b = 1
	sum = 0
	for i in range(n):
		sum += abs(b - a[i])
		b *= base
		if sum > ans:
			break
	ans = min(ans, sum)
print(ans)


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
maximum_power = n - 1
maximum = a[-1]
root = maximum ** (1 / maximum_power)
result = math.inf
for c in [math.floor(root), math.ceil(root)]:
	cost = 0
	c_to_the_power = 1
	for x in a:
		cost += abs(x - c_to_the_power)
		if cost > result:
			cost = result
			break
		c_to_the_power *= c
	result = min(result, cost)
print(result)


import sys

def i():
	return sys.stdin.readline()[:-1]
n = int(i())
listNums = sorted(list(map(int, i().split())))
cost = sum(listNums) - n
guess = int(listNums[-1] ** (1 / (n - 1)) + 1)
if n < 40:
	for x in range(-10, 5):
		currGuess = guess + x
		if currGuess <= 0:
			continue
		currCost = 0
		power = 1
		for y in range(len(listNums)):
			currCost += abs(power - listNums[y])
			power *= currGuess
		cost = min(cost, currCost)
print(cost)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 100000000000000.0
c = 1
while True:
	cost = 0
	k = 1
	for i in range(len(a)):
		cost += abs(a[i] - k)
		k = k * c
		if k > 100000000000000.0:
			cost = 100000000000000.0
			break
		if cost > 100000000000000.0:
			break
	if cost == 100000000000000.0:
		break
	ans = min(cost, ans)
	c += 1
print(ans)


from math import *
from sys import *
mod = 10 ** 10
mod = mod + 7

def power(x, y, mod):
	res = 1
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % mod
		y = y >> 1
		x = x * x % mod
	return res
n = int(stdin.readline().strip())
a = list(map(int, stdin.readline().strip().split()))
a.sort()
k = a[n - 1]
p = 1 / (n - 1)
m = k ** p
b = ceil(m)
c = floor(m)
ans = 0
for i in range(n):
	z = power(b, i, mod)
	s = a[i] - z
	s = abs(s)
	ans = ans + s
r = 0
ans = int(ans)
for i in range(n):
	ab = power(c, i, mod)
	s = a[i] - ab
	s = abs(s)
	r = r + s
r = int(r)
print(min(ans, r))


from sys import stdin

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

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

def linput():
	return list(map(int, stdin.readline().split()))
from collections import defaultdict
from math import factorial
n = iinput()
a = linput()
a.sort()
cost = 0
for i in range(n):
	cost += abs(a[i] - 1)
p = 1
for i in range(2, 100000):
	if i ** (n - 1) >= 10 ** 9:
		p = i
		break
for m in range(2, p + 1):
	temp = 0
	for i in range(n):
		temp += abs(m ** i - a[i])
	if cost > temp:
		cost = temp
		c = m
print(cost)


n = int(input())
s = map(int, input().split())
s = sorted(s)
i = 1
while i ** (n - 1) < s[-1]:
	i += 1
a = 0
b = 0
for (j, x) in enumerate(s):
	a += abs(x - i ** j)
	b += abs(x - (i - 1) ** j)
print(min(a, b))


n = int(input())
xs = [int(x) for x in input().split()]
if n > 100:
	print(sum((x - 1 for x in xs)))
elif n == 2:
	print(xs[0] - 1)
else:
	xs.sort()
	ans = 123456123467819234
	i = 0
	while True:
		i += 1
		cur = 0
		for j in range(len(xs)):
			d = pow(i, j)
			cur += abs(d - xs[j])
			if cur >= ans:
				break
		else:
			ans = min(ans, cur)
			continue
		break
	print(ans)


import sys
input = sys.stdin.readline
import math
n = int(input())
l = list(map(int, input().split()))
l.sort()
count = float('infinity')
ans = 1
t = int(pow(l[-1], 1 / (n - 1)))
I = t
for i in range(-1, 2):
	I = t + i
	if I <= 0:
		continue
	res = 0
	for j in range(n):
		res += abs(I ** j - l[j])
	count = min(count, res)
print(count)


n = int(input())
vals = list(map(int, input().split(' ')))
ans = 10000000000000000000000000000000000000000000000
vals.sort()
for x in range(0, 10000000):
	temp = 0
	for hoho in range(n):
		temp += abs(vals[hoho] - x ** hoho)
	if ans > temp:
		ans = temp
	else:
		break
print(ans)


import math
t = int(input())
l = list(map(int, input().split()))
l.sort()
cost = 1000000000000000000
for c in range(1, 100000):
	ct = 0
	f = 0
	for i in range(t):
		b = c ** i
		if b > 1000000000000000:
			f = 1
			break
		ct += abs(l[i] - b)
	if f == 0:
		cost = min(cost, ct)
print(cost)


import sys
input = sys.stdin.readline

def calc(r, n):
	return pow(r, n - 1)
n = int(input())
a = [int(i) for i in input().split()]
if n > 200:
	sys.stdout.write(str(sum(a) - n))
else:
	a.sort()
	maxa = a[-1]
	(lo, hi) = (1, 1000000000)
	while lo < hi:
		mid = (lo + (hi - 1)) // 2
		mx1 = calc(mid, n)
		mx2 = calc(mid + 1, n)
		if abs(maxa - mx1) < abs(maxa - mx2):
			hi = mid
		else:
			lo = mid + 1
	(pq, pq1) = ([], [])
	for i in range(n):
		pq.append(mid ** i)
	for i in range(n):
		pq1.append((mid + 1) ** i)
	(ans, ans1) = (0, 0)
	for i in range(n):
		ans += abs(a[i] - pq[i])
		ans1 += abs(a[i] - pq1[i])
	sys.stdout.write(str(min(ans1, ans)) + '\n')


import sys
import math
input = sys.stdin.readline
from collections import deque
from queue import LifoQueue
n = int(input())
a = list(map(int, input().split()))
so = 0
for i in a:
	so += i
h = sorted(a)
if a != [1] * n:
	for i in range(2, 10 ** 9 + 1):
		if so <= (i ** n - 1) // (i - 1):
			I = i
			break
	for i in range(2, 10 ** 9 + 1):
		if h[-1] <= i ** (n - 1):
			J = i
			break
	(ans, ans1) = (0, 0)
	for i in range(n):
		ans += abs(J ** i - h[i])
	for i in range(n):
		ans1 += abs((J - 1) ** i - h[i])
	print(min(ans1, ans))
else:
	print(0)


n = int(input())
a = input().split()
for i in range(len(a)):
	a[i] = int(a[i])
a.sort()
r = pow((n - 1) * a[n - 1], 1 / (n - 1)) + 1

def Val(x):
	tmp = 0
	for i in range(len(a)):
		tmp = tmp + abs(x ** i - a[i])
		if tmp > 9223372036854775807:
			return 9223372036854775807
	return tmp
l = 1
while r - l > 1:
	mid = (l + r) // 2
	if Val(mid + 1) <= Val(mid):
		l = mid
	else:
		r = mid
i = mid + 10
ans = Val(i)
i = i - 1
while i > mid - 11:
	ans = min(ans, Val(i))
	i = i - 1
print(int(ans))


from collections import defaultdict as dd
import sys

def getval(l, i):
	m = 1
	curr = 0
	for j in range(n):
		curr += abs(l[j] - m)
		m = m * i
		if m > 1000000000000000000:
			return 1000000000000000000
	return curr
input = sys.stdin.readline
n = int(input())
l = list(map(int, input().split()))
l.sort()
lo = 1
hi = 1000000
while hi - lo > 1:
	mid = (hi + lo) // 2
	val1 = getval(l, mid)
	val2 = getval(l, mid + 1)
	if val2 < val1:
		lo = mid
	else:
		hi = mid
print(min(getval(l, hi), getval(l, lo)))


import math
n = int(input())
list1 = list(map(int, input().split()))
list1.sort()
x1 = math.ceil(list1[n - 1] ** (1 / (n - 1)))
x2 = math.floor(list1[n - 1] ** (1 / (n - 1)))
answer1 = 0
answer2 = 0
for i in range(0, n):
	answer1 += abs(x1 ** i - list1[i])
	answer2 += abs(x2 ** i - list1[i])
print(min(answer1, answer2))


n = int(input())
a = list(map(int, input().split()))
a.sort()
res = sum((v - 1 for v in a))
if n > 2:
	c = 2
	while True:
		s = 0
		v = 1
		ok = True
		for i in range(n):
			s += abs(a[i] - v)
			v *= c
			if s > res:
				ok = False
				break
		if not ok:
			break
		res = s
		c += 1
elif n == 2:
	res = a[0] - 1
print(res)


n = int(input())
arr = [int(d) for d in input().split()]
arr.sort()
t = int(pow(arr[n - 1], 1 / (n - 1)))
s1 = 0
s2 = 0
for i in range(n):
	k1 = arr[i] - t ** i
	k2 = arr[i] - (t + 1) ** i
	if k1 >= 0:
		s1 += k1
	else:
		s1 -= k1
	if k2 >= 0:
		s2 += k2
	else:
		s2 -= k2
print(int(s1) if s1 <= s2 else int(s2))


n = int(input())
a = [int(x) for x in input().split()]
a = sorted(a)
c = 1
while 1:
	temp = 0
	for i in range(n):
		temp += abs(pow(c, i) - a[i])
	if c == 1:
		ans = temp
	elif temp < ans:
		ans = temp
	else:
		break
	c += 1
print(ans)


N = int(input())
a = sorted(map(int, input().split()))
ans = 0
if N >= 100:
	for i in range(N):
		ans += a[i] - 1
	print(ans)
	exit()
i = 0
while True:
	if pow(i, N - 1) > a[-1]:
		t = i
		break
	i += 1
ans = 0
for i in range(N):
	ans += abs(pow(t, i) - a[i])
ans2 = 0
for i in range(N):
	ans2 += abs(pow(t - 1, i) - a[i])
print(min(ans, ans2))


import os
import heapq
import sys, threading
import math
import bisect
import operator
from collections import defaultdict
from io import BytesIO, IOBase

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

def power(x, p):
	res = 1
	while p:
		if p & 1:
			res = res * x
		x = x * x
		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()
		arr.sort()
		counter = 0
		cost = 0
		take = sum(arr)
		for i in range(n):
			cost += abs(arr[i] - 1)
		if n <= 32:
			c = 0
			for i in range(1, 100000):
				temp = 0
				c = 0
				for j in range(n):
					if power(i, j) > 10 ** 10:
						c = 1
						break
					temp += abs(arr[j] - power(i, j))
				if c == 0:
					cost = min(cost, temp)
		print(cost)
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())
num = map(int, input().split())
num = sorted(num)
base = int(num[-1] ** (1 / (n - 1)))
base2 = base + 1
out = out2 = 0
for i in range(n):
	out += abs(num[i] - base ** i)
	out2 += abs(num[i] - base2 ** i)
print(min(out, out2))


import sys
import math
readline = lambda : sys.stdin.readline().strip()
N = int(readline())
A = list(map(int, readline().split()))
A.sort()
M = A[-1]

def find_cost(c):
	cost = 0
	b = 0
	for a in A:
		cost += abs(c ** b - a)
		b = b + 1
	return cost

def solve():
	pivot = M ** (1 / (N - 1))
	lb = math.floor(pivot)
	ub = math.ceil(pivot)
	cost1 = find_cost(ub)
	cost2 = find_cost(lb)
	return min(cost1, cost2)
print(solve())


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
import threading
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')
n = int(input())
a = list(map(int, input().split()))
a.sort()
inf = 10 ** 18
ans = sum(a) - n
for x in range(1, 10 ** 9):
	tot = 0
	curpow = 1
	for i in range(n):
		tot += abs(a[i] - curpow)
		curpow *= x
		if curpow > inf:
			break
	if curpow > inf:
		break
	if curpow / x > ans + a[n - 1]:
		break
	ans = min(ans, tot)
print(ans)


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

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

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

def inputstring():
	return [x for x in input()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
n = inputnum()
a = inputlist()
a.sort()
c1 = math.ceil(pow(a[n - 1], 1 / (n - 1)))
c2 = c1 - 1
ans1 = 0
ans2 = 0
for i in range(n):
	ans2 += abs(a[i] - pow(c2, i))
if a[n - 1] == 1:
	print(0)
elif n > 55:
	print(ans2)
else:
	for i in range(n):
		ans1 += abs(a[i] - pow(c1, i))
	print(min(ans1, ans2))


import math
INF = float('inf')

def tc():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	ans = INF
	lim = math.pow(10 ** 9, 1 / (n - 1))
	lim = min(math.ceil(lim), 100000)
	for i in range(lim + 1):
		tmp = 0
		for (j, x) in enumerate(a):
			tmp += abs(x - i ** j)
		ans = min(ans, tmp)
	print(ans)
tc()


import os
import sys
from io import BytesIO, IOBase

def main():
	pass
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')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True
n = int(input())
l = sorted(list(map(int, input().split())))
if n == 2:
	print(l[1] - l[0])
else:
	ans = 10000000000000000
	for i in range(1, 100006):
		ca = 0
		p = 1
		for j in range(0, n):
			ca += abs(l[j] - p)
			p *= i
			if ca > ans:
				break
		ans = min(ans, ca)
	print(ans)


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

def cal(x):
	res = 0
	for item in range(n):
		res += abs(x ** item - a[item])
	return res
a.sort()
r = 1
l = 1
while r ** (n - 1) <= a[n - 1]:
	r += 1
while r - l > 10:
	mid = l + r >> 1
	midmid = r + mid >> 1
	if int(cal(mid)) <= int(cal(midmid)):
		r = midmid
	else:
		l = mid
ans = 1e+18
for i in range(l, min(r + 1, l + 11)):
	ans = min(ans, cal(i))
print(ans)


t = 1
import math
while t:
	n = int(input())
	a = [int(i) for i in input().split()]
	a = sorted(a)
	if n == 1:
		print(0)
		break
	m = a[-1] + sum(a) - n
	i = 1
	temp = 0
	ans = int(1e+18)
	ind = -1
	while temp <= m:
		temp = 0
		for j in range(n):
			temp += abs(a[j] - i ** j)
		ans = min(ans, temp)
		if ans == temp:
			ind = i
		i += 1
	print(ans)
	t -= 1


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
m = 0
for i in arr:
	m += abs(i - 1)
c = 2
if n > 10:
	while c < 20:
		t = 0
		for i in range(n):
			t += abs(c ** i - arr[i])
			if t >= m:
				break
		if t < m:
			m = t
		c += 1
	print(m)
else:
	while c <= 1000000:
		t = 0
		for i in range(n):
			t += abs(c ** i - arr[i])
			if t >= m:
				break
		if t < m:
			m = t
		c += 1
	print(m)


import math as mt
t = int(input())
arr = list(map(int, input().strip().split()))[:t]
arr.sort()
ans = 999999999999999999
for i in range(0, 99999):
	summ = 0
	for j in range(0, t):
		summ = summ + abs(arr[j] - pow(i, j))
	if ans > summ:
		ans = summ
	elif ans <= summ:
		break
print(ans)


def calc(nums):
	nums.sort()
	estimations = [int(nums[-1] ** (1 / (len(nums) - 1)))]
	estimations.append(estimations[0] + 1)
	best_cost = -1
	for est in estimations:
		if est == 0:
			continue
		cost = 0
		for (i, num) in enumerate(nums):
			cost += abs(est ** i - num)
		if cost < best_cost or best_cost < 0:
			best_cost = cost
	return best_cost

def get_ints():
	return [int(n) for n in input().split()]

def get_floats():
	return [float(n) for n in input().split()]

def seq2str(seq):
	return ' '.join((str(item) for item in seq))
zzz = get_ints()
assert len(zzz) == 1
n = zzz[0]
zzz = get_ints()
assert len(zzz) == n
nums = zzz
res = calc(nums)
print(res)


n = int(input())
ar = [int(i) for i in input().split()]
k = 0
ar.sort()
while k ** (n - 1) < max(ar):
	k += 1
s1 = 0
s2 = 0
for i in range(n):
	s1 += abs(ar[i] - k ** i)
	s2 += abs(ar[i] - (k - 1) ** i)
print(min(s1, s2))


import sys
from collections import defaultdict as dd
from collections import deque
from functools import *
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations, product

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def inc(d, c):
	d[c] = d[c] + 1 if c in d else 1

def bo(i):
	return ord(i) - ord('A')

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

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

def gh():
	sys.stdout.flush()

def isvalid(i, j):
	return 0 <= i < n and 0 <= j < n

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = 1
while t > 0:
	t -= 1
	n = fi()
	a = li()
	a.sort()
	maxi = abs(n - sum(a))
	if n == 1:
		print(maxi)
		continue

	def can(mid):
		c = 0
		k = 1
		for j in range(n):
			c += abs(k - a[j])
			k *= mid
			if k >= 10 ** 18:
				c = 10 ** 18
				break
		return c
	l = 0
	r = 10 ** 9
	while l <= r:
		mid1 = l + (r - l) // 3
		mid2 = r - (r - l) // 3
		p = can(mid1)
		q = can(mid2)
		maxi = min([maxi, p, q])
		if p > q:
			l = mid1 + 1
		else:
			r = mid2 - 1
	print(maxi)


n = int(input())
lst = list(map(int, input().split()))
lst.sort()
c = 1
while 1:
	temp = 0
	for i in range(n):
		temp += abs(pow(c, i) - lst[i])
	if c == 1:
		ans = temp
	elif temp < ans:
		ans = temp
	else:
		break
	c += 1
print(ans)


import math
n = int(input())
arr = sorted(list(map(int, input().split())))
ans = int(1000000000000000.0) + 7
for i in range(0, 100000):
	tmp = 0
	for j in range(n):
		tmp += abs(arr[j] - i ** j)
	if ans > tmp:
		ans = int(tmp)
	elif ans <= tmp:
		break
print(ans)


import math

def cost(c, MAX_ANS):
	ans = 0
	v = 1
	for i in range(n):
		ans += abs(v - array[i])
		if ans > MAX_ANS:
			return -1
		v *= c
	return ans
n = int(input())
array = [int(ai) for ai in input().split()]
array.sort()
MAX_ANS = 0
for i in range(n):
	MAX_ANS += array[i]
for i in range(100000):
	ans = cost(i, MAX_ANS)
	if ans != -1:
		MAX_ANS = min(MAX_ANS, ans)
print(MAX_ANS)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
difference_between_ones = 0
for num in a:
	difference_between_ones += abs(num - 1)
candidate = 2
flag = 0
while True:
	difference = 0
	for (degree, num) in enumerate(a):
		difference += abs(num - pow(candidate, degree))
		if difference_between_ones < difference:
			flag = 1
			break
	if difference_between_ones > difference:
		difference_between_ones = difference
	if flag == 1:
		break
	candidate += 1
print(difference_between_ones)


n = int(input())
a = list(map(int, input().split()))
a.sort()
val1 = int(a[-1] ** (1 / (n - 1)))
val2 = val1 + 1
(res1, res2) = (0, 0)
for i in range(0, n):
	res1 += abs(a[i] - val1 ** i)
	res2 += abs(a[i] - val2 ** i)
print(min(res1, res2))


n = int(input())
a = list(map(int, input().split()))
a.sort()
c = int(a[-1] ** (1 / (n - 1)))
s = 0
p = 0
for i in range(n):
	s += abs(a[i] - c ** i)
	p += abs(a[i] - (c + 1) ** i)
print(min(s, p))


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
c1 = math.ceil(a[-1] ** (1 / (n - 1)))
c2 = math.floor(a[-1] ** (1 / (n - 1)))
ans1 = 0
ans2 = 0
for i in range(len(a)):
	t = c1 ** i - a[i]
	ans1 += abs(t)
	t = c2 ** i - a[i]
	ans2 += abs(t)
print(min(ans1, ans2))


import sys
n = int(input())
num = list(map(int, input().split()))
num.sort()
answer = sys.maxsize * sys.maxsize
for i in range(1, 100001):
	temp = 0
	flag = True
	for j in range(n):
		if temp > answer:
			break
		try:
			temp += abs(num[j] - pow(i, j))
		except:
			flag = False
			break
	if flag:
		answer = min(answer, temp)
print(answer)


n = int(input())
a = list(map(int, input().split()))
a.sort()
add = sum(a)
c = add - n
j = 2
while pow(j, n - 1) <= add * 2:
	b = [1]
	for k in range(n - 1):
		b.append(b[-1] * j)
	total = sum([abs(a[i] - b[i]) for i in range(n)])
	c = min(c, total)
	j += 1
print(c)


import sys
import math
input = sys.stdin.readline
MAX_NUMBER = 4000000000
MIN_INF = float('-INF')

def get_cost(A, power):
	if pow(power, len(A) - 1) > MAX_NUMBER:
		return MIN_INF
	B = [power ** i for i in range(len(A))]
	return sum((abs(a - b) for (a, b) in zip(A, B)))
N = int(input())
A = list(map(int, input().split(' ')))
A.sort()
close_power = round(pow(MAX_NUMBER, 1.0 / (N - 1)))
min_cost = MAX_NUMBER * MAX_NUMBER
for power in range(close_power, 0, -1):
	cost = get_cost(A, power)
	if cost != MIN_INF:
		min_cost = min(min_cost, cost)
print(min_cost)


import math
t = int(input())
arr = list(map(int, input().split()))
arr = sorted(arr)
tsum = sum(arr)
n = len(arr)
if tsum == n:
	print(0)
else:
	v = int(arr[-1] ** (1 / (n - 1)))
	min_diff = float('inf')
	tdiff1 = 0
	tdiff2 = 0
	for j in range(n):
		val_1 = v ** j
		tdiff1 += abs(arr[j] - val_1)
		val_2 = (v + 1) ** j
		tdiff2 += abs(arr[j] - val_2)
	print(min(tdiff1, tdiff2))


from collections import defaultdict
from math import inf
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ma = inf
kk = 10 ** 15
c = 1
while c <= 10 ** 5:
	ans = 0
	i = 0
	f = 0
	while i < n:
		if c ** i >= kk:
			f = 1
			break
		ans += abs(arr[i] - c ** i)
		i += 1
	if f:
		break
	c += 1
	ma = min(ans, ma)
print(ma)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
result = 10 ** 30
for i in range(1, 200000):
	now = 0
	s = 1
	for j in range(n):
		now += abs(a[j] - s)
		if s > 10 ** 30:
			now = 10 ** 30
			break
		s *= i
	result = min(result, now)
print(result)


n = int(input())
nums = [int(x) for x in input().strip().split()]
nums = sorted(nums)
biggest = nums[-1]
lowest = float('inf')
good = True
i = 2
while good:
	diff = abs(biggest - i ** (n - 1))
	if diff <= lowest:
		lowest = diff
	else:
		break
	i += 1
i -= 1
diff = abs(biggest - 1)
if diff <= lowest:
	i = 1
tot = 0
for j in range(n):
	tot += abs(nums[j] - i ** j)
tot2 = 0
for j in range(n):
	tot2 += abs(nums[j] - (i + 1) ** j)
tot3 = 0
for j in range(n):
	tot3 += abs(nums[j] - (i - 1) ** j)
print(min(tot, tot2, tot3))


import sys
import math
from functools import reduce
import bisect

def getN():
	return int(input())

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

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

def input():
	return sys.stdin.readline().rstrip()

def index(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	return False
n = getN()
arr = sorted(getList())
if n == 1:
	print(arr[0] - 1)
l = r = -1
for i in range(1, 10 ** 5):
	if i ** (n - 1) >= arr[-1]:
		r = i
		l = i - 1 if i - 1 > 1 else -1
		break
ans1 = 0
for x in range(n):
	ans1 += abs(arr[x] - r ** x)
if l + 1:
	ans2 = 0
	for x in range(n):
		ans2 += abs(arr[x] - l ** x)
	ans1 = min(ans1, ans2)
print(min(ans1, sum([x - 1 for x in arr])))


def main():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	m = 0
	for i in a:
		m += i - 1
	z = 2
	found = False
	while True:
		candidate = 0
		for (c, el) in enumerate(a):
			candidate += abs(el - z ** c)
			if candidate >= m:
				found = True
				break
		if found:
			break
		m = candidate
		z += 1
	print(m)
main()


def main():
	n = int(input())
	list = []
	str1 = input()
	list = str1.split(' ')
	ans = 0
	for i in range(0, n):
		ans = ans + int(list[i])
		list[i] = int(list[i])
	list.sort()
	minn = ans - n
	for i in range(1, 100000):
		ans = 0
		if pow(i, n - 1) > 100000000000000:
			break
		for j in range(0, n):
			ans = ans + abs(int(list[j]) - pow(i, j))
		minn = min(minn, ans)
	print(minn)
main()


n = int(input())
A = list(map(int, input().split()))
A.sort()
m = 10 ** 18
a = m
for i in range(1, 10 ** 9):
	b = 0
	for j in range(n):
		b += abs(A[j] - i ** j)
	if b > a:
		break
	else:
		m = min(b, m)
		a = b
print(m)


import math
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
c1 = arr[0] - 1
c2 = arr[0] - 1
x = arr[-1] ** (1 / float(n - 1))
x1 = math.ceil(x)
x2 = math.floor(x)
for i in range(1, n):
	d1 = abs(arr[i] - x1 ** i)
	c1 += d1
	d2 = abs(arr[i] - x2 ** i)
	c2 += d2
print(min(c1, c2))


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
inf = 10 ** 18
ans = inf
for k in range(1, 10 ** 5):
	tmp = 0
	for i in range(n):
		tmp = tmp + abs(a[i] - k ** i)
		if tmp > ans:
			break
	if ans > tmp:
		ans = tmp
print(ans)


n = int(input())
l = list(map(int, input().split()))
l.sort()
c1 = int(l[-1] ** (1 / (n - 1)))
c2 = c1 + 1
ans1 = ans2 = 0
for i in range(n):
	ans1 += abs(l[i] - c1 ** i)
for i in range(n):
	ans2 += abs(l[i] - c2 ** i)
print(min(ans1, ans2))


n = int(input())
ar = list(map(int, input().split()))
ar.sort()
ans = 0
for i in ar:
	ans += abs(i - 1)
if n == 1:
	print(ans)
	exit(0)
if n == 2:
	print(abs(i - ar[0]))
	exit(0)
if n >= 50:
	print(ans)
	exit(0)
for i in range(2, 100000):
	s = 0
	ok = 1
	for j in range(0, n):
		if pow(i, j) > 1e+16:
			ok = 0
			break
		if s > 1e+16:
			ok = 0
			break
		s += abs(pow(i, j) - ar[j])
	if not ok:
		break
	ans = min(ans, s)
print(ans)


import sys
import math
N = int(input())
A = [int(x) for x in input().split()]
A.sort()

def find_cost(c):
	cost = 0
	for i in range(N):
		cost += abs(A[i] - pow(c, i))
	return cost
pivot = A[-1] ** (1 / (N - 1))
lb = math.floor(pivot)
ub = math.ceil(pivot)
cost1 = find_cost(lb)
cost2 = find_cost(ub)
print(min(cost1, cost2))


import math
n = int(input())
A = [int(i) for i in input().split()]
A.sort()
prev = math.floor(A[-1] ** (1 / (n - 1)))
nxt = math.ceil(A[-1] ** (1 / (n - 1)))
ans1 = 0
ans2 = 0
for i in range(n):
	ans1 += abs(A[i] - prev ** i)
	ans2 += abs(A[i] - nxt ** i)
print(min(ans1, ans2))


n = int(input())
arr = list(map(int, input().split()))
res = 10 ** 18
arr.sort()
for k in range(10 ** 6):
	if k ** (n - 1) > 10 ** 10:
		break
	temp = 0
	for i in range(n):
		temp += abs(arr[i] - k ** i)
	if res < temp:
		break
	res = min(res, temp)
print(res)


import math as m
n = int(input())
v = [int(x) for x in input().split()]
v.sort()
maximum = m.ceil(v[-1] ** (1 / (n - 1)))
minimum = m.floor(v[-1] ** (1 / (n - 1)))
s1 = 0
s = 0
for i in range(n):
	s1 += abs(v[i] - maximum ** i)
for i in range(n):
	s += abs(v[i] - minimum ** i)
print(min(s, s1))


n = int(input())
lis = sorted(map(int, input().split()))
if n == 1:
	print(0)
else:
	root = int(lis[-1] ** (1 / float(n - 1))) + 1
	ans = 100000000000000000000000000
	for i in range(1, root + 2):
		if i ** (n - 1) > 20 ** 9:
			break
		c = 1
		tmp = 0
		for j in range(n):
			tmp += abs(lis[j] - c)
			c *= i
		ans = min(ans, tmp)
	ans = min(ans, tmp)
	print(ans)


n = int(input())
a = [int(item) for item in input().split()]
if n == 1:
	print(0)
	exit()
ans = -1
a.sort()
for p in range(1, int(pow(1000000000, 1.0 / (n - 1))) + 2):
	cur = 0
	for i in range(n):
		cur += abs(a[i] - pow(p, i))
	if ans == -1:
		ans = cur
	else:
		ans = min(ans, cur)
print(ans)


import math
n = int(input(''))
arr = list(map(int, input().split()))
arr.sort()
ans = 1000000000000000
if n == 3:
	cmax = 100000
else:
	cmax = 100000 // n
for c in range(1, cmax + 1):
	mx = 0
	x = 1
	for i in range(n):
		mx += abs(arr[i] - x)
		if mx > ans:
			break
		x *= c
	if ans > mx:
		ans = mx
print(ans)


import sys
import math, bisect
sys.setrecursionlimit(10 ** 5)
from collections import defaultdict
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, OrderedDict

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

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

def Neo():
	return list(map(int, sys.stdin.readline().split()))
n = I()
A = Neo()
A.sort()
val = (10 ** 9) ** (1.0 / (n - 1))
maxx = 10 ** 18
for i in range(1, int(val) + 2):
	c = 0
	for j in range(n):
		c += abs(i ** j - A[j])
	maxx = min(maxx, c)
print(maxx)


import math
n = int(input())
l = list(map(int, input().strip().split()))
l.sort()
cost1 = 0
cost2 = 0
c = l[-1] ** (1 / (n - 1))
a = math.ceil(c)
b = math.floor(c)
for i in range(n):
	cost1 = cost1 + abs(a ** i - l[i])
	cost2 = cost2 + abs(b ** i - l[i])
print(min(cost1, cost2))


import math
n = int(input())
v = list(map(int, input().split()))
v.sort()
temp = v[n - 1] ** float(1 / (n - 1))
itr = math.ceil(temp)
ans = 100000000000000000000
for i in range(1, itr + 1):
	cost = 0
	for j in range(n):
		cost = cost + abs(v[j] - i ** j)
	ans = min(ans, cost)
print(ans)


from sys import stdin, stdout
import math
from collections import Counter, deque
L = lambda : list(map(int, stdin.readline().strip().split()))
M = lambda : map(int, stdin.readline().strip().split())
I = lambda : int(stdin.readline().strip())
S = lambda : stdin.readline().strip()
C = lambda : stdin.readline().strip().split()
mod = 1000000007

def pr(a):
	print(''.join(list(map(str, a))))

def solve():
	n = I()
	a = L()
	a.sort()
	x = round(pow(a[-1], 1 / (n - 1)))
	ma = pow(10, 20)
	for i in range(x - 2, x + 3):
		ans = 0
		te = 1
		for j in range(n):
			ans += abs(a[j] - te)
			if ans > ma:
				break
			te *= i
		ma = min(ma, ans)
	print(ma)
for _ in range(1):
	solve()


import os
import sys
from io import BytesIO, IOBase
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')

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
from math import floor
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
n = int(ri())
a = Ri()
a.sort()
val = pow(a[-1], 1 / (n - 1))
(fir, sec) = (floor(val), ceil(val))
minn = 10 ** 18
ans = 0
for i in range(n - 1, -1, -1):
	ans += abs(pow(fir, i) - a[i])
minn = min(ans, minn)
ans = 0
for i in range(n - 1, -1, -1):
	ans += abs(pow(sec, i) - a[i])
minn = min(minn, ans)
print(minn)


import sys
_LIMIT = 10 ** 18

def test(n, a, c):
	v = 1
	r = 0
	for i in range(n):
		r += abs(v - a[i])
		v *= c
		if v >= _LIMIT:
			return (_LIMIT, v)
	return (r, v)

def solve(n, a):
	a = [int(x) for x in a.strip().split()]
	a = sorted(a)
	(r, cn) = test(n, a, 1)
	for i in range(1, 10 ** 9):
		(v, cn) = test(n, a, i)
		if cn > _LIMIT or cn // i > r + a[-1]:
			break
		r = min(r, v)
	return r
input = sys.stdin.readline
n = int(input())
a = input()
r = solve(n, a)
print(r)


from sys import stdin
input = stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
ans = 9876543219876543210
x = 1
flag = 0
while True:
	(now1, now2) = (0, 1)
	for y in range(n):
		now1 += abs(a[y] - now2)
		now2 *= x
		if now2 > 10 ** 19:
			flag = 1
			break
	ans = min(ans, now1)
	x += 1
	if flag == 1:
		break
print(ans)


def cd(l, n, mid):
	ans = 0
	c = 1
	for i in range(n):
		ans += abs(l[i] - c)
		c = c * mid
	return ans

def abc(l, n):
	i = 1
	j = 31623
	while i <= j:
		mid = i + (j - i) // 2
		x = cd(l, n, mid)
		a = cd(l, n, mid - 1)
		b = cd(l, n, mid + 1)
		if a >= x and b >= x:
			return mid
		elif b >= x and a <= x:
			j = mid - 1
		else:
			i = mid + 1
for _ in range(1):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	if n > 67:
		print(cd(l, n, 1))
		continue
	if n > 30:
		ans = cd(l, n, 1)
		ans = min(ans, cd(l, n, 2))
		print(ans)
		continue
	ans = 1000000000000
	i = 1
	e = pow(l[-1], 1 / (n - 1))
	e = int(e) + 1
	while i <= e:
		ans = min(ans, cd(l, n, i))
		i += 1
	ans = min(ans, cd(l, n, i))
	print(ans)


import math
n = int(input())
l = list(map(int, input().split()))
l.sort()
k = l[-1]
c = math.log(k, 10) / (n - 1)
r = pow(10, c)
r = int(r)
ans = 100000000000000000
for i in range(r, r + 2):
	a1 = 0
	for j in range(0, n):
		a1 += abs(pow(i, j) - l[j])
	ans = min(ans, a1)
print(ans)


from math import *
n = int(input())
liczby = sorted(list(map(int, input().split())))
pier = liczby[-1] ** (1 / (n - 1))
(c1, c2) = (floor(pier), ceil(pier))
(wynik1, wynik2) = (0, 0)
for x in range(n):
	wynik1 += abs(liczby[x] - c1 ** x)
	wynik2 += abs(liczby[x] - c2 ** x)
print(min(wynik1, wynik2))


import sys
input = lambda : sys.stdin.readline().rstrip()
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
c = int(pow(a[-1], 1 / (n - 1)))
ans = 10 ** 18
for j in range(c, c + 2):
	cur = 0
	for i in range(n):
		cur += abs(a[i] - pow(j, i))
	ans = min(ans, cur)
print(ans)


from collections import Counter, defaultdict, deque
import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	arr = sorted([int(x) for x in input().split()])
	if n > 100:
		print(sum(arr) - n)
		return
	c = 2
	rec = sum(arr) - n
	while c ** (n - 1) < n * 10 ** 9:
		t = [c ** i for i in range(n)]
		p = 0
		for i in range(n):
			p += abs(t[i] - arr[i])
		rec = min(rec, p)
		c += 1
	print(rec)
tt = 1
for test in range(tt):
	solve()


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
ans = 10 ** 100
cur_ans = 0
prev = 10 ** 100
p = 0
while True:
	cur_ans = 0
	for i in range(n):
		cur_ans += abs(a[i] - p ** i)
	p += 1
	if cur_ans > prev:
		break
	prev = cur_ans
	ans = min(ans, cur_ans)
print(ans)


length = int(input())
arr = sorted(list(map(int, input().split())))
val = int(arr[-1] ** (1 / (length - 1)))
i = 0
z = 0
for (index, x) in enumerate(arr):
	i += abs(x - val ** index)
	z += abs(x - (val + 1) ** index)
print(min(i, z))


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
s1 = 0
s2 = 0
j1 = 0
j2 = 0
c1 = math.ceil(pow(a[-1], 1 / (n - 1)))
c2 = math.floor(pow(a[-1], 1 / (n - 1)))
for i in a:
	s1 = s1 + abs(c1 ** j1 - i)
	j1 = j1 + 1
for i in a:
	s2 = s2 + abs(c2 ** j2 - i)
	j2 = j2 + 1
print(min(s1, s2))


from sys import stdin
input = lambda : stdin.readline().strip()
from collections import deque as d
import math
l = len
n = int(input())
a = sorted(map(int, input().split()))
ma = a[n - 1]
x = ma ** (1 / (n - 1))
p = math.ceil(x)
q = math.floor(x)
cost1 = 0
cost2 = 0
for i in range(n):
	cost1 += abs(p ** i - a[i])
	cost2 += abs(q ** i - a[i])
print(min(cost1, cost2))


from collections import Counter
import math
n = int(input())
l = list(map(int, input().split()))
l.sort()
m = l[-1]
p = m ** (1 / (n - 1))
ans = math.ceil(p)
ans1 = int(p)
c1 = 0
c2 = 0
for i in range(n):
	if ans ** i != l[i]:
		c1 += abs(ans ** i - l[i])
for i in range(n):
	if ans1 ** i != l[i]:
		c2 += abs(ans1 ** i - l[i])
print(min(c1, c2))


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
prev = [float('inf')]
limit = 31624
val = 0
for i in range(limit):
	temp_ans = 0
	for j in range(n):
		temp_ans += abs(i ** j - arr[j])
	if temp_ans < prev[-1]:
		val = i
		prev.append(temp_ans)
	else:
		break
print(prev[-1])


import math
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
a = int(arr[-1] ** (1 / (n - 1))) + 1
minm = float('inf')
c = 0
m = 0
if a ** (len(arr) - 1) < 10 ** 14:
	for i in range(a, 0, -1):
		arr1 = [i ** j for j in range(n)]
		count = 0
		for (e1, e2) in zip(arr1, arr):
			count += abs(e1 - e2)
		if minm >= count:
			minm = count
			c += 1
		m += 1
		if m == 2:
			break
else:
	count = 0
	for i in arr:
		count += abs(1 - i)
	minm = min(count, minm)
print(minm)


import math
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = 10 ** 15
cons = 1
while True:
	val = 0
	for i in range(n):
		val += abs(cons ** i - arr[i])
		if val >= ans:
			val = -1
			break
	if val == -1:
		break
	ans = min(ans, val)
	cons += 1
print(ans)


def pow(a, b):
	res = 1
	while b != 0:
		if b % 2:
			b -= 1
			res *= a
		else:
			b //= 2
			a *= a
	return res
n = int(input())
a = list(map(int, input().split()))
a.sort()
big = 100000000000
out1 = 1000000000000000
out2 = 0
i = 1
while 1:
	out2 = 0
	flag = 0
	for j in range(n):
		zz = pow(i, j)
		if zz > big:
			flag = 1
			break
		out2 += abs(zz - a[j])
	if flag:
		break
	i = i + 1
	out1 = min(out1, out2)
print(out1)


biggest = 1 << 64
n = int(input())
ar = [int(val) for val in input().split()]
ar.sort()

def f(c):
	ret = 0
	nw = 1
	for i in range(n):
		ret += int(abs(ar[i] - nw))
		nw = nw * c
	return ret
if n > 65:
	print(sum(ar) - n)
else:
	c = 2
	mx = 0
	ans = sum(ar) - n
	while 1:
		res = f(c)
		if res > ans:
			break
		ans = res
		c += 1
	print(ans)


def answer(n, A):
	A.sort()
	ans = 10 ** 20
	if n <= 32:
		x = int(A[-1] ** (1 / (n - 1))) + 3
		for i in range(1, x):
			count = 0
			for j in range(n):
				count += abs(A[j] - i ** j)
			ans = min(ans, count)
		return ans
	count = 0
	for i in range(n):
		count += abs(A[i] - 1)
	return count
n = int(input())
A = list(map(int, input().split()))
print(answer(n, A))


n = int(input())
ar = [int(i) for i in input().split()]
ar.sort()
kekw = 10 ** 18
res = sum(ar) - n
for i in range(1, 40000):
	kek = 1
	buf = 0
	for j in range(n):
		buf += abs(ar[j] - kek)
		if buf >= res or kek > kekw // i:
			break
		kek *= i
	res = min(res, buf)
print(res)


n = int(input())
a = list(map(int, input().split()))
a.sort()
i = 1
while i ** (n - 1) < a[-1]:
	i += 1
s1 = 0
s2 = 0
for (j, x) in enumerate(a):
	s1 += abs(i ** j - x)
	s2 += abs((i - 1) ** j - x)
print(min(s1, s2))


import sys

def main():
	n = int(input())
	arr = get_array()
	arr.sort()
	ans = 10 ** 18
	r = 10 ** 5 // n
	for i in range(1, r + 1):
		curr = 0
		x = 0
		for j in arr:
			curr += abs(j - i ** x)
			x += 1
		ans = min(ans, curr)
	print(ans)
get_array = lambda : list(map(int, sys.stdin.readline().split()))
get_ints = lambda : map(int, sys.stdin.readline().split())
input = lambda : sys.stdin.readline().strip()
main()


import math
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
ans = 99999999999999
if n < 100:
	for c in range(1, int(math.sqrt(10 ** 9) + 50)):
		temp = 0
		mul = 1
		for i in a:
			temp += abs(i - mul)
			mul *= c
		ans = min(ans, temp)
else:
	ans = 0
	for i in a:
		ans += abs(i - 1)
print(ans)


import sys
import math
input = sys.stdin.readline

def inInt():
	return int(input())

def inStr():
	return input().strip('\n')

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

def inSList():
	return input().split()

def solve(n, l):
	l.sort()
	c = 1
	m = None
	while True:
		sum = 0
		for x in range(n):
			sum += abs(l[x] - c ** x)
		if m is None:
			m = sum
		elif sum < m:
			m = sum
		else:
			return m
		c = c + 1
n = inInt()
l = inIList()
print(solve(n, l))


def main():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	c = 1
	while c ** (n - 1) < a[n - 1]:
		c += 1
	sum1 = 0
	sum2 = 0
	for i in range(n):
		sum1 += abs(a[i] - c ** i)
		sum2 += abs(a[i] - (c - 1) ** i)
	print(min(sum1, sum2))
main()


import math

def solve(n, ar):
	ar = sorted(ar)
	limit = int(100000.0) * int(1000000000.0) * 2
	ans = math.inf
	for c in range(1, 100000):
		res = 0
		flag = False
		v = 1
		for i in range(n):
			res += abs(v - ar[i])
			v = v * c
			if v > limit:
				flag = True
				break
		if flag:
			continue
		ans = min(ans, res)
	print(ans)
n = int(input())
ar = list(map(int, input().split()))
solve(n, ar)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
s = a[n - 1] ** (1 / (n - 1))
s1 = int(s)
c = [s1 - 1, s1, s1 + 1]
ans = 0
d = []
for i in c:
	ans = 0
	if i != 0:
		for j in range(n):
			ans += abs(a[j] - i ** j)
		d.append(ans)
print(min(d))


def bin_search(x, n):
	beg = 0
	end = 10 ** max(1, 10 - n)
	while beg < end:
		mid = (beg + end) // 2
		if mid ** (n - 1) >= x and (mid - 1) ** (n - 1) < x:
			return mid
		elif (mid - 1) ** (n - 1) >= x:
			end = mid
		else:
			beg = mid + 1
n = int(input())
a = list(map(int, input().split()))
a.sort()
x = a[-1]
c1 = bin_search(x, n)
c2 = c1 - 1
count1 = 0
count2 = 0
for i in range(0, n):
	count1 = count1 + abs(a[i] - c1 ** i)
	count2 = count2 + abs(a[i] - c2 ** i)
print(min(count1, count2))


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
(l, r) = (1, int(10 ** (9 / (n - 1))) + 1)
while l < r:
	mid = (l + r) // 2
	cost1 = 0
	cost2 = 0
	for i in range(n):
		cost1 += abs(mid ** i - arr[i])
		cost2 += abs((mid + 1) ** i - arr[i])
	if cost1 > cost2:
		l = mid + 1
	else:
		r = mid
res = 0
for i in range(n):
	res += abs(l ** i - arr[i])
print(res)