#include <stdio.h>
#include <stdlib.h>

void sort(int *, int);
int linear(int *, int*, int, int);
int same(int *, int);

int main() {
  int *s, *t;
  int n, q, i;

  scanf("%d", &n);
  s = (int *)malloc(n*sizeof(int));
  for(i=0;i<n;i++){
    if(scanf("%d", &s[i])==EOF)break;
  }
  sort(s, n);

  scanf("%d", &q);
  t = (int *)malloc(q*sizeof(int));
  for(i=0;i<q;i++){
    if(scanf("%d", &t[i])==EOF)break;
  }
  sort(t, q);

  for(i=0;i<n;i++){
    printf("%d ", s[i]);
  }
  printf("\n");
  for(i=0;i<q;i++){
    printf("%d ", t[i]);
  }
  printf("\n");

  printf("%d\n", linear(s, t, n, q));

  free(s);
  free(t);
  
  return 0;
}

void sort(int *A, int n){
  int i, j, m, temp;

  for(i=0;i<n;i++){
    m=i;
    for(j=i+1;j<n;j++){
      if(A[j]<A[m]) m=j;
    }

    if(i!=m){
      temp=A[i];
      A[i]=A[m];
      A[m]=temp;
    }
  }
}

int linear(int *s, int *t, int n, int q){
  int i, middle;
  int count = 0, flag=0, left, right;

  for(i=0;i<n;i++){
    left=0;
    right=q;
    while(left<right){
      middle = (left + right)/2;
      printf("left: %d middle: %d right: %d\n", left, middle, right);
      if(s[i]==t[middle] && same(s,i)==0) {
	count++;
	break;
      }
      else if(s[i]>t[middle]) left=middle+1;
      else right=middle;
      if(left-right>=0) break;
    }
  }
  return count;
}

int same(int *s, int k){
  int i;

  for(i=0;i<k;i++){
    if(s[i]==s[k]) return 1;
  }

  return 0;
}