#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int c[102][N], v[102][2 * N], a[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int j = 1; j <= 100; ++j)
    for (int i = 1; i <= n; ++i) c[j][i] = c[j][i - 1] + (a[i] == j);
  int p = 0;
  for (int j = 1; j <= 100; ++j)
    if (c[j][n] >= c[p][n]) p = j;
  memset(v, -1, sizeof(v));
  for (int j = 1; j <= 100; ++j) v[j][n] = 0;
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= 100; ++j) {
      if (j == p) continue;
      int &x = v[j][c[p][i] - c[j][i] + n];
      if (~x)
        ans = max(ans, i - x);
      else
        x = i;
    }
  cout << ans << endl;
  return 0;
}
