
A Clattering of Jackdaws by Dun.can on flickr, cc by
A comment chain is alternating if the scores $$$s_1, s_2, \ldots, s_n$$$ of the comments all are non-zero, and every pair of adjacent scores $$$s_i$$$, $$$s_{i+1}$$$ have opposite signs. In particular, a single comment with a non-zero score or even a comment chain without any comment is an alternating comment chain.
There are two operations Nick can do to make the comment chain alternating:
Nick can apply these operations in any order, any number of times. How fast can he make the comment chain alternating?
For example, consider Sample Input 1 below, where the scores in the comment chain are $$$8, 8, 2, -2$$$, and it takes Nick $$$10$$$ seconds to create an account and $$$50$$$ seconds to file a report for one comment. In this case it is optimal to first create $$$3$$$ fake accounts and use them to upvote the fourth comment and downvote the third, followed by reporting the first comment. This results in the scores $$$8, -1, 1$$$, which is an alternating chain. The time used for this is $$$80$$$ seconds.
The input consists of:
Output the smallest time to make the comment chain alternating by applying the operations above.
4 10 50 8 8 2 -2
80
6 100 33 5 -13 0 0 -12 0
132