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