Problem:
Score : 500 points

Problem Statement

We have a sequence of N integers: A_1, A_2, \cdots, A_N.

You can perform the following operation between 0 and K times (inclusive):

Choose two integers i and j such that i \neq j, each between 1 and N (inclusive). Add 1 to A_i and -1 to A_j, possibly producing a negative element.

Compute the maximum possible positive integer that divides every element of A after the operations. Here a positive integer x divides an integer y if and only if there exists an integer z such that y = xz.

Constraints

2 \leq N \leq 500

1 \leq A_i \leq 10^6

0 \leq K \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \cdots A_{N-1} A_{N}

Output

Print the maximum possible positive integer that divides every element of A after the operations.

Sample Input 1

2 3
8 20

Sample Output 1

7

7 will divide every element of A if, for example, we perform the following operation:

Choose i = 2, j = 1. A becomes (7, 21).

We cannot reach the situation where 8 or greater integer divides every element of A.

Sample Input 2

2 10
3 5

Sample Output 2

8

Consider performing the following five operations:

Choose i = 2, j = 1. A becomes (2, 6).

Choose i = 2, j = 1. A becomes (1, 7).

Choose i = 2, j = 1. A becomes (0, 8).

Choose i = 2, j = 1. A becomes (-1, 9).

Choose i = 1, j = 2. A becomes (0, 8).

Then, 0 = 8 \times 0 and 8 = 8 \times 1, so 8 divides every element of A. We cannot reach the situation where 9 or greater integer divides every element of A.

Sample Input 3

4 5
10 1 2 22

Sample Output 3

7

Sample Input 4

8 7
1 7 5 6 8 2 6 5

Sample Output 4

5

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF int(1e9+1)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
#define MX (1<<20)
#define IS(A) ((cn[A>>6]>>(A&63))&1)
#define ST(A) (cn[A>>6]|=1ULL<<((A&63)))
ll P[MX>>1]={2},L(1),cn[1+(MX>>6)];
void gen(){
    ST(0),ST(1);
    int Q(1+sqrt(MX));
    for(ll i(4);i<MX;i+=2)ST(i);
    for(int k(3);k<=Q;k+=2)if(!IS(k))
        for(ll h(k<<1),j(k*k);j<MX;j+=h)ST(j);
    for(int i(3);i<MX;i+=2)if(!IS(i))P[L++]=i;
}
int fc(int N,int*f,int*c){
    int L(0);
    for(int i(0),h(0);N>=P[i]*P[i];++i,h=0){
        while(!(N%P[i]))++h,N/=P[i];
        if(h)f[L]=P[i],c[L++]=h;
    }
    if(N>1)f[L]=N,c[L++]=1;
    return L;
}
void rec(int*f,int*c,int p,int L,vi&o,int S){
    if(p==L)o.PB(S);
    else F(c[p]+1)rec(f,c,p+1,L,o,S),S*=f[p];
}
void dsr(int N,vi&o){
    o.clear();
    static int f[64],c[64];
    int L(fc(N,f,c));
    rec(f,c,0,L,o,1);
    sort(o.begin(),o.end(),greater<int>());
}
int N,A[MX],K,T,V[MX];
bool ok(int M){
    int I=0,J=N-1,q=0;
    F(N)V[i]=A[i]%M;
    sort(V,V+N);
    while(I<J){
        int m=min(V[I],M-V[J]);
        q+=m,V[I]-=m,V[J]+=m,V[J]%=M;
        if(q>K)return 0;
        I+=!V[I];
        J-=!V[J];
    }
    return 1;
}
vi o;
int main(void){
    gen(),scanf("%d%d",&N,&K),ga(N,A),T=accumulate(A,A+N,0);
    dsr(T,o);
    for(auto&h:o)if(ok(h))return printf("%d\n",h),0;
    assert(0);
    return 0;
}