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 long long int ary=5e3+5;
const long long int mod=1e9+7;
//const ll inf=1e18;

using namespace std;
//using namespace __gnu_pbds;
long long int n,h[ary],bp[ary],p=31;
string s;
long long int hash(long long int l,long long int r){
	return (h[r]-(h[l-1]*bp[r-l+1]%mod)+mod)%mod;
}
bool ch(long long int k){
	for(int i=0;i<s.size();i++){
		if(i+k-1>=s.size()){
			break;
		}
		for(int j=i+k;j<s.size();j++){
			if(j+k-1>=s.size()){
				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<s.size();i++){
		h[i]=s[i];
		if(i){
			h[i]+=(h[i-1]*p);
		}
		h[i]%=mod;
	}
	long long int l=1,r=n,ans=0;
	while(l<=r){
		long long int m=(l+r)/2;
		if(ch(m)){
			l=m+1;
			ans=m;
		}
		else{
			r=m-1;
		}
	}
	cout<<ans;
}

Compiler output:
a.cc: In function 'bool ch(long long int)':
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:15: note:                 'long long int hash(long long int, long long int)'
   39 | long long int hash(long long int l,long long int 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:15: note:                 'long long int hash(long long int, long long int)'
   39 | long long int hash(long long int l,long long int r){
      |               ^~~~