#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int N = 4005;
int n, cnt;
map<int, int> mp;
set<int> gra[N];
set<int>::iterator it;
int main() {
  mp.clear();
  cin >> n;
  cnt = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (!mp.count(a)) {
      mp[a] = ++cnt;
      gra[cnt].clear();
    }
    gra[mp[a]].insert(i);
  }
  int maxx = 0;
  for (int i = 1; i <= cnt; i++)
    for (int j = 1; j <= cnt; j++) {
      if (i == j) {
        maxx = max(maxx, (int)gra[i].size());
        continue;
      }
      int sz = 1, pos = *gra[i].begin(), now = 1;
      while (1) {
        if (now == 0) {
          it = gra[i].lower_bound(pos);
          if (it == gra[i].end()) break;
          pos = *it;
          sz++;
          now ^= 1;
        } else {
          it = gra[j].lower_bound(pos);
          if (it == gra[j].end()) break;
          pos = *it;
          sz++;
          now ^= 1;
        }
      }
      maxx = max(maxx, sz);
    }
  cout << maxx << endl;
}
