#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + ch - '0';
  return (f == 1) ? x : -x;
}
const int maxn = 200005;
const int inf = 0x3f3f3f3f;
int n, a[maxn], cnt[maxn], sum[maxn << 1];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), cnt[a[i]]++;
  int mx = 0, se = 0, D = 0;
  for (int i = 1; i <= 100; i++)
    if (cnt[i] > mx)
      mx = cnt[i], se = 1, D = i;
    else if (cnt[i] == mx)
      se++;
  if (se >= 2) return printf("%d\n", n), 0;
  int ans = 0;
  for (int i = 1; i <= 100; i++)
    if (i != D) {
      for (int j = 0; j <= 2 * n; j++) sum[j] = inf;
      int now = 0;
      sum[n] = 0;
      for (int j = 1; j <= n; j++) {
        now += (a[j] == D) ? 1 : (a[j] == i) ? -1 : 0;
        ans = max(ans, j - sum[now + n]);
        sum[now + n] = min(sum[now + n], j);
      }
    }
  printf("%d\n", ans);
  return 0;
}
