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 
//"Pure violence will become the only basis of power" - :)
import java.util.*;
import java.io.*;

public class Solution {
	public static PrintWriter w = new PrintWriter(System.out);
	public static void main(String args[] ) throws Exception {
		Reader in = new Reader();
		int t = 1;//in.nextInt();
		while(t-- > 0) {
			int n = in.nextInt();
			int[] arr1 = new int[n+1];
			for (int i=1; i<=n; i++)
				arr1[i] = in.nextInt();
			int m = in.nextInt();
			int[] arr2 = new int[m+1];
			for (int i=1; i<=m; i++)
				arr2[i] = in.nextInt();
			int[][][] dp = new int[n+1][m+1][2];
			for (int i=1; i<=n; i++) {
				int curr = 0, pre = -1;
				for (int j=1; j<=m; j++) {
					dp[i][j][0] = dp[i-1][j][0];
					dp[i][j][1] = dp[i-1][j][1];
					if(arr1[i] == arr2[j]) {
						dp[i][j][0] = curr + 1;
						dp[i][j][1] = pre;
					}
					if(arr1[i] > arr2[j]) {
						if(dp[i-1][j][0] > curr) {
							curr = dp[i][j][0];
							pre = j;
						}
					}
				}
			}
			int x=n,y=1,ans = dp[x][y][0];
			for (int i=2; i<=m; i++) {
				if(dp[n][i][0] > ans) {
					ans = dp[n][i][0];
					x = n;
					y = i;
				}
			}
			w.println(ans);
			ArrayList<Integer> list = new ArrayList<>();
			// for (int[][] i : dp) {
			// 	for (int[] j : i) {
			// 		w.print("( " + j[0] + "," + j[1] + ")");
			// 	}
			// 	w.println();
			// }
			//w.println(x + " " + y);
			while(x >=0 && y >=0 && dp[x][y][0] != 0) {
				if(arr1[x] == arr2[y]) {
					list.add(arr1[x]);
					y = dp[x][y][1];
					x--;
				} else
					x--;
				// w.println(x + " " + y);
				// w.flush();
			}
			for (int i=list.size()-1; i>=0; i--)
				w.print(list.get(i) + " ");
			w.println();
		}
		w.flush();	
		return;
	}
}

class Reader {
	final private int BUFFER_SIZE = 1 << 16;
	private DataInputStream din;
	private byte[] buffer;
	private int bufferPointer, bytesRead;

	public Reader() {
		din = new DataInputStream(System.in);
		buffer = new byte[BUFFER_SIZE];
		bufferPointer = bytesRead = 0;
	}
	public String nextLine() throws IOException {
		int c = read();
		while(isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while(!isEndOfLine(c));
		return res.toString();
	}
	public String next() throws IOException {
		int c = read();
		while(isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while(!isSpaceChar(c));
		return res.toString();
	}
	public int nextInt() throws IOException {
		int ret = 0;
		byte c = read();
		while(c <= ' ')
			c = read();
		boolean neg = (c == '-');
		if(neg)
			c = read();
		do {
			ret = ret * 10 + c - '0';
		} while((c = read()) >= '0' && c <= '9');
		if (neg)
			return -ret;
		return ret;
	}
	public int[] nextIntArray(int n) throws IOException {
		int a[] = new int[n];
		for(int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}
	public int[][] next2dIntArray(int n, int m) throws IOException {
		int a[][] = new int[n][m];
		for(int i = 0; i < n; i++)
			for(int j = 0; j < m; j++)
				a[i][j] = nextInt();
		return a;
	}
	public char nextChar() throws IOException {
		return next().charAt(0);
	}
	public long nextLong() throws IOException {
		long ret = 0;
		byte c = read();
		while(c <= ' ')
			c = read();
		boolean neg = (c == '-');
		if(neg)
			c = read();
		do {
			ret = ret * 10 + c - '0';
		} while((c = read()) >= '0' && c <= '9');
		if (neg)
			return -ret;
		return ret;
	}
	public double nextDouble() throws IOException {
		double ret = 0, div = 1;
		byte c = read();
		while(c <= ' ')
			c = read();
		boolean neg = (c == '-');
		if(neg)
			c = read();
		do {
			ret = ret * 10 + c - '0';
		} while((c = read()) >= '0' && c <= '9');
		if (c == '.') {
			while((c = read()) >= '0' && c <= '9') {
				ret += (c - '0') / (div *= 10);
			}
		}
		if(neg)
			return -ret;
		return ret;
	}
	private void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
		if(bytesRead == -1)
			buffer[0] = -1;
	}
	private byte read() throws IOException {
		if(bufferPointer == bytesRead)
			fillBuffer();
		return buffer[bufferPointer++];
	}
	public void close() throws IOException {
		if(din == null)
			return;
		din.close();
	}
	public boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}
	private boolean isEndOfLine(int c) {
		return c == '\n' || c == '\r' || c == -1;
	}
}	