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