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())
l = list(map(int, input().split()))
sum=0
absum_2=0
absum_1=0
absum0=0
absum1=0
absum2=0
for i in range(N):
    sum+=l[i]-(i+1)

b=int(abs(sum)/N)
if sum<0:
    for j in range(N):
        absum_2+=abs(l[j]-(j+1)+b-2)
        absum_1+=abs(l[j]-(j+1)+b-1)
        absum0+=abs(l[j]-(j+1)+b)
        absum1+=abs(l[j]-(j+1)+b+1)
        absum2+=abs(l[j]-(j+1)+b+2)
else:
    for j in range(N):
        absum_2+=abs(l[j]-(j+1)-b+2)
        absum_1+=abs(l[j]-(j+1)-b+1)
        absum0+=abs(l[j]-(j+1)-b)
        absum1+=abs(l[j]-(j+1)-b-1)
        absum2+=abs(l[j]-(j+1)-b-2)
print(min(absum_2,absum_1,absum0,absum1,absum2))

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)
b=int(((sum(A)-T)/N))
print(b)
Total=0
for i in range(N):
    Total = Total+abs(A[i]-(b+i))
print(int(Total))

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = list(map(int,input().split()))
b = []
cnt = 1
for num in a:
    num -= cnt
    b.append(num)
    cnt += 1
test = [int(np.mean(b))-2,int(np.mean(b))-1,int(np.mean(b)),int(np.mean(b))+1,int(np.mean(b))+2]
ans = []
s = 9999999999999
for i in test:
    cnt = 1
    c = []
    for num in a:
        st = 0
        st = abs(num - (i+cnt))
        c.append(st)
        cnt += 1
    ans.append(np.sum(c))
print(np.min(ans))

Submission status: Wrong Answer

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

sum = 0
for n in range(N):
    sum += An[n] - (n+1)
    
a, b, c = sum//N -1, sum//N, sum//N + 1

ans = [0]*3
for n in range(N):
    ans[0] += abs(An[n] - (a+n+1))
    ans[1] += abs(An[n] - (b+n+1))
    ans[2] += abs(An[n] - (c+n+1))

print(min(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
NP = 0
NM = 0
for i in range(N):
	NM = NM + A[i]
	NP = NP + i+1

b = round((NM-NP)/N) - 50
sad = 0
out = NM**2
for j in range(101):
	b = b + j
	sad = 0
	for i in range(N):
		sad = sad + abs(A[i]-b-i-1)
	if sad<out:
		out = sad
print(out)

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 = min2  = 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:
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)))

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

Submission status: Wrong Answer

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

sum = 0
for n in range(N):
    sum += An[n] - (n+1)
    
a, b, c = sum//N -1, sum//N, sum//N + 1

ans = [0]*3
for n in range(N):
    ans[0] += abs(An[n] - (a+n+1))
    ans[0] += abs(An[n] - (b+n+1))
    ans[1] += abs(An[n] - (c+n+1))

print(min(ans))

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)


for _ in range(iter):
    b1 = (2*b0 + b3) /3
    b2 = (b0 + 2*b3) /3
    
    f1, f2 = 0, 0
    for i in range(n):
        f1 += abs(a[i] - b1 - i)
        f2 += abs(a[i] - b2 - i)
    
    if f1 > f2: b0 = b1
    else:       b3 = b2
    
    if abs(b2 - b1) < 0.01: break
                            
print(round(f1))

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:
    sub = list(set(sub))
    res = float('inf')
    for s in sub:
        tmp = 0
        for i in range(N):
            tmp += abs(A[i]-(s+i+1))

        if tmp < res:
            res = tmp
        
print(int(res))

Submission status: Wrong Answer

Solution code:
N =int(input())
A= list(map(int,input().split( )))
B = []
b = 0
Ans = 1000000000
while True:
    for i in range(1,N+1):
        a = 0
        a = abs(A[i-1] - i - b)
        B.append(a)
    p = sum(B)
    if p > Ans:
        break
    else:
        B = []
        Ans = p
        b = b - 1
        
    
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)

if avg >= 0:
    g1 = int(avg * -1)
    g2 = g1 + 1
else:
    g1 = int(avg)
    g2 = g1 - 1

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

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]
ans=10**13
ansj=0
for i in range(chuouchi-N//2-10,chuouchi-N//2+10):
    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())
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 = round(N/1000)+2

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:
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:mid+20]
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:
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)), math.floor(sum2/(2*n))]
ans=10**10

for bbb in bb:
    sumans=0
    for aa in b:
        sumans+=(math.fabs(aa-bbb))
    ans=min(ans,sumans)

print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
cp = 0
cn = 0
pc=0
nc=0
for i in range(n):
    k = a[i]-i-1
    if k>0:
        cp +=k
        pc +=1
    if k<0:
        cn +=k
        nc +=1
cpn = cp+cn
if cpn ==0:
    print(abs(cp)+abs(cn))
    exit()
x=cpn//n
c1 = 0
c2 = 0
c3 = 0
c4 = 0
for i in range(n):
    c1 += abs(a[i]-(i+1+x))
for i in range(n):
    c2 += abs(a[i]-(i+x))
for i in range(n):
    c3 += abs(a[i]-(i+2+x))
for i in range(n):
    c4 += abs(a[i]-(i-1+x))
print(min(c1,c2,c3))

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = list(map(int,input().split()))
b = []
cnt = 1
for num in a:
    num -= cnt
    b.append(num)
    cnt += 1
test = [int(np.mean(b))-1,int(np.mean(b)),int(np.mean(b))+1]
ans = []
s = 9999999999999
for i in test:
    cnt = 1
    c = []
    for num in a:
        st = 0
        st = abs(num - (i+cnt))
        c.append(st)
        cnt += 1
    ans.append(np.sum(c))
print(np.min(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]
ans=10**11
ansj=0
for i in range(chuouchi-N//2-10,chuouchi-N//2+10):
    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()))
for i in range(N):
    A[i] -= (i+1)

mean= int(sum(A)/N)
ans = 0
for i in range(N):
    ans += abs(A[i]-mean)

temp = 0
for i in range(N):
    temp += abs(A[i]-(mean+1))
if temp < ans:
    ans = temp
    
temp = 0
for i in range(N):
    temp += abs(A[i]-(mean-1))
if temp < ans:
    ans = temp
print(int(ans))

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

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, -b + 1, -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
from scipy.optimize import minimize
N = int(input())
A = list(map(int,input().split()))

def func(x):
    return sum([abs(v - (x + i + 1)) for i,v in enumerate(A)])

def cons(x):
    return -10^9 <= x <= 10^9

cons = (
    {
        'type': 'ineq', 'fun': cons
    }
)
result = minimize(func,x0=-10^9,constraints=cons,method="SLSQP")
print(int(np.round(result['fun'])))

Submission status: Wrong Answer

Solution code:
def BinSearch(A, hi, lo):
    b = (hi + lo) // 2
    tmp0 = FindAns(A, b - 1)
    tmp1 = FindAns(A, b)
    if hi == lo:
        tmp2 = FindAns(A, b + 1)
        return min(tmp0, tmp1, tmp2)
    if tmp0 < tmp1:
        return BinSearch(A, b - 1, lo)
    else:
        return BinSearch(A, hi, lo + 1)
    
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
A = sorted(A)
hi = int(len(A) / 2 + 1)
lo = int(len(A) / 2 - 1)

print(BinSearch(A, hi, lo))

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

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

print(min(result1, result2, result3))

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
ans1 = 0
ans2 = 0
ans3 = 0
ans4 = 0
for i in range(N):
    ans1 += abs(avef-c[i])
    ans2 += abs(avec-c[i])
    ans3 += abs(avec+1-c[i])
    ans4 += abs(avef-1-c[i])
print(min(ans1,ans2,ans3,ans4))

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

print(s2)

ave = round(sum(s2) / N)

print(ave)

c = round(N/100)+2

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())
s = input().split()
s1 = [int(s) for s in s]

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

print(s2)

ave = round(sum(s2) / N)

print(ave)

c = round(N/100)+2

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



print(x)

Submission status: Wrong Answer

Solution code:
import math

N=int(raw_input())
array=map(int, raw_input().split())

sum=0

for i in range(len(array)):
    array[i] = array[i] -(i+1)
    sum = sum + array[i]

#print array
ave=sum/len(array)
ave_c=int(math.ceil(ave))
ave_f=int(math.floor(ave))

sad_c = 0
sad_f = 0

for i in range(len(array)):
    sad_c = sad_c + abs(array[i] -ave_c)
    sad_f = sad_c + abs(array[i] -ave_f)

if sad_c < sad_f:
    print sad_c
else:
    print sad_f

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

if min > min2:
  print(min2)
else:
  print(min)

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_base = int(average)
sum_base = 0
for k in range(N):
    sum_base += abs(B[k] - b_base)

# print(sum_base)

sum_large = sum_base
j = 0
while(True):
    j += 1
    sum_large_past = sum_large
    b_large = b_base + j
    sum_large = 0
    for k in range(N):
        sum_large += abs(B[i] - b_large)
    # print("sum_large = ", end="")
    # print(sum_large)
    if(sum_large > sum_large_past):
        large_min = sum_large_past
        break

sum_small = sum_base
j = 0
while(True):
    j += 1
    sum_small_past = sum_small
    b_small = b_base - j
    sum_small = 0
    for k in range(N):
        sum_small += abs(B[i] - b_small)
    # print("sum_small = ", end="")
    # print(sum_small)
    if(sum_small > sum_small_past):
        small_min = sum_small_past
        break


print(min([large_min, small_min]))

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 - 2, b - 1, b, b + 1, b + 2]
    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:
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(abs(elem - i) - abs(surume)) for i, elem in enumerate(a, 1)]
print(sum(e))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python
# coding: UTF-8


def sad(list, b):
    value = 0
    n = 1
    for a in list:
        value += abs(a - (b+n))
        n += 1
    return value


def main():
    mn = 1000000
    n = (int)(input())
    lst = list(int(i) for i in input().split())
    mx = max(lst)
    for i in range(mx):
        if(sad(lst, i) < mn):
            mn = sad(lst, i)
    print(mn)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
b = max(A) - N

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

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)
a.sort()
key = [[0,0] for i in range(n)]
for i in range(1,n):
    key[i] = [(a[i]-a[i-1])//2,(a[i]+a[i-1])//2]
key.sort()
ans = 0
for i in range(n):
    ans += abs(a[i]-key[0][1])
print(ans)

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
b0 = b1-1
b2=b1+1

sum_a=[0]*3

for i in range(N):
    sum_a[0]+=abs(a[i]-b0)


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

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

print(min(sum_a))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().strip().split()))
s = 0
result = 0
for i in range(N):
	A[i] = A[i]-(i+1)
	s+=A[i]
b = round(s/N)
for i in range(N):
	result += abs(A[i]-b)
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
tmp = 0
B = []
for i in range(n):
    tmp += A[i] - (i+1)
b = tmp//n
ans = 10000000
for j in [-1, 0, 1]:
    tmp = 0
    c = b + j
    for i in range(n):
        tmp += abs(A[i] - (c+i+1))
    if ans > tmp: ans = tmp
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())
R = [A[i]-(i+1) for i in range(N)]
b = sum(R)/N
print sum([abs(b-r) for r in R])

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

subB = {}
for k,v in sub_dic.items():
    subB[k] = abs(k*v)
# 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 subB.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:
#!/usr/bin/env python
# -*- coding:utf-8 -*-

N = int(input())
A = list(map(int, input().split()))
T = int((N*(N-1))/2)
b=float((sum(A)-T)//N)
Total=0
for i in range(N):
    Total = Total+abs(A[i]-(b+i))
print(int(Total))

Submission status: Wrong Answer

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

mean= sum(A)/N
ans = 0
for i in range(N):
    ans += abs(A[i]-mean)

print(int(ans))

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python
# coding: UTF-8


def sad(list, b):
    value = 0
    n = 1
    for a in list:
        value += abs(a - (b+n))
        n += 1
    return value


def main():
    mn = 1000000
    n = (int)(input())
    lst = list(int(i) for i in input().split())
    mx = max(lst)
    for i in range(mx):
        if(sad(lst, i) < mx):
            mn = sad(lst, i)
    print(mn)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
ck = 10000000000
for b in range(0,max(A)):
    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:
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)]
num3 = int((num1 + num2)/2)
num4 = num3 - 1
num5 = num3 + 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)
ans3 = 0
for i in range(n):
    ans3 += abs(a[i]-num3)
ans4 = 0
for i in range(n):
    ans4 += abs(a[i]-num4)
ans5 = 0
for i in range(n):
    ans5 += abs(a[i]-num5)

ans = min(ans1,ans2)
ans = min(ans,ans3)
ans = min(ans,ans4)
ans = min(ans,ans5)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
a = [int(i) for i in input().split()]
for i in range(n):
    a[i] -= i
mc = math.ceil(sum(a)/n)
mf = math.floor(sum(a)/n)
ac = [0 for i in range(n)]
af = [0 for i in range(n)]
for i in range(n):
    ac[i] = abs(a[i]- mc)
    af[i] = abs(a[i]- mf)

print(min([sum(ac),sum(af)]))

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_0 = math.floor(SUM//N) -1
b_1 = math.floor(SUM//N) 
b_2 = math.ceil(SUM//N)
b_3 = math.ceil(SUM//N) + 1

S_0 = 0
S_1 = 0
S_2 = 0
S_3 = 0

for i in range(N):
	S_0 += abs(A[i] - (b_0 + i))
	S_1 += abs(A[i] - (b_1 + i))
	S_2 += abs(A[i] - (b_2 + i))
	S_3 += abs(A[i] - (b_3 + i))

print(min(S_0,S_1,S_2,S_3))

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)
b=float((sum(A)-T)//N)
Total=0
for i in range(N):
    Total = Total+abs(A[i]-(b+i))
print(Total)

Submission status: Wrong Answer

Solution code:
# C - Linear Approximation
# https://beta.atcoder.jp/contests/abc102/tasks/arc100_a

# C_Linear_Approximation.py

# 7
# 1 1 1 1 2 3 4
#import sys

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

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

if sum >= 0:
    candidates = [int(sum / N), int(sum / N) + 1]
else:
    candidates = [int(sum / N) - 1, int(sum / N)]

sadnesses = []
for b in candidates:
    sadness = 0
    for i in range(N):
        if a[i] > b:
            sadness += a[i] - b
        else:
            sadness += b - a[i]
    sadnesses.append(sadness)

sadnesses.sort()
print(sadnesses[0])

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
ans1 = 0
ans2 = 0
for i in range(N):
    ans1 += abs(avef-c[i])
    ans2 += abs(avec-c[i])
print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
import math

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

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

average1 = int(math.floor(sum(Ad) / float(len(Ad))))
average2 = int(math.ceil(sum(Ad) / float(len(Ad))))

diff1 = 0
diff2 = 0
for i, v in enumerate(A):
    diff1 += abs(v - (average1 + i + 1))
    diff2 += abs(v - (average2 + i + 1))
    # diff += abs(v - (i + 1))

# print(A)
# print(Ad)
# print(average)
# print(diff1)
# print(diff2)
print(min(diff1, diff2))

Submission status: Wrong Answer

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

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


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


if min_ans_b < min_ans:
    min_ans = min_ans_b

print(min_ans)

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
    b5 = max(A_i)
    b6 = min(A_i)
    score1 = 0
    score2 = 0
    score3 = 0
    score4 = 0
    score5 = 0
    score6 = 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])
        score5 += abs(b5 - A_i[i])
        score6 += abs(b6 - A_i[i])

    print min(score1, score2, score3, score4,score5,score6)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
n  = int(input())
arr = list(map(int,input().split()))
dif = []
for i,j in enumerate(arr):
    dif.append(j - (i + 1))
count = Counter(dif)
b = count.most_common()[0][0]
if sum(dif) == 0:
    b = 0
print(sum(list(map(lambda x:abs(x - b) , dif))))

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
a = [int(i) for i in input().split()]
print(a)
for i in range(n):
    a[i] -= i
print(a)
mc = math.ceil(sum(a)/n)
mf = math.floor(sum(a)/n)
ac = [0 for i in range(n)]
af = [0 for i in range(n)]
for i in range(n):
    ac[i] = abs(a[i]- mc)
    af[i] = abs(a[i]- mf)

print(min([sum(ac),sum(af)]))

Submission status: Wrong Answer

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

minabs = -1
for b in range(min(A)-N,max(A) + 1):
    sumA = 0
    sA = [abs(item - b - i) for i,item in enumerate(A)]
    if minabs == -1:
        minabs = sumA
    if sum(sA) < minabs:
        minabs = sum(sA)
print(minabs)

Submission status: Wrong Answer

Solution code:

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

avg = 0
i = 1
for x in a:
    avg = avg - i + x

avg = avg // n

minv = 18446744073709551615
for i in range(200):
    i = i - 100 + avg
    tmp = 0
    for x in a:
        tmp = tmp + abs(x - i)
    minv = min(minv, tmp)

print(minv)

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

# print(A)
# print(A_minus_i)

bf = np.average(A_minus_i)
# print(bf)

b_l = int(bf)+1
b_m = int(bf)
b_s = int(bf)-1

score_l = sum([abs(a - b_l) for a in A_minus_i])
score_m = sum([abs(a - b_m) for a in A_minus_i])
score_s = sum([abs(a - b_s) for a in A_minus_i])

print(min(score_l, score_m, score_s))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().strip().split(' ')))
count01 = 0
while count01 < N:
  A[count01] = A[count01]-count01-1
  count01 += 1

B = sum(A)//N

count02 = 0
while count02 < N:
  A[count02] = abs(A[count02] -B)
  count02 +=1

Ans = sum(A)
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()
print(c)
ave = sum(c)/N
avef = math.floor(ave)
avec = avef + 1
ans1 = 0
ans2 = 0
for i in range(N):
    ans1 += abs(avef-c[i])
    ans2 += abs(avec-c[i])
print(min(ans1,ans2))

Submission status: Wrong Answer

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

minabs = -1
for b in range(min(A)-N,max(A) + 1):
    sumA = 0
    sA = [abs(item - b - i) for item,i in enumerate(A)]
    if minabs == -1:
        minabs = sumA
    if sum(sA) < minabs:
        minabs = sum(sA)
print(minabs)

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

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(-10, 11):
    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 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<40:
    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-20:mid+20]
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:
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)
b3 = -math.floor(sum/n)
b4 = 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))
sum_b3 = 0
for i in range(0, n):
    sum_b3 += abs(a[i] - (i+1+b3))
sum_b4 = 0
for i in range(0, n):
    sum_b4 += abs(a[i] - (i+1+b4))
print(min(sum_b1, sum_b2, sum_b3, sum_b4))

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

res = sum([abs(x) for x in array2])
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 res > tmp else res)