from itertools import accumulate

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



def check(d):

    r = sorted([v % d for v in A])

    r_inv = [d - v for v in r]    

    r_cs = [0] + list(accumulate(r))

    r_inv_cs = list(accumulate(r_inv[::-1]))[::-1] + [0]



    ret = False

    for i in range(N + 1):

        flg1 = r_cs[i] <= K

        flg2 = r_cs[i] == r_inv_cs[i]

        ret = (flg1 and flg2) or ret

    

    return ret



M = sum(A)

ans = 0

for i in reversed(list(range(1, int(M ** 0.5) + 1))):

    if M % i == 0 and check(i):

        ans = max(ans, i)

    if M % (M // i) == 0 and check(M // i):

        ans = max(ans, M // i)

        

print(ans)

from itertools import accumulate



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



s = sum(A)

divisor = []

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

    if s % i == 0:

        divisor.append(i)

        if i != s // i:

            divisor.append(s // i)



ans = 0

for d in divisor:

    x = sorted(v % d for v in A)

    y = [d - r for r in x]

    x_s = [0] + list(accumulate(x))

    y_s = list(accumulate(y[::-1]))[::-1] + [0]



    for i in range(N + 1):

        if x_s[i] <= K and x_s[i] == y_s[i]:

            ans = max(ans, d)

            break



print(ans)

from itertools import accumulate

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


def check(d):
    r = sorted([v % d for v in A])
    r_inv = [d - v for v in r]
    r_cs = [0] + list(accumulate(r))
    r_inv_cs = list(accumulate(r_inv[::-1]))[::-1] + [0]
    ret = False
    for i in range(N + 1):
        flg1 = r_cs[i] <= K
        flg2 = r_cs[i] == r_inv_cs[i]
        ret = (flg1 and flg2) or ret
    return ret


M = sum(A)
ans = 0
for i in reversed(list(range(1, int(M**0.5) + 1))):
    if M % i == 0 and check(i):
        ans = max(ans, i)
    if M % (M // i) == 0 and check(M // i):
        ans = max(ans, M // i)
print(ans)

from itertools import accumulate

N, K, *A = list(map(int, open(0).read().split()))
s = sum(A)
divisor = []
for i in range(1, int(s**0.5) + 1):
    if s % i == 0:
        divisor.append(i)
        if i != s // i:
            divisor.append(s // i)
ans = 0
for d in divisor:
    x = sorted(v % d for v in A)
    y = [d - r for r in x]
    x_s = [0] + list(accumulate(x))
    y_s = list(accumulate(y[::-1]))[::-1] + [0]
    for i in range(N + 1):
        if x_s[i] <= K and x_s[i] == y_s[i]:
            ans = max(ans, d)
            break
print(ans)

- - -def check(d): -    r = sorted([v % d for v in A]) -    r_inv = [d - v for v in r] -    r_cs = [0] + list(accumulate(r)) -    r_inv_cs = list(accumulate(r_inv[::-1]))[::-1] + [0] -    ret = False +s = sum(A) +divisor = [] +for i in range(1, int(s**0.5) + 1): +    if s % i == 0: +        divisor.append(i) +        if i != s // i: +            divisor.append(s // i) +ans = 0 +for d in divisor: +    x = sorted(v % d for v in A) +    y = [d - r for r in x] +    x_s = [0] + list(accumulate(x)) +    y_s = list(accumulate(y[::-1]))[::-1] + [0] -        flg1 = r_cs[i] <= K -        flg2 = r_cs[i] == r_inv_cs[i] -        ret = (flg1 and flg2) or ret -    return ret - - -M = sum(A) -ans = 0 -for i in reversed(list(range(1, int(M**0.5) + 1))): -    if M % i == 0 and check(i): -        ans = max(ans, i) -    if M % (M // i) == 0 and check(M // i): -        ans = max(ans, M // i) +        if x_s[i] <= K and x_s[i] == y_s[i]: +            ans = max(ans, d) +            break