#include <bits/stdc++.h>
int n, a[4010], last, i, j, r;
short d[4010][4010];
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (i = 1; i <= n; ++i)
    for (j = last = 0; j < i; ++j) {
      d[i][j] = d[j][last] + 1;
      if (a[j] == a[i]) last = j;
      if (d[i][j] > r) r = d[i][j];
    }
  printf("%d", r);
}
