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.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class AlmostArithmeticSequences {

    static FastReader read = new FastReader();
    static int mxn = (int)(1e6+10);
    public static void main(String[] args) {

        solve();

    }

    private static void solve() {

        int n = read.nextInt();

        int[] arr = new int[n+1];
        ArrayList<Integer>[] ind = new ArrayList[mxn];

        for (int i=1;i<=n;++i){
            arr[i] = read.nextInt();
            if (ind[arr[i]] == null){
                ArrayList<Integer> tmp = new ArrayList<>();
                tmp.add(i);
                ind[arr[i]] = tmp;
            } else
                ind[arr[i]].add(i);
        }


        Arrays.sort(arr);

        int[] uni = Arrays.stream(arr).distinct().toArray();

        int ans  =Integer.MIN_VALUE;
        for (int i=1;i<uni.length;++i){
            for (int j=1;j<uni.length;++j){
                if (i!=j){
                    ans  =Math.max(ans,res(ind[uni[i]], ind[uni[j]]));
                } else
                    ans = Math.max(ans, ind[uni[i]].size());
            }
        }

        System.out.println(ans);


    }

    private static int res(ArrayList<Integer> v1, ArrayList<Integer> v2) {

        int res = 0;



        for (int i1=0,i2=0,cur=-1;i1<v1.size() && i2<v2.size();){
            while (i1<v1.size() && v1.get(i1) < cur){
                i1++;
            }

            if (i1 == v1.size()){
                break;
            }

            res++;

            cur = v1.get(i1);

            while (i2<v2.size() && v2.get(i2) < cur){
                i2++;
            }

            if (i2 == v2.size()){
                break;
            }

            res++;
            cur = v2.get(i2);
        }

//        int low = 0, high = v1.size()-1;
//
//        int i1 = 0;
//
//        int ans = -1;
//        while (low<=high){
//            int mid = (low+high)>>1;
//
//            if (v1.get(mid) < cur){
//                low = mid+1;
//            } else {
//                ans = mid;
//                high  = mid-1;
//            }
//        }



        return res;
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        String[] strArray() {
            String[] str = nextLine().split(" ");
            return str;
        }

        int[] intArray(int n) {
            String[] str = strArray();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = Integer.parseInt(str[i]);
            }
            return arr;
        }
    }

}
