#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> dups[4010];
  map<int, int> mp;
  int n, a, ind = 0;
  cin >> n;
  int mx = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    if (!mp[a]) mp[a] = ++ind;
    int tmp = mp[a];
    dups[tmp].push_back(i);
    mx = max(mx, (int)dups[tmp].size());
  }
  for (int i = 1; i <= ind; ++i)
    for (int j = i + 1; j <= ind; ++j) {
      int l = 0, r = 0, cnt = 0;
      int turn = -1;
      while (l < dups[i].size() && r < dups[j].size()) {
        cnt++;
        if (turn == -1) {
          if (dups[i][l] < dups[j][r]) {
            turn = 2;
            l++;
          } else {
            turn = 1;
            r++;
          }
        } else {
          if (turn == 1) {
            while (r < dups[j].size() && dups[j][r] < dups[i][l]) r++;
            l++;
            turn = 2;
          } else {
            while (l < dups[i].size() && dups[i][l] < dups[j][r]) l++;
            r++;
            turn = 1;
          }
        }
      }
      if (turn == 1 && l < dups[i].size())
        cnt++;
      else if (turn == 2 && r < dups[j].size())
        cnt++;
      mx = max(mx, cnt);
    }
  cout << mx << endl;
  return 0;
}
