#include <bits/stdc++.h>
using namespace std;
int dp[510], a[510], b[510], f[510];
int main() {
  int n, m;
  while (~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]);
    memset(dp, 0, sizeof(dp));
    memset(f, 0, sizeof(f));
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      int k = 0;
      for (int j = 1; j <= m; j++) {
        if (a[i] > b[j] && dp[k] < dp[j]) {
          k = j;
        } else if (a[i] == b[j]) {
          dp[j] = dp[k] + 1;
          f[j] = k;
        }
      }
    }
    int flag = 0;
    for (int i = 1; i <= m; i++) {
      if (dp[i] > ans) ans = dp[i], flag = i;
    }
    printf("%d\n", ans);
    int c[510], cnt = 0;
    while (flag != 0) {
      c[cnt++] = flag;
      flag = f[flag];
    }
    for (int i = cnt - 1; i >= 0; i--) printf("%d ", b[c[i]]);
    printf("\n");
  }
  return 0;
}
