#include <bits/stdc++.h>
using namespace std;
const int maxn = 601;
int x[maxn], t[maxn], y[maxn], f[maxn][maxn], m, n, ans;
struct node {
  int len;
  int s[maxn];
} a[maxn], now;
void input() {
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) scanf("%d", &x[i]);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &y[i]);
}
void dp() {
  for (int i = 1; i <= m; i++) {
    now.len = 0;
    memset(now.s, 0, sizeof(now.s));
    for (int j = 1; j <= n; j++) {
      if (x[i] > y[j] && a[j].len > now.len) {
        now = a[j];
      }
      if (x[i] == y[j]) {
        a[j] = now;
        a[j].len++;
        a[j].s[a[j].len] = y[j];
      }
    }
  }
}
int main() {
  input();
  dp();
  int p = 0;
  int maxx = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i].len >= maxx) {
      maxx = a[i].len;
      p = i;
    }
  }
  printf("%d\n", a[p].len);
  for (int i = 1; i <= a[p].len; i++) printf("%d ", a[p].s[i]);
  printf("\n");
  return 0;
}
