#include <bits/stdc++.h>
using namespace std;
const int N = 505;
int n, m, a[N], b[N], dp[N][N];
pair<int, pair<int, int> > p[N][N], ls;
void print(pair<int, pair<int, int> > pp) {
  int x = pp.first, y = pp.second.first;
  if (x != 0 && y != 0) print(p[x][y]);
  if (pp.second.second != -1) printf("%d ", pp.second.second);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
  b[0] = -1;
  for (int i = 1; i <= n; i++) {
    int maxx = 0;
    ls = make_pair(i - 1, make_pair(0, -1));
    for (int j = 1; j <= m; j++) {
      if (a[i] == b[j])
        dp[i][j] = maxx + 1, p[i][j] = ls, p[i][j].second.second = b[j];
      else
        dp[i][j] = dp[i - 1][j], p[i][j] = p[i - 1][j];
      if (a[i] > b[j])
        if (maxx < dp[i - 1][j])
          maxx = dp[i - 1][j], ls = make_pair(i - 1, make_pair(j, -1));
    }
  }
  int maxn = -0x3f3f3f3f;
  pair<int, pair<int, int> > lss;
  for (int i = 1; i <= m; i++)
    if (maxn < dp[n][i]) maxn = dp[n][i], lss = make_pair(n, make_pair(i, -1));
  printf("%d\n", maxn);
  if (maxn) print(lss);
  return 0;
}
