Flying Squirrel

There are N upright poles placed in a row, numbered 1,2,,N from left to right. The ith pole is affixed to a position Di right of the origin, and extends from the ground to a height Hi. In addition, pole 1 stands right on the origin, i.e. D1=0.

A flying squirrel rests at height L on pole 1. Now, the squirrel wants to go through all the poles from left to right, and ultimately reach a height R on pole N.

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 d in height whenever it glides d units towards the right. The squirrel must not land on the ground between poles, but may reach a pole exactly at height 0.

The flying squirrel may also climb up or down each pole. On any pole i, it takes Wi effort for the squirrel to climb 1 unit up the pole, and no effort for it to climb down. The squirrel cannot climb above its current pole's height Hi, or into the ground.

Figure 1 below shows a valid path the squirrel may take.

Figure 1
Figure 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 2.
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 N, the number of poles in the arrangement.
N lines of input follow. The ith of these lines contains 3 integers Di, Hi, and Wi, denoting that the ith pole is located Di from the left, has a height of Hi, and requires Wi effort for the flying squirrel to ascend one unit on.
One line of input follows. This line contains 2 integers Li and Ri, the initial height of the squirrel on the 1st pole and its destination height on the Nth 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 1 if no such path exists.

Limits

2N500000.
0=D1<D2<<DN109.
1Hi109 (1iN)
0Wi109 (1iN)
0LH1
0RHN
Subtask # Score Constraints
1 4 Wi=0 (1iN)
2 13 Wi=1 (1iN)
3 18 WiWi+1 (1iN1)
4 15 N500
Hi500 (1iN)
5 18 N5000
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 23+26=18.



Submitting to 'Flying Squirrel'


You're not logged in! Click here to login


Submitting to 'Flying Squirrel'


You're not logged in! Click here to login


Submitting .cpp to 'Flying Squirrel'


You're not logged in! Click here to login

Time Limit: 3 Seconds
Memory Limit: 1024MB
Your best score: 0
Source: Korean IOI Selection Day 1

Subtask Score
1 4
2 13
3 18
4 15
5 18
6 32
7 0