#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1000000000")
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
using namespace std;
const int maxn = (int)2e5 + 5, maxm = 100;
int v[maxn];
int cnt[maxm];
int posit = 0;
int num[maxn + 1][maxm];
int last[2 * maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d", &v[i]);
    v[i]--;
    cnt[v[i]]++;
  }
  int x = 0;
  for (int i = 0; i < maxm; i++) {
    if (cnt[i] > cnt[x]) {
      x = i;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (v[i - 1] == x) {
      for (int j = 0; j < maxm; j++) {
        num[i][j] = num[i - 1][j] + 1;
      }
    } else {
      memcpy(num[i], num[i - 1], sizeof num[i]);
      num[i][v[i - 1]]--;
    }
  }
  int ans = 0;
  for (int i = 0; i < maxm; i++) {
    if (i == x) {
      continue;
    }
    memset(last, -1, sizeof last);
    last[maxn] = 0;
    for (int j = 1; j <= n; j++) {
      int d = num[j][i] + maxn;
      if (last[d] != -1) {
        ans = max(ans, j - last[d]);
      } else {
        last[d] = j;
      }
    }
  }
  cout << ans << '\n';
}
