Neighbourly Plans I
Neighbourly Plans I
After graduating from RSP, Tom and Patrick can't wait to move to Sydney! Since they are such good friends, they want to live as close to each other as possible. But, they're not that good friends, so they don't want to be in the same location.
Instead, they want to live as close as possible to each other (Euclidean distance), without being in the same location.
Recently, Tom and Patrick looked at several properties. They have a list of everywhere they would each be willing to live at, including their longitude and latitude.
Which two locations are optimal for Tom and Patrick to live as close as possible, and who will live where?
Input
The first line of each test case consists of an integer
, the number of properties Tom is willing to live at.
The next lines of each case are in the form
, representing the position of a place Tom is willing to live at.
The next line of each case consists of an integer
, the number of properties Patrick is willing to live at.
The next lines of each case are in the form
, representing the position of a place Patrick is willing to live at.
Output
Output the longitude and latitude Tom should live at on one line, followed by the longitude and latitude Patrick should live at on the next line - so that Tom and Patrick live as close as possible to each other.
Note: In the case of a tie, use the earliest place in Tom's list. If it's still a tie, use the earliest place in Patrick's list.
Note: There is guaranteed to be a solution!
Example
Input
2
25 25
13 16
2
25 25
14 16
Output
13 16
14 16
The closest pair of locations Tom and Patrick are happy to live at is unit apart.
_Note: Remember, they don't want to live in the exact same location!_
Input
3
1 1
2 2
3 3
3
3 1
2 2
1 3
Output
1 1
2 2
Comments