#include <bits/stdc++.h>
using namespace std;
int f[501][501];
int a[501], b[501];
int n;
int m;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  cin >> m;
  for (int i = 1; i <= m; i++) cin >> b[i];
  for (int i = 1; i <= n; i++) {
    int len = 0;
    for (int j = 1; j <= m; j++) {
      f[i][j] = f[i - 1][j];
      if (a[i] == b[j]) f[i][j] = max(f[i][j], len + 1);
      if (a[i] > b[j]) len = max(len, f[i][j]);
    }
  }
  int mx_len = 0;
  for (int i = 1; i <= m; i++) mx_len = max(mx_len, f[n][i]);
  cout << mx_len << '\n';
  int pre = 2e9;
  if (mx_len) {
    vector<int> res;
    int cur_pos = n;
    for (int j = m; j >= 1; j--)
      if (f[cur_pos][j] == mx_len && b[j] < pre) {
        for (int i = cur_pos; i >= 1; i--)
          if (a[i] == b[j]) {
            cur_pos = i - 1;
            break;
          }
        mx_len--;
        res.push_back(b[j]);
        pre = b[j];
        if (!mx_len) break;
      }
    reverse(res.begin(), res.end());
    for (auto& p : res) cout << p << ' ';
  }
}
