stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int main()

{

	int a,b,c,k,turn;

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

	for(;;)

	{

		if(b<=a)

		{

			b*=2;

			turn++;

		}

		else

		{

			break;

		}

	}

	for(;;)

	{

		if(c<=b)

		{

			c*=2;

			turn++;

		}

		else

		{

			break;

		}

	}

	if(turn<=k)

	{

		printf("Yes");

	}

	else

	{

		printf("No");

	}

}

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

int main(){

	int a,b,c,k,count=0;

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

	while(a>=b){

		b=b*2;

		count++;

	}

	while(b>=c){

		c=c*2;

		count++;

	}

	if(count>k)

	printf("No");

	else

	printf("Yes");

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

#include <cstdio>

#include <cstdlib>

#include <algorithm>



using namespace std;



long long n;



bool check(long long a, long long b)

{

	return a % b == 0;

}



void work()

{

	for (long long i = 1; i <= 3500; i++)

	{

		for (long long j = i; j <= 3500; j++)

		{

			if (4*i*j-(i+j)*n <= 0) continue;

			if (check(i*j*n, 4*i*j-(i+j)*n))

			{

				printf("%I64d %I64d %I64d\n", i,j, (i*j*n)/(4*i*j-(i+j)*n));

				return;

			}

		}

	}

}



int main()

{

	scanf("%I64d", &n);

	work(); 

	return 0;

}

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

#include <math.h>

typedef long long ll;

int main()

{

	ll N;

	scanf("%lld",&N);

	int flag=0;

	for(ll h=1;h<=3500;h++)

	{

		if (flag) break;

		for(ll n=1;n<=3500;n++)

		{

			if(flag) break;

			if(N-4*n>0) continue;

				ll de=4*h*n-N*(h+n);

				ll bde=N*h*n;

				if(de<=0||bde<=0) continue;

				if(de>0&&bde>0&&bde%de==0)

				{

					printf("%lld %lld %lld\n",h,n,bde/de);

					flag=1; 

				} 

				

				

		}

		

	}

	return 0;

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

#include<stdio.h>

using namespace std;

long long N;

int main()

{

	while (scanf("%lld", &N) != EOF)

	{

		long long  h, n, t1, t2;

		bool flag = 0;

		for (h = 1; h <= 3500; h++) 

		{

			for (n = 1; n <= 3500; n++)

			{

				t1 = N*h*n;

				t2 = 4 * h*n - n*N - h*N;

				if (t1 > 0 && t2 > 0 && t1%t2 == 0)

				{

					printf("%lld %lld %lld\n", h, n, t1 / t2);

					flag = 1;

					break;

				}

			}

			if (flag)

				break;

		}

	}

	return 0;

}

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

#include <math.h>

typedef long long ll;

int main()

{

	ll N;

	scanf("%lld",&N);

	int flag=0;

	for(ll h=1;h<=3500;h++)

	{

		if (flag) break;

		for(ll n=1;n<=3500;n++)

		{

			if(flag) break;

			if(N-4*n>0) continue;

				ll de=4*h*n-N*(h+n);

				ll bde=N*h*n;

				if(de<=0||bde<=0) continue;

				if(de>0&&bde>0&&bde%de==0)

				{

					printf("%lld %lld %lld\n",h,n,bde/de);

					flag=1; 

				} 

				

				

		}

		

	}

	return 0;

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

using namespace std;

int main()

{

	long long N, h, n, w;

	cin >> N;

	int flag = 0;

	for (h = 1; h <= 3500; h++)

	{

		for (n = 1; n <= 3500; n++)

		{

			if ((4 * h*n - N*h - N*n) > 0 && ((N*h*n) % (4 * h*n - N*h - N*n) == 0))

			{

				flag = 1;

				break;

			}

		}

		if (flag == 1)

		{

			cout << h << " " << n << " " << (N*h*n) / (4 * h*n - N*h - N*n) << endl;

			break;

		}

	}

	return 0;

}

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

#include <math.h>

typedef long long ll;

int main()

{

	ll N;

	scanf("%lld",&N);

	int flag=0;

	for(ll h=1;h<=3500;h++)

	{

		if (flag) break;

		for(ll n=1;n<=3500;n++)

		{

			if(flag) break;

			if(N-4*n>0) continue;

				ll de=4*h*n-N*(h+n);

				ll bde=N*h*n;

				if(de<=0||bde<=0) continue;

				if(de>0&&bde>0&&bde%de==0)

				{

					printf("%lld %lld %lld\n",h,n,bde/de);

					flag=1; 

				} 

				

				

		}

		

	}

	return 0;

}
// Slower C++ solution:
/*main*/

#include <iostream>

#include <stdio.h>

#include <cstdlib>

using namespace std;



typedef long long LL;

LL N,molecule,denominator;

int main()

{

    LL h,n,w;

    int flag = 0;

    scanf("%I64d",&N);

    for(h=1; h<=3500; h++)

    {

        for(n=1; n<=3500; n++)

        {

            molecule = 4*h*n - N*n - N*h;

            denominator = N*h*n;

            if(molecule>0 && denominator%molecule==0 && denominator/molecule<=3500)

            {

                w = denominator / molecule;

                printf("%I64d %I64d %I64d",h,n,w);

                flag = 1; break;

            }

        }

        if(flag) break;

    }

    return 0;

}

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

#include <math.h>

typedef long long ll;

int main()

{

	ll N;

	scanf("%lld",&N);

	int flag=0;

	for(ll h=1;h<=3500;h++)

	{

		if (flag) break;

		for(ll n=1;n<=3500;n++)

		{

			if(flag) break;

			if(N-4*n>0) continue;

				ll de=4*h*n-N*(h+n);

				ll bde=N*h*n;

				if(de<=0||bde<=0) continue;

				if(de>0&&bde>0&&bde%de==0)

				{

					printf("%lld %lld %lld\n",h,n,bde/de);

					flag=1; 

				} 

				

				

		}

		

	}

	return 0;

}
// Slower C++ solution:
#include<iostream>//暴力？

using namespace std;



int main()

{

	long long N, h, n, w;

	long long up, down;

	while (cin >> N)

	{

		w = 0;

		for (h = 1; h <= 3500; h++)

		{

			for (n = 1; n <= 3500; n++)

			{

				up = 4 * h*n - N*h - N*n;

				down = N*h*n;

				if (up > 0 && down%up == 0 && down / up <= 3500)

				{

					w = down / up;

					cout << h << " " << n << " " << w << endl;

				}

				if (w != 0)

				{

					break;

				}

			}

			if (w != 0)

			{

				break;

			}

		}

	}

	return 0;

}

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



int main()

{

    long long N, n, h, w;

    scanf("%lld", &N);

    int flag = 0;

    for(n = 1; n <= 3500; n++)

    {

        for(h = 1; h <= 3500; h++)

        {

            long long u = N * n * h;

            long long d = 4 * h * n - N * h - N * n;

            if(d > 0 && u % d == 0)

            {

                w = u / d;

                flag = 1;

                break;

            }

        }

        if(flag)

            break;

    }

    printf("%lld %lld %lld\n", h, n, w);

    return 0;

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

#include<stdio.h>

using namespace std;

long long N;

int main()

{

	while (scanf("%lld", &N) != EOF)

	{

		long long  h, n, t1, t2;

		bool flag = 0;

		for (h = 1; h <= 3500; h++) 

		{

			for (n = 1; n <= 3500; n++)

			{

				t1 = N*h*n;

				t2 = 4 * h*n - n*N - h*N;

				if (t1 > 0 && t2 > 0 && t1%t2 == 0)

				{

					printf("%lld %lld %lld\n", h, n, t1 / t2);

					flag = 1;

					break;

				}

			}

			if (flag)

				break;

		}

	}

	return 0;

}

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



int main()

{

    long long N, n, h, w;

    scanf("%lld", &N);

    int flag = 0;

    for(n = 1; n <= 3500; n++)

    {

        for(h = 1; h <= 3500; h++)

        {

            long long u = N * n * h;

            long long d = 4 * h * n - N * h - N * n;

            if(d > 0 && u % d == 0)

            {

                w = u / d;

                flag = 1;

                break;

            }

        }

        if(flag)

            break;

    }

    printf("%lld %lld %lld\n", h, n, w);

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int main()

{

	string s;

	cin>>s;

	for(int i=0;i<(int)s.length()-1;i++) if(s[i]=='A'&&s[i+1]=='C') return puts("Yes"),0;

	return puts("No"),0;

}

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

#include <string.h>

int main()

{

	char a[6];

	scanf("%s",a);

	if(strstr(a,"AC")) printf("Yes\n");

	else printf("No\n");

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

using namespace std;

char n;

int main()

{

	while(cin>>n)

	{

		if(n=='A')

		{

			cin>>n;

			if(n=='C')

			{

				cout<<"Yes"<<endl;

				return 0;

			}

		}

	}

	cout<<"No"<<endl;

	return 0;

}

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

#include <string.h>

int main()

{

	char a[6];

	scanf("%s",a);

	if(strstr(a,"AC")) printf("Yes\n");

	else printf("No\n");

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int main()

{   

    string s;

    cin >> s;

    for(int i = 0; s[i] != '\0'; i++)

    {

        if(s[i]=='A'&&s[i+1]=='C')

        {

            cout << "Yes" << endl;

            return 0;

        }

    }

    cout << "No" << endl;

    return 0;

}

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

#include <string.h>

int main()

{

	char a[6];

	scanf("%s",a);

	if(strstr(a,"AC")) printf("Yes\n");

	else printf("No\n");

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int main(){   

    string s;

    cin>>s;

    for(int i=0;s[i]!='\0';i++){

        if(s[i]=='A'&&s[i+1]=='C'){

            cout<<"Yes"<<endl;

            return 0;

        }

    }

    cout<<"No"<<endl;

    return 0;

}

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

#include <string.h>

int main()

{

	char a[6];

	scanf("%s",a);

	if(strstr(a,"AC")) printf("Yes\n");

	else printf("No\n");

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int kmp[1000010];

char s1[1000010], s2[1000010];



int main() {

    scanf( "%s" , s1 + 1 );

    s2[1] = 'A';

    s2[2] = 'C';

    int len1 = strlen( s1 + 1 );

    int len2 = strlen( s2 + 1 );

    for( int i = 2 ; i <= len2 ; i++ ) {

        int j = kmp[i-1];

        while ( j && s2[j+1] != s2[i] ) j = kmp[j];

        kmp[i] = j + ( s2[j+1] == s2[i] );

    }

    for( int i = 1 , j = 0 ; i <= len1 + 1 ; i++ ) {

        if ( j == len2 ){ printf("Yes\n"); return 0; }

        while ( j && s2[j+1] != s1[i] ) j = kmp[j];

        j += ( s2[j+1] == s1[i] );

    }

    printf("No\n");

    return 0;

}

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

int a;

char s[20];

int main ()

{

	scanf ("%s",s);

	for (a=0;s[a];a=s[a]=='A'&&s[a+1]=='C'?10:a+1) ;

	printf ("%s\n",a==10?"Yes":"No");

	return 0;

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

#include<iostream>

#include<cstring>

using namespace std;

char a[6];

int main(){

	cin>>a;

	for(int i=0;i<strlen(a);i++){

		if(a[i]=='A'&&a[i+1]=='C'){

			puts("Yes");

			return 0;

		}

	}

	puts("No");

	return 0;

}

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

int a;

char s[20];

int main ()

{

	scanf ("%s",s);

	for (a=0;s[a];a=s[a]=='A'&&s[a+1]=='C'?10:a+1) ;

	printf ("%s\n",a==10?"Yes":"No");

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

int main()

{

    char a[6];

    scanf("%s",a);

    if(strstr(a,"AC")) cout<<"Yes"<<endl;

    else cout<<"No"<<endl;

    return 0;}

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

int a;

char s[20];

int main ()

{

	scanf ("%s",s);

	for (a=0;s[a];a=s[a]=='A'&&s[a+1]=='C'?10:a+1) ;

	printf ("%s\n",a==10?"Yes":"No");

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main() {

	ios::sync_with_stdio(0);

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

	string s; cin >> s;

	for (int i = 0; i < s.length() - 1; i++) if (s[i] == 'A' && s[i + 1] == 'C') {

		cout << "Yes" << endl;

		return 0;

	}

	cout << "No" << endl;

	return 0;

}




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

#include <cstring>



int main() {

	char str[1010];

	scanf("%s", str);

	puts(strstr(str, "AC") ? "Yes" : "No");

	return 0;

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

#include<string>

#include<map>

#include<queue>

using namespace std;

map<string, int> sop;string s;

bool check(int mid)

{

	for (int i =1; i <= s.size() - mid+1; i++) {

		string op = s.substr(i-1, mid);

		if (sop[op])

		{

			if (i - sop[op] >= mid)

				return true;

		}

		else

			sop[op] = i;

	}

	return false;

}

int main()

{

	int n;

	cin >> n;

	cin >> s;

	int l = 0, r = n / 2;

	while (l < r) {

		int mid =(l + r + 1)/2;

		if (check(mid))

			l = mid;

		else

			r = mid - 1;

	}

	cout << l << endl;

	return 0;

}

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

#include<string.h>

#include<algorithm>

#include<queue>

using namespace std;

typedef struct pp

{   char x[50];

    int t,R;

}S;

S s[105];

bool cmp(int a,int b)

{   return a>b;

}

int main()

{   int i,j,T,n,maxn=0,k,s=0,q;

    int y[26]={0};

    char x[6000];

    scanf("%d",&n);

    scanf("%s",x);

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

    {

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

        {   if(x[i]==x[j]&&x[i-1]!=x[j-1])

            {   //if(j==2)printf("##\n");

                q=1;

                for(k=1;k<j-i;k++)

                {   if(x[i+k]==x[j+k])q++;

                    else break;

                }

                if(q>maxn&&j-i>=q)maxn=q;

                //if(j==2)printf("##%d\n",q);

            }

        }

    }

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

    return 0;

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

#include<cstring>

#include<cmath>

#include<algorithm>

#include<iostream>

#include<set>

#include<queue>

#include<map>

using namespace std;

int n;

string str;

int check(int a)

{

	map<string, int> m;

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

	{

		string s = str.substr(i - 1, a);

		if (m[s])

		{

			if (i - m[s] >= a) return true;

		}

		else

			m[s] = i;

	}

	return false;

}



int main()

{

	cin >> n >> str;

	int l = 0,r = n / 2;

	while (l <= r)

	{

		int mid = l + r >> 1;

		if (check(mid)) l = mid+1;

		else  r = mid-1;

	}

	cout << r << endl;



}

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

#include<string.h>

#include<algorithm>

#include<queue>

using namespace std;

typedef struct pp

{   char x[50];

    int t,R;

}S;

S s[105];

bool cmp(int a,int b)

{   return a>b;

}

int main()

{   int i,j,T,n,maxn=0,k,s=0,q;

    int y[26]={0};

    char x[6000];

    scanf("%d",&n);

    scanf("%s",x);

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

    {

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

        {   if(x[i]==x[j]&&x[i-1]!=x[j-1])

            {   //if(j==2)printf("##\n");

                q=1;

                for(k=1;k<j-i;k++)

                {   if(x[i+k]==x[j+k])q++;

                    else break;

                }

                if(q>maxn&&j-i>=q)maxn=q;

                //if(j==2)printf("##%d\n",q);

            }

        }

    }

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

    return 0;

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

#include<cmath>

#include<algorithm>

#include<queue>

using namespace std;

int a[5001][5001] = {0};

int main() 

{



	int n,i,j;

	string s;

	cin >> n;

	cin >> s;

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

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

		{

			if (i == j)

				continue;

			if (s[i]==s[j])

			{

				a[i + 1][j + 1] = a[i][j] + 1;

			}

		}

	int max = 0;

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

		for (j = 1; j <= n; j++)

		{

			if (a[i][j] > max&&(i-a[i][j])>=j)

				max = a[i][j];

		}

	cout << max;

	return 0;

}

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

#include<string.h>

#include<algorithm>

#include<queue>

using namespace std;

typedef struct pp

{   char x[50];

    int t,R;

}S;

S s[105];

bool cmp(int a,int b)

{   return a>b;

}

int main()

{   int i,j,T,n,maxn=0,k,s=0,q;

    int y[26]={0};

    char x[6000];

    scanf("%d",&n);

    scanf("%s",x);

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

    {

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

        {   if(x[i]==x[j]&&x[i-1]!=x[j-1])

            {   //if(j==2)printf("##\n");

                q=1;

                for(k=1;k<j-i;k++)

                {   if(x[i+k]==x[j+k])q++;

                    else break;

                }

                if(q>maxn&&j-i>=q)maxn=q;

                //if(j==2)printf("##%d\n",q);

            }

        }

    }

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

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



const int MAXN = 5050;



const long long P1 = 1087;

const long long P2 = 1097;

const long long MOD1 = 1e9 + 7;

const long long MOD2 = 1e9 + 123;





int N;



char ar[MAXN];



long long int hash1[MAXN];

long long int hash2[MAXN];



long long int power1[MAXN];

long long int power2[MAXN];



inline long long get_hash( int i, int len, long long P, long long MOD, long long power[], long long hash[] ) {



	long long first = (hash[i] - hash[i + len] + MOD) % MOD;



	return (first * power[i]) % MOD;

}



inline bool check( int len ) {



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

		for( int j = i + len ; j <= N - len + 1 ; j++ ) {

			if ( get_hash(i, len, P1, MOD1, power1, hash1) == get_hash(j, len, P1, MOD1, power1, hash1)

			 && get_hash(i, len, P2, MOD2, power2, hash2) == get_hash(j, len, P2, MOD2, power2, hash2) ) {

				// cerr << i << " " << j << " " << len << endl;

				return true;

			}

		}

	}



	return false;

}



int main() {



	string s;



	power1[0] = power2[0] = 1LL;



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

		power1[i] = (power1[i - 1] * P1) % MOD1;

		power2[i] = (power2[i - 1] * P2) % MOD2;

	}



	scanf("%d%s", &N, ar + 1);



	for( int i=N ; i ; i-- ) {

		hash1[i] = (((power1[N - i] * (ar[i] - 'a')) % MOD1) + hash1[i + 1]) % MOD1;

		hash2[i] = (((power2[N - i] * (ar[i] - 'a')) % MOD2) + hash2[i + 1]) % MOD2;

	}



	int lo = 0, hi = N, result;



	cerr << hi << endl;



	while( lo <= hi ) {



		int mi = (lo + hi) / 2;



		// cerr << mi << endl;



		if (check(mi)) {

			result = mi;

			lo = mi + 1;

		} else {

			hi = mi - 1;

		}

	}



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

	return 0;

}

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

#include<cstring>

#include<cstdlib>

#include<cstdio>

#include<map>

#define pii pair<int,int>

#define mod 1000000007

#define MOD 998244353

#define SED 233

#define N 200020

#define sed 173

using namespace std;

int has[N],pw[N];

int geth(int x,int y)

{

	return (has[y]-1ll*has[x-1]*pw[y-x+1]%mod+mod)%mod;

}

int _has[N],_pw[N];

int _geth(int x,int y)

{

	return (_has[y]-1ll*_has[x-1]*_pw[y-x+1]%MOD+MOD)%MOD;

}

int n;

char ch[N];

map<pii,bool>vis;

bool check(int len)

{

	vis.clear();

	for(int i=n-len+1;i;i--)

	{

		int j=i+len;

		if(j+len-1<=n)vis[make_pair(geth(j,j+len-1),_geth(j,j+len-1))]=1;

		pii tmp=make_pair(geth(i,i+len-1),_geth(i,i+len-1));

		if(vis[tmp])return true;

	}

	return false;

}

int main()

{

	scanf("%d%s",&n,ch+1),pw[0]=_pw[0]=1;

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

		pw[i]=1ll*pw[i-1]*sed%mod,has[i]=(1ll*has[i-1]*sed%mod+ch[i])%mod,

		_pw[i]=1ll*_pw[i-1]*SED%MOD,_has[i]=(1ll*_has[i-1]*SED%MOD+ch[i])%MOD;

	int l=1,r=n,ret=0;

	while(l<=r)

	{

		int mid=(l+r)>>1;

		if(check(mid))l=mid+1,ret=mid;

		else r=mid-1;

	}

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

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define mp make_pair

#define ff first

#define ss second

using namespace std;

typedef long long LL;

typedef pair<LL, LL> PLL;

typedef pair<int, int> PII;

 

const PLL M = mp(1e9+7, 1e9+9);        ///Should be large primes

const LL base = 875329;               ///Should be a prime larger than highest value

const int N = 1e5+7;                 ///Highest length of string

 

ostream& operator<<(ostream& os, PLL hash) {

    return os<<"("<<hash.ff<<", "<<hash.ss<<")";

}

 

PLL operator+ (PLL a, LL x)     {return mp(a.ff + x, a.ss + x);}

PLL operator- (PLL a, LL x)     {return mp(a.ff - x, a.ss - x);}

PLL operator* (PLL a, LL x)     {return mp(a.ff * x, a.ss * x);}

PLL operator+ (PLL a, PLL x)    {return mp(a.ff + x.ff, a.ss + x.ss);}

PLL operator- (PLL a, PLL x)    {return mp(a.ff - x.ff, a.ss - x.ss);}

PLL operator* (PLL a, PLL x)    {return mp(a.ff * x.ff, a.ss * x.ss);}

PLL operator% (PLL a, PLL m)    {return mp(a.ff % m.ff, a.ss % m.ss);}

 

PLL pb[N];      ///powers of base mod M

///Call pre before everything

void pre() {

    pb[0] = mp(1,1);

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

        pb[i] = (pb[i-1] * base)%M;

}

 

///Calculates hashes of all prefixes of s including empty prefix

vector<PLL> hashList(string &s) {

    int n = s.size();

    vector<PLL> ans(n+1);

    ans[0] = mp(0,0);

 

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

        ans[i] = (ans[i-1] * base + s[i-1])%M;

    return ans;

}

 

///Calculates hash of substring s[l..r] (1 indexed)

PLL Hash(vector<PLL> &hashlist, int l, int r) {

    int len = (r-l+1);

    return ((hashlist[r] - hashlist[l-1]*pb[len])%M+M)%M;

}

vector<PLL>hashVec;

int n; 

bool ok(int len) {



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

        

        PLL val1 = Hash(hashVec , i , i+len-1);

        

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

            

            PLL val2 = Hash(hashVec , j , j+len-1);

            if(val1 == val2) return true;

        }

    }

    return false;

}





int main() {

    

    ios::sync_with_stdio(false);

    cin.tie(0);

    pre();

    

    

    string str;

    

    cin>>n>>str;

    

    hashVec = hashList(str);

    

    int lo = 0 , hi = n;

    int ans = 0;

    

    while(lo <= hi) {

        

        int mid = (lo+hi)/2;

        

        if(ok(mid)) {

            ans = mid;

            lo = mid+1;

        }

        else hi = mid-1;

    }

    cout<<ans<<'\n';

    return 0;

    



}

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

#include<stdio.h>

#include<string>

#include<stdlib.h>

#include<math.h>

#include<queue>

#include<algorithm>

using namespace std;

int n;

char x[5010];

int y[5010][5010];

int main()

{

	int i,k,max=0;

	cin>>n;

	cin>>x;

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

		for(k=1;k<=n;k++)

		{

			if(i==k)

				continue;

			if(x[i-1]==x[k-1])

				y[i][k]=1+y[i-1][k-1];

			if(y[i][k]>max&&i<k-y[i][k]+1)

				max=y[i][k];

		}

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

	return 0;

}