403074: GYM100989 L Plus or Minus (A)
Description
AbdelKader enjoys math. He feels very frustrated whenever he sees an incorrect equation and so he tries to make it correct as quickly as possible!
Given an equation of the form: A1 o A2 o A3 o ... o An = 0, where o is either + or -. Your task is to help AbdelKader find the minimum number of changes to the operators + and -, such that the equation becomes correct.
You are allowed to replace any number of pluses with minuses, and any number of minuses with pluses.
InputThe first line of input contains an integer N (2 ≤ N ≤ 20), the number of terms in the equation.
The second line contains N integers separated by a plus + or a minus -, each value is between 1 and 108.
Values and operators are separated by a single space.
OutputIf it is impossible to make the equation correct by replacing operators, print - 1, otherwise print the minimum number of needed changes.
ExamplesInput7Output
1 + 1 - 4 - 4 - 4 - 2 - 2
3Input
3Output
5 + 3 - 7
-1