#include <bits/stdc++.h>
using namespace std;
int n;
int a[(int)(2e5 + 10)];
int Hash[105];
int sum[(int)(2e5 + 10)];
unordered_map<int, int> st;
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i], Hash[a[i]]++, st[a[i]] = 1;
  vector<int> v;
  int maxx = 0;
  for (auto x : st) {
    int i = x.first;
    if (Hash[i] > maxx) {
      v.clear();
      v.push_back(i);
      maxx = Hash[i];
    } else if (Hash[i] == maxx)
      v.push_back(i);
  }
  if (v.size() > 1)
    cout << n << endl;
  else {
    int D = v[0];
    int res = 0;
    for (auto x : st) {
      int i = x.first;
      if (i == D) continue;
      unordered_map<int, int> mn;
      unordered_map<int, int> mx;
      mn[0] = 0;
      mx[0] = 0;
      memset(sum, 0, (n + 5) * sizeof(int));
      for (int j = 1; j <= n; j++) {
        if (a[j] == i) {
          sum[j] = sum[j - 1] - 1;
        } else if (a[j] == D) {
          sum[j] = sum[j - 1] + 1;
        } else {
          sum[j] = sum[j - 1];
        }
        if (mn.count(sum[j]) == 0) mn[sum[j]] = j;
        mx[sum[j]] = j;
      }
      for (int j = 1; j <= n; j++) {
        res = max(res, mx[sum[j]] - mn[sum[j]]);
      }
    }
    cout << res << endl;
  }
}
