#C8106. Intersection of Two Sorted Arrays

    ID: 52052 Type: Default 1000ms 256MiB

Intersection of Two Sorted Arrays

Intersection of Two Sorted Arrays

You are given two sorted arrays \( A \) and \( B \). Your task is to compute the intersection of these two arrays. In other words, you need to find all elements that appear in both arrays and output them in sorted order without duplicates.

For example, if \( A = [1, 3, 4, 6, 7, 9] \) and \( B = [1, 2, 4, 5, 9, 10] \), then the intersection is \( A \cap B = [1, 4, 9] \).

Note that the arrays may contain duplicates, but the output should list each common element only once.

inputFormat

The input consists of two lines. The first line contains space-separated integers representing the first sorted array. The second line contains space-separated integers representing the second sorted array.

outputFormat

Print the common elements of the two arrays as space-separated integers in one line. If there is no common element, print an empty line.## sample

1 3 4 6 7 9
1 2 4 5 9 10
1 4 9