import java.util.Scanner; 
public class Main 
{ 
    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; 
        } 
        Set<Integer> setA = new HashSet<>();
        Set<Integer> setB = new HashSet<>(); 
        for (int i = 0; i < N; i++)
        { 
            setA.add(sc.nextInt()); 
        } 
        for (int i = 0; i < M; i++) 
        { 
            setB.add(sc.nextInt()); 
            
        } 
        Set<Integer> union = new HashSet<>(setA); 
        union.addAll(setB); 
        printSorted(union); 
        Set<Integer> diff = new HashSet<>(setA); 
        diff.removeAll(setB); 
        printSorted(diff); 
        Set<Integer> inter = new HashSet<>(setA); 
        inter.retainAll(setB); 
        printSorted(inter); 
        
    }
    public static void printSorted(Set<Integer> set)
    { 
        List<Integer> list = new ArrayList<>(set); 
        Collections.sort(list); 
        for (int num : list)
        { 
            System.out.print(num + " "); 
        } 
        System.out.println(); 
 } 
} 
 
 