output_description: Print the maximum possible positive integer that divides every element of A
  after the operations.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N K
      A_1 A_2 \cdots A_{N-1} A_{N}
attempt: import sys
  
  read = sys.stdin.buffer.read
  readline = sys.stdin.buffer.readline
  readlines = sys.stdin.buffer.readlines
  
  n, k = map(int, input().split())
  a = [int(i) for i in input().split()]
  
  
  def divisorize(fct):
      b, e = fct.pop()
      pre_div = divisorize(fct) if fct else [[]]
      suf_div = [[(b, k)] for k in range(e + 1)]
      return [pre + suf for pre in pre_div for suf in suf_div]
  
  
  def factorize(n):
      fct = []
      b, e = 2, 0
      while b * b <= n:
          while n % b == 0:
              n = n // b
              e = e + 1
          if e > 0:
              fct.append((b, e))
          b, e = b + 1, 0
      if n > 1:
          fct.append((n, 1))
      return fct
  
  
  def num(fct):
      a = 1
      for base, exponent in fct:
          a = a * base**exponent
      return a
  
  
  c = []
  fct = factorize(sum(a))
  for div in divisorize(fct):
      c.append(num(div))
  
  c.sort(reverse=True)
  ans = 1
  from heapq import heapify, heappush, heappop
  
  for num in c:
      chk = 0
      cnt = 0
      pl = []
      mi = []
      heapify(pl)
      heapify(mi)
      for j in a:
          m = min(j % num, num - j % num)
          chk += m
          if m == j % num:
              cnt += m
              heappush(pl, -m)
          else:
              cnt -= m
              heappush(mi, -m)
  
      for i in range(abs(cnt) // num):
          if cnt < 0 and pl != []:
              p = heappop(pl)
              chk += p
              chk += num
          elif cnt > 0 and mi != []:
              q = heappop(mi)
              chk -= q
              chk -= num
      if chk <= 2 * k:
          ans = num
          break
  
  print(ans)
  
problem_description: Statement
  
  We have a sequence of N integers: A_1, A_2, \cdots, A_N.
  
  You can perform the following operation between 0 and K times (inclusive):
  
    * Choose two integers i and j such that i \neq j, each between 1 and N (inclusive). Add 1 to A_i and -1 to A_j, possibly producing a negative element.
  
  Compute the maximum possible positive integer that divides every element of A
  after the operations. Here a positive integer x divides an integer y if and
  only if there exists an integer z such that y = xz.
samples: [{"input": "2 3\n    8 20", "output": "7\n    \n\n7 will divide every element of A if, for example, we perform the following\noperation:\n\n  * Choose i = 2, j = 1. A becomes (7, 21).\n\nWe cannot reach the situation where 8 or greater integer divides every element\nof A.\n\n* * *"}, {"input": "2 10\n    3 5", "output": "8\n    \n\nConsider performing the following five operations:\n\n  * Choose i = 2, j = 1. A becomes (2, 6).\n  * Choose i = 2, j = 1. A becomes (1, 7).\n  * Choose i = 2, j = 1. A becomes (0, 8).\n  * Choose i = 2, j = 1. A becomes (-1, 9).\n  * Choose i = 1, j = 2. A becomes (0, 8).\n\nThen, 0 = 8 \\times 0 and 8 = 8 \\times 1, so 8 divides every element of A. We\ncannot reach the situation where 9 or greater integer divides every element of\nA.\n\n* * *"}, {"input": "4 5\n    10 1 2 22", "output": "7\n    \n\n* * *"}, {"input": "8 7\n    1 7 5 6 8 2 6 5", "output": "5"}]