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:
def k(arr,n):
  o=1
  s=0
  for k in arr:
    s+=abs(k-(n+o))
    o+=1
  return s

input()
a=input().split()
b=[]
for x in a:
  b.append(int(x))

r=9999999999
for z in range(-max(b),max(b)):
  buf=k(b,z)
  if buf<r:
    r=buf
  else:
    break

print(r)

Submission status: Wrong Answer

Solution code:
size = int(input())
array = list(map(int, input().split(' ')))
x = [i for i in range(1, size+1)]
diff = 0
for i in range(0, size):
    diff += array[i] - x[i]
result = 0
diff = diff//size
for i in range(0, size):
    temp = array[i] - x[i] - diff
    result += temp if temp>0 else -1*temp
print(result)

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 = math.floor(sum(an)/len(an))
b2 = math.ceil(sum(an)/len(an))
b3 = int(sum(an)/len(an))
bs = [sum([abs(an[i] - b1) for i in range(N)]), sum([abs(an[i] - b2) for i in range(N)]), sum([abs(an[i] - b3) for i in range(N)])]
print(min(bs))

Submission status: Wrong Answer

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

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

ave1=sum(A)//len(A)

ave2=-(-sum(A)//len(A))
B=A[:]
for i in range(0,N):
    A[i]-=ave1
    B[i]-=ave2
    A[i]=abs(A[i])
    B[i]=abs(B[i])
print(min(sum(A),sum(B)))

Submission status: Wrong Answer

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

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

ans1 = 0
a = sum(B)//N
for k in B:
    ans1 += abs(k-a)

ans2 = 0
b = 1+a
for k in B:
    ans2 += abs(k-b)

print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())

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

b = math.floor(((sum(A) - (N + 1) * (N)/2)/N))
s0 = 0
s1 = 0
s2 = 0

for i in range(N):
    s0 += abs(A[i] - b - i - 1)
    s1 += abs(A[i] - b - i)
    s2 += abs(A[i] - b - i - 2)

print(min([s0, s1, s2]))

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) :
for i in range(0, 2*(10**5) + 2) :
    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)
        
print(min_sum)

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))
M = np.array([X,np.ones(len(X))])
M = M.T
a,b = np.linalg.lstsq(M,A)[0]
m1 = np.sum(np.absolute(A-N-int(b)))
m2 = np.sum(np.absolute(A-N-int(b)-1))
print(min([m1,m2]))

Submission status: Wrong Answer

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

A = sum(a)
B = n * (n+1) // 2
b = (A - B) // n

for i in range(n-1):
    ans += abs(a[i] - (b+(i+1)))
print(int(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)
sum = 0
for i in range(n):
    sum += a[i]
key = [sum//n+i for i in range(-50,51)]
ans = [0 for i in range(101)]
for i in range(101):
    for j in range(n):
        ans[i] += abs(a[j]-key[i])
print(min(ans))

Submission status: Wrong Answer

Solution code:
N=int(input())
line=input()
line=line.rstrip().split(" ")
list1=[]
for i in range(N):
    list1.append(int(line[i]))
#print(list1)
list2=[]
list3=[]
for k in range(2):
    for j in range(N):
        list2.append(abs(list1[j]-j-1+k))
    list3.append(sum(list2))
#print(list3)
if list3[0]>=list3[1]:
    count=10000000000000
    
    for l in range(100000):
        list4=[]
        for m in range(N):
            list4.append(abs(list1[m]-m-1-l))
        if sum(list4)<=count:
            count=sum(list4)
        else:
            print(count)
                
            break
            
        
else:
    count=10000000000000
    for l in range(-1,100000):
        list4=[]
        for m in range(N):
            list4.append(abs(list1[m]-m-1+l))
            
        if sum(list4)<=count:
            count=sum(list4)
        else:
            print(count)
            #print(list4)
            break

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split(" ")))
countList = []

for b in range(-n, n):
    count = 0
    for i in range(n):
        count += abs(A[i] -(b +(i + 1)))
    countList.append(count)
print(min(countList))

Submission status: Wrong Answer

Solution code:
def FindAns(A, b):
    ans = 0
    for a in A:
        ans += abs(a - b)
    return ans

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

center = int(sum(A) / len(A))
print(min(FindAns(A, center - 1), FindAns(A, center), FindAns(A, center + 1)))

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)

candidates = [b_avg - 2, b_avg - 1, b_avg, b_avg + 1, b_avg + 2]

res = 10000000000

for c in candidates:
    v = 0
    for i in range(n):
        v += abs(a[i] - c - (i + 1))
    if v < res:
        res = v

print(res)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
l=list(map(int, input().split()))
for i in range(n):
    l[i]-=(i+1)
avg=sum(l)/n
fb=math.floor(avg)
cb=math.ceil(avg)
sadf=sadc=0
for i in l:
    sadf+=abs(i-fb)
    sadc+=abs(i-cb)

sad=min(sadf, sadc)
print(sad)

Submission status: Wrong Answer

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

ans=10**10

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

for i in range(ave-N//2-10,ave-N//2+10):
    goukei=0
    for j in range(N):
        goukei+=abs(S[j]-(i+j+1))
        
    if ans>goukei:
        ans=goukei
        
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

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

print(s)

Submission status: Wrong Answer

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

def kanashimi(b):
    
    out = 0
    for i in range(N):
        out = out + abs(A[i]-(b+(i+1)))
    return out 
tmp = sum(A)/N - (N+1)/2
if tmp > 0:
    b = math.floor(tmp)
else:
    b = math.ceil(tmp)

print(kanashimi(b))

Submission status: Wrong Answer

Solution code:
N=int(input())

a2=list(map(int,input().split()))
a=[0]*N

for i in range(1,N+1):
    a[i-1]=a2[i-1]-i

b1=sum(a)//N

b2=b1+1

sum_a1=0

for i in range(N):
    sum_a1+=abs(a[i]-b1)


sum_a2=0

for i in range(N):
    sum_a2+=abs(a[i]-b2)

if sum_a2>sum_a1:
    print(sum_a1)
else:
    print(sum_a2)

Submission status: Wrong Answer

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

max_num = max(len(n_list), max(n_list))
min_num = 0

min_sad = float('Inf')

for b in range(min_num, max_num+1):
  sad = 0
  for i, a in enumerate(n_list):
    sad += abs(a-(b+i+1))
  min_sad = min(min_sad, sad)

print(min_sad)

Submission status: Wrong Answer

Solution code:
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]

b = su // N

result = 0
for i in range(len(A)):
    result += abs(A[i] - b)

print(result)

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
if counter_m == N:
    min_temp = -min(temp2)
    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 = -max(temp2)
    for i in range(N):
        temp2[i]+=max_temp
    print(sum(list(map(abs,temp2)))) 
else:
    print(sum(list(map(abs,temp2))))

Submission status: Wrong Answer

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

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

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


print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
    a[i] = a[i] - i - 1
count = Counter(a)
if max(count.values()) == 1:
    for i in range(n):
        ans += abs(a[i])
else:
    ans_0 = 0
    for i in range(n):
        ans_0 += abs(a[i])
    b = 0
    max_value = 0
    keys = list(count.keys())
    values = list(count.values())
    for i, value in enumerate(values):
        if max_value < value:
            max_value = value
            b = keys[i]
    for i in range(n):
        ans += abs(a[i] - b)
    if ans_0 < ans:
        ans = ans_0
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stderr
from functools import reduce
from operator import add
def f(): return [int(i) for i in input().split()]
def debug(*x, sep=" ", end="\n"):
    for item in x:
        stderr.write(repr(item))
        stderr.write(sep)
    stderr.write(end)

n = int(input())
a = f()

b = (sum(a) - sum(range(1,n+1))) // n
ans = 0
for i,v in enumerate(a):
    ans += abs(v - (b + i + 1))
print(ans)

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)
  ans.append(sum(temp))

print(min(ans))

Submission status: Wrong Answer

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

for j in range(10000):
    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:
from statistics import mean
import math
N = int(input())
*A, = map(int, input().split())
B = [A[i]-i for i in range(N)]
b = mean(B)
bm = math.floor(b)
K = [x - bm for x in B]
KZ = [abs(x) for x in K]
Z = sum(KZ)
for i in range(200):
    C = [abs(x-i+100) for x in K]
    Z = min([sum(C),Z])
print(int(Z))

Submission status: Wrong Answer

Solution code:
def sad_value(a,b,N):
	sumNum=0
	for i in range(N):
		sumNum+=abs(a[i]-(b+i))

	return sumNum


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

min_sad=100000


for i in range(-N,N):
	sadV=sad_value(b,i,N)
	if(min_sad>sadV):
		min_sad=sadV


print(min_sad)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
a2 = [0] * n
b = 999999999999

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

#print(a2)
res = [0] * n
mean = sum(a2)//n
for i in range(n):
    res[i] = abs(a2[i] - mean)

print(sum(res))

Submission status: Wrong Answer

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

Ad = []
for i, v in enumerate(A):
    Ad.append(v - i - 1)

average = int(round(sum(Ad) / float(len(Ad))))

diff = 0
for i, v in enumerate(A):
    diff += abs(v - (average + i + 1))
    # diff += abs(v - (i + 1))

# print(A)
# print(Ad)
# print(average)
print(diff)

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)])
a_sum = np.sum(arr)
sum = n*(n+1)/2

kouho1 = (a_sum-sum)//n
kouho2 = kouho1+1
kouho3 = kouho1-1

a1 = arr-kouho1
a2 = arr-kouho2
a3 = arr-kouho3

a1 = a1-per
a2 = a2-per
a3 = a3-per

tes = [np.sum(np.abs(a1)),np.sum(np.abs(a2)),np.sum(np.abs(a3))]


print(int(min(tes)))

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
s = 0
for i in range(n):
    s += a[i]
#print(a)

s = s/n
s_i = int(s)
#print(s)

num1 = s_i
if num1>=0:
    num2 = num1 + 1
else: num2 = num1 - 1

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
num_str=input().split()
num=list(map(int, num_str))
num=list(map(lambda x: x-1, num))
for b in range(max(num)):
    ans=0
    best=0
    map(lambda x:abs(x-b)+ans,num)
    best=min(ans,best)
print(best)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())

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

b = math.floor(((sum(A) - (N + 1) * (N)/2)/N))
s = 0

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

print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
a2 = [0] * n
b = 999999999999

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

print(a2)
res = [0] * n
mean = sum(a2)//n
for i in range(n):
    res[i] = abs(a2[i] - mean)

print(sum(res))

Submission status: Wrong Answer

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

A = sum(a)
B = n * (n+1) / 2
b = (A - B) / n

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

Submission status: Wrong Answer

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

l=list()
for i in range(N):
  l.append(A[0]-(N+1))
s=sum(l)
n=s/N
if n==0:
  print(0)
else:
  print(s-N*round(n))

Submission status: Wrong Answer

Solution code:
from statistics import mean

N = int(input())

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

for i in range(N):
  A[i]=A[i]-(i+1)
  
m = round(mean(A))
m_plus = m+1
m_minus = m-1
m_plus2 = m+2
m_minus2 = m-2

out_a = 0
out_b = 0
out_c = 0
out_d = 0
out_e = 0

for i in A:
  out_a += abs(i-m)
  out_b += abs(i-m_plus)
  out_c += abs(i-m_minus)
  out_d += abs(i-m_plus2)
  out_e += abs(i-m_minus2)
  
print(min(out_a,out_b,out_c,out_d,out_e))

Submission status: Wrong Answer

Solution code:
def solve(xs, n):
    xs = [x - i for (x, i) in zip(xs, range(1, n + 1))]
    b, m = divmod(sum(xs), len(xs))
    s = sum(abs(x - b) for x in xs)
    if m == 0:
        return s
    return min(s, abs(sum(abs(x - b + 1) for x in xs)), abs(sum(abs(x - b - 1) for x in xs)))

if __name__ == "__main__":
    n = int(input())
    xs = [int(s) for s in input().split()]
    print(solve(xs, n))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    A_i = []
    for i in range(N):
        A_i.append(int(input_raw[i]) - i)

    ave_A = (sum(A_i)/N)
    b1 = (ave_A)
    b2 = ave_A + 1
    b3 = (max(A_i) + min(A_i))/2
    b4 = (max(A_i) + min(A_i))/2 + 1
    score1 = 0
    score2 = 0
    score3 = 0
    score4 = 0
    for i in range(N):
        score1 += abs(b1 - A_i[i])
        score2 += abs(b2 - A_i[i])
        score3 += abs(b3 - A_i[i])
        score4 += abs(b4 - A_i[i])


    print min(score1, score2, score3, score4)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))

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

sumB = 0
for i in range(N):
    sumB += B[i]

average = sumB / N

b_median = int(average)
b_small = b_median - 1
b_large = b_median + 1

sum_m = 0
sum_s = 0
sum_l = 0
for i in range(N):
    sum_m += abs(B[i] - b_median)
    sum_s += abs(B[i] - b_small)
    sum_l += abs(B[i] - b_large)

print(min([sum_m, sum_s, sum_l]))

Submission status: Wrong Answer

Solution code:
a = int(input())
b = [int(i) for i in input().split()]
n = float("inf")
for i in range(-100000,100000):
     k = 0
     for j in range(a):
         k += abs(b[j] - (i + j))
     if k < n:
         n = k
print(n)

Submission status: Wrong Answer

Solution code:
import sys


def main():
    """
    1 <=  N <= 2 * 10^5
    1 <= ai <= 10^9
    """
    N = int(input())
    *A, = map(int, input().split())

    ans = f(N, A)
    print(ans)


def f(N, A):
    """
    直感: Aの平均値 => はずれ
    A-iの平均値
    """
    C = [a - i for i, a in enumerate(A, 1)]
    b = sum(C) // N
    # print(b)
    # print(C)
    ans = sum(abs(c - b) for c in C)

    return ans


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split(" ")))
A_i = [0]*N
K_1 = 0
K_2 = 0
K_3 = 0

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

b_0 = sum(A_i) / len(A_i)

b_1 = int(b_0)
b_2 = b_1 - 1
b_3 = b_1 + 1

for i in range(N):
    K_1 = K_1 + abs(A_i[i] - b_1)
    K_2 = K_2 + abs(A_i[i] - b_2)
    K_3 = K_3 + abs(A_i[i] - b_3)

print(min(K_1, K_2, K_3))

Submission status: Wrong Answer

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

min_sum = 9999999999999
i_atmin = -1
prev_i = -1

checked_both = 0

# for i in range(0, 2*(10**5) + 2) :
for i in range(0, 2*(10**5) + 2) :
    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_over, sum_over_minus) > min_sum :
        break
        
    if min(sum_over, sum_over_minus) < min_sum :
        min_sum = min(sum_over, sum_over_minus)
        # i_atmin = i
        
    # print("DBG : ", i, sum_over)
        
print(min_sum)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
num=900
count=46463435
b=0
while(num>=0):
    sum=0
    for i in range(len(l)):
        sum+=abs(l[i]-(b+i))
    if(sum<count):
        count=sum
    b+=1
    num-=1
print(count)

Submission status: Wrong Answer

Solution code:
import sys


def main():
    """
    1 <=  N <= 2 * 10^5
    1 <= ai <= 10^9
    """
    N = int(input())
    *A, = map(int, input().split())

    ans = f(N, A)
    print(ans)


def f(N, A):
    """
    直感: Aの平均値 => はずれ
    A-iの平均値
    """
    C = [a - i for i, a in enumerate(A, 1)]
    b = sum(C) // N
    print(b)
    print(C)
    ans = sum(abs(c - b) for c in C)

    return ans


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

ave = round(sum(s2) / N)
ave2 = ave -1
ave3 = ave +1


x = [abs(s1[j] - (ave + j)) for j in range(N)]
y = [abs(s1[j] - (ave2 + j)) for j in range(N)]
z = [abs(s1[j] - (ave3 + j)) for j in range(N)]

print(min(sum(x),sum(y),sum(z)))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ans=10**10

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

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

Submission status: Wrong Answer

Solution code:

import math


def main():
    n=input()
    n=int(n)
    temp=input()
    temp=list(map(int,list(temp.split(" "))))    
    
    ans=0
    for i in range(n):
        temp[i]-=(i+1)
    av = sum(temp)/len(temp)
    can1=math.ceil(av)
    can2=math.floor(av)
    can3=can1-1
    can4=can1+1
    can5=can2-1
    can6=can2+1
    cans=[can1,can2,can3,can4,can5,can6]
    anss=[]
    for c in cans:
        for t in temp:
            ans+=abs(t-c) 
        anss.append(ans)  
        ans=0  

    print(min(anss))  
    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

a_mean = round(sum(a_m) / N)
if a_mean < 0:
    a_mean = a_mean - 1

results = [abs(a - a_mean) for a in a_m]
print(sum(results))

Submission status: Wrong Answer

Solution code:
def c_linear_approximation(N, A):
    import collections
    t = [None for _ in range(len(A))]
    for j, k in enumerate(A):
        t[j] = k-(j+1)
    t_freq = collections.Counter(t)
    freq_max = -1
    freq_option = []
    for k, v in t_freq.items():
        if v > freq_max:
            freq_option = [k]
            freq_max = v
        elif v == freq_max:
            freq_option.append(k)
    ans = float('inf')
    for b in freq_option:
        tmp = 0
        for t_k in t:
            tmp += abs(t_k-b)
        ans = min(ans, tmp)

    return ans
N = int(input())
A = [int(i) for i in input().split()]
print(c_linear_approximation(N, A))

Submission status: Wrong Answer

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

not_abs = [v-i for i, v in enumerate(a, 1)]

c = Counter(not_abs)
num = c.most_common()[0][0]
total = 0


for i in range(n):
    not_abs[i] -= num
    total += abs(not_abs[i])

print(total)

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)])
a_sum = np.sum(arr)
sum = n*(n+1)/2

kouho1 = (a_sum-sum)//n
kouho2 = n+1
kouho3 = n-1

a1 = arr-kouho1
a2 = arr-kouho2
a3 = arr-kouho3

a1 = a1-per
a2 = a2-per
a3 = a3-per

tes = [np.sum(np.abs(a1)),np.sum(np.abs(a2)),np.sum(np.abs(a3))]

print(int(min(tes)))

Submission status: Wrong Answer

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

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

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

a.sort()
as0=[-i for i in a if i<0]
al0=[i for i in a if i>=0]
ans=10**12
b_choice=[]
if len(as0)>0:
    for i in range(as0[-1]-100,as0[-1]+100):
        b_choice.append(i)
if len(al0)>0:
    for i in range(al0[0]-100,al0[0]+100):
        b_choice.append(i)
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:
m=int(input())
l=list(map(int,input().split()))
s=1
li=[]
for i in l:
    li.append(i-s)
    s+=1
s=int(sum(li)/s)

list=[abs(i-s) for i in li]
print(sum(list))

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:
    for i in range(N):
        res += abs(A[i]-(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:
n = int(input())
a = list(map(int,input().split()))

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

s = s/n
s_i = int(s)
#print(s)

num1 = s_i
if num1>=0:
    num2 = num1 + 1
else: num2 = num1 - 1

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

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

Submission status: Wrong Answer

Solution code:
def k(arr,n):
  o=1
  s=0
  for k in arr:
    s+=abs(k-(n+o))
    o+=1
  return s

input()
a=input().split()
b=[]
for x in a:
  b.append(int(x))

r=9999999999
for z in range(0,10):
  buf=k(b,z)
  if buf<r:
    r=buf
  print(buf)

print(r)

Submission status: Wrong Answer

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

for i in range(N):
    A[i] -= i+1
    
R = math.ceil(sum(A)/N)
L = sum(A)//N
    
ansR, ansL = 0, 0
for i in A:
    ansR += abs(i-R)
    ansL += abs(i-L)

print(min(ansR,ansL))

Submission status: Wrong Answer

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

sum = 0
ans = []

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

print(min(ans))

Submission status: Wrong Answer

Solution code:
def solve(xs, n):
    xs = [x - i for (x, i) in zip(xs, range(1, n + 1))]
    b, m = divmod(sum(xs), len(xs))
    s = sum(abs(x - b) for x in xs)
    if m == 0:
        return s
    return min(s, abs(sum(abs(x - b + 1) for x in xs)))

if __name__ == "__main__":
    n = int(input())
    xs = [int(s) for s in input().split()]
    print(solve(xs, n))

Submission status: Wrong Answer

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

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

avg = (total/N)

'''
up = 0
down = 0
for i in range(N):
    if avg >= A[i]:
        down = down + 1
    else:
        up = up + 1


if down > up:
    if avg < 0:
        avg = int(avg) - 1
    else:
        avg = int(avg)
else:
    avg = round(avg)



sad = 0
for i in range(N):
    sad = sad + abs(A[i]-avg)
'''

l = [int(avg)-1,int(avg),int(avg) + 1]
sad = []
for i in range(3):
    tmp = 0
    for j in range(N):
        tmp = tmp + abs(A[j]-l[i])
    sad.append(tmp)
    
print(min(sad))

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

c=int(sum(s)/b)
d=0
for j in range(0,b):
    d+=abs(c-s[j])
print(d)

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)]

b = math.floor(sum(an)/len(an))
print(sum([abs(an[i] - b) for i in range(N)]))

Submission status: Wrong Answer

Solution code:
import math

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

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

av = sum(ns)/len(ns)

l = math.floor(av)
h = math.ceil(av)

ls = 0
hs = 0

for na in ns:
    ls += abs(na-l)
    hs += abs(na-h)

print(min(ls, hs))

Submission status: Wrong Answer

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

A2 = [A[i-1]-i for i in range(1,N+1)]
A2x = Counter(A2).most_common()[0][0]

res = sum(map(abs, map(lambda x:x-A2x, A2)))

print(res)

Submission status: Wrong Answer

Solution code:
from pprint import pprint

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

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

# pprint(As)

b = sum(As)//len(As)

ans = 0

for A in As:
    ans += abs(A-b)

print(ans)

Submission status: Wrong Answer

Solution code:

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

Ai_i = []

for i in range(len(A)):
    Ai_i.append(A[i] - (i+1))

max_ = max(Ai_i)
min_ = min(Ai_i)


min_abs = 9999999999
min_index = 0

for b in range(min_-1, max_+1):
    abss = []
    for i in range(len(Ai_i)):
        abss.append(abs(Ai_i[i] + b))
    abs_sum = sum(abss)
    if abs_sum < min_abs:
        min_abs = abs_sum

print(min_abs)

Submission status: Wrong Answer

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

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

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

a.sort()
as0=[-i for i in a if i<0]
al0=[i for i in a if i>=0]
ans=10**12
b_choice=[]
if len(as0)>0:
    b_choice.append(as0[-1])
if len(al0)>0:
    b_choice.append(al0[0])
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:
N = int(input())
A = [int(i) for i in input().split()]

sum = 0
ans = []

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

print(min(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
la=list(map(int,input().split()))
lan=np.array(la)
for i in range(len(lan)):
    lan[i]=lan[i]-i-1
ave=np.mean(lan)
X0=sum(abs(lan-int(ave)))
X1=sum(abs(lan-int(ave)-1))
X2=sum(abs(lan-int(ave)+1))
print(min(X0,X1,X2))

Submission status: Wrong Answer

Solution code:
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=s//N
print(k(A,b))

Submission status: Wrong Answer

Solution code:
from statistics import mean
import math
N = int(input())
*A, = map(int, input().split())
B = [A[i]-i for i in range(N)]
b = mean(B)
bm = math.floor(b)
K = [x - bm for x in B]
KZ = [abs(x) for x in K]
Z = sum(KZ)
for i in range(20):
    C = [abs(x-i+10) for x in K]
    Z = min([sum(C),Z])
print(int(Z))

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*
N = int(input())
nums = list(map(int, input().split()))
nums_s = sorted(nums)
middle = int(len(nums_s)/2)
b = nums_s[middle] - (middle+1)

result = 0
for i in range(1,N+1):
    result += abs(nums[i-1]-(b+i))
print(result)

Submission status: Wrong Answer

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

L = [v - (i+1) for i,v in enumerate(A)]
b = sum(L) // N
ans = 0
for i in range(N):
    ans += abs(A[i] - (b + i+1))
print(ans)