#C7649. Common Elements in Three Arrays

    ID: 51543 Type: Default 1000ms 256MiB

Common Elements in Three Arrays

Common Elements in Three Arrays

Given three arrays of integers, your task is to find all the unique elements that are present in all three arrays. The result should be output in sorted order.

You need to compute the intersection of the three sets, that is, the set:

$$S = S_1 \cap S_2 \cap S_3,$$

where \(S_1, S_2, S_3\) are the sets of elements from the three arrays respectively.

The input is read from stdin and the output must be written to stdout as space-separated integers. If there are no common elements, output an empty line.

inputFormat

The input consists of four lines:

  • The first line contains an integer N representing the number of elements in the first array.
  • The second line contains N space-separated integers forming the first array.
  • The third line contains space-separated integers forming the second array.
  • The fourth line contains space-separated integers forming the third array.

Note: The second and third arrays can have different lengths.

outputFormat

Output the common elements present in all three arrays as space-separated integers in sorted order on one line. If there are no common elements, output an empty line.

## sample
6
1 5 10 20 40 80
6 7 20 80 100
3 4 15 20 30 70 80 120
20 80