#include <bits/stdc++.h>
using namespace std;
const int SIZE = 1 << 26;
char gc[SIZE], *pgc = gc;
char pc[SIZE], *ppc = pc;
clock_t clk = clock();
struct flusher {
  flusher() { fread(gc, true, SIZE, stdin); }
  ~flusher() { fwrite(pc, true, ppc - pc, stdout); }
} Flusher;
int _Neg = 0;
template <class T>
void rd(T& x) {
  x = _Neg = 0;
  while (!isdigit(*pgc)) {
    if ((*pgc++) == '-') {
      _Neg = 1;
    }
  }
  while (isdigit(*pgc)) {
    x = x * 10 + *pgc++ - 48;
  }
  if (_Neg) {
    x = -x;
  }
}
int _Stk[233], _Top = 0;
template <class T>
void pt(T x, char c = '\n') {
  if (x < 0) {
    *ppc++ = '-';
    x = -x;
  }
  do {
    _Stk[++_Top] = x % 10;
    x /= 10;
  } while (x);
  while (_Top) {
    *ppc++ = _Stk[_Top--] + 48;
  }
  *ppc++ = c;
}
void pts(const string& str) {
  int len = (int)str.size();
  for (int i = 0; i <= len - 1; i++) {
    *ppc++ = str[i];
  }
  *ppc++ = '\n';
}
template <class T>
void cmax(T& x, const T& y) {
  x = (x > y) ? x : y;
}
template <class T>
void cmin(T& x, const T& y) {
  x = (x < y) ? x : y;
}
int n;
const int N = 2e5 + 1;
int a[N];
int cnt[N];
int f[N];
int g[N << 1];
int main() {
  rd(n);
  for (int i = 1; i <= n; i++) rd(a[i]);
  for (int i = 1; i <= n; i++) {
    ++cnt[a[i]];
  }
  int mx = max_element(cnt + 1, cnt + 100 + 1) - cnt;
  int ans = 0;
  for (int x = 1; x <= 100; x++) {
    if (x == mx) continue;
    memset(f, 0, sizeof(f));
    memset(g, 0, sizeof(g));
    for (int i = 1; i <= n; i++) {
      f[i] = f[i - 1];
      if (a[i] == x) ++f[i];
      if (a[i] == mx) --f[i];
    }
    for (int i = n; i >= 1; i--) {
      cmax(ans, g[f[i - 1] + n] - i + 1);
      cmax(g[f[i] + n], g[f[i] + n + 1]);
      cmax(g[f[i] + n], i);
    }
  }
  pt(ans);
  return 0;
}
