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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public class Main implements Runnable {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new Thread(new Main()).start();
	}

	public void run() {
		Locale.setDefault(Locale.US);
		try {
			run1();
		} catch (IOException e) {
			throw new RuntimeException();
		}
	}

	int nextInt(StreamTokenizer st) throws IOException {
		st.nextToken();
		return (int) st.nval;
	}

	private List<Integer> kmp(String x, String a) {
		String s = a + "$" + x;
		int[] oppa = new int[s.length()];
		oppa[0] = 0;
		int tmp = 0;
		List<Integer> res = new ArrayList<Integer>();
		for (int i = 1; i < s.length(); i++) {
			while (tmp != 0 && s.charAt(tmp) != s.charAt(i)) {
				// System.out.println(i + " " + tmp);
				tmp = oppa[tmp - 1];
			}
			if (s.charAt(tmp) == s.charAt(i))
				tmp++;
			oppa[i] = tmp;
			if (tmp == a.length()) {
				res.add(i - a.length() - a.length());
			}
		}
		return res;
	}

	double nextDouble(StreamTokenizer st) throws IOException {
		st.nextToken();
		return st.nval;
	}

	String nextLine(StreamTokenizer st) throws IOException {
		st.nextToken();
		return st.sval;
	}

	public void run1() throws IOException {
		// Scanner sc = new Scanner(new FileReader("input.txt"));
		// Scanner sc = new Scanner(new InputStreamReader(System.in));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("input.txt"));
		// PrintWriter pw = new PrintWriter(new FileWriter("output.txt"));
		int n = Integer.parseInt(br.readLine());
		String[] s = br.readLine().split(" ");
		int[] arr = new int[n];
		for (int i = 0; i < n; i++)
			arr[i] = Integer.parseInt(s[i]);
		long[] b = new long[] { 12423444747513l, 324254646443145235l };
		long[][] hash = new long[2][n + 1];
		for (int j = 0; j < 2; j++)
			for (int i = 0; i < n; i++) {
				hash[j][i + 1] = hash[j][i] * b[j] + arr[i];
			}
		Map<Integer, List<Integer>> map = new HashMap<Integer, List<Integer>>();
		for (int i = 0; i < n; i++) {
			if (!map.containsKey(arr[i]))
				map.put(arr[i], new ArrayList<Integer>(10));
			map.get(arr[i]).add(i);
		}
		long[][] pow = new long[2][n];
		pow[0][0] = pow[1][0] = 1;
		for (int j = 0; j < 2; j++)
			for (int i = 1; i < n; i++)
				pow[j][i] = pow[j][i - 1] * b[j];
		List<int[]> oppa = new ArrayList<int[]>();
		for (List<Integer> l : map.values()) {
			int m = l.size();
			for (int u : l)
				for (int v : l)
					if (u < v && v + v - u <= n) {
						boolean ok = true;
						for (int j = 0; j < 2; j++) {
							if (hash[j][v] - hash[j][u] * pow[j][v - u] != hash[j][v
									+ v - u]
									- hash[j][v] * pow[j][v - u])
								ok = false;
						}
						if (ok)
							oppa.add(new int[] { u, v });
					}
		}
		Collections.sort(oppa, new Comparator<int[]>() {
			public int compare(int[] a, int[] b) {
				if (a[1] - a[0] != b[1] - b[0])
					return a[1] - a[0] - b[1] + b[0];
				return a[0] - b[0];
			}
		});
		int cur = 0;
		for (int[] tmp : oppa) {
			if (tmp[0] >= cur)
				cur = tmp[1];
		}
		System.out.println(n - cur);
		for (int i = cur; i < n; i++)
			System.out.print(arr[i] + " ");
		// pw.close();
	}

	int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}
}