stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:


// in the name of Allah ;

#include<bits/stdc++.h>

using namespace std;

const int maxn = 1e2 + 10 ;

int n , m , q ;

int arr[maxn*maxn] , mat[maxn][maxn] ;

void input() 

{

	cin >> n >> m >> q ;

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

		cin >> arr[i] ;

}

int main()

{

	input() ;

	int p = 0 ;

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

	{

		if ( i % 2 ) 

		{

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

				if ( arr[p] ) 

					mat[i][j] = p , arr[p]-- ;

				else

					p++ , j-- ;

				

		}

		else

		{

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

				if ( arr[p] ) 

					mat[i][j] = p , arr[p]-- ;

				else

					p++ , j++ ; 

		}

	}

	for ( int i = 0 ; i < n ; cout << endl , i++ ) 

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

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

}


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



using namespace std;



#define pb push_back

#define ff first

#define ss second



typedef long long ll;

const ll MAXN = 2e6 + 10, inf = 1e18, mod = 1e9 + 7;



struct pair_hash {

	template <class T1, class T2>

	std::size_t operator () (const std::pair<T1,T2> &p) const {

		auto h1 = std::hash<T1>{}(p.first);

		auto h2 = std::hash<T2>{}(p.second);



		return h1 ^ h2;  

	}

};



ll pw(ll te, ll tee) {

	if (tee == 0)	return 1;

	ll res = pw(te, tee / 2);

	return (tee % 2 ? te * res * res : res * res);

}



ll a[MAXN], n, h, w, ans[105][105];



void Read_input() {

	cin >> h >> w >> n;

	for (ll i = 1; i <= n; i++)	cin >> a[i];

}



void Solve() {

	ll cnt = 0, k = 1;

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

		if (i % 2) {

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

				ans[i][j] = k;

				cnt++;

				if (cnt >= a[k]) {

					cnt = 0;

					k++;

				}

			}

		}

		else {

			for (ll j = w; j > 0; j--) {

				ans[i][j] = k;

				cnt++;

				if (cnt >= a[k]) {

					cnt = 0;

					k++;

				}

			}

		}

	}

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

		cout << ans[i][1];

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

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

		cout << endl;

	}

}





int main() {



	ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0);

	//freopen("input.txt", "r", stdin),	freopen("output.txt", "w", stdout);



	Read_input(),	Solve();

	return 0;

}

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



using namespace std;



int R, C, x[10005], n, a = 1, banyak, y[105][105];

int main(){

    cin >> R >> C;

    cin >> n;

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

        cin >> x[i];

    }

    for(int r=1; r<=R; r++){

        if(r%2 == 1){

            for(int c=1; c<=C; c++){

                if(banyak == x[a]){

                    a++;

                    y[r][c] = a;

                    banyak = 1;

                }

                else{

                    y[r][c] = a;

                    banyak++;

                }

            }

        }

        else{

            for(int c=C; c>=1; c--){

                if(banyak == x[a]){

                    a++;

                    y[r][c] = a;

                    banyak = 1;

                }

                else{

                    y[r][c] = a;

                    banyak++;

                }

            }

        }

    }

    for(int r=1; r<=R; r++){

        for(int c=1; c<=C; c++){

            if(banyak == x[a]){

                a++;

                cout << y[r][c];

                banyak = 1;

            }

            else{

                cout << y[r][c];

                banyak++;

            }

            cout << " ";

        }

        cout << endl;

    }

}

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

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.213390175257747x):
#include<stdio.h>

#include<stdlib.h>

#define SWAP(a,b) ((a)^=(b)^=(a)^=(b))

typedef long long ll;

int map[105][105];

int col[10005];

int main(void)

{

	int H, W, N;

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

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

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

	int i, j, m, s = 1, a = 0, b = W - 1;

	i = j = m = 0;

	while (m < N)

	{

		for (int k = 0; k < col[m]; k++) {

			map[i][j] = m + 1;

			if (j == b)

				SWAP(a, b), s = -s, i++;

			else

				j += s;

		}

		m++;

	}

	for (int i = 0; i < H; putchar('\n'),i++)

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

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

	return 0;

}
// 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.675101227837983x):
#include<stdio.h>

#include<stdlib.h>

#define SWAP(a,b) ((a)^=(b)^=(a)^=(b))

typedef long long ll;

int map[105][105];

int col[10005];

int main(void)

{

	int H, W, N;

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

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

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

	int i, j, m, s = 1, a = 0, b = W - 1;

	i = j = m = 0;

	while (m < N)

	{

		for (int k = 0; k < col[m]; k++) {

			map[i][j] = m + 1;

			if (j == b)

				SWAP(a, b), s = -s, i++;

			else

				j += s;

		}

		m++;

	}

	for (int i = 0; i < H; putchar('\n'),i++)

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

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

	return 0;

}
// 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.150772330912019x):
#include<stdio.h>

#include<stdlib.h>

#define SWAP(a,b) ((a)^=(b)^=(a)^=(b))

typedef long long ll;

int map[105][105];

int col[10005];

int main(void)

{

	int H, W, N;

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

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

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

	int i, j, m, s = 1, a = 0, b = W - 1;

	i = j = m = 0;

	while (m < N)

	{

		for (int k = 0; k < col[m]; k++) {

			map[i][j] = m + 1;

			if (j == b)

				SWAP(a, b), s = -s, i++;

			else

				j += s;

		}

		m++;

	}

	for (int i = 0; i < H; putchar('\n'),i++)

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

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

	return 0;

}
// 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.19459331961789x):
#include<stdio.h>

#include<stdlib.h>

#define SWAP(a,b) ((a)^=(b)^=(a)^=(b))

typedef long long ll;

int map[105][105];

int col[10005];

int main(void)

{

	int H, W, N;

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

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

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

	int i, j, m, s = 1, a = 0, b = W - 1;

	i = j = m = 0;

	while (m < N)

	{

		for (int k = 0; k < col[m]; k++) {

			map[i][j] = m + 1;

			if (j == b)

				SWAP(a, b), s = -s, i++;

			else

				j += s;

		}

		m++;

	}

	for (int i = 0; i < H; putchar('\n'),i++)

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

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

	return 0;

}
// 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.19459331961789x):
#include<stdio.h>

#include<stdlib.h>

#define SWAP(a,b) ((a)^=(b)^=(a)^=(b))

typedef long long ll;

int map[105][105];

int col[10005];

int main(void)

{

	int H, W, N;

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

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

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

	int i, j, m, s = 1, a = 0, b = W - 1;

	i = j = m = 0;

	while (m < N)

	{

		for (int k = 0; k < col[m]; k++) {

			map[i][j] = m + 1;

			if (j == b)

				SWAP(a, b), s = -s, i++;

			else

				j += s;

		}

		m++;

	}

	for (int i = 0; i < H; putchar('\n'),i++)

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

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

	return 0;

}
// 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.260169739537606x):
#include<stdio.h>

#include<stdlib.h>

#define SWAP(a,b) ((a)^=(b)^=(a)^=(b))

typedef long long ll;

int map[105][105];

int col[10005];

int main(void)

{

	int H, W, N;

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

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

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

	int i, j, m, s = 1, a = 0, b = W - 1;

	i = j = m = 0;

	while (m < N)

	{

		for (int k = 0; k < col[m]; k++) {

			map[i][j] = m + 1;

			if (j == b)

				SWAP(a, b), s = -s, i++;

			else

				j += s;

		}

		m++;

	}

	for (int i = 0; i < H; putchar('\n'),i++)

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

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

	return 0;

}
// 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.180563381512106x):
#include<stdio.h>

#include<stdlib.h>

#define SWAP(a,b) ((a)^=(b)^=(a)^=(b))

typedef long long ll;

int map[105][105];

int col[10005];

int main(void)

{

	int H, W, N;

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

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

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

	int i, j, m, s = 1, a = 0, b = W - 1;

	i = j = m = 0;

	while (m < N)

	{

		for (int k = 0; k < col[m]; k++) {

			map[i][j] = m + 1;

			if (j == b)

				SWAP(a, b), s = -s, i++;

			else

				j += s;

		}

		m++;

	}

	for (int i = 0; i < H; putchar('\n'),i++)

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

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

	return 0;

}
// 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.286894471161896x):
#include<stdio.h>

#include<stdlib.h>

#define SWAP(a,b) ((a)^=(b)^=(a)^=(b))

typedef long long ll;

int map[105][105];

int col[10005];

int main(void)

{

	int H, W, N;

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

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

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

	int i, j, m, s = 1, a = 0, b = W - 1;

	i = j = m = 0;

	while (m < N)

	{

		for (int k = 0; k < col[m]; k++) {

			map[i][j] = m + 1;

			if (j == b)

				SWAP(a, b), s = -s, i++;

			else

				j += s;

		}

		m++;

	}

	for (int i = 0; i < H; putchar('\n'),i++)

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

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

	return 0;

}
// 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.152031763919647x):
#include<stdio.h>

#include<stdlib.h>

#define SWAP(a,b) ((a)^=(b)^=(a)^=(b))

typedef long long ll;

int map[105][105];

int col[10005];

int main(void)

{

	int H, W, N;

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

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

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

	int i, j, m, s = 1, a = 0, b = W - 1;

	i = j = m = 0;

	while (m < N)

	{

		for (int k = 0; k < col[m]; k++) {

			map[i][j] = m + 1;

			if (j == b)

				SWAP(a, b), s = -s, i++;

			else

				j += s;

		}

		m++;

	}

	for (int i = 0; i < H; putchar('\n'),i++)

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

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

	return 0;

}
// 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.152031763919647x):
#include<stdio.h>

#include<stdlib.h>

#define SWAP(a,b) ((a)^=(b)^=(a)^=(b))

typedef long long ll;

int map[105][105];

int col[10005];

int main(void)

{

	int H, W, N;

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

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

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

	int i, j, m, s = 1, a = 0, b = W - 1;

	i = j = m = 0;

	while (m < N)

	{

		for (int k = 0; k < col[m]; k++) {

			map[i][j] = m + 1;

			if (j == b)

				SWAP(a, b), s = -s, i++;

			else

				j += s;

		}

		m++;

	}

	for (int i = 0; i < H; putchar('\n'),i++)

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

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

	return 0;

}
// Slower C++ solution:


// in the name of Allah ;

#include<bits/stdc++.h>

using namespace std;

const int maxn = 1e2 + 10 ;

int n , m , q ;

int arr[maxn*maxn] , mat[maxn][maxn] ;

void input() 

{

	cin >> n >> m >> q ;

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

		cin >> arr[i] ;

}

int main()

{

	input() ;

	int p = 0 ;

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

	{

		if ( i % 2 ) 

		{

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

				if ( arr[p] ) 

					mat[i][j] = p , arr[p]-- ;

				else

					p++ , j-- ;

				

		}

		else

		{

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

				if ( arr[p] ) 

					mat[i][j] = p , arr[p]-- ;

				else

					p++ , j++ ; 

		}

	}

	for ( int i = 0 ; i < n ; cout << endl , i++ ) 

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

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

}


// Faster C++ solution for the same problem (measured speedup: 5.216104144189791x):
#include<stdio.h>

#include<stdlib.h>

#define SWAP(a,b) ((a)^=(b)^=(a)^=(b))

typedef long long ll;

int map[105][105];

int col[10005];

int main(void)

{

	int H, W, N;

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

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

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

	int i, j, m, s = 1, a = 0, b = W - 1;

	i = j = m = 0;

	while (m < N)

	{

		for (int k = 0; k < col[m]; k++) {

			map[i][j] = m + 1;

			if (j == b)

				SWAP(a, b), s = -s, i++;

			else

				j += s;

		}

		m++;

	}

	for (int i = 0; i < H; putchar('\n'),i++)

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

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

	return 0;

}