#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4009;
int a[MAXN], dp[MAXN][MAXN];
map<int, int> mp;
int eq[MAXN];
int main() {
  int i, j, n, ed;
  while (scanf("%d", &n) != EOF) {
    ed = 0;
    mp.clear();
    for (i = 0; i < n; ++i) {
      scanf("%d", a + i);
      if (mp.find(a[i]) == mp.end()) mp[a[i]] = ed++;
    }
    for (i = 0; i < n; ++i) a[i] = mp[a[i]];
    memset(dp, 0, sizeof(dp));
    memset(eq, 0, sizeof(eq));
    for (i = 0; i < n; ++i) {
      ++eq[a[i]];
    }
    int ans = *max_element(eq, eq + MAXN);
    if (n >= 2) ans = max(ans, 2);
    for (i = 0; i < n; ++i) {
      for (j = 0; j < i; ++j) {
        if (a[i] != a[j])
          dp[a[j]][a[i]] = max(2, max(dp[a[j]][a[i]], dp[a[i]][a[j]] + 1));
      }
    }
    for (i = 0; i < n; ++i) {
      for (j = 0; j < n; ++j) ans = max(ans, dp[i][j]);
    }
    printf("%d\n", ans);
  }
  return 0;
}
