#C12777. Common Elements
Common Elements
Common Elements
Given two lists of integers, your task is to find the common elements that are present in both lists. The output list must contain these common elements in the order in which they appear in the first list and without any duplicates. Mathematically, you are to compute the set $$R = \{ x \in L_1 \mid x \in L_2 \}$$ while preserving the order of occurrence from the first list.
For example, if the first list is [1, 2, 3, 4, 5] and the second list is [4, 5, 6, 7, 8], the answer should be [4, 5].
inputFormat
The input consists of two lines:
- The first line contains the elements of the first list, separated by spaces. This line can be empty, representing an empty list.
- The second line contains the elements of the second list, separated by spaces. This line can also be empty.
All elements are integers.
outputFormat
Output a single line with the common elements separated by a single space. If there are no common elements, output an empty line.
## sample1 2 3 4 5
4 5 6 7 8
4 5