Problem:


Score : 300 points

Problem Statement

Snuke has an integer sequence A of length N.

He will freely choose an integer b.
Here, he will get sad if A_i and b+i are far from each other.
More specifically, the sadness of Snuke is calculated as follows:

abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))

Here, abs(x) is a function that returns the absolute value of x.

Find the minimum possible sadness of Snuke.

Constraints

1 \leq N \leq 2 \times 10^5

1 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the minimum possible sadness of Snuke.

Sample Input 1

5
2 2 3 5 5

Sample Output 1

2

If we choose b=0, the sadness of Snuke would be abs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2.
Any choice of b does not make the sadness of Snuke less than 2, so the answer is 2.

Sample Input 2

9
1 2 3 4 5 6 7 8 9

Sample Output 2

0

Sample Input 3

6
6 5 4 3 2 1

Sample Output 3

18

Sample Input 4

7
1 1 1 1 2 3 4

Sample Output 4

6



Sample input:
5
2 2 3 5 5


Sample output:
2

Submission status: Wrong Answer

Solution code:
def main():
    n, *a, = map(int, open(0).read().split())
    a = [x - i for i, x in enumerate(a, 1)]
    b = sum(a) // n
    ans1 = sum([abs(x - b) for x in a])
    ans2 = sum([abs(x - b - 1) for x in a])
    print(min(ans1, ans2))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n, *a, = map(int, open(0).read().split())
    a = [x - i for i, x in enumerate(a, 1)]
    b = sum(a) // n
    ans = sum([abs(x - b) for x in a])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    ans = 10**18
    k = (sum(A) - ((N+1)*N//2)) // N
    for b in range(k, k+2):
        f = 0
        for i, a in enumerate(A):
            f += abs(a - (b+i+1))
        ans = min(f, ans)
    print(ans)

abc102_c()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    L = lmi()
    L_dec = [elm - (i + 1) for i, elm in enumerate(L)]
    avg = sum(L_dec) // n
    a = 0
    for elm in L_dec:
        a += abs(elm - (avg - 1))
    b = 0
    for elm in L_dec:
        b += abs(elm - (avg))
    c = 0
    for elm in L_dec:
        c += abs(elm - (avg + 1))
    
    print(min(a, b, c))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    L = lmi()
    L_dec = [elm - (i + 1) for i, elm in enumerate(L)]
    avg = sum(L_dec) / n
    a = 0
    for elm in L_dec:
        a += abs(elm - math.floor(avg))
    b = 0
    for elm in L_dec:
        b += abs(elm - math.ceil(avg))
    
    print(min(a, b))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    L = lmi()
    L_dec = [elm - i for i, elm in enumerate(L)]
    avg = sum(L_dec) / n
    a = 0
    for elm in L_dec:
        a += abs(elm - math.floor(avg))
    b = 0
    for elm in L_dec:
        b += abs(elm - math.ceil(avg))
    
    print(min(a, b))


if __name__ == "__main__":
    main()

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
a.sort()

if N % 2 == 0:
    b = a[(N - 1) // 2] + 1
else: b = a[(N - 1) // 2]

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

print(sum(a))

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
a.sort()

b = sum(a)//N
ans = []

for j in [-1, 0, 1]:
    c = a[:]
    for i in range(N):
        c[i] = abs(c[i] -(b + j))
    ans.append(sum(c))

print(min(ans))

Submission status: Wrong Answer

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

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


tmp = total / N
if tmp > 0:
    tmp = int(tmp+0.5)
elif tmp < 0:
    tmp = int(tmp-0.5) - 1
else:
    tmp = 0
ans = 0
for i, a in enumerate(A):
    ans += abs(a-(tmp+(i+1)))

print(ans)

Submission status: Wrong Answer

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

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

tmp = int(total // N) + 1
tmp2 = int(total//N)

ans = 0
ans2 = 0
for i, a in enumerate(A):
    ans += abs(a-(tmp+(i+1)))
    ans2 += abs(a-(tmp2+(i+1)))

print(min(ans, ans2))

Submission status: Wrong Answer

Solution code:
import math

def mean(x):
    n = len(x)
    return sum(x)/n

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

ai = [a[i] - (i+1) for i in range(n)]
b = math.floor(mean(ai))
result = sum([abs(ai[i] - b) for i in range(n)])
print(result)

Submission status: Wrong Answer

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

c = [a[i]-i-1 for i in range(n)]
ans = 0
c.sort()
print(c)
if n%2 == 1:
    b = c[n//2]
    for i in range(n):
        ans += abs(c[i]-b)
else:
    b = (c[n//2]+c[n//2-1])//2
    #print(b)
    for i in range(n):
        ans += abs(c[i]-b)
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc102/tasks/arc100_a
# 13:03-13:20


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

    B = [A[i]-i for i in range(N)]
    
    b = sum(B) // N

    def sumb(x):
        return sum([abs(b-x) for b in B])
    
    ans1 = sumb(b-1)
    ans2 = sumb(b)
    ans3 = sumb(b+1)

    return min(ans1, ans2, ans3)


print(main())

Submission status: Wrong Answer

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

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

if len(arr)%2==0:
  tmp=[arr[len(arr)//2-1],arr[len(arr)//2]]
else:
  tmp=[arr[len(arr)//2]]

ans=10**20
for b in tmp:
  ans=min(ans,sum([abs(a[i]-b-i-1) for i in range(n)]))
print(ans)

Submission status: Wrong Answer

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

b_low=-1*(10**10)
b_high=10**10
b_low_d=sum([abs(a[i]-(b_low+2+i)) for i in range(n)])-sum([abs(a[i]-(b_low+1+i)) for i in range(n)])
b_high_d=sum([abs(a[i]-(b_high+2+i)) for i in range(n)])-sum([abs(a[i]-(b_high+1+i)) for i in range(n)])

while b_high-b_low>10:
  b_tmp=(b_low+b_high)//2
  b_tmp_d=sum([abs(a[i]-(b_tmp+2+i)) for i in range(n)])-sum([abs(a[i]-(b_tmp+1+i)) for i in range(n)])
  if b_tmp_d>0:
    b_high=b_tmp
  else:
    b_low=b_tmp

ans=10**10
for j in range(b_low,b_high):
  ans=min(ans,sum([abs(a[i]-(j+2+i)) for i in range(n)]))

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a2 = [a[i] - i - 1 for i in range(n)]
mean = sum(a2) / len(a2)
b = np.floor(mean)
a3 = sum([abs(a2[i] - b) for i in range(n)])
b = np.ceil(mean)
a4 = sum([abs(a2[i] - b) for i in range(n)])
print(int(min(a3, a4)))

Submission status: Wrong Answer

Solution code:
# ABC102C

import numpy as np
n = int(input())
a = [int(x) for x in input().split()]
a = np.array(a)
Min = np.inf
for b in range(100000):
    x = b+np.arange(1, n+1)
    Min = min(Min, sum(abs(a - x)))
print(Min)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
list_ai = list(map(int,input().split()))
list1 = [x-(i+1) for i,x in enumerate(list_ai)]
a1 = np.array(list1)
median1 = int(np.floor(np.median(a1)))
ans = int(np.sum(a1-median1))
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
list_ai = list(map(int,input().split()))
list1 = [x-(i+1) for i,x in enumerate(list_ai)]
a1 = np.array(list1)
median1 = int(np.floor(np.median(a1)))
ans = np.sum(a1-median1)
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)]

b = sorted(a)
if n % 2 != 0:
    b = b[n // 2]
else:
    b = (b[n // 2] + b[n // 2 - 1]) / 2

a = [abs(a[i] - b) for i in range(n)]
ans = sum(a)
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)]

b = sorted(a)
if n % 2 != 0:
    b = b[n // 2]
else:
    b = (b[(n + 1) // 2] + b[(n - 1) // 2]) / 2

a = [abs(a[i] - b) for i in range(n)]
ans = sum(a)
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)]

b = sorted(a)
if n % 2 != 0:
    b = b[n // 2]
else:
    b = (b[(n + 1) // 2] + b[(n - 1) // 2]) / 2

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

ans = sum(a)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

if len(set(a)) == n:
    b = 0
else:
    b = Counter(a).most_common()[0][0]

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

ans = sum(a)
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()

mid = (a[0] + a[-1]) // 2
ans = [0,0]
if mid > 0 :
    mid1 = mid + 1
else:
    mid1 = mid - 1
for i, aa in enumerate(a):
    ans[0] += abs(aa - mid)
    ans[1] += abs(aa - mid1)
print(min(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
a_ls = list(map(int, input().split()))
diff_ls = [a - i for i, a in enumerate(a_ls,1)]
diff_ls.sort()
avg_small = sum(diff_ls) // n
avg_large = avg_small + 1
ans = float('inf')
for avg in [avg_large, avg_small]:
    Sum = 0
    for diff in diff_ls:
        Sum += abs(diff - avg)
    ans = min(ans, Sum)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_ls = list(map(int, input().split()))
diff_ls = [a - i for i, a in enumerate(a_ls,1)]
avg_small = sum(diff_ls) // n
avg_large = avg_small + 1
ans = float('inf')
for avg in [avg_large, avg_small]:
    Sum = 0
    for diff in diff_ls:
        Sum += abs(diff - avg)
    ans = min(ans, Sum)
print(ans)

Submission status: Wrong Answer

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

b.sort()

b2=sum(b)//n

bsum=0
for i in range(n):
    bsum+=abs(b[i]-b2)
    
bsum2=0
for i in range(n):
    bsum2+=abs(b[i]-b2-1)

print(min(bsum,bsum2))

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
x = list(map(int,input().split()))
ans = 0
for i in range(n):
    x[i]-=i+1
ave=math.floor(sum(x)/len(x))
for i in range(n):
    ans+=abs(x[i]-ave)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    Ai = [a-i-1 for i, a in enumerate((A))]
    b = sum(Ai) / N
    b = int(Decimal(str(b)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
    ans = sum([abs(a - b) for a in Ai])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

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

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

# _A = list(map(abs, A))

average = math.floor(sum(A) / len(A)) - 1

for i in range(len(A)):
    A[i] = abs(A[i] - average)

sadness = sum(A)

print(sadness)

Submission status: Wrong Answer

Solution code:
import math

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

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

# _A = list(map(abs, A))

average = math.floor(sum(A) / len(A)) + 1

for i in range(len(A)):
    A[i] = abs(A[i] - average)

sadness = sum(A)

print(sadness)

Submission status: Wrong Answer

Solution code:
import math

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

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

# _A = list(map(abs, A))

average = math.floor(sum(A) / len(A))

for i in range(len(A)):
    A[i] = abs(A[i] - average)

sadness = sum(A)

print(sadness)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
lst = list(map(int, input().split()))

res = 0
for i in range(n):
  res += lst[i] - i
res = res/n

p = math.floor(res)
q = math.ceil(res)
o = p - 1
r = q + 1
os = ps = qs = rs =  0

for i in range(n):
  ps += abs(lst[i] - (p+i))
  qs += abs(lst[i] - (q+i))
  rs += abs(lst[i] - (r+i))
  os += abs(lst[i] - (o+i))
print(min(min(ps, qs), min(os, rs)))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
lst = list(map(int, input().split()))

res = 0
for i in range(n):
  res += lst[i] - i
res = res/n

p = math.floor(res)
q = math.ceil(res)
o = p - 1
r = q + 1
os = ps = qs = rs =  0

for i in range(n):
  ps += abs(lst[i] - (p+i))
  qs += abs(lst[i] - (q+i))
  rs += abs(lst[i] - (r+i))
  os += abs(lst[i] - (o+i))
print(min(ps, qs))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
lst = list(map(int, input().split()))

res = 0
for i in range(n):
  res += lst[i] - i
res = res/n
p = math.floor(res)
q = math.ceil(res)
ps = qs = 0

for i in range(n):
  ps += abs(lst[i] - (p+i))
  qs += abs(lst[i] - (q+i))
  
print(min(ps, qs))

Submission status: Wrong Answer

Solution code:
import math

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

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

left = -abs(min(A))
right = abs(max(A))
minimum = right
# print(A, left, right)
for b in range(left, right + 1):
    sadness = 0
    for Ai in A:
        sadness = abs(Ai - b)

    minimum = min(sadness, minimum)

print(sadness)

Submission status: Wrong Answer

Solution code:
import math

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

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

_A = list(map(abs, A))

average = math.floor(sum(_A) / len(_A))

for i in range(len(A)):
    A[i] = abs(A[i] - average)

sadness = sum(A)

print(sadness)

Submission status: Wrong Answer

Solution code:
import math

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

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

_A = list(map(abs, A))

average = math.ceil(sum(_A) / len(_A))

for i in range(len(A)):
    A[i] = abs(A[i] - average)

sadness = sum(A)

print(sadness)

Submission status: Wrong Answer

Solution code:
import math

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

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

_A = map(abs, A)
_A = list(A)

average = math.ceil(sum(_A) / len(_A))

for i in range(len(A)):
    A[i] = abs(A[i] - average)

sadness = sum(A)

print(sadness)

Submission status: Wrong Answer

Solution code:
import math

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

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

_A = map(abs, A)
_A = list(A)

average = math.floor(sum(_A) / len(_A))

for i in range(len(A)):
    A[i] = abs(A[i] - average)

sadness = sum(A)

print(sadness)

Submission status: Wrong Answer

Solution code:
import math

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

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

average = math.ceil(sum(A) / len(A))

for i in range(len(A)):
    A[i] = abs(A[i] - average)

sadness = sum(A)

print(sadness)

Submission status: Wrong Answer

Solution code:
import math

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

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

average = math.floor(sum(A) / len(A))

for i in range(len(A)):
    A[i] = abs(A[i] - average)

sadness = sum(A)

print(sadness)

Submission status: Wrong Answer

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

for i in range(N):
    A[i] =A[i]-(i+1)
d = {}
for a in A:
    if a in d:
        d[a] += 1
        continue
    d[a] = 1

mid = 0
for key in d:
    mid += d[key]*key
mid = mid//N

min = float('inf')

for i in range(mid, mid+1, 1):
    ans = 0
    for a in A:
        ans += abs(a-i)
    if ans<min:

        min = ans
print(min)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
sad = 0

def calc_sad(mid):
  ret = 0
  b = sorted(A)[mid-1]-(mid)
  for i in range(n):
    ret += abs(A[i]-(i+1)-b)
  return ret

if n%2==1:
  mid = (n+1)//2
  sad = calc_sad(mid)
else:
  mid_low = n//2
  mid_high = n//2+1
  sad = min(calc_sad(mid_low),calc_sad(mid_high))
print(sad)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
A = [a-i-1 for i, a in enumerate(map(int, input().split()))]
x = Counter(A)
target = x.most_common(1)[0][0]

ans = sum([abs(a-target) for a in A])

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
for i in range(n):
    a[i]-=(i+1)
m=int(sum(a)/n)
m1=m+1
m2=m-1
s=0
s1=0
s2=0
for i in range(n):
    s+=abs(a[i]-m)
    s1+=abs(a[i]-m1)
    s2+=abs(a[i]-m2)
print(min(s,s1,s2))

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')

def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()
    ret = {}
    for i, v in enumerate(A):
        ret[i] = abs(v - (i + 1))

    ret = sorted(ret.items(), key=lambda x:x[1])
    md = ret[len(ret)//2][1]

    ans = 0
    for r in ret:
        ans += abs(r[1] - md)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
for i in range(n):
  a[i] = a[i]-(i+1)
b = np.sum(a)//n
ans_lis = [b-3,b-2,b-1, b, b+1, b+2,b+3]
ans = 10**18
for i in ans_lis:
  ans =min(ans, np.sum(np.abs(a-i)))
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
for i in range(n):
  a[i] = a[i]-(i+1)
b = np.sum(a)//n
ans_lis = [b-2,b-1, b, b+1, b+2]
ans = 10**18
for i in ans_lis:
  ans =min(ans, np.sum(np.abs(a-i)))
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
for i in range(n):
  a[i] = a[i]-(i+1)
b = np.sum(a)//n
ans_lis = [b-1, b, b+1]
ans = 10**16
for i in ans_lis:
  ans =min(ans, np.sum(np.abs(a-i)))
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
n = int(input())
ns = list(map(int, input().split()))
new_ns = sorted([num - i - 1 for i, num in enumerate(ns)])
s = sum(new_ns)
b = 0
d = n / 2
while d > 0.01:
    sb = sum(abs(num - (b + 1)) for num in new_ns)
    if sb < s:
        b += d
        d /= 2
        s = sum(abs(num - b) for num in new_ns)
    else:
        b -= d
        d /= 2
        s = sum(abs(num - b) for num in new_ns)
print(min(sum(abs(num-int(b)) for num in new_ns), sum(abs(num-ceil(b)) for num in new_ns)))

Submission status: Wrong Answer

Solution code:
from math import ceil
n = int(input())
ns = list(map(int, input().split()))
new_ns = sorted([num - i - 1 for i, num in enumerate(ns)])
s = sum(new_ns)
b = 0
d = n // 2 + 1
while d >= 1:
    sb = sum(abs(num - (b + 1)) for num in new_ns)
    if sb < s:
        b += d
        d //= 2 + 1
        s = sum(abs(num - b) for num in new_ns)
    else:
        b -= d
        d //= 2 - 1
        s = sum(abs(num - b) for num in new_ns)
print(s)

Submission status: Wrong Answer

Solution code:
min = 0
c = 1
I = 0
N = int(input())
A = list(map(int,input().split()))
for i in A:
  I = (i -(0 + c))
  min += I
  c += 1
print(min)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = [int(i) for i in input().split()]
c = Counter(A)
val = c.most_common()
ans = 10000000000

for j in range(len(val)):
    for i in range(N):
        if A[i] == val[j][0]:
            idx = i + 1
            break
    b = val[j][0] - idx
    tmp = 0
    for i in range(N):
        tmp += abs(A[i] - (b + i + 1))
    ans = min(ans, tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

a = [int(i)-j for i,j in zip(input().split(),range(n))]

l = - 2 * 10 ** 5

r = 2 * 10 ** 5

def f(x):
  return sum(map(lambda y: abs(y - x), a))

while r - l > 3:
  l_r = (r - l) // 3
  l_i = l + l_r
  i_r = r - l_r
  if f(l_i) > f(i_r):
    l = l_i
  else:
    r = i_r
print(min(f(l),f(l+1),f(l+2),f(l+3)))

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
pr_abs = []
for i in range(n):
  pr_abs.append(a_list[i] - i-1)

left = -10**18
right = 10**18
first = 10**18

avg = round((sum(pr_abs)//len(pr_abs)))
ans = 0
for i in range(n):
  ans += abs(pr_abs[i] - avg)
  
print(ans)

Submission status: Wrong Answer

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

res = 0
for i in range(N):
    A[i] = abs(A[i]-(i+1))
b = A[N//2]
print(sum(list(map(lambda x:abs(x-b),A))))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
a = nl()

def calculate(a, med):
    ans = []
    start = med - len(a) // 2
    for i in range(len(a)):
        ans.append(abs(a[i] - start - i))
    #print(ans)
    return sum(ans)

if n % 2 == 1:
    med = sorted(a)[n//2]
    print(calculate(a, med))
else:
    med1 = sorted(a)[n//2]
    med2 = sorted(a)[n//2 - 1]
    print(min([calculate(a, med1), calculate(a, med2), calculate(a, med1+1), calculate(a, med2+1)]))