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

#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.157290400618752x):
#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 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.419467721956978x):
#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<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.257225559581063x):
#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> //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.152024610517623x):
#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<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.252377020103629x):
#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<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;

}

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

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



int integer_a[105][105],integer_b[10000+50];



int main ()

{

    int h,m;

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

    {

        int i,j,t,k=0;

        scanf("%d",&t);

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

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

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

        {

            if(i%2==0)

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

                {

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

                    integer_b[k]--;

                    if(integer_b[k]==0)

                        k++;

                }

            if(i%2==1)

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

                {

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

                    integer_b[k]--;

                    if(integer_b[k]==0)

                        k++;

                }

        }

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

        {

            for(j=0;j<m-1;j++)

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

            printf("%d\n",integer_a[i][m-1]);

        }

    }

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



int integer_a[105][105],integer_b[10000+50];



int main ()

{

    int h,m;

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

    {

        int i,j,t,k=0;

        scanf("%d",&t);

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

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

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

        {

            if(i%2==0)

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

                {

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

                    integer_b[k]--;

                    if(integer_b[k]==0)

                        k++;

                }

            if(i%2==1)

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

                {

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

                    integer_b[k]--;

                    if(integer_b[k]==0)

                        k++;

                }

        }

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

        {

            for(j=0;j<m-1;j++)

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

            printf("%d\n",integer_a[i][m-1]);

        }

    }

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



int integer_a[105][105],integer_b[10000+50];



int main ()

{

    int h,m;

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

    {

        int i,j,t,k=0;

        scanf("%d",&t);

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

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

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

        {

            if(i%2==0)

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

                {

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

                    integer_b[k]--;

                    if(integer_b[k]==0)

                        k++;

                }

            if(i%2==1)

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

                {

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

                    integer_b[k]--;

                    if(integer_b[k]==0)

                        k++;

                }

        }

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

        {

            for(j=0;j<m-1;j++)

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

            printf("%d\n",integer_a[i][m-1]);

        }

    }

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



int integer_a[105][105],integer_b[10000+50];



int main ()

{

    int h,m;

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

    {

        int i,j,t,k=0;

        scanf("%d",&t);

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

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

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

        {

            if(i%2==0)

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

                {

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

                    integer_b[k]--;

                    if(integer_b[k]==0)

                        k++;

                }

            if(i%2==1)

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

                {

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

                    integer_b[k]--;

                    if(integer_b[k]==0)

                        k++;

                }

        }

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

        {

            for(j=0;j<m-1;j++)

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

            printf("%d\n",integer_a[i][m-1]);

        }

    }

}