This problem differs from one which was on the online contest.

The sequence a1, a2, ..., an is called increasing, if ai < ai + 1 for i < n.

The sequence s1, s2, ..., sk is called the subsequence of the sequence a1, a2, ..., an, if there exist such a set of indexes 1 ≤ i1 < i2 < ... < ik ≤ n that aij = sj. In other words, the sequence s can be derived from the sequence a by crossing out some elements.

You are given two sequences of integer numbers. You are to find their longest common increasing subsequence, i.e. an increasing sequence of maximum length that is the subsequence of both sequences.

Input

The first line contains an integer n (1 ≤ n ≤ 500) — the length of the first sequence. The second line contains n space-separated integers from the range [0, 109] — elements of the first sequence. The third line contains an integer m (1 ≤ m ≤ 500) — the length of the second sequence. The fourth line contains m space-separated integers from the range [0, 109] — elements of the second sequence.

Output

In the first line output k — the length of the longest common increasing subsequence. In the second line output the subsequence itself. Separate the elements with a space. If there are several solutions, output any.

Examples

Input

7
2 3 1 6 5 4 6
4
1 3 5 6


Output

3
3 5 6 


Input

5
1 2 0 2 1
3
1 0 1


Output

2
0 1 
/**
 * Created by Aminul on 11/27/2018.
 */

import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class CF10D {
    public static void main(String[] args)throws Exception {
        FastReader in = new FastReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        TreeSet<Integer> set = new TreeSet<>();
        HashMap<Integer, Integer> map = new HashMap<>();
        n = in.nextInt();
        a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            set.add(a[i]);
        }
        m = in.nextInt();
        b = new int[m];
        for (int i = 0; i < m; i++) {
            b[i] = in.nextInt();
            set.add(b[i]);
        }

        int idx = 0;
        int reverseMap[] = new int[set.size()];
        for(int i : set) {
            reverseMap[idx] = i;
            map.put(i, idx++);
        }

        next = new TreeSet[idx];
        for (int i = 0; i < idx; i++) {
            next[i] = new TreeSet<>();
        }

        for (int i = 0; i < n; i++) {
            a[i] = map.get(a[i]);
            next[a[i]].add(i);
        }
        for (int i = 0; i < m; i++) {
            b[i] = map.get(b[i]);
        }

        dp = new int[n][m];
        for(int d[] : dp) Arrays.fill(d, -1);

        int res = solve(0, 0);
        int ans[] = new int[res];
        getSolution(0, 0, ans, 0);

        pw.println(res);
        for(int i : ans) pw.print(reverseMap[i]+" ");
        pw.println();

        pw.close();
    }

    static int n, a[], m, b[], dp[][];
    static TreeSet<Integer>[] next;

    static int solve(int i, int j) {
        if(i >= n || j >= m) return 0;
        if(dp[i][j] != -1) return dp[i][j];
        Integer nxt = next[b[j]].ceiling(i);
        int max = 0;
        if(nxt != null && (i == 0 || a[i-1] < b[j])) max = max(max, 1 + solve(nxt+1, j+1));
        max = max(max, solve(i, j+1));
        return dp[i][j] = max;
    }

    static void getSolution(int i, int j, int ans[], int pos) {
        if(i >= n || j >= m) return;
        Integer nxt = next[b[j]].ceiling(i);
        int p = 0, q = 0;
        if(nxt != null && (i == 0 || a[i-1] < b[j])) p =  1 + solve(nxt+1, j+1);
        q =  solve(i, j+1);
        if(p >= q && p > 0) {
            ans[pos++] = b[j];
            getSolution(nxt+1, j+1, ans, pos);
        } else if(q > 0) {
            getSolution(i, j+1, ans, pos);
        }
    }

    static void debug(Object...obj) {
        System.err.println(Arrays.deepToString(obj));
    }

    static class FastReader {
        InputStream is;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0, ptrbuf = 0;

        public FastReader(InputStream is) {
            this.is = is;
        }

        public int readByte() {
            if (lenbuf == -1) throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0) return -1;
            }
            return inbuf[ptrbuf++];
        }

        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }
        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }

        public String next() {
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while (!(isSpaceChar(b))) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }



        public String nextLine() {
            int c = skip();
            StringBuilder sb = new StringBuilder();
            while (!isEndOfLine(c)){
                sb.appendCodePoint(c);
                c = readByte();
            }
            return sb.toString();
        }

        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        public long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public char[] next(int n) {
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }

        public char readChar() {
            return (char) skip();
        }
    }
}