#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int mod = 998244353;
const int N = 1e6 + 5;
int len, n, m, dp[505], a[505], b[505], path[505], la;
void print(int p) {
  if (p) {
    print(path[p]);
    printf("%d ", b[p]);
  }
}
int main() {
  cin >> n;
  for (int i = (1); i < (n + 1); i++) scanf("%d", &a[i]);
  cin >> m;
  for (int i = (1); i < (m + 1); i++) scanf("%d", &b[i]);
  for (int i = (1); i < (n + 1); i++) {
    int t = 0;
    for (int j = (1); j < (m + 1); j++) {
      if (a[i] == b[j]) {
        dp[j] = dp[t] + 1;
        path[j] = t;
      }
      if (b[j] < a[i] && dp[j] > dp[t]) {
        t = j;
      }
    }
  }
  for (int i = (1); i < (m + 1); i++)
    if (dp[i] > dp[la]) la = i;
  cout << dp[la] << endl;
  print(la);
}
