2312.The Same Calendar

Time Limit: 1s Memory Limit: 256MB

The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.

The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year.

Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (https://en.wikipedia.org/wiki/Leap_year).

Input Format(From the terminal/stdin)

The only line contains integer y (1000 \le y \lt 100'000) - the year of the calendar.

Output Format(To the terminal/stdout)

Print the only integer y' - the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar.

Sample Input 1

Copy
2016
    \n

Sample Output 1

Copy
2044
    \n

Sample Input 2

Copy
2000
    \n

Sample Output 2

Copy
2028
    \n

Sample Input 3

Copy
50501
     \n

Sample Output 3

Copy
50507
     \n

Hints

Today is Monday, the 13th of June, 2016.

Submit

请先 登录

© 2025 FAQs