#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const double pi = acos(-1.0);
int n, m;
int a[555], b[555], dp[555], path[555];
void outpath(int pos) {
  if (pos == 0) return;
  outpath(path[pos]);
  printf("%d ", b[pos]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
  for (int i = 1; i <= n; i++) {
    int p = 0;
    for (int j = 1; j <= m; j++) {
      if (a[i] == b[j] && dp[p] + 1 > dp[i])
        dp[j] = dp[p] + 1, path[j] = p;
      else if (a[i] > b[j] && dp[p] < dp[j])
        p = j;
    }
  }
  int pos = 0;
  for (int i = 1; i <= m; i++) {
    if (dp[i] > dp[pos]) pos = i;
  }
  printf("%d\n", dp[pos]);
  outpath(pos);
  return 0;
}
