document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <cstdio>
  2. const int SIZE = 1e3;
  3. int row_st[SIZE],N;
  4. int main(){
  5.     scanf("%d",&N);
  6.     printf("%d\\n",N);
  7.     int now=0;
  8.     for(int i=0;i<N;i+=2){
  9.         row_st[i]=now;
  10.         now+=N;
  11.     }
  12.     for(int i=1;i<N;i+=2){
  13.         row_st[i]=now;
  14.         now+=N;
  15.     }
  16.     int ll=row_st[0],rr=row_st[0]+N-1;
  17.     for(int j=0;j<N;j++){
  18.         int v;
  19.         if(j<3)v=ll++;
  20.         else if(j%4!=2)v=rr--;
  21.         else v=ll++;
  22.         printf("%d%c",v," \\n"[j==N-1]);
  23.     }
  24.     for(int i=1;i<N-1;i++){
  25.         if(i%2==1){
  26.             for(int j=0;j<N;j++)printf("%d%c",row_st[i]+j," \\n"[j==N-1]);
  27.         }
  28.         else{
  29.             for(int j=0;j<N;j++)printf("%d%c",row_st[i]+N-1-j," \\n"[j==N-1]);
  30.         }
  31.     }
  32.     ll=row_st[N-1],rr=row_st[N-1]+N-1;
  33.     for(int j=0;j<N;j++){
  34.         int v;
  35.         if(j%4==1||j%4==2)v=rr--;
  36.         else v=ll++;
  37.         printf("%d%c",v," \\n"[j==N-1]);
  38.     }
  39.     return 0;
  40. }
');