#include <bits/stdc++.h>
using namespace std;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, 1, 0, -1};
const int MOD = 1e9 + 7;
const int INF = 1e9;
int n;
vector<int> num;
vector<vector<int> > ind(1e6 + 1);
short mem[4000][4000];
int solve(int idx, int prvidx) {
  if (mem[idx][prvidx] != -1) return mem[idx][prvidx];
  int nxt = num[idx] + -(num[idx] - num[prvidx]);
  auto it = upper_bound(ind[nxt].begin(), ind[nxt].end(), idx);
  if (it == ind[nxt].end()) return 1;
  int ret = solve(*it, idx) + 1;
  return mem[idx][prvidx] = ret;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  memset(mem, -1, sizeof mem);
  cin >> n;
  num.resize(n);
  for (int i = 0; i < n; i++) cin >> num[i], ind[num[i]].push_back(i);
  int mx = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      mx = max(mx, solve(j, i));
    }
  }
  cout << mx + 1 << endl;
  cin.ignore(), cin.get();
}
