#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long int n;
  cin >> n;
  map<long long int, long long int> m;
  long long int ind = 0;
  long long int a[n];
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    if (m.count(a[i]) == 0) {
      m[a[i]] = ind;
      ind++;
    }
  }
  for (long long int i = 0; i < n; i++) a[i] = m[a[i]];
  long long int ans = 0;
  long long int dp[n][n];
  for (long long int i = 0; i < n; i++)
    for (long long int j = 0; j < n; j++) {
      dp[i][j] = 1;
    }
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < i; j++) {
      dp[i][a[j]] = max(1 + dp[j][a[i]], dp[i][a[j]]);
    }
  }
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < n; j++) {
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans;
}
