#K58217. Employee Worked Hours Calculation

    ID: 30594 Type: Default 1000ms 256MiB

Employee Worked Hours Calculation

Employee Worked Hours Calculation

You are given a series of log records representing employee clock-in and clock-out events. Each record contains an employee identifier, an event type (either clock_in or clock_out), and a timestamp (in minutes since the start of the day). Your task is to compute the total number of minutes each employee has worked. The result should be sorted in ascending order by the employee identifier.

For an employee, the worked minutes is computed as the sum of the differences between corresponding clock_out and clock_in timestamps. If an employee clocks in and then clocks out immediately, the worked minutes is 0. Assume that the log records are always provided in chronological order and that every clock_in event is eventually followed by a clock_out event.

Formally, for each employee e, if they have clock-in time t_in and then clock-out time t_out, then the work time is computed as:

[ T_e = \sum_{i}(t_{out}^{(i)} - t_{in}^{(i)}) ]

Your program should read input from stdin and write the result to stdout.

inputFormat

The input is given on the standard input in the following format:

N
employee_id1 event_type1 timestamp1
employee_id2 event_type2 timestamp2
... 
employee_idN event_typeN timestampN

Here, the first line contains an integer N denoting the number of log records. Each of the following N lines contains a log record with three fields separated by spaces:

  • employee_id: a string identifier.
  • event_type: either clock_in or clock_out.
  • timestamp: an integer representing the time in minutes.

outputFormat

The output should be printed on the standard output. For each employee who has at least one complete clock-in/clock-out pair, print a line with the employee identifier and the total minutes worked separated by a space. The output should be sorted in ascending order by employee identifier.

## sample
6
emp1 clock_in 480
emp2 clock_in 540
emp1 clock_out 780
emp2 clock_out 600
emp1 clock_in 800
emp1 clock_out 960
emp1 460

emp2 60

</p>