#include <bits/stdc++.h>
using namespace std;
vector<int> v[4005];
int newnum[4005], num[4005];
int main() {
  int n;
  scanf("%d", &n);
  int i;
  for (i = 0; i < n; i++) {
    scanf("%d", &num[i]);
    newnum[i] = num[i];
  }
  sort(newnum, newnum + n);
  int newn = unique(newnum, newnum + n) - newnum;
  for (i = 0; i < n; i++) {
    int x = lower_bound(newnum, newnum + newn, num[i]) - newnum;
    v[x].push_back(i);
  }
  int j;
  int ma = 0;
  for (i = 0; i < newn; i++) {
    for (j = 0; j < newn; j++) {
      if (i == j) {
        ma = max(ma, (int)v[i].size());
        continue;
      }
      vector<int> temp;
      temp.resize(v[i].size() + v[j].size());
      merge(v[i].begin(), v[i].end(), v[j].begin(), v[j].end(), temp.begin());
      int k;
      int x1 = 0, x2 = 0;
      for (k = 0; k < temp.size(); k++) {
        if (num[temp[k]] == newnum[i]) {
          x1 = x2 + 1;
        } else {
          x2 = x1 + 1;
        }
      }
      ma = max(max(ma, x1), x2);
    }
  }
  printf("%d\n", ma);
  return 0;
}
