Permutation *p* is an ordered set of integers *p*<sub class="lower-index">1</sub>,  *p*<sub class="lower-index">2</sub>,  ...,  *p*<sub class="lower-index">*n*</sub>, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p*<sub class="lower-index">*i*</sub>. We'll call number *n* the size or the length of permutation *p*<sub class="lower-index">1</sub>,  *p*<sub class="lower-index">2</sub>,  ...,  *p*<sub class="lower-index">*n*</sub>.

You have a sequence of integers *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub>. In one move, you are allowed to decrease or increase any number by one. Count the minimum number of moves, needed to build a permutation from this sequence.
The first line contains integer *n* (1 ≤ *n* ≤ 3·10<sup class="upper-index">5</sup>) — the size of the sought permutation. The second line contains *n* integers *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> ( - 10<sup class="upper-index">9</sup> ≤ *a*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">9</sup>).
def main():
    n = int(input())
    elems = list(sorted(map(int, input().split(" "))))

    start_pos = 0
    while start_pos < n and elems[start_pos] <= 0:
        start_pos += 1

    less = elems[:start_pos]
    positive = elems[start_pos:]
    gte = []

    used = {}
    for x in positive:
        if x <= n:
            used[x] = 1
        else:
            gte.append(x)

    result = 0
    i = 1
    while i <= n:
        if not gte and not less:
            break
        if i in used:
            i += 1
            continue

        a = (gte[0] - i) if gte else None
        b = (abs(less[-1]) + i) if less else None

        if a is None and b is not None:
            less.pop()
            used[i] = 1
            result += b
            i += 1
            continue
        if b is None and a is not None:
            gte.pop(0)
            used[i] = 1
            result += a
            i += 1
            continue

        if a <= b:
            gte.pop(0)
            used[i] = 1
            result += a
        else:
            less.pop()
            used[i] = 1
            result += b
        i += 1

    print(result)

 
if __name__ == "__main__":
    main()
