/* -*- coding: utf-8 -*- * * 633.cc: No.633 バスの運賃 - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100; /* typedef */ typedef vector vi; typedef queue qi; typedef pair pii; /* global variables */ int as[MAX_N], bs[MAX_N], cs[MAX_N]; /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n - 1; i++) scanf("%d", &as[i]); for (int i = 0; i < n; i++) scanf("%d%d", &bs[i], &cs[i]); int k = 0, sum = 0; for (int i = 0; i < n - 1; i++) { k += cs[i] - bs[i]; sum += as[i] * k; } printf("%d\n", sum); return 0; }