#include <bits/stdc++.h>
using namespace std;
template <typename Tp>
inline void read(Tp &x) {
  x = 0;
  bool neg = false;
  char c = getchar();
  for (; !isdigit(c); c = getchar()) {
    if (c == '-') {
      neg = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (neg) {
    x = -x;
  }
}
const int N = 200000 + 5;
const int M = 100 + 5;
int n;
int a[N], bin[M];
int p[N];
int main() {
  read(n);
  for (int i = 1; i <= n; ++i) {
    read(a[i]);
    ++bin[a[i]];
  }
  int D = 1, cnt = 1;
  for (int i = 2; i < M; ++i) {
    if (bin[i] > bin[D]) {
      D = i;
      cnt = 1;
    } else if (bin[i] == bin[D]) {
      ++cnt;
    }
  }
  if (cnt >= 2) {
    printf("%d\n", n);
    return 0;
  }
  int ans = 0;
  auto solve = [&](const int &V) {
    memset(p, -1, sizeof(int) * (n + 1));
    int cur = bin[D];
    p[cur] = 0;
    for (int i = 1; i <= n; ++i) {
      if (a[i] == D) {
        --cur;
      } else if (a[i] == V) {
        ++cur;
      }
      if (p[cur] == -1) {
        p[cur] = i;
      } else {
        ans = std::max(ans, i - p[cur]);
      }
    }
  };
  for (int i = 1; i < M; ++i) {
    if (bin[i] != 0 && i != D) {
      solve(i);
    }
  }
  printf("%d\n", ans);
  return 0;
}
