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!int; auto n = readln.chomp.to!size_t; auto ci = iota(n).map!(_ => readln.chomp.to!int).array; auto maxR = (ci.sum + b) / n; int calc(int r) { return ci.map!(c => (c - r).abs).sum; } auto s = iota(maxR + 1) .map!(r => calc((r + 1).to!int) - calc(r.to!int)) .assumeSorted.lowerBound(0); writeln(calc(s.length.to!int)); }