#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop - opt(on)
using namespace std;
long long int n, mx, mxn, ans = 0;
vector<long long int> a, l, r;
vector<vector<long long int>> pre;
void build() {
  mx = 0, mxn = 0;
  pre.assign(101, vector<long long int>(n + 1, 0));
  for (long long int i = 1; i <= n; i++) {
    pre[a[i]][i]++;
    for (long long int j = 1; j <= 100; j++) pre[j][i] += pre[j][i - 1];
    if (pre[a[i]][i] > mx) mx = pre[a[i]][i], mxn = a[i];
  }
  return;
}
long long int solve(long long int x) {
  if (x == mxn) return 0;
  l.assign(2 * n + 5, 10000000000000000),
      r.assign(2 * n + 5, -10000000000000000);
  for (long long int i = 0; i <= n; i++) {
    long long int ii = pre[mxn][i] - pre[x][i] + n;
    l[ii] = min(l[ii], i), r[ii] = max(r[ii], i);
  }
  long long int ans = 0;
  for (long long int i = 0; i <= 2 * n + 1; i++) {
    ans = max(ans, r[i] - l[i]);
  }
  return ans;
}
signed main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n, a.resize(n + 1);
  for (long long int i = 1; i <= n; i++) cin >> a[i];
  build(), ans = 0;
  for (long long int i = 1; i <= 100; i++) ans = max(ans, solve(i));
  cout << ans << "\n";
  return 0;
}
