#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int n, a[N], cnt[N], zs, ans;
int fir[N << 1];
void work(int x) {
  int now = N;
  memset(fir, -1, sizeof(fir));
  fir[now] = 0;
  for (int i = 1, iE = n; i <= iE; i++) {
    if (a[i] == zs)
      now++;
    else if (a[i] == x)
      now--;
    if (fir[now] == -1)
      fir[now] = i;
    else
      ans = max(ans, i - fir[now]);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1, iE = n; i <= iE; i++) scanf("%d", &a[i]), cnt[a[i]]++;
  for (int i = 1, iE = n; i <= iE; i++)
    if (cnt[i] > cnt[zs]) zs = i;
  for (int i = 1, iE = min(n, 100); i <= iE; i++)
    if (i != zs) work(i);
  printf("%d\n", ans);
  return 0;
}
