Magic Compass
InterviewTime limit1sMemory limit1024 MB
Given M compass readings that each give the direction from a cell to a hidden treasure on an N x N grid, find the treasure's cell.
- Level
Easy2 of 10
- Topics
- Brute force, Implementation
- Solved
- No attempts yet
Problem
Use a magic compass to find a treasure hidden in an area. 

The figure above shows the first sample. When the compass is activated, its red needle points toward the treasure in one of eight directions: up, down, left, right, or one of the four diagonals.
The directions are numbered 1 to 8 clockwise, starting from the top. The coordinates denote the cell in the -th row from the top and the -th column from the left. ( and are integers from 1 to .)
- Direction 1: the treasure has a smaller coordinate and the same coordinate.
- Direction 2: the treasure has a smaller coordinate and a larger coordinate.
- Direction 3: the treasure has the same coordinate and a larger coordinate.
- Direction 4: the treasure has a larger coordinate and a larger coordinate.
- Direction 5: the treasure has a larger coordinate and the same coordinate.
- Direction 6: the treasure has a larger coordinate and a smaller coordinate.
- Direction 7: the treasure has the same coordinate and a smaller coordinate.
- Direction 8: the treasure has a smaller coordinate and a smaller coordinate.
Using the records of compass uses, find the location of the treasure. The compass position and the treasure position are always different, and the answer is guaranteed to be unique.
Input
The first line contains two integers and , separated by a space. (, )
Each of the next lines contains , , and , separated by spaces. These mean that the compass was used at and the treasure was in direction from that position. (, , all integers)
Output
Print the coordinates of the cell where the treasure is hidden.