Language: C++

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

#define Mset(s, n)      memset(s, n, sizeof(s))
#define Rp0(i, m)       for(int i = 0; i < m; ++i)
#define Rpd(i, m, l)    for(int i = l; i >= m; --i)
#define Rp1(i ,m)       for(int i = 1; i <= m; i++)
#define All(a)          (a).begin(), (a).end()
#define Lwb             lower_bound
#define Upb             upper_bound
#define Sz(a)           int((a).size())
#define u_map           unordered_map
#define Exist(a, b)     (find(All(a), (b)) != (a).end())
#define Sort(x)         sort(All(x))
#define Gsort(x)        sort(All(x), greater<typeof(*((x).begin()))>())
#define Unique(v)       Sort(v); (v).resize(unique(ALL(v)) - (v).begin())

#define fi              first
#define se              second
#define pb              push_back
#define pf              push_front
#define is              insert
#define ooi             INT_MAX
#define ool             LLONG_MAX
#define ll              long long
#define ull             unsigned ll
#define ld              long double
#define pii             pair<int, int>
#define vi              vector<int>
#define vpii            vector<pii>

const ll MOD = (ll) 1e9 + 7;
const ld PI = acos((ld) -1);
inline int Get_bit(int x, int k){return (x >> (k - 1)) & 1;}
inline ll Gcd(ll a, ll b) {ll r; while(b){ r = a % b; a = b; b = r;} return a;}
inline ll Lcm(ll a, ll b) {return a / Gcd(a, b) * b;}
inline ll Pow(ll n, ll k) {ll r = 1; for(; k; k >>= 1, n = n * n % MOD){if(k & 1) r = r * n % MOD;} return r;}
const int base = 311;


const int N = 1e4 + 10;


int n, m, k, q, ans;

ll pw[N];

struct HASH{
    vector<ll> val;
    int len;
    void Build(string s){
        len = Sz(s);
        val.assign(len, 0);
        for(int i = 1; i < len; i++){
            val[i] = (val[i - 1] * base + s[i]) % MOD;
        }
    }

    ll Get(int l, int r){
        return (val[r] - val[l - 1] * pw[r - l + 1] + MOD * MOD) % MOD;
    }
}a, b;

unordered_map<ll, vector<pii> > mp;
unordered_map<ll, vpii > ::iterator  it;

void Solve(){
    string s;
    cin >> n >> s;
    s = ' ' + s;
    pw[0] = 1;
    for(int i = 1; i < N; i++) pw[i] = (pw[i - 1] * base) % MOD;
    a.Build(s);
    for(int k = 1; k <= n; k++){
        for(int i = 1; i <= n - k + 1; i++){
            mp[a.Get(i, i + k - 1)].pb(make_pair(i, i + k - 1));
        }
    }
    for(it: mp){
        vpii a = it.se;
        sort(All(a));
        int m = Sz(a);
        if(a[0].se < a[m - 1].fi){
            ans = max(ans, a[0].se - a[0].fi + 1);
        }
    }
    cout << ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);
    Solve();
}










Compiler output:
a.cc: In function 'void Solve()':
a.cc:79:11: error: found ':' in nested-name-specifier, expected '::'
   79 |     for(it: mp){
      |           ^
      |           ::
a.cc:79:9: error: 'it' is not a class, namespace, or enumeration
   79 |     for(it: mp){
      |         ^~
a.cc:88:1: error: expected primary-expression before '}' token
   88 | }
      | ^
a.cc:87:17: error: expected ')' before '}' token
   87 |     cout << ans;
      |                 ^
      |                 )
   88 | }
      | ~                
a.cc:79:8: note: to match this '('
   79 |     for(it: mp){
      |        ^
a.cc:88:1: error: expected primary-expression before '}' token
   88 | }
      | ^