#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
constexpr int MX = 2e5 + 5, MA = 105;
int a[MX], cnt[MA];
int main() {
  if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) ++cnt[a[i]];
  int m = *max_element(cnt, cnt + MA);
  vector<int> d;
  for (int i = 0; i < MA; ++i)
    if (cnt[i] == m) d.push_back(i);
  if (d.size() > 1) {
    cout << n;
    return 0;
  }
  int ans = 0;
  for (int i = d[0], j = 0; j < MA; ++j)
    if (j != i) {
      unordered_map<int, int> um;
      um[0] = -1;
      for (int k = 0, sum = 0; k < n; ++k) {
        if (a[k] == i)
          ++sum;
        else if (a[k] == j)
          --sum;
        if (!um.count(sum)) um[sum] = k;
        ans = max(k - um[sum], ans);
      }
    }
  cout << ans;
}
