#include <bits/stdc++.h>
using namespace std;
int b[5000], dp[5000][5000], ap[5000][5000];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (n); j++) dp[i][j] = 0;
  for (int i = 0; i < (n); i++) cin >> b[i];
  for (int i = 0; i < (n); i++) {
    int u = -1;
    for (int j = 0; j < (n); j++) {
      ap[i][j] = u;
      if (b[j] == b[i]) {
        u = j;
      }
    }
  }
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (i); j++) {
      dp[j][i] = 2;
      if (ap[i][j] != -1) dp[j][i] = 1 + dp[ap[i][j]][j];
    }
  int res = 0;
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (i); j++) res = max(res, dp[j][i]);
  if (n == 1)
    cout << 1 << endl;
  else
    cout << res << endl;
}
