#include<stdio.h>intmain(){
int array [1000][1000];int n;int state =1;int count =0;scanf("%d",&n);int i, j;for( i =0; i < n; i++){
for( j =0; j < n; j++){
scanf("%d",&array[i][j]);}}
i =0;
j =0;while(count < n * n){
switch(state){
case1://向右
printf("%d ",array[i][j++]);if( i ==0){
state =3;}elseif( i == n -1){
state =4;}break;case2://向下
printf("%d ",array[i++][j]);if( j ==0){
state =4;}elseif( j == n -1){
state =3;}break;case3://向左下
printf("%d ",array[i++][j--]);if( j ==0){
state =2;}if( i == n -1){
state =1;}break;case4://向右上
printf("%d ",array[i--][j++]);if( i ==0){
state =1;}if( j == n -1){
state =2;}break;}
count++;}return0;}