#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const string nl = "\n";
vector<int> readVector(int n) {
  vector<int> ret(n);
  for (int i = 0; i < n; i++) cin >> ret[i];
  return ret;
}
vector<int> a;
int n;
int check(int d, int v) {
  int sum = 0;
  unordered_map<int, int> presum;
  presum[0] = 0;
  int max_len = 0;
  for (int i = 1; i <= n; i++) {
    int el;
    if (a[i - 1] == d)
      el = 1;
    else if (a[i - 1] == v)
      el = -1;
    else
      el = 0;
    sum += el;
    if (presum.count(sum) == 0) {
      presum[sum] = i;
    } else {
      max_len = max(max_len, i - presum[sum]);
    }
  }
  return max_len;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n;
  map<int, int> freq;
  for (int i = 0; i < n; i++) {
    int el;
    cin >> el;
    freq[el]++;
    a.push_back(el);
  }
  if (freq.size() == 1) {
    cout << 0 << nl;
    exit(0);
  }
  pair<int, int> mostfreq = {0, 0};
  for (auto &pr : freq) {
    if (pr.second > mostfreq.second) mostfreq = pr;
  }
  int bound = min(n, 100);
  int ans = 0;
  for (int i = 1; i <= bound; i++) {
    ans = max(ans, check(i, mostfreq.first));
  }
  cout << ans << nl;
  return 0;
}
