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: Wrong Answer

Solution code:
import collections

def calc_score(key):
    return sum([abs(b - key) for b in bList])

def calc_center():
    ans = 0
    for pair in scList:
        ans += pair[0]*pair[1]
    ans = ans / N
    return ans
  
N = int(input().strip())
aList = list(map(int, input().strip().split(" ")))

bList = [a - i - 1 for i,a in enumerate(aList)]
cList = collections.Counter(bList)

ans = 1000000

scList = cList.most_common()

center = calc_center()
print(min(calc_score(int(center)), calc_score(int(center)+1)))

Submission status: Wrong Answer

Solution code:
import collections

def calc_score(key):
    return sum([abs(b - key) for b in bList])

N = int(input().strip())
aList = list(map(int, input().strip().split(" ")))

bList = [a - i - 1 for i,a in enumerate(aList)]
cList = collections.Counter(bList)

ans = 1000000

scList = cList.most_common()
for pair in scList:
    score = calc_score(pair[0])
    ans = score
    
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

def calc_score(key):
    return sum([abs(b - key) for b in bList])

N = int(input().strip())
aList = list(map(int, input().strip().split(" ")))

bList = [a - i - 1 for i,a in enumerate(aList)]
cList = collections.Counter(bList)

ans = 1000000

scList = cList.most_common()
for pair in scList:
    score = calc_score(pair[0])
    if(score >= ans):
        break
    ans = score
    
print(ans)

Submission status: Wrong Answer

Solution code:
def s(aa, b):
    return sum(abs(a - (b + i + 1)) for i, a in enumerate(aa))


def main():
    n = int(input())
    aa = list(map(int, input().split()))
    b0 = -n
    b2 = 1000000000
    s0 = s(aa, b0)
    s2 = s(aa, b2)
    while b0 < b2:
        if s0 < s2:
            b2 = (b0 + b2) // 2
            s2 = s(aa, b2)
        else:
            if b2 - b0 == 1:
                break
            b0 = (b0 + b2) // 2
            s0 = s(aa, b0)
    print(s0)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
an_list = list(map(int, input().split()))
distance = []
for b in range(-n-1, n+1):
    sad = [abs(an_list[i] - b - i-1) for i in range(n)]
    distance.append(sum(sad))

print(min(distance))

Submission status: Wrong Answer

Solution code:
n = int(input())
an_list = list(map(int, input().split()))
distance = []
for b in range(n+1):
    sad = [abs(an_list[i] - b - i-1) for i in range(n)]
    distance.append(sum(sad))

print(min(distance))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(n) for n in input().split(" ")]
a = [a[n] - n - 1  for n in range(N)]
a = sorted(a)
if(N%2==1):
    median = a[int(N/2)]
else:
    median = (a[int(N/2)-1] + a[int(N/2)] )/ 2
sum = 0
for i in range(N):
    sum += abs(a[i] - median)
print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)

def calc(mid):
  res = 0
  for i in a:
    res += abs(i-mid)
  return res

if n%2==1:
  res = calc(a[n//2])
else:
  res = float('inf')
  if (a[n//2-1]+a[n//2])%2==0:
    res = calc((a[n//2-1]+a[n//2])//2)
  else:
    mid = (a[n//2-1]+a[n//2]) // 2
    res = min(calc(mid), calc(mid+1))

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
an = [int(i) for i in input().split()]
total = 0
for i in range(n):
    total += abs(an[i]-(i-1)//2)
print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())
array = list(map(int,input().split(" ")))
arra = []
i = 0
while i < N:
  arra.append(array[i]-(i+1))
  i+=1
arra.sort()
if N%2 == 0:
  m = (0.5)*(arra[int(N/2)-1]+arra[int(N/2)])
else:
  m = arra[int((N-1)/2)]
j = 0
sum = 0
while j < N:
  sum+=abs(array[j]-(m+j+1))
  j+=1
print(sum)

Submission status: Wrong Answer

Solution code:
import sys

N = input()
A = map(int, raw_input().split())
A = [A[i] - i - 1 for i in range(N)]
b = A[N / 2]
print sum([abs(a - b) for a in A])

Submission status: Wrong Answer

Solution code:
import sys

N = input()
A = map(int, raw_input().split())
A = [abs(A[i] - i - 1) for i in range(N)]
b = A[N / 2]
print sum([abs(A[i] - b) for i in range(N)])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

X = [a-(i+1) for i, a in enumerate(A)]
X.sort()
print(X)
b = X[(N)//2]
print(sum([abs(x - b) for x in X]))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted([int(_) for _ in input().split()])
X = [A[_] - (_ + 1) for _ in range(N)]
print(sum([abs(X[_] - X[N // 2]) for _ in range(N)]))

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
for i in range(N) :
    L[i] -= (i+1) 
L = sorted(L)
p = 0
for i in range(N) :
    p += abs(L[i])
if len(L) % 2 != 0 :
    med = L[N//2]
    ans = min(abs(p-med*N),abs(p+med*N))
else :
    med = (L[N//2-1]+L[N//2])//2
    ans = min(abs(p-med*N),abs(p+med*N))
print(ans)

Submission status: Wrong Answer

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

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

a.sort()

if n % 2 == 1:
    median = a[n // 2]
else:
    median = (a[n//2] + a[n//2+1]) // 2

ans = 0
for i in range(n):
    ans += abs(a[i] - median)

print(ans)

Submission status: Wrong Answer

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

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

if n % 2 == 1:
    median = a[n // 2]
else:
    median = (a[n//2] + a[n//2+1]) // 2

ans = 0
for i in range(n):
    ans += abs(a[i] - median)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
for i in range(N) :
    L[i] -= (i+1) 
L = sorted(L)
p = 0
for i in range(N) :
    p += abs(L[i])
if len(L) % 2 != 0 :
    med = L[N//2]
    ans = abs(p-med*N)
else :
    med = (L[N//2-1]+L[N//2])//2
    ans = p-med*N
    
print(ans)

Submission status: Wrong Answer

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

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

mean = sum(a) // n

ans = float('inf')
for b in range(mean, mean+2):
    cost = 0
    for i in a:
        cost += abs(i - b)
    ans = min(ans, cost)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

amini = [ai-(i+1) for i,ai in enumerate(a)]
b = amini[n//2]

print(sum([abs(ai-(b+i+1)) for i, ai in enumerate(a)]))

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
l=sum([i-j+1 for i,j in enumerate(a)])
print(min(math.ceil(l/n),math.floor(l/n)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#ABC102C
N=int(input())
A=list(map(int, input().split()))
b=(sum(A)-(N+1)*N/2)//N
ans1=0
ans2=0
for i in range(N):
    ans1+=abs(A[i]-(b+i+1))
    ans2+=abs(A[i]-(b+1+i+1))
print(int(min(ans1,ans2)))

Submission status: Wrong Answer

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

sum=0
for i in range(n):
  a[i]=a[i]-(i+1)
  sum=sum+abs(a[i])
print(sum)

Submission status: Wrong Answer

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


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

ave = sum(a) // n
acopy1 = a[:]
acopy2 = a[:]

for i in range(n):
    acopy1[i] = abs(a[i] - ave)

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

print(min(sum(acopy1), sum(acopy2)))

Submission status: Wrong Answer

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


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

ave = sum(a) // n
acopy = a[:]


for i in range(n):
  a[i] = abs(a[i] - ave)

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

print(min(sum(a), sum(acopy)))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
for i in range(n):
  a[i] -= (i+1)
ave = sum(a) // n
for i in range(n):
  a[i] = abs(a[i] - ave)
print(sum(a))

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))
a2 = a - np.arange(1,n+1)
abar1 = np.floor(np.mean(a2))
abar2 = np.ceil(np.mean(a2))
res = int(min(sum(abs(a2-abar1)), sum(abs(a2-abar2))))

print(res)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a_list = map(lambda x: int(x), input().split(' '))
    b_list = [x - i for i, x in zip(range(1, n+1), a_list)]
    b_list.sort()
    median = 0
    if n % 2 == 0:
        median = (b_list[n//2-1] + b_list[n//2]) / 2
    else:
        median = b_list[n//2]
    result = sum([abs(x - median) for x in b_list])
    print(result)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a_list = map(lambda x: int(x), input().split(' '))
    b_list = [x - i for i, x in zip(range(1, n+1), a_list)]
    b_list.sort()
    median = 0
    if n % 2 == 0:
        median = (b_list[n//2-1] + b_list[n//2]) / 2
    else:
        median = b_list[n//2]
    result = sum([x - median for x in b_list])
    print(result)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from statistics import median 
n = int(input())
a = list(map(int,input().split()))
ls = []
for i in range(n):
    ls.append(a[i] - i - 1)
b = median(ls)
if b % 1 == 0:
    ans = 0
    b = int(b)
    for i in range(n):
        ans += abs(a[i] - (b + i + 1))
    print(ans)
else:
    bigans = smallans = 0
    for i in range(n):
        bigans += abs(a[i] - (int(b) + i + 2))
        smallans += abs(a[i] - (int(b) + i + 1))
        print(min(bigans,smallans))

Submission status: Wrong Answer

Solution code:
# Linear Approximation
from statistics import median
n = int(input())
a = list(map(int, input().split()))
b = []
_sum = 0
for i in range(n):
    b.append(a[i] - i - 1)
med = median(b)
for i in range(n):
    _sum += abs(b[i] - med)
print(_sum)

Submission status: Wrong Answer

Solution code:
from statistics import median
n = int(input())
nums = list(map(int, input().split()))
bs = nums.copy()
tmp = 0

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


med = median(bs)

ans = 0
for i in range(n):
    ans += abs(bs[i] - med)

print(ans)

Submission status: Wrong Answer

Solution code:
count = int(input())
nums = list(map(int, input().split()))


def f(b):
    sum_num = 0
    for x, num in enumerate(nums, 1):
        sum_num += abs(num - (b + x))

    return sum_num


maximum = max(nums)

minimum = 10000000
for i in range(0, maximum + 1):
    calc = f(i)
    if minimum > calc:
        minimum = calc
        ans = calc

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
nums = list(map(int,input().split()))
tmp =[]

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


if sum(nums) !=0:
  counter = Counter(nums)
  a = counter.most_common()[0][0]
  a *= -1
  nums = list(map(lambda x: x+a,nums))
  print(sum(nums))
else:
  print(sum(list(map(abs,(nums)))))

Submission status: Wrong Answer

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

for j in range(-500,1000):
  a = 0
  for i in range(n):
    a += abs(nums[i]-(j+(i+1)))
  tmp.append(a)

print(min(tmp))

Submission status: Wrong Answer

Solution code:
from collections import Counter

def cnt_sum(N, A):
    C = Counter(A).most_common(2)
    sum = 0
    if len(C) == 1:
        for i in A:
             sum += abs(i-C[0][0])
    elif C[0][1] == C[1][1]:
        for i in A:
            sum += abs(i)
    else:
        for i in A:
            sum += abs(i-C[0][0])
    print(sum)

def main():
    N = int(input())
    A = [j - (i+1) for i , j in enumerate(map(int, input().split()))]
    cnt_sum(N, A)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

def sunuke(An,b):
    ret = 0
    for i,Ai in enumerate(An):
        ret += abs(Ai - (b + i + 1))

    return ret


if N % 2 == 0:
    #偶数の場合
    center_idx1 = N // 2 - 1
    b1 = An[center_idx1] - center_idx1 -1
    center_idx2 = center_idx1 + 1
    b2 = An[center_idx2] - center_idx2 -1
    print(min([sunuke(An,b1),sunuke(An,b2)]))
else:
    #奇数の場合
    center_idx = (N+1) // 2 - 1
    b = An[center_idx] - center_idx -1
    print(sunuke(An,b))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
a=[]
for i in range(N):
    a.append(A[i]-i)
if len(a)%2==0:
    p=a[len(a)//2]
else:
    p=a[len(a)//2]
ans=0
for j in range(N):
    ans+=abs(a[j]-p)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(1,n+1):
    b.append(a[i-1] - i)
b.sort
if n % 2 != 0:
    B = b[int((n-1)/2)]
    ans = 0
    for i in range(n):
        ans += abs(a[i]-i-1-B)
    print(ans)
else:
    big = b[int(n/2)]
    smo = b[int((n-2)/2)]
    smoB = int((big+smo)/2)
    bigB = smoB + 1
    big = smo = 0
    for i in range(n):
        big += abs(a[i]-i-1-bigB)
    for i in range(n):
        smo += abs(a[i]-i-1-smoB)
    print(min(big,smo))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(1,n+1):
    b.append(a[i-1] - i)
b.sort
if n % 2 != 0:
    B = b[int((n-1)/2)]
    ans = 0
    for i in range(n):
        ans += abs(a[i]-i-1-B)
    print(ans)
else:
    big = b[int((n)/2)]
    smo = b[int(n-2/2)]
    smoB = int((big+smo)/2)
    bigB = smoB + 1
    big = smo = 0
    for i in range(n):
        big += abs(a[i]-i-1-bigB)
    for i in range(n):
        smo += abs(a[i]-i-1-smoB)
    print(min(big,smo))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
#aの共分散を求める
xave = ((n*(n-1))/2)/n
yave = sum(a)/n
cov = 0
for i in range(n):
    cov += (i+1-xave)*(a[i]-yave)
cov = cov/n
#x(仮想)の共分散
dps = 0
for i in range(n):
    dps += (i+1-xave)**2
dps = dps / n
A = cov / dps
B = int(yave - A * xave)
ansls = []
for j in range(2):
    ans = 0
    for i in range(n):
        ans += abs(a[i] - i - 1 - B - j)
    ansls.append(ans)
print(max(ansls))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
#aの共分散を求める
xave = ((n*(n-1))/2)/n
yave = sum(a)/n
cov = 0
for i in range(n):
    cov += (i+1-xave)*(a[i]-yave)
cov = cov/n
#x(仮想)の共分散
dps = 0
for i in range(n):
    dps += (i+1-xave)**2
dps = dps / n
A = cov / dps
B = int(yave - A * xave)
ansls = []
for j in range(n):
    ans = 0
    for i in range(n):
        ans += abs(a[i] - i - 1 - B - j)
    ansls.append(ans)
print(max(ansls))

Submission status: Wrong Answer

Solution code:
from statistics import median as med
n = int(input())
a = list(map(int,input().split()))
b1 = []
for i in range(n):
    b1.append(a[i]-i-1)
b1.sort
b = med(b1)
ans = 0
for i in range(n):
    ans += abs(a[i] - i - 1 - b)
print(ans)

Submission status: Wrong Answer

Solution code:
from statistics import median as med
n = int(input())
a = list(map(int,input().split()))
b1 = []
for i in range(n):
    b1.append(a[i]-i-1)
b1.sort
b = med(b1)
ans = 0
for i in range(n):
    ans += abs(a[i] - i - 1)
print(ans)

Submission status: Wrong Answer

Solution code:
def f(x,i,n):
    sadness = 0
    for j in range(n):
        sadness += abs(x[j]-i)
    return(sadness)
N = int(input())
H = [int(i) for i in input().split()]
for i in range(N):
    H[i] -= i+1
H = sorted(H)
k = N // 2
if N == 1 :
    print(H[0])
else:
    print(f(H,H[k],N))

Submission status: Wrong Answer

Solution code:
def f(x,i,n):
    sadness = 0
    for j in range(n):
        sadness += abs(x[j]-i)
    return(sadness)
N = int(input())
H = [int(i) for i in input().split()]
for i in range(N):
    H[i] -= i+1
Mean = sum(H) // N
print(min(f(H,Mean-1,N),f(H,Mean,N),f(H,Mean+1,N)))

Submission status: Wrong Answer

Solution code:
def f(x,i,n):
    sadness = 0
    for j in range(n):
        sadness += abs(x[j]-i)
    return(sadness)
N = int(input())
H = [int(i) for i in input().split()]
for i in range(N):
    H[i] -= i+1
Mean = sum(H) // N
print(min(f(H,Mean,N),f(H,Mean+1,N)))

Submission status: Wrong Answer

Solution code:
import statistics
N = int(input())
an = list(map(int,input().split(" ")))
for i in range(N):
    an[i] -= (i+1)
b = statistics.median(an)
an = list(map(lambda x:abs(x-b),an))
print(sum(an))

Submission status: Wrong Answer

Solution code:
N = int(input())
an = list(map(int,input().split(" ")))
for i in range(N):
    an[i] -= (i+1)
b = round(sum(an)/len(an))
an = list(map(lambda x:abs(x-b),an))
print(sum(an))

Submission status: Wrong Answer

Solution code:
N = int(input())
an = list(map(int,input().split(" ")))
for i in range(N):
    an[i] -= i
b = round(sum(an)/len(an))
an = list(map(lambda x:abs(x-b),an))
print(sum(an))

Submission status: Wrong Answer

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

for i in range(N):
    A[i] -= i
X = [abs(a - A[N//2]) for a in A]
print(sum(X))

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list (map(int,input().split()))
abs_list=[]
for b in range(-max(a),max(a)):
	c=0
	for i in range(N):
		c=abs(a[i]-(b+i+1))+c	
	abs_list.append(c)	
print(abs_list)	
print(min(abs_list))

Submission status: Wrong Answer

Solution code:
n = int(input())
listA = list(map(int, input().split()))
index=0
sum =0
while index < len(listA):
    listA[index]-=index+1
    sum+=listA[index]
    index+=1

if sum%n ==0:
    a = sum//n
    sum2=0
    index2=0
    while index2< len(listA):
        listA[index2] -=a
        if listA[index2] <0:
            sum2-=listA[index2]
        else:
            sum2+=listA[index2]
        index2+=1
    print(sum2)
else:
    a = sum//n
    sum2=0
    sum3 =0
    sum4 =0
    index3=0
    while index3< len(listA):
        listA[index3] -=a
        if listA[index3] <0:
            sum2-=listA[index3]
        else:
            sum2+=listA[index3]
        index3+=1
    index3 =0
    while index3< len(listA):
        listA[index3] -=1
        if listA[index3] <0:
            sum3-=listA[index3]
        else:
            sum3+=listA[index3]
        index3+=1
    index3 =0
    while index3< len(listA):
        listA[index3] +=2
        if listA[index3] <0:
            sum4-=listA[index3]
        else:
            sum4+=listA[index3]
        index3+=1
    print(min(sum2, sum3, sum4))

Submission status: Wrong Answer

Solution code:
n = int(input())
listA = list(map(int, input().split()))
index=0
sum =0
while index < len(listA):
    listA[index]-=index+1
    sum+=listA[index]
    index+=1

if sum%n ==0:
    a = sum//n
    sum2=0
    index2=0
    while index2< len(listA):
        listA[index2] -=a
        if listA[index2] <0:
            sum2-=listA[index2]
        else:
            sum2+=listA[index2]
        index2+=1
    print(sum2)
else:
    a = sum//n
    sum2=0
    sum3 =0
    index3=0
    while index3< len(listA):
        listA[index3] -=a
        if listA[index3] <0:
            sum2-=listA[index3]
        else:
            sum2+=listA[index3]
        index3+=1
    index3 =0
    while index3< len(listA):
        listA[index3] -=1
        if listA[index3] <0:
            sum3-=listA[index3]
        else:
            sum3+=listA[index3]
        index3+=1
    print(min(sum2, sum3))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
sum_=0
dic = {}
for i,x in enumerate(A):
    if dic.get(x-(i+1),0) == 0:
        dic[x-(i+1)] = 1
    else:
        dic[x-(i+1)] += 1
tup = sorted(dic.items(),key=lambda x:x[0])
num = 0
mid = 0

for i in range(len(tup)-1):
    num += tup[i][1]
    if num >= (N+1)//2:
        mid = tup[i][0]
        break

ans = 0
for i,x in enumerate(A):
    ans+=abs(x-mid-(i+1))
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
sum_=0
for i,x in enumerate(A):
    sum_+=x-(i+1)
mean = int((sum_+0.5)//N) 
ans = 0
for i,x in enumerate(A):
    ans+=abs(x-mean-(i+1))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split(" ")))

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

import math

ave1 = math.floor(sum(a) / n)
ave2 = math.ceil(sum(a)/n)
ans1,ans2 = 0,0
for i in range(n):
    ans1 += abs(a[i]-ave1)
    ans2 += abs(a[i]-ave2)

print(min(ans1,ans2))

Submission status: Wrong Answer

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


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

b= int( p_sum / N)
d1, d2, d3=0, 0, 0
for i in range(N):
	d1= d1+abs(B[i]-b)
	d2= d2+abs(B[i]-(b+1))
	d3= d3+abs(B[i]-(b-1))

if d1 > d2:
	print(d2)
elif d1 > d3:
	print(d3)
else:
	print(d1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(a[i]-i-1 for i in range(n))
b.sort()

def sadness(x,y):
  s = 0
  for i in range(len(y)):
    s += abs(y[i]-x)
  return s

if n%2 == 0:
  print(sadness(a[int(n/2)],b))
else:
  print(sadness(a[int((n-1)/2)],b))

Submission status: Wrong Answer

Solution code:
import statistics

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

b = int(statistics.median(A)) - (N // 2)
print(sum([abs(n - (b+i)) for i, n in enumerate(A)]))

Submission status: Wrong Answer

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

b = (sum(A) // N) - (N // 2)
print(sum([abs(n - (b+i)) for i, n in enumerate(A)]))

Submission status: Wrong Answer

Solution code:
# 頭の体操
n = int(input())
a = sorted([ int(v)-i-1 for i,v in enumerate(input().split()) ])
ans = 0
n = n+1 if n%2!=0 else n
# 中央値で反転
print(sum(a[n//2:]) - sum(a[:n//2]))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted([ int(v)-i-1 for i,v in enumerate(input().split()) ])
ans = 0
n = n+1 if n%2==0 else n
print(sum(a[n//2:]) - sum(a[:n//2]))

Submission status: Wrong Answer

Solution code:
import statistics
n = int(input())
a = [ int(v)-i-1 for i,v in enumerate(input().split()) ]
b = statistics.median(a)
ans = 0
for i in a:
    ans += abs(i-b)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [ int(v)-i-1 for i,v in enumerate(input().split()) ]
b = sum(a)/n
b = int(b) -1 if b - int(b) < 0 else int(b)
ans = 0
for i in a:
    ans += abs(i-b)

print(ans)

Submission status: Wrong Answer

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

a.sort()
s=0
b=[-10000000]
for i in range(1,n+1):
  s+=a[i]
  b.append(s)

ave=s//n

s1=0
s2=0
s3=0
for i in range(1,n+1):
  s3+=abs(a[i]-(ave-1))
  s1+=abs(a[i]-ave)
  s2+=abs(a[i]-(ave+1))
print(min(s1,s2))

Submission status: Wrong Answer

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

a.sort()
s=0
b=[-10000000]
for i in range(1,n+1):
  s+=a[i]
  b.append(s)

ave=s//n

s1=0
s2=0
for i in range(1,n+1):
  s1+=abs(a[i]-ave)
  s2+=abs(a[1]-(ave+1))
print(min(s1,s2))

Submission status: Wrong Answer

Solution code:
from statistics import median

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

C = [A[i]-i for i in range(N)]
print(C)    
if N%2 ==1:
    B = C[int(N/2)]
else:
    B = C[int((N-1)/2)]+A[int((N+1)/2)]

print(sum(C)-N*B)

Submission status: Wrong Answer

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

idx = n // 2
ans = sum([abs(b - B[idx]) for b in B])
if n % 2 == 0:
    idx = n // 2
    ans = min(ans, sum([abs(b - B[idx]) for b in B]))
print('{:.0f}'.format(ans))

Submission status: Wrong Answer

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

idx = n // 2
ans = sum([abs(b - B[idx]) for b in B])
print(ans)
if n % 2 == 0:
    idx = n // 2
    ans = min(ans, sum([abs(b - B[idx]) for b in B]))
print('{:.0f}'.format(ans))

Submission status: Wrong Answer

Solution code:
import statistics
n = int(input())
a = [int(x) for x in input().split()]
a_alt = [x - i - 1 for i,x in enumerate(a)]
mid = statistics.median(a_alt)
print(sum([abs(x - mid) for x in a_alt]))

Submission status: Wrong Answer

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

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

heikin=math.floor(sum(a)/n)

for i in range(n):
    a[i]-=heikin
ans1=sum(map(abs,a))
    
for i in range(n):
    a[i]-=1
ans2=sum(map(abs,a))

for i in range(n):
    a[i]+=2
ans3=sum(map(abs,a))

print(min(ans1,ans2,ans3))

Submission status: Wrong Answer

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

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

heikin=math.floor(sum(a)/n)

for i in range(n):
    a[i]-=heikin
    
print(sum(map(abs,a)))

Submission status: Wrong Answer

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

def sunuke(b):
    ans=0
    for i in range(n):
        ans+=abs(a[i]-b-i-1) 
    return ans 
        
for i in range(-n,n+1):
    answer.append(sunuke(i))
    
print(min(answer))

Submission status: Wrong Answer

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

def sunuke(b):
    ans=0
    for i in range(n):
        ans+=abs(a[i]-b-i-1) 
    return ans 
        
while k<1:
    if sunuke(b)<sunuke(b+1):
        print(sunuke(b))
        k=1
    else:
        b+=1

Submission status: Wrong Answer

Solution code:
from math import floor, ceil
from statistics import mean, median

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

for i in range(len(A)):
  A[i] -= i+1

av = median(A)
#x = floor(av)
#y = ceil(av)
xans = 0
#yans = 0
for i in range(len(A)):
  xans += abs(A[i]-av)
  #yans += abs(A[i]-y)

print(xans)

Submission status: Wrong Answer

Solution code:
from math import floor, ceil
from statistics import mean

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

for i in range(len(A)):
  A[i] -= i+1

av = mean(A)
x = floor(av)
y = ceil(av)
xans = 0
yans = 0
for i in range(len(A)):
  xans += abs(A[i]-x)
  yans += abs(A[i]-y)

print(min(xans, yans))

Submission status: Wrong Answer

Solution code:
from math import floor, ceil
from statistics import mean

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

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

av = mean(A)
x = floor(av)
y = ceil(av)
xans = 0
yans = 0
for i in range(len(A)):
  xans += abs(A[i]-x)
  yans += abs(A[i]-y)

print(min(xans, yans))

Submission status: Wrong Answer

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

#N = 1
#A = [10**9]*N

A_n = [A[i-1] - i for i in range(1,N+1)]

if N%2 == 0:
    cent_max = A_n[N//2]
    cent_min = A_n[N//2-1]
else:
    cent = A_n[N//2]
    
if N%2 == 0:    
    sadness1 = sum([abs(A_n[i]-cent_min) for i in range(N)])
    sadness2 = sum([abs(A_n[i]-cent_max) for i in range(N)])
    sadness = min(sadness1, sadness2)

else:
    sadness = sum([abs(A_n[i]-cent) for i in range(N)])

print(sadness)

Submission status: Wrong Answer

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

A_n = [A[i-1] - i for i in range(1,N+1)]

if N%2 == 0:
    cent_min = A_n[N//2]
    cent_max = A_n[N//2-1]
else:
    cent = A_n[N//2]
    
if N%2 == 0:    
    sadness1 = sum([abs(A_n[i]-cent_min) for i in range(N)])
    sadness2 = sum([abs(A_n[i]-cent_max) for i in range(N)])
    sadness = min(sadness1, sadness2)
else:
    sadness = sum([abs(A_n[i]-cent) for i in range(N)])

print(sadness)

Submission status: Wrong Answer

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

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

if N%2 == 0:
    cent_min = A_n[N//2]
    cent_max = A_n[N//2-1]
else:
    cent = A_n[N//2]
    
if N%2 == 0:    
    sadness1 = sum([abs(A_n[i]-cent_min) for i in range(N)])
    sadness2 = sum([abs(A_n[i]-cent_max) for i in range(N)])
    sadness = min(sadness1, sadness2)
else:
    sadness = sum([abs(A_n[i]-cent) for i in range(N)])

print(sadness)

Submission status: Wrong Answer

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

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

cent = A_n[N//2]

ans = 0
sadness = [abs(A_n[i]-cent) for i in range(N)]

ans = sum(sadness)
print(ans)

Submission status: Wrong Answer

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

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

print(sum(abs(x-y) for x,y in zip(A, A[::-1]))/2)

Submission status: Wrong Answer

Solution code:
# https://beta.atcoder.jp/contests/abc102/tasks/arc100_a

if __name__ == '__main__':
    # n = 7
    # a = [1, 1, 1, 1, 2, 3, 4]

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

    d = []

    for i, a_i in enumerate(a):
        diff = int(a_i) - (i + 1)
        d.append(diff)

    d.sort()
    if n % 2 == 1:
        median = d[(n - 1) // 2]
    else:
        left_index = (n - 1) // 2
        median = sum(d[left_index:left_index + 1]) // 2

    ans = 0
    for d_i in d:
        ans += abs(d_i - median)
    print(ans)