#include using namespace std; int index(int i, int j, int n) { return i*n+j; } void readinput(int mx[], int n ) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { int ind = index(i,j,n); cin>>mx[ind]; } } } string dummy(int p, int d, int n) { string so=""; int x =n*n/d;//count of elements in a region int r1=1; int r=0; for (int i = 0; i < n; i++) { string s=""; for (int j = 0; j < n; j++) { r++; if(r>x) { r=1;r1++; } if ((i%2)==0) { s+=to_string(r1)+" "; } else { s=to_string(r1)+" "+s; } } so+=s+"\n"; } string rez = ""; for (int i = 0; i < p; i++) { rez+=so; } return rez; } int main() { int n,d,p; string rez=""; freopen("gerrymandering.in","r",stdin); freopen("gerrymandering.out","w",stdout); cin>>n>>d>>p; //cout << "0%2 " << 0%2 << "\n1%2 "<< 1%2 << "\n2%2 " << 2%2; int country[n*n]; readinput(country,n); rez = dummy(p, d, n); cout << rez; }