#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("Ofast")
using namespace std;
const long double pi = acos(-1);
const long long int M = LLONG_MAX, N = 1e7 + 5, INF = 1e18;
void solve() {
  long long int n, k, lm = 0;
  cin >> n;
  map<long long int, vector<long long int> > make_pair;
  for (long long int i = 1; i <= n; i++) {
    cin >> k;
    make_pair[k].push_back(i);
  }
  for (auto i : make_pair) {
    lm = max((long long int)(i.second).size() - 1, lm);
  }
  map<long long int, vector<long long int> >::iterator i, j;
  for (i = make_pair.begin(); i != make_pair.end(); i++) {
    for (j = i, j++; j != make_pair.end(); j++) {
      long long int l = 0;
      if ((long long int)(i->second).size() > 0 &&
          (long long int)(j->second).size() > 0) {
        vector<long long int>::iterator pi, pj;
        pi = i->second.begin();
        pj = j->second.begin();
        while (pi != i->second.end() && pj != j->second.end()) {
          if (*pj > *pi) {
            l++;
            while (*pi < *pj && pi != i->second.end()) pi++;
          } else if (*pi > *pj) {
            l++;
            while (*pj < *pi && pj != j->second.end()) pj++;
          }
        }
      }
      lm = max(l, lm);
    }
  }
  cout << lm + 1 << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
