package net.ipipip0129.yukicoder.no633; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int busStopCount = Integer.parseInt(scan.nextLine()); int[] busStopMoney = new int[busStopCount - 1]; for (int i = 0; i < busStopCount - 1; i++) busStopMoney[i] = Integer.parseInt(scan.nextLine()); int busPassengers = Integer.parseInt(scan.nextLine().split(" ")[1]); int toalMonay = 0; for (int i = 0; i < busStopCount - 1; i++) { toalMonay += busStopMoney[i] * busPassengers; String[] data = scan.nextLine().split(" "); busPassengers += Integer.parseInt(data[1]) - Integer.parseInt(data[0]); } System.out.println(toalMonay); } }