#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-9;
const long long int mod = 1e9 + 7;
const long long int inf = 1LL << 30;
const int MAXN = 1e5 + 5;
void cp() {
  int n;
  cin >> n;
  vector<int> arr(n), freq(100);
  for (int &x : arr) cin >> x, x--, freq[x]++;
  int ans = 0;
  int most = 0, mx = 0;
  for (int i = 0; i < 100; i++)
    if (freq[i] > mx) mx = freq[i], most = i;
  for (int i = 0; i < 100; i++)
    if (i != most && freq[i] == mx) ans = n;
  vector<int> pref(2 * n + 1);
  for (int k = 0; k < 100; k++) {
    if (k == most) continue;
    fill(pref.begin(), pref.end(), 2 * n);
    pref[0 + n] = -1;
    int sum = 0;
    for (int i = 0; i < n; i++) {
      if (arr[i] == most)
        sum++;
      else if (arr[i] == k)
        sum--;
      int p = pref[sum + n];
      ans = max(ans, i - p);
      pref[sum + n] = min(pref[sum + n], i);
    }
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  t = 1;
  while (t--) {
    cp();
  }
  return 0;
}
