#include <bits/stdc++.h>
using std::max;
using std::min;
const int inf = 0x3f3f3f3f, Inf = 0x7fffffff;
const long long INF = 0x3f3f3f3f3f3f3f3f;
std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
template <typename _Tp>
_Tp gcd(const _Tp &a, const _Tp &b) {
  return (!b) ? a : gcd(b, a % b);
}
template <typename _Tp>
inline _Tp abs(const _Tp &a) {
  return a >= 0 ? a : -a;
}
template <typename _Tp>
inline void chmax(_Tp &a, const _Tp &b) {
  (a < b) && (a = b);
}
template <typename _Tp>
inline void chmin(_Tp &a, const _Tp &b) {
  (b < a) && (a = b);
}
template <typename _Tp>
inline void read(_Tp &x) {
  char ch(getchar());
  bool f(false);
  while (!isdigit(ch)) f |= ch == 45, ch = getchar();
  x = ch & 15, ch = getchar();
  while (isdigit(ch)) x = (((x << 2) + x) << 1) + (ch & 15), ch = getchar();
  f && (x = -x);
}
template <typename _Tp, typename... Args>
inline void read(_Tp &t, Args &...args) {
  read(t);
  read(args...);
}
inline int read_str(char *s) {
  char ch(getchar());
  while (ch == ' ' || ch == '\r' || ch == '\n') ch = getchar();
  char *tar = s;
  *tar = ch, ch = getchar();
  while (ch != ' ' && ch != '\r' && ch != '\n' && ch != EOF)
    *(++tar) = ch, ch = getchar();
  return tar - s + 1;
}
const int N = 200005;
int a[N], cnt[N], sum[N];
int pos[N + N];
int main() {
  int n;
  read(n);
  for (int i = 1; i <= n; ++i) read(a[i]), ++cnt[a[i]];
  int maxx = *std::max_element(cnt + 1, cnt + 101), id = 0;
  for (int i = 1; i <= 100; ++i)
    if (cnt[i] == maxx) id = i;
  int ans = 0;
  for (int x = 1; x <= 100; ++x) {
    if (x == id) continue;
    memset(pos, 255, sizeof(pos));
    pos[N] = 0;
    for (int i = 1; i <= n; ++i) {
      sum[i] = sum[i - 1] + (a[i] == id) - (a[i] == x);
      if (~pos[sum[i] + N])
        chmax(ans, i - pos[sum[i] + N]);
      else
        pos[sum[i] + N] = i;
    }
  }
  printf("%d\n", ans);
  return 0;
}
