#include <bits/stdc++.h>
const int maxn = 200005, maxk = 105;
int n, maxx, cnt, ans;
int a[maxn], tot[maxk], sum[maxn], t[maxn * 2];
inline int min(int a, int b) { return a < b ? a : b; }
inline int max(int a, int b) { return a > b ? a : b; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    tot[a[i]]++;
  }
  for (int i = 1; i <= 100; i++) {
    if (tot[i] == maxx) cnt++;
    if (tot[i] > maxx) cnt = 1, maxx = tot[i];
  }
  if (cnt > 1) {
    printf("%d\n", n);
    return 0;
  }
  for (int i = 1; i <= 100; i++)
    if (tot[i] == maxx) {
      maxx = i;
      break;
    }
  for (int i = 1; i <= 100; i++) {
    for (int j = 1; j <= n; j++)
      sum[j] = sum[j - 1] + (a[j] == i ? -1 : (a[j] == maxx ? 1 : 0));
    for (int j = -n; j <= n; j++) t[n + j] = 1000000000;
    for (int j = 1; j <= n; j++) {
      ans = max(ans, j - t[n + sum[j]] + 1);
      t[n + sum[j - 1]] = min(t[n + sum[j - 1]], j);
    }
  }
  printf("%d\n", ans);
  return 0;
}
