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;
long long MOD_EXPO(long long b, long long p, long long m) {
  if (p == 0) return 1;
  long long ret = MOD_EXPO(b, p / 2, m) % m;
  ret = (ret * ret) % m;
  return ((p & 1) ? (ret * b) % m : ret % m);
}
long long POWER(long long N, long long K) {
  long long i, ans = 1;
  for (i = 1; i <= K; i++) ans *= N;
  return ans;
}
int SET(int N, int pos) { return (N | (1 << pos)); }
int RESET(int N, int pos) { return (N & !(1 << pos)); }
bool CHECK(int N, int pos) { return (N & (1 << pos)); }
int dx4[] = {1, -1, 0, 0};
int dy4[] = {0, 0, 1, -1};
int dx6[] = {0, 0, 1, -1, 0, 0};
int dy6[] = {1, -1, 0, 0, 0, 0};
int dz6[] = {0, 0, 0, 0, 1, -1};
int dx8[] = {1, -1, 0, 0, -1, 1, -1, 1};
int dy8[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dkx8[] = {-1, 1, -1, 1, -2, -2, 2, 2};
int dky8[] = {2, 2, -2, -2, 1, -1, 1, -1};
int tc = 1;
const double eps = 1e-9;
const double pi = acos(-1.0);
const long long int mx = 4e3;
const long long int mod = 1e9 + 7;
int dp[mx + 5][mx + 5];
int a[mx + 5];
int main() {
  int n, index;
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  index = 0;
  map<int, int> mp;
  for (int i = 0; i < n; i++)
    if (mp.find(a[i]) == mp.end()) mp[a[i]] = index++;
  for (int i = 0; i < n; i++) a[i] = mp[a[i]];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) dp[i][j] = 1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < i; j++) {
      dp[i][a[j]] = max(1 + dp[j][a[i]], dp[i][a[j]]);
    }
  int ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) ans = max(ans, dp[i][j]);
  cout << ans << "\n";
  return 0;
}
