#include <bits/stdc++.h>
using namespace std;
pair<int, int> save[505];
vector<int> ans;
int in1[505], in2[505];
int main() {
  int i, n, m, j, k, mx, p;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &in1[i]);
  scanf("%d", &m);
  for (i = 1; i <= m; i++) scanf("%d", &in2[i]);
  for (i = 1; i <= m; i++) {
    mx = 0, p = 1000;
    for (j = 1; j <= n; j++) {
      if (in2[i] == in1[j]) {
        if (1 > mx) {
          mx = 1, p = j;
        }
        for (k = i - 1; k >= 1; k--) {
          if (in2[i] > in2[k]) {
            if (save[k].second < j && 1 + save[k].first > mx) {
              mx = save[k].first + 1;
              p = j;
            }
          }
        }
      }
    }
    save[i].first = mx, save[i].second = p;
  }
  int mm = 0, id;
  for (i = 1; i <= m; i++) {
    if (save[i].first > mm) {
      mm = save[i].first;
      id = i;
    }
  }
  if (mm == 0) {
    printf("0\n");
    return 0;
  }
  int ck = 1;
  ans.push_back(in2[id]);
  while (ck) {
    ck = 0;
    for (k = id - 1; k >= 1; k--) {
      if (in2[id] > in2[k]) {
        if (save[k].second < save[id].second &&
            1 + save[k].first == save[id].first) {
          id = k;
          ans.push_back(in2[id]);
          ck = 1;
          break;
        }
      }
    }
  }
  reverse(ans.begin(), ans.end());
  printf("%d\n", ans.size());
  for (i = 0; i < ans.size(); i++) printf("%d ", ans[i]);
}
