We call a sequence of strings t1, ..., tk a journey of length k, if for each i > 1 ti is a substring of ti - 1 and length of ti is strictly less than length of ti - 1. For example, {ab, b} is a journey, but {ab, c} and {a, a} are not.

Define a journey on string s as journey t1, ..., tk, such that all its parts can be nested inside s in such a way that there exists a sequence of strings u1, ..., uk + 1 (each of these strings can be empty) and s = u1 t1 u2 t2... uk tk uk + 1. As an example, {ab, b} is a journey on string abb, but not on bab because the journey strings ti should appear from the left to the right.

The length of a journey on a string is the number of strings in it. Determine the maximum possible length of a journey on the given string s.

Input

The first line contains a single integer n (1 ≤ n ≤ 500 000) — the length of string s.

The second line contains the string s itself, consisting of n lowercase Latin letters.

Output

Print one number — the maximum possible length of string journey on s.

Examples

Input

7
abcdbcc


Output

3


Input

4
bbcb


Output

2

Note

In the first sample, the string journey of maximum length is {abcd, bc, c}.

In the second sample, one of the suitable journeys is {bb, b}.
#include <bits/stdc++.h>
using namespace std;
char str[500010];
int v[500010 * 24], ls[500010 * 24], rs[500010 * 24], rt[500010], sa[500010],
    rnk[500010], height[500010], f[500010], tax[500010], lg2[500010],
    st[25][500010], n, m, i, j, l, r, ans = 0, sz = 0;
void msort() {
  int i;
  for (i = 1; i <= m; i++) tax[i] = 0;
  for (i = 1; i <= n; i++) tax[rnk[f[i]]]++;
  for (i = 1; i <= m; i++) tax[i] += tax[i - 1];
  for (i = n; i; i--) sa[tax[rnk[f[i]]]--] = f[i];
}
void getsa() {
  int i, k, s = 0;
  for (i = 1; i <= n; i++) {
    rnk[i] = str[i - 1];
    f[i] = i;
  }
  m = 128;
  msort();
  m = 0;
  for (k = 1; m < n; k <<= 1) {
    s = 0;
    for (i = n - k + 1; i <= n; i++) f[++s] = i;
    for (i = 1; i <= n; i++)
      if (sa[i] > k) f[++s] = sa[i] - k;
    msort();
    for (i = 1; i <= n; i++) swap(rnk[i], f[i]);
    rnk[sa[1]] = 1;
    for (i = 2; i <= n; i++)
      if ((f[sa[i]] == f[sa[i - 1]]) &&
          (((sa[i] + k > n) && (sa[i - 1] + k > n)) ||
           (f[sa[i] + k] == f[sa[i - 1] + k])))
        rnk[sa[i]] = rnk[sa[i - 1]];
      else
        rnk[sa[i]] = rnk[sa[i - 1]] + 1;
    m = rnk[sa[n]];
  }
}
void getheight() {
  int i, j, k = 0;
  for (i = 1; i <= n; i++)
    if (rnk[i] > 1) {
      if (k) k--;
      j = sa[rnk[i] - 1];
      for (; (i + k <= n) && (j + k <= n) && (str[i + k - 1] == str[j + k - 1]);
           k++)
        ;
      height[rnk[i]] = k;
    }
}
void getst() {
  int i, j;
  for (i = 2; i <= n; i++) lg2[i] = lg2[i >> 1] + 1;
  for (i = 1; i <= n; i++) st[0][i] = height[i];
  for (i = 1; i <= lg2[n]; i++)
    for (j = 1; j <= n - (1 << i) + 1; j++)
      st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
}
int rmq(int l, int r) {
  int len = r - l;
  l++;
  if (l > r) return n;
  return min(st[lg2[len]][l], st[lg2[len]][r - (1 << lg2[len]) + 1]);
}
int find1(int x, int y, int k) {
  int l = x, r = y, mid = (l + r) >> 1, ans = y;
  for (; l <= r; mid = (l + r) >> 1)
    if (rmq(mid, y) >= k) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  return ans;
}
int find2(int x, int y, int k) {
  int l = x, r = y, mid = (l + r) >> 1, ans = x;
  for (; l <= r; mid = (l + r) >> 1)
    if (rmq(x, mid) >= k) {
      ans = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  return ans;
}
void build(int &k, int l, int r) {
  k = ++sz;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(ls[k], l, mid);
  build(rs[k], mid + 1, r);
}
void update(int k1, int &k2, int l, int r, int x, int y) {
  k2 = ++sz;
  if (l == r) {
    v[k2] = max(v[k2], y);
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid) {
    update(ls[k1], ls[k2], l, mid, x, y);
    rs[k2] = rs[k1];
  } else {
    update(rs[k1], rs[k2], mid + 1, r, x, y);
    ls[k2] = ls[k1];
  }
  v[k2] = max(v[ls[k2]], v[rs[k2]]);
}
int query(int k, int l, int r, int x, int y) {
  if ((x <= l) && (r <= y)) return v[k];
  int mid = (l + r) >> 1, ans = 0;
  if (x <= mid) ans = max(ans, query(ls[k], l, mid, x, y));
  if (y > mid) ans = max(ans, query(rs[k], mid + 1, r, x, y));
  return ans;
}
int main() {
  scanf("%d%s", &n, str);
  getsa();
  getheight();
  getst();
  build(rt[n + 1], 1, n);
  for (i = n; i; i--) {
    for (j = f[i + 1] + 1; j > 1; j--) {
      if (i + j > n) continue;
      l = find1(1, rnk[i], j - 1);
      r = find2(rnk[i], n, j - 1);
      if (query(rt[i + j], 1, n, l, r) >= j - 1) break;
      if (i < n) {
        l = find1(1, rnk[i + 1], j - 1);
        r = find2(rnk[i + 1], n, j - 1);
        if (query(rt[i + j], 1, n, l, r) >= j - 1) break;
      }
    }
    f[i] = j;
    ans = max(ans, j);
    update(rt[i + 1], rt[i], 1, n, rnk[i], j);
  }
  printf("%d", ans);
  return 0;
}
