import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    auto N = readln.chomp.to!int;
    auto a = readln.split.to!(long[]);
    sort(a).group.map!(g => g[1] >= g[0] ? g[1] - g[0] : g[1]).sum.writeln;
}

