#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const long long N = 2e5 + 100;
const long long inf = 1e7;
const long long mod1 = 1e9 + 7;
const long long mod2 = 998244353;
const long long base = 137;
const long long al = 26;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  ;
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; ++i) cin >> a[i];
  vector<long long> id[101];
  for (long long i = 0; i < n; ++i) id[a[i]].push_back(i);
  long long freq = 0;
  for (long long i = 0; i < 101; ++i) freq = max(freq, (long long)id[i].size());
  vector<long long> v;
  for (long long i = 0; i < 101; ++i) {
    if (id[i].size() == freq) v.push_back(i);
  }
  if (v.size() > 1)
    cout << n;
  else {
    long long x = v[0];
    long long res = 0;
    for (long long y = 1; y < 101; ++y) {
      if (y == x) continue;
      vector<pair<long long, long long>> val;
      for (long long i = 0; i < n; ++i) {
        if (a[i] == x) val.emplace_back(i, 1);
        if (a[i] == y) val.emplace_back(i, -1);
      }
      unordered_map<long long, long long> lowest;
      long long s = 0;
      for (long long i = 0; i < val.size(); ++i) {
        s += val[i].second;
        long long ri = n - 1;
        if (i != val.size() - 1) ri = val[i + 1].first - 1;
        if (s == 0) {
          res = max(res, ri + 1);
          continue;
        }
        if (lowest.count(s))
          res = max(res, ri - val[lowest[s]].first);
        else
          lowest[s] = i;
      }
    }
    cout << res;
  }
}
