#include <bits/stdc++.h>
using namespace std;
const int maxn = 4010;
short ans[maxn][maxn];
bool s[maxn][maxn];
int a[maxn];
map<int, int> c;
int cc[maxn];
int cnt = 0;
int find(int x) {
  if (c.find(x) == c.end()) {
    c[x] = ++cnt;
  }
  return c[x];
}
int n;
int main() {
  while (scanf("%d", &n) != EOF) {
    c.clear();
    memset(ans, 0, sizeof(ans));
    memset(s, 0, sizeof(s));
    memset(cc, 0, sizeof(cc));
    cnt = 0;
    int ret = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      int t = find(a[i]);
      cc[t]++;
      ret = max(cc[t], ret);
      for (int j = 1; j <= cnt; j++)
        if (j != t && s[j][t] == 1) {
          ans[j][t]++;
          s[j][t] = 0;
        }
      for (int j = 1; j <= cnt; j++)
        if (j != t && s[t][j] == 0) {
          ans[t][j]++;
          s[t][j] = 1;
        }
    }
    for (int i = 1; i <= cnt; i++)
      for (int j = 1; j <= cnt; j++) ret = max((int)ans[i][j] + 1, ret);
    printf("%d\n", ret);
  }
  return 0;
}
