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()))
A_i = [a - (i+1) for i, a, in enumerate(A)]
B = [i for i in range(-N, N, 1)]
lis = []
for b in B:
    lis.append(sum([abs(a - b) for a in A_i]))

print(min(lis))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
ck = 10000000000
for b in range(0,1000000000):
    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

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
arr = np.array(list(map(int,input().split())))
per = np.array([i+1 for i in range(n)])

arr = arr-per

arr2 = arr.copy()

arr2.sort()

kouho = (arr2[0]+arr2[-1])//2
kouho1 = kouho+1
kouho2 = kouho-1

ave = np.sum(arr2)//n
ave1 = ave+1
ave2 = ave-1

m = [np.sum(np.abs(arr-kouho)),np.sum(np.abs(arr-kouho1)),np.sum(np.abs(arr-kouho2)),np.sum(np.abs(arr-ave)),np.sum(np.abs(arr-ave1)),np.sum(np.abs(arr-ave2))]


print(int(min(m)))

Submission status: Wrong Answer

Solution code:
import math

def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, = read_line(int)

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

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

avg = sum(AA) / len(AA)

b1 = math.ceil(avg)
b2 = math.floor(avg)

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

print(min(sadness1, sadness2))

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    B = []
    ans = 10**9

    for i, a in enumerate(A):
        B.append(a - i - 1)

    for b in [min(B), max(B), (min(B)+max(B))//2]:
        tmp = 0
        for i, a in enumerate(A):
            tmp += abs(a - i - b - 1)
        ans = min(ans, tmp)

    print(ans)

Submission status: Wrong Answer

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

sum = 0
for i in range(N):
    arr[i] = arr[i] - i - 1
    sum += arr[i]

average = round(sum / N)

res =0
for i in range(len(arr)):
    res += abs(average - arr[i])

print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
Ai = list(map(int, input().split()))
sub = N * (N+1)/2
avr = (sum(Ai) - sub) // N

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

print(int(ans))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# AtCoder Beginner Contest


if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    a_total = sum(a)
    n_total = (n * (n + 1)) // 2
    b = (a_total - n_total) // n
    bs = [0, b - 1, b, b + 1]
    ans = float('inf')

    for bi in bs:
        i = 1
        total = 0

        for ai in a:
            total += abs(ai - (bi + i))
            i += 1

        ans = min(ans, total)

    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
X = np.array(range(1,N+1))
b = np.average(A-X)
m0 = np.sum(np.absolute(A-X-int(b)+2))
m1 = np.sum(np.absolute(A-X-int(b)+1))
m2 = np.sum(np.absolute(A-X-int(b)))
m3 = np.sum(np.absolute(A-X-int(b)-1))
m4 = np.sum(np.absolute(A-X-int(b)-2))
print(min([m0,m1,m2,m3,m4]))

Submission status: Wrong Answer

Solution code:
#c

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

for i in range(1,n+1):
    a[i-1] -= i
num1 = a[int(n/2)-1]
num2 = a[int(n/2)]

ans1 = 0
for i in range(n):
    ans1 += abs(a[i]-num1)
ans2 = 0
for i in range(n):
    ans2 += abs(a[i]-num2)

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

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a= list(map(int,input().split()))
ans = 100000000000
#b = [0 for i in range(n+1)]

#for i in range(n):
#    b[i+1] = b[i] + a[i]
sa = 0
ans = 0
for i in range(n):
    b = abs(a[i] -(i+1))
    #print(b)
    ans += b
    sa = max(sa,b)
#print(ans)
c = 0
d = 0
for i in range(n):
    for j in range(int(sa*2)):
        c += abs(a[i] - (j+i+1-sa))    
    #print(c,d)
    ans = min(c,ans)


print(ans)

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 = []
for d in range(-2, 3):
    q.append(sum(abs(x - (floor(ave) + d)) for x in p))
print(min(q))

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))
    factors = [ factor-k for factor,k in zip(a, range(1,n+1)) ]
    factors.sort(key=lambda tmp:abs(tmp))
    ans = min(sum([ abs(factor-factors[0]) for factor in factors ]),sum([ abs(factor-factors[n-1]) for factor in factors ]))
    print(ans)

Submission status: Wrong Answer

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

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

x, y = 0, 0
cx, cy = 0, 0
for i in range(N):
    if A[i] > 0:
        x += A[i]
        cx += 1
    elif A[i] < 0:
        y += A[i]
        cy += 1

b = 0
if cx > 0:
    b += x / cx
if cy > 0:
    b += y / cy
b = int(b)

ans = float('inf')
for j in range(-5, 6):
    v = 0
    for i in range(N):
        v += abs(A[i] - (b + j))
    ans = min(ans, v)
print(ans)

Submission status: Wrong Answer

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

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

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

sum_b1 = 0
for i in range(0, n):
    sum_b1 += abs(a[i] - (i+1+b1))
sum_b2 = 0
for i in range(0, n):
    sum_b2 += abs(a[i] - (i+1+b2))
print(min(sum_b1, sum_b2))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def abs(a,b):
    if a < b:
        return b - a
    else :
        return a - b

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

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

b = round(sum(A)/N)
ans = 0

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

print(ans)

Submission status: Wrong Answer

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

import numpy as np

A = np.array(A)
I = np.array(list(range(1, N + 1)))

G = A - I

#print(G)
b = np.min(G)
#print(b)

re = 10 ** 10
# 引き算結果が正の場合
if b > 0:
    G = G - np.full(N, b)
    G = np.absolute(G)
    re = np.sum(G)
# 負が混じっている場合
else:
    uG = np.unique(G)
    for i in uG:
        temp = np.sum(np.absolute(G - np.full(N , i)))
#        print(temp)
        if re > temp:
            re = temp

print(re)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
output = 0
b = [abs(elem - i) for i, elem in enumerate(a, 1)]
c = Counter(b)
d = c.most_common()

surume = 0
if len(d) == 1:
    surume = d[0][0]
else:
    if d[0][1] == d[1][1]:
        surume = 0
    else:
        surume = d[0][0]
e = [abs(elem - i + surume) for i, elem in enumerate(a, 1)]
print(sum(e))

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

print(min(k(A,0),k(A,s//N)))

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    B = []
    ans = 10**9

    for i, a in enumerate(A):
        B.append(a - i - 1)

    print(B)
    for b in [min(B), max(B), (min(B)+max(B))//2]:
        tmp = 0
        for i, a in enumerate(A):
            tmp += abs(a - i - b - 1)
        ans = min(ans, tmp)

    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
center = round( (max(A) + min(A)) / 2)

min_sum = 10 ** 9 * 2 * 10 ** 5
for i in range(-1, 2):
    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 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

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

mid=n//2
b_choice=a[mid-10:mid+10]
for b in b_choice:
    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:
input()
n = [(int(i) - h - 1)  for h, i in enumerate(input().split())]
s = set()
l = []
for i in n:
    if i > 0:
      l.append(i)
    else:
        s.add(i)
print(sum([abs(i) for i in l + list(s)]))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
num=10
count=46463435
ma=max(l)
m=ma//2
mi=min(l)
k=m
b=0
while(num>=0):
    sum=0
    sum1=0
    sum2=0
    sum4=0
    sum3=0
    for i in range(len(l)):
        sum+=abs(l[i]-(b+i+1))
        sum1+=abs(l[i]-(ma+i+1))
        sum3+=abs(l[i]-(m+i+1))
        sum2+=abs(l[i]-(k+i+1))
        sum4+=abs(l[i]-(mi+i+1))
    if(sum<count):
        count=sum
    if(sum4<count):
        count=sum4
    if(sum1<count):
        count=sum1
    if(sum3<count):
        count=sum3
    if(sum2<count):
        count=sum2
    b+=1
    ma-=1
    m-=1
    mi+=1
    k+=1
    num-=1
print(count)

Submission status: Wrong Answer

Solution code:
import math

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

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

b1 = math.floor(su / N)
b2 = math.ceil(su / N)

result1 = 0
result2 = 0
for i in range(len(A)):
    result1 += abs(A[i] - b1)
    result2 += abs(A[i] - b2)

print(min(result1, result2))

Submission status: Wrong Answer

Solution code:
from math import floor, ceil

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

A = [A[i] - (i+1) for i in range(N)]
b = floor(sum(A)/N)
b_ = ceil(sum(A)/N)
ans = min(sum([abs(a-b) for a in A]), sum([abs(a-b_) for a in A]))
print(ans)

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

print(sum(A)-(b*N+k))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

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

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

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

Submission status: Wrong Answer

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

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

    dif_sum = sum(dif)
    n1, n2 = dif_sum // n, dif_sum // n + 1

    dm1, dm2 = 0, 0
    for i in range(n):
        dm1 += abs(dif[i]-n1)
        dm2 += abs(dif[i]-n2)

    print(min(dm1, dm2))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
b = int(input())
x = list(map(int, input().split()))

def absadd(a_i, i, B):
    return abs((a_i-i) -B)

candi = []
for B in range(-b, b):
    ret = 0
    for idx, ele in enumerate(x):
        ret += absadd(ele, idx+1, B)

    candi.append(ret)

print(min(candi))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
X = np.array(range(1,N+1))
b = np.average(A-X)
m0 = np.sum(np.absolute(A-X-int(b)+1))
m1 = np.sum(np.absolute(A-X-int(b)))
m2 = np.sum(np.absolute(A-X-int(b)-1))
print(min([m0,m1,m2]))

Submission status: Wrong Answer

Solution code:
size = int(input())
A = list(map(int,input().split()))
i = list(range(1,size+1))

remain_list = [A-i for(A,i) in zip(A,i)]
print(remain_list)
while(True):
    zero_count = len([i for i in remain_list if i ==0])
    minus_count = len([i for i in remain_list if i <0])
    plus_count = len([i for i in remain_list if i > 0])

    if zero_count == max(zero_count,minus_count,plus_count) or plus_count == minus_count:
        break

    if plus_count == max(zero_count,minus_count,plus_count):
        remain_list = [num - 1 for num in remain_list]

    if minus_count == max(zero_count,minus_count,plus_count):
        remain_list = [num + 1 for num in remain_list]


sum_list =[abs(num) for num in remain_list]
print(sum_list)
print(sum(sum_list))

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
input_list = []
input_counter = Counter()
ans = 0
index = 1
for i in input().split():
    item = int(i) - index
    input_list.append(item)
    input_counter[item] += 1
    index += 1

b = max(input_counter, key=input_counter.get)

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

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
number=[]
for i in range (N):
    number.append(i)
diff=[]
for j in range (N):
    diff.append(number[j]-A[j])
print(diff)
import collections
c = collections.Counter(diff)
c.most_common()
print(c.most_common())
for k in range (N):
    diff[k]=abs(diff[k]-c.most_common()[0][0])
print(sum(diff))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
i = 1
#for j in range(len(A)):
#    A[j] = A[j] - i
#    i += 1

#print(A)

B = sum(A) - N * (N + 1) // 2
#print(B)

if B == 0:
    ans = 0
    for i in range(len(A)):
        ans = ans + abs(A[i] - i - 1)

    print(ans)

elif B > 0:
    b = 0
    C = B - N*b
    while abs(C) > abs(C - N * (b + 1)):
        b += 1
        C = C - N * b

    print(C)

elif B < 0:
    b = 0
    C = B - N * b
    while abs(C) > abs(C - N * (b - 1)):
        b -= 1
        C = C - N * b

    print(C)

Submission status: Wrong Answer

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

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

subA = []
sub_dic = {}
for i in range(N):
    tmp = An[i]-(i+1)
    subA.append(tmp)
    if tmp in sub_dic:
        sub_dic[tmp] += 1
    else:
        sub_dic[tmp] = 1


# print(subA)
# print(sub_dic)

if max(sub_dic.values()) == 1:
    min_v = 0
    for v in subA:
        min_v += abs(v)
    print(min_v)

else:

    max_sub_k = max([(v,k) for k,v in sub_dic.items()])[1]

    min_v = 0
    for k,v in sub_dic.items():
        min_v += (k - max_sub_k) * v

    print(abs(min_v))

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = input().split(" ")
nums2 = [int(x)-i-1 for i,x in enumerate(nums)]
nums2.sort()
length = len(nums2)
numpre = 0
same = 1
if length == 1:
  value = nums2[0]

for n,m in zip(nums2[:-1],nums2[1:]):
  print("c")
  if n == m:
    same += 1
  else:
    impact = same + numpre
    if impact > length-impact:
      value = n
      break
    numpre += same
    same = 1
  value = m

answer = 0
for i in nums2:
  answer += abs(i-value)
print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = map(int, input().split())
A = list(A)
SA = sorted(A)
b = SA[N-1] - N
ans = 0
for i in range(N):
    x = abs(A[i] - (b+i+1))
    ans += x
print(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 - 1)

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

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

print(min(s1,s2,s3))

Submission status: Wrong Answer

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

B = 0
for i in range(N):
    value = A[i] - (i+1)
    B += value
sigma = B
B = round(B / N)

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

print(ans)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3

import math

n = int(input())
a = [int(i) for i in input().split()]
b = [0 for i in range(n)]
b_sum = 0

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

b_avg = math.floor(b_sum / n)

tmp = b_avg

res = 10**16

while True:
    v = 0
    for i in range(n):
        v += abs(a[i] - tmp - (i + 1))
    if v < res:
        res = v
    else:
        break
    tmp += 1

while True:
    v = 0
    for i in range(n):
        v += abs(a[i] - tmp - (i + 1))
    if v < res:
        res = v
    elif v > res:
        break
    tmp -= 1

print(res)

Submission status: Wrong Answer

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

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

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

mn = 100000000000000000000
sum_b1 = 0
for i in range(0, n):
    sum_b1 += abs(a[i] - (i+1+b1))
if mn > sum_b1:
    mn = sum_b1

sum_b2 = 0
for i in range(0, n):
    sum_b2 += abs(a[i] - (i+1+b2))
if mn > sum_b2:
    mn = sum_b2
print(mn)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
result = 2 ** 32
for b in range(-2 * N, 2 * N):
    tmp = 0
    for i in range(N):
        tmp += abs(A[i] - (b + i))
        if(tmp > result):
            break
    if(result > tmp):
        result = tmp
print(result)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a= list(map(int,input().split()))
ans = 100000000000
#b = [0 for i in range(n+1)]

#for i in range(n):
#    b[i+1] = b[i] + a[i]
sa = 0
ans = 0
for i in range(n):
    b = abs(a[i] -(i+1))
    #print(b)
    ans += b
    sa = max(sa,b)
#print(ans)
c = 0
d = 0
for i in range(n):
    c += abs(a[i] - (sa+i+1))    
    d += abs(a[i] - (i+1-sa))
    #print(c,d)
ans = min(c,d,ans)


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

#四捨五入
if sum >= 0:
    b = round(sum/n)
else:
    b = round(sum/n) - 1

#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 numpy as np

n = int(input())
arr = np.array(list(map(int,input().split())))
per = np.array([i+1 for i in range(n)])

arr = arr-per

arr2 = arr.copy()

arr2.sort()

kouho = (arr2[0]+arr2[-1])//2
kouho1 = kouho+1
kouho2 = kouho-1

m = [np.sum(np.abs(arr-kouho)),np.sum(np.abs(arr-kouho1)),np.sum(np.abs(arr-kouho2))]


print(int(min(m)))

Submission status: Wrong Answer

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

print(m())

Submission status: Wrong Answer

Solution code:
def match_num(a, match):
    match_lst = []
    match = [j-len(match) for j in match]
    for k in range(len(match)*2):
        match_b = 0
        for i in range(len(match)):
            if a[i] == match[i]:
                match_b += 1
        match_lst.append(match_b)
        print(match) ##
        match = [j+1 for j in match]
    print(match_lst) ##
    return match_lst

def absnuke(a, b, n):
    sum = 0
    for i in range(n):
        sum += abs(a[i]-(b+i+1))
    return sum

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


match = [x for x in range(1,n+1)]

ans = match_num(a, match)

if max(ans)==1:
    b = 0
else:
    b = ans.index(max(ans))-len(match)
print(absnuke(a, b, n))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
output = 0
b = [abs(elem - i) for i, elem in enumerate(a, 1)]
c = Counter(b)
d = c.most_common()

surume = 0
if len(d) == 1:
    surume = d[0][0]
else:
    if d[0][1] == d[1][1]:
        surume = 0
    else:
        surume = d[0][0]
c = map(lambda n: abs(n-surume), b)
print(sum(c))

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
array = [int(x) for x in input().split()]
array2 = [array[x]-(x+1) for x in range(len(array))]

sad = sum(array2)

b = math.ceil(sad/n)*-1 if sad >= 0 else math.ceil(sad//n)
tmp = sum([abs(abs(x) + b) for x in array2])

print(tmp if sad > tmp else sad)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
ck = 10000000000
for b in range(0,N+1):
    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(b)
        print(ck)
        break

Submission status: Wrong Answer

Solution code:
import copy

N = int(input())
An = list(map(int, input().split()))
Bn = [x for x in An]

for n in range(N):
    An[n] -= (n+1)

An.sort()

if (N % 2 == 0):
    cent = An[(N-1)//2] + An[(N-1)//2 + 1] // 2
else:
    cent = An[(N-1)//2]

ans = 0
for n in range(N):
    ans += abs(Bn[n] -(cent+n+1))

print(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:
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).astype('int64'), np.ceil(c).astype('int64')
min_1 = np.abs(b - c1).sum()
min_2 = np.abs(b - c2).sum()
print(min(min_1, min_2))

Submission status: Wrong Answer

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

for i in range(N):
    sad += abs(A[i]-(i+1))
    sad_2 += A[i]-(i+1)

if sad_2==0:
    print(sad)

elif sad_2<0:
    print(abs( sad- abs(( (sad_2//N)*N ))))
    
else:
    print(sad-( (sad//N)*N ))

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list(map(int, input().split()))
sum=0
absum=0
absum2=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:
    b=int(abs(sum)/N)
    if sum<0:
        for j in range(N):
            absum+=abs(l[j]-(j+1)+b)
            absum2+=abs(l[j]-(j+1)+b+1)
    else:
        for j in range(N):
            absum+=abs(l[j]-(j+1)-b)
            absum2+=abs(l[j]-(j+1)-b-1)
    print(min(absum,absum2))

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)]
min_fa = min(fa)
max_fa = max(fa)
min_fb = sum(map(lambda x: x - min_fa, fa))
max_fb = -1 * sum(map(lambda x: x - max_fa, fa))
result = min_fb if min_fb < max_fb else max_fb
print result

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
ck = 10000000000
for b in range(0,N+1):
    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(b)
        print(ck)
        break

Submission status: Wrong Answer

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

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

subA = []
sub_dic = {}
for i in range(N):
    tmp = An[i]-(i+1)
    subA.append(tmp)
    if tmp in sub_dic:
        sub_dic[tmp] += 1
    else:
        sub_dic[tmp] = 1


print(subA)
print(sub_dic)

if max(sub_dic.values()) == 1:
    min_v = 0
    for v in subA:
        min_v += abs(v)
    print(min_v)

else:

    max_sub_k = max([(v,k) for k,v in sub_dic.items()])[1]

    min_v = 0
    for k,v in sub_dic.items():
        min_v += (k - max_sub_k) * v

    print(abs(min_v))

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 == 32 or c == 0:
            print c
            break
        
main()

Submission status: Wrong Answer

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

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

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

mn = 10000000000000
sum_b1 = 0
for i in range(0, n):
    sum_b1 += abs(a[i] - (i+1+b1))
if mn > sum_b1:
    mn = sum_b1

sum_b2 = 0
for i in range(0, n):
    sum_b2 += abs(a[i] - (i+1+b2))
if mn > sum_b2:
    mn = sum_b2
print(mn)

Submission status: Wrong Answer

Solution code:
import math
input()
A = [int(a)-i-1 for i, a in enumerate(input().split())]
avg = math.floor(sum(A)/len(A))
print(sum(abs(a-avg) for a in A))

Submission status: Wrong Answer

Solution code:
import itertools, math

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


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

b_low = math.floor(SUM//N)
b_high = math.ceil(SUM//N)

S_low = 0
S_high = 0

for i in range(N):
	S_low  += abs(A[i] - b_low  - i)
	S_high += abs(A[i] - b_high - i)

print(min(S_low,S_high))

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(1e2)


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:
def run(n, a):
    a = [a[i]-i-1 for i in range(len(a))]
    a.sort()
    m = a[int((n-1)/2)]
    ret = 0
    for ai in a:
        print('ai - m', (ai - m))
        ret += abs(ai - m)
    return ret


def read_line():
    n = int(input())
    a = list(map(int, input().split()))
    return (n, a)


def main():
    n, a = read_line()
    print(run(n, a))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

x=10**10
for i in range(1,n+1):
    al.append(abs(a[i-1]-i))
    s+=abs(a[i-1]-i)
    
for i in range(1,max(al)+1):
    s2=0
    for j in range(n):
        s2+=abs(al[j]-i)
    if s2<x:
        x=s2
print(x)

Submission status: Wrong Answer

Solution code:
b = int(input())
x = list(map(int, input().split()))

def absadd(a_i, i, B):
    print(a_i, i, B, '\n')
    return abs((a_i-i) -B)

candi = []
for B in range(-b, b):
    ret = 0
    for idx, ele in enumerate(x):
        ret += absadd(ele, idx+1, B)

    candi.append(ret)

print(min(candi))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
S=list(map(int,input().split()))

ans=10**15

ave=0
for i in range(N):
    ave+=S[i]
ave=ave//N


ansj=0
for i in range(ave-N//2-5,ave-N//2+5):
    goukei=0
    for j in range(N):
        goukei+=abs(S[j]-(i+j+1))
        ansj=j
    if ans>goukei:
        ans=goukei
        

for i in range(max(S)-5,max(S)+5):
    goukei=0
    for j in range(N):
        goukei+=abs(S[j]-(i+j+1))
        ansj=j
    if ans>goukei:
        ans=goukei

for i in range(min(S)-5,min(S)+5):
    goukei=0
    for j in range(N):
        goukei+=abs(S[j]-(i+j+1))
        ansj=j
    if ans>goukei:
        ans=goukei
        
print(ans)

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)]
b1 = sum(a2)//n
b2 = b1 - 1
b3 = b1 + 1
ans1 = 0
ans2 = 0
ans3 = 0
for i in range(n):
	ans1 += abs(a2[i] - b1)
	ans2 += abs(a2[i] - b2)
	ans3 += abs(a2[i] - b3)
print(min(ans1,ans2,ans3))

Submission status: Wrong Answer

Solution code:
import collections
 
N = int(input())
A = [int(i) for i in input().split()]
 
sub = [A[i]-(i+1) for i in range(N)]
m = collections.Counter(sub).most_common()
res = 0
 
if m[0][1] == 1:
    if m[0][0] == -m[len(sub)-1][0]:
        for i in range(N):
            res += abs(A[i]-(i+1))
    else:
        maxNum = max(sub)
        minNum = min(sub)
        if abs(maxNum) < abs(minNum):
            for i in range(N):
                res += abs(A[i]-(maxNum+i+1))
        else:
            for i in range(N):
                res += abs(A[i]-(minNum+i+1))
else:
    for i in range(N):
        res += abs(A[i]-(m[0][0]+i+1))
print(res)

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)
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:
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()
a_S=sum(a)
ans=10**12
for b in range(a_S//n-10,a_S//n+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:
import math
N = int(input())
a = list(map(int,input().split()))
c = []
for i in range(N):
    c.append(a[i]-(i+1))
c.sort()
ave = sum(c)/N
avef = math.floor(ave)
avec = avef + 1
b = 0
if abs(avef-ave) < abs(avec-ave):
    b = avef
else:
    b = avec
ans = 0
for i in range(N):
    ans += abs(b-c[i])
print(ans)

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(min(ans))