A new school year has begun, which means you'll have to ride the bus through traffic jams to the university again.
You know that there are n intersections with traffic lights between the starting and ending stops.
The starting stop is located immediately after intersection 0, and the ending stop is just after intersection n.
You know that the bus takes ai seconds to travel from the (i - 1)-th intersection to the i-th intersection. The time spent at stops can be neglected.
For the traffic light at the i-th intersection, three characteristics are known:
If the bus arrives exactly when the light switches to red, it will not be able to pass.
Using all this information, determine how many seconds the entire bus trip will take from start to finish.
The first line contains an integer n (1 ≤ n ≤ 104) — the number of intersections on your way.
The second line contains integers a1, a2, ..., an (1 ≤ ai ≤ 104, i = 1, 2, ..., n) — the time it takes for the bus to travel from the (i - 1)-th to the i-th intersection.
Each of the following n lines contains three integers ri, gi, di (1 ≤ ri, gi ≤ 1000, 1 ≤ di ≤ 104) — the characteristics of the i-th traffic light.
In a single line, output an integer — the time it will take for you to travel by bus from the starting stop to the ending stop.
3
100 110 50
80 20 50
60 10 100
30 40 50
370
First test example
| Name |
|---|


