#include <bits/stdc++.h>
namespace IO {
const int N = 5e5;
char buf[N], *p1 = buf, *p2 = buf;
inline char getchar() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, N, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <typename T>
inline void read(T &x) {
  x = 0;
  bool f = 0;
  char a = getchar();
  for (; !isdigit(a); a = getchar())
    if (a == '-') f = 1;
  for (; isdigit(a); a = getchar()) x = x * 10 + (a ^ 48);
  if (f) x = -x;
}
char Of[105], *O1 = Of, *O2 = Of;
template <typename T>
inline void print(T n, char ch = '\n') {
  if (n < 0) putchar('-'), n = -n;
  if (n == 0) putchar('0');
  while (n) *(O1++) = (n % 10) ^ 48, n /= 10;
  while (O1 != O2) putchar(*(--O1));
  putchar(ch);
}
}  // namespace IO
using IO ::print;
using IO ::read;
using namespace std;
const int N = 4e5 + 10;
int n;
int a[N], cnt[N], mx;
int tong[N];
int solve(int v) {
  int res = 0;
  for (register int i = 0; i <= n * 2; i++) tong[i] = 0;
  int nw = 0;
  for (register int i = 1; i <= n; i++) {
    if (a[i] == mx) nw--;
    if (a[i] == v) nw++;
    if (nw == 0)
      res = max(res, i);
    else {
      if (tong[n + nw] == 0)
        tong[n + nw] = i;
      else
        res = max(res, i - tong[n + nw]);
    }
  }
  return res;
}
int main() {
  read(n);
  for (register int i = 1; i <= n; i++) {
    read(a[i]);
    cnt[a[i]]++;
    if (cnt[a[i]] > cnt[mx]) mx = a[i];
  }
  int Ans = 0;
  for (register int i = 1; i <= 100; i++)
    if (i != mx) Ans = max(Ans, solve(i));
  print(Ans);
  return 0;
}
