#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long int M = 1000000007;
long long int inv(long long int a, long long int b) {
  return 1 < a ? b - inv(b % a, a) * b / a : 1;
}
long long int gcd(long long int x, long long int y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
pair<long long int, long long int> neigh[4] = {
    {-1, 0}, {1, 0}, {0, 1}, {0, -1}};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for (long long int _i = 0; _i < (n); _i++) cin >> a[_i];
  vector<pair<long long int, long long int> > res;
  long long int count[101];
  memset(count, 0, sizeof(count));
  for (long long int i = 0; i < (n); i++) {
    count[a[i]]++;
  }
  for (long long int i = 1; i < (101); i++) {
    res.push_back({count[i], i});
  }
  sort(res.begin(), res.end());
  if (res[99].first == res[98].first) {
    cout << (n) << endl;
    return 0;
  }
  long long int num = res[99].second;
  long long int ans = 0;
  for (long long int i = 1; i < (101); i++) {
    if (num == i) continue;
    long long int tmp[n];
    for (long long int j = 0; j < (n); j++) {
      tmp[j] = num == a[j] ? 1 : (a[j] == i ? -1 : 0);
    }
    unordered_map<long long int, long long int> last(n);
    last[0] = -1;
    long long int sum = 0;
    for (long long int j = 0; j < (n); j++) {
      sum += tmp[j];
      if (last.count(sum))
        ans = max(ans, j - last[sum]);
      else
        last[sum] = j;
    }
  }
  cout << ans << endl;
}
