First Date

Time limit10sMemory limit512 MB

Summary
For each given last Julian calendar date, print the next day written as a Gregorian date.
Level

Medium4 of 10

Topics
Simulation, Math
Solved
No attempts yet

Problem

In 1582, Pope Gregory XIII decreed a calendar reform so that the mean length of the calendar year, counted in days, would sit closer to the length of an astronomical year. The reform replaced the Julian calendar with the Gregorian calendar.

Both calendars have regular years of 365 days and leap years of 366 days. February has 28 days in a regular year, and in a leap year it gains one extra day, February 29.

The only difference between the two calendars is the rule that decides which years are leap years. In the Julian calendar, every year divisible by 4 is a leap year. In the Gregorian calendar a year divisible by 4 is a leap year as well, except when it is divisible by 100 and not by 400.

Under those rules, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300 and 2400 are all leap years in the Julian calendar. Of that list, only 1600, 2000 and 2400 are leap years in the Gregorian calendar.

The Julian calendar has a mean year length of 365.25 days and the Gregorian calendar has a mean year length of 365.2425 days. An astronomical year is about 365.24219 days, so the Gregorian value is much closer.

The reform also skipped a run of dates, to undo the drift that more than 1500 years of the Julian calendar had built up. It declared that October 4, 1582 in the Julian calendar was followed directly by October 15, 1582 in the Gregorian calendar.

By the end of the 16th century the Reformation was under way. Catholic countries tended to obey the papal decree, but many other countries kept the Julian calendar for much longer. The United Kingdom switched on September 2, 1752 (Julian), which was followed by September 14, 1752 (Gregorian). Eleven dates had to be skipped by then. The last European country to switch was Greece, where February 15, 1923 (Julian) was followed by March 1, 1923 (Gregorian), skipping 13 dates.

You are given the last day on which the Julian calendar was in effect for some country, written as a Julian date. Determine the next day's Gregorian date, that is, the first date that country wrote in the Gregorian calendar.

Input

Each line contains one date in the Julian calendar, formatted as YYYY-MM-DD. The date is no earlier than October 4, 1582 and no later than October 18, 9999. It is the last day on which the Julian calendar is in effect for some country. Read lines until the end of input.

Output

For every given date, print the first Gregorian date after that country's calendar transition, formatted as YYYY-MM-DD, one per line and in the same order as the input.

Examples1

  1. Example 1

    Input
    1582-10-04
    1752-09-02
    1900-02-25
    1923-02-15
    
    Expected output
    1582-10-15
    1752-09-14
    1900-03-10
    1923-03-01