#include <bits/stdc++.h>
using namespace std;
vector<int> cnt[1000000];
bool flag[1000005];
int main() {
  int n;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (long long(i) = (0); (i) <= (1e6); (i)++) {
    flag[i] = 0;
  }
  int arr[4005];
  for (long long(i) = (0); (i) < (n); (i)++) {
    cin >> arr[i];
    cnt[arr[i]].push_back(i);
  }
  int best = 1;
  for (long long(i) = (0); (i) < (n); (i)++) {
    if (flag[arr[i]] == 0) {
      flag[arr[i]] = 1;
      for (long long(j) = (i + 1); (j) < (n); (j)++) {
        int a = 0, b = 0, res = 0, sa = cnt[arr[i]].size(),
            sb = cnt[arr[j]].size(), now = -1;
        int f = 1;
        while (a < sa && b < sb) {
          if (f) {
            while (a < sa && now >= cnt[arr[i]][a]) {
              a++;
            }
            if (a < sa) {
              now = cnt[arr[i]][a];
              res++;
            }
          } else {
            while (b < sb && now >= cnt[arr[j]][b]) {
              b++;
            }
            if (b < sb) {
              now = cnt[arr[j]][b];
              res++;
            }
          }
          f ^= 1;
        }
        best = max(best, res);
      }
    }
  }
  cout << best << endl;
}
