#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7, inf = 0x3f3f3f3f, mod = 1e9 + 7;
int a[maxn], cnt[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i], cnt[a[i]]++;
  int mx = 0, f = -1;
  for (int i = 1; i <= 100; ++i) {
    if (cnt[i] > mx) {
      mx = cnt[i];
      f = i;
    }
  }
  int ans = 0;
  for (int i = 1; i <= 100; ++i) {
    if (!cnt[i] || i == f) continue;
    vector<int> pre(2 * n + 2, -1);
    int cur = n;
    pre[n] = 0;
    for (int j = 1; j <= n; ++j) {
      if (a[j] == i)
        cur--;
      else if (a[j] == f)
        cur++;
      if (pre[cur] == -1)
        pre[cur] = j;
      else
        ans = max(ans, j - pre[cur]);
    }
  }
  cout << ans << '\n';
  return 0;
}
