#include <bits/stdc++.h>
using namespace std;
int a[600], b[600];
int f[600][600];
struct node {
  int p, q;
};
node pre[600][600];
void pt(int x, int y) {
  if (pre[x][y].p != x || pre[x][y].q != y) {
    pt(pre[x][y].p, pre[x][y].q);
  }
  printf("%d ", a[x]);
}
int main() {
  int n, m;
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  cin >> m;
  for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
  int ans = 0;
  int c, d;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (a[i] != b[j]) continue;
      f[i][j] = 1;
      pre[i][j] = node{i, j};
      if (f[i][j] > ans) {
        ans = f[i][j];
        c = i;
        d = j;
      }
      for (int p = 1; p < i; p++) {
        if (a[i] <= a[p]) continue;
        for (int q = 1; q < j; q++) {
          if (b[j] <= b[q]) continue;
          if (a[p] != b[q]) continue;
          if (f[i][j] < f[p][q] + 1) {
            f[i][j] = f[p][q] + 1;
            pre[i][j] = node{p, q};
          }
          if (f[i][j] > ans) {
            ans = f[i][j];
            c = i;
            d = j;
          }
        }
      }
    }
  printf("%d\n", ans);
  if (ans) pt(c, d);
  return 0;
}
