#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N];
int b[N];
int n;
int mp[2 * N];
int ans;
unordered_map<int, int> num;
int sol_01(int a[], int n) {
  memset(mp, -1, sizeof mp);
  int cur = 0;
  int ans = 0;
  int offset = 2e5;
  for (int i = 1; i <= n; i++) {
    cur += a[i];
    if (cur == 0) ans = i;
    if (mp[cur + offset] != -1)
      ans = max(ans, i - mp[cur + offset]);
    else
      mp[cur + offset] = i;
  }
  return ans;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    num[a[i]]++;
  }
  int maxx = 0;
  int cc = 0;
  for (int i = 1; i <= 100; i++)
    if (num[i] > cc) {
      maxx = i;
      cc = num[i];
    }
  for (int i = 1; i <= 100; i++)
    if (num[i] && i != maxx) {
      for (int j = 1; j <= n; j++)
        if (a[j] == maxx)
          b[j] = 1;
        else if (a[j] == i)
          b[j] = -1;
        else
          b[j] = 0;
      ans = max(ans, sol_01(b, n));
    }
  cout << ans << endl;
  return 0;
}
