#include <bits/stdc++.h>
using namespace std;
struct coord {
  int i;
  int j;
  coord() {
    i = 0;
    j = 0;
  }
  coord(int x, int y) {
    i = x;
    j = y;
  }
};
int main() {
  int n, m;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; ++i) cin >> a[i];
  cin >> m;
  vector<int> b(m + 1);
  for (int i = 1; i <= m; ++i) cin >> b[i];
  vector<vector<int>> dp(n + 1, vector<int>(m + 1));
  vector<vector<coord>> dp_way(n + 1, vector<coord>(m + 1));
  int max_count = 0;
  coord max_coord;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (a[i] == b[j]) {
        dp[i][j] = 1;
        for (int p = 1; p < i; ++p) {
          for (int k = 1; k < j; ++k) {
            if (a[i] > a[p] && 1 + dp[p][k] > dp[i][j]) {
              dp[i][j] = dp[p][k] + 1;
              dp_way[i][j] = coord(p, k);
            }
          }
        }
        if (max_count < dp[i][j]) {
          max_count = dp[i][j];
          max_coord = coord(i, j);
        }
      }
    }
  }
  cout << max_count << '\n';
  vector<int> answer(max_count + 1);
  coord now = max_coord;
  for (int i = max_count; i > 0; --i) {
    answer[i] = a[now.i];
    now = dp_way[now.i][now.j];
  }
  for (int i = 1; i <= max_count; ++i) cout << answer[i] << ' ';
  return 0;
}
