#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
long long int power(long long int x, long long int y) {
  long long int res = 1;
  x = x % mod;
  while (y > 0) {
    if (y & 1) res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res;
}
long long int exp(long long int x, long long int y) {
  if (y == 0) return 1;
  if (x == 0 || x == 1) return x;
  long long int p = exp(x, y / 2);
  p = (p * p);
  if (y % 2) p = (x * p);
  return p;
}
bool check_prime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
const long long int max_size = 1e7 + 5;
bool prime[max_size];
void prime_seive(long long int n) {
  memset(prime, true, sizeof(prime));
  for (long long int i = 2; i * i <= n; i++) {
    if (prime[i]) {
      for (long long int j = i * i; j <= n; j += i) prime[j] = false;
    }
  }
}
void solve();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  t = 1;
  for (long long int z = 1; z <= t; z++) {
    solve();
  }
  return 0;
}
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> A(n);
  for (int i = 0; i < (int)A.size(); ++i) cin >> A[i];
  unordered_map<long long int, long long int> m;
  for (long long int i = 0; i < n; i++) m[A[i]]++;
  vector<long long int> store;
  long long int freq = 0;
  for (auto &it : m) {
    if (it.second > freq) {
      store.clear();
      store.push_back(it.first);
      freq = it.second;
    } else if (it.second == freq) {
      store.push_back(it.first);
    }
  }
  if (store.size() >= 2) {
    cout << n << "\n";
    return;
  }
  long long int val = store[0];
  long long int ans = 0;
  for (long long int i = 1; i <= 100; i++) {
    if (i == val) continue;
    unordered_map<long long int, long long int> make_pair;
    long long int sum = 0;
    for (long long int j = 0; j < n; j++) {
      if (A[j] == i)
        sum--;
      else if (A[j] == val)
        sum++;
      else
        sum += 0;
      if (sum == 0) {
        ans = max(ans, j + 1);
      } else {
        if (make_pair.find(sum) != make_pair.end()) {
          ans = max(ans, j - make_pair[sum]);
        } else
          make_pair[sum] = j;
      }
    }
  }
  cout << ans << "\n";
  return;
}
