#include <bits/stdc++.h>
using namespace std;
int a[507];
int b[507];
int dp[507][507];
int f[507];
int n, m;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  cin >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> b[i];
    f[i] = 0;
  }
  for (int j = 1; j <= m; ++j) {
    int t = 0;
    for (int i = 1; i <= n; ++i) {
      if (a[i] == b[j]) t = 1;
      dp[i][j] = t;
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      int t = 0;
      for (int k = 1; k <= i; ++k) {
        if (a[k] == b[j]) {
          t = 1;
          break;
        }
      }
      dp[i][j] = t;
    }
  }
  for (int i = 2; i <= n; ++i) {
    for (int j = 2; j <= m; ++j) {
      if (a[i] != b[j]) dp[i][j] = dp[i - 1][j];
      if (a[i] == b[j]) {
        int ans = 0;
        for (int k = 1; k < j; ++k) {
          if (b[j] <= b[k]) continue;
          if (dp[i - 1][k] > ans) {
            ans = dp[i - 1][k];
            f[j] = k;
          }
        }
        dp[i][j] = ans + 1;
      }
    }
  }
  int ansm = 1, t = dp[n][1];
  for (int j = 2; j <= m; ++j) {
    if (dp[n][j] > t) {
      t = dp[n][j];
      ansm = j;
    }
  }
  cout << dp[n][ansm] << endl;
  if (dp[n][ansm] == 0) return 0;
  vector<int> ansvec;
  for (int i = ansm; i != 0; i = f[i]) ansvec.push_back(b[i]);
  for (int i = ansvec.size() - 1; i >= 0; --i) cout << ansvec[i] << ' ';
  return 0;
}
