def solve():

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

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

    max_total = 22361 # sqrt(10**6 * 500)

    total = sum(A)

    search_space = set([])



    max_d = 1

    for d in range(1, min(total, max_total) ):

        if total % d == 0:

            search_space.add(d)

            search_space.add(total // d)

    

    # print(search_space)

    

    for d in search_space:

        if total % d == 0:

            remainders = [a%d for a in A]

            remainders = sorted(remainders)

            # print(d, remainders)

            positive_rem = 0

            negative_rem = 0

            flag = True

            for rem in remainders:

                if positive_rem+rem <= K:

                    positive_rem += rem

                elif negative_rem+(d-rem) <=K:

                    negative_rem += (d-rem)

                else: 

                    flag = False

                    break



            if flag and d > max_d:

                # print(d, remainders, positive_rem, negative_rem)

                max_d = d

            

    print(max_d)

    

solve()
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 = list(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()
def solve():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    max_total = 22361  # sqrt(10**6 * 500)
    total = sum(A)
    search_space = set([])
    max_d = 1
    for d in range(1, min(total, max_total)):
        if total % d == 0:
            search_space.add(d)
            search_space.add(total // d)
    # print(search_space)
    for d in search_space:
        if total % d == 0:
            remainders = [a % d for a in A]
            remainders = sorted(remainders)
            # print(d, remainders)
            positive_rem = 0
            negative_rem = 0
            flag = True
            for rem in remainders:
                if positive_rem + rem <= K:
                    positive_rem += rem
                elif negative_rem + (d - rem) <= K:
                    negative_rem += d - rem
                else:
                    flag = False
                    break
            if flag and d > max_d:
                # print(d, remainders, positive_rem, negative_rem)
                max_d = d
    print(max_d)


solve()

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 = list(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()

+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が低いのを取ってきてマッチングを取る -    max_total = 22361  # sqrt(10**6 * 500) -    total = sum(A) -    search_space = set([]) -    max_d = 1 -    for d in range(1, min(total, max_total)): -        if total % d == 0: -            search_space.add(d) -            search_space.add(total // d) -    # print(search_space) -    for d in search_space: -        if total % d == 0: -            remainders = [a % d for a in A] -            remainders = sorted(remainders) -            # print(d, remainders) -            positive_rem = 0 -            negative_rem = 0 -            flag = True -            for rem in remainders: -                if positive_rem + rem <= K: -                    positive_rem += rem -                elif negative_rem + (d - rem) <= K: -                    negative_rem += d - rem -                else: -                    flag = False -                    break -            if flag and d > max_d: -                # print(d, remainders, positive_rem, negative_rem) -                max_d = d -    print(max_d) +    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)