#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a;
int longestSubarray(int D, int V) {
  unordered_map<int, int> presum;
  presum[0] = -1;
  int sum = 0;
  int max_length = 0;
  bool hasV = false;
  for (int i = 0; i < n; ++i) {
    if (a[i] == D) {
      sum++;
    } else if (a[i] == V) {
      sum--;
      hasV = true;
    }
    if (presum.find(sum) != presum.end()) {
      max_length = max(max_length, i - presum[sum]);
    } else {
      presum[sum] = i;
    }
  }
  if (!hasV) {
    return 0;
  }
  return max_length;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  unordered_map<int, int> frequency;
  int D;
  int max_f = 0;
  bool isUnique = false;
  for (int i = 0; i < n; i++) {
    frequency[a[i]]++;
    if (frequency[a[i]] > max_f) {
      isUnique = true;
      max_f = frequency[a[i]];
      D = a[i];
    } else if (frequency[a[i]] == max_f) {
      isUnique = false;
    }
  }
  if (max_f == n) {
    cout << 0 << endl;
    return 0;
  }
  if (!isUnique) {
    cout << n << endl;
    return 0;
  }
  int largest = 0;
  for (int i = 1; i <= 100; i++) {
    if (i != D) {
      largest = max(largest, longestSubarray(D, i));
    }
  }
  cout << largest << endl;
}
