n = int(raw_input()) fee = [] for i in range(0, n-1): fee.append(int(raw_input())) b, c = map(int, raw_input().split()) now = c sum = 0 for i in range(0, n-1): sum += fee[i]*now b, c = map(int, raw_input().split()) now = now - b + c print sum