Language: C++

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

const int N = 3005, INF = 1 << 30;

char s[N];
int n, a[N], r[N];
int wa[N], wb[N], wv[N], wc[N];
int sa[N], rank[N], height[N];

inline int cmp(int *r, int a, int b, int l) { return r[a] == r[b] && r[a + l] == r[b + l]; }

void SA(int *r, int n, int m) {
    int *x = wa, *y = wb;
    for (int i = 0; i < m; ++i) wc[i] = 0;
    for (int i = 0; i < n; ++i) ++wc[x[i] = r[i]];
    for (int i = 1; i < m; ++i) wc[i] += wc[i - 1];
    for (int i = n - 1; i >= 0; --i) sa[--wc[x[i]]] = i;
    int p = 1;
    for (int j = 1; p < n; j <<= 1, m = p) {
        p = 0;
        for (int i = n - j; i < n; ++i) y[p++] = i;
        for (int i = 0; i < n; ++i)
            if (sa[i] >= j)
                y[p++] = sa[i] - j;
        for (int i = 0; i < n; ++i) wv[i] = x[y[i]];
        for (int i = 0; i < m; ++i) wc[i] = 0;
        for (int i = 0; i < n; ++i) ++wc[wv[i]];
        for (int i = 1; i < m; ++i) wc[i] += wc[i - 1];
        for (int i = n - 1; i >= 0; --i) sa[--wc[wv[i]]] = y[i];
        swap(x, y);
        x[sa[0]] = 0;
        p = 1;
        for (int i = 1; i < n; ++i) x[sa[i]] = cmp(y, sa[i - 1], sa[i], j) ? p - 1 : p++;
    }
    for (int i = 1; i < n; ++i) rank[sa[i]] = i;
    int k = 0;
    for (int i = 0; i < n - 1; height[rank[i++]] = k) {
        if (k)
            --k;
        for (int j = sa[rank[i] - 1]; r[i + k] == r[j + k]; ++k)
            ;
    }
}

bool isok(int k) {
    bool flag = 0;
    int mx = -INF, mm = INF;
    for (int i = 2; i <= n; ++i) {
        if (height[i] >= k) {
            mm = min(mm, min(sa[i], sa[i - 1]));
            mx = max(mx, max(sa[i], sa[i - 1]));
            if (mx - mm > k)
                return 1;
        } else {
            mx = -INF, mm = INF;
        }
    }
    return 0;
}

int main() {
    scanf("%d", &n);
    scanf("%s", &s);
    for (int i = 0; i < n; ++i) a[i] = s[i];
    --n;
    for (int i = 0; i < n; ++i) r[i] = a[i + 1] - a[i] + 88;
    r[n] = 0;
    SA(r, n + 1, 176);
    int l = 0, r = n >> 1;
    while (l < r) {
        int mid = l + r + 1 >> 1;
        if (isok(mid))
            l = mid;
        else
            r = mid - 1;
    }
    printf("%d\n", l + 1);
	return 0;
}

Compiler output:
a.cc: In function 'void SA(int*, int, int)':
a.cc:36:33: error: reference to 'rank' is ambiguous
   36 |     for (int i = 1; i < n; ++i) rank[sa[i]] = i;
      |                                 ^~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:60,
                 from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:9:12: note:                 'int rank [3005]'
    9 | int sa[N], rank[N], height[N];
      |            ^~~~
a.cc:38:39: error: reference to 'rank' is ambiguous
   38 |     for (int i = 0; i < n - 1; height[rank[i++]] = k) {
      |                                       ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:9:12: note:                 'int rank [3005]'
    9 | int sa[N], rank[N], height[N];
      |            ^~~~
a.cc:41:25: error: reference to 'rank' is ambiguous
   41 |         for (int j = sa[rank[i] - 1]; r[i + k] == r[j + k]; ++k)
      |                         ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:9:12: note:                 'int rank [3005]'
    9 | int sa[N], rank[N], height[N];
      |            ^~~~