import std.algorithm, std.array, std.container, std.range, std.bitmanip; import std.numeric, std.math, std.bigint, std.random, core.bitop; import std.string, std.regex, std.conv, std.stdio, std.typecons; void main() { auto b = readln.chomp.to!long; auto n = readln.chomp.to!size_t; auto ci = iota(n).map!(_ => readln.chomp.to!long).array; long calc(long r) { return ci.map!(c => (c - r).abs.to!long).sum; } auto mi = 0L, ma = (ci.sum + b) / n, r = -1L; while (ma - mi > 2) { auto mt1 = (mi * 2 + ma) / 3; auto mt2 = (mi + ma * 2) / 3; auto r1 = calc(mt1); auto r2 = calc(mt2); if (r1 > r2) { mi = mt1; } else { ma = mt2; } } r = iota(mi, ma + 1).map!(r => calc(r)).reduce!(min); writeln(r); }