#include <bits/stdc++.h>
using namespace std;
int cnt[1000005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  map<int, int> m;
  int a[n];
  int index = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (m.find(a[i]) == m.end()) m[a[i]] = index++;
  }
  for (int i = 0; i < n; i++) a[i] = m[a[i]];
  int dp[n][n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) dp[i][j] = 1;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      dp[i][a[j]] = max(dp[i][a[j]], 1 + dp[j][a[i]]);
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) ans = max(ans, dp[i][j]);
  }
  cout << ans;
  return 0;
}
