#include <bits/stdc++.h>
template <typename T>
inline void rd(T& x) {
  int si = 1;
  char c = getchar();
  x = 0;
  while (!isdigit(c)) si = c == '-' ? -1 : si, c = getchar();
  while (isdigit(c)) x = x * 10 + c - 48, c = getchar();
  x *= si;
}
template <typename T, typename... Args>
inline void rd(T& x, Args&... args) {
  rd(x);
  rd(args...);
}
const int kN = 4e5 + 5, kMov = 2e5 + 3, kInf = 0x3f3f3f3f;
const long long kMod = 998244353, kInfLL = 0x3f3f3f3f3f3f3f3fLL;
int n, A[kN], cnt[kN], b[kN];
int main() {
  int T = 1;
  while (T--) {
    int mx_A = 0, ans = 0;
    rd(n);
    for (int i = 1; i <= n; ++i) rd(A[i]), ++cnt[A[i]];
    for (int i = 1; i <= std::min(n, 100); ++i) {
      if (cnt[i] > cnt[mx_A]) mx_A = i;
    }
    for (int i = 1; i <= std::min(n, 100); ++i)
      if (i != mx_A) {
        memset(b, 0xff, sizeof(b));
        int s = 0;
        b[kMov] = 0;
        for (int j = 1; j <= n; ++j) {
          if (A[j] == mx_A)
            ++s;
          else if (A[j] == i)
            --s;
          if (b[s + kMov] == -1) b[s + kMov] = j;
          ans = std::max(ans, j - b[s + kMov]);
        }
      }
    printf("%d\n", ans);
  }
  return 0;
}
