#include <bits/stdc++.h>
using namespace std;
std::mt19937 rng(
    (int)std::chrono::steady_clock::now().time_since_epoch().count());
const int N = 500005;
const int dl = 200005;
int fl[N];
int32_t main() {
  map<int, int> fa;
  int n;
  cin >> n;
  vector<int> v(n);
  int opt = 0;
  for (int i = 0; i < (n); ++i)
    cin >> v[i], fa[v[i]]++, opt = max(opt, fa[v[i]]);
  int good = -1;
  for (int i = 0; i < (n); ++i) {
    if (fa[v[i]] == opt) {
      if (good == -1) {
        good = v[i];
        continue;
      }
      if (good != v[i]) {
        cout << n << endl;
        return 0;
      }
    }
  }
  int ans = 0;
  for (int ix = 1; ix <= 100; ix++) {
    if (ix == good) continue;
    vector<int> p(n);
    for (int i = 0; i < (n); ++i) {
      if (v[i] == good)
        p[i] = -1;
      else if (v[i] == ix) {
        p[i] = 1;
      } else {
        p[i] = 0;
      }
      fl[-i + dl] = -1;
      fl[-(i + 1) + dl] = -1;
      fl[i + dl] = -1;
      fl[(i + 1) + dl] = -1;
    }
    int csum = 0;
    for (int i = 0; i < (n); ++i) {
      csum += p[i];
      if (csum == 0) ans = max(ans, i + 1);
      if (fl[csum + dl] != -1) ans = max(ans, i - fl[csum + dl]);
      if (fl[csum + dl] == -1) fl[csum + dl] = i;
    }
  }
  cout << ans << endl;
}
