Language: C++

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

void solve(long long N, std::string S) {}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long N;
  scanf("%lld", &N);#include <bits/stdc++.h>
using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" ";
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

struct SuffixArray {
    string s;
    lli n, k;
    vector<lli> sa, tmp, rank_sa;
  
    struct CompareSA {
      lli n, k;
      const vector<lli> &rank;
      CompareSA(lli n, lli k, const vector<lli> &rank_sa)
          : n(n), k(k), rank(rank_sa) {
      }
      bool operator()(lli i, lli j) {
        if(rank[i] != rank[j])
          return rank[i] < rank[j];
        else {
          lli rank_ik = (i + k <= n ? rank[i + k] : -1);
          lli rank_jk = (j + k <= n ? rank[j + k] : -1);
          return rank_ik < rank_jk;
        }
      }
    };
    SuffixArray(const string &S) {
      s = S;
      n = S.size();
      sa = vector<lli>(n + 1);
      rank_sa = vector<lli>(n + 1);
      tmp = vector<lli>(n + 1);
      createSuffixArray();
    }
    void createSuffixArray() {
      for(lli i = 0; i <= n; i++) {
        sa[i] = i;
        rank_sa[i] = i < n ? (lli)s[i] : -1;
      }
  
      for(k = 1; k <= n; k *= 2) {
        CompareSA csa(n, k, rank_sa);
        sort(sa.begin(), sa.end(), csa);
  
        tmp[sa[0]] = 0;
        for(lli i = 1; i <= n; i++) {
          tmp[sa[i]] = tmp[sa[i - 1]];
          if(csa(sa[i - 1], sa[i])) tmp[sa[i]]++;
        }
        for(lli i = 0; i <= n; i++) {
          rank_sa[i] = tmp[i];
        }
      }
    }
  bool contains(string t){
    lli l = 1;
    lli r = n+1;
    while(r - l > 1) {
      lli mid =(r+l)/ 2;
      lli index = sa[mid];
      lli cmp = s.compare(index, t.size(), t);
      if(cmp > 0)
        r = mid;
      else
        l = mid;
    }
    return s.compare(sa[l], t.size(), t) == 0;
  }
    set<lli> containsRange(string t){
      set<lli> rtn;
      lli outL,outR;
      {
        lli l = 1;
        lli r = n+1;
        while(r - l > 1) {
          lli mid =(r+l)/ 2;
          lli index = sa[mid];
          lli cmp = s.compare(index, t.size(), t);
          if(cmp > 0)
            r = mid;
          else
            l = mid;
        }
        outL = l;
      }
      {
        lli l = 0;
        lli r = n+1;
        while(r - l > 1) {
          lli mid =(r+l)/ 2;
          lli index = sa[mid];
          lli cmp = s.compare(index, t.size(), t);
          if(cmp < 0)
            l = mid;
          else
            r = mid;
        }
        
        outR = r;
      }
      LOG2(outR,outL);
      REP(i,outR,outL+1)rtn.insert(sa[i]);
      return rtn;
    }
  };


void func(long long N, std::string S){

    SuffixArray sa(S);

    for(lli targetL = S.size()/2;targetL>0;targetL--){
        REP(i,0,S.size()-targetL){
            string t = S.substr(i,targetL);
            set<lli> ss = sa.containsRange(t);

            LOG3(targetL,i,t);
            
            LOG(ss.size());

            auto L = ss.begin();
            auto R = ss.rbegin();

            LOG2(*L,*R);
            if( (*R) - (*L) >= targetL){
                cout<<targetL<<endl;
                return;
            }
        }
    }

    cout<<0<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    func(N, S);
    return 0;
}

  std::string S;
  std::cin >> S;
  solve(N, S);
  return 0;
}


Compiler output:
a.cc:11:21: error: stray '#' in program
   11 |   scanf("%lld", &N);#include <bits/stdc++.h>
      |                     ^
a.cc: In function 'int main()':
a.cc:11:22: error: 'include' was not declared in this scope
   11 |   scanf("%lld", &N);#include <bits/stdc++.h>
      |                      ^~~~~~~
a.cc:11:31: error: 'bits' was not declared in this scope
   11 |   scanf("%lld", &N);#include <bits/stdc++.h>
      |                               ^~~~
a.cc:11:36: error: 'stdc' was not declared in this scope; did you mean 'std'?
   11 |   scanf("%lld", &N);#include <bits/stdc++.h>
      |                                    ^~~~
      |                                    std
a.cc:12:1: error: expected primary-expression before 'using'
   12 | using namespace std;
      | ^~~~~
a.cc:27:1: error: a template declaration cannot appear at block scope
   27 | template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
      | ^~~~~~~~
a.cc:132:38: error: a function-definition is not allowed here before '{' token
  132 | void func(long long N, std::string S){
      |                                      ^
a.cc:160:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
  160 | int main(){
      |         ^~
a.cc:160:9: note: remove parentheses to default-initialize a variable
  160 | int main(){
      |         ^~
      |         --
a.cc:160:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:160:11: error: a function-definition is not allowed here before '{' token
  160 | int main(){
      |           ^