#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  int freq[101] = {0};
  for (int i = 0; i < n; i++) {
    freq[arr[i]]++;
  }
  int maxfreq = 0, maxnum = -1;
  for (int i = 0; i < 101; i++) {
    if (freq[i] > maxfreq) {
      maxfreq = freq[i];
      maxnum = i;
    }
  }
  int newarr[n];
  int pref[n];
  int ans = 0;
  for (int i = 1; i < 101; i++) {
    if (i == maxnum) continue;
    for (int j = 0; j < n; j++) {
      if (arr[j] == i)
        newarr[j] = -1;
      else if (arr[j] == maxnum)
        newarr[j] = 1;
      else
        newarr[j] = 0;
    }
    vector<pair<int, int>> preffreq(2 * n + 3, make_pair(-2, 200010));
    pref[0] = newarr[0];
    preffreq[n].first = -1;
    preffreq[n].second = -1;
    preffreq[pref[0] + n].first = max(preffreq[pref[0] + n].first, 0);
    preffreq[pref[0] + n].second = min(preffreq[pref[0] + n].second, 0);
    for (int j = 1; j < n; j++) {
      pref[j] = pref[j - 1] + newarr[j];
      preffreq[pref[j] + n].first = max(preffreq[pref[j] + n].first, j);
      preffreq[pref[j] + n].second = min(preffreq[pref[j] + n].second, j);
    }
    for (auto x : preffreq) {
      if (x.first != -2) {
        ans = max(ans, x.first - x.second);
      }
    }
  }
  cout << ans << "\n";
}
int main() {
  int t;
  t = 1;
  while (t--) solve();
}
