#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000 + 10;
int a[MAXN];
int sum[MAXN];
int cnt[100 + 10];
vector<int> vc;
unordered_map<int, int> mp;
int exist[MAXN];
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;
  }
  sum[0] = 0;
  int ans = 0;
  for (int x : vc) {
    if (x == D) continue;
    mp.clear();
    exist[0] = 0;
    mp[0] = 0;
    for (int i = 1; i <= n; ++i) {
      if (a[i] == D)
        sum[i] = sum[i - 1] + 1;
      else if (a[i] == x)
        sum[i] = sum[i - 1] - 1;
      else
        sum[i] = sum[i - 1] + 0;
      if (mp.count(sum[i]) == 0) mp[sum[i]] = i;
      if (a[i] == D) {
        exist[i] = exist[i - 1] + 1;
      } else {
        exist[i] = exist[i - 1];
      }
    }
    int L = 0;
    for (int r = 1; r <= n; ++r) {
      if (mp.count(sum[r])) {
        int l = mp[sum[r]] + 1;
        if (l <= r && exist[r] - exist[l - 1] >= 1) {
          L = max(L, r - l + 1);
        }
      }
    }
    ans = max(ans, L);
  }
  printf("%d\n", ans);
  return 0;
}
