#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
int a[maxn], b[maxn], n, m;
int f[maxn][maxn], z[maxn][maxn];
void print(int p) {
  if (!p) return;
  print(z[n][p]);
  printf("%d ", b[p]);
}
int main() {
  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]);
  }
  for (int i = 1; i <= n; i++) {
    int pos = 0;
    for (int j = 1; j <= m; j++) {
      if (a[i] == b[j]) {
        f[i][j] = f[i - 1][pos] + 1;
        z[i][j] = pos;
      } else {
        f[i][j] = f[i - 1][j];
        z[i][j] = z[i - 1][j];
      }
      if (b[j] < a[i] && f[i - 1][j] > f[i - 1][pos]) {
        pos = j;
      }
    }
  }
  int pos = 0;
  for (register int i = 1; i <= m; i++) {
    if (f[n][i] > f[n][pos]) pos = i;
  }
  printf("%d\n", f[n][pos]);
  print(pos);
  return 0;
}
