#include <bits/stdc++.h>
using namespace std;
int f[110];
int v[200010];
int best[200010];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &v[i]);
    f[v[i]]++;
  }
  int maxF = 0;
  int fV = 0;
  for (int i = 0; i <= 100; i++) {
    if (f[i] > maxF) {
      maxF = f[i];
      fV = i;
    }
  }
  int ans = 1000000000;
  for (int cnd = 0; cnd <= 100; cnd++) {
    memset(best, 0, sizeof(best));
    if (cnd == fV) continue;
    int diff = f[fV] - f[cnd];
    if (diff == 0) {
      ans = 0;
      break;
    }
    int cum = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (v[i] == cnd) cum--;
      if (v[i] == fV) cum++;
      best[i] = max(best[i + 1], cum);
      if (cum == diff) ans = min(ans, n - i);
    }
    cum = 0;
    for (int i = 0; i < n; i++) {
      if (v[i] == cnd) cum--;
      if (v[i] == fV) cum++;
      if (cum == diff) ans = min(ans, i + 1);
      int beg = i + 1;
      int end = n - 1;
      while (beg != end && beg <= end) {
        int mid = (beg + end) / 2 + 1;
        if (best[mid] >= diff - cum) {
          beg = mid;
        } else {
          end = mid - 1;
        }
      }
      if (cum + best[beg] == diff) {
        ans = min(ans, i + 1 + n - beg);
      }
    }
  }
  printf("%d\n", n - ans);
  return 0;
}
