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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C255 solver = new C255();
        solver.solve(1, in, out);
        out.close();
    }

    static class C255 {
        int n;
        int[] a;
        int[][] memo;
        HashMap<Integer, TreeSet<Integer>> inds;

        int dp(int prev, int cur) {
            if (cur == n) return 0;
            if (memo[prev][cur] != -1) return memo[prev][cur];
            int ans = 0;
            Integer next = inds.get(a[prev]).higher(cur);
            if (next != null) {
                ans = 1 + dp(cur, next);
            }
            return memo[prev][cur] = ans;
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            a = new int[n];
            memo = new int[n][n];
            inds = new HashMap<>();
            for (int i = 0; i < n; ++i) {
                a[i] = in.nextInt();
                if (!inds.containsKey(a[i])) inds.put(a[i], new TreeSet<>());
                inds.get(a[i]).add(i);
            }
            int ans = 1;
            for (int i = 0; i < n; ++i) Arrays.fill(memo[i], -1);
            for (int i = 0; i < n; ++i) {
                HashSet<Integer> seen = new HashSet<>();
                for (int j = i + 1; j < n; ++j) {
                    if (seen.contains(a[j])) continue;
                    seen.add(a[j]);
                    ans = Math.max(ans, 2 + dp(i, j));
                }
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}

