#include <bits/stdc++.h>
using namespace std;
int stmp;
const int MAX = 100000;
const int INF = 1000000001;
void compress(vector<int> &V) {
  vector<int> tmp(V);
  sort((tmp).begin(), (tmp).end());
  tmp.resize(unique((tmp).begin(), (tmp).end()) - tmp.begin());
  for (int i = 0; i < (((int)(V).size())); ++i)
    V[i] = lower_bound((tmp).begin(), (tmp).end(), V[i]) - tmp.begin();
}
int n;
int main(int argc, char *argv[]) {
  stmp = scanf("%d", &n);
  vector<int> arr(n);
  for (int i = 0; i < (n); ++i) stmp = scanf("%d", &arr[i]);
  compress(arr);
  int res = 1;
  for (int i = 0; i < (n); ++i) {
    vector<int> last(n, -1);
    vector<int> cnt(n, 0);
    int p = i;
    for (int j = (i); j <= (n - 1); ++j)
      if (arr[j] == arr[i])
        ++cnt[arr[i]], p = j;
      else {
        if (last[arr[j]] != p) ++cnt[arr[j]];
        last[arr[j]] = p;
      }
    res = max(res, cnt[arr[i]]);
    for (int j = 0; j < (n); ++j)
      if (arr[i] != j) res = max(res, 2 * cnt[j] + (p > last[j]));
  }
  printf("%d\n", res);
  return 0;
}
