#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int maxn = 1e6 + 10;
const long long inf = 0x3f3f3f3f;
const long long oo = 8e18;
const int dir[][2] = {{0, 1}, {1, 0},  {0, -1}, {-1, 0},
                      {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
int a[maxn], cnt[110], sum[maxn], n;
int solve(int x, int y) {
  unordered_map<int, int> m;
  for (int i = 1; i <= n; i++) {
    sum[i] = sum[i - 1];
    if (a[i] == x) sum[i]++;
    if (a[i] == y) sum[i]--;
  }
  int ans = 0;
  m[0] = 1;
  for (int i = 1; i <= n; i++) {
    if (m[sum[i]]) ans = max(ans, i - m[sum[i]] + 1);
    if (!m[sum[i]]) m[sum[i]] = i + 1;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  int x = max_element(cnt, cnt + 105) - cnt;
  int ans = 0;
  for (int i = 1; i <= 100; i++) {
    if (i == x) continue;
    ans = max(ans, solve(x, i));
  }
  cout << ans << '\n';
  return 0;
}
