#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  std::cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const long long int N = 1e5 + 5;
void Hariiih() {
  long long int n;
  cin >> n;
  long long int arr[n + 1];
  arr[0] = INT_MAX;
  for (long long int i = 0; i < n; ++i) {
    cin >> arr[i + 1];
  }
  long long int dp[n + 4][n + 4];
  memset(dp, 0, sizeof(dp));
  long long int ans = min(n, 2ll);
  for (long long int i = 1; i <= n; i++) {
    long long int prev = 0;
    for (long long int j = 0; j < i; j++) {
      dp[i][j] = dp[j][prev] + 1;
      if (arr[j] == arr[i]) prev = j;
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << '\n';
  return;
}
signed main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) Hariiih();
  return 0;
  return 0;
}
