#include <bits/stdc++.h>
using namespace std;
int n, dp[4000][4000][2], v[4000], last[1000001], need, res = 1;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", v + i);
  for (int i = n - 1; i >= 0; --i) {
    for (int j = n - 1; j >= i; --j) last[v[j]] = -1;
    for (int j = n - 1; j > i; --j) {
      for (int o = 0; o < 2; ++o) {
        need = o ? v[i] - v[j] : v[j] - v[i];
        need *= o ? 1 : -1;
        need += v[j];
        if (need >= 1 && need <= 1000000 && last[need] != -1)
          dp[i][j][o] = 1 + dp[j][last[need]][!o];
        if (o && res < dp[i][j][o] + 2) res = dp[i][j][o] + 2;
      }
      last[v[j]] = j;
    }
  }
  printf("%d\n", res);
  return 0;
}
