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.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

public class C {
    
    static StringTokenizer st;
    static BufferedReader in;
    static class Sort implements Comparable<Sort> {
        int val, ind;
        public int compareTo(Sort arg0) {
            return this.val-arg0.val;
        }
    }
    static int L, n;
    static int[][]c;
    static class Segment implements Comparable<Segment> {
        int L, R, leng;
        public int compareTo(Segment o) {
            if (this.leng==o.leng)
                return this.L-o.L;
            return this.leng-o.leng;
        }
        public Segment(int L, int R) {
            this.L = L;
            this.R = R;
            this.leng = R-L;
        }
    }
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        n = nextInt();
        Sort[]a = new Sort[n];
        for (int i = 0; i < n; i++) {
            a[i] = new Sort();
            a[i].val = nextInt();
            a[i].ind = i;
        }
        Arrays.sort(a);
        int[]real_value = new int[n];
        real_value[0] = a[0].val;
        int[]b = new int[n];
        b[a[0].ind] = 0;
        int t = 0;
        for (int i = 1; i < n; i++) {
            if (a[i].val != a[i-1].val)
                t++;
            real_value[t] = a[i].val;
            b[a[i].ind] = t;
        }
        int[]cnt = new int[n], p = new int[n];
        while ((1 << L) <= n)
            L++;
        c = new int[L+1][n];
        for (int i = 0; i < n; i++) {
            cnt[b[i]]++;
        }
        for (int i = 1; i < n; i++) {
            cnt[i] += cnt[i-1];
        }
        for (int i = 0; i < n; i++) {
            p[--cnt[b[i]]] = i;
        }
        int classes = 1;
        c[0][p[0]] = 0;
        for (int i = 1; i < n; i++) {
            if (b[p[i]] != b[p[i-1]])
                classes++;
            c[0][p[i]] = classes-1;
        }
        int[]pn = new int[n];
        for (int h = 0; (1 << h) < n; h++) {
            L = h+1;
            for (int i = 0; i < n; i++) {
                pn[i] = p[i]-(1 << h);
                if (pn[i] < 0)
                    pn[i] += (1 << h);
            }
            Arrays.fill(cnt, 0);
            for (int i = 0; i < n; i++) {
                cnt[c[h][pn[i]]]++;
            }
            for (int i = 1; i < n; i++) {
                cnt[i] += cnt[i-1];
            }
            for (int i = n-1; i >= 0; i--) {
                p[--cnt[c[h][pn[i]]]] = pn[i];
            }
            classes = 1;
            c[h+1][p[0]] = 0;
            for (int i = 1; i < n; i++) {
                int mid1 = (p[i]+(1 << h)) % n, mid2 = (p[i-1]+(1 << h)) % n;
                if (c[h][p[i]] != c[h][p[i-1]] || c[h][mid1] != c[h][mid2])
                    classes++;
                c[h+1][p[i]] = classes-1;
            }
        }
        ArrayList<Integer>[]L = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            L[i] = new ArrayList<Integer>();
        }
        for (int i = 0; i < n; i++) {
            L[b[i]].add(i);
        }
        ArrayList<Segment> List = new ArrayList<Segment>();
        for (int i = 0; i < n; i++) {
            if (L[i].size() >= 2) {
                for (int j = 0; j < L[i].size(); j++) {
                    for (int j2 = j+1; j2 < L[i].size(); j2++) {
                        if (lcp(L[i].get(j), L[i].get(j2)) >= L[i].get(j2)-L[i].get(j))
                            List.add(new Segment(L[i].get(j), L[i].get(j2)));
                    }
                }
            }
        }
        Collections.sort(List);
        int last = -1;
        for (Segment s : List) {
            if (s.L > last)
                last = s.R-1;
        }
        pw.println(n-1-last);
        for (int i = last+1; i < n; i++) {
            pw.print(real_value[b[i]]+" ");
        }
        pw.close();
    }
    private static int lcp(int i, int j) {
        int res = 0;
        for (int k = L; k >= 0; k--) {
            if (i+(1 << k) <= n && j+(1 << k) <= n && c[k][i]==c[k][j]) {
                res += (1 << k);
                i += (1 << k);
                j += (1 << k);
            }
        }
        return res;
    }
    private static int nextInt() throws IOException{
        return Integer.parseInt(next());
    }
    
    private static long nextLong() throws IOException{
        return Long.parseLong(next());
    }
    
    private static double nextDouble() throws IOException{
        return Double.parseDouble(next());
    }
    
    private static String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
}