// editor1
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        TreeSet<Integer> first=new LinkedHashSet<>();
        HashSet<Integer> second=new HashSet<>();
        for(int i=0;i<n;i++){
            first.add(sc.nextInt());
        }
        for(int i=0;i<m;i++){
            second.add(sc.nextInt());
        }
        TreeSet<Integer> union=new HashSet<>(first);
        TreeSet<Integer> diff=new HashSet<>(first);
        TreeSet<Integer> intersection=new HashSet<>(first);
        union.addAll(second);
        for(int i:union){
            System.out.print(i+" ");
        }
        System.out.println();
        diff.removeAll(second);
        for(int i:diff){
            System.out.print(i+" ");
        }
        System.out.println();
        intersection.retainAll(second);
        for(int i:intersection){
            System.out.print(i+" ");
        }
    }
}