#include <bits/stdc++.h>
using namespace std;
int n, cnt[200200], mx = 0, val = 0, arr[200200], pr[200200], a[200200], ans;
void solve() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
    if (cnt[a[i]] > mx) {
      mx = cnt[a[i]];
      val = a[i];
    }
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == val) {
      arr[i] = -1;
    }
  }
  for (int i = 1; i <= 100; i++) {
    if (i == val) {
      continue;
    }
    vector<int> lPos(400400, -1);
    lPos[200000] = 0;
    for (int i1 = 1; i1 <= n; i1++) {
      if (a[i1] == i) {
        arr[i1] = 1;
      } else {
        if (a[i1] != val) {
          arr[i1] = 0;
        }
      }
      pr[i1] = pr[i1 - 1] + arr[i1];
      if (lPos[pr[i1] + 200000] == -1) {
        lPos[pr[i1] + 200000] = i1;
      } else {
        ans = max(ans, i1 - lPos[pr[i1] + 200000]);
      }
    }
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int q;
  q = 1;
  while (q != 0) {
    solve();
    --q;
  }
}
