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

#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

#include<set>

using namespace std;

typedef long long LL;

const int INF=0x3f3f3f3f;

const int MAXN=1e5+5;

int a[MAXN];

int G[105][105];



int main()

{

    int h,w;

    while(scanf("%d%d",&h,&w)!=EOF)

    {

        int n;

       cin>>n;

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

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

        int cnt=1;

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

        {

            if(i&1)

            {

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

                {

                   if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}

                   else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}

                }

            }else

            {

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

                {

                    if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}

                    else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}

                }

            }

        }

        for(int k=1;k<=h;++k)

        {

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

            {

                if(j!=w) printf("%d ",G[k][j]);

                else printf("%d\n",G[k][j]);

            }

        }

    }

    return 0;

}


// Optimized solution to the same problem (faster):
#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;

}

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

using namespace std;



const int MAXN=1e5+5;



int main()

{

	int a[MAXN];

	int b[110][110];

    int h,w;

    while(scanf("%d%d",&h,&w)!=EOF)

    {

        int n;cin>>n;

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

          cin>>a[i];

        int k=1;

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

        {

            if(i&1)

            {

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

                {

                   if(a[k]>0) {b[i][j]=k;--a[k];}

                   else if(a[k]==0) {++k;b[i][j]=k;--a[k];}

                }

            }

			else

            {

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

                {

                    if(a[k]>0) {b[i][j]=k;--a[k];}

                    else if(a[k]==0) {++k;b[i][j]=k;--a[k];}

                }

            }

        }

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

        {

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

            {

                if(j!=w) cout<<b[i][j]<<endl;

                else cout<<b[i][j]<<endl;

            }

        }

    }

}

// Optimized solution to the same problem (faster):
#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;

}

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

#include<cstdio>

#include<vector>

#include<cstring>

#include<cmath>

#include<algorithm>

#include<set>

using namespace std;

typedef long long LL;

const int INF=0x3f3f3f3f;

const int MAXN=1e5+5;

int a[MAXN];

int G[105][105];



int main()

{

    int h,w;

    while(scanf("%d%d",&h,&w)!=EOF)

    {

        int n;

        scanf("%d",&n);

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

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

        int cnt=1;

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

        {

            if(i&1)

            {

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

                {

                   if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}

                   else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}

                }

            }else

            {

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

                {

                    if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}

                    else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}

                }

            }

        }

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

        {

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

            {

                if(j!=w) printf("%d ",G[i][j]);

                else printf("%d\n",G[i][j]);

            }

        }

    }

    return 0;

}


// Optimized solution to the same problem (faster):
#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;

}

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

#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

#include<set>

using namespace std;

typedef long long LL;

const int INF=0x3f3f3f3f;

const int MAXN=1e5+5;

int a[MAXN];

int G[105][105];



int main()

{

    int h,w;

    while(scanf("%d%d",&h,&w)!=EOF)

    {

        int n;

        scanf("%d",&n);

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

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

        int cnt=1;

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

        {

            if(i&1)

            {

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

                {

                   if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}

                   else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}

                }

            }else

            {

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

                {

                    if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}

                    else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}

                }

            }

        }

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

        {

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

            {

                if(j!=w) printf("%d ",G[i][j]);

                else printf("%d\n",G[i][j]);

            }

        }

    }

///ajvnajk.vnafnv

    return 0;

}

// Optimized solution to the same problem (faster):
#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;

}

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


// in the name of Allah ;

#include<bits/stdc++.h>

using namespace std;

const int maxn = 1e2 + 10 ;

int n , m , q ;

int arr[maxn*maxn] , mat[maxn][maxn] ;

void input() 

{

	cin >> n >> m >> q ;

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

		cin >> arr[i] ;

}

int main()

{

	input() ;

	int p = 0 ;

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

	{

		if ( i % 2 ) 

		{

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

				if ( arr[p] ) 

					mat[i][j] = p , arr[p]-- ;

				else

					p++ , j-- ;

				

		}

		else

		{

			for ( int j = m-1 ; j >= 0 ; j-- ) 

				if ( arr[p] ) 

					mat[i][j] = p , arr[p]-- ;

				else

					p++ , j++ ; 

		}

	}

	for ( int i = 0 ; i < n ; cout << endl , i++ ) 

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

			cout << mat[i][j] +1 << " " ;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
# 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;

    }

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

	}

}














// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

	}




// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// 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: