#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int a[501], b[501];
  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);
  a[0] = b[0] = 0;
  int dp[501][501], pre[501][501];
  memset(dp, 0, sizeof(dp));
  memset(pre, 0, sizeof(pre));
  for (int i = 1; i <= n; i++) {
    int k = 0;
    for (int j = 1; j <= m; j++) {
      if (a[i] != b[j]) dp[i][j] = dp[i - 1][j];
      if (a[i] > b[j] && dp[i][j] > dp[i][k]) k = j;
      if (a[i] == b[j]) {
        dp[i][j] = dp[i][k] + 1;
        pre[i][j] = k;
      }
    }
  }
  int ans = -1, x = n, y = 0;
  for (int i = 0; i <= m; i++) {
    if (dp[n][i] > ans) {
      ans = dp[n][i];
      y = i;
    }
  }
  vector<int> path;
  while (dp[x][y]) {
    if (a[x] != b[y])
      x--;
    else {
      path.push_back(b[y]);
      y = pre[x][y];
    }
  }
  printf("%d\n", ans);
  for (int i = path.size() - 1; i >= 0; i--) {
    printf("%d ", path[i]);
  }
  return 0;
}
