stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



#define pb push_back

#define ff first

#define ss second



typedef long long ll;

const ll MAXN = 2e6 + 10, inf = 1e18, mod = 1e9 + 7;



struct pair_hash {

	template <class T1, class T2>

	std::size_t operator () (const std::pair<T1,T2> &p) const {

		auto h1 = std::hash<T1>{}(p.first);

		auto h2 = std::hash<T2>{}(p.second);



		return h1 ^ h2;  

	}

};



ll pw(ll te, ll tee) {

	if (tee == 0)	return 1;

	ll res = pw(te, tee / 2);

	return (tee % 2 ? te * res * res : res * res);

}



ll a[MAXN], n, h, w, ans[105][105];



void Read_input() {

	cin >> h >> w >> n;

	for (ll i = 1; i <= n; i++)	cin >> a[i];

}



void Solve() {

	ll cnt = 0, k = 1;

	for (ll i = 1; i <= h; i++) {

		if (i % 2) {

			for (ll j = 1; j <= w; j++) {

				ans[i][j] = k;

				cnt++;

				if (cnt >= a[k]) {

					cnt = 0;

					k++;

				}

			}

		}

		else {

			for (ll j = w; j > 0; j--) {

				ans[i][j] = k;

				cnt++;

				if (cnt >= a[k]) {

					cnt = 0;

					k++;

				}

			}

		}

	}

	for (ll i = 1; i <= h; i++) {

		cout << ans[i][1];

		for (ll j = 2; j <= w; j++)

			cout << " " << ans[i][j];

		cout << endl;

	}

}





int main() {



	ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0);

	//freopen("input.txt", "r", stdin),	freopen("output.txt", "w", stdout);



	Read_input(),	Solve();

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.27928545740714x):
#include<stdio.h>

#include<stdlib.h>

#define SWAP(a,b) ((a)^=(b)^=(a)^=(b))

typedef long long ll;

int map[105][105];

int col[10005];

int main(void)

{

	int H, W, N;

	scanf("%d %d %d", &H, &W, &N);

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

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

	int i, j, m, s = 1, a = 0, b = W - 1;

	i = j = m = 0;

	while (m < N)

	{

		for (int k = 0; k < col[m]; k++) {

			map[i][j] = m + 1;

			if (j == b)

				SWAP(a, b), s = -s, i++;

			else

				j += s;

		}

		m++;

	}

	for (int i = 0; i < H; putchar('\n'),i++)

		for (int j = 0; j < W; j++)

			printf("%d ", map[i][j]);

	return 0;

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



using namespace std;



int R, C, x[10005], n, a = 1, banyak, y[105][105];

int main(){

    cin >> R >> C;

    cin >> n;

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

        cin >> x[i];

    }

    for(int r=1; r<=R; r++){

        if(r%2 == 1){

            for(int c=1; c<=C; c++){

                if(banyak == x[a]){

                    a++;

                    y[r][c] = a;

                    banyak = 1;

                }

                else{

                    y[r][c] = a;

                    banyak++;

                }

            }

        }

        else{

            for(int c=C; c>=1; c--){

                if(banyak == x[a]){

                    a++;

                    y[r][c] = a;

                    banyak = 1;

                }

                else{

                    y[r][c] = a;

                    banyak++;

                }

            }

        }

    }

    for(int r=1; r<=R; r++){

        for(int c=1; c<=C; c++){

            if(banyak == x[a]){

                a++;

                cout << y[r][c];

                banyak = 1;

            }

            else{

                cout << y[r][c];

                banyak++;

            }

            cout << " ";

        }

        cout << endl;

    }

}

// Faster C++ solution for the same problem (measured speedup: 5.217801830764236x):
#include<stdio.h>

#include<stdlib.h>

#define SWAP(a,b) ((a)^=(b)^=(a)^=(b))

typedef long long ll;

int map[105][105];

int col[10005];

int main(void)

{

	int H, W, N;

	scanf("%d %d %d", &H, &W, &N);

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

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

	int i, j, m, s = 1, a = 0, b = W - 1;

	i = j = m = 0;

	while (m < N)

	{

		for (int k = 0; k < col[m]; k++) {

			map[i][j] = m + 1;

			if (j == b)

				SWAP(a, b), s = -s, i++;

			else

				j += s;

		}

		m++;

	}

	for (int i = 0; i < H; putchar('\n'),i++)

		for (int j = 0; j < W; j++)

			printf("%d ", map[i][j]);

	return 0;

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

#include <string>



#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define SafeDeleteArray(pData) { try { delete [] pData; } catch (...) { assert(false); } pData=NULL; }

int a[10000]={0};

int b[100][100]={0};

int main()

{

    int H , W, n;

    cin >>H >>W;

    cin >>n;

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

        cin >>a[i];

    int k=1;

    for(int j=1;j<=H;j+=2){

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

            while(a[k]==0&&k<n)

                k++;

            b[j][i]=k;

            a[k]--;

        }

        if(j+1>H)

            break;

        for(int i=W;i>=1;i--){

            while(a[k]==0&&k<n)

                k++;

            b[j+1][i]=k;

            a[k]--;

        }

    }

    //SafeDeleteArray(a);

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

        for(int j=1;j<W;j++)

            cout<<b[i][j]<<" ";

        cout<<b[i][W]<<endl;

    }



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.211442058073693x):
#include<stdio.h>

#include<stdlib.h>

#define SWAP(a,b) ((a)^=(b)^=(a)^=(b))

typedef long long ll;

int map[105][105];

int col[10005];

int main(void)

{

	int H, W, N;

	scanf("%d %d %d", &H, &W, &N);

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

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

	int i, j, m, s = 1, a = 0, b = W - 1;

	i = j = m = 0;

	while (m < N)

	{

		for (int k = 0; k < col[m]; k++) {

			map[i][j] = m + 1;

			if (j == b)

				SWAP(a, b), s = -s, i++;

			else

				j += s;

		}

		m++;

	}

	for (int i = 0; i < H; putchar('\n'),i++)

		for (int j = 0; j < W; j++)

			printf("%d ", map[i][j]);

	return 0;

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

#include <sstream>

#include <algorithm>

#include <cstdio>

#include <cmath>

#include <set>

#include <map>

#include <queue>

#include <string>

#include <cstring>

#include <bitset>

#include <functional>

#include <random>

#define REP(i,a,n) for(int i=a;i<=n;++i)

#define PER(i,a,n) for(int i=n;i>=a;--i)

#define hr putchar(10)

#define pb push_back

#define lc (o<<1)

#define rc (lc|1)

#define mid ((l+r)>>1)

#define ls lc,l,mid

#define rs rc,mid+1,r

#define x first

#define y second

#define io std::ios::sync_with_stdio(false)

#define endl '\n'

#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})

using namespace std;

typedef long long ll;

typedef pair<int,int> pii;

const int P = 1e9+7, INF = 0x3f3f3f3f;

ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}

ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}

ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}

inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}

//head







const int N = 200;

int h,w,n,a[N*N];

int c[N][N];



int main() {

	scanf("%d%d%d",&h,&w,&n);

	REP(i,1,n) scanf("%d",a+i);

	int now = 1, res = a[1];

	REP(i,1,h) {

		if (i&1) {

			REP(j,1,w) { 

				c[i][j]=now;

				if (!--res) res=a[++now];

			}

		}

		else {

			PER(j,1,w) {

				c[i][j]=now;

				if (!--res) res=a[++now];

			}

		}

	}

	REP(i,1,h) {

		REP(j,1,w) printf("%d ",c[i][j]);hr;

	}

}














// Faster C++ solution for the same problem (measured speedup: 5.191818199025359x):
#include<stdio.h>

#include<stdlib.h>

#define SWAP(a,b) ((a)^=(b)^=(a)^=(b))

typedef long long ll;

int map[105][105];

int col[10005];

int main(void)

{

	int H, W, N;

	scanf("%d %d %d", &H, &W, &N);

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

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

	int i, j, m, s = 1, a = 0, b = W - 1;

	i = j = m = 0;

	while (m < N)

	{

		for (int k = 0; k < col[m]; k++) {

			map[i][j] = m + 1;

			if (j == b)

				SWAP(a, b), s = -s, i++;

			else

				j += s;

		}

		m++;

	}

	for (int i = 0; i < H; putchar('\n'),i++)

		for (int j = 0; j < W; j++)

			printf("%d ", map[i][j]);

	return 0;

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

using namespace std;



int c[110][110];

int n;

int a[11000];



int main() {

	ios::sync_with_stdio(0);

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

	int h, w; cin >> h >> w;

	cin >> n;

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

	int x = 0, y = 0, dir = 1;

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

		for(int j = 0; j < a[i]; ++ j) {

			c[x][y] = i + 1;

			if(y == w - 1 && dir == 1 || y == 0 && dir == -1) {

				dir *= -1;

				++ x;

			} else {

				y += dir;

			}

		}

	}

	for(int i = 0; i < h; ++ i) for(int j = 0; j < w; ++ j) cout << c[i][j] << " \n"[j == w - 1];

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.280361435433311x):
#include<stdio.h>

#include<stdlib.h>

#define SWAP(a,b) ((a)^=(b)^=(a)^=(b))

typedef long long ll;

int map[105][105];

int col[10005];

int main(void)

{

	int H, W, N;

	scanf("%d %d %d", &H, &W, &N);

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

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

	int i, j, m, s = 1, a = 0, b = W - 1;

	i = j = m = 0;

	while (m < N)

	{

		for (int k = 0; k < col[m]; k++) {

			map[i][j] = m + 1;

			if (j == b)

				SWAP(a, b), s = -s, i++;

			else

				j += s;

		}

		m++;

	}

	for (int i = 0; i < H; putchar('\n'),i++)

		for (int j = 0; j < W; j++)

			printf("%d ", map[i][j]);

	return 0;

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

using namespace std;

int a[101][101],b[10001];

int main ()

{

	int h,w;

	scanf("%d%d",&h,&w);

		int i,j,t,k=0;

		scanf("%d",&t);

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

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

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

		{

			if(i%2==0)

				for(j=0;j<w;j++)

				{

					a[i][j]=k+1;

					b[k]--;

					if(b[k]==0)

						k++;

				}

			if(i%2==1)

				for(j=w-1;j>=0;j--)

				{

					a[i][j]=k+1;

					b[k]--;

					if(b[k]==0)

						k++;

				}

		}

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

		{

			for(j=0;j<w-1;j++)

				printf("%d ",a[i][j]);

			printf("%d\n",a[i][w-1]);

		}

		return 0;

	}




// Faster C++ solution for the same problem (measured speedup: 5.150053070905351x):
#include<stdio.h>

#include<stdlib.h>

#define SWAP(a,b) ((a)^=(b)^=(a)^=(b))

typedef long long ll;

int map[105][105];

int col[10005];

int main(void)

{

	int H, W, N;

	scanf("%d %d %d", &H, &W, &N);

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

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

	int i, j, m, s = 1, a = 0, b = W - 1;

	i = j = m = 0;

	while (m < N)

	{

		for (int k = 0; k < col[m]; k++) {

			map[i][j] = m + 1;

			if (j == b)

				SWAP(a, b), s = -s, i++;

			else

				j += s;

		}

		m++;

	}

	for (int i = 0; i < H; putchar('\n'),i++)

		for (int j = 0; j < W; j++)

			printf("%d ", map[i][j]);

	return 0;

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

using namespace std;

int main(){

	int a,b,c,js=0,s;

	cin>>a>>b>>c;

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

	{

		cin>>s;

		if(s>=c||s<b)

		js++;

	}

	cout<<js<<endl;

}

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

int main()

{

    int a,b,c,ans=0;

    scanf("%d%d%d",&a,&b,&c);

    int s[a];

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

    {

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

        if(s[i]<b||s[i]>=c)

            ans++;

    }

    printf("%d\n",ans);

    return 0;

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

using namespace std;

const int TAM = 100003;

typedef long long ll;



ll arr [TAM], acum [TAM], n;



int main(){



    scanf("%lld",&n);

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

        scanf("%lld",&arr[i]);

        acum[i] = arr[i];

        if( i ) acum[i] += acum[i-1];

    }

    ll del = 0, ca = 0, cb = 0;

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

        if( i%2 ){

            if( acum[i] + del >= 0 ){

                ca += (acum[i] + del + 1);

                del -= (acum[i] + del + 1);

            }

        }else{

            if( acum[i] + del <= 0 ){

                ca += (-(acum[i] + del) + 1);

                del += (-(acum[i] + del) + 1);

            }

        }

    }

    del = 0;

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

        if( i%2 == 0 ){

            if( acum[i] + del >= 0 ){

                cb += (acum[i] + del + 1);

                del -= (acum[i] + del + 1);

            }

        }else{

            if( acum[i] + del <= 0 ){

                cb += (-(acum[i] + del) + 1);

                del += (-(acum[i] + del) + 1);

            }

        }

    }

    ca = min(ca,cb);

    printf("%lld\n",ca);



    return 0;

}


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

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

}


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

}
// Slower C++ solution:
/*

 * 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);



}

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

}
// 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: 1.7975320059086382x):
//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);

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









}


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

}