#include <bits/stdc++.h>
using namespace std;
int arr[4009];
int mak[1000009];
int dp[4009][4009];
bool mark[4009];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  set<int> v;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    v.insert(arr[i]);
  }
  int c = 1;
  for (auto i = v.begin(); i != v.end(); i++) {
    mak[*i] = c;
    c++;
  }
  for (int i = 0; i < n; i++) {
    arr[i] = mak[arr[i]];
  }
  for (int i = 1; i < c; i++) {
    for (int j = 1; j < c; j++) {
      dp[i][j] = 1;
    }
  }
  int ans = 1;
  for (int i = 1; i < n; i++) {
    memset(mark, 0, sizeof(mark));
    for (int j = i - 1; j >= 0; j--) {
      if (mark[arr[j]]) {
        continue;
      }
      mark[arr[j]] = true;
      dp[arr[i]][arr[j]] = max(dp[arr[i]][arr[j]], dp[arr[j]][arr[i]] + 1);
      ans = max(ans, dp[arr[i]][arr[j]]);
    }
  }
  cout << ans << endl;
}
