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