#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n + 1, 0);
  vector<int> freq(101, 0);
  array<int, 2> mx = {0, 0};
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    freq[a[i]]++;
    mx = max(mx, {freq[a[i]], a[i]});
  }
  int one = mx[1];
  int res = 0;
  for (int two = 1; two <= 100; two++) {
    unordered_map<int, int> m;
    m.reserve((1 << 15));
    m.max_load_factor(0.25);
    m[0] = 0;
    int s = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] == one)
        s++;
      else if (a[i] == two)
        s--;
      if (m.find(s) != m.end())
        res = max(res, i - m[s]);
      else
        m[s] = i;
    }
  }
  cout << res << "\n";
  return 0;
}
