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.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.TreeSet;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author AlexFetisov
 */
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);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    public static final long P = 1000000007;

    long[] hash;
    long[] pow;

    long getHash(int from, int to) {
        if (from == 0) return hash[to];
        return hash[to] - hash[from-1] * pow[to - from + 1];
    }

    int[][] pos;
    int[] cnt;

    TreeSet<Inter> intervals;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int[] a = Utils.readIntArray(in, n);
        int[] original = a.clone();
        int[] b = a.clone();
        b = ArrayUtils.sortAndUnique(b);
        int max = 0;
        for (int i = 0; i < n; ++i) {
            a[i] = Arrays.binarySearch(b, a[i]) + 1;
            max = Math.max(max, a[i]);
        }
        hash = new long[n];
        hash[0] = a[0] + 1;
        for (int i = 1; i < n; ++i) {
            hash[i] = hash[i-1] * P + a[i] + 1;
        }
        pow = new long[n+1];
        pow[0] = 1;
        for (int i = 1; i <= n; ++i) pow[i] = pow[i-1] * P;

        pos = new int[max + 1][10];
        cnt = new int[max + 1];

        for (int i = 0; i < n; ++i) {
            pos[a[i]][cnt[a[i]]++] = i;
        }

        intervals = new TreeSet<Inter>();

        for (int i = 0; i <= max; ++i) {
            for (int j = 0; j < cnt[i]; ++j) {
                for (int k = j + 1; k < cnt[i]; ++k) {
                    int pos1 = pos[i][j], pos2 = pos[i][k];
                    int len2 = pos2 - pos1;
                    if (pos2 + len2 - 1 < n) {
                        if (getHash(pos1, pos1 + len2 - 1) == getHash(pos2, pos2 + len2 - 1)) {
                            intervals.add(new Inter(pos1, pos2 + len2 - 1));
                        }
                    }
                }
            }
        }
        int limit = -1;
        while (!intervals.isEmpty()) {
            Inter interval = intervals.first();
            intervals.remove(interval);
            if (interval.x > limit) {
                limit = interval.x + (interval.y - interval.x + 1) / 2 - 1;
            }
        }
        out.println(n - limit - 1);
        for (int i = limit + 1; i < n; ++i) {
            out.print(original[i] + " ");
        }
        out.println();
    }

    class Inter implements Comparable<Inter> {

        int x, y;

        Inter(int x, int y) {
            this.x = x;
            this.y = y;
        }

        public int compareTo(Inter o) {
            if (y - x != o.y - o.x) {
                return y - x - (o.y - o.x);
            }
            return x - o.x;
        }
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer stt;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
    }

    public String nextLine() {
        try {
            return reader.readLine().trim();
        } catch (IOException e) {
            return null;
        }
    }

    public String nextString() {
        while (stt == null || !stt.hasMoreTokens()) {
            stt = new StringTokenizer(nextLine());
        }
        return stt.nextToken();
    }

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

}

class Utils {
    public static int[] readIntArray(InputReader in, int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) {
            a[i] = in.nextInt();
        }
        return a;
    }

}

class ArrayUtils {

    public static int[] sortAndUnique(int[] a) {
        int[] b = a.clone();
        Arrays.sort(b);
        ArrayList<Integer> temp = new ArrayList<Integer>();
        temp.add(b[0]);
        int size = 1;
        for (int i = 1; i < b.length; ++i) {
            if (temp.get(size-1) != b[i]) {
                temp.add(b[i]);
                ++size;
            }
        }
        return CollectionUtils.toArray(temp);
    }

}

class CollectionUtils {
    public static int[] toArray(Collection<Integer> collection) {
        int[] result = new int[collection.size()];
        int index = 0;
        for (int element : collection) {
            result[index++] = element;
        }
        return result;
    }

    //    public static List<Double> unique(List<Double> a) {
//        List<Double> result = new ArrayList<Double>();
//        result.add(a.get(0));
//        int last = 0;
//        for (int i = 1; i < a.size(); ++i) {
//            if (DoubleUtils.compareTo(a.get(i), result.get(last)) != 0) {
//                result.add(a.get(i));
//                ++last;
//            }
//        }
//        return result;
//    }

//    public static void unique(List<Integer> a) {
//        Collections.sort(a);
//        int size = 1;
//        for (int i = 1; i < a.size(); i++) {
//            if (!a.get(i).equals(a.get(size - 1))) {
//                a.set(size++, a.get(i));
//            }
//        }
//        for (int i = a.size() - 1; i >= size; i--) {
//            a.remove(i);
//        }
//    }

}