#include <bits/stdc++.h>
using namespace std;
int a[510], n, b[510], m, pre[510], ans[510], ma, cn[510], cnt;
int f[510][510];
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 val = 0, p = 0;
    for (int j = 1; j <= m; j++) {
      if (a[i] == b[j])
        f[i][j] = val + 1, pre[j] = p;
      else
        f[i][j] = f[i - 1][j];
      if (b[j] < a[i] && f[i - 1][j] > val) val = f[i - 1][j], p = j;
    }
  }
  int ans = 0, j = 0;
  for (int i = 1; i <= m; i++)
    if (f[n][i] > ans) ans = f[n][i], j = i;
  printf("%d\n", ans);
  while (j) {
    cnt++;
    cn[cnt] = b[j];
    j = pre[j];
  }
  for (int jj = cnt; jj; jj--) printf("%d ", cn[jj]);
  return 0;
}
