#include <bits/stdc++.h>
using namespace std;
struct RTC {};
int first_pos[1000001];
int ans[4001][4001];
int n;
int v[4002];
map<int, int> cnt;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int pos = 1; pos <= n; pos++) {
    cin >> v[pos];
    cnt[v[pos]]++;
    if (first_pos[v[pos]] == 0) first_pos[v[pos]] = pos;
  }
  int sol = 0;
  for (auto e : cnt) sol = max(sol, e.second);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j < i; j++) {
      int a = first_pos[v[j]], b = first_pos[v[i]];
      if (a == b) continue;
      ans[a][b] = max(ans[a][b], ans[b][a] + 1);
      sol = max(sol, ans[a][b] + 1);
    }
  cout << sol << '\n';
  return 0;
}
