#include <bits/stdc++.h>
using namespace std;
char nn = '\n';
char ss = ' ';
const int mod = 1e9 + 7;
int n, m;
void solve_test() {
  cin >> n;
  vector<int> a(n);
  int ans = 1, x = 1;
  map<int, int> num;
  int arr[n + 1][n + 1];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (num.find(a[i]) == num.end()) num[a[i]] = x++;
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      arr[num[a[i]]][num[a[j]]] = 1;
      arr[num[a[j]]][num[a[i]]] = 1;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = i + 1; j < n; j++) {
      if (a[i] != a[j]) {
        arr[num[a[i]]][num[a[j]]] = 1 + arr[num[a[j]]][num[a[i]]];
        ans = max(ans, arr[num[a[i]]][num[a[j]]]);
      }
    }
  }
  map<int, int> mp1;
  for (int i = n - 1; i >= 0; i--) {
    mp1[a[i]]++;
    ans = max(ans, mp1[a[i]]);
  }
  cout << ans << nn;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve_test();
  }
  return 0;
}
