#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n + 1);
  const int M = 105;
  vector<int> frec(M, 0);
  vector<int> val;
  int mx = 0;
  int cnt = 0;
  int who = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    frec[a[i]] += 1;
    if (frec[a[i]] > mx) {
      mx = frec[a[i]];
      cnt = 1;
      who = a[i];
    } else if (frec[a[i]] == mx) {
      cnt += 1;
    }
    val.push_back(a[i]);
  }
  if (cnt > 1) {
    cout << n << '\n';
    return (0);
  }
  sort(begin(val), end(val));
  val.erase(unique(begin(val), end(val)), end(val));
  int ans = 0;
  for (int bi : val) {
    if (bi == who) continue;
    vector<int> dp(2 * n + 1, INT_MAX);
    int offset = n;
    auto get = [&](int pos) { return pos + offset; };
    dp[get(0)] = 0;
    int acc = 0;
    int res = 0;
    for (int i = 1; i <= n; i++) {
      int cost = (a[i] == bi) ? 1 : (a[i] == who) ? -1 : 0;
      acc += cost;
      int x = get(acc);
      if (dp[x] != INT_MAX) res = max(res, i - dp[x]);
      dp[x] = min(dp[x], i);
    }
    ans = max(ans, res);
  }
  cout << ans << '\n';
  return (0);
}
