#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long INF = 1e18;
const double eps = 1e-10;
const double pi = acos(-1);
mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count());
template <class T>
inline void upmin(T &x, T y) {
  x = x > y ? y : x;
}
template <class T>
inline void upmax(T &x, T y) {
  x = x < y ? y : x;
}
const int maxn = 4e5 + 233;
int a[maxn];
int cnt[maxn];
int n;
const int base = 2e5 + 5;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(10);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  int mx = 0, len = 1;
  for (int i = 1; i <= 100; i++) {
    if (cnt[i] > cnt[mx])
      mx = i, len = 1;
    else if (cnt[i] == cnt[mx])
      len++;
  }
  if (len >= 2) {
    cout << n << '\n';
  } else {
    int res = 0;
    for (int i = 1; i <= 100; i++) {
      if (i == mx) continue;
      memset(cnt, -1, sizeof(cnt));
      cnt[base] = 0;
      int sum = 0;
      for (int j = 1; j <= n; j++) {
        if (a[j] == i) sum++;
        if (a[j] == mx) sum--;
        if (cnt[base + sum] != -1) upmax(res, j - cnt[base + sum]);
        if (cnt[base + sum] == -1) cnt[base + sum] = j;
      }
    }
    printf("%d\n", res);
  }
  return 0;
}
