import sys from collections import deque, Counter input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 import heapq class MedianHeap(): def __init__(self): self.top = [] self.bottom = [] def __len__(self): return len(self.top) + len(self.bottom) def add(self, x): heapq.heappush(self.top, x) while len(self.top) - 2 >= len(self.bottom): heapq.heappush(self.bottom, -heapq.heappop(self.top)) while self.top and self.bottom and self.top[0] < -self.bottom[0]: x = heapq.heappop(self.top) y = heapq.heappop(self.bottom) heapq.heappush(self.top, -y) heapq.heappush(self.bottom, -x) def med(self): if len(self) % 2: return self.top[0] else: return self.top[0] n = ii() a = li() a.sort() a = [a[i] - i for i in range(n)] stack = [] for V in a: M = MedianHeap() M.add(V) stack.append(M) while len(stack) >= 2: X = stack.pop() Y = stack.pop() m2 = X.med() m1 = Y.med() if m1 <= m2: stack.append(Y) stack.append(X) break else: if 1: for v in X.top: Y.add(v) for v in X.bottom: Y.add(-v) stack.append(Y) else: for v in Y.top: X.add(v) for v in Y.bottom: X.add(-v) stack.append(X) P = [len(stack[i]) for i in range(len(stack))] cnt = 0 b = [0] * n for i, v in enumerate(P): med = stack[i].med() for x in range(v): b[cnt] = med cnt += 1 ans = sum([abs(a[i] - b[i]) for i in range(n)]) print(ans)