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:
# -*- coding: utf-8 -*-
import numpy as np

N = int(input())
list_A = list(map(int, input().split()))
arr_A = np.array(list_A)

b_opt = (arr_A.sum() - N * (N + 1) / 2) / N

sadness = min(np.abs(arr_A - np.arange(1, N + 1) - np.ceil(b_opt)).sum(),
              np.abs(arr_A - np.arange(1, N + 1) - np.floor(b_opt)).sum()
              )
print(int(sadness))

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
tot=sum(A)-n*(n+1)//2
ans1,ans2=0,0
for i in range(n):
  ans1+=abs(A[i]-tot//n-(i+1))
for i in range(n):
  ans2+=abs(A[i]-tot//n+1-(i+1))
print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
tot=sum(A)-n*(n+1)//2
b=0
if tot%n<n/2:
  b=tot//n
else:
  b=tot//n+1
ans=0
for i in range(n):
  ans+=abs(A[i]-b-(i+1))
print(ans)

Submission status: Wrong Answer

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

def solve():
    INF = 10**9
    N = int(input())
    A = list(map(int, input().split()))
    MAX_B = 10**6+1

    sum_a = sum(A)

    sum_i = 0
    for i in range(1, N+1):
        sum_i += i
    
    ans = INF
    for i in range(MAX_B):
        ans = min(ans, abs(sum_a-(sum_i+i*N)))

    print(ans)

if __name__ == "__main__":
    solve()

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_sum=sum(a)
min_1=0
min_2=0
for i in range(n):
    min_1+=abs(a[i]-a_sum//n)
for i in range(n):
    min_2+=abs(a[i]-(a_sum//n+1))
print(min(min_1,min_2))

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int, input().split()))
A = [As[i] - (i+1) for i in range(N)]
b1 = int(sum(A) /N)
if sum(A) >= 0:
    b2 = b1+1
else:
    b2 = b1-1
ans1 = 0
ans2 = 0
for i in range(N):
    ans1 += abs(A[i] -b1)
    ans2 += abs(A[i] - b2)
print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int, input().split()))
A = [As[i] - (i+1) for i in range(N)]
b1 = int(sum(A) /N)
if b1 >= 0:
    b2 = b1+1
else:
    b2 = b1-1
ans1 = 0
ans2 = 0
for i in range(N):
    ans1 += abs(A[i] -b1)
    ans2 += abs(A[i] - b2)
print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int, input().split()))
A = [As[i] - (i+1) for i in range(N)]
b1 = sum(A) // N
b2 = b1+1
ans1 = 0
ans2 = 0
for i in range(N):
    ans1 += abs(A[i] -b1)
    ans2 += abs(A[i] - b2)
print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int, input().split()))
A = [As[i] - i for i in range(N)]
b1 = sum(A) // N
b2 = b1+1
ans1 = 0
ans2 = 0
for i in range(N):
    ans1 += abs(A[i] -b1)
    ans2 += abs(A[i] - b2)
print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
L = [0]*N
for i in range(N):
  L[i] = A[i]-i-1
L.sort()
S = 0
if len(L)%2 == 0:
  k = L[len(L)//2]
  for i in range(len(L)):
    S += abs(L[i]-k)
else:
  k = (L[len(L)//2-1]+L[len(L)//2])//2
  for i in range(len(L)):
    S += abs(L[i]-k)
print(S)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
for i in range(N):
  L[i] = L[i]-i-1
L.sort()
S = 0
if len(L)%2 == 0:
  k = L[len(L)//2]
  for i in range(len(L)):
    S += abs(L[i]-k)
else:
  k = (L[len(L)//2-1]+L[len(L)//2])//2
  for i in range(len(L)):
    S += abs(L[i]-k)
print(S)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
for i in range(N):
  L[i] = L[i]-i-1
L.sort()
S = 0
if len(L)%2 == 0:
  k = L[(len(L)-1)//2]
  for i in range(len(L)):
    S += abs(L[i]-k)
else:
  k = (L[len(L)//2-1]+L[len(L)//2])/2
  for i in range(len(L)):
    S += abs(L[i]-k)
print(S)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
for i in range(N):
  L[i] = L[i]-i-1
L.sort()
S = 0
if len(L)%2 == 0:
  k = L[(len(L)-1)//2]
  for i in range(len(L)):
    S += abs(L[i]-k)
else:
  k = (L[len(L)//2-1]+L[len(L)//2])//2
  for i in range(len(L)):
    S += abs(L[i]-k)
print(S)

Submission status: Wrong Answer

Solution code:
N=int(input())
B=list(map(int,input().strip().split(" ")))
B=sorted(B)
B2=[B[i]-(i+1) for i in range(N)]
want=B2[N//2]
ans=0
for x in B2:
    ans+=abs(x-want)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
def f(n, b, c):
    return np.sum(np.abs(c-b))

def solve(n, a):
    c = np.asarray([(a[i]-i-1) for i in range(n)], dtype=int)
    b = np.median(c)
    return f(n, b, c)

assert solve(5, [2, 2, 3, 5, 5]) == 2
assert solve(9, [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 0
assert solve(6, [6, 5, 4, 3, 2, 1]) == 18
assert solve(7, [1, 1, 1, 1, 2, 3, 4]) == 6
n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))

Submission status: Wrong Answer

Solution code:
import numpy as np
def f(n, b, c):
    return np.sum(np.abs(c-b))

def solve(n, a):
    c = np.asarray([(a[i]-i-1) for i in range(n)], dtype=int)
    S = list(sorted(set(c)))
    m = len(S)
    lb = 0
    ub = m-1
    for i in range(100):
        i1 = (2*lb + ub) // 3
        i2 = (lb + 2*ub) // 3
        b1 = S[i1]
        b2 = S[i2]
        if f(n, b1, c) < f(n, b2, c):
            ub = i1
        else:
            lb = i2
    return min([f(n, S[i], c) for i in range(lb, ub+1)])

assert solve(5, [2, 2, 3, 5, 5]) == 2
assert solve(9, [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 0
assert solve(6, [6, 5, 4, 3, 2, 1]) == 18
assert solve(7, [1, 1, 1, 1, 2, 3, 4]) == 6
n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))

Submission status: Wrong Answer

Solution code:
def f(n, b, c):
    return sum([abs(c[i]-b) for i in range(n)])

def solve(n, a):
    c = [(a[i]-i-1) for i in range(n)]
    S = list(sorted(set(c)))
    m = len(S)
    lb = 0
    ub = m-1
    for i in range(100):
        i1 = (2*lb + ub) // 3
        i2 = (lb + 2*ub) // 3
        b1 = S[i1]
        b2 = S[i2]
        if f(n, b1, c) < f(n, b2, c):
            ub = i1
        else:
            lb = i2
    return min([f(n, S[i], c) for i in range(lb, ub+1)])

assert solve(5, [2, 2, 3, 5, 5]) == 2
assert solve(9, [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 0
assert solve(6, [6, 5, 4, 3, 2, 1]) == 18
assert solve(7, [1, 1, 1, 1, 2, 3, 4]) == 6
n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
x = {}
ans = 0
for ind,i in enumerate(A):
    if(i-ind in x):
        x[i-ind]+=1
    else:
        x[i-ind]=1
max_i = max(x,key=x.get)
for ind,i in enumerate(A):
    ans+=abs(i-ind-max_i)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = [int(v)-(i+1) for i,v in enumerate(input().split())]
res = math.floor(sum(A)/len(A))
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
def app(n):
    if n == -N:
        return 10**10
    ans = 0
    for a,i in zip(A,range(1,N+1)):
        ans += abs(a-(n+i))
    return min(ans,app(n-1))
print(app(N))

Submission status: Wrong Answer

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

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

b0 = int(sum(b) / n)

total1 = 0
for i in range(n):
    total1 += abs(b[i] - b0)

total2 = 0
for i in range(n):
    total2 += abs(b[i] - b0 - 1)

total3 = 0
for i in range(n):
    total3 += abs(b[i] - b0 + 1)

print(min(total1, total2, total3))

Submission status: Wrong Answer

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

d_ = [A_[i] - (i+1) for i in range(N)]

d_ave = sum(d_)/N
d_floor = sum([abs(d_[i] - math.floor(d_ave)) for i in range(N)])
d_ceil = sum([abs(d_[i] - math.ceil(d_ave)) for i in range(N)])
print(min(d_floor,d_ceil))

Submission status: Wrong Answer

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

s = -s
x1 = int(-s//N)
x2 = x1 + 1
x3 = x1 - 1
ans1,ans2,ans3 = 0,0,0
for i in range(N):
  ans1 += abs(x1-A[i])
  ans2 += abs(x2-A[i])
  ans3 += abs(x3-A[i])
ans = min(ans1,ans2,ans3)
print(ans)

Submission status: Wrong Answer

Solution code:
""" AtCoder """

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

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

b = sum(A) // N
bb = b + 1

ans = 0
ansans = 0

for a in A:
    ans += abs(a - b)
    ansans += abs(a - bb)


print(min(ans, ansans))

Submission status: Wrong Answer

Solution code:
""" AtCoder """

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

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

b = sum(A) // N

ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys, math

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

A = [A[k]-(k+1) for k in range(N)]
B = set(A)
smallest = sum([abs(A[k]) for k in range(N)])

for b in sorted(B):
  total = sum([abs(A[k]-b) for k in range(N)])
  if total < smallest:
    smallest = total
  elif total > smallest:
    print(smallest)
    sys.exit()
  elif b == max(B):
    print(total)
    sys.exit()

Submission status: Wrong Answer

Solution code:
import numpy as np 
import sys

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

A -= np.array([k+1 for k in range(N)])
smallest = sum(abs(A))
for b in range(int(min(A)), int(max(A))+1):
  total = sum(np.abs(A-b))
  if total > smallest:
    print(smallest)
    sys.exit()
  smallest = total
print(0)

Submission status: Wrong Answer

Solution code:
import numpy as np 
import sys

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

A -= np.array([k+1 for k in range(N)])
smallest = sum(abs(A))
for b in range(int(min(A)), int(max(A))+1):
  total = sum(np.abs(A-b))
  if total > smallest:
    print(smallest)
    sys.exit()
  smallest = total

print(A[0])

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 = sorted(A)
if N % 2:
    M = A[N // 2]
else:
    M = A[N // 2 - 1] + A[N // 2]
S = 0
for i in range(N):
    S += abs(A[i] - M)
print(S)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = I()
    a = LI()
    for i in range(n):
        a[i] -= i+1
    a.sort()
    b = sum(a)//n
    ans = 0
    for i in range(n):
        ans += abs(a[i]-b)
    ans2 = 0
    b += 1
    for i in range(n):
        ans2 += abs(a[i]-b)
    print(min(ans,ans2))

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = I()
    a = LI()
    for i in range(n):
        a[i] -= i+1
    a.sort()
    b = sum(a)//n
    ans = 0
    for i in range(n):
        ans += abs(a[i]-b)
    print(ans)

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Wrong Answer

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

d={}
for i in range(1,len(a)+1):
    if(a[i-1]-i in d):
        d[a[i-1]-i]+=1
    else:
        d.update({i-a[i-1]:1})

d=sorted(d.items(),key=lambda x:x[1])
s=d[-1][0]*-1
ans=0

for i in range(1,len(a)+1):
    ans+=abs(a[i-1]-(s+i))
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)
# print(A)
num=sum(A)//len(A)
num2=sum(A)//len(A)+1
B=[]
for i in range(n):
    A[i]-=num
    B.append(A[i]+1)
for i in range(n):
    A[i]=abs(A[i])
    B[i]=abs(B[i])

# print(A,B)
print(min(sum(A),sum(B)))

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
for i in range(n):
    A[i]-=(i+1)
# print(A)
num=sum(A)//len(A)
num2=sum(A)//len(A)+1
B=[]
for i in range(n):
    A[i]-=num
    B.append(A[i]-1)
for i in range(n):
    A[i]=abs(A[i])
    B[i]=abs(B[i])

# print(A,B)
print(min(sum(A),sum(B)))

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
for i in range(n):
    A[i]-=(i+1)
num=sum(A)//len(A)
for i in range(n):
    A[i]-=num
    A[i]=abs(A[i])
print(sum(A))

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    a[i]=a[i]-i-1
a.sort()
if n%2==1:
    p=a[n//2]
    print(abs(sum(a[:n//2])-p*(n//2))+sum(a[n//2+1:])-p*(n//2))
else:
    l=a[n//2-1]+a[n//2]
    s=math.floor(l/2)
    t=math.ceil(l/2)
    print(min(abs(sum(a[:n//2]))-s*n//2+sum(a[n//2:])-s*(n//2),abs(sum(a[:n//2]))-t*n//2+sum(a[n//2:])-t*(n//2)))

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
k=math.floor((sum(a)-n*(n+1)//2)/n)
l=math.ceil((sum(a)-n*(n+1)//2)/n)
c=0
d=0
for i in range(n):
    c+=abs(a[i]-k-i-1)
    d+=abs(a[i]-l-i-1)
print(min(c,d))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
k=round((sum(a)-n*(n+1)//2)/n)
c=0
for i in range(n):
    c+=abs(a[i]-k-i-1)
print(c)

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
c=0
for i in range(n):
    c+=abs(a[i]-int(sum(a)/n))
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = 0 ; zero = 0
for i in range(n):
	zero += abs(a[i] - (b + 1))
	b += 1
print(zero)

Submission status: Wrong Answer

Solution code:
import collections
import statistics

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

n = input()
l = list(map(int, input().split()))
x = []
for i in range(len(l)):
  x.append(l[i] - i - 1)
    
c = collections.Counter(x)
max_k = max(c, key=c.get)
keys = [k for k, v in c.items() if v == c[max_k]]
if (len(keys) % 2 != 0):
  b = statistics.median(keys)
  print(sadness(l, b))
else:
  b_low = statistics.median_low(keys)
  b_high = statistics.median_high(keys)
  print(min(sadness(l, b_low), sadness(l, b_high)))

Submission status: Wrong Answer

Solution code:
import collections

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

n = input()
l = list(map(int, input().split()))
x = []
for i in range(len(l)):
  x.append(l[i] - i - 1)
    
c = collections.Counter(x)
max_k = max(c, key=c.get)
keys = [k for k, v in c.items() if v == c[max_k]]
minsad = 1000000000
for i in range(len(keys)):
  b = keys[i]
  s = sadness(l, b)
  if (minsad > s):
    minsad = s
print(minsad)

Submission status: Wrong Answer

Solution code:
import collections

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

n = input()
l = list(map(int, input().split()))
x = []
for i in range(len(l)):
  x.append(l[i] - i - 1)
    
c = collections.Counter(x)
max_k = max(c, key=c.get)
print(max_k)
keys = [k for k, v in c.items() if v == c[max_k]]
print(keys)
minsad = 1000000000
for i in range(len(keys)):
  b = keys[i]
  s = sadness(l, b)
  if (minsad > s):
    minsad = s
print(minsad)

Submission status: Wrong Answer

Solution code:
import math
N=int(input().strip())
a=list(map(int, input().strip().split(' ')))
for i in range(N):
    a[i]=a[i]-(i+1)
b=sum(a)/N
ans1=0
ans2=0
b1=math.floor(sum(a)/N)
b2=math.ceil(sum(a)/N)
for i in range(N):
    ans1+=abs(a[i]-b1)
for i in range(N):
    ans2+=abs(a[i]-b2)


print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
def checker(A, b):
    return sum([abs(A[i]-(b+i)) for i in range(0, len(A))])


def exec():
    N = int(input())
    A = [int(c) for c in input().split()]
    lst = [checker(A, b) for b in range(N)]

    print(min(lst))


exec()

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(i) for i in input().split(' ')]
for i in range(len(A)):
  A[i]-=i+1
if len(A)%2==1:
  b=A[(len(A)-1)//2]
else:
  b=A[(len(A))//2-1]
s=0
for i in range(len(A)):
  s+=abs(A[i]-b)
print(s)

Submission status: Wrong Answer

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

N=int(input())
A=[int(i) for i in input().split(' ')]
MIN=None
for b in range(min(A[0],A[-1]-len(A)+1),max(A[-1],A[0]+len(A)-1)):
  if MIN==None:
    MIN=func(A,b)
  elif MIN>func(A,b):
    MIN=func(A,b)
print(MIN)

Submission status: Wrong Answer

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

N=int(input())
A=[int(i) for i in input().split(' ')]
min=None
for b in range(A[0],A[-1]-len(A)+1):
  if min==None:
    min=func(A,b)
  elif min>func(A,b):
    min=func(A,b)
print(min)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    ans = 1<<32;
    for b in range(-2*10**5, 2*10**5):
        kanasisa = 0
        for i,aa in enumerate(a):
            kanasisa += abs(aa-(b+i))
        ans = min(ans,kanasisa)

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    ans = 1<<32;
    for b in range(0, 2*10**5):
        kanasisa = 0
        for i,aa in enumerate(a):
            kanasisa += abs(aa-(b+i))
        ans = min(ans,kanasisa)

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    ans = 1<<32;
    for b in range(-500, 500):
        kanasisa = 0
        for i,aa in enumerate(a):
            kanasisa += abs(aa-(b+i))
        ans = min(ans,kanasisa)

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math

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

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

ave = sum(A2) / N

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


def calcSad(A2, b):
    sum = 0
    for i in A2:
        sum += abs(i - b)
    return sum


sum_b1 = calcSad(A2, b1)
sum_b2 = calcSad(A2, b2)

print(min(sum_b1, sum_b2))


sys.exit(0)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
lis = list(map(int,input().split()))
for i in range(n):lis[-(i+1)] += i
cou = 0
co = 0
num = math.ceil(sum(lis)/n)
nu = math.floor(sum(lis)/n)
for i in range(n):
  cou += abs(lis[i]-num)
  co += abs(lis[i]-nu)
print(min(cou,co))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
lis = list(map(int,input().split()))
for i in range(n):lis[i] -= i
cou = 0
co = 0
num = math.ceil(sum(lis)/n)
nu = math.floor(sum(lis)/n)
for i in range(n):
  cou += abs(lis[i]-num)
  co += abs(lis[i]-nu)
print(min(cou,co))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
lis = list(map(int,input().split()))
cou = 0
co = 0
num = math.ceil(sum(lis))
nu = math.floor(sum(lis))
for i in range(n):
  cou += abs(lis[i]-(num + i + 1))
  co += abs(lis[i]-(nu + i + 1))
print(min(cou,co))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
lis = list(map(int,input().split()))
for i in range(n):lis[i] -= i
num1 = math.ceil(sum(lis)/n)
num2 = math.floor(sum(lis)/n)
ans = 0
an = 0
for i in range(n):
  ans += abs(lis[i]-num1)
  an += abs(lis[i]-num2)
print(min(an,ans))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 23 16:16:49 2018

@author: masato
"""

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

result = 9999999999999999999
kanasii = 0

for b in range(num + 1000):
    kanasii = 0
    for i in range(num):
        kanasii += abs(a[i]-(b+i))
    if kanasii < result:
        result = kanasii

print(result)

Submission status: Wrong Answer

Solution code:
L = []
N = int(input())
A = list(map(int,input().split()))
for i in range(N) :
    A[i] -= i
a = abs(min(0,min(A)))
for l in range(N) :
    A[l] += a
z = sum(A)
for j in range(a+1) :
    p = 0
    for k in range(N) :
        A[k] -= 1
        p += abs(A[k])
    L.append(p)
print(min(min(L),z))

Submission status: Wrong Answer

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

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

mean = sum(A) // N


def f(m):
    ret = 0
    for a in A:
        ret += abs(a - m)
    return ret


print(min(f(mean), f(mean + 1)))

Submission status: Wrong Answer

Solution code:
import math

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

aa = list(map(lambda e: e[1] - (e[0] + 1), enumerate(a)))
minbf = math.floor(sum(aa) / len(aa))
minbc = math.ceil(sum(aa) / len(aa))
ansf = sum(map(lambda ea: abs(ea - minbf), aa))
ansc = sum(map(lambda ea: abs(ea - minbc), aa))

ans = min(ansf, ansc)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

aa = list(map(lambda e: e[1] - (e[0] + 1), enumerate(a)))
minbf = math.floor(sum(aa) / len(aa))
ansf = sum(map(lambda ea: abs(ea - minbf), aa))

Submission status: Wrong Answer

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

aa = list(map(lambda e: e[1] - (e[0] + 1), enumerate(a)))
minb = round(sum(aa) / len(aa))
ans = sum(map(lambda ea: abs(ea - minb), aa))
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np

N = stdin.readline().rstrip()
A = np.array([int(x) for x in stdin.readline().split()], dtype=int)
B = A - np.arange(1, len(A) + 1)
b = int(np.median(B))
print((B - b).sum())

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())
A = list(map(int, input().split()))
accum = [0 for i in range(N + 1)]
for i in range(N):
    accum[i + 1] = accum[i] + A[i]
#accum[i + 1] = A[0] + A[1] + ... + A[i]
#sum(A[i:j]) = A[i] + A[i+1] + ... + A[j-1] = accum[j] - accum[i]
ans = float('inf')
for i in range(2, N - 1, 1): #2番目の区切りを A[i-1]とA[i]の間に入れる
    zenhan = accum[i] #(= sum(A[:i]))
    kouhan = accum[N] - accum[i]#(= sum(A[i:N]))
    index1l = bisect.bisect(accum, zenhan // 2, lo = 2, hi = i) - 1
    index1r = min(index1l + 1, i - 1)
    index3l = bisect.bisect(accum, zenhan + (kouhan // 2), lo = i + 2, hi = N) - 1
    index3r = min(index3l + 1, N - 1)
    for index1 in (index1l, index1r):
        for index3 in (index3l, index3r):
            B, C, D, E = accum[index1], accum[i] - accum[index1], accum[index3] - accum[i], accum[N] - accum[index3]
            M = max(B, C, D, E)
            m = min(B, C, D, E)
            ans = min(ans, M - m)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
M = N // 2
X = list(map(int, input().split()))
A = sorted([X[i] - (i + 1) for i in range(N)])
print(sum(A[-M:]) - sum(A[:M]))

Submission status: Wrong Answer

Solution code:
import math
def main():
  N = int(input())
  t = input().split(" ")
  a = []
  for i in range(N):
    ii = int(t[i])
    a.append(ii-i-1)
  s = sum(a)
  t = math.floor(s/N)
  b = 0
  c = 0
  for i in range(N):
  	b += abs(a[i] - t)
  	c += abs(a[i] - t - 1)
  if c < b:
    print(c)
  else:
    print(b)
main()

Submission status: Wrong Answer

Solution code:
N=int(input())
a=input()
S=a.split(" ")
for i in range(N):
    S[i] = int(int(S[i])-(i+1))
b=sum(S)/N
for t in range(N):
    S[t] = abs(int(S[t])-b)
print(int(sum(S)))

Submission status: Wrong Answer

Solution code:
from statistics import median

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

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

med = median(A)
    
ans = 0
for i in A:
    ans += abs(i-med)

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)

sum = 0
for i in A:
    sum += i

print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = input().split()
ans = 0
for i in range(0,N):
	a[i] = int(a[i])-i
ave = sum(a)/len(a)
for i in range(0,N):
	ans += abs(a[i]-ave)
print(int(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
a = [x - i - 1 for i, x in enumerate(A)]
c = a[N // 2]
print(sum([abs(i - c) for i in a]))

Submission status: Wrong Answer

Solution code:
while True:
    try:
        n = int(input())
        num = list(map(int, input().split()))
        for ind in range(len(num)):
            num[ind] -= ind+1
        d = min(num)
        if d < 0:
            d = 0
        print(sum(abs(i-d)for i in num))
    except:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        n = int(input())
        num = list(map(int,input().split()))
        for ind in range(len(num)):
            num[ind] -= ind+1
        d = sum(num)//n
        print(sum(abs(i-d) for i in num))
    except:
        break

Submission status: Wrong Answer

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

B = [A[i] - (i + 1) for i in range(len(A))]
B = sorted(B)

while True:
    P = [x for x in B if x > 0]
    M = [x for x in B if x < 0]
    cP = len(P)
    cM = len(M)
    cZ = len(B) - cP - cM

    if (cM == cP == 0):
        break
    if (cM < cP + cZ) and (cP < cM + cZ):
        break
    if (cM == cP + cZ) and (cP == cM + cZ):
        break
    if (cM < cP + cZ):
        # print('b++')
        B = [B[i] - min(P) for i in range(len(B))]
    elif (cP < cM + cZ):
        # print('b--')
        B = [B[i] - max(M) for i in range(len(B))]

print(sum(B))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
for i in range(0,len(a)):
    a[i] -= i
b = [sum(a)//len(a),sum(a)//len(a)+1]
c = []
d = []
for i in range(0,len(a)):
    c.append(abs(a[i] - b[0]))
    d.append(abs(a[i] - b[1]))
print(min(sum(c),sum(d)))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
 
b = [(a[i] - i) for i in range(n)]
sorted(b)
num = b[ n // 2]
 
Ans = 0
mi = len(b)//2
for i in range(n):
    Ans += abs(b[i]-b[mi])
 
print(Ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
 
b = [(a[i] - i) for i in range(n)]
sorted(b)
num = b[ n // 2]
 
result = 0
for i in b:
    result += abs(num - i)
 
print(result)

Submission status: Wrong Answer

Solution code:
import statistics

def f(a, n):
    a2 = [ai - (i+1) for (i,ai) in enumerate(a)]
    b = statistics.median(a2)
    
    sadness = sum(abs(ai - b) for ai in a2)
    
    b += 1
    sadness2 = sum(abs(ai - b) for ai in a2)

    
    return min(sadness, sadness2)
    
n = int(input())
a = [int(i) for i in input().split()]
print(f(a, n))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
 
b = [(a[i] - i) for i in range(n)]
sorted(b)
num = b[ (n - 1) // 2]
 
result = 0
for i in b:
    result += abs(num - i)
 
print(result)

Submission status: Wrong Answer

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



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


## pre
X = [a-(i+1) for i,a in enumerate(A)]


print(kanashisa(X[N//2]))

Submission status: Wrong Answer

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



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


## pre
X = [a-(i+1) for i,a in enumerate(A)]
X.sort()
total =sum(X) +N*N
x_index= 0
ans =999999999
left = 0
right = N
for i in range(-N ,2*10**5+1):
    while x_index < N and X[x_index]==i:
        x_index+=1
        right -=1
        left +=1

    total = total + left -right
    #print(i,total,x_index,left,right)
    ans = min(ans,total)

print(ans)

Submission status: Wrong Answer

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

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

a.sort()
b = [a[0]]
for i in a[1:]:
    b.append(b[-1] + i)
hi = len(a)
lo = 0


def score(index):
    return abs((lft * a[index] - b[index]) - (b[-1] - b[index] - (len(a) - index) * a[index]))


for i in range(10000):
    lft = (hi + 2 * lo) // 3
    rgt = (2 * hi + lo) // 3
    ltmp = score(lft)
    rtmp = score(rgt)
    if ltmp <= rtmp:
        lo = lft
    else:
        hi = rgt

print(score(lo))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

B = np.array([0]*N)

l = input().split()

for i in range(N):
    B[i] = int(l[i]) - (i+1)
    
B = np.sort(B)

if N % 2 == 1:
    b_mid = B[int(N/2)]
else:
    mid = int(N/2) - 1
    b_mid = int( (B[mid] + B[mid+1])/2 )

dif = B - b_mid

print(np.sum(dif))