LCC '25 Contest 1 S5 - Moonlight's Box Challenge
View as PDF is a devious person, and hates seeing people happy. The one thing he hates more than people being happy is  specifically being happy. After plotting for a year,  has created a machine that allows him to teleport anything into a box he's created. The box isn't your typical box, either. It comprises of  dimensions, specifically to trap devious little creatures from escaping from his grasp. To add insult to injury,  has chosen the perfect time to strike, Halloween, so  will miss out on candy. On the day of Halloween, instead of letting him go trick-or-treating,  has decided to put   into an 
-dimensional box. The box has one vertex at 
, and the 
 dimension of the box has side length 
. However,   isn't pleased with being stuck in this box, and still wants to go trick-or-treating. There are houses located at each vertex of the box, more formally where the 
th coordinate is either 
 or 
, and  wants to eventually end up at one of these vertices, so he can fulfill his lifelong dreams of collecting candy.
Unfortunately, isn't the sharpest tool in the shed. Once he starts moving in a direction, he's unwilling to change directions unless he reaches a face of the box. When he reaches the face of the box, will change directions such that his new direction is his old direction reflected along the normal to this plane. Below is an example of bouncing in a 2-dimensional space.

 is given a direction vector (, 
, ..., 
) to start with, and an initial position (
, 
, ..., 
). Please help him determine whether or not it is possible for him to reach a corner of the box.
Input Specification
The first line of input will contain one integer , the number of dimensions of the box.
The next line of input will contain  space-separated integers, representing 
, the dimensions of the box.
The following line of input will contain another  space-separated integers, representing 
, the starting position of 
The final line of input will contain  space-separated integers, representing 
, the initial direction vector that  moves in.
Output Specification
On one line, output YES if he can reach a house, and NO if  cannot.
Constraints
Subtask 1 [20%]
Subtask 2 [30%]
Subtask 2 [50%]
No additional constraints
Sample Input 1
2
4 4
1 3
3 1Output for Sample Input 1
YESExplanation of Output for Sample Input 1
After one unit of time, he will have travelled to the point , which is a corner.
Sample Input 2
2
4 4
1 3
3 0Output for Sample Input 2
NOExplanation of Output for Sample Input 2
Note that no matter how  moves, he will always have a -coordinate of 
, and no corners have a 
-coordinate of 
. This means he will never reach a corner.
Comments