#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   void qread(int &x) {     int neg = 1;     x = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) neg = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) x = 10 * x + c -  0 , c = getchar();     x *= neg;   }   const int maxn = 500005;   int n;   char s[maxn];   int dp[maxn];   namespace Sgt {   int sz;   int t[maxn * 4];   void init() {     for (sz = 1; sz <= n; sz <<= 1)       ;     for (int(i) = 0; (i) < sz << 1; i++) t[i] = 0;   }   void upd(int v, int val) {     v += sz;     t[v] = val;     for (v >>= 1; v; v >>= 1) t[v] = max(t[v << 1], t[v << 1 | 1]);   }   int qry(int l, int r) {     int res = 0;     for (l += sz, r += sz; l <= r; l >>= 1, r >>= 1) {       if (l & 1) res = max(res, t[l]), l++;       if ((r + 1) & 1) res = max(res, t[r]), r--;     }     return res;   }   }  // namespace Sgt   namespace St {   const int mlog = 20;   int mn[maxn][mlog];   void init(int *a) {     for (int(i) = 0; (i) < n; i++) mn[i][0] = a[i];     for (int(j) = 1; (j) <= mlog - 1; j++)       for (int(i) = 0; (i) < n; i++) {         if (i + (1 << j - 1) >= n)           mn[i][j] = 1e9;         else           mn[i][j] = min(mn[i][j - 1], mn[i + (1 << j - 1)][j - 1]);       }   }   pair<int, int> getval(int p, int len) {     int l = p, r = p;     for (int i = mlog - 1; i >= 0; i--) {       if (l - (1 << i) >= 0 && mn[l - (1 << i) + 1][i] >= len) l -= (1 << i);       if (r + (1 << i) < n && mn[r + 1][i] >= len) r += (1 << i);     }     return make_pair(l, r);   }   }  // namespace St   namespace Sa {   pair<int, int> cur[maxn];   int tmp[maxn], sum[maxn], sa[maxn], rk[maxn], lcp[maxn];   void rsort() {     int mx = 0;     for (int(i) = 0; (i) < n; i++)       sum[cur[i].second]++, mx = max(mx, cur[i].second);     for (int(i) = 1; (i) <= mx; i++) sum[i] += sum[i - 1];     for (int i = n - 1; i >= 0; i--) tmp[--sum[cur[i].second]] = i;     for (int(i) = 0; (i) < mx + 1; i++) sum[i] = 0;     mx = 0;     for (int(i) = 0; (i) < n; i++)       sum[cur[tmp[i]].first]++, mx = max(mx, cur[tmp[i]].first);     for (int(i) = 1; (i) <= mx; i++) sum[i] += sum[i - 1];     for (int i = n - 1; i >= 0; i--) sa[--sum[cur[tmp[i]].first]] = tmp[i];     for (int(i) = 0; (i) < mx + 1; i++) sum[i] = 0;     rk[sa[0]] = 0;     for (int(i) = 1; (i) <= n - 1; i++)       rk[sa[i]] = rk[sa[i - 1]] + (cur[sa[i]] != cur[sa[i - 1]]);   }   void init() {     for (int(i) = 0; (i) < n; i++) cur[i] = make_pair(s[i], s[i]);     rsort();     for (int m = 1; m <= n; m <<= 1) {       for (int(i) = 0; (i) < n; i++)         cur[i] = make_pair(rk[i] + 1, i + m < n ? (rk[i + m] + 1) : 0);       rsort();     }     int h = 0;     for (int(i) = 0; (i) < n; i++) {       if (rk[i] == 0) continue;       int j = sa[rk[i] - 1];       if (h) h--;       while (i + h < n && j + h < n && s[i + h] == s[j + h]) h++;       lcp[rk[i]] = h;     }     St::init(lcp);   }   }  // namespace Sa   int main() {     scanf( %d%s , &n, s);     Sgt::init();     Sa::init();     int ans = 0;     for (int i = n - 1; i >= 0; i--) {       dp[i] = dp[i + 1] + 1;       for (;;) {         bool ok = false;         pair<int, int> cur = St::getval(Sa::rk[i], dp[i] - 1);         ok |= (Sgt::qry(cur.first, cur.second) >= dp[i] - 1);         if (i + 1 < n) {           cur = St::getval(Sa::rk[i + 1], dp[i] - 1);           ok |= (Sgt::qry(cur.first, cur.second) >= dp[i] - 1);         }         if (ok) break;         if (i + dp[i] - 1 < n) Sgt::upd(Sa::rk[i + dp[i] - 1], dp[i + dp[i] - 1]);         dp[i]--;       }       ans = max(ans, dp[i]);     }     printf( %d n , ans);     return 0;   }