#include <bits/stdc++.h>
using namespace std;
int a[510], b[510], dp[510], pre[510], res[510];
int main() {
  int n, m, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  cin >> m;
  for (int i = 1; i <= m; ++i) cin >> b[i];
  for (int i = 1; i <= n; ++i) {
    int pos = 0;
    for (int j = 1; j <= m; ++j) {
      if (a[i] == b[j]) {
        dp[j] = dp[pos] + 1;
        pre[j] = pos;
      }
      if (b[j] < a[i] && dp[pos] < dp[j]) pos = j;
    }
  }
  int pos = 0;
  for (int i = 1; i <= m; ++i) {
    if (ans < dp[i]) {
      ans = dp[i];
      pos = i;
    }
  }
  for (int i = 1; i <= ans; ++i) {
    res[i] = b[pos];
    pos = pre[pos];
  }
  printf("%d\n", ans);
  for (int i = ans; i > 0; --i) printf(i == 1 ? "%d\n" : "%d ", res[i]);
  return 0;
}
