#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 200000 + 10;
int a[MAXN];
int cnt[100 + 10];
vector<int> vc;
int mp[MAXN * 2];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    cnt[a[i]]++;
  }
  int D = -1;
  bool flag = false;
  for (int i = 1; i <= 100; ++i) {
    if (cnt[i]) {
      vc.push_back(i);
      if (D == -1 || cnt[D] < cnt[i]) {
        D = i;
        flag = false;
      } else if (D != -1 && cnt[i] == cnt[D] && i != D) {
        flag = true;
      }
    }
  }
  if (flag) {
    printf("%d\n", n);
    return 0;
  }
  int ans = 0;
  for (int x : vc) {
    if (x == D) continue;
    int end = 2 * n;
    for (int i = 0; i <= end; ++i) mp[i] = INF;
    int presum = 0;
    mp[n] = 0;
    for (int i = 1; i <= n; ++i) {
      if (a[i] == D)
        presum++;
      else if (a[i] == x)
        presum--;
      ans = max(ans, i - mp[presum + n]);
      mp[presum + n] = min(mp[presum + n], i);
    }
  }
  printf("%d\n", ans);
  return 0;
}
