#include <bits/stdc++.h>
using namespace std;
int ara[4005];
vector<int> vec[1000005];
int main() {
  int n, i, j, k, p, q, x, y;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> ara[i];
    vec[ara[i]].push_back(i);
  }
  int ans = 0;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      if (i == j) continue;
      p = ara[i], q = ara[j];
      if (vec[p][0] != i || vec[q][0] != j) continue;
      int a, b;
      x = 0;
      for (a = b = 0; b < vec[q].size(); b++) {
        if (a == vec[p].size()) break;
        if (vec[q][b] > vec[p][a]) {
          x += 2;
          while (a < vec[p].size() && vec[q][b] > vec[p][a]) a++;
        }
      }
      a = vec[p].size() - 1, b = vec[q].size() - 1;
      if (vec[p][a] > vec[q][b]) x++;
      ans = max(ans, x);
    }
  }
  for (i = 1; i <= 1000000; i++) ans = max(ans, (int)vec[i].size());
  printf("%d\n", ans);
  return 0;
}
