#include <bits/stdc++.h>
using namespace std;
const long long sz = 2e5 + 10;
long long ara[sz], cnt[105], prv[2 * sz], n;
inline long long solve(long long v1, long long v2) {
  memset(prv, -1, sizeof(prv));
  long long sum = 0, ret = 0;
  prv[0 + sz] = 0;
  for (long long i = 1; i <= n; ++i) {
    if (ara[i] == v1)
      sum++;
    else if (ara[i] == v2)
      sum--;
    if (prv[sum + sz] != -1)
      ret = max(ret, i - prv[sum + sz]);
    else
      prv[sum + sz] = i;
  }
  return ret;
}
int main() {
  long long f = 0, num = 0;
  cin >> n;
  for (long long i = 1; i <= n; ++i) {
    scanf("%lld", &ara[i]);
    cnt[ara[i]]++;
    if (cnt[ara[i]] > f) {
      f = cnt[ara[i]];
      num = ara[i];
    }
  }
  long long ans = 0;
  for (long long i = 1; i <= 100; ++i) {
    if (i != num) ans = max(ans, solve(num, i));
  }
  cout << ans << '\n';
  return 0;
}
