#include <bits/stdc++.h>
using namespace std;
long long n, a[4005], dp[4005][4005], p, ans;
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    p = 0;
    for (int j = 0; j < i; j++) {
      dp[j][i] = 1 + dp[p][j];
      ans = max(ans, dp[j][i]);
      if (a[i] == a[j]) p = j;
    }
  }
  cout << ans << endl;
  return 0;
}
