#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int modInverse(long long int n, long long int p) {
  return power(n, p - 2, p);
}
struct point {
  long long int x, y;
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  vector<long long int> arr(n);
  vector<long long int> fre(101, 0);
  long long int mx = 0;
  set<long long int> s1;
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i];
    s1.insert(arr[i]);
    fre[arr[i]]++;
    mx = max(mx, fre[arr[i]]);
  }
  long long int cnt = 0, val = -1;
  for (auto x : s1) {
    if (fre[x] == mx) {
      cnt++;
      val = x;
    }
  }
  if (cnt > 1) {
    cout << n << "\n";
    return 0;
  }
  long long int ans = 0;
  for (long long int i = 1; i < 101; i++) {
    if (i != val) {
      vector<long long int> arr1(arr);
      unordered_map<long long int, long long int> ps;
      long long int sum = 0;
      for (long long int j = 0; j < n; j++) {
        if (arr1[j] == i) {
          arr1[j] = -1;
        } else if (arr1[j] == val) {
          arr1[j] = 1;
        } else {
          arr1[j] = 0;
        }
        sum += arr1[j];
        if (sum == 0) {
          ans = max(ans, j + 1);
        } else if (ps[sum] != 0) {
          ans = max(ans, j - ps[sum] + 1);
        }
        if (sum != 0 && ps[sum] == 0) {
          ps[sum] = j + 1;
        }
      }
    }
  }
  cout << ans << "\n";
}
