#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int a[maxn], f[maxn];
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    f[a[i]]++;
  }
  int d = -1, cnt = -1;
  for (int i = 1; i <= n; ++i) {
    if (f[i] > cnt) {
      cnt = f[i];
      d = i;
    }
  }
  int ans = 0;
  int lim = min(n, 100);
  for (int i = 1; i <= lim; ++i) {
    if (i == d) continue;
    unordered_map<int, int> mp;
    mp.reserve(1024);
    mp.max_load_factor(0.25);
    mp[0] = 0;
    int pref = 0;
    for (int j = 1; j <= n; ++j) {
      if (a[j] == d) ++pref;
      if (a[j] == i) --pref;
      if (mp.find(pref) != mp.end()) {
        ans = max(ans, j - mp[pref]);
      } else {
        mp[pref] = j;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
