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:
from statistics import mean

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


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

b=round(float(mean(A)))

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

print(summ)

Submission status: Wrong Answer

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

answer = 65535
max_A = max(A)
for x in range(-max_A-1, max_A+1):
    total = sum([abs(num - (i+1) - x) for i, num in enumerate(A)])
    if total > answer:
        break
    answer = total

print(answer)

Submission status: Wrong Answer

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

print(abs((sum(A) - int(0.5 * N * (N + 1))) % N))

Submission status: Wrong Answer

Solution code:
import statistics


N   = int(input())
A   = list(map(int, input().split()))
A_b = [a - (idx + 1) for idx, a in enumerate(A)]
med = int(statistics.median(A_b))

print(int(sum(A_b) - med*len(A_b)))

Submission status: Wrong Answer

Solution code:
import statistics


N   = int(input())
A   = list(map(int, input().split()))
A_b = [a - (idx + 1) for idx, a in enumerate(A)]
med = statistics.median(A_b)

print(int(sum(A_b) - med*len(A_b)))

Submission status: Wrong Answer

Solution code:
def med(data):
    N = len(data)
    data.sort()
    if N % 2 == 0:
        median1 = N/2
        median2 = N/2 + 1
        median1 = int(median1) - 1
        median2 = int(median2) - 1
        median = (data[median1] + data[median2]) / 2
        return median
    else:
        median = (N + 1) / 2
        median = int(median) - 1
        median = data[median]
        return median

import sys
N = int(input())
lists = [int(i) for i in input().split()]
sok = sys.maxsize
list2 = [x - j - 1 for j, x in enumerate(lists)]
b = med(list2)
kanashi = 0
for xx in list2:
    kanashi += abs(xx - b)
print(kanashi)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
lists = [int(i) for i in input().split()]
sok = sys.maxsize
list2 = [xx - 5 for xx in range (2 * 5 + 1)]
for b in list2:
    kanashi = 0
    i = 1
    for x in lists:
        kanashi += abs(x - (b + i))
        i += 1
    if (kanashi < sok):
        sok = kanashi
print(sok)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
lists = [int(i) for i in input().split()]
sok = sys.maxsize
for b in range(max(lists)):
    kanashi = 0
    i = 1
    for x in lists:
        kanashi += abs(x - (b + i))
        i += 1
    if (kanashi < sok):
        sok = kanashi
print(sok)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

def getBList(A):
    bList = []
    for i in range(1, len(A)+1):
        bList.append(A[i-1]-i)
    return bList

def getMedian(bList):
    tmp = sorted(bList)
    if len(bList) % 2 == 1:
        return tmp[len(bList)//2]
    else:
        return (tmp[len(bList)//2]+tmp[len(bList)-1]//2)//2

def solve(A, b):
    ssum = 0
    for i in range(len(A)):
        ssum += abs(A[i] - (b+i+1))
    return ssum

if __name__ == "__main__":

    N = int(input())
    A = [int(x) for x in input().split()]
    print(solve(A, getMedian(getBList(A))))

Submission status: Wrong Answer

Solution code:
# coding: utf-8

def getBList(A):
    bList = []
    for i in range(1, len(A)+1):
        bList.append(A[i-1]-i)
    return bList

def getMedian(bList):
    tmp = sorted(bList)
    if len(bList) % 2 == 1:
        return tmp[len(bList)//2]
    else:
        return (tmp[len(bList)//2]+tmp[len(bList)-1]//2)//2

def solve(bList, b):
    ssum = 0
    for i in range(len(A)):
        ssum += abs(bList[i] + b)
    return ssum

if __name__ == "__main__":

    N = int(input())
    A = [int(x) for x in input().split()]
    print(solve(getBList(A), getMedian(getBList(A))))

Submission status: Wrong Answer

Solution code:
# coding: utf-8

def getBList(A):
    bList = []
    for i in range(1, len(A)+1):
        bList.append(A[i-1]-i)
    return bList

def getMedian(bList):
    bList.sort()
    if len(bList) % 2 == 1:
        return bList[len(bList)//2]
    else:
        return (bList[len(bList)//2]+bList[len(bList)-1]//2)//2

def solve(bList, b):
    ssum = 0
    for i in range(len(A)):
        ssum += abs(bList[i] + b)
    return ssum

if __name__ == "__main__":

    N = int(input())
    A = [int(x) for x in input().split()]
    print(solve(getBList(A), getMedian(getBList(A))))

Submission status: Wrong Answer

Solution code:
# coding: utf-8

def getBList(A):
    bList = []
    for i in range(1, len(A)+1):
        bList.append(A[i-1]-i)
    return bList

def getMedian(bList):
    bList.sort()
    if len(bList) % 2 == 1:
        return bList[len(bList)//2]
    else:
        return (bList[len(bList)//2]+bList[len(bList)-1]//2)//2

def solve(A, b):
    ssum = 0
    for i in range(len(A)):
        ssum += abs(A[i] - (b + (i+1)))
    return ssum

if __name__ == "__main__":

    N = int(input())
    A = [int(x) for x in input().split()]
    print(solve(A, getMedian(getBList(A))))

Submission status: Wrong Answer

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

#Biを作成
B = A.copy()
for i in range(N):
    B[i] = B[i] - (i+1)

B.sort()
chuo=B[int(N//2)]

tmp=0
for i in B:
    tmp += i - chuo
print(tmp)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted([int(x)-(i+1) for i,x in enumerate(input().split())])
ans=float("inf")
average=sum(a)//n
for i in range(average-1,average+3):
    ans=min(ans,sum([abs(x-i) for x in a]))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted([int(x)-(i+1) for i,x in enumerate(input().split())])
ans=float("inf")
average=sum(a)//n
for i in range(n-1,n+3):
    ans=min(ans,sum([abs(x-average) for x in a]))
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

def calc(b, A):
    ans = 0
    for i, a in enumerate(A, start=1):
        ans += abs(a - (b + i))
    return ans

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

    total = 0
    for i, a in enumerate(A, start=1):
        total += a - i

    x = total // N
    print(min([calc(x - 1, A), calc(x, A), calc(x + 1, A)]))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
a = list(range(1,N+1))
elements = sorted([i-j for (i,j) in zip(A,a)])
if(N%2 == 1):
    b = abs(elements[N//2])
else:
    b = abs(elements[(N//2)-1])
answer = sum([abs(i-j-b) for (i,j) in zip(A,a)])
print(answer)

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()
mid1=a[int(len(a)/2)-1]
mid2=a[int(len(a)/2)]
res1=0
res2=0
for i in range(n):
    res1+=a[i]-mid1
    res2+=a[i]-mid2
print(min(res1,res2))

Submission status: Wrong Answer

Solution code:
N = int(input("paste test case"))
list_A = [int(str_A) for str_A in input().split(" ")]

b = 0


def absolution(a, b, i):
    return abs(a - (b + i + 1))


if b >= 0:
    list_A_func = [absolution(a, b, i) for i, a in enumerate(list_A)]
    print(sum(list_A_func))

Submission status: Wrong Answer

Solution code:
def main():
    n=int(input())
    num=[int(i) for i in input().split()]
    b = (sum(num) - n * (n+1) * 0.5) / n
    a=b
    while a>=1:
        a -= 1
    if a >= 0.5:
        b = int(b+0.5)
    else:
        b = int(b)
    counter = 0
    for i in range(len(num)):
        counter += abs(num[i] - b)
    print(counter)
main()

Submission status: Wrong Answer

Solution code:
def main():
    n=int(input())
    num=[int(i) for i in input().split()]
    b = (sum(num) - n * (n+1) * 0.5) / n
    a=b
    while(a>=1):
        a -= 1
    if a >= 0.5:
        b = int(b+1)
    else:
        b = int(b)
    counter = 0
    for i in range(len(num)):
        counter += abs(num[i] - b)
    print(counter)
main()

Submission status: Wrong Answer

Solution code:
def main():
    n=int(input())
    num=[int(i) for i in input().split()]
    b = (sum(num) - n * (n+1) * 0.5) / n
    a=b
    while(a>=1):
        a -= 1
    if a > 0.5:
        b = int(b+1)
    else:
        b = int(b)
    counter = 0
    for i in range(len(num)):
        counter += abs(num[i] - b)
    print(counter)

Submission status: Wrong Answer

Solution code:
def main():
    n=input()
    num=[int(i) for i in input().split()]
    b = (sum(num) - n * (n+1) * 0.5) / n
    a=b
    while(a>=1):
        a -= 1
    if a > 0.5:
        b = int(b+1)
    else:
        b = int(b)
    counter = 0
    for i in range(len(num)):
        counter += abs(num[i] - b)
    print(counter)

Submission status: Wrong Answer

Solution code:
import statistics

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

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

a_med = statistics.median(a)
b = 0

for i in range(N):
	b += abs(a[i] - a_med)
	b = int(b)
print(b)

Submission status: Wrong Answer

Solution code:
import statistics

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

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

a_med = statistics.median(a)
b = 0

for i in range(N):
	b += abs(a[i] - a_med)

print(b)

Submission status: Wrong Answer

Solution code:
import statistics

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

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

a_med = statistics.median(a)
b = 0

for i in range(N):
	b += abs(a[i] - a_med)

print(b)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
b = 0
sad2 = []
sad2.append(100000)
j = 0
while True:
    sad = 0
    for i in range(len(A)):
        sad += abs(A[i]-(b+i+1))
    if sad2[j] < sad:
        break
    sad2.append(sad)
    b += 1
    j += 1
sad3 = []
sad3.append(100000)
k = 0
while True:
    sad = 0
    for i in range(len(A)):
        sad += abs(A[i]-(b+i+1))
    if sad3[k] < sad:
        break
    sad3.append(sad)
    b -= 1
    k += 1
sad4 = sad2 + sad3
print(min(sad4))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
b = 0
sad2 = 1000000
sad = 0
while True:
    for i in range(len(A)):
        sad += abs(A[i]-(b+i+1))
    if sad2 < sad:
        break
    sad2 = sad
    b += 1
print(sad2)

Submission status: Wrong Answer

Solution code:
m = int(input())
a = list( map( int, input().split() ) )
resi = temp = 0
for i in range(-m,m):
  sumi = 0
  j = 1
  for ai in a:
    sumi = sumi  + abs(ai - (i + j))
    j +=1
  if i == 0:
    temp = sumi
  if temp > sumi:
    temp = sumi
print(temp)

Submission status: Wrong Answer

Solution code:
m = int(input())
a = list( map( int, input().split() ) )
resi = temp = 0
for i in range(m):
  sumi = 0
  j = 0
  for ai in a:
    sumi = sumi  + abs(ai - (i - j))
    j +=1
  if i == 1:
    temp = sumi
  if temp > sumi:
    temp = sumi
    resi = i
print(resi)

Submission status: Wrong Answer

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

# calc median 
a_s = sorted(a)
medians = []
# if odd 
if N % 2 != 0 :
    medians.append(a_s[N // 2] - N // 2 - 1)
else :
    medians.append(a_s[N // 2] - N // 2 - 1)
    medians.append(a_s[N // 2 + 1] - (N // 2))
    
min_sum = sum(a)

for m in medians :
    sum_over = 0
    
    for i in range(N) :
        sum_over += abs(a[i] - (m + i + 1))
    
    min_sum = min(min_sum, sum_over)
    
print(min_sum)

Submission status: Wrong Answer

Solution code:
import numpy as np


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

med = np.median(a)
tgt = int(med - N // 2 - 1)

res = 0

for i in range(N) :
    res += abs(a[i] - (tgt + i + 1))
    
print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    A[i] = A[i] - i
sorted(A)
halfN = int(N/2)
x = 0
for i in range(N):
    x = x + abs(A[i] - A[halfN])
print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    A[i] = A[i] - i
sorted(A)
halfN = int(N/2)
x = 0
list = []
for j in range(-1,1):
    for i in range(N):
        x = x + abs(A[i] - A[halfN+j])
    list.append(x)
    x = 0
print(min(list))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    A[i] = A[i] - i
sorted(A)
halfN = int(N/2)
x = 0
list = []
for j in range(-1,1):
    for i in range(N):
        x = x + abs(A[i] - A[halfN+j])
    list.append(x)
    x = 0
print(min(list))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    A[i] = A[i] - i
sorted(A)
halfN = int(N/2)
x = 0
list = []
for j in range(-1,1):
    for i in range(N):
        x = x + abs(A[i] - A[halfN] + j)
    list.append(x)
    x = 0
print(min(list))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    A[i] = A[i] - i
sum = 0
for i in range(N):
    sum = sum + A[i]
ave = int(sum/N)
x = 0
list = []
for j in range(-2,2):
    for i in range(N):
        x = x + abs(A[i] - ave + j)
    list.append(x)
    x = 0
print(min(list))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
max = max(A)
list = []
x = 0
for i in range(N):
    A[i] = A[i] -i
sum = 0
for i in range(N):
    sum = sum + A[i]
ave = int(sum/N)
for j in range(-3,3):
    for i in range(N):
        x = x + abs(A[i]-ave+j)
    list.append(x)
    x=0
print(min(list))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
max = max(A)
list = []
x = 0
for i in range(N):
    A[i] = A[i] -i
sum = 0
for i in range(N):
    sum = sum + A[i]
ave = int(sum/N)
for i in range(N):
    x = x + abs(A[i]-ave-i)
print(x)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
max = max(A)
list = []
x = 0
for b in range(max):
    for i in range(N):
        x = x + abs(A[i]-(b+i))
    list.append(x)
    x = 0
print(min(list))

Submission status: Wrong Answer

Solution code:
# encoding: utf-8

#input
n = int(input())
A = [int(i) for i in input().split()]
# print(A)
def sad_value(A,b):
    sadness = 0
    for i in range(len(A)):
        sadness += abs(A[i]-b-i-1)
    return sadness

sadness = []
for i in range(100):
    sadness.append(sad_value(A, i-50))
sadness.sort()
print(sadness[0])

Submission status: Wrong Answer

Solution code:
# encoding: utf-8

#input
n = int(input())
A = [int(i) for i in input().split()]
# print(A)
def sad_value(A,b):
    sadness = 0
    for i in range(len(A)):
        sadness += abs(A[i]-b-i-1)
    return sadness

sadness = []
for i in range(10):
    sadness.append(sad_value(A, i-5))
sadness.sort()
print(sadness[0])

Submission status: Wrong Answer

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


N = int(input())
A = list(map(int,input().split()))
m = [kanashimi(N,A,b) for b in range(-N,N)]
print(min(m))

Submission status: Wrong Answer

Solution code:
# https://beta.atcoder.jp/contests/abc102/tasks/arc100_a
import statistics
import numpy as np

n = int(input())
nums = np.array(list(map(int, input().split())))
iteration = np.array(list(range(1, n + 1)))

difference_list = nums - iteration
median = statistics.median(difference_list)
print(sum(abs(difference_list - median)))

Submission status: Wrong Answer

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


if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    total = 0

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

    sorted_a = sorted(a)
    b = a[n // 2]

    for i in range(n):
        total += abs(a[i] - b)

    print(total)

Submission status: Wrong Answer

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


if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    total = 0

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

    sorted_a = sorted(a)
    b = a[n // 2]

    for i in range(n):
        total += abs(a[i] - b)

    print(total)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
L=len(a)
for i in range(L):
    a[i]-=(i+1)
dic={}
for i in a:
    if i not in dic:
        dic[i]=1
    else:
        dic[i]+=1
M=max(dic.values())
if M==1:
    c=0
else:
    for i in dic:
        if dic[i]==M:
            c=i

count=0
for i in a:
    count+=abs(c-i)
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())

k = list(int(i) for i in input().split())  

q = []
for x in range(n):
  q.append(abs(k[x]-(x+1)))


if len(q) == len(set(q)):
  print(sum(set(q)))
else:
  print(sum(q))

Submission status: Wrong Answer

Solution code:
n = int(input())

k = list(int(i) for i in input().split())  

q = []
for x in range(n):
  q.append(abs(k[x]-(x+1)))


print(sum(set(q)))

Submission status: Wrong Answer

Solution code:
n = int(input())

k = list(int(i) for i in input().split())  


q = []
for x in range(n):
  q.append(abs(k[x]-(x+1)))

  
print(sum(set(q)))

Submission status: Wrong Answer

Solution code:
n = int(input())

k = list(int(i) for i in input().split())  


q = []
for x in range(n):
  q.append(abs(k[x]-(x+1)))

  
print(sum(q))

Submission status: Wrong Answer

Solution code:
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 i in a:
    ans += abs(i - b)

print(ans)

Submission status: Wrong Answer

Solution code:
import statistics

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

sub_a = [a_n - i - 1 for i, a_n in enumerate(a)]
median = statistics.median(sub_a)
print(sum([abs(sub_a_n-median) for sub_a_n in sub_a]))

Submission status: Wrong Answer

Solution code:
import statistics

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

sub_a = [a_n - i - 1 for i, a_n in enumerate(a)]
median = statistics.median(sub_a)
print(sum(sub_a) - len(sub_a)*median)

Submission status: Wrong Answer

Solution code:
import math
import statistics
import numpy as np
size = int(input())
A = np.array(list(map(int,input().split())))
i = np.array(list(range(1,size+1)))

remain_list = A-i
median = statistics.median(remain_list)
print(sum(remain_list - median))

Submission status: Wrong Answer

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

ans = float("inf")
for b in range(min(A), max(A)):
    loss = sum([abs(A[i] - b) for i in range(N)])
    ans = min(ans, loss)

print(ans)

Submission status: Wrong Answer

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

ans = float("inf")
for b in range(min(A), max(A)):
    loss = sum([abs(A[i] - b) for i in range(N)])
    if ans > loss:
        ans = loss


print(ans)

Submission status: Wrong Answer

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

sub_abs_a = [abs(a_n - i - 1) for i, a_n in enumerate(a)]

print(sum(sub_abs_a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from statistics import *

n = int(input())
list = input().split()

for i in range(n):
    list[i] = int(list[i])-(i+1)

b = int(median(list))

for i in range(n):
    list[i] = int(list[i]-b)
    
print(sum(list))

Submission status: Wrong Answer

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

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

#まず数列の総計を求める
sum=0
for i in range(N):
   sum=sum+list[i]

print(sum)
b=N*N + N
b=b-2*sum
b=-b/(2*N)
print(b)
#bに一番近い整数を求める
seisubu=int(b)
shosubu=b-int(b)

if shosubu < 0.5 and shosubu > -0.5:
	b=int(b)
elif b >= 0:
	b=int(b)+1
else:
	b=int(b)-1
	

#悲しみを求める
i=0
sad=0
for i in range(N):
	a=list[i]
	i=i+1
	print(a-b-i)
	if a-(b+i) < 0:
		sad=sad+(b+i)-a
	else:
		sad=sad+a-(b+i)
	
print(sad)

Submission status: Wrong Answer

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

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

#まず数列の総計を求める
sum=0
for i in range(N):
   sum=sum+list[i]

b=N*N + N
b=b-2*sum
b=b/(2*N)

#bに一番近い整数を求める
seisubu=int(b)
shosubu=b-int(b)

if shosubu < 0.5 and shosubu > -0.5:
	b=int(b)
elif b >= 0:
	b=int(b)+1
else:
	b=int(b)-1
	
#悲しみを求める
i=0
sad=0
for i in range(N):
	a=list[i]
	i=i+1
	if a-(b+i) < 0:
		sad=sad+(b+i)-a
	else:
		sad=sad+a-(b+i)
	
print(sad)

Submission status: Wrong Answer

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

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

#まず数列の総計を求める
sum=0
for a in list:
   sum=sum+a

b=N*N + N
b=b-2*sum
b=b/(2*N)

#bに一番近い整数を求める
seisubu=int(b)
shosubu=b-int(b)

if shosubu < 0.5 and shosubu > -0.5:
	b=int(b)
elif b >= 0:
	b=int(b)+1
else:
	b=int(b)-1
	
#悲しみを求める
i=0
sad=0
for a in list:
	i=i+1	
	if a-(b+i) < 0:
		sad=sad+(b+i)-a
	else:
		sad=sad+a-(b+i)
	
	
	
print(sad)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 10 ** 10
B = []
for i in range(N):
    B.append(A[i] - (i + 1))
B.sort()
if N % 2 == 0:
    med = [B[int(N / 2) - 1], int((B[int(N / 2) - 1] + B[int(N / 2)] / 2)), B[int(N / 2)]]
else:
    med = [B[int((N + 1) / 2) - 1]]
for b in med:
    Sum = 0
    for i in range(N):
        Sum += abs(A[i] - (b + i + 1))
    if Sum < ans:
        ans = Sum
print(ans)

Submission status: Wrong Answer

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

A = input().rstrip().split()
#print(A)
i = 0
kari =[]
for j in A:
    i +=1
    B = int(j)-i
    kari.append(B)
#print(kari)
b = statistics.median(kari)

sum = 0
for i in kari:
    sum+=abs(i-b)
print(sum)

Submission status: Wrong Answer

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

A = input().rstrip().split()
#print(A)
i = 0
kari =[]
for j in A:
    i +=1
    B = int(j)-i
    kari.append(B)
#print(kari)
#print(statistics.median(kari))
b = statistics.median(kari)

sum = 0
for i in kari:
    sum+=i-b
print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
res = list()
for i, num in enumerate(a):
  res.append(abs(num - i))
print(min(res))

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

if n%2 == 0:
    med = (a[n//2] + a[(n+1)//2]) / 2
else:
    med = a[n//2]

result = 0
for num in a:
    result += abs(num - med)


print(result)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000)

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

le =[0]*N
for i in range(0,N):
    le[i]=int(li[i])
f=[False]

def sadmin(n1,b,le,sum0):
    # print(sum0)
    if f[0] == True:
        return
    sum = 0
    for i in range(0,n1):
        sum = sum + abs(le[i]-i-1-b)
    if sum < sum0:
        # print("再起")
        sadmin(n1,b+1,le,sum)
    else:
        print(sum0)
        f[0] = True
        return
    if f[0] == True:
        return
    print(1)
    return sum

sadmin(N,-200000,le,100000000)

Submission status: Wrong Answer

Solution code:
N = int(input())
li = input().rstrip().split()

le =[0]*N
for i in range(0,N):
    le[i]=int(li[i])
f=[False]

def sadmin(n1,b,le,sum0):
    if f[0] == True:
        return
    sum = 0
    for i in range(0,n1):
        sum = sum + abs(le[i]-i-1-b)
    if sum < sum0:
        # print("再起")
        sadmin(n1,b+1,le,sum)
    else:    
        print(sum0)
        f[0] = True
        return
    if f[0] == True:
        return
    print(1)    
    return sum

sadmin(N,-3,le,1000000)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a_tmp = input().split()
a = []
for i in range(n):
    a.append(int(a_tmp[i])-i-1)

if len(a) % 2 == 0:
    x = a[len(a)//2]
else:
    x = a[len(a)//2]
ans = 0
for _ in a:
    ans += math.fabs(_ - x)
print(int(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np
"""
N = int(input())
tmp = input().split(' ')

A = []
for i in range(N):
    A.append(int(tmp[i]))
"""

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

A = np.asarray(A)

z = np.asarray([x for x in range(1, N+1)])
#pdb.set_trace()
A = A - z

b = np.round(np.median(A))
A = A - b
A = np.absolute(A)
print(A.sum().astype(np.uint32))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
tmp = input().split(' ')

A = []
for i in range(N):
    A.append(int(tmp[i]))

A = np.asarray(A)

z = np.asarray([x for x in range(1, N+1)])
A = A - z

b = np.round(np.median(A))
A = A - b
A = np.absolute(A)
print(A.sum().astype(np.uint32))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
tmp = input().split(' ')

A = []
for i in range(N):
    A.append(int(tmp[i]))

A = np.asarray(A)

z = np.asarray([x for x in range(N)])
A = A - z

b_ceil = np.ceil(np.median(A)).astype(np.int32)
b_floor = np.floor(np.median(A)).astype(np.int32)

A_ceil = A - b_ceil
A_ceil = np.absolute(A_ceil)
A_floor = A - b_floor
A_floor = np.absolute(A_floor)

print(np.min((A_ceil.sum(), A_floor.sum())).astype(np.uint32))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
tmp = input().split(' ')

A = []
for i in range(N):
    A.append(int(tmp[i]))

A = np.asarray(A)

z = np.asarray([x for x in range(N)])
A = A - z

b = np.round(np.median(A)).astype(np.int32)
A = A - b
A = np.absolute(A)
print(A.sum().astype(np.uint32))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
tmp = input().split(' ')

A = []
for i in range(N):
    A.append(int(tmp[i]))

A = np.asarray(A)

z = np.asarray([x for x in range(N)])
A = A - z

b = np.round(np.median(A)).astype(np.uint32)
A = A - b
A = np.absolute(A)
print(A.sum().astype(np.uint32))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
tmp = input().split(' ')

A = []
for i in range(N):
    A.append(int(tmp[i]))

A = np.asarray(A)

z = np.asarray([x for x in range(N)])
A = A - z

b = np.round(np.median(A)).astype(np.int32)
print(b)
A = A - b
A = np.absolute(A)
print(A.sum().astype(np.uint32))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
tmp = input().split(' ')

A = []
for i in range(N):
    A.append(int(tmp[i]))

A = np.asarray(A)

z = np.asarray([x for x in range(N)])
A = A - z

b = np.round(np.median(A)).astype(np.uint32)
print(b)
A = A - b
A = np.absolute(A)
print(A.sum().astype(np.uint32))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
tmp = input().split(' ')

A = []
for i in range(N):
    A.append(int(tmp[i]))

A = np.asarray(A)

z = np.asarray([x for x in range(N)])
A = A - z

b = np.round(np.median(A))
A = A - b
A = np.absolute(A)
print(A.sum().astype(np.uint8))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
tmp = input().split(' ')

A = []
for i in range(N):
    A.append(int(tmp[i]))

A = np.asarray(A)

z = np.asarray([x for x in range(N)])
A = A - z

b = np.median(A)
A = A - b
A = np.abs(A)
print(A.sum().astype(np.uint32))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
tmp = input().split(' ')

A = []
for i in range(N):
    A.append(int(tmp[i]))

A = np.asarray(A)

z = np.asarray([x for x in range(N)])
A = A - z

b = np.median(A)
A = A - b
A = np.abs(A)
print(A.sum().astype(np.uint8))

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# --------------------------------------------

dp = None

def main():
    N = int(input())
    A = [int(_) for _ in input().split()]

    i = 0
    while i < len(A):
        A[i] -= (i + 1)
        i += 1

    b = sum(A) / len(A)

    if A.count(math.ceil(b)) > A.count(math.floor(b)):
        b = math.ceil(b)
    else:
        b = math.floor(b)

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

    print(sad)

main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# --------------------------------------------

dp = None

def main():
    N = int(input())
    A = [int(_) for _ in input().split()]

    i = 0
    while i < len(A):
        A[i] -= (i + 1)
        i += 1

    b = round(sum(A) / len(A))

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

    print(sad)

main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))

ar = a - range(1, len(a) + 1)
bm = ar.mean()
b1, b2 = np.floor(bm), np.ceil(bm)
print(int(min(np.abs(ar - b1).sum(), np.abs(ar - b2).sum())))