stablegradients/pie-gem5-pairs huggingface dataset:
// 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: 1.1701283464227223x):
#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;

}
// 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: 1.2758553111807107x):
#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];

		}

	}

}
// 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: 1.1677026916334006x):
#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];

		}

	}

}
// 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: 1.261015266914023x):
#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;

}
// 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: 1.1541206188996724x):
#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;

}
// Slower C++ solution:
/*===============================================================

*  Filename: B.cpp

*  Author: zhuyutian

*  Date: 2018.04.16

================================================================*/

#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef unsigned long long ull;

const int maxn = 100005;



int H,W;

int N;

int c[maxn];

int res[105][105];



int main()

{

    //freopen("B.in","r",stdin);

    //freopen("B.out","w",stdout);

    cin>>H>>W>>N;

	for(int i = 1; i <= N; i++) cin>>c[i];

	int x = 1,y = 1,dy = 1;

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

		while(c[i]--){

			res[x][y] = i;

			y += dy;

			if(y > W || y < 1){

				x++;

				dy = -dy;

				if(dy > 0) y = 1;

				else y = W;

			}

		}

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

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

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

		cout<<endl;

	}

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.19825917358634x):
#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>

#define LL long long

using namespace std;



#define maxn 10007

const int INF=0x3f3f3f3f;





vector <int> v;

int a[107][107];

int main()

{

    int h,w,n,i,j,k,x,y;

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

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

    {

        scanf("%d",&x);

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

        {

            v.push_back(i);

        }

    }

    int cnt=0;

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

    {

        if(i%2==1)

        {

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

                a[i][j]=v[cnt++];

        }

        else

        {

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

                a[i][j]=v[cnt++];

        }

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

        for(j=2;j<=w;j++)

        {

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

        }

        printf("\n");

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.147845444334478x):
#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 <map>

#include <set>

#include <stack>

#include <queue>

#include <vector>

#include <cmath>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <iostream>

#include <algorithm>

#define ll long long

#define ms(a,b) memset(a,b,sizeof(a))

using namespace std;



const int MAXN = 1e2 + 100;

const int INF = 0x3FFFFFFF;

const ll MOD = 1e9+7;



int color[MAXN][MAXN];

int a[MAXN * MAXN];



int main()

{

    int r, c;

    cin >> r >> c;

    //int pro = r * c;

    int n;

    cin >> n;

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

        cin >> a[i];

    int index = 1;

    int cnt = a[1];

    int num = 1;

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

    {

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

        {

            if(!cnt)

            {

//                if(index + 1 > n)

//                {

//                    for(int q = 1; q <= r; q++)

//                    {

//                        for(int k = 1; k <= c - 1; k++)

//                        {

//                            cout << color[q][k] << " ";

//                        }

//                        cout << color[q][c] << endl;

//                    }

//                    return 0;

//                }

//                else

//                {

                    cnt = a[++index];

                    num++;

//                    color[i][j] = num;

//                    cnt--;

//                }

            }

//            else

//            {

                color[i][j] = num;

                cnt--;

//            }

//            cout << index << endl;

        }

    }

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

    {

        if(q % 2)

        {

            //cout << "--" << endl;

            for(int k = 1; k <= c - 1; k++)

            {

                cout << color[q][k] << " ";

            }

            cout << color[q][c] << endl;

        }

        else

        {

            //cout << n << endl;

            for(int k = c; k >= 2; k--)

            {

                cout << color[q][k] << " ";

            }

            cout << color[q][1] << endl;

        }

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.195652867952019x):
#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 h,w,n;

int num[100010];

int MAP[110][110];

int x,y,d;



int dir[][2] = { 1 , 0 , 

			0 , 1,

			-1 , 0,

			0 , -1};



int main(){

	memset(MAP,0,sizeof(MAP));

	d = 0;

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

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

		scanf("%d",num+i);

	x = y = 1;

	int cnt = 0;

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

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

			MAP[x][y] = i;

			if(++cnt == w*h)

				break;

			while(x+dir[d][0] > h 

				|| y+dir[d][1] > w 

				|| y+dir[d][1] <= 0 

				|| x+dir[d][0] <= 0

				|| MAP[x+dir[d][0]][y+dir[d][1]])

				d++,

				d%=4;

			x += dir[d][0];

			y += dir[d][1];

		}

	}

	for(int i=1;i<=h;i++,printf("\n")){

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

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

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

	}

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.40954261948228x):
#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<algorithm>

using namespace std;

struct ss

{

    int num;

    int gs;

}a[10001];

bool cmp(ss c,ss b)

{

    return c.gs>b.gs;

}

int main()

{

    int maze[100][100];

    int h,w,n,i,j;

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

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

    {

        cin>>a[i].gs;

        a[i].num=i+1;

    }

    sort(a,a+n,cmp);

    int t=0,y=0;

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

    {

        if(i%2==0){

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

        {

            y++;

            if(y>a[t].gs)t=t+1,y=1;

            maze[i][j]=a[t].num;

        }}

        else

        {

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

           {

            y++;

            if(y>a[t].gs)t=t+1,y=1;

            maze[i][j]=a[t].num;

           }

        }

    }

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

    {

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

        {

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

        }

        cout<<endl;

    }

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.247597584088185x):
#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> //Ithea Myse Valgulious

namespace chtholly{

typedef long long ll;

#define re0 register int

#define rec register char

#define rel register ll

#define gc getchar

#define pc putchar

#define p32 pc(' ')

#define pl puts("")

/*By Citrus*/

inline int read(){

  int x=0,f=1;char c=gc();

  for (;!isdigit(c);c=gc()) f^=c=='-';

  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');

  return f?x:-x;

  }

template <typename mitsuha>

inline bool read(mitsuha &x){

  x=0;int f=1;char c=gc();

  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';

  if (!~c) return 0;

  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');

  return x=f?x:-x,1;

  }

template <typename mitsuha>

inline int write(mitsuha x){

  if (!x) return pc(48);

  if (x<0) x=-x,pc('-');

  int bit[20],i,p=0;

  for (;x;x/=10) bit[++p]=x%10;

  for (i=p;i;--i) pc(bit[i]+48);

  return 0;

  }

inline char fuhao(){

  char c=gc();

  for (;isspace(c);c=gc());

  return c;

  }

}using namespace chtholly;

using namespace std;

int h=read(),w=read(),n=read(),ans[150][150],nx=1,ny=1;



int main(){

int i;

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

  int x=read();

  for (;nx<=h&&x>0;){

    if (nx&1){

      for (int &k=ny;k<=w&&x-->0;++k) ans[nx][k]=i;

	  }

	else{

	  for (int &k=ny;k&&x-->0;--k) ans[nx][k]=i;

	  }

	if (!ny||ny>w){

	  ++nx;

	  if (!ny) ++ny;

	  if (ny>w) --ny;

	  } 

    }

  }

for (i=1;i<=h;++i,pl){

  for (int j=1;j<=w;++j,p32) write(ans[i][j]);

  }

}

// Faster C++ solution for the same problem (measured speedup: 5.142589297893768x):
#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;

}