#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int sum[N][110];
int cnt[N];
int a[N];
int main() {
  int n;
  cin >> n;
  int ans = 0;
  int mx = 0, mxi = 0, tot = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    cnt[a[i]]++;
    if (mx < cnt[a[i]]) {
      mx = cnt[a[i]];
      mxi = a[i];
      tot = 1;
    } else if (mx == cnt[a[i]]) {
      tot++;
    }
  }
  if (tot > 1) {
    cout << n << '\n';
    return 0;
  }
  for (int k = 1; k <= min(n, 100); ++k) {
    if (k == mxi) continue;
    int now = 0;
    unordered_map<int, int> mp;
    mp[0] = 0;
    for (int i = 1; i <= n; ++i) {
      if (a[i] == mxi) {
        now++;
      } else if (a[i] == k) {
        now--;
      }
      if (!mp.count(now)) {
        mp[now] = i;
      } else {
        ans = max(ans, i - mp[now]);
      }
    }
  }
  cout << ans;
  return 0;
}
