#include <bits/stdc++.h>
using namespace std;
typedef struct _node {
  struct _node* L;
  struct _node* R;
  long long int key;
} tree;
typedef tree* treenode;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n, k;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  ;
  map<long long int, vector<long long int> > m;
  for (long long int i = 0; i < n; i++) m[a[i]].push_back(i);
  long long int ans = 0;
  for (map<long long int, vector<long long int> >::iterator it = m.begin();
       it != m.end(); it++) {
    ans = max(ans, (long long int)((it->second).size()));
    map<long long int, vector<long long int> >::iterator it1 = it;
    it1++;
    for (; it1 != m.end(); it1++) {
      long long int count = 0;
      long long int i = 0, j = 0;
      if ((it->second)[0] < (it1->second)[0]) {
        count = 2;
        while (i < (long long int)((it->second).size()) and
               j < (long long int)((it1->second).size())) {
          bool flag = false;
          while (i < (long long int)((it->second).size())) {
            if ((it->second)[i] > (it1->second)[j]) {
              flag = true;
              count++;
              break;
            }
            i++;
          }
          if (flag) {
            while (j < (long long int)((it1->second).size())) {
              if ((it->second)[i] < (it1->second)[j]) {
                count++;
                break;
              }
              j++;
            }
          }
        }
      } else {
        count = 2;
        while (i < (long long int)((it->second).size()) and
               j < (long long int)((it1->second).size())) {
          bool flag = false;
          while (j < (long long int)((it1->second).size())) {
            if ((it->second)[i] < (it1->second)[j]) {
              flag = true;
              count++;
              break;
            }
            j++;
          }
          if (flag) {
            while (i < (long long int)((it->second).size())) {
              if ((it->second)[i] > (it1->second)[j]) {
                count++;
                break;
              }
              i++;
            }
          }
        }
      }
      ans = max(count, ans);
    }
  }
  cout << ans << endl;
  return 0;
}
