stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.232559363899203x):
#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);

}
// Slower C++ solution:
#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);

}

// Faster C++ solution for the same problem (measured speedup: 5.1576438834779355x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.052113845894323x):
#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;

}
// Slower C++ solution:
#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;



}


// Faster C++ solution for the same problem (measured speedup: 5.181141861339486x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.127116669311387x):
#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;

}
// Slower C++ solution:
#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);

}

// Faster C++ solution for the same problem (measured speedup: 5.1576438834779355x):
#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;

	double m=0.006,f,t,a;

	double 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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.052113845894323x):
#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;

	double m=0.006,f,t,a;

	double 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;

}
// Slower C++ solution:
#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;



}


// Faster C++ solution for the same problem (measured speedup: 5.181141861339486x):
#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;

	double m=0.006,f,t,a;

	double 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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.127116669311387x):
#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;

	double m=0.006,f,t,a;

	double 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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.2415524900083215x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.051780258842721x):
//

//  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;

}
// Slower C++ solution:
#include<cstdio>

#include<vector>

#include<algorithm>

using namespace std;



#define ran 555



int n, lim;

int a[ran], pre[ran], suf[ran];

//int rem[ran], nr;



bool chk(int x) {

	int reqd = 0;

	vector<int> v;

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

	{

		int cur = a[i] % x;

		v.push_back(cur);

	}

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

	int l = 0, r = v.size() - 1;

	int rem = 0;

	while(l <= r)

	{

		if(rem <= 0)

		{

			rem += v[l];

			reqd += v[l];

			l++;

		}

		else

		{

			rem -= (x - v[r]);

			reqd += (x - v[r]);

			r--;

		}

	}

	if(reqd > 2 * lim)

		return 0;

	if(rem != 0)

		return 0;

	return 1;

	

	/*nr = 0;

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

		if (a[i] % mo) rem[nr++] = a[i]%mo;

	}

	if (!nr) return true;

	sort(rem, rem+nr);

	

	int mi = 2e9;

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

		pre[i] = rem[i];

		if(i>0) pre[i] += pre[i-1];

	}

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

		suf[i] = mo - rem[i];

		if(i<n-1) suf[i] += suf[i+1];

	}

	//for(int i=0;i<n;i++) printf("%d%c", pre[i], i<n-1 ? ' ' : '\n');

	//for(int i=0;i<n;i++) printf("%d%c", suf[i], i<n-1 ? ' ' : '\n');

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

		mi = min(mi, max(pre[i-1], suf[i]));

	//printf("%d %d\n", mo, mi);

	return (mi <= lim);*/

}



int main() {

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

	int s = 0;

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

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

		s += a[i];

	}

	

	int ans = 1;

	for(int i=1;i*i<=s;i++) {

		if (s%i) continue;

		if(chk(i)) ans = max(ans, i);

		if(chk(s/i)) ans = max(ans, s/i);

	}

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

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.827117904001454x):
#include<cstdio>

#include<vector>

#include<algorithm>

using namespace std;



#define ran 555



int n, lim;

int a[ran];

long long pre[ran], suf[ran];

int rem[ran], nr;



bool chk(int mo) {

	/*int reqd = 0;

	vector<int> v;

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

	{

		int cur = a[i] % x;

		v.push_back(cur);

	}

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

	int l = 0, r = v.size() - 1;

	int rem = 0;

	while(l <= r)

	{

		if(rem <= 0)

		{

			rem += v[l];

			reqd += v[l];

			l++;

		}

		else

		{

			rem -= (x - v[r]);

			reqd += (x - v[r]);

			r--;

		}

	}

	if(reqd > 2 * lim)

		return 0;

	if(rem != 0)

		return 0;

	return 1;*/

	

	nr = 0;

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

		if (a[i] % mo) rem[nr++] = a[i]%mo;

	}

	if (!nr) return true;

	sort(rem, rem+nr);

	

	int mi = 2e9;

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

		pre[i] = rem[i];

		if(i>0) pre[i] += pre[i-1];

	}

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

		suf[i] = mo - rem[i];

		if(i<nr-1) suf[i] += suf[i+1];

	}

	/*if (mo==3) {

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

		for(int i=0;i<nr;i++) printf("%d%c", pre[i], i<nr-1 ? ' ' : '\n');	

		for(int i=0;i<nr;i++) printf("%d%c", suf[i], i<nr-1 ? ' ' : '\n');

	}*/

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

		mi = min((long long)mi, max(pre[i-1], suf[i]));

	//if (mi<=lim) printf("%d %d\n", mo, mi);

	return (mi <= lim);

}



int main() {

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

	int s = 0;

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

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

		s += a[i];

	}

	

	int ans = 1;

	for(int i=1;i*i<=s;i++) {

		if (s%i) continue;

		if(chk(i)) ans = max(ans, i);

		if(chk(s/i)) ans = max(ans, s/i);

	}

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

	

	return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 4.834544912349607x):
#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;

}
// Slower C++ solution:
#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;			

}

// Faster C++ solution for the same problem (measured speedup: 2.645933196462967x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.1205535197901653x):
#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;

const int MAX=1e5 + 10;

int n,m,Sub[MAX];

vector<int>g[MAX];

bool vis[MAX];

int dfs(int root)

{

    if(vis[root])return Sub[root];

    vis[root]=1;

    int ans=0;

    for(int x:g[root]){

            ans=max(ans,1+ dfs(x));

    }

    return Sub[root]=ans;

}

int main ()

{

    cin >> n >> m;

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

        int u,v;

        cin >> u >> v;

        g[u].push_back(v);

    }

    int ans=0;

    for(int i=1;i<=n;i++) if(!vis[i])ans = max(ans,dfs(i));

    cout<<ans;

    return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.1242472979450155x):
#include<bits/stdc++.h>

using namespace std;



#define MX 100005

#define ll long long



vector < int > G[MX];

vector < int > topsort;

bool vis[MX];

ll dp[MX];



void dfs(int n){

    vis[n] = 1;

    for (int i = 0; i < G[n].size(); i++){

        int nxt = G[n][i];

        if (!vis[nxt])

            dfs(nxt);

    }

    topsort.push_back(n);

}



void solve(){

    for (int x = 0; x < topsort.size(); x++){

        int cur = topsort[x];

        if (G[cur].size() == 0){

            dp[cur] = 0;

        }

        else{

            ll mx = 0;

            for (int i = 0; i < G[cur].size(); i++){

                int nxt = G[cur][i];

                mx = max(mx, dp[nxt]);

            }

            dp[cur] = mx + 1;

        }

    }





}



int main()

{

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

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

        int u, v; scanf("%d%d", &u, &v);

        G[u].push_back(v);

    }



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

        if (!vis[i])

            dfs(i);

    }

    solve();

    ll res = 0;

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

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



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

    return 0;

}