#include <bits/stdc++.h>
using namespace std;
const int maxN = 500;
int a[maxN];
int b[maxN];
int c[maxN];
int dp[maxN];
stack<int> s;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int m;
  cin >> m;
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
  }
  for (int i = 1; i <= n; i++) {
    int B = 0;
    int id = 0;
    for (int j = 1; j <= m; j++) {
      if (a[i] == b[j]) {
        dp[j] = B + 1;
        c[j] = id;
      } else if (a[i] > b[j] && dp[j] > B) {
        B = dp[j];
        id = j;
      }
    }
  }
  int MAX = 0;
  int id = 0;
  for (int i = 1; i <= m; i++) {
    if (dp[i] > MAX) {
      MAX = dp[i];
      id = i;
    }
  }
  cout << MAX << endl;
  while (id > 0) {
    s.push(b[id]);
    id = c[id];
  }
  while (!s.empty()) {
    cout << s.top() << " ";
    s.pop();
  }
  return 0;
}
