#K59817. Intersection and Union of Sorted Lists
Intersection and Union of Sorted Lists
Intersection and Union of Sorted Lists
You are given two sorted lists of integers. Your task is to compute the intersection and the union of these lists. The intersection should contain only those numbers that appear in both lists, while the union should include every distinct number from the two lists.
Note that the lists might contain duplicate values, but the resultant intersection and union should not have any duplicates and must be in increasing order.
The input is read from stdin and the output should be printed to stdout.
inputFormat
The input consists of four lines:
1. An integer n, which is the number of elements in the first list.
2. n space-separated integers representing the first list (may contain duplicates).
3. An integer m, which is the number of elements in the second list.
4. m space-separated integers representing the second list (may contain duplicates).
outputFormat
The output consists of two lines:
1. The first line should display the intersection of the two lists (space-separated in increasing order). If there is no intersection, output an empty line.
2. The second line should display the union of the two lists (space-separated in increasing order).## sample
6
1 2 2 3 4 5
5
2 2 3 4 6
2 3 4
1 2 3 4 5 6
</p>