Unneighbourly Plans


Submit solution

Points: 1
Time limit: 1.5s
Memory limit: 256M

Author:
Problem type
Allowed languages
C++, Java, Python

Ray and Justin are moving to Sydney and are picking places to stay. They don't like each other so they have decided to come together and pick places that are as far away as possible.

Help them pick a pair of houses from the possibilities that have the maximum Euclidean distance from each other. Euclidean distance is defined using Pythagoras' Theorem as d=\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}.

Input

The first line contains a single integer n\ (1 \leq n \leq 1000). The next n lines each contain two integers separated by a space of the form x_i\ y_i\ (1 \leq x_i,y_i \leq 10^6) representing the coordinates of the ith place Ray is willing to live.

The same is repeated for Justin's properties; the next line contains a single integer m\ (1 \leq m \leq 1000). The next m lines similarly contain two integers separated by a space between 1 and 10^6 each representing the coordinates of each place Justin is willing to live at.

Output

Output the x and y coordinates Ray should live at on one line, followed by the coordinates Justin should live at on the next line.

If there is a tie, use the point that occurs earliest in Ray's list. If there is still a tie, use the point that occurs earliest in Justin's list.

Hint: When calculating distances, it is possible for a regular 32-bit int to be overflown (10^6\times 10^6=10^12>2^32). It is good practice to calculate and check these things generally in contests yourselves, but we'll tell you this time that you should use a bigger type like long long or int64_t (C++).

Example 1

Input 1
2
10 5
5 7
2
1 3
4 2
Output 1
10 5
1 3
Explanation 1

The distance between (10,5) and (1,3) is \sqrt{(10-1)^2+(5-3)^2}\approx9.22. This is the furthest distance between any pair of properties in either list, so this is where they should choose to live.

Input 2
3
0 0
1 1
2 2
3
3 0
0 3
-1 2
Output 2
0 0
3 0
Explanation 2

It's evident that the maximum distance between any pair of properties is 3, but there are multiple pairs with this distance, so the tiebreaker should be used. The pairs with this distance are (0,0)-(3,0), (0,0)-(0,3), and (2,2)-(-1,2). As stated, we should use the point that occurs earliest in Ray's list, so out of (0,0) and (2,2) we will be picking (0,0). However, there is still a tie, so we should use the point that occurs earlier in Justin's list - that being (3,0).


Comments

There are no comments at the moment.