#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int cnt[110];
int n;
int pre[maxn * 2];
int arr[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
    ++cnt[arr[i]];
  }
  int mx = 0, md = 0;
  for (int i = 1; i <= 100; i++) {
    if (cnt[i] > mx) {
      mx = cnt[i];
      md = i;
    }
  }
  int ans = 0;
  for (int i = 1; i <= 100; i++) {
    if (i == md) continue;
    fill(pre, pre + 2 * n + 1, n + 1);
    pre[n] = 1;
    int sum = n;
    for (int j = 1; j <= n; j++) {
      sum += (arr[j] == md ? -1 : (arr[j] == i ? 1 : 0));
      ans = max(ans, j - pre[sum] + 1);
      if (pre[sum] == n + 1) pre[sum] = j + 1;
    }
  }
  printf("%d\n", ans);
  return 0;
}
