#include <bits/stdc++.h>
const int maxn = 505;
int N;
int M;
int A[maxn];
int B[maxn];
int dp[maxn][maxn];
int Pre[maxn][maxn];
void print(int x) {
  if (!x) return;
  print(Pre[N][x]);
  printf("%d ", B[x]);
}
int main() {
  scanf("%d", &N);
  for (register int i = 1; i <= N; i++) scanf("%d", &A[i]);
  scanf("%d", &M);
  for (register int i = 1; i <= M; i++) scanf("%d", &B[i]);
  for (register int i = 1; i <= N; i++) {
    int maxx = 0, pre = 0;
    for (register int j = 1; j <= M; j++) {
      if (A[i] == B[j]) {
        if (dp[i][j] < maxx + 1) {
          dp[i][j] = maxx + 1;
          Pre[i][j] = pre;
        }
      } else {
        dp[i][j] = dp[i - 1][j];
        Pre[i][j] = Pre[i - 1][j];
      }
      if (B[j] < A[i] && maxx < dp[i - 1][j]) maxx = dp[i - 1][j], pre = j;
    }
  }
  int Ans = 0, Ans_p = 0;
  for (register int i = 1; i <= M; i++)
    if (Ans < dp[N][i]) Ans = dp[N][i], Ans_p = i;
  printf("%d\n", Ans);
  print(Ans_p);
  return 0;
}
