#include <bits/stdc++.h>
using namespace std;
int mark[1000001] = {0};
int dp[4001][4001];
int main() {
  int n;
  cin >> n;
  int ar[n];
  for (int i = 0; i <= n - 1; i++) {
    cin >> ar[i];
    mark[ar[i]] = 1;
  }
  int ni = 1;
  for (int i = 0; i <= 1000000; i++) {
    if (mark[i] == 1) {
      mark[i] = ni;
      ni++;
    }
  }
  for (int i = 0; i <= n - 1; i++) {
    ar[i] = mark[ar[i]];
  }
  for (int i = 0; i <= 4000; i++)
    for (int j = 0; j <= 4000; j++) dp[i][j] = 0;
  for (int i = 0; i <= n - 1; i++) {
    for (int j = 0; j <= 4000; j++) dp[ar[i]][j] = dp[j][ar[i]] + 1;
  }
  int ans = 0;
  for (int i = 0; i <= 4000; i++)
    for (int j = 0; j <= 4000; j++) ans = max(ans, dp[i][j]);
  cout << ans;
  return 0;
}
