#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int a[n + 1];
  vector<int> cnt(105, 0);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  int max_cnt = 0, val;
  for (int i = 1; i <= 100; i++) {
    if (cnt[i] > max_cnt) {
      max_cnt = cnt[i];
      val = i;
    }
  }
  int tot_cnt = 0;
  for (int i = 1; i <= 100; i++) {
    if (cnt[i] == max_cnt) tot_cnt++;
  }
  if (tot_cnt > 1) {
    cout << n << '\n';
    return 0;
  }
  int final_ans = 0;
  unordered_map<int, int> pos;
  for (int i = 1; i <= 100; i++) {
    if (i == val || cnt[i] == 0) {
      continue;
    }
    for (int j = -n; j <= n; j++) {
      pos[j] = n;
    }
    pos[0] = 0;
    int tmp = 0, max_range = 0;
    for (int j = 1; j <= n; j++) {
      if (a[j] == i) {
        tmp--;
      } else if (a[j] == val) {
        tmp++;
      }
      max_range = max(max_range, max(j - pos[tmp], 0));
      pos[tmp] = min(pos[tmp], j);
    }
    final_ans = max(final_ans, max_range);
  }
  cout << final_ans << '\n';
  return 0;
}
