#include <bits/stdc++.h>
using namespace std;
const int maxn = 200007;
int a[maxn] = {0};
const int maxel = 107;
int ch[maxel] = {0};
vector<pair<int, int> > vl;
vector<pair<int, int> > vr;
int main() {
  int n;
  cin >> n;
  int chm = 0;
  int chi = -1;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    ch[a[i]] += 1;
    if (ch[a[i]] > chm) {
      chm = ch[a[i]];
      chi = a[i];
    }
  }
  int maxres = 0;
  for (int i = 0; i < maxel; ++i) {
    if (i != chi) {
      vl.clear();
      vl.reserve(n + 3);
      vr.clear();
      vr.reserve(n + 3);
      int gain = 0;
      int maxgain = 0;
      vl.push_back(make_pair(0, 0));
      for (int k = 0; k < n; ++k) {
        if (a[k] == chi)
          ++gain;
        else if (a[k] == i)
          --gain;
        if (gain > maxgain) {
          maxgain = gain;
          vl.push_back(make_pair(k + 1, gain));
        }
      }
      gain = 0;
      maxgain = 0;
      vr.push_back(make_pair(0, 0));
      for (int k = n - 1; k >= 0; --k) {
        if (a[k] == chi)
          ++gain;
        else if (a[k] == i)
          --gain;
        if (gain > maxgain) {
          maxgain = gain;
          vr.push_back(make_pair(n - k, gain));
        }
      }
      int yl = 0;
      int yr = vr.size() - 1;
      int maxdl = n - vl[yl].first - vr[yr].first;
      int gain_need = ch[chi] - ch[i];
      while (yl < vl.size()) {
        int gl = vl[yl].second;
        while (yr - 1 >= 0 && vr[yr - 1].second + gl >= gain_need) yr--;
        int dl = n - vl[yl].first - vr[yr].first;
        maxdl = max(maxdl, dl);
        ++yl;
      }
      maxres = max(maxres, maxdl);
    }
  }
  cout << maxres;
  return 0;
}
