#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 0;
  char c = getchar();
  while (!isdigit(c)) f |= c == '-', c = getchar();
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  return f ? -x : x;
}
inline int max(int a, int b, int c) { return max(a, max(b, c)); }
int n, a[200010], cnt[200010];
int f[2 * 200010], ans;
int main() {
  cin >> n;
  vector<int> pos[200010];
  for (int i = 1; i <= n; ++i) a[i] = read(), ++cnt[a[i]];
  int mx = 0, p = 0;
  bool F = 0;
  for (int i = 1; i <= 100; ++i)
    if (cnt[i] > mx) mx = cnt[i], p = i;
  for (int i = 1; i <= 100; ++i)
    if (cnt[i] == mx && p != i) F = 1;
  for (int i = 1; i <= 100; ++i) {
    memset(f, -1, sizeof f);
    f[200000] = 0;
    int s = 0;
    for (int j = 1; j <= n; ++j) {
      if (a[j] == p)
        --s;
      else if (a[j] == i)
        ++s;
      if (~f[s + 200000])
        ans = max(ans, j - f[s + 200000]);
      else
        f[s + 200000] = j;
    }
  }
  cout << ans << endl;
  return 0;
}
