#include <bits/stdc++.h>
using namespace std;
int a[505], b[505];
int dp[505][505];
int pre[505][505];
int main() {
  int len1, len2;
  scanf("%d", &len1);
  for (int i = 1; i <= len1; ++i) scanf("%d", &a[i]);
  scanf("%d", &len2);
  for (int i = 1; i <= len2; ++i) scanf("%d", &b[i]);
  memset(dp, 0, sizeof(dp));
  memset(pre, -1, sizeof(pre));
  for (int i = 1; i <= len1; ++i) {
    int Max = 0, k = 0;
    for (int j = 1; j <= len2; ++j) {
      dp[i][j] = dp[i - 1][j];
      if (a[i] > b[j] && Max < dp[i - 1][j]) Max = dp[i - 1][j], k = j;
      if (a[i] == b[j]) dp[i][j] = Max + 1, pre[i][j] = k;
    }
  }
  int k = 1;
  for (int i = 1; i <= len2; ++i) {
    if (dp[len1][i] > dp[len1][k]) k = i;
  }
  printf("%d\n", dp[len1][k]);
  if (dp[len1][k] == 0) return 0;
  vector<int> r;
  for (int i = len1; i >= 1; --i) {
    if (pre[i][k] != -1) {
      r.push_back(a[i]);
      k = pre[i][k];
    }
  }
  printf("%d", r.back());
  for (int i = r.size() - 2; i >= 0; --i) printf(" %d", r[i]);
  printf("\n");
}
