Language: C++

#include<bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end());
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
template<typename T1, typename T2> inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> inline bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct Setup {
    static constexpr int PREC = 20;
    Setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

struct RollingHash {
    using ull=unsigned long long;
    static constexpr ull MASK30 = (1ULL << 30) - 1;
    static constexpr ull MASK31 = (1ULL << 31) - 1;
    static constexpr ull MOD = (1ULL << 61) - 1;
    static constexpr ull POSITIVIZER = MOD * 4;
    static const ull B0, B1;
    static const std::random_device rng;
    static std::vector<ull> powB0, powB1;
    const int n;
    std::vector<ull> h0{0}, h1{0};
    ull mul(ull a, ull b) const {
        ull au = a >> 31;
        ull ad = a & MASK31;
        ull bu = b >> 31;
        ull bd = b & MASK31;
        ull mid = ad * bu + au * bd;
        return au * bu * 2 + (mid >> 30) + ((mid & MASK30) << 31) + ad * bd;
    }
    template<typename Itr> RollingHash(Itr begin, Itr end): n(end - begin) {
        for (auto itr = begin; itr != end; itr++) {
            h0.push_back((mul(h0.back(), B0) + *itr) % MOD);
            h1.push_back((mul(h1.back(), B1) + *itr) % MOD);
        }
        while (powB0.size() <= n) {
            powB0.push_back(mul(powB0.back(), B0) % MOD);
            powB1.push_back(mul(powB1.back(), B1) % MOD);
        }
    }
    std::pair<ull, ull> get(int l, int r) const {
        return {(h0[r] + POSITIVIZER - mul(h0[l], powB0[r - l])) % MOD,
                (h1[r] + POSITIVIZER - mul(h1[l], powB1[r - l])) % MOD};
    }
};
const std::random_device RollingHash::rng;
const RollingHash::ull RollingHash::B0 = std::uniform_int_distribution<ull>(1, (MOD >> 1) - 1)(rng);
const RollingHash::ull RollingHash::B1 = std::uniform_int_distribution<ull>(MOD >> 1, MOD - 1)(rng);
std::vector<RollingHash::ull> RollingHash::powB0{1};
std::vector<RollingHash::ull> RollingHash::powB1{1};

long long binarySearch(long long ok, long long ng, std::function<bool(int)> check) {
    while (abs(ok - ng) > 1) {
        long long mid = ok + ng >> 1;
        (check(mid) ? ok : ng) = mid;
    }
    return ok;
}

int N;
string S;
signed main() {
    cin >> N >> S;
    RollingHash rh(all(S));
    cout << binarySearch(0, N + 1, [&](int x) {
        rep(i, N - x + 1) {
            for (int j = i + x; j < N - x + 1; j++) {
                if (rh.get(i, i + x) == rh.get(j, j + x)) { return true; }
            }
        }
        return false;
    }) << endl;
}

Compiler output:
In file included from /usr/include/c++/14/bits/stl_algo.h:65,
                 from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/uniform_int_dist.h: In instantiation of 'std::uniform_int_distribution<_IntType>::result_type std::uniform_int_distribution<_IntType>::operator()(_UniformRandomBitGenerator&, const param_type&) [with _UniformRandomBitGenerator = const std::random_device; _IntType = long long unsigned int; result_type = long long unsigned int]':
/usr/include/c++/14/bits/uniform_int_dist.h:204:34:   required from 'std::uniform_int_distribution<_IntType>::result_type std::uniform_int_distribution<_IntType>::operator()(_UniformRandomBitGenerator&) [with _UniformRandomBitGenerator = const std::random_device; _IntType = long long unsigned int; result_type = long long unsigned int]'
  204 |         { return this->operator()(__urng, _M_param); }
      |                  ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
a.cc:91:95:   required from here
   91 | const RollingHash::ull RollingHash::B0 = std::uniform_int_distribution<ull>(1, (MOD >> 1) - 1)(rng);
      |                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/uniform_int_dist.h:365:49: error: no match for call to '(const std::random_device) ()'
  365 |                 __ret = __tmp + (__uctype(__urng()) - __urngmin);
      |                                           ~~~~~~^~
In file included from /usr/include/c++/14/random:48,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:179:
/usr/include/c++/14/bits/random.h:1781:5: note: candidate: 'std::random_device::result_type std::random_device::operator()()' (near match)
 1781 |     operator()()
      |     ^~~~~~~~
/usr/include/c++/14/bits/random.h:1781:5: note:   passing 'const std::random_device*' as 'this' argument discards qualifiers
/usr/include/c++/14/bits/uniform_int_dist.h:370:34: error: no match for call to '(const std::random_device) ()'
  370 |           __ret = __uctype(__urng()) - __urngmin;
      |                            ~~~~~~^~
/usr/include/c++/14/bits/random.h:1781:5: note: candidate: 'std::random_device::result_type std::random_device::operator()()' (near match)
 1781 |     operator()()
      |     ^~~~~~~~
/usr/include/c++/14/bits/random.h:1781:5: note:   passing 'const std::random_device*' as 'this' argument discards qualifiers
/usr/include/c++/14/bits/uniform_int_dist.h: In instantiation of 'static _Up std::uniform_int_distribution<_IntType>::_S_nd(_Urbg&, _Up) [with _Wp = long unsigned int; _Urbg = const std::random_device; _Up = unsigned int; _IntType = long long unsigned int]':
/usr/include/c++/14/bits/uniform_int_dist.h:328:33:   required from 'std::uniform_int_distribution<_IntType>::result_type std::uniform_int_distribution<_IntType>::operator()(_UniformRandomBitGenerator&, const param_type&) [with _UniformRandomBitGenerator = const std::random_device; _IntType = long long unsigned int; result_type = long long unsigned int]'
  328 |                 __ret = _S_nd<__UINT64_TYPE__>(__urng, __u32erange);
      |                         ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/uniform_int_dist.h:204:34:   required from 'std::uniform_int_distribution<_IntType>::result_type std::uniform_int_distribution<_IntType>::operator()(_UniformRandomBitGenerator&) [with _UniformRandomBitGenerator = const std::random_device; _IntType = long long unsigned int; result_type = long long unsigned int]'
  204 |         { return this->operator()(__urng, _M_param); }
      |                  ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
a.cc:91:95:   required from here
   91 | const RollingHash::ull RollingHash::B0 = std::uniform_int_distribution<ull>(1, (MOD >> 1) - 1)(rng);
      |                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/uniform_int_dist.h:269:34: error: no match for call to '(const std::random_device) ()'
  269 |           _Wp __product = _Wp(__g()) * _Wp(__range);
      |                               ~~~^~
/usr/include/c++/14/bits/random.h:1781:5: note: candidate: 'std::random_device::result_type std::random_device::operator()()' (near match)
 1781 |     operator()()
      |     ^~~~~~~~
/usr/include/c++/14/bits/random.h:1781:5: note:   passing 'const std::random_device*' as 'this' argument discards qualifiers
/usr/include/c++/14/bits/uniform_int_dist.h:276:38: error: no match for call to '(const std::random_device) ()'
  276 |                   __product = _Wp(__g()) * _Wp(__range);
      |                                   ~~~^~
/usr/include/c++/14/bits/random.h:1781:5: note: candidate: 'std::random_device::result_type std::random_device::operator()()' (near match)
 1781 |     operator()()
      |     ^~~~~~~~
/usr/include/c++/14/bits/random.h:1781:5: note:   passing 'const std::random_device*' as 'this' argument discards qualifiers