#include <bits/stdc++.h>
using namespace std;
vector<int> vec[4500];
int a[4500], h[4500];
int n;
bool cmp(int left, int right) { return a[left] < a[right]; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), h[i] = i;
  sort(h + 1, h + 1 + n, cmp);
  int pre = -1000500;
  int cnt = 0;
  for (int i = 1; i <= n; ++i)
    if (pre != a[h[i]])
      pre = a[h[i]], a[h[i]] = ++cnt;
    else
      a[h[i]] = cnt;
  for (int i = 1; i <= n; ++i) vec[a[i]].push_back(i);
  int ans = -1;
  for (int i = 1; i <= cnt; ++i)
    for (int j = 1; j <= cnt; ++j) {
      int count = 0, ii = 0, jj = 0;
      int last = -1;
      while (ii < vec[i].size() && jj < vec[j].size()) {
        while (ii < vec[i].size() && vec[i][ii] <= last) ii++;
        if (ii >= vec[i].size()) break;
        last = vec[i][ii];
        count++;
        while (jj < vec[j].size() && vec[j][jj] <= last) jj++;
        if (jj >= vec[j].size()) break;
        last = vec[j][jj];
        count++;
      }
      if (ans < count) ans = count;
    }
  printf("%d\n", ans);
  return 0;
}
