#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
const long long MAXN = 2e5 + 10;
const long long INF = 0x3f3f3f3f;
const long long MOD = 1e9 + 7;
const long double eps = 1e-9;
const long double PI = acos(-1.0);
long long n, maxV = 0;
long long arr[MAXN], cnt[MAXN], mp[MAXN * 2];
long long solve(long long x) {
  memset(mp, 0x3f, sizeof(mp));
  mp[n] = -1;
  long long sum = 0;
  long long res = 0;
  for (long long i = 0; i < n; i++) {
    if (arr[i] == maxV)
      sum++;
    else if (arr[i] == x)
      sum--;
    if (mp[n + sum] >= INF) {
      mp[n + sum] = i;
    } else {
      res = max(res, i - mp[n + sum]);
    }
  }
  return res;
}
signed main() {
  n = read();
  for (long long i = 0; i < n; i++) {
    arr[i] = read();
    cnt[arr[i]]++;
  }
  long long fre = 0;
  for (long long i = 0; i < n; i++) {
    if (cnt[arr[i]] > fre) {
      fre = cnt[arr[i]];
      maxV = arr[i];
    }
  }
  long long ans = 0;
  for (long long i = 1; i <= min(100ll, n); i++) {
    if (!cnt[i] || i == maxV) continue;
    ans = max(ans, solve(i));
  }
  cout << ans << endl;
  return 0;
}
