#include <bits/stdc++.h>
using namespace std;
template <typename T>
void afill(T *arr, int size, T val) {
  fill(arr, arr + size, val);
}
long long mod;
double eps = 1e-9;
int n, t, m, q;
int dp[1 << 12][1 << 12], arr[1 << 12];
pair<int, int> tmp[1 << 12];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> tmp[i].first;
    tmp[i].second = i;
  }
  sort(tmp, tmp + n);
  int prev = tmp[0].first, cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (prev == tmp[i].first)
      arr[tmp[i].second] = cnt;
    else {
      prev = tmp[i].first;
      arr[tmp[i].second] = ++cnt;
    }
  }
  int ans = 1;
  for (int i = 1; i < n; ++i)
    for (int j = i - 1; j >= 0; --j) {
      dp[i][arr[j]] = max(dp[i][arr[j]], dp[j][arr[i]] + 1);
      ans = max(ans, dp[i][arr[j]] + 1);
    }
  cout << ans << '\n';
}
