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 C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

// AtCoder-Template.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second
#define FOR(i,N) for(auto i=0; i<N; ++i)
#define FORREV(i,N,_cnt) for(auto i=N-1,cnt=_cnt; cnt > 0; --i, --cnt)
#define ALL(x) x.begin(), x.end()

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T& a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T& a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
	ifstream ifs("in.txt");
	cin.rdbuf(ifs.rdbuf());
#endif
	ll N; cin >> N; vector<ll> A(N); FOR(i, N) cin >> A[i];
	// RUISEKI
	vector<ll> Rui(N); Rui[0] = A[0];

	

	ll ans = 0;
	if (Rui[0] == 0) {
		ans += 1;
		Rui[0] = 1;
	}
	FOR(i, N - 1) {
		Rui[i + 1] += Rui[i] + A[i + 1];

		if (i + 1 >= 1 and Rui[i+1] * Rui[i] >= 0) {
			if (Rui[i + 1] * Rui[i] == 0 and Rui[i] > 0) {
				ans += 1; Rui[i + 1] = -1;
			}
			else if (Rui[i + 1] * Rui[i] == 0 and Rui[i] < 0) {
				ans += 1; Rui[i + 1] = 1;
			}
			else { // 両方とも同じ符号になった場合
				if (Rui[i + 1] > 0) {
					ans += Rui[i + 1] + 1;
					Rui[i + 1] = -1;
				}
				else {
					ans += - Rui[i + 1] + 1;
					Rui[i + 1] = 1;

				}
			}
		}
	}

	///////////////////////////////////////////////
/////////              ///////////////
///////////////////////////////////////////////


	ll tmp = 0;
	if (Rui[0] == 0) {
		tmp += 1;
		Rui[0] = -1;
	}
	FOR(i, N - 1) {
		Rui[i + 1] += Rui[i] + A[i + 1];
		
		if (i + 1 >= 1 and Rui[i + 1] * Rui[i] >= 0) {
			if (Rui[i + 1] * Rui[i] == 0 and Rui[i] > 0) {
				tmp += 1; Rui[i + 1] = -1;
			}
			else if (Rui[i + 1] * Rui[i] == 0 and Rui[i] < 0) {
				tmp += 1; Rui[i + 1] = 1;
			}
			else { // 両方とも同じ符号になった場合
				if (Rui[i + 1] > 0) {
					tmp += Rui[i + 1] + 1;
					Rui[i + 1] = -1;
				}
				else {
					tmp += -Rui[i + 1] + 1;
					Rui[i + 1] = 1;

				}
			}
		}
	}
	chmin(ans, tmp);



	cout << ans << endl;
	//cout << 0 << endl;


	return 0;
}