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 Rust (1.15.1) (judge verdict: Accepted)

#[test]
fn test_solve() {
    assert_eq!(solve("4\n1 -3 1 0\n"), "4\n");
    assert_eq!(solve("5\n3 -6 4 -5 7\n"), "0\n");
    assert_eq!(solve("6\n-1 4 3 2 -5 4\n"), "8\n");
}

fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let n: usize = sc.read();
    let a: Vec<isize> = (0..n).map(|_| sc.read()).collect();

    let ans: usize = [0, 1]
        .iter()
        .map(|&stt| {
            let mut sum = 0;
            let mut scr = 0;
            for i in 0..n {
                sum += a[i];
                let d = if i & 1 == stt && sum <= 0 {
                    1 - sum
                } else if i & 1 != stt && sum >= 0 {
                    -1 - sum
                } else {
                    0
                };
                sum += d;
                scr += d.abs() as usize;
            }
            scr
        })
        .min()
        .unwrap();

    format!("{}\n", ans)
}

fn main() {
    let mut buf = String::new();
    use std::io;
    use std::io::{Read, Write};
    io::stdin().read_to_string(&mut buf).unwrap();
    io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}

struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
}