#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n + 1);
  vector<vector<int>> pos(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pos[a[i]].emplace_back(i);
  }
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    mx = max(mx, (int)pos[i].size());
  }
  int can = -1;
  for (int i = 1; i <= n; i++) {
    if ((int)pos[i].size() == mx) {
      if (can == -1)
        can = i;
      else
        return cout << n, 0;
    }
  }
  int ans = 0;
  for (int num = 1; num <= min(100, n); num++) {
    if (pos[num].empty() || num == can) continue;
    vector<int> v(n + 1);
    for (int i = 1; i <= n; i++) {
      v[i] = v[i - 1];
      if (a[i] == can) v[i]--;
      if (a[i] == num) v[i]++;
    }
    vector<int> pos(2 * n + 1);
    for (int i = 0; i <= n; i++) pos[v[i] + n] = max(pos[v[i] + n], i);
    for (int i = 0; i <= n; i++) ans = max(ans, pos[v[i] + n] - i);
  }
  cout << ans;
}
