#include <bits/stdc++.h>
using namespace std;
int n, A[4005], B[4005][4005], D[1000005];
int main() {
  int t, mx = 1;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", A + i);
    D[A[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    if (D[A[i]] > mx) mx = D[A[i]];
  }
  for (int i = 1; i <= n; i++) {
    t = n + 1;
    for (int j = n; j >= 0; j--) {
      B[i][j] = t;
      if (A[j] == A[i]) t = j;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (B[i][0] != i || B[j][0] != j || A[i] == A[j]) continue;
      int a = i, b = j;
      int cnt = 2;
      while (a <= n && b <= n) {
        if (a < b) {
          a = B[i][a];
          if (a > b && a <= n) cnt++;
        } else {
          b = B[j][b];
          if (b > a && b <= n) cnt++;
        }
      }
      mx = max(mx, cnt);
    }
  }
  cout << mx << endl;
  return 0;
}
