#include <bits/stdc++.h>
using namespace std;
int const MAXN = 8010;
int const MAX_W = 2001000;
int const SHIFT = 2000020;
int s[MAXN];
int cnt[MAX_W * 2], cnt_z[MAX_W * 2];
int to_clear[MAXN];
int main() {
  int n;
  scanf("%d", &n);
  if (n == 1) {
    printf("1");
    return 0;
  }
  for (int i = 0; i < n; i++) scanf("%d", &s[i]);
  int mx_len = 0;
  for (int i = 0; i < MAX_W * 2; i++) {
    cnt[i] = 0;
    cnt_z[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    int to_clear_len = 0;
    int cnt_zeros = 1;
    for (int j = i + 1; j < n; j++) {
      int diff = s[j] - s[i];
      if (diff == 0) {
        cnt_zeros++;
        continue;
      }
      if (cnt_z[diff + SHIFT] < cnt_zeros) {
        cnt[diff + SHIFT] += 2;
        cnt_z[diff + SHIFT] = cnt_zeros;
        to_clear[to_clear_len++] = diff;
      }
    }
    for (int j = 0; j < to_clear_len; j++) {
      int diff = to_clear[j];
      if (cnt_z[diff + SHIFT] < cnt_zeros) cnt[diff + SHIFT]++;
      mx_len = max(mx_len, cnt[diff + SHIFT]);
      cnt[diff + SHIFT] = 0;
      cnt_z[diff + SHIFT] = 0;
    }
    int len = 0;
    for (int j = i; j < n; j++)
      if (s[j] == s[i]) len++;
    mx_len = max(mx_len, len);
  }
  cout << mx_len;
  return 0;
}
