#include <bits/stdc++.h>
using namespace std;
int n;
int a[2000007], b[2000007];
unordered_map<int, int> cnt;
unordered_map<int, int> las;
int main() {
  scanf("%d", &n);
  auto mx = make_pair(0, 0);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    cnt[a[i]]++;
    mx = max(mx, make_pair(cnt[a[i]], a[i]));
  }
  int maxx = mx.first;
  int id = mx.second;
  int sum = 0;
  for (auto [x, y] : cnt) {
    sum += (y == maxx);
  }
  if (sum > 1) {
    printf("%d\n", n);
    return 0;
  }
  assert(cnt.size() <= 100);
  int ans = 0;
  for (auto [y, x] : cnt) {
    if (y == id) continue;
    las.clear();
    int tp = 0;
    las[tp] = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] == y) tp--;
      if (a[i] == id) tp++;
      if (las.find(tp) == las.end()) {
        las[tp] = i;
      }
      ans = max(ans, i - las[tp]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
