403075: GYM100989 M Plus or Minus (B)
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
M. Plus or Minus (B)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
George met AbdelKader in the corridor of the CS department busy trying to fix a group of incorrect equations. Seeing how fast he is, George decided to challenge AbdelKader with a very large incorrect equation. AbdelKader happily accepted the challenge!
InputThe first line of input contains an integer N (2 ≤ N ≤ 300), 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 300.
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