#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // C++ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include //#include #define rep(i,j,k) for(int i=(int)j;i<(int)k;i++) #define ll long long #define Sort(v) sort(all(v)) #define INF 1000000000 #define END return 0 #define pb push_back #define se second #define fi first #define pb push_back #define all(v) (v).begin() , (v).end() #define MP make_pair #define MOD 1000000007LL; using namespace std; int day[12]={31,28,31,30,31,30,31,31,30,31,30,31}; int main (){ int n; cin>>n; vector a(n-1),b(n),c(n); rep(i,0,n-1)cin>>a[i]; rep(i,0,n)cin>>b[i]>>c[i]; ll ans=0; ll isRide=0; isRide+=c[0]; rep(i,1,n){ ans+=isRide*a[i-1]; isRide-=b[i]; isRide+=c[i]; } cout<