///wrong ans:01-handmade-08 still wrong WHY???
/***
##########
***
18
xyzxyzxyzxyzxyzxyz


ans= 9 hobe;

but ans=3 ashtese

15
xyzxyzxyzxyzxyz

ans= 3

##
vital case:
7
aaaaaaa

ans= 1 ashtese ; but actually ans= 3

##
vital case 2:
10
aaaabbbbbb

ans=1 ashe ; but ans= 3 must be

##
************
this is the case:
9
bbbbbbbbc
ans= 4 sure

but ans=1 ashtese

*/

#include<bits/stdc++.h>

using namespace std;
#define ll long long

void computeLPSArray(string str, int M, int lps[])
{
	int len = 0; //lenght of the previous longest prefix suffix
	int i;

	lps[0] = 0; //lps[0] is always 0
	i = 1;

	// the loop calculates lps[i] for i = 1 to M-1
	while (i < M)
	{
	if (str[i] == str[len])
	{
		len++;
		lps[i] = len;
		i++;
	}
	else // (pat[i] != pat[len])
	{
		if (len != 0)
		{
			// This is tricky. Consider the example AAACAAAA
			// and i = 7.
			len = lps[len-1];

			// Also, note that we do not increment i here
		}
		else // if (len == 0)
		{
			lps[i] = 0;
			i++;
		}
	}
	}
}

// Returns true if str is repetition of one of its substrings
// else return false.
int isRepeat(string str)
{
	// Find length of string and create an array to
	// store lps values used in KMP
	//int n = strlen(str);
	int n= str.size();
	int lps[n];

	// Preprocess the pattern (calculate lps[] array)
	computeLPSArray(str, n, lps);

	// Find length of longest suffix which is also
	// prefix of str.
	int len = lps[n-1];

	// If there exist a suffix which is also prefix AND
	// Length of the remaining substring divides total
	// length, then str[0..n-len-1] is the substring that
	// repeats n/(n-len) times (Readers can print substring
	// and value of n/(n-len) for more clarity.
	return (len > 0 && n%(n-len) == 0)? (n/(n-len)): -1;
}

ll zAlgo(string str, ll*z,ll n)
{
    ll len=isRepeat(str);
    ll eachLen= n/len;
    ll len2=0;
    if(len!=-1)
    {
        len2= (len/2)*eachLen;

    }





    ///n= length of z array = length of string
    ll L=0;
    ll R=0;
    for(ll i=1; i<n; i++)
    {
//        if(z[i]==i){
//                ///for eg, abcdabcdabcd; Now pos i=8 how uchit
//                ///because "abcdabcd" is both prefix and suffix
//                ///from ith pos but overlap ; so i=5 e max value possible=4
//
//                //z[i]--;
//                continue;
//        }



        if(i>R)
        {
            ///then i is OUTSIDE of Z BOX

            ///******THese part of code is whenever a new z box is created
            L= R=i;
            while(R<n && str[R-L]== str[R])
            {
                R++;
            }
            z[i]= R-L; ///Length= 8-4= 4
            ///but R= 7 hobe
            R--;
            ///********************************
        }
        else{
            ll k=i-L;
            ll val= z[k];
            if(i+val<=R){
                ///then Z box er modhdhei thakbe ; so z[k] i answer
                z[i]= z[k];

            }
            else{
                ///same code as if i>R
                ///*****
                L=R=i;
                while(R<n && str[R-L]== str[R])
                {
                    R++;
                }
                z[i]= R-L; ///Length= 8-4= 4
                ///but R= 7 hobe
                R--;
                ///******
            }

        }
        ///cout<<"z[i]="<<z[i]<<"\ti="<<i<<"\n";
        z[i]= min(z[i],i);
        ///***New condition ; so that no overlapping ; eg ababa

    }
    ll maxLen= 0;

    for(ll i=1; i<n; i++)
    {
        if(z[i]>maxLen) maxLen= z[i];

        ///if(z[i]==len) cnt++;
    }

    return max(maxLen, len2);



}







int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll len;
    cin>>len;
    string str;
    cin>>str;


    ll ans=0;
    for(ll i=0; i<len; i++)
    {
        ll n= len-i;
        string r = str.substr(i, n);
        ///string substr (size_t pos, size_t len) const;
        ll *z=new ll[n];
        int zLen=zAlgo(r, z, n);
        if(ans<zLen) ans= zLen;

        ///cout<<"zLen="<<zLen<<"\n";

    }
    cout<<ans<<"\n";





    return 0;

}



Measured memory_bytes: 98048