James is practicing his parkour skills at a local urban park. The park has pillars of varying heights arranged in a line. James moves between these pillars by either performing a Hip, meaning he moves to an adjacent pillar; or a Hop, meaning he hops to the second pillar to his left or right.
James is practicing routes along these pillars. Each route consists of a start and end destination. James' biggest concern is the effect the elevation changes have on his knees, so he would like to minimize the sum of the differences in heights for each Hip and Hop he makes.
Input Specification
The input begins with two integers . The next line contains integers , the height of a pillar. The next lines each contain two integers , the start and finish pillar for each route.
For 30% of cases, .
For 60% of cases, .
Output Specification
For each route, output the minimum sum of the differences in heights for each Hip or Hop that James takes.
Sample Input 1
5 3
1 4 2 1 2
1 3
5 1
2 5
Sample Output 1
1
1
2
Comments