#include <bits/stdc++.h>
using namespace std;
int n, v[200010];
int solve(int a, int b) {
  vector<int> curv(n, 0), lmPosOfSum(2 * n + 2, -2);
  for (int i = (0); i < (n); i++)
    if (v[i] == a) curv[i] = 1;
  for (int i = (0); i < (n); i++)
    if (v[i] == b) curv[i] = -1;
  lmPosOfSum[n] = -1;
  int sum = 0, ret = 0;
  for (int i = (0); i < (n); i++) {
    sum += curv[i];
    if (lmPosOfSum[n + sum] == -2) lmPosOfSum[n + sum] = i;
    ret = max(ret, i - lmPosOfSum[n + sum]);
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  vector<int> freq(100, 0);
  for (int i = (0); i < (n); i++) {
    cin >> v[i];
    v[i]--;
    freq[v[i]]++;
  }
  int maxfreq = -1;
  for (int i = (0); i < (100); i++) maxfreq = max(maxfreq, freq[i]);
  int cant = 0;
  for (int i = (0); i < (100); i++)
    if (freq[i] == maxfreq) cant++;
  int ans = 0;
  if (cant > 1)
    ans = n;
  else {
    int val = -1;
    for (int i = (0); i < (100); i++)
      if (freq[i] == maxfreq) val = i;
    assert(val != -1);
    for (int i = (0); i < (100); i++)
      if (i != val) ans = max(ans, solve(val, i));
  }
  cout << ans << '\n';
  return 0;
}
