#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500 + 10;
int a[MAXN], b[MAXN], n, m, markA[MAXN][MAXN], dp[MAXN][MAXN];
pair<int, int> par[MAXN][MAXN];
int main() {
  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++) {
    for (int j = 1; j <= m; j++) {
      for (int k = 1; k <= j; k++) {
        if (a[i] == b[k]) markA[i][j] = k;
      }
    }
  }
  dp[0][0] = 0;
  for (int i = 1; i <= m; i++) {
    if (b[i] == a[1]) dp[1][i] = 1, par[1][i] = {-1, -1};
    dp[i][0] = -1e9;
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i] != b[j]) {
        par[i][j] = {-1, -1};
        continue;
      }
      dp[i][j] = 1;
      for (int k = 1; k < i; k++) {
        if (a[i] > a[k]) {
          if (dp[k][markA[k][j]] + 1 > dp[i][j]) {
            par[i][j] = {k, markA[k][j]};
            dp[i][j] = dp[k][markA[k][j]] + 1;
          }
        }
      }
    }
  }
  int ans = 0, x, y;
  vector<int> v;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (dp[i][j] > ans) {
        x = i;
        y = j;
        ans = dp[i][j];
      }
    }
  }
  cout << ans << endl;
  if (ans == 0) return 0;
  while (x > 0 && y > 0) {
    v.push_back(a[x]);
    pair<int, int> p = par[x][y];
    x = p.first;
    y = p.second;
  }
  reverse(v.begin(), v.end());
  for (int i : v) cout << i << ' ';
  return 0;
}
