spoj#MACVSMAG. Machau vs Maggu
Machau vs Maggu
You will find three types of people in an engineering college Maggu,Machau and Others. We all know how much hard Maggu people try to portray themselves as Machau but they never succeed. Today Machau people have decided to recruit few Maggus and convert them to Machau. All the Maggus who wanted to become Machau had to reach Machau Club situated at YAY MACHAU" from their current location A. Machau people had laid many books everywhere on the campus to distract Maggus and make it difficult for them to reach Machau club. The campus can be imagined as a large NxN grid in which Maggu is located at position Awhich is denoted by (Ax,Ay) coordinate and the Machau Club is located at position B which is denoted by (Bx,By) coordinate. Machau people had laid books at M random locations denoted by (Xi,Yi) where 1<=i<=M.Additionally to prevent Maggus who take up the challenge to runaway Machau people laid books everywhere outside the rectangular area where Maggu's location A and Machau Club's location B are are ends of the diagonal of that rectangular area. A Maggu can only walk in left,right,up or downdirections from his current place as long as he doesn't leave the campus i.e. he stays inside the NxN grid. If a Maggu wants to become Machau he must reach Machau Club without touching a single book in his path and without leaving the campus grid.
More formally stating the problem: Given an N x N grid with M non reachable cells.Test whether cell "B" can be reached from cell"A" provided only left,right,up and down movements are valid.
You must print "YAY MACHAU" if it is possible for a Maggu to reach Machau Club else print "MAGGU FOREVER"
Input
First line will contain 6 integers N,M,Ax,Ay,Bx and By Where, N=No.of rows and columns in campus grid
M=Total number of books laid on the campus
Ax,Ay=Coordinates of Maggu
Bx,By=Coordinates of Machau Club
Next M lines will contain Xi and Yi denoting coordinates on NxN grid which contain books to distract MAGGUS
NOTE: If any book is placed in position A or B MAGGU will always be distracted. All (Xi,Yi) pairs are not guaranteed to be distinct.
Output
Print "YAY MACHAU" if Maggu can reach Machau club otherwise print "MAGGU FOREVER" [without quotes]
Constrains
1<=N<=10^9
1<=M<=10^5
1<=Ax,Ay,Bx,By,Xi,Yi<=N
Sample Input
1000 2 10 1000 1000 10
1 1
100 100
Sample Output
YAY MACHAU