#C13528. List Intersection

    ID: 43076 Type: Default 1000ms 256MiB

List Intersection

List Intersection

Given two lists of integers, find the intersection of the two lists by preserving the order of appearance from the first list. An element is included in the output if it appears in both lists. Note that if an element appears multiple times in the first list and it exists in the second list, each occurrence from the first list should be included in the result.

For example, if the first list is [1, 2, 3, 4] and the second list is [3, 4, 5, 6], the output should be [3, 4].

inputFormat

The input consists of two lines. The first line contains space-separated integers representing the elements of the first list. The second line contains space-separated integers representing the elements of the second list. If a list is empty, the corresponding line will be empty.

outputFormat

Output a single line containing the intersection of the two lists, with the numbers separated by a single space. If the intersection is empty, output an empty line.## sample

1 2 3 4
3 4 5 6
3 4