#include <bits/stdc++.h>
using namespace std;
int maxSum(int *arr, int n) {
  unordered_map<int, int> presum;
  int sum = 0;
  int max_len = 0;
  for (int i = 0; i < n; i++) {
    sum += arr[i];
    if (arr[i] == 0 && max_len == 0) max_len = 1;
    if (sum == 0) max_len = i + 1;
    if (presum.find(sum) != presum.end()) {
      max_len = max(max_len, i - presum[sum]);
    } else {
      presum[sum] = i;
    }
  }
  return max_len;
}
int solve(int *a, int n, int res, int i) {
  int b[n];
  for (int j = 0; j < n; j++) {
    if (a[j] == res)
      b[j] = 1;
    else if (a[j] == i)
      b[j] = -1;
    else
      b[j] = 0;
  }
  return maxSum(b, n);
}
int main() {
  int n;
  cin >> n;
  int a[n];
  int cnt[101] = {};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  int res = 0;
  for (int i = 1; i <= 100; i++)
    if (cnt[res] < cnt[i]) res = i;
  int ans = 0;
  for (int i = 1; i <= 100; i++)
    if (i != res) ans = max(ans, solve(a, n, res, i));
  cout << ans << endl;
  return 0;
}
