Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as:

  * a1 = p, where p is some integer; 
  * ai = ai - 1 + ( - 1)i + 1·q (i > 1), where q is some integer. 



Right now Gena has a piece of paper with sequence b, consisting of n integers. Help Gena, find there the longest subsequence of integers that is an almost arithmetical progression.

Sequence s1, s2, ..., sk is a subsequence of sequence b1, b2, ..., bn, if there is such increasing sequence of indexes i1, i2, ..., ik (1 ≤ i1 < i2 < ... < ik ≤ n), that bij = sj. In other words, sequence s can be obtained from b by crossing out some elements.

Input

The first line contains integer n (1 ≤ n ≤ 4000). The next line contains n integers b1, b2, ..., bn (1 ≤ bi ≤ 106).

Output

Print a single integer — the length of the required longest subsequence.

Examples

Input

2
3 5


Output

2


Input

4
10 20 10 30


Output

3

Note

In the first test the sequence actually is the suitable subsequence. 

In the second test the following subsequence fits: 10, 20, 10.
#include <bits/stdc++.h>
using namespace std;
void print() { cout << endl; }
template <typename First, typename... Strings>
void print(First arg, const Strings &...rest) {
  cout << arg << " ";
  print(rest...);
}
template <typename T>
void print(vector<T> &v) {
  for (T x : v) cout << x << " ";
  cout << endl;
}
long long int calc(vector<long long int> &a, vector<long long int> &b) {
  long long int cnt = 0, last = -1;
  while (1) {
    long long int in = upper_bound(a.begin(), a.end(), last) - a.begin();
    if (in == a.size()) return cnt;
    cnt++;
    last = a[in];
    in = upper_bound(b.begin(), b.end(), last) - b.begin();
    if (in == b.size()) return cnt;
    cnt++;
    last = b[in];
  }
  return cnt;
}
void test_case() {
  long long int n;
  cin >> n;
  vector<long long int> arr(n);
  for (long long int i = 0; i < n; i++) cin >> arr[i];
  map<long long int, vector<long long int> > mp;
  for (long long int i = 0; i < n; i++) mp[arr[i]].push_back(i);
  long long int res = 0;
  for (auto &x : mp) {
    for (auto &y : mp) {
      res = max(res, calc(x.second, y.second));
    }
  }
  print(res);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  for (long long int i = 0; i < t; i++) {
    test_case();
  }
  return 0;
}
