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: def e_max_gcd(N, K, A):
      def divisor_list(n):
          """n の正の約数のリスト"""
          ret = []
          for k in range(1, int(n**0.5) + 1):
              if n % k == 0:
                  ret.append(k)
                  if k != n // k:
                      ret.append(n // k)
          ret.sort()
          return ret
  
      ans = 1  # 任意の整数は1の倍数
      for c in divisor_list(sum(A)):  # sum(A)の約数が解の candidate
          r = sorted([a % c for a in A])
          # rをある位置で左右に分けたとき、「左」には-1、「右」には+1する操作を
          # 行って全要素をcの倍数にしたい。このとき、「左」の要素の和の分だけ
          # 操作してよいが、それはKを超えてはならない。
          # 最初、すべての要素を「左」に入れる。
          # 「左」の要素の関数値A(-1してcの倍数にするための操作回数)は最初sum(r)とし、
          # 「右」の要素の関数値B(+1してcの倍数にするための操作回数)は最初0とする。
          # ここで「左」の要素eを右から順に「右」に入れていくとすると、1つ入れるごとに
          # A の値は e だけ減り、B の値は c - e だけ増える。
          # よって A-B の値は1つ「右」に入れるごとに c だけ減る。
          # ゆえに、「右」に何個の要素を入れるべきかは sum(r)//c からわかる。
          if sum(r[: N - sum(r) // c]) <= K:
              ans = max(ans, c)
      return ans
  
  
  N, K = [int(i) for i in input().split()]
  A = [int(i) for i in input().split()]
  print(e_max_gcd(N, K, A))
  
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"}]