/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-13 02:18:49
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

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

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

using ull = unsigned long long;

class RollingHash {
 public:
  RollingHash(const std::string& s) : s_(s) { Initialize(); }

  // get hash value of [left, right)
  std::pair<ull, ull> GetHash(int left, int right) {
    ull ret0 =
        (hash0_[right] - hash0_[left] * power0_[right - left] % mod0_ + mod0_) %
        mod0_;
    ull ret1 =
        (hash1_[right] - hash1_[left] * power1_[right - left] % mod1_ + mod1_) %
        mod1_;
    return {ret0, ret1};
  }

 private:
  const std::string s_;
  static ull base0_;
  static ull base1_;
  static constexpr ull mod0_ = 2020202077;
  static constexpr ull mod1_ = 2020202111;
  std::vector<ull> hash0_;
  std::vector<ull> hash1_;
  static std::vector<ull> power0_;
  static std::vector<ull> power1_;
  static std::mt19937_64 mt_;

  void Initialize() {
    size_t n = s_.size();
    //hash0_.assign(n + 1, 0);
    //hash1_.assign(n + 1, 0);
    hash0_.resize(n + 1);
    hash1_.resize(n + 1);
    hash0_[0] = hash1_[0] = 0;
    for (size_t i = 0; i < n; ++i) {
      hash0_[i + 1] = (hash0_[i] * base0_ + s_[i]) % mod0_;
      hash1_[i + 1] = (hash1_[i] * base1_ + s_[i]) % mod1_;
    }
    //while (power0_.size() <= n) {
    for (size_t i = 0; i < n; ++i) {  
      power0_.emplace_back(power0_.back() * base0_ % mod0_);
      power1_.emplace_back(power1_.back() * base1_ % mod1_);
    }
  }
};

std::mt19937_64 RollingHash::mt_(
    std::chrono::steady_clock::now().time_since_epoch().count());
ull RollingHash::base0_ =
    std::uniform_int_distribution<ull>(2, RollingHash::mod0_ - 1)(RollingHash::mt_);
ull RollingHash::base1_ =
    std::uniform_int_distribution<ull>(2, RollingHash::mod1_ - 1)(RollingHash::mt_);
std::vector<ull> RollingHash::power0_{1};
std::vector<ull> RollingHash::power1_{1};

void ABC141_E() {
  int n; cin >> n;
  string s; cin >> s;
  RollingHash rh(s);

  auto ok = [&](int x) -> bool{
    for (int i = 0; i + 2 * x <= n; ++i) {
      for (int j = i + x; j + x <= n; ++j) {
        if (rh.GetHash(i, i + x) == rh.GetHash(j, j + x)) {
          return true;
        }
      }
    }
    return false;
  };

  int low = 0, high = n / 2 + 1;

  while (high - low > 1) {
    int mid = (low + high) >> 1;
    if (ok(mid)) {
      low = mid;
    } else {
      high = mid;
    }
  }

  cout << low << '\n';
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  ABC141_E();

  return 0;
}

Measured memory_bytes: 512