Problem:


Score : 300 points

Problem Statement

Snuke has an integer sequence A of length N.

He will freely choose an integer b.
Here, he will get sad if A_i and b+i are far from each other.
More specifically, the sadness of Snuke is calculated as follows:

abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))

Here, abs(x) is a function that returns the absolute value of x.

Find the minimum possible sadness of Snuke.

Constraints

1 \leq N \leq 2 \times 10^5

1 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the minimum possible sadness of Snuke.

Sample Input 1

5
2 2 3 5 5

Sample Output 1

2

If we choose b=0, the sadness of Snuke would be abs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2.
Any choice of b does not make the sadness of Snuke less than 2, so the answer is 2.

Sample Input 2

9
1 2 3 4 5 6 7 8 9

Sample Output 2

0

Sample Input 3

6
6 5 4 3 2 1

Sample Output 3

18

Sample Input 4

7
1 1 1 1 2 3 4

Sample Output 4

6



Sample input:
5
2 2 3 5 5


Sample output:
2

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
total = 0
for i in range(n):
    a[i] = a[i] - (i + 1)
if n % 2 == 0:
    ave = a[int(n/2)]
    for i in range(n):
        total += abs(a[i] - ave)
    print(total)
else:
    total2 = 0
    ave = a[int(n/2)]
    for i in range(n):
        total += abs(a[i] - ave)
    ave = a[int((n + 1)/2)]
    for i in range(n):
        total2 += abs(a[i] - ave)
    if total2 >= total:
        print(total2)
    else:
        print(total)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
total = 0
for i in range(n):
    a[i] = a[i] - (i + 1)
if n % 2 == 0:
    ave = a[int(n/2)]
else:
    ave = int((a[int(n/2)] + a[int((n + 1)/2)]) / 2)
for i in range(n):
    total += abs(a[i] - ave)
print(total)

Submission status: Runtime Error

Solution code:
# ABC102-C
import numpy as np
import statistics
N = int(input())
A = list(map(int, input().split()))
B = np.array(range(1, N+1))
A = np.array(A)
C = abs(A - B)
b = int(round(statistics.mode(C)))
print(sum(abs(C - b)))

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(i) for i in input().split()]

val = []

for i in range(n):
    val.append(a[i]-i)

val.sort()
#print(val)

#idx = [(val[0],0)]
idx = []
cnt = 1
for i in range(n-1):
    if val[i] == val[i+1]:
        #cnt += 1
        if i == n-2:
            idx.append((val[i],i+2))
        continue
    else:
        if i == n-2:
            idx.append((val[i],i+1))
            idx.append((val[i+1],i+2))
        else:
           idx.append((val[i],i+1)) 
        #cnt = 1
        
ans_val = 0
ans2_val = 0
ans3_val = 0

flag2 = False
flag3 = False

for i in range(len(idx)):
    if idx[i][1] >= (n) // 2:
        ans_val = idx[i][0]
        
        #print(i-1)
        if i-1 >= 0:
            flag2 = True
            ans2_val = idx[i-1][0]
        
        if i+1 <= n-1:
            flag3 = True
            ans3_val = idx[i+1][0]
        
        break

#print(idx,ans_val,ans2_val)
#exit()
     
ans = 0
ans2 = 10**20
ans3 = 10**20
for i in range(n):
    ans += abs(a[i]-ans_val-i)
    if flag2 == True:
        ans2 += abs(a[i]-ans2_val-i)
    if flag3 == True:
        ans3 += abs(a[i]-ans3_val-i)
    


print(min(ans,ans2,ans3))

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(i) for i in input().split()]

val = []

for i in range(n):
    val.append(a[i]-i)

val.sort()
#print(val)

#idx = [(val[0],0)]
idx = []
cnt = 1
for i in range(n-1):
    if val[i] == val[i+1]:
        #cnt += 1
        if i == n-2:
            idx.append((val[i],i+2))
        continue
    else:
        if i == n-2:
            idx.append((val[i],i+1))
            idx.append((val[i+1],i+2))
        else:
           idx.append((val[i],i+1)) 
        #cnt = 1
        
ans_val = 0
ans2_val = 0
ans3_val = 0

flag2 = False
flag3 = False

for i in range(len(idx)):
    if idx[i][1] >= (n) // 2:
        ans_val = idx[i][0]
        
        #print(i-1)
        if i-1 >= 0:
            flag2 = True
            ans2_val = idx[i-1][0]
        
        if i+1 <= n-1:
            flag3 = True
            ans3_val = idx[i+1][0]
        
        break

#print(idx,ans_val,ans2_val)
#exit()
     
ans = 0
ans2 = 0
ans3 = 0
for i in range(n):
    ans += abs(a[i]-ans_val-i)
    ans2 += abs(a[i]-ans2_val-i)
    ans3 += abs(a[i]-ans3_val-i)
    

print(min(ans,ans2,ans3))

Submission status: Runtime Error

Solution code:
N=int(input())
A = list(map(int, input().split()))
X=[]
ans=0
import copy
B = copy.deepcopy(A)
for i in range(N):
  A[i]=A[i]-(i+1)
A.sort()
s=int(N/2)
if N%2==0:
    for i in range(A[s-1],A[s+1]+1):
        S=0
        for j in range(N):
            S=S+abs(B[j]-(i+j+1))
        X.append(S)
    print(min(X))
else:
    for i in range(A[s-1],A[s+1]+1):
        S=0
        for j in range(N):
            S=S+abs(B[j]-(i+j+1))
        X.append(S)
    print(min(X))

Submission status: Runtime Error

Solution code:
N=int(input())
A = list(map(int, input().split()))
X=[]
ans=0
import copy
B = copy.deepcopy(A)
for i in range(N):
  A[i]=A[i]-(i+1)
A.sort()
s=int(N/2)
if N%2==0:
    for i in range(A[s-1],A[s+1]):
        S=0
        for j in range(N):
            S=S+abs(B[j]-(i+j+1))
        X.append(S)
    print(min(X))
else:
    for i in range(A[s-1],A[s+1]):
        S=0
        for j in range(N):
            S=S+abs(B[j]-(i+j+1))
        X.append(S)
    print(min(X))

Submission status: Runtime Error

Solution code:
N=int(inpur())
A = list(map(int, input().split()))
X=[]
ans=0
import copy
B = copy.deepcopy(A)
for i in range(N):
  A[i]=A[i]-(i+1)
A.sort()
s=int(N/2)
if N%2==0:
    for i in range(A[s-1],A[s+1]):
        S=0
        for j in range(N):
            S=S+abs(B[j]-(i+j+1))
        X.append(S)
    print(min(X))
else:
    for i in range(A[s-1],A[s+1]):
        S=0
        for j in range(N):
            S=S+abs(B[j]-(i+j+1))
        X.append(S)
    print(min(X))

Submission status: Runtime Error

Solution code:
n,*l=map(int,open(0).read().split())
a=sorted([l[i]-i-1for i in range(n)])
f=lambda x:sum(abs(l[i]-i-1-x)for i in range(n))
print(min(f(a[n//2]),f(a[n//2+1])))

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(b) for b in input().split()]
sa = []
for i, v in enumerate(a):
    sa.append(v - (i + 1))
min = sum(sa)
shift = -1 if min > -1 else 1

while(True):
    sa = [c + shift for c in sa]
    print (sa)
    if ((abs(sum(sa)) < n) and sum(sa) > 0):
        print (abs(sum(sa)))
        break

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = [A[i]-i for i in range(N)]
S = sorted(B)

res = 0
if N%2 == 1:
    b = S[(N-1)//2]#中央値
    for i in range(N):
        res += abs(B[i]-b)
else:
    medint1 = N//2
    medint2 = N//2-1
    med1 = S[medint1]
    med2 = S[medint2]
    for i in range(N):
        t1 += abs(B[i]-med1)
        t2 += abs(B[i]-med2)
    res = min(t1,t2)
print(res)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= i+1
b = sorted(a)
center1 = b[n//2+1]
center2 = 0
if not n == 1:
    center2 = b[n//2]
buf1 = 0
buf2 = 0
for i in range(n):
    buf1 += abs(b[i]-center1)
    buf2 += abs(b[i]-center2)
print(int(min(buf1, buf2)))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= i+1
b = sorted(a)
center1 = b[n//2+1]
center2 = b[n//2]
buf1 = 0
buf2 = 0
for i in range(n):
    buf1 += abs(b[i]-center1)
    buf2 += abs(b[i]-center2)
print(int(min(buf1, buf2)))

Submission status: Runtime Error

Solution code:
from functools import reduce
import math
import collections

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    A = list(int(_) for _ in input().split())
    A_fixed = []
    for i in range(N):
        A_fixed.append(A[i]-i-1)
    cnt = 0
    B = A_fixed.sorted()
    b = B[N//2]
    for i in range(N):
        cnt += abs(b-A_fixed[i])
    # print(A_fixed)
    # print(b)
    print(cnt)    
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math

N=int(input())
A=list(map(int,input().split()))

for i in range(N):
    A[i]-=i+1
A.sort()
a=N//2

def sad(A,a):
    sadness=0
    for i in range(N):
        sadness+=abs(A[i]-A[a])
    return sadness

if N//2==0:
    ans=min(sad(A,a),sad(A,a+1))
else:
    ans=sad(A,a)
print(ans)

Submission status: Runtime Error

Solution code:
import math

N=int(input())
A=list(map(int,input().split()))

for i in range(N):
    A[i]-=i+1
A.sort()
a=N//2

def sad(A,a):
    sadness=0
    for i in range(N):
        sadness+=abs(A[i]-A[a])
    return sadness

print(min(sad(A,a),sad(A,a+1)))

Submission status: Runtime Error

Solution code:
n = int(input())
dat = list(map(int, input().split()))
dat_d = []

total = 0
for i in range( n):
    total += (dat[i] - (i+1))
    dat_d.append(dat[i] - (i+1))

#print(dat)
#print(dat_d)
#print(total)
#f = (total // n)
#print(f)

f = (dat_d[n//2])
dat_d = list(map(lambda x: x - f, dat_d))
total = 0
for i in range(n):
    total += abs(dat_d[i])

f = (dat_d[n//2 + 1])
dat_d = list(map(lambda x: x - f, dat_d))
total2 = 0
for i in range(n):
    total2 += abs(dat_d[i])

total = min(total, total2)

print(total)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
A = list(map(int, input().split()))
A = [A[i]-(i+1) for i in range(n)]
#print(A)
A.sort()
i = n/2
a,b = A[math.floor(i)], A[math.ceil(i)]
ans,ans1=0,0
for i in A:
    ans += abs(i-a)
    ans1 += abs(i-b)
print(min(ans,ans1))

Submission status: Runtime Error

Solution code:
N = int(input())
a_lis = list(map(int, input().split()))

maximum = max(a_lis)
minimum = min(a_lis)


new_mx = maximum - N + 1
count = [0] * (max(new_mx, minimum) + 1 - min(new_mx, minimum))
for num in range(min(new_mx, minimum), max(new_mx, minimum) + 1):
    tmp = 0
    for i in range(N):
        tmp += abs(a_lis[i] - num - i)
    count[num - min(new_mx, minimum)] = tmp
print(min(count))

Submission status: Runtime Error

Solution code:
import statistics

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

b = [a[i] - i for i in range(N)]
median = statistics.median(b)

ans = 0
for i in range(N):
    ans += abs(b[i] - int(median))

print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
SA=sum(A)

sum=[(i**2+i)//2 for i in range(2*10**5)]

i=0
while sum[i]<SA:
    i+=1

# print(sum[:20])
# print(i)

ans1=0
ans2=0
for j in range(N):
    ans1+=abs(A[j]-(i-N+j))
    ans2+=abs(A[j]-(i-N+j+1))

print(min(ans1,ans2))

Submission status: Runtime Error

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
result=N*10**9
for i in range(N/2):
  result_tmp=N*10**9
  for j in range(N):
    result_tmp+=abs(A[j]-(b+j+1))
  if result>result_tmp:
    result=result_tmp
print(result)

Submission status: Runtime Error

Solution code:
import statistics

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

for i in range(n):
  a[i] = a[i] - (i + 1)


a.sort()
med = statistics.median(a)

n = 0

for ai in a:
  n += abs(ai - med)

print(n)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))

A = [A[i] - i - 1 for i in range(N)]
A = sorted(A)
indx = int(len(A) / 2)

b = sum([abs(a - A[indx]) for a in A])
b1 = sum([abs(a - A[indx-1]) for a in A])
b2 = sum([abs(a - A[indx+1]) for a in A])

print(min([b, b1, b2]))

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(x-i-1) for i,x in enumerate(input().split())]

if len(a)%2==1:
    md = a[len(a)//2]
    ans = 0
    for i in a:
        ans += abs(i-md)
    print(ans)
else:
    md1 = a[len(a)//2]
    md2 = a[len(a)//2]
    ans1 = 0
    ans2 = 0
    for i in a:
        ans1 += abs(i-md1)
        ans2 += abs(i-md2)
    print(min(ans1,ans2))

Submission status: Runtime Error

Solution code:
N = int(input())
Alist = list(map(int, input().split()))
Alist = [Alist[i] - (i+1) for i in range(N)]
Alist.sort()

sumlist = []
for i in range(N-1):
    if i < N // 2:
        sumlist.append(- sum(Alist[:i+1]) + sum(Alist[i+1:]) - Alist[i+1] * (N - 2 * (i + 1)))
    else:
        sumlist.append(- sum(Alist[:i+1]) + sum(Alist[i+1:]) + Alist[i] * (N - 2 * (N - i - 1)))
    
print(min(sumlist))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = []

for b in range(,):
    for b in range(1,n+1):
        for i in range(n):
            temp = abs(a[i] - (1 + b))

Submission status: Runtime Error

Solution code:
import bisect as bi

N = int(input())
A = [int(t) for t in input().split()]

A = sorted([A[i]-i-1 for i in range(N)])

nega_cnt = bi.bisect_left(A, 0)
posi_cnt = N - bi.bisect_right(A, 0)
zero_cnt = N - nega_cnt - posi_cnt


def calc():
    if nega_cnt + zero_cnt >= posi_cnt and posi_cnt + zero_cnt >= nega_cnt:
        return sum([abs(t) for t in A])

    if posi_cnt > nega_cnt + zero_cnt:
        idx = (posi_cnt-(nega_cnt + zero_cnt) - 1) // 2 + 1
        a = A[-posi_cnt:][idx]
        return sum([abs(t-a) for t in A])

    if posi_cnt + zero_cnt < nega_cnt:
        idx = (nega_cnt-(posi_cnt + zero_cnt))//2 + 1
        a = A[:nega_cnt][-idx]
        return sum([abs(t-a) for t in A])


print(calc())

Submission status: Runtime Error

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

for k in range(N):
    A[k] -= k

A.sort()


def get_pity_sum(x):
    pity_sum = 0
    for l in A:
        if A[x] - l >= 0:
            pity_sum += A[x] - l
        else:
            pity_sum += l - A[x]
    return pity_sum


if N % 2 == 1:
    c = get_pity_sum(int((N - 1) / 2))
    if N == 1:
        print(c)
    print(min(c, get_pity_sum(int((N - 1) / 2 - 1)), c + (A[int((N - 1) / 2) + 1] - A[int((N - 1) / 2)]) * 2, c + (A[int((N - 1) / 2)] - A[int((N - 1) / 2 - 1)]) * 2))
else:
    d = get_pity_sum(int(N / 2))
    print(min(get_pity_sum(int(N / 2)), d + (A[int(N / 2) + 1] - A[int(N / 2)]) * 2))

Submission status: Runtime Error

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

for k in range(N):
    A[k] -= k

A.sort()


def get_pity_sum(x):
    pity_sum = 0
    for l in A:
        if A[x] - l >= 0:
            pity_sum += A[x] - l
        else:
            pity_sum += l - A[x]
    return pity_sum


if N % 2 == 1:
    c = get_pity_sum(int((N - 1) / 2))
    print(min(c, get_pity_sum(int((N - 1) / 2 - 1)), c + (A[int((N - 1) / 2) + 1] - A[int((N - 1) / 2)]) * 2, c + (A[int((N - 1) / 2)] - A[int((N - 1) / 2 - 1)]) * 2))
else:
    d = get_pity_sum(int(N / 2))
    print(min(get_pity_sum(int(N / 2)), d + (A[int(N / 2) + 1] - A[int(N / 2)]) * 2))

Submission status: Runtime Error

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

for k in range(N):
    A[k] -= k

A.sort()


def get_pity_sum(x):
    pity_sum = 0
    for l in A:
        if A[x] - l >= 0:
            pity_sum += A[x] - l
        else:
            pity_sum += l - A[x]
    return pity_sum


if N % 2 == 1:
    c = get_pity_sum(int((N - 1) / 2))
    print(min(c, get_pity_sum(int((N - 1) / 2 - 1)), c + (A[int((N - 1) / 2) + 1] - A[int((N - 1) / 2)]) * 2, c + (A[int((N - 1) / 2)] - A[int((N - 1) / 2 - 1)]) * 2))
else:
    print(min(get_pity_sum(int(N / 2)), get_pity_sum(int(N / 2 - 1))))

Submission status: Runtime Error

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

for k in range(N):
    A[k] -= k

A.sort()


def get_pity_sum(x):
    pity_sum = 0
    for l in A:
        if A[x] - l >= 0:
            pity_sum += A[x] - l
        else:
            pity_sum += l - A[x]
    return pity_sum


if N % 2 == 1:
    print(min(get_pity_sum(int((N - 1) / 2)), get_pity_sum(int((N - 1) / 2 - 1)), get_pity_sum(int((N - 1) / 2 + 1))))
else:
    print(min(get_pity_sum(int(N / 2)), get_pity_sum(int(N / 2 - 1))))

Submission status: Runtime Error

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

for k in range(N):
    A[k] -= k

A.sort()


def get_pity_sum(x):
    pity_sum = 0
    for l in A:
        if A[x] - l >= 0:
            pity_sum += A[x] - l
        else:
            pity_sum += l - A[x]
    return pity_sum


if N % 2 == 1:
    print(min(get_pity_sum(int((N - 1) / 2)), get_pity_sum(int((N - 1) / 2 - 1)), get_pity_sum(int((N - 1) / 2 + 1))))
else:
    print(min(get_pity_sum(int(N / 2)), get_pity_sum(int(N / 2 - 1)), get_pity_sum(int(N / 2 - 2))))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))

ans = 0
for i in range(N):
    A[i] -= i+1

b_index = N // 2

def regret(A, b):
    result = 0
    for a in A:
        result += abs(a-b)
    return result

print(min(regret(A, A[b_index]), regret(A, A[b_index+1])))

Submission status: Runtime Error

Solution code:
n = int(input())
A = [int(i) for i in input().split()] 

def sadness(A, b):
  sad = sum([abs(a - (b + (i+1))) for i, a in enumerate(A)])
  return sad

def moveb(A):
  global b
  thresh_up = sadness(A, b) - sadness(A, b + 1)
  thresh_dw = sadness(A, b) - sadness(A, b - 1)
  if ((thresh_up > 0) and (thresh_dw < 0)):
    b -= 1
  elif ((thresh_up < 0) and (thresh_dw > 0)):
    b += 1
  elif ((thresh_up < 0) and (thresh_dw < 0)):
    return 'success'
  return 'calculating'
  

b = 0
ans = ''
while ans != 'success':
  ans =  moveb(A)

print (sadenss(A, b))

Submission status: Runtime Error

Solution code:
n = int(input())
A = [int(i) for i in input().split()] 

def sadness(A, b):
  sad = sum([abs(a - (b + (i+1))) for i, a in enumerate(A)])
  return sad

def moveb(A):
  global b
  thresh_up = sadness(A, b) - sadness(A, b + 1)
  thresh_dw = sadness(A, b) - sadness(A, b - 1)
  if (thresh_up > 0) && (thresh_dw < 0):
    b -= 1
  elif (thresh_up < 0) && (thresh_dw > 0):
    b += 1
  elif (thresh_up < 0) && (thresh_dw < 0):
    return 'success'
  return 'calculating'
  

b = 0
ans = ''
 while ans != 'success':
    ans =  moveb(A)

print (sadenss(A, b))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    A[i] = A[i] - (i+1)

A = sorted(A)
m = float('inf')
for b in [A[N//2-1], A[N//2], A[N//2+1]]:
    diff = sum(list(map(lambda x: abs(x-b),A)))
    m = min(m,diff)

print(m)

Submission status: Runtime Error

Solution code:
def main():
	N = int(input())
	A = list(map(int, input().split()))
	for i in range(N):
		A[i] -= i+1
	A.sort()

	mid1 = A[N//2]
	mid2 = A[N//2 + 1]
	ans1 = 0
	ans2 = 0
	for i in range(N):
		ans1 += abs(A[i] - mid1)
		ans2 += abs(A[i] - mid2)

	print(min(ans1, ans2))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
B = []
for i in range(N):
  B.append(A[i]-i-1)
B.sort()
b = B[2//N]
ans = 0
for a in B:
  ans += abs(b-a)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
b = sorted([a-i for i,a in enumerate(A,1)])

minus = 0
plus = 0
for c in b:
    if c <0:
        minus +=1
    elif c >0:
        plus +=1

m1 = b[N//2]
m2 = b[N//2+1]
out = min(sum([abs(c-m1) for c in b]),sum([abs(c-m2) for c in b]))
print(out)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
b = sorted([b-i for i,b in enumerate(A,1)])

minus = 0
plus = 0
for i,c in enumerate(b,1):
    if c <0:
        minus +=1
    elif c >0:
        plus +=1

m = b[(N-minus+plus)//2]
out = sum([abs(c-m) for c in b])
print(out)

Submission status: Runtime Error

Solution code:
N = int(input())
A = map(int, input().split())
kn = 0
for b in range(len(A)):
  kn += abs(A[b] - (0 + b))
print(kn)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
 
import sys
sys.setrecursionlimit(1000000)
 
N = int(input())
A = list(map(int, input().rstrip().split(' ')))
 
A_dash = [x - i - 1 for i, x in enumerate(A)]
 
def recursive(X):
    if len(X) == 1:
        return sum([abs(x - X[0]) for x in A_dash])
    elif len(X) == 2:
        if sum([abs(x - X[1]) for x in A_dash]) - sum([abs(x - X[0]) for x in A_dash]) > 0:
            return sum([abs(x - X[0]) for x in A_dash])
        else:
            return sum([abs(x - X[1]) for x in A_dash])
        
    if sum([abs(x - X[len(X)//2]) for x in A_dash]) - sum([abs(x - X[len(X)//2 - 1]) for x in A_dash]) < 0:
        return recursive(X[len(X)//2:])
    else:
        return recursive(X[:len(X)//2 + 1])
 
print(recursive(list(range(min(A_dash), max(A_dash) + 1))))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

N = int(input())
A = list(map(int, input().rstrip().split(' ')))

A_dash = [x - i - 1 for i, x in enumerate(A)]

def recursive(X):
    if len(X) == 1:
        return sum([abs(x - X[0]) for x in A_dash])
    elif len(X) == 2:
        if sum([abs(x - X[1]) for x in A_dash]) - sum([abs(x - X[0]) for x in A_dash]) > 0:
            return sum([abs(x - X[0]) for x in A_dash])
        else:
            return sum([abs(x - X[1]) for x in A_dash])
        
    if sum([abs(x - X[len(X)//2]) for x in A_dash]) - sum([abs(x - X[len(X)//2 - 1]) for x in A_dash]) < 0:
        return recursive(X[len(X)//2:])
    else:
        return recursive(X[:len(X)//2 + 1])

print(recursive(list(range(min(A_dash), max(A_dash) + 1))))

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
  a[n]-=i
x=sum(a)//n
ans=0
for i in a:
  ans+=abs(i-x)
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
  a[n]-=i
x=sum(a)//n
ans=0
for i in a:
  ans+=abs(i-b)
print(ans)

Submission status: Runtime Error

Solution code:
from statistics import mean
N = int(input())
A = list(map(int,input().split()))

#b : bias 
#Aの列を x + b　と最も近く近似できるバイアスbを探索

b = round(mean(A) - (N+1)/2)

minimum = b-100
maximum = max(A)

Loss = [0] * (maximum-minimum)
for i in range(minimum,maximum):
    sumsum =0
    for j in range(N):
        sumsum += abs(A[j]-(i+j+1))
    Loss[i-minimum] = sumsum
    
print(min(Loss))

Submission status: Runtime Error

Solution code:
from statistics import mean
N = int(input())
A = list(map(int,input().split()))

#b : bias 
#Aの列を x + b　と最も近く近似できるバイアスbを探索

b = round(mean(A) + (N+1)/2)

minimum = b-100
maximum = max(A)

Loss = [0] * (maximum-minimum)
for i in range(minimum,maximum):
    sumsum =0
    for j in range(N):
        sumsum += abs(A[j]-(i+j+1))
    Loss[i-minimum] = sumsum
    
print(min(Loss))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = [A[i] - (i+1) for i in range(N)]

B.sort()

print(sum(abs(x - B[2//N]) for x in B))

Submission status: Runtime Error

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
for i in range(N):
  A[i]=A[i]-1-i
b=A[N//2]
c=A[(N//2)+1]
ans1,ans2=0,0
for i in range(N):
  ans1+=abs(A[i]-b)
  ans2+=abs(A[i]-c)
print(min(ans1,ans2))

Submission status: Runtime Error

Solution code:
#from collections import Counter
import math
N=int(input())
A=list(map(int,input().split()))
l=[]
n=1
for i in A:
    l.append(i-n)
    n+=1
l.sort()
#中央値
#切り捨て
c=int(math.floor(N/2))
b=A[c]
ans_l=[]
ans=0
for j in l:
    ans+=abs(j-l[b])

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int, input().split()))
a_ = [n - (i+1) for i, n in enumerate(a) ]

b = sum(a_) // N
b_ = b + 1
s = [abs(n - b) for i, n in enumerate(a_)]
s_ = [abs(n - b_) for i, n in enumerate(a_)]

print(min(sum(s), sum(s_))

Submission status: Runtime Error

Solution code:
n=int(input())

X=list(map(int,input().split()))
Y=[]
for i in range(n):
    Y.append(X[i]-(i+1))
Y.sort()
res_1=0
res_2=0
if n%2==1:
    m=Y[int((n-1)/2)]
    for j in range(n):
        res_1+=abs(Y[j]-m)
else:
    m=Y[int(n/2)-1]
    n=Y[int(n/2)]
    for j in range(n):
        res_1+=abs(Y[j]-m)
        res_2+=abs(Y[j]-n)
    res_1=min(res_1,res_2)
        
    

print(res_1)

Submission status: Runtime Error

Solution code:
a,b,c=map(int,input().split())

X=[a,b,c]
X.sort()
x=X[2]
y=X[1]
z=X[0]


sabun1=x-y
sabun2=x-z

if sabun1%2==0 and sabun2%2==0:
    res=(sabun1+sabun2)/2
elif sabun1%2==1 and sabun2%2==1:
    res=(sabun1//2+sabun2//2)+1
elif sabun1%2==0 and sabun2%2==1:
    res=(sabun1/2)+(sabun2//2)+2
else:
    res=(sabun1//2)+(sabun2/2)+2

print(int(res))

Submission status: Runtime Error

Solution code:
N = int(input())
L = list(map(int,input().split()))
for i in range(N):
    L[i] = L[i] - (i+1)
L = sorted(L)
#print(L)
ans = 0
import statistics 
med = int(statistics.median(L))
#print(med)
for i in range(N):
    ans+=abs(L[i]-med)
print(ans)

Submission status: Runtime Error

Solution code:
import statistics


N = int(input())
A = list(map(int, input().split()))

A = [a - i for i, a in enumerate(A)]

M = int(statistics.median(A_b))
R = []

for m in [M-2, M-1, M, M+1, M+2]:
    R.append(sum([abs(a - m) for a in A]))

print(min(R))

Submission status: Runtime Error

Solution code:
import statistics


N = int(input())
A = list(map(int, input().split()))

A = [a - i for i, a in enumerate(A)]

M = int(statistics.median(A_b))
R = []

for m in [M-2. M-1, M, M+1, M+2]:
    R.append(sum([abs(a - m) for a in A]))

print(min(R))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
Asort = sorted([A[i]-i-1 for i in range(N)])

if N%2 == 0:
    b_tmp = Asort[N//2]
else:
    b_tmp = (Asort[N//2] + Asort[N//2 + 1])// 2
# print(b_tmp)
minA = 10**9
for b in range(b_tmp-1,b_tmp+2):
    submin = [abs(A[i]-b-i-1) for i in range(N)]
    # print(submin)
    minA = min(sum(submin),minA)

print(minA)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
for x in range(N):
    A[x] -= (x+1)

sorted_A = sorted(A)

if N % 2 == 1:
    ans = sum(map(lambda x: abs(x-sorted_A[N//2+2]),A))
    for x in range(sorted_A[N//2],sorted_A[N//2+2]):
        y = sum(map(lambda z: abs(z -x),A))
        if ans > y :
            ans = y
else:
    ans = sum(map(lambda x: abs(x-sorted_A[N//2+1]),A))
    for x in range(sorted_A[N//2],sorted_A[N//2+1]):
        y = sum(map(lambda z: abs(z -x),A))
        if ans > y :
            ans = y
    
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
A_list = list(map(int, input().split()))
for i in range(n):
    A_list[i] -= i
A_list.sort()
A_cum = [0] * n
for i in range(n):
    if i == 0:
        A_cum[0] = A_list[0]
    else:
        A_cum[i] = A_cum[i-1] + A_list[i]

def findinfindex(sortedlist, key, l, r):
    if r - l <= 0:
        return l
    m = (l+r+1)//2
    if sortedlist[m] > key:
        return findinfindex(sortedlist, key, l, m-1)
    else:
        return findinfindex(sortedlist, key, m, r)

sadmin = -1
for b in range(A_list[n//2],A_list[(n+1)//2]+1):
    lastminus = findinfindex(A_list, b, 0, n-1)
    sadness = (2*lastminus - n + 2)*b - 2*A_cum[lastminus] + A_cum[n-1]
    if sadmin == -1:
        sadmin = sadness
    elif sadness < sadmin:
        sadmin = sadness
    else:
        break
print(sadmin)

Submission status: Runtime Error

Solution code:
n = int(input())
A_list = list(map(int, input().split()))
for i in range(n):
    A_list[i] -= i
A_list.sort()
A_cum = [0] * n
for i in range(n):
    if i == 0:
        A_cum[0] = A_list[0]
    else:
        A_cum[i] = A_cum[i-1] + A_list[i]
def findinfindex(sortedlist, key, l, r):
    if r - l <= 0:
        return l
    m = (l+r+1)//2
    if sortedlist[m] > key:
        return findinfindex(sortedlist, key, l, m-1)
    else:
        return findinfindex(sortedlist, key, m, r)
sadmin = -1
for b in range(A_list[n//2],A_list[(n+1)//2]+1):
    lastminus = findinfindex(A_list, b, 0, n-1)
    sadness = (2*lastminus - n + 2)*b - 2*A_cum[lastminus] + A_cum[n-1]
    if sadmin == -1:
        sadmin = sadness
    elif sadness < sadmin:
        sadmin = sadness
    else:
        break
print(sadmin)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    a[i]=a[i]-(i+1)
a.sort()
b=0
c=0
if n%2==0:
    for i in range(n):
        b+=abs(a[i]-a[n//2])
    for j in range(n):
        c+=abs(a[i]-a[n//2+1])
    print(min(b,c))
else:
    for i in range(n):
        b+=abs(a[i]-a[n//2+1])
    print(b)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = []

for i in range(N):
    B.append(A[i] - i - 1)

B = sorted(B)
M = B[int((N + 1)/2)]
ans = 0

for i in range(N):
    t = B[i] - M
    if t < 0:
        t = (-1) * t
    ans += t

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = []

for i in range(N):
    B.append(A[i] - i)

B = sorted(B)
M = B[int((N + 1)/2)]
ans = 0

for i in range(N):
    t = B[i] - M
    if t < 0:
        t = (-1) * t
    ans += t

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = []

for i in range (N):
    B[i] = A[i]- i

B = sorted(B)
M = B[int((N + 1)/2)]
ans = 0

for i in range(N):
    t = B[i] - M
    if t < 0:
        t = (-1) * t
    ans += t

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())))
M = int((N + 1)/2)
ans = 0

for i in range(N):
    t = A[i] - A[M]
    if t < 0:
        t = (-1) * t
    ans += t

print(ans)

Submission status: Runtime Error

Solution code:
import statistics
N = int(input())
A = list(map(int, input().split()))

for i in range(N):
	A[i] = A[i] - (i+1)
A.sort()

b = statistics.median(A)

ans = 0

for i in range(N):
	ans += abs(A[i] - b)
print(ans

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))

for i in range(N):
	A[i] = A[i] - (i+1)
A.sort()
ans = 10000000000000000000000000000000

def dis(a):
	return abs(a - b)

r = np.arange(min(A), max(A)+1)
for b in r:
	l = list(map(dis, A))
	ans = min(sum(l), ans) 

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
A=list(map(int,input().split()))
q=0
Z=[]
t=min(A)
for b in range(int((max(A)-min(A))//2)):
  q=0
  for j in range(n):
    q+=abs(A[j]-b-t-j-1)
  Z.append(q)
print(min(Z))

Submission status: Runtime Error

Solution code:
n=int(input())
A=list(map(int,input().split()))
q=0
Z=[]
for b in range(max(A)-min(A)):
  q=0
  for j in range(n):
    q+=abs(A[j]-b-min[A]-j-1)
  Z.append(q)
print(min(Z))