#!/usr/bin/env python import statistics n = int(input().strip()) indat = [int(x) for x in input().split()] median = statistics.median(indat) median = round(median) diff = [abs(median - x) for x in indat] print(sum(diff))