#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a[505], b[505], dp[505], pre[505][505];
  memset(dp, 0, sizeof(dp));
  cin >> n;
  int i, j, ans = 0, x, y;
  for (i = 1; i <= n; i++) scanf("%d", a + i);
  cin >> m;
  for (i = 1; i <= m; i++) scanf("%d", b + i);
  for (i = 1; i <= n; i++) {
    int mark = 0;
    int last;
    for (j = 1; j <= m; j++) {
      if (a[i] > b[j] && mark < dp[j]) {
        mark = dp[j];
        last = j;
      }
      if (a[i] == b[j]) {
        dp[j] = mark + 1;
        pre[i][j] = last;
      }
      if (dp[j] > ans) {
        ans = dp[j];
        x = i;
        y = j;
      }
    }
  }
  int res[505];
  for (i = 1; i <= ans; i++) {
    res[i] = b[y];
    y = pre[x][y];
    while (a[x] != b[y]) x--;
  }
  cout << ans << endl;
  for (i = ans; i >= 1; i--) {
    printf("%d ", res[i]);
  }
  return 0;
}
