stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<cstdio>

#include<iostream>

#include<algorithm>

#include<cstring>

#include<cmath>



using namespace std;



typedef long long ll;

const ll mod=1e9+7;

const ll MAXN=1e5+10;

const ll INF=0x7fffffff;



int a[MAXN],n;



void swp(int x,int y){

	int t=a[x];

	a[x]=a[y];

	a[y]=t;

}

//

//void print(){

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

//		cout<<a[i]<<" ";

//	}

//	cout<<endl;

//} 



int main()//所有的循环已改正 

{

	cin>>n;

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

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

	}

	int ans=0;

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

		if(a[i]==i){

			swp(i,i+1);

			ans++;

//			print();

		}

	}

	cout<<ans<<endl;

	return 0;

}	 


// Optimized solution to the same problem (faster):
#include<cstdio>



int a[100000+5],n;



void swp(int x,int y){

	int t=a[x];

	a[x]=a[y];

	a[y]=t;

}



int main()

{

	scanf("%d",&n);

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

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

	}

	int ans=0;

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

		if(a[i]==i){

			swp(i,i+1);

			ans++;

		}

	}

	printf("%d",ans);

	return 0;

}	 


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

using namespace std;



long long pw[20];



int main() {

	

	ios::sync_with_stdio(0);

	cin.tie(0), cout.tie(0);

	

	pw[0] = 1;

	for (int i = 1; i < 20; i++) pw[i] = pw[i - 1] * 10;

	

	int K; cin >> K;

	long long now = 0;

	while (K--) {

		now++;

		auto nxt = now, nxt_sum = 0LL;

		{

			auto buf = now;

			while (buf) nxt_sum += buf % 10, buf /= 10;

		}

		for (int i = 1; i < 18; i++) if (now >= pw[i]) {

			auto cur = now / pw[i] * pw[i] + pw[i] - 1;

			auto sum = 0LL, buf = cur;

			while (buf) sum += buf % 10, buf /= 10;

			if ((long long)cur * nxt_sum < (long long)nxt * sum) {

				nxt = cur, nxt_sum = sum;

			}

		}

		now = nxt;

		cout << now << "\n";

	}

	

	return 0;

}


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

double cal(long long x)

{

    long long sum=0,temp=x;

    while(x)

	{

        sum+=x%10;

        x/=10;

    }

    return (double)temp/sum;

}

int main()

{

	long long num=0,bot=1,temp1,temp2;

    int k;

    scanf("%d",&k);

    while(1)

	{

        while(1)

		{

			temp1=num+bot;

			temp2=num+bot*10;

			if(cal(temp1)<=cal(temp2))break;

            else bot=temp2-num;

        }

        num+=bot;

        printf("%lld\n",num);

        k--;

        if(!k)break;

    }

}

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

using namespace std;

typedef long long ll;



int main() {

	ios::sync_with_stdio(0); cin.tie(0);

	string s, t; cin >> s >> t;

	s += t[t.size()-1];

	cout << ((s==t)?"Yes":"No") << '\n';

	return 0;

}

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

#include <string.h>

int main(){

	char s[400],t[400];

	scanf("%s",s);

	getchar();

	scanf("%s",t);

	getchar();

	int len = strlen(s);

	t[len] = '\0';

	if (strcmp (s,t) == 0){

		printf("Yes\n");

	}

	else{

		printf("No\n");

	}

	return 0;

}

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

#include <iomanip>

#include <algorithm>

#include <string>

#include <cstring>

#include <cstdio>

#include <cmath>

#include <map>

#include <set>

#include <stack>

#include <queue>

#include <sstream>

#include <vector>

#define INF 0x3f3f3f3f

using namespace std;



typedef long long ll;

const int mod = 1e9 + 7;

const int maxn = 10005;

const double pi = acos(-1.0);



string s,t;



int main()

{

    while(cin >> s)

    {

        cin >> t;

        int len = s.length();

        int flag = 0;

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

        {

            if(s[i] != t[i])

            {

                flag = 1;

                cout << "No" << endl;

                break;

            }

        }

        if(flag == 0)

            cout << "Yes" << endl;

    }

    return 0;

}




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

#include <string.h>

int main(){

	char s[400],t[400];

	scanf("%s",s);

	getchar();

	scanf("%s",t);

	getchar();

	int len = strlen(s);

	t[len] = '\0';

	if (strcmp (s,t) == 0){

		printf("Yes\n");

	}

	else{

		printf("No\n");

	}

	return 0;

}

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

#include <iostream>



using namespace std;



int main()

{

    string a,b;

    cin >> a >> b;

    for (int i=a.size();i>=0;i--)

    {

         if (a[0]==b[0]&&i==0)

        {

            cout << "Yes";

            break;

        }

        else if (a[i]!=b[i] && i!=a.size())

        {

            cout << "No";

            break;

        }

    }



    return 0;

}


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

#include <string.h>

int main(){

	char s[400],t[400];

	scanf("%s",s);

	getchar();

	scanf("%s",t);

	getchar();

	int len = strlen(s);

	t[len] = '\0';

	if (strcmp (s,t) == 0){

		printf("Yes\n");

	}

	else{

		printf("No\n");

	}

	return 0;

}

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

using namespace std;



using ll = long long;

using ull = unsigned long long;

using ld = long double;



#define MOD 1000000007



#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)

#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)

#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)

#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)

#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)

#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)

#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)

#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)

#define iter(i, it) for(auto &(i): (it))



template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {

    cout << "(" << m.first << ", " << m.second << ")";

    return s;

}

template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {

    ll c = 0;

    cout << "{ ";

    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");

    cout << "}";

    return s;

}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {

    cout << "{ ";

    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");

    cout << "}";

    return s;

}

template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {

    ll c = 0;

    cout << "{ ";

    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");

    cout << "}";

    return s;

}



int main(void) {

    string S;

    string T;

    cin >> S >> T;

    if(string(T.begin(), T.begin() + S.size()) == S) cout << "Yes" << endl;

    else cout << "No" << endl;

    return 0;

}


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

#include<string.h>



int main(void){

    char s[11], t[11];

    scanf("%s %s", s, t);

    puts(strncmp(s, t, strlen(s)) == 0 ? "Yes" : "No");

    return 0;

}


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

using namespace std;



using ll = long long;

using ull = unsigned long long;

using ld = long double;



#define MOD 1000000007



#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)

#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)

#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)

#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)

#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)

#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)

#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)

#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)

#define iter(i, it) for(auto &(i): (it))



template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {

    cout << "(" << m.first << ", " << m.second << ")";

    return s;

}

template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {

    ll c = 0;

    cout << "{ ";

    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");

    cout << "}";

    return s;

}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {

    cout << "{ ";

    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");

    cout << "}";

    return s;

}

template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {

    ll c = 0;

    cout << "{ ";

    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");

    cout << "}";

    return s;

}



int main(void) {

    string S;

    string T;

    cin >> S >> T;

    T.pop_back();

    if(T == S) cout << "Yes" << endl;

    else cout << "No" << endl;

    return 0;

}


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

#include<string.h>



int main(void){

    char s[11], t[11];

    scanf("%s %s", s, t);

    puts(strncmp(s, t, strlen(s)) == 0 ? "Yes" : "No");

    return 0;

}


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



using namespace std;

int g[1005][1005];

int main()

{

    int n,m;cin>>n>>m;

    int q;cin>>q;

    int i=0,j=0;

    int dir=0;

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

    {

        int x;

        scanf("%d",&x);

        while(x--)

        {

            g[i][j]=k;

            if(!dir)

            {

                j++;

                if(j>=m)

                {

                    dir=!dir;

                    i++;

                    j=m-1;

                }

            }

            else

            {

                j--;

                if(j<0)

                {

                    dir=!dir;

                    i++;

                    j=0;

                }

            }

        }

    }



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

    {

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

        {

            if(j!=0)printf(" ");

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

        }

        printf("\n");

    }



}


// Optimized solution to the same problem (faster):
#include<cstdio>

int p[100 + 10][100 + 10];

int a[10000 + 10];

int h, w, n;



int main() {

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

	for (int i = 1;i <= n;i++)scanf("%d", &a[i]);

	int i = 1, j = 1, t = h*w, k = 1;

	while (t--) {

		p[i][j] = k;

		a[k]--;

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

		if (j & 1) {

			if (i == h)j++;

			else i++;

		}

		else {

			if (i == 1)j++;

			else i--;

		}

	}

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

		for (int j = 1;j < w;j++)printf("%d ", p[i][j]);

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

	}

	for (int j = 1;j < w;j++)printf("%d ", p[h][j]);

	printf("%d", p[h][w]);

	return 0;

}

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

#include<cstdio>

#include<cstring>

#include<string>

#include<algorithm>

#include<cmath>

using namespace std;



int h,w,n;

int a[10010],mp[110][110];



int main()

{

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

    scanf("%d",&n);

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

    {

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

    }

    int k=1;

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

    {

        int j;

        if(i%2==1) j=1;

        else j=w;

        while(j>=1&&j<=w)

        {

            while(a[k]<=0) k++;

            if(a[k]>0)

            {

                mp[i][j]=k;

                a[k]--;

                if(i%2==1) j++;

                else j--;

            }

        }

    }

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

    {

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

        {

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

        }

        printf("\n");

    }

    return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

int p[100 + 10][100 + 10];

int a[10000 + 10];

int h, w, n;



int main() {

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

	for (int i = 1;i <= n;i++)scanf("%d", &a[i]);

	int i = 1, j = 1, t = h*w, k = 1;

	while (t--) {

		p[i][j] = k;

		a[k]--;

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

		if (j & 1) {

			if (i == h)j++;

			else i++;

		}

		else {

			if (i == 1)j++;

			else i--;

		}

	}

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

		for (int j = 1;j < w;j++)printf("%d ", p[i][j]);

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

	}

	for (int j = 1;j < w;j++)printf("%d ", p[h][j]);

	printf("%d", p[h][w]);

	return 0;

}

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

#include<string> 

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

} 

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

#include<math.h> 

#include<stdlib.h>

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

   

int main ()  

{  

    int h,w;  

    int wanglianhua=100; 

    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]);  

        }  

    }  int wang_lianhua=200; 

}  

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

#include<cstdio>

#include<cmath>

using namespace std;

int main()

{

    int a[10000];

    int G[105][105];

    long i,j,n,h,w;

    cin >> h >> w;

    cin >> n;

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

    cin>>a[i];

    long ans=1;

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

    {

        if(i&1)

        {

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

            {

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

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

            }

        }

        else

        {

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

            {

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

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

            }

        }

    }

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

    {

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

        {

            if(j!=w) cout<<G[i][j]<<" ";

            else cout<<G[i][j]<<endl;

        }

    }

return 0;

}


// Optimized solution to the same problem (faster):


#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]);  

        }  

    }  

}  

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

int a[10000000];

int G[105][105];



int main()

{

    int h,w;

    while(cin>>h>>w)

    {

        int n;

        cin>>n;

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

            cin>>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) cout<<G[i][j]<<" ";

                else cout<<G[i][j]<<endl;

            }

        }

    }

    return 0;

}


// Optimized solution to the same problem (faster):


#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]);  

        }  

    }  

}  

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



const int MAXN=10005;

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;

}

// Optimized solution to the same problem (faster):


#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]);  

        }  

    }  

}  

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):


#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]);  

        }  

    }  

}  

// Fastest known solution for this problem: