#include <bits/stdc++.h>
using namespace std;
int n;
int a[(int)(2e5 + 10)];
int Hash[105];
int sum[(int)(2e5 + 10)];
unordered_set<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.insert(a[i]);
  vector<int> v;
  int maxx = 0;
  int D = 0;
  int count = 0;
  for (auto i : st) {
    if (Hash[i] > maxx) {
      count = 1;
      D = i;
      maxx = Hash[i];
    } else if (Hash[i] == maxx)
      count++;
  }
  if (count > 1)
    cout << n << endl;
  else {
    int res = 0;
    for (auto i : st) {
      if (i == D) continue;
      unordered_map<int, int> mn;
      mn[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;
        res = max(res, j - mn[sum[j]]);
      }
    }
    cout << res << endl;
  }
}
