#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
const int N = 2e5 + 5;
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
int a[N], cnt[105];
unordered_map<int, int, custom_hash> mp;
int main(int argc, char **argv) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int mx = 0, x = -1;
  for (int i = (0); i < (n); i++) {
    cin >> a[i];
    cnt[a[i]]++;
    if (cnt[a[i]] > mx) {
      mx = cnt[a[i]];
      x = a[i];
    }
  }
  int ans = 0;
  for (int i = (1); i < (101); i++) {
    mp.clear();
    if (i == x) continue;
    mp[0] = -1;
    int cnt = 0;
    for (int j = (0); j < (n); j++) {
      if (a[j] == x)
        cnt++;
      else if (a[j] == i)
        cnt--;
      if (mp.find(cnt) == mp.end())
        mp[cnt] = j;
      else
        uax(ans, j - mp[cnt]);
    }
  }
  cout << ans << '\n';
  return 0;
}
