#include <bits/stdc++.h>
using namespace std;
set<long long int> s;
vector<long long int> pos[1000005], temp;
long long int res = 0;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  long long int b[n];
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    s.insert(b[i]);
    pos[b[i]].push_back(i);
  }
  for (auto it : s) temp.push_back(it);
  for (int i = 0; i < temp.size(); i++)
    for (int j = i + 1; j < temp.size(); j++) {
      long long int flag, f1, f2;
      if (pos[temp[i]][0] < pos[temp[j]][0]) {
        flag = 0;
        f1 = 1;
        f2 = 0;
      } else {
        flag = 1;
        f1 = 0;
        f2 = 1;
      }
      long long int tem = 1;
      while (f1 < (long long int)pos[temp[i]].size() &&
             f2 < (long long int)pos[temp[j]].size()) {
        if (!flag) {
          while (f1 < (long long int)pos[temp[i]].size() &&
                 f2 < (long long int)pos[temp[j]].size() &&
                 pos[temp[i]][f1] < pos[temp[j]][f2])
            f1++;
          while (f1 < (long long int)pos[temp[i]].size() &&
                 f2 < (long long int)pos[temp[j]].size() &&
                 pos[temp[j]][f2] < pos[temp[i]][f1])
            f2++;
          flag ^= 1;
          tem++;
        } else {
          while (f1 < (long long int)pos[temp[i]].size() &&
                 f2 < (long long int)pos[temp[j]].size() &&
                 pos[temp[i]][f1] > pos[temp[j]][f2])
            f2++;
          while (f1 < (long long int)pos[temp[i]].size() &&
                 f2 < (long long int)pos[temp[j]].size() &&
                 pos[temp[j]][f2] > pos[temp[i]][f1])
            f1++;
          flag ^= 1;
          tem++;
        }
      }
      if (flag == 1 && f1 < (long long int)pos[temp[i]].size() &&
          pos[temp[i]][f1] > pos[temp[j]][pos[temp[j]].size() - 1])
        tem++;
      if (flag == 0 && f2 < (long long int)pos[temp[j]].size() &&
          pos[temp[j]][f2] > pos[temp[i]][pos[temp[i]].size() - 1])
        tem++;
      res = max(res, tem);
    }
  for (int i = 0; i < temp.size(); i++)
    res = max(res, (long long int)pos[temp[i]].size());
  cout << res << endl;
  return 0;
}
