#include <bits/stdc++.h>
using namespace std;
int N, M;
int A[505], B[505];
int DP[505][505];
int DP2[505][505];
int solve(int a, int b) {
  if (a > N || b > M) return 0;
  if (DP[a][b] != -1) return DP[a][b];
  if (B[b] <= A[a]) return DP[a][b] = solve(a, b + 1);
  int i, ret = solve(a, b + 1), ans;
  for (i = a + 1; i <= N; i++)
    if (A[i] == B[b]) {
      ans = solve(i, b + 1) + 1;
      if (ans > ret) {
        DP2[a][b] = 0;
        ret = ans;
      }
    }
  return DP[a][b] = ret;
}
int main() {
  int k, i, j, last;
  scanf("%d", &N);
  for (i = 1; i <= N; i++) scanf("%d", &A[i]);
  scanf("%d", &M);
  for (i = 1; i <= M; i++) scanf("%d", &B[i]);
  A[0] = -1;
  memset(DP, -1, sizeof(DP));
  memset(DP2, -1, sizeof(DP));
  int ans = solve(0, 1);
  cout << ans << endl;
  i = -1;
  for (k = ans; k >= 1; k--)
    for (i++; i <= N; i++) {
      for (j = 1; j <= M; j++)
        if (DP[i][j] == k && !DP2[i][j]) {
          printf("%d ", B[j]);
          break;
        }
      if (j != M + 1) break;
    }
  cout << endl;
  return 0;
}
