#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define pb push_back
#define pf push_front
int main(void){
  ll n,k;
  cin>>n>>k;
  vector<ll> a(n);
  ll max1=-1;
  ll sum1=0;
  rep(i,n){
    cin>>a[i];
    max1=max(max1,a[i]);
    sum1+=a[i];
  }
  //MAXから順にsum1の約数を格納
  deque<ll> divisors;
  for(ll i=1;i<=(ll)sqrt(sum1);i++){
    if(sum1%i==0){
      divisors.pb(sum1/i);
    }
  }
  for(ll i=(ll)sqrt(sum1)-1;i>=1;i--){
    if(sum1%i==0){
      divisors.pb(i);
    }
  }
  /*cout<<"test ";
  rep(i,divisors.size()){
    cout<<divisors[i]<<" ";
  }*/
  //cout<<endl;
  //vector<ll> b(n);
  deque<ll> plus1;
  deque<ll> minus1;
  rep(i,divisors.size()){
    ll plus=0;
    ll minus=0;
    rep(j,n){
      //b[i]=min(a[j]%divisors[i],(ll)abs(divisors[i]-a[j]%divisors[i]));
      if(a[j]%divisors[i]>(ll)abs(divisors[i]-(a[j]%divisors[i]))){
        minus+=((ll)abs(divisors[i]-a[j]%divisors[i]))%divisors[i];
        minus1.pb(((ll)abs(divisors[i]-a[j]%divisors[i]))%divisors[i]);
      }else{
        plus+=a[j]%divisors[i];
        plus1.pb(a[j]%divisors[i]);
      }
    }
    sort(plus1.begin(),plus1.end());
    sort(minus1.begin(),minus1.end());
    /*rep(i,plus1.size()){
      cout<<plus1[i]<<" ";
    }
    cout<< " plus i "<<divisors[i]<<endl;
    rep(i,minus1.size()){
      cout<<minus1[i]<<" ";
    }
    cout<< " minus i "<<divisors[i]<<endl;*/
    ll num=0;
    if(plus>minus){
      ll diff=(ll)abs(plus-minus);
      plus-=minus;
      num+=minus;
      while(minus>0){
        if(minus>plus1.front()){
          minus-=plus1.front();
          //num+=plus1.front();
          plus1.pop_front();
        }else{
          plus1[0]-=minus;
          //num+=minus;
          minus=0;
        }
      }
      ll sum2=0;
      for(auto itr=plus1.begin();itr!=plus1.end();++itr){
        sum2+=*itr;
      }
      if(sum2%divisors[i]!=0){
        cout<<"error";
      }
      ll times=0;
      //cout<<"times "<<sum2/divisors[i]<<endl;
      for(auto itr=plus1.end();itr!=plus1.begin()&&times<sum2/divisors[i];--itr){
        if(itr==plus1.end())--itr;
        //cout<<"*itr " <<*itr<<" i "<<divisors[i]<<" ";
        num+=(divisors[i]-*itr)%divisors[i];
        times++;
      }

    }else{
      ll diff=(ll)abs(plus-minus);
      minus-=plus;
      num+=plus;
      while(plus>0){
        if(plus>minus1.front()){
          plus-=minus1.front();
          //num+=minus1.front();
          minus1.pop_front();
        }else{
          minus1[0]-=plus;
          //num+=plus;
          plus=0;
        }
      }
      ll sum2=0;
      for(auto itr=minus1.begin();itr!=minus1.end();++itr){
        //if(itr==minus1.begin())itr++;
        sum2+=*itr;
      }
      if(sum2%divisors[i]!=0){
        cout<<"error";
      }
      ll times=0;
      /*rep(i,minus1.size()){
        cout<<minus1[i]<<" ";
      }*/
      //cout<< " minus i "<<divisors[i]<<endl;
      for(auto itr2=minus1.end();itr2!=minus1.begin()&&times<sum2/divisors[i];--itr2){
        //cout<<"w";
        if(itr2==minus1.end())--itr2;
        num+=(divisors[i]-*itr2)%divisors[i];
        //cout<<(divisors[i]-*itr2)%divisors[i]<<"*itr"<<*itr2<<endl;
        times++;
      }
    }
    if(k>=num ){
      //cout<<"num "<<num<<" i "<<divisors[i]<<endl;
      cout<<divisors[i]<<endl;
      break;
    }
    plus1.clear();
    minus1.clear();

  }
  return 0;
}

Measured memory_bytes: 256