A commercial kitchen logs a timestamped event every time a station begins or finishes preparing an order. Each order is prepared by exactly one station and generates exactly two log entries at that station: one start event and one end event, both carrying the same order id. Given the full log, compute, for every station that appears in the log, the average preparation duration — end timestamp minus start timestamp — across all the orders it handled.
The first line contains a single integer n, the number of log entries (n is always even). Each of the next n lines contains four space-separated fields: station_id order_id event timestamp, where station_id and order_id are integers, event is the literal string start or end, and timestamp is a non-negative real number of seconds (given with up to 3 digits after the decimal point). For every (station_id, order_id) pair appearing in the log there is exactly one start entry and exactly one end entry — they may appear in either order within the log — and the end timestamp is always strictly greater than the matching start timestamp.
Print one line per distinct station_id that appears in the log, in ascending order of station_id: the station_id, a single space, then its average preparation duration formatted with exactly 3 digits after the decimal point.
Example 1
Input
10 0 0 start 0.712 0 0 end 1.520 0 1 start 3.140 0 1 end 4.120 1 0 start 0.550 1 0 end 1.550 1 1 start 0.430 1 1 end 1.420 2 0 start 4.100 2 0 end 4.512
Expected
0 0.894 1 0.995 2 0.412
Explanation
Station 0 handled two orders with durations 1.520-0.712=0.808 and 4.120-3.140=0.980, averaging to (0.808+0.980)/2=0.894. Station 1 handled two orders with durations 1.000 and 0.990, averaging to 0.995. Station 2 handled a single order with duration 4.512-4.100=0.412, so its average is just 0.412.
Example 2
Input
4 0 5 start 0 0 5 end 10 0 6 start 2 0 6 end 8
Expected
0 8.000
Explanation
Station 0 handled two orders with durations 10-0=10 and 8-2=6, averaging (10+6)/2=8, printed as 8.000.
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 →