import std.stdio; import std.algorithm; import std.array; import std.bigint; import std.conv; import std.math; import std.range; import std.string; import std.typecons; long diffSum(long[] arr, long p) { long ret; foreach(a; arr) ret += (p - a).abs; return ret; } void main() { int N = readln.chomp.to!int; auto Y = readln.chomp.split.map!(to!long).array; auto t = reduce!(min, max)(Y); // これすごい long lb = t[0], rb = t[1] + 1, mid; long ans = Y.diffSum(reduce!("a + b")(0L, Y) / N); /* while (rb - lb > 1) { mid = (lb + rb) / 2; long dsum = Y.diffSum(mid); if (ans < dsum) { rb = mid; } else { ans = dsum; lb = mid; } } */ //ans = ans.min(Y.diffSum(lb).min(Y.diffSum(rb))); ans.writeln; }