Problem H
Same Slides
Wally’s Water Park has a special feature! Each day of the year, there is a unique set of slides that are open for operation. Each year the exact same sets of slides are open on each day. For example, the sets of slides open for operation on March 8th, 2025 would be the same as the set of slides open for operation on March 8th, 2028. You have a special pass that gives you free access to the park, but only every $n$ days. Today, you had a great time at the park, and you would like to know how long you have to wait until the next time you can experience the same set of slides again for free.
Wally’s Water Park exists on a special planet where every month has 31 days, except February (Month 2), which has 28 days. On leap years, February has 29 days instead. Every year still has 12 months. Leap years occur when the year is a multiple of 4, except for years evenly divisible by 100 but not by 400. As an example, the years 1996, 2000, 2024 are leap years, but the years 1900, 2025 are not leap years.
Input
The first line of input consists of four integers $1 \leq n \leq 10$, $1 \leq y \leq 100000$, $1 \leq m \leq 12$, and $1 \leq d \leq 31$. $y$ is today’s year, $m$ is today’s month, and $d$ is today’s date.
Output
Output the minimum number of days that you have to wait until you can experience the same set of slides again. If the date is invalid, output ‘IMPOSSIBLE’.
Sample Input 1 | Sample Output 1 |
---|---|
7 2025 3 8 |
1477 |
Sample Input 2 | Sample Output 2 |
---|---|
1 1000 2 29 |
IMPOSSIBLE |