Time limit per test: 1.25 second(s) Memory limit: 262144 kilobytes
input: standard output: standard
From the very early days of the Kingdom one of the most honorable duties for its citizen was the duty of the Royal Guardian. The Guardians serve as personal bodyguards for the King. At any moment of time exactly one of the Guardians was assigned to perform this duty.
Recently the King have issued the new labour rules. According to these rules the five day working week (from Monday to Friday) became mandatory for all citizens. Each working day starts at 9:00 in the morning and lasts until 18:00 in the evening. Any duties in non-working hours are subject for additional reward, however it is not allowed to work more than T non-working hours during one calendar week. A week starts on 00:00 on Monday and ends on 24:00 on Sunday.
The Labour Union of Guardians has decided to check the schedule of duties of the Royal Guardians, and you were chosen to help them.
You are given the initial schedule of duties, and a list of updates to this schedule. Find the fraction of time during which the entire schedule was valid according to the labour rules. You are only interested in time interval from T1 to T2, so you ignore all the duties outside this interval.
The first line of the input file contains three integers N, M and T. Here N (1 ≤ N ≤ 105) is the number of entries in the schedule, M (0 ≤ M ≤ 105) is the number of updates to the schedule, and T (0 ≤ T ≤ 123) is the number of hours that one is allowed to work during the non-working hours per week.
The second line contains two dates — T1 and T2 (It is guaranteed that T1 comes earlier than T2).
The next N lines describes the initial schedule of the Guardians. Each line consists of a date Di and the name of the Guardian that starts his duty at time Di (1 ≤ i ≤ N, it is guaranteed that Dis are in ascending order, and D1 comes no later than T1). (The name is a case-sensitive sequence of English characters.) After starting his duty at time Di the Guardian serves until the next Guardian comes to replace him.
Each of the following M lines describes the schedule of updates. Each update is described by Ai — the date when this update become active, Bi and Ei (the time slot of the update), and the Guarding name (in the same format as above). When this update becomes active, the schedule is modified in the following manner: this guardian will now serve the duties between Bi and Ei, the schedule outside this time slot is not affected (see the note below the example for more explanations). It is guaranteed that Ai comes no later than Bi, and Bi earlier than Ei. All Ais are in non-descending order. When several updates happen at the same time, you should apply them in the order they're given in the input file.
All Ti, Di, Ai, Bi and Ei in the input file are dates in format YYYY-MM-DD hh:mm. All dates are between 2009-01-01 00:00 and 2009-12-31 23:59, inclusive.
Output just one number — the fraction of time from T1 to T2 during which the schedule was valid according to the labour rules. Your answer will be accepted when it's within 10-6 absolute or relative error of the correct one.
Here's what happens in the example case. We're only interested in a part of a day, from 9 in the morning to 22 in the evening. Initially, Vasya is scheduled to perform the duties from 9 in the morning to 14 in the afternoon, and Vanya is scheduled to perform the duties from 14 in the afternoon to 22 in the evening. This means Vasya works only during the working hours, and Vanya gets all the hard work of 4 non-working hours, which is more than the maximum of 2 allowed. Thus this schedule is invalid according to the labour rules.
However, at 15 in the afternoon the schedule is updated. Now, Vasya is performing the duties from 9 to 14 and from 16 to 20, and Vanya is performing the duties from 14 to 16 and from 20 to 22. This means 2 non-working hours for each of the Guardians, which is allowed under the labour rules.
So the schedule was invalid from 9 in the morning to 15 in the afternoon, and valid from 15 in the afternoon to 22 in the evening, which corresponds to the fraction of 7/13.
Codeforces (c) Copyright 2010-2019 Mike Mirzayanov