Language: C++

#include <bits/stdc++.h>
using namespace std;
#define MAXN 22222
#define INF (1<<30)
int wa[MAXN],wb[MAXN],wv[MAXN],ws[MAXN];
int cmp(int *r,int a,int b,int l)
{
    return r[a]==r[b] && r[a+l]==r[b+l];
}
int sa[MAXN],ran[MAXN],height[MAXN];
void SA(int *r,int n,int m)
{
    int *x=wa,*y=wb;

    for(int i=0; i<m; ++i)
        ws[i]=0;
    for(int i=0; i<n; ++i)
        ++ws[x[i]=r[i]];
    for(int i=1; i<m; ++i)
        ws[i]+=ws[i-1];
    for(int i=n-1; i>=0; --i)
        sa[--ws[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)
            ws[i]=0;
        for(int i=0; i<n; ++i)
            ++ws[wv[i]];
        for(int i=1; i<m; ++i)
            ws[i]+=ws[i-1];
        for(int i=n-1; i>=0; --i)
            sa[--ws[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)
        ran[sa[i]]=i;
    int k=0;
    for(int i=0; i<n-1; height[ran[i++]]=k)
    {
        if(k)
            --k;
        for(int j=sa[ran[i]-1]; r[i+k]==r[j+k]; ++k);
    }
}

int n,a[MAXN],r[MAXN];
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()
{
    char s[5005];
    scanf("%d",&n);
    scanf("%s",s);
    for(int i=0; i<n; ++i)
        a[i]=s[i]-'0';
    --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);

    return 0;
}


Compiler output:
a.cc: In function 'void SA(int*, int, int)':
a.cc:16:9: error: reference to 'ws' is ambiguous
   16 |         ws[i]=0;
      |         ^~
In file included from /usr/include/c++/14/istream:1109,
                 from /usr/include/c++/14/sstream:40,
                 from /usr/include/c++/14/complex:45,
                 from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127,
                 from a.cc:1:
/usr/include/c++/14/bits/istream.tcc:1073:5: note: candidates are: 'template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::ws(basic_istream<_CharT, _Traits>&)'
 1073 |     ws(basic_istream<_CharT, _Traits>& __in)
      |     ^~
a.cc:5:32: note:                 'int ws [22222]'
    5 | int wa[MAXN],wb[MAXN],wv[MAXN],ws[MAXN];
      |                                ^~
a.cc:18:11: error: reference to 'ws' is ambiguous
   18 |         ++ws[x[i]=r[i]];
      |           ^~
/usr/include/c++/14/bits/istream.tcc:1073:5: note: candidates are: 'template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::ws(basic_istream<_CharT, _Traits>&)'
 1073 |     ws(basic_istream<_CharT, _Traits>& __in)
      |     ^~
a.cc:5:32: note:                 'int ws [22222]'
    5 | int wa[MAXN],wb[MAXN],wv[MAXN],ws[MAXN];
      |                                ^~
a.cc:20:9: error: reference to 'ws' is ambiguous
   20 |         ws[i]+=ws[i-1];
      |         ^~
/usr/include/c++/14/bits/istream.tcc:1073:5: note: candidates are: 'template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::ws(basic_istream<_CharT, _Traits>&)'
 1073 |     ws(basic_istream<_CharT, _Traits>& __in)
      |     ^~
a.cc:5:32: note:                 'int ws [22222]'
    5 | int wa[MAXN],wb[MAXN],wv[MAXN],ws[MAXN];
      |                                ^~
a.cc:20:16: error: reference to 'ws' is ambiguous
   20 |         ws[i]+=ws[i-1];
      |                ^~
/usr/include/c++/14/bits/istream.tcc:1073:5: note: candidates are: 'template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::ws(basic_istream<_CharT, _Traits>&)'
 1073 |     ws(basic_istream<_CharT, _Traits>& __in)
      |     ^~
a.cc:5:32: note:                 'int ws [22222]'
    5 | int wa[MAXN],wb[MAXN],wv[MAXN],ws[MAXN];
      |                                ^~
a.cc:22:14: error: reference to 'ws' is ambiguous
   22 |         sa[--ws[x[i]]]=i;
      |              ^~
/usr/include/c++/14/bits/istream.tcc:1073:5: note: candidates are: 'template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::ws(basic_istream<_CharT, _Traits>&)'
 1073 |     ws(basic_istream<_CharT, _Traits>& __in)
      |     ^~
a.cc:5:32: note:                 'int ws [22222]'
    5 | int wa[MAXN],wb[MAXN],wv[MAXN],ws[MAXN];
      |                                ^~
a.cc:36:13: error: reference to 'ws' is ambiguous
   36 |             ws[i]=0;
      |             ^~
/usr/include/c++/14/bits/istream.tcc:1073:5: note: candidates are: 'template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::ws(basic_istream<_CharT, _Traits>&)'
 1073 |     ws(basic_istream<_CharT, _Traits>& __in)
      |     ^~
a.cc:5:32: note:                 'int ws [22222]'
    5 | int wa[MAXN],wb[MAXN],wv[MAXN],ws[MAXN];
      |                                ^~
a.cc:38:15: error: reference to 'ws' is ambiguous
   38 |             ++ws[wv[i]];
      |               ^~
/usr/include/c++/14/bits/istream.tcc:1073:5: note: candidates are: 'template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::ws(basic_istream<_CharT, _Traits>&)'
 1073 |     ws(basic_istream<_CharT, _Traits>& __in)
      |     ^~
a.cc:5:32: note:                 'int ws [22222]'
    5 | int wa[MAXN],wb[MAXN],wv[MAXN],ws[MAXN];
      |                                ^~
a.cc:40:13: error: reference to 'ws' is ambiguous
   40 |             ws[i]+=ws[i-1];
      |             ^~
/usr/include/c++/14/bits/istream.tcc:1073:5: note: candidates are: 'template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::ws(basic_istream<_CharT, _Traits>&)'
 1073 |     ws(basic_istream<_CharT, _Traits>& __in)
      |     ^~
a.cc:5:32: note:                 'int ws [22222]'
    5 | int wa[MAXN],wb[MAXN],wv[MAXN],ws[MAXN];
      |                                ^~
a.cc:40:20: error: reference to 'ws' is ambiguous
   40 |             ws[i]+=ws[i-1];
      |                    ^~
/usr/include/c++/14/bits/istream.tcc:1073:5: note: candidates are: 'template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::ws(basic_istream<_CharT, _Traits>&)'
 1073 |     ws(basic_istream<_CharT, _Traits>& __in)
      |     ^~
a.cc:5:32: note:                 'int ws [22222]'
    5 | int wa[MAXN],wb[MAXN],wv[MAXN],ws[MAXN];
      |                                ^~
a.cc:42:18: error: reference to 'ws' is ambiguous
   42 |             sa[--ws[wv[i]]]=y[i];
      |                  ^~
/usr/include/c++/14/bits/istream.tcc:1073:5: note: candidates are: 'template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::ws(basic_istream<_CharT, _Traits>&)'
 1073 |     ws(basic_istream<_CharT, _Traits>& __in)
      |     ^~
a.cc:5:32: note:                 'int ws [22222]'
    5 | int wa[MAXN],wb[MAXN],wv[MAXN],ws[MAXN];
      |                                ^~