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 
def get_lcis_length(X, Y):
    len_Y = len(Y)
    
    # maintain current lcis length
    # curr_lcis_len: len lcis(X, Y[0..i])
    
    curr_lcis_len = [0] * len_Y
    for u in X:
        lcis_prefix_max = []
        curr_max = 0
        
        # copy current lcis length table and create prefix max from it
        # to make access in next step be O(1)
        for i, v in enumerate(Y):
            if v < u:
                curr_max = max(curr_max, curr_lcis_len[i])
            lcis_prefix_max.append(curr_max)
        
        # loop through all elements in Y
        # update current lcis length if the element matches with current element in X
        for i, v in enumerate(Y):
            if u == v:
                curr_lcis_len[i] = max(curr_lcis_len[i], (0 if i == 0 else lcis_prefix_max[i - 1]) + 1)
    
    # find maximum lcis length
    max_lcis_length = curr_lcis_len[0]
    for i, u in enumerate(curr_lcis_len):
        max_lcis_length = max(max_lcis_length, u)
        
    # Backtrack to get the LCIS
    # Redo all previous step, but break when we found lcis that has the same length
    # with max_lcis_length
    # Need to break the loop to stop backtracking table (bt) being updated
    
    # No need to backtrack if there is no LCIS
    if max_lcis_length == 0:
        print(0)
        return max_lcis_length
    
    curr_lcis_len = [0] * len_Y
    bt = [-1] * len_Y # backtracking table
    
    for u in X:
        lcis_prefix_max = []
        bt_id = []
        curr_max = 0
        curr_id_max = -1;
        
        # copy current lcis length table and create prefix max from it
        # to make access in next step be O(1)
        # but, we also keep where should we backtrack if we use the lcis_pref_max
        for i, v in enumerate(Y):
            if v < u:
                if curr_max < curr_lcis_len[i]:
                    curr_max = curr_lcis_len[i]
                    curr_id_max = i
            lcis_prefix_max.append(curr_max)
            bt_id.append(curr_id_max)
        
        # loop through all elements in Y
        # update current lcis length if the element matches with current element in X
        for i, v in enumerate(Y):
            if u == v:
                if curr_lcis_len[i] < (0 if i == 0 else lcis_prefix_max[i - 1]) + 1:
                    curr_lcis_len[i] = (0 if i == 0 else lcis_prefix_max[i - 1]) + 1
                    bt[i] = (-1 if i == 0 else bt_id[i - 1]) # also update where should we backtrack if using this index
                    
                    # if this is one of the lcis, use the backtrack table to track the values
                    if curr_lcis_len[i] == max_lcis_length:
                        lcis_list = []
                        now = i
                        while now != -1:
                            lcis_list.append(Y[now]);
                            now = bt[now]
                        lcis_list.reverse()
                        
                        print(max_lcis_length)
                        for i, u in enumerate(lcis_list):
                            print(u, end=('\n' if i == max_lcis_length - 1 else ' '))
                        return max_lcis_length, lcis_list
    return max_lcis_length

x = []
try:
    while True:
        y = input()
        x.append(y)
except EOFError:
    pass

x = ' '.join(x)
x = x.split()
x = [int(i) for i in x]

X = []
Y = []
num_x = x[0]
for i in range(1, num_x + 1):
    X.append(x[i])
for i in range(x[num_x + 1]):
    Y.append(x[num_x + 2 + i])
    
get_lcis_length(X, Y)
  				    			 	 		  			  	 	 		