using System; using System.Collections.Generic; using System.Linq; class Solution { static void Main() { var n = int.Parse(Console.ReadLine()); var a = new int[n]; var b = new int[n]; var c = new int[n]; for (int i = 1; i < n; i++) { a[i] = int.Parse(Console.ReadLine()); } for (int i = 0; i < n; i++) { var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); b[i] = vals[0]; c[i] = vals[1]; } int pay = 0; int customer = 0; for (int i = 0; i < n; i++) { pay += a[i] * customer; customer += c[i] - b[i]; } Console.WriteLine(pay); } }