#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(0));
const long long inf = 0x3f3f3f3f3f3f3f3fLL;
const long long N = 3e5 + 5;
const long long MOD = 1e9 + 7;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> a(n + 1), cnt(105);
  long long mxcnt = 0, val = -1, mx = -1;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
    mx = max(mx, a[i]);
    if (cnt[a[i]] > mxcnt) {
      val = a[i];
      mxcnt = cnt[a[i]];
    }
  }
  long long ans = 0;
  vector<long long> p(2 * n + 1);
  for (long long i = 1; i <= mx; i++) {
    if (i != val) {
      for (long long j = 0; j <= 2 * n; j++) p[j] = -1;
      long long c = n;
      p[c] = 0;
      for (long long j = 1; j <= n; j++) {
        if (a[j] == val)
          c++;
        else if (a[j] == i)
          c--;
        if (p[c] == -1)
          p[c] = j;
        else
          ans = max(ans, j - p[c]);
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
