#include <bits/stdc++.h>
using namespace std;
const int maxn = 200001;
int a[maxn], c[maxn], lst[maxn * 2];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    c[a[i]]++;
  }
  int ans = 0;
  int x = max_element(c + 1, c + 1 + n) - c;
  for (int y = 1; y <= min(100, n); ++y) {
    if (x == y) continue;
    memset(lst, -1, sizeof(lst));
    int s = n;
    lst[n] = 0;
    for (int i = 0; i < n; ++i) {
      if (a[i] == x)
        s++;
      else if (a[i] == y)
        s--;
      if (lst[s] != -1)
        ans = max(ans, i - lst[s] + 1);
      else
        lst[s] = i + 1;
    }
  }
  cout << ans << '\n';
}
