This problem has nothing to do with Little Chris. It is about hill climbers instead (and Chris definitely isn't one).
There are
n hills arranged on a line, each in the form of a vertical line segment with one endpoint on the ground. The hills are numbered with numbers from 1 to
n from left to right. The
i-th hill stands at position
xi with its top at height
yi. For every two hills
a and
b, if the top of hill
a can be seen from the top of hill
b, their tops are connected by a rope. Formally, the tops of two hills are connected if the segment connecting their top points does not intersect or touch any of the other hill segments. Using these ropes, the hill climbers can move from hill to hill.
There are
m teams of climbers, each composed of exactly two members. The first and the second climbers of the
i-th team are located at the top of the
ai-th and
bi-th hills, respectively. They want to meet together at the top of some hill. Now, each of two climbers move according to the following process:
-
if a climber is at the top of the hill where the other climber is already located or will come eventually, the former climber stays at this hill;
-
otherwise, the climber picks a hill to the right of his current hill that is reachable by a rope and is the rightmost possible, climbs this hill and continues the process (the climber can also climb a hill whose top is lower than the top of his current hill).
For each team of climbers, determine the number of the meeting hill for this pair!
Output
In a single line output
m space-separated integers, where the
i-th integer is the number of the meeting hill for the members of the
i-th team.