#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
int dp[maxn][maxn], a[maxn], b[maxn], ans;
pair<int, int> pre[maxn][maxn];
void dfs(int x, int y) {
  if (x == 0 || y == 0) return;
  dfs(pre[x][y].first, pre[x][y].second);
  printf("%d ", a[x]);
}
int main() {
  int n, m;
  cin >> n;
  for (register int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  cin >> m;
  for (register int i = 1; i <= m; ++i) scanf("%d", &b[i]);
  for (register int i = 1; i <= n; ++i) {
    for (register int j = 1; j <= m; ++j) {
      if (a[i] != b[j]) continue;
      dp[i][j] = 1;
      for (register int k = 1; k <= i - 1; ++k)
        for (register int w = 1; w <= j - 1; ++w)
          if (a[i] > a[k] && b[j] > b[w] && dp[k][w] + 1 > dp[i][j])
            dp[i][j] = dp[k][w] + 1, pre[i][j].first = k, pre[i][j].second = w;
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << "\n";
  if (ans == 0) return 0;
  for (register int i = 1; i <= n; ++i)
    for (register int j = 1; j <= m; ++j)
      if (ans == dp[i][j]) {
        dfs(i, j);
        goto Here;
      }
Here:
  return 0;
}
