#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

struct SuffixArray {
	struct SAComp {
		const int h;
		const vector<int> &g;
		SAComp(int h, vector<int> &g) : h(h), g(g) { ; }
		bool operator() (int a, int b) {
			return a != b && (g[a] != g[b] ? g[a] < g[b] : g[a + h] < g[b + h]);
		}
	};

	int n;
	char *str;
	vector<int> sa, lcp;

	SuffixArray(const string &t) : n(t.size()), sa(n + 1), lcp(n + 1) {
		str = new char[n + 1];
		strcpy(str, t.c_str());

		// build SA
		vector<int> g(n + 1, 0), b(n + 1, 0);
		REP(i, n + 1) { sa[i] = i; g[i] = str[i]; }
		sort(begin(sa), end(sa), SAComp(0, g));
		for (int h = 1; b[n] != n; h *= 2) {
			SAComp comp(h, g);
			sort(sa.begin(), sa.end(), comp);
			REP(i, n) b[i + 1] = b[i] + comp(sa[i], sa[i + 1]);
			REP(i, n + 1) g[sa[i]] = b[i];
		}

		// build LCP
		int h = 0;
		REP(i, n + 1) b[sa[i]] = i;
		REP(i, n + 1) {
			if (b[i]) {
				for (int j = sa[b[i] - 1]; j + h<n && i + h<n && str[j + h] == str[i + h]; ++h);
				lcp[b[i]] = h;
			}
			else {
				lcp[b[i]] = -1;
			}
			if (h > 0) --h;
		}
	}
	~SuffixArray() { delete[]str; }

	/*
	int find(string t) {
		int m = t.size();
		char p[m + 1];
		strcpy(p, t.c_str());
		int left = -1, right = n + 1;
		while (left + 1 < right) {
			int mid = (left + right) / 2;
			if (strncmp(str + sa[mid], p, m) < 0) left = mid;
			else right = mid;
		}
		return strncmp(str + sa[right], p, m) == 0 ? sa[right] : -1;
	}
	*/
};

signed main() {
	ll n;
	string s;

	cin >> n >> s;

	SuffixArray SA(s);

	ll ans = 0;

	//cout << SA.sa << endl;
	//cout << SA.lcp << endl;

	REP(i, n) {
		//cout << min(SA.sa[i], SA.sa[i + 1]) + SA.lcp[i + 1] << endl;
		//cout << max(SA.sa[i], SA.sa[i + 1]) << endl;
		if (min(SA.sa[i], SA.sa[i + 1]) + SA.lcp[i + 1] <= max(SA.sa[i], SA.sa[i + 1])) {
			ans = max(ans, SA.lcp[i + 1]);
		}
	}

	ll now = 0;
	ll cnt = 1;
	ll ans2 = 0;

	s = s + "#!$&~=)(%}{+*><?_@;:][.,-$!)%";

	REP(i, 26) {
		now = 0;
		while (now < n) {
			//cout << s.substr(now, i + 1) << endl;
			if (s.substr(now, i + 1) == s.substr(now + i + 1, i + 1)) {
				cnt++;
			}
			else if(cnt > 1) {
				ans2 = max(ans2, cnt * (i + 1) / 2);
				cnt = 1;
			}
			now += i + 1;
		}
	}

	cout << max(ans, ans2) << endl;
}

Measured memory_bytes: 384