#include <bits/stdc++.h>
using namespace std;
map<int, int> m;
int maxi, n, a, x;
vector<int> v[5000];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    if (m.find(a) == m.end()) {
      m[a] = x, x++;
    }
    v[m[a]].push_back(i);
  }
  for (int i = 0; i < x; i++) {
    int st1 = 0, st2 = 0;
    int sz = (v[i].size());
    maxi = max(maxi, sz);
    for (int j = i + 1; j < x; j++) {
      int st1 = 0, st2 = 0, ln = 0, pr = -1;
      while (st1 < v[i].size() && st2 < v[j].size()) {
        if (v[i][st1] < v[j][st2]) {
          if (pr != i) ln++;
          pr = i;
          st1++;
          if (st1 >= v[i].size() && st2 < v[j].size()) {
            ln++;
          }
        } else {
          if (pr != j) ln++;
          pr = j;
          st2++;
          if (st2 >= v[j].size() && st1 < v[i].size()) {
            ln++;
          }
        }
      }
      maxi = max(maxi, ln);
    }
  }
  printf("%d", maxi);
  return 0;
}
