#include <bits/stdc++.h>
using namespace std;
const long long BIG_INF = 2e18;
const long long INF = 2e9;
const int MAXN = 5e5;
const int alphabet = 26;
const long long mod = 1e9 + 7;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  ~debug() {
    cerr << '\n';
    ;
  }
  template <class c>
  typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) {
    cerr << boolalpha << i;
    return *this;
  }
  template <class c>
  typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) {
    return *this << range(begin(i), end(i));
  }
  template <class c, class b>
  debug& operator<<(pair<b, c> d) {
    return *this << "(" << d.first << ", " << d.second << ")";
  }
  template <class c>
  debug& operator<<(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it;
    return *this << "]";
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, ans = 0;
  cin >> n;
  vector<int> a(n + 1);
  vector<int> cnt(101, 0);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  int best = max_element(cnt.begin(), cnt.end()) - cnt.begin();
  for (int x = 1; x <= 100; ++x) {
    if (x == best || cnt[x] == 0) {
      continue;
    }
    unordered_map<int, int> pos_first;
    vector<int> pref(n + 1, 0);
    for (int i = 1; i <= n; ++i) {
      pref[i] = pref[i - 1];
      if (a[i] == best) {
        pref[i]++;
      }
      if (a[i] == x) {
        pref[i]--;
      }
      if (pref[i] != 0 && pos_first[pref[i]] == 0) {
        pos_first[pref[i]] = i;
      } else {
        ans = max(ans, i - pos_first[pref[i]]);
      }
    }
  }
  cout << ans << '\n';
  ;
  return 0;
}
