#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  long long n, m, p = 0;
  cin >> n;
  vector<long long> a(n + 1), b;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  cin >> m;
  b.resize(m + 1);
  for (long long i = 1; i <= m; i++) cin >> b[i];
  vector<vector<long long> > d(n, vector<long long>(m, 0));
  vector<long long> ans, dp(1e5, 0), par(1e5);
  for (long long i = 1, k = 0; i <= n; i++, k = 0) {
    for (long long j = 1; j <= m; j++) {
      if (a[i] == b[j]) {
        dp[j] = dp[k] + 1;
        par[j] = k;
      }
      if (a[i] > b[j] && dp[k] < dp[j]) {
        k = j;
      }
    }
  }
  for (long long i = 1; i <= m; i++) {
    if (dp[i] > dp[p]) p = i;
  }
  cout << dp[p] << endl;
  vector<long long> q;
  while (true) {
    if (!p) {
      break;
    }
    q.push_back(b[p]);
    p = par[p];
  }
  reverse((q).begin(), (q).end());
  for (long long i : q) cout << i << ' ';
}
