#include <bits/stdc++.h>
template <class I>
inline void read(I &num) {
  num = 0;
  char c = getchar(), up = c;
  while (!isdigit(c)) up = c, c = getchar();
  while (isdigit(c)) num = (num << 1) + (num << 3) + (c ^ '0'), c = getchar();
  up == '-' ? num = -num : 0;
  return;
}
template <class I>
inline void read(I &a, I &b) {
  read(a);
  read(b);
}
template <class I>
inline void read(I &a, I &b, I &c) {
  read(a);
  read(b);
  read(c);
}
int n;
int a[200009], sum[200009];
int buc[109], left[200009 << 1];
int maxi, num;
inline int getval(int x, int i) {
  if (a[i] == maxi) return 1;
  if (a[i] == x) return -1;
  return 0;
}
inline int getd(int x) { return x + n; }
signed main() {
  read(n);
  for (int i = 1; i <= n; i++) read(a[i]), ++buc[a[i]];
  int tot = 0;
  for (int i = 1; i <= 100; i++) {
    if (buc[i] == num) ++tot;
    if (buc[i] > num) num = buc[i], tot = 1, maxi = i;
  }
  if (tot >= 2) return printf("%d\n", n), 0;
  int ans = 0;
  for (int i = 1; i <= 100; i++) {
    sum[0] = 0;
    for (int j = 1; j <= n; j++) {
      sum[j] = sum[j - 1] + getval(i, j);
    }
    memset(left, 0x3f, sizeof left);
    for (int j = 1; j <= n; j++) {
      ans = std::max(ans, j - left[getd(sum[j])] + 1);
      if (left[getd(sum[j - 1])] > n) left[getd(sum[j - 1])] = j;
    }
  }
  std::cout << ans << '\n';
  return 0;
}
