#include <bits/stdc++.h>
using namespace std;
int n, mx = 0, ans = 0, a[200010], cnt[200010], b[400010];
void sol(int x, int y) {
  for (int i = 0; i <= 2 * n; i++) b[i] = -1;
  b[n] = 0;
  int cur = 0;
  bool flag = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == x)
      cur++, flag = 1;
    else if (a[i] == y)
      cur--, flag = 1;
    if (!flag) continue;
    if (b[cur + n] == -1)
      b[cur + n] = i;
    else
      ans = max(ans, i - b[cur + n]);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    cnt[a[i]]++;
  }
  for (int i = 1; i <= n; i++)
    if (cnt[mx] < cnt[a[i]]) mx = a[i];
  for (int i = 1; i <= 100; i++)
    if (i != mx && cnt[i] != 0) sol(mx, i);
  printf("%d\n", ans);
  return 0;
}
