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: Accepted

Solution code:
import statistics
import math
N = int( input())
temp = list(map(int,input().split(" ")))
for i in range(len(temp)):
    temp[i] = (temp[i] - (i+1))

m = statistics.median(temp)
nums = list(map(lambda x:abs(x-m),temp))
ans = sum(nums)
ans = int(ans)
print(ans)

Submission status: Accepted

Solution code:
from math import ceil

N = int(input())
A = [int(c) - i for i, c in enumerate(input().split())]

A.sort()

median = A[ceil((N - 1) /2)]

num = 0
for i in range(N):
    num += abs(A[i] - median)

print(num)

Submission status: Accepted

Solution code:
N = int(input())
src = list(map(int,input().split()))
 
dis = [a-i-1 for i,a in enumerate(src)]
center = sorted(dis)[N//2]
 
ans = 0
for a in dis:
    ans += abs(a - center)
print(ans)

Submission status: Accepted

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

B = sorted(B)
mid = B[N // 2]
num = 0
for i in range(N):
    num += abs(B[i] - mid)

print(num)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
B = []
for i in range(n):
    B.append(A[i]-(i+1))
B.sort()
M = B[n//2]
res = 0
for b in B:
    res += abs(b-M)
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import statistics
N = int(input())
A = list(map(int, input().split()))
B = []
for i in range(N):
  B.append(A[i]-(i+1))
#print(B)
b = statistics.median(B)

s = 0
for i in range(N):
  s += abs(A[i] - (b+i+1))
print(int(s))

Submission status: Accepted

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

b = []
i = 1
for a in A:
    b.append(a-i)
    i+=1

b.sort()

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

abs = lambda x : x if x > 0 else -x
sad = lambda x : abs(x - med)
print(sum(map(sad,b)))

Submission status: Accepted

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

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

    for i in range(0, N):
        A[i] = A[i] - (i+1)
    
    sorted_A = sorted(A)
    b = sorted_A[N//2]

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

    print(ans)

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int, input().split()))
A = [As[i] - (i+1) for i in range(N)]
A.sort()
b1 = A[N//2]
b2 = A[N//2 -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: Accepted

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]
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: Accepted

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: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
li = []
ans = 0
for ind,i in enumerate(A):
    li+=[i-(ind+1)]
li.sort()
x = li[(len(li)-1)//2]
for i in li:
    ans+=abs(i-x)
print(ans)

Submission status: Accepted

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 int(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: Accepted

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

Submission status: Accepted

Solution code:
_,a=open(0);a=sorted(int(x)-i for i,x in enumerate(a.split()));print(sum(abs(i-a[len(a)//2])for i in a))

Submission status: Accepted

Solution code:
input();a=sorted(int(x)-i for i,x in enumerate(input().split()));print(sum(abs(i-a[len(a)//2])for i in a))

Submission status: Accepted

Solution code:
from numpy import*;n,*a=map(int,open(0).read().split());x=sorted(array(a)-arange(1,n+1));print(sum(abs(x-x[n//2])))

Submission status: Accepted

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 = A[N // 2] if N % 2 else A[((N - 1) // 2 + N // 2) // 2]

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

print(sum)

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
for i in range(n):
  l[i]-=i
l.sort()
m=n//2
mm=l[m]
ans=0
for i in range(n):
  ans+=abs(l[i]-mm)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
B = [A[i]-i-1 for i in range(0,N)]
median = np.median(B)
print(int(np.sum(np.abs(B-median))))

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
for i in range(N):
    A[i] -= i+1
A.sort()
len_A = len(A)
Sum = 0
for i in range(len_A//2):
    Sum += A[len_A-1-i] - A[i]
print(Sum)

Submission status: Accepted

Solution code:
import statistics
import math

input()
num_list = [int(x) - i for (i,x) in enumerate(input().split(),1)]
med = statistics.median_low(num_list)
sad_list = [abs(x-med) for x in num_list]

print (sum(sad_list))

Submission status: Accepted

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

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

import numpy as np
b0 = np.median(b)
print(int(np.sum(np.abs(b - b0))))

Submission status: Accepted

Solution code:

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

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

bs = [As[N//2]]
if N % 2 == 0:
    bs.append(As[N//2-1])

total = 2*10**14
for b in bs:
    t = 0
    for A in As:
        t += abs(A - b)
    total = min(total, t)
print(total)

Submission status: Accepted

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

d_mid = d_[int(N/2)]
print(sum([abs(d_[i]-d_mid) for i in range(N)]))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
b=input().split()
a=[0]*n
for i in range(n):
    a[i]=int(b[i])-i
a.sort()
c=a[n//2]
ans=0
for i in range(n):
  ans+=abs(a[i]-c)
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

A = sorted(A)

if N % 2 == 1:
    b = A[N//2]
    for i in A:
        ans += abs(i - b)
    print(ans)
else:
    ans = -sum(A[:N//2])+sum(A[N//2:])
    print(ans)

Submission status: Accepted

Solution code:
""" AtCoder """

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

if N ==1:
    print(0)
    exit()

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

A.sort()

b = A[N//2]

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
""" AtCoder """

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

if N ==1:
    print(0)
    exit()

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

A.sort()

b = A[N//2]
bb = A[N//2 + 1]

ans = 0
ansans = 0

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

print(min(ans, ansans))

Submission status: Accepted

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

ai = list(sorted([a - i - 1 for i, a in enumerate(alist)]))
if n % 2 == 1:
  b = ai[n // 2]
  print(sum(abs(_ai - b) for _ai in ai))
else:
  b = (ai[n // 2 - 1] + ai[n // 2])
  if b % 2 == 0:
    b //= 2
    print(sum(abs(_ai - b) for _ai in ai))
  else:
    b //= 2
    print(min(sum(abs(_ai - b - 1) for _ai in ai), sum(abs(_ai - b) for _ai in ai)))

Submission status: Accepted

Solution code:
import sys

N = int(input())
A = list(map(int, input().split()))
A = sorted([A[k]-(k+1) for k in range(N)])

if N == 1:
  print(0)
  sys.exit()

for k in range((N-2)//2 + 1, N-1):
  if A[k] < A[k+1]:
    b = k
    break
  if k == N-2:
    print(0)
    sys.exit()
print(sum([abs(A[k]-A[b]) for k in range(N)]))

Submission status: Accepted

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
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = II()
    A = LI()
    for i in range(n):
        A[i] = A[i] - i - 1
    import statistics
    a = round(statistics.median(A))
    ans = 0
    for i in range(n):
        ans += abs(A[i] - a)
    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: Accepted

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

Submission status: Accepted

Solution code:
import math
def p(d): print(d)
def i(): return input()

def LI():  # Line Integer
    # 1行 1つの数字
    return int(input())
def LIS():  # Line IntegerS
    # 1行 mつの数字
    return [int(x) for x in input().split()]
def MLIS(n):  # Multi Line IntegerS
    # n行 mつの数字
    return [[int(x) for x in input().split()] for y in range(n)]
def LC():  # Line Character
    # 1行 1つの文字列
    return input()
def LCS(): # Line CharacterS
    # 1行 nつの文字列
    return [x for x in input().split()]
def MLCS(n): # Multi Line CharacterS
    # n行 mつの文字列
    return [[x for x in input().split()] for y in range(n)]

def alp2int(alphabet):
    # アルファベットの番号を返す
    return ord(alphabet) - ord('a')
def int2alp(num):
    # 番号からアルファベットを返す
    return chr(num + ord('a'))
def cnt2dic(lst, dic={}):
    # 同じものをカウントして辞書型にする
    for x in lst:
        key = str(x)
        if key in dic:
            dic[key] += 1
        else:
            dic[key] = 1
    return dic
def dic2lst(dic, key=lambda x:x[1]):
    # 辞書をタプルの配列にする
    return sorted(list(dic.items()), key=key);

def unqlst(lst):
    return list(set(lst))

def A():
    a = LC()
    if a[0] == a[2]:
        print('Yes')
    else:
        print('No')

def B():
    a, b, c, d = LIS()
    s = max(a, c)
    e = min(b, d)
    if s < e:
        p(e-s)
    else:
        p(0)

def C():
    N = LI()
    reds = sorted(MLIS(N), key=lambda x:x[0])
    blues = sorted(MLIS(N), key=lambda x:x[0])

    blueF = [False for x in range(N)]

    count = 0

    for i in range(N):
        for j in range(N):
            if blueF[j] == False and reds[i] < blues[j]:
                blueF[j] = True
                count += 1
                break
    print(count)

def D():
    pass

def E():
    s = LC()
    k = LI()
    words = []
    for b in range(len(s)):
        for e in range(1, 6):
            if s[b:b+e] != '':
                words.append(s[b:b+e])
    words = sorted(unqlst(words))
    print(words[k-1])
def F():
    pass

def G():
    n = LI()
    A = LIS()
    B = [A[i] - (i+1) for i in range(n)]
    B = sorted(B)

    b = B[n//2]

    count = 0
    for i in range(n):
        kana = abs(A[i] - (b + i + 1))
        count += kana
    print(count)

def H():
    pass

G()

Submission status: Accepted

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)
    ans3 = 0
    b = a[n//2]
    for i in range(n):
        ans3 += abs(a[i]-b)
    print(min(ans,ans2,ans3))

#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: Accepted

Solution code:
n=int(input());a=sorted(int(x)-i for i,x in enumerate(input().split()));print(sum(abs(i-a[n//2])for i in a))

Submission status: Accepted

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

print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

m = []
for i in range(n):
    m.append(l[i]-i-1)

m.sort()
index = n//2

b = m[index]

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

print(ans)

Submission status: Accepted

Solution code:
import statistics

n = int(input())
A = list(map(int, input().split()))
B = [A[i-1]-i for i in range(1,n+1)]
b = statistics.median(B)

print(int(sum([abs(B[i]-b) for i in range(n)])))

Submission status: Accepted

Solution code:
import statistics

n = input()
l = list(map(int, input().split()))
x = []
for i in range(len(l)):
  x.append(l[i] - i)
    
b = 0
if (len(x) % 2 == 1):
  b = statistics.median(x)
else:
  b = statistics.median_low(x)

sad = 0
for i in x:
  sad += abs(i - b)

print(sad)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = []
for i,j in enumerate(a):
  b.append(j-i)
b.sort()
c = b[n//2]
ans = 0
for i in b:
  ans += abs(i-c)
print(ans)

Submission status: Accepted

Solution code:
N=int(input())

A=list(map(int,input().split()))
B=[]
for i in range(N):
    B.append(A[i]-i)
    
B.sort()

if N==0:
    print(1)
elif N%2==1:
    ANS=0
    for j in range(N):
        ANS+=abs(B[j]-B[N//2])
    print(ANS)
else:
    S=0
    for j in range(N):
        S+=abs(B[j]-B[N//2-1])
    L=0
    for k in range(N):
        L+=abs(B[j]-B[N//2])
    print(min(S,L))

Submission status: Accepted

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

A2 = sorted([A[i]-i-1 for i in range(len(A))])
median = A2[len(A)//2]

ans = 0
for i in range(len(A)):
    ans += abs(A2[i]-median)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

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

b1 = A[N//2-1]
b2 = A[N//2]

ans1 = 0
ans2 = 0

for i in range(N):
    ans1 = ans1 + abs(A[i]-b1)
    ans2 = ans2 + abs(A[i]-b2)
    
print(min(ans1, ans2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, As = int(input()), map(int, input().split())
As = sorted([A - i - 1 for i, A in enumerate(As)])
b = As[N // 2]
print(sum(map(lambda A: abs(A - b), As)))

Submission status: Accepted

Solution code:
def inpli(): return [int(v)-i-1 for i,v in enumerate(input().split())]
N = int(input())
A = sorted(inpli())
a = A[N//2]
ans = 0
for i in A:
    ans += abs(a-i)
print(ans)

Submission status: Accepted

Solution code:
import statistics
n=int(input())
a=list(map(int,input().split()))
for i in range(len(a)):
    a[i]-=i
x=0
m=statistics.median(a)
for i in a:
    x+=abs(i-m) 
print(int(x))

Submission status: Accepted

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

a = [i - 1 - ind for ind, i in enumerate(a)]
a.sort()
b = a[len(a)//2]
ans = sum([abs(i - b) for i in a])
print(ans)

Submission status: Accepted

Solution code:
N=int(input().strip())
a=list(map(int, input().strip().split(' ')))
for i in range(N):
    a[i]=a[i]-i
a.sort()
m=a[(N-1)//2]
ans=0
for i in range(N):
    ans+=abs(a[i]-m)
print(ans)

Submission status: Accepted

Solution code:
from statistics import median
N = int(input())
A = list(map(int,input().split()))
B = [A[i] - i - 1 for i in range(N)]
b = round(median(B))
C = [abs(B[i] - b) for i in range(N)]
print(sum(C))

Submission status: Accepted

Solution code:
N=int(input())
A=[int(i) for i in input().split(' ')]
for i in range(len(A)):
  A[i]-=i+1
A.sort()
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: Accepted

Solution code:
import numpy as np

N = int(input())
A = list(map(int, input().split()))
A = np.array([A[i] - i for i in range(N)])
b = np.median(A)
sadness = np.sum(np.abs(A - b))
print(int(sadness))

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    B = [a[i]-i-1 for i in range(len(a))]
    B.sort()
    ans = 0
    for i,aa in enumerate(a):
        ans+=abs(aa-(i+1)-B[len(B)//2])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

B = sorted(A2)

b = B[int(N/2)]


A3 = [abs(a - b) for a in A2]

print(sum(A3))


sys.exit(0)

Submission status: Accepted

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

alist = [ai[i]-i-1 for i in range(N)]
alist.sort()

middle = alist[N//2]
al = [abs(i-middle) for i in alist]
print(sum(al))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
list_a = list(map(int, input().split()))
list_123 = []
for i in range(n):
    list_123.append(i+1)
list_dif = [0]*n
for i in range(n):
    list_dif[i] = list_a[i] - list_123[i]
list_dif_sorted = sorted(list_dif)
med = list_dif_sorted[n//2]
ans = 0
for i in range(n):
    ans += abs(list_dif[i] - med)
print(ans)

Submission status: Accepted

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

def main():
    n = int(input())
    ai = list(map(int, input().split()))
    assert len(ai) == n

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

    ai = sorted(ai)
    b = ai[(n - 1) // 2]

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

    print(mi)

main()

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

print(sum(map(lambda x:abs(x-b),A)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

As.sort()
b = As[N // 2]

print(sum([abs(A - b) for A in As]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = []
for i,x in enumerate(input().split()):
    x = int(x)
    a.append(x-(i+1))
a = sorted(a)

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

ret = 0
for x in a:
    ret += abs(x-b)
print(ret)

Submission status: Accepted

Solution code:
import numpy

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

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

mid = int(numpy.median(A))


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


print(f(mid))

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
aa = inpl()
for i in range(N):
	aa[i] -= i+1

aa.sort()

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

ans = 0
for a in aa:
	ans += abs(mid-a)

print(ans)

Submission status: Accepted

Solution code:
N = int(raw_input())
nums = list(map(int,raw_input().split()))
lo = -pow(10,9)
hi = pow(10,9)

def f(cur):
    res = 0
    for i in range(N):
        res += abs(nums[i]-(cur+i+1))
    return res

ans = pow(10,15)

while lo<=hi:
    mid = (lo+hi)/2
    t1,t2 = f(mid),f(mid+1)
    ans = min(ans,t1,t2)
    if t1>t2:
        lo = mid+1
    else:
        hi = mid-1

print ans

Submission status: Accepted

Solution code:
n=int(input())
list=[int(x) for x in input().split()]
suma=0
asum=0
for k in range(n):
    list[k]-=k
list.sort()
suma=list[(1+n)//2-1]
for k in list:
    asum+=abs(suma-k)
print(asum)

Submission status: Accepted

Solution code:
from statistics import median

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

aa = list(map(lambda e: e[1] - (e[0] + 1), enumerate(a)))
minb = median(aa)


ans = int(sum(map(lambda ea: abs(ea - minb), aa)))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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 = np.sort(A - np.arange(1, len(A) + 1))
b = B[len(B) // 2]
print(np.abs(B - b).sum())

Submission status: Accepted

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)])
if N == 1:
    print(0)
else:
    print(sum(A[-M:]) - sum(A[:M]))

Submission status: Accepted

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)
  a.sort()
  if N % 2 == 0:
    t = (a[N//2-1] + a[N//2])//2
  else:
    t = a[(N-1)//2]
  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: Accepted

Solution code:
N = int(input())
As = sorted([int(a)-i for i, a in enumerate(input().strip().split(' '))])

temp1 = 0
temp2 = sum(As)
for i, a in enumerate(As):
    temp1 += As[i]
    temp2 -= As[i]
    r = As[i] * (i+1) - temp1 +\
    temp2 - As[i] * (N-1-i)
    result = min(result, r) if i != 0 else r
print(result)

Submission status: Accepted

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

B = []

for i, a in zip(range(1, n+1), A):
    B.append(a-i)

B.sort()
m = B[n//2]

ans = 0

for b in B:
    ans += abs(b-m)

print(ans)

Submission status: Accepted

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

import statistics

# 入力データ
in_cnt = int(input())
in_data = [int(i) for i in input().split()]

corrent_data = [0 for i in range(in_cnt)]
for idx in range(in_cnt):
	corrent_data[idx] = in_data[idx] - idx - 1

med_low = statistics.median_low(corrent_data)

ans=0
for idx in range(in_cnt):
	ans += abs( med_low - corrent_data[idx] )

print(ans)

Submission status: Accepted

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

from statistics import median
A = [a - i - 1 for i, a in enumerate(A)]
m = int(median(A))

print(sum(abs(a - m) for a in A))

Submission status: Accepted

Solution code:
n = int(input())

a = list(map(int,input().split()))
a = [a[i]-i for i in range(n)]
a.sort()
ans = 0
for i in range(n):
    ans += abs(a[i]-a[n//2])
print(ans)

Submission status: Accepted

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

median = sorted([x-i-1 for i, x in enumerate(data)])[n // 2]

ans = sum([abs(x-(median + i+1)) for i, x in enumerate(data)])
print(ans)

Submission status: Accepted

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

def main():
    N, A = read()
    B = [0 for _ in range(N)]
    for i in range(N):
        B[i] = A[i] - (i+1)
    B.sort()
    if N % 2 == 1:
        b = B[int((N-1)/2)]
    else:
        bl = B[int(N/2) - 1]
        br = B[int(N/2)]
        b = int((bl + br) / 2)

    sum = 0
    for i in range(N):
        sum += abs(B[i] - b)
    print(sum)


main()

Submission status: Accepted

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 = int(median(A))
    
ans = 0
for i in A:
    ans += abs(i-med)

print(ans)

Submission status: Accepted

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
a=i2()
for i in range(n):
 a[i]-=i+1
a=sorted(a)
b=n//2
if n%2:
   c=a[b]
   for i in range(n):
     a[i]=abs(a[i]-c)
else:
   b=(a[b]+a[b-1])//2
   for i in range(n):
     a[i]=abs(a[i]-b)
print(sum(a))

Submission status: Accepted

Solution code:
import statistics
import math

N = int(input())
a = input().split()
ans = 0
for i in range(0,N):
	a[i] = int(a[i])-i
med = int(statistics.median(a))
for i in range(0,N):
	ans += abs(a[i]-med)
print(int(ans))

Submission status: Accepted

Solution code:
n = int(input())
A = [int(i) for i in input().split(" ")]
b = 0
B = [A[i] - (i+1) for i in range(n)]
B.sort()
b = B[n//2]
sc = 0

for i in range(n):
    sc += abs(A[i] - (b+i+1))
    #print(A[i] - (b+i+1))
print(sc)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
for i in range(n):
    a[i] -= i+1

#中央値を求める
a.sort()
if len(a) % 2 == 0:
    c = (a[len(a)//2] + a[len(a)//2-1]) // 2
else:
    c = a[len(a)//2]

def hoge(b):
    v = 0
    for x in a:
        v += abs(x-b)
    return v

print(hoge(c))

Submission status: Accepted

Solution code:
i=int
k=input
N = i(k())
l = list(map(i,k().split()))
for j in range(N):
 l[j] -= (j+1)
l.sort()
print(sum(list(map(lambda x: abs(x - l[N//2]),l))))

Submission status: Accepted

Solution code:
N = int(input())
lis = list(map(int,input().split()))
for i in range(len(lis)):
  lis[i] -= (i+1)
lis.sort()
m = N // 2
c = lis[m]
print(sum(list(map(lambda x: abs(x - c), lis))))

Submission status: Accepted

Solution code:
'''input
7
1 1 1 1 2 3 4
'''
n = input()
arr = map(int,raw_input().split())
for i in range(n):
	arr[i] = (arr[i]-(i+1))
arr.sort()
mean = float(arr[n//2])
ans = 10**30
for i in range(int(mean)-30,int(mean)+30):
	q = 0
	for j in range(n):
		q += abs(arr[j]-i)
	ans = min(q,ans)
print ans

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
nums = list(map(int,input().split()))
ans = 0
B = []

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

B.sort()
b = B[n // 2]

for j in range(n):
    ans += abs(nums[j] - (j + 1 + b))

print(ans)