#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const double EPS = 1e-9;
const double PI = acos(-1.);
const long long LL_INF = 1e17 + 16;
const int INF = 1e9 + 10;
const long long MOD = 1e9 + 7;
const int MAXN = 2e5 + 5, MAXD = 105;
int v[MAXN];
int cnt[MAXD];
int dif_ind[2 * MAXN];
int process(int n, int a, int b) {
  if (a == b) {
    return 0;
  }
  int ans = 0;
  int *_dif_ind = dif_ind + n;
  for (int i = (-n); i <= (int)(n); i++) {
    _dif_ind[i] = -1;
  }
  _dif_ind[0] = 0;
  int balance = 0;
  for (int i = (1); i <= (int)(n); i++) {
    if (v[i] == a) {
      balance++;
    } else if (v[i] == b) {
      balance--;
    }
    if (_dif_ind[balance] == -1) {
      _dif_ind[balance] = i;
    } else {
      ans = max(ans, i - _dif_ind[balance]);
    }
  }
  return ans;
}
void solve() {
  int n;
  scanf("%d", &n);
  int maxi = 0;
  for (int i = (1); i <= (int)(n); i++) {
    scanf("%d", &v[i]);
    cnt[v[i]]++;
    if (cnt[v[i]] > cnt[maxi]) {
      maxi = v[i];
    }
  }
  int ans = 0;
  for (int i = (0); i < (int)(MAXD); i++) {
    ans = max(ans, process(n, maxi, i));
  }
  printf("%d\n", ans);
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
}
