#include <bits/stdc++.h>
using namespace std;
const int N = 502;
pair<int, pair<int, int> > dp[N][N];
int a[N];
int b[N];
map<int, int> a_val_to_pos;
int main() {
  int n, m;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  cin >> m;
  for (int i = 0; i < m; ++i) cin >> b[i];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (b[j] == a[i]) {
        dp[i][j].first = 1;
        dp[i][j].second.first = -1;
        dp[i][j].second.second = -1;
        for (int k = j - 1; k >= 0; --k) {
          if (b[k] < b[j]) {
            if ((a_val_to_pos.find(b[k]) != a_val_to_pos.end()) &&
                dp[a_val_to_pos[b[k]]][k].first + 1 > dp[i][j].first) {
              dp[i][j].first = dp[a_val_to_pos[b[k]]][k].first + 1;
              dp[i][j].second.first = a_val_to_pos[b[k]];
              dp[i][j].second.second = k;
            }
          }
        }
      } else {
        dp[i][j].first = 0;
        dp[i][j].second.first = -1;
        dp[i][j].second.second = -1;
      }
    }
    a_val_to_pos[a[i]] = i;
  }
  int ans_i = -1, ans_j = -1, mx = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j)
      if (dp[i][j].first > mx) {
        mx = dp[i][j].first;
        ans_i = i;
        ans_j = j;
      }
  }
  vector<int> ans;
  cout << mx << endl;
  if (mx > 0) {
    for (;;) {
      ans.push_back(b[ans_j]);
      if (dp[ans_i][ans_j].second.first != -1) {
        int tmp = ans_i;
        ans_i = dp[tmp][ans_j].second.first;
        ans_j = dp[tmp][ans_j].second.second;
      } else {
        break;
      }
    }
    reverse(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); ++i) cout << ans[i] << " ";
    cout << endl;
  }
  return 0;
}
