#include <bits/stdc++.h>
using namespace std;
int a[550], b[550];
int pre[550];
int dp[550][550];
int main() {
  int n, m;
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  cin >> m;
  for (int i = 1; i <= m; i++) scanf("%d", b + i);
  for (int i = 1; i <= n; i++) {
    int tpos = 0;
    for (int j = 1; j <= m; j++) {
      dp[i][j] = dp[i - 1][j];
      if (b[j] < a[i] && dp[i - 1][j] > dp[i - 1][tpos]) tpos = j;
      if (a[i] == b[j] && dp[i - 1][tpos] + 1 > dp[i][j]) {
        pre[j] = tpos;
        dp[i][j] = dp[i - 1][tpos] + 1;
      }
    }
  }
  int tpos = 0;
  for (int i = 1; i <= m; i++)
    if (dp[n][i] > dp[n][tpos]) tpos = i;
  int cnt = dp[n][tpos];
  cout << cnt << endl;
  vector<int> ans;
  for (; cnt; cnt--, tpos = pre[tpos]) {
    ans.push_back(b[tpos]);
  }
  while (!ans.empty()) printf("%d ", ans.back()), ans.pop_back();
  return 0;
}
