def main():
    n = int(input())
    X = list(map(int, input().split()))
    X.sort()
    k = 0
    if X[0] >= 2:
        inc = 2
    else:
        inc = 1
    for i in range(n//2):
        if 2*i + inc <= X[i]:
            k += X[i] - 2*i - inc
        else:
            k += 2*i + inc - X[i]
            X[i] = 2*i + inc
            j = i
            while j < n//2 - 1 and X[j] >= X[j+1]:
                while X[j] >= X[j+1]:
                    X[j+1] += 1
                    k += 1
                j += 1
            
    print(k)
    
main()
