Under construction

Still being built. Things may change

Forest for the Trees

Interview

Time limit2sMemory limit1024 MB

Summary
Given a map of tree coordinates and sensor readings taken at an unknown heading, find the robot's grid position, or report Impossible or Ambiguous.
Level

Medium5 of 10

Topics
Hash map, Brute force, Implementation
Solved
No attempts yet

Problem

You have sent a robot into a forest, and it has gotten lost. The robot has a sensor that detects all trees around it, regardless of occlusions. Unfortunately, all trees in this forest look alike. You have a map of all the trees as (x,y)(x,y) points. Every tree is at an integer coordinate, but not every integer coordinate is occupied, since this used to be a tree farm.

The robot always places itself at integer coordinates and aligned with the positive or negative xx or yy axis. It is never at the same location as a tree. Its heading relative to the map is unknown. Each sensor reading is a tuple (distance to the right of the robot, distance forward of the robot). Either value can be negative, because the sensor covers all directions. Find where the robot is.

Input

The first line contains three integers ntn_t, nsn_s, and rmaxr_{max}: the number of trees in the forest, the number of trees sensed by the robot, and the maximum Manhattan distance (sum of the absolute xx and yy distances) of any sensor reading. Each of the next ntn_t lines contains two integers xx and yy, the location of a tree in the global coordinate system. Each of the final nsn_s lines contains two integers. The first integer si,xs_{i,x} is the distance along the axis perpendicular to the robot's heading, and the second integer si,ys_{i,y} is the distance along the axis parallel to the robot's heading.

It is guaranteed that ∣si,x∣+∣si,y∣≤rmax|s_{i,x}|+|s_{i,y}| \leq r_{max} for all ii. Also, 0<nt≤50000 < n_t \leq 5000, 0<ns≤10000 < n_s \leq 1000, 0<rmax≤10000 < r_{max} \leq 1000, and −100000≤x,y≤100000-100000 \leq x,y \leq 100000 for every tree.

Output

Print the xx and yy location of the robot as two integers separated by a space. If no location on the map could produce the given sensor values, print "Impossible". If two or more distinct locations and/or orientations could produce the given sensor values, print "Ambiguous".

Examples1

  1. Example 1

    Input
    4 4 100
    1 1
    2 2
    2 1
    3 3
    0 1
    0 2
    -1 2
    -2 3
    
    Expected output
    0 1