#include <bits/stdc++.h>
using namespace std;
const int Maxn = 4005;
vector<int> pos[Maxn];
int a[Maxn], b[Maxn];
int n, ans;
int main() {
  int i, j, k, l;
  while (~scanf("%d", &n)) {
    for (i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      b[i] = a[i];
    }
    sort(b + 1, b + n + 1);
    for (i = 1; i <= n; i++) pos[i].clear();
    for (i = 1; i <= n; i++) {
      int tp = lower_bound(b + 1, b + n + 1, a[i]) - b;
      pos[tp].push_back(i);
    }
    ans = 0;
    for (i = 1; i <= n; i++) ans = max(ans, int(pos[i].size()));
    for (i = 1; i <= n; i++) {
      if (pos[i].size() == 0) continue;
      for (j = 1; j <= n; j++) {
        if (i == j) continue;
        int th = 1;
        k = 0;
        l = 0;
        while (1) {
          if (th & 1) {
            for (; l < pos[j].size() && pos[j][l] < pos[i][k]; l++)
              ;
            if (l >= pos[j].size()) break;
            th++;
          } else {
            for (; k < pos[i].size() && pos[i][k] < pos[j][l]; k++)
              ;
            if (k >= pos[i].size()) break;
            th++;
          }
        }
        ans = max(ans, th);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
