#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[(500 + 5)], b[(500 + 5)];
int dp[(500 + 5)];
int p[(500 + 5)];
int ans;
void LCIS(int x) {
  if (p[x]) LCIS(p[x]);
  cout << b[x] << " ";
  return;
}
int main() {
  cin >> n;
  for (register int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  cin >> m;
  for (register int i = 1; i <= m; ++i) {
    cin >> b[i];
  }
  int pos = 0, tmp;
  for (register int i = 1; i <= n; ++i) {
    tmp = 0;
    for (register int j = 1; j <= m; ++j) {
      if (a[i] > b[j] && dp[j] > dp[tmp]) tmp = j;
      if (a[i] == b[j]) {
        dp[j] = dp[tmp] + 1;
        p[j] = tmp;
      }
    }
  }
  for (register int i = 1; i <= m; ++i) {
    if (dp[i] > dp[pos]) pos = i;
  }
  cout << dp[pos] << "\n";
  if (dp[pos]) LCIS(pos);
  return 0;
}
