#include <bits/stdc++.h>
using namespace std;
const int maxn = 500 + 1;
int dp[maxn], a[maxn], b[maxn], m, n, sag[maxn];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  cin >> m;
  for (int i = 0; i < m; i++) cin >> b[i];
  fill(dp, dp + maxn, 0);
  fill(sag, sag + maxn, -1);
  for (int i = 0; i < n; i++) {
    int al = 0;
    int sagi = -1;
    for (int j = 0; j < m; j++) {
      if (a[i] == b[j])
        if (dp[j] < al + 1) {
          dp[j] = al + 1;
          sag[j] = sagi;
        }
      if (a[i] > b[j])
        if (dp[j] > al) {
          al = dp[j];
          sagi = j;
        }
    }
  }
  int lcis = 0, indx = 0;
  for (int i = 0; i < m; i++)
    if (dp[i] > lcis) {
      lcis = dp[i];
      indx = i;
    }
  cout << lcis << endl;
  if (lcis == 0) return 0;
  stack<int> ans;
  while (indx != -1) {
    ans.push(b[indx]);
    indx = sag[indx];
  }
  while (!ans.empty()) {
    cout << ans.top() << " ";
    ans.pop();
  }
  return 0;
}
