#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 518;
int a[MAX_N], b[MAX_N], last[2 * MAX_N], d[MAX_N][MAX_N];
pair<int, int> pr[MAX_N][MAX_N];
set<int> s;
map<int, int> ma;
vector<int> numbers;
int main() {
  int n, m;
  scanf("%d", &n);
  for (int i = 0; (i) < (n); ++i) scanf("%d", &a[i]), s.insert(a[i]);
  scanf("%d", &m);
  for (int i = 0; (i) < (m); ++i) scanf("%d", &b[i]), s.insert(b[i]);
  int it = 0;
  for (auto k : s) ma[k] = it++, numbers.push_back(k);
  for (int i = 0; (i) < (n); ++i) a[i] = ma[a[i]];
  for (int i = 0; (i) < (m); ++i) b[i] = ma[b[i]];
  for (int i = 0; (i) < (n); ++i) {
    for (int j = 0; (j) < ((n + m)); ++j) last[j] = -1;
    for (int j = 0; (j) < (m); ++j) {
      last[b[j]] = j;
      if (a[i] != b[j]) continue;
      d[i][j] = 1;
      pr[i][j] = make_pair(-1, -1);
      for (int g = 0; (g) < (i); ++g)
        if (a[g] < a[i] && last[a[g]] != -1) {
          if (d[i][j] < d[g][last[a[g]]] + 1) {
            d[i][j] = d[g][last[a[g]]] + 1;
            pr[i][j] = make_pair(g, last[a[g]]);
          }
        }
    }
  }
  int x = 0, y = 0, maxx = 0;
  for (int i = 0; (i) < (n); ++i)
    for (int j = 0; (j) < (m); ++j)
      if (d[i][j] > maxx) maxx = d[i][j], x = i, y = j;
  printf("%d\n", d[x][y]);
  if (d[x][y] == 0) return 0;
  vector<int> v;
  while (x >= 0 && y >= 0) {
    v.push_back(a[x]);
    int x2 = pr[x][y].first;
    y = pr[x][y].second;
    x = x2;
  }
  reverse((v).begin(), (v).end());
  for (int k : v) printf("%d ", numbers[k]);
  return 0;
}
