def main(): n = int(input()) a = [int(input()) for _ in range(n-1)] b = [] c = [] for _ in range(n): b_, c_ = map(int, input().split()) b.append(b_) c.append(c_) current = 0 fee_sum = 0 for fee, exit, enter in zip(a, b, c): current += (enter-exit) fee_sum += current * fee print(fee_sum) if __name__ == "__main__": main()