/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <ext/random>
#include <ext/rope>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using ull = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  os << '{';
  for (size_t i = 0; i < vec.size(); ++i) {
    os << vec[i];
    if (i != vec.size() - 1) os << ',';
  }
  os << '}';
  return os;
}
template<typename T, typename U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '{' << p.first << " " << p.second << '}';
}
// constant
constexpr int INF = (1<<30) - 1;  // 1.073741823e9
constexpr int64 INF64 = (1LL<<62) - 1;  // 4.611686018427387903e18
constexpr int MOD = 1'000'000'007;

template<typename T>
class SegmentTree {
 public:
  SegmentTree(const std::vector<T>& vec, const T& initial_value,
               std::function<T(T, T)> operation)
      : initial_value_(initial_value), vec_(vec), operation_(operation) {
    Initialize();
  }
  void Update(int position, T new_value);
  T Query(int a, int b);
  T operator[](const int& position) const;

 private:
  int n_;
  const T initial_value_;
  const std::vector<T> vec_;
  std::vector<T> data_;
  std::function<T(T, T)> operation_;
  void Initialize();
};

template<typename T>
void SegmentTree<T>::Initialize() {
  int vsize = static_cast<int>(vec_.size());
  n_ = 1;
  while (n_ < vsize) {
    n_ <<= 1;
  }
  data_.assign(2 * n_, initial_value_);
  for (int i = 0; i < vsize; ++i) {
    data_[i + n_] = vec_[i];
  }
  for (int i = n_ - 1; i > 0; --i) {
    data_[i] = operation_(data_[2 * i], data_[2 * i + 1]);
  }
}

template<typename T>
void SegmentTree<T>::Update(int position, T new_value) {
  position += n_;
  data_[position] = new_value;
  while (position > 0) {
    position >>= 1;
    data_[position] = operation_(data_[2 * position], data_[2 * position + 1]);
  }
}

// return Query[a, b)
template<typename T>
T SegmentTree<T>::Query(int a, int b) {
  int vl = initial_value_, vr = initial_value_;
  for (a += n_, b += n_; a < b; a >>= 1, b >>= 1) {
    if (a & 1) vl = operation_(vl, data_[a++]);
    if (b & 1) vr = operation_(data_[--b], vr);
  }
  return operation_(vl, vr);
}

template<typename T>
T SegmentTree<T>::operator[](const int& position) const {
  return data_[n_ + position];
}

void DSL_2_B() {
  int n, q; cin >> n >> q;
  SegmentTree<int> seg(vector<int>(n, 0), 0, [](int x, int y){ return x + y; });
  rep(i, q) {
    int com, x, y; cin >> com >> x >> y;
    if (com == 0) {
      seg.Update(x, seg[x] + y);
    } else {
      cout << seg.Query(x, y + 1) << '\n';
    }
  }
}

class RollingHash {
 public:
  RollingHash(const std::string& s) : s_(s) { Initialize(); }
  std::pair<ull, ull> GetHash(int left, int right);

 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 __gnu_cxx::sfmt19937_64 sfmt_;
  void Initialize();
};

void RollingHash::Initialize() {
  size_t n = s_.size();
  hash0_.assign(n + 1, 0);
  hash1_.assign(n + 1, 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) {
    power0_.emplace_back(power0_.back() * base0_ % mod0_);
    power1_.emplace_back(power1_.back() * base1_ % mod1_);
  }
}

inline std::pair<ull, ull> RollingHash::GetHash(int left, int right) {
 /*
  ull ret0 =
      hash0_[right] + mod0_ - hash0_[left] * power0_[right - left] % mod0_;
  if (ret0 >= mod0_) ret0 -= mod0_;
  ull ret1 =
      hash1_[right] + mod1_ - hash1_[left] * power1_[right - left] % mod1_;
  if (ret1 >= mod1_) ret1 -= mod1_;
 */
  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};
}

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

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

  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';

  return 0;
}

Measured memory_bytes: 532