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)

    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)



if __name__ == "__main__":

    main()
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)



if __name__ == "__main__":

    main()

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)
    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)


if __name__ == "__main__":
    main()

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)


if __name__ == "__main__":
    main()

-    s = Divisor_Set(a_sum) +    st = Divisor_Set(a_sum) -    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: +    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: