Walk

Interview

Time limit1sMemory limit1024 MB

Summary
Parse walking segments given as duration and pace per kilometre, then report total distance in metres and average speed in km/h.
Level

Medium4 of 10

Topics
Implementation, Math, Simulation, String matching
Solved
No attempts yet

Problem

Mart takes a walk every day, and his sports watch records the duration and the speed of each constant-speed segment of the walk. After the walk, Mart can download the log file to his computer. From this file, determine the total distance of the walk and the average speed.

Input

The first line contains an integer NN (1≤N≤10 0001 \le N \le 10\,000). Each of the next NN lines contains the following space-separated data about one segment:

  • the duration of the segment in minutes and seconds, in the form MMmSSs, where MM is the integer number of minutes (the minutes part is omitted when the duration is less than one minute) and SS is the integer number of seconds (which never exceeds 5959);
  • the word kiirusega;
  • the speed on this segment, expressed as minutes and seconds per kilometre, in the form MMmSSs/km, where MM is the integer number of minutes and SS is the integer number of seconds (which never exceeds 5959). You may assume that Mart needs at least one minute, but less than one hour, per kilometre.

You may also assume that the total duration of all segments does not exceed 2424 hours.

Output

Print two lines:

  • on the first line, the total distance of the walk rounded to the nearest metre, in the form LLm, where LL is the integer number of metres;
  • on the second line, the average speed in the form VVkm/h, where VV is the average speed in kilometres per hour, rounded to exactly three decimal places.

Examples3

  1. Example 1

    Input
    3
    8m30s kiirusega 9m10s/km
    4m10s kiirusega 8m1s/km
    21s kiirusega 4m10s/km
    
    Expected output
    1531m
    7.057km/h
    
  2. Example 2

    Input
    1
    10m0s kiirusega 5m0s/km
    
    Expected output
    2000m
    12.000km/h
    
  3. Example 3

    Input
    2
    30m0s kiirusega 6m0s/km
    30m0s kiirusega 4m0s/km
    
    Expected output
    12500m
    12.500km/h