#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &i : a) cin >> i;
  vector<int> cnt(101);
  for (auto i : a) cnt[i]++;
  int most = max_element((cnt).begin(), (cnt).end()) - cnt.begin();
  int ans = 0;
  for (int val = 1; val <= 100; ++val) {
    if (most == val) continue;
    unordered_map<int, int> pref;
    pref[0] = 1;
    int cur = 0;
    bool was = 0;
    for (int j = 0; j < n; ++j) {
      if (a[j] == val) was = 1, cur++;
      if (a[j] == most) was = 1, cur--;
      if (was) {
        int prv = pref[cur];
        if (prv != 0) ans = max(ans, j + 2 - prv);
      }
      if (pref[cur] == 0) pref[cur] = j + 2;
    }
  }
  cout << ans;
  return 0;
}
