There are upright poles placed in a row, numbered from left to right. The pole is affixed to a position right of the origin, and extends from the ground to a height . In addition, pole stands right on the origin, i.e. .
A flying squirrel rests at height on pole . Now, the squirrel wants to go through all the poles from left to right, and ultimately reach a height on pole .
To get between poles, the flying squirrel can glide from one adjacent pole to the next - the squirrel glides in perfect diagonals, dropping a distance in height whenever it glides units towards the right. The squirrel must not land on the ground between poles, but may reach a pole exactly at height .
The flying squirrel may also climb up or down each pole. On any pole , it takes effort for the squirrel to climb unit up the pole, and no effort for it to climb down. The squirrel cannot climb above its current pole's height , or into the ground.
Figure 1 below shows a valid path the squirrel may take.
Figure 1Figure 2 below shows two invalid paths. The left path is invalid as the flying squirrel lands on the ground between poles; while the right path is invalid as the squirrel does not land on pole .
Figure 2
Your task is to determine the minimum effort required for the flying squirrel to get to its target position, passing through all poles in between.
Input format
The first line of input consists of a single integer , the number of poles in the arrangement.
lines of input follow. The of these lines contains 3 integers , , and , denoting that the pole is located from the left, has a height of , and requires effort for the flying squirrel to ascend one unit on.
One line of input follows. This line contains 2 integers and , the initial height of the squirrel on the pole and its destination height on the pole respectively.
Output format
Output a single integer on a single line - the minimum effort required for the squirrel to reach its destination through a valid path, or if no such path exists.
Limits
.
.
Subtask #
Score
Constraints
1
4
2
13
3
18
4
15
5
18
6
32
No additional constraints
Samples
Sample Input 1
Sample Output 1
3
0 8 3
2 5 4
5 5 6
5 4
18
In this input example, it is optimal for the squirrel to climb 2 units up pole 1 to reach a height of 7, glide to the top of pole 2 and then to height 3 on pole 3, before climbing 2 units up pole 3 to reach its destination.
This takes a total effort of .