#include <bits/stdc++.h>
using namespace std;
const int MAXN = int(5e2 + 5);
int l1, l2;
int f[MAXN][MAXN];
int a[MAXN], b[MAXN];
void Print(int x, int y) {
  if (f[x][y] == 1) {
    printf("%d ", b[y]);
    return;
  }
  if (x == 0 || y == 0) return;
  if (f[x][y] == f[x - 1][y]) {
    Print(x - 1, y);
    return;
  }
  for (int i = y - 1; i >= 1; i--)
    if (b[i] < b[y] && f[x][y] == f[x - 1][i] + 1) {
      Print(x, i);
      printf("%d ", b[y]);
      return;
    }
}
int main() {
  int ans = 0, a1, b1;
  scanf("%d", &l1);
  for (int i = 1; i <= l1; i++) scanf("%d", &a[i]);
  scanf("%d", &l2);
  for (int i = 1; i <= l2; i++) scanf("%d", &b[i]);
  for (int i = 1; i <= l1; i++)
    for (int j = 1; j <= l2; j++) {
      if (a[i] != b[j])
        f[i][j] = f[i - 1][j];
      else {
        int Max = 0;
        for (int k = 1; k < j; k++)
          if (b[k] < b[j]) Max = max(Max, f[i - 1][k]);
        f[i][j] = Max + 1;
        if (ans < f[i][j]) ans = f[i][j], a1 = i, b1 = j;
      }
    }
  printf("%d\n", ans);
  if (ans) Print(a1, b1);
}
