#include <bits/stdc++.h>
using namespace std;
bitset<4000> bs[4000];
int n;
int a[4000], b[4000];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }
  sort(b, b + n);
  int ub = unique(b, b + n) - b;
  for (int i = 0; i < n; i++) {
    a[i] = lower_bound(b, b + ub, a[i]) - b;
    bs[a[i]].set(i);
  }
  int maxn = 2;
  for (int i = 0; i < n; i++) {
    maxn = max(maxn, (int)bs[i].count());
  }
  if (n == 1) {
    puts("1");
    return 0;
  }
  for (int i = 0; i < ub; i++)
    if (bs[i].count() > 1) {
      for (int j = i + 1; j < ub; j++) {
        if (bs[i].count() + bs[j].count() <= maxn) continue;
        int now = 0, ff = -1;
        for (int k = 0; k < 4000; k++) {
          if (bs[i][k] && (ff == -1 || ff == 1)) {
            now++;
            ff = 2;
          } else if (bs[j][k] && (ff == -1 || ff == 2)) {
            now++;
            ff = 1;
          }
        }
        maxn = max(now, maxn);
      }
    }
  printf("%d\n", maxn);
  return 0;
}
