#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> p) {
  out << p.first << ' ' << p.second;
  return out;
}
template <class T1, class T2>
istream& operator>>(istream& in, pair<T1, T2>& p) {
  in >> p.first >> p.second;
  return in;
}
template <class T>
istream& operator>>(istream& in, vector<T>& v) {
  for (auto& x : v) in >> x;
  return in;
}
template <class T>
ostream& operator<<(ostream& out, vector<vector<T>>& v) {
  for (auto& x : v) out << x << '\n';
  return out;
}
template <class T>
ostream& operator<<(ostream& out, vector<T>& v) {
  for (auto x : v) out << x << ' ';
  return out;
}
long long n;
vector<long long> v;
void solve() {
  cin >> n;
  v.resize(n);
  cin >> v;
  long long ans = 0;
  map<long long, long long> mp;
  for (long long i = 0; i < n; i++) {
    mp[v[i]]++;
  }
  long long mx = -1e9, fr = 0, val = -1;
  for (auto p : mp) {
    if (p.second > mx) {
      fr = 1;
      mx = p.second;
      val = p.first;
    } else if (p.second == mx) {
      fr++;
    }
  }
  if (fr > 1) {
    cout << n;
    return;
  }
  long long res = 0;
  for (long long i = 1; i < min(100ll, n) + 1; i++) {
    vector<long long> p(n + 1, 0);
    vector<long long> pos(2 * (n + 1), -1);
    if (i == val) continue;
    for (long long j = 0; j < n; j++) {
      if (v[j] == i)
        p[j + 1] = 1;
      else if (v[j] == val)
        p[j + 1] = -1;
    }
    pos[n] = 0;
    for (long long j = 1; j < n + 1; j++) {
      p[j] += p[j - 1];
      if (pos[p[j] + n] != -1)
        res = max(res, j - pos[p[j] + n]);
      else
        pos[p[j] + n] = j;
    }
  }
  cout << res;
}
signed main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cerr.tie(0);
  ;
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
