#include <bits/stdc++.h>
using namespace std;
vector<int> v[4000];
map<int, int> mymap;
int main() {
  int n;
  while (scanf("%d ", &n) != EOF) {
    mymap.clear();
    int m = 0;
    for (int i = 0; i < n; ++i) {
      int x;
      scanf("%d ", &x);
      if (mymap.find(x) == mymap.end()) {
        mymap[x] = m;
        v[m].clear();
        v[m++].push_back(i);
      } else {
        v[mymap[x]].push_back(i);
      }
    }
    int ans = 0;
    for (int i = 0; i < m; ++i) {
      ans = max(ans, (int)v[i].size());
      for (int j = i + 1; j < m; ++j) {
        int a = 0, b = 0;
        int now = -1;
        int nxt;
        if (v[i][0] < v[j][0])
          nxt = i;
        else
          nxt = j;
        int t = 0;
        while (true) {
          if (nxt == i) {
            if (a == v[i].size())
              break;
            else if (v[i][a] > now) {
              now = v[i][a];
              nxt = j;
              ++t;
            }
            ++a;
          } else {
            if (b == v[j].size())
              break;
            else if (v[j][b] > now) {
              now = v[j][b];
              nxt = i;
              ++t;
            }
            ++b;
          }
        }
        ans = max(ans, t);
      }
    }
    cout << ans << endl;
  }
}
