Language: C++

#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

#include <sstream>

#define debug(args...) { std::string _s = #args; std::replace(_s.begin(), _s.end(), ',', ' '); std::stringstream _ss(_s); std::istream_iterator<std::string> _it(_ss); _err(std::cerr, _it, args); }
#define WHATIS(x) std::cerr << #x << " is " << x << '\n'

template<typename T>
std::ostream& operator<<(std::ostream&o,const std::vector<T>&v) {
	o<<'['; for(int i=0;i<v.size();i++) o<<v[i]<<","[i==v.size()-1]; o<<']'; return o;
}

void _err(std::ostream& cerr,std::istream_iterator<std::string> it) { cerr << '\n'; }
template<typename T, typename... Args>
void _err(std::ostream& cerr, std::istream_iterator<std::string> it, T a, Args... args) {
    cerr << *it << " = " << a << "  ";
    _err(cerr,++it, args...);
}


struct ZAlgorithm
{
	std::vector<int> z;
	ZAlgorithm(std::string s) : z(s.size(),0) {
		int l,r;
		// [l,r)
		l=r=0;
		z[0] = s.size();
		for(int i=1;i<s.size();i++) {
			if(i>=r) {
				l=r=i;
				while(r<s.size() && s[r]==s[r-l]) r++;
				z[i] = r-l;
				continue;
			}
			if(z[i-l]<r-i) {
				z[i] = z[i-l];
				continue;
			}
			l=i;
			while(r<s.size() && s[r]==s[r-l]) r++;
			z[i] = r-l;
			continue;
		}
	}
};


signed main() {
	int n;
	std::cin >> n;
	std::string s;
	std::cin >> s;
	int max = 0;
	for(int i=0;i<n;i++) {
		ZAlgorithm z(s.substr(i,n-i));
		for(int j=1;j<z.z.size();j++) {
			if(z.z[j]<=j) max = std::max(max,z.z[j]);
		}
	}
	print(max);
	return 0;
}


Compiler output:
a.cc:37:30: error: 'std::istream_iterator' has not been declared
   37 | void _err(std::ostream& cerr,std::istream_iterator<std::string> it) { cerr << '\n'; }
      |                              ^~~
a.cc:37:51: error: expected ',' or '...' before '<' token
   37 | void _err(std::ostream& cerr,std::istream_iterator<std::string> it) { cerr << '\n'; }
      |                                                   ^
a.cc:39:31: error: 'std::istream_iterator' has not been declared
   39 | void _err(std::ostream& cerr, std::istream_iterator<std::string> it, T a, Args... args) {
      |                               ^~~
a.cc:39:52: error: expected ',' or '...' before '<' token
   39 | void _err(std::ostream& cerr, std::istream_iterator<std::string> it, T a, Args... args) {
      |                                                    ^
a.cc: In function 'void _err(std::ostream&, int)':
a.cc:40:14: error: 'it' was not declared in this scope; did you mean 'int'?
   40 |     cerr << *it << " = " << a << "  ";
      |              ^~
      |              int
a.cc:40:29: error: 'a' was not declared in this scope
   40 |     cerr << *it << " = " << a << "  ";
      |                             ^
a.cc:41:21: error: 'args' was not declared in this scope; did you mean 'Args'?
   41 |     _err(cerr,++it, args...);
      |                     ^~~~
      |                     Args