ExpertDates & Time50 points

Renewal schedule with plan upgrades

A streaming service in Cape Town bills monthly. The customer signs up on a date and is charged the plan price immediately. Renewal number k (k = 1, 2, ...) happens on add_months(signup, k), where add_months keeps the signup day number but uses the last day of a short month (signup 31 Jan gives renewals on 28 Feb, 31 Mar, 30 Apr; with signup 29 Jan 2028 the February renewal is 29 Feb). Always count from the original signup date, never from the previous renewal.

When the customer changes plan on some date inside a cycle (between two renewal dates), they pay the prorated difference at once: (new price - current price) * left / days, where days is the length of the current cycle in days (from the last renewal or signup up to the next renewal) and left is the days from the change date to the next renewal. Round the magnitude to whole cents with halves up, then restore the sign (a downgrade gives a negative amount). From then on, the new price is used for renewals.

Task: line 1: signup date. Line 2: starting price in cents. Line 3: number of renewals n. Line 4: number of plan changes u. Then u lines date new_price_cents, sorted by date, always strictly after signup, strictly before renewal n, and never on a renewal date. Print the events in date order, one per line: YYYY-MM-DD SIGNUP x.xx, YYYY-MM-DD RENEWAL x.xx or YYYY-MM-DD CHANGE x.xx (negative amounts get a leading minus). Finish with Total: x.xx, the sum of all amounts.

Sample tests

Input

2026-01-31
1500
4
1
2026-03-10 2500

Expected output

2026-01-31 SIGNUP 15.00
2026-02-28 RENEWAL 15.00
2026-03-10 CHANGE 6.77
2026-03-31 RENEWAL 25.00
2026-04-30 RENEWAL 25.00
2026-05-31 RENEWAL 25.00
Total: 111.77

Input

2028-01-29
999
3
0

Expected output

2028-01-29 SIGNUP 9.99
2028-02-29 RENEWAL 9.99
2028-03-29 RENEWAL 9.99
2028-04-29 RENEWAL 9.99
Total: 39.96

Your answer is also checked against 4 hidden tests.