#!/usr/bin/env python3 import sys def main(): N = int(input()) A = [int(input()) for _ in range(N - 1)] num = 0 ans = 0 for i in range(N): B, C = map(int,input().split()) num += C - B if i == N - 1: break ans += A[i] * num print(ans) return if __name__ == '__main__': main()