#K45882. Calculate Active Session Duration

    ID: 27852 Type: Default 1000ms 256MiB

Calculate Active Session Duration

Calculate Active Session Duration

You are given a sequence of log entries. Each log entry contains a timestamp in ISO 8601 format and an action.

A session is defined as the period between a login action and the subsequent logout action. Other actions (such as view or click) should be ignored when computing the session duration.

Your task is to calculate the total active duration of all sessions (in seconds). In mathematical terms, if a session starts at time \(t_{start}\) and ends at time \(t_{end}\), its duration is \(t_{end} - t_{start}\). Sum the durations for all valid sessions to get the final result.

inputFormat

The input is read from standard input (stdin).\nThe first line contains an integer (n) representing the number of log entries.\nThe next (n) lines each contain a log entry with two space-separated strings:\n- A timestamp in ISO 8601 format (for example, 2023-10-10T14:48:00Z)\n- An action, which can be one of: "login", "logout", "view", or "click".

outputFormat

Output a single integer on standard output (stdout) that represents the total active duration in seconds.## sample

2
2023-10-10T14:48:00Z login
2023-10-10T14:51:00Z logout
180