#include <bits/stdc++.h>
using namespace std;
const int MAXN = 505;
int a[MAXN], b[MAXN];
int dp[MAXN];
int n, m;
int step[MAXN];
void print(int x) {
  if (x == 0) return;
  print(step[x]);
  printf("%d ", b[x]);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  cin >> m;
  for (int i = 1; i <= m; i++) cin >> b[i];
  for (int i = 1; i <= n; i++) {
    int pos = 0;
    for (int j = 1; j <= m; j++) {
      if (a[i] == b[j]) {
        dp[j] = dp[pos] + 1;
        step[j] = pos;
      }
      if (a[i] > b[j] && dp[pos] < dp[j]) {
        pos = j;
      }
    }
  }
  int ans = 0, ans2 = 0;
  for (int i = 1; i <= m; i++) {
    if (dp[i] > ans2) {
      ans2 = dp[i];
      ans = i;
    }
  }
  cout << ans2 << endl;
  print(ans);
  return 0;
}
