1 #include<iostream>
2 #include<cstdio>
3 #include<cmath>
4 #include<cstring>
5 #define LL unsigned long long
6 using namespace std;
7 int n,m;
8 LL ans=0,x,y;
9 long long a,b,c,p[100001],val[100001];
10 inline long long read(){
11 long long x=0,f=1;
12 char ch;
13 ch=getchar();
14 while (ch<'0'||ch>'9'){
15 if (ch='-')f=-1;
16 ch=getchar();
17 }
18 while (ch>='0'&&ch<='9'){
19 x=x*10+ch-'0';
20 ch=getchar();
21 }
22 return x*f;
23 }
24 inline LL Min(LL x,LL y){
25 if (x<y)return x;
26 else return y;
27 }
28 inline LL Max(LL x,LL y){
29 if (x>y)return x;
30 else return y;
31 }
32 int main(){
33 n=read();
34 m=read();
35 for (register int i=1;i<=m;++i)p[i]=read();
36 memset(val,0,sizeof(val));
37 for (register int i=1;i<m;++i){
38 x=Max(p[i],p[i+1]);
39 y=Min(p[i],p[i+1]);
40 val[y]++;
41 val[x]--;
42 }
43 for (register int i=1;i<=n;++i)val[i]+=val[i-1];
44 for (register int i=1;i<n;++i){
45 a=read();b=read();c=read();
46 ans+=Min(a*val[i],b*val[i]+c);
47 }
48 cout<<ans;
49 }