#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
long long INF = 1e17 + 7;
int n, m;
int a[555], b[555];
set<int> s1, s2;
vector<int> v[3];
map<int, int> M;
int num[555];
void build() {
  for (int i = 1; i <= n; i++) {
    if (s2.count(a[i])) v[0].push_back(a[i]);
  }
  for (int i = 1; i <= m; i++) {
    if (s1.count(b[i])) v[1].push_back(b[i]);
  }
  int x = 1;
  for (auto i : s1) {
    if (s2.count(i) == 0) continue;
    M[i] = x;
    num[x] = i;
    x++;
  }
  for (int i = 0; i < v[0].size(); i++) v[0][i] = M[v[0][i]];
  for (int i = 0; i < v[1].size(); i++) v[1][i] = M[v[1][i]];
}
int nxt1[513][513];
int nxt2[513][513];
int last[513];
int dp[513][513];
int DP(int x, int y) {
  int &ret = dp[x][y];
  if (ret != -1) return ret;
  ret = 0;
  for (int i = v[0][x] + 1; i <= 500; i++) {
    if (nxt1[x][i] != -1 && nxt2[y][i] != -1)
      ret = max(ret, DP(nxt1[x][i], nxt2[y][i]));
  }
  ret++;
  return ret;
}
void f(int x, int y) {
  int ret = dp[x][y];
  cout << num[v[0][x]] << " ";
  for (int i = v[0][x] + 1; i <= 500; i++) {
    if (nxt1[x][i] != -1 && nxt2[y][i] != -1)
      if (ret - 1 == DP(nxt1[x][i], nxt2[y][i])) {
        f(nxt1[x][i], nxt2[y][i]);
        return;
      }
  }
}
int main() {
  memset(dp, -1, sizeof(dp));
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    s1.insert(a[i]);
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    s2.insert(b[i]);
  }
  build();
  memset(last, -1, sizeof(last));
  for (int i = v[0].size() - 1; i >= 0; i--) {
    for (int j = 1; j <= 500; j++) nxt1[i][j] = last[j];
    last[v[0][i]] = i;
  }
  memset(last, -1, sizeof(last));
  for (int i = v[1].size() - 1; i >= 0; i--) {
    for (int j = 1; j <= 500; j++) nxt2[i][j] = last[j];
    last[v[1][i]] = i;
  }
  int ret = 0;
  int p1, p2;
  for (int i = 0; i < v[0].size(); i++) {
    for (int j = 0; j < v[1].size(); j++) {
      if (v[0][i] == v[1][j]) {
        if (ret < DP(i, j)) {
          p1 = i, p2 = j;
        }
        ret = max(ret, DP(i, j));
      }
    }
  }
  cout << ret << endl;
  if (ret == 0) return 0;
  f(p1, p2);
  return 0;
}
