Language: C++

#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
typedef long long int ll;
using namespace std;

#define MOD 1000000007
ll extgcd(ll a, ll b, ll &x, ll &y) {
  ll g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
ll gcd(ll a, ll b) { ll x, y; return extgcd(a, b, x, y);}

class llm{
	ll n;
public:
	llm(){n = 0;}
	llm(ll n){this->n = (n >= 0) ? (n % MOD) : (MOD - 1 - (-n-1 % MOD));}
	operator ll() const {return n;}
	llm operator+(const llm &y) const{ return llm((ll)*this + (ll)y);}
	llm operator+=(const llm &y) { *this = *this + y; return *this;}
	llm operator-(const llm &y) const{ return llm((ll)*this - (ll)y);}
	llm operator-=(const llm &y) { *this = *this - y; return *this;}
	llm operator-() const{ return llm(0) - *this;}
	llm operator*(const llm &y) const{ return llm((ll)*this * (ll)y);}
	llm operator*=(const llm &y) { *this = *this * y; return *this;}
	llm operator/(const llm &y) const{ return *this * y.inv();}
	llm operator/=(const llm &y) { *this = *this / y; return *this;}
	llm inv() const{
		ll x, y;
		if (extgcd(n, MOD, x, y) == 1) return llm(x);
  		return llm(0); // unsolvable
	}
	friend istream& operator >> (istream& os, llm& x);
	friend ostream& operator << (ostream& os, const llm& x);
};
istream& operator >> (istream& is, llm& x){ll n; is >> n; x = llm(n); return is;}
ostream& operator << (ostream& os, const llm& x){os << (ll)x; return os;}

template<typename T> T comb(ll n, ll k){
	T ret = 1;
	for(ll i=1;i<=k;i++) ret = ret * T(n - k + i) / T(i);
	return ret;
}
ll n; string s;

class RollingHash{
  /*
    // class llm の定義が必要． 
  	auto rh = RollingHash("abcdedede");
    assert(rh.hash(3, 5) == rh.hash(5, 7));
  */
public:
  llm base = llm(256); // 文字コードの最大値より大きい必要あり．
  string s = "";
  ll n = 0;
  vector<llm> power, invPower, cumsum;
  RollingHash(){}
  RollingHash(string s){
    this->s = s;
    this->n = s.size();
    power = vector<llm>(n);
    power[0] = llm(1);
    for(int i=1;i<n;i++){
      power[i] = power[i-1] * base;
    }
    invPower = vector<llm>(n);
    invPower[0] = llm(1);
    llm invBase = llm(1) / base;
    for(int i=1;i<n;i++){
      invPower[i] = invPower[i-1] * invBase;
    }
    cumsum = vector<llm>(n + 1);
    for(int i=0;i<n;i++){
      cumsum[i+1] = cumsum[i] + power[i] * llm((ll)s[i]);
    }
  }
  llm hash(ll st, ll ed){
    st = min(max(st, 0), n-1);
    ed = max(min(ed, s.size()), st);
    return (cumsum[ed] - cumsum[st]) * invPower[st];
  }
};

RollingHash rh;

bool isOK(ll len){
  for(int i=0;i+len<=n;i++){
    for(int j=i+len;j+len<=n;j++){
      if (rh.hash(i, i+len) == rh.hash(j, j+len)) return true;
    }
  }
  return false;
}

ll binarySearch() {
    ll ok = 0;
    ll ng = n / 2 + 1;
    while (llabs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (isOK(mid)) ok = mid;
        else ng = mid;
    }
    return ok; // Returns most extreme ok index
}

int main(){
  cin >> n; cin >> s;
  rh = RollingHash(s);
  
  cout << binarySearch() << endl;
  
  return 0;
}
  

Compiler output:
a.cc: In member function 'llm RollingHash::hash(ll, ll)':
a.cc:80:17: error: no matching function for call to 'max(ll&, int)'
   80 |     st = min(max(st, 0), n-1);
      |              ~~~^~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:80:17: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   80 |     st = min(max(st, 0), n-1);
      |              ~~~^~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:80:17: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   80 |     st = min(max(st, 0), n-1);
      |              ~~~^~~~~~~
a.cc:81:17: error: no matching function for call to 'min(ll&, std::__cxx11::basic_string<char>::size_type)'
   81 |     ed = max(min(ed, s.size()), st);
      |              ~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:81:17: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'})
   81 |     ed = max(min(ed, s.size()), st);
      |              ~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:81:17: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   81 |     ed = max(min(ed, s.size()), st);
      |              ~~~^~~~~~~~~~~~~~