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)

#include <bits/stdc++.h>
#include <functional>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<double,double> dd;
typedef pair<ll,ll> pll;
typedef pair<string,int> psi;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvll;
typedef vector<vector<ii> > vvip;
typedef vector<ii> vii;
typedef map<int,int> mpi;
#define pb push_back
#define F first
#define S second
//#define MOD 1000000007
#define NA -1
#define ALL(v) v.begin(),v.end()
#define mp make_pair
#define rep(i, n) for (int (i) = 0; (i) < (n); (i) ++)
#define rep1(i, n) for (int (i) = 1; (i) <= (n); (i) ++)
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define db(x) {cout << #x << " = " << (x) << endl;}
#define dba(a, x, y) {cout<<#a<<" :";FOR(i123,x,y)cout<<setw(4)<<(a)[i123];cout<<endl;}
#define foreach(e, x) for (__typeof(x.begin()) e = x.begin(); e != x.end(); e++) 
#define clr(x) memset(x,0,sizeof(x));
#define sz(x) int((x).size())
#define endl '\n'
const int INF = INT_MAX;
const ll INFL = LLONG_MAX;
const ld pi = acos(-1);
#define sc(t) scanf("%d",&t)
// vector<string> split(const string &s, char delim) {
//     stringstream ss(s);
//     string item;
//     vector<string> tokens;
//     while (getline(ss, item, delim)) {
//         tokens.push_back(item);
//     }
//     return tokens;
// }

typedef pair<pll,ll> ppll;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
#define re return
#define MAX 100

 // struct compare  
 // {  
 //   bool operator()(const ii& a, const ii& b)  
 //   {  
 //       re (a.S-a.F+1 < b.S-b.F+1) || (a.S-a.F+1 == b.S-b.F+1 && a.F>b.F);
 //   }
 // };

	ll xx(vll &v)
	{
		ll s=0;
	ll ans=0;
	int n=sz(v);
	for(int i=0;i<n;i++)
	{
		if(!i)
		s=v[0];
		else
		{
			if(s>0)
			{
				if( s+v[i]<0)
				{
					s+=v[i];
					continue;
				}
				ll x ,y;
				x= max(s+v[i]+1,(ll)0);
				ans+=x;
				if(x!=0)
				s=-1;
			}
			else
			{
				if( s+v[i]>0)
				{
					s+=v[i];
					continue;
				}
				ll x ,y;
				x= max(1-(s+v[i]),(ll)0);
				ans+=x;
				if(x!=0)
				s=1;

			}
		}

	}
	re ans;
}
int main()
{
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt","r",stdin);
	//     freopen("output.txt","w",stdout);;
	// #endif
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	//ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
	ios_base::sync_with_stdio(0); cout.precision(15); cout << fixed; cout.tie(0); cin.tie(0);
	int n;
	cin>>n;
	vll v(n);
	rep(i,n)
	cin>>v[i];
	if(n==1)
	{
		cout<<0<<endl;
		re 0;
	}
	ll ans=INFL;
	if(v[0]==0)
	{
		v[0]+=1;
		ans=min(ans,xx(v));
		v[0]=-1;
		ans=min(ans,xx(v));
	}
	else if(v[0]>0)
	{
		ans=min(ans,xx(v));
		v[0]=-1;
		ans=min(ans,xx(v));
		
	}
	else 
	{
		ans=min(ans,xx(v));
		v[0]=1;
		ans=min(ans,xx(v));
		

	}
cout<<ans<<endl;



}