#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn];
int cnt[maxn];
int s[maxn * 2], e[maxn * 2];
int maxx;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    cnt[a[i]]++;
    maxx = max(maxx, cnt[a[i]]);
  }
  int tmp = -1;
  for (int i = 1; i <= n; i++) {
    if (cnt[a[i]] == maxx && a[i] != tmp) {
      if (tmp != -1) {
        printf("%d\n", n);
        return 0;
      }
      tmp = a[i];
    }
  }
  int ans = 0;
  for (int i = 1; i <= 100; i++) {
    if (cnt[i] == 0 || i == tmp) continue;
    int sum = 0;
    for (int j = 1; j < maxn * 2; j++) s[j] = -1, e[j] = -1;
    s[maxn] = 0;
    e[maxn] = 0;
    for (int j = 1; j <= n; j++) {
      if (a[j] == i)
        sum++;
      else if (a[j] == tmp)
        sum--;
      if (s[sum + maxn] == -1) s[sum + maxn] = j;
      e[sum + maxn] = j;
    }
    for (int j = 0; j < maxn * 2; j++) ans = max(ans, e[j] - s[j]);
  }
  cout << ans;
  return 0;
}
