#K72192. Intersection of Two Sorted Lists
Intersection of Two Sorted Lists
Intersection of Two Sorted Lists
You are given two sorted lists of integers. Your task is to find the intersection of these two lists. The intersection should contain only the unique numbers that appear in both lists and must be output in sorted order.
Note: The input lists are guaranteed to be sorted in non-decreasing order. If there is no intersection between the two lists, output an empty result.
The problem can be mathematically formulated as follows: Given two sorted sequences \(A = [a_1, a_2, \dots, a_n]\) and \(B = [b_1, b_2, \dots, b_m]\), find the set \(C = A \cap B\) and output the sorted list of elements in \(C\).
inputFormat
The input is read from standard input and consists of four lines:
- The first line contains an integer \(n\), the number of elements in the first list.
- The second line contains \(n\) space-separated integers representing the first sorted list.
- The third line contains an integer \(m\), the number of elements in the second list.
- The fourth line contains \(m\) space-separated integers representing the second sorted list.
outputFormat
Output a single line to standard output containing the unique elements that are present in both lists in sorted order, separated by a single space. If there is no intersection, output an empty line.
## sample3
1 2 3
3
4 5 6