#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, m, b;
  scanf("%d", &n);
  vector<int> first;
  vector<int> second;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    first.push_back(a);
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d", &b);
    second.push_back(b);
  }
  vector<int> table(m, 0);
  vector<int> parent(m, 0);
  for (int i = 0; i < n; i++) {
    int current = 0;
    int last = -1;
    for (int j = 0; j < m; j++) {
      if (first[i] == second[j] && current + 1 > table[j]) {
        table[j] = current + 1;
        parent[j] = last;
      }
      if (first[i] > second[j] && table[j] > current) {
        current = table[j];
        last = j;
      }
    }
  }
  int maximum = 0;
  int index = -1;
  for (int i = 0; i < m; i++) {
    if (table[i] > maximum) {
      maximum = table[i];
      index = i;
    }
  }
  vector<int> result;
  while (index != -1) {
    result.push_back(second[index]);
    index = parent[index];
  }
  reverse(result.begin(), result.end());
  if (maximum == 0)
    printf("0\n");
  else {
    printf("%d\n", maximum);
    for (int i = 0; i < result.size(); i++) {
      printf("%d ", result[i]);
    }
    printf("\n");
  }
  return 0;
}
