stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

#include<set>

#include<ctime>

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.144399246331974x):


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

#define rush() int T;scanf("%d",&T);while(T--)  

#define f(i,a,b) for(register int i=a;i<=b;i++)

#include<stdio.h>  

   

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

   

int main ()  

{  

    int h,w;  

    

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

    {  

        int i,j,t,k=0;  

        scanf("%d",&t);  

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

            scanf("%d",&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++)  

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

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

        }  

    }  

}
// Slower C++ solution:
/*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;

}

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

#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

const int MAXN = 1204;

int h,w,n;

int ma[MAXN][MAXN],a[20001];

void solve(){

	cin >> h >> w >> n;

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

		cin >> a[i];

	int tot = n;

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

		if(i % 2){

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

				ma[i][j] = tot,a[tot] --;

				if(a[tot] == 0) tot --;

			}

		}

		else{

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

				ma[i][j] = tot,a[tot] --;

				if(a[tot] == 0) tot --;

			}

		} 

	}

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

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

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

		}

		cout << endl;

	}

	return;

}



int main(){

	solve();

	return 0;

}
// Slower C++ solution:
/*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;

}

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

}
// Slower C++ solution:
/*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;

}

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

using namespace std;

#define all(v) ((v).begin()),((v).end())

#define ll long long

#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

double const EPS = 1e-12, PI = acos(-1);

const int N = 1e6 + 9, M = 1e7 + 9, OO = 1e9 + 7, MOD = 1e9 + 7, MOD2 = 998244353;

const ll inf = 1e18;



int ans[109][109];



int main() {

	fastIO;

#ifdef LOCAL

//	freopen("input.in", "rt", stdin);

#endif

	int n, m, q, a;

	cin >> n >> m >> q;

	bool dir = 1;

	int r = 1, c = 1;

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

		cin >> a;

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

			ans[r][c] = i + 1;

			if(dir) ++c;

			else --c;

			if(c == m + 1) {

				c = m;

				dir = 0;

				++r;

			} else if(c == 0) {

				c = 1;

				dir = 1;

				++r;

			}

		}

	}

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

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

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

		cout << '\n';

	}

	return 0;

}
// Slower C++ solution:
/*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;

}

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

#define ll long long

using namespace std;

const int N = 1e5 + 5;



int ans[105][105];



int main()

{

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

    int r, c, n;

    cin >> r >> c >> n;

    map<int, int> freq;

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

        int x;

        cin >> x;

        freq[i + 1] = x;

    }

    int cnt = 1;

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

        if(i % 2 == 0){

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

                ans[i][j] = cnt;

                freq[cnt]--;

                if(freq[cnt] == 0) cnt++;

            }

        }

        else{

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

                ans[i][j] = cnt;

                freq[cnt]--;

                if(freq[cnt] == 0) cnt++;

            }

       }

    }

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

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

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

        }

        cout << '\n';

    }







    return 0;

}
// Slower C++ solution:
/*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;

}

// Faster C++ solution for the same problem (measured speedup: 1.2584593685090437x):
//#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef pair<ll,ll> pll;

#define mp make_pair

#define f first

#define s second

#define pb push_back



const int N = 1e4 + 5;

const int OO = 2e9;



int h,w,n,a[N],ans[101][101];



void init() {







}



int main() {



    ios_base::sync_with_stdio(false);

    cin.tie(0);



    cin >> h >> w >> n;



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



        cin >> a[i];



    }



    int cur = 0;



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



        if(i&1) {



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



                if (!a[cur]) ++cur;

                ans[i][j] = cur + 1;

                a[cur]--;



            }



        } else {



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



                if (!a[cur]) ++cur;

                ans[i][j] = cur + 1;

                a[cur]--;



            }



        }



    }



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



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



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



        }



        cout << '\n';



    }



    return 0;



}
// Slower C++ solution:
#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;

}






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

   

int a[105][105],b[10000+50];  

   

int main ()  

{  

    int h,w;  

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

    {  

        int i,j,t,k=0;  

        scanf("%d",&t);  

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

            scanf("%d",&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++)  

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

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

        }  

    }  

}
// Slower C++ solution:
#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");

        }

    }

}


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

   

int a[105][105],b[10000+50];  

   

int main ()  

{  

    int h,w;  

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

    {  

        int i,j,t,k=0;  

        scanf("%d",&t);  

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

            scanf("%d",&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++)  

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

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

        }  

    }  

}
// Slower C++ solution:
#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;

 }

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

   

int a[105][105],b[10000+50];  

   

int main ()  

{  

    int h,w;  

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

    {  

        int i,j,t,k=0;  

        scanf("%d",&t);  

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

            scanf("%d",&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++)  

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

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

        }  

    }  

}