Language: C++

#include "bits/stdc++.h"
#include <random>
#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

constexpr int dx[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
constexpr int dy[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
// verified: http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3381829
// moda, modb は桁数増やした方が良いかも.
using namespace std;
class RollingHash {
  using ull = uint64_t;
  int n;
  mt19937 rand_src(std::random_device{}());
  static const ull moda = (ull)1e9 + 7;
  static const ull modb = (ull)1e9 + 9;
  // static const ull b1 = (ull)17, b2 = (ull)19;
  ull b1 = (ull)rnd.randInt(2, 114514), b2 = (ull)rnd.randInt(2, 114514);
  std::vector<ull> a, b, p, q;

public:
  RollingHash(const std::string& str) : n((int)str.size()), a(n + 1, 0), b(n + 1, 0), p(n + 1, 1), q(n + 1, 1) {
    for (int i = 0; i < n; i++) {
      a[i + 1] = (a[i] * b1 + ull(str[i])) % moda;
      b[i + 1] = (b[i] * b2 + ull(str[i])) % modb;
      p[i + 1] = p[i] * b1 % moda;
      q[i + 1] = q[i] * b2 % modb;
    }
  }
  // [l, r) のハッシュ値を取得
  std::pair<ull, ull> query(int l, int r) {
    assert(0 <= l && l <= r && r <= n);
    ull h1 = (p[r - l] * a[l] - a[r] + moda) % moda;
    ull h2 = (q[r - l] * b[l] - b[r] + modb) % modb;
    return std::make_pair(h1, h2);
  }
};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  string s; cin >> s;
  RollingHash h(s);
  using ull = uint64_t;
  map< pair<ull, ull>, int> a, b, c;
  REP(i, n)FOR(j, i, n) {
    auto d = h.query(i, j + 1);
    if (a.count(d)) {
      a[d] = min((int)i, a[d]);
    }
    else {
      a[d] = i;
    }
    if (b.count(d)) {
      b[d] = max((int)i, b[d]);
    }
    else {
      b[d] = i;
    }
    c[d] = j - i + 1;
  }
  int ans = 0;
  for (auto d : c) {
    auto p = d.first;
    if (b[p] - a[p] >= d.second)ans = max(ans, d.second);
  }
  cout << ans << endl;
}


Compiler output:
a.cc:46:38: error: expected ')' before '{' token
   46 |   mt19937 rand_src(std::random_device{}());
      |                   ~                  ^
      |                                      )
a.cc:46:41: error: expected unqualified-id before ')' token
   46 |   mt19937 rand_src(std::random_device{}());
      |                                         ^
a.cc:50:17: error: 'rnd' was not declared in this scope; did you mean 'rand'?
   50 |   ull b1 = (ull)rnd.randInt(2, 114514), b2 = (ull)rnd.randInt(2, 114514);
      |                 ^~~
      |                 rand
a.cc:50:51: error: 'rnd' was not declared in this scope; did you mean 'rand'?
   50 |   ull b1 = (ull)rnd.randInt(2, 114514), b2 = (ull)rnd.randInt(2, 114514);
      |                                                   ^~~
      |                                                   rand
a.cc: In member function 'std::mt19937 RollingHash::rand_src(std::random_device)':
a.cc:46:39: warning: no return statement in function returning non-void [-Wreturn-type]
   46 |   mt19937 rand_src(std::random_device{}());
      |                                       ^