stablegradients/pie-gem5-pairs huggingface dataset:
// 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.242757924126902x):
#include<cstdio>

const int maxn = 110;

int tag[maxn*maxn];

int tmp[maxn*maxn];

int ans[maxn][maxn];

int main()

{

	int n,m;

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

		int times,cnt = 1,change = 1;

		scanf("%d",&times);

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

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

			for(int j = 1; j<=tag[i]; j++){

				tmp[cnt] = i; cnt++;

			}

		}

		cnt = 1;

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

			if(change == 1){

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

					ans[i][j] = tmp[cnt];

					cnt++;

				}

			}else {

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

					ans[i][j] = tmp[cnt];

					cnt++;

				}

			}

			change = change * -1;

		}

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

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

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

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

			}

			printf("\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 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.163415073037507x):
#include<cstdio>

const int maxn = 110;

int tag[maxn*maxn];

int tmp[maxn*maxn];

int ans[maxn][maxn];

int main()

{

	int n,m;

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

		int times,cnt = 1,change = 1;

		scanf("%d",&times);

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

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

			for(int j = 1; j<=tag[i]; j++){

				tmp[cnt] = i; cnt++;

			}

		}

		cnt = 1;

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

			if(change == 1){

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

					ans[i][j] = tmp[cnt];

					cnt++;

				}

			}else {

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

					ans[i][j] = tmp[cnt];

					cnt++;

				}

			}

			change = change * -1;

		}

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

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

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

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

			}

			printf("\n");

		}

	}

	return 0;

}
// Slower C++ solution:
//20-27行描述了填色标准，算法核心

//为什么这么移动？

//走S形

//在奇数行时，向右移动；在偶数行时，向左移动

//奇数行末尾，列数达到最大，向下移动；偶数行末尾，列数为1，向下移动

//用代码描述一下就是这样

//理论上还可以选择另一种S形状，即“竖过来”

#include <bits/stdc++.h>

using namespace std;

int r,c;//行数、列数

int n;//颜色总数

int x,y;//当前待着色点坐标

int ans[200][200];//答案记录表



int main()

{

    cin>>r>>c>>n;//分别输入行数、列数、颜色总数

    x=1,y=1;//初始坐标设置为（1，1）

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

    {

        int cnt;//“当前颜色剩余着色块数”计数器

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

}


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

const int maxn = 110;

int tag[maxn*maxn];

int tmp[maxn*maxn];

int ans[maxn][maxn];

int main()

{

	int n,m;

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

		int times,cnt = 1,change = 1;

		scanf("%d",&times);

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

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

			for(int j = 1; j<=tag[i]; j++){

				tmp[cnt] = i; cnt++;

			}

		}

		cnt = 1;

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

			if(change == 1){

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

					ans[i][j] = tmp[cnt];

					cnt++;

				}

			}else {

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

					ans[i][j] = tmp[cnt];

					cnt++;

				}

			}

			change = change * -1;

		}

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

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

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

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

			}

			printf("\n");

		}

	}

	return 0;

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

#include<iostream>

#include<cstring>



using namespace std;



int a[10010];

int pic[110][110];



int main()

{

    int H,W,N;

    int i,j,k=0;

    memset(a,0,sizeof(a));

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

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

    {

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

    }

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

    {

        if(i%2==0)

        {

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

            {

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

                --a[k];

                if(a[k]==0)++k;

            }

        }

        if(i%2==1)

        {

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

            {

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

                --a[k];

                if(a[k]==0)++k;

            }

        }

    }

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

    {

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

        {

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

            if(j==W-1)printf("\n");

            else printf(" ");

        }

    }

    return 0;

}

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

const int maxn = 110;

int tag[maxn*maxn];

int tmp[maxn*maxn];

int ans[maxn][maxn];

int main()

{

	int n,m;

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

		int times,cnt = 1,change = 1;

		scanf("%d",&times);

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

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

			for(int j = 1; j<=tag[i]; j++){

				tmp[cnt] = i; cnt++;

			}

		}

		cnt = 1;

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

			if(change == 1){

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

					ans[i][j] = tmp[cnt];

					cnt++;

				}

			}else {

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

					ans[i][j] = tmp[cnt];

					cnt++;

				}

			}

			change = change * -1;

		}

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

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

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

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

			}

			printf("\n");

		}

	}

	return 0;

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

#include <iostream>

using namespace std;

int xx[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) xx[x/w][x%w]=i+1;

            else xx[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",xx[i][j]);

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

        }

    }

    return 0;

}


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

const int maxn = 110;

int tag[maxn*maxn];

int tmp[maxn*maxn];

int ans[maxn][maxn];

int main()

{

	int n,m;

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

		int times,cnt = 1,change = 1;

		scanf("%d",&times);

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

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

			for(int j = 1; j<=tag[i]; j++){

				tmp[cnt] = i; cnt++;

			}

		}

		cnt = 1;

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

			if(change == 1){

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

					ans[i][j] = tmp[cnt];

					cnt++;

				}

			}else {

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

					ans[i][j] = tmp[cnt];

					cnt++;

				}

			}

			change = change * -1;

		}

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

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

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

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

			}

			printf("\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;

int a[100005];

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.134977898644315x):
#include<cstdio>

const int maxn = 110;

int tag[maxn*maxn];

int tmp[maxn*maxn];

int ans[maxn][maxn];

int main()

{

	int n,m;

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

		int times,cnt = 1,change = 1;

		scanf("%d",&times);

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

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

			for(int j = 1; j<=tag[i]; j++){

				tmp[cnt] = i; cnt++;

			}

		}

		cnt = 1;

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

			if(change == 1){

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

					ans[i][j] = tmp[cnt];

					cnt++;

				}

			}else {

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

					ans[i][j] = tmp[cnt];

					cnt++;

				}

			}

			change = change * -1;

		}

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

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

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

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

			}

			printf("\n");

		}

	}

	return 0;

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

using namespace std;

int ans[200][200];

int main(){

	int x,y;

	int dir=1;

	cin>>y>>x;

	int n;

	cin>>n;

	int posx=1,posy=1;

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

	int xc;

	cin>>xc;

	for(int x1=1;x1<=xc;++x1){

	ans[posy][posx]=a;

	posx+=dir; 

	if(posx>x||posx==0){posy++;dir=-dir;if(posx==0)posx=1;else posx=x;}

	}

	

	}

	for(int a1=1;a1<=y;++a1){

	for(int a2=1;a2<=x;++a2){

	cout<<ans[a1][a2];

	if(a2==x)cout<<endl;else cout<<" ";

	}}

	

	

	

	

	return 0;} 

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

const int maxn = 110;

int tag[maxn*maxn];

int tmp[maxn*maxn];

int ans[maxn][maxn];

int main()

{

	int n,m;

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

		int times,cnt = 1,change = 1;

		scanf("%d",&times);

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

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

			for(int j = 1; j<=tag[i]; j++){

				tmp[cnt] = i; cnt++;

			}

		}

		cnt = 1;

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

			if(change == 1){

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

					ans[i][j] = tmp[cnt];

					cnt++;

				}

			}else {

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

					ans[i][j] = tmp[cnt];

					cnt++;

				}

			}

			change = change * -1;

		}

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

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

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

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

			}

			printf("\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]);

            }

        }

    }

///for(int i = 0;)

    return 0;

}

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

const int maxn = 110;

int tag[maxn*maxn];

int tmp[maxn*maxn];

int ans[maxn][maxn];

int main()

{

	int n,m;

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

		int times,cnt = 1,change = 1;

		scanf("%d",&times);

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

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

			for(int j = 1; j<=tag[i]; j++){

				tmp[cnt] = i; cnt++;

			}

		}

		cnt = 1;

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

			if(change == 1){

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

					ans[i][j] = tmp[cnt];

					cnt++;

				}

			}else {

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

					ans[i][j] = tmp[cnt];

					cnt++;

				}

			}

			change = change * -1;

		}

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

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

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

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

			}

			printf("\n");

		}

	}

	return 0;

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



using namespace std;



int a[10010];

int g[110][110];



int main()

{

	int h , w;

	cin >> h >> w;

	int n;

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

			{

				if(a[x] > 0)

				{

					g[i][j] = x;

					a[x]--;

				}

				else

				{

					x++;

					g[i][j] = x;

					a[x]--;

				}

			}

		}

		else

		{

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

			{

				if(a[x] > 0)

				{

					g[i][j] = x;

					a[x]--;

				}

				else

				{

					x++;

					g[i][j] = x;

					a[x]--;

				}

			}

		}

	}

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

	{

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

		{

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

		}

		cout << endl;

	}

	

	return 0;

}

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

const int maxn = 110;

int tag[maxn*maxn];

int tmp[maxn*maxn];

int ans[maxn][maxn];

int main()

{

	int n,m;

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

		int times,cnt = 1,change = 1;

		scanf("%d",&times);

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

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

			for(int j = 1; j<=tag[i]; j++){

				tmp[cnt] = i; cnt++;

			}

		}

		cnt = 1;

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

			if(change == 1){

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

					ans[i][j] = tmp[cnt];

					cnt++;

				}

			}else {

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

					ans[i][j] = tmp[cnt];

					cnt++;

				}

			}

			change = change * -1;

		}

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

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

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

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

			}

			printf("\n");

		}

	}

	return 0;

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



using namespace std;



int board[105][105];



int main(){

	

	int H,W,N;

	while(scanf("%d %d %d",&H,&W,&N) == 3){

		memset(board,0,sizeof board);

		int x = 1,y = 1;

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

			int t;

			scanf("%d",&t);

			while(t){

				board[x][y] = i;

				--t;

				if(y<W && !board[x][y+1])++y;

				else if(x<H && !board[x+1][y])++x;

				else if(y>1 && !board[x][y-1])--y;

				else if(x>1 && !board[x-1][y])--x;

			}

		}

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

			printf("%d",board[i][1]);

			for(int j=2 ; j<=W ; ++j)printf(" %d",board[i][j]);

			printf("\n");

		}

	}

	

	return 0;

} 

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

const int maxn = 110;

int tag[maxn*maxn];

int tmp[maxn*maxn];

int ans[maxn][maxn];

int main()

{

	int n,m;

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

		int times,cnt = 1,change = 1;

		scanf("%d",&times);

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

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

			for(int j = 1; j<=tag[i]; j++){

				tmp[cnt] = i; cnt++;

			}

		}

		cnt = 1;

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

			if(change == 1){

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

					ans[i][j] = tmp[cnt];

					cnt++;

				}

			}else {

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

					ans[i][j] = tmp[cnt];

					cnt++;

				}

			}

			change = change * -1;

		}

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

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

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

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

			}

			printf("\n");

		}

	}

	return 0;

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

using namespace std;

typedef  long long ll ;

const int maxn=1e2+3,maxxn=1e4+2;

vector<pair<int,int> >v[maxn][maxn];

bool mark[maxn][maxn];

int ans[maxn][maxn];

pair<int,int>p[maxxn];

int c;

void dfs(int u,int k){

    mark[u][k]=1;

    if(p[c].first<=0)c++;

    ans[u][k]=p[c].second;

    p[c].first--;

    for(int i=0;i<v[u][k].size();i++){

        int x1=v[u][k][i].first,y1=v[u][k][i].second;

        if(!mark[x1][y1])dfs(x1,y1);

    }

}

int main() {

    int h,w,n;

    cin>>h>>w>>n;

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

        int x;

        cin>>x;

        p[i]=make_pair(x,i+1);

    }

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

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

            if(j+1<=w)v[i][j].push_back(make_pair(i,j+1));

            if(j-1>0)v[i][j].push_back(make_pair(i,j-1));

            if(i+1<=h)v[i][j].push_back(make_pair(i+1,j));

            if(i-1>0)v[i][j].push_back(make_pair(i-1,j));

        }

    }

    dfs(1,1);

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

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

        cout<<endl;

    }

    return 0;

}

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

const int maxn = 110;

int tag[maxn*maxn];

int tmp[maxn*maxn];

int ans[maxn][maxn];

int main()

{

	int n,m;

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

		int times,cnt = 1,change = 1;

		scanf("%d",&times);

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

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

			for(int j = 1; j<=tag[i]; j++){

				tmp[cnt] = i; cnt++;

			}

		}

		cnt = 1;

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

			if(change == 1){

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

					ans[i][j] = tmp[cnt];

					cnt++;

				}

			}else {

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

					ans[i][j] = tmp[cnt];

					cnt++;

				}

			}

			change = change * -1;

		}

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

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

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

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

			}

			printf("\n");

		}

	}

	return 0;

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

using namespace std;



#define LL long long

#define LD long double

#define Mod 1000000007

#define L_Mod 17100000013



const double eps = 1e-9;

const int INF = 0x3f3f3f3f;

const double PI = 3.1415926535;



#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);



#define ree(a,n) memset(a,n,si 2)



#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))

#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))

#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))





int main()

{

    LL i,j,w,h,n,m,a[105][105]= {0},tp[10013]= {0},num=0;

    cin>>w>>h;

    cin>>n;

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

        cin>>tp[i];

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

    {

        if(i%2==0)

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

            {

                if(tp[num]==0)

                    num++;

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

                tp[num]--;

            }

        else

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

            {

                if(tp[num]==0)

                    num++;

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

                tp[num]--;



            }

    }

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

    {

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

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

        cout<<endl;

    }

}


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

const int maxn = 110;

int tag[maxn*maxn];

int tmp[maxn*maxn];

int ans[maxn][maxn];

int main()

{

	int n,m;

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

		int times,cnt = 1,change = 1;

		scanf("%d",&times);

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

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

			for(int j = 1; j<=tag[i]; j++){

				tmp[cnt] = i; cnt++;

			}

		}

		cnt = 1;

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

			if(change == 1){

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

					ans[i][j] = tmp[cnt];

					cnt++;

				}

			}else {

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

					ans[i][j] = tmp[cnt];

					cnt++;

				}

			}

			change = change * -1;

		}

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

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

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

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

			}

			printf("\n");

		}

	}

	return 0;

}