#include <bits/stdc++.h>
using namespace std;
long long fastpow(long long a, long long b,
                  long long m = (long long)(1e9 + 7)) {
  long long res = 1;
  a %= m;
  while (b > 0) {
    if (b & 1) res = (res * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return res;
}
signed main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ;
  long long n;
  cin >> n;
  vector<long long> arr(n);
  vector<long long> freq(105);
  for (auto &a : arr) {
    cin >> a;
    freq[a]++;
  }
  vector<long long> temp = freq;
  sort(temp.begin(), temp.end());
  if (temp[104] == temp[103]) {
    cout << n << "\n";
    return 0;
  }
  long long mx = max_element(freq.begin(), freq.end()) - freq.begin();
  long long ans = 0;
  vector<long long> cache(4e5 + 5, -10);
  for (long long elem = 1; elem <= 100; elem++) {
    if (elem != mx) {
      cache[0 + (2e5 + 2)] = -1;
      vector<long long> okays;
      okays.push_back(0 + (2e5 + 2));
      long long run = 0;
      for (long long i = 0; i < n; i++) {
        if (arr[i] == mx) {
          run++;
        }
        if (arr[i] == elem) {
          run--;
        }
        if (cache[run + (2e5 + 2)] != -10) {
          ans = max(ans, i - cache[run + (2e5 + 2)]);
        } else {
          cache[run + (2e5 + 2)] = i;
          okays.push_back(run + (2e5 + 2));
        }
      }
      for (auto x : okays) {
        cache[x] = -10;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
