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;

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;

}


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

#include <queue>;

using namespace std;



int cols[10010];

int res[101][101];

int main()

{

	int row, col, n;

	scanf("%d %d %d", &row, &col, &n);

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

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

	int c = 1;

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

	{

		if (i % 2 == 0)

		{

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

			{ 

				if (cols[c] <= 0)

					c++;

				res[i][j] = c;

				cols[c]--;

			}



		}

		else

		{

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

			{

				if (cols[c] <= 0)

					c++;

				res[i][j] = c;

				cols[c]--;

			}

		}

	}

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

	{

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

		{

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

			if (j != col - 1)

				printf(" ");

		}

		printf("\n");

	}

	return 0;

}

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

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

#include <queue>;

using namespace std;



int cols[10010];

int res[101][101];

int main()

{

	int row, col, n;

	scanf("%d %d %d", &row, &col, &n);

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

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

	int c = 1;

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

	{

		if (i % 2 == 0)

		{

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

			{ 

				if (cols[c] <= 0)

					c++;

				res[i][j] = c;

				cols[c]--;

			}



		}

		else

		{

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

			{

				if (cols[c] <= 0)

					c++;

				res[i][j] = c;

				cols[c]--;

			}

		}

	}

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

	{

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

		{

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

			if (j != col - 1)

				printf(" ");

		}

		printf("\n");

	}

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

            }

        }

    }

///for(int i = 0;)

    return 0;

}

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

#include <queue>;

using namespace std;



int cols[10010];

int res[101][101];

int main()

{

	int row, col, n;

	scanf("%d %d %d", &row, &col, &n);

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

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

	int c = 1;

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

	{

		if (i % 2 == 0)

		{

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

			{ 

				if (cols[c] <= 0)

					c++;

				res[i][j] = c;

				cols[c]--;

			}



		}

		else

		{

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

			{

				if (cols[c] <= 0)

					c++;

				res[i][j] = c;

				cols[c]--;

			}

		}

	}

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

	{

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

		{

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

			if (j != col - 1)

				printf(" ");

		}

		printf("\n");

	}

	return 0;

}

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

}

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

#include <queue>;

using namespace std;



int cols[10010];

int res[101][101];

int main()

{

	int row, col, n;

	scanf("%d %d %d", &row, &col, &n);

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

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

	int c = 1;

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

	{

		if (i % 2 == 0)

		{

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

			{ 

				if (cols[c] <= 0)

					c++;

				res[i][j] = c;

				cols[c]--;

			}



		}

		else

		{

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

			{

				if (cols[c] <= 0)

					c++;

				res[i][j] = c;

				cols[c]--;

			}

		}

	}

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

	{

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

		{

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

			if (j != col - 1)

				printf(" ");

		}

		printf("\n");

	}

	return 0;

}

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

}

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

}

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

    }

}


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

}

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

} 

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

}

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

#include<cstdio>

#include<iomanip>

#include<algorithm>

#include<vector>

#include<set>

#include<list>

#include<queue>

#include<deque>

#include<unordered_map>

#include<map>

#include<string>

#include<cstring>

#include<stack>

#include<cmath>



#define vint vector<int>

#define vstr vector<string>

#define vll vector<long long>

#define ll long long

#define pf printf

#define sf scanf

#define sfd(n) scanf("%d", &n)

#define sflf(n) scanf("%lf", &n)

#define sfll(n) scanf("%lld", &n)

#define pfd(n) printf("%d", n)

#define pflf(n) printf("%lf", n)

#define pfll(n) printf("%lld", n)

#define pft	printf("\t")

#define pfn printf("\n")

#define pfk printf(" ")

#define PI 3.1415926

#define MAX 100000

#define M 1e18



using namespace std;



int main() {

	int h, w;

	int n;

	sfd(h);

	sfd(w);

	sfd(n);

	int num;

	int** ans = new int*[h];

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

		ans[i] = new int[w];

	}

	bool f = false;

	int l = 0, k = 0;

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

		sfd(num);

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

			ans[l][k] = i;

//			cout << "l = " << l << "    k = " << k << endl;

			if( l%2==0 ) {

				k++;

			}else {

				k--;

			}

			if( k>=w ) {

				k--;

				l++;

			}

			if( k<0 ) {

				k++;

				l++;

			}

			if( l>=h ) {

				f = true;

				break;

			}

		}

		if( f ) {

			break;

		}

	}

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

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

			pfd(ans[i][j]);

			if( j<w-1 ) {

				pfk;

			}

		}

		pfn;

	}



	return 0;

}

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

}

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

using namespace std;



int a[100005];

int rlt[105][105];

int main(){

	int h, w, n;

	cin >> h >> w >> n;

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

	int cur = 0, cnt = 0;

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

		if(i % 2 == 0){

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

				rlt[i][j] = cur;

				a[cur] --;

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

			}

		}

		else {

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

				rlt[i][j] = cur;

				a[cur] --;

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

			}

		}

	}

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

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

			cout << rlt[i][j] + 1 << " \n"[j == w - 1];

		}

	}

}


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

}

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

using namespace std;

int grid[105][105];

int main(){

	int n , m , k;

	cin>>n>>m>> k;

	vector<int>vi;

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

		int x ;cin>>x;

		vi.push_back(x);

	}

	int curr = 0 ,cnt = 0;

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

		if(i%2==0){

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

				grid[j][i] = curr+1;

				cnt++;

				if(cnt == vi[curr]){

					curr++;

					cnt = 0;

				}

			}

		}else{

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

				grid[j][i] = curr+1;

				cnt++;

				if(cnt == vi[curr]){

					curr++;

					cnt = 0;

				}			

			}

		}

	}

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

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

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

		}

		cout<<endl;

	}

	return 0;

}




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

}

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

}


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

}


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

#include<iostream>

#include<stdio.h>

#include<queue>

#include<ctime>

#include<vector>

#include<math.h>

#include<stack>

#include<map>

#include<vector>

#include<set>

#include<algorithm>

using namespace std;

int a[105][105], b[10010];

int main()

{

	int h, w;

	while (cin>>h>>w)

	{

		int i, j, t, m,k = 0;

		cin >> t;

		for (i = 0; i < t; 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++;

				}

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

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

			cout << a[i][w - 1]<<endl;

		}

	}

}

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