#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
const int nmax = 200010;
int fst[nmax * 2];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VI a(n);
  for (int i = 0; i < (n); ++i) cin >> a[i];
  int amax = 0;
  for (int i = 0; i < (n); ++i) amax = max(amax, a[i]);
  assert(amax <= 105);
  VI hist(amax + 1);
  for (int i = 0; i < (n); ++i) hist[a[i]] += 1;
  int fmax = 0;
  for (int i = 0; i < (amax + 1); ++i) fmax = max(fmax, hist[i]);
  int fmaxcnt = 0;
  int mi = 0;
  for (int i = 0; i < (amax + 1); ++i)
    if (hist[i] == fmax) {
      fmaxcnt++;
      mi = i;
    }
  if (fmaxcnt >= 2) {
    cout << n << endl;
    return 0;
  }
  int ans = 0;
  for (int x = 0; x < (amax + 1); ++x) {
    if (x == mi) continue;
    int now = nmax;
    for (int i = 0; i < (nmax * 2); ++i) fst[i] = -1;
    fst[now] = 0;
    for (int i = 0; i < (n); ++i) {
      if (a[i] == mi)
        now++;
      else if (a[i] == x)
        now--;
      if (fst[now] == -1)
        fst[now] = i + 1;
      else {
        ans = max(ans, i + 1 - fst[now]);
      }
    }
  }
  cout << ans << endl;
}
