#include <bits/stdc++.h>
using namespace std;
void BuildLCIS(const int size1, const int size2, long long* sequence1,
               long long* sequence2) {
  int* length = new int[size2];
  int* prev_index = new int[size2];
  for (int i = 0; i < size2; ++i) {
    length[i] = 0;
    prev_index[i] = -1;
  }
  for (int i = 0; i < size1; ++i) {
    int parent = -1;
    int currentLen = 0;
    for (int j = 0; j < size2; ++j) {
      if (sequence2[j] == sequence1[i] && length[j] < currentLen + 1) {
        length[j] = currentLen + 1;
        prev_index[j] = parent;
      } else if (sequence2[j] < sequence1[i] && currentLen < length[j]) {
        parent = j;
        currentLen = length[j];
      }
    }
  }
  int maxLen = 0;
  int index = -1;
  for (int i = 0; i < size2; ++i) {
    if (length[i] > maxLen) {
      maxLen = length[i];
      index = i;
    }
  }
  int* result_sequence = new int[size2];
  for (int i = 0; index != -1; ++i) {
    result_sequence[i] = sequence2[index];
    index = prev_index[index];
  }
  cout << maxLen << endl;
  for (int i = maxLen - 1; i >= 0; --i) {
    cout << result_sequence[i] << ' ';
  }
  delete[] prev_index;
  delete[] result_sequence;
}
int main() {
  int size1;
  cin >> size1;
  long long* sequence1 = new long long[size1];
  for (int i = 0; i < size1; ++i) {
    cin >> sequence1[i];
  }
  int size2;
  cin >> size2;
  long long* sequence2 = new long long[size2];
  for (int i = 0; i < size2; ++i) {
    cin >> sequence2[i];
  }
  BuildLCIS(size1, size2, sequence1, sequence2);
  delete[] sequence1;
  delete[] sequence2;
  return 0;
}
