Language: C++

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll unsigned long long
using namespace std;
int n,ans;
ll hash[5010],pow[5010];
char s[5010];
inline bool check(int len){
	bool flag=1;ll tmp1,tmp2;
	for(register int i=1;i<=n-len*2;i++){
		tmp1=hash[i+len]-hash[i]*pow[len];
		for(register int j=i+len;j+len<=n;j++){
			tmp2=hash[j+len]-hash[j]*pow[len];
			if(tmp1==tmp2){
				flag=0;return true;
			}
		}
	}
	return false;
}
inline void binary(int le,int ri){
	while(le<=ri){
		int mid=(le+ri)>>1;
		if(check(mid)){
			ans=mid;le=mid+1;
		}
		else{
			ri=mid-1;
		}
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n;scanf("%s",s+1);
	pow[0]=1;for(register int i=1;i<=5000;i++) pow[i]=pow[i-1]*131;
	for(register int i=1;i<=strlen(s+1);i++) hash[i]=hash[i-1]*131+s[i]-'a'+1;
	binary(0,n); 
	cout<<ans<<endl;
}

Compiler output:
a.cc:8:15: warning: built-in function 'pow' declared as non-function [-Wbuiltin-declaration-mismatch]
    8 | ll hash[5010],pow[5010];
      |               ^~~
a.cc: In function 'bool check(int)':
a.cc:12:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   12 |         for(register int i=1;i<=n-len*2;i++){
      |                          ^
a.cc:13:22: error: reference to 'hash' is ambiguous
   13 |                 tmp1=hash[i+len]-hash[i]*pow[len];
      |                      ^~~~
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: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:8:4: note:                 'long long unsigned int hash [5010]'
    8 | ll hash[5010],pow[5010];
      |    ^~~~
a.cc:13:34: error: reference to 'hash' is ambiguous
   13 |                 tmp1=hash[i+len]-hash[i]*pow[len];
      |                                  ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:8:4: note:                 'long long unsigned int hash [5010]'
    8 | ll hash[5010],pow[5010];
      |    ^~~~
a.cc:14:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   14 |                 for(register int j=i+len;j+len<=n;j++){
      |                                  ^
a.cc:15:30: error: reference to 'hash' is ambiguous
   15 |                         tmp2=hash[j+len]-hash[j]*pow[len];
      |                              ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:8:4: note:                 'long long unsigned int hash [5010]'
    8 | ll hash[5010],pow[5010];
      |    ^~~~
a.cc:15:42: error: reference to 'hash' is ambiguous
   15 |                         tmp2=hash[j+len]-hash[j]*pow[len];
      |                                          ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:8:4: note:                 'long long unsigned int hash [5010]'
    8 | ll hash[5010],pow[5010];
      |    ^~~~
a.cc: In function 'int main()':
a.cc:37:35: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   37 |         pow[0]=1;for(register int i=1;i<=5000;i++) pow[i]=pow[i-1]*131;
      |                                   ^
a.cc:38:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   38 |         for(register int i=1;i<=strlen(s+1);i++) hash[i]=hash[i-1]*131+s[i]-'a'+1;
      |                          ^
a.cc:38:50: error: reference to 'hash' is ambiguous
   38 |         for(register int i=1;i<=strlen(s+1);i++) hash[i]=hash[i-1]*131+s[i]-'a'+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:8:4: note:                 'long long unsigned int hash [5010]'
    8 | ll hash[5010],pow[5010];
      |    ^~~~
a.cc:38:58: error: reference to 'hash' is ambiguous
   38 |         for(register int i=1;i<=strlen(s+1);i++) hash[i]=hash[i-1]*131+s[i]-'a'+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:8:4: note:                 'long long unsigned int hash [5010]'
    8 | ll hash[5010],pow[5010];
      |    ^~~~