#include <bits/stdc++.h>
using namespace std;
int a[501], b[501], n, m, le[501][501], maxx = 0;
pair<int, int> record[501][501];
void find(int x, int y) {
  if (!x || !y) return;
  find(record[x][y].first, record[x][y].second);
  if (a[x] == b[y]) cout << a[x] << " ";
}
int main() {
  int x, y, maxx = 0, i;
  while (cin >> n) {
    maxx = 0;
    le[0][0] = le[0][1] = le[1][0] = 0;
    for (x = 1; x <= n; x++) cin >> a[x];
    cin >> m;
    for (x = 1; x <= m; x++) cin >> b[x];
    for (x = 1; x <= n; x++) {
      int p = 0;
      for (y = 1; y <= m; y++) {
        if ((a[x] > b[y]) && le[x - 1][y] > le[x - 1][p]) p = y;
        if (a[x] == b[y]) {
          record[x][y] = make_pair(x - 1, p);
          le[x][y] = le[x - 1][p] + 1;
        } else {
          record[x][y] = make_pair(x - 1, y);
          le[x][y] = le[x - 1][y];
        }
      }
    }
    for (x = 1; x <= m; x++) {
      if (le[n][x] > maxx) {
        maxx = le[n][x];
        i = x;
      }
    }
    cout << maxx << endl;
    find(n, i);
    cout << endl;
  }
}
