#include <bits/stdc++.h>
using namespace std;
template <typename P, typename Q>
P CeilDiv(P _dividend, Q _divider) {
  return static_cast<P>((_dividend - 1LL + _divider) / _divider);
}
template <typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
  for (Tp current = _begin; current != _end; ++current) {
    std::cout << *current << _delim;
  }
  std::cout << '\n';
}
using ll = int64_t;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<int>(1e9 + 7);
vector<pii> Merge(const vector<int>& a, const vector<int>& b) {
  int i = 0;
  int j = 0;
  vector<pii> res;
  res.reserve(static_cast<int>((a).size()) + static_cast<int>((b).size()));
  while (i < static_cast<int>((a).size()) && j < static_cast<int>((b).size())) {
    if (a[i] < b[j]) {
      res.emplace_back(-1, a[i]);
      ++i;
    } else {
      res.emplace_back(1, b[j]);
      ++j;
    }
  }
  while (i < static_cast<int>((a).size())) {
    res.emplace_back(-1, a[i]);
    ++i;
  }
  while (j < static_cast<int>((b).size())) {
    res.emplace_back(1, b[j]);
    ++j;
  }
  return res;
}
int used[400005];
int Get(vector<pii> vec, int n) {
  int sum = 200000;
  int res = 0;
  memset(used, -1, sizeof(used));
  used[sum] = 0;
  for (int i = 0; i < (static_cast<int>((vec).size())); ++i) {
    if (used[sum] != -1) {
      res = max(res, vec[i].second -
                         (used[sum] > 0 ? vec[used[sum] - 1].second + 1 : 0));
    } else {
      used[sum] = i;
    }
    sum += vec[i].first;
  }
  if (used[sum] != -1) {
    res = max(res, n - (used[sum] > 0 ? vec[used[sum] - 1].second + 1 : 0));
  }
  return res;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n;
  cin >> n;
  vector<vector<int>> pos(101);
  for (int i = 0; i < (n); ++i) {
    int x;
    cin >> x;
    pos[x].push_back(i);
  }
  int b = 0;
  for (int i = 0; i < (100); ++i) {
    if (static_cast<int>((pos[i + 1]).size()) >
        static_cast<int>((pos[b]).size())) {
      b = i + 1;
    }
  }
  int ans = 0;
  for (int a = 1; a <= 100; ++a) {
    if (a != b) {
      ans = max(ans, Get(Merge(pos[a], pos[b]), n));
    }
  }
  cout << ans << "\n";
  return 0;
}
