Train Travel

No attempts yetTime limit1sMemory limit256 MB

Problem

There are NN cities on a line numbered 11 to NN. Rail ii connects cities ii and i+1i+1 bidirectionally.

For each rail you may pay ticket fare AiA_i per ride, or buy a rail-specific IC card for CiC_i once and pay BiB_i per ride on that rail (Ai>BiA_i > B_i). You start with no cards.

You visit cities P1,P2,,PMP_1, P_2, \ldots, P_M in order, moving from PjP_j to Pj+1P_{j+1} on day jj. Minimize total spending on card purchases plus rides.

Input

Line 1: NN, MM. Line 2: P1,,PMP_1, \ldots, P_M. Next N1N-1 lines: AiA_i, BiB_i, CiC_i for rail ii.

Output

Print the minimum total cost.

Constraints

2N,M1000002 \leq N, M \leq 100000, 1Bi<Ai1000001 \leq B_i < A_i \leq 100000, 1Ci1000001 \leq C_i \leq 100000, 1PjN1 \leq P_j \leq N, and PjPj+1P_j \neq P_{j+1}.