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:
N=int(input())
A=list(map(int, input().split()))
B=[A[i]-i-1 for i in range(N)]
m=sum(B)//N
ms=[m-2, m-1, m, m+1, m+2]
temp=[]
for i in range(3):
  m=ms[i]
  temp.append(sum([abs(B[j]-m) for j in range(N)]))
print(min(temp))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
B=[A[i]-i-1 for i in range(N)]
m=sum(B)//N
ms=[m-1, m, m+1]
temp=[]
for i in range(3):
  m=ms[i]
  temp.append(sum([abs(B[j]-m) for j in range(N)]))
print(min(temp))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
for i in range(N):
    a[i] -= i + 1
b = sum(a) / N
if b >= 0:
    if b % 1 >= 0.5:
        b += 1
else:
    if b % -1 <= -0.5:
        b -= 1
b = int(b)
ans_0 = 0
ans_1 = 0
ans_2 = 0
for i in range(N):
    ans_0 += abs(a[i] - b)

for i in range(N):
    ans_1 += abs(a[i] - (b + 1))
for i in range(N):
    ans_2 += abs(a[i] - (b - 1))
print(min(ans_0, ans_1, ans_2))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
for i in range(N):
    a[i] -= i + 1
b = sum(a) / N
if b % 1 >= 0.5:
    if b >= 0:
        b += 1
    else:
        b -= 1
b = int(b)
ans = 0
for i in range(N):
    ans += abs(a[i] - b)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import statistics
input = sys.stdin.readline

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

for i in range(N):
    A[i] -= i + 1
A = sorted(A)
med = statistics.median(A)

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

Submission status: Wrong Answer

Solution code:
import sys
import statistics
input = sys.stdin.readline

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

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

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

for i in range(N):
    A[i] -= i + 1
ave = round(sum(A) / N)

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
    A[i] -= i + 1
    ans += abs(A[i])
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input().split()
a=sorted([int(s[i])-i-1 for i in range(n)])

if n==1:
    print(0)
else:
    mi=[]
    h=sum(a)
    k=h
    for i in range(n-1):
        c,d=a[i],a[i+1]
        k-=2*a[i]
        m=k
        l=(i+1)-(n-i-1)
        if l>0:
            m+=(l*a[i+1])
        else:
            m+=(l*a[i])
        mi.append(m)
    mi.append(h-a[0]*n)
    mi.append(a[-1]*n-h)
    print(min(mi))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input().split()
a=sorted([int(s[i])-i-1 for i in range(n)])

if n==1:
    print(0)
else:
    mi=[]
    k=sum(a)
    for i in range(n-1):
        c,d=a[i],a[i+1]
        k-=2*a[i]
        m=k
        l=(i+1)-(n-i-1)
        if l>0:
            m+=(l*a[i+1])
        else:
            m+=(l*a[i])
        mi.append(m)
    mi.append(k-a[0]*n)
    mi.append(a[-1]*n-k)
    print(min(mi))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input().split()
a=sorted([int(s[i])-i-1 for i in range(n)])

if n==1:
    print(0)
elif n==2:
    うんち
else:
    #それぞれの間で考える
    mi=[]
    k=sum(a)
    for i in range(n-1):
        c,d=a[i],a[i+1]
        k-=2*a[i]
        m=k
        l=(i+1)-(n-i-1)
        if l>0:
            m+=(l*a[i+1])
        else:
            m+=(l*a[i])
        mi.append(m)
    #print(mi)
    print(min(mi))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input().split()
a=sorted([int(s[i])-i-1 for i in range(n)])

if n==1:
    print(0)
elif n==2:
    t
else:
    #それぞれの間で考える
    mi=[]
    k=sum(a)
    for i in range(n-1):
        c,d=a[i],a[i+1]
        k-=2*a[i]
        m=k
        l=(i+1)-(n-i-1)
        if l>0:
            m+=(l*a[i+1])
        else:
            m+=(l*a[i])
        mi.append(m)
    #print(mi)
    print(min(mi))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input().split()
a=sorted([int(s[i])-i-1 for i in range(n)])

if n==1:
    print(0)
else:
    #それぞれの間で考える
    mi=[]
    k=sum(a)
    for i in range(n-1):
        c,d=a[i],a[i+1]
        k-=2*a[i]
        m=k
        l=(i+1)-(n-i-1)
        if l>0:
            m+=(l*a[i+1])
        else:
            m+=(l*a[i])
        mi.append(m)
    #print(mi)
    print(min(mi))

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)

ave = sum(b)//n
if ave >=0:
  x = [0]*n
  y = [0]*n
  for i in range(n):
    x[i] = abs(b[i]-ave)
    y[i] = abs(b[i]-ave-1)
else:
  x = [0]*n
  y = [0]*n
  for i in range(n):
    x[i] = abs(b[i]-ave)
    y[i] = abs(b[i]-ave+1)  

ans1 = 0
ans2 = 0
for i in range(n):
  ans1 += abs(x[i])
  ans2 += abs(y[i])
  
print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np

def solve(N: int, A: "List[int]"):
    sum_ = 0
    for i, a in enumerate(A):
        sum_ += a - (i + 1)
    b = round(sum_/N)

    def get_sadness(b, A=A):
        ans = 0
        for i, a in enumerate(A):
            ans += abs(a - (i + 1) - b)
        return ans
    sadness = [0]*3
    sadness[0] = get_sadness(b=b)
    sadness[1] = get_sadness(b=b-1)
    sadness[2] = get_sadness(b=b+1)
    ans = sadness[np.argsort(sadness)[0]]
    print(ans)

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def list_minus_b(b_i, list_i):
  dif = []
  for value in list_i:
    dif.append(abs(b_i - value))
  return sum(dif)

length = int(input())
inp = input().split(' ')
A = []
for i in range(0, length):
  A.append(int(inp[i]) - i - 1)

min_difs = 10 ** 9
for i in range(min(A), max(A)):
  diff = list_minus_b(i, A)
  if diff < min_difs:
    min_difs = diff

print(min_difs)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
list_a = list(map(int, input().split()))
list_a = [a-i-1 for i, a in enumerate(list_a)]
avg_ce = math.ceil(sum(list_a) / len(list_a))
avg_fl = math.floor(sum(list_a) / len(list_a))
result_ce = sum([abs(a-avg_ce) for a in list_a])
result_fl = sum([abs(a-avg_fl) for a in list_a])
print(min(result_ce, result_fl))

Submission status: Wrong Answer

Solution code:
# sad = abs(A[1] - (b+1)) + abs(A[2] - (b+2)) + abs(A[3] - (b+3)) + ... + abs(A[n] - (b+n))
# A = 2 2 3 5 5 -> 1   2   3   4   5
#            b=0   1   0   0   1   0  ↓ -5
#            b=1   0  -1  -1   0  -1  ↓ -5


n = int(input())
arr = list(map(int, input().split()))
tmp = sum([abs(v - (i + 1)) for i, v in enumerate(arr)])
j = 1
while True:
    target = sum([abs(v + (j - i + 1)) for i, v in enumerate(arr)])
    if tmp <= target:
        print(tmp)
        exit()
    tmp = target
    j += 1

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

N = int(input())

A = np.array(list(map(int,input().split())))

B = np.arange(1,N+1)

dif = np.mean(A-B)

if dif < 0:
    dif = int(math.floor(dif))
else:
    dif = int(round(dif))


ans = np.sum(np.abs(A-B-dif))

print(ans)

Submission status: Wrong Answer

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


ave = sum(al) // len(al)
start = ave
ans = float("inf")
while True:
    tmp = 0
    for idx, a in enumerate(al):
        tmp += abs(start+ idx+1 - a)
    if ans > tmp:
        ans = tmp
    else:
        break
    start += 1

start = ave
while True:
    tmp = 0
    for idx, a in enumerate(al):
        tmp += abs(start +idx +1- a)
    if ans > tmp:
        ans = tmp
    else:
        break
    start -= 1

print(ans)

Submission status: Wrong Answer

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

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

ave = sum(al) // len(al)
start = ave
ans = float("inf")
while True:
    tmp = 0
    for a in al:
        tmp += abs(ave - a)
    if ans > tmp:
        ans = tmp
    else:
        break
    start += 1
start = ave
while True:
    tmp = 0
    for a in al:
        tmp += abs(ave - a)
    if ans > tmp:
        ans = tmp
    else:
        break
    start -= 1

print(ans)

Submission status: Wrong Answer

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

for i in range(n):
    al[i] -= i+1
ave3 = sum(al) // len(al) - 1 
ave1 = sum(al) // len(al)
ave2 = sum(al) // len(al) + 1
ans1 = 0
for a in al:
    ans1 += abs(ave1 - a)

ans2 = 0
for a in al:
    ans2 += abs(ave2 - a)
ans3 = 0
for a in al:
    ans3 += abs(ave3 - a)
print(min(ans1, ans2, ans3))

Submission status: Wrong Answer

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

for i in range(n):
    al[i] -= i+1
ave3 = sum(al) // len(al) - 1 
ave1 = sum(al) // len(al)
ave2 = sum(al) // len(al) + 1
ans1 = 0
for a in al:
    ans1 += abs(ave1 - a)

ans2 = 0
for a in al:
    ans2 += abs(ave2 - a)
ans3 = 0
for a in al:
    ans3 += abs(ave3 - a)
print(min(ans1, ans2, ave3))

Submission status: Wrong Answer

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

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

ave1 = sum(al) // len(al)
ave2 = sum(al) // len(al) + 1
ans1 = 0
for a in al:
    ans1 += abs(ave1 - a)

ans2 = 0
for a in al:
    ans2 += abs(ave2 - a)
print(min(ans1, ans2))

Submission status: Wrong Answer

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

c = collections.Counter(a)
m = c.most_common()[0][0]
ans = sum(abs(x-m) for x in a)
print(ans)

Submission status: Wrong Answer

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

my_round_int = lambda x: int((x * 2 + 1) // 2)
if sum(a)<0:
  ave = -1*my_round_int(abs(sum(a))/n)
  ave1 = ave - 1
  ave2 = ave + 1
else:
  ave = my_round_int(sum(a)/n)
  ave1 = ave-1
  ave2 = ave+1

ans = sum(abs(x-ave) for x in a)
ans1 = sum(abs(x-ave1) for x in a)
ans2 = sum(abs(x-ave2) for x in a)
print(min(ans,ans1,ans2))

Submission status: Wrong Answer

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

def my_round2(val, digit=0):
    p = 10 ** digit
    s = math.copysign(1, val)
    return (s * val * p * 2 + 1) // 2 / p * s
ave = my_round2(sum(a)/n)
ans = sum(abs(x-ave) for x in a)
print(ans)

Submission status: Wrong Answer

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

ave = round(sum(a)/n)
ans = sum(abs(x-ave) for x in a)
print(ans)

Submission status: Wrong Answer

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

b = [0]*n
for i in range(n):
  b[i] = a[i] - (i+1)  
  
if n%2 ==1:
  median = b[n//2] 
else:
  median = (b[n//2]+b[(n//2)+1])//2
  
ans = 0
for i in range(n):
  ans+= abs(a[i] -(median + i+1))
  
print(ans)

Submission status: Wrong Answer

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

total = 0
for i in range(n):
  total += aa[i] - (i+1)
  
b = (total//n)

ans = 0
for i in range(n):
  ans += abs(aa[i] - (b+i+1))
  
print(ans)

Submission status: Wrong Answer

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

total = 0
for i in range(n):
  total += aa[i] - (i+1)
  
b = -abs(total//n)

ans = 0
for i in range(n):
  ans += abs(aa[i] - (b+i+1))
  
print(ans)

Submission status: Wrong Answer

Solution code:
import statistics
import math

N=int(input())
A=[int(x) for x in input().split()]
def ka(b):
  k=0
  for i in range(N):
    k += abs(A[i]-(b+i+1))
  return k

B=[]
for j in range(N):
  B +=[A[j]-j-1]
p=statistics.median(B)
answer=min(ka(p-1),ka(p+1),ka(p))
print(answer)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input().strip())
A = [int(x) - (i + 1) for i, x in enumerate(input().strip().split())]
B = sorted(A)
ans = 10 ** 11
for i in B[len(B)//2-1:len(B)//2+3]:
    ans = min(ans, sum([abs(a - i) for a in A]))

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input().strip())
A = [int(x) - (i + 1) for i, x in enumerate(input().strip().split())]
B = sorted(A)[(len(A)+1)//2-1]

print(sum([a - B for a in A]))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input().strip())
A = [int(x) - (i + 1) for i, x in enumerate(input().strip().split())]
B = sorted(A)
ans = 10 ** 11
for i in B[len(B)//2-1:len(B)//2+2]:
    ans = min(ans, sum([abs(a - i) for a in A]))

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input().strip())
A = [int(x) - (i + 1) for i, x in enumerate(input().strip().split())]
B = sorted(A)
ans = 10 ** 9 + 7
for i in B[len(B)//2-1:len(B)//2+2]:
    ans = min(ans, sum([abs(a - i) for a in A]))

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input().strip())
A = [int(x) - (i + 1) for i, x in enumerate(input().strip().split())]
B = int(sum(A)/len(A))
ans = 10 ** 9 + 7
for i in [B - 1, B, B + 1]:
    ans = min(ans, sum([abs(a - i) for a in A]))

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input().strip())
A = [int(x) - 1 for x in input().strip().split()]
print(sum(A) - int(sum(A)/len(A)) * len(A))

Submission status: Wrong Answer

Solution code:
from math import floor, ceil
n=int(input())
a=[int(i) for i in input().split()]
su=0

for i in range(len(a)):
    su+=(a[i] - (i+1))
val,val1 = floor(su/n),ceil(su/n)

ans = 10**11

fir,sec=0,0

for i in range(len(a)):
    fir+=abs(a[i]-val-(i+1))
    sec+=abs(a[i]-val1-(i+1))
print(min(fir,sec))

Submission status: Wrong Answer

Solution code:
import math
n =int(input())
a = list(map(int,input().split()))
f = 0
c = 0
flor = math.floor((sum(a)/n-(n+1)/2))
ceil = flor + 1
for i in range(n):
    a[i]=a[i]-i-1
    f += abs(a[i]-flor)
    c += abs(a[i]-ceil)
ans = f
if c<f:
    ans=c
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

n=int(input())
a=[int(x) for x in input().split()]
s=[0 for x in range(n)]

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

a.sort()

s=0
if n%2:
  for i in range(n):
    s += abs(a[i]-a[n//2])
  print(s)
else:
  m=10**14
  v=(a[n//2-1]+a[n//2])//2
  for i in range(v,v+2):
    s = 0
    for j in range(n):
      s += abs(a[j]-i)
    m = min(m,s)
  print(s)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(x) for x in input().split()]
s=[0 for x in range(n)]

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

a.sort()

s=0
if s%2:
  for i in range(n):
    s += abs(a[i]-a[n//2])
  print(s)
else:
  m=10**14
  v=(a[n//2-1]+a[n//2])//2
  for i in range(v,v+2):
    s = 0
    for j in range(n):
      s += abs(a[j]-i)
    m = min(m,s)
  print(s)

Submission status: Wrong Answer

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 = A[0]
# A = list(map(lambda x : x - a, A))
# print(A)


b_1 = math.ceil(sum(A) / N)
b_2 = math.floor(sum(A) / N)
b_3 = round(sum(A) / N)
ans_1 = 0
ans_2 = 0
ans_3 = 0

for i in range(N):
	ans_1 += abs(A[i] - b_1)
	ans_2 += abs(A[i] - b_2)
	ans_3 += abs(A[i] - b_3)
	
print(int(min(ans_1, min(ans_2, ans_3))))

Submission status: Wrong Answer

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 = A[0]
# A = list(map(lambda x : x - a, A))
# print(A)


b_1 = math.ceil(sum(A) / N)
b_2 = math.floor(sum(A) / N)
b_3 = round(sum(A) / N)
ans_1 = 0
ans_2 = 0
ans_3 = 0

for i in range(N):
	ans_1 += abs(A[i] - b_1)
	ans_2 += abs(A[i] - b_2)
	ans_3 += abs(A[i] - b_3)
	
print(min(ans_1, min(ans_2, ans_3)))

Submission status: Wrong Answer

Solution code:
#                         author:  kagemeka 
#                         created: 2019-11-08 14:51:29(JST)
## internal modules
import sys
# import collections
import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## external modules
# import scipy.special   # if use comb function on AtCoder, 
# import scipy.misc      # select scipy.misc.comb (old version) 

def main():
    n, *a = (int(x) for x in sys.stdin.read().split())
    
    for i in range(n):
        a[i] -= (i + 1)

    b1 = math.floor(sum(a) / n)
    b2 = math.ceil(sum(a) / n)

    ans = min(sum([abs(a[i] - b1) for i in range(n)]), sum([abs(a[i] - b2) for i in range(n)]))
    print(ans)



if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = list(map(int, input().split()))
i = [i for i in range(1, n+1)]
l = np.array(a) - np.array(i)
b = np.mean(l)
if b >= 0:
    b = int(round(b))
else:
    b = int(round(b) - 1)
print(sum(abs(l-b)))

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = list(map(int, input().split()))
i = [i for i in range(1, n+1)]
l = np.array(a) - np.array(i)
b = int(np.mean(l))

ans = float('inf')
for i in range(-5, 5):
    ans = min(ans, sum(abs(l - (b+i))))
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = list(map(int, input().split()))
i = [i for i in range(1, n+1)]
l = np.array(a) - np.array(i)
b = int(np.mean(l))

ans = float('inf')
for i in range(-1, 2):
    ans = min(ans, sum(abs(l - (b+i))))
print(ans)

Submission status: Wrong Answer

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

li = []

for i in range(n):
    memo = a[i]-(i+1)
    li.append(memo)

li.sort()
print(li)
memo = len(li)
memo2 = li[memo//2]

li2 = [-(memo2) for i in range(len(li))]
for i in range(n):
    li[i] = li[i] + li2[i]
print(li)
ttl = 0
for i in range(n):
    ttl += abs(li[i])

print(ttl)

Submission status: Wrong Answer

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

li = []

for i in range(n):
    memo = a[i]-(i+1)
    li.append(memo)

li.sort()

memo = len(li)
memo2 = li[memo//2]

li2 = [-(memo2) for i in range(len(li))]
li = li + li2

ttl = 0
for i in range(n):
    ttl += abs(li[i])

print(ttl)

Submission status: Wrong Answer

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

li = []

for i in range(n):
    memo = a[i]-(i+1)
    li.append(memo)

li.sort()

memo = len(li)
memo2 = li[memo//2]

li2 = [memo2 for i in range(len(li))]
li = li + li2

ttl = 0
for i in range(n):
    ttl += abs(li[i])

print(ttl)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a_c = a
for i in range(n):
    a_c[i] -= i
sorted(a_c)
med = a_c[n // 2]
score = 0
for i in range(n):
    score += abs(a_c[i] - med)

print(score)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
import copy
import sys
import fractions
import numpy as np
from functools import reduce


# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

n = getInputInt()
data = getInputListInt()

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

ave = np.mean(data)

ave = round(ave)

ans = 0

for i in range(n):
    ans += abs(data[i] - ave)

print(int(ans))

Submission status: Wrong Answer

Solution code:
N= int(input())
A= [int(x) for x in input().split()]
def kanasimi(n):
    k=0
    for i in range(N):
        k +=abs(A[i]-(n+i+1))
    return k
result = 10*6
for i in range(max(A)):
    result = min(result,kanasimi(i))
print(result)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
R = np.array([x+1 for x in range(N)])

av = int(np.round((np.average(A-R))))
answer = 10 ** 9
for i in range(-5, 5):
    result = abs(A-R-av-i).sum()
    if answer > result:
        answer = result
print(answer)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
R = np.array([x+1 for x in range(N)])

av = int(np.round((np.average(A-R))))
answer = 10 ** 5
for i in range(-5, 5):
    result = abs(A-R-av-i).sum()
    if answer > result:
        answer = result
print(answer)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
R = np.array([x+1 for x in range(N)])

av = int(np.round((np.average(A-R))))
answer = 0
for i in range(-10, 10):
    result = abs(A-R-av-i).sum()
    if answer > result:
        answer = result
print(answer)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
R = np.array([x+1 for x in range(N)])

av = int(np.round((np.average(A-R))))

print(min(abs(A-R-av-1).sum(), abs(A-R-av).sum(), abs(A-R-av+1).sum()))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
R = np.array([x+1 for x in range(N)])

av = int(np.round((np.average(A-R))))
print(min(abs(A-R-av).sum(), abs(A-R-av+1).sum()))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
R = np.array([x+1 for x in range(N)])

av = int(np.average(A-R))
print(min(abs(A-R-av).sum(), abs(A-R-av+1).sum()))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
R = np.array([x+1 for x in range(N)])

av = int(np.average(A-R))
print(abs(A-R-av).sum())

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
R = np.array([x+1 for x in range(N)])

av = int(np.average(A-R))
print(abs(A-R-av))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
def check(x):
    sm=0 
    for i in range(n):
        sm+=abs(l[i]-(i+x+1))
    return sm 
lo=0 
hi=10**10 
while lo<=hi:
    mi=(lo+hi)>>1 
    a=check(mi)
    b=check(mi-1)
    c=check(mi+1)
    if b<a: 
        hi=mi-1 
        ans=b
    elif c<a:
        ans=c
        lo=mi+1 
    else:
        ans=a 
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
def check(x):
    sm=0 
    for i in range(n):
        sm+=abs(l[i]-(i+x+1))
    return sm 
lo=0 
hi=10**10 
while lo<=hi:
    mi=(lo+hi)>>1 
    a=check(mi)
    b=check(mi-1)
    c=check(mi+1)
    if b<a: 
        hi=mi-1 
        ans=c 
    elif c<a:
        ans=c
        lo=mi+1 
    else:
        ans=a 
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
A = list(map(int,input().split()))
A = np.array([a-i for i,a in enumerate(A,1)])
A = np.sort(A)

#中央値
if n % 2:
	z = A[n//2]
else:
	x = A[n//2-1]
	y = A[n//2]
	z = (x+y)//2

Z = np.array([abs(z)]*n)
# print(A,Z)
print(abs(np.sum(np.abs(A)-Z)))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = list(map(int,input().split()))
B = []
ans = 10 ** 100

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

ave = sum(A) / N
B.append(math.floor(ave))
B.append(math.ceil(ave))

for j in range (0,2):
  s = 0
  for i in range (0,N):
    s = s + abs(A[i] - B[j])
  ans = min(ans,s)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = list(map(int,input().split()))
B = []
ans = 10 ** 10

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

ave = sum(A) / N
B.append(math.floor(ave))
B.append(math.ceil(ave))

for j in range (0,2):
  s = 0
  for i in range (0,N):
    s = s + abs(A[i] - B[j])
  ans = min(ans,s)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [A[i] - i - 1 for i in range(N)]
cost = lambda x : sum([abs(b - x) for b in B])
x1 = max(B)
x1_cost = cost(x1)
x4 = min(B)
x4_cost = cost(x4)
x2 = (x4 - x1) // 4 * 2 + x1
x3 = (x4 - x1) // 4 * 3 + x1
x2_cost = cost(x2)
x3_cost = cost(x3)
while True:
  if x2_cost < x3_cost:
    x4 = x3
    x4_cost = x3_cost
  elif x2_cost > x3_cost:
    x1 = x2
    x1_cost = x2_cost
  else:
  	break
  x2 = (x4 - x1) // 4 * 2 + x1
  x3 = (x4 - x1) // 4 * 3 + x1
  x2_cost = cost(x2)
  x3_cost = cost(x3)
  if x4 - x1 < 3:
    break

print(min([x1_cost, x2_cost, x3_cost, x4_cost]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

ave = sum(a)/n
ave1= math.ceil(ave)
ave2= math.floor(ave)


print(min(sum([abs(a[i]-ave1) for i in range(n)]),sum([abs(a[i]-ave2) for i in range(n)])))

Submission status: Wrong Answer

Solution code:
N=int(input())
l=list(map(int,input().split()))
sort_l=sorted(l)
center_num=sort_l[N//2]
ans=0
for i in range(N):
  ans+=abs(l[i]-(i+center_num-N//2))
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
l=list(map(int,input().split()))
sort_l=sorted(l)
center_num=sort_l[N//2]
ans=0
for i in range(N):
  ans+=abs(l[i]-(center_num-N//2+i))
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
m=sum(l)//len(l)
ans=0
ans1=0
ans2=0
for i in range(n):
    ans+=abs(l[i]-m)
    ans1+=abs(l[i]-m-1)
    ans2+=abs(l[i]-m+1)
print(min(ans,ans1,ans2))

Submission status: Wrong Answer

Solution code:
import math
import statistics
n = int(input())
a = list(map(int,input().split()))
a = [aa-i-1 for i, aa in enumerate(a)]
answer = 10**9
median_low = statistics.median_low(a)
median_high = statistics.median_high(a)

for m in (median_low,median_high):
  ans=0
  for aa in a:
    ans += abs(aa-m)
  answer = min(ans,answer)
print(answer)

Submission status: Wrong Answer

Solution code:
import math
import bisect
n = int(input())
a = list(map(int,input().split()))
a = [aa-i-1 for i, aa in enumerate(a)]
a.sort()

g = math.floor(sum(a)/n)
g_index = bisect.bisect_left(a, g)

answer = n*10**20
for gg in (g,a[g_index],a[g_index-1]):
  ans = 0
  for aa in a:
    ans += abs(aa-gg)
  answer = min(answer,ans)
print(answer)

Submission status: Wrong Answer

Solution code:
import math
import bisect
n = int(input())
a = list(map(int,input().split()))
a = [aa-i-1 for i, aa in enumerate(a)]
a.sort()

g = math.floor(sum(a)/n)
g_index = bisect.bisect_left(a, g)

answer = n*10**9
for gg in (g,a[g_index],a[g_index-1]):
  ans = 0
  for aa in a:
    ans += abs(aa-gg)
  answer = min(answer,ans)
print(answer)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a = list(map(int,input().split()))
a = [aa-i-1 for i, aa in enumerate(a)]

g = math.floor(sum(a)/n)
answer = n*10**9
for gg in (g-1,g,g+1,g+2):
  ans = 0
  for aa in a:
    ans += abs(aa-gg)
  answer = min(answer,ans)
print(answer)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a = list(map(int,input().split()))
a = [aa-i-1 for i, aa in enumerate(a)]

g = math.floor(sum(a)/n)
answer = 10**9*n
for gg in (g,g+1):
  ans = 0
  for aa in a:
    ans += abs(aa-gg)
  answer = min(answer,ans)
print(answer)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a = list(map(int,input().split()))
a = [aa-i-1 for i, aa in enumerate(a)]

g = math.floor(sum(a)/n)
answer = 10**9
for gg in (g,g+1):
  ans = 0
  for aa in a:
    ans += abs(aa-gg)
  answer = min(answer,ans)
print(answer)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a = list(map(int,input().split()))
a = [aa-i-1 for i, aa in enumerate(a)]

g = math.floor(sum(a)/n)
answer = 0
for aa in a:
  answer += abs(aa-g)
print(answer)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#102c
import math

N = int(input()) #N<2 * 10**5
A_list = [int(e) for e in input().split()] #0 < A

A_sub_i_list = [A_list[i]-(i+1) for i in range(N)]
#print(A_sub_i_list)

average = sum(A_sub_i_list)/N
#print(average)

ceil_avg = math.ceil(average)
ans_ceil = sum([abs(A_sub_i_list[i]-ceil_avg) for i in range(N)])
floor_avg = math.floor(average)
ans_floor = sum([abs(A_sub_i_list[i]-floor_avg) for i in range(N)])

print(min(ans_ceil,ans_floor))

Submission status: Wrong Answer

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