#include <bits/stdc++.h>
using namespace std;
const int N = 4005;
const long long MOD = 1e9 + 7;
const double EBS = 1e-7;
int dX[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dY[] = {1, -1, 0, 0, 1, -1, -1, 1};
vector<int> adj[N];
int a[N], ans, n, ID;
void Compress() {
  map<int, int> mp;
  set<int> st;
  for (int i = 0; i < n; ++i) st.insert(a[i]);
  for (auto x : st) mp[x] = ID++;
  for (int i = 0; i < n; ++i) a[i] = mp[a[i]];
}
int solve(int p, int q) {
  int idx = -1;
  int ret = 0;
  while (true) {
    int cur = p;
    auto it = upper_bound(adj[cur].begin(), adj[cur].end(), idx);
    if (it == adj[cur].end()) return ret;
    idx = *it;
    ret++;
    swap(p, q);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  Compress();
  for (int i = 0; i < n; ++i) adj[a[i]].push_back(i);
  for (int i = 0; i < ID; ++i)
    for (int j = 0; j < ID; ++j) ans = max(ans, solve(i, j));
  cout << ans << endl;
  return 0;
}
