This problem differs from one which was on the online contest.

The sequence a1, a2, ..., an is called increasing, if ai < ai + 1 for i < n.

The sequence s1, s2, ..., sk is called the subsequence of the sequence a1, a2, ..., an, if there exist such a set of indexes 1 ≤ i1 < i2 < ... < ik ≤ n that aij = sj. In other words, the sequence s can be derived from the sequence a by crossing out some elements.

You are given two sequences of integer numbers. You are to find their longest common increasing subsequence, i.e. an increasing sequence of maximum length that is the subsequence of both sequences.

Input

The first line contains an integer n (1 ≤ n ≤ 500) — the length of the first sequence. The second line contains n space-separated integers from the range [0, 109] — elements of the first sequence. The third line contains an integer m (1 ≤ m ≤ 500) — the length of the second sequence. The fourth line contains m space-separated integers from the range [0, 109] — elements of the second sequence.

Output

In the first line output k — the length of the longest common increasing subsequence. In the second line output the subsequence itself. Separate the elements with a space. If there are several solutions, output any.

Examples

Input

7
2 3 1 6 5 4 6
4
1 3 5 6


Output

3
3 5 6 


Input

5
1 2 0 2 1
3
1 0 1


Output

2
0 1 
#include <bits/stdc++.h>
typedef short int int16;
typedef int int32;
typedef long long int64;
const double PI = acos(-1.0);
const long long MOD = (long long)1E9 + 7LL;
template <class T>
T Susake_pow(T a, T b) {
  T res;
  if (b == 0)
    return 1;
  else
    while ((b & 1) == 0) {
      b >>= 1;
      a *= a;
    }
  res = a;
  b >>= 1;
  while (b != 0) {
    a *= a;
    if ((b & 1) != 0) res *= a;
    b >>= 1;
  }
  return res;
}
template <class T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
  if (a < 0) return lcm(-a, b);
  if (b < 0) return lcm(a, -b);
  return a * (b / gcd(a, b));
}
template <class T>
inline char *Susake_nsystem(T n) {
  T t = 0, i;
  char *s, *p;
  s = (char *)malloc(sizeof(char) * 1000);
  p = (char *)malloc(sizeof(char) * 1000);
  while (n) {
    s[t] = n % 26 + 64;
    if (s[t] == 64) {
      s[t] += 26;
      n -= 26;
    }
    t++;
    n /= 26;
  }
  s[t] = '\0';
  for (i = 0; i < t; i++) p[i] = s[t - 1 - i];
  p[i] = '\0';
  free(s);
  return p;
}
int Susake_system(char *s) {
  int len = strlen(s), i, sum = 0;
  char p[1000];
  for (i = 0; i < len; i++) p[i] = s[len - 1 - i] - 64;
  for (i = 0; i < len; i++) sum += p[i] * Susake_pow(26, i);
  return sum;
}
int a[505], b[505];
int dp[505], path[505];
int Susake_lcis[505][505];
void Susake_LCIS(int a[], int la, int b[], int lb) {
  memset(path, 0, sizeof(path));
  memset(Susake_lcis, 0, sizeof(Susake_lcis));
  memset(dp, 0, sizeof(dp));
  int i, j, k, Max;
  for (i = 1; i <= la; i++) {
    memcpy(Susake_lcis[i], Susake_lcis[i - 1], sizeof(Susake_lcis[0]));
    for (k = 0, j = 1; j <= lb; j++) {
      if (b[j - 1] < a[i - 1] && dp[j] > dp[k]) k = j;
      if (b[j - 1] == a[i - 1] && dp[k] + 1 > dp[j]) {
        dp[j] = dp[k] + 1, Susake_lcis[i][j] = i * (lb + 1) + k;
      }
    }
  }
  for (Max = 0, i = 1; i <= lb; i++)
    if (dp[i] > dp[Max]) Max = i;
  for (i = la * lb + la + Max, j = dp[Max]; j;
       i = Susake_lcis[i / (lb + 1)][i % (lb + 1)], j--)
    path[j] = b[i % (lb + 1) - 1];
  printf("%d\n", dp[Max]);
  if (Max) {
    if (dp[Max] == 1)
      printf("%d\n", path[1]);
    else {
      for (int i = 1; i <= dp[Max] - 1; i++) printf("%d ", path[i]);
      printf("%d\n", path[dp[Max]]);
    }
  }
}
int main(int argc, char *argv[]) {
  int n, m;
  while (scanf("%d", &n) != EOF) {
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    scanf("%d", &m);
    for (int i = 0; i < m; i++) scanf("%d", &b[i]);
    Susake_LCIS(a, n, b, m);
  }
  return 0;
}
