#include <bits/stdc++.h>
using namespace std;
const int M = 1e6 + 10;
int a[M];
vector<int> g[M];
bool used1[M], used2[M];
int main() {
  int n;
  int ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    g[a[i]].push_back(i);
    if (used1[a[i]]) used2[i] = true;
    used1[a[i]] = true;
  }
  for (int i1 = 0; i1 < n; i1++)
    for (int j1 = 0; j1 < n; j1++) {
      int i = a[i1], j = a[j1];
      if (used2[i1] || used2[j1]) continue;
      if (i == j) {
        ans = max(ans, (int)g[i].size());
        continue;
      }
      int p2 = 0, p1 = 0;
      int cur = 0;
      while (p1 != (int)g[i].size() && p2 != (int)g[j].size()) {
        cur++;
        while (p2 < (int)g[j].size() && g[j][p2] < g[i][p1]) p2++;
        if (p2 == g[j].size()) break;
        cur++;
        while (p1 < (int)g[i].size() && g[i][p1] < g[j][p2]) p1++;
      }
      ans = max(ans, cur);
    }
  cout << ans;
  return 0;
}
