NOI Contest Archive

Archive / 2020 / February 2020

Full Moon Day

Medium · National Olympiad in Informatics Sri Lanka - February 2020

In a galaxy far, far away, there’s a planet named Planet-X. This planet has M months per year and D days per month. However, unlike planet Earth it has N number of moons. Each moon takes a different number of days (Xn) to orbit Planet-X. So, on this planet a day is called a Full Moon day, if all the moons get its lunar phase as Full Moon on that day. ( A lunar phase of a moon is the shape of the sunlit portion of the moon i.e. the visible portion of the moon )

Given a date of a full moon day(D1), your task is to find whether the 2nd date(D2) is a full moon day. If it’s not a full moon day, find C, the number of days to the closest full moon day.

Input Format

First line contains 3 integers, M, D & N.
Next line contains N integers, X1, X2, …, Xn
Next line contains 3 integers, y1, m1, d1. The year, month and date of D1 respectively.
Last line contains 3 integers, y2, m2, d2. The year, month and date of D2 respectively.

Output Format

If D2 is a Full Moon Day, print “FULL MOON DAY”.
If not, print a single positive integer C, the number of days to the closest full moon day.

Constraints

If the number of days between D1 & D2 is Z,

Limits

Sample Input 0

12 30 1
28
2019 12 10
2020 1 8

Sample Output 0

FULL MOON DAY

Sample Input 1

5 10 2
2 3
2019 1 1
2019 2 2

Sample Output 1

1