#include <bits/stdc++.h>
using namespace std;
int n;
int im_gonna_solve_F(int a[], int D, int V) {
  unordered_map<int, int> m;
  int summ = 0;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int temp = 0;
    if (a[i] == D)
      temp = 1;
    else if (a[i] == V)
      temp = -1;
    summ = summ + temp;
    if (summ == 0) {
      ans = i + 1;
      continue;
    }
    if (m.find(summ) != m.end()) {
      ans = max(ans, i - m[summ]);
      continue;
    }
    m[summ] = i;
  }
  return ans;
}
int main() {
  cin >> n;
  int a[n];
  int freq[101] = {0};
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    freq[a[i]]++;
  }
  int maxx = 0;
  int index;
  for (int i = 1; i <= 100; ++i) {
    if (freq[i] > maxx) {
      maxx = freq[i];
      index = i;
    }
  }
  vector<int> d_set;
  for (int i = 1; i < 101; ++i) {
    if (freq[i] == maxx) d_set.push_back(i);
  }
  int ans = 0;
  if (d_set.size() > 1) {
    cout << n;
    return 0;
  }
  for (auto x : d_set) {
    int D = x;
    for (int V = 1; V <= 100; ++V) {
      ans = max(ans, im_gonna_solve_F(a, D, V));
    }
  }
  cout << ans;
}
