#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:64000000")
const int MAXN = 4005;
int n, res;
int a[MAXN];
int b[1 << 20];
int c[MAXN];
int d[MAXN][MAXN];
inline int find(int x) {
  int l = 0, r = n - 1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (c[mid] == x) return mid;
    if (c[mid] > x)
      r = mid - 1;
    else
      l = mid + 1;
  }
  return -1;
}
inline void init() {
  memset(b, 0, sizeof b);
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    ++b[a[i]];
    c[i] = a[i];
    res = max(res, b[a[i]]);
  }
  sort(c, c + n);
}
int main() {
  res = 1;
  init();
  memset(d, 0, sizeof d);
  for (int i = 0; i < n; ++i) {
    int x = find(a[i]);
    for (int y = 0; y < n; ++y) {
      if (x == y) continue;
      if (!(d[x][y] & 1)) ++d[x][y];
      if (d[y][x] & 1) ++d[y][x];
    }
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) res = max(res, d[i][j]);
  printf("%d\n", res);
  return 0;
}
