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(){
    scanf("%d",&n);
        for(int i=0; i<n; ++i) scanf("%d",a+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);

    return 0;
}


Compiler output:
a.cc: In function 'void SA(int*, int, int)':
a.cc:13:28: error: reference to 'ws' is ambiguous
   13 |     for(int i=0; i<m; ++i) 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:14:30: error: reference to 'ws' is ambiguous
   14 |     for(int i=0; i<n; ++i) ++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:15:28: error: reference to 'ws' is ambiguous
   15 |     for(int i=1; i<m; ++i) 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:15:35: error: reference to 'ws' is ambiguous
   15 |     for(int i=1; i<m; ++i) 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:16:36: error: reference to 'ws' is ambiguous
   16 |     for(int i=n-1; i>=0; --i) 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:24:32: error: reference to 'ws' is ambiguous
   24 |         for(int i=0; i<m; ++i) 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:25:34: error: reference to 'ws' is ambiguous
   25 |         for(int i=0; i<n; ++i) ++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:26:32: error: reference to 'ws' is ambiguous
   26 |         for(int i=1; i<m; ++i) 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:26:39: error: reference to 'ws' is ambiguous
   26 |         for(int i=1; i<m; ++i) 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:27:40: error: reference to 'ws' is ambiguous
   27 |         for(int i=n-1; i>=0; --i) 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];
      |                                ^~