import  sequtils, strutils, algorithm, math

var
  n = readLine(stdin).parseInt
  a:seq[int] = readLine(stdin).split.map(parseInt)
  a1:seq[int]
  res:seq[int] = @[]

for i in (min(a) * 2 - 1)..(max(a) * 2 - 1):
  a1 = a.map(proc(x:int):int = x mod i)
  res.add(sum(a1))

echo max(res) - n