#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  int a[n + 1], mx = 0;
  for (register int i = 1; i < ((n) + 1); i++) cin >> a[i];
  int dp[n + 1][n + 1];
  memset(dp, 0, sizeof dp);
  for (register int i = 1; i < ((n) + 1); i++) {
    for (int j = 0, pv = 0; j < i; j++) {
      dp[j][i] = dp[pv][j] + 1;
      if (a[i] == a[j]) pv = j;
      mx = max(mx, dp[j][i]);
    }
  }
  cout << mx << endl;
  return 0;
}
