#include <bits/stdc++.h>
const int INF = 0x7f7f7f7f, N = 4005;
using namespace std;
int n;
int a[N], b[N];
int dp[N][N], ans;
int main() {
  scanf("%d", &n);
  if (n <= 2) return printf("%d\n", n), 0;
  for (register int i = 1; i <= n; i++) scanf("%d", &a[i]), b[i] = a[i];
  sort(b + 1, b + 1 + n);
  int m = unique(b + 1, b + 1 + n) - b;
  for (register int i = 1; i <= n; i++)
    a[i] = lower_bound(b + 1, b + 1 + m, a[i]) - b;
  for (register int i = 1; i <= n; i++) {
    for (register int j = i + 1; j <= n; j++) {
      dp[j][a[i]] = dp[i][a[j]] + 1;
      ans = max(ans, dp[j][a[i]]);
    }
  }
  printf("%d\n", ans + 1);
  return 0;
}
