#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
int a[maxn], b[maxn], dp[maxn], pl[maxn], n, m;
void print(int x) {
  if (!x) return;
  print(pl[x]);
  printf("%d ", b[x]);
}
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 pos = 0;
    for (int j = 1; j <= m; j++) {
      if (a[i] == b[j]) {
        dp[j] = dp[pos] + 1;
        pl[j] = pos;
      } else if (a[i] > b[j] && dp[pos] < dp[j])
        pos = j;
    }
  }
  int fin = 0;
  for (int i = 1; i <= m; i++)
    if (dp[i] > dp[fin]) fin = i;
  printf("%d\n", dp[fin]);
  print(fin);
  return 0;
}
