#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e9;
const int MX = 2e5 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0};
template <class T>
using V = vector<T>;
template <class T>
bool ckmin(T& a, const T& b) {
  return a > b ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
long long cdiv(long long a, long long b) {
  return a / b + ((a ^ b) > 0 && a % b);
}
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
long long random(long long a, long long b) { return a + rng() % (b - a + 1); }
void IO() {}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  IO();
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = (0); i < (N); ++i) cin >> a[i];
  int cnt[101];
  fill(cnt, cnt + 101, 0);
  int mx = 0, D;
  for (auto x : a) {
    cnt[x]++;
    if (ckmax(mx, cnt[x])) D = x;
  }
  int ans = 0;
  for (int V = (1); V < (101); ++V)
    if (V != D) {
      vector<int> v(N);
      for (int i = (0); i < (N); ++i) {
        if (a[i] == D)
          v[i] = 1;
        else if (a[i] == V)
          v[i] = -1;
        else
          v[i] = 0;
      }
      unordered_map<int, int> pre;
      int s = 0;
      for (int i = (0); i < (N); ++i) {
        s += v[i];
        pre[s] = INF;
      }
      pre[0] = -1;
      for (int i = (0); i < (N); ++i) {
        if (i) v[i] += v[i - 1];
        ckmax(ans, i - pre[v[i]]);
        if (pre[v[i]] == INF) pre[v[i]] = i;
      }
    }
  cout << ans << "\n";
  return 0;
}
