#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int NAX = 2e5 + 5, MOD = 1000000007;
int a[NAX];
int freq[101];
void solveCase() {
  int n;
  cin >> n;
  for (size_t i = 0; i < n; ++i) {
    cin >> a[i];
    ++freq[a[i]];
  }
  auto maxfreq = *max_element(freq, freq + 101);
  if (count(freq, freq + 101, maxfreq) > 1) {
    cout << n << '\n';
    return;
  }
  int maxlen = 0;
  int maxidx = max_element(freq, freq + 101) - freq;
  for (size_t i = 0; i < 101; ++i) {
    if (i == maxidx) continue;
    map<int, int> maxr;
    int cnt = 0;
    for (int j = n - 1; j >= 0; --j) {
      auto it = maxr.find(cnt);
      if (it != maxr.end())
        maxlen = max(maxlen, it->second - j);
      else
        maxr[cnt] = j;
      if (a[j] == maxidx)
        ++cnt;
      else if (a[j] == i)
        --cnt;
    };
    auto it = maxr.find(cnt);
    if (it != maxr.end()) maxlen = max(maxlen, it->second + 1);
  }
  cout << maxlen << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  for (int i = 1; i <= t; ++i) solveCase();
  return 0;
}
