#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500;
int lenA, lenB, ans;
int A[MAXN + 5], B[MAXN + 5], dp[MAXN + 5], pre[MAXN + 5];
void Print(int x) {
  if (!x) return;
  Print(pre[x]);
  if (pre[x]) printf(" ");
  printf("%d", B[x]);
}
int main() {
  scanf("%d", &lenA);
  for (int i = 1; i <= lenA; i++) scanf("%d", &A[i]);
  scanf("%d", &lenB);
  for (int i = 1; i <= lenB; i++) scanf("%d", &B[i]);
  int beg = 0;
  for (int i = 1; i <= lenA; i++) {
    int pos = 0;
    for (int j = 1; j <= lenB; j++) {
      if (A[i] == B[j]) dp[j] = dp[pos] + 1, pre[j] = pos;
      if (A[i] > B[j] && dp[j] > dp[pos]) pos = j;
    }
  }
  for (int i = 1; i <= lenB; i++)
    if (dp[i] > ans) ans = dp[i], beg = i;
  printf("%d\n", ans);
  Print(beg);
  printf("\n");
  return 0;
}
