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.List;
import java.io.StreamTokenizer;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.HashMap;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.util.Collection;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		TokenizerReader in = new TokenizerReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class SuffixArray {
    final int[][] classes;
    final int n, L;
    int[] array;

    SuffixArray(final int[] a) {
        this.n = a.length;
        int L = Integer.highestOneBit(n);
        if (n > L)
            L <<= 1;
        this.L = L = Integer.numberOfTrailingZeros(L) + 1;
        this.classes = new int[L][n];
        Integer[] idx = new Integer[n];
        for (int i = 0; i < n; ++i)
            idx[i] = i;
        for (int i = 0; i < L; ++i) {
            Comparator<Integer> cmp;
            if (i == 0) {
                cmp = new Comparator<Integer>() {
                    @Override
                    public int compare(Integer o1, Integer o2) {
                        if (a[o1] < a[o2])
                            return -1;
                        else if (a[o1] > a[o2])
                            return 1;
                        else return 0;
                    }
                };
            } else {
                final int prevL = i-1;
                cmp = new Comparator<Integer>() {
                    @Override
                    public int compare(Integer o1, Integer o2) {
                        int d = classes[prevL][o1] - classes[prevL][o2];
                        if (d != 0)
                            return d;
                        o1 += (1<<prevL);
                        if (o1 >= n)
                            return -1;
                        o2 += (1<<prevL);
                        if (o2 >= n)
                            return 1;
                        return classes[prevL][o1] - classes[prevL][o2];
                    }
                };
            }
            Arrays.sort(idx, cmp);
            classes[i][idx[0]] = 0;
            for (int j = 1; j < n; ++j) {
                if (cmp.compare(idx[j-1], idx[j]) == 0)
                    classes[i][idx[j]] = classes[i][idx[j-1]];
                else
                    classes[i][idx[j]] = classes[i][idx[j-1]] + 1;
            }
        }

        array = new int[n];
        for (int i = 0; i < n; ++i)
            array[i] = idx[i];
    }

    int getLCP(int charIdx1, int charIdx2) {
        int res = 0;
        for (int i = L-1; i >= 0; --i) {
            if (classes[i][charIdx1] == classes[i][charIdx2]) {
                res += (1<<i);
                charIdx1 += (1<<i);
                charIdx2 += (1<<i);
                if (charIdx1 >= n || charIdx2 >= n)
                    break;
            }
        }
        return res;
    }
}

class TaskC {
    public void solve(@SuppressWarnings("UnusedParameters") int testNumber, TokenizerReader in, PrintWriter out) {
        int n = in.nextInt();
        int[] a = new int[n];
        HashMap<Integer, ArrayList<Integer>> entries = new HashMap<Integer, ArrayList<Integer>>();
        for (int i = 0; i < n; ++i) {
            a[i] = in.nextInt();
            ArrayList<Integer> list = entries.get(a[i]);
            if (list == null) {
                list = new ArrayList<Integer>();
                entries.put(a[i], list);
            }
            list.add(i);
        }
        SuffixArray sa = new SuffixArray(a);

        ArrayList<Pair<Integer>> candidates = new ArrayList<Pair<Integer>>();

        for (ArrayList<Integer> list: entries.values()) {
            Collections.sort(list);
            int k = list.size();
            for (int i = 0; i < k; ++i) for (int j = i+1; j < k; ++j) {
                int lcp = sa.getLCP(list.get(i), list.get(j));
                if (lcp >= list.get(j) - list.get(i))
                    candidates.add(new Pair<Integer>(list.get(i), list.get(j)));
            }
        }

        Collections.sort(candidates, new Comparator<Pair<Integer>>() {
            @Override
            public int compare(Pair<Integer> o1, Pair<Integer> o2) {
                int d = (o1.t2 - o1.t1) - (o2.t2 - o2.t1);
                if (d != 0)
                    return d;
                return o1.t1 - o2.t1;
            }
        });
        int left = 0;
        for (Pair<Integer> p: candidates)
            if (p.t1 >= left)
                left = p.t2;

        out.println(n - left);
        for (int i = left; i < n; ++i)
            out.print(a[i] + " ");
        out.println();
    }
}

class TokenizerReader extends StreamTokenizer {
    public TokenizerReader(InputStream in) {
        super(new BufferedReader(new InputStreamReader(in)));
        defaultConfig();
    }

    public String nextString() {
        try {
            nextToken();
        } catch (IOException e) {
            throw new RuntimeException("nextString: exception in line " + lineno(), e);
        }
        return sval;
    }

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

    public void defaultConfig() {
        resetSyntax();
        wordChars(33, 126);
        whitespaceChars(0, ' ');
    }

    }

class Pair<T> {
    public final T t1, t2;

    public Pair(T t1, T t2) {
        this.t1 = t1;
        this.t2 = t2;
    }

    public int hashCode() {
        return t1.hashCode() * 31013 + t2.hashCode();
    }

    public boolean equals(Object obj) {
        Pair<T> p = (Pair<T>) obj;
        return t1.equals(p.t1) && t2.equals(p.t2);
    }
}