#include <bits/stdc++.h>
using namespace std;
ifstream fin("in.in");
ofstream fout("out.out");
const int N = 4000 + 10;
int n, a[N], res = 1;
vector<pair<int, int> > v[N];
int find(int i, int x) {
  int ind =
      lower_bound(v[i].begin(), v[i].end(), make_pair(x, 0)) - v[i].begin();
  if (ind == v[i].size()) return 1;
  if (v[i][ind].first != x) return 1;
  return v[i][ind].second;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    map<int, int> m;
    map<int, int>::iterator it;
    for (int j = 0; j < i; j++) {
      int dif = a[i] - a[j];
      int len = find(j, -dif) + 1;
      m[dif] = max(m[dif], len);
      res = max(res, m[dif]);
    }
    for (it = m.begin(); it != m.end(); it++)
      v[i].push_back(make_pair(it->first, it->second));
  }
  cout << res << endl;
  return 0;
}
