#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  map<int, int> mp;
  int idx = 0;
  for (int i = 0; i < n; i++) {
    if (mp.find(v[i]) == mp.end()) mp[v[i]] = idx++;
  }
  for (int i = 0; i < n; i++) v[i] = mp[v[i]];
  vector<vector<int> > dp(n, vector<int>(n, 1));
  int an = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) dp[i][v[j]] = max(dp[j][v[i]] + 1, dp[i][v[j]]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) an = max(an, dp[i][j]);
  }
  cout << an << endl;
}
