#include <bits/stdc++.h>
using namespace std;
int Set(int n, int pos) { return n = n | (1 << pos); }
int reset(int n, int pos) { return n = n & ~(1 << pos); }
bool check(int n, int pos) { return (bool)(n & (1 << pos)); }
int ara[505], ara2[505];
int dp[505], parent[505], n, m;
void LCIS() {
  for (int i = 0; i < n; i++) {
    int curr = 0, last = -1;
    for (int j = 0; j < m; j++) {
      if (ara[i] == ara2[j] && curr + 1 > dp[j]) {
        dp[j] = curr + 1;
        parent[j] = last;
      } else if (ara[i] > ara2[j] && dp[j] > curr) {
        curr = dp[j];
        last = j;
      }
    }
  }
  int ans = 0, idx = -1;
  for (int i = 0; i < m; i++) {
    if (ans < dp[i]) {
      ans = dp[i];
      idx = i;
    }
  }
  printf("%d\n", ans);
  vector<int> v;
  while (idx != -1) {
    v.push_back(ara2[idx]);
    idx = parent[idx];
  }
  for (int i = ans - 1; i >= 0; i--) {
    printf("%d", v[i]);
    if (i > 0) printf(" ");
  }
  printf("\n");
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &ara[i]);
  scanf("%d", &m);
  for (int j = 0; j < m; j++) scanf("%d", &ara2[j]);
  memset(dp, 0, sizeof(dp));
  memset(parent, 0, sizeof(parent));
  LCIS();
  return 0;
}
