A shipping harbor logs every cargo handoff it processes. Each handoff record names the day it happened, the terminal where it happened, the captain who brought the shipment in, and the dockhand who received it. The same captain may make several handoffs on the same day at the same terminal, and the same dockhand may receive several of them. For every (day, terminal) pair that appears in the log at least once, the harbor wants the number of distinct captains and the number of distinct dockhands recorded there.
n, the number of handoff records.n lines contains one record: an integer day, a string terminal, an integer captainId, and an integer dockhandId, separated by single spaces.For every distinct (day, terminal) pair that appears in the input, print one line with the day, the terminal, the number of distinct captain IDs recorded for that pair, and the number of distinct dockhand IDs recorded for that pair, separated by single spaces. Print the lines ordered by day ascending, breaking ties by terminal in ascending lexicographic order. A (day, terminal) pair that never appears in the input must not be printed.
terminal consists of 1 to 20 lowercase English letters.Example 1
Input
6 1 alpha 101 501 1 alpha 102 501 1 bravo 103 502 2 alpha 101 503 2 alpha 101 503 2 alpha 104 501
Expected
1 alpha 2 1 1 bravo 1 1 2 alpha 2 2
Explanation
Day 1 at terminal alpha has two records, from captains 101 and 102, both received by dockhand 501, giving 2 distinct captains and 1 distinct dockhand. Day 1 at terminal bravo has a single record (captain 103, dockhand 502), giving 1 and 1. Day 2 at terminal alpha has three records; captain 101 appears twice and captain 104 once, so there are 2 distinct captains, and dockhands 503 and 501 both appear, so there are 2 distinct dockhands. The three pairs are printed sorted by day, then terminal: '1 alpha 2 1', '1 bravo 1 1', '2 alpha 2 2'.
Example 2
Input
4 5 charlie 9 9 5 charlie 9 9 5 charlie 9 9 5 charlie 9 9
Expected
5 charlie 1 1
Explanation
All four records share the same day, terminal, captain, and dockhand, so only one (day, terminal) pair appears, with exactly one distinct captain and one distinct dockhand: '5 charlie 1 1'.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →