#include <bits/stdc++.h>
using namespace std;
long long int solve(vector<long long int>& a, long long int u, long long int v,
                    long long int n) {
  unordered_map<long long int, long long int> mp;
  vector<long long int> b(n);
  for (int i = 0; i < n; i++) {
    if (a[i] == u) {
      b[i] = 1;
    } else if (a[i] == v) {
      b[i] = -1;
    } else {
      b[i] = 0;
    }
  }
  long long int ans = 0;
  mp[0] = 0;
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += b[i];
    if (mp.find(sum) != mp.end()) {
      ans = max(ans, i + 1 - mp[sum]);
    } else {
      mp[sum] = i + 1;
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  vector<long long int> a(n), b(101, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  long long int mx = 0, count = -1;
  for (int i = 0; i <= 100; i++) {
    if (b[i] > count) {
      count = b[i];
      mx = i;
    }
  }
  long long int ans = 0;
  for (int i = 0; i < 101; i++) {
    if (i != mx) {
      ans = max(ans, solve(a, i, mx, n));
    }
  }
  cout << ans << "\n";
  return 0;
}
