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

A = [int(c) for c in input().split()]

S = sum(A)

pls = []

for i in range(1,S):

  if i*i>S:

    break

  if S%i==0:

    pls += [i]

    pls += [S//i]

pls.sort(reverse=True)

for p in pls:

    B = []

    for i in range(N):

      B += [A[i]%p]

    B.sort()

    for j in range(N):

      if B[j]!=0:

        break

    m = j

    lim = N-1

    cnt = 0

    while m<lim:

      if B[m]<p-B[-1]:

        B[-1] += B[m]

        cnt += B[m]

        B[m] = 0

        m += 1

      elif B[m]>p-B[-1]:

        cnt += p-B[-1]

        B[m] -= p-B[-1]

        B.pop()

        lim -= 1

      else:

        B.pop()

        cnt += B[m]

        B[m] = 0

        m += 1

        lim -= 1

    if B[-1]==0 and cnt<=K:

      print(p)

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

pls = []

S = sum(A)

for i in range(1,int(S**0.5)+1):

  if S%i==0:

    pls.append(i)

    pls.append(S//i)

pls.sort()

ans = 0

for p in pls:

  B = [a%p for a in A]

  B.sort()

  i = 0

  j = N-1

  cnt = K

  while i<N:

    if B[i]!=0:

      break

    i += 1

  else:

    ans = p

    continue

  while True:

    a = B[i]

    b = B[j]

    if a<p-b:

      if cnt<a:

        break

      B[j] += a

      cnt -= a

      i += 1

    elif a>p-b:

      if cnt<p-b:

        break

      B[i] -= p-b

      cnt -= p-b

      j -= 1

    else:

      if cnt<a:

        break

      cnt -= a

      i += 1

      j -= 1

    if i>=j:

      ans = p

      break

print(ans)
N, K = list(map(int, input().split()))
A = [int(c) for c in input().split()]
S = sum(A)
pls = []
for i in range(1, S):
    if i * i > S:
        break
    if S % i == 0:
        pls += [i]
        pls += [S // i]
pls.sort(reverse=True)
for p in pls:
    B = []
    for i in range(N):
        B += [A[i] % p]
    B.sort()
    for j in range(N):
        if B[j] != 0:
            break
    m = j
    lim = N - 1
    cnt = 0
    while m < lim:
        if B[m] < p - B[-1]:
            B[-1] += B[m]
            cnt += B[m]
            B[m] = 0
            m += 1
        elif B[m] > p - B[-1]:
            cnt += p - B[-1]
            B[m] -= p - B[-1]
            B.pop()
            lim -= 1
        else:
            B.pop()
            cnt += B[m]
            B[m] = 0
            m += 1
            lim -= 1
    if B[-1] == 0 and cnt <= K:
        print(p)
        break

N, K, *A = list(map(int, open(0).read().split()))
pls = []
S = sum(A)
for i in range(1, int(S**0.5) + 1):
    if S % i == 0:
        pls.append(i)
        pls.append(S // i)
pls.sort()
ans = 0
for p in pls:
    B = [a % p for a in A]
    B.sort()
    i = 0
    j = N - 1
    cnt = K
    while i < N:
        if B[i] != 0:
            break
        i += 1
    else:
        ans = p
        continue
    while True:
        a = B[i]
        b = B[j]
        if a < p - b:
            if cnt < a:
                break
            B[j] += a
            cnt -= a
            i += 1
        elif a > p - b:
            if cnt < p - b:
                break
            B[i] -= p - b
            cnt -= p - b
            j -= 1
        else:
            if cnt < a:
                break
            cnt -= a
            i += 1
            j -= 1
        if i >= j:
            ans = p
            break
print(ans)

-N, K = list(map(int, input().split())) -A = [int(c) for c in input().split()] +N, K, *A = list(map(int, open(0).read().split())) +pls = [] -pls = [] -for i in range(1, S): -    if i * i > S: -        break +for i in range(1, int(S**0.5) + 1): -        pls += [i] -        pls += [S // i] -pls.sort(reverse=True) +        pls.append(i) +        pls.append(S // i) +pls.sort() +ans = 0 -    B = [] -    for i in range(N): -        B += [A[i] % p] +    B = [a % p for a in A] -    for j in range(N): -        if B[j] != 0: +    i = 0 +    j = N - 1 +    cnt = K +    while i < N: +        if B[i] != 0: -    m = j -    lim = N - 1 -    cnt = 0 -    while m < lim: -        if B[m] < p - B[-1]: -            B[-1] += B[m] -            cnt += B[m] -            B[m] = 0 -            m += 1 -        elif B[m] > p - B[-1]: -            cnt += p - B[-1] -            B[m] -= p - B[-1] -            B.pop() -            lim -= 1 +        i += 1 +    else: +        ans = p +        continue +    while True: +        a = B[i] +        b = B[j] +        if a < p - b: +            if cnt < a: +                break +            B[j] += a +            cnt -= a +            i += 1 +        elif a > p - b: +            if cnt < p - b: +                break +            B[i] -= p - b +            cnt -= p - b +            j -= 1 -            B.pop() -            cnt += B[m] -            B[m] = 0 -            m += 1 -            lim -= 1 -    if B[-1] == 0 and cnt <= K: -        print(p) -        break +            if cnt < a: +                break +            cnt -= a +            i += 1 +            j -= 1 +        if i >= j: +            ans = p +            break +print(ans)