Solve problem "Cubes" online - Learn Python 3 - Snakify

Problem «Cubes» (Medium)


Statement

Alice and Bob like to play with colored cubes. Each child has its own set of cubes and each cube has a distinct color, but they want to know how many unique colors exist if they combine their block sets. To determine this, the kids enumerated each distinct color with a random number from \( 0 \) to \( 10^{8} \). At this point their enthusiasm dried up, and you are invited to help them finish the task.

Given two integers that indicate the number of blocks in Alice's and then Bob's sets \( N \) and \( M \). The following \( N \) lines contain the numerical color value for each cube in Alice's set. Then the last \( M \) rows contain the numberical color value for each cube in Bob's set.

Find three sets: the numerical colors of cubes in both sets, the numerical colors of cubes only in Alice's set, and the numerical colors of cubes only in Bob's set. For each set, print the number of elements in the set, followed by the numerical color elements, sorted in ascending order.


In all the problems input the data using input() and print the result using print().



Saved solutions

Tests

Input Correct answer Result
4 3
0
1
10
9
1
3
0
2
0
1
2
9
10
1
3
2 2
1
2
2
3
1
2
1
1
1
3
0 0
0

0

0
1 1
0
1
0

1
0
1
1
8 5
1
10
100
1000
10000
100000
1000000
10000000
1
100
10000
1000000
100000000
4
1
100
10000
1000000
4
10
1000
100000
10000000
1
100000000