#include <bits/stdc++.h>
const int Maxn = 501;
int a[Maxn], b[Maxn], p[Maxn], maxl[Maxn], o[Maxn];
int main() {
  int n, m, i, j, k;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) scanf("%d", a + i);
  scanf("%d", &m);
  for (i = 1; i <= m; ++i) scanf("%d", b + i);
  for (i = 1; i <= n; ++i) {
    k = 0;
    for (j = 1; j <= m; ++j)
      if (a[i] == b[j] && maxl[k] + 1 > maxl[j])
        maxl[j] = maxl[k] + 1, p[j] = k;
      else if (b[j] < a[i] && maxl[j] > maxl[k])
        k = j;
  }
  k = j = 0;
  for (i = 1; i <= m; ++i)
    if (maxl[i] > maxl[j]) j = i;
  for (i = j; i; i = p[i]) o[++k] = b[i];
  printf("%d\n", k);
  while (k) printf("%d ", o[k--]);
  puts("");
}
