Bolder Yarn Knots
Gats found a row of yarn knots. The knots are numbered through from left to right, and knot has height .
Gats starts on some knot and repeatedly jumps according to the following rules.
For his current knot :
- On the left, consider the closest knot such that and .
Every jump goes to a knot with strictly larger height, so Gats eventually stops.
You are given starting knots. For each starting knot, determine where Gats stops and the total distance he travels.
Input
The first line contains two integers and (), the number of knots and the number of starting questions.
Output
For each query, print two integers and on one line. Here, is the index of the knot where Gats stops when starting from , and is the total distance he travels, equal to the sum of over all jumps from knot to knot .
Samples
Sample 1
Input
7 4 3 1 4 2 5 2 6 1 2 4 7
Output
7 6 7 5 7 3 7 0
For , the walk is , so and . For , the walk is . For , Gats is already at a stopping knot.