#C10523. Non-overlapping Walking Time Calculation

    ID: 39738 Type: Default 1000ms 256MiB

Non-overlapping Walking Time Calculation

Non-overlapping Walking Time Calculation

You are given a series of events that mark the starting and stopping times of a runner's walk. Each event is represented as a line with two tokens: the event type (either start or stop) and a timestamp (an integer). The input ends with a line containing the word end. Your task is to calculate the total time the runner has been walking, taking into account that some intervals might overlap. When intervals overlap, the overlapping period should only be counted once.

Formally, if the merged intervals are represented as ({[s_i, t_i]}{i=1}^{k}), the answer is given by
(\displaystyle total = \sum
{i=1}^{k}(t_i - s_i)).

inputFormat

The input consists of multiple lines. Each line (except the last) contains an event described by two tokens separated by a space: the event type (start or stop) and a timestamp (integer). The last line will be the word end indicating the end of input.

outputFormat

Output a single integer which is the total walking time computed from the non-overlapping time intervals.## sample

start 1
stop 5
end
4