Set Operations
Completed
Read two lines of integers A and B. Print (sorted, one line each): A ∪ B, A ∩ B, A − B, and the symmetric difference.
Input
Two lines.
Output
Four lines (an empty result prints an empty line).
Example
Input
1 2 3 4 3 4 5
Output
1 2 3 4 5 3 4 1 2 1 2 5
Editor
Python
Hints
| union, & intersection, - difference, ^ symmetric difference.
Solution explanation
Set operators mirror maths notation and are very fast.
Show solution
a = set(map(int, input().split()))
b = set(map(int, input().split()))
print(*sorted(a | b))
print(*sorted(a & b))
print(*sorted(a - b))
print(*sorted(a ^ b))