#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int a[n];
  vector<int> cnt(101, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  vector<int> h;
  int high = 0;
  for (int i = 1; i < 101; i++) {
    if (high < cnt[i]) {
      h.clear();
      h.push_back(i);
      high = cnt[i];
    } else if (high == cnt[i]) {
      h.push_back(i);
    }
  }
  if ((int)h.size() > 1) {
    cout << n << '\n';
    return;
  }
  int ans = 0;
  for (int i = 1; i < 101; i++) {
    if (i == h[0]) {
      continue;
    }
    int last[2 * n];
    fill(last, last + 2 * n, -2);
    int cur = 0;
    last[cur + n] = -1;
    int ret = 0;
    for (int j = 0; j < n; j++) {
      int num = 0;
      if (a[j] == i) {
        num--;
      } else if (a[j] == h[0]) {
        num++;
      }
      cur += num;
      if (last[cur + n] == -2) {
        last[cur + n] = j;
      } else {
        ret = max(ret, j - last[cur + n]);
      }
    }
    ans = max(ret, ans);
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
