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.

-----Constraints-----
 - 2 \leq N \leq 500
 - 1 \leq A_i \leq 10^6
 - 0 \leq K \leq 10^9
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N K
A_1 A_2 \cdots A_{N-1} A_{N}

-----Output-----
Print the maximum possible positive integer that divides every element of A after the operations.

-----Sample Input-----
2 3
8 20

-----Sample Output-----
7

7 will divide every element of A if, for example, we perform the following operation:
 - Choose i = 2, j = 1. A becomes (7, 21).
We cannot reach the situation where 8 or greater integer divides every element of A.

Difficulty: interview

Starter code:

Solutions:
# 割り切る数は、Aの総和の約数である
# 自分自身を除く約数について大きい順にすべて試して、当てはまるものがあれば答え

# 8,20を7の倍数に近づけるとき、
# 8 -> mod 7が1であり、-1か+6で7の倍数になる
# 20 -> mod 7が6であり、-6か+1で7の倍数になる
# -1と+1をペアにすることが出来て、この操作回数1をK = 3から引くと2となり、これが偶数ならOK

import sys
readline = sys.stdin.readline

N,K = map(int,readline().split())
A = list(map(int,readline().split()))

all = sum(A)
divisors = []
for i in range(1,int(all ** 0.5) + 1):
  if all % i == 0:
    divisors.append(i)
    divisors.append(all // i)

divisors = sorted(divisors,reverse = True)

#print(divisors)

for d in divisors:
  mods = [0] * (N)
  for i in range(len(A)):
    mods[i] = A[i] % d
  mods = sorted(mods)
  #print("d",d,"mods",mods)
  mods_front = [0] * N
  mods_front[0] = mods[0]
  for i in range(1,N):
    mods_front[i] = mods_front[i - 1] + mods[i]
  mods_back = [0] * N
  mods_back[-1] = d - mods[-1]
  #print("mods_front",mods_front)
  for i in range(N - 2,-1,-1):
    mods_back[i] = mods_back[i + 1] + (d - mods[i])
  #print("mods_back",mods_back)
  for i in range(N - 1):
    if mods_front[i] == mods_back[i + 1]:
      if K >= min(mods_front[i],mods_back[i + 1]):
        print(d)
        return
else:
  print(1)

from math import sqrt

def Divisor_Set(n):
    s = set()
    for i in range(1, int(sqrt(n))+2):
        if n%i == 0:
            s.add(i)
            s.add(n//i)
    return s

def main():
    n, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    a_sum = sum(a)
    st = Divisor_Set(a_sum)
    ans = 1
    st.remove(1)
    for v in st:
        b = [x%v for x in a]
        b.sort()
        for i in range(n-1):
            b[i+1] += b[i]
        for i in range(n-1):
            if b[i] == v*(n-i-1) - (b[-1] - b[i]):
                if b[i] <= k and ans < v:
                    ans = v
    print(ans)

def __starting_point():
    main()

__starting_point()


N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

s = sum(A)



def solve():
    ans = 1
    idx = 1

    while idx * idx <= s:
        if s % idx == 0:
            if ok(s // idx):
                return s // idx
            if ok(idx):
                ans = idx
        idx += 1

    return ans


def ok(i):
    D = list([x for x in [a % i for a in A] if x != 0])
    D.sort()

    l = len(D)

    S = [0] * (l + 1)
    for j in range(l):
        S[j + 1] = S[j] + D[j]

    for j in range(l):
        if S[j] == i * (l - j) - (S[l] - S[j]) and S[j] <= K:
            return True

    return False


print((solve()))


def main():
    N,K,*A=map(int, open(0).read().split())
    S=sum(A)
    X=[S]
    for i in range(2,int(S**.5)+1):
        if S%i==0:
            X.append(i)
            if i*i!=S:
                X.append(S//i)
    ans=1
    for x in X:
        B=[a%x for a in A]
        y=sum(B)//x
        z=sum(sorted(B, reverse=True)[y:])
        if z<=K:
            ans=max(ans,x)
    print(ans)

def __starting_point():
    main()
__starting_point()

def divisor(n):
    res = []
    i = 1
    while i*i <= n:
        if n%i == 0:
            res.append(i)
            if i*i != n:
                res.append(n//i)
        i += 1
    res.sort()
    return res

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
S = sum(A)
ans = 1
for d in divisor(S):
    rs = [a%d for a in A]
    rs.sort()
    Sum = [0]*(N+1)
    Sum2 = [0]*(N+1)
    for i in range(1,N+1):
        Sum[i] = Sum[i-1]+rs[i-1]
        Sum2[i] = Sum2[i-1]+(d-rs[i-1])
    for i in range(N+1):
        if Sum[i] == Sum2[N]-Sum2[i]:
            if Sum[i] <= K:
                ans = d
print(ans)


def max2(x,y):
    return x if x > y else y

def divisors(n):
    i = 1
    table = set()
    while i * i <= n:
        if not n % i:
            table.add(i)
            table.add(n//i)
        i += 1
    table = list(table)
    return table

import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
D = divisors(S)
D.sort()
res = 0
for k in D:
    B = []
    for a in A:
        B.append(a%k)
    B.sort()
    cnt = sum(B)//k
    if k*cnt - sum(B[-cnt:]) <= K:
        res = max2(res, k)

print(res)

import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
A = np.array(lr())
sum = A.sum()
# Aiが1以上のため、answerはsumの約数

def make_divisors(n): # nの約数を列挙
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

B = make_divisors(sum)

for x in B[::-1]:
    c = A % x
    c.sort()
    d = x - c
    c_cum = c.cumsum()
    d_cum = d.cumsum()
    
    for i in range(N):
        y = c_cum[i]
        z = d_cum[N-1] - d_cum[i]
        if y > K or z > K:
            continue
        result = (y + z) // 2
        if result <= K:
            print(x)
            return


from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
import unittest
from io import StringIO
import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    def make_divisors(n):
        divisors = []
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                divisors.append(i)
                if i != n // i:  # 平方数の場合n**0.5を1つだけにしてる
                    divisors.append(n//i)

        divisors.sort(reverse=True)  # ソートしたけりゃして
        return divisors

    M = make_divisors(sum(A))

    def main():
        for i in M:
            AA = [0]*N
            age = 0
            # delete = 0
            for j in range(N):
                AA[j] = A[j] % i
                #if AA[j] == 0:
                    # delete += 1
                    # age -= i
                age += i-AA[j]
            AA.sort()

            times = 10**9
            sage = 0
            for j in range(0,N-1):
                sage += AA[j]
                age -= i-AA[j]
                if sage % i == age % i:
                    times = min(max(sage, age), times)
            if times <= K:
                return i
    print(main())

resolve()

import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N,K=LI()
AS=LI()
SUMM= sum(AS)

DIVS=set()
for i in range(1,40000):
    if SUMM % i == 0:
        DIVS.add(i)
        DIVS.add(SUMM//i)
# DIVS.sort(reversed=True)
# print(DIVS)

DIFF=[0]*N
ACC=[0]*N

# res = 0

for div in sorted(DIVS, reverse=True):
    for i in range(N):
        DIFF[i] = AS[i]%div
    DIFF.sort()
    ACC[0] = DIFF[0]
    for i in range(1,N): ACC[i] = ACC[i-1] + DIFF[i]
    # print(ACC)
    for i in range(N-1):
        left = ACC[i]
        right = (N-1-i)*div-(ACC[N-1]-ACC[i])
        if left%div == right%div:
            if max(left, right) <= K:
                # print(max(left, right))
                print(div)
                return


# print(DIFF)
# print(res)


# 割り切る数は、Aの総和の約数である
# 自分自身を除く約数について大きい順にすべて試して、当てはまるものがあれば答え

# 8,20を7の倍数に近づけるとき、
# 8 -> mod 7が1であり、-1か+6で7の倍数になる
# 20 -> mod 7が6であり、-6か+1で7の倍数になる

import sys
readline = sys.stdin.readline

N,K = map(int,readline().split())
A = list(map(int,readline().split()))

all = sum(A)
divisors = []
for i in range(1,int(all ** 0.5) + 1):
  if all % i == 0:
    divisors.append(i)
    divisors.append(all // i)

divisors = sorted(divisors,reverse = True)

for d in divisors:
  mods = [0] * (N)
  for i in range(len(A)):
    mods[i] = A[i] % d
  mods = sorted(mods)
  mods_front = [0] * N
  mods_front[0] = mods[0]
  for i in range(1,N):
    mods_front[i] = mods_front[i - 1] + mods[i]
  mods_back = [0] * N
  mods_back[-1] = d - mods[-1]
  for i in range(N - 2,-1,-1):
    mods_back[i] = mods_back[i + 1] + (d - mods[i])
  for i in range(N - 1):
    if mods_front[i] == mods_back[i + 1]:
      if K >= mods_front[i]:
        print(d)
        return
else:
  print(1)

n, k = map(int, input().split())
a = list(map(int, input().split()))

def ok(d):
    m = sorted(a % d for a in a)
    s, e, plus, minus = 0, len(m) - 1, 0, 0
    while True:
        if s > e:
            return (plus == minus)
        if plus <= minus:
            plus += m[s]
            if plus > k:
                return False
            s += 1
        else:
            minus += d - m[e]
            if minus > k:
                return False
            e -= 1
    return False

b = sum(a)
ret = 1
d = 1
while d * d <= b:
    if b % d == 0:
        if ok(d):
            ret = max(ret, d)
        if ok(b // d):
            ret = max(ret, b //d)
    d += 1
print(ret)

import numpy as np


# 約数の列挙
def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    divisors.sort()
    return divisors


N, K, *A = map(int, open(0).read().split())

A = np.array(A, np.int64)
d = make_divisors(A.sum())

for i in d[::-1]:
    r = A % i
    r.sort()
    r = r[r != 0]
    if r.size == 0:
        print(i)
        return
    else:
        n = np.arange(r.size - 1, 0, -1)

    np.cumsum(r, out=r)
    equal = np.where(r[:-1] == i * n - (r[-1] - r[:-1]))[0]
    if np.any(r[equal] <= K):
        print(i)
        return

from itertools import accumulate
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
M = sum(A)

# 答えの候補を列挙
ans_candidates = []
for n in range(1, int(M ** 0.5) + 1):
    if M % n == 0:
        ans_candidates.append(n)
        ans_candidates.append(M // n)


ans = 0
for X in ans_candidates:
    A_mod = sorted([a % X for a in A])
    U = [X - a for a in A_mod]
    D = [-a for a in A_mod]  # わかりやすいので

    U = list(accumulate(U))
    D = list(accumulate(D))

    for i in range(N):
        if -D[i] > K:
            break

        if -D[i] == (U[-1] - U[i]):
            ans = max(ans, X)
            break

print(ans)


def get_divisor(num, max_val):
    ret = []
    num_sq = int(num**0.5)
    for k in range(1, num_sq+1):
        if num % k == 0:
            if k <= max_val: ret.append(k)
            if num//k <= max_val: ret.append(num//k)
            
    return ret

# 下からmodが低いのを取ってきてマッチングを取る
def solve():
    N,K = map(int, input().split())
    A = list(map(int, input().split()))
    sum_A = sum(A)
    max_A = max(A)
    div = get_divisor(sum_A, max_A+K)
    ret = 1
    for d in div:
        sum_k = 0
        red_k = 0
        flag = True
        mod_d = [a%d for a in A]
        mod_d.sort()
        # print(d, mod_d)
        for a in mod_d:
            if sum_k+a <= K:
                sum_k += a
            else: 
                red_k += d-a
            if sum_k-red_k < 0:
                break

        if (sum_k-red_k)%d == 0: ret = max(ret, d)
            
    print(ret)
    
solve()

import  numpy as np


def divisors(num):
    array = []
    limit = int(num ** 0.5) + 1
    for i in range(1, limit):
        if num % i == 0:
            div1 = i
            div2 = num//i
            array.append(div1)
            if div1 != div2:
                array.append(div2)
    array.sort(reverse=True)
    return array


n, k = map(int, input().split())
A = np.array(list(map(int, input().split())), dtype=int)

total = sum(A)
candidates = divisors(total)


for div in candidates:
    mods = A % div
    mods.sort()
    add = div - mods

    addcum = np.cumsum(add)
    subcum = np.cumsum(mods)
    for i in range(n):
        addcount = addcum[n-1] - addcum[i]
        subcount = subcum[i]
        if addcount == subcount and addcount <= k:
            print(div)
            return

from math import sqrt
def Divisor_Set(n):
    s = set()
    for i in range(1, int(sqrt(n))+2):
        if n%i == 0:
            s.add(i)
            s.add(n//i)
    return s

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a_sum = sum(a)
    s = Divisor_Set(a_sum)
    ans = 1
    for v in s:
        a_mod = [x%v for x in a]
        a_mod.sort()
        for i in range(1, n):
            a_mod[i] += a_mod[i-1]
        for i in range(n):
            l, r = a_mod[i], v*(n-i-1) - (a_mod[-1] - a_mod[i])
            if l == r and r <= k:
                if ans < v:
                    ans = v
    print(ans)

def __starting_point():
    main()
__starting_point()

from collections import deque
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    def ok(f):
        bb=[a%f for a in aa]
        bb.sort()
        i,j=0,n-1
        s=t=0
        while i<=j:
            if s>t:
                t+=f-bb[j]
                j-=1
            else:
                s+=bb[i]
                i += 1
        return s<=k

    n,k=MI()
    aa=LI()
    s=sum(aa)
    ff=[]
    for d in range(1,s+1):
        if d**2>s:break
        if s%d==0:
            ff.append(d)
            ff.append(s//d)
    if ff[-1]==ff[-2]:ff.pop()
    ff.sort(reverse=True)
    for f in ff:
        if ok(f):
            print(f)
            break

main()

n, k = map(int, input().split())
a = list(map(int, input().split()))
m = sum(a)

def divisor(n):
    ass = []
    for i in range(1, int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            ass.append(n//i)
    return ass
f = divisor(m)
f.sort(reverse=True)

for p in f:
  b = [x%p for x in a]
  b.sort()
  t = 0
  c = n
  for x in b:
    if x + t > k:
      break
    t += x
    c -= 1
  if c*p - sum(b) + t <= k:
    print(p)
    break

def make_divisor_list(n):
    result = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            result.append(i)
            result.append(n // i)
    return result


def calc_min_ops(r, d):
    i, j = 0, len(r)
    while i < j and r[i] == 0:
        i += 1
    i -= 1
    a, b = 0, 0
    while j-i != 1:
        if a <= b:
            i += 1
            a += r[i]
        else:
            j -= 1
            b += d - r[j]
    return a


N, K, *A = list(map(int, open(0).read().split()))

c = sum(A)
divisors = make_divisor_list(c)
divisors.sort(reverse=True)
r = [None] * N

for d in divisors:
    for i in range(N):
        r[i] = A[i] % d
    r.sort()
    if calc_min_ops(r, d) <= K:
        print(d)
        break


def factor(N):
    arr=[]
    for i in range(1,int(N**0.5)+1):
        if(N%i==0):
            arr.append(i)
            if(N//i!=i):
                arr.append(N//i)
    return arr

n,k=map(int,input().split())
a=list(map(int,input().split()))
sum_=sum(a)

fac=sorted(factor(sum_),reverse=True)
ans=1
for x in fac:
    li=sorted(z%x for z in a)
    res=0
    cum=[0]*(n+1)
    for i in range(n):
        cum[i+1]=cum[i]+li[i]
    for i in range(1,n):
        l,r=cum[i],x*(n-i)-(cum[n]-cum[i])
        if l==r and r<=k:
            ans=max(ans,x)
print(ans)

def make_divisors(n: int) -> list:
    """自然数nの約数を列挙したリストを出力する
    計算量: O(sqrt(N))
    入出力例: 12 -> [1, 2, 3, 4, 6, 12]
    """
    divisors = []
    for k in range(1, int(n ** 0.5) + 1):
        if n % k == 0:
            divisors.append(k)
            if k != n // k:
                divisors.append(n // k)
    divisors = sorted(divisors)
    return divisors


def solve(val):
    res = []
    for i in range(n):
        tmp = a[i] % val
        if tmp == 0:
            continue
        res.append(a[i] % val)
    res = sorted(res)
    if not res:
        return True
    l_val = 0
    for i in range(len(res)):
        l_val += res[i]
        if l_val > k:
            l_pos = i - 1
            break
    else:
        return True
    r_val = 0
    for i in range(l_pos + 1, len(res)):
        r_val += val - res[i]
    return r_val <= k
            
      
        
    
n, k = map(int, input().split())
a = list(map(int, input().split()))

sum_a = sum(a)
div = make_divisors(sum_a)
ans = 0
for i in div:
    if solve(i):
        ans = max(ans, i)
print(ans)

n,k=map(int,input().split())
a=[int(x) for x in input().split()]
s=sum(a)

candidates=set()
for i in range(1,int(s**0.5)+1):
  if s%i==0:
    candidates.add(i)
    candidates.add(s//i)

ans=0
for cdd in candidates:
  f=sorted([x%cdd for x in a])
  # calc need
  ans=max(ans,cdd) if sum(f[:-sum(f)//cdd])<=k else ans   
    
print(ans)

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
Asum = sum(A)

div = set()
for i in range(1, int(Asum ** 0.5 + 0.5) + 1):
    if Asum % i == 0:
        div.add(i)
        div.add(Asum//i)

ans = 1
for d in div:
    R = [a % d for a in A]
    R.sort()
    r = sum(R) // d
    l = N - r
    need = sum(R[:l])
    if need <= K:
        ans = max(ans, d)
print(ans)


from itertools import accumulate
from math import floor, sqrt
N, K = map(int,input().split())
A = list(map(int,input().split()))
sm = sum(A)
divs = set()
for i in range(1, floor(sqrt(sm))+1):
    if sm % i == 0:
        divs.add(i)
        divs.add(sm // i)
ans = 1
for d in divs:
    ls = sorted(map(lambda x: x%d, A))
    acc = [0]+list(accumulate(ls, lambda x,y:x+y))
    for i in range(1, N):
        minus = acc[i]-acc[0]
        plus = d*(N-i) - (acc[-1]-acc[i])
        if plus == minus and plus <= K:
            ans = max(ans, d)
print(ans)

def divisors(n):
    i = 1
    table = set()
    while i * i <= n:
        if not n % i:
            table.add(i)
            table.add(n//i)
        i += 1
    table = list(table)
    return table

def binary_search_int(ok, ng, test):
    """
    :param ok: solve(x) = True を必ず満たす点
    :param ng: solve(x) = False を必ず満たす点
    """
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if test(mid):
            ok = mid
        else:
            ng = mid
    return ok

import numpy as np
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
S = sum(A)
D = divisors(S)
D.sort()

def test(x):
    k = D[x]
    B = A%k
    B.sort()
    cnt = sum(B)//k
    return k*cnt - sum(B[-cnt:]) <= K

p = binary_search_int(0,len(D),test)
q = binary_search_int(p+1,len(D),test)
print(max(D[p],D[q]) if q != p+1 else D[p])

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def divisors(n):
    lower = []
    upper = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            lower.append(i)
            if i != n // i:
                upper.append(n // i)

    lower.extend(reversed(upper))
    return lower


def main():
    N, K, *A = list(map(int, read().split()))

    total = sum(A)
    div = divisors(total)

    for d in reversed(div):
        vec = [a % d for a in A]
        vec.sort()

        M = len(vec)
        csum_sub = [0] * (M + 1)
        csum_add = [0] * (M + 1)
        for i in range(M):
            csum_sub[i + 1] = csum_sub[i] + vec[i]
            csum_add[i + 1] = csum_add[i] + d - vec[i]

        for i in range(M + 1):
            if csum_sub[i] <= K and csum_sub[i] == csum_add[M] - csum_add[i]:
                print(d)
                return

    return


def __starting_point():
    main()

__starting_point()

n, k = map(int, input().split())
A = list(map(int, input().split()))
s = sum(A)
def md(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse=True)
    return divisors
P = md(s)
def test(x):
  L = sorted([a%x for a in A])
  M = sum(L)
  c = M//x
  for _ in range(c):
    M -= L.pop()
  return M <= k

for p in P:
  if test(p):
    print(p)
    break

N,K=map(int, input().split())
A=list(map(int, input().split()))

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
  
D=make_divisors(sum(A))
ans=1
for i in D:
  E=[]
  for j in A:
    d=j%i
    if d!=0:
      E.append(d)
  if len(E)==0:
    ans=i
  E=sorted(E)
  cn=0
  e=sum(E)
  left,right=e,0
  #print(i,E)
  for k in range(len(E)):
    left-=E[-1-k]
    right+=(i-E[-1-k])
    if left==right:
      if left<=K:
        ans=i
      break
print(ans)

import numpy as np

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

n, k = map(int,input().split())
a = list(map(int,input().split()))

asum = sum(a)
adiv = make_divisors(asum)
adiv.reverse()

a = np.array(a)
ans = 1
flg = False
for i in adiv:
    a_ = np.sort(a % i)
    # print(i, a_)
    msum = a_.sum()
    msum_ = 0
    for j in range(-1, -n-1, -1):
        msum -= a_[j]
        msum_ += i - a_[j]
        if msum_ > k:
            break
        if msum < msum_:
            break
        if msum == msum_ :
            ans = i
            flg = True
            break
    if flg:
        break

print(ans)

n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
s = sum(a)
dl = []
for i in range(1,int(s**0.5)+1):
    if s%i == 0:
        dl.append(i)
        if i != s//i:
            dl.append(s//i)
dl.sort(reverse = True)

def search(x):
    ml = []
    for i in a:
        ml.append(i%x)
    ml.sort(reverse = True)
    ms = sum(ml)
    count = 0
    i = 0
    while k > count and ms > count:
        mi = x-ml[i]
        if k >= mi:
            count += mi
            ms -= ml[i]
            
        else:
            break
        i += 1

    if k >= count and count == ms:
        return True
    else:
        return False

for i in dl:
    
    if search(i):
        print(i)
        return



n,k=list(map(int,input().split()))
A=list(map(int,input().split()))

s=sum(A)
import math
def yakusu(n):
  ans_local=set()
  for i in range(1,int(math.sqrt(n))+1):
    if n%i==0:
      ans_local = ans_local | set([i,n//i]) #setなので平方数でもOK
  return list(ans_local)  #必要に応じてsort

yaku=sorted(yakusu(s), reverse=1)
#print(yaku)
for mod in yaku:
    B=[i%mod for i in A if i%mod!=0]
    if B==[] : print(mod);return
    if len(B)==1:
        q=B[0]
        if 0<=q<=k or mod-k<=q: print(mod);return
        else:continue
    B.sort()
    r=[B[0]]*len(B)
    for i in range(len(B)-1):
        r[i+1]= r[i]+B[i+1]
    now=float("INF")
    for i in range(1,len(B)): #切り方
        if r[i-1] ==  mod*(len(B)-i)-(r[-1]-r[i-1]) and r[i-1]<=k:
            print(mod);return

    


from math import sqrt
from itertools import accumulate


def common_divisors(x):
    ret = []
    for i in range(1, int(sqrt(x)) + 1):
        if x % i == 0:
            ret.append(i)
            ret.append(x // i)

    return ret


n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

sm = sum(a)
cd = common_divisors(sm)

ans = 1
for ecd in cd:
    r = [e % ecd for e in a]
    r.sort()
    acc = [0] + list(accumulate(r))
    for i in range(1, n + 1):
        sub = acc[i-1]
        add = ecd * (n - i + 1) - (acc[n] - acc[i-1])
        if sub == add:
            if sub <= k:
                ans = max(ans, ecd)

print(ans)


import  numpy as np


def divisors(num):
    array = []
    limit = int(num ** 0.5) + 1
    for i in range(1, limit):
        if num % i == 0:
            div1 = i
            div2 = num//i
            array.append(div1)
            if div1 != div2:
                array.append(div2)
    array.sort(reverse=True)
    return array


n, k = map(int, input().split())
A = np.array(list(map(int, input().split())), dtype=int)

total = sum(A)
candidates = divisors(total)


for div in candidates:
    mods = A % div
    mods.sort()
    subcum = np.cumsum(mods)
    idx = subcum[n-1] // div
    count = subcum[-1-idx]
    if count <= k:
        print(div)
        return

from math import sqrt
from itertools import accumulate


def common_divisors(x):
    ret = []
    for i in range(1, int(sqrt(x)) + 1):
        if x % i == 0:
            ret.append(i)
            ret.append(x // i)

    return ret


n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

sm = sum(a)
cd = common_divisors(sm)

ans = 0
for ecd in cd:
    r = [e % ecd for e in a]
    r.sort()
    sub = [0] + list(accumulate(r))
    add = [0] + list(accumulate(ecd - e for e in r[::-1]))
    add = add[::-1]
    for sb, ad in zip(sub, add):
        if sb == ad and sb <= k:
            ans = max(ans, ecd)

print(ans)


from math import sqrt
from itertools import accumulate


def common_divisors(x):
    ret = []
    for i in range(1, int(sqrt(x)) + 1):
        if x % i == 0:
            ret.append(i)
            ret.append(x // i)

    return ret


n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

sm = sum(a)
cd = common_divisors(sm)

ans = 1
for ecd in cd:
    r = [e % ecd for e in a]
    r.sort()
    sub = [0] + list(accumulate(r))
    add = [0] + list(accumulate(ecd - e for e in r[::-1]))
    add = add[::-1]
    for sb, ad in zip(sub, add):
        if sb == ad and sb <= k:
            ans = max(ans, ecd)

print(ans)


from math import sqrt
from bisect import bisect_left

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    sum_a = sum(a)
    st = set()
    for v in range(1, int(sqrt(sum_a))+2):
        if sum_a % v == 0:
            st.add(v)
            st.add(sum_a//v)
    st.remove(1)
    ans = 1
    for target in st:
        a_mod_t = [v % target for v in a]
        a_mod_t.sort()
        for i in range(n-1):
            a_mod_t[i+1] += a_mod_t[i]
        for i in range(n):
            sum_L, sum_R = a_mod_t[i], a_mod_t[-1] - a_mod_t[i]
            len_L, len_R = i+1, n-i-1
            if sum_L == target * len_R - sum_R:
                if sum_L <= k:
                    if ans < target:
                        ans = target
    print(ans)

def __starting_point():
    main()
__starting_point()

N, K = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
max_div = int(S**0.5)

# Sの約数を列挙する
small_div = []
large_div = []
for i in range(1, max_div+1):
  if S%i == 0:
    small_div.append(i)
    large_div.append(S//i)

# 約数を降順に並べる
div = large_div + small_div[::-1]

ans = 1
for d in div:
  r = []
  for a in A:
    r.append(a%d)
  
  r.sort()
  # (d-ri)足すか、ri引くか、それぞれ累積和を求めておく
  minus = [0]*(N+1)
  plus = [0]*(N+1)
  for i, ri in enumerate(r, 1):
    minus[i] = minus[i-1] + ri
  
  for i, ri in enumerate(r[::-1], 1):
    plus[i] = plus[i-1] + (d - ri)
  
  plus = plus[::-1]
  for m, p in zip(minus, plus):
    if m == p and m <= K:
      ans = d
      break
  
  else:
    continue
  
  break

print(ans)

import numpy as np


# 約数の列挙
def make_divisors(n):
    divisors = set()
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.add(i)
            divisors.add(n // i)
    return sorted(list(divisors))


N, K, *A = list(map(int, open(0).read().split()))

A = np.array(A, np.int64)
d = make_divisors(A.sum())

for i in d[::-1]:
    r = A % i
    r = r[r.nonzero()]
    l = r.size
    if l == 0:
        print(i)
        return
    else:
        n = np.arange(l - 1, 0, -1)
    r.sort()
    np.cumsum(r, out=r)
    if np.any((r[:-1] == i * n - (r[-1] - r[:-1])) & (r[:-1] <= K)):
        print(i)
        return


def main():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    m = sum(A)
    d = []
    for i in range(1, int(m**0.5)+1):
        if m % i == 0:
            d.append(i)
            if i != m // i:
                d.append(m//i)
    d.sort(reverse=True)
    for j in d:
        if j > K + max(A):
            continue
        l = []
        for i in A:
            l.append(i % j)
        t = N - sum(l) // j
        l.sort()
        if sum(l[:t]) <= K:
            print(j)
            return
    print((1))
main()


import heapq

def divisor(i):
    s = []
    for j in range(1, int(i ** (1 / 2)) + 1):
        if i % j == 0:
            s.append(i // j)
            s.append(j)
    return sorted(set(s))

n, k = map(int, input().split())
a = list(map(int, input().split()))
suma = sum(a)
s = divisor(suma)
for i in range(1, len(s) + 1):
    x = s[-i]
    y = suma // x
    h = []
    heapq.heapify(h)
    for j in a:
        y -= j // x
        heapq.heappush(h, -(j % x))
    cnt = 0
    for _ in range(y):
        cnt += (heapq.heappop(h) % x)
    if cnt <= k:
        print(x)
        return

import sys

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    sumA = sum(A)
    D = []
    for i in range(1, sumA + 1):
        if i ** 2 > sumA: break
        if sumA % i == 0:
            D.append(i)
            if i ** 2 != sumA: D.append(sumA // i)
    D.sort(reverse = True)
    for i, d in enumerate(D):
        L = []
        count = 0
        for a in A:
            if a % d > 0: 
                L.append(a % d)
                count += 1
        L.sort()
        if count > 0:
            minus, plus = [0] * count, [0] * count
            minus[0] = L[0]
            plus[count - 1] = d - L[count - 1]
            for i in range(1, count):
                minus[i] = minus[i-1] + L[i]
                plus[count - 1 - i] = plus[count - i] +  d - L[count - 1 - i]
            Op = K + 1
            for i in range(count - 1):
                if abs(minus[i] - plus[i + 1]) % d == 0: Op = min(Op, max(minus[i], plus[i + 1]))
            if Op <= K:
                print(d)
                break
    else: print(1)

    return 0

def __starting_point():
    solve()
__starting_point()

n,k=map(int,input().split())
a=[int(x) for x in input().split()]
s=sum(a)

candidates=set()
for i in range(1,int(s**0.5)+1):
  if s%i==0:
    candidates.add(i)
    candidates.add(s//i)

ans=0
for cdd in candidates:
  div_cdd=[0]*n
  for i in range(n):
    div_cdd[i]=a[i]%cdd
  div_cdd=sorted(div_cdd)
  pstv,ngtv=0,-sum(div_cdd)
  # calc need
  if pstv==-ngtv:
    ans=max(ans,cdd)
    continue
  for i in range(n):
    pstv+=cdd-div_cdd[-1-i]
    ngtv+=div_cdd[-1-i]
    if pstv==-ngtv: break
  ans=max(ans,cdd) if pstv<=k else ans
    
print(ans)

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

# 約数列挙
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

ans = 1

for div in make_divisors(sum(a)):
    mod_div = []
    for ai in a:
        mod_div.append(ai % div)
    mod_div.sort()

    tmp_p = n * div - sum(mod_div)
    tmp_m = 0

    for i, x in enumerate(mod_div):
        tmp_m += x
        tmp_p -= div - x
        if tmp_m == tmp_p and tmp_m <= k:
            ans = max(div, ans)

print(ans)


from itertools import accumulate
n,k = map(int,input().split())
a = list(map(int,input().split()))
suma = sum(a)
devisor = []
for i in range(1,int(suma**0.5)+1):
  if suma%i == 0:
    devisor.extend((i,suma//i))
devisor.sort(reverse=True)
for x in devisor:
  b = [a[i]%x for i in range(n)]
  b.sort()
  sumb = list(accumulate(b))
  for y in range(n-1):
    bf = sumb[y]
    bl = sumb[n-1]-sumb[y]
    if bf%x == (x-(bl%x))%x:
      if k>=max(bf,(n-1-y)*x-bl):
        print(x)
        return
      else:
        continue

N,K = map(int,input().split())
A = list(map(int,input().split()))

S = sum(A)
ans = 0

for i in range(1,int(S**0.5)+1):
    if S%i != 0:
        continue
        
    for j in range(2):
        d = i if j else S//i
        B = sorted(map(lambda a:a%d,A))
        C = [0]
        for k in range(N):
            C.append(C[-1]+B[k])
            
        for k in range(N+1):
            if ((N-k)*d-(C[-1]-C[k])-C[k])%d == 0:
                if max(C[k],(N-k)*d-(C[-1]-C[k])) <= K:
                    ans = max(ans,d)
                    
print(ans)

INF = float("inf")
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

def get_divisors(num):
    f_divs, l_divs = [], []
    for i in range(1, int(num**0.5)+1):
        if not num % i:
            f_divs.append(i)
            if i != num // i:
                l_divs.append(num // i)
    return f_divs + l_divs[::-1]

divs = get_divisors(sum(a))
ans = 1

def evl(d):
    rem = [x % d for x in a]
    rem.sort()
    s = sum(rem)
    c = 0
    for i, x in enumerate(rem):
        c += x
        if c == d*(n-i-1) - (s-c):
            return c <= k
    return False

for d in divs[::-1]:
    if evl(d):
        print(d)
        break


import numpy as np

def divisor(x):
    div = []
    for i in range(1,int(x**0.5)+1):
        if x%i == 0:
            div.append(i)
            if x != i**2: div.append(x//i)    
    return div


def mincount(a,x):
    
    minus = np.sort(a%x)
    adj_sum = minus.sum()    
    convert = adj_sum//x
    
    return adj_sum - minus[-convert:].sum()


N,K = map(int,input().split())
A = np.array(list(map(int,input().split())))

div = divisor(A.sum())
div.sort(reverse=True)

for d in div:
    if mincount(A,d)<=K:
        print(d)
        break

# https://betrue12.hateblo.jp/entry/2020/03/28/142051

def main():
    N, K = list(map(int, input().split()))
    *A, = list(map(int, input().split()))

    def divisor_generator(n):
        div = 1

        stock = []
        while div * div <= n:
            if n % div == 0:
                yield n // div
                stock.append(div)
            div += 1

        for div in reversed(stock):
            yield div

    tot = sum(A)
    for div in divisor_generator(tot):
        k = tot // div - sum(a // div for a in A)
        R = sorted(a % div for a in A)
        Rc = [div - r for r in R]

        cond = (sr := sum(r for r in R[:N - k])) == sum(r for r in Rc[N - k:]) and sr <= K
        if cond:
            print(div)
            return


def __starting_point():
    main()

__starting_point()

from itertools import accumulate

def divisors(n):
    lst = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            lst.append(i)
            if i != n // i: lst.append(n // i)
    return lst

N, K = map(int, input().split())
*A, = map(int, input().split())
cands = divisors(sum(A))
for d in sorted(cands, reverse=True):
    rems = sorted([a % d for a in A])
    cumsum_rems = [0] + list(accumulate(rems))
    for i in range(1, N):
        minus = cumsum_rems[i]
        plus = d * (N - i) - (cumsum_rems[N] - minus)
        if max(minus, plus) <= K: break
    else:
        continue
    break
print(d)

import  numpy as np


def divisors(num):
    array = []
    limit = int(num ** 0.5) + 1
    for i in range(1, limit):
        if num % i == 0:
            div1 = i
            div2 = num//i
            array.append(div1)
            if div1 != div2:
                array.append(div2)
    array.sort(reverse=True)
    return array


n, k = map(int, input().split())
A = np.array(list(map(int, input().split())), dtype=int)

total = sum(A)
candidates = divisors(total)


for div in candidates:
    mods = A % div
    mods.sort()
    np.cumsum(mods, out=mods)
    idx = mods[n-1] // div
    count = mods[-1-idx]
    if count <= k:
        print(div)
        return

def max2(x,y):
    return x if x > y else y

def divisors(n):
    i = 1
    table = set()
    while i * i <= n:
        if not n % i:
            table.add(i)
            table.add(n//i)
        i += 1
    table = list(table)
    return table

import numpy as np
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
S = sum(A)
D = divisors(S)
D.sort()
res = 0
for k in D:
    B = A%k
    B.sort()
    cnt = sum(B)//k
    if k*cnt - sum(B[-cnt:]) <= K:
        res = max2(res, k)

print(res)

import numpy as np

def getDivisor(n):
    divisor = []
    tmp = n
    for i in range(2, int(n**0.5)+1):
        cnt = 1
        d = [1,]
        while tmp%i == 0:
            d.append(i**cnt)
            tmp //= i
            cnt += 1
        if cnt > 1:
            divisor.append(d)
    if tmp != 1:
        divisor.append([1,tmp])
    if divisor == []:
        divisor.append([1,n])
        
    divisor_mat = np.matrix(1) 
    for d in divisor:
        d = np.matrix(d)
        mat = []
        for dcol in divisor_mat:
            mat.append(dcol.T * d)
        divisor_mat = np.concatenate(mat)
    divisor_mat = np.array(divisor_mat.flatten())
    divisor_mat = np.array(divisor_mat[0].tolist())
    divisor_mat.sort()
    return divisor_mat

n, k = map(int, input().split())
a = list(map(int, input().split()))

a = np.array(a)
sum_a = a.sum()
divisor = getDivisor(sum_a)
for d in divisor[::-1]:
  tmp = a % d
  idx = tmp.sum() // d
  tmp.sort()
  num_op = tmp[:-idx].sum()
  if num_op <= k:
    break
print(d)

def main():
    N, K = list(map(int, input().split(' ')))
    A = list(map(int, input().split(' ')))
    # Calculate divisors of sum(A)
    S = sum(A)
    divs = list()
    n = 1
    while n ** 2 <= S:
        if S % n == 0:
            m = S // n
            if n != m:
                divs.extend([n, m])
            else:
                divs.append(n)
        n += 1
    divs.sort(reverse=True)
    # calc answer
    ans = S
    for d in divs:
        B = [a % d for a in A]
        B.sort(reverse=True)
        t = sum(B) // d
        k = sum(B) - sum(B[:t])
        if d == 1:
            k = 0
        if k <= K:
            ans = d
            break
    print(ans)


def __starting_point():
    main()
__starting_point()

import sys
import numpy as np
input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort(reverse=True)
    return divisors

def main():
    n, k = map(int, input().split())
    a = np.array([int(x) for x in input().split()])
    key = make_divisors(np.sum(a))
    
    for v in key:
        mod = np.sort(a%v)
        c1, c2 = 0, np.sum(mod)
        judge = c2
        for i in range(n-1, -1, -1):
            c1 += v-mod[i]
            c2 -= mod[i]
            judge = min(judge, max(c1, c2))
        if judge <= k:
            print(v)
            return
    
    
def __starting_point():
    main()
__starting_point()

n,k=map(int,input().split())
a=[int(x) for x in input().split()]
s=sum(a)

candidates=set()
for i in range(1,int(s**0.5)+2):
  if s%i==0:
    candidates.add(i)
    candidates.add(s//i)

ans=0
for cdd in candidates:
  div_cdd=[0]*n
  for i in range(n):
    div_cdd[i]=a[i]%cdd
  div_cdd=sorted(div_cdd)
  pstv,ngtv=0,-sum(div_cdd)
  # calc need
  if pstv==-ngtv:
    ans=max(ans,cdd)
    continue
  for i in range(n):
    pstv+=cdd-div_cdd[-1-i]
    ngtv+=div_cdd[-1-i]
    if pstv==-ngtv: break
  ans=max(ans,cdd) if pstv<=k else ans
    
print(ans)

def yakusu(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
N,K=map(int,input().split())
L=list(map(int,input().split()))
a=sum(L)
R=yakusu(a)[::-1]
for i in range(len(R)):
  add=0
  minus=0
  s=R[i]
  A=list()
  B=list()
  for j in range(N):
    k=L[j]
    a=k%s
    b=s-a
    if a>b:
      add+=b
      B.append(b)
    elif a<b:
      minus+=a
      A.append(a)
    else:
      add+=a
      B.append(a)
  #足した分=add else:minus どっちでも:even
  A=sorted(A)
  B=sorted(B)
  if minus==add:
    d=minus
    if d<=K:
      print(s)
      return
  elif minus>add:
    q=(minus-add)//s
    d=sum(A[:len(A)-q])
    if d<=K:
      print(s)
      return
  else:
    q=(add-minus)//s
    d=sum(B[:len(B)-q])
    if d<=K:
      print(s)
      return

import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

N,K = list(map(int,input().split()))
A = list(map(int,input().split()))

def is_divide(d):
    Rs = [a%d for a in A]
    Rs.sort()
    cumsum = [0] * (N + 1)
    for i in range(N - 1,-1,-1):
        cumsum[i] = cumsum[i + 1] + d - Rs[i]
    cum = 0
    for i in range(N):
        if max(cum,cumsum[i]) <= K:
            return True
        cum += Rs[i]
    return False

S = sum(A)
ans = 0
for i in range(1,S + 1):
    if i*i > S:
        break
    if S%i == 0:
        if is_divide(i):
            ans = max(ans,i)
        if is_divide(S//i):
            ans = max(ans,S//i)
print(ans)


N, K = map(int, input().split())
*A, = map(int, input().split())
A.sort()

S = sum(A)
candidates = []
for i in range(1, int(S**0.5)+1):
    if S%i:continue
    a, b = i, S//i
    
    candidates.append(a)
    if a!=b:
        candidates.append(b)
candidates.sort()

ans = 0
for d in candidates:
    rems = []
    rems_size, rems_sum = 0, 0

    for i in A:
        if i%d:
            rems.append(i%d)
            rems_size += 1
            rems_sum += i%d

    rems.sort()

    a = 0
    for i, j in enumerate(rems[:-1], start=1):
        a += j
        b = d*(rems_size-i)-(rems_sum-a)
        if max(a, b)<=K:
            ans = max(ans, d)
    if not rems:
        ans = max(ans, d)

print(ans)

import heapq
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

x = sum(a)
search = []
i = 1
while i ** 2 <= x:
    if x % i == 0:
        heapq.heappush(search, -i)
        heapq.heappush(search, -x//i)
    i += 1

while search:
    ans = -heapq.heappop(search)
    u = [a[i] % ans for i in range(n)]
    u.sort()

    plus = [0]
    minus = [0]
    for i in range(n):
        plus.append(plus[-1] + ans - u[i])
        minus.append(minus[-1] + u[i])

    for i in reversed(list(range(n+1))):
        # print(i)
        m = minus[i]
        p = plus[-1] - plus[i]
        if m == p and m <= k:
            print(ans)
            return



def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
l = make_divisors(s)
l.sort(reverse=True)
for i in l:
    l2 = [j % i for j in a]
    l2.sort(reverse=True)
    m = sum(l2) - sum(l2[:sum(l2)//i])
    if i == 1:
        m = 0
    if m <= k:
        s = i
        break
print(s)

N, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]

def yaku(N):
    res = []
    for i in range(1, round(N**(1/2)) + 3 ):
        if N%i == 0:
            res.append(i)

    res2 = [N//i for i in res]
    res = list(set(res + res2))
    return res

ys = yaku(sum(A))
ys.sort(reverse=True)
for y in ys:
    M = [a%y for a in A if a%y]
    ma = 0
    mi = y*len(M) - sum(M)
    M.sort()
    for m in M:
        ma += m
        mi -= (y - m)
        if ma == mi:
            break
    if ma <= K:
        print(y)
        return


import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N,K=LI()
AS=LI()
SUMM= sum(AS)

DIVS=set()
for i in range(1,40000):
    if SUMM % i == 0:
        DIVS.add(i)
        DIVS.add(SUMM//i)
# print(DIVS)

DIFF=[0]*N

res = 0
for div in DIVS:
    for i in range(N):
        DIFF[i] = AS[i]%div
    DIFF.sort()
    i = 0
    j = N-1
    sm = 0
    cost = 0
    while i <= j:
        if sm + DIFF[j] >= div:
            sm -= (div - DIFF[j])
            j -= 1
        else:
            cost += DIFF[i]
            sm += DIFF[i]
            i += 1
    # print("div:{} sum: {} cost: {}".format(div, sm, cost))
    if cost <= K: res = max(res, div)

# print(DIFF)
print(res)


def main():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    m = sum(A)
    d = []
    for i in range(1, int(m**0.5)+1):
        if m % i == 0:
            d.append(i)
            if i != m // i:
                d.append(m//i)
    d.sort(reverse=True)
    for j in d:
        if j > K + max(A):
            continue
        l = []
        for i in A:
            l.append(i % j)
        t = N - sum(l) // j
        l.sort()
        if sum(l[:t]) <= K:
            print(j)
            return
    print((1))
main()


import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def make_divisors(n): # nの約数を列挙
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort(reverse=True)
    return divisors

# 全ての合計の約数が答えの候補、上から可能かどうか見ていく
N, K = lr()
A = np.array(lr())
total = A.sum()
D = make_divisors(total) # 降順
for d in D:
    B = A % d   
    B.sort()
    inc = d - B
    B_cum = B.cumsum()
    inc_cum = inc.cumsum()
    for i in range(N):
        x = B_cum[i]
        y = inc_cum[N-1] - inc_cum[i]
        if x > K or y > K:
            continue
        if (x+y) // 2 <= K:
            print(d); return


import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())

def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SI(): return input().split()

def printlist(lst, k='\n'): print((k.join(list(map(str, lst)))))
INF = float('inf')

from math import ceil, floor, log2
from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product
from heapq import heapify, heappop, heappush


def solve():
    n, k = MI()
    A = LI()
    sm = sum(A)

    div = []
    for i in range(1, int(pow(sm, 0.5))+1):
        if sm % i: continue
        div.append(i)
        if i != sm //i:
            div.append(sm // i)
    ans = 1
    for d in div:
        R = [a % d for a in A]
        R.sort()
        plus = 0
        minus = 0
        for r in R:
            plus += d - r
        for r in R:
            minus += r
            plus -= d - r
            if minus == plus and plus <= k:
                ans = max(ans, d)
    print(ans)



def __starting_point():
    solve()

__starting_point()

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return a // gcd(a, b) * b

def isPrime(x):
    if x < 2 or x % 2 == 0:
        return False
    if x == 2:
        return True
    i = 3
    while i * i <= x:
        if x % i == 0:
            return False
        i += 2
    return True

def divisor(x):
    res = []
    i = 1
    while i * i <= x:
        if x % i == 0:
            res.append(i)
            if i * i != x:
                res.append(x // i)
        i += 1
    res = sorted(res)
    return res

def factor(x):
    res = []
    if x == 1:
        res.push_back(1)
        return res
    i = 2
    while i * i <= x:
        while x % i == 0:
            res.append(i)
            x //= i
    if x != 1:
        res.append(x)
    res = sorted(res)
    return res

        


def __starting_point():
    N,K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    A = sorted(A)
    sum_v = sum(A)
    div = divisor(sum_v)
    div = sorted(div, reverse=True)
    for e in div:
        ok = True
        b = [int(a % e) for a in A]
        b = sorted(b)
        v = sum(b)
        v //= e
        ans = 0
        for i in range(N-v):
            ans += b[i]
        
        if ans <= K:
            print(e)
            return

__starting_point()

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
S = sum(A)

def canMake(n):
    B = [a % n for a in A]
    B.sort()

    left = 0
    right = sum(B)
    for i, b in enumerate(B, start=1):
        left += b
        right -= b
        if left == n * (N - i) - right:
            return left <= K
    return False

ans = 1
for i in range(1, int(S**0.5) + 100):
    if S % i != 0:
        continue
    k = S // i

    if canMake(i):
        ans = max(ans, i)
    if canMake(k):
        ans = max(ans, k)
        break

print(ans)


#  --*-coding:utf-8-*--

import math



def main():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))

    s = sum(A)

    D1 = []
    D2 = []

    for i in range(1, int(math.sqrt(s))+1):
        if s%i == 0:
            D1.append(s//i)
            D2.append(i)

    for d in D1 + list(reversed(D2)):
        B = sorted([a%d for a in A])
        x = sum(B[:-sum(B)//d])
        
        if x <= K:
            print(d)
            return

main()


N, K = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)

def isOk(n):
    B = [a % n for a in A]
    B.sort()

    now = 0
    S = sum(B)
    for i, b in enumerate(B[: -1]):
        now += b
        S -= b
        if now == n * (N - i - 1) - S and now <= K:
            return True
    return False

ans = 1
for i in range(1, int(S**0.5) + 100):
    if S % i != 0:
        continue
    j = S // i

    if isOk(i):
        ans = max(ans, i)
    if isOk(j):
        ans = max(ans, j)

print(ans)

import numpy as np

N, K = list(map(int, input().split()))
As_lis = list(map(int, input().split()))

As_arr = np.array(As_lis)
S = np.sum(As_arr)

smaller_factors = []
larger_factors = []
for i in range(1, int(S ** 0.5) + 1):
    if S % i == 0:
        smaller_factors.append(i)
        larger_factors.append(S // i)

for fac in larger_factors:
    mods = As_arr % fac
    k = np.sum(np.sort(mods)[:N - np.sum(mods) // fac])
    if k <= K:
        print(fac)
        return

for fac in reversed(smaller_factors):
    mods = As_arr % fac
    k = np.sum(np.sort(mods)[:N - np.sum(mods) // fac])
    if k <= K:
        print(fac)
        return



def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

N, K = map(int,input().split())
A = list(map(int,input().split()))
S = sum(A)
L = make_divisors(S)
ans = 0
for i in L:
    D = []
    for a in A:
        if a % i != 0:
            D.append(a % i)
    D.sort()
    L1 = [0]
    L2 = [0]
    for j in range(len(D)):
        L1.append(L1[-1] + D[j])
        L2.append(L2[-1] + i - D[len(D)-1-j])
    L2.reverse()
    
    for j in range(len(D)+1):
        if K >= max(L1[j], L2[j]):
            ans = max(ans, i)

print(ans)

N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
def divisor_all(n): # 約数全列挙
    l = [1,n]
    for i in range(2,int(pow(n,1/2))+1):
        if n % i == 0:
            if i == n//i:
                l.append(i)
            else:
                l.append(i)
                l.append(n//i)
    l.sort(reverse=True)
    return l # list
D = divisor_all(sum(A))
def accumulater1D(A): # B:list[int]
    B = [0]*len(A)
    B[0] = A[0]
    for i in range(1,len(B)):
        B[i] = B[i-1]+A[i]
    return B # Aの1次元累積和
import bisect
ans = 0

for d in D:
    R = [A[i]%d for i in range(N) if A[i]%d!=0]
    nr = len(R)
    
    R.sort()
    if len(R)==0:
        ans = d
        break
    LR = accumulater1D(R)
    RR = list(reversed(accumulater1D([d-R[nr-1-i] for i in range(nr)])))
    
    for i in range(nr-1):
        if LR[i]==RR[i+1]:
            if LR[i]<=K:
                ans = d
                break
    if ans != 0:
        break
print(ans)





import numpy as np


# 約数の列挙
def make_divisors(n):
    divisors = set()
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.add(i)
            divisors.add(n // i)
    return sorted(list(divisors))


N, K, *A = list(map(int, open(0).read().split()))

A = np.array(A, np.int64)
d = make_divisors(A.sum())

for i in d[::-1]:
    r = A % i
    r = r[r != 0]
    l = r.size
    if l == 0:
        print(i)
        return
    else:
        n = np.arange(l - 1, 0, -1)
    r.sort()
    np.cumsum(r, out=r)
    if np.any((r[:-1] == i * n - (r[-1] - r[:-1])) & (r[:-1] <= K)):
        print(i)
        return


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,k = LI()
    a = LI()
    s = sum(a)
    dv = set([1,s])
    for i in range(2,int(s**0.5)+5):
        if s%i == 0:
            dv.add(i)
            dv.add(s//i)

    def f(i):
        pm = []
        for c in a:
            t = c % i
            if t == 0:
                continue
            pm.append((i-t, t))
        pm.sort()
        p = pi = m = 0
        mi = len(pm) - 1
        while pi <= mi:
            if p < m:
                p += pm[pi][0]
                pi += 1
            else:
                m += pm[mi][1]
                mi -= 1
        return max(p,m) <= k

    r = 1
    for c in dv:
        if f(c):
            if r < c:
                r = c

    return r


print(main())





n,k=map(int,input().split())
a=list(map(int,input().split()))
m=sum(a)
cd=set(())
for i in range(1,int(m**0.5)+2):
  if m%i==0:
    cd.add(i)
    cd.add(m//i)
cd=list(cd)
cd.sort(reverse=True)
def func(x):
  r=[ai%x for ai in a]
  r.sort()
  tmp=0
  sr=[0]
  for ri in r:
    tmp+=ri
    sr.append(tmp)
  for i in range(n+1):
    tmp0=sr[i]
    tmp1=(n-i)*x-(sr[-1]-sr[i])
    if tmp0==tmp1 and tmp0<=k:
      return True
  return False


for x in cd:
  if x==1:
    print(1)
    return
  if func(x):
    print(x)
    return

from collections import deque
def isok(x):
    que=deque(sorted(z%x for z in a))
    res=0
    while que:
        l=que[0]
        if l==0:
            que.popleft()
            continue
        r=que[-1]
        if r==0:
            que.pop()
            continue
        d=min(l,x-r)
        que[0]-=d
        que[-1]=(que[-1]+d)%x
        res+=d
    return res
        
def factor(N):
    arr=[]
    for i in range(1,int(N**0.5)+1):
        if(N%i==0):
            arr.append(i)
            if(N//i!=i):
                arr.append(N//i)
    return arr

n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
sum_=sum(a)

fac=sorted(factor(sum_),reverse=True)
ans=1
for x in fac:
    c=isok(x)
    if c<=k:
        ans=x
        break
print(ans)


def make_divisors(n):
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            yield i
            if i != n // i:
                yield n // i


N, K = list(map(int, input().split()))
A = tuple(map(int, input().split()))

divisors = list(make_divisors(sum(A)))
divisors.sort(reverse=True)

for divisor in divisors:
    M = [a % divisor for a in A]
    M.sort(reverse=True)
    # divisorで割った余が大きい方に貪欲に+1していく
    if sum(M[sum(M) // divisor:]) <= K:
        print(divisor)
        return


# 解説AC
from collections import deque

def check(d:int):
    """ K回以下の操作でAがdの倍数となるか判定する """
    mod = deque(sorted([a % d for a in A if (a % d != 0)]))

    ans = 0
    while mod:
        modmin = mod.popleft() # modの最小値

        # modmin -> 0 を考える
        ans += modmin
        while modmin:
            if not mod: return False # modmin -> 0 にできない
            modmax = mod.pop()
            sub = d - modmax # modmax -> d にする操作回数
            if sub <= modmin:
                # modmin -> 0 の方が操作回数が必要な場合
                modmin -= sub
            else:
                # modmax -> d の方が操作回数が必要な場合
                # (※ modmax > d となることはない)
                modmax += modmin
                if modmax % d != 0:
                    mod.append(modmax)
                modmin = 0
    
    return True if (ans <= K) else False
    

def make_divisors(n:int):
    """ nの約数を昇順で列挙 """
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

###############################
N,K = map(int, input().split())
A = [int(i) for i in input().split()]

sumA_divisors = make_divisors(sum(A))

ans = 0
for d in sumA_divisors:
    if check(d):
        ans = d

print(ans)

# 割り切る数は、Aの総和の約数である
# 約数について大きい順にすべて試して、当てはまるものがあれば答え

# 8,20を7の倍数に近づけるとき、
# 8 -> mod 7が1であり、-1か+6で7の倍数になる
# 20 -> mod 7が6であり、-6か+1で7の倍数になる
# 負の和と正の和が一致したとき、そのときの絶対値が答え
# 1,1,2,3,4,5と並べて、前から足していくのが最善。入れ替えると絶対値が増加するので損しかしない

import sys
readline = sys.stdin.readline

N,K = list(map(int,readline().split()))
A = list(map(int,readline().split()))

all = sum(A)
divisors = []
for i in range(1,int(all ** 0.5) + 1):
  if all % i == 0:
    divisors.append(i)
    divisors.append(all // i)

divisors = sorted(divisors,reverse = True)

for d in divisors:
  mods = [0] * (N)
  for i in range(len(A)):
    mods[i] = A[i] % d
  mods = sorted(mods)
  mods_front = [0] * N
  mods_front[0] = mods[0]
  for i in range(1,N):
    mods_front[i] = mods_front[i - 1] + mods[i]
  mods_back = [0] * N
  mods_back[-1] = d - mods[-1]
  for i in range(N - 2,-1,-1):
    mods_back[i] = mods_back[i + 1] + (d - mods[i])
  for i in range(N - 1):
    if mods_front[i] == mods_back[i + 1]:
      if K >= mods_front[i]:
        print(d)
        return
else:
  print((1))


import numpy as np


# 約数の列挙
def make_divisors(n):
    divisors = set()
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.add(i)
            divisors.add(n // i)
    return sorted(list(divisors))


N, K, *A = map(int, open(0).read().split())

A = np.array(A, np.int64)
d = make_divisors(A.sum())

for i in d[::-1]:
    r = A % i
    r = r[r != 0]
    l = r.size
    if l == 0:
        print(i)
        return
    else:
        n = np.arange(l - 1, 0, -1)
    r.sort()
    np.cumsum(r, out=r)
    equal = np.where(r[:-1] == i * n - (r[-1] - r[:-1]))[0]
    if np.any(r[equal] <= K):
        print(i)
        return

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
Asum = sum(A)

div = set()
for i in range(1, int(Asum ** 0.5 + 0.5) + 1):
    if Asum % i == 0:
        div.add(i)
        div.add(Asum//i)

ans = 1
for d in div:
    now = 10 ** 18
    R = [a % d for a in A]
    R.sort()
    Rsum = sum(d - r for r in R)
    Lsum = 0
    for r in R:
        Lsum += r
        Rsum -= d - r
        now = min(now, max(Lsum, Rsum))

    if now <= K:
        ans = max(ans, d)

print(ans)


def divisor(n):
  ass=[]
  for i in range(1,int(n**0.5)+1):
    if n%i==0:
      ass.append(i)
      if i!=n//i:ass.append(n//i)
  return ass
_,k=map(int,input().split())
a=list(map(int,input().split()))
for ans in sorted(divisor(sum(a)))[::-1]:
  b=[i%ans for i in a if i%ans]
  n=len(b)
  b.sort()
  m=[0]+[i for i in b]
  p=[ans-i for i in b]+[0]
  for i in range(n):
    m[i+1]+=m[i]
    p[-i-2]+=p[-i-1]
  flag=False
  for i in range(n+1):
    if max(m[i],p[i])>k:continue
    if abs(m[i]-p[i])%ans!=0:continue
    flag=True
  if flag:print(ans);return

import sys
from itertools import accumulate
N, K = list(map(int, input().split()))
*A, = list(map(int, input().split()))
S = sum(A)

div_small = []
div_large = []
for p in range(1, int(S**0.5)+1):
    if S % p == 0:
        div_small.append(p)
        if S // p != p:
            div_large.append(S//p)
div_large += div_small[::-1]

for d in div_large:
    R = sorted([a % d for a in A])
    SR = sum(R)
    acc = tuple(accumulate(R))

    for i, l in enumerate(acc):
        r = d*(N-i-1)-(SR-l)
        if l == r:
            if l <= K:
                print(d)
                return
            else:
                break


# 約数の列挙
#############################################################


def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n // i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
#############################################################


N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

sum_A = sum(A)
div_list = make_divisors(sum_A)
ans = 1
# print(div_list)

for div in div_list:
    tmp = []
    for a in A:
        tmp.append(a % div)
    tmp.sort()
    cumsum1 = [0]
    cumsum2 = [0]
    for i in tmp:
        cumsum1.append(cumsum1[-1] + i)
        if i != 0:
            cumsum2.append(cumsum2[-1] + (div - i))
        else:
            cumsum2.append(cumsum2[-1])
    for i in range(1, N):
        if cumsum1[i] <= K and cumsum2[N] - cumsum2[i] <= K:
            ans = div

print(ans)


def divisors(N):
    return sorted(sum((list({n, N // n}) for n in range(1, int(N ** 0.5) + 1) if not N % n), []), reverse=True)
N, K = map(int, input().split())
A = tuple(map(int, input().split()))
D = divisors(sum(A))
for d in D:
    L = sorted(a % d for a in A)
    if not sum(L):
        print(d)
        break
    left, right = 0, N - 1
    count = 0
    while left < right:
        if L[left] + L[right] <= d:
            next_right = right - (L[right] + L[left] == d)
            next_left = left + 1
            L[right] += L[left]
            count += L[left]
            L[left] = 0
        else:
            next_left = left
            next_right = right - 1
            m = d - L[right]
            count += m
            L[right] += m
            L[left] -= m
        left, right = next_left, next_right
    if count <= K:
        print(d)
        break

n, k = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)

cands = []
for x in range(1, int(s ** 0.5) + 1):
    if s % x == 0:
        cands.append(x)
        if x != s // x:
            cands.append(s // x)

cands.sort(reverse=True)
#print(cands)

ans = 0
for cand in cands:
    b = [a[i] % cand for i in range(n)]
    b.sort()
    sb = [0 for _ in range(n+1)]
    for i in range(n):
        sb[i+1] = sb[i] + b[i]
    #print(cand, sb)

    flg = False
    for i in range(n+1):
        x = max(sb[i], cand * (n - i) - (sb[n] - sb[i]))
        #print(i, sb[i], cand * (n - i) - (sb[n] - sb[i]))
        if x <= k:
            flg = True
            break

    if flg:
        print(cand)
        break

import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def make_divisors(n): # nの約数を列挙
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort(reverse=True)
    return divisors

# 全ての合計の約数が答えの候補、上から可能かどうか見ていく
N, K = lr()
A = np.array(lr())
total = A.sum()
D = make_divisors(total) # 降順
for d in D:
    B = A % d   
    B.sort()
    inc = d - B
    B_cum = B.cumsum()
    inc_cum = inc.cumsum()
    for i in range(N):
        x = B_cum[i]
        y = inc_cum[N-1] - inc_cum[i]
        if x > K: # xは単調増加
            break
        if y > K:
            continue
        if (x+y) // 2 <= K:
            print(d); return


import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def make_divisors(n):
    divisors = []
    for i in range(1, int(pow(n, 0.5)) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    divisors.sort()
    return divisors


def resolve():
    n, k = list(map(int, input().split()))
    A = sorted(list(map(int, input().split())))

    div = make_divisors(sum(A))
    res = 1
    for x in div:
        B = sorted([a % x for a in A])
        M, P = [0], [0]
        for i in range(n):
            M.append(M[-1] + B[i])
            P.append(P[-1] + x - B[i])
        M.pop(0)
        P.pop(0)
        for i in range(n - 1):
            m = M[i]
            p = P[n - 1] - P[i]
            if m <= k and p <= k and m % x == p % x:
                res = max(res, x)
    print(res)


def __starting_point():
    resolve()

__starting_point()

import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print((k.join(list(map(str, lst)))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    N, K = MI()
    A = LI()

    M = sum(A)
    divs = []
    for i in range(1, int(pow(M, 0.5))+1):
        if M % i: continue
        divs.append(i)
        if i != M//i: divs.append(M//i)
    divs.sort(reverse=True)

    for d in divs:
        B = list([x%d for x in A])
        B.sort()
        C = list([d-x for x in B])
        # print(d, B, C)
        # print(list(accumulate(B)), list(accumulate(C)))
        Ba = list(accumulate(B))
        Ca = list(accumulate(C))
        for i in range(0, N-1):
            b = Ba[i]
            c = Ca[-1] - Ca[i]
            # print(b, c)
            if b == c and b <= K:
                print(d)
                return
    print((1))


def __starting_point():
    solve()

__starting_point()

n,k = list(map(int,input().split()))
A = list(map(int,input().split()))
S = sum(A)
ans = 1
div = []
for i in range(1,int(S**0.5)+2):
    if S%i == 0:
        if S//i != i:
            div.append(S//i)
            div.append(i)
        else:
            div.append(i)
div.sort()
L = []
for i in range(len(div)):
    cur = div[i]
    mod = []
    for j in range(n):
        if A[j]%cur != 0:
            mod.append(A[j]%cur)
    if len(mod) == 0:
        ans = max(ans, cur)
    else:
        mod.sort()
        mod_dash = []
        for j in range(len(mod)):
            mod_dash.append(cur-mod[j])
        mod2 = [mod[0]]
        mod3 = [mod_dash[0]]
        for j in range(1,len(mod)):
            t = mod2[j-1]+mod[j]
            mod2.append(t)
            u = mod3[j-1]+mod_dash[j]
            mod3.append(u)
        c = 10**10
        for j in range(1,len(mod2)):
            c = min(c, max(mod2[len(mod2)-j-1],mod3[len(mod3)-1]-mod3[len(mod3)-j-1]))
        if c <= k:
            ans = max(ans, cur)
print(ans)


n,k=map(int,input().split())
a=[int(x) for x in input().split()]
s=sum(a)

candidates=set()
for i in range(1,int(s**0.5)+1):
  if s%i==0:
    candidates.add(i)
    candidates.add(s//i)

ans=0
for cdd in candidates:
  div_cdd=[0]*n
  for i in range(n):
    div_cdd[i]=a[i]%cdd
  div_cdd=sorted(div_cdd)
  # calc need
  idx=n-sum(div_cdd)//cdd
  need=0
  for i in range(idx):
    need+=div_cdd[i]
  ans=max(ans,cdd) if need<=k else ans
    
print(ans)

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def divisors(n):
    lower = []
    upper = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            lower.append(i)
            if i != n // i:
                upper.append(n // i)

    lower.extend(reversed(upper))
    return lower


def main():
    N, K, *A = list(map(int, read().split()))

    total = sum(A)
    div = divisors(total)

    for d in reversed(div):
        vec = [a % d for a in A if a % d]
        if not vec:
            print(d)
            return
        vec.sort()
        M = len(vec)
        csum_sub = [0] * (M + 1)
        csum_add = [0] * (M + 1)
        for i in range(M):
            csum_sub[i + 1] = csum_sub[i] + vec[i]
            csum_add[i + 1] = csum_add[i] + d - vec[i]

        for i in range(1, M):
            if csum_sub[i] <= K and csum_sub[i] == csum_add[M] - csum_add[i]:
                print(d)
                return

    return


def __starting_point():
    main()

__starting_point()

def get_divisors(x):
    i = 1
    ret = set()
    while i * i <= x:
        if x % i == 0:
            ret.add(i)
            ret.add(x // i)

        i += 1

    return ret


n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

sm = sum(a)
divs = get_divisors(sm)

ans = 0
for div in divs:
    mods = [e % div for e in a]
    mods.sort()
    p = 0
    m = n * div - sum(mods)
    for mod in mods:
        p += mod
        m -= div - mod
        if p == m:
            if p <= k:
                ans = max(ans, div)
            break

print(ans)


import math

n,k=map(int,input().split())

A=list(map(int,input().split()))

x=sum(A)

X=[]

for i in range(1,int(math.sqrt(x))+1):
    if x%i==0:
        X.append(i)
        X.append(x//i)
X.sort(reverse=True)

for i in X:
    B=[]
    for j in range(n):
        B.append(A[j]%i)
    B.sort()
    if sum(B[:-1*(sum(B)//i)])<=k:
        print(i)
        break

N,K=map(int,input().split())
alist=list(map(int,input().split()))

sum_a=sum(alist)
alist.sort()
#print(sum_a,alist)

#M=1の場合にも対応
divisor_set=set()
for i in range(1,int(sum_a**0.5)+1):
  if sum_a%i==0:
    divisor_set.add(i)
    divisor_set.add(sum_a//i)
divisor_list=list(divisor_set)
divisor_list.sort()
#print(divisor_list)

answer=0
for d in divisor_list:
  rlist=[]
  for a in alist:
    rlist.append((a%d,(d-a%d)%d))
  rlist.sort()
  
  s1list,s2list=[0],[0]
  for r1,r2 in rlist:
    s1list.append(s1list[-1]+r1)
    s2list.append(s2list[-1]+r2)
  #print(d,s1list,s2list)
  
  for i in range(len(rlist)):
    r1sum=s1list[i]
    r2sum=s2list[-1]-s2list[i]
    if r1sum==r2sum and r1sum<=K:
      answer=d
      break
      
print(answer)

from collections import deque
def isok(x):
    que=deque(sorted(z%x for z in a))
    res=0
    while que:
        l=que[0]
        if l==0:
            que.popleft()
            continue
        r=que[-1]
        if r==0:
            que.pop()
            continue
        d=min(l,x-r)
        que[0]-=d
        que[-1]=(que[-1]+d)%x
        res+=d
    return res
        

n,k=map(int,input().split())
a=list(map(int,input().split()))
sum_=sum(a)

fac=set()
for i in range(1,sum_+1):
    if i*i>sum_:
        break
    if sum_%i==0:
        fac.add(i)
        fac.add(sum_//i)

fac=sorted(fac,reverse=True)
ans=1
for x in fac:
    c=isok(x)
    if c<=k:
        ans=x
        break
print(ans)