stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
/*9:00 UTC+4.5

Contest2 [Cloned]

End: 2019-09-02 13:00 UTC+4.5

04:00:00

Ended

Overview

Problem

Status

Rank (04:00:00)

0 Comments

Previous12345…Next

Username



Amirack

Prob

	Result 

	Time

(ms)	Mem

(MB)	Lang 

	Submit Time

Amirack

E

Wrong Answer

C++

6 days ago

Amirack

E

Language Rejected

C++

6 days ago

Amirack

B

Accepted

6	1.4	

C++

6 days ago

Amirack

B

Wrong Answer

C++

6 days ago

Amirack

A

Accepted

1	0.3	

C++

6 days ago

           

All Copyright Reserved © 2010-2019 Xu Han

Server Time: 2019-09-08 18:16:44 UTC+4.5



#21598412 | Amirack's solution for [AtCoder-2687] [Problem B]

Status

Accepted

Time

6ms

Memory

1408kB

Length

1046

Lang

C++14 (GCC 5.3.0)

Submitted

2019-09-02 10:16:44

Shared



RemoteRunId

7304502

25.0 / 25.0

Select Code

*/

#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 <bits/stdc++.h>

using namespace std;

int a[10005];

int b[105][105];

int main()

{

	int h,w,n;

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

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

	{

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

	}

	int x=1;

	int y=1;

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

	{

		while(a[i])

		{

			a[i]--;

			b[y][x]=i;

			if(y%2==0)

			{

				x--;

			}

			else

			{

				x++;

			}

			if(x>w)

			{

				x--;

				y++;

			}

			if(x<1)

			{

				x++;

				y++;

			}

		}

	}

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

	{

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

		{

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

		}

		printf("%d\n",b[i][w]);

	}

	return 0;

}

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

#include<stdio.h>

#include<cstring>

#include<algorithm>

using namespace std;

int main()

{

    int h,w;

    int n;

    int c[10090];

    cin>>h>>w>>n;

    int last=1;

    int map[103][103];

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

    {

        cin>>c[i];

    }

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

    {

        if(i%2==0)

        {



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

            {

                if(c[last]--){map[i][j]=last;if(c[last]==0)last++;}

            }

            if(c[last]--){map[i][w-1]=last;if(c[last]==0)last++;}

        }

        else

        {

            for(int j=w-1;j>0;j--)if(c[last]--){map[i][j]=last;if(c[last]==0)last++;}

            if(c[last]--){map[i][0]=last;if(c[last]==0)last++;}

        }

    }

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

    {



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

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





    }

    return 0;

}






// Optimized solution to the same problem (faster):
#include<stdio.h>  

int a[105][105];

int b[10050];  

   

int main()  

{  

    int H,W;  

    while(scanf("%d%d",&H,&W)!=EOF)  

    {  

        int t,k=0;  

        scanf("%d",&t);  

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

        {

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

	}

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

        {  

            if(i%2==0)  

            {

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

            	 {  

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

          	      	b[k]--;  

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

            	 }

	     }

            else if(i%2==1)  

            {

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

     	       	 {  

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

            	        b[k]--;  

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

                 }  

            }

        }  

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

        {  

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

            {

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

            }

            printf("%d\n",a[i][W-1]);  

        }  

    }  

}

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

using namespace std;

int main()

{

    int h,w;

    int n;

    int a[10010],b[10010];

    int c[110][110];

    while(scanf("%d%d",&h,&w)!=EOF)

    {

        scanf("%d",&n);

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

        {

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

        }

        int bb=0,bbb=0;

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

        {

            for(int j=0;j<a[bbb];j++)

            {

                b[bb++]=i;

            }

            bbb++;

        }

        int ss=0;

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

        {

            if(i%2==0)

            {

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

                {

                    c[i][j]=b[ss++];

                }

            }

            else

            {

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

                {

                    c[i][j]=b[ss++];

                }

            }

        }

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

        {

            printf("%d",c[i][0]);

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

            {

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

            }

            printf("\n");

        }

    }

}


// Optimized solution to the same problem (faster):
#include<stdio.h>  

int a[105][105];

int b[10050];  

   

int main()  

{  

    int H,W;  

    while(scanf("%d%d",&H,&W)!=EOF)  

    {  

        int t,k=0;  

        scanf("%d",&t);  

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

        {

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

	}

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

        {  

            if(i%2==0)  

            {

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

            	 {  

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

          	      	b[k]--;  

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

            	 }

	     }

            else if(i%2==1)  

            {

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

     	       	 {  

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

            	        b[k]--;  

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

                 }  

            }

        }  

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

        {  

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

            {

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

            }

            printf("%d\n",a[i][W-1]);  

        }  

    }  

}

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

   

 using namespace std;

   

 #define MP make_pair

 #define PB push_back

 typedef long long LL;

 typedef pair<int,int> PII;

 const double eps=1e-8;

 const double pi=acos(-1.0);

 const int K=1e6+7;

 const int mod=1e9+7;

  

 int r,c,n,x,y,ans[200][200];

  

 int main(void)

 {

     scanf("%d%d%d",&r,&c,&n);

     x=1,y=1;

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

     {

         scanf("%d",&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<stdio.h>  

int a[105][105];

int b[10050];  

   

int main()  

{  

    int H,W;  

    while(scanf("%d%d",&H,&W)!=EOF)  

    {  

        int t,k=0;  

        scanf("%d",&t);  

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

        {

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

	}

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

        {  

            if(i%2==0)  

            {

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

            	 {  

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

          	      	b[k]--;  

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

            	 }

	     }

            else if(i%2==1)  

            {

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

     	       	 {  

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

            	        b[k]--;  

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

                 }  

            }

        }  

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

        {  

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

            {

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

            }

            printf("%d\n",a[i][W-1]);  

        }  

    }  

}

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

       cin>>n;

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

             cin>>a[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<stdio.h>  

int a[105][105];

int b[10050];  

   

int main()  

{  

    int H,W;  

    while(scanf("%d%d",&H,&W)!=EOF)  

    {  

        int t,k=0;  

        scanf("%d",&t);  

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

        {

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

	}

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

        {  

            if(i%2==0)  

            {

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

            	 {  

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

          	      	b[k]--;  

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

            	 }

	     }

            else if(i%2==1)  

            {

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

     	       	 {  

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

            	        b[k]--;  

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

                 }  

            }

        }  

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

        {  

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

            {

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

            }

            printf("%d\n",a[i][W-1]);  

        }  

    }  

}

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

        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;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>  

int a[105][105];

int b[10050];  

   

int main()  

{  

    int H,W;  

    while(scanf("%d%d",&H,&W)!=EOF)  

    {  

        int t,k=0;  

        scanf("%d",&t);  

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

        {

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

	}

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

        {  

            if(i%2==0)  

            {

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

            	 {  

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

          	      	b[k]--;  

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

            	 }

	     }

            else if(i%2==1)  

            {

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

     	       	 {  

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

            	        b[k]--;  

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

                 }  

            }

        }  

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

        {  

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

            {

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

            }

            printf("%d\n",a[i][W-1]);  

        }  

    }  

}

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

using namespace std;

int a[10005];

int b[10005];

int main()

{

int h, w;

cin >> h >> w;

int n;

cin >> n;

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

cin >> b[i];

int temp = 1;

int j = 1;

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

{

while (b[i] > 0)

{

a[j] = temp;

j++;

b[i]--;

}

temp++;

}

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

{

if (i % 2 == 1)

{

for (int p = w*(i - 1) + 1; p <= i*w; p++)

{

cout << a[p] << " ";

}

if (i != h)

cout << endl;

}

else if (i % 2 == 0)

{

for (int p = w*i; p >= w*(i - 1) + 1; p--)

{

cout << a[p] << " ";

}

if (i != h)

cout << endl;

}

}

return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>  

int a[105][105];

int b[10050];  

   

int main()  

{  

    int H,W;  

    while(scanf("%d%d",&H,&W)!=EOF)  

    {  

        int t,k=0;  

        scanf("%d",&t);  

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

        {

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

	}

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

        {  

            if(i%2==0)  

            {

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

            	 {  

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

          	      	b[k]--;  

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

            	 }

	     }

            else if(i%2==1)  

            {

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

     	       	 {  

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

            	        b[k]--;  

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

                 }  

            }

        }  

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

        {  

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

            {

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

            }

            printf("%d\n",a[i][W-1]);  

        }  

    }  

}

// 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 b,w;

    while(scanf("%d%d",&b,&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<=b;++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<=b;++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<stdio.h>  

int a[105][105];

int b[10050];  

   

int main()  

{  

    int H,W;  

    while(scanf("%d%d",&H,&W)!=EOF)  

    {  

        int t,k=0;  

        scanf("%d",&t);  

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

        {

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

	}

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

        {  

            if(i%2==0)  

            {

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

            	 {  

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

          	      	b[k]--;  

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

            	 }

	     }

            else if(i%2==1)  

            {

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

     	       	 {  

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

            	        b[k]--;  

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

                 }  

            }

        }  

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

        {  

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

            {

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

            }

            printf("%d\n",a[i][W-1]);  

        }  

    }  

}

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

#include <string>

#include <ctime>

#include <cstring>

#include <cstdlib>

#include <cmath>

#include<cstdio>

#define PI 3.1415927

#include <vector>

using namespace std;



int main()

{

    int r,c,n;

    int a[200][200];

    cin>>r>>c>>n;

    int x=1,y=1;

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

    {

        int m;

        cin>>m;

        while(m--)

        {

            a[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+1; i++)

    {

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

        {

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

        }

    }

    return 0;

}




// Optimized solution to the same problem (faster):
#include<stdio.h>  

int a[105][105];

int b[10050];  

   

int main()  

{  

    int H,W;  

    while(scanf("%d%d",&H,&W)!=EOF)  

    {  

        int t,k=0;  

        scanf("%d",&t);  

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

        {

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

	}

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

        {  

            if(i%2==0)  

            {

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

            	 {  

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

          	      	b[k]--;  

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

            	 }

	     }

            else if(i%2==1)  

            {

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

     	       	 {  

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

            	        b[k]--;  

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

                 }  

            }

        }  

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

        {  

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

            {

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

            }

            printf("%d\n",a[i][W-1]);  

        }  

    }  

}

// 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 IN=0x3f3f3f3f;

const int MAX=1e5+5;

int a[MAX];

int G[110][110];



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 cn=1;

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

        {

            if(i&1)

            {

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

                {

                   if(a[cn]>0) {G[i][j]=cn;--a[cn];}

                   else if(a[cn]==0) {++cn;G[i][j]=cn;--a[cn];}

                }

            }else

            {

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

                {

                    if(a[cn]>0) {G[i][j]=cn;--a[cn];}

                    else if(a[cn]==0) {++cn;G[i][j]=cn;--a[cn];}

                }

            }

        }

        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<stdio.h>  

int a[105][105];

int b[10050];  

   

int main()  

{  

    int H,W;  

    while(scanf("%d%d",&H,&W)!=EOF)  

    {  

        int t,k=0;  

        scanf("%d",&t);  

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

        {

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

	}

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

        {  

            if(i%2==0)  

            {

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

            	 {  

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

          	      	b[k]--;  

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

            	 }

	     }

            else if(i%2==1)  

            {

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

     	       	 {  

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

            	        b[k]--;  

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

                 }  

            }

        }  

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

        {  

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

            {

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

            }

            printf("%d\n",a[i][W-1]);  

        }  

    }  

}

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



using namespace std;



int main()

{

    int h,w,n;

    int i;

    cin>>h;

    cin>>w;

    int b[h][w];

    cin>>n;

    int a[n];

    int c[h*w];

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

    {

        cin>>a[i];

    }

    int j=0;

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

    {

        while(a[i]!=0)

        {

            c[j]=i+1;

            ++j;

            --a[i];

        }

    }

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

    {

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

        {

            b[i][j]=c[i*w+j];

        }

    }

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

    {

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

        {

            b[i][w-1-j]=c[i*w+j];

        }

    }

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

    {

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

        {

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

        }

        cout<<endl;

    }

    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>  

int a[105][105];

int b[10050];  

   

int main()  

{  

    int H,W;  

    while(scanf("%d%d",&H,&W)!=EOF)  

    {  

        int t,k=0;  

        scanf("%d",&t);  

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

        {

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

	}

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

        {  

            if(i%2==0)  

            {

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

            	 {  

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

          	      	b[k]--;  

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

            	 }

	     }

            else if(i%2==1)  

            {

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

     	       	 {  

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

            	        b[k]--;  

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

                 }  

            }

        }  

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

        {  

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

            {

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

            }

            printf("%d\n",a[i][W-1]);  

        }  

    }  

}

// Fastest known solution for this problem: