CDVII

Time limit1sMemory limit128 MB

Problem

Roman roads are famous for their longevity and sound engineering, but sound engineering is not cheap. To recover construction costs, a toll highway called the CDVII charges every car that uses it.

The fare works like this. Driving on the road costs a fixed amount per kilometre travelled, and the exact rate depends on the hour of the day at which the trip begins. Cameras at every entrance and every exit photograph the licence plate of each car as it enters and as it leaves.

At the end of every calendar month the registered owner receives one bill per vehicle. The bill charges:

  • the per-kilometre toll for every kilometre travelled, using the rate for the hour in which each trip started;
  • $1 for every trip; and
  • a $2 account charge for the bill itself.

Given all the licence-plate photographs taken during one month, produce that month's bills.

Input

The input has two parts: the fare structure, then the photo records.

The first line contains 24 non-negative integers. The $i$-th of them (with $i$ counted from $0$) is the toll, in cents per kilometre, for a trip that begins during hour $i$: the first value applies from 00:00 to 00:59, the second from 01:00 to 01:59, and so on up to 23:00 to 23:59.

Each remaining line is one photo record with four whitespace-separated fields:

  1. the licence number of the vehicle (up to 20 alphanumeric characters);
  2. the moment of the photo in the format mm:dd:hh:mm (month, day, hour and minute on a 24-hour clock);
  3. the word enter or exit; and
  4. the location of that entrance or exit, in kilometres from one end of the highway.

All records lie within a single month. To find the trips of one vehicle, sort its records by time and scan them from earliest to latest: whenever an enter record is immediately followed by an exit record, the two form one trip and both are removed from further consideration; any other record (an enter not followed by an exit, or an exit at the start or following an already-discarded record) is ignored. Equivalently, an enter is paired with the chronologically next record of the same vehicle only when that record is an exit. No two records of the same vehicle share a time, and there are at most 1000 photo records.

Output

For every vehicle that completes at least one trip, print one line containing the licence number, a single space, and the total amount owed for the month.

Measure the money in cents. A trip that begins during hour $h$ and runs between locations $a$ and $b$ costs $|a-b|$ times the hour-$h$ rate, in cents. The monthly total for a vehicle is

$$\text{total} = \sum_{\text{trips}} |a-b| \cdot \text{rate}(h) ;+; 100 \cdot (\text{number of trips}) ;+; 200 .$$

Print the total as dollars: a $ sign, then the whole number of dollars, a decimal point, and exactly two digits of cents (for example, a total of 1860 cents is written $18.60).

List the vehicles in ascending order of licence number, comparing the licence strings by character code, so that digits precede uppercase letters, which precede lowercase letters. A vehicle with no completed trip produces no line.