This page is still under construction.

Parts of this page are still being built. What you see may change.

Time Cards

Time limit1sMemory limit128 MB

Summary
For each cow, pair her START and STOP entries and print the total time she spent at the milking machine as hours and minutes.
Level

Easy2 of 10

Topics
Implementation, Simulation, Array
Solved
No attempts yet

Problem

To improve productivity, a farmer gives each cow extra hay based on how long it spends at a milking machine, so every cow now uses a time card. When a cow starts at a machine she writes the start time on the master card, and when she leaves she writes the stop time. There are enough machines that every cow can be milked at the same time.

There are NN cows numbered 1…N1 \ldots N (1≤N≤1451 \le N \le 145) and NlinesNlines total entries (1≤Nlines≤14581 \le Nlines \le 1458). Each entry lists a cow number CC (1≤C≤N1 \le C \le N), a keyword (START or STOP), and a time given as two integers HHHH and MMMM (0≤HH≤230 \le HH \le 23, 0≤MM≤590 \le MM \le 59). Cows never stay at a machine past midnight, and every START entry has a matching STOP entry that appears later in the file.

Compute the total time each cow spends at the milking machine.

Input

  • Line 1: two space-separated integers NN and NlinesNlines.
  • Lines 2…Nlines+12 \ldots Nlines+1: each line has four space-separated values — CC, the keyword (START or STOP), HHHH, and MMMM.

Output

  • Lines 1…N1 \ldots N: line ii contains two space-separated integers — the number of hours and the number of minutes that cow ii spent at the milking machine. The minutes value never exceeds 59.

Examples1

  1. Example 1

    Input
    2 6
    1 START 9 0
    2 START 9 30
    1 STOP 10 0
    2 STOP 10 15
    1 START 17 0
    1 STOP 17 42
    
    Expected output
    1 42
    0 45