#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7, INF = 9e18, inf = 2e9;
int n, m, a[509], b[509];
int mx, id, ans, x;
vector<int> dp[509], v;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  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) {
    mx = 0;
    id = 0;
    for (int j = 1; j <= m; ++j) {
      if (b[j] < a[i] && mx < dp[j].size()) {
        mx = dp[j].size();
        id = j;
      }
      if (b[j] == a[i]) {
        v = dp[id];
        v.push_back(b[j]);
        dp[j] = v;
        if (ans < mx + 1) {
          ans = mx + 1;
          x = j;
        }
      }
    }
  }
  cout << ans << '\n';
  for (int i = 0; i < ans; ++i) cout << dp[x][i] << ' ';
  return 0;
}
