#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool ylmin(T &a, T b) {
  return a < b ? 0 : (a = b, 1);
}
template <class T>
inline bool ylmax(T &a, T b) {
  return a > b ? 0 : (a = b, 1);
}
template <class T>
inline T abs(T x) {
  return x < 0 ? -x : x;
}
inline char read() {
  static const int IO_LEN = 1024 * 1024;
  static char buf[IO_LEN], *ioh, *iot;
  if (ioh == iot) {
    iot = (ioh = buf) + fread(buf, 1, IO_LEN, stdin);
    if (ioh == iot) return -1;
  }
  return *ioh++;
}
template <class T>
inline void read(T &x) {
  static int iosig;
  static char ioc;
  for (iosig = 0, ioc = read(); !isdigit(ioc); ioc = read())
    if (ioc == '-') iosig = 1;
  for (x = 0; isdigit(ioc); ioc = read()) x = (x << 1) + (x << 3) + (ioc ^ '0');
  if (iosig) x = -x;
}
const int MAXN = 2e5 + 10;
int n, ans, a[MAXN], cnt[MAXN], pos[MAXN << 1];
int main() {
  read(n);
  for (int i = (1); i <= (n); i++) read(a[i]), cnt[a[i]]++;
  int d = max_element(cnt + 1, cnt + n + 1) - cnt;
  int *last = &pos[MAXN];
  for (int s = (1); s <= (100); s++) {
    if (s == d) continue;
    for (int i = (-n); i <= (n); i++) last[i] = -1;
    int nw = 0;
    last[0] = 0;
    for (int i = (1); i <= (n); i++) {
      if (a[i] == s)
        nw++;
      else if (a[i] == d)
        nw--;
      if (last[nw] == -1)
        last[nw] = i;
      else
        ylmax(ans, i - last[nw]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
