#include <algorithm>
#include <bitset>
//#include <boost/multiprecision/cpp_int.hpp>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
// namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
// using ll = boost::multiprecision::cpp_int;
using ll = long long;
#define FOR(i, N) for(ll i = 0; i < N; ++i)

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
// using int = ll;
ll gcd(ll m, ll n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
void swap(ll &a, ll &b) {
    ll tmp = a;
    a = b;
    b = tmp;
}
ll combi(ll n, ll k) {
    ll r = 1, rr = 1;
    for(ll i = 0; i < k; ++i) {
        r *= (n - i);
        rr *= (i + 1);
        // r %= 1000000007;
        // rr %= 1000000007;
    }
    r /= rr;
    // r %= 1000000007;
    return r;
}

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    FOR(i, N) { cin >> A[i]; }
    ll sum = 0;
    FOR(i, N) { sum += A[i]; }
    // sum は ansで割り切れる
    // sum%ans==0
    // 3 1 2 1
    //差が奇数->K奇数->偶数のものを裏返す 偶数->どうしようもなくね
    // 1 2 0 1 3 2 1 0
    // 40
    ll max_ = 0;
    for(ll i = sqrt(sum); i >= 1; --i) {
        if(sum % i != 0)
            continue;

        do{
            vector<ll> sub;
            FOR(j, N) {
                ll tmp = A[j] % i;
                
                if(tmp!=0){
                    sub.push_back(tmp);
                }
            }
            sort(ALL(sub));
            ll subs = sub.size();
            if(subs==0){
                if(max_ < i) {
                    max_ = i;
                }
                break;
            }
            else if(subs==1){
                break;
            }
            vector<ll> suba(subs), subb(subs);
            suba[0] = sub[0];
            FOR(j, subs - 1) { 
                suba[j + 1] = suba[j] + sub[j+1];
            }
            subb[subs-1] = -i+sub[subs - 1];
            FOR(j, subs - 1) {
                //subs-(subs-2+2)
                subb[subs-(j + 2)] = subb[subs-(j+1)] - (i-sub[subs-(j+2)]); 
            }
            subb.push_back(0);
            FOR(j,subs){
                if(suba[j]+subb[j+1]==0){
                    if(max_<i&&K>=suba[j]){
                        max_ = i;
                    }
                    break;
                }
            }
        } while(false);

        do {
            ll ii = sum/i;
            vector<ll> sub;
            FOR(j, N) {
                ll tmp = A[j] % ii;

                if(tmp != 0) {
                    sub.push_back(tmp);
                }
            }
            sort(ALL(sub));
            ll subs = sub.size();
            if(subs == 0) {
                if(max_ < ii) {
                    max_ = ii;
                }
                break;
            } else if(subs == 1) {
                break;
            }
            vector<ll> suba(subs), subb(subs);
            suba[0] = sub[0];
            FOR(j, subs - 1) { suba[j + 1] = suba[j] + sub[j+1]; }
            subb[subs - 1] = -ii + sub[subs - 1];
            FOR(j, subs - 1) {
                // subs-(subs-2+2)
                subb[subs - (j + 2)] =
                    subb[subs - (j + 1)] - (ii - sub[subs - (j + 2)]);
            }
            subb.push_back(0);
            FOR(j, subs) {
                if(suba[j] + subb[j + 1] == 0) {
                    if(max_ < ii && K >= suba[j]) {
                        max_ = ii;
                    }
                    break;
                }
            }
        } while(false);
    }
    //3 1 2 1
    //1 2 0 1 3 2 1 0


    // 0  0  1  1  1  2  2  3
    // 0  0 -4 -4 -4 -3 -3 -2
    //-4 -3 0 -4 -2 -3 -4 0
    cout << max_ << endl;
}


Measured memory_bytes: 256