#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[4005];
vector<int> u[4005];
int Hash[1000005];
int calc(vector<int> u, vector<int> v) {
  int i = 0, j = 0, Count = 0;
  int n = ((int)(u).size()), m = ((int)(v).size());
  vector<int> ans;
  (ans).clear();
  while (i < n && j < m) {
    if (u[i] < v[j]) {
      ans.push_back(u[i]);
      i++;
    } else {
      ans.push_back(v[j]);
      j++;
    }
  }
  while (i < n) {
    ans.push_back(u[i]);
    i++;
  }
  while (j < m) {
    ans.push_back(v[j]);
    j++;
  }
  for (i = 0; i < ((int)(ans).size()); i++)
    if (i == 0 || Hash[ans[i]] != Hash[ans[i - 1]]) Count++;
  return Count;
}
int main() {
  int i, j, n, m, ans, s;
  while (scanf("%d", &n) != EOF) {
    ans = 1;
    m = 0;
    for (i = 1; i <= n; i++) {
      scanf("%d", &a[i].first);
      Hash[i] = a[i].first;
      a[i].second = i;
    }
    sort(a + 1, a + n + 1);
    for (i = 1; i <= n; i++) {
      ++m;
      (u[m]).clear();
      j = i;
      while (j <= n && a[j].first == a[i].first) {
        u[m].push_back(a[j].second);
        j++;
      }
      i = j - 1;
    }
    for (i = 1; i <= m; i++) {
      ans = max(ans, ((int)(u[i]).size()));
      for (j = 1; j < i; j++) ans = max(ans, calc(u[i], u[j]));
    }
    printf("%d\n", ans);
  }
  return 0;
}
