Citizenship Application#2758

Citizenship Application

1 second
64 megabytes
Very easy

In Canada, after becoming a permanent resident, you may apply for citizenship. To be eligible, you must have resided in Canada for at least days (about years) during the days (about years) immediately prior to your application (the application date itself is not counted). Any days spent outside Canada do not count towards the residency requirement. Additionally, if you resided in Canada (for example, for studies) prior to becoming a permanent resident during the -day period (up to days before landing), those pre-landing days are counted as half days rounded down (for example, days count as days). Thus, the start date of residence is counted as a half day if it is before the landing date (and up to days prior), or as a whole day if it coincides with the landing date.

In this problem, you are to determine the earliest date on which you may apply for citizenship.

Input

The input consists of several cases. For each case, the first line contains the start date of residence in the country. The second line contains the date when you became a permanent resident. The third line contains an integer (0 \leq N \leq 100), the number of trips outside Canada. Each of the next lines contains two dates separated by a space, representing the start and end date (inclusive) of each trip outside Canada. You are considered to be outside Canada from the start date through the end date.

You may assume the start date of residence is not later than the permanent resident date. You may also assume that the start date of each trip is not after its end date, no trip lasts more than days, no trip includes the start date of residence or the permanent resident date, and no two trips overlap. No trip occurs before the start of residence. All dates are given in the format Month/Day/Year and are valid; none is before January 1, 1980 or after December 31, 2020.

Output

For each case, print on a single line the earliest date (in the input format) on which you may apply for citizenship.

Examples

Example 1

Loading
Loading