#include <bits/stdc++.h>
double abcxx00;
using namespace std;
const int maxn(5 + 4000);
int one[maxn], two[maxn], n;
vector<int> loca[1000000 + 5];
vector<pair<int, int> > vec;
int cyh() {
  if (n == 1) return 1;
  sort(two + 1, two + n + 1);
  int en = unique(two + 1, two + n + 1) - (two);
  en--;
  int ans = 1, e, f, s, k, t;
  for (e = 1; e <= en; e++)
    for (ans = max(ans, (int)loca[two[e]].size()), f = e + 1; f <= en; f++) {
      vec.clear();
      for (s = loca[two[e]].size(), k = 0; k < s; k++)
        vec.push_back(make_pair(loca[two[e]].at(k), -1));
      for (s = loca[two[f]].size(), k = 0; k < s; k++)
        vec.push_back(make_pair(loca[two[f]].at(k), 1));
      sort(vec.begin(), vec.end());
      for (t = 1, s = vec.size(), k = 1; k < s; k++)
        t += (vec.at(k).second != vec.at(k - 1).second);
      ans = max(ans, t);
    }
  return ans;
}
int main() {
  int e;
  while (cin >> n) {
    for (e = 1; e <= 1000000; e++) loca[e].clear();
    for (e = 1; e <= n; e++)
      cin >> one[e], two[e] = one[e], loca[one[e]].push_back(e);
    cout << cyh() << endl;
  }
  return 0;
}
