#include <bits/stdc++.h>
using namespace std;
int n, a[4010], dp[4010][4010], ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 0, p = 0; j < i; j++) {
      dp[j][i] = dp[p][j] + 1;
      if (a[j] == a[i]) p = j;
      ans = max(ans, dp[j][i]);
    }
  printf("%d", ans);
  return 0;
}
