#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 5;
const int p = 105;
int bin[MAX * 3];
int a[MAX], cnt[p], tmp[MAX];
int n, amax, cc, pl, ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), cnt[a[i]]++;
  for (int i = 1; i < p; i++) {
    if (cnt[i] == amax)
      cc++;
    else if (cnt[i] > amax)
      amax = cnt[i], pl = i, cc = 1;
  }
  if (cc > 1) {
    printf("%d\n", n);
    return 0;
  }
  memset(bin, -1, sizeof(bin));
  bin[0] = 0;
  for (int i = 1; i < p; i++)
    if (cnt[i] && i != pl) {
      int pre = 0;
      tmp[0] = 0;
      for (int j = 1; j <= n; j++) {
        if (a[j] == pl) pre++;
        if (a[j] == i) pre--;
        if (bin[pre] != -1)
          ans = max(ans, j - bin[pre]);
        else
          bin[pre] = j, tmp[++tmp[0]] = pre;
      }
      for (int j = 1; j <= tmp[0]; j++) bin[j] = -1;
    }
  printf("%d", ans);
  return 0;
}
