#include <bits/stdc++.h>
using namespace std;
int f[4005][4005];
int a[4005];
int main() {
  int i, j, k, n, m = 0;
  memset(f, 0, sizeof(f));
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    k = 0;
    for (j = 0; j < i; j++) {
      f[i][j] = f[j][k] + 1;
      if (a[j] == a[i]) {
        k = j;
      }
      m = max(m, f[i][j]);
    }
  }
  cout << m << endl;
}
