#include <bits/stdc++.h>
using namespace std;
int dp[4005][4005], v[4005], n, res;
vector<int> vec;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v[i] = x;
    vec.push_back(x);
  }
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  for (int i = 0; i < n; i++) {
    int a = lower_bound(vec.begin(), vec.end(), v[i]) - vec.begin();
    dp[a][a]++;
    for (int j = 0; j < vec.size(); j++)
      if (j != a && dp[j][a] % 2 == 1) dp[j][a]++;
    for (int j = 0; j < vec.size(); j++)
      if (j != a && dp[a][j] % 2 == 0) dp[a][j]++;
  }
  for (int i = 0; i < 4005; i++)
    for (int j = 0; j < 4005; j++) res = max(res, dp[i][j]);
  cout << res << endl;
}
