// editor1
import java.util.*;
public class Sol
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int m = sc.nextInt();
        
        if(n<=0 || m<=0)
        {
            System.out.println("Invalid input");
            return;
        }
        
        List<Integer> max = new ArrayList<>();
        List<Integer> zoe = new ArrayList<>();
        
        
        
        for(int i = 0;i<n;i++)
        {
            max.add(sc.nextInt());
        }
        
        for(int i = 0;i<m;i++)
        {
            zoe.add(sc.nextInt());
        }
        
        Set<Integer> uion = new TreeSet<>(max);
        Set<Integer> diff = new TreeList<>(max);
        
        uion.addAll(zoe);
        diff.removeAll(zoe);
        max.retainAll(zoe);
        
        for(int i:uion)
        {
            System.out.print(i+" ");
        }
        System.out.println();
        
        for(int i:diff)
        {
            System.out.print(i+" ");
        }
        System.out.println();
     
        for(int i:max)
        {
            System.out.print(i+" ");
        }
        System.out.println();
           
    }
}