#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 5;
int arr[maxn], cnt[maxn], tag[maxn];
int pre[maxn];
int n;
int get(int x) {
  for (int i = 1; i <= n; i++) {
    if (arr[i] == x) tag[i] = -1;
    pre[i] = pre[i + n] = -1;
  }
  pre[0] = -1;
  pre[n] = 0;
  int ret = 0;
  for (int i = 1; i <= n; i++) {
    tag[i] += tag[i - 1];
    if (pre[tag[i] + n] != -1)
      ret = max(ret, i - pre[tag[i] + n]);
    else
      pre[tag[i] + n] = i;
  }
  return ret;
}
void solve() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> arr[i], cnt[arr[i]]++;
  int v = 0;
  for (int i = 1; i <= 100; i++)
    if (cnt[i] > cnt[v]) v = i;
  int ans = 0;
  for (int i = 1; i <= 100; i++) {
    if (i == v) continue;
    for (int j = 1; j <= n; j++)
      if (arr[j] == v)
        tag[j] = 1;
      else
        tag[j] = 0;
    ans = max(ans, get(i));
  }
  cout << ans << '\n';
}
signed main() {
  solve();
  return 0;
}
