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 ull=unsigned long long;
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 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 << 1) + (mid >> 30) + ((mid & MASK30) << 31) + ad * bd;
    }
    ull calcMod(ull val) const {
        val = (val & MOD) + (val >> 61);
        if (val > MOD) { val -= MOD; }
        return val;
    }
    template<typename Itr> RollingHash(Itr begin, Itr end): n(end - begin) {
        for (auto itr = begin; itr != end; itr++) {
            h0.push_back(calcMod((mul(h0.back(), B0) + *itr)));
            h1.push_back(calcMod((mul(h1.back(), B1) + *itr)));
        }
        while (powB0.size() <= n) {
            powB0.push_back(calcMod(mul(powB0.back(), B0)));
            powB1.push_back(calcMod(mul(powB1.back(), B1)));
        }
    }
    std::pair<ull, ull> get(int l, int r) const {
        return {calcMod((h0[r] + POSITIVIZER - mul(h0[l], powB0[r - l]))),
                0};
    }
};
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));
    for (int x = N / 2; x >= 0; x--) {
        unordered_map<pair<ull, ull>, int> mp;
        rep(i, N - x + 1) {
            auto cur = rh.get(i, i + x);
            if (mp.count(cur) != 0) {
                if (mp[cur] <= i - x) {
                    cout << x << endl;
                    return 0;
                }
            }
            else { mp[cur] = i; }
        }
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:116:44: error: use of deleted function 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map() [with _Key = std::pair<long long unsigned int, long long unsigned int>; _Tp = long long int; _Hash = std::hash<std::pair<long long unsigned int, long long unsigned int> >; _Pred = std::equal_to<std::pair<long long unsigned int, long long unsigned int> >; _Alloc = std::allocator<std::pair<const std::pair<long long unsigned int, long long unsigned int>, long long int> >]'
  116 |         unordered_map<pair<ull, ull>, int> mp;
      |                                            ^~
In file included from /usr/include/c++/14/unordered_map:41,
                 from /usr/include/c++/14/functional:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/unordered_map.h:148:7: note: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map() [with _Key = std::pair<long long unsigned int, long long unsigned int>; _Tp = long long int; _Hash = std::hash<std::pair<long long unsigned int, long long unsigned int> >; _Pred = std::equal_to<std::pair<long long unsigned int, long long unsigned int> >; _Alloc = std::allocator<std::pair<const std::pair<long long unsigned int, long long unsigned int>, long long int> >]' is implicitly deleted because the default definition would be ill-formed:
  148 |       unordered_map() = default;
      |       ^~~~~~~~~~~~~
/usr/include/c++/14/bits/unordered_map.h: At global scope:
/usr/include/c++/14/bits/unordered_map.h:148:7: error: use of deleted function 'std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = std::pair<long long unsigned int, long long unsigned int>; _Value = std::pair<const std::pair<long long unsigned int, long long unsigned int>, long long int>; _Alloc = std::allocator<std::pair<const std::pair<long long unsigned int, long long unsigned int>, long long int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::pair<long long unsigned int, long long unsigned int> >; _Hash = std::hash<std::pair<long long unsigned int, long long unsigned int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>]'
In file included from /usr/include/c++/14/bits/unordered_map.h:33:
/usr/include/c++/14/bits/hashtable.h:539:7: note: 'std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = std::pair<long long unsigned int, long long unsigned int>; _Value = std::pair<const std::pair<long long unsigned int, long long unsigned int>, long long int>; _Alloc = std::allocator<std::pair<const std::pair<long long unsigned int, long long unsigned int>, long long int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::pair<long long unsigned int, long long unsigned int> >; _Hash = std::hash<std::pair<long long unsigned int, long long unsigned int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>]' is implicitly deleted because the default definition would be ill-formed:
  539 |       _Hashtable() = default;
      |       ^~~~~~~~~~
/usr/include/c++/14/bits/hashtable.h:539:7: error: use of deleted function 'std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_Hashtable_base() [with _Key = std::pair<long long unsigned int, long long unsigned int>; _Value = std::pair<const std::pair<long long unsigned int, long long unsigned int>, long long int>; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::pair<long long unsigned int, long long unsigned int> >; _Hash = std::hash<std::pair<long long unsigned int, long long unsigned int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, false, true>]'
In file included from /usr/include/c++/14/bits/hashtable.h:35:
/usr/include/c++/14/bits/hashtable_policy.h:1731:7: note: 'std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_Hashtable_base() [with _Key = std::pair<long long unsigned int, long long unsigned int>; _Value = std::pair<const std::pair<long long unsigned int, long long unsigned int>, long long int>; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::pair<long long unsigned int, long long unsigned int> >; _Hash = std::hash<std::pair<long long unsigned int, long long unsigned int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, false, true>]' is implicitly deleted because the default definition would be ill-formed:
 1731 |       _Hashtable_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1731:7: error: use of deleted function 'std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::_Hash_code_base() [with _Key = std::pair<long long unsigned int, long long unsigned int>; _Value = std::pair<const std::pair<long long unsigned int, long long unsigned int>, long long int>; _ExtractKey = std::__detail::_Select1st; _Hash = std::hash<std::pair<long long unsigned int, long long unsigned int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; bool __cache_hash_code = true]'
/usr/include/c++/14/bits/hashtable_policy.h: In instantiation of 'std::__detail::_Hashtable_ebo_helper<_Nm, _Tp, true>::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash<std::pair<long long unsigned int, long long unsigned int> >]':
/usr/include/c++/14/bits/hashtable_policy.h:1328:7:   required from here
 1328 |       _Hash_code_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1245:49: error: use of deleted function 'std::hash<std::pair<long long unsigned int, long long unsigned int> >::hash()'
 1245 |       _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
      |                                                 ^~~~~
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/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/functional_hash.h:102:12: note: 'std::hash<std::pair<long long unsigned int, long long unsigned int> >::hash()' is implicitly deleted because the default definition would be ill-formed:
  102 |     struct hash : __hash_enum<_Tp>
      |            ^~~~
/usr/include/c++/14/bits/functional_hash.h:102:12: error: no matching function for call to 'std::__hash_enum<std::pair<long long unsigned int, long long unsigned int>, false>::__hash_enum()'
/usr/include/c++/14/bits/functional_hash.h:83:7: note: candidate: 'std::__hash_enum<_Tp, <anonymous> >::__hash_enum(std::__hash_enum<_Tp, <anonymous> >&&) [with _Tp = std::pair<long long unsigned int, long long unsigned int>; bool <anonymous> = false]'
   83 |       __hash_enum(__hash_enum&&);
      |       ^~~~~~~~~~~
/usr/include/c++/14/bits/functional_hash.h:83:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/functional_hash.h:102:12: error: 'std::__hash_enum<_Tp, <anonymous> >::~__hash_enum() [with _Tp = std::pair<long long unsigned int, long long unsigned int>; bool <anonymous> = false]' is private within this context
  102 |     struct hash : __hash_enum<_Tp>
      |            ^~~~
/usr/include/c++/14/bits/functional_hash.h:84:7: note: declared private here
   84 |       ~__hash_enum();
      |       ^
/usr/include/c++/14/bits/hashtable_policy.h:1245:49: note: use '-fdiagnostics-all-candidates' to display considered candidates
 1245 |       _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
      |                                                 ^~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1328:7: note: 'std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::_Hash_code_base() [with _Key = std::pair<long long unsigned int, long long unsigned int>; _Value = std::pair<const std::pair<long long unsigned int, long long unsigned int>, long long int>; _ExtractKey = std::__detail::_Select1st; _Hash = std::hash<std::pair<long long unsigned int, long long unsigned int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; bool __cache_hash_code = true]' is implicitly deleted because the default definition would be ill-formed:
 1328 |       _Hash_code_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1328:7: error: use of deleted function 'std::__detail::_Hashtable_ebo_helper<1, std::hash<std::pair<long long unsigned int, long long unsigned int> >, true>::~_Hashtable_ebo_helper()'
/usr/include/c++/14/bits/hashtable_policy.h:1242:12: note: 'std::__detail::_Hashtable_ebo_helper<1, std::hash<std::pair<long long unsigned int, long long unsigned int> >, true>::~_Hashtable_ebo_helper()' is implicitly deleted because the default definition would be ill-formed:
 1242 |     struct _Hashtable_ebo_helper<_Nm, _Tp, true>
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1242:12: error: use of deleted function 'std::hash<std::pair<long long unsigned int, long long unsigned int> >::~hash()'
/usr/include/c++/14/bits/functional_hash.h:102:12: note: 'std::hash<std::pair<long long unsigned int, long long unsigned int> >::~hash()' is implicitly deleted because the default definition would be ill-formed:
  102 |     struct hash : __hash_enum<_Tp>
      |            ^~~~
/usr/include/c++