ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

1841. Cableways

Time limit: 1.0 second
Memory limit: 64 MB
Vova bought a new wide-angle lens for his camera a few days ago. Now he wants to take a panoramic photo with this lens, and that is the reason why he decided to climb the nearest hill.
There is a single narrow serpentine path leading from base of the hill to its top. Vova introduced coordinate axes in such a way that OY is directed along the hill side from base to top and OX is orthogonal to it. The path is represented as a polyline with n segments, vertices of which follow in the order of strictly increasing y-coordinate. For each segment of the path, Vova knows the time required to change x-coordinate by one while moving along this segment.
Moreover, Vova can use cableways. They start at some point of the path, run strictly up the hill parallel to OY axis and end at the next intersection with the path. Vova knows the time required to use each cableway.
Help Vova climb the hill before it gets dark! Note that Vova is so determined that he will refuse to go down the hill even if this action helps him to climb the hill faster.

Input

The first line contains a number of segments in the path n (1 ≤ n ≤ 105). The next line contains n + 1 integers which are x-coordinates of polyline vertices in the order from base to top. No two consecutive vertices have the same x-coordinate. The i-th of the following n lines contains integers vi and mi which are time required to change x-coordinate by one while moving along the i-th segment and a number of cableways starting at the i-th segment, respectively. The rest of this line contains mi pairs of integers describing the cableways. Each cableway is described with x-coordinate of its start point and time required to use this cableway. The cableways are described in the order from base to top. No two cableways start at the same point. If a cableway starts at the common point of two path segments, it encounters in the description of only one segment. It is guaranteed that each cableway ends somewhere on the path. All numbers in lines are separated by spaces. All coordinates don't exceed 106 in their absolute value. All times are positive and don't exceed 106. The total number of cableways doesn't exceed 105.

Output

Output the minimal time required to climb the hill.

Samples

inputoutput
4
0 5 15 10 0
1 1 1 100
1 1 7 1
1 0
1 0
15
3
0 10 0 10
10 0
10 1 10 1
10 0
101
Problem Author: Denis Dublennykh
Problem Source: Ural SU Contest. Petrozavodsk Summer Session, August 2010