#include <bits/stdc++.h>
using namespace std;
map<int, vector<int> > m;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    m[x].push_back(i);
  }
  int ans = 0;
  for (__typeof((m).begin()) i = (m).begin(); i != (m).end(); i++) {
    ans = max(ans, (int)i->second.size());
    const vector<int>& v1 = i->second;
    for (__typeof((m).begin()) j = (m).begin(); j != (m).end(); j++) {
      if (j->first == i->first) continue;
      const vector<int>& v2 = j->second;
      int p1 = 0, p2 = 0;
      int t = 1;
      while (1) {
        while (p2 + 1 < v2.size() && v2[p2] < v1[p1]) p2++;
        if (v2[p2] < v1[p1]) break;
        ans = max(ans, ++t);
        while (p1 + 1 < v1.size() && v1[p1] < v2[p2]) p1++;
        if (v1[p1] < v2[p2]) break;
        ans = max(ans, ++t);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
