#include <bits/stdc++.h>
using namespace std;
map<int, vector<int> > mp;
int count(int n, int m) {
  vector<int> a = mp[n];
  vector<int> b = mp[m];
  int a_i = 0, b_i = 0;
  int cur, cnt = 1;
  if (a[a_i] < b[b_i]) {
    cur = 0;
  } else {
    cur = 1;
  }
  while (a_i < a.size() && b_i < b.size()) {
    if (cur == 0) {
      if (a[a_i] >= b[b_i]) {
        b_i++;
      } else {
        cur = 1;
        cnt++;
      }
    } else {
      if (a[a_i] <= b[b_i]) {
        a_i++;
      } else {
        cur = 0;
        cnt++;
      }
    }
  }
  return cnt;
}
int main() {
  int n, t;
  scanf("%d", &n);
  set<int> s;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    scanf("%d", &t);
    mp[t].push_back(i);
    s.insert(t);
  }
  for (set<int>::iterator i = s.begin(); i != s.end(); i++) {
    v.push_back(*i);
  }
  int mm = 0;
  if (v.size() == 1) {
    cout << n << endl;
    return 0;
  }
  for (int i = 0; i < v.size(); i++) {
    for (int j = 0; j < v.size(); j++) {
      mm = max(mm, count(v[i], v[j]));
    }
  }
  cout << mm << endl;
  return 0;
}
