#C5039. Common Rides
Common Rides
Common Rides
You are given three lists of ride IDs representing the rides that three friends, Alice, Bob, and Charlie, would like to try. Some rides may appear more than once in a list, but only unique rides in each list should be considered. Your task is to find all the ride IDs that are common to all three lists. Output these ride IDs in ascending order, prefixed by the count of such unique rides. If no ride is common in all three lists, just output 0.
In mathematical terms, given three sets: [ A = {a_1, a_2, \dots, a_{k_1}}, \quad B = {b_1, b_2, \dots, b_{k_2}}, \quad C = {c_1, c_2, \dots, c_{k_3}} ] Find the intersection: [ I = A \cap B \cap C ] and output: [ |I|, I_1, I_2, \dots, I_{|I|} ] where (|I|) is the number of common rides and (I_1, I_2, \dots, I_{|I|}) are the sorted ride IDs. If (I = \emptyset), output 0.
inputFormat
The input is read from standard input (stdin) and consists of four lines:
- The first line contains three space-separated integers: (k_1), (k_2), (k_3), representing the number of rides in Alice's, Bob's, and Charlie's lists respectively.
- The second line contains (k_1) space-separated integers representing Alice's ride IDs.
- The third line contains (k_2) space-separated integers representing Bob's ride IDs.
- The fourth line contains (k_3) space-separated integers representing Charlie's ride IDs.
All ride IDs are positive integers.
outputFormat
Print a single line to standard output (stdout). If there is at least one common ride, first print the count of unique common ride IDs followed by the sorted ride IDs separated by spaces. If no common ride exists, print only 0.## sample
4 5 4
10 30 50 70
10 20 30 50 80
10 30 50 90
3 10 30 50