#include <bits/stdc++.h>
using namespace std;
struct iii {
  int a, b, c;
  iii() {}
  iii(int a, int b, int c) : a(a), b(b), c(c) {}
  bool operator<(const iii &e) const {
    return a < e.a || a == e.a && (b < e.b || b == e.b && c < e.c);
  }
};
struct Scanner {
  Scanner &operator>>(int &x) {
    scanf("%d", &x);
    return *this;
  }
  Scanner &operator>>(double &x) {
    scanf("%lf", &x);
    return *this;
  }
  Scanner &operator>>(char *x) {
    scanf("%s", x);
    return *this;
  }
  Scanner &operator>>(long long &x) {
    scanf("%I64d", &x);
    return *this;
  }
  Scanner &operator>>(pair<int, int> &x) {
    scanf("%d%d", &x.first, &x.second);
    return *this;
  }
  Scanner &operator>>(pair<double, double> &x) {
    scanf("%lf%lf", &x.first, &x.second);
    return *this;
  }
} in;
template <typename T>
T sq(const T &x) {
  return x * x;
}
template <typename T>
void minl(T &a, const T &b) {
  if (a > b) a = b;
}
template <typename T>
void maxl(T &a, const T &b) {
  if (a < b) a = b;
}
template <typename T>
void usort(vector<T> &a) {
  sort((a).begin(), (a).end());
  a.erase(unique((a).begin(), (a).end()), a.end());
}
template <typename T>
int index(const vector<T> &a, const T &x) {
  return lower_bound((a).begin(), (a).end(), x) - a.begin();
}
template <typename T>
void operator+=(vector<T> &a, const T &x) {
  a.push_back(x);
}
template <typename T>
bool operator&(const set<T> &a, const T &x) {
  return a.find(x) != a.end();
}
pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) {
  return pair<int, int>(a.first + b.first, a.second + b.second);
}
pair<int, int> operator-(const pair<int, int> &a, const pair<int, int> &b) {
  return pair<int, int>(a.first - b.first, a.second - b.second);
}
long long cross(const pair<int, int> &a, const pair<int, int> &b) {
  return (long long)a.first * b.second - (long long)b.first * a.second;
}
long long dot(const pair<int, int> &a, const pair<int, int> &b) {
  return (long long)a.first * b.first + (long long)a.second * b.second;
}
const int N = 500;
template <typename T>
int GCIS(T *a, int l1, T *b, int l2, T *ans) {
  int f[N + 1][N + 1] = {};
  int DP[N + 1] = {};
  int i, j, k, mx;
  for (i = 1; i <= l1; i++) {
    k = 0;
    memcpy(f[i], f[i - 1], sizeof(f[0]));
    for (j = 1; j <= l2; j++) {
      if (b[j - 1] < a[i - 1] && DP[j] > DP[k]) k = j;
      if (b[j - 1] == a[i - 1] && DP[k] + 1 > DP[j])
        DP[j] = DP[k] + 1, f[i][j] = i * (l2 + 1) + k;
    }
  }
  for (mx = 0, i = 1; i <= l2; i++)
    if (DP[i] > DP[mx]) mx = i;
  for (i = l1 * l2 + l1 + mx, j = DP[mx]; j;
       i = f[i / (l2 + 1)][i % (l2 + 1)], j--)
    ans[j - 1] = b[i % (l2 + 1) - 1];
  return DP[mx];
}
void york() {
  int a[N];
  int b[N];
  int c[N];
  int n1, n2;
  in >> n1;
  for (int i = 0; i < n1; i++) in >> a[i];
  in >> n2;
  for (int i = 0; i < n2; i++) in >> b[i];
  int ans = GCIS(a, n1, b, n2, c);
  cout << ans << endl;
  for (int i = 0; i < ans; i++) cout << c[i] << ' ';
}
int main() {
  york();
  return 0;
}
