Demerit Points

Time limit1sMemory limit128 MB

Problem

A certain region manages driver's license demerit points and merit points with the following rules.

A new driver starts with no merit or demerit points. When a driver is convicted of a driving offense, they receive between 2 and 15 demerit points, depending on the severity of the offense.

One merit point is awarded, up to a maximum of five, for each two-year interval in which the driver has no offenses and no demerit points. Each merit point cancels up to two demerit points. When a subsequent offense occurs:

  • If the number of demerit points exceeds double the number of merit points, the demerit points are reduced by double the number of merit points, and the merit points are set to 0.
  • If the number of demerit points is less than or equal to double the number of merit points, the demerit points are reduced to 0, and the merit points are reduced by half the number of demerit points. Any fractional merit points are discarded.

Demerit points are reduced whenever the driver goes one year free of any offense. The reduction lowers the demerit points by half or by 2, whichever is greater. Any fractional or negative demerit points are discarded (set to 0). This reduction takes place on each anniversary of the most recent offense, while demerit points remain.

If a new offense occurs on the same day as a demerit-point reduction or a merit-point award, the reduction/award is applied first, before the new demerit points are added.

Given the records for one driver, output the number of merit or demerit points whenever it changes.

Input

The first line contains the license issue date in yyyymmdd format. Each subsequent line contains offense information in chronological order: the offense date (yyyymmdd) and the demerit points applied (an integer between 2 and 15).

Output

On the license issue date, and whenever the number of merit or demerit points changes, output the date and the points on one line using the format below. Output terminates once merit points reach 5 following the last offense.

  • With demerit points: YYYY-MM-DD N demerit point(s).
  • With merit points: YYYY-MM-DD N merit point(s).
  • With neither: YYYY-MM-DD No merit or demerit points.