import strutils, sequtils, sugar let n = parseInt stdin.readLine a = (n-1).newSeqWith parseInt stdin.readLine bcs = n.newSeqWith stdin.readLine.split.map parseInt xs = newSeq.collect: for bc in bcs: let b = bc[0] c = bc[1] c - b var cnt = 0 ans = 0 for i, v in a: cnt += xs[i] ans += v * cnt echo ans