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