#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long power(long long x, long long y, long long p = 1e18) {
  long long result = 1;
  x %= p;
  while (y > 0) {
    if (y & 1) result = (result * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return result;
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  unordered_map<long long, long long> mp;
  long long mux = 0, d;
  bool foo = false;
  for (long long i = 0; i < (long long)(n); ++i) {
    cin >> a[i];
    mp[a[i]]++;
    if (mux == mp[a[i]]) {
      foo = true;
    } else if (mux < mp[a[i]]) {
      mux = mp[a[i]];
      d = a[i];
      foo = false;
    }
  }
  if (foo) {
    cout << n;
    return;
  }
  long long res = 0;
  for (long long i = 1; i <= (long long)(100); ++i) {
    if (i == d) continue;
    long long cur = 0;
    unordered_map<long long, long long> sums;
    sums[0] = -1;
    for (long long j = 0; j < (long long)(n); ++j) {
      if (a[j] == i)
        cur--;
      else if (a[j] == d)
        cur++;
      if (sums.find(cur) == sums.end())
        sums[cur] = j;
      else {
        res = max(res, j - sums[cur]);
      }
    }
  }
  cout << res << "\n";
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  long long x = 1;
  cout << fixed << setprecision(12);
  while (t--) {
    solve();
    x++;
  }
  cerr << "Time Taken : " << (float)clock() / CLOCKS_PER_SEC << " secs"
       << "\n";
}
