#include <bits/stdc++.h>
using namespace std;
int n, m, mn;
int a[505], b[505];
int dp[505][505], previ[505][505], prevj[505][505];
int prec[505][505];
void solve() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) scanf("%d", &b[i]);
  mn = min(m, n);
  memset(prevj, -1, sizeof(prevj));
  memset(previ, -1, sizeof(previ));
  for (int i = 0; i < n; i++) {
    int t = -1;
    for (int j = 0; j < m; j++) {
      prec[i][j] = t;
      if (b[j] == a[i]) t = j;
    }
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (a[i] == b[j]) {
        dp[i][j] = 1;
        for (int k = 0; k < i; k++)
          if (a[k] < a[i]) {
            int s = prec[k][j];
            if (s != -1 && dp[k][s] + 1 > dp[i][j]) {
              dp[i][j] = dp[k][s] + 1;
              previ[i][j] = k;
              prevj[i][j] = s;
            }
          }
      } else {
        dp[i][j] = -1;
      }
    }
  int res = 0, ii = -1, jj = -1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (dp[i][j] > res) {
        res = dp[i][j];
        ii = i;
        jj = j;
      }
    }
  vector<int> v;
  while (ii >= 0 && jj >= 0) {
    v.push_back(a[ii]);
    int tmp = previ[ii][jj];
    jj = prevj[ii][jj];
    ii = tmp;
  }
  printf("%d\n", res);
  for (int i = (int)v.size() - 1; i >= 0; i--) printf("%d ", v[i]);
}
int main() {
  solve();
  return 0;
}
