#include <bits/stdc++.h>
using namespace std;
const int o = 501;
int n, a[o], b[o], f[o][o], p[o][o], c[o], q, w, m, ans;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  a[0] = b[0] = -1e9;
  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++) {
    for (int j = 1; j <= m; j++)
      if (a[i] == b[j]) {
        for (int k = 0; k < j; k++)
          if (b[k] < a[i] && f[i][j] < f[i - 1][k] + 1)
            f[i][j] = f[i - 1][k] + 1, p[i][j] = k;
      } else
        f[i][j] = f[i - 1][j], p[i][j] = p[i - 1][j];
    if (i == n) {
      for (int j = 1; j <= m; j++)
        if (f[i][j] > ans) ans = f[n][j], q = j;
    }
  }
  while (q) c[++w] = b[q], q = p[n][q];
  cout << ans << "\n";
  for (int i = w; i >= 1; i--) cout << c[i] << " ";
  return 0;
}
