description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | n = int(input())
a = [int(i) for i in input().split()]
a.sort()
mn = int(1e18)
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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR LIST IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF NUMBER VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR IF VAR BIN_OP NUMBER NUMBER IF VAR BIN_OP NUMBER NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
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\}$. | 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 = 1e18
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)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
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\}$. | 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)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
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\}$. | 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) > 1e16:
ok = 0
break
if s > 1e16:
ok = 0
break
s += abs(pow(i, j) - ar[j])
if not ok:
break
ans = min(ans, s)
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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(9e18 ** (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(9e18)
for i in range(l, r + 1):
res = min(res, check(a, i))
print(res) | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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 ASSIGN VAR VAR VAR VAR VAR VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR WHILE NUMBER IF VAR VAR UNKNOWN NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR UNKNOWN NUMBER ASSIGN VAR NUMBER IF VAR VAR UNKNOWN NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER VAR IF VAR VAR NUMBER UNKNOWN NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF NONE IF VAR NONE ASSIGN VAR VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
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\}$. | 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() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR |
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\}$. | 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) | FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR STRING NUMBER NUMBER WHILE VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
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\}$. | 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 ASSIGN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER BIN_OP VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
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\}$. | 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 | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR IF VAR BIN_OP NUMBER NUMBER IF VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
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\}$. | 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") | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING |
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\}$. | 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() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
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\}$. | 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) | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF STRING VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR VAR FUNC_DEF WHILE VAR EXPR VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER EXPR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
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\}$. | 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)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
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\}$. | 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() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR RETURN VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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(1e20):
break
else:
ans = min(ans, tsum)
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | IMPORT ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR RETURN VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
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\}$. | 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() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR BIN_OP NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR |
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\}$. | 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)) | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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)) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | def problem(A, c):
ans = 0
k = 1
for i in range(len(A)):
ans += abs(k - A[i])
k = k * c
if k > 1e18:
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) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR IF VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR |
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\}$. | 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)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER VAR VAR RETURN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
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\}$. | 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() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER |
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\}$. | 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) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
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\}$. | 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)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
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\}$. | 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)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
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\}$. | 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)),
)
) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR |
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\}$. | INF = int(1e18)
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) | ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
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\}$. | 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() | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
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\}$. | 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 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER WHILE VAR NUMBER VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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:])) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | n = int(input())
arr = list(map(int, input().split()))
arr.sort()
x = int(arr[-1] ** (1 / n))
ans = [1e30]
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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR LIST NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
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\}$. | 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 = 1e18
for i in range(l, min(r + 1, l + 11)):
ans = min(ans, cal(i))
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
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\}$. | 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)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | n = int(input())
a = list(map(int, input().split()))
a.sort()
mini = 1e40
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 >= 1e20:
check = True
break
if check:
break
mini = min(mini, sum)
print(int(mini)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
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\}$. | 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)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
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\}$. | 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)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
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\}$. | n = int(input())
arr = [int(x) for x in input().split()]
best = int(1e18 + 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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 = 1e19
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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER |
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\}$. | 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()) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER RETURN BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
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\}$. | 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)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
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\}$. | 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() | ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
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\}$. | 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)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER WHILE NUMBER VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
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\}$. | 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 FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF NONE RETURN VAR NONE FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
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\}$. | 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 > 1e20:
cur = 1e20
break
ans = min(ans, cur)
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR IF VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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\}$. | 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))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.