Mission control keeps a contact log for a fleet of satellites: each entry records a satellite's id and the calendar day (a plain integer day number counted from an arbitrary epoch) on which mission control received a signal from it. For every distinct satellite in the log, its first-contact day is the smallest day number recorded for it. A satellite is said to have a solid first link if mission control also received at least one signal from that same satellite on the very next calendar day (first-contact day + 1). Across all distinct satellites appearing in the log, compute the fraction that have a solid first link, rounded to exactly two decimal places.
m — the number of log entries.m lines contains two integers satellite_id day, meaning mission control received a signal from that satellite on that day. Entries are not guaranteed to be sorted by day, and the same (satellite_id, day) pair may appear more than once.Print one line containing a single number: the count of satellites with a solid first link divided by the total count of distinct satellites in the log, rounded to exactly two decimal places (for example 0.33, 1.00, or 0.67).
1 <= m <= 1000000 <= satellite_id <= 1000000 <= day <= 100000Example 1
Input
5 1 10 1 11 2 50 3 11 3 90
Expected
0.33
Explanation
Satellite 1's first-contact day is 10, and it also has a signal on day 11 (10+1), so it's solid. Satellite 2's only signal is day 50; day 51 is absent, so it's not solid. Satellite 3's first-contact day is 11 (the smaller of its two entries, 11 and 90); day 12 is absent, so it's not solid. 1 of 3 satellites are solid: 1/3 rounds to 0.33.
Example 2
Input
5 1 1 1 1 1 2 2 5 2 6
Expected
1.00
Explanation
Satellite 1 has three rows but only two distinct days (1 and 2, since day 1 is duplicated); its first-contact day is 1 and day 2 is present, so it's solid. Satellite 2's first-contact day is 5, and day 6 is present, so it's also solid. Both of the 2 satellites are solid: 2/2 = 1.00.
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 →