int main()
{
    int row, col, i, j, k, l, circle = 0, num = 0;
    cin >> row >> col;
    int a[100][100];
    for (i = 0; i < row; i++)
        for (j = 0; j < col; j++)
            cin >> a[i][j];
    while (true)
    {
        for (i = circle; i < col - circle; i++)
        {
            cout << a[circle][i] << endl;
            num++;
        }
        if (num == row * col) break;

        for (i--, j = circle + 1; j < row - circle; j++)
        {
            cout << a[j][i] << endl;
            num++;
        }
        if (num == row * col) break;

        for (j--, k = i - 1; k >= circle; k--)
        {
            cout << a[j][k] << endl;
            num++;
        }
        if (num == row * col) break;

        for (k++, l = j - 1; l > circle; l--)
        {
            cout << a[l][k] << endl;
            num++;
        }
        if (num == row * col) break;

        circle++;
    }
    return 0;
}


int main()
{
int m,n,sxrow,xxrow,sxcol,xxcol,i,j,a[M][N],num,s=0;
	scanf("%d%d",&m,&n);
	for(i=0;i<m;i++){
		for(j=0;j<n;j++){
		scanf("%d",&a[i][j]);
		}
	}
	num=m*n;
	sxrow=m-1;xxrow=0;
	sxcol=n-1;xxcol=0;
	while(s!=num){
	for(i=xxcol;i<=sxcol;i++){
		printf("%d\n",a[xxrow][i]);
		s++;
	}
	if(s==num){break;}
	for(i=xxrow+1;i<=sxrow;i++){
		printf("%d\n",a[i][sxcol]);
		s++;
	}

	if(s==num){break;}
	for(i=sxcol-1;i>=xxcol;i--){
		printf("%d\n",a[sxrow][i]);
		s++;
	}

	if(s==num){break;}
	xxrow++;xxcol++;

	for(i=sxrow-1;i>=xxrow;i--){
		printf("%d\n",a[i][xxcol-1]);
		s++;
	}

	if(s==num){break;}
	sxrow--;sxcol--;

}
	return 0;
}


int main()
{
	int col,row,ROW,COL,n[100][100],i,b=0,N;
	scanf("%d %d",&ROW,&COL);
	N=ROW*COL;
	for(row=0;row<ROW;row++){
		for(col=0;col<COL;col++){
			scanf("%d",&n[row][col]);
		}
	}
	for(i=0;;i++){
		if(b<N){
		for(col=i,row=i;col<(COL-i);col++){
			if(b<N){
				printf("%d\n",n[row][col]);
				b+=1;
			}else break;
		}
		for(col=COL-1-i,row=i+1;row<ROW-i;row++){
			if(b<N){
				printf("%d\n",n[row][col]);
				b+=1;
			}else break;
		}
		for(row=ROW-1-i,col=COL-2-i;col>=i;col--){
			if(b<N){
				printf("%d\n",n[row][col]);
				b+=1;
			}else break;
		}
		for(col=i,row=ROW-2-i;row>=i+1;row--){
			if(b<N){
				printf("%d\n",n[row][col]);
				b+=1;
			}else break;
		}
		}else break;
	}
	return 0;
}


int main(int argc, char* argv[])
{
	int row,col,i=0,j=0,array[100][100],n=0,t=0;
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
		{
			scanf("%d",&array[i][j]);
		}
	}
	i=0;
	j=0;
	while(1)
	{
		for(j=n;j<=col-1-n;j++)
		{
			printf("%d\n",array[i][j]);
			t++;
		}
		j=j-1;
		if(t==row*col)
		{
			break;
		}
		for(i=1+n;i<=row-1-n;i++)
		{
			printf("%d\n",array[i][j]);
			t++;
		}
		i=i-1;
		if(t==row*col)
		{
			break;
		}
		for(j=col-2-n;j>=n;j--)
		{
			printf("%d\n",array[i][j]);
			t++;
		}
		j=j+1;
		if(t==row*col)
		{
			break;
		}
		for(i=row-2-n;i>=1+n;i--)
		{
			printf("%d\n",array[i][j]);
			t++;
		}
		i=i+1;
		if(t==row*col)
		{
			break;
		}
		n++;

	}

	return 0;
}


void main()
{
	int row,col,a[100][100],i,k;
	void shun(int a[][100],int x,int y);
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++)
	{
		for(k=0;k<col;k++)
		{
			scanf("%d",&a[i][k]);
		}
	}
	shun(a,row,col);
}
void shun(int a[][100],int x,int y)
{
	int b=0,c,d=0,e=0,sum,n=0;
	sum=x*y;
	while(n<=sum)
	{
		for(c=b;c<y;c++)
		{
			printf("%d\n",a[b][c]);
			n=n+1;
			if(n==sum)
				break;
		}
		b=b+1;
		if(n==sum)
			break;

		for(c=b;c<x;c++)
		{
			printf("%d\n",a[c][y-1]);
			n=n+1;
			if(n==sum)
				break;
		}
		y=y-1;
		if(n==sum)
			break;
		for(c=y-1;c>=d;c--)
		{
			printf("%d\n",a[x-1][c]);
			n=n+1;
			if(n==sum)
				break;
		}
		x=x-1;
		d=d+1;
		if(n==sum)
			break;
		for(c=x-1;c>=b;c--)
		{
			printf("%d\n",a[c][e]);
			n=n+1;
			if(n==sum)
				break;
		}
		e=e+1;
		if(n==sum)
			break;
	}
}


//#include<stdlib.h>
//#include<math.h>
int main()
{
	int n,i,j;
	char c;
	int row1,row2,col1,col2;
	int a[101][101];
	scanf("%d %d",&row2,&col2);
	for(i=0;i<row2;i++){
		for(j=0;j<col2;j++){
			scanf("%d",&(a[i][j]));
		}
	}

	i=0;j=-1;
	c='r';
	n=row2*col2;
	row1=0;
	col1=0;
	row2=row2-1;
	col2=col2-1;
	while(n)
	{

		switch(c) {
		case 'l':
			j--;
			if(j==col1) {
				c='u';
				row2--;
			}
			break;
		case 'r':
			j++;
			if(j==col2) {
				c='d';
				row1++;
			}
			break;
		case 'u':
			i--;
			if(i==row1) {
				c='r';
				col1++;
			}
			break;
		case 'd':
			i++;
			if(i==row2) {
				c='l';
				col2--;
			}
		}
		printf("%d\n",a[i][j]);
		n--;
	}

	return 0;
}


int main ()
{
	int mat[100][100];
	int i,j,row,col;
	int m=0,n=0;
	int count=0;

	scanf("%d%d",&row,&col);

	for(i=0;i<100;i++)
		for(j=0;j<100;j++)
			mat[i][j]=-1;
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			scanf("%d",&mat[i][j]);
	for(;;)
	{
		for(;;)
		{
			printf("%d\n",mat[m][n]);
			count++;
			mat[m][n]=-1;
			n++;
			if(mat[m][n]==-1)
			{
				n--;
				m++;
				break;
			}
		}
		if(count>=row*col)break;
		for(;;)
		{
			printf("%d\n",mat[m][n]);
			count++;
			mat[m][n]=-1;
			m++;
			if(mat[m][n]==-1)
			{
				m--;
				n--;
				break;
			}
		}
		if(count>=row*col)break;
		for(;;)
		{
			printf("%d\n",mat[m][n]);
			count++;
			mat[m][n]=-1;
			n--;
			if(mat[m][n]==-1)
			{
				n++;
				m--;
				break;
			}
		}
		if(count>=row*col)break;
		for(;;)
		{
			printf("%d\n",mat[m][n]);
			count++;
			mat[m][n]=-1;
			m--;
			if(mat[m][n]==-1)
			{
				m++;
				n++;
				break;
			}
		}
		if(count>=row*col)break;
	}
	return 0;
}


int main(int argc, char* argv[])
{
	int array[100][100];
	int n,row,col,i,j,k=0,r,t,x=0;
	float m;
	scanf("%d",&row);
	scanf("%d",&col);
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
		{
	    	scanf("%d",&array[i][j]);
		}
	}
	if(row>col)
	{
		n=col;
	}
	else n=row;
	m=(float)n;
		while(k<m/2)
		{
			for(j=k;j<col-k;j++)
			{
				if(x!=row*col)
				{
					printf("%d\n",array[k][j]);
					x++;
				}
			}
			for(i=k+1;i<row-1-k;i++)
			{
				if(x!=row*col)
				{
					printf("%d\n",array[i][col-k-1]);
					x++;
				}
			}
			for(t=col-k-1;t>k;t--)
			{
				if(x!=row*col)
				{
					printf("%d\n",array[row-k-1][t]);
					x++;
				}
			}
			for(r=row-1-k;r>k;r--)
			{
				if(x!=row*col)
				{
					printf("%d\n",array[r][k]);
					x++;
				}
			}
			k++;
		}
	return 0;
}


int		arr[100][100] = {0};
int		pos[120][120] = {0};
int		rr, cc;

void	bianli(int, int, int, int);

int main()
{
	int	i, j;
	cin >> rr;
	cin >> cc;

	for(i = 0; i < rr; i ++)
	{
		for (j = 0; j < cc; j ++)
		{
			cin >> arr[i][j];
			pos[i][j] = 1;
		}
	}

	bianli(0, 0, 0, 1);
return 0;
}

//0 ??? 1 ???
void	bianli(int k, int ii, int jj, int s)
{
	if(pos[ii][jj] == 0)
	{
		return;
	}

	int i, j;
	//??
	if(k == 0)
	{
		//??
		if(s == 0)
		{
			for (j = jj; j >= 0; j --)
			{
				if(pos[ii][j] == 1)
				{
					cout << arr[ii][j] << endl;
					pos[ii][j] = 0;
				}
				else
				{
					bianli(1, ii - 1, j + 1, 0);
					return;
				}
			}
			bianli(1, ii - 1, 0, 0);
			return;
		}
		//??
		else
		{
			for (j = jj; j < cc; j ++)
			{
				if(pos[ii][j] == 1)
				{
					cout << arr[ii][j] << endl;
					pos[ii][j] = 0;
				}
				else
				{
					bianli(1, ii + 1, j - 1, 1);
					return;
				}
			}
			bianli(1, ii + 1, cc - 1, 1);
			return;
		}
	}
	//??
	else
	{
		//??
		if(s == 0)
		{
			for (i = ii; i >= 0; i --)
			{
				if(pos[i][jj] == 1)
				{
					cout << arr[i][jj] << endl;
					pos[i][jj] = 0;
				}
				else
				{
					bianli(0, i + 1, jj + 1, 1);
					return;
				}
			}
			bianli(0, 0, jj + 1, 1);
			return;
		}

		//??
		else
		{
			for (i = ii; i < rr; i ++)
			{
				if(pos[i][jj] == 1)
				{
					cout << arr[i][jj] << endl;
					pos[i][jj] = 0;
				}
				else
				{
					bianli(0, i - 1, jj - 1, 0);
					return;
				}
			}
			bianli(0, rr - 1, jj - 1, 0);
			return;
		}
	}

return;
}


int main(){
    int visit[105][105];
    int num[105][105];
    int i,j,row,col;
    scanf("%d %d",&row,&col);
    for(i = 0; i < row; i++){
            for(j = 0; j < col; j++){
                    visit[i][j] = 0;
                    scanf("%d",&num[i][j]);
            }
    }
    int direct = right;
    int x = 0,y = 0;
    while(1){
             if(x < 0||x >= row||y < 0||y >= col||visit[x][y] == 1){break;}
             visit[x][y] = 1;
             printf("%d\n",num[x][y]);
             switch(direct){        //???????????????
                     case up:       //???????????????
                          if(x - 1 < 0||visit[x - 1][y] == 1){
                               direct = (direct + 1) % 4;
                          }
                          break;
                     case down:
                          if(x + 1 >= row||visit[x + 1][y] == 1){
                               direct = (direct + 1) % 4;
                          }
                          break;
                     case left:
                          if(y - 1 < 0||visit[x][y - 1] == 1){
                               direct = (direct + 1) % 4;
                          }
                          break;
                     case right:
                          if(y + 1 >= col||visit[x][y + 1] == 1){
                               direct = (direct + 1) % 4;
                          }
                          break;
                     default:break;
             }
             switch(direct){
                     case up:x--;break;
                     case down:x++;break;
                     case left:y--;break;
                     case right:y++;break;
                     default:break;
             }
    }
    return 0;
}


/*
 * 1104-1.cpp
 *
 *  Created on: 2011-11-5
 *      Author: Administrator
 */
int main(){
	int row,col;
	cin>>row>>col;
	int a[row][col];
	int i,j,k,m,s=0;
	m=row*col;
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			cin>>a[i][j];

	for(i=0;i<row/2;i++){
		for(j=i;j<col-i-1;j++){
			if(s>=m)
										break;
			else{
				cout<<a[i][j]<<endl;
				s++;}

		}

		for(k=i;k<row-i-1;k++){
			if(s>=m)
								break;
			else{

			cout<<a[k][col-i-1]<<endl;
				s++;}

		}

		for(j=col-i-1;j>i;j--){
			if(s>=m)
								break;
			else{
				cout<<a[row-1-i][j]<<endl;
				s++;}

		}

		for(k=row-i-1;k>i;k--){
			if(s>=m)
								break;
			else{
				cout<<a[k][i]<<endl;
				s++;}

		}

	}
	if(row%2){
		for(j=row/2;j<col-row/2;j++)
			cout<<a[row/2][j]<<endl;
	}

	return 0;

}


int main()
{
    int m,n,time=0;
    cin>>m>>n;
    int a[m][n];
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<n;j++)
        cin>>a[i][j];
    }

    for(int i=0;;i++)
    {
        for(int j=i;j<=n-1-i;j++)
        {
            cout<<a[i][j]<<endl;
            time++;
        }
        if(time==m*n)break;

        for(int j=i+1;j<=m-1-i;j++)
        {
            cout<<a[j][n-i-1]<<endl;
            time++;
        }
        if(time==m*n)break;

        for(int j=n-i-2;j>=i;j--)
        {
            cout<<a[m-i-1][j]<<endl;
            time++;
        }
        if(time==m*n)break;

        for(int j=m-i-2;j>=i+1;j--)
        {
            cout<<a[j][i]<<endl;
            time++;
        }
        if(time==m*n)break;
    }
    return 0;
}


int main()
{
	int a[100][100]={0},i,j,row,col,p,sum=0;
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++){
		for(j=0;j<col;j++)
			scanf("%d",&a[i][j]);
	}
	for(p=0;;p++){
		for(j=p;j<=col-p-1;j++){
			printf("%d\n",a[p][j]);
			sum=sum+1;
		}
		if(sum==row*col)
			break;
		for(i=p+1;i<=row-p-1;i++){
			printf("%d\n",a[i][col-p-1]);
			sum=sum+1;
		}
		if(sum==row*col)
			break;
		for(j=col-p-2;j>=p;j--){
			printf("%d\n",a[row-p-1][j]);
			sum=sum+1;
		}
		if(sum==row*col)
			break;
		for(i=row-p-2;i>=p+1;i--){
			printf("%d\n",a[i][p]);
			sum=sum+1;
		}
		if(sum==row*col)
			break;
	}
	return 0;
}


int main(){
	int a[100][100]={0},row,col,num=0;
	cin>>row>>col;
	for(int i=0;i<row;i++){
		for(int j=0;j<col;j++){
			cin>>a[i][j];
		}
	}
	for(int i=0;;i++){
		if(num>=row*col)break;
		int b,x,y,z;
		for(b=i;b<col-i;b++){
			cout<<a[i][b]<<endl;
			num++;
		}
		if(num>=row*col)break;
		for(x=i+1;x<row-i;x++){
			cout<<a[x][b-1]<<endl;
			num++;
		}
		if(num>=row*col)break;
		for(y=col-i-2;y>=i;y--){
			cout<<a[row-i-1][y]<<endl;
			num++;
		}
		if(num>=row*col)break;
		for(z=row-i-2;z>i;z--){
			cout<<a[z][i]<<endl;
			num++;
		}
	}

	return 0;
}


int main()
{
	int row=0,col=0;
	cin>>row>>col;
	int array[101][101];
	int i=0,j=0,k=0;
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			cin>>array[i][j];
	for(k=0;(row-2*k>2)&&(col-2*k>2);k++){
		for(j=k;j<col-k;j++)
			cout<<array[k][j ]<<endl;
		for(i=k+1;i<row-k;i++)
			cout<<array[i][col-1-k]<<endl;
		for(j=col-2-k;j>=k;j--)
			cout<<array[row-1-k][j]<<endl;
		for(i=row-2-k;i>=k+1;i--)
			cout<<array[i][k]<<endl;
	}
	if(row==col){
		for(j=k;j<col-k;j++)
			cout<<array[k][j ]<<endl;
		for(i=k+1;i<row-k;i++)
			cout<<array[i][col-1-k]<<endl;
		for(j=col-2-k;j>=k;j--)
			cout<<array[row-1-k][j]<<endl;
		for(i=row-2-k;i>=k+1;i--)
			cout<<array[i][k]<<endl;
	}
	else{
		for(j=k;j<col-k;j++)
			cout<<array[k][j ]<<endl;
		for(i=k+1;i<row-k;i++)
			cout<<array[i][col-1-k]<<endl;
	}
	return 0;
}


int main()
{int sz[100][100];
int hang,lie;
scanf("%d %d",&hang,&lie);
for(int a=0;a<hang;a++){
	for(int b=0;b<lie;b++){
	  scanf("%d",&sz[a][b]);
	}
}
int c,d,e,f;
int hs=0,ls=0;
int hz=hang-1,lz=lie-1;
while(hs<=hz&&ls<=lz)
{if(hs!=hz&&lz!=ls)
	{for(c=ls;c<=lz-1;c++){
	  printf("%d\n",sz[hs][c]);
	}
	for(d=hs;d<=hz-1;d++){
	  printf("%d\n",sz[d][lz]);
	}
	for(e=lz;e>=ls+1;e--){
	  printf("%d\n",sz[hz][e]);
	}
    for(f=hz;f>=hs+1;f--){
	  printf("%d\n",sz[f][ls]);
}}

else{for(int m=hs;m<=hz;m++){
	  for(int n=ls;n<=lz;n++){
	    printf("%d\n",sz[m][n]);
	}
}}
	hs++;
	ls++;
	hz--;
	lz--;
}

return 0;
}


int main()
{
int row,col;
int i,j,n,time=0;
scanf("%d%d",&row,&col);
int array[100][100];
for(i=0;i<row;i++)
   for(j=0;j<col;j++)
    scanf("%d",&array[ i ][ j ]);
   for (n=0;;n++)
   {
    for (i=n;i<col-n;i++)
    {
     cout << array[ n ][ i ] << endl;
     time++;//??????????time?????
    }
    printf("\n");
    if(time==row*col)break;
    for (j=n+1;j<row-n;j++)
    {
     cout << array[ j ][col-n-1] << endl;
     time++;
    }
    printf("\n");
    if(time==row*col)break;
    for (i=col-2-n;i>=n;i--)
    {
     cout << array[row-n-1][ i ] << endl;
     time++;
    }
    printf("\n");
    if(time==row*col)break;
    for (j=row-2-n;j>n;j--)
    {
     cout << array[ j ][ n ] << endl;
     time++;
    }
    printf("\n");
    if(time==row*col)break;
   }
   return 0;
}


int main() {
	int row,col;
	int sz[100][100];
	scanf("%d %d",&row,&col);
	for(int i=0;i<row;i++){
		for(int j=0;j<col;j++){
			scanf("%d",&sz[i][j]);
		}
	}
	int xx_row=0;
	int sx_row=row-1;
	int xx_col=0;
	int sx_col=col-1;
	while((xx_row<sx_row)&&(xx_col<sx_col)){
		for(int i=xx_col;i<sx_col;i++){
			printf("%d\n",sz[xx_row][i]);
		}
		for(int j=xx_row;j<sx_row;j++){
			printf("%d\n",sz[j][sx_col]);
		}
		for(int k=sx_col;k>xx_col;k--){
			printf("%d\n",sz[sx_row][k]);
		}
		for(int p=sx_row;p>xx_row;p--){
			printf("%d\n",sz[p][xx_col]);
		}
		xx_row++;
		sx_row--;
		xx_col++;
		sx_col--;}
if((xx_row==sx_row)&&(xx_col!=sx_col)){
for(int i=xx_row;i<=sx_col;i++){printf("%d\n",sz[xx_row][i]);}}
if((xx_col==sx_col)&&(xx_row!=sx_row)){
for(int i=xx_col;i<=sx_row;i++){printf("%d\n",sz[i][xx_col]);}}
if((xx_row==sx_row)&&(xx_col==sx_col)){
printf("%d\n",sz[xx_row][sx_col]);}
return 0;
}


int main()
{
    int 	arrey [100][100];
	int i, j, k, times, all;
	int row, col;

	cin >> row >> col;
	for(i = 0; i < row; i ++)
		for(j = 0; j < col ; j ++)
			cin >> arrey[i][j];
		k = 0;
		times = 0;
		all = row * col;
		do{
			i = k;
			j = k;
			for( ; j < col - 1; j ++)
			{
				cout <<  arrey[i][j] << endl;
				times ++;
			}
		     for( ; i < row - 1;i ++)
					{
				 cout << arrey[i][j] << endl;
						times ++;}
			 if( k < col - 1 && k < row - 1 )
			 {

					for( ;j > k; j --)
					{
						cout << arrey[i][j] << endl;
						times ++;
					}
					for( ;i > k; i --)
					{
						cout << arrey[i][j] << endl;
						times ++;
					}
			 }

				else	if( k == col - 1 && col == row )
					{
						cout << arrey[k][k];
						times++;
					}
				else
				{
					cout << arrey[i][j];
					times ++;
				}
					if( times == all)
						break;
					col --;
					row --;
					k ++;
		}while(1);
			return 0;
}


typedef struct
{
	int file;
	int flag;
}map;
void main()
{
	map a[200][200];
	int count=0,i,j,col,row;
	char direction='d';
	for(i=1;i<=200;i++)
	{
		for(j=1;j<=200;j++)
		{
			a[i-1][j-1].flag=0;
		}
	}
	scanf("%d %d",&row,&col);
	for(i=1;i<=row;i++)
	{
		for(j=1;j<=col;j++)
		{
			scanf("%d",&a[i][j].file);
			a[i][j].flag=1;
		}
	}
	i=1;
	j=1;
	do
	{
		count++;
		switch(direction)
		{
		case'd':
			a[i][j].flag=0;
			if(a[i][j+1].flag==1)
			{
				printf("%d\n",a[i][j].file);
				j++;
			}
			else
			{
				printf("%d\n",a[i][j].file);
				direction='s';
				i++;
			}
			break;
		case's':
			a[i][j].flag=0;
			if(a[i+1][j].flag==1)
			{
				printf("%d\n",a[i][j].file);
				i++;
			}
			else
			{
				printf("%d\n",a[i][j].file);
				direction='a';
				j--;
			}
			break;
		case'a':
			a[i][j].flag=0;
			if(a[i][j-1].flag==1)
			{
				printf("%d\n",a[i][j].file);
				j--;
			}
			else
			{
				printf("%d\n",a[i][j].file);
				direction='w';
				i--;
			}
			break;
		case'w':
			a[i][j].flag=0;
			if(a[i-1][j].flag==1)
			{
				printf("%d\n",a[i][j].file);
				i--;
			}
			else
			{
				printf("%d\n",a[i][j].file);
				direction='d';
				j++;
			}
			break;
		default:
			break;
		}
	}while(count!=row*col);
}


int main ()
{
	int array[100][100];										//??????array
	int row, col;												//?????
	cin >> row >> col;											//?????
	for ( int i = 0; i < row; i ++ )							//????
		for ( int j = 0; j < col; j ++ )
			cin >> array[i][j];
	int startrow = 0, startcol = 0;								//??????????
	int sum = 0;												//???????????
	while (true)												//?????????????
	{
		for ( int i = startcol; i < col-startcol; i ++ )
		{cout << array[startrow][i]<<endl;sum ++;}
		if ( sum == row * col ) break;
		for ( int i = startrow + 1; i < row-startrow; i ++ )
		{cout << array[i][col-startcol-1]<<endl;sum ++;}
		if ( sum == row * col ) break;
		for ( int i = col-startcol-2; i > startcol; i -- )
		{cout << array[row-startrow-1][i]<<endl;sum ++;}
		if ( sum == row * col ) break;
		for ( int i = row-startrow-1; i > startrow; i -- )
		{cout << array[i][startcol]<<endl;sum ++;}
		if ( sum == row * col ) break;
		startrow ++;											//????????????????
		startcol ++;
	}
	return 0;
}


int main()
{
int row,col;
int i,j,n,time=0;
scanf("%d%d",&row,&col);
int array[100][100];
for(i=0;i<row;i++)
   for(j=0;j<col;j++)
    scanf("%d",&array[ i ][ j ]);
   for (n=0;;n++)
   {
    for (i=n;i<col-n;i++)
    {
     printf("%d\n",array[ n ][ i ]);
     time++;
    }
    if(time==row*col)break;
    for (j=n+1;j<row-n;j++)
    {
     printf("%d\n",array[ j ][col-n-1]);
     time++;
    }
    if(time==row*col)break;
    for (i=col-2-n;i>=n;i--)
    {
     printf("%d\n",array[row-n-1][ i ]);
     time++;
    }
    if(time==row*col)break;
    for (j=row-2-n;j>n;j--)
    {
     printf("%d\n",array[ j ][ n ]);
     time++;
    }
    if(time==row*col)break;
   }
   scanf("%d%d",&row,&col);
   return 0;
}


int main() {
	int row = 0, col = 0, sumtimes = 0, i = 0, j = 0,sum=0;
	cin >> row >> col;
	int max = row > col ? row : col;
	int a[row][col];
	for (int i = 0; i < row; i++)
		for (int j = 0; j < col; j++)
			cin >> a[i][j];
	while (sum<row*col) {
		for (j = sumtimes / 4; j <= col - 1 - sumtimes / 4; j++) {
			cout << a[i][j] << endl;
			sum++;
		}
		if (sum==row*col)break;
		sumtimes++;
		for (i = sumtimes / 4 + 1; i <= row - 1 - sumtimes / 4 - 1; i++) {
			cout << a[i][j - 1] << endl;
			sum++;
		}
		if (sum==row*col)break;
		sumtimes++;
		for (j--; j >= sumtimes / 4; j--) {
			cout << a[i][j] << endl;
			sum++;
		}
		if (sum==row*col)break;
		sumtimes++;
		for (i--; i >= sumtimes / 4 + 1; i--) {
			cout << a[i][j + 1] << endl;
			sum++;
		}
		if (sum==row*col)break;
		i++;
		sumtimes++;

	}
	return 0;
}


int main(){
	int array[100][100];
	int i,j,x,y,row,col;
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++){
		for(j=0;j<col;j++){
			scanf("%d",&array[i][j]);
		}
	}
	x=0;
	y=0;
	while(1){

		for(j=y;j<col;j++){
			printf("%d\n",array[x][j]);
		}

		x++;
		if( x == row  ){
			break;
		}
		for(i=x;i<row;i++){
			printf("%d\n",array[i][col-1]);
		}

		col=col-1;
		if( y == col )
			break;

		for(j=col-1;j>=y;j--){
			printf("%d\n",array[row-1][j]);
		}
		row=row-1;
		for(i=row-1;i>=x;i--){
			printf("%d\n",array[i][y]);
		}
		y++;
		if( x == row )
			break;
	}
	return 0;
}


int main()
{
	int row,col,i,j,array[100][100];
	scanf("%d %d\n",&row,&col);
	for(i=0;i<row;i++){
		for(j=0;j<col;j++){
		scanf("%d",&array[i][j]);
		}
	}
	int x_row=0,s_row=row-1,x_col=0,s_col=col-1;
	while(x_row<s_row&&x_col<s_col){
		for(j=x_col;j<s_col;j++){
			if(x_row==0&&j==0){
			printf("%d",array[x_row][j]);
			}else{
			printf("\n%d",array[x_row][j]);
			}
		}
		for(i=x_row;i<s_row;i++){
		printf("\n%d",array[i][s_col]);
		}
		for(j=s_col;j>x_col;j--){
		printf("\n%d",array[s_row][j]);
		}
		for(i=s_row;i>x_row;i--){
		printf("\n%d",array[i][x_col]);
		}
		x_row+=1;
		s_row-=1;
		x_col+=1;
		s_col-=1;
	}
	if(row<=col&&row%2==1){
		for(j=(row-1)/2;j<=col-1-(row-1)/2;j++){
			if(row==1&&j==0){
			printf("%d",array[(row-1)/2][j]);
			}else{
		printf("\n%d",array[(row-1)/2][j]);
			}
		}
	}
	if(col<row&&col%2==1){
		for(i=(col-1)/2;i<=row-1-(col-1)/2;i++){
		printf("\n%d",array[i][(col-1)/2]);
		}
	}
	return 0;
}


int main()
{
    int sz[N][N];
	int row,col;
	scanf("%d%d",&row,&col);
	int i,j;
    for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
		{
			scanf("%d",&sz[i][j]);
		}
	}
	int sx=0,xx=row-1,zx=0,yx=col-1;
	while((sx<xx)&&(zx<yx))
	{
	    for(j=zx;j<yx;j++)
		{
		   printf("%d\n",sz[sx][j]);
		}
	    for(j=sx;j<xx;j++)
		{
		   printf("%d\n",sz[j][yx]);
		}
	    for(j=yx;j>zx;j--)
		{
		   printf("%d\n",sz[xx][j]);
		}
	    for(j=xx;j>sx;j--)
		{
		   printf("%d\n",sz[j][zx]);
		}
		sx++;;xx--;zx++;yx--;
	}
	if((sx==xx)&&(zx==yx))
	{
		printf("%d\n",sz[sx][zx]);
	}
	if((sx==xx)&&(zx<yx))
	{
		for(i=zx;i<=yx;i++)
		{
			printf("%d\n",sz[sx][i]);
		}
	}
	if((sx<xx)&&(zx==yx))
	{
		for(i=sx;i<=xx;i++)
		{
			printf("%d\n",sz[i][zx]);
		}
	}
	return 0;
}


int main(int argc, char* argv[])
{
	int row,col,i,h,num,total;
	int sz[100][100];
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++){
		for(h=0;h<col;h++){
			scanf("%d",&sz[i][h]);
		}
	}
	num=0;
	h=0;
	total=row*col;
	while(1){
		for(i=h;i<col-h;i++){
			printf("%d\n",sz[h][i]);
			num++;
			if(num==total){
				return 0;
			}
		}
		for(i=h+1;i<row-h;i++){
			printf("%d\n",sz[i][col-1-h]);
			num++;
			if(num==total){
				return 0;
			}
		}
		for(i=h+1;i<col-h;i++){
			printf("%d\n",sz[row-1-h][col-1-i]);
			num++;
			if(num==total){
				return 0;
			}
		}
		for(i=h+1;i<row-h-1;i++){
			printf("%d\n",sz[row-1-i][h]);
			num++;
			if(num==total){
				return 0;
			}
		}
		h++;
	}
}


int main()
{
	int hui[100][100];
	int row,col;
	int n,m,i;
	int rowa,cola;
	int T;
	scanf("%d %d\n",&rowa,&cola);
	if(rowa<cola){T=rowa;}else{T=cola;}
	row=rowa-1;col=cola-1;
	for(n=0;n<rowa;n++){
		for(m=0;m<cola;m++){
			scanf("%d",&hui[n][m]);
		}
	}
	for(i=0;i<floor(T*0.5+0.5);){
		for(n=i,m=i;n<row-i+1;){
				if(m<col-i){
				printf("%d\n",hui[n][m]);
				m++;
			}else{
				printf("%d\n",hui[n][m]);
				n++;
			}
		}
		i++;
		if(m>col/2&&n>row/2){
			for(n=row-i+1,m=col-i;n>i-1;){
				if(m>i-1){
					printf("%d\n",hui[n][m]);
					m--;
				}else{
					printf("%d\n",hui[n][m]);
					n--;
				}
			}
		}
	}

	return 0;
}


/*
 * 1.cpp
 *
 *  Created on: 2011-11-4
 *      Author: 11294
 */
int main() {
	int row, col;
	cin >> row >> col;
	int array[row][col];
	int i, j;
	for (i = 0; i < row; i++) {
		for (j = 0; j < col; j++) {
			cin >> array[i][j];
		}
	}
	int p = 0;
	for (; !(2 * p >= col - 2 || 2 * p >= row - 2);) {
		for (i = p; i <= col - 2 - p; i++) {
			cout << array[p][i] << endl;
		}
		for (j = p; j <= row - 2 - p; j++) {
			cout << array[j][col - 1 - p] << endl;
		}
		for (i = p; i <= col - 2 - p; i++) {
			cout << array[row - 1 - p][col - i - 1] << endl;
		}
		for (j = p; j <= row - 2 - p; j++) {
			cout << array[row - 1 - j][p] << endl;
		}
		p++;
	}
	if (col == row) {
		for (i = p; i <= col - 1 - p; i++) {
			cout << array[p][i] << endl;
		}
		if(col%2==0){
		for (i = col - 1 - p; i >= p; i--) {
			cout << array[p + 1][i] << endl;
		}
	}}
	if (col > row) {
		for (i = p; i <= col - 1 - p; i++) {
			cout << array[p][i] << endl;
		}
		if(row%2==0){
		for (i = col - 1 - p; i >= p; i--) {
			cout << array[p + 1][i] << endl;
		}
	}}
	if (col < row) {
		for (i = p; i <= row - 1 - p; i++) {
			cout << array[i][p] << endl;
		}
		if(col%2==0){
		for ( i = row - 1 - p;i >= p; i--) {
			cout << array[i][p+1] << endl;
		}
	}}
	return 0;
}


int main()
{
 int sz[100][100],i=0,j=0,row,col;
 int hxx,hsx,lxx,lsx,m1,m2,m3,m4,n1,n2;
 scanf("%d%d",&row,&col);
 for(i=0;i<row;i++)
 {
  for(j=0;j<col;j++)
  {
   scanf("%d",&sz[i][j]);
  }
 }

 hxx=0;hsx=row-1;lxx=0;lsx=col-1;
 for(hxx=0,hsx=row-1,lxx=0,lsx=col-1;hxx<hsx&&lxx<lsx;hxx++,hsx--,lxx++,lsx--)
 {
    for(m1=lxx;m1<lsx;m1++)
 {
  printf("%d\n",sz[hxx][m1]);
 }
 for(m2=hxx;m2<hsx;m2++)
 {
  printf("%d\n",sz[m2][lsx]);
 }
 for(m3=lsx;m3>lxx;m3--)
 {
  printf("%d\n",sz[hsx][m3]);
 }
    for(m4=hsx;m4>hxx;m4--)
 {
  printf("%d\n",sz[m4][lxx]);
 }
 }
 if(hxx==hsx)
 {
  for(n1=lxx;n1<=lsx;n1++)
  {
   printf("%d\n",sz[hxx][n1]);
  }
 }
 else if(lxx==lsx)
 {
  for(n2=hxx;n2<=hsx;n2++)
  {
   printf("%d\n",sz[n2][lxx]);
  }
 }
  return 0;
}


int main() {
	int row,col,xxrow,sxrow,xxcol,sxcol,i,j,sz[100][100];
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++){
		for(j=0;j<col;j++){
			scanf("%d",&sz[i][j]);
		}
	}
	i=0;
	j=0;
	xxrow=0;
	sxrow=row-1;
	xxcol=0;
	sxcol=col-1;
	while(xxrow<sxrow&&xxcol<sxcol){
		for(j=xxcol;j<sxcol;j++)
			printf("%d\n",sz[xxrow][j]);
		for(i=xxrow;i<sxrow;i++)
			printf("%d\n",sz[i][sxcol]);
		for(j=sxcol;j>xxrow;j--)
			printf("%d\n",sz[sxrow][j]);
		for(i=sxrow;i>xxrow;i--)
			printf("%d\n",sz[i][xxcol]);
		xxrow++;
		sxrow--;
		xxcol++;
		sxcol--;
	}
	if(xxrow==sxrow||xxcol==sxcol){
		if(xxrow==sxrow&&xxcol!=sxcol){
			for(j=xxcol;j<=sxcol;j++)
				printf("%d\n",sz[xxrow][j]);
		}
		if(xxrow!=sxrow&&xxcol==sxcol){
			for(i=xxrow;i<=sxrow;i++)
				printf("%d\n",sz[i][xxcol]);
		}
		if(xxrow==sxrow&&xxcol==sxcol)
			printf("%d\n",sz[xxrow][xxcol]);
	}
	return 0;
}


int main()
{
    int row, col, count = 0, count0;
    int a[99][99];
    cin >> row >> col;
    for (int i =0; i < row; i++)
    {
        for (int j = 0; j < col; j++)
        {
            cin >> a[i][j];
        }
    }
    count0 = row * col;
    for (int k = 0; ;k++, col--, row--)
    {
        for (int i = k; i < col; i++)
        {
            cout << a[k][i] << endl;
            count++;
            if (count == count0)
                break;
        }
        if (count == count0)
            break;
        for (int i = k + 1; i < row; i++)
        {
            cout << a[i][col - 1] << endl;
            count++;
            if (count == count0)
                break;
        }
        if (count == count0)
            break;
        for (int i = col - 2; i >= k; i--)
        {
            cout << a[row - 1][i] << endl;
            count++;
            if (count == count0)
                break;
        }
        if (count == count0)
            break;
        for (int i = row - 2; i >= k + 1; i--)
        {
            cout << a[i][k] << endl;
            count++;
            if (count == count0)
                break;
        }
        if (count == count0)
            break;
    }
    return 0;
}


int main(){
 int row,col,xx_row,sx_row,xx_col,sx_col,a[100][100],i,j;
 scanf("%d%d",&row,&col);
 for(i=0;i<row;i++){
  for(j=0;j<col;j++){
   scanf("%d",&a[i][j]);
  }
 }
 xx_row=0;
 sx_row=row;
 xx_col=0;
 sx_col=col;
 while((xx_row<=sx_row)&&(xx_col<=sx_col)){
  for(j=xx_col;j<sx_col;j++){
   printf("%d\n",a[xx_row][j]);
  }

  for(i=xx_row+1;i<sx_row;i++){
   printf("%d\n",a[i][sx_col-1]);
  }
  if(xx_row>=sx_row-1){
   break;
  }
      if(xx_col>=sx_col-1){
   break;
  }
  for(j=sx_col-2;j>xx_col;j--){
   printf("%d\n",a[sx_row-1][j]);
  }
  for(i=sx_row-1;i>xx_row;i--){
   printf("%d\n",a[i][xx_col]);
  }
  xx_row++;
  xx_col++;
  sx_row--;
  sx_col--;
 }

 return 0;
}


int main()
{
	int n[ROW][COL],row,col,i,j,begin;
    scanf("%d%d",&row,&col);
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++) scanf("%d",&n[i][j]);
	}
    for(begin=0;;begin++)
		{
			if(begin>=(col-begin)) break;
			for(i=begin,j=begin;j<(col-begin);j++) printf("%d\n",n[i][j]);
		    if((begin+1)>=(row-begin)) break;
		    else for(i=(begin+1),j=(col-begin-1);i<(row-begin);i++) printf("%d\n",n[i][j]);
	        if((col-begin-2)<begin) break;
		    else for(i=(row-begin-1),j=(col-begin-2);j>(begin-1);j--) printf("%d\n",n[i][j]);
            if((row-begin-2)<(begin+1)) break;
		    else for(i=(row-begin-2),j=begin;i>begin;i--) printf("%d\n",n[i][j]);

	}
}


int num[100][100];     //float:??????????????
int row,col,i,j;
void output(int,int,int,int);
int main(){
	cin>>row>>col;
	for(i = 0;i < row;i++)
		for(j = 0;j < col;j++)
			cin>>num[i][j];
	output(0,0,row,col);
	return 0;
}

void output(int x,int y,int a,int b){  //???x?y?????a?b????
	int i;
	if(a == 1){
		for(i = x;i < x+b;i++)
			printf("%d\n",num[x][i]);
	}
	else if(a == 2){
		for(i = x;i < x+b;i++)
			printf("%d\n",num[x][i]);
		for(i = x + b - 1;i >= x;i--)
			printf("%d\n",num[x+1][i]);
	}
	else if(b == 1){
		for(i = y;i < y+a;i++)
			printf("%d\n",num[i][y]);
	}
	else if(b == 2){
		printf("%d\n",num[x][y]);
		for(i = y;i < y+a;i++)
			printf("%d\n",num[i][y+1]);
		for(i = y + a - 1;i > y;i--)
			printf("%d\n",num[i][y]);
	}
	else{
		for(i = x;i < x + b;i++)printf("%d\n",num[x][i]);
		for(i = y + 1;i < y + a;i++)printf("%d\n",num[i][x+b-1]);
		for(i = x + b - 2;i >= x;i--)printf("%d\n",num[y+a-1][i]);
		for(i = y + a - 2;i > y;i--)printf("%d\n",num[i][y]);
		output(x+1,y+1,a - 2,b - 2);
	}
}


void main()
{
int row=0,col=0;
int i=0,j=0,n=0,t=0;
scanf("%d%d",&row,&col);
int array[100][100];
for(i=0;i<row;i++)
   for(j=0;j<col;j++)
    scanf("%d",&array[ i ][ j ]);
   for (n=0;;n++)
   {
    for (i=n;i<col-n;i++)
    {
     printf("%d\n",array[ n ][ i ]);
     t++;
    }

    if(t==row*col)
		break;
    for (j=n+1;j<row-n;j++)
    {
     printf("%d\n",array[ j ][col-n-1]);
     t++;
    }

    if(t==row*col)
		break;
    for (i=col-2-n;i>=n;i--)
    {
     printf("%d\n",array[row-n-1][ i ]);
     t++;
    }

    if(t==row*col)
		break;
    for (j=row-2-n;j>n;j--)
    {
     printf("%d\n",array[ j ][ n ]);
     t++;
    }

    if(t==row*col)
		break;
   }

}


int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	int sz[100][100];
	int x=0,y;
	while(x<n){
		for(y=0;y<m;y++){
			scanf("%d",&(sz[x][y]));
		}
		x++;
	}
	int xx_row,xx_col,sx_row,sx_col;
	int i,j;
	xx_row=xx_col=0;
	sx_row=n-1;
	sx_col=m-1;
	while(xx_row<sx_row && xx_col<sx_col){
		for(j=xx_col;j<sx_col;j++){
			printf("%d\n",sz[xx_row][j]);
		}
		for(i=xx_row;i<sx_row;i++){
			printf("%d\n",sz[i][sx_col]);
		}
		for(j=sx_col;j>xx_col;j--){
			printf("%d\n",sz[sx_row][j]);
		}
		for(i=sx_row;i>xx_row;i--){
			printf("%d\n",sz[i][xx_col]);
		}
		xx_row++;
		xx_col++;
		sx_row--;
		sx_col--;
	}
	if(xx_row==sx_row){
		for(j=xx_col;j<=sx_col;j++){
			printf("%d\n",sz[sx_row][j]);
		}
	}else{
	if(xx_col==sx_col){
		for(i=xx_row;i<=sx_row;i++){
			printf("%d\n",sz[i][sx_col]);
		}
	}
	}
	return 0;
}


int main()
{
	int row, col;
	cin >> row >> col;
	int matrix[100][100];
	int i, j, u, v, n, s;
	for (i = 1; i <= row; i++)
	{
		for (j = 1; j <= col; j++)
		{
			cin >> matrix[i][j];
		}
	}
	if (row > col)
	{
		if (col % 2 == 0)
			n = col / 2;
		else
			n = col / 2 + 1;
	}
	else
	{
		if (row % 2 == 0)
			n = row / 2;
		else
			n = row / 2 + 1;
	}
	u = 1;
	v = 1;
	for (s = 1; s <= n; s++)
	{
		cout << matrix[u][v] << endl;
		for (i = 1; i <= col - 1; i++)
		{
			v++;
			cout << matrix[u][v] << endl;
		}
		for (i = 1; i <= row - 1; i++)
		{
			u++;
			cout << matrix[u][v] << endl;
		}
		if (row != 1)
		{
			for (i = 1; i <= col - 1; i++)
			{
				v--;
				cout << matrix[u][v] << endl;
			}
		}
		if (col != 1)
		{
			for (i = 1; i <= row - 2; i++)
			{
				u--;
				cout << matrix[u][v] << endl;
			}
		}
		v = v + 1;
		col = col - 2;
		row = row - 2;
	}
	return 0;
}


int sz[100][100];
int main(){
	int k,ROW,COL,row,col,time=0,m=0;
	scanf("%d %d",&ROW,&COL);
	for(row=0;row<ROW;row++){
		for(col=0;col<COL;col++){
			scanf("%d",&sz[row][col]);
		}
	}
	for(k=0;k<100;k++){
		for(col=k;col<COL-k-1;col++){
			printf("%d\n",sz[k][col]);
			time++;
				if(time==COL*ROW){
					m=1;
					break;
				}
		}
		for(row=k;row<ROW-k-1;row++){
			if(m==1) break;
			printf("%d\n",sz[row][COL-k-1]);
			time++;
            if(time==COL*ROW){
					m=1;
					break;
		}
		}
		for(col=COL-k-1;col>k;col--){
			if(m==1) break;
			printf("%d\n",sz[ROW-k-1][col]);
			time++;
            if(time==COL*ROW){
					m=1;
					break;
		}
		}
		for(row=ROW-k-1;row>k;row--){
			if(m==1) break;
			printf("%d\n",sz[row][k]);
			time++;
 //           printf("time=%d\n",time);
			if(time==COL*ROW){
					m=1;
					break;
			}
		}
		if(time==COL*ROW-1){
			printf("%d",sz[(ROW-1)/2][(COL-1)/2]);
			break;
		}
	if(m==1)  break;
	}
        return 0;
}


int main()
{
 int row,col;
 int i,j,n,time=0,x;

 scanf("%d%d",&row,&col);
 int array[100][100];
 for(i=0;i<row;i++)
  for(j=0;j<col;j++)
   scanf("%d",&array[i][j]);
  for (n=0;;n++)
  {
   for (i=n;i<col-n;i++)
   {
    printf("%d\n",array[n][i]);
    time++;
   }

   if(time==row*col)break;
   for (j=n+1;j<row-n;j++)
   {
    printf("%d\n",array[j][col-n-1]);
    time++;
   }
   if(time==row*col)break;
   for (i=col-2-n;i>=n;i--)
   {
    printf("%d\n",array[row-n-1][i]);
    time++;
   }

   if(time==row*col)break;
   for (j=row-2-n;j>n;j--)
   {
    printf("%d\n",array[j][n]);
    time++;
   }
   if(time==row*col)break;
  }
  return 0;
}


int main(){
int row,col,t;
int jz[100][100];
t=1;
scanf("%d %d",&row,&col);
for(int f=0;f<row;f++){
	for(int g=0;g<col;g++){
scanf("%d",&jz[f][g]);}
}
for(int i=0;1;i++){
	if(t==row*col+1){
		break;}
	for(int n=i;n<col-i;n++){
		if(t==row*col+1){
		break;}
	printf("%d\n",jz[i][n]);
	t++;
	}
	for(int m=i+1;m<row-i;m++){
		if(t==row*col+1){
		break;}
		printf("%d\n",jz[m][col-(i+1)]);
		t++;}
	for (int k=col-(i+2);k>=i;k--){
		if(t==row*col+1){
		break;}
			printf("%d\n",jz[row-(i+1)][k]);
	t++;}
	for(int e=row-(i+2);e>=i+1;e--){
		if(t==row*col+1){
		break;}
	printf("%d\n",jz[e][i]);
	t++;}

}
return 0;

}


int u[1000][1000];
int main()
{
    int row,col,i,j,sum,k,m;
    scanf("%d%d",&row,&col);
    for(i=0;i<row;i++)
    {
	for(j=0;j<col;j++)
        {
	    scanf("%d",&u[i][j]);
	}
    }
    if(row>col)
    {
        m=col;
    }
    else
    {
        m=row;
    }

    for(k=0;k<m;k++)
    {
        for(j=k;j<col-k;j++)
        {
	    printf("%d\n",u[k][j]);
        }
	if(k+1>=row-k)
        {
            break;
	}

        for(i=k+1;i<row-k;i++)
        {
	    printf("%d\n",u[i][col-k-1]);
	}
	if(col-2-k<k)
        {
	    break;
	}

        for(j=col-2-k;j>=k;j--)
        {
	    printf("%d\n",u[row-k-1][j]);
	}
        if(row-2-k<=k)
        {
	    break;
	}

        for(i=row-2-k;i>k;i--)
        {
	    printf("%d\n",u[i][k]);
	}

    }
    return 0;
}


int main()
{
    int row, col;
    int i, j, n, time = 0;
    cin >> row >> col;
    int a[100][100];
    for (i = 0; i < row; i++)
        for (j = 0; j < col; j++)
            cin >> a[i][j];
    for (n = 0; ; n++)
    {
        for (i = n; i < col - n; i++)
        {
            cout << a[n][i] << endl;
            time++;
        }
        if (time == row * col)
            break;
        for (j = n + 1; j < row - n; j++)
        {
            cout << a[j][(col - n - 1)] << endl;
            time++;
        }
        if (time == row * col)
            break;
        for (i = col - 2 - n; i >= n; i--)
        {
            cout << a[row - n - 1][i] << endl;
            time++;
        }
        if (time == row * col)
            break;
        for (j = row - 2 - n; j > n; j--)
        {
            cout << a[j][n] << endl;
            time++;
        }
        if (time == row * col)
            break;
    }
    return 0;
}


int matrix[101][101];

void transform(int , int);

int main()
{
        int m, n;
        int i, j;
        scanf("%d%d", &m, &n);
        for (i = 1; i <= m ; i++)
                for (j = 1; j <= n; j++) {
                        scanf("%d", &matrix[i][j]);
                }
        transform(m, n);

        return 0;
}

void transform(int m, int n)
{
        int total = m * n;
        int index = 0;
        int dir = 0;
        int x = 0, y = 0;
        int times[4] = {0};

        while (index < total) {
                switch(dir) {
                        case 0:
                                x++;y++;
                                while ( y < n - times[1] ) {
                                        printf("%d\n", matrix[x][y]);
                                        y++;
                                        index++;
                                }
                                break;
                        case 1:
                                while ( x < m - times[2]) {
                                        printf("%d\n", matrix[x][y]);
                                        x++;
                                        index++;
                                }
                                break;
                        case 2:
                                while ( y > times[3] + 1 ) {
                                        printf("%d\n", matrix[x][y]);
                                        y--;
                                        index++;
                                }
                                break;
                        case 3:
                                while ( x > times[0] ) {
                                        printf("%d\n", matrix[x][y]);
                                        x--;
                                        index++;
                                }
                                break;
                        default:
                                break;
                }
                if (total - index == 1) {
                        if (dir == 3) x++, y++;
                        printf("%d\n", matrix[x][y]);
                        index++;
                }
                times[dir]++;
                dir = (dir+1)%4;
        }
}


int main()
  { int i,j,k,hang,lie,a[100][100],total,sum=0;//??????????total?????????total=hang*lie?

    scanf("%d %d\n",&hang,&lie);
    total=hang*lie;
    for(i=0;i<=hang-1;i++)
    { for(j=0;j<=lie-1;j++)
      scanf("%d",&a[i][j]);}

    for(k=1;k<=10000;k++)
    {
      for(j=k-1;j<=lie-k;j++)
      { printf("%d\n",a[k-1][j]);sum=sum+1;
        if(sum==total)goto end;}

      for(i=k;i<=hang-k;i++)
    { printf("%d\n",a[i][lie-k]);
       sum=sum+1;
        if(sum==total)goto end; }
      for(j=lie-k-1;j>=k-1;j--)

       { printf("%d\n",a[hang-k][j]);
       sum=sum+1;
        if(sum==total)goto end;}

      for(i=hang-k-1;i>=k;i--)

     { printf("%d\n",a[i][k-1]);
        sum=sum+1;
        if(sum==total)goto end;  }

        }
     end:;
    return 0;
     }


int main(int argc, char* argv[])
{
	int ROW,COL,row,col,rowxia,rowup,colxia,colup;
	int array[99][99];
	scanf("%d%d",&ROW,&COL);
	for(row=0;row<ROW;row++){
		for(col=0;col<COL;col++){
	scanf("%d",&array[row][col]);}}
	for(rowxia=0,rowup=ROW-1,colxia=0,colup=COL-1;rowxia<rowup&&colxia<colup;rowxia++,colxia++,rowup--,colup--){
	for(row=rowxia,col=colxia;col<colup;col++){
    printf("%d\n",array[row][col]);}
		for(col=colup,row=rowxia;row<rowup;row++){
		printf("%d\n",array[row][col]);}
		for(row=rowup,col=colup;col>colxia;col--){
		printf("%d\n",array[row][col]);}
		for(col=colxia,row=rowup;row>rowxia;row--){
			printf("%d\n",array[row][col]);}}
	if(rowup==rowxia){
		for(col=colxia,row=rowup;col<=colup;col++){
			printf("%d\n",array[row][col]);}}
	else if(colup==colxia){
		for(row=rowxia,col=colup;row<=rowup;row++){
	printf("%d\n",array[row][col]);}}
	return 0;
}


int main(){
    int array[100][100],row,col,min,i,j,k;
    scanf("%d%d",&row,&col);
    for(i=0;i<row;i++){
        for(j=0;j<col;j++){
            scanf("%d",&array[i][j]);
        }
    }
    if(row<col){
        min=row;
    }else min=col;
    for(k=0;k<min/2;k++){
        for(j=k;j<col-k-1;j++){
            printf("%d\n",array[k][j]);
        }
        for(j=k;j<row-1-k;j++){
            printf("%d\n",array[j][col-1-k]);
        }
        for(j=col-1-k;j>k;j--){
            printf("%d\n",array[row-1-k][j]);
        }
        for(j=row-1-k;j>k;j--){
            printf("%d\n",array[j][k]);
        }
    }
    if(min%2==1){

        if(row<col){
            for(i=min/2;i<(col-min/2);i++){
            printf("%d\n",array[row/2][i]);
           }
        }
        else if(row>col){
            for(i=min/2;i<(row-min/2);i++){
                printf("%d\n",array[i][col/2]);
            }
        }
        else if(row==col){
            printf("%d\n",array[col/2][col/2]);
        }
    }
    return 0;
}


int main()
{
	int a[110][110],row,col,i,j,k,l=0,s=0;;
	scanf("%d %d",&row,&col);
	for(i=0;i<row;i++){
	for(j=0;j<col;j++)scanf("%d",&a[i][j]);}

	for(i=1;l<row*col;i++){
	k=i%4;
	if(k==1){
			if(s<col-s-1)
				for(j=s;j<col-s-1;j++){printf("%d\n",a[s][j]);l++;	if(l==row*col)break;}
			if(s==col-s-1)continue;
}

	if(k==2){
			if(s<row-s-1)
				for(j=s;j<row-s-1;j++){printf("%d\n",a[j][col-s-1]);l++;if(l==row*col)break;}
			if(s==row-s-1)continue;
		}

	if(k==3){
			if(s<col-s-1)
				for(j=col-s-1;j>s;j--){printf("%d\n",a[row-s-1][j]);l++;if(l==row*col)break;}
			if(s==col-s-1)continue;
		}

	if(k==0){
			if(s<row-s-1)
				for(j=row-s-1;j>s;j--){printf("%d\n",a[j][s]);l++;if(l==row*col)break;}
			if(s==row-s-1&&l==row*col-1){printf("%d\n",a[s][s]);l++;}
			if(s==row-s-1&&l!=row*col-1)continue;
		}

	if(k==0)s++;

	}
	return 0;
}


int main()
{
	int number[100][100];
	int row,col,i,j,a=0,zongshu=0;
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
		{
			scanf("%d",&number[i][j]);
		}
	}
	for(a=0;a>=0;a++)
	{
		for(j=a;j<col-a;j++)
		{
			printf("%d\n",number[a][j]);
			zongshu++;
		}
		if(zongshu==row*col)
		{
			break;
		}
		for(i=a+1;i<row-a;i++)
		{
			printf("%d\n",number[i][col-a-1]);
			zongshu++;
		}
		if(zongshu==row*col)
		{
			break;
		}
		for(j=col-2-a;j>=a;j--)
		{
			printf("%d\n",number[row-a-1][j]);
			zongshu++;
		}
		if(zongshu==row*col)
		{
			break;
		}
        for(i=row-2-a;i>a;i--)
		{
			printf("%d\n",number[i][a]);
			zongshu++;
		}
		if(zongshu==row*col)
		{
			break;
		}
	}
	return 0;
}


int main()
{
	int row,col,i,j,k,p,a[101][101],l,h,n;
	cin>>row>>col;
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			cin>>a[i][j];
	l=col,h=row,p=0,n=0;
	while(1){
		for(j=p;j<l-p;j++){
				cout<<a[p][j]<<endl;
				n++;
		}
		if(n==row*col)break;
		for(i=p+1;i<h-p;i++){
			cout<<a[i][l-p-1]<<endl;
			n++;
		}
		if(n==row*col)break;
		for(j=l-2-p;j>=p;j--){
			cout<<a[h-p-1][j]<<endl;
			n++;
		}
		if(n==row*col)break;
		for(i=h-2-p;i>p;i--){
			cout<<a[i][p]<<endl;
			n++;
		}
		if(n==row*col)break;
		p++;
	}
	return 0;
}


int main(){
	int row , col ;
	int a[100][100];
	int i,j;
	int flag=1;
	cin >> row >> col ;
	int  topBorder=0,bottomBorder=row-1;
	int leftBorder=0,rightBorder=col-1;
	int x=0,y=0;
	for(i=0;i<row;i++){
		for(j=0;j<col;j++){
			cin>>a[i][j];
		}
	}
	for(i=0;i<row*col;i++){
			cout<<a[y][x]<<endl;
		if(flag==1){
			if(x+1>rightBorder){
				flag=2;
				y++;
				topBorder++;
			}
			else{
			x++;
			}
		}
		else if(flag==2){
			if(y+1>bottomBorder){
				flag=3;
				x--;
				rightBorder--;
			}
			else{
				y++;
			}
		}
			else if(flag==3){
				if(x-1<leftBorder)
				{
					flag=4;
					y--;
					bottomBorder--;
				}
				else{
					x--;
				}
			}
			else{
				if(y-1<topBorder){
					flag=1;
					x++;
					leftBorder++;
				}
				else{
					y--;
				}
			}
		}
	return 0;
}


int main()
{
    int flag = 0;
    int time = 0;
    int i, j, k = 0;
    int row, col;
    int a[100][100];
    cin >> row >> col;
    for (i = 0; i < row; i++)
    {
        for (j = 0; j < col; j++)
        {
            cin >> a[i][j];
        }
    }
    for (k = 0; k <= row * col; )
    {
        for (j = time; j < col - time ;j++)
        {
            cout << a[time][j] << endl;
            k ++;
            if (k == row * col)
            {
                flag = 1;
                break;
            }
        }
        if (flag)
        break;
        for (i = 1 + time; i < row - time; i++)
        {
            cout << a[i][col - 1 - time] << endl;
            k++;
            if (k == row * col)
            {
                flag = 1;
                break;
            }
        }
        if (flag)
        break;
        for (j = col - 2 - time ; j > time; j--)
        {
            cout << a[row - 1 - time][j] << endl;
            k ++;
            if (k == row * col)
            {
                flag = 1;
                break;
            }
        }
        if (flag)
        break;
        for (i = row - 1 - time; i > time;i--)
        {
            cout << a[i][time] << endl;
            k ++;
            if (k == row * col)
            {
                flag = 1;
                break;
            }
        }
        if (flag)
        break;
        time ++;
    }
    return 0;
}


int b[100][100];
void circle ( int array[100][100], int row, int col )
{
	int i;
	for ( i = 0; i < col; i ++ )
		cout << array[0][i] << endl;
	for ( i = 1; i < row; i ++ )
		cout << array[i][col-1] << endl;
	for ( i = col - 2; i >= 0; i -- )
	{
		if ( row > 1 )
			cout << array[row-1][i] << endl;
	}
	for ( i = row - 2; i > 0; i -- )
	{
		if ( col > 1 )
			cout << array[i][0] << endl;
	}
}
void change ( int array[100][100], int row, int col )
{
	int i, j;
	for ( i = 0; i < row - 2; i ++ )
	{
		for ( j = 0; j < col - 2; j ++ )
		{
			b[i][j] = array[i+1][j+1];
		}
	}
}

int main ()
{
	int i, j, row, col, array[100][100], k = 0;
	cin >> row >> col;
	for ( i = 0; i < row; i ++ )
	{
		for ( j = 0; j < col; j ++ )
		{
			cin >> array[i][j];
			b[i][j] = array[i][j];
		}
	}
	if ( row > col )
	{
		for ( k = 0; k < col; k = k + 2 )
		{
			circle( b, row - k, col - k );
			change( b, row - k, col - k );
		}
	}
	else
	{
		for ( k = 0; k < row; k = k + 2 )
		{
			circle( b, row - k, col - k );
			change( b, row - k, col - k );
		}
	}
	return 0;
}


void main()
{
	int a[100][100];
	int i,j,row,col,n=0;
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++)
	{
		scanf("%d",&a[i][0]);
		for(j=1;j<col;j++)
		{
			scanf(" %d",&a[i][j]);
		}
	}
	for(i=0;;i++)
	{
		for(j=i;j<col-i;j++,n++)
			printf("%d\n",a[i][j]);
		if(n==row*col)
			break;
		for(j=i+1;j<row-i;j++,n++)
			printf("%d\n",a[j][col-i-1]);
		if(n==row*col)
			break;
		for(j=col-i-2;j>i;j--,n++)
			printf("%d\n",a[row-i-1][j]);
		if(n==row*col)
			break;
		for(j=row-i-1;j>i;j--,n++)
			printf("%d\n",a[j][i]);
		if(n==row*col)
			break;
	}
}


int shuzu[100][100];

int main (){
	int line,row;
	cin >> line>>row ;
	for(int i=0;i<line;i++)
		for(int j=0;j<row;j++)
			cin >> shuzu[i][j];
/*	if(shuzu[x][y-1]==-1&&shuzu[x][y+1]==-1&&shuzu[x-1][y]==-1&&shuzu[x+1][y]==-1)
		return ;
		*/
	int a,b,sum=0,allg;
	int x=0,y=row-1,i=0,j=line-1;
	while(sum<(allg=row*line))
	{
		for(a=x;a<=y;a++)
		{
		cout <<shuzu[i][a]<<endl;
		sum++;
		if(sum==allg)
			return 0;
		}
	i++;
	for(b=i;b<=j;b++)
		{
		cout <<shuzu[b][y]<<endl;
		sum++;
		if(sum==allg)
			return 0;
		}
	y--;
	for(a=y;a>=x;a--)
		{
		cout <<shuzu[j][a]<<endl;
		sum++;
		if(sum==allg)
			return 0;
		}
	j--;
	for(b=j;b>=i;b--)
		{
		cout << shuzu[b][x]<<endl;
		sum++;
		if(sum==allg)
			return 0;
		}
	x++;
		}
	return 0;
}


void main()
{
	int array[100][100],row,col,n,count=0,i,j,k,*p;
	scanf("%d%d",&row,&col);
	n=row*col;
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
		{
			scanf("%d",&array[i][j]);
		}
	}
	for(k=0;;k++)
	{
		for(p=array[k]+k;p<array[k]+col-k-1;p++)
		{
			printf("%d\n",*p);
			count++;
		}
		if(count==n)
			break;
		for(i=k;i<row-k;i++)
		{
			printf("%d\n",*(*(array+i)+col-k-1));
			count++;
		}
		if(count==n)
			break;
		for(i=col-k-2;i>=k;i--)
		{
			printf("%d\n",*(*(array+row-k-1)+i));
			count++;
		}
		if(count==n)
			break;
		for(i=row-k-2;i>k;i--)
		{
			printf("%d\n",*(*(array+i)+k));
            count++;
		}
		if(count==n)
			break;
	}
}


int main ()
{
	int row, col, a[105][105],i, j, k, min;
	cin >> row >> col;
	for (i = 0; i < row; i ++ )
	{
		for (j = 0; j < col; j ++)
		{
			cin >> a[i][j];
		}
	}
	if (row < col)
		min = row;
	else
		min = col;
	if (min % 2 == 0)
		min = min / 2;
	else
		min = min / 2 + 1;
	for (k = 0; k < min; k ++)
	{
		for (j = k; j < col - k; j ++)
		{
			cout << a[k][j] << endl;
		}
		for (i = k + 1; i < row - k ; i ++)
		{
			cout << a [i][col - k -1] << endl;
		}
		for (j = col - 2 - k; j >= k && (row - k - 1 > k); j --)
		{
			cout << a [row - k - 1][j] << endl;
		}
		for (i = row - 2 - k; i >= 1 + k && (col - k - 1 > k); i -- )
		{
			cout << a [i][k] << endl;
		}
	}
	return 0;
}


int main()
{
    int a[100][100];
    int flag[100][100] = {0};
    int i, j, row, col;
    int count = 0;
    cin >> row >> col;
    for (i = 0; i < row; i++)
     for (j = 0; j < col; j++)
     {
          cin >> a[i][j];
     }
    int hang1 = 0;
    int hang2 = row - 1;
    int lie1 = col - 1;
    int lie2 = 0;
    while (count < row * col)
    {
           for (j = 0; j < col; j++)
           {
                if (flag[hang1][j] == 0)
                {
                    cout << a[hang1][j] << endl;
                    count++;
                    flag[hang1][j] = 1;
                }
           }
           hang1++;
           for (i = 0; i < row; i++)
           {
                if (flag[i][lie1] == 0)
                {
                    cout << a[i][lie1] << endl;
                    count++;
                    flag[i][lie1] = 1;
                }
           }
           lie1--;
           for (j = col - 1; j >= 0; j--)
           {
                if (flag[hang2][j] == 0)
                {
                    cout << a[hang2][j] << endl;
                    count++;
                    flag[hang2][j] = 1;
                }
           }
           hang2--;
           for (i = row - 1; i >= 0; i--)
           {
                if (flag[i][lie2] == 0)
                {
                    cout << a[i][lie2] << endl;
                    count++;
                    flag[i][lie2] = 1;
                }
           }
           lie2++;
    }
    return 0;
}


int main(){
    int row,cow;
    scanf("%d%d",&row,&cow);
    int array[row][cow];
    for(int i=0;i<row;i++){
        for(int k=0;k<cow;k++){
            scanf("%d",&array[i][k]);
        }
    }
    int time=0;
    for(int i=0;i<100;i++){
        for(int m=i;m<cow-i;m++){
            printf("%d\n",array[i][m]);
            time++;
        }
        if(time==row*cow){
            break;
        }
        for(int n=i+1;n<row-i;n++){
            printf("%d\n",array[n][cow-i-1]);
            time++;
        }
        if(time==row*cow){
            break;
        }
        for(int j=cow-2-i;j>=i;j--){
            printf("%d\n",array[row-i-1][j]);
            time++;
        }
        if(time==row*cow){
            break;
        }
        for(int l=row-2-i;l>=i+1;l--){
            printf("%d\n",array[l][i]);
            time++;
        }
        if(time==row*cow){
            break;
        }
    }
  return 0;
}


int main()
{
    int row, col, a[100][100], t = 0, sum, n = 0;
    cin >> row >> col;

    for (int i = 0; i <= row - 1; i++)
    {
        for (int j = 0; j <= col - 1; j++)
        {
            cin >> a[i][j];
        }
    }

    sum = row * col;
    while (1)
    {
        for (int i = n; i < col - n; i++)
        {
            cout << a[n][i] << endl;
            t++;
        }
        if (t == sum) break;
        for (int i = n + 1; i < row - n; i++)
        {
            cout << a[i][col - n - 1] << endl;
t++;
        }
        if (t == sum) break;
        for (int i = col - n - 2; i >= n; i--)
        {
            cout << a[row - n - 1][i] << endl;
            t++;
        }
        if (t == sum) break;
        for (int i = row - n - 2; i > n; i--)
        {
            cout << a[i][n] << endl;
            t++;
        }
        if (t == sum) break;
        n++;
    }
    return 0;
}


int array[100][100];
int main()
{
	int row,col,i,j,k,c,count=0;
	cin>>row>>col;
	for (i=1;i<=row;i++)
		for (j=1;j<=col;j++)
			cin>>array[i][j];
	c=row*col;
	for (k=1,i=1,j=1;k<=c;k++)
	{
		count++;
		cout<<array[i][j]<<endl;
		if (count<col)
			j++;
		else if (count==col||count<col+row-1)
			i++;
		else if (count==col+row-1||count<2*col+row-2)
			j--;
		else if (count==2*col+row-2||count<(col+row)*2-4)
			i--;
		else
		{
			j++;
			row-=2;col-=2;count=0;
		}
	}
	return 0;
}


int sign[100][100]={0},arr[100][100];
void right(int i,int j)
{
	void down(int i,int j);
	printf("%d\n",arr[i][j]);
	sign[i][j]=0;
	if(sign[i][j+1]!=0)
	{
		right(i,j+1);
	}
	else
	{
		if(sign[i+1][j]!=0)
		{
			down(i+1,j);
		}
	}
}
void left(int i,int j)
{
	void up(int i,int j);
	printf("%d\n",arr[i][j]);
	sign[i][j]=0;
	if(sign[i][j-1]!=0&&j>0)
	{
		left(i,j-1);
	}
	else
	{
		if(sign[i-1][j]!=0)
		{
			up(i-1,j);
		}
	}
}
void up(int i,int j)
{
	void right(int i,int j);
	printf("%d\n",arr[i][j]);
	sign[i][j]=0;
	if(sign[i-1][j]!=0&&i>0)
	{
		up(i-1,j);
	}
	else
	{
		if(sign[i][j+1]!=0)
		{
			right(i,j+1);
		}
	}
}
void down(int i,int j)
{
	void left(int i,int j);
	printf("%d\n",arr[i][j]);
	sign[i][j]=0;
	if(sign[i+1][j]!=0)
	{
		down(i+1,j);
	}
	else
	{
		if(sign[i][j-1]!=0)
		{
			left(i,j-1);
		}
	}
}
int main()
{
	void left(int i,int j);
	void right(int i,int j);
	void up(int i,int j);
	void down(int i,int j);
	int row,col,i,j;
	scanf("%d %d",&row,&col);
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
		{
			scanf("%d",&arr[i][j]);
			sign[i][j]=1;
		}
	}
	right(0,0);
	return 0;
}


int main()
{
	int array[100][100]={0};
	int x,y;
	cin>>x>>y;
	for(int i=0;i!=x;i++)
		for(int j=0;j!=y;j++)
			cin>>array[i][j];
	int x1=0,x2=x-1,y1=0,y2=y-1;
	while(x2>=x1&&y2>=y1)
	{
		if(x2==x1&&y2==y1)
			cout<<array[x1][y1]<<endl;
		else if(x2==x1)
		{
			for(int k=y1;k<=y2;k++)
				cout<<array[x1][k]<<endl;
		}
		else if(y1==y2)
		{
			for(int k=x1;k<=x2;k++)
				cout<<array[k][y1]<<endl;
		}
		else
		{
			for(int k=y1;k<y2;k++)
		    	cout<<array[x1][k]<<endl;
		    for(int k=x1;k<x2;k++)
		    	cout<<array[k][y2]<<endl;
		    for(int k=y2;k>y1;k--)
		    	cout<<array[x2][k]<<endl;
		    for(int k=x2;k>x1;k--)
		    	cout<<array[k][y1]<<endl;
		}
	  	x1++;
	   	x2--;
	   	y1++;
    	y2--;

	}
	return 0;
}


int main()
{
	int a[100][100];
	int m,n,i,j;
	int mini,maxi,minj,maxj;
	int time,count=0;;
	scanf("%d %d",&m,&n);
	for (i=0;i<m;i++)
	{
		for (j=0;j<n;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	mini=0;
	maxi=m-1;
	minj=0;
	maxj=n-1;
	for (time=1;count<m*n;time++)
	{
		switch (time%4)
		{
		  case 1:
			  {
				  for (i=mini,j=minj;j<=maxj;j++)
				  {
					  printf("%d\n",a[i][j]);
					  count++;
				  }
				  mini++;
				  break;
			  }
		  case 2:
			  {
				  for (j=maxj,i=mini;i<=maxi;i++)
				  {
					  printf("%d\n",a[i][j]);
					  count++;
				  }
				  maxj--;
				  break;
			  }
		  case 3:
			  {
				  for (i=maxi,j=maxj;j>=minj;j--)
				  {
					  printf("%d\n",a[i][j]);
					  count++;
				  }
				  maxi--;
				  break;
			  }
		  case 0:
			  {
				  for (j=minj,i=maxi;i>=mini;i--)
				  {
					  printf("%d\n",a[i][j]);
					  count++;
				  }
				  minj++;
				  break;
			  }
		}
	}
	return 0;
}


int A[100][100]={0};
void shuchu1(int a,int b,int c,int d)//a<b&&c<d
{
	for(int i=c;i<=d;i++)
	{
		cout<<A[a][i]<<endl;
	}
	for(int i=a+1;i<=b;i++)
	{
		cout<<A[i][d]<<endl;
	}
	for(int i=d-1;i>=c;i--)
	{
		cout<<A[b][i]<<endl;
	}
	for(int i=b-1;i>=a+1;i--)
	{
		cout<<A[i][c]<<endl;
	}
}
void shuchu2(int a,int b,int c,int d)//a==b&&c<d
{
	for(int i=c;i<=d;i++)
	{
		cout<<A[a][i]<<endl;
	}

}
void shuchu3(int a,int b,int c,int d)//c==d&&a<b
{
	for(int i=c;i<=d;i++)
	{
		cout<<A[a][i]<<endl;
	}
	for(int i=a+1;i<=b;i++)
	{
		cout<<A[i][d]<<endl;
	}

}
void shuchu4(int a,int b,int c,int d)//a==b&&c==d
{
	cout<<A[a][c]<<endl;
}
int main()
{

	int row,col;
	cin>>row>>col;
	for(int i=0;i<row;i++)//?????????
	{
		for(int j=0;j<col;j++)
		{
			cin>>A[i][j];
		}
	}
	int a=0;
	int c=0;
	int b=row-1;
	int d=col-1;
	while(b>=a&&d>=c)
	{
		if(a<b&&c<d)
		{
			shuchu1(a,b,c,d);
		}
		if(a==b&&c<d)
		{
			shuchu2(a,b,c,d);
		}
		if(c==d&&a<b)
		{
			shuchu3(a,b,c,d);
		}
		if(a==b&&c==d)
		{
			shuchu4(a,b,c,d);
		}
		a++;b--;c++;d--;
	}

	return 0;//????

}


int main()
{
	int n,m,a[1000][1000],i,j,s,q=0;
	cin>>n>>m;
	for(i=0;i<n;i++)
		for(j=0;j<m;j++)
			cin>>a[i][j];
	int flag=0;
	for(i=0;;i++)
	{
		for(j=q;j<m-q;j++)
		{
			flag++;
			cout<<endl<<a[i][j];
		}
		if(flag==n*m)
			break;
		j--;
		for(s=i+1;s<n-q;s++)
		{
			flag++;
			cout<<endl<<a[s][j];
		}
		if(flag==n*m)
			break;
		s--;
		for(j=j-1;j>=q;j--)
		{
			flag++;
			cout<<endl<<a[s][j];
		}
		if(flag==n*m)
			break;
		j++;
		for(s=s-1;s>q;s--)
		{
			flag++;
			cout<<endl<<a[s][j];
		}
		if(flag==n*m)
			break;
		q++;
	}
	return 0;
}


int main()
{
	int a, b, n = 1;
	cin >> a >> b;
	int c[101][101];
	for (int i = 1; i <= a; i++)
	for (int j = 1; j <= b; j++)
	cin >> c[i][j];
	while (2 * n <= a && 2 * n <= b)
	{
		for (int i = n; i <= b - n; i++)
		cout << c[n][i] << endl;
		for (int i = n; i <= a - n; i++)
		cout << c[i][b-n+1] << endl;
		for (int i = b - n + 1; i > n; i--)
		cout << c[a-n+1][i] << endl;
		for (int i = a - n+1; i > n; i--)
		cout << c[i][n] << endl;
		n++;
	}
	for (int i = n; i <= b + 1 - n; i++)
	for (int j = n; j <= a + 1 - n; j++)
	cout << c[j][i] << endl;
	return 0;
}


int main()
{
    int array[100][100],col,row,cs=0,i,j,x=0;
    scanf("%d%d",&row,&col);

    for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
            scanf("%d",&array[i][j]);
    }

    do{
        for(i=cs;i<cs+col-1;i++)
            printf("%d\n",array[cs][i]);

        for(i=cs;i<cs+row-1;i++)
            printf("%d\n",array[i][cs+col-1]);

        if(i!=cs){
        for(i=cs;i<cs+col-1;i++)
            printf("%d\n",array[cs+row-1][2*cs+col-i-1]);
        }else
        {
            printf("%d\n",array[cs+row-1][cs+col-1]);
            x=1;
        }

        if(i!=cs){
        for(i=cs;i<cs+row-1;i++)
            printf("%d\n",array[2*cs+row-i-1][cs]);
        }else if(x==0)
            printf("%d\n",array[cs+row-1][cs]);

        cs++;
        col-=2;
        row-=2;

    } while(col>0&&row>0);

    return 0;
}


int main()
{
	/* Read data */
	int col, row, a[100][100];
	cin >> row >> col;
	for(int i=0; i<row; ++i)
		for(int j=0; j<col; ++j)
			cin >> a[i][j];
	/* Const direction */
	const int dir[4][2] = {{0,1},{1,0},{0,-1},{-1,0}};
	/* Parameter Initialization */
	/* State records current direction index, step records step size for 4 directions, curstep is current step size, pos records current position */
	int state=0, step[4] = {col, row-1, col-1, row-2}, curstep=step[state], pos[2] = {0,0}, flag=1;
	/* Main Solver */
	while(curstep > 0)
	{
		for(int i=0+flag; i<curstep; ++i)
		{
			cout << a[pos[0]][pos[1]] << endl;
			pos[0] += dir[state][0];
			pos[1] += dir[state][1];
		}
		step[state] = step[state]-2;
		state = (state+1)%4;
		curstep = step[state];
		flag = 0;
	}
	cout << a[pos[0]][pos[1]] << endl;
	return 0;
}


int main()
{
	int input[100][100],i,j,k,m,n,output[10000],a=0;
	int row,col;
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
			scanf("%d",&input[i][j]);
	}
	for(i=0;i<row;i++)
	{
		for(j=i;j<col-i;j++)
		{
			output[a++]=input[i][j];
		}
		for(k=i+1;k<row-i;k++)
		{
			output[a++]=input[k][j-1];
		}
		for(m=j-2;m>=i;m--)
		{
			output[a++]=input[k-1][m];
		}
		for(n=k-2;n>i;n--)
		{
			output[a++]=input[n][m+1];
		}
		if(i==k)
		{
			break;
		}
	}
	for(i=0;i<row*col-1;i++)
		printf("%d\n",output[i]);
	printf("%d",output[row*col-1]);
	return 0;
}


int main()
{
   int row;
   int col;
   int i,j,k;
   int t=0;
   int a[200][200];
   scanf("%d%d",&row,&col);
   for(i=0;i<row;i++)
   {
	   for(j=0;j<col;j++)
	   {
		   scanf("%d",&a[i][j]);
	   }
   }
   for(i=0;i<row;i++)
   {
	   for(j=i;j<col-i;j++)
	   {
		  t++;
		  if(t==row*col){
			  printf("%d",a[i][j]);
	return 0;}
		  else {printf("%d\n",a[i][j]);}

	   }
	   j=col-i-1;
	   for(k=i+1;k<row-i;k++)
	   {
		 t++;
		  if(t==row*col){
			  printf("%d",a[k][j]);
	return 0;}
		  else {printf("%d\n",a[k][j]);}

	   }
	   k=row-i-1;
	   for(j=col-i-2;j>=i;j--)
	   {
		  t++;
		  if(t==row*col){
			  printf("%d",a[k][j]);
	return 0;}
		  else {printf("%d\n",a[k][j]);}

	   }
	   j=i;
	   for(k=row-i-2;k>i;k--)
	   {
		   t++;
		  if(t==row*col){
			  printf("%d",a[k][j]);
	return 0;}
		  else {printf("%d\n",a[k][j]);}

	   }
   }

	return 0;

}


int main()
{
    int array[100][100],row,col,i,j,k,a,b,c,d;
    scanf("%d %d",&row,&col);
    for (i=0;i<row;i++)
    {
        for (j=0;j<col;j++)
        {
            scanf("%d",&(array[i][j]));
        }
    }
    for (k=0;k<row;k++)
    {
        if (row-1-k-k==1&&col-1-k-k==1)
        {
            printf("%d\n%d\n%d\n%d\n",array[k][k],array[k][k+1],array[k+1][k+1],array[k+1][k]);
        break;
        }
        if (row-1-k-k==0&&col-1-k-k==0)
        {
            printf("%d",array[k][k]);
            break;
        }
        if (row-1-k-k==1&&col-1-k-k==0)
        {
            printf("%d\n%d\n",array[k][k],array[k+1][k]);
            break;
        }

        if (row-1-k-k==1&&col-1-k-k!=1)
        {
            for (i=k,j=k;j<col-1-k;j++)
            {
                printf("%d\n",array[i][j]);
            }
            for (i=k,j=col-1-k;i<row-1-k;i++)
            {
                printf("%d\n",array[i][j]);
            }
            for (i=row-1-k,j=col-1-k;j>k;j--)
            {
                printf("%d\n",array[i][j]);
            }
            break;
        }
        if (row-1-k-k==0)
        {
            for (i=k,j=k;j<=col-1-k;j++)
            {
                printf("%d\n",array[i][j]);
            }
            break;
        }
        if (col-1-k-k==1)
        {
            for (i=k,j=k;j<col-1-k;j++)
            {
                printf("%d\n",array[i][j]);
            }
            for (i=k,j=col-1-k;i<row-1-k;i++)
            {
                printf("%d\n",array[i][j]);
            }
            for (i=row-1-k,j=col-1-k;j>k;j--)
            {
                printf("%d\n",array[i][j]);
            }
            for (i=row-1-k,j=k;i>k;i--)
            {
                printf("%d\n",array[i][j]);
             }
             break;
        }
        if (col-1-k-k==0)
        {
            for (i=k,j=col-1-k;i<=row-1-k;i++)
            {
                printf("%d\n",array[i][j]);
            }
            break;
        }
        for (i=k,j=k;j<col-1-k;j++)
        {
            printf("%d\n",array[i][j]);
        }
        for (i=k,j=col-1-k;i<row-1-k;i++)
        {
            printf("%d\n",array[i][j]);
        }
        for (i=row-1-k,j=col-1-k;j>k;j--)
        {
            printf("%d\n",array[i][j]);
        }
        for (i=row-1-k,j=k;i>k;i--)
        {
            printf("%d\n",array[i][j]);
        }
     }
     return 0;
}


/* title:???????? *
 * author:???*
 * time:2011.10.28*/

int main()
{
	int array[100][100];
	int row, col, i, j, k, h, m = 0, r1, r2, n = 0;
	cin >> row >> col;
	r1 = row;
	r2 = col;
	for(i = 0; i < row; i++)
		for(j = 0; j < col; j++)
		{
			cin >> array[i][j];
		}
	for(m = 0; m <= r2 / 2 && m <= r1 / 2; m++)
	{
		for(j = m; j < col; j++)
		{
			n++;
			if(n > r1 * r2)
				break;
			cout << array[m][j] << endl;
		}
		for(i = m + 1; i < row; i++)
		{
			n++;
			if(n > r1 * r2)
				break;
			cout << array[i][col - 1] << endl;
		}
		for(k = col - 2; k >= m; k--)
		{
			n++;
			if(n > r1 * r2)
				break;
			cout << array[row - 1][k] << endl;
		}
		for(h = row - 2; h > m; h--)
		{
			n++;
			if(n > r1 * r2)
				break;
			cout << array[h][m] << endl;
		}
		row = row - 1;
		col = col - 1;
	}
	return 0;
}


int main()
{
  int row,col,i,j,u[100][100],a,sum=0;
  scanf("%d%d",&row,&col);
  for(i=0;i<row;i++)
   {
      for(j=0;j<col;j++)
      {
         scanf("%d",&u[i][j]);
       }
   }
  for(a=0;a<row/2+1;a++)
  {
      for(i=a,j=a;j<col-a;j++)
      {
        printf("%d\n",u[i][j]);
        sum++;
        if(sum==row*col)
             break;
      }
      if(sum==row*col)
             break;
      for(j=col-a-1,i=a+1;i<row-a;i++)
      {
        printf("%d\n",u[i][j]);
        sum++;
        if(sum==row*col)
             break;
       }
       if(sum==row*col)
             break;

      for(i=row-a-1,j=col-a-2;j>=a;j--)
        {
        printf("%d\n",u[i][j]);
        sum++;
       if(sum==row*col)
             break;
       }
       if(sum==row*col)
             break;
      for(j=a,i=row-a-2;i>a;i--)
        {
        printf("%d\n",u[i][j]);
        sum++;
       if(sum==row*col)
             break;
       }
	   if(sum==row*col)
             break;
  }

  return 0;
}


int main(){
	int h,l,i,k,n,hsx,hxx=0,lsx,lxx=0;
	int shu[100][100];
	scanf("%d%d",&h,&l);
	for(i=0;i<h;i++){
		for(k=0;k<l;k++){
			scanf("%d",&(shu[i][k]));
		}
	}
	hsx=h-1;
	lsx=l-1;
	for(n=0;(hsx>hxx)&&(lsx>lxx);n++){
		for(k=lxx;k<lsx;k++){
			printf("%d\n",shu[hxx][k]);
		}
		for(i=hxx;i<hsx;i++){
			printf("%d\n",shu[i][lsx]);
		}
		for(k=lsx;k>lxx;k--){
			printf("%d\n",shu[hsx][k]);
		}
		for(i=hsx;i>hxx;i--){
			printf("%d\n",shu[i][lxx]);
		}
		hsx--;
		hxx++;
		lsx--;
		lxx++;
	}
	    if((hxx==hsx)&&(lsx>lxx)){
			for(k=lxx;k<=lsx;k++){
				printf("%d\n",shu[hxx][k]);
			}
		}
		else if((lxx==lsx)&&(hsx>hxx)){
			for(i=hxx;i<=hsx;i++){
				printf("%d\n",shu[i][lxx]);
			}
		}
		else if((hsx==hxx)&&(lsx==lxx)){
			printf("%d",shu[hxx][lxx]);
		}

	return 0;
}


int main(){
	int i,j,n,all,row,col,sum;
	int sz[200][200];
	sum=0;
	scanf("%d%d",&row,&col);
	all=row*col;
	for(i=0;i<row;i++){
		for(j=0;j<col;j++){
			scanf("%d",&sz[i][j]);
		}
	}
	for(n=0;;n++){
		for(i=n;i<(col-n);i++)
		{
			printf("%d\n",sz[n][i]);
			sum=sum+1;

		}
		if(sum==all) break;
		for(j=n+1;j<(row-n);j++)
		{
			printf("%d\n",sz[j][col-n-1]);
			sum=sum+1;

		}
		if(sum==all) break;
		for(i=col-2-n;i>=n;i--)
		{
			printf("%d\n",sz[row-n-1][i]);
			sum=sum+1;

		}
		if(sum==all) break;
		for(j=(row-2-n);j>n;j--)
		{
			printf("%d\n",sz[j][n]);
			sum=sum+1;
		}
		if(sum==all) break;
	}

	return 0;
}


int main()
{
	int row , col ;
	cin >> row >> col ;
	int a[row][col] ;
	for( int i = 0 ; i < row ; i ++ )
		for( int j = 0 ; j < col ; j ++ )
			cin >> a[i][j] ;
	int minrow = 0 , maxrow = row - 1 ,
			mincol = 0 , maxcol = col - 1 , n = 0 , i = 0 , j = 0 , count = 0 ;
	for( ; n > -1 ; n ++ )
	 {
	/*for( ; minrow <= i && i <= maxrow && mincol <= j && j <= maxcol ;
			n % 2 == 0 ? n % 4 == 0 ? j ++ : j -- : n % 4 == 1 ? i ++ : i -- )
		cout << a[i][j] << endl ;*/
		if( n % 2 == 0 )
	{
		if( n % 4 == 0 ) {
			for( ; j <= maxcol ; j ++ )
			{
				cout << a[i][j] << "\n"  ;
				count ++ ;
			}
			minrow ++ ; j -- ; i ++ ; }
		else {
			for( ; j >= mincol ; j -- )
			{
				cout << a[i][j] << "\n" ;
				count ++ ;
			}
			maxrow -- ; j ++ ; i -- ; }
	}
	else
	{
		if( n % 4 == 1 ){
			for( ; i <= maxrow ; i ++ )
			{
				cout << a[i][j] << "\n" ;
				count ++ ;
			}
			maxcol -- ; i -- ; j -- ; }
		else {
			for( ; i >= minrow ; i -- )
			{
				cout << a[i][j] << "\n" ;
				count ++ ;
			}
			mincol ++ ; i ++ ; j ++ ;}
	}
    if( count == row * col ) break ;
	}
	return 0 ;
}


int main()
{
int row,col;
cin>>row>>col;
int shuzu[100][100];
int p=0,q=0,count=0;
for(p=0;p<row;p++)
	for(q=0;q<col;q++){cin>>shuzu[p][q];}
for(;row-count>0&&col-count>0;)
{
p=count;for(q=count;q<col;q++){cout<<shuzu[p][q]<<endl;}
if(row==count+1)return 0;
q=col-1;for(p=count+1;p<row;p++){cout<<shuzu[p][q]<<endl;}
if(col==1+count)return 0;
p=row-1;for(q=col-2;q>=count;q--){cout<<shuzu[p][q]<<endl;}
q=count;for(p=row-2;p>count;p--){cout<<shuzu[p][q]<<endl;}
row--;col--;count++;
}
return 0;
}


int main()
{
	int ROW,COL;
	int array[100][100];
	scanf("%d%d",&ROW,&COL);
	for(int row=0;row<ROW;row++)
	{
		for(int col=0;col<COL;col++)
		{
			scanf("%d",&array[row][col]);
		}
	}
	//????
    int sx_row=0,xx_row=ROW-1,sx_col=0,xx_col=COL-1;

    while((xx_row>sx_row)&&(xx_col>sx_col))

	{
		for(int i1=sx_row,j1=sx_col;j1<xx_col;j1++)
		{

			printf("%d\n",array[i1][j1]);
		}
	    for(int j2=xx_col,i2=sx_row;i2<xx_row;i2++)
		{

			printf("%d\n",array[i2][j2]);
		}
	    for(int i3=xx_row,j3=xx_col;j3>sx_col;j3--)
		{

		    printf("%d\n",array[i3][j3]);
		}
	    for(int i4=xx_row,j4=sx_col;i4>sx_row;i4--)
		{

			printf("%d\n",array[i4][j4]);
		}
	    sx_row++;
	    sx_col++;
	    xx_row--;
	    xx_col--;
	}
	if((sx_row==xx_row)&&(sx_col!=xx_col))
	{
        for(int i=sx_col;i<=xx_col;i++)
		{
			printf("%d\n",array[sx_row][i]);
		}
	}
	else if(sx_col==xx_col)
	{
		for(int j=sx_row;j<=xx_row;j++)
		{
			printf("%d\n",array[j][sx_col]);
		}
	}
	return 0;
}


int main()
{
    int row,col,n;
    cin >> row >> col;
    n=row*col;
    int array[row][col];
    int i,j;
    for (i=1;i<=row;i++)
    {
        for (j=1;j<=col;j++)
        {
            int a;
            cin >> a;
            array[i-1][j-1]=a;
        }
    }
    int mini=0,minj=0,k;
    for (k=1;k<=n;)
    {
        if (j!=col)
        {             j=minj;
                      while (j<col)
                      {
                            cout << array[mini][j] << endl;
                            k++;
                            j++;
                      }
        }
        mini++;
        if (k>n)
        {
                break;
        }
        if (j==col)
        {
                   i=mini;
                   while (i<row)
                   {
                         cout << array[i][col-1] << endl;
                         k++;
                         i++;
                   }
        }
        col--;
        if (k>n)
        {
                break;
        }
        if (i==row)
        {
                   j=col-1;
                   while (j>=minj)
                   {
                         cout << array[row-1][j] << endl;
                         k++;
                         j--;
                   }
        }
        row--;
        if (k>n)
        {
                break;
        }
        if (j<minj)
        {
                   i=row-1;
                   while (i>=mini)
                   {
                         cout << array[i][minj] << endl;
                         k++;
                         i--;
                   }
        }
        minj++;
        if (k>n)
        {
                break;
        }
    }

    return 0;
}


int main ()
{
	int a[100][100]={0},cnt=0,i,j,row,col,l=0;
	cin >> row>>col ;
	cnt = row * col ;
	for(i = 0 ;i < row;i++)
	{
		for(j = 0 ; j <col ;j++)
			cin >> a[i][j] ;
	}
	while(cnt > 0)
	{
		for(j=l;j<(col-l);j++)
		{
			cout << a[l][j]<<endl;
			cnt--;
		}
		if(cnt == 0) break ;
		for (i=(l+1);i<row-l;i++)
		{
			cout << a[i][col-l-1]<<endl;
			cnt--;
		}
		if(cnt == 0) break ;
		for(j=col-l-2;j>l-1;j--)
		{
			cout << a[row-l-1][j]<<endl;
			cnt-- ;
		}
		if(cnt == 0) break ;
		for(i=row-l-2;i>l;i--)
		{
			cout << a[i][l]<<endl;
			cnt--;
		}
		l++ ;
	}
	return 0 ;
}


int main()
{
	int i,j,m,n,a[100][100];
	int shang,xia,zuo,you;
	scanf("%d %d",&m,&n);

	for(i=0;i<m;i++){
		for(j=0;j<n;j++){
			scanf("%d",&a[i][j]);
		}
	}
		shang=0;
		zuo=0;
		xia=m-1;
		you=n-1;
	while(zuo<=you&&(shang<=xia)){
		if(zuo!=you&&shang!=xia){

			for(i=shang,j=zuo;j<=you;j++){
				printf("%d\n",a[i][j]);
			}
			for(j=you,i=shang+1;i<=xia;i++){
				printf("%d\n",a[i][j]);
			}
			for(i=xia,j=you-1;j>=zuo;j--){
				printf("%d\n",a[i][j]);
			}
			for(i=xia-1,j=zuo;i>shang;i--){
				printf("%d\n",a[i][j]);
			}
		}
		else if(zuo==you&&shang!=xia){
			for(j=zuo,i=shang;i<=xia;i++){
				printf("%d\n",a[i][j]);
			}
		}
		else if(shang==xia&&zuo!=you){
			for(i=shang,j=zuo;j<=you;j++){
				printf("%d\n",a[i][j]);
			}
		}
		else if(shang==xia&&zuo==you){
			i=shang;j=zuo;
			printf("%d\n",a[i][j]);
		}
		zuo++,shang++,you--,xia--;

	}

	return 0;
}


int main()
{
	int hangshu, lieshu, array[101][101], i, j;
	cin >> hangshu >> lieshu;
	for (i = 0; i < hangshu; i++)
		for (j = 0; j < lieshu; j++)
			cin >> array[i][j];
	int count = 0;
	int total = hangshu * lieshu;
	lieshu--; hangshu--;
	for (i = 0; i <= hangshu; i++)
	{
		for (j = i; j <= lieshu - i; j++)
		{
			cout << array[i][j] << endl;
			count++;
		}
		if (count == total)
			break;
		for (j = i + 1; j <= hangshu - i; j++)
		{
			cout << array[j][lieshu - i] << endl;
			count++;
		}
		if (count == total)
			break;
		for (j = lieshu - i - 1; j >= i; j--)
		{
			cout << array[hangshu - i][j] << endl;
			count++;
		}
		if (count == total)
			break;
		for (j = hangshu - i - 1; j >= i + 1; j--)
		{
			cout << array[j][i] << endl;
			count++;
		}
		if (count == total)
			break;
	}
	return 0;
}


int main(int argc, char *argv[])
{int array[100][100];
int row,col,i,j,rowmin,rowmax,colmin,colmax;
scanf("%d%d",&row,&col);
for(i=0;i<row;i++)
for(j=0;j<col;j++)
scanf("%d",&array[i][j]);
rowmin=0;
rowmax=row-1;
colmin=0;
colmax=col-1;
while(colmin<colmax&&rowmin<rowmax){
for(i=colmin;i<colmax;i++)
printf("%d\n",array[rowmin][i]);
for(i=rowmin;i<rowmax;i++)
printf("%d\n",array[i][colmax]);
for(i=colmax;i>colmin;i--)
printf("%d\n",array[rowmax][i]);
for(i=rowmax;i>rowmin;i--)
printf("%d\n",array[i][colmin]);
rowmin++;
rowmax--;
colmin++;
colmax--;}
if(rowmin==rowmax&&colmin<colmax)
{for(i=colmin;i<=colmax;i++)
printf("%d\n",array[rowmin][i]);}
else if(rowmin<rowmax&&colmin==colmax)
{for(i=rowmin;i<=rowmax;i++)
printf("%d\n",array[i][colmin]);
     }
else if(rowmin==rowmax&&colmin==colmax)
printf("%d\n",array[rowmin][colmax]);

  return 0;
}


int sum(int a,int b,int c){
	int d=0,e;
	for(e=1;e<=c;e++){
		d=a+a+b+b-4*(2*e-1)+d;
	}
  return d;
}

int min(int a,int b,int c,int d){
	if(a<b)
	  b=a;
	if(b<c)
	  c=b;
	if(c<d)
	  d=c;

  return d;
}

int main(){
	int a[100][100],s[10000];
	int row,col,i,j,b,c,d,e;
	int f,g,h;
    scanf("%d%d",&row,&col);
	for(i=1;i<=row;i++){
		for(j=1;j<=col;j++){
			scanf("%d",&a[i][j]);
			b=col-j;
			c=row-i;
			d=min(i-1,j-1,b,c);
			e=sum(row,col,d);
			f=i-d;
			g=j-d;
            if(f==1&&g>=1)
				h=e+g;
			else if(g==(col-2*d)&&f<=(row-2*d))
				h=e+f+g-1;
			else
				h=e+row+col-1-4*d+col-2*d-g+row-2*d-f;

			s[h]=a[i][j];
		}
	}

	for(i=1;i<=row*col;i++)
		printf("%d\n",s[i]);

return 0;
}


int main() {
	int row,col;
	int sz[100][100];
	scanf("%d %d",&row,&col);
	for(int i=0;i<row;i++){
		for(int j=0;j<col;j++){
			scanf("%d",&sz[i][j]);
		}
	}
	int xx_row=0;
	int sx_row=row-1;
	int xx_col=0;
	int sx_col=col-1;
	while((xx_row<sx_row)&&(xx_col<sx_col)){
		for(int i=xx_col;i<sx_col;i++){
			printf("%d\n",sz[xx_row][i]);
		}
		for(int j=xx_row;j<sx_row;j++){
			printf("%d\n",sz[j][sx_col]);
		}
		for(int k=sx_col;k>xx_col;k--){
			printf("%d\n",sz[sx_row][k]);
		}
		for(int p=sx_row;p>xx_row;p--){
			printf("%d\n",sz[p][xx_col]);
		}
		xx_row++;
		sx_row--;
		xx_col++;
		sx_col--;
	}
	if(xx_row==sx_row){
		if(xx_col!=sx_col){
		     for(int i=xx_col;i<=sx_col;i++){
			     printf("%d\n",sz[xx_row][i]);
			 }
		}
	}
	if(xx_col==sx_col){
		for(int j=xx_row;j<=sx_row;j++){
			printf("%d\n",sz[j][xx_col]);
		}
	}
	return 0;
}


int main()
{
	int i,j,det[100][100],ROW,COL,row1,row2,col1,col2,count=0;
	scanf("%d%d",&ROW,&COL);
	for(j=0;j<ROW;j++){
		for(i=0;i<COL;i++){
			scanf("%d",&det[j][i]);
		}
	}
	row1=0;
	row2=ROW-1;
	col1=0;
	col2=COL-1;
	while(row2>=row1&&col2>=col1){
		for(i=col1;i<=col2;i++){
			printf("%d\n",det[row1][i]);
			count++;
		} //verforward

		if(count==ROW*COL){
			break;
		}
		for(j=(row1+1);j<=row2;j++){
			printf("%d\n",det[j][col2]);
			count++;
		} //hordown

		if(count==ROW*COL){
			break;
		}
		for(i=col2-1;i>=col1;i--){
			printf("%d\n",det[row2][i]);
			count++;
		} //verbackward

		if(count==ROW*COL){
			break;
		}
		for(j=(row2-1);j>=(row1+1);j--){
			printf("%d\n",det[j][col1]);
			count++;
		} //horup

		col1++;
		col2--;
		row1++;
		row2--;
	}
	return 0;
}


int main()
{int row,col;
int i,j;
cin>>row>>col;
int a[101][101];
for(i=0;i<row;i++)
{
 for(j=0;j<col;j++)
 {
  cin>>a[i][j];
 }
}
int x;
for(x=0;x<=row&&x<=col;x++)
{
	i=x;
	if(x<=col-1-x)
	{
	for(j=x;j<=col-1-x;j++)
	{
		cout<<a[i][j]<<endl;
	}
	}
	else {break;}
	j=j-1;
	if(x+1<=row-1-x)
	{
		for(i=x+1;i<=row-1-x;i++)
		{
			cout<<a[i][j]<<endl;
		}
	}
	else {break;}
	i=row-1-x;
	if(x<=col-2-x)
	{
	for(j=col-2-x;j>=x;j--)
	{
		cout<<a[i][j]<<endl;
	}
	}
	else {break;}
	j=x;
	if(x+1<=row-2-x)
	{
		for(i=row-2-x;i>=x+1;i--)
		{
			cout<<a[i][j]<<endl;
		}
	}
	else {break;}
}
return 0;
}


int main()
{
	int a[100][100],row ,col;
	cin>>row>>col;
	for(int i=0;i<row;i++)             //????
		for(int j=0;j<col;j++)
			cin>>a[i][j];
	int flag=0;       //??
	for(int i=0;;i++)
	{
		for(int j=i;j<=col-i-1;j++)       //??
		{
			cout<<a[i][j]<<endl;
			flag+=1;
		}
		if(flag==row*col)
				break;
		for(int j=i+1;j<=row-i-1;j++)      //??
		{
			cout<<a[j][col-i-1]<<endl;
			flag+=1;
		}
		if(flag==row*col)
				break;
		for(int j=col-i-2;j>=i+1;j--)        //??
		{
			cout<<a[row-i-1][j]<<endl;
			flag+=1;
		}
		if(flag==row*col)
				break;
		for(int j=row-i-1;j>=i+1;j--)          //??
		{
			cout<<a[j][i]<<endl;
			flag+=1;
		}
		if(flag==row*col)
				break;
	}
	return 0;
}


void main()
{
	int a[100][100];
	int row,col,i,j;
	scanf("%d %d",&row,&col);
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			scanf("%d",&a[i][j]);
	int s_row=0,s_col=0,e_row=row-1,e_col=col-1;
	while(1)
	{
		if (s_row>e_row)
			break;
		for (i=s_col;i<=e_col;i++)
			printf("%d\n",a[s_row][i]);
		s_row++;
		if (s_col>e_col)
			break;
		for (i=s_row;i<=e_row;i++)
			printf("%d\n",a[i][e_col]);
		e_col--;
		if (s_row>e_row)
			break;
		for (i=e_col;i>=s_col;i--)
			printf("%d\n",a[e_row][i]);
		e_row--;
		if (s_col>e_col)
			break;
		for (i=e_row;i>=s_row;i--)
			printf("%d\n",a[i][s_col]);
		s_col++;
	}
}


int main()
{
	int array[101][101],row,col;
	int i=0,j=0,sum=0;
	cin>>row>>col;
	for(i=0;i<row;i++){
		for(j=0;j<col;j++){
		cin>>array[i][j];
		}}//????
	int n=0;
	for(n=0;;n++){
		for(j=n;j<=col-n-1;j++){
			cout<<array[n][j]<<endl;
			sum++;//???
		}
		if(sum==row*col)break;
		for(i=n+1;i<=row-1-n;i++){
		cout<<array[i][col-n-1]<<endl;
		sum++;
		}//???
	    if(sum==row*col)break;
		for(j=col-n-2;j>=n;j--){
		cout<<array[row-1-n][j]<<endl;
		sum++;
		}//???
			if(sum==row*col)break;
			for(i=row-2-n;i>=n+1;i--){
			cout<<array[i][n]<<endl;
			sum++;
			}//???
				if(sum==row*col)break;
	}
	return 0;
}


int main(){
	int sz[100][100],row,col;
	scanf("%d %d",&row,&col);
	for(int i=0;i<row;i++){
		for(int j=0;j<col;j++){
			scanf("%d",&sz[i][j]);
		}
	}
	int xx_row=0,sx_row=row-1;
	int xx_col=0,sx_col=col-1;
	int k,n;
	while(xx_row<sx_row&&xx_col<sx_col){
    	for(k=xx_col;k<=sx_col-1;k++){
	    	printf("%d\n",sz[xx_row][k]);
		}
		for(n=xx_row;n<=sx_row-1;n++){
		    printf("%d\n",sz[n][sx_col]);
		}
        for(k=sx_col;k>=xx_col+1;k--){
	    	printf("%d\n",sz[sx_row][k]);
		}
		for(n=sx_row;n>=xx_row+1;n--){
	    	printf("%d\n",sz[n][xx_col]);
		}
	xx_col++;
	sx_col--;
	xx_row++;
	sx_row--;
	}
	if(sx_row==xx_row){
		for(k=xx_col;k<=sx_col;k++){
			printf("%d\n",sz[sx_row][k]);
		}
	}else
		if(xx_row==sx_col){
			for(n=xx_row;n<=sx_row;n++){
				printf("%d\n",sz[n][sx_col]);
			}
		}
		return 0;
}


int main()
{
	int row,col,x,y,a[100][100],flag=0,i,k;
	scanf("%d%d",&row,&col);
	for(x=0;x<row;x++){
		for(y=0;y<col;y++){
			scanf("%d",&a[x][y]);}
	}
	k=(row>col)?col:row;
    for(i=0;i<k;i++){
		for(y=i;y<col-i;y++){
			printf("%d\n",a[i][y]);
			flag++;}
          if(flag==row*col)
			  break;
		for(x=i+1;x<row-i;x++){
			printf("%d\n",a[x][col-1-i]);
	    	flag++;}
		if(flag==row*col)
			  break;
		for(y=col-2-i;y>=i;y--){
			printf("%d\n",a[row-1-i][y]);
	    	flag++;}
		if(flag==row*col)
			  break;
		for(x=row-2-i;x>i;x--){
			printf("%d\n",a[x][i]);
	    	flag++;}
		if(flag==row*col)
			  break;
	}
	return 0;
}


int main()
{
	int a[100][100], row, col;
	cin >> row >> col;
	for (int i = 0; i < row; i++)
		for (int j = 0; j < col; j++)
			cin >> a[i][j];
	int r = 0, c = 0, num = 0, n = row * col, row0 = 0, col0 = 0;
	while (true)
	{
		for (; c < col; c++)
		{
			cout << a[r][c] <<endl;
			num++;
		}
		if (num == n)
			break;
		row0++;
		c--;
		r++;
		for (; r < row; r++)
		{
			cout << a[r][c] << endl;
			num++;
		}
		if (num == n)
			break;
		col--;
		r--;
		c--;
		for (; c >= col0; c--)
		{
			cout << a[r][c] << endl;
			num++;
		}
		if (num == n)
			break;
		row--;
		c++;
		r--;
		for (; r >= row0; r--)
		{
			cout << a[r][c] << endl;
			num++;
		}
		if (num == n)
			break;
		col0++;
		r++;
		c++;
	}
	cin >> row;
	return 0;
}


int row,col,array[MAXN][MAXN],sign[MAXN][MAXN];

int main(){
	memset(array,0,sizeof(array));
	memset(sign,0,sizeof(sign));
	cin>>row>>col;
	for(int i=0;i<row;i++){
		for(int j=0;j<col;j++) cin>>array[i][j];
	}
	int num=0,sxy=0,cxy=0,mrow=0,mcol=0;;//0==x,1==y;0==left->right/down;1==right/up
	while(num<row*col){
		if(sxy==0){
			while(mcol<col&&mcol>=0){
				if(sign[mrow][mcol]==0)	{
					cout<<array[mrow][mcol]<<endl;
					num++;
				}
				sign[mrow][mcol]=1;
				if(cxy==0){
					if(mcol+1<col&&sign[mrow][mcol+1]==0) mcol++;
					else break;
				}
				else{
					if(mcol-1>=0&&sign[mrow][mcol-1]==0) mcol--;
					else break;
				}
			}
			sxy=1;
		}
		else{
			while(mrow<row&&mrow>=0){
				if(sign[mrow][mcol]==0){
					cout<<array[mrow][mcol]<<endl;
					num++;
				}
				sign[mrow][mcol]=1;
				if(cxy==0){
					if(mrow+1<row&&sign[mrow+1][mcol]==0) mrow++;
					else break;
				}
				else{
					if(mrow-1>=0&&sign[mrow-1][mcol]==0) mrow--;
					else break;
				}
			}
			sxy=0;
			cxy=(cxy) ? 0 : 1;
		}
	}
}


void main(){
     int i,j,xr,sr,xc,sc,row,col,matrix[ROW][COL];
	 scanf("%d%d",&row,&col);
	 for(i=0;i<row;i++)
		 for(j=0;j<col;j++)
			 scanf("%d",&matrix[i][j]);
     xr=0;
	 sr=row-1;
	 xc=0;
	 sc=col-1;
	 while(xr<sr&&xc<sc){
	      for(j=xc;j<sc;j++)
			  printf("%d\n",matrix[xr][j]);
		  for(i=xr;i<sr;i++)
			  printf("%d\n",matrix[i][sc]);
          for(j=sc;j>xc;j--)
			  printf("%d\n",matrix[sr][j]);
		  for(i=sr;i>xr;i--)
			  printf("%d\n",matrix[i][xc]);
		  xr++;
		  sr--;
		  xc++;
		  sc--;
	 }
	 if(xr==sr&&xc==sc)
		 printf("%d",matrix[xr][xc]);
	 else {
		 if(xr==sr)
		 for(j=xc;j<=sc;j++)
			  printf("%d\n",matrix[xr][j]);
	     if(xc==sc)
            for(i=xr;i<=sr;i++)
				printf("%d\n",matrix[i][sc]);
	 }
}


// homework : ????????
// name     : ???

int main()
{
	int array[100][100];
	int row, col;
	cin >> row >> col;
	for( int i = 0; i < row; i++ )
	{
		for( int j = 0; j < col; j++ )
		{
			cin >> array[i][j];
		}
	}
	for( int row1 = 0, row2 = row - 1,col1 = 0, col2 = col - 1; col1 <= col2 && row1 <= row2; row1++, row2--, col1++, col2-- )
	{
		if( col1 == col2 && row1 == row2 )
		{
			cout << array[row1][col1] << endl;
			break;
		}
		if( row1 == row2 )
		{
			for( int i =col1; i <= col2; i++ )
				cout << array[row1][i] << endl;
			break;
		}
		if( col1 == col2 )
		{
			for( int i = row1; i <= row2; i++ )
				cout << array[i][col1] << endl;
			break;
		}
		for( int i = col1; i < col2; i++ )
			cout << array[row1][i] << endl;
		for( int i = row1; i < row2; i++ )
			cout << array[i][col2] << endl;
		for( int i = col2; i > col1; i-- )
			cout << array[row2][i] << endl;
		for( int i = row2; i > row1; i-- )
			cout << array[i][col1] << endl;
	}

	return 0;
}


/*
 * ????????.cpp
 *
 *  Created on: 2012-12-27
 *      Author: i
 */
int a[103][103]={0},n=0,m=0;
void shuchu(int hang,int lie){
	int i=0;
	if((n%2==0&&hang>=n/2)||(m%2==0&&lie>=m/2)){}
	else if(m%2==1&&lie==m/2)for(i=hang;i<n-hang;i++)cout<<a[i][lie]<<endl;
	else if(n%2==1&&hang==n/2)for(i=lie;i<m-lie;i++)cout<<a[hang][i]<<endl;
	else{
		for(i=lie;i<m-lie;i++)cout<<a[hang][i]<<endl;
		for(i=hang+1;i<n-hang;i++)cout<<a[i][m-lie-1]<<endl;
		for(i=m-lie-2;i>=lie;i--)cout<<a[n-hang-1][i]<<endl;
		for(i=n-hang-2;i>=hang+1;i--)cout<<a[i][lie]<<endl;
		shuchu(hang+1,lie+1);
	}
}
int main(){
	int i=0,j=0;
	cin>>n>>m;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cin>>a[i][j];
		}
	}
	shuchu(0,0);
	return 0;
}


int main()
{
	int a[105][105];
	int row,col,i,j,t=0,temp=0,count=0;
	scanf("%d%d",&row,&col);
	int sum=row*col;
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			scanf("%d",&a[i][j]);
	while(1)
	{
		for(i=t;i<col-t;i++)
		{
			printf("%d\n",a[t][i]);
			count++;
		}
		if(count==sum)
			break;
		for (i=t+1;i<row-t;i++)
		{
			printf("%d\n",a[i][col-t-1]);
			count++;
		}
		if(count==sum)
			break;
		for (i=col-2-t;i>=t;i--)
		{
			printf("%d\n",a[row-t-1][i]);
			count++;
		}
        if(count==sum)
			break;
		for (i=row-2-t;i>t;i--)
		{
			printf("%d\n",a[i][t]);
            count++;
		}
        if(count==sum)
			break;
		t++;
	}
	return 0;
}


int main()
{
	const int max = 100;
	int row, col, i, j;
	cin >> row;
	cin >> col;
	int num[max + 2][max + 2];
	for(i = 0; i < max + 2; i++)
	{
		for(j = 0; j < max + 2; j++)
		{
			num[i][j] = -1;
		}
	}
	for(i = 1; i <= row; i++)
	{
		for(j = 1; j <= col; j++)
		{
			cin >> num[i][j];
		}
	}
	int flag = 0;
	int maxnum = row * col;
	int count = 0;
	i = 1;
	j = 1;
	while(1)
	{
		if(flag == 0)
		{
			while(num[i][j] != -1)
			{
				cout << num[i][j] << endl;
				num[i][j] = -1;
				count++;
				j++;
			}
			j--;
			i++;
			flag = 1;
		}
		else
		{
			if(flag == 1)
			{
				while(num[i][j] != -1)
				{
					cout << num[i][j] << endl;
					num[i][j] = -1;
					count++;
					i++;
				}
				i--;
				j--;
			    flag = 2;
			}
			else {
				if(flag == 2)
				{
					while(num[i][j] != -1)
					{
						cout << num[i][j] << endl;
						num[i][j] = -1;
						count++;
						j--;
					}
					j++;
					i--;
					flag = 3;
				}
				else
				{
					while(num[i][j] != -1)
					{
						cout << num[i][j] << endl;
						num[i][j] = -1;
						count++;
						i--;
					}
					i++;
					j++;
					flag = 0;
				}
			}
		}
		if(count == maxnum) break;
	}
	return 0;
}


int main()
{
	int row, col, n = 0;
	int i, j;
	int a[100 + 10][100 + 10] = {0};
	cin >> row >> col;
	for (i = 0; i < row; i ++)
		for (j = 0; j < col; j ++)
		cin >> a[i][j];
	i = 0; j = 0;
	int buttom = row, right = col, left = 0, top = 0;
	for (;;)
	{
		while(j <= right - 1)
		{n ++; cout << a[i][j ++] << endl;}
		if (n == col * row) break;
		j --; i ++; top ++;
		while(i <= buttom - 1)
		{n ++; cout << a[i ++][j] << endl;}
		if (n == col * row) break;
		i --; j --; right --;
		while(j >= left)
		{n ++; cout << a[i][j --] << endl;}
		if (n == col * row) break;
		j ++; i --; buttom --;
		while(i >= top)
		{n ++; cout << a[i --][j] << endl;}
		if (n == col * row) break;
		i ++; j ++; left ++;
	}
	return 0;
}


int main(){
	int i,j,t,row,col;
	int a[100][100];

	scanf("%d%d",&row,&col);
	if(row>=col){
		t=col/2;
	}
	else{
		t=row/2;
	}
	for(i=0;i<row;i++){
		for(j=0;j<col;j++){
			scanf("%d",&a[i][j]);
		}

	}
	int rmax=row-1,rmin=0,cmax=col-1,cmin=0;

//	printf("%d",t);

	for(i=0;i<t;i++){
		for(j=cmin;j<cmax;j++){
			printf("%d\n",a[rmin][j]);
		}
		for(j=rmin;j<rmax;j++){
			printf("%d\n",a[j][cmax]);
		}
		for(j=cmax;j>cmin;j--){
			printf("%d\n",a[rmax][j]);
		}
		for(j=rmax;j>rmin;j--){
			printf("%d\n",a[j][cmin]);
		}
		rmax-=1;
		rmin+=1;
		cmax-=1;
		cmin+=1;
	}

	if(col%2!=0&&row>=col){
		for(i=t;i<row-t;i++){
			printf("%d\n",a[i][col/2]);
		}
	}
	else if(row%2!=0&&row<=col){
		for(i=t;i<col-t;i++){
			printf("%d\n",a[row/2][i]);
		}
	}

	return 0;
}


int main()
{
	int a,b;
	cin>>a>>b;
	int n[a][b];
	int s=0,e=b-1,p=0,q=a-1;
	for(int i=0;i<a;i++)
		for(int j=0;j<b;j++)
			cin>>n[i][j];

	if(s==e)
				for(int i=p;i<=q;i++)
					cout<<n[i][0]<<endl;
			else if(p==q) for(int i=s;i<=e;i++)
				cout<<n[0][i]<<endl;

	while(s<e&&p<q)
	{
		for(int i=s;i<e;i++){
			cout<<n[p][i]<<endl;

		}

		for(int i=p;i<q;i++)
					{cout<<n[i][e]<<endl;}
		for(int i=e;i>s;i--)
					{cout<<n[q][i]<<endl;}
		for(int i=q;i>p;i--)
					{cout<<n[i][s]<<endl;}
		s++;
		e--;
		p++;
		q--;
	if(s==e){for(int i=p;i<=q;i++)
		{cout<<n[i][s]<<endl;}
	break;
	}
	if(p==q){for(int i=s;i<=e;i++)

		{cout<<n[p][i]<<endl;}
	break;
	}

	}

	return 0;

}


int main()
{
	int x,y,k,sum;
	int a[100][100];
	int i,j;
	int count;
	scanf("%d %d",&x,&y);
	count=0;
	for(i=0;i<x;i++)
	{
		for(j=0;j<y;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	sum=x*y;
	i=0;
	j=0;
	k=0;
	while(count<sum)
	{
		for(j=0+k;j<y;j++)
		{
			printf("%d\n",a[i][j]);
		}
			count+=y-k;
		if(count==sum)
			break;
		for(i=1+k;i<x;i++)
		{
			printf("%d\n",a[i][j-1]);
		}
			count+=x-1-k;
		if(count==sum)
			break;
		y--;
		for(j=y-1;j>=k;j--)
		{
			printf("%d\n",a[i-1][j]);
		}
			count+=y-k;
		if(count==sum)
			break;
		x--;
		for(i=x-1;i>k;i--)
		{
			printf("%d\n",a[i][j+1]);
		}
			count+=x-1-k;
		k++;
		i=k;
	}
	}


int main()
{
	int s[100][100]={0},re[100][100]={0},h=0,l=0,dh=0,dl=0,i=0,j=0,k=0,x[4]={0,1,0,-1},y[4]={1,0,-1,0};//hêÇDDêy lêÇáDêy ij¶¼êÇÑ-»·¿ØÖÆ±äá¿   sêÇ?æ·ÅÕaD©êy×Ö?Äêy×é  reêÇ¼ÇÂ¼ÕaD©êy×ÖóDÃ»óD±»×ß?½?Äêy×é x[4]êÇ?ãòÆ¶??Äê±oòDDêy?Ä±ä»??ÄÏòá¿y[4]êÇ?ãòÆ¶??Äê±oòáDêy±ä»??ÄÏòá¿
	  cin>>h>>l;
	  for(i=1;i<=h;i++)
	     for(j=1;j<=l;j++)
	         {cin>>s[i][j];re[i][j]=1;}
	  dh=1;
	  dl=1;
	  k=0;
	  cout<<s[1][1]<<endl;
	  re[1][1]=0;
	  for(i=1;i<=h*l-1;i++)//¿aê¼±éàú
	    {
		    if(re[dh+x[k]][dl+y[k]]==1)
		    {
			    re[dh+x[k]][dl+y[k]]=0;
				dh+=x[k];
				dl+=y[k];
				cout<<s[dh][dl]<<endl;
				continue;
			}
			if(re[dh+x[k]][dl+y[k]]==0)
			{
			   k=(k+1)%4;//»»·½Ïò
			    re[dh+x[k]][dl+y[k]]=0;
				dh+=x[k];
				dl+=y[k];
				cout<<s[dh][dl]<<endl;
				continue;
			}
		}
	  return 0;
}


int main()
{
	int i,j,row,col,row0=0,col0=0;
	int a[200][200];
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			scanf("%d",&a[i][j]);
	while(row0>=0)
	{
		if(row0+1==row)
		{
			for(i=col0;i<col;i++)
				printf("%d\n",a[row0][i]);
		    break;
		}
		if(col0+1==col)
		{
			for(i=row0;i<row;i++)
				printf("%d\n",a[i][col0]);
			break;
		}
        if(row0+1==row&&col0+1==col)
		{
			printf("%d\n",a[row0][col0]);
			break;
		}
		for(i=col0;i<col;i++)
			printf("%d\n",a[row0][i]);
		for(i=row0+1;i<row;i++)
			printf("%d\n",a[i][col-1]);
		for(i=col-2;i>=col0;i--)
			printf("%d\n",a[row-1][i]);
		for(i=row-2;i>=row0+1;i--)
			printf("%d\n",a[i][col0]);
		row0++;
		col0++;
		row--;
		col--;
		if(row0>row-1||col0>col-1)
			break;

	}
	return 0;
}


int main()
{
	int row, col, num[100][100], count;
	int r, l;
	int i, j, k;
	cin >> row >> col;
	count = row * col;
	for (i = 1; i <= row; i++)   // i???
	{
		for (j = 1; j <= col; j++)  // j???
		{
			cin >> num[i][j];
		}
	} // end for
	int r1, r2, l1, l2;
	r1 = 1;
	r2 = row;
	l1 = 1;
	l2 = col;
	while ((r1 <= r2) && (l1 <= l2))
	{
		int flag = 0;
		for (l = l1; l <= l2; l++)
		{
			cout << num[r1][l];
			count--;   // count?????????
			if (count != 0)
			{
				cout << endl;
			}
			else
			{
				flag = 1;
			}
		}
		if (flag)
		{
			break;
		}
		for (r = r1 + 1; r <= r2; r++)
		{
			cout << num[r][l2];
			count--;
			if (count != 0)
			{
				cout << endl;
			}
			else
			{
				flag = 1;
			}
		}
		if (flag)
		{
			break;
		}
		for (l = l2 - 1; l >= l1; l--)
		{
			cout << num[r2][l];
                                                                 			count--;
			if (count != 0)
			{
				cout << endl;
			}
			else
			{
				flag = 1;
			}
		}
		if (flag)
		{
			break;
		}
		for (r = r2 - 1; r > r1; r--)
		{
			cout << num[r][l1];
			count--;
			if (count != 0)
			{
				cout << endl;
			}
			else
			{
				flag = 1;
			}
		}
		if (flag)
		{
			break;
		}
		else
		{
			r1++;
			r2--;
			l1++;
			l2--;
		}
	}  // end while
	return 0;
}


int main()
{
    int a[110][110],row,col,i,j=0,k=0,geshu=0,zong;
    scanf("%d %d",&row,&col);
    zong=row*col;
    for(i=0;i<row;i++)
    {
                      for(j=0;j<col;j++)
                      {
                                        scanf("%d",&a[i][j]);
                      }
    }
    j=0;i=0;
    while(col>=1&&row>=1)
    {
                         if(geshu==zong) break;
                         for(j=k;j<col;j++)
                         {
                                           printf("%d\n",a[k][j]);
                                           geshu+=1;
                         }
                         if(geshu==zong) break;
                         for(i=k+1;i<=(row-1);i++)
                         {
                                           printf("%d\n",a[i][col-1]);
                                           geshu+=1;
                         }
                         if(geshu==zong) break;
                         for(j=col-2;j>=k;j--)
                         {
                                                printf("%d\n",a[row-1][j]);
                                                geshu+=1;
                         }
                         if(geshu==zong) break;
                         for(i=row-2;i>=(k+1);i--)
                         {
                                                 printf("%d\n",a[i][k]);
                                                 geshu+=1;
                         }
                         row-=1;
                         col-=1;
                         k+=1;

    }
    return 0;
}


void Matrix(int a[100][100],int srow,int scol,int erow,int ecol)
{
	int i,j;
	for(i=scol;i<=ecol;i++)
		printf("%d\n",a[srow][i]);
	for(i=srow+1;i<=erow;i++)
		printf("%d\n",a[i][ecol]);
	if(erow>srow)
		for(i=ecol-1;i>=scol;i--)
			printf("%d\n",a[erow][i]);
	if(ecol>scol)
		for(i=erow-1;i>=srow+1;i--)
			printf("%d\n",a[i][scol]);
	if(erow-srow>=2&&ecol-scol>=2)
		Matrix(a,srow+1,scol+1,erow-1,ecol-1);
}
main()
{
	int a[100][100],i,j,m,n;
	scanf("%d %d",&m,&n);
	for(i=0;i<m;i++)
		for(j=0;j<n;j++)
			scanf("%d",&a[i][j]);
	Matrix(a,0,0,m-1,n-1);
}


int main()
{
 int row,col;
 int i,j,n,time=0;
 scanf("%d%d",&row,&col);
 int array[100][100];
 for(i=0;i<row;i++)
  for(j=0;j<col;j++)
   scanf("%d",&array[i][j]);
  for (n=0;;n++)
  {
   for (i=n;i<col-n;i++)
   {
    printf("%d\n",array[n][i]);
    time++;
	if(time!=0)
	{
		printf("\n");
	}
   }
   if(time==row*col)break;

   for (j=n+1;j<row-n;j++)
   {
    printf("%d\n",array[j][col-n-1]);
    time++;
		if(time!=row*col)
	{
		printf("\n");
	}
   }
   if(time==row*col)break;
   for (i=col-2-n;i>=n;i--)
   {
    printf("%d\n",array[row-n-1][i]);
    time++;
		if(time!=row*col)
	{
		printf("\n");
	}
   }
   if(time==row*col)break;
   for (j=row-2-n;j>n;j--)
   {
    printf("%d\n",array[j][n]);
    time++;
		if(time!=row*col)
	{
		printf("\n");
	}
   }
   if(time==row*col)break;
  }
  return 0;
}


int main()
{
 int row,col;
 int i,j,n;
 int t=0;
 int array[100][100];
 scanf("%d %d",&row,&col);
 for(i=0;i<row;i++)
  for(j=0;j<col;j++)
   scanf("%d",&array[i][j]);
  for (n=0;n<row;n++)
  {
   for (i=n;i<col-n;i++)
   {
    printf("%d\n",array[n][i]);
    t++;
   }
   printf("\n");
   if(t==row*col)
	   break;
   for (j=n+1;j<row-n;j++)
   {
    printf("%d\n",array[j][col-n-1]);
    t++;
   }
   printf("\n");
   if(t==row*col)
	   break;
   for (i=col-2-n;i>=n;i--)
   {
    printf("%d\n",array[row-n-1][i]);
    t++;
   }
   printf("\n");
   if(t==row*col)
	   break;
   for (j=row-2-n;j>n;j--)
   {
    printf("%d\n",array[j][n]);
    t++;
   }
   printf("\n");
   if(t==row*col)
	   break;
  }
  return 0;
}


int a[104][104],n=0;
int row,col,i,j,s;

int out(int ai,int aj,int bi,int bj)
{
     int i,j;
     for (i=aj;i<=bj;i++) {printf("%d\n",a[ai][i],n); n++;}
     for (i=ai+1;i<=bi;i++) {printf("%d\n",a[i][bj],n);n++;}
     if (ai!=bi) {for (i=bj-1;i>aj;i--) {printf("%d\n",a[bi][i],n);n++;} }
     if (aj!=bj) {for (i=bi;i>ai;i--) {printf("%d\n",a[i][aj],n);n++;} }
    // printf("   %d******%d  %d \n",n,ai,aj);
     if (n!=s) out(ai+1,aj+1,bi-1,bj-1);
     return 0;
    }

int main()
{
    scanf("%d %d",&row,&col);
    s=row*col;
    for (i=1;i<=row;i++)
    {
        for(j=1;j<=col;j++)
        {
                           scanf("%d",&a[i][j]);
        }}
    out(1,1,row,col);
    return 0;
}


/*
 * huixingbianli.cpp
 *
 *  Created on: 2012-12-8
 *      Author: Lenovo
 */
int array[100][100];
int row,col;
void out(int beginx,int beginy,int r,int c)
{
	if(r==0||c==0) return;
	int x,y;
	if(r==1)
	{
		for(x=beginx;x<beginx+c;x++)
			cout<<array[beginy][x]<<endl;
		return;
	}
	if(c==1)
	{
		for(y=beginy;y<beginy+r;y++)
			cout<<array[y][beginx]<<endl;
		return;
	}
	for(x=beginx;x<beginx+c;x++)
		cout<<array[beginy][x]<<endl;
	x--;
	for(y=beginy+1;y<beginy+r;y++)
		cout<<array[y][x]<<endl;
	y--;
	for(x=x-1;x>=beginx;x--)
		cout<<array[y][x]<<endl;
	x++;
	for(y=y-1;y>beginy;y--)
		cout<<array[y][x]<<endl;
	beginx++;
	beginy++;
	r-=2;
	c-=2;
	out(beginx,beginy,r,c);
}
int main()
{

	int row,col,i,j;
	cin>>row>>col;
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			cin>>array[i][j];
	out(0,0,row,col);
	return 0;
}


int main()
{
	int i,j,k,l,row,col,shuzu[100][100],n=0,m=0,b=1;
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++){
	    for(j=0;j<col;j++){
		scanf("%d",&shuzu[i][j]);
	    }
	}
	for(i=0;;i++){
	    for(j=m;j<col-i;j++){
		printf("%d\n",shuzu[i][j]);
		n++;
	    }
	    m++;
	    if(n==row*col){
		break;
	    }
	    for(j=b;j<row-i;j++){
		k=col-1-i;
		printf("%d\n",shuzu[j][k]);
		n++;
	    }
	    b++;
	    if(n==row*col){
		break;
	    }
	    for(j=k-1;j>=i;j--){
		l=row-1-i;
		printf("%d\n",shuzu[l][j]);
		n++;
	    }
	    if(n==row*col){
		break;
	    }
	    for(j=l-1;j>i;j--){
	        printf("%d\n",shuzu[j][i]);
		n++;
	    }
	    if(n==row*col){
		break;
	    }
	}
	return 0;
}


int main(){
int xx_col,sx_col,xx_row,sx_row,row,col,k,i,a[100][100];
scanf("%d%d",&row,&col);
for(k=0;k<row;k++){
	for(i=0;i<col;i++){
		scanf("%d",&a[k][i]);
	}
}
xx_col=0;
xx_row=0;
sx_col=col-1;
sx_row=row-1;
for(;xx_col<=sx_col&&xx_row<=sx_row;xx_col++,xx_row++,sx_col--,sx_row--){
	if(xx_col!=sx_col&&xx_row!=sx_row){
	for(i=xx_col;i<sx_col;i++){
		printf("%d\n",a[xx_row][i]);
	}
	for(i=xx_row;i<sx_row;i++){
		printf("%d\n",a[i][sx_col]);
	}
	for(i=sx_col;i>xx_col;i--){
		printf("%d\n",a[sx_row][i]);
	}
	for(i=sx_row;i>xx_row;i--){
		printf("%d\n",a[i][xx_col]);
	}
	}else if(xx_col==sx_col){
		for(i=xx_row;i<=sx_row;i++){
			printf("%d\n",a[i][xx_col]);

		}
	}else if(xx_row==sx_row){
		for(i=xx_col;i<=sx_col;i++){
			printf("%d\n",a[xx_row][i]);

		}
	}
}
return 0;
}


int main()
{
	int row,col,matrix[ROW][COL],k[100000];
	int i,j,a=0;

	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++){
		for(j=0;j<col;j++){
			scanf("%d",&matrix[i][j]);
		}
	}
	int xx_row,sx_row,xx_col,sx_col;
    xx_row=0;
    sx_row=row-1;
    xx_col=0;
    sx_col=col-1;
    while((xx_row<=sx_row)&&(xx_col<=sx_col)){
		if((xx_row==sx_row)&&(xx_col==sx_col)){
			k[a]=matrix[xx_row][xx_col];
			a++;
		}
		for(j=xx_col;j<sx_col;j++){
			k[a]=matrix[xx_row][j];
			a++;
		}
		for(i=xx_row;i<sx_row;i++){
			k[a]=matrix[i][sx_col];
			a++;
		}
		for(j=sx_col;j>xx_col;j--){
			k[a]=matrix[sx_row][j];
			a++;
		}
		for(i=sx_row;i>xx_row;i--){
			k[a]=matrix[i][xx_col];
			a++;
		}
		xx_row++;
    	sx_row--;
        xx_col++;
        sx_col--;
	}
	for(i=0;i<row*col;i++)
	{
		printf("%d\n",k[i]);
	}
	return 0;
}