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