#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using dd = long double;
namespace {
static bool constexpr dbg = 0;
ll constexpr N = 4100;
ll n, res, b[N], t[N];
int16_t mp[N][2 * N];
void init() {
  cin >> n;
  for (ll i = 1; i <= (ll)(n); ++i) cin >> b[i];
}
void solve() {
  for (ll i = 1; i <= (ll)(n); ++i) t[i] = b[i];
  sort(t + 1, t + 1 + n);
  auto end = unique(t + 1, t + 1 + n);
  ll id = 0;
  map<ll, ll> m;
  for (auto i = t + 1; i < end; ++i) m[*i] = ++id;
  for (ll i = 1; i <= (ll)(n); ++i) b[i] = m[b[i]];
  for (ll i = 1; i <= (ll)(n); ++i) {
    for (ll j = 1; j < i; ++j) {
      ll d = b[i] - b[j];
      mp[i][N + d] = 1 + mp[j][N - d];
      res = max<ll>(res, mp[i][N + d]);
    }
  }
  cout << (1 + res);
}
}  // namespace
int main() {
  if (!dbg) {
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  }
  cout << fixed << setprecision(20);
  init();
  solve();
  return 0;
}
