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())
num = list(map(int,input().split()))
ans = [] 
for b in range(-N,N):
  temp = []
  for i in range(len(num)):
    a = abs(num[i]-(b+i+1))
    temp.append(a)
    sums = sum(temp)
  if len(ans)==0 or ans[0] > sums:
    ans.append(sums)
    
print(min(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

num_args = int(input())
input_list = input().split(" ")
input_list = [ int(i) for i in input_list]

input_list = np.array(input_list)
temp = np.array([i for i in range(1,num_args+1)])

b = math.floor(np.sum(input_list - temp)/num_args)
loss1 = np.sum(abs(input_list - temp+int(b)))

b = math.ceil(np.sum(input_list - temp)/num_args)
loss2 = np.sum(abs(input_list - temp + int(b)))

print(min(loss1,loss2))

Submission status: Wrong Answer

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

min_ans = 100000000
for b in range(-max(A), max(A)):
    ans = 0
    for i in range(len(A)):
        #print(A[i], b, i, abs(A[i] - (b + i + 1)))
        ans += abs(A[i] - (b + i + 1))
    #print("ans", b, ans)
    if min_ans >= ans: min_ans = ans
    else: break
    
"""b = -1
min_ans_b = 10000000
while True:
    ans = 0
    for i in range(len(A)):
        #print(A[i], b, i, abs(A[i] - (b + i + 1)))
        ans += abs(A[i] - (b + i + 1))
    #print("ans", b, ans)
    if min_ans_b >= ans: min_ans_b = ans
    else: break
    b -= 1


if min_ans_b < min_ans:
    min_ans = min_ans_b
"""
print(min_ans)

Submission status: Wrong Answer

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

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

s = sum(new_A)
X = s // N

s1 = 0
for a in new_A:
    s1 += abs(a - X)

s2 = 0
for a in new_A:
    s2 += abs(a - X)

s3 = 0
for a in new_A:
    s3 += abs(a - X)

print(min(s1,s2,s3))

Submission status: Wrong Answer

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

for i in range(n):
    c.append(a[i] - (i + 1))
ave = sum(c)//n

ans = 10**14*n

for b in range(ave-100, ave+100):
    t = 0
    for i in range(n):
        t += abs(c[i]-b)
    ans = min(ans, t)

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().rstrip().split()))
work=int()
testA=int()
testB=int()
testC=int()
B=list(A[i]-i for i in range(N))
work=sum(B)//N
testA=sum(abs(B[i]-work) for i in range(N))
testB=sum(abs(B[i]-work-1) for i in range(N))
testC=sum(abs(B[i]-work+1) for i in range(N))
output=min(testA,testB,testC)
print(output)

Submission status: Wrong Answer

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

sum = 0
ans = []

for b in range(-N, N):
    for i in range(N):
        sum += abs(A[i] - (b + i))
    else:
        ans.append(sum)
        sum = 0

print(ans)

Submission status: Wrong Answer

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

npA = np.array(A)
npi = np.arange(1,N+1)
diff = npA - npi

ave = np.sum(diff) // (N+1)
print(ave)
diff2 = diff - ave
ans1 = np.sum(abs(diff2))


c = col.Counter(diff)
most = c.most_common()[0][0]
diff3 = diff - most
ans2 = np.sum(abs(diff3))

if ans1 > ans2:
    print(ans2)
else:
    print(ans1)

Submission status: Wrong Answer

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

for b in range(-10000,10000):
  sad=0
  for i in range(N):
    sad+=abs(A[i]-(b+i+1))
  if(sad_s<0):
    sad_s=sad
  elif(sad<sad_s):
    sad_s=sad
  
print(sad_s)

Submission status: Wrong Answer

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

sum = 0
j = 1
for i in lst:
    sum += (i-j)
    j+=1

b = round(sum/n)


j = 1
sad = 0
for a in lst:
    sad += abs(a-(b+j))
    j += 1
print(sad)

Submission status: Wrong Answer

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

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

ad = []
j = 1
for i in a:
    ad.append(i - j)
    j += 1

s = sum(ad)
avg = s / len(ad)
g1 = int(avg * -1)

if avg >= 0:
    j = g1
    j2 = g1 + 1
    d1 = 0
    d2 = 0
    for i in a:
        d1 += abs(i - j)
        d2 += abs(i - j2)
        j += 1
        j2 += 1
    print(min(d1, d2))
    exit()
    

j = 0 - g1
j2 = 0 - g1 - 1
d1 = 0
d2 = 0
for i in a:
    d1 += abs(i - j)
    d2 += abs(i - j2)
    j += 1
    j2 += 1

print(min(d1, d2))

Submission status: Wrong Answer

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

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

ans = 99999999999999
for bj in range(b-10, b+10):
    res = 0
    for i in range(N):
        res += abs(A[i] - (bj+(i+1)))
    ans = min(ans, res)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
INF = 10**10
n = int(input())
a = [int(_) - (i + 1) for i, _ in enumerate(input().split())]
a_posi = [ai for ai in a if ai >= 0]
a_posi_num = len(a_posi)
a_posi_sum = sum(a_posi)
a_nega = [ai for ai in a if ai < 0]
a_nega_num = len(a_nega)
a_nega_sum = abs(sum(a_nega))

grief = INF
for b in set(a):
    if b >= 0:
        tmp = (a_posi_sum - b * a_posi_num) + (a_nega_sum + b * a_nega_num)
    else:
        tmp = (a_posi_sum + (-b) * a_posi_num) + (a_nega_sum -
                                                  (-b) * a_nega_num)

    if tmp < grief:
        grief = tmp

print(grief)

Submission status: Wrong Answer

Solution code:
def kanashisa(A, b):
    ret = 0
    for i in range(len(A)):
        ret += abs(A[i]-(b+i+1))
    return ret

def main():
    N = int(raw_input())
    A = map(int, raw_input().split())

    high, low = int(1e9), int(-1e9)

    cnt = 0
    while True:
        mid = (high+low) / 2
        a = kanashisa(A, high)
        b = kanashisa(A, low)
        c = kanashisa(A, mid)

        if a >= b and b <= c:
            high = mid
            low = low
        elif a >= b and b >= c:
            high = low
            low = mid
        elif b > a and a < c:
            high = mid
            low = high
        elif b > a and a > c:
            high = high
            low = mid

        cnt += 1
        if cnt == 100 or c == 0:
            print c
            break
        
main()

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

num_args = int(input())
input_list = input().split(" ")
input_list = [ int(i) for i in input_list]

input_list = np.array(input_list)
temp = np.array([i for i in range(1,num_args+1)])

b = math.floor(np.sum(input_list - temp)/num_args)


temp = temp+int(b)
print(np.sum(abs(input_list - temp)))

Submission status: Wrong Answer

Solution code:
n = int(input())
aa = [int(x) for x in input().split()]

ami = [ x - i - 1 for i, x in enumerate(aa)]

def sadness(al, b):
    sadl = [abs(x - b) for x in al]
    return sum(sadl)

if min(ami) >= 0:
    print(sum(ami) - n*min(ami))
elif max(ami) <= 0:
    print(sum(ami) - n*min(ami))
else:
    sadnl = [sadness(ami, i) for i in range(min(ami),max(ami))]
    print(min(sadnl))

Submission status: Wrong Answer

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

if N%2 == 0:
    k = (N+1)*N//2
else:
    k = (N+1)*(N//2)+(N+1)//2

b = (sum(A)-k)//N

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

Submission status: Wrong Answer

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

ans = 0
x = 0
y = 0

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

x = x // n

for i in range(n):
    ans += abs(P[i] - (i+1) - x)

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*
N = int(input())
nums = list(map(int, input().split()))
nums_s = set(nums)
res = []
for i in nums_s:
    b = i - (nums.index(i)+1)
    result = 0
    for i in range(1,N+1):
        result += abs(nums[i-1]-(b+i))
    res.append(result)
print(min(res))

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
a = [int(i) for i in input().split()]   
a = [a[i] - i for i in range(len(a))]

a_plus = [i for i in a if i>=0]
a_minus = [abs(i) for i in a if i < 0]
count_plus_num, count_plus = Counter(a_plus).most_common()[0]
count_minus = len(a_minus)
if count_plus > count_minus:
    ans = sum([abs(i-count_plus_num) for i in a])
else:
    ans = sum([abs(i) for i in a])
print(ans)

Submission status: Wrong Answer

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

b1 = int(sum(an)/len(an))
b_cand = [b1, b1-1, b1-2, b1+1,b1+2, -b1, -b1-1, -b1-2, -b1+1,-b1+2]
bs = [sum([abs(an[i] - b) for i in range(N)]) for b in b_cand]
print(min(bs))

Submission status: Wrong Answer

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

useds = []
min_value = 10000000000000000000

for j in range(len(A)):
	sa = A[j-1]-j
	if((sa not in useds)==True):
		useds.append(sa)
		b = int(sa)
		sum_As = 0
		for p in range(1,len(A)+1):
			sum_As += abs(A[p-1]-(b+p))

		if(sum_As<min_value):
			min_value = int(sum_As)

print(min_value)

Submission status: Wrong Answer

Solution code:
import statistics
N = int(input())
A = [int(x) for x in input().split(' ')]
def score(C, b):
    s = 0
    for i, Ci in enumerate(C):
        s += abs(Ci - b)
    return s

C = [Ai - (i+1) for i, Ai in enumerate(A)]
b = statistics.median(C)
print(score(C, b))

Submission status: Wrong Answer

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

b = 0
for i, a in enumerate(A, 1):
    b += a - i
#b = round(b / N)
if b >= 0:
    b1 = int(b / N)
    b2 = b1 + 1
else:
    b1 = int(b / N)
    b2 = b1 - 1
#b = int(b / N)


ans1 = 0
ans2 = 0
for i, a in enumerate(A, 1):
    ans1 += abs(a - b1 - i)
    ans2 += abs(a - b2 - i)

print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
#coding: utf-8

def calcSad(a_list, b):
    sadness = 0
    for i in range(len(a_list)):
        sadness += abs( a[i] - (b + i + 1) )
    return sadness

def check(a_list):
    max = -1
    start,end = (0,-1)
    tmp = 0
    for i in range(len(a_list) - 1):
        if a[i+1] - a[i] == 1:
            tmp += 1
            if tmp > max:
                max = tmp
                end = i+1
        else:
            if tmp > max:
                start = i+1
            tmp = 0
    
    if end != -1:
        b = a[end] - end - 1
    else:
        b = 0
    return b

if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split(" ")))
    b = check(a)
    result = calcSad(a,b)
    print(result)

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())
fa = [A[i] - (i + 1) for i in xrange(N)]
fb = map(lambda x: x - min(fa), fa)
print sum(fb)

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
for j in range(n):
    a[j] -= b
    if a[j] < 0:
        a[j] *= -1
print(sum(a))

Submission status: Wrong Answer

Solution code:
from math import ceil, floor

N = int(input())
A = [int(t) for t in input().split()]
if len(A) != N: raise

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

ave = sum(p) / N
q = sum(abs(x - ceil(ave))  for x in p)
r = sum(abs(x - floor(ave)) for x in p)
print(min(q, r))

Submission status: Wrong Answer

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

N = int(input())
A = list(map(int, input().split(" ")))
A_i = [0]*N
K = [0] * 51

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

b_0 = sum(A_i) / len(A_i)
b = [0] * 51
b[0] = int(b_0)
for i in range(1,51):
    b[i] = b[0] + int(i - 25.5)
# print(b)
for i in range(N):
    for j in range(51):
        K[j] = K[j] + abs(A_i[i] - b[j])
# print(K)

print(min(K))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
ck = 10000000000
for r in range(0,1):
    for b in range(N*r,N-(N*r)):
        k = 0
        for i in range(0,N):
            k = k + abs(A[i] - (b+i+1))
        if k < ck:
            ck = k
        elif k >= ck:
            #print(ck)
            break
else:
    print(ck)

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split(' '))))
err=[]
for b in range(min(A)-N,max(A)):
    B=np.array([b + i for i in range(N)])
    err.append(np.sum(np.abs(A-B)))
print(min(err))

Submission status: Wrong Answer

Solution code:
m=int(input())
l=list(map(int,input().split()))
s=1
li=[]
for i in l:
    li.append(i-s)
    s+=1

b=int(sum(li)/m)
#print(s)
#print(li)
#print(sum(li))
if(b<0):
    b-=1
#print(b)
list=[abs(i-b) for i in li]
print(sum(list))

Submission status: Wrong Answer

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

n_max = max(list)
n_min = min(list)

list2 = [(list[i]-(i+1)) for i in range(n)]

lowlim = min(list2)
hilim  = max(list2)

sorrow = int(0)
for b in range(lowlim, hilim):
    tmp = int(0)
    for j in range(n):
        tmp += abs(list2[j]-b)
    if tmp > sorrow:
        sorrow = tmp

print(sorrow)

Submission status: Wrong Answer

Solution code:
input()
n = [(int(i) - h - 1)  for h, i in enumerate(input().split())]
l = len(n)
now = 10**9
for b in range(min(n), max(n)+1):
    t = 0
    for a_i in n:
        t += abs(a_i - b)
    if t < now:
        now = t
    else:
        break
print(now)

Submission status: Wrong Answer

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

if n==1:
    print(0)
    sys.exit()

def abs(a):
    if a<0:
        return -a
    else:
        return a

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

a.sort()
ans=10**12
mid=n//2
for b in range(a[mid]-10,a[mid]+10):
    S=0
    for j in range(n):
        S+=abs(a[j]-b)
    ans=min(ans,S)
if ans==10**12:
    ans=0
print(ans)

Submission status: Wrong Answer

Solution code:
number = input()
b = input()
b = b.split()
x=[]
y=[]

for j in range(100000):
    x.append(-j)
x.sort()

for j in range(100000):
    x.append(j+1)

for h in x:
    sad=0
    for i,b2 in enumerate(b):
        i = int(i)
        b2 = int(b2)
        sad+=abs(b2 - h - i)
    y.append(sad)

print(min(y))

Submission status: Wrong Answer

Solution code:
def kanashisa(A, b):
    ret = 0
    for i in range(len(A)):
        ret += abs(A[i]-(b+i+1))
    return ret

def main():
    N = int(raw_input())
    A = map(int, raw_input().split())

    high, low = int(1e9), int(-1e9)

    cnt = 0
    while True:
        mid = (high+low) / 2
        a = kanashisa(A, high)
        b = kanashisa(A, low)
        c = kanashisa(A, mid)

        if a >= b and b <= c:
            high = mid
            low = low
        elif a >= b and b >= c:
            high = low
            low = mid
        elif b > a and a < c:
            high = mid
            low = high
        elif b > a and a > c:
            high = high
            low = mid

        cnt += 1
        if cnt == 1000 or c == 0:
            print c
            break
        
main()

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().rstrip().split()))
work=int()
testA=int()
testB=int()
B=list(A[i]-i for i in range(N))
work=sum(B)//N
testA=sum(abs(B[i]-work) for i in range(N))
testB=sum(abs(B[i]-work-1) for i in range(N))
output=min(testA,testB)
print(output)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
a = np.array([int(i) for i in input().split()])

b = a - np.arange(1,N+1)
c = b.sum()/N
c1,c2 = np.floor(c), np.ceil(c)
c3, c4 = c1-1, c1+1
min_1 = np.abs(b - c1).sum()
min_1 = min_1.astype('int64')
min_2 = np.abs(b - c2).sum()
min_2 = min_2.astype('int64')
min_3 = np.abs(b - c3).sum()
min_3 = min_3.astype('int64')
min_4 = np.abs(b - c4).sum()
min_4 = min_4.astype('int64')
print(min(min_1, min_2, min_3, min_4))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=input()
A=map(int, raw_input().split())
B=range(1,N+1)

C=[]
for x,y in zip(A,B):
	C.append(x-y)

K=Counter(C)
L=sorted(K.items(), key=lambda x: x[1],reverse=True)
z=L[0][0]

D=[0,z]

ans=float("inf")
for x in D:
	t=0
	for y in C:
		t+=abs(-1*x+y)
	ans=min(ans, abs(t))

print ans

Submission status: Wrong Answer

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

sum = 0
j = 1
for i in lst:
    sum += (i-j)
    j+=1

b = sum//n

#print(b)

j = 1
sad = 0
for a in lst:
    sad += abs(a-(b+j))
    j += 1
print(sad)

Submission status: Wrong Answer

Solution code:
import sys

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

for i in range(N):
    A_list[i] = A_list[i] - i - 1

ave = sum(A_list) / N
b = round(ave)

sadness = sys.maxsize
for b in range(b - 1, b + 3):
    tmp_sadness = 0
    for A in A_list:
        tmp_sadness += abs(A - b)
    if(sadness > tmp_sadness):
        sadness = tmp_sadness

print(sadness)

Submission status: Wrong Answer

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

if n==1:
    print(0)
    sys.exit()

def abs(a):
    if a<0:
        return -a
    else:
        return a

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

a.sort()
ans=10**12
mid=n//2
for b in range(a[mid],a[mid]+20):
    S=0
    for j in range(n):
        S+=abs(a[j]-b)
    ans=min(ans,S)
if ans==10**12:
    ans=0
print(ans)

Submission status: Wrong Answer

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

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

ad = []
j = 1
for i in a:
    ad.append(i - j)
    j += 1

s = sum(ad)
avg = s / len(ad)
g1 = int(avg * -1)

if avg >= 0:
    j = 1
    j2 = 0
    d1 = 0
    d2 = 0
    for i in a:
        d1 += abs(i - j)
        d2 += abs(i - j2)
        j += 1
        j2 += 1
    print(min(d1, d2))
    exit()
    

j = 0 - g1
j2 = 0 - g1 - 1
d1 = 0
d2 = 0
for i in a:
    d1 += abs(i - j)
    d2 += abs(i - j2)
    j += 1
    j2 += 1

print(min(d1, d2))

Submission status: Wrong Answer

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

N = int(input())
A = list(map(int, input().split(" ")))
A_i = [0]*N
K = [0] * 101

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

b_0 = sum(A_i) / len(A_i)
b = [0] * 101
b[0] = int(b_0)
for i in range(1,101):
    b[i] = b[0] + int(i - 50.5)
# print(b)
for i in range(N):
    for j in range(101):
        K[j] = K[j] + abs(A_i[i] - b[j])
# print(K)

print(min(K))

Submission status: Wrong Answer

Solution code:
def kanashisa(A, b):
    ret = 0
    for i in range(len(A)):
        ret += abs(A[i]-(b+i+1))
    return ret

def main():
    N = int(raw_input())
    A = map(int, raw_input().split())

    high, low = int(1e9), int(-1e9)

    cnt = 0
    while True:
        mid = (high+low) / 2
        a = kanashisa(A, high)
        b = kanashisa(A, low)
        c = kanashisa(A, mid)

        if a >= b and b <= c:
            high = mid
            low = low
        elif a >= b and b >= c:
            high = low
            low = mid
        elif b > a and a < c:
            high = mid
            low = high
        elif b > a and a > c:
            high = high
            low = mid

        cnt += 1
        if cnt == 10000 or c == 0:
            print c
            break
        
main()

Submission status: Wrong Answer

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

N = int(input())
A = list(map(int, input().split(" ")))
A_i = [0]*N
K = [0] * 101

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

b_0 = sum(A_i) / len(A_i)
b = [0] * 101
b[0] = int(b_0)
for i in range(1,101):
    b[i] = b[0] + int(i - 50.5)
print(b)
for i in range(N):
    for j in range(101):
        K[j] = K[j] + abs(A_i[i] - b[j])
print(K)

print(min(K))

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list(map(int, input().split()))
sum=0
absum=0
for i in range(N):
    sum+=l[i]-(i+1)
if abs(sum)<N/2:
    for j in range(N):
        absum+=abs(l[j]-(j+1))
    print(absum)
else:
    if abs(sum)%N==0:
        b=int(abs(sum)/N)
    else:
        b=int(abs(sum)/N)+1
    if sum<0:
        for j in range(N):
            absum+=abs(l[j]-(j+1)+b)
    else:
        for j in range(N):
            absum+=abs(l[j]-(j+1)-b)
    print(absum)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a = list(map(int, input().split()))
sm = 0
for i in range(len(a)):
    a[i] -= i + 1
    sm += a[i]
s = math.floor(sm/len(a))
t = math.ceil(sm/len(a))
ans = 0
anss = 0
for i in range(len(a)):
    ans += abs(a[i] - t)
    anss += abs(a[i] - s)
print(min(ans, anss))

Submission status: Wrong Answer

Solution code:
import math

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

A_ = [A[i] - i for i in range(N)]
s = sum(A_)/N
b1 = math.floor(s)
b2 = math.ceil(s)

A_max = max(A_)
A_min = min(A_)

A_b1 = sum([abs(a - b1) for a in A_])
A_b2 = sum([abs(a - b2) for a in A_])
A_max = sum([abs(a - A_max - 1) for a in A_])
A_min = sum([abs(a - A_min - 1) for a in A_])

print(min((A_b1, A_b2, A_max, A_min)))

Submission status: Wrong Answer

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

temp = range(1,N+1)
temp2=[]
counter_m = 0
# counter_p = 0
for i in range(N):
    temp2.append(A[i]-temp[i])
    if A[i] -temp[i] <= 0:
        counter_m+=1
# print(temp2)
if counter_m == N:
    min_temp = abs(max(temp2) - min(temp2))
    # print(min_temp)
    for i in range(N):
        temp2[i] += min_temp
    print(sum(list(map(abs,temp2))))
    
# temp2 = list(map(abs,temp2))
elif counter_m == 0:
    max_temp = - abs(max(temp2) -min(temp2))
    for i in range(N):
        temp2[i]+=max_temp
    print(sum(list(map(abs,temp2)))) 
else:
    print(sum(list(map(abs,temp2))))

# print(temp2)
# print(counter_m)

Submission status: Wrong Answer

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

b = 0
min_ans = 100000000
while True:
    ans = 0
    for i in range(len(A)):
        #print(A[i], b, i, abs(A[i] - (b + i + 1)))
        ans += abs(A[i] - (b + i + 1))
    #print("ans", b, ans)
    if min_ans >= ans: min_ans = ans
    else: break
    b += 1

b = -1
min_ans_b = 10000000
while True:
    ans = 0
    for i in range(len(A)):
        #print(A[i], b, i, abs(A[i] - (b + i + 1)))
        ans += abs(A[i] - (b + i + 1))
    #print("ans", b, ans)
    if min_ans_b >= ans: min_ans_b = ans
    else: break
    b -= 1

if min_ans_b < min_ans:
    min_ans = min_ans_b

print(min_ans)

Submission status: Wrong Answer

Solution code:
m=int(input())
l=list(map(int,input().split()))
s=1
li=[]
for i in l:
    li.append(i-s)
    s+=1

b=int(sum(li)/s)
if(b<0):
    b-=2
#print(b)
list=[abs(i-b) for i in li]
print(sum(list))

Submission status: Wrong Answer

Solution code:
b = int(input())  
s = list(map(int,input().split( )))
for i in range(0,b):
	s[i]+=200001-i

e=10000000
for j in range(min(s),max(s)):
    d=0
    for k in range(0,b):
         d+=abs(j-s[k])
    if d<e :
        e=d
print(e)

Submission status: Wrong Answer

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

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

a_floor = math.floor(sum(a_m) / N)
a_ceil = math.ceil(sum(a_m) / N)

results_floor = sum([abs(a - a_floor) for a in a_m])
results_ceil = sum([abs(a - a_ceil) for a in a_m])

if results_floor > results_ceil:
    print(results_ceil)
else:
    print(results_floor)

Submission status: Wrong Answer

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

a = []

c = 0
for i in range(n):
    a.append(aa[i]-(i+1))
    c += (aa[i]-(i+1))

god = c / n
#print(god)

import math as m

kouho1 = m.ceil(god)
kouho2 = m.floor(god)
    

ans1 = 0
ans2 = 0
ans3 = 0
ans4 = 0
for i in a:
    ans1 += abs(i  - kouho1)
    ans2 += abs(i  - kouho2)
    ans3 += abs(i + kouho1)
    ans4 += abs(i + kouho2)
    
print(min(ans1,ans2,ans3,ans4))

Submission status: Wrong Answer

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

if n==1:
    print(0)
    sys.exit()

def abs(a):
    if a<0:
        return -a
    else:
        return a

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

a.sort()
ans=10**12
mid=n//2
for b in range(a[mid],a[mid]+10):
    S=0
    for j in range(n):
        S+=abs(a[j]-b)
    ans=min(ans,S)
if ans==10**12:
    ans=0
print(ans)

Submission status: Wrong Answer

Solution code:
from math import *
n=int(input())
arr=list(map(int,input().split()))
for i in range(n):
    arr[i]-=(i+1)
k=sum(arr)
l=floor(k/n)
if(l==0):
    ans1=0
    ans2=0
    ans3=0
    for i in range(n):
        ans1+=abs(arr[i])
        ans2+=abs(arr[i]-1)
        ans3+=abs(arr[i]+1)
    print(min(ans1,ans2,ans3))
else:
    ans1=0
    ans2=0
    ans3=0
    for i in range(n):
        ans1+=abs(arr[i]-l)
        ans2+=abs(arr[i]-l-1)
        ans3+=abs(arr[i]-l+1)
    print(min(ans1,ans2,ans3))

Submission status: Wrong Answer

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

b0, b1, b2, b3 = -int(1e9), 0, 0, int(1e9)
iter = int(1e3)


def f(b):
    ans = 0
    for i in range(n):
        ans += abs(a[i] - b - i)
    return ans

for _ in range(iter):
    b1 = (2*b0 + b3) /3
    b2 = (b0 + 2*b3) /3
    
    if f(b1) > f(b2): b0 = b1
    else:             b3 = b2
    
    if b2 - b1 < 0.01: break
                   
                   
print(round(f(b1)))

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
input_list = [int(i) for i in input().split()]

input_counter = Counter()
ans1 = 0

for i in range(N):
    input_list[i] -= i+1
    input_counter[input_list[i]] += 1

a = max(input_counter.values())
for value in input_counter.keys():
    if a == input_counter[value]:
        b = value
        break

for i in range(N):
    ans1 += abs(input_list[i] - b)

print(ans1)

Submission status: Wrong Answer

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

a = [a[i]-i for i in range(n)]
b = sum(a)//n
a = [i-b for i in a]
ans = 0
ans1 = 0
ans2 = 0
ans3 = 0
for i in a:
    ans += abs(i)
for i in a:
    ans1 += abs(i+1)
for i in a:
    ans2 += abs(i-1)
for i in a:
    ans3 += abs(i+2)

print(min(ans,ans1,ans2,ans3))

Submission status: Wrong Answer

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

min_sum = -1
i_atmin = -1

# for i in range(0, 2*(10**5) + 2) :
i = min(a)
while(i <= max(a)) : 
    sum_over = 0
    sum_over_minus = 0
    
    for j in range(N) :
        sum_over += abs(a[j] - (i + j))
        
    for j in range(N) :
        sum_over_minus += abs(a[j] - (j - i))
        
    if min_sum != -1 and min(sum_over, sum_over_minus) > min_sum :
        break
        
    if min_sum == -1 or min(sum_over, sum_over_minus) < min_sum :
        min_sum = min(sum_over, sum_over_minus)
        i_atmin = i
        
    i += 1
        
print(min_sum)

Submission status: Wrong Answer

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

for i in range(n):
    c.append(a[i] - (i + 1))
ave = sum(c)//n

ans = 10**8*n

for b in range(ave-100, ave+100):
    t = 0
    for i in range(n):
        t += abs(c[i]-b)
    ans = min(ans, t)

print(ans)

Submission status: Wrong Answer

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

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

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

k=[]
for b in range((-1)*max(a),max(a)+1):
    k.append(0)
    x=[j-b for j in a]
    y=[abs(i) for i in x]
    k[b+max(a)]=sum(y)
    
print(min(k))

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = [int(x) for x in input().split()]
a = 0
for i in range(n):
    lst[i] = lst[i] - (i + 1)
    a += lst[i]
b = int(round((a/n),0))
print(str(a-b))

Submission status: Wrong Answer

Solution code:
def func(a, b, c):
    # aはA1からANまでの和、bはb、ｃはn
    sum_b = c*b
    sum_n = 0
    for i in range(1,c+1):
        sum_n = sum_n + i

    return(abs(a-sum_b-sum_n))

n = int(input())
an = input().split()
an_sum = 0

for i in an:
    an_sum = an_sum + int(i)

Submission status: Wrong Answer

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

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

s = 0
for i,a in enumerate(A):
    i+=1
    s += a - i

b=floor(s/N)
print(k(A,b))

Submission status: Wrong Answer

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

ans = 0
x = 0
y = 0

for i in range(n):
    a = P[i] - (i + 1)
    if a < 0:
        x += a
    else:
        y += a

if y < abs(x):
    p = (x // n)
    for i in range(n):
        a = P[i] - (i + 1) - p
        if a < 0:
            x -= a
        else:
            y += a

    print(y)
    
else:
    print(-x + y)

Submission status: Wrong Answer

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

N = int(input())
A = list(map(int, input().split(" ")))
A_i = [0]*N
K = [0] * 101

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

b_0 = sum(A_i) / len(A_i)
b = [0] * 101
b[0] = int(b_0)
for i in range(1,101):
    b[i] = b[0] + int(i - 50.5)

for i in range(N):
    for j in range(11):
        K[j] = K[j] + abs(A_i[i] - b[j])

print(min(K))

Submission status: Wrong Answer

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

dif = []
for idx, v in enumerate(A_list, 1):
    dif.append(v - idx)
b = 0
dif_num = sum(map(abs, (map(lambda x: x + b, dif))))
b = 1
while True:
    # l = list(map(lambda x: x + b, dif))
    dif_num2 = sum(map(abs, (map(lambda x: x + b, dif))))
    if dif_num2 < dif_num:
        dif_num = dif_num2
        b += 1
    else:
        break
print(dif_num)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input().split()
s1 = [int(s) for s in s]

s2 = [s1[i]-i-1 for i in range(N)]

ave = round(sum(s2) / N)



x =min([ sum([abs(s1[j] - (ave + j-i)) for j in range(N)]) for i in range(N)])
y =min([ sum([abs(s1[j] - (ave + j+i)) for j in range(N)]) for i in range(N)])


print(min(x, y))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(N):
    A[i] -= i + 1
summ = 0
center = round(sum(A) / len(A))

min_sum = 10 ** 9 * 2 * 10 ** 5
for i in range(-2, 3):
    summ = 0
    for j in range(N):
        summ += abs(A[j] - center + i)
    min_sum = min(min_sum, summ)
print(min_sum)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
a = np.array([int(i) for i in input().split()])

b = a - np.arange(1,N+1)
c = b.sum()/N
c1,c2 = np.floor(c), np.ceil(c)
min_1 = np.abs(b - c1).sum()
min_1 = min_1.astype('int64')
min_2 = np.abs(b - c2).sum()
min_2 = min_2.astype('int64')
print(min(min_1, min_2))