#include <bits/stdc++.h>
using namespace std;
long long int dp[4003][4003], m[1000003], cnt[1000006];
int main() {
  long long int n, b[4003], i, j, k;
  long long int ans = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> b[i];
    cnt[b[i]]++;
    ans = max(ans, cnt[b[i]]);
  }
  for (i = 1; i <= n; i++) {
    long long int prev = 0;
    for (j = 0; j < i; j++) {
      dp[i][j] = dp[j][prev] + 1;
      if (b[i] == b[j]) prev = j;
    }
  }
  for (i = 0; i <= n; i++)
    for (j = 0; j <= n; j++) ans = max(ans, dp[i][j]);
  cout << ans << endl;
}
