#include <bits/stdc++.h>
using namespace std;
bool v[4000];
int t[4000];
vector<vector<int> > p;
int f(int a, int b) {
  int c = 2;
  for (int i = 0, j = 0;; c++) {
    if (p[a][i] < p[b][j]) {
      do {
        if (++i == p[a].size()) return c;
      } while (p[a][i] < p[b][j]);
    } else {
      do {
        if (++j == p[b].size()) return c;
      } while (p[b][j] < p[a][i]);
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &t[i]);
  for (int i = 0; i < n; i++) {
    if (v[i]) continue;
    p.push_back(vector<int>());
    for (int j = i; j < n; j++)
      if (t[i] == t[j]) {
        v[j] = true;
        p.back().push_back(j);
      }
  }
  int m = 0;
  for (int i = 0; i < p.size(); i++) m = max(m, (int)p[i].size());
  for (int i = 0; i < p.size() - 1; i++)
    for (int j = i + 1; j < p.size(); j++) m = max(m, f(i, j));
  printf("%d\n", m);
  return 0;
}
