Problem: Once Bob saw a string. It contained so many different letters, that the letters were marked by numbers, but at the same time each letter could be met in the string at most 10 times. Bob didn't like that string, because it contained repeats: a repeat of length x is such a substring of length 2x, that its first half coincides character by character with its second half. Bob started deleting all the repeats from the string. He does it as follows: while it's possible, Bob takes the shortest repeat, if it is not unique, he takes the leftmost one, and deletes its left half and everything that is to the left of this repeat.

You're given the string seen by Bob. Find out, what it will look like after Bob deletes all the repeats in the way described above.

Input

The first input line contains integer n (1 ≤ n ≤ 105) — length of the string. The following line contains n space-separated integer numbers from 0 to 109 inclusive — numbers that stand for the letters of the string. It's guaranteed that each letter can be met in the string at most 10 times.

Output

In the first line output the length of the string's part, left after Bob's deletions. In the second line output all the letters (separated by a space) of the string, left after Bob deleted all the repeats in the described way.

Examples

Input

6
1 2 3 1 2 3


Output

3
1 2 3 


Input

7
4 5 6 5 6 7 7


Output

1
7 

Solution (in JAVA):

Solution:
import java.util.*;
import java.io.*;

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

	FastReader in = new FastReader();
	PrintWriter out = new PrintWriter(System.out);
	void run(){
		work();
		out.flush();
	}
	long mod=1000000007;
	long gcd(long a,long b) {
		return a==0?b:gcd(b%a,a);
	}
	void work() {
		int n=ni();
		long[] A=na(n);
		HashMap<Long,ArrayList<Integer>> map=new HashMap<>();
		for(int i=0;i<n;i++) {
			if(map.get(A[i])==null) {
				map.put(A[i],new ArrayList<>());
			}
			map.get(A[i]).add(i);
		}
		long[] pow=new long[n];
		long[] rec=new long[n];
		pow[0]=1;
		for(int i=1;i<n;i++) {
			pow[i]=(pow[i-1]*mod)%mod;
		}
		long cur=0;
		for(int i=0;i<n;i++) {
			cur=(cur*mod+A[i])%mod;
			rec[i]=cur;
		}
		PriorityQueue<int[]> pq=new PriorityQueue(new Comparator<int[]>() {
			public int compare(int[] A1,int[] A2) {
				if(A1[1]-A1[0]==A2[1]-A2[0]) {
					return A1[0]-A2[0];
				}
				return (A1[1]-A1[0])-(A2[1]-A2[0]);
			}
		});
		for(long key:map.keySet()) {
			ArrayList<Integer> list=map.get(key);
			for(int i=0;i<list.size();i++) {
				for(int j=i+1;j<list.size();j++) {
					pq.add(new int[] {list.get(i),list.get(j)});
				}
			}
		}
		int r=0;
		out:
		for(;pq.size()>0;) {
			int[] q=pq.poll();
			int s1=q[0];
			int e1=q[1]-1;
			int s2=q[1];
			int e2=s2+e1-s1;
			if(s1<r||e2>=n) continue;
			long v1=((rec[e1]-(s1==0?0:(rec[s1-1]*pow[e1-s1+1])))%mod+mod)%mod;
			long v2=((rec[e2]-(s2==0?0:(rec[s2-1]*pow[e2-s2+1])))%mod+mod)%mod;
			if(v1==v2) {
				for(;s1<=e1;s1++,s2++) {
					if(A[s1]!=A[s2]) {
						continue out;
					}
				}
				r=q[1];
			}
		}
		out.println(n-r);
		for(int i=r;i<n;i++) {
			out.print(A[i]+" ");
		}
	}
	
	
	//input
	private ArrayList<Integer>[] ng(int n, int m) {
		ArrayList<Integer>[] graph=(ArrayList<Integer>[])new ArrayList[n];
		for(int i=0;i<n;i++) {
			graph[i]=new ArrayList<>();
		}
		for(int i=1;i<=m;i++) {
			int s=in.nextInt()-1,e=in.nextInt()-1;
			graph[s].add(e);
			graph[e].add(s);
		}
		return graph;
	}

	private ArrayList<long[]>[] ngw(int n, int m) {
		ArrayList<long[]>[] graph=(ArrayList<long[]>[])new ArrayList[n];
		for(int i=0;i<n;i++) {
			graph[i]=new ArrayList<>();
		}
		for(int i=1;i<=m;i++) {
			long s=in.nextLong()-1,e=in.nextLong()-1,w=in.nextLong();
			graph[(int)s].add(new long[] {e,w,i});
			graph[(int)e].add(new long[] {s,w});
		}
		return graph;
	}

	private int ni() {
		return in.nextInt();
	}

	private long nl() {
		return in.nextLong();
	}
	
	private String ns() {
		return in.next();
	}

	private long[] na(int n) {
		long[] A=new long[n];
		for(int i=0;i<n;i++) {
			A[i]=in.nextLong();
		}
		return A;
	}
	private int[] nia(int n) {
		int[] A=new int[n];
		for(int i=0;i<n;i++) {
			A[i]=in.nextInt();
		}
		return A;
	}
}	

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());
	}
}