Stupid with Love


Submit solution

Points: 1
Time limit: 1.5s
Memory limit: 256M

Author:
Problem type

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 10 + 5 \times 9 = 10 + 45 = 55, but Cady is going to calculate it as ((10 + 5) \times 9) = 15 \times 9 = 135. 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 n (1 \leq n \leq 10^5), the number of expressions in Cady's quiz.

The next n lines are mathematical expressions in the form [m] [number] [operation] [number] [operation] ... [number], where m (1 \leq m \leq 8) is the number of terms (numbers) in the expression. These terms can be anything between 1 and 10 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
  • 1 + 2 \times 3 + 4 = 1 + 6 + 4 = 11 is correct, but Cady will calculate it as ((3 \times 3) + 4) = 9 + 4 = 13, so she gets |11-13| = 2 wrongness.
  • 2 + 4 \times 3 = 2 + 12 = 14 is correct, but Cady will calculate it as (2 + 4) \times 3 = 6 \times 3 = 18, so she gets |14 - 18| = 4 wrongness.
  • 1 + 1 = 2 using both methods, so Cady gets 0 wrongness for this expression.

Cady's total wrongness is 6 for this quiz.


Comments

There are no comments at the moment.