#C12126. Intersection of Two Lists
Intersection of Two Lists
Intersection of Two Lists
Given two lists of integers, A and B, your task is to compute their intersection. For every element a in A, if a is also present in B, then a should appear in the output. The order of appearance in the output must be the same as the order in which the elements occur in A.
Formally, for each element \(a\) in A, if \(a \in B\), then include \(a\) in the resulting list. Note that if an element appears multiple times in A and is present in B, it should be output as many times as it appears in A.
inputFormat
The input is read from standard input (stdin) in the following format:
- The first line contains an integer \(n\), the number of elements in the first list.
- The second line contains \(n\) space-separated integers.
- The third line contains an integer \(m\), the number of elements in the second list.
- The fourth line contains \(m\) space-separated integers.
outputFormat
Output the intersection list as a sequence of integers separated by a single space. If there are no common elements, output an empty line.
## sample4
1 2 3 4
4
3 4 5 6
3 4