Language: C++

#include <bits/stdc++.h>
#define off  exit( 0 )
#define cn   continue
#define rt   return
#define sc   scanf
#define pr   printf
#define pb   push_back
#define pf   push_front
#define p_f  pop_front
#define p_b  pop_back
#define ff   first
#define ss   second
#define ll   long long
#define ld   long double
#define N    5256
#define M    1000000007
#define I    1000000000000000000
#define pdd  pair < ld, ld >
#define pll  pair < ll, ll >
#define pii  pair < int, int >
#define sqr( a )           a * a
#define all( c )           c.begin(), c.end()
#define srt( c )           sort( all( c ) )
#define rev( c )           reverse( all( c ) )
#define srtr( c )          sort( c.rbegin(), c.rend() );

using namespace std;
ll n;
string s;
ll h[N][N];
map < ll, bool > m;
bool ok;
void solve()
{
    cin >> n >> s;
    for( int i = 0; i < n; i ++ )
    {
        h[i][i] = s[i] - 'a' + 1;
        for( int j = i + 1; j < n; j ++ )
            h[i][j] = ( ( h[i][j-1] * 31LL ) + ( s[j] - 'a' + 1LL ) ) % M;
    }
    ll l = 1, r = n - 1, ans = 0;
    while( l <= r )
    {
        ll len = l + r >> 1;
        ok = 0;
        m.clear();
        for( int i = 0; i + len - 1 < n; i ++ )
        {
            if( m[ h[i][i + len - 1] ] )
            {
                ok = 1;
                break;
            }
            if( i - len + 1 >= 0 )
                m[ h[i + len - 1] ][i] = 1;
        }
        if( ok )
        {
            l = len + 1;
            ans = l;
        }
        else r = len - 1;
    }
    cout << ans;
}

int main()
{
    int tt = 1;
    //sc( "%d", &tt );
    for( int i = 1; i <= tt; i ++ )
        solve();
}












Compiler output:
a.cc: In function 'void solve()':
a.cc:56:18: error: ambiguous overload for 'operator[]' (operand types are 'std::map<long long int, bool>' and 'long long int [5256]')
   56 |                 m[ h[i + len - 1] ][i] = 1;
      |                  ^
In file included from /usr/include/c++/14/map:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_map.h:504:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = long long int; _Tp = bool; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, bool> >; mapped_type = bool; key_type = long long int]' (near match)
  504 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:504:7: note:   conversion of argument 1 would be ill-formed:
a.cc:56:33: error: invalid conversion from 'long long int*' to 'std::map<long long int, bool>::key_type' {aka 'long long int'} [-fpermissive]
   56 |                 m[ h[i + len - 1] ][i] = 1;
      |                    ~~~~~~~~~~~~~^
      |                                 |
      |                                 long long int*
/usr/include/c++/14/bits/stl_map.h:524:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](key_type&&) [with _Key = long long int; _Tp = bool; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, bool> >; mapped_type = bool; key_type = long long int]' (near match)
  524 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:524:7: note:   conversion of argument 1 would be ill-formed:
a.cc:56:33: error: invalid conversion from 'long long int*' to 'std::map<long long int, bool>::key_type' {aka 'long long int'} [-fpermissive]
   56 |                 m[ h[i + len - 1] ][i] = 1;
      |                    ~~~~~~~~~~~~~^
      |                                 |
      |                                 long long int*