Language: C++

#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <tuple>
#include <ctime>
#include <map>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr r, l;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

template <class T>
class hash_string {
public:
  using mod_type = unsigned long long;
  using base_type = unsigned;
  using size_type = unsigned;
  static constexpr mod_type mod = (1ll << 61) - 1;
  static base_type base() { return T::value; }

private:
  std::string M_string;
  std::vector<mod_type> M_power, M_hash;

public:
  hash_string() { init(); }
  hash_string(const std::string &initial_) { init(initial_);}

  void init() {
    M_string = "";
    M_power.assign(1, 1);
    M_hash.assign(1, 0);
  }
  void init(const std::string &initial_) {
    init();
    add_string(initial_);
  }

  void add_string(const std::string &str) {
    size_type cur_size = M_string.size();
    size_type next_size = M_string.size() + str.size();
    M_string += str;
    M_power.resize(next_size + 1);
    M_hash.resize(next_size + 1);
    for (size_type i = cur_size; i < next_size; ++i) {
      M_power[i + 1] = (__uint128_t) M_power[i] * base() % mod;
      M_hash[i + 1] = ((__uint128_t) M_hash[i] * base() + M_string[i])% mod;
    }
  }

  size_type size() const {
    return M_string.size();
  }
  bool empty() const {
    return M_string.size();
  }
  const std::string &get() const {
    return M_string;
  }
  
  mod_type hash(size_type l, size_type r) const {
    return (M_hash[r] + mod - ((__uint128_t) M_power[r - l] * M_hash[l]) % mod) % mod;
  }
  size_type lcp(size_type l, size_type r) const {
    size_type ok = 0, ng = std::min(M_string.size() - l, M_string.size() - r) + 1;
    while (ng - ok > 1) {
      size_type md = (ok + ng) >> 1;
      (hash(l, l + md) == hash(r, r + md) ? ok : ng) = md;
    }
    return ok;
  }

};

struct rolling_hash_base { static const unsigned value = 869120; };
using rolling_hash = hash_string<rolling_hash_base>;

int main() {
  int N;
  std::string S;
  std::cin >> N >> S;
  rolling_hash rh(S);
  auto check = [&](int d){
    std::unordered_map<unsigned long long, std::vector<int>> map;
    for (int i: range(0, N - d + 1)) {
      map[rh.hash(i, i + d)].push_back(i);
    }
    for (const auto &x: map) {
      if (x.second.back() - x.second.front() >= d) {
        return true;
      }
    }
    return false;
  };
  int ok = 0, ng = S.size();
  while (ng - ok > 1) {
    int md = (ok + ng) >> 1;
    (check(md) ? ok : ng) = md;
  }
  std::cout << ok << '\n';
  return 0;
}


Compiler output:
a.cc: In lambda function:
a.cc:130:10: error: 'unordered_map' is not a member of 'std'
  130 |     std::unordered_map<unsigned long long, std::vector<int>> map;
      |          ^~~~~~~~~~~~~
a.cc:9:1: note: 'std::unordered_map' is defined in header '<unordered_map>'; this is probably fixable by adding '#include <unordered_map>'
    8 | #include <map>
  +++ |+#include <unordered_map>
    9 | 
a.cc:130:24: error: expected primary-expression before 'unsigned'
  130 |     std::unordered_map<unsigned long long, std::vector<int>> map;
      |                        ^~~~~~~~
a.cc:132:7: error: 'map' was not declared in this scope
  132 |       map[rh.hash(i, i + d)].push_back(i);
      |       ^~~
a.cc:132:7: note: suggested alternatives:
In file included from /usr/include/c++/14/map:63,
                 from a.cc:8:
/usr/include/c++/14/bits/stl_map.h:102:11: note:   'std::map'
  102 |     class map
      |           ^~~
/usr/include/c++/14/map:89:13: note:   'std::pmr::map'
   89 |       using map
      |             ^~~
a.cc:134:25: error: 'map' was not declared in this scope
  134 |     for (const auto &x: map) {
      |                         ^~~
a.cc:134:25: note: suggested alternatives:
/usr/include/c++/14/bits/stl_map.h:102:11: note:   'std::map'
  102 |     class map
      |           ^~~
/usr/include/c++/14/map:89:13: note:   'std::pmr::map'
   89 |       using map
      |             ^~~