#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <iomanip>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <array>
#include <list>
#include <forward_list>
#include <complex>
#include <numeric>
#include <regex>
#include <boost/optional.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <boost/range/irange.hpp>

using namespace std;

//#define int mnt
#define let const auto&
#define var decltype(auto)
#define ref auto&&

using mnt = int_fast64_t;

using ll = long long;
using ld = long double;

template<typename T=int> using vec = vector<T>;
template<typename T=int> using mat = vec<vec<T>>;
template<typename T=int> using dic = map<string, T>;
template<typename T=int> using dict = unordered_map<string, T>;
template<typename T=int> using pqg = priority_queue<T, vector<T>, greater<T>>;
template<typename T=int, class F=less<T>> using pq = priority_queue<T, vector<T>, F>;

using pii = pair<int, int>;
using vi = vector<int>;
using mi = vector<vector<int>>;
using vp = vector<pii>;
using vb = vector<bool>;

template<typename T=int> using opt = boost::optional<T>;
//using cint = boost::multiprecision::cpp_int;
//using boost::irange;

constexpr int IINF = 0x3f3f3f3f;
constexpr mnt LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int INF = (int)LINF;

constexpr mnt MOD = 1e9+7;

#define overload4(a,b,c,d,name,...) name
#define rep1(n) for(int i=0,_i=(n);i<_i;++i)
#define rep2(i,n) for(int i=0,_##i=(n);i<_##i;++i)
#define rep3(i,a,b) for(int i=(a),_##i=(b);i<_##i;++i)
#define rep4(i,a,b,c) for(int i=(a),_##i=(b),_##i##i=(c);i<_##i;i+=_##i##i)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep1(n) for(int i=(n)-1;i>=0;--i)
#define rrep2(i,n) for(int i=(n)-1;i>=0;--i)
#define rrep3(i,a,b) for(int i=(b)-1,_##i=(a);i>=_##i;--i)
#define rrep4(i,a,b,c) for(int i=((b)-(a)-1)/(c)*(c)+(a),_##i=(a),_##i##i=(c);i>=_##i;i-=_##i##i)
#define rrep(...) overload4(__VA_ARGS__,rrep4,rrep3,rrep2,rrep1)(__VA_ARGS__)

#define eb emplace_back
#define pb push_back
#define pob pop_back
#define puf push_front
#define pof pop_front

#define mp make_pair
#define mt make_tuple
#define fat forward_as_tuple

#define ft first
#define sd second

#define all(a) begin(a), end(a)
#define rall(a) rbegin(a), rend(a)

#define elif else if
#define unless(a) if(!(a))
#define qt(a) #a

#define endl '\n'
#define deci(n) fixed << setprecision(n)
#define zfl(n) setfill(‘0’) << setw(n)

template<typename T=int, class C> inline constexpr T sz(const C& a) { return (T)a.size(); }
template<class C> inline constexpr C& rev(C& a) { reverse(begin(a), end(a)); return a; }
template<class C> inline constexpr C rev(C&& a) { return forward<C>(rev(a)); }
template<class C> inline constexpr C& sort(C& a) { sort(begin(a), end(a)); return a; }
template<class C> inline constexpr C sort(C&& a) { return forward<C>(sort(a)); }
template<class C> inline constexpr bool np(C& a) { return next_permutation(begin(a), end(a)); }
template<class C> inline constexpr bool pp(C& a) { return prev_permutation(begin(a), end(a)); }
template<class C, typename T> inline constexpr bool bs(const C& a, const T& v) { return binary_search(begin(a), end(a), v); }
template<class C, typename T> inline constexpr auto lb(const C& a, const T& v) { return lower_bound(begin(a), end(a), v); }
template<class C, typename T> inline constexpr auto ub(const C& a, const T& v) { return upper_bound(begin(a), end(a), v); }
template<class C, class F> inline constexpr auto bd(const C& a, const F& f) { return partition_point(begin(a), end(a), f); } // boundary
template<class C> inline constexpr auto& min(const C& a) { return *min_element(begin(a), end(a)); }
template<class C> inline constexpr auto& max(const C& a) { return *max_element(begin(a), end(a)); }
template<class T> inline constexpr void rs(vector<T>& a, size_t n) { a.resize(n); }
template<class T> inline constexpr void rsv(vector<T>& a, size_t n) { a.reserve(n); }
template<class C> inline constexpr auto sum(const C& c) { return accumulate(next(begin(c)), end(c), *begin(c)); }
template<class C, class F> inline constexpr auto foldl(const C& c, const F& f) { return accumulate(next(begin(c)), end(c), *begin(c), f); }

template<typename T> inline constexpr T gcd2(T a, T b) { while(b) { T t = b; b = a%b; a = t; } return a; }
template<typename T> inline constexpr T lcm2(T a, T b) { return a / gcd2(a, b) * b; }
template<typename T> inline constexpr T extgcd2(T a, T b, T& x, T& y) { x = 1; y = 0; while (b) { T t = a / b; a -= t * b; swap(a, b); x -= t * y; swap(x, y); } return a; }

template<typename T> inline constexpr bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline constexpr bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } return false; }

template<typename T> inline constexpr T ceil(const T& A, const T& B) { return (A+B-1) / B; } // ceil(A/B)

#define mv(T,...) make_v<T>(__VA_ARGS__)
template<typename T> inline constexpr auto make_v() { return vector<T>(); } template<typename T> inline constexpr auto make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts> inline constexpr auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }

template<typename T> struct has_itr {
  template<typename U> static auto check(U x) -> decltype(begin(x), end(x), true_type()); static false_type check(...);
  static bool constexpr value = decltype(check(declval<T>()))::value;
};
template<typename T, typename V, enable_if_t<!has_itr<T>::value, nullptr_t> = nullptr> inline constexpr void fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V, enable_if_t< has_itr<T>::value, nullptr_t> = nullptr> inline constexpr void fill_v(T& t, const V& v) { for(auto&& e : t) fill_v(e, v); }
template<typename T, class F, enable_if_t<!has_itr<T>::value, nullptr_t> = nullptr> inline constexpr T& apply(T& t, const F& f) { return t = f(t); }
template<typename T, class F, enable_if_t<!has_itr<T>::value, nullptr_t> = nullptr> inline constexpr T apply(T&& t, const F& f) { return f(forward<T>(t)); }
template<typename T, class F, enable_if_t< has_itr<T>::value, nullptr_t> = nullptr> inline constexpr T& apply(T& t, const F& f) { for(auto&& e : t) apply(e, f); return t; }
template<typename T, class F, enable_if_t< has_itr<T>::value, nullptr_t> = nullptr> inline constexpr T apply(T&& t, const F& f) { return forward<T>(apply(t, f)); }

template<typename T> istream& operator>>(istream& is, vector<T>& v) { for(auto&& x : v) is >> x; return is; }
template<typename T> struct is_string : false_type {}; template<> struct is_string<string> : true_type {};
template<typename T, enable_if_t<has_itr<T>::value && !is_string<T>::value, nullptr_t> = nullptr> ostream& operator<<(ostream& os, const T& t)
{ for(auto i=begin(t); i != end(t); ++i) { if( i!= begin(t)) os << ' '; os << *i; } return os; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first; is >> p.second; return is; }
template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.first << ' ' << p.second; return os; }

template<typename T> struct is_pair : false_type {}; template<typename T, typename U> struct is_pair<pair<T, U>> : true_type {};
template<typename T, enable_if_t<!is_pair<T>::value, nullptr_t> = nullptr> inline constexpr T& dcr(T& t) { return --t; }
template<typename T, enable_if_t< is_pair<T>::value, nullptr_t> = nullptr> inline constexpr T& dcr(T& t) { --t.ft; --t.sd; return t; }

template<typename T> struct is_priority_queue : false_type {}; template<class T, class V, class C> struct is_priority_queue<priority_queue<T, V, C>> : true_type {};
template<typename T, enable_if_t< is_priority_queue<T>::value, nullptr_t> = nullptr> inline constexpr auto pop_front(T& p) { auto q = p.top(); p.pop(); return q; }

struct InitIO {
  InitIO() {
    cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15);
    #ifndef LOCAL
      cerr.rdbuf(nullptr);
    #endif
  }
} initio;
#ifdef LOCAL
  #include <boost/type_index.hpp>
  #define trace(...) Trace(" " #__VA_ARGS__ ",", __VA_ARGS__)
  template<typename T> inline string type_name() { return boost::typeindex::type_id_with_cvr<T>().pretty_name(); }
  template<typename T> inline const char* Trace(const char* n, const T& t) {
    auto c = strchr(n+1, ','); cerr.write(n, c-n) << " = " << t << "; // " << type_name<T>() << "\n"; return c; }
  template<typename T, typename... Ts> inline const char* Trace(const char* n, const T& t, const Ts&... ts) {
    const char* c = Trace(n, t); return Trace(c+1, ts...); }
#else
  #define trace(...)
#endif

#define in(T,...) In<T>(__VA_ARGS__)
template<typename T> inline void sc(T& x) { cin >> x; }
template<typename T, typename... Ts> inline void sc(T& t, Ts&... ts) { sc(t); sc(ts...); }
template<typename T=int> inline T In() { T x; sc(x); return x; }
template<typename T, typename... Ts> inline auto In(Ts ...ts) { auto v = make_v<T>(ts...); sc(v); return v; }
inline string input() { string str; cin >> ws; getline(cin, str); return str; }
template<typename T> inline void out(const T& x) { cout << x; }
template<typename T, typename... Ts> inline void out(const T& t, const Ts&... ts) { out(t); out(' '); out(ts...); }
template<typename T> inline void err(const T& x) { cerr << x; }
template<typename T, typename... Ts> inline void err(const T& t, const Ts&... ts) { err(t); err(' '); err(ts...); }
template<typename... Ts> inline void print(const Ts&... ts) { out(ts...); out('\n'); }
template<typename... Ts> inline void debug(const Ts&... ts) { err(ts...); err('\n'); }

inline constexpr auto yes(const bool& c) { return c ? "yes" : "no"; }
inline constexpr auto Yes(const bool& c) { return c ? "Yes" : "No"; }
inline constexpr auto YES(const bool& c) { return c ? "YES" : "NO"; }
inline constexpr auto pos(const bool& c) { return c ? "possible" : "impossible"; }
inline constexpr auto Pos(const bool& c) { return c ? "Possible" : "Impossible"; }
inline constexpr auto POS(const bool& c) { return c ? "POSSIBLE" : "IMPOSSIBLE"; }

constexpr int lim = 1e5+7;

/*bool check(string& S) {
  vi cnt(26);
  for(let c : S) ++cnt[c-'a'];
  rep(i, 26) if(cnt[i] > 1) return true;
  return false;
}*/

signed main() {

  let N = in();
  let S = input();

  //if(!check(S)) { print(0); return 0; }

  var dp = mv(int, N+2, N+2);
  rep(i, 1, N) dp[i][0] = dp[0][i] = (S[i] == S[0] ? 1 : 0);

  rep(i, 1, N) rep(j, 1, N) {
    if(i == j) continue;
    if(S[i] == S[j]) {
      int pre = dp[i-1][j-1];
      if(j-i > pre) dp[i][j] = pre + 1;
    }
  }

  int ans = 0;
  // rep(i, N) rep(j, i+1, N) if(chmax(ans, dp[i][j])) trace(i, j, ans);
  rep(i, N) rep(j, i+1, N) chmax(ans, dp[i][j]);
  print(ans);

  return 0;
}


Measured memory_bytes: 98176