import std.algorithm; import std.conv; import std.stdio; import std.string : chomp; void main(string[] args) { immutable n = readln.chomp.to!int; int[100] tariff, cumsum; foreach (i; 0..n - 1) { tariff[i + 1] = readln.chomp.to!int; } foreach (i; 1..n) { cumsum[i] = cumsum[i - 1] + tariff[i]; } int total; foreach (i; 0..n) { int[2] passengers; readln.splitter.map!(to!int).copy(passengers[]); total += cumsum[i] * passengers[0]; total -= cumsum[i] * passengers[1]; } writeln(total); }