Language: C++

//order_of_key(k): Number of items strictly smaller than k .
//find_by_order(k): K-th element in a set (counting from zero).
#include <iostream>
//#include <ext/pb_ds/assoc_container.hpp>

#define full(x,n) x,x+n+1
#define full(x) x.begin(),x.end()
#define finish return 0

#define putb push_back
#define f first
#define s second

//logx(a^n)=loga(a^n)/logx(a)
//logx(a*b)=logx(a)+logx(b)
//logx(y)=log(y)/log(x)

#define ordered_set tree<ll,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define putf push_front
#define gainb pop_back

#define gainf pop_front
#define len(x) (ll)x.size()

// 1/b%mod=b^(m-2)%mod
// (a>>x)&1==0

typedef double db;
typedef long long ll;

const ll ary=5e3+5;
const ll mod=1e9+7;
const ll inf=1e18;

using namespace std;
using namespace __gnu_pbds;
ll n,h[ary],bp[ary],p=31;
string s;
ll hash(ll l,ll r){
	return (h[r]-(h[l-1]*bp[r-l+1]%mod)+mod)%mod;
}
ll ch(ll k){
	for(int i=0;i<len(s);i++){
		if(i+k-1>=len(s)){
			break;
		}
		for(int j=i+k;j<len(s);j++){
			if(j+k-1>=len(s)){
				break;
			}
			if(hash(i,i+k-1)==hash(j,j+k-1)){
				return 1;
			}
		}
	}
	return 0;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	bp[0]=1;
	for(int i=1;i<=ary-5;i++){
		bp[i]=bp[i-1]*p;
		bp[i]%=mod;
	}
	cin>>n>>s;
	for(int i=0;i<len(s);i++){
		h[i]=s[i];
		if(i){
			h[i]+=(h[i-1]*p);
		}
		h[i]%=mod;
	}
	ll l=1,r=n,ans=0;
	while(l<=r){
		ll m=(l+r)/2;
		if(ch(m)){
			l=m+1;
			ans=m;
		}
		else{
			r=m-1;
		}
	}
	cout<<ans;
}

Compiler output:
a.cc:7:9: warning: "full" redefined
    7 | #define full(x) x.begin(),x.end()
      |         ^~~~
a.cc:6:9: note: this is the location of the previous definition
    6 | #define full(x,n) x,x+n+1
      |         ^~~~
a.cc:36:17: error: '__gnu_pbds' is not a namespace-name
   36 | using namespace __gnu_pbds;
      |                 ^~~~~~~~~~
a.cc: In function 'll ch(ll)':
a.cc:51:28: error: reference to 'hash' is ambiguous
   51 |                         if(hash(i,i+k-1)==hash(j,j+k-1)){
      |                            ^~~~
In file included from /usr/include/c++/14/string_view:50,
                 from /usr/include/c++/14/bits/basic_string.h:47,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:3:
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:39:4: note:                 'll hash(ll, ll)'
   39 | ll hash(ll l,ll r){
      |    ^~~~
a.cc:51:43: error: reference to 'hash' is ambiguous
   51 |                         if(hash(i,i+k-1)==hash(j,j+k-1)){
      |                                           ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:39:4: note:                 'll hash(ll, ll)'
   39 | ll hash(ll l,ll r){
      |    ^~~~