#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:500000000")
using namespace std;
int A[4005];
map<int, int> m;
map<int, int>::iterator iter;
int dp[4005][2 * 4005];
int c[1111111];
int main() {
  int n, i, j;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &A[i]), c[A[i]]++, m[A[i]] = 0;
  int cnt = 0;
  for (iter = m.begin(); iter != m.end(); iter++) iter->second = cnt++;
  for (i = 0; i < n; i++) A[i] = m[A[i]];
  for (i = 0; i < n; i++)
    for (j = 0; j < cnt * 2; j++) dp[i][j] = 1;
  for (i = 1; i < n; i++)
    for (j = 0; j < i; j++)
      if (A[j] <= A[i])
        dp[i][cnt + (A[i] - A[j])] =
            max(dp[i][cnt + (A[i] - A[j])], dp[j][A[i] - A[j]] + 1);
      else
        dp[i][A[j] - A[i]] =
            max(dp[i][A[j] - A[i]], dp[j][cnt + (A[j] - A[i])] + 1);
  int res = 1;
  for (i = 0; i < n; i++)
    for (j = 0; j < 2 * cnt; j++) res = max(res, dp[i][j]);
  printf("%d\n", max(res, *max_element(c, c + 1111111)));
}
