#include <bits/stdc++.h>
using namespace std;
template <class T>
bool mmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool mmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
void yesno(bool c) { cout << (c ? "YES" : "NO") << '\n'; }
void yes() { yesno(true); }
void no() { yesno(false); }
void imp() { cout << "-1" << '\n'; }
const int inf = 0x3f3f3f3f;
const long long infl = 0x3f3f3f3f3f3f3f3f;
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); i++) cin >> a[i];
  vector<int> occ(101);
  int mocc = -1, d = -1;
  for (int i = 0; i < (n); i++) {
    occ[a[i]]++;
    if (mmax(mocc, occ[a[i]])) d = a[i];
  }
  int ans = 0, off = n + 5;
  for (int val = 1; val <= (100); val++) {
    vector<int> pos(2 * off, -2);
    pos[off] = -1;
    int sm = 0;
    for (int i = 0; i < (n); i++) {
      if (a[i] == d)
        sm++;
      else if (a[i] == val)
        sm--;
      if (pos[sm + off] == -2)
        pos[sm + off] = i;
      else {
        mmax(ans, i - pos[sm + off]);
      }
    }
  }
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tc = 1;
  while (tc--) solve();
  return 0;
}
