stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



#define SIZE 100100

#define POS 1

#define NEG 0



int n;

long long arr[SIZE];



long long solve(long long sum, int index, int should){

    if(index == n){

        return 0;

    }



    long long ans = 0LL;



    sum += arr[index];

    if(sum <= 0 && should == POS){

        ans += (abs(sum) + 1);

        ans += solve(1, index + 1, NEG);

    }else if(sum >= 0 && should == NEG){

        ans += (abs(sum) + 1);

        ans += solve(-1, index + 1, POS);

    }else{

        ans += solve(sum, index + 1, 1 - should);

    }



    return ans;

}



int main(){

    #ifdef magUNbos

    freopen("a.in.c","r",stdin);

    #endif // magUNbos



    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    cin >> n ;

    for(int i = 0; i < n ; i++){

        cin >> arr[i];

    }



    long long a1 = solve(0LL, 0, POS);

    long long a2 = solve(0LL, 0, NEG);



    cout << min(a1, a2) << endl;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long LL;

 

inline int read(){

	char ch = getchar(); int x = 0, op = 1;

	while (ch < '0' || '9' < ch) { if (ch == '-') op = -1; ch = getchar(); }

	while ('0' <= ch && ch <= '9') { x = x*10 + ch-'0'; ch = getchar(); }

	return op * x;

}

const int maxn = 100009;

LL n, s[maxn], t, res1, res2, op;

 

int main(){

	n = read();

	for (LL i=1; i<=n; i++) s[i] = s[i-1] + read();

	op = 1; t = 0;

	for (LL i=1; i<=n; i++){

		if (op == 1 && (s[i]+t) <= 0){

			res1 += 1 - (s[i]+t);

			t = 1 - s[i];

		}

		if (op == -1 && (s[i]+t) >= 0){

			res1 += (s[i]+t) + 1;

			t = -s[i] - 1;

		}

		op = -op;

	}

	op = -1; t = 0;

	for (LL i=1; i<=n; i++){

		if (op == 1 && (s[i]+t) <= 0){

			res2 += 1 - (s[i]+t);

			t = 1 - s[i];

		}

		if (op == -1 && (s[i]+t) >= 0){

			res2 += (s[i]+t) + 1;

			t = -s[i] - 1;

		}

		op = -op;

	}

	printf("%lld\n", min(res1, res2));

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
/*

 * swq.cpp

 *

 *  Created on: 5/09/2017

 *      Author: cristhian

 */

#include<bits/stdc++.h>





using namespace std;





int main(){



	int n;



	cin >> n;



	vector<int> vec;

	for(int i = 0; i < n; i++){

		int aux;

		cin >> aux;

		vec.push_back(aux);

	}

	long long sumA =0;

	long long sumB = 0;



	long long auxA = vec[0];

	long long auxB;

	if(auxA > 0){

		auxB = -1;

		sumB += auxA + 1;

	}else if(auxA < 0){

		auxB = 1;

		sumB += abs(auxA) + 1;

	}else{

		auxA = 1;

		auxB = -1;

		sumA++;

		sumB++;

	}



	long long sumAuxA = auxA;

	long long sumAuxB = auxB;

	for(int i = 1; i < n; i++){

		if(sumAuxA > 0){

			sumAuxA += vec[i];

			sumAuxB += vec[i];

			if(sumAuxA >= 0){

				sumA += sumAuxA+1;

				sumAuxA = -1;

			}



			if(sumAuxB <= 0){

							sumB += abs(sumAuxB)+1;

							sumAuxB = 1;

						}

		}else{

			sumAuxA += vec[i];

			sumAuxB += vec[i];

			if(sumAuxA <= 0){

				sumA += abs(sumAuxA)+1;

				sumAuxA = 1;

			}



			if(sumAuxB >= 0){

				sumB += sumAuxB+1;

				sumAuxB = -1;

			}

		}

	}





	cout << min(sumA, sumB);



}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long LL;

 

inline int read(){

	char ch = getchar(); int x = 0, op = 1;

	while (ch < '0' || '9' < ch) { if (ch == '-') op = -1; ch = getchar(); }

	while ('0' <= ch && ch <= '9') { x = x*10 + ch-'0'; ch = getchar(); }

	return op * x;

}

const int maxn = 100009;

LL n, s[maxn], t, res1, res2, op;

 

int main(){

	n = read();

	for (LL i=1; i<=n; i++) s[i] = s[i-1] + read();

	op = 1; t = 0;

	for (LL i=1; i<=n; i++){

		if (op == 1 && (s[i]+t) <= 0){

			res1 += 1 - (s[i]+t);

			t = 1 - s[i];

		}

		if (op == -1 && (s[i]+t) >= 0){

			res1 += (s[i]+t) + 1;

			t = -s[i] - 1;

		}

		op = -op;

	}

	op = -1; t = 0;

	for (LL i=1; i<=n; i++){

		if (op == 1 && (s[i]+t) <= 0){

			res2 += 1 - (s[i]+t);

			t = 1 - s[i];

		}

		if (op == -1 && (s[i]+t) >= 0){

			res2 += (s[i]+t) + 1;

			t = -s[i] - 1;

		}

		op = -op;

	}

	printf("%lld\n", min(res1, res2));

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



/*

 * 

 */

int main(int argc, char** argv) {

    cin.tie(NULL);

    ios::sync_with_stdio(0);

    

    long n; cin >> n;

    long arr[100010];

    memset(arr, 0, sizeof arr);

    

    for(int i = 0; i < n; i++){

        long aux; cin >> aux;

        arr[i] = aux;

    }

    

    long contA = 0, contB = 0, sumB = 0, sumA = 0;

    

    if(arr[0] < 0){

        contB += abs(arr[0]) + 1;

        sumB = 1;     

        sumA = arr[0];       

    }else if(arr[0] > 0){

        contA += abs(arr[0]) + 1;

        sumA = -1;

        sumB = arr[0];     

    }

    if(arr[0] == 0){

        contB++;

        contA++;

        sumA = -1;

        sumB = 1;

    }

    //cout << "SUM a "<<sumA<<" SUM b "<<sumB<<'\n';

    //cout <<"A "<< contA <<" B "<<contB<<'\n';

    for(int i = 1; i < n; i++){

        if(sumA > 0){

            sumA += arr[i];

            if(sumA >= 0){

                contA += sumA + 1;

                sumA = -1;

            }

        }else if(sumA < 0){

            sumA += arr[i];

            if(sumA <= 0){

                contA += abs(sumA) + 1;

                sumA = 1;                            

            }

        }

        

        if(sumB > 0){

            sumB += arr[i];

            if(sumB >= 0){

                contB += sumB + 1;

                sumB = -1;

            }

        }else if(sumB < 0){

            sumB += arr[i];

            if(sumB <= 0){

                contB += abs(sumB) + 1;

                sumB = 1;

            }

        }

        //cout << "SUM a "<<sumA<<" SUM b "<<sumB<<'\n';

        //cout <<"A "<< contA <<" B "<<contB<<'\n';

    }

    

    cout << min(contA, contB)<<'\n';

    return 0;

}


// Optimized solution to the same problem (faster):
 #include<cstring>

#include<cstdio>

#include<cmath>

#include<memory.h>

#include<algorithm>

#include<map>

#define ll long long

#define ld long double

#define maxn 310

#define For(i,j,k)  for(ll i=j;i<=k;++i)

#define FOr(i,j,k)  for(ll i=j;i>=k;--i)

const ll inf=1e9;

const ld eps=1e-7;

using namespace std;

inline ll read(){   ll x=0,f=1;char ch=getchar();   while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}  while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}  return x*f; }

inline void wrote(ll x){    if (x<0) putchar('-'),x=-x; if (x>=10) wrote(x/10);   putchar(x%10+'0');  }

void writeln(ll x){ wrote(x);   puts("");   }

const ll N=100010;

ll a[N],n;

ll dis(ll a,ll b){	return abs(a-b);	}

ll work(){

	ll sum=0,ans=0;

	For(i,1,n){

		sum+=a[i];

		if (i&1){

			if (sum<=0)	ans+=dis(1,sum),sum=1;

		}else{

			if (sum>=0)	ans+=dis(-1,sum),sum=-1;

		}

	}return ans;

}

int main(){

	n=read();

	For(i,1,n)	a[i]=read();

	ll ans1=work();

	For(i,1,n)	a[i]=-a[i];

	ll ans2=work();

	writeln(min(ans1,ans2));

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define vi vector<int>

#define ll long long

#define dbug(a) cerr<<#a<<" : "<<a<<endl;

#define For(i,n) for(int i =0;i<n;i++)

#define FOR(i,a,b) for(int i =a;i<b;i++)

#define inf 100000

using namespace std;

int n;

ll a[inf];

ll sum[inf];



bool eqsig(ll a, ll b){

    if(a<0 && b>0)

        return true;

    if(a>0 && b<0)

        return true;

    return false;

}



ll solve(){

    ll ans=0;

    For(i,n-1){

        sum[i+1]=sum[i]+a[i+1];

        if(eqsig(sum[i],sum[i+1]))

            continue;

        if(sum[i]<0){

            ans-=(sum[i+1]-1);

            sum[i+1]=1;

        }

        if(sum[i]>0){

            ans+=(sum[i+1]+1);

            sum[i+1]=-1;

        }



    }

    return ans;

}



int main(){





    #ifdef magUNbos

        freopen("in","r",stdin);

        freopen("out","w",stdout);

    #endif // magUNbos





        cin>>n;

        For(i,n)

            cin>>a[i];

        sum[0]=a[0];

        ll aa,bb;

        if(a[0]==0){

            sum[0]=1;

            aa=solve()+1;

            sum[0]=-1;

            bb=solve()+1;

        }else

        if(a[0]>0){

            aa=solve();

            sum[0]=-1;

            bb=solve()+a[0]+1;

        }

        else if(a[0]<0){

            aa=solve();

            sum[0]=1;

            bb=solve()-(a[0]-1);

        }

        cout<<min(aa,bb)<<endl;









}


// Optimized solution to the same problem (faster):
 #include<cstring>

#include<cstdio>

#include<cmath>

#include<memory.h>

#include<algorithm>

#include<map>

#define ll long long

#define ld long double

#define maxn 310

#define For(i,j,k)  for(ll i=j;i<=k;++i)

#define FOr(i,j,k)  for(ll i=j;i>=k;--i)

const ll inf=1e9;

const ld eps=1e-7;

using namespace std;

inline ll read(){   ll x=0,f=1;char ch=getchar();   while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}  while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}  return x*f; }

inline void wrote(ll x){    if (x<0) putchar('-'),x=-x; if (x>=10) wrote(x/10);   putchar(x%10+'0');  }

void writeln(ll x){ wrote(x);   puts("");   }

const ll N=100010;

ll a[N],n;

ll dis(ll a,ll b){	return abs(a-b);	}

ll work(){

	ll sum=0,ans=0;

	For(i,1,n){

		sum+=a[i];

		if (i&1){

			if (sum<=0)	ans+=dis(1,sum),sum=1;

		}else{

			if (sum>=0)	ans+=dis(-1,sum),sum=-1;

		}

	}return ans;

}

int main(){

	n=read();

	For(i,1,n)	a[i]=read();

	ll ans1=work();

	For(i,1,n)	a[i]=-a[i];

	ll ans2=work();

	writeln(min(ans1,ans2));

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
//Be Name Khoda

/*

ID: aminra81

PROG: :)))

LANG: C++

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long double ld;

const int MOD = (int)1e9 + 7;

const ll inf = (ll)1e18;

const int infint = (int)2e9;

const int MAXN = 1e6 + 7;

ll part[MAXN], part2[MAXN];

int main()

{

	ios::sync_with_stdio(false);

	cin.tie(0); cout.tie(0);

	int n;

	cin >> n;

	for (int i = 0; i < n; i++)

	{

		int a; 

		cin >> a;

		part[i] = a;

		part2[i] = a;

		if(i != 0)

			part[i] += part[i - 1], part2[i] += part2[i - 1];

	}

	ll sum = 0, ans = 0;

	//first +

	for (int i = 0; i < n; i++)

	{

		part[i] += sum;

		if(i % 2 == 0 and part[i] <= 0)

		{

			ans += 1 - part[i];

			sum += 1 - part[i];

		}

		if(i % 2 and part[i] >= 0)

		{

			ans += part[i] + 1;

			sum -= part[i] + 1;

		}

	}

	

	//first -

	ll sum2 = 0, ans2 = 0;

	for (int i = 0; i < n; i++)

	{

		part2[i] += sum2;

		if(i % 2 == 0 and part2[i] >= 0)

		{

			ans2 += part2[i] + 1;

			sum2 -= part2[i] + 1;

		}

		if(i % 2 and part2[i] <= 0)

		{

			ans2 += 1 - part2[i];

			sum2 += 1 - part2[i];

		}

	}

	cout << min(ans, ans2);

}

// Optimized solution to the same problem (faster):
 #include<cstring>

#include<cstdio>

#include<cmath>

#include<memory.h>

#include<algorithm>

#include<map>

#define ll long long

#define ld long double

#define maxn 310

#define For(i,j,k)  for(ll i=j;i<=k;++i)

#define FOr(i,j,k)  for(ll i=j;i>=k;--i)

const ll inf=1e9;

const ld eps=1e-7;

using namespace std;

inline ll read(){   ll x=0,f=1;char ch=getchar();   while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}  while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}  return x*f; }

inline void wrote(ll x){    if (x<0) putchar('-'),x=-x; if (x>=10) wrote(x/10);   putchar(x%10+'0');  }

void writeln(ll x){ wrote(x);   puts("");   }

const ll N=100010;

ll a[N],n;

ll dis(ll a,ll b){	return abs(a-b);	}

ll work(){

	ll sum=0,ans=0;

	For(i,1,n){

		sum+=a[i];

		if (i&1){

			if (sum<=0)	ans+=dis(1,sum),sum=1;

		}else{

			if (sum>=0)	ans+=dis(-1,sum),sum=-1;

		}

	}return ans;

}

int main(){

	n=read();

	For(i,1,n)	a[i]=read();

	ll ans1=work();

	For(i,1,n)	a[i]=-a[i];

	ll ans2=work();

	writeln(min(ans1,ans2));

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define Would

#define you

#define please





int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);

	

	int N;

	cin >> N;

	ll A[100001] = {};

	rep1(i, N) {

		cin >> A[i];

		A[i] += A[i - 1];

	}

	ll k1[2] = {};

	ll k2[2] = {};



	rep1(i, N) {

		if (i % 2) {

			if (A[i] - k1[0] + k1[1] <= 0) k1[1] += 1 - A[i] + k1[0] - k1[1];

			if (A[i] - k2[0] + k2[1] >= 0) k2[0] += 1 + A[i] - k2[0] + k2[1];

		}

		else {

			if (A[i] - k1[0] + k1[1] >= 0) k1[0] += 1 + A[i] - k1[0] + k1[1];

			if (A[i] - k2[0] + k2[1] <= 0) k2[1] += 1 - A[i] + k2[0] - k2[1];

		}



	}



	ll kotae = min(k1[0] + k1[1], k2[0] + k2[1]);

	co(kotae);



	Would you please return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm, ct;

inline char getcha() {

	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	int A = 0;

	int pn = 1;

	if (ci - cn + 16 > cm) {

		if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }

		A = ct - '0';

		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;

		return pn * A;

	}

	else {

		if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }

		A = ct - '0';

		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;

		return pn * A;

	}

}



int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N = getint();



	int s1 = 0;

	ll kotae1 = 0;

	int s2 = 0;

	ll kotae2 = 0;

	rep(i, N) {

		int a = getint();

		s1 += a;

		s2 += a;

		if (i & 1) {

			if (s1 <= 0) {

				kotae1 += 1 - s1;

				s1 = 1;

			}

			if (s2 >= 0) {

				kotae2 += s2 + 1;

				s2 = -1;

			}

		}

		else {

			if (s2 <= 0) {

				kotae2 += 1 - s2;

				s2 = 1;

			}

			if (s1 >= 0) {

				kotae1 += s1 + 1;

				s1 = -1;

			}

		}

	}

	co(min(kotae1, kotae2));



	Would you please return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>



using namespace std;



const int maxn = 1e5;

int a[maxn + 100], b[maxn + 100];



int main() {

    int n;

    cin >> n;

    for (int i = 0; i < n; i++){

        cin >> a[i];

        b[i] = a[i];

    }

    long long sum = 0, ope1 = 0;

    for (int i = 0; i < n; i++){

        sum += a[i];

        if (i % 2 == 0 && sum <= 0){

            ope1 += 1 - sum;

            sum = 1;

        }

        if (i % 2 == 1 && sum >= 0){

            ope1 += sum + 1;

            sum = -1;

        }

    }

    sum = 0;

    long long ope2 = 0;

    for (int i = 0; i < n; i++){

        sum += a[i];

        if (i % 2 == 0 && sum >= 0){

            ope2 += sum + 1;

            sum = -1;

        }

        if (i % 2 == 1 && sum <= 0){

            ope2 += 1 - sum;

            sum = 1;

        }

    }

    cout << min(ope1, ope2) << endl;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

#define ll long long

#define N 200005

#define mod 1000000007

#define rep(i,j,k) for (ll i=j;i<=k;++i)

#define per(i,j,k) for (ll i=j;i>=k;--i)

using namespace std;

inline ll read(){

	char ch=getchar(); ll x=0,f=1;

	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }

	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }

	return x*f;

}

ll n,sum1,sum2,ans1,ans2,x;

int main(){

	n=read();

	rep(i,1,n){

		sum1+=x=read();

		sum2+=x;

		if (i&1){

			if (sum1<=0) ans1+=1-sum1,sum1=1;

			if (sum2>=0) ans2+=sum2+1,sum2=-1;

		}else{

			if (sum1>=0) ans1+=sum1+1,sum1=-1;

			if (sum2<=0) ans2+=1-sum2,sum2=1;

		}

	}

	printf("%lld",min(ans1,ans2));

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define ll long long

#define For(i,x,y) for(int i=x;i<=y;i++)

#define Rep(i,x,y) for(int i=x;i>=y;i--)

#define Forn(i,x,y) for(int i=x;i<y;i++)

#define oo 1000000

#define zyy 1000000007

#define N 100005

#define int ll

using namespace std;

inline int read(){int x=0,f=0;char ch=getchar();for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1;for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-48;return f?-x:x;}

inline void write(int x){if(x<10) putchar(x+48);else write(x/10),putchar(x%10+48);}

inline void writeln(int x){if(x<0) putchar('-'),x=-x;write(x);putchar('\n');}

int n,a[N];

inline int work(){

	int sum=0,ans=0;

	For(i,1,n){

		sum+=a[i];

		if(i&1){

			if(sum<=0) ans+=abs(sum-1),sum=1;

		}else{

			if(sum>=0) ans+=abs(sum+1),sum=-1;

		}

	}

	return ans;

}

main(){

	n=read();int ans1,ans2;

	For(i,1,n) a[i]=read();ans1=work();

	For(i,1,n) a[i]=-a[i];ans2=work();

	writeln(min(ans1,ans2));

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

#define ll long long

#define N 200005

#define mod 1000000007

#define rep(i,j,k) for (ll i=j;i<=k;++i)

#define per(i,j,k) for (ll i=j;i>=k;--i)

using namespace std;

inline ll read(){

	char ch=getchar(); ll x=0,f=1;

	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }

	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }

	return x*f;

}

ll n,sum1,sum2,ans1,ans2,x;

int main(){

	n=read();

	rep(i,1,n){

		sum1+=x=read();

		sum2+=x;

		if (i&1){

			if (sum1<=0) ans1+=1-sum1,sum1=1;

			if (sum2>=0) ans2+=sum2+1,sum2=-1;

		}else{

			if (sum1>=0) ans1+=sum1+1,sum1=-1;

			if (sum2<=0) ans2+=1-sum2,sum2=1;

		}

	}

	printf("%lld",min(ans1,ans2));

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



int N;

vector<int>a(100010); // 終了コード136が出る場合は配列を余分に取る。制約最大+αが望ましい



long calc(long s){

  long sum=0, res=0;

    for(int i=0; i<N; i++, s*=-1){

     sum+=a[i];

     if(sum*s>0){continue;} // 初項が＋か―かで結果が出る問題である。sの変化を基準にしている。

     res+=abs(sum-s); // abs(sum-s)を算出すると符号を変えるのに必要な操作回数の値がresに入る

     sum+=s*abs(sum-s); // sum*sが成り立たないという事は、

    }             // sumに新しく入れる数値がsの基準に合致していないためであり、sを掛ける必要がある

  return res; // 操作回数の最小値

}



int main() {

  cin>>N;

  for(int i=0; i<N; i++){

   cin>>a[i]; }

  

  cout<<min(calc(1), calc(-1));

  return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



int main() {

int N;

  cin>>N;

  

  long long a, sum1=0, sum2=0, ans1=0, ans2=0; // ansは操作回数の最小値

  for(int i=1; i<=N; i++){

   cin>>a;    // 各iまでの和の符号を正負交互にするので、

    sum1+=a;  // この問題は各和の奇数番目と偶数番目を操作して、どちらが小さくなるかという話になるの

    sum2+=a;

    if(i%2!=0){ // 各和の奇数番目の操作。正と負の場合に分ける

       if(sum1<=0){ // 和が負なら正にする

         ans1+=1-sum1; // 負の値が正の＋1になる回数分足す

         sum1=1; } // 上記の操作をしたのでsum1=1にする

       if(sum2>=0){ // 和が正なら負にする

         ans2+=1+sum2; // 正の値が負の―1になる回数分足す

         sum2=-1; }  // 上記の操作をしたのでsum2=-1にする

    }

    

    else{ // 各和の偶数番目の操作。正と負の場合に分ける

       if(sum1>=0){ // 和が正なら負にする

         ans1+=1+sum1; // ans1はsum1に初項＋で操作していった場合の操作回数

         sum1=-1; }

       if(sum2<=0){ // 和が負なら正にする

         ans2+=1-sum2; // ans2はsum2に初項―で操作していった場合の操作回数

         sum2=1;  }    

    }  

  }

  

 cout<<min(ans1, ans2);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

#define ll long long

#ifdef PAPITAS

	#define DEBUG 1

#else

	#define DEBUG 0

#endif

#define _DO_(x) if(DEBUG) x



int main()

{

	ios::sync_with_stdio(false);cin.tie(NULL);

	int n;

	cin >> n;

	int arr[n];

	ll a = 0, b = 0, sa = 0, sb = 0;

	for(int i = 0; i< n; i++){

		cin >> arr[i];

	}

	for(int i = 0; i < n; i++){

		sa += arr[i];

		sb += arr[i];

		if(i%2 == 0){

			if(sa <= 0){

				a += 1 - sa;

				sa = 1;

			}

			if(sb >= 0){

				b += sb + 1;

				sb = -1;

			}

		}else{

			if(sa >= 0){

				a += sa + 1;

				sa = -1;

			}

			if(sb <= 0){

				b += 1 - sb;

				sb = 1;

			}

		}

	}

	cout << min(a, b);

	return 0;

}




// Optimized solution to the same problem (faster):
#include <cstdio>

#define For(i,j,k) for(int i=j;i<=k;i++)

#define Dow(i,j,k) for(int i=j;i>=k;i--)

#define LL long long

using namespace std ;

inline int read() {

	int x = 0 , f = 1 ;

	char ch = getchar() ;

	while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar() ; }

	while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar() ; }

	return x * f ;

}



const int N = 1e5+11,mod = 1e9+7;

LL ans1,ans2,sum;

int n;

int a[N];



inline LL abs(LL x) {

	if(x<0) x=-x;

	return x;

}

inline LL min(LL x,LL y) {

	if(x<y) return x;

	return y;

}



int main() {

	n=read();

	For(i, 1, n) a[i]=read();

	For(i, 1, n) {

		sum= sum+a[i];

		if(i%2==1) 

			if(sum<=0) {

				ans1=ans1 + abs(1-sum);

				sum=1;

			}

			else {}

		else 

			if(sum>=0) {

				ans1=ans1 + abs(-1-sum);

				sum=-1;

			}

	}

	

	sum = 0;

	For(i, 1, n) {

		sum = sum+a[i]; 

		if(i%2==0) 

			if(sum<=0) {

				ans2=ans2 + abs(1-sum);

				sum=1;

			}

			else {}

		else 

			if(sum>=0) {

				ans2=ans2 + abs(-1-sum);

				sum=-1;

			}

	}

	printf("%lld\n",min(ans1,ans2));

}










// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

long long sum,ans;

const int N=100005;

int a[N],n,pos;

void read(int &x)

{

    x=0;

    int y=1;

    char c=getchar();

    while (c>'9'||c<'0')

    {

        if (c=='-')

            y=-1;

        c=getchar();

    }

    while (c>='0'&&c<='9')

    {

        x=x*10+c-'0';

        c=getchar();

    }

    x*=y;

}

int main()

{

	read(n);

	for (int i=1;i<=n;++i)

		read(a[i]);

	for (int i=1;i<=n;++i)

		a[i]+=a[i-1];

	pos=0;

	for (int i=1;i<=n;++i)

	{

		if (i&1&&a[i]+pos<=0)

		{

			sum+=1-a[i]-pos;

			pos=1-a[i];

		}

		if (!(i&1)&&a[i]+pos>=0)

		{

			sum+=a[i]+pos+1;

			pos=-a[i]-1;

		}

	}

	pos=0;

	for (int i=1;i<=n;++i)

	{

		if (i&1&&a[i]+pos>=0)

		{

			ans+=a[i]+pos+1;

			pos=-a[i]-1;

		}

		if (!(i&1)&&a[i]+pos<=0)

		{

			ans+=1-a[i]-pos;

			pos=1-a[i];

		}

	}

	cout<<min(ans,sum);

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#define For(i,j,k) for(int i=j;i<=k;i++)

#define Dow(i,j,k) for(int i=j;i>=k;i--)

#define LL long long

using namespace std ;

inline int read() {

	int x = 0 , f = 1 ;

	char ch = getchar() ;

	while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar() ; }

	while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar() ; }

	return x * f ;

}



const int N = 1e5+11,mod = 1e9+7;

LL ans1,ans2,sum;

int n;

int a[N];



inline LL abs(LL x) {

	if(x<0) x=-x;

	return x;

}

inline LL min(LL x,LL y) {

	if(x<y) return x;

	return y;

}



int main() {

	n=read();

	For(i, 1, n) a[i]=read();

	For(i, 1, n) {

		sum= sum+a[i];

		if(i%2==1) 

			if(sum<=0) {

				ans1=ans1 + abs(1-sum);

				sum=1;

			}

			else {}

		else 

			if(sum>=0) {

				ans1=ans1 + abs(-1-sum);

				sum=-1;

			}

	}

	

	sum = 0;

	For(i, 1, n) {

		sum = sum+a[i]; 

		if(i%2==0) 

			if(sum<=0) {

				ans2=ans2 + abs(1-sum);

				sum=1;

			}

			else {}

		else 

			if(sum>=0) {

				ans2=ans2 + abs(-1-sum);

				sum=-1;

			}

	}

	printf("%lld\n",min(ans1,ans2));

}










// Fastest known solution for this problem: