Mission control tracks a swarm of relay satellites. Every ground station that makes contact with a satellite logs a single signal-strength reading for that satellite's numeric ID. To decide which units need a boost, engineers want, for every satellite that appears in the log, the average of its five strongest readings — using integer (floor) division so the result is always a whole number.
The first line contains a single integer n, the number of log entries.
Each of the next n lines contains two integers id and reading, meaning a ground station recorded reading for the satellite with ID id.
For every distinct satellite ID that appears in the log, in ascending order of ID, print a line containing the ID and the floor-averaged value of its five strongest readings (the sum of its five highest readings, integer-divided by 5), separated by a single space.
Example 1
Input
11 1 91 1 92 1 60 1 65 1 87 2 93 2 97 2 77 2 100 2 100 2 76
Expected
1 79 2 93
Explanation
Satellite 1 has exactly five readings: 91, 92, 60, 65, 87. Their sum is 395, and 395 // 5 = 79. Satellite 2 has six readings; its five strongest are 100, 100, 97, 93, and 77, which sum to 467, and 467 // 5 = 93 (the remainder 2 is dropped by floor division). Satellites are printed in ascending ID order, so satellite 1's line comes before satellite 2's.
Example 2
Input
5 5 10 5 10 5 10 5 10 5 10
Expected
5 10
Explanation
Satellite 5 has exactly five readings, all equal to 10. Their sum is 50, and 50 // 5 = 10, so the only output line is '5 10'.
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 →