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 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class LCIS {

	static int extend=1;
	static pair[][]dp;
	static int []a,b;
/*public static int search(int x,ArrayList<Integer> a,int []b)
{
	int ans=-1;
	int lo=0;
	int hi=a.size()-1;
	while(lo<=hi)
	{
		int mid=(lo+hi)/2;
		if(b[a.get(mid)]<x)
			lo=mid+1;
		else
		{
			ans=mid;
			hi=mid-1;
		}
	}
	return ans;
}
public static void print(int []a,int idx)
{
	if(p[idx]!=-1)
		print(a,p[idx]);
	System.out.print(a[idx]+" ");
	
}*/
	public static void print(int i,int j)
	{
		if(i==0 && j==0)
		{
			if(a[0]==b[j])
				System.out.print(a[0]+" ");
			return;
		}
		if(i==0)
		{
			if(a[i]==b[j])
			{
				System.out.print(a[0]+" ");
				return;
			}
			else
			{	
				print(i,j-1);
				return;
			}	
		}
		if(j==0)
		{
			if(a[i]==b[j])
			{
				System.out.print(b[0]+" ");
				return;
			}
			else
			{	
				print(i-1,j);
				return;
			}	
		}
		
		if(a[i]==b[j])
		{
			int last=dp[i-1][j-1].last;
			if(a[i]>last)
			{	
				print(i-1,j-1);
				System.out.print(a[i]+" ");
				
				
			}	
			else
			{
				if(dp[i-1][j-1].len==1)
				{
					System.out.print(a[i]+" ");
				}
				else
				{	
					print(i-1,j-1);
				}	
			}
		}
		else
		{
			int len1=dp[i-1][j].len;
			int len2=dp[i][j-1].len;
			if(len1>len2)
				print(i-1,j);
			else if(len2>len1)
				print(i,j-1);
			else
			{
				int last1=dp[i-1][j].last;
				int last2=dp[i][j-1].last;
				if(last1<last2)
					print(i-1,j);
				else 
					print(i,j-1);
			}
		}
			
	}
	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		a=new int [n];
		for(int i=0;i<n;i++)
			a[i]=sc.nextInt();
		
		int n2=sc.nextInt();
		b=new int [n2];
		
		for(int i=0;i<n2;i++)
		{	
			b[i]=sc.nextInt();
			
		}	
		dp=new pair[n][n2];
		if(a[0]==b[0])
			dp[0][0]=new pair(1,a[0]);
		else
			dp[0][0]=new pair(0,-1);
		for(int i=1;i<n2;i++)
		{
			if(b[i]==a[0])
			{
				dp[0][i]=new pair(1,a[0]);
			}
			else
				dp[0][i]=dp[0][i-1];
		}
		for(int i=1;i<n;i++)
		{
			if(a[i]==b[0])
			{
				dp[i][0]=new pair(1,b[0]);
			}
			else
				dp[i][0]=dp[i-1][0];
		}
		int [][]print=new int [n][n2];
		for(int i=1;i<n;i++)
			for(int j=1;j<n2;j++)
			{
				if(a[i]==b[j])
				{
					int last=dp[i-1][j-1].last;
					if(a[i]>last)
					{	
						dp[i][j]=new pair(dp[i-1][j-1].len+1,a[i]);
						
					}	
					else
					{
						if(dp[i-1][j-1].len==1)
						{
							dp[i][j]=new pair(1,a[i]);
						}
						else
							dp[i][j]=dp[i-1][j-1];
					}
				}
				else
				{
					int len1=dp[i-1][j].len;
					int len2=dp[i][j-1].len;
					if(len1>len2)
						dp[i][j]=dp[i-1][j];
					else if(len2>len1)
						dp[i][j]=dp[i][j-1];
					else
					{
						int last1=dp[i-1][j].last;
						int last2=dp[i][j-1].last;
						if(last1<last2)
							dp[i][j]=dp[i-1][j];
						else 
							dp[i][j]=dp[i][j-1];
					}
				}
			}
		
		System.out.println(dp[n-1][n2-1].len);
		if(dp[n-1][n2-1].len>0)
			print(n-1,n2-1);
		

	}
	static class pair
	{
		int len,last;
		pair(int a,int b)
		{
			len=a;last=b;
		}
		
	}
	static class Scanner 
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException 
		{
			while (st == null || !st.hasMoreTokens()) 
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}
		
		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}
		
		public double nextDouble() throws IOException
		{
			return Double.parseDouble(next());
		}
		
		public boolean ready() throws IOException {return br.ready();}


	}
}
