Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

The problem statement has recently been changed. View the changes.

×
D. Hill Climbing

time limit per test

1 secondmemory limit per test

256 megabytesinput

standard inputoutput

standard outputThis 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 *x*_{i} with its top at height *y*_{i}. 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 *a*_{i}-th and *b*_{i}-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!

Input

The first line of input contains a single integer *n* (1 ≤ *n* ≤ 10^{5}), the number of hills. The next *n* lines describe the hills. The *i*-th of them contains two space-separated integers *x*_{i}, *y*_{i} (1 ≤ *x*_{i} ≤ 10^{7}; 1 ≤ *y*_{i} ≤ 10^{11}), the position and the height of the *i*-th hill. The hills are given in the ascending order of *x*_{i}, i.e., *x*_{i} < *x*_{j} for *i* < *j*.

The next line of input contains a single integer *m* (1 ≤ *m* ≤ 10^{5}), the number of teams. The next *m* lines describe the teams. The *i*-th of them contains two space-separated integers *a*_{i}, *b*_{i} (1 ≤ *a*_{i}, *b*_{i} ≤ *n*), the numbers of the hills where the climbers of the *i*-th team are located. It is possible that *a*_{i} = *b*_{i}.

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.

Examples

Input

6

1 4

2 1

3 2

4 3

6 4

7 4

3

3 1

5 6

2 3

Output

5 6 3

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Apr/12/2021 16:34:11 (f2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|