#K64057. Machine Operating Time Calculation

    ID: 31890 Type: Default 1000ms 256MiB

Machine Operating Time Calculation

Machine Operating Time Calculation

You are given a sequence of events that indicate when a machine starts and stops operating. For each valid pair of events, where a 'start' event is immediately followed by a corresponding 'stop' event, you must calculate the operating duration by subtracting the start timestamp from the stop timestamp. The total operating time is the sum of these individual durations.

Formally, if a machine starts at time \(t_{start}\) and stops at time \(t_{stop}\), then the operating interval is \(t_{stop} - t_{start}\). Your task is to sum all such intervals and output the total operating time in seconds.

inputFormat

The first line contains an integer (n) representing the number of events. Each of the following (n) lines contains a string and an integer separated by a space. The string will be either "start" or "stop", indicating the type of event, while the integer represents the timestamp (in seconds). It is guaranteed that the events are provided in chronological order and every "start" event is followed by a corresponding "stop" event.

outputFormat

Output a single integer representing the total operating time of the machine in seconds.## sample

4
start 1
stop 5
start 6
stop 10
8