#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<long long int, char> p1, pair<long long int, char> p2) {
  return p1.first > p2.first;
}
long long int dp[5000][5000];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  long long int a[n], i, j;
  for (i = 0; i < n; i++) cin >> a[i];
  long long int c = 1, ans = 0;
  map<long long int, long long int> m;
  for (i = 0; i < n; i++) {
    if (m[a[i]] == 0) m[a[i]] = c;
    c++;
  }
  for (i = 0; i <= n; i++)
    for (j = 0; j <= n; j++) dp[i][j] = 1;
  for (i = 0; i < n; i++) a[i] = m[a[i]];
  for (i = 0; i < n; i++)
    for (j = 0; j < i; j++) {
      dp[i][a[j]] = max(1 + dp[j][a[i]], dp[i][a[j]]);
      ans = max(ans, dp[i][a[j]]);
    }
  cout << max(ans, (long long int)1) << "\n";
}
