#include <bits/stdc++.h>
using namespace std;
int f[4001][4001];
int main() {
  int n, i, j, s, ans = 1;
  int a[4001], b[4001];
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  map<int, int> m;
  map<int, int>::iterator itr;
  s = unique(b, b + n) - b;
  for (i = 1; i <= s; i++) m.insert(make_pair(b[i - 1], i));
  for (i = 0; i < n; i++) {
    a[i] = m[a[i]];
  }
  for (i = 1; i < n; i++) {
    for (j = 0; j < i; j++) {
      f[i][a[j]] = max(max(f[i][a[j]], f[j][a[i]] + 1), 2);
      ans = max(ans, f[i][a[j]]);
    }
  }
  cout << ans;
  return 0;
}
