#region Header #!/usr/bin/env python3 # from typing import * import sys import io import math import collections import decimal import itertools from queue import PriorityQueue import bisect import heapq def input(): return sys.stdin.readline()[:-1] sys.setrecursionlimit(1000000) #endregion # _INPUT = """# paste here... # """ # sys.stdin = io.StringIO(_INPUT) def main(): N = int(input()) Y = sorted(list(map(int, input().split()))) n = N // 2 d = sum(abs(y - Y[n]) for y in Y) print(d) if __name__ == '__main__': main()