#include <bits/stdc++.h>
using namespace std;
namespace Solve {
const int MAXN = 505;
int N, M, A[MAXN], B[MAXN];
int F[MAXN][MAXN], G[MAXN][MAXN][2];
void Dp() {
  memset(G, 0, sizeof(G));
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      if (A[i] != B[j]) continue;
      for (int u = 1; u < i; u++) {
        for (int v = 1; v < j; v++) {
          if (A[u] < A[i]) {
            if (F[u][v] > F[i][j]) {
              F[i][j] = F[u][v];
              G[i][j][0] = u;
              G[i][j][1] = v;
            }
          }
        }
      }
      F[i][j]++;
    }
  }
  return;
}
int stk[MAXN], top = 0;
void work() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%d", &A[i]);
  scanf("%d", &M);
  for (int i = 1; i <= M; i++) scanf("%d", &B[i]);
  memset(F, 0, sizeof(F));
  Dp();
  int ans = 0, mi = 0, mj = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      if (F[i][j] > ans) {
        ans = F[i][j];
        mi = i, mj = j;
      }
    }
  }
  printf("%d\n", ans);
  while (mi >= 1 && mj >= 1) {
    stk[++top] = A[mi];
    int nxti = G[mi][mj][0], nxtj = G[mi][mj][1];
    mi = nxti, mj = nxtj;
  }
  while (top) printf("%d ", stk[top--]);
  printf("\n");
  return;
}
}  // namespace Solve
int main() {
  Solve::work();
  return 0;
}
