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

   

 using namespace std;

   

 #define MP make_pair

 #define PB push_back

 typedef long long LL;

 typedef pair<int,int> PII;

 const double eps=1e-8;

 const double pi=acos(-1.0);

 const int K=1e6+7;

 const int mod=1e9+7;

  

 int r,c,n,x,y,ans[200][200];

  

 int main(void)

 {

     scanf("%d%d%d",&r,&c,&n);

     x=1,y=1;

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

     {

         scanf("%d",&cnt);

         while(cnt--)

         {

             ans[x][y]=i;

             if(y==c&&x%2==1)

                 y=c,x++;

             else if(y==1&&x%2==0)

                 y=1,x++;

             else if(x&1)

                 y++;

             else

                 y--;

         }

     }

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

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

         printf("%d%c",ans[i][j],j==c?'\n':' ');

     return 0;

 }


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

int p[100 + 10][100 + 10];

int a[10000 + 10];

int h, w, n;



int main() {

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

	for (int i = 1;i <= n;i++)scanf("%d", &a[i]);

	int i = 1, j = 1, t = h*w, k = 1;

	while (t--) {

		p[i][j] = k;

		a[k]--;

		if (!a[k])k++;

		if (j & 1) {

			if (i == h)j++;

			else i++;

		}

		else {

			if (i == 1)j++;

			else i--;

		}

	}

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

		for (int j = 1;j < w;j++)printf("%d ", p[i][j]);

		printf("%d\n", p[i][w]);

	}

	for (int j = 1;j < w;j++)printf("%d ", p[h][j]);

	printf("%d", p[h][w]);

	return 0;

}

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

using namespace std;

int h,l;

int sumn;

int x,y;

int answer[200][200];



int main()

{

    cin>>h>>l>>sumn;

    x=1,y=1;

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

    {

        int count;

        cin>>count;

        while(count--)

        {

            answer[x][y]=i;

            if(y==l&&x%2==1)

                {y=l;x++;}

            else if(y==1&&x%2==0)

                {y=1;x++;}

            else if(x&1)

                y++;

            else

                y--;

        }

    }

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

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

            {

			 printf("%d%c",answer[i][j],j==l?'\n':' ');

        	}

    return 0;

}

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

int p[100 + 10][100 + 10];

int a[10000 + 10];

int h, w, n;



int main() {

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

	for (int i = 1;i <= n;i++)scanf("%d", &a[i]);

	int i = 1, j = 1, t = h*w, k = 1;

	while (t--) {

		p[i][j] = k;

		a[k]--;

		if (!a[k])k++;

		if (j & 1) {

			if (i == h)j++;

			else i++;

		}

		else {

			if (i == 1)j++;

			else i--;

		}

	}

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

		for (int j = 1;j < w;j++)printf("%d ", p[i][j]);

		printf("%d\n", p[i][w]);

	}

	for (int j = 1;j < w;j++)printf("%d ", p[h][j]);

	printf("%d", p[h][w]);

	return 0;

}

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

#include<cstdio>

using namespace std;



int dx[4]={1,-1,0,0};



int h,w,n;

int cnt;

int a[100005];

int ans[105][105];



void dfs(int x,int y,int l,int f){

	ans[x][y]=a[l];

//	cout<<x<<" "<<y<<" "<<l<<endl;

	if(l==h*w)return;

	int xx=x+dx[f];

	if(xx<=h&&xx>0)dfs(xx,y,l+1,f);else dfs(x,y+1,l+1,f^1);

}



int main(){

	cin>>h>>w>>n;

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

		int x;

		cin>>x;

		while(x--){

			a[++cnt]=i;

		}

	}

	dfs(1,1,1,0);

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

		for(int j=1;j<=w;j++)cout<<ans[i][j]<<" ";

		cout<<endl;

	}

}

// Optimized solution to the same problem (faster):
//蛇形填数



#include<stdio.h>



int main(){

	int H,W,N;int num[10001];int ans[100][100];

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

	scanf("%d",&N);

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

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

	}

	int hs=0,he=H-1,ws=0,we=W-1;

	int nowh=0,noww=0;

	bool flagr=true,flagd=false,flagl=false,flagt=false;

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

		while(num[i]--){

			if(flagr){

				ans[nowh][noww++]=i;

				if(noww>we){

					flagr=false;

					noww=we;

					nowh++;

					hs++;

					flagd=true;

				}

			}

			else if(flagd){

				ans[nowh++][noww]=i;

				if(nowh>he){

					flagd=false;

					nowh=he;

					noww--;

					we--;

					flagl=true;

				}

			}

			else if(flagl){

				ans[nowh][noww--]=i;

				if(noww<ws){

					flagl=false;

					noww=ws;

					nowh--;

					he--;

					flagt=true;

				}

			}

			else if(flagt){

				ans[nowh--][noww]=i;

				if(nowh<hs){

					flagt=false;

					nowh=hs;

					noww++;

					ws++;

					flagr=true;

				}

			}

		}

	}

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

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

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

			if(j!=W-1)

				printf(" ");

			else

				printf("\n"); 

		}

	}

	return 0;

} 

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

using namespace std ;

const int maxn = 1e4 + 10 ;

int a[maxn] , n , w , h , mat[110][100];

int main()

{

	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

	cin >>h >> w >>  n ;

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

		cin >> a[i] ;

	int x = 1 ;

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

	{

		if ( i%2 == 1 ) 

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

			{

				//cout << x <<" " << a[x] << endl;

				if ( a[x] ) 

					mat[i][j] = x, a[x]-- ;

				else x++ , mat[i][j] = x , a[x] -- ;



			}

		else

		{

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

			{

				//cout << x << " " << a[x] << endl;

				if (a[x] )

					mat[i][j] = x , a[x]--;

				else

					x++ , mat[i][j] = x , a[x] -- ;

			}

		}

	}

	//cout << " **** " << endl;

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

	{

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

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

		cout << "\n" ;

	}	



}


// Optimized solution to the same problem (faster):
//蛇形填数



#include<stdio.h>



int main(){

	int H,W,N;int num[10001];int ans[100][100];

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

	scanf("%d",&N);

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

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

	}

	int hs=0,he=H-1,ws=0,we=W-1;

	int nowh=0,noww=0;

	bool flagr=true,flagd=false,flagl=false,flagt=false;

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

		while(num[i]--){

			if(flagr){

				ans[nowh][noww++]=i;

				if(noww>we){

					flagr=false;

					noww=we;

					nowh++;

					hs++;

					flagd=true;

				}

			}

			else if(flagd){

				ans[nowh++][noww]=i;

				if(nowh>he){

					flagd=false;

					nowh=he;

					noww--;

					we--;

					flagl=true;

				}

			}

			else if(flagl){

				ans[nowh][noww--]=i;

				if(noww<ws){

					flagl=false;

					noww=ws;

					nowh--;

					he--;

					flagt=true;

				}

			}

			else if(flagt){

				ans[nowh--][noww]=i;

				if(nowh<hs){

					flagt=false;

					nowh=hs;

					noww++;

					ws++;

					flagr=true;

				}

			}

		}

	}

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

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

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

			if(j!=W-1)

				printf(" ");

			else

				printf("\n"); 

		}

	}

	return 0;

} 

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

using namespace std;



int main(){

	int h,w;

	cin>>h>>w;

	int n;

	cin>>n;

	int a[n];

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

		cin>>a[i];

	}

	vector<int>vc[h];

	int ans=1;

	int i=0;

	while(i<h){

		if(a[ans-1]==0){

			ans++;

		}

		else{

			vc[i].push_back(ans);

			a[ans-1]--;

		}

		if(vc[i].size()==w){

			i++;

		}

	}

	int jvb=0;

	for(int j=0;j<h;j++){

		if(jvb%2==0){

			for(int k=0;k<vc[j].size();k++){

				cout<<vc[j][k]<<" ";

			}

		}

		else{

			for(int k=vc[j].size()-1;k>=0;k--){

				cout<<vc[j][k]<<" ";

			}

		}

		jvb++;

		cout<<endl;

	}

}

// Optimized solution to the same problem (faster):
//蛇形填数



#include<stdio.h>



int main(){

	int H,W,N;int num[10001];int ans[100][100];

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

	scanf("%d",&N);

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

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

	}

	int hs=0,he=H-1,ws=0,we=W-1;

	int nowh=0,noww=0;

	bool flagr=true,flagd=false,flagl=false,flagt=false;

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

		while(num[i]--){

			if(flagr){

				ans[nowh][noww++]=i;

				if(noww>we){

					flagr=false;

					noww=we;

					nowh++;

					hs++;

					flagd=true;

				}

			}

			else if(flagd){

				ans[nowh++][noww]=i;

				if(nowh>he){

					flagd=false;

					nowh=he;

					noww--;

					we--;

					flagl=true;

				}

			}

			else if(flagl){

				ans[nowh][noww--]=i;

				if(noww<ws){

					flagl=false;

					noww=ws;

					nowh--;

					he--;

					flagt=true;

				}

			}

			else if(flagt){

				ans[nowh--][noww]=i;

				if(nowh<hs){

					flagt=false;

					nowh=hs;

					noww++;

					ws++;

					flagr=true;

				}

			}

		}

	}

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

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

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

			if(j!=W-1)

				printf(" ");

			else

				printf("\n"); 

		}

	}

	return 0;

} 

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



using namespace std;

typedef pair <int, int> pii;



const int maxn = 10001;



int h,w,a[maxn],p=1,n;

stack <int> v;

void input();

void solve();



int main(){

	input();

	solve();

	

	return 0;

}

void input(){

	cin>>h>>w>>n;

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

		cin>>a[i];

	}

}

void solve(){

	for (int j=0;j<h;j++){

		if (j%2==0){

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

				if (a[p]>1){

					cout<<p<<" ";

					a[p]--;

				}

				else{

					cout<<p<<" ";

					a[p]--;

					p++;

				}

			}

		}

		else{

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

				if (a[p]>1){

					v.push(p);

					a[p]--;

				}

				else{

					v.push(p);

					a[p]--;

					p++;

				}

			}

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

				cout<<v.top()<<" ";

				v.pop();

			}

		}

		cout<<endl;

	}

}

// Optimized solution to the same problem (faster):
//蛇形填数



#include<stdio.h>



int main(){

	int H,W,N;int num[10001];int ans[100][100];

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

	scanf("%d",&N);

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

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

	}

	int hs=0,he=H-1,ws=0,we=W-1;

	int nowh=0,noww=0;

	bool flagr=true,flagd=false,flagl=false,flagt=false;

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

		while(num[i]--){

			if(flagr){

				ans[nowh][noww++]=i;

				if(noww>we){

					flagr=false;

					noww=we;

					nowh++;

					hs++;

					flagd=true;

				}

			}

			else if(flagd){

				ans[nowh++][noww]=i;

				if(nowh>he){

					flagd=false;

					nowh=he;

					noww--;

					we--;

					flagl=true;

				}

			}

			else if(flagl){

				ans[nowh][noww--]=i;

				if(noww<ws){

					flagl=false;

					noww=ws;

					nowh--;

					he--;

					flagt=true;

				}

			}

			else if(flagt){

				ans[nowh--][noww]=i;

				if(nowh<hs){

					flagt=false;

					nowh=hs;

					noww++;

					ws++;

					flagr=true;

				}

			}

		}

	}

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

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

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

			if(j!=W-1)

				printf(" ");

			else

				printf("\n"); 

		}

	}

	return 0;

} 

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

#include <stdio.h>

#include <iomanip>

#include <climits>

#include <vector>

#include <string>

#define REP(a,b) for(int a=0; a<b; a++)

using namespace std;



vector <int> colors;

int canvas[105][105];



int main() {

  ios_base::sync_with_stdio(false);

  int H, W, N, c;

  cin >> H >> W >> N;

  colors.push_back(0);

  REP(i, N){

    int temp;

    cin >> temp;

    colors.push_back(temp);

  }

  c = 1;

  REP(i, H){

    if(i % 2 == 0){

      REP(j, W){

        canvas[i][j] = c;

        colors[c]--;

        if(colors[c] == 0) c++;

      }

    }else{

      for(int j = W-1; j >= 0; j--){

        canvas[i][j] = c;

        colors[c]--;

        if(colors[c] == 0) c++;

      } 

    }

  }

  REP(i, H){

    REP(j, W){

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

    }

    cout << endl;

  }

}

// Optimized solution to the same problem (faster):
//蛇形填数



#include<stdio.h>



int main(){

	int H,W,N;int num[10001];int ans[100][100];

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

	scanf("%d",&N);

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

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

	}

	int hs=0,he=H-1,ws=0,we=W-1;

	int nowh=0,noww=0;

	bool flagr=true,flagd=false,flagl=false,flagt=false;

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

		while(num[i]--){

			if(flagr){

				ans[nowh][noww++]=i;

				if(noww>we){

					flagr=false;

					noww=we;

					nowh++;

					hs++;

					flagd=true;

				}

			}

			else if(flagd){

				ans[nowh++][noww]=i;

				if(nowh>he){

					flagd=false;

					nowh=he;

					noww--;

					we--;

					flagl=true;

				}

			}

			else if(flagl){

				ans[nowh][noww--]=i;

				if(noww<ws){

					flagl=false;

					noww=ws;

					nowh--;

					he--;

					flagt=true;

				}

			}

			else if(flagt){

				ans[nowh--][noww]=i;

				if(nowh<hs){

					flagt=false;

					nowh=hs;

					noww++;

					ws++;

					flagr=true;

				}

			}

		}

	}

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

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

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

			if(j!=W-1)

				printf(" ");

			else

				printf("\n"); 

		}

	}

	return 0;

} 

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

#define maxn 110

using namespace std;

int sq[maxn][maxn];

int color[10100];

int n,h,w;

int main(){

	cin>>h>>w;

	cin>>n;

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

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

	}

	getchar();

	int k=1;

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

		if(i%2==0){

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

				if(color[k]!=0){

					sq[i][j]=k;

					color[k]--;

				}

				if(color[k]==0){

					k++;

				}

			}

		}

		if(i%2==1){

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

				if(color[k]!=0){

					sq[i][j]=k;

					color[k]--;

				}

				if(color[k]==0){

					k++;

				}				

			}

		}

	}

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

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

			cout<<sq[i][j];

			if(j!=w-1){

				cout<<" ";

			}

		}

		cout<<endl;

	}

}

// Optimized solution to the same problem (faster):
//蛇形填数



#include<stdio.h>



int main(){

	int H,W,N;int num[10001];int ans[100][100];

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

	scanf("%d",&N);

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

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

	}

	int hs=0,he=H-1,ws=0,we=W-1;

	int nowh=0,noww=0;

	bool flagr=true,flagd=false,flagl=false,flagt=false;

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

		while(num[i]--){

			if(flagr){

				ans[nowh][noww++]=i;

				if(noww>we){

					flagr=false;

					noww=we;

					nowh++;

					hs++;

					flagd=true;

				}

			}

			else if(flagd){

				ans[nowh++][noww]=i;

				if(nowh>he){

					flagd=false;

					nowh=he;

					noww--;

					we--;

					flagl=true;

				}

			}

			else if(flagl){

				ans[nowh][noww--]=i;

				if(noww<ws){

					flagl=false;

					noww=ws;

					nowh--;

					he--;

					flagt=true;

				}

			}

			else if(flagt){

				ans[nowh--][noww]=i;

				if(nowh<hs){

					flagt=false;

					nowh=hs;

					noww++;

					ws++;

					flagr=true;

				}

			}

		}

	}

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

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

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

			if(j!=W-1)

				printf(" ");

			else

				printf("\n"); 

		}

	}

	return 0;

} 

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

#include<cstdio>

using namespace std;

int step(int &x,int &y,int h,int w)//奇数行=>;偶数行<=

{

    if((x%2==1 && y==w && x==h)||(x%2==0 && x==h && y==1))return 0;

    if(x%2==1)if(y==w){x++;return 0;}else {y++;return 0;}

    if(x%2==0)if(y==1){x++;return 0;}else {y--;return 0;}

    return 0;

}

int main()

{

    int h,w,n,g[105][105],a[10002];

    cin>>h>>w>>n;

    for(int i=1;i<=n;i++)scanf("%d",&a[i]);

    int x=1,y=1;

    int temp=1;

    int color=0;

    while(temp<=h*w)

    {

        color++;

        for(int j=1;j<=a[color];j++)

        {

            temp++;

            g[x][y]=color;

            step(x,y,h,w);

        }

    }

    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<cmath>

#include<cstdio>

#include<stdlib.h>

#include<algorithm>

#include<cstring>

#include<iostream>

#include<iomanip>

#include<string>

using namespace std;

int main()

{

	int a,b,cont[10000+50],boom[105][105];

	while(cin>>a>>b)

	{

		memset(cont,0,sizeof(cont));

		memset(boom,0,sizeof(boom));

		int n,i,j,sum=0;

		cin>>n;

		//temp=n;

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

			cin>>cont[i];

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

		{

			if(i%2==0)

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

				{

					boom[i][j]=sum+1;

					cont[sum]--;

					if(cont[sum]==0)sum++;

				}

			else

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

				{

					boom[i][j]=sum+1;

					cont[sum]--;

					if(cont[sum]==0)sum++;

				}

		}

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

		{

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

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

			cout<<boom[i][j]<<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>

using namespace std;

int main()

{

	int map[110][110];

	int n,m,i,j,num,x,y,t,flag;

	while(~scanf("%d %d",&n,&m))

	{

		scanf("%d",&t);

		x=1;y=1;flag=1;

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

		{

			scanf("%d",&num);

			for(j=1;j<=num;j++)

			{

				map[x][y]=i;

				if(flag)

				{

					y++;

					if(y>m)

					{

						flag=0;

						x++;y--;

					}

				}

				else

				{

					y--;

					if(y<=0)

					{

						flag=1;

						x++;y++;

					}

				}

			}

		}

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

		{

			for(j=1;j<m;j++)

			{

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

			}

			printf("%d\n",map[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 <cmath>

#include <cstdlib>

#include <ctime>

#include <vector>

#include <cstring>

#include <algorithm>

#include <numeric>

#define maxn 1000000



using namespace std;



int paint[110][110];

int main()

{

    int h,w,n,x=0;

    cin>>h>>w>>n;

    int a[n];

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

    {

        cin>>a[i];

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

        {

            if((x/w)%2==0) paint[x/w][x%w]=i+1;

            else paint[x/w][w-(x%w)-1]=i+1;

            x++;

        }

    }

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

    {

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

        {

            if(j==w-1) printf("%d\n",paint[i][j]);

            else printf("%d ",paint[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 <cmath>

#include <cstdlib>

#include <ctime>

#include <vector>

#include <cstring>

#include <algorithm>

#include <numeric>

#define maxn 1000000



using namespace std;



int paint[110][110];

int main()

{

    int h,w,n,x=0;

    cin>>h>>w>>n;

    int a[n];

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

    {

        cin>>a[i];

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

        {

            if((x/w)%2==0) paint[x/w][x%w]=i+1;

            else paint[x/w][w-(x%w)-1]=i+1;

            x++;

        }

    }

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

    {

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

        {

            if(j==w-1) printf("%d\n",paint[i][j]);

            else printf("%d ",paint[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>

using namespace std;

int main()

{

    int h,w,n,b[10000+50],a[105][105],i,j,k;

    while(cin>>h>>w>>n)

    {

        k=0;

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

        {

            cin>>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++;

                }

            }

            else

            {

                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;j++)

        {

            cout<<a[i][j];

            if(j==w-1)cout<<endl;

            else cout<<" ";

        }

    }

}


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