#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using pi = pair<int, int>;
namespace output {
void pr(int x) { cout << x; }
void pr(long x) { cout << x; }
void pr(ll x) { cout << x; }
void pr(unsigned x) { cout << x; }
void pr(unsigned long x) { cout << x; }
void pr(unsigned long long x) { cout << x; }
void pr(float x) { cout << x; }
void pr(double x) { cout << x; }
void pr(long double x) { cout << x; }
void pr(char x) { cout << x; }
void pr(const char* x) { cout << x; }
void pr(const string& x) { cout << x; }
void pr(bool x) { pr(x ? "true" : "false"); }
template <class T1, class T2>
void pr(const pair<T1, T2>& x);
template <class T>
void pr(const T& x);
template <class T, class... Ts>
void pr(const T& t, const Ts&... ts) {
  pr(t);
  pr(ts...);
}
template <class T1, class T2>
void pr(const pair<T1, T2>& x) {
  pr("{", x.first, ", ", x.second, "}");
}
template <class T>
void pr(const T& x) {
  pr("{");
  bool fst = 1;
  for (const auto& a : x) pr(!fst ? ", " : "", a), fst = 0;
  pr("}");
}
void ps() { pr("\n"); }
template <class T, class... Ts>
void ps(const T& t, const Ts&... ts) {
  pr(t);
  if (sizeof...(ts)) pr(" ");
  ps(ts...);
}
void pc() { cout << "]" << endl; }
template <class T, class... Ts>
void pc(const T& t, const Ts&... ts) {
  pr(t);
  if (sizeof...(ts)) pr(", ");
  pc(ts...);
}
}  // namespace output
using namespace output;
const int MX = 200005;
const int MOD = (int)(1e9 + 7);
const ll INF = (ll)1e18;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vi a(n);
  vi cnt(101);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  pi best = make_pair(-1, -1);
  for (int i = 1; i <= 100; i++) {
    if (cnt[i] > best.second) best = make_pair(i, cnt[i]);
  }
  for (int i = 1; i <= 100; i++) {
    if (i != best.first && cnt[i] == best.second) {
      cout << n << '\n';
      return 0;
    }
  }
  int ret = 0;
  for (int v = 1; v <= 100; v++) {
    if (v == best.first) continue;
    int ans = 0;
    vi nv(n);
    for (int i = 0; i < n; i++) {
      if (a[i] == v)
        nv[i] = -1;
      else if (a[i] == best.first)
        nv[i] = 1;
    }
    vi mn(2 * n + 1, -2);
    mn[n] = -1;
    int sum = 0;
    for (int i = 0; i < n; i++) {
      sum += nv[i];
      if (mn[sum + n] != -2)
        ans = max(ans, i - mn[sum + n]);
      else
        mn[sum + n] = i;
    }
    ret = max(ret, ans);
  }
  cout << ret << '\n';
}
