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

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class  test{
	
	// ArrayList<Integer> lis = new ArrayList<Integer>();
	// ArrayList<String> lis = new ArrayList<String>();
	// PriorityQueue<Integer> que = new PriorityQueue<Integer>();
	//  Stack<Integer> que = new Stack<Integer>();
    //	static long sum=0;
	// int a,b,c;
	// 1000000007 (10^9+7)
	//static int mod = 1000000007;
	static int mod = 1000000009,r=0;
   // static int dx[]={1,-1,0,0};
//	static int dy[]={0,0,1,-1};
//	static int dx[]={1,-1,0,0,1,1,-1,-1};
//  static int dy[]={0,0,1,-1,1,-1,1,-1};
	//static long H,L;
	//static Set<Integer> set = new HashSet<Integer>();
	
public  static void main(String[] args)   throws Exception, IOException{
   //String line=""; throws Exception, IOException
   //(line=br.readLine())!=null
	//Scanner sc =new Scanner(System.in);
	// !!caution!! int long //  
	Reader sc = new Reader(System.in);
  // while( ){
	  // int  n=sc.nextInt(),m=sc.nextInt();//a[]=new int[n],b[]=new int[n];
	
	int n=sc.nextInt(),x[]=new int[4001],c[]=new int[n],k=0,re=1;
    boolean b[]=new boolean[1000001];
    HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
	for(int i=0;i<n;i++){
		c[i]=sc.nextInt();
	   if( b[c[i]] ){ map.put(c[i],  map.get(c[i])+1 ); re=max(re,map.get(c[i])); }	
	   else { map.put(c[i],1); x[k]=c[i];  b[x[k]]=true; k++;}
	}
	
	
	for(int i=0;i<k;i++){
		for(int j=i+1;j<k;j++){
		  int a=-1,aa=0;  
		  if( map.get(x[i])+map.get(x[j])<=re )continue;
		  for(int t=0;t<n;t++){
			 if( c[t]!=a && ( c[t]==x[i]||c[t]==x[j] ) ){aa++; a=c[t];  } 
			  
		  }
		re=max(re,aa);	
		}
	}
	
	
	System.out.println(re);
}


static void db(Object... os){
    System.err.println(Arrays.deepToString(os));

}
}



class Reader
{
	private BufferedReader x;
	private StringTokenizer st;
	
	public Reader(InputStream in)
	{
		x = new BufferedReader(new InputStreamReader(in));
		st = null;
	}
	public String nextString() throws IOException
	{
		while( st==null || !st.hasMoreTokens() )
			st = new StringTokenizer(x.readLine());
		return st.nextToken();
	}
	public int nextInt() throws IOException
	{
		return Integer.parseInt(nextString());
	}
	public long nextLong() throws IOException
	{
		return Long.parseLong(nextString());
	}
	public double nextDouble() throws IOException
	{
		return Double.parseDouble(nextString());
	}
}




/*class P implements Comparable<P>{
//	implements Comparable<P>
	int a,b,c;
	P(int a,int b,int c){
		this.a=a;
		this.b=b;
		this.c=c;
	} 
	public int compareTo(P x){
	   	 return b-x.b; 
	   }
}
*/
