import sys

import numpy as np

from numba import njit



read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline



in_n = lambda: int(readline())

in_nn = lambda: list(map(int, readline().split()))

in_nl = lambda: list(map(int, readline().split()))

in_na = lambda: list(map(int, read().split()))

in_s = lambda: readline().rstrip().decode('utf-8')





@njit('(i8,i8[:],i8,)', cache=True)

def sad(N, A, x):

    s = 0

    for i in range(N):

        s += abs(A[i] - (x + i + 1))

    return s





@njit('(i8,i8[:],)', cache=True)

def solve(N, A):



    min_n = np.min(A) - 10**9

    max_n = np.max(A) + 10**9



    while max_n - min_n != 1:

        tn = (min_n + max_n) // 2

        if sad(N, A, tn) < sad(N, A, tn + 1):

            max_n = tn

        else:

            min_n = tn



    return max_n





def main():



    N = in_n()

    A = np.array(readline().split(), np.int64)



    b = solve(N, A)

    print((sad(N, A, b)))





if __name__ == '__main__':

    main()

import sys

import numpy as np



read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline



in_n = lambda: int(readline())

in_nn = lambda: list(map(int, readline().split()))

in_nl = lambda: list(map(int, readline().split()))

in_na = lambda: list(map(int, read().split()))

in_s = lambda: readline().rstrip().decode('utf-8')





def solve(N, A):



    def sad(x):

        s = 0

        for i in range(N):

            s += abs(A[i] - (x + i + 1))

        return s



    min_n = np.min(A) - 10**9

    max_n = np.max(A) + 10**9



    while max_n - min_n != 1:

        tn = (min_n + max_n) // 2

        if sad(tn) < sad(tn + 1):

            max_n = tn

        else:

            min_n = tn



    return sad(max_n)





def main():



    N = in_n()

    A = np.array(readline().split(), np.int64)



    print((solve(N, A)))





def cc_export():

    from numba.pycc import CC

    cc = CC('my_module')

    cc.export('solve', '(i8,i8[:],)')(solve)

    cc.compile()





if __name__ == '__main__':

    import sys

    if sys.argv[-1] == 'ONLINE_JUDGE':

        cc_export()

        exit(0)

    from my_module import solve

    main()

import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
in_n = lambda: int(readline())
in_nn = lambda: list(map(int, readline().split()))
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: list(map(int, read().split()))
in_s = lambda: readline().rstrip().decode("utf-8")


@njit("(i8,i8[:],i8,)", cache=True)
def sad(N, A, x):
    s = 0
    for i in range(N):
        s += abs(A[i] - (x + i + 1))
    return s


@njit("(i8,i8[:],)", cache=True)
def solve(N, A):
    min_n = np.min(A) - 10**9
    max_n = np.max(A) + 10**9
    while max_n - min_n != 1:
        tn = (min_n + max_n) // 2
        if sad(N, A, tn) < sad(N, A, tn + 1):
            max_n = tn
        else:
            min_n = tn
    return max_n


def main():
    N = in_n()
    A = np.array(readline().split(), np.int64)
    b = solve(N, A)
    print((sad(N, A, b)))


if __name__ == "__main__":
    main()

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
in_n = lambda: int(readline())
in_nn = lambda: list(map(int, readline().split()))
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: list(map(int, read().split()))
in_s = lambda: readline().rstrip().decode("utf-8")


def solve(N, A):
    def sad(x):
        s = 0
        for i in range(N):
            s += abs(A[i] - (x + i + 1))
        return s

    min_n = np.min(A) - 10**9
    max_n = np.max(A) + 10**9
    while max_n - min_n != 1:
        tn = (min_n + max_n) // 2
        if sad(tn) < sad(tn + 1):
            max_n = tn
        else:
            min_n = tn
    return sad(max_n)


def main():
    N = in_n()
    A = np.array(readline().split(), np.int64)
    print((solve(N, A)))


def cc_export():
    from numba.pycc import CC

    cc = CC("my_module")
    cc.export("solve", "(i8,i8[:],)")(solve)
    cc.compile()


if __name__ == "__main__":
    import sys

    if sys.argv[-1] == "ONLINE_JUDGE":
        cc_export()
        exit(0)
    from my_module import solve

    main()

-from numba import njit -@njit("(i8,i8[:],i8,)", cache=True) -def sad(N, A, x): -    s = 0 -    for i in range(N): -        s += abs(A[i] - (x + i + 1)) -    return s +def solve(N, A): +    def sad(x): +        s = 0 +        for i in range(N): +            s += abs(A[i] - (x + i + 1)) +        return s - -@njit("(i8,i8[:],)", cache=True) -def solve(N, A): -        if sad(N, A, tn) < sad(N, A, tn + 1): +        if sad(tn) < sad(tn + 1): -    return max_n +    return sad(max_n) -    b = solve(N, A) -    print((sad(N, A, b))) +    print((solve(N, A))) + + +def cc_export(): +    from numba.pycc import CC + +    cc = CC("my_module") +    cc.export("solve", "(i8,i8[:],)")(solve) +    cc.compile() +    import sys + +    if sys.argv[-1] == "ONLINE_JUDGE": +        cc_export() +        exit(0) +    from my_module import solve +