#include <bits/stdc++.h>
using namespace std;
void foo() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> freq(n + 5);
  int max_freq = 0;
  int val;
  for (int i : a) {
    freq[i]++;
    if (freq[i] > max_freq) {
      max_freq = freq[i];
      val = i;
    }
  }
  int ans = 0;
  for (int x = 1; x <= min(n, 100); x++) {
    if (x == val) continue;
    vector<int> first(n * 2 + 5, 1e8);
    first[n] = -1;
    int pref = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == val) {
        pref++;
      } else if (a[i] == x) {
        pref--;
      }
      ans = max(ans, i - first[pref + n]);
      first[pref + n] = min(first[pref + n], i);
    }
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  foo();
}
