#include <bits/stdc++.h>
using namespace std;
int n, m, a[555], b[555], dp[555], pre[555];
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(pre, pre + m, -1);
  for (int i = 0; i < n; i++) {
    int l = 0, from = -1;
    for (int j = 0; j < m; j++) {
      if (b[j] == a[i] && l + 1 > dp[j]) {
        dp[j] = l + 1;
        pre[j] = from;
      }
      if (b[j] < a[i] && dp[j] > l) {
        l = dp[j];
        from = j;
      }
    }
  }
  int ans = -1, last = -1;
  for (int i = 0; i < m; i++)
    if (dp[i] > ans) ans = dp[i], last = i;
  cout << ans << endl;
  if (ans == 0) return 0;
  vector<int> v;
  while (last != -1) {
    v.push_back(b[last]);
    last = pre[last];
  }
  reverse(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
}
