#include <bits/stdc++.h>
using namespace std;
long long LCIS(vector<long long> arr1, vector<long long> arr2) {
  long long n = arr1.size(), m = arr2.size();
  long long table[1000], parent[1000];
  for (long long j = 0; j < m; j++) table[j] = 0;
  for (long long i = 0; i < n; i++) {
    long long current = 0, last = -1;
    for (long long j = 0; j < m; j++) {
      if (arr1[i] == arr2[j]) {
        if (current + 1 > table[j]) {
          table[j] = current + 1;
          parent[j] = last;
        }
      }
      if (arr1[i] > arr2[j]) {
        if (table[j] > current) {
          current = table[j];
          last = j;
        }
      }
    }
  }
  long long result = 0, index = -1;
  for (long long i = 0; i < m; i++) {
    if (table[i] > result) {
      result = table[i];
      index = i;
    }
  }
  long long lcis[result];
  for (long long i = 0; index != -1; i++) {
    lcis[i] = arr2[index];
    index = parent[index];
  }
  cout << result << endl;
  for (long long i = result - 1; i >= 0; i--) printf("%lld ", lcis[i]);
  return result;
}
int main() {
  long long n, m;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> m;
  vector<long long> b(m);
  for (long long i = 0; i < m; i++) {
    cin >> b[i];
  }
  LCIS(a, b);
}
