Problem:
Score : 300 points

Problem Statement

You are given an integer sequence of length N. The i-th term in the sequence is a_i.
In one operation, you can select a term and either increment or decrement it by one.

At least how many operations are necessary to satisfy the following conditions?

For every i (1≤i≤n), the sum of the terms from the 1-st through i-th term is not zero.

For every i (1≤i≤n-1), the sign of the sum of the terms from the 1-st through i-th term, is different from the sign of the sum of the terms from the 1-st through (i+1)-th term.

Constraints

2 ≤ n ≤ 10^5

|a_i| ≤ 10^9

Each a_i is an integer.

Input

Input is given from Standard Input in the following format:

n
a_1 a_2 ... a_n

Output

Print the minimum necessary count of operations.

Sample Input 1

4
1 -3 1 0

Sample Output 1

4

For example, the given sequence can be transformed into 1, -2, 2, -2 by four operations. The sums of the first one, two, three and four terms are 1, -1, 1 and -1, respectively, which satisfy the conditions.

Sample Input 2

5
3 -6 4 -5 7

Sample Output 2

0

The given sequence already satisfies the conditions.

Sample Input 3

6
-1 4 3 2 -5 4

Sample Output 3

8

Solution in JavaScript (node.js v5.12) (judge verdict: Wrong Answer)

var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
	var N = nextInt();
	var list = nextIntArray();
	var oddCount = 0;
	var evenCount = 0;
	var oddSum = new Array(N);//1, -1, 1, -1
	var evenSum = new Array(N);//-1, 1 ,-1 ,1
	if(list[0] == 0){
		oddCount++;
		evenCount++;
	}else{
		if(list[0] < 0){
			oddCount += Math.abs(list[0]) + 1;
			oddSum[0] = 1;
			evenSum[0] = list[0];
		}else{
			evenCount += Math.abs(list[0]) + 1;
			evenSum[0] = -1;
			oddSum[0] = list[0];
		}
	}
	for(var i = 1; i < N; i++){
		oddSum[i] = oddSum[i - 1] + list[i];
		evenSum[i] = evenSum[i - 1] + list[i];
		if((oddSum[i - 1] < 0 && oddSum[i] > 0) || (oddSum[i - 1] > 0 && oddSum[i] < 0)){
			
		}else{
			if((oddSum[i - 1] > 0)){
				oddCount += oddSum[i] + 1;
				oddSum[i] = -1;
			}else{
				oddCount += Math.abs(oddSum[i]) + 1;
				oddSum[i] = 1;
			}
		}
		if((evenSum[i - 1] < 0 && evenSum[i] > 0) || (evenSum[i - 1] > 0 && evenSum[i] < 0)){
			
		}else{
			if((evenSum[i - 1] > 0)){
				evenCount += evenSum[i] + 1;
				evenSum[i] = -1;
			}else{
				evenCount += Math.abs(evenSum[i]) + 1;
				evenSum[i] = 1;
			}
		}
	}
	myout(Math.min(evenCount, oddCount));
}