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

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

def sad(b):
    f = lambda x: abs(x-b)
    return sum(map(f, A2))

max_ = max(A2)
min_ = min(A2)
cur = (max_ - min_) // 2
w = (max_ - min_) // 4

while(w > 0):
    left = cur - w
    right = cur + w

    cur_sad = sad(cur)
    left_sad = sad(left)
    right_sad = sad(right)

    #print(w, cur, cur_sad)
    if left_sad > cur_sad and cur_sad > right_sad:
        cur = right
    elif left_sad < cur_sad and cur_sad < right_sad:
        cur = left
    else:
        w = w // 2

print(sad(cur))

Submission status: Wrong Answer

Solution code:
import math

n=int(input())
a=list(map(int,input().split()))
b=[a[i]-(i+1) for i in range(n)]
sumb2=0
sum2=0
for bb in b:
    sumb2 += (bb**2)

for bb in b:
    sum2+=bb*2
bb=[math.ceil(sum2/(2*n))+i for i in range(-10,10)]
ans=10**10
print(math.ceil(sumb2-(sum2**2/(4*n))))

Submission status: Wrong Answer

Solution code:
def cal(l,b):
    ans=0
    t1 = 0
    t2 = 0
    for i in range(len(l)):
        t = l[i]-(i+1+b)
        ans +=abs(t)
        if t <=0:
            t1+= t
        else:
            t2+= t
    return (ans,t1,t2)

if __name__ == "__main__":
    N = int(input())
    l = list(map(int,input().split(' ')))
    maxb = max(l)
    minb = -2*10**5
    pid = int((maxb+minb)/2)
    ans =10**9
    while 1:
        temp = cal(l,pid)
        if ans >temp[0]:
            ans =temp[0]
        if minb >= pid or pid >= maxb:
            break
        if abs(temp[1]) >abs(temp[2]):
            maxb =pid
            pid=int((maxb+minb)/2)
        else:
            minb =pid
            pid=int((maxb+minb)/2)
    
    print(ans)

Submission status: Wrong Answer

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

S1=[]
for i in range(N):
    S1.append(S[i])
S1.sort()
chuouchi=S1[len(S1)//2]
chuouchi2=S1[len(S1)//2-1]
ans=10**20
ansj=0
A=chuouchi-N//2-5
B=chuouchi-N//2+5
C=chuouchi2-N//2-5
D=chuouchi2-N//2+5
for i in range(A,B):
    goukei=0
    for j in range(N):
        goukei+=abs(S[j]-(i+j+1))
        
    if ans>goukei:
        ans=goukei
        
for i in range(C,D):
    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=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=set(C)
L=list(K)
L.append(0)
L.sort()
 
h=len(L)
l=0
 
 
ans=float("inf")
 
for j in range(100):
	m=(h+l)/2
	x=L[m]
	t=0
	for y in C:
		t+=abs(-1*x+y)
 
	if 0<=t<ans:
		ans=t
		h=m
	else:
		l=m
	ans=min(ans,t)
 
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)
g2 = g1 - 1
g3 = g1 + 1
g4 = g1 - 2

d1 = 0
d2 = 0
d3 = 0
d4 = 0
j = 1
for i in a:
    d1 += abs(j + g1 - i)
    d2 += abs(j + g2 - i)
    d3 += abs(j + g3 - i)
    d4 += abs(j + g4 - i)
    j += 1
print(min(d1, d2, d3, d4))

Submission status: Wrong Answer

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

temp = range(1,N+1)
temp2=[]
counter_m = 0
temp_ans = 10**20
# 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:
    temp_sorted = sorted(temp2)
    min_temp = abs(temp_sorted[int(N/2)]) 
    # print(min_temp)
    # 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:
    temp_sorted = sorted(temp2)
    max_temp = - abs(temp_sorted[int(N/2)])
    # print(int(N/2)-1)
    # print("maxtemp:{}".format(max_temp))
    temp_counter = collections.Counter(temp2)
    # print(temp_counter)
    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:
# -*- coding: utf-8 -*-
"""
Created on Sun Jul  1 20:09:43 2018
ABC102C
@author: maezawa
"""
import math
n = int(input())
a = list(map(int, input().split()))

abssum = 0
pm = 0
normsum = 0

for i in range(n):
    d = abs(a[i]-i-1)
    abssum += d
    normsum += a[i]-i-1
    if d > 0:
        pm += 1
    elif d < 0:
        pm -= 1

b = math.floor(normsum/n)

#print(abssum, pm, normsum)
print(abs(abssum+pm*b))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
A -= np.arange(1,N+1)

def sad(b):
    return int(np.sum(np.abs(A - b)))

l = -1e10
r =  1e10
m = 1e30
tmp = 1e30
tmp2 = 1e30
while tmp2 != sad(m):
    if tmp > sad(m):
        tmp = sad(m)
    tmp2 = sad(m)
    m = (l + r) // 2
    if sad(m) - sad(m+1) >= 0:
        l = m
    else:
        r = m

print(tmp)

Submission status: Wrong Answer

Solution code:
N=int(input())

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

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

b1=sum(a3)//N

b = list(range(b1-3, b1+3))

sum_min = 1000000000000

for j in b:
    sum_a=0
    for i in range(N):
        sum_a+=abs(a[i]-j)
    if sum_a<sum_min:
        sum_min=sum_a

print(sum_min)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

bf = np.average(A_minus_i)
b = int(bf)

min_score = sum(A_minus_i)

scores = []

for i in range(0, 50):
    for j in (1, -1):
        score = sum([abs(a - (b+j*i)) for a in A_minus_i])
        scores.append(score)

print(min(scores))

Submission status: Wrong Answer

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

Ai_i = [0 for i in range(len(A))]

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

n = 5

b_ceil = ceil(sum(Ai_i) / len(Ai_i))

bs = list(range(b_ceil-n, b_ceil+n))

abss_ls = [ 0 for i in range(len(bs)) ]
for i in range(len(bs)):
    for j in range(len(Ai_i)):
        abss_ls[i] += abs(Ai_i[j] - bs[i])

min_abs = min(abss_ls)
print(min_abs)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
A = list(map(int, input().split()))
li = []
b = 0
if max(A) > sum(A):
  b = -max(A)
  for i in range(N):
    li.append(abs(A[i]-(b+i+1)))
  print(sum(li))
else :
  for i in range(N):
    li.append(abs(A[i]-(b+i+1)))
  c = collections.Counter(li)
  b = -c.most_common()[0][0]
  li.clear()
  for i in range(N):
    li.append(abs(A[i]-(b+i+1)))
  print(sum(li))

Submission status: Wrong Answer

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

min_ans = pow(10,15)
b = 0
step = int(max(A) / 2)
while True:
    ans = 0
    for i in range(len(A)):
        ans += abs(A[i] - (b + i + 1))
    if min_ans >= ans:
        min_ans = ans
        b += step
    else:
        b -= step
    step = int(step/2)
    if step < 1: break

min_ans_b = pow(10,15)
b = 0
step = int(-max(A) / 2)
while True:
    ans = 0
    for i in range(len(A)):
        ans += abs(A[i] - (b + i + 1))
    if min_ans_b >= ans:
        min_ans_b = ans
        b -= step
    else:
        b += step
    step = int(step/2)
    if step < 1: break

if min_ans_b < min_ans:
    min_ans = min_ans_b

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), n)
    s = sum(abs(x - b) for x in xs)
    return min(s, sum(abs(x - b + 1) for x in xs), 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:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
N = int(input())
A = list(map(int, input().split()))
T = int((N*(N+1))/2)
#print(sum(A),T)
b=int(((sum(A)-T)//N))
#print(b)
Total=0
print(int(sum(A)-T-N*b))
#for i in range(N):
 #   Total = Total+abs(A[i]-(b+(i+1)))
#print(Total)

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

# grief = INF
# for b in set(a):
#     tmp = sum([abs(ai - b) for ai in a])
#     if tmp < grief:
#         bb = b
#         grief = tmp

# print(grief)

mean = int(sum(a) / len(a))
grief = INF
for b in range(mean - 100, mean + 100):
    tmp_grief = sum([abs(ai - b) for ai in a])
    if tmp_grief < grief:
        grief = tmp_grief

print(grief)

Submission status: Wrong Answer

Solution code:
N =int(input())
A= list(map(int,input().split( )))
B = []
ANS = []
b = 0
t = 0
Ans =0
while True:
    for i in range(1,N+1):
        a = 0
        a = abs(A[i-1] - i - b)
        B.append(a)
    p = sum(B)
    ANS.append(p)
    B = []
    b = b - 1
    t = t + 1
    if t == 100:
        break
Ans = min(ANS)   
print(Ans)

Submission status: Wrong Answer

Solution code:
import math

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

sum_i = 0
for i in range(1, len(n_list)+1):
  sum_i += i

avg_n = sum(n_list) / len(n_list)
avg_i = sum_i / len(n_list)
b = avg_n - avg_i
n_b = -(avg_n - avg_i)

pos_sad = 0
neg_sad = 0

for i, a in enumerate(n_list):
  pos_sad += abs(a-(b+i+1))

for i, a in enumerate(n_list):
  neg_sad += abs(a-(n_b+i+1))

print(math.floor(min(pos_sad, neg_sad)))

Submission status: Wrong Answer

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

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

def sad(b):
    f = lambda x: abs(x-b)
    return sum(map(f, A2))

max_ = max(A2)
min_ = min(A2)
cur = (max_ - min_) // 2
w = (max_ - min_) // 4

while(w > 1):
    left = cur - w
    right = cur + w

    cur_sad = sad(cur)
    left_sad = sad(left)
    right_sad = sad(right)

    #print(w, cur, cur_sad)
    if left_sad > cur_sad and cur_sad > right_sad:
        cur = right
    elif left_sad < cur_sad and cur_sad < right_sad:
        cur = left
    else:
        w = w // 2

print(sad(cur))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
A -= np.arange(1,N+1)

def sad(b):
    return int(np.sum(np.abs(A - b)))

l = -1e12
r =  1e12
m = 1e30
tmp = 1e30
tmp2 = 1e30
while tmp2 != sad(m):
    if tmp > sad(m):
        tmp = sad(m)
    tmp2 = sad(m)
    m = (l + r) // 2
    if sad(m) - sad(m+1) >= 0:
        l = m
    else:
        r = m

print(tmp)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

point = sum(input_list) // N
b = max(input_counter, key=input_counter.get)

for i in range(N):
    ans1 += abs(input_list[i] - b)
    ans2 += abs(input_list[i] - point)
    ans3 += abs(input_list[i] - point + 1)
    ans4 += abs(input_list[i] - point - 1)

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

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

# grief = INF
# for b in set(a):
#     tmp = sum([abs(ai - b) for ai in a])
#     if tmp < grief:
#         bb = b
#         grief = tmp

# print(grief)

mean = int(sum(a) / len(a))
grief = INF
for b in range(mean - 10, mean + 10):
    tmp_grief = sum([abs(ai - b) for ai in a])
    if tmp_grief < grief:
        grief = tmp_grief

print(grief)

Submission status: Wrong Answer

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

Ai_i = [0 for i in range(len(A))]

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

n = 50

b_ceil = ceil(sum(Ai_i) / len(Ai_i))

bs = list(range(b_ceil-n, b_ceil+n))

abss_ls = [ 0 for i in range(len(bs))]
for i in range(len(bs)):
    for j in range(len(Ai_i)):
        abss_ls[i] += abs(Ai_i[j] - bs[i])

min_abs = min(abss_ls)
print(min_abs)

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:
    fans=10000000000
    for j in range(100):
        ans1=0
        ans2=0
        for i in range(n):
            ans1+=abs(arr[i]-l-j)
            ans2+=abs(arr[i]-l+j)
        fans=min(fans,ans1,ans2)
    print(fans)

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

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

print(Sum_A-(b*N+k))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
N = int(input())
A = list(map(int, input().split()))
T = int((N*(N+1))/2)
#print(sum(A),T)
b=int(((sum(A)-T)//N))
#print(b)
Total=0
print(sum(A)-T-N*b)
#for i in range(N):
 #   Total = Total+abs(A[i]-(b+(i+1)))
#print(Total)

Submission status: Wrong Answer

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

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(-100* N, 100* 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:
# coding: utf-8
# Your code here!
N=int(input())
S=list(map(int,input().split()))

S1=[]
for i in range(N):
    S1.append(S[i])
S1.sort()
chuouchi=S1[len(S1)//2]
chuouchi2=S1[len(S1)//2-1]
ans=10**18
ansj=0
A=chuouchi-N//2-6
B=chuouchi-N//2+6
C=chuouchi2-N//2-6
D=chuouchi2-N//2+6
for i in range(A,B):
    goukei=0
    for j in range(N):
        goukei+=abs(S[j]-(i+j+1))
        
    if ans>goukei:
        ans=goukei
        
for i in range(C,D):
    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

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

sum_i = 0
for i in range(1, len(n_list)+1):
  sum_i += i

avg_n = sum(n_list) / len(n_list)
avg_i = sum_i / len(n_list)
b = avg_n - avg_i

min_sad = 0

for i, a in enumerate(n_list):
  min_sad += abs(a-(b+i+1))

print(math.floor(min_sad))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
A -= np.arange(1,N+1)

def sad(b):
    return int(np.sum(np.abs(A - b)))

l = -1e9
r =  1e9
m = 1e30
tmp = 1e30
tmp2 = 1e30
while tmp2 != sad(m):
    if tmp > sad(m):
        tmp = sad(m)
    tmp2 = sad(m)
    m = (l + r) // 2
    if sad(m) - sad(m+1) >= 0:
        l = m
    else:
        r = m

print(tmp)

Submission status: Wrong Answer

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

cmin=min(C)
cmax=max(C)
L=range(cmin,cmax+1)

h=len(L)
l=0


ans=float("inf")

for j in range(300):
	m=(h+l)/2
	x=L[m]
	t=0
	for y in C:
		t+=abs(-1*x+y)

	if t<ans:
		ans=t
		h=m
	else:
		l=m
	ans=min(ans,t)

print ans

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
l=list(map(lambda x:int(x),input().split(' ')))
l=[l[i]-(i+1) for i in range(N)]
dl=collections.Counter(l)
ans=[0]*(len(dl))
n=len(dl)//2
if n==0:
    n=1
for i in range(n):
    k=dl.most_common()[i][0] 
    k*=-1
    ans[i]=sum([abs(l[j]+k) for j in range(N)])
print(min(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

bf = np.average(A_minus_i)
b = int(bf)

min_score = sum(A_minus_i)

scores = []

for i in range(0, 100):
    for j in (1, -1):
        score = sum([abs(a - (b+j*i)) for a in A_minus_i])
        scores.append(score)

print(min(scores))

Submission status: Wrong Answer

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

s=10000000
aaa=max(a_list)-min(a_list)
b_list=range(min(a_list)-aaa,max(a_list)+aaa)

for i in range(len(b_list)):
  s_koho=0
  for j in range(len(a_list)):
    s_koho += abs(a_list[j]-(b_list[i]+(j+1)))
  if s_koho<s:
    s=s_koho

print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(a)-i-1 for i, a in enumerate(input().split())]
avg = round(sum(A)/n)
print(min(
    sum(abs(a-avg) for a in A),
    sum(abs(a-avg+1) for a in A),
    sum(abs(a-avg-1) for a in A)
))

Submission status: Wrong Answer

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

print(m())

Submission status: Wrong Answer

Solution code:
from itertools import groupby
import statistics
N = int(input())
A = list(map(int, input().split(' ')))

p = [v - (i + 1) for i, v in enumerate(A)]
s_p = [i for i, v in list(groupby(sorted(p)))]
cand = [min(s_p), max(s_p), int(statistics.mean(s_p)), int(statistics.mean(s_p))-1, int(statistics.mean(s_p))+1, int(statistics.median(s_p)), int(statistics.median(s_p))-1, int(statistics.median(s_p))+1, 0]

res = float('INF')
for k in cand:
    res = min(res, sum([abs(i - k) for i in p]))

print(res)

Submission status: Wrong Answer

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

Ai_i = []

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

n = 50

b_ceil = ceil(sum(Ai_i) / len(Ai_i))

bs = list(range(b_ceil-n, b_ceil+n))

abss_ls = [ 0 for i in range(len(bs))]
for i in range(len(bs)):
    for j in range(len(Ai_i)):
        abss_ls[i] += abs(Ai_i[j] - bs[i])

min_abs = min(abss_ls)
print(min_abs)

Submission status: Wrong Answer

Solution code:
import math

def ret(l, b):
  r = 0
  for i in range(len(l)):
    r += int(math.fabs(l[i] - b - i))
  return r

input()
l = list(map(int, input().split()))
a = sum(list(map(lambda k: k - l.index(k)-1, l))) / len (l)
x = int(a) + 1
y = int(a)
z = int(a) - 1
print(min(ret(l, x), ret(l, y), ret(l,z)))

Submission status: Wrong Answer

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

S1=[]
for i in range(N):
    S1.append(S[i])
S1.sort()
chuouchi=S1[len(S1)//2]
chuouchi2=S1[len(S1)//2-1]
ans=10**18
ansj=0
A=chuouchi-N//2-5
B=chuouchi-N//2+5
C=chuouchi2-N//2-5
D=chuouchi2-N//2+5
for i in range(A,B):
    goukei=0
    for j in range(N):
        goukei+=abs(S[j]-(i+j+1))
        
    if ans>goukei:
        ans=goukei
        
for i in range(C,D):
    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 = [int(i) for i in input().split()]

points = [(i+1, y) for i, y in enumerate(A)]

diff_list = [y - x for x, y in points]
diff_list.sort()

def eval_sadness(points, b):
    return sum([abs(y - (b + x)) for x, y in points])

max_b = diff_list[-1]
min_b = diff_list[0]
mid_b = (max_b + min_b)//2



def search(max_b, mid_b, min_b):
#    print("search", max_b, mid_b, min_b)
    
    eval_max = eval_sadness(points, max_b)
    eval_min = eval_sadness(points, min_b)
    eval_mid = eval_sadness(points, mid_b)

    minimum = min(eval_max, eval_mid, eval_min)
    #print(eval_mid)

    if minimum == eval_max:
        return eval_max
    elif minimum == eval_min:
        return eval_min
    elif eval_max == eval_min + 1:
        # no mid position
        return minimum
    else:
        return min(search(max_b, (max_b + mid_b)//2, mid_b), search(mid_b, (mid_b + min_b)//2, min_b))

if max_b == min_b:
    print(eval_sadness(points, min_b))
else:
    print(search(max_b, mid_b, min_b))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
AS = input().split()
for i in AS:
    i = int(i)
b = 0
a = int(max(AS))
c = -int(max(AS))
old_list = []
while(not ( b in old_list)):  
    result_a = 0
    result_c = 0
    for j in range (1, N+1):
        result_a += abs(int(AS[j-1]) - a - j)
    for j in range (1, N+1):
        result_c += abs(int(AS[j-1]) - c - j)
    if result_a >= result_c:
        a = b
        old_list.append(b)
    else:
        c = b
        old_list.append(b)
    b = (a+c) // 2
result = 0
for i in range (1, N+1):
    result += abs(int(AS[i-1]) - old_list[-1] - i)
print(result)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

point = sum(input_list) // N
b = max(input_counter, key=input_counter.get)

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

print(min(ans1, ans2, ans3))

Submission status: Wrong Answer

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

cmin=min(C)
cmax=max(C)
L=range(cmin,cmax+1)

h=len(L)
l=0


ans=float("inf")

for j in range(100):
	m=(h+l)/2
	x=L[m]
	t=0
	for y in C:
		t+=abs(-1*x+y)

	if t<ans:
		ans=t
		h=m
	else:
		l=m
	ans=min(ans,t)

print ans

Submission status: Wrong Answer

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

# print(lisnum)

hiki = []
k = 1
for k in range(N):
    hiki.append(k + 1)
# print(hiki)

n = 0
total = []
abstotal =[]
for n in range(N):
    total.append(lisnum[n] - hiki[n])
# print(total)

X = math.floor(float(sum(total)/len(total)))
Y = math.ceil(float(sum(total)/len(total)))

ans1 = 0
x = 0
for x in range(N):
    ans1 += abs(total[x] - X)
# print(ans1)

ans2 = 0
x = 0
for x in range(N):
    ans2 += abs(total[x] - Y)
# print(ans2)

ans3 = 0
x = 0
for x in range(N):
    ans3 += abs(total[x] - (X-1))
ans4 = 0
x = 0
for x in range(N):
    ans4 += abs(total[x] - (Y+1))
print(min(ans1, ans2, ans3, ans4))

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


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]
    max_sub_k = 0
    max_sub_v = 0
    for k,v in sub_dic.items():
        if max_sub_v < abs(v):
            max_sub_k = abs(k)
            max_sub_v = abs(v)
        elif max_sub_v == abs(v):
            if max_sub_k < abs(k):
                max_sub_k = abs(k)
                max_sub_v = abs(v)

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

    print(abs(min_v))

Submission status: Wrong Answer

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

max = max(a)
min = max * -1
ans = 10000000
prev = 10000000
t = len(a)
flag = 0
for b in range(min,max):
  sum = 0
  for i in range(t):
    sum += abs(a[i] - (b+i+1))
  if ans > sum:
    ans = sum
  if prev < sum:
    break
  prev = sum

print(ans)

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

c.sort()
ave = c[n//2]
    

ans = 10**8*n

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

print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    B = []
    ans = 0
 
    for i, a in enumerate(A):
        B.append(a - i - 1)

    for i, a in enumerate(A):
       ans += abs(a - i - B[0] - 1)

    for b in B:
        tmp = 0
        for i, a in enumerate(A):
            tmp += abs(a - i - b - 1)

        ans = min(ans, tmp)
        if ans < tmp:
            break

    print(ans)

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+N*2*r,N-N*2*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(b)
            #print(ck)
            break
else:
    #print(b, 2)
    print(ck)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

point = sum(input_list) // N
b = max(input_counter, key=input_counter.get)

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

print(min(ans1, ans2, ans3))

Submission status: Wrong Answer

Solution code:
from scipy import optimize
N = int(input())
A = list(map(lambda x:int(x),input().split(" ")))
def f(x):
    tmp = 0
    for i in range(0,len(A)):
        tmp += abs(A[i]-(x+i+1))
    return tmp
print(int(round(optimize.brent(f,full_output=True,brack=(min(A),max(A)),maxiter=20)[1])))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

bf = np.average(A_minus_i)
b = int(bf)

min_score = sum(A_minus_i)

scores = []

for i in range(0, 10):
    for j in (1, -1):
        score = sum([abs(a - (b+j*i)) for a in A_minus_i])
        scores.append(score)

print(min(scores))

Submission status: Wrong Answer

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

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)
b3 = b1 - 1
b4 = b1 + 1

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

print(min(result1, result2, result3, result4))

Submission status: Wrong Answer

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

sad = [0 for i in range(N)]

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

print(min(sad))

Submission status: Wrong Answer

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

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(-1000* N, 1000* 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:
import numpy as np

N = int(input())
M = input().rstrip().split()

num=[]

for i in range(N):
  k = int(M[i])
  num.append(k-i-1)
    
num = np.array(num)

ave = int(np.average(num))

min = np.sum(np.absolute(num - ave))
min2 = np.sum(np.absolute(num - ave + 1))
min3 = np.sum(np.absolute(num - ave - 1))

if min >= min2 and min3 >= min2:
  print(min2)
elif min3 >= min:
  print(min)
else:
  print(min3)

Submission status: Wrong Answer

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

sum_dif_A = 0
for i in range(N):
    sum_dif_A += A[i] - (i+1)
if sum_dif_A >= 0:
    sad_value = int(sum_dif_A // N)
else:
    sad_value = int((-sum_dif_A // N)*(-1))
answer = 0
for i in range(N):
    answer += abs(A[i] - (sad_value+i+1))
print(str(answer))

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)

c = 10

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

print(min(x, y))

Submission status: Wrong Answer

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


mini = 99999999999

for i in range(-max(a), max(a)):
    total = 0
    for j in range(n):
        total += abs(a[j] - (i + j))

    mini = min(total, mini)

print(mini)