def list_divisors(pd)
  return [1] if pd.size == 0
  q,d = pd[0]
  ds = list_divisors(pd[1..-1])
  x = 1
  (0..d).map{
    ds.map{ |d| d * x }.tap{ x *= q }
  }.flatten
end

require "prime"
N,K,*A = `dd`.split.map &:to_i
SA = A.inject(:+)

ds = list_divisors(SA.prime_division).sort
p ds.reverse_each.find{ |d|
  as = A.map{ |a| a % d }.select{ |a| a > 0 }.sort
  dd = as.inject(0,:+)
  next true if dd == 0
  n = dd / d
  as[0...(as.size - n)].inject(0,:+) <= K
}

