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

	}

}

// Faster C++ solution for the same problem (measured speedup: 5.2568999003440675x):
//蛇形填数



#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;

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

  }

}

// Faster C++ solution for the same problem (measured speedup: 5.288778160075069x):
//蛇形填数



#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;

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

	}

}

// Faster C++ solution for the same problem (measured speedup: 5.226585584078328x):
//蛇形填数



#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;

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

}




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

int main ()

{

    int H,W,N,a[10005],b[10005],n;

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

    scanf("%d",&N);

    n=1;

    for (int ni=1;ni<=N;ni++) {scanf("%d",&a[ni]);for (int ai=1;ai<=a[ni];ai++) {b[n]=ni;n++;}}

    for (int hi=1;hi<=H;hi++)

    {

        if (hi%2==1)  {for (int wi=1;wi<=W;wi++) printf ("%d ",b[(hi-1)*W+wi]);printf("\n");}

        if (hi%2==0)  {for (int wi=1;wi<=W;wi++) printf ("%d ",b[(hi-1)*W+W-wi+1]);printf("\n");}

    }

    return 0;

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

}




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

#include<cstring>

#include<algorithm>

#include<string>

using namespace std;

int a[10010],ans[103][103];



int main()

{

	int h,w;

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

	int N;

	scanf("%d",&N);

	

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

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

	}

	int n = 1,m = 1,inc=1;

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

		int cnt=a[i];

		for(;cnt!=0;cnt--){

			ans[n][m] = i;

			m+=inc;

			if(m==w+1||m==0){

				n++;

				inc = -inc;

				m+=inc;

			}

		}

	}	

	

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

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

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

		} 

	} 

	return 0;

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

}


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

#include<cstring>

#include<algorithm>

#include<string>

using namespace std;

int a[10010],ans[103][103];



int main()

{

	int h,w;

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

	int N;

	scanf("%d",&N);

	

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

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

	}

	int n = 1,m = 1,inc=1;

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

		int cnt=a[i];

		for(;cnt!=0;cnt--){

			ans[n][m] = i;

			m+=inc;

			if(m==w+1||m==0){

				n++;

				inc = -inc;

				m+=inc;

			}

		}

	}	

	

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

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

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

		} 

	} 

	return 0;

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

}

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

#include<cstring>

#include<algorithm>

#include<string>

using namespace std;

int a[10010],ans[103][103];



int main()

{

	int h,w;

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

	int N;

	scanf("%d",&N);

	

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

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

	}

	int n = 1,m = 1,inc=1;

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

		int cnt=a[i];

		for(;cnt!=0;cnt--){

			ans[n][m] = i;

			m+=inc;

			if(m==w+1||m==0){

				n++;

				inc = -inc;

				m+=inc;

			}

		}

	}	

	

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

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

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

		} 

	} 

	return 0;

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

}


































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

#include<cstring>

#include<algorithm>

#include<string>

using namespace std;

int a[10010],ans[103][103];



int main()

{

	int h,w;

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

	int N;

	scanf("%d",&N);

	

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

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

	}

	int n = 1,m = 1,inc=1;

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

		int cnt=a[i];

		for(;cnt!=0;cnt--){

			ans[n][m] = i;

			m+=inc;

			if(m==w+1||m==0){

				n++;

				inc = -inc;

				m+=inc;

			}

		}

	}	

	

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

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

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

		} 

	} 

	return 0;

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

}


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

#include<cstring>

#include<algorithm>

#include<string>

using namespace std;

int a[10010],ans[103][103];



int main()

{

	int h,w;

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

	int N;

	scanf("%d",&N);

	

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

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

	}

	int n = 1,m = 1,inc=1;

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

		int cnt=a[i];

		for(;cnt!=0;cnt--){

			ans[n][m] = i;

			m+=inc;

			if(m==w+1||m==0){

				n++;

				inc = -inc;

				m+=inc;

			}

		}

	}	

	

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

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

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

		} 

	} 

	return 0;

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

        }

    }

}


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

#include<cstring>

#include<algorithm>

#include<string>

using namespace std;

int a[10010],ans[103][103];



int main()

{

	int h,w;

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

	int N;

	scanf("%d",&N);

	

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

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

	}

	int n = 1,m = 1,inc=1;

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

		int cnt=a[i];

		for(;cnt!=0;cnt--){

			ans[n][m] = i;

			m+=inc;

			if(m==w+1||m==0){

				n++;

				inc = -inc;

				m+=inc;

			}

		}

	}	

	

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

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

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

		} 

	} 

	return 0;

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

}


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

#include<cstring>

#include<algorithm>

#include<string>

using namespace std;

int a[10010],ans[103][103];



int main()

{

	int h,w;

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

	int N;

	scanf("%d",&N);

	

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

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

	}

	int n = 1,m = 1,inc=1;

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

		int cnt=a[i];

		for(;cnt!=0;cnt--){

			ans[n][m] = i;

			m+=inc;

			if(m==w+1||m==0){

				n++;

				inc = -inc;

				m+=inc;

			}

		}

	}	

	

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

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

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

		} 

	} 

	return 0;

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

            }

        }

    }

}

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

#include<cstring>

#include<algorithm>

#include<string>

using namespace std;

int a[10010],ans[103][103];



int main()

{

	int h,w;

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

	int N;

	scanf("%d",&N);

	

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

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

	}

	int n = 1,m = 1,inc=1;

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

		int cnt=a[i];

		for(;cnt!=0;cnt--){

			ans[n][m] = i;

			m+=inc;

			if(m==w+1||m==0){

				n++;

				inc = -inc;

				m+=inc;

			}

		}

	}	

	

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

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

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

		} 

	} 

	return 0;

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

}


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

#include<cstring>

#include<algorithm>

#include<string>

using namespace std;

int a[10010],ans[103][103];



int main()

{

	int h,w;

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

	int N;

	scanf("%d",&N);

	

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

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

	}

	int n = 1,m = 1,inc=1;

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

		int cnt=a[i];

		for(;cnt!=0;cnt--){

			ans[n][m] = i;

			m+=inc;

			if(m==w+1||m==0){

				n++;

				inc = -inc;

				m+=inc;

			}

		}

	}	

	

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

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

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

		} 

	} 

	return 0;

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

}

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

#include<cstring>

#include<algorithm>

#include<string>

using namespace std;

int a[10010],ans[103][103];



int main()

{

	int h,w;

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

	int N;

	scanf("%d",&N);

	

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

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

	}

	int n = 1,m = 1,inc=1;

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

		int cnt=a[i];

		for(;cnt!=0;cnt--){

			ans[n][m] = i;

			m+=inc;

			if(m==w+1||m==0){

				n++;

				inc = -inc;

				m+=inc;

			}

		}

	}	

	

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

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

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

		} 

	} 

	return 0;

}