stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 9.80490115803255x):
 #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));

}
// Slower C++ solution:
//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);

}

// Faster C++ solution for the same problem (measured speedup: 5.454646218149674x):
 #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));

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.7973525060844906x):
#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





int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N;

	cin >> N;



	ll s1 = 0;

	ll kotae1 = 0;

	ll s2 = 0;

	ll kotae2 = 0;

	rep(i, N) {

		int a;

		cin >> a;

		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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.8150091159518007x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.326640224252551x):
#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));

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.224520572772258x):
#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));

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.4015806422006376x):
#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);

}
// Slower C++ solution:
#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;

}




// Faster C++ solution for the same problem (measured speedup: 5.379634071215145x):
#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));

}
// Slower C++ solution:
#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);

}

// Faster C++ solution for the same problem (measured speedup: 5.244276159494129x):
#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));

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int main()

{

    int n;

    scanf("%d",&n);

    int a[n],i,cnt=0;

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

    {

        scanf("%d",&a[i]);

    }

    sort(a,a+n);

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

    {

        if(a[i]==a[i+1])

        {

            cnt++;

        }



    }

    if(cnt>0)

        printf("NO\n");

    else

        printf("YES\n");

    return 0;



}


// Faster C++ solution for the same problem (measured speedup: 4.650924983747474x):
#include<cstdio>

#include<algorithm>

using namespace std;

int main()

{

	int N,a[200000],flag=1;

	scanf("%d",&N);

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

	scanf("%d",&a[i]);

	sort(a,a+N);

	for(int i=N-1;i>0;i--)

	{

		if(a[i]==a[i-1])

		{

			flag=0;

			break;

		}

	}

	if(flag==1)	printf("YES\n");

	else	printf("NO\n");

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>



using namespace std;



int N;

long long arr[200005];



int main(){

    cin >> N;

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

        cin >> arr[i];

    sort(arr + 1, arr + 1 + N);

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

        if (arr[i] == arr[i - 1]){

            cout << "NO";

            return 0;

        }

    }

    cout << "YES";

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.71454925725141x):
#include<cstdio>

#include<algorithm>

using namespace std;

int main()

{

	int N,a[200000],flag=1;

	scanf("%d",&N);

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

	scanf("%d",&a[i]);

	sort(a,a+N);

	for(int i=N-1;i>0;i--)

	{

		if(a[i]==a[i-1])

		{

			flag=0;

			break;

		}

	}

	if(flag==1)	printf("YES\n");

	else	printf("NO\n");

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

set<int> kk;

int main()

{

    int n;

    cin>>n;

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

    {

        int k;

        cin>>k;

        kk.insert(k);

    }



    if(kk.size()==n)

        printf("YES\n");

    else

        printf("NO\n");

}

// Faster C++ solution for the same problem (measured speedup: 4.704451522550378x):
#include<cstdio>

#include<algorithm>

using namespace std;

int main()

{

	int N,a[200000],flag=1;

	scanf("%d",&N);

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

	scanf("%d",&a[i]);

	sort(a,a+N);

	for(int i=N-1;i>0;i--)

	{

		if(a[i]==a[i-1])

		{

			flag=0;

			break;

		}

	}

	if(flag==1)	printf("YES\n");

	else	printf("NO\n");

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);

#define fs first

#define sc second

using namespace std;

typedef long long ll;

typedef pair<int,int> pii;

const int maxn = 1e6+10;

using namespace std;



int N;

int a[maxn];

int main(){

	// debug;

	ios;



	cin>>N;

	for(int i = 0;i<N;i++) cin>>a[i];

	sort(a,a+N);

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

		if(a[i] == a[i-1]) {

			cout<<"NO"<<'\n';

			return 0;

		}

	}

	cout<<"YES\n";



	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.763981259912152x):
#include<cstdio>

#include<algorithm>

using namespace std;

int main()

{

	int N,a[200000],flag=1;

	scanf("%d",&N);

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

	scanf("%d",&a[i]);

	sort(a,a+N);

	for(int i=N-1;i>0;i--)

	{

		if(a[i]==a[i-1])

		{

			flag=0;

			break;

		}

	}

	if(flag==1)	printf("YES\n");

	else	printf("NO\n");

}
// Slower C++ solution:
#include<cstdio>

#include<set> 

using namespace std;

int main()

{

	int N,t;

	scanf("%d",&N);

	set<int> a;

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

	{

		scanf("%d",&t);

		a.insert(t);

	}

	if(N==a.size())	printf("YES\n");

	else	printf("NO\n");

}


// Faster C++ solution for the same problem (measured speedup: 4.362373768967692x):
#include<cstdio>

#include<algorithm>

using namespace std;

int main()

{

	int N,a[200000],flag=1;

	scanf("%d",&N);

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

	scanf("%d",&a[i]);

	sort(a,a+N);

	for(int i=N-1;i>0;i--)

	{

		if(a[i]==a[i-1])

		{

			flag=0;

			break;

		}

	}

	if(flag==1)	printf("YES\n");

	else	printf("NO\n");

}