#include <bits/stdc++.h>
using namespace std;
set<int> s;
vector<int> a[1000009];
int f(int p, int q) {
  int c = 0, val = 0;
  bool f = true;
  while (upper_bound(a[p].begin(), a[p].end(), val) != a[p].end() && f) {
    c++, val = *upper_bound(a[p].begin(), a[p].end(), val);
    if (upper_bound(a[q].begin(), a[q].end(), val) != a[q].end())
      c++, val = *upper_bound(a[q].begin(), a[q].end(), val);
    else
      f = false;
  }
  return c;
}
int main() {
  int n, ans = -1, x;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    s.insert(x);
    a[x].push_back(i);
  }
  set<int>::iterator it1 = s.begin();
  for (; it1 != s.end(); it1++) {
    for (set<int>::iterator it2 = s.begin(); it2 != s.end(); it2++) {
      if (*it1 != *it2) {
        ans = max(ans, f(*it1, *it2));
      }
    }
  }
  for (set<int>::iterator it = s.begin(); it != s.end(); it++) {
    int sz = a[*it].size();
    if (sz > ans) ans = a[*it].size();
  }
  cout << ans << endl;
  return 0;
}
