Stupid with Love
Cady has a huge crush on Aaron Samuels, who sits in front of her in math class. But how can she get him to talk to her?
That's it! If she acts dumb, she can convince Aaron to be her tutor! But how can she do it? For this basic math quiz, she'll ignore order of operations, and just evaluate the operations from left to right.
For example, the expression , but Cady is going to calculate it as
. Usually multiplication would go first, but because Cady is evaluating from left-to-right, the plus goes first instead.
The amount of "wrongness" Cady gets from a question is equal to the absolute difference between her answer and the correct value of the expression. Given a series of expressions, figure out just how wrong Cady is.
Input
The first line consists of an integer
, the number of expressions in Cady's quiz.
The next lines are mathematical expressions in the form
[m] [number] [operation] [number] [operation] ... [number]
, where
is the number of terms (numbers) in the expression. These terms can be anything between
and
inclusive, and the operations can be addition (
+
), subtraction (-
) or multiplication (*
).
Output
Calculate the total "wrongness" Cady will get by evaluating the equations badly.
Example
Input
3
4 1 + 2 * 3 + 4
3 2 + 4 * 3
2 1 + 1
Output
6
is correct, but Cady will calculate it as
, so she gets
wrongness.
is correct, but Cady will calculate it as
, so she gets
wrongness.
using both methods, so Cady gets
wrongness for this expression.
Cady's total wrongness is 6 for this quiz.
Comments