A community seed vault runs periodic giveaway events throughout the year, and every packet handed to a member garden is recorded as one line in a distribution log. Each log line records which distribution event it belongs to, which seed variety was given out, the year of the event, how many packets were handed out in that single line, and a nominal catalogue price the vault keeps for its own bookkeeping. The vault's coordinators want a running total that ignores year and price entirely: for every variety code that shows up anywhere in the log, report how many packets of that variety have been given out in total across every log line, and list the varieties from the smallest code to the largest.
Line 1: one integer N — the number of distribution log lines.
The next N lines each contain five integers: eventId varietyCode year packets labelPrice.
For every distinct varietyCode that appears in the log, print one line varietyCode totalPackets, where totalPackets is the sum of packets over every log line carrying that variety code. Print the lines in strictly increasing order of varietyCode.
Example 1
Input
3 1 100 2008 10 5000 2 100 2009 12 5000 3 200 2011 15 9000
Expected
100 22 200 15
Explanation
Variety 100 appears in two lines with packets 10 and 12, for a total of 22; variety 200 appears once with 15 packets. Sorted by ascending variety code, the output is '100 22' followed by '200 15'.
Example 2
Input
1 5 300 2020 7 100
Expected
300 7
Explanation
There is a single log line, for variety 300 with 7 packets, so the only output line is '300 7'.
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 →