Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
def divisor_list(N): #素因数分解
    res = []
    i = 1
    while i*i < N:
        if N%i == 0:
            res.append(i)
            res.append(N//i)
        i += 1
    if i*i == N: res.append(i)
    return sorted(res)

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,k = [int(i) for i in readline().split()]
a = [int(i) for i in readline().split()]


l = reversed(divisor_list(sum(a)))


def check(x):
    res = []
    for ai in a:
        c = ai%x
        d = ai%x-x
        if abs(c) > abs(d): res.append(d)
        else: res.append(c)
    res.sort(key = abs)
    
    d = sum(res)

    if d > 0:
        idx = -1
        while d != 0:
            if res[idx]>0:
                d -= x
                res[idx] -= x
                idx -= 1
    if d < 0:
        idx = -1
        while d != 0:
            if res[idx]<0:
                d += x
                res[idx] += x
                idx -= 1
                
    c = sum([x for x in res if x > 0])        

#    print(x,c,res)
    return (c <= k)



for x in l:
    if check(x):
        print(x)
        exit()




















Fixed submission:
# coding: utf-8
# Your code here!
def divisor_list(N): #素因数分解
    res = []
    i = 1
    while i*i < N:
        if N%i == 0:
            res.append(i)
            res.append(N//i)
        i += 1
    if i*i == N: res.append(i)
    return sorted(res)

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,k = [int(i) for i in readline().split()]
aaa = [int(i) for i in readline().split()]


l = list(reversed(divisor_list(sum(aaa))))


def check(x):
    res = []
    for ai in aaa:
        c = ai%x
        d = ai%x-x
        if abs(c) > abs(d): res.append(d)
        else: res.append(c)
    res.sort(key = abs)
    
    d = sum(res)
    if d > 0:
        idx = -1
        while d > 0:
            if res[idx]>0:
                d -= x
                res[idx] -= x
            idx -= 1
    elif d < 0:
        idx = -1
        while d < 0:
            if res[idx]<0:
                d += x
                res[idx] += x
            idx -= 1
                
    c = sum([i for i in res if i > 0])        

#    print(x,c,res)
    return (c <= k)



for x in l:
    if check(x):
        print(x)
        exit()

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
def divisor_list(N): #素因数分解
    res = []
    i = 1
    while i*i < N:
        if N%i == 0:
            res.append(i)
            res.append(N//i)
        i += 1
    if i*i == N: res.append(i)
    return sorted(res)

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,k = [int(i) for i in readline().split()]
a = [int(i) for i in readline().split()]


l = reversed(divisor_list(sum(a)))


def check(x):
    res = []
    for ai in a:
        c = ai%x
        d = ai%x-x
        if abs(c) > abs(d): res.append(d)
        else: res.append(c)
    res.sort(key = abs)
    
    d = sum(res)

    if d > 0:
        idx = -1
        while d != 0:
            if res[idx]>0:
                d -= x
                res[idx] -= x
                idx -= 1
    if d < 0:
        idx = -1
        while d != 0:
            if res[idx]<0:
                d += x
                res[idx] += x
                idx -= 1
                
    c = sum([x for x in res if x > 0])        

#    print(x,c,res)
    return (c <= k)



for x in l:
    if check(x):
        print(x)
        exit()




















Fixed submission:
# coding: utf-8
# Your code here!
def divisor_list(N): #素因数分解
    res = []
    i = 1
    while i*i < N:
        if N%i == 0:
            res.append(i)
            res.append(N//i)
        i += 1
    if i*i == N: res.append(i)
    return sorted(res)

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,k = [int(i) for i in readline().split()]
aaa = [int(i) for i in readline().split()]


l = list(reversed(divisor_list(sum(aaa))))


def check(x):
    res = []
    for ai in aaa:
        c = ai%x
        d = ai%x-x
        if abs(c) > abs(d): res.append(d)
        else: res.append(c)
    res.sort(key = abs)
    
    d = sum(res)
    if d > 0:
        idx = -1
        while d > 0:
            if res[idx]>0:
                d -= x
                res[idx] -= x
            idx -= 1
    elif d < 0:
        idx = -1
        while d < 0:
            if res[idx]<0:
                d += x
                res[idx] += x
            idx -= 1
                
    c = sum([i for i in res if i > 0])        

#    print(x,c,res)
    return (c <= k)



for x in l:
    if check(x):
        print(x)
        exit()