stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int x[100010],w[100010];

int ans[100010]; 

int n,L,r,t;

long long fldl;

int main()

{

	scanf("%d%d%d",&n,&L,&t);

    for(int i = 1;i <= n;i++)

    {

        scanf("%d%d",&x[i],&w[i]);

		if(w[i] == 2)w[i] = -1;

	}

    for(int i = 1;i <= n;i++)

    {

        int len = x[i] + w[i] * t;

        if (len > 0) (fldl += len / L) %= n;

        else if (len < 0) (fldl += (len + 1) / L - 1) %= n;

        ans[i] = (len % L + L) % L;

    }

    sort(ans + 1 ,ans + n + 1);

    fldl = (fldl + n) % n;

    for(int i = fldl + 1;i <= n;i++)printf("%d\n",ans[i]);

    for(int i = 1;i <= fldl;i++) printf("%d\n",ans[i]);

    return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

using namespace std;

const int N=1e5+10;

int x[N], w[N], ans[N], n, m, t;

long long mi;

int main() {

	scanf("%d%d%d", &n, &m, &t);

	for(int i=1; i<=n; i++) { scanf("%d%d", &x[i], &w[i]); if(w[i]==2) w[i]=-1; }

	int to=0;for(int i=1; i<=n; i++) {to=x[i]+t*w[i]; if(to>0) (mi+=to/m)%=n; if(to<0) (mi+=(to+1)/m-1)%=n; ans[i]=(to%m+m)%m;}

	sort(ans+1, ans+n+1), mi=(mi+n)%n;

	for(int i=mi+1; i<=n; i++) printf("%d\n", ans[i]); for(int i=1; i<=mi; i++) printf("%d\n", ans[i]);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<algorithm>

using namespace std;

long long n,l,t,x,w,ans[100001],p,s;

int main(){

	scanf("%lld%lld%lld",&n,&l,&t);

	for(long long i=1;i<=n;i++){

		scanf("%lld%lld",&x,&w);

        if(w==2)p=x-t;

        else p=x+t;

        if(p>0)s=(s+p/l)%n;

        if(p<0)s=(s+(p+1)/l-1)%n;

        ans[i]=(p%l+l)%l;

    }

    sort(ans+1,ans+n+1);

    if(s>=0)s=s%n;

    else{

    	p=(s+1)/n+1;

    	s=s+p*n;

	}

    for(long long i=s+1;i<=n;i++)printf("%lld\n",ans[i]);

    for(long long i=1;i<=s;i++)printf("%lld\n",ans[i]);

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

using namespace std;

const int N=1e5+10;

int x[N], w[N], ans[N], n, m, t;

long long mi;

int main() {

	scanf("%d%d%d", &n, &m, &t);

	for(int i=1; i<=n; i++) { scanf("%d%d", &x[i], &w[i]); if(w[i]==2) w[i]=-1; }

	int to=0;for(int i=1; i<=n; i++) {to=x[i]+t*w[i]; if(to>0) (mi+=to/m)%=n; if(to<0) (mi+=(to+1)/m-1)%=n; ans[i]=(to%m+m)%m;}

	sort(ans+1, ans+n+1), mi=(mi+n)%n;

	for(int i=mi+1; i<=n; i++) printf("%d\n", ans[i]); for(int i=1; i<=mi; i++) printf("%d\n", ans[i]);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define N 100001

using namespace std;

long long c;

int x[N],w[N],ans[N];

int main()

{

	int n,L,t;

    scanf("%d%d%d",&n,&L,&t);

    for(int i=1;i<=n;i++)

    {

        scanf("%d%d",&x[i],&w[i]);

    }

    for(int i=1;i<=n;i++)

    {

        if(w[i]==2)w[i]=-1;

        int r=x[i]+w[i]*t;

        if(r>0) 

        {

        	(c+=r/L)%=n;

		}

        else if(r<0)

        {

        	(c+=(r+1)/L-1)%=n;

		}

        ans[i]=(r%L+L)%L;

    }

    sort(ans+1,ans+n+1);

    c=(c+n)%n;

    for(int i=c+1;i<=n;i++)

    {

        printf("%d\n",ans[i]);

    }

    for(int i=1;i<=c;i++)

    {

       printf("%d\n",ans[i]); 

    }

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

using namespace std;

const int N=1e5+10;

int x[N], w[N], ans[N], n, m, t;

long long mi;

int main() {

	scanf("%d%d%d", &n, &m, &t);

	for(int i=1; i<=n; i++) { scanf("%d%d", &x[i], &w[i]); if(w[i]==2) w[i]=-1; }

	int to=0;for(int i=1; i<=n; i++) {to=x[i]+t*w[i]; if(to>0) (mi+=to/m)%=n; if(to<0) (mi+=(to+1)/m-1)%=n; ans[i]=(to%m+m)%m;}

	sort(ans+1, ans+n+1), mi=(mi+n)%n;

	for(int i=mi+1; i<=n; i++) printf("%d\n", ans[i]); for(int i=1; i<=mi; i++) printf("%d\n", ans[i]);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

const int maxn = 100035;



int a[maxn],n,l,t,x,cnt;



int main()

{

    scanf("%d%d%d",&n,&l,&t);

    for (int i=1; i<=n; i++)

    {

        scanf("%d%d",&a[i],&x);

        a[i] += x==1?t:-t;

        cnt += a[i]/l;

        if (a[i]%l<0) cnt--;

        ((a[i]%=l)+=l)%=l;

    }

    std::sort(a+1, a+n+1);

    ((cnt%=n)+=n)%=n;

    for (int i=cnt+1; i<=n; i++) printf("%d\n",a[i]);

    for (int i=1; i<=cnt; i++) printf("%d\n",a[i]);

    return 0;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

using namespace std;

 

const int maxn=1e5+5;

 

int n,rk,L,T;

int pos[maxn];

 

int read() {

	int x=0,f=1;char ch=getchar();

	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;

	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';

	return x*f;

}

 

int main() {

	n=read(),L=read(),T=read();

	for(int i=1;i<=n;i++) {

		int x=read(),w=read();

		if(w==2)pos[i]=x-T;

		else pos[i]=x+T;

		rk+=pos[i]/L;

		if(pos[i]%L<0)rk--;

		pos[i]=(pos[i]%L+L)%L;

	}

	sort(pos+1,pos+n+1);

	rk=(rk%n+n)%n;

	for(int i=rk+1;i<=n;i++)

		printf("%d\n",pos[i]);

	for(int i=1;i<=rk;i++)

		printf("%d\n",pos[i]);

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

int n;

int d[1000000];



string check2(){

  int nowpos=n-1;

  int canhop=n-1;

  int minhop=n-1;



  for(int j=0;j<300000;j++){

    canhop=nowpos-d[nowpos]/10;

    minhop=canhop;

    if(canhop<=0)return "yes";



    for(int i=nowpos;i>=canhop;i--){

      if(i-d[i]/10<minhop){

        nowpos=i;

        minhop=i-d[i]/10;

      }

    }





  }

  return "no";

}



string check1(){

  int nowpos=0;

  int canhop=0;

  int maxhop=0;



  for(int j=0;j<300000;j++){

    canhop=d[nowpos]/10+nowpos;

    maxhop=canhop;

    if(canhop>=n-1)return check2();



    for(int i=nowpos;i<=canhop;i++){

      if(d[i]/10+i>=maxhop){

        nowpos=i;

        maxhop=d[i]/10+i;

      }

    }

  }

  return "no";

}



int main(){

  cin >>n;

  for(int i=0;i<n;i++){

    cin>>d[i];

    int sub=d[i]%10;

    d[i]-=sub;

  }

  cout <<check1()<<endl;

  return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

int N;

int d[1000000];

string checkprev(){

	int canhop=1;

	for(int i = N-1;i>0;i--){

		canhop--;

		canhop = max(canhop,d[i]/10);

		if(canhop ==0)

			return "no";

	}

	return "yes";

}

string checkfront(){

	int canhop=1;

	for(int i = 0;i<N;i++){

	canhop--;

	canhop = max(canhop,d[i]/10);

	if(canhop ==0)

		return "no";

	}

	return checkprev();

}

int main(){

	cin >> N;

	for(int i = 0;i<N;i++){

		cin >> d[i];

	}

	cout << checkfront()<<endl;

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



int main () {

	int r;

	cin >> r;

	if (r<1200){

		cout << "ABC" <<endl;

	}

	if (r<2800&&r>=1200){

		cout << "ARC" << endl;

	}

	if (r>=2800&&r<=4208) {

		cout << "AGC" << endl;

	}

	

	return 0;

	



}

// Optimized solution to the same problem (faster):
#include <stdio.h>

int main(){

	int input;

	scanf ("%d", &input);

	if (input<1200){

		printf ("ABC\n");

	}else if (input>=1200&&input<2800){

		printf ("ARC\n");

	}else printf ("AGC\n");

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



int R;

int main () {

	cin >> R;

	if (R < 1200) {

	cout << "ABC" << endl;

	}else if (R < 2800) {

	cout << "ARC" << endl;

	}else {

	cout << "AGC" << endl;

}	

return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>

int main(){

	int input;

	scanf ("%d", &input);

	if (input<1200){

		printf ("ABC\n");

	}else if (input>=1200&&input<2800){

		printf ("ARC\n");

	}else printf ("AGC\n");

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

#include <algorithm>

#include <climits>

using namespace std;

int main() {

	cin.tie(0); ios::sync_with_stdio(false);

	long long a, N, s, A = (LLONG_MAX), l = 0, r = 0, S[100002] = { 0 }; cin >> N >> s;

	for (int i = 1; i <= N;i++) { cin >> a;S[i] += S[i - 1] + a; }

	for(;;){

		if (S[r] - S[l] >= s) { A = min(A, r - l); l++; }else r++;

		if (r > N || l > N) { if (A == (LLONG_MAX))A = 0; cout << A << endl; return 0; }

	}

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

long long i,a,N,s,A=INT_MAX,l,r,S[100002];int main(){scanf("%ld%ld",&N,&s);for(;i<N;i++){scanf("%ld",&a);S[i+1]+=S[i]+a;}for(;;){if(S[r]-S[l]>=s){A=std::min(A,r-l);l++;}else r++;if(r>N){if(A==INT_MAX)A=0;printf("%ld\n",A);return 0;}}}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

int main() {

	long long a, N, s, A = (LLONG_MAX), l = 0, r = 0, S[100002] = { 0 }; cin >> N >> s;

	for (int i = 1; i <= N;i++) { cin >> a;S[i] += S[i - 1] + a; }

	for(;;){

		if (S[r] - S[l] >= s) { A = min(A, r - l); l++; }else r++;

		if (r > N || l > N) { if (A == (LLONG_MAX))A = 0; cout << A << endl; return 0; }

	}

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

long long i,a,N,s,A=INT_MAX,l,r,S[100002];int main(){scanf("%ld%ld",&N,&s);for(;i<N;i++){scanf("%ld",&a);S[i+1]+=S[i]+a;}for(;;){if(S[r]-S[l]>=s){A=std::min(A,r-l);l++;}else r++;if(r>N){if(A==INT_MAX)A=0;printf("%ld\n",A);return 0;}}}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;int main(){cin.tie(0);ios::sync_with_stdio(false);long long i,a,N,s,A=LLONG_MAX,l=0,r=0,S[100002]={0};cin>>N>>s;for(i=1;i<=N;i++){cin>>a;S[i]+=S[i- 1]+a;}for(;;){if(S[r]-S[l]>=s){A=min(A,r-l);l++;}else(r++);if(r>N){if(A==LLONG_MAX)A=0;cout<<A<<endl;return 0;}}}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

long long i,a,N,s,A=INT_MAX,l,r,S[100002];int main(){scanf("%ld%ld",&N,&s);for(;i<N;i++){scanf("%ld",&a);S[i+1]+=S[i]+a;}for(;;){if(S[r]-S[l]>=s){A=std::min(A,r-l);l++;}else r++;if(r>N){if(A==INT_MAX)A=0;printf("%ld\n",A);return 0;}}}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



int n,t,a,h[1010];





int main()

{

    cin>>n>>t>>a;



    for (int i = 0; i < n; i++)

    {

        cin>>h[i];

    }



    

    int ans = 0;

    double min_diff = 1<<30;



    for (int i = 0; i < n; i++)

    {

        double temp = t - h[i] * 0.006;

        double difftemp = abs(a-temp);



        if(min_diff > difftemp){

            min_diff = difftemp;

            ans = i+1;

        }

    }

    

    cout << ans << endl;

    

    return 0;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

int N, T, A, X;

int main()

{

    scanf("%d%d%d", &N, &T, &A);

    int res = 0;

    int cc = 1 << 30;

    for (int i = 1; i <= N; i++)

    {

        scanf("%d", &X);

        int d = (T * 1000 - X * 6) - A * 1000;

        if (d < 0)

            d = -d;

        if (cc > d)

            cc = d, res = i;

    }

    printf("%d\n", res);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<iostream>

#include<algorithm>

#include<stack>

#include<cmath>

using namespace std;

double arr[1005];

int main(){

	int n;

	int t,a;

	cin>>n;

	cin>>t>>a;

	for(int i=0;i<n;i++){

		cin>>arr[i];

		arr[i]=t-arr[i]*0.006;

		arr[i]-=a;

		arr[i]=abs(arr[i]);

	}

	stack<int>s;

	for(int i=0;i<n;i++){

		if(s.empty()||arr[s.top()]>arr[i])

			s.push(i);

	}

	printf("%d",s.top()+1);

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <math.h>

#include <stdlib.h>

/*int min(double *x,int n){

	int i,c=0;

	double ans;

	ans=100005;

	for(i=0; i<n; i++){

		if(ans>x[i]){

			ans=x[i];

			c=i;

		}

	}

	return c;

}*/

int main()

{

	int n,i,c=0;

	double h[1005],max,m=0.006,f,t,a,ans[1005];

	scanf("%d%lf%lf",&n,&t,&a);

	max=1000000.000;

	for(i=0; i<n; i++){

		scanf("%lf",&h[i]);

		f=(h[i]*m);

		f=t-f;

		ans[i]=abs(a-f);

		if(ans[i]<max){

			max=ans[i];

			c=i;

		}

		//printf("%lf\n",ans[i]);

	}

	printf("%d\n",c+1);

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

const int N = 100010;

int main(){

	int n,a,t;int s;

	int ans;

	double minn=0x3f3f3f;

	scanf("%d %d %d",&n,&t,&a);

	for(int i=1;i<=n;i++){

		scanf("%d",&s);

		double tt=t-s*0.006;

		if(abs(tt-a)<minn){

			minn=abs(tt-a);

			ans=i;

		}

//		printf("%d\n",minn);

	}

	printf("%d\n",ans);

    return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <math.h>

#include <stdlib.h>

/*int min(double *x,int n){

	int i,c=0;

	double ans;

	ans=100005;

	for(i=0; i<n; i++){

		if(ans>x[i]){

			ans=x[i];

			c=i;

		}

	}

	return c;

}*/

int main()

{

	int n,i,c=0;

	double h[1005],max,m=0.006,f,t,a,ans[1005];

	scanf("%d%lf%lf",&n,&t,&a);

	max=1000000.000;

	for(i=0; i<n; i++){

		scanf("%lf",&h[i]);

		f=(h[i]*m);

		f=t-f;

		ans[i]=abs(a-f);

		if(ans[i]<max){

			max=ans[i];

			c=i;

		}

		//printf("%lf\n",ans[i]);

	}

	printf("%d\n",c+1);

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



#define sz 100005

#define nl printf("\n");

#define ll long long int



char f,g;

bool flag;

pair < int ,int > pi;

map < int , int > mp;

vector < int > v,va,vb;

int arr[sz],brr[sz],crr[sz];







int main(){



    double a,b,c,d,temp=INT_MAX,ans=INT_MAX,temp2;

    int n,m, i,j,k, x=0,y=0,z=0,idx;



    cin>>n>>a>>b;

    for(i=1; i<=n; i++){

        cin>>c;



        temp=a-c*0.006;

        temp2=(b-temp);

        if(temp2<0)

            temp2*=-1.0;

        if(temp2<ans){

            ans=temp2;

            idx=i;

        }

    }

    cout<<idx<<endl;







    return 0;



}


// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <math.h>

#include <stdlib.h>

/*int min(double *x,int n){

	int i,c=0;

	double ans;

	ans=100005;

	for(i=0; i<n; i++){

		if(ans>x[i]){

			ans=x[i];

			c=i;

		}

	}

	return c;

}*/

int main()

{

	int n,i,c=0;

	double h[1005],max,m=0.006,f,t,a,ans[1005];

	scanf("%d%lf%lf",&n,&t,&a);

	max=1000000.000;

	for(i=0; i<n; i++){

		scanf("%lf",&h[i]);

		f=(h[i]*m);

		f=t-f;

		ans[i]=abs(a-f);

		if(ans[i]<max){

			max=ans[i];

			c=i;

		}

		//printf("%lf\n",ans[i]);

	}

	printf("%d\n",c+1);

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main()

{

    int i,j,ans,sum,temp,n,a,h,x;

    double dans,asum,diff,y,min=100000.00;

    vector<int>v1;

    vector<double>v2,v3;

    cin>>n>>h>>a;

    for(i=0;i<n;i++)

    {

        cin>>x;

        v1.push_back(x);

    }

    for(i=0;i<n;i++)

    {

        diff=(h-v1[i]*0.006);

        v2.push_back(diff);

    }

    for(i=0;i<v2.size();i++)

    {

        diff=abs(v2[i]-a);

        v3.push_back(diff);

    }

    for(i=0;i<v3.size();i++)

    {

        if(v3[i]<min)

        {

            min=v3[i];

        }

    }

    for(i=0;i<v3.size();i++)

    {

        if(min==v3[i])

        {

            break;

        }

    }

    cout<<i+1<<endl;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <math.h>

#include <stdlib.h>

/*int min(double *x,int n){

	int i,c=0;

	double ans;

	ans=100005;

	for(i=0; i<n; i++){

		if(ans>x[i]){

			ans=x[i];

			c=i;

		}

	}

	return c;

}*/

int main()

{

	int n,i,c=0;

	double h[1005],max,m=0.006,f,t,a,ans[1005];

	scanf("%d%lf%lf",&n,&t,&a);

	max=1000000.000;

	for(i=0; i<n; i++){

		scanf("%lf",&h[i]);

		f=(h[i]*m);

		f=t-f;

		ans[i]=abs(a-f);

		if(ans[i]<max){

			max=ans[i];

			c=i;

		}

		//printf("%lf\n",ans[i]);

	}

	printf("%d\n",c+1);

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main(void){

	int n;

	int t,a;

	int h[1001];

	cin>>n;

	cin>>t>>a;

	for(int i=1;i<=n;i++){

		cin>>h[i];

	}

	int MIN;

	int x=INT_MAX;

	int z;

	a*=1000;

	for(int i=1;i<=n;i++){

		MIN=t*1000-h[i]*6;

		if(x>abs(MIN-a)){

			x=abs(MIN-a);

			z=i;

		}

	}

	cout<<z<<endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

using namespace std;

int main(void){

	int n;

	int t,a;

	int h;

	int i;

	int x,ans,MIN;

	int sum;

	scanf("%d%d%d",&n,&t,&a);

	MIN=1000000000;

	ans=0;

	for(i=1;i<=n;i++){

		scanf("%d",&h);

		x=t*1000-h*6;

		sum=x-a*1000;

		if(sum<0)	sum*=-1;

		if(MIN>sum){

			MIN=sum;

			ans=i;

		}

	}

	printf("%d\n",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>



using namespace std;

int main()

{

    float n,t,a,h[1000000]={},num=0,z=999999999,x=0;

    cin>>n>>t>>a;

    for (int i=1; i<=n; i++)

    {

        cin>>h[i];

    }

        num=(t-a)/0.006;

    

    for (int i=1; i<=n; i++)

       {

           if (num>=h[i])

           {

               if (num-h[i]<z)

               {

                   x=i;

                   z=num-h[i];

               }

           }

           if (num<h[i])

           {

               if (h[i]-num<z)

               {

                   x=i;

                   z=h[i]-num;

               }

           }

       }

    cout<<x;

    return 0;

}

// Optimized solution to the same problem (faster):
//

//  main.cpp

//  瀹

//

//  Created by RMBP on 2019/10/13.

//  Copyright 漏 2019 RMBP. All rights reserved.

//



#include <iostream>

using namespace std;

int main() {

    int n,t,a,i,b;

    double h[100000],c,e;

    e=0;

    c=1000000;

    b=0;

    cin>>n>>t>>a;

    for (i=0;i<n;i++){

        cin>>h[i];

        e=t-h[i]*0.006-a;

        

        if (t-h[i]*0.006<a){

            

            e=a-(t-h[i]*0.006);

            

        }

        

        

        if (e<c){

            c=e;

            b=i;

            

        }

        

    }

    cout<<b+1;

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <algorithm>

#include <cstdio>

#include <deque>

#include <vector>



#define rep(i,n) for(int i=0;i<(n);i++)



using namespace std;



bool check(vector<int> a,int k,int d){

	int n=a.size();

	rep(i,n) a[i]%=d;

	sort(a.begin(),a.end());



	deque<int> D(a.begin(),a.end());

	while(D.size()>=2){

		int x=D.front(),y=d-D.back();

		if     (x<=y && x<=k) D.pop_front(), D.back ()+=x, k-=x;

		else if(x> y && y<=k) D.pop_back (), D.front()-=y, k-=y;

		else return false;

	}

	return true;

}



int main(){

	int n,k; scanf("%d%d",&n,&k);

	vector<int> a(n);

	rep(i,n) scanf("%d",&a[i]);



	int ans=0,sum=0;

	rep(i,n) sum+=a[i];

	for(int d=1;d*d<=sum;d++) if(sum%d==0) {

		if(check(a,k,  d  )) ans=max(ans,  d  );

		if(check(a,k,sum/d)) ans=max(ans,sum/d);

	}

	printf("%d\n",ans);



	return 0;

}


// Optimized solution to the same problem (faster):
#include <algorithm>

#include <cstdio>

#include <numeric>



#define rep(i,n) for(int i=0;i<(n);i++)



using namespace std;



int n,k,a[500];



bool check(int d){

	int b[500];

	rep(i,n) b[i]=a[i]%d;

	sort(b,b+n);



	int sum=accumulate(b,b+n,0);

	return accumulate(b,b+n-sum/d,0)<=k;

}



int main(){

	scanf("%d%d",&n,&k);

	rep(i,n) scanf("%d",&a[i]);



	int ans=0,sum=accumulate(a,a+n,0);

	for(int d=1;d*d<=sum;d++) if(sum%d==0) {

		if(check(  d  )) ans=max(ans,  d  );

		if(check(sum/d)) ans=max(ans,sum/d);

	}

	printf("%d\n",ans);



	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

long long n, m, a, b, maxx, fix[300000], dp[300000];

vector <long long> g[300000];

long long dfs (long long v)

{

	if (fix[v] == 1)

		return dp[v] + 1;

	fix[v] = 1;

	for (int i = 0; i < g[v].size(); i ++)

	{

		dp[v] = max (dp[v], dfs(g[v][i]));

	}

		

	return dp[v] + 1;

}

int main()

{

	cin >> n >> m;

	for (int i = 1; i <= m; i ++)

	{

		cin >> a >> b;

		g[a].push_back(b);

	}

	

	for (int i = 1; i <= n; i ++)

		if (fix[i] == 0)

			dfs (i);

	for (int i = 1; i <= n; i ++)

		maxx = max (maxx, dp[i]);

	cout << maxx;			

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

 

#define f first

#define s second

#define ll long long

#define db double

#define pb push_back

#define p_q priority_queue

 

using namespace std;

 

const int N = 3e3, Mod = 998244353, INF = 1e9;



ll dp[100001], a, b, n, m, maxx;

vector <ll> g[100001];



ll dfs (ll u) { 

    

    if (g[u].size() == 0) return 0;

    if (dp[u] != -1) return dp[u];

   

    

    for (int i = 0; i < g[u].size(); i ++) {

        dp[u] = max (dp[u], dfs (g[u][i]) + 1);

        

    }

    

    return dp[u];

    

}

 

int main() {

 

	ios::sync_with_stdio(0);

	cin.tie(0); cout.tie(0);

 	

 	

	cin >> n >> m;

	for (int i = 1; i <= m; i ++) {

	    cin >> a >> b;

	    g[a].pb(b);

	  

	}

	for (int i = 1; i <= n; i ++) dp[i] = -1;

	

	for (int i = 1; i <= n; i ++) {

	 

	    maxx = max (dfs(i), maxx);

	    

	}

	cout << maxx;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

#define ALL(x) (x).begin(),(x).end()

#define uniq(x) (x).erase(unique(ALL(x)),(x).end())

#define SORT(x) sort(ALL(x))

#define REV(x) reverse(ALL(x))

#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)

#define debug(x) cerr<<#x<<"="<<(x)<<endl

#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl

#define ri(x) scanf("%d",&x)

#define rl(x) scanf("%lld",&x)

#define rlcfpoj(x) scanf("%I64d",&x)

#define pi(x) printf("%d",x)

#define pl(x) printf("%lld",x)

#define plcfpoj(x) printf("%I64d",x)

#define lfd() printf("\n")

#define sp() printf(" ")

#define inrep(x) int x;scanf("%d",&x);while(x--)

#define testbit(mask,i) (((mask)>>(i))&1)

#define setbit(mask,i) ((mask)|(1<<i))

#define delbit(mask,i) ((mask)^(1<<i))

int dp[100100];

int n,m;

vector<int> ga[100100];

int u,v;

int d(int x){

	if(dp[x]!=-1)

		return dp[x];

	int &res=dp[x];

	res=0;

	for(int i=0;i<ga[x].size();i++){

		int y=ga[x][i];

		res=max(res,d(y)+1);

	}

	return res;

}

int main(){

	//freopen("input.txt","r",stdin);

	//freopen("output.txt","w",stdout);

	ios::sync_with_stdio(false);

	cin.tie(NULL);

	cout.tie(NULL);

	cin>>n>>m;

	for(int i=1;i<=m;i++){

		cin>>u>>v;

		ga[u].push_back(v);

	}

	int res=0;

	memset(dp,-1,sizeof(dp));

	for(int i=1;i<=n;i++){

		res=max(res,d(i));

	}

	cout<<res<<endl;

	return 0;

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

const int MAXM = 100010;

int n, m, f[MAXM], w[MAXM], rd[MAXM];

struct edge{

	int next, to;

}e[MAXM];

int fir[MAXM],num=0;

void join(int a,int b)

{

	e[++num].to=b;

	e[num].next=fir[a];

	fir[a]=num;

}

void topo()

{

	queue<int> q;

	for(int i=1;i<=n;i++)  

		if(rd[i]==0)

		{

			q.push(i);

			f[i]=0;  

		}	

	while(!q.empty())

	{

		int u=q.front();

		q.pop();

		for(int i=fir[u];i;i=e[i].next)

		{

			int v=e[i].to;

			f[v]=std::max(f[v],f[u]+1);

			rd[v]--;                  

			if(rd[v]==0)q.push(v);

		} 

	}

}

int main()

{

	scanf("%d%d",&n,&m);

	for(int i=1;i<=m;i++)

	{

		int a,b;

		scanf("%d%d",&a,&b);

		join(a,b); 

		rd[b]++;

	}

	topo();

	int ans=0;

	for(int i=1;i<=n;i++)

		ans=std::max(ans,f[i]);

	printf("%d\n",ans);

	return 0;

}

// Fastest known solution for this problem: