from heapq import * class SlopeTrick: def __init__(self): self.minf = 0 self.inf = 1 << 60 self.R = [self.inf] self.L = [self.inf] self.addr = 0 self.addl = 0 @property def min(self): return self.minf def get_min(self): return (self.minf, -self.L[0] + self.addl, self.R[0] + self.addr) # add f(x) = a def add(self, a): self.minf += a # add f(x) = max(0, x - a) def add_x_a(self, a): self.minf += max(0, -self.L[0] + self.addl - a) heappush(self.L, self.addl - a) heappush(self.R, -heappop(self.L) + self.addl - self.addr) # add f(x) = max(0, a - x) def add_a_x(self, a): self.minf += max(0, a - self.R[0] - self.addr) heappush(self.R, a - self.addr) heappush(self.L, -heappop(self.R) - self.addr + self.addl) # add f(x) = abs(x - a) def add_abs(self, a): self.add_a_x(a) self.add_x_a(a) def add_l(self, x): assert x <= 0 self.addl += x def add_r(self, x): assert x >= 0 self.addr += x def solve(n, A): A.sort() for i in range(n): A[i] -= i st = SlopeTrick() for a in A: st.add_abs(a) while len(st.R) > 1: heappop(st.R) return st.min if __name__ == "__main__": n = int(input()) A = list(map(int, input().split())) print(solve(n, A))