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.*;
import java.util.*;

public class Main {
	InputReader scn;
	PrintWriter out;
	String INPUT = "2\r\n" + 
			"3 5\r\n" + 
			"";

	void solve() {
		int n = scn.nextInt();
		int[] a = new int[n];
		BitSet bs = new BitSet();
		for(int i = 0; i < n; i++) {
			a[i] = scn.nextInt();
			bs.set(a[i]);
		}
		int[][] arr = new int[bs.cardinality()][];
		bs.clear();
		for(int i = 0, x = 0; i < n; i++) {
			if(bs.get(a[i])) {
				continue;
			}
			int k = 0;
			for(int j = i; j < n; j++) {
				if(a[i] == a[j]) {
					k++;
				}
			}
			arr[x] = new int[k];
			bs.set(a[i]);
			k = 0;
			for(int j = i; j < n; j++) {
				if(a[i] == a[j]) {
					arr[x][k++] = j + 1;
				}
			}
			x++;
		}
		
		int ans = 0;
		n = arr.length;
		for(int i = 0; i < n; i++) {
			ans = Math.max(ans, arr[i].length);
			for(int j = i; j < n; j++) {
				if(i == j) {
					continue;
				}
				int rv = merge(arr[i], arr[j]);
				ans = Math.max(ans, rv);
			}
		}
		
		out.println(ans);
	}
	
	int merge(int[] a, int[] b) {
		int n = a.length, m = b.length;
		int[] c = new int[n + m];
		
		int i = 0, j = 0, k = 0;
		while(i < n && j < m) {
			if(a[i] < b[j]) {
				c[k++] = a[i++];
			} else {
				c[k++] = -b[j++];
			}
		}
		while(i < n) {
			c[k++] = a[i++];
		}
		while(j < m) {
			c[k++] = -b[j++];
		}
		
		int rv = 1;
		for(i = 1; i < n + m; i++) {
			if(c[i] * c[i - 1] < 0) {
				rv++;
			}
		}
		
		return rv;
	}

	void run() throws Exception {
		boolean onlineJudge = System.getProperty("ONLINE_JUDGE") != null;
		out = new PrintWriter(System.out);
		scn = new InputReader(onlineJudge);
		long time = System.currentTimeMillis();
		solve();
		out.flush();
		if (!onlineJudge) {
			System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" }));
		}
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	class InputReader {
		InputStream is;

		public InputReader(boolean onlineJudge) {
			is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		}

		byte[] inbuf = new byte[1024];
		public int lenbuf = 0, ptrbuf = 0;

		int readByte() {
			if (lenbuf == -1)
				throw new InputMismatchException();
			if (ptrbuf >= lenbuf) {
				ptrbuf = 0;
				try {
					lenbuf = is.read(inbuf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return -1;
			}
			return inbuf[ptrbuf++];
		}

		boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		int skip() {
			int b;
			while ((b = readByte()) != -1 && isSpaceChar(b))
				;
			return b;
		}

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

		char nextChar() {
			return (char) skip();
		}

		String next() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		char[] next(int n) {
			char[] buf = new char[n];
			int b = skip(), p = 0;
			while (p < n && !(isSpaceChar(b))) {
				buf[p++] = (char) b;
				b = readByte();
			}
			return n == p ? buf : Arrays.copyOf(buf, p);
		}

		int nextInt() {
			int num = 0, b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		long nextLong() {
			long num = 0;
			int b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		char[][] nextMatrix(int n, int m) {
			char[][] map = new char[n][];
			for (int i = 0; i < n; i++)
				map[i] = next(m);
			return map;
		}

		int[] nextArray(int n, boolean isOneInd) {
			int k = isOneInd ? 1 : 0;
			int[] a = new int[n + k];
			for (int i = k; i < n + k; i++)
				a[i] = nextInt();
			return a;
		}

		int[] shuffle(int[] arr) {
			Random r = new Random();
			for (int i = 1, j; i < arr.length; i++) {
				j = r.nextInt(i);
				arr[i] = arr[i] ^ arr[j];
				arr[j] = arr[i] ^ arr[j];
				arr[i] = arr[i] ^ arr[j];
			}
			return arr;
		}
	}
}
