semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int a[100][100]={0};
int main()
{void p(char c,int b1,int b2,int b3,int b4);
 int i,j,k,l,n,m;
 scanf("%d%d",&m,&n);
 for(i=0;i<m;i++)
  for(j=0;j<n;j++)
   scanf("%d",&a[i][j]);
 p('y',0,0,n-1,m-1);
}
void p(char c,int b1,int b2,int b3,int b4)
{
 int i,j,k,l;
 if(c=='y')
 {for(i=b1;i<=b3;i++)
   printf("%d\n",a[b2][i]);
  if(b2!=b4) 
   p('x',b1,b2+1,b3,b4);}
 if(c=='x')
 {for(i=b2;i<=b4;i++)
   printf("%d\n",a[i][b3]);
  if(b1!=b3) 
   p('z',b1,b2,b3-1,b4);}
 if(c=='z')
 {for(i=b3;i>=b1;i--)
   printf("%d\n",a[b4][i]);
  if(b2!=b4) 
   p('s',b1,b2,b3,b4-1);}
 if(c=='s')
 {for(i=b4;i>=b2;i--)
   printf("%d\n",a[i][b1]);
  if(b1!=b3) 
   p('y',b1+1,b2,b3,b4);}
}
main()
{int i,j,k,m,n,p,q,s;
 scanf("%d %d",&m,&n);
 struct{int k;int p;}shu[m+2][n+2];
 
 for(i=1;i<=m;i++)
  {for(j=1;j<=n;j++)
    {scanf("%d",&shu[i][j].k);shu[i][j].p=1;}}
 
 for(j=0;j<=(n+1);j++)
  shu[0][j].p=0;
 for(j=0;j<=(n+1);j++)
  shu[m+1][j].p=0;
 for(i=0;i<=(m+1);i++)
  shu[i][n+1].p=0; 
 for(i=0;i<=(m+1);i++)
  shu[i][0].p=0; 

 // for(i=0;i<(m+2);i++)
  //{for(j=0;j<(n+2);j++)
  //printf("%d\n",shu[i][j].p);}
 for(i=1,j=1,s=1;;)
 {
 for(;;)
  {if(shu[i][j].p==1) 
       {printf("%d\n",shu[i][j].k);shu[i][j].p=0;j++;}
   else {if((shu[i][j].p==0)&&(shu[i][j-2].p==0)&&(shu[i-1][j-1].p==0)&&(shu[i+1][j-1].p==0))
         {s=0;break;}
         else {i=i+1;j=j-1;break;}
        }
  }
 for(;;)  
  { if(shu[i][j].p==1)
       {printf("%d\n",shu[i][j]);shu[i][j].p=0;i++;}
    else { if((shu[i][j].p==0)&&(shu[i-2][j].p==0)&&(shu[i-1][j+1].p==0)&&(shu[i-1][j-1].p==0))
                 {s=0;break;}
          else {i=i-1;j=j-1;break;}     
         }
  } 
 for(;;)
 {  if(shu[i][j].p==1)
    {printf("%d\n",shu[i][j]);shu[i][j].p=0;j--;}
    else  {if((shu[i][j].p==0)&&(shu[i][j+2].p==0)&&(shu[i-1][j+1].p==0)&&(shu[i+1][j+1].p==0))
             {s=0;break;}
           else {j++;i--;break;}
          }
 }
 for(;;)
 {  if(shu[i][j].p==1)
    {printf("%d\n",shu[i][j]);shu[i][j].p=0;i--;}
    else {if((shu[i+2][j].p==0)&&(shu[i][j].p==0)&&(shu[i+1][j+1].p==0)&&(shu[i+1][j-1].p==0))
         {s=0;break;}
          else {j++;i++;break;}
         }
 }
 if(s==0) break;
 
 }
}
int main()
{
	int a[100][100]= {0}, r, c, i, j, n = 0;
	cin >> r >> c ;
	for (i = 1; i <= r; i++)
	{
		for (j = 1; j <= c; j++)
		{
			cin >> a[i][j];
		}
	}
	j = 1;
	i = 0;
	while ((2 * n < c - 1) && (2 * n < r - 1))
	{
		for (i  = 1 + n; i <= c - n; i++)
		{
			cout << a[j][i] << endl;
		}
		i--;
	    for (j = j + 1; j <= r - n; j++)
		{
		    cout << a[j][i] << endl;
		}
		j--;
	    for (i = i - 1; i >= 1 + n; i--)
		{
		    cout << a[j][i] << endl;
		}
		i++;
	    for (j = j - 1; j > 1 + n; j--)
		{
		    cout << a[j][i] << endl;
		}
		j++;
	    n++;
	}
	if(2 * n == r - 1)
		for (i  = 1 + n; i <= c - n; i++)
		{
			cout << a[j][i] << endl;
		}
	else if(2 * n == c - 1)
		for (j = j; j <= r - n; j++)
		{
		    cout << a[j][i + 1] << endl;
		}
	return 0;
}
/*
 * hui.cpp
 *
 *  Created on: 2013-11-5
 *      Author: ??
 */
int main(){
	int r,c;
	cin>>r>>c;
	int a[r][c],b[r+2][c+2],d[r*c];
	for(int ii=0;ii<r+2;ii++){
		for(int jj=0;jj<c+2;jj++){
			b[ii][jj]=1;
		}
	}
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			cin>>a[i][j];
			b[i+1][j+1]=0;
		}
	}
	int ii=0,jj=0;
	b[1][1]=1;
	d[0]=a[0][0];
	for(int m=1;m<r*c;m++){
		if(jj+1<c&&b[ii+1][jj+1+1]==0&&b[ii-1+1][jj+1]==1&&b[ii+1][jj-1+1]==1)
		{jj++;d[m]=a[ii][jj];b[ii+1][jj+1]++;}
		else if(ii+1<r&&b[ii+1+1][jj+1]==0&&b[ii+1][jj+1+1]==1&&b[ii-1+1][jj+1]==1)
		{ii++;d[m]=a[ii][jj];b[ii+1][jj+1]++;}
		else if(jj-1>=0&&b[ii+1][jj-1+1]==0&&b[ii+1+1][jj+1]==1&&b[ii+1][jj+1+1]==1)
		{jj--;d[m]=a[ii][jj];b[ii+1][jj+1]++;}
		else if(ii-1>=1&&b[ii-1+1][jj+1]==0&&b[ii+1][jj-1+1]==1&&b[ii+1+1][jj+1]==1)
		{ii--;d[m]=a[ii][jj];b[ii+1][jj+1]++;}
	}
	for(int f=0;f<r*c;f++){
		cout<<d[f]<<endl;
	}
	return 0;
}
int main()
{
    int r[4]={0,1,0,-1};
    int c[4]={1,0,-1,0};
    int row,col,i=0,j=0,k=0,x=r[0],y=c[0];
    scanf("%d%d",&row,&col);
    int array[row][col];
    for(int a=0;a<row;a++){
        for(int b=0;b<col;b++){
            scanf("%d",&(array[a][b]));
           }
        }

    
    for(i=0;i<row*col;i++,j+=x,k+=y){
        printf("%d\n",array[j][k]);
        if(x==r[0]&&y==c[0]&&j+k==col-1){
            x=r[1];
            y=c[1];
        }else if(x==r[1]&&y==c[1]&&j-k==row-col){
            x=r[2];
            y=c[2];
        }else if(x==r[2]&&y==c[2]&&j+k==row-1){
            x=r[3];
            y=c[3];
        }else if(x==r[3]&&y==c[3]&&j==k+1){
            x=r[0];
            y=c[0];
        }
    }
	return 0;
}
int main()
{
	int i,j,a[100][100]={{0},{0}},s=0,b,t=0,r=0,c=0,R,rmin=0,C,cmin=0;
	scanf("%d%d",&R,&C);
	for(i=0;i<R;i++)
	{
		for(j=0;j<C;j++)
		{
			scanf("%d",&a[i][j]);
			t=t+1;
		}
	}
	for(b=0;b<=10000;b++)
	{
		for(c=cmin;c<C;c++)
		{
			printf("%d\n",a[r][c]);
			s=s+1;
			if(s==t)
				return 0;
		}
		C-=1;
		c-=1;
		rmin+=1;
		for(r=rmin;r<R;r++)
		{
			printf("%d\n",a[r][c]);
			s=s+1;	
			if(s==t)
				return 0;
		}
		R-=1;
		r-=1;
		for(c=C-1;c>=cmin;c--)
		{
			printf("%d\n",a[r][c]);
			s=s+1;	
			if(s==t)
				return 0;
		}
		c+=1;
		for(r=R-1;r>=rmin;r--)
		{
			printf("%d\n",a[r][c]);
			s=s+1;		
			if(s==t)
				return 0;
		}
		r+=1;
		cmin+=1;
	}
}
int main(){
	int i,j,k=1,n,m;
	int sz[100][100];
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&sz[i][j]);
		}
	}
	for(k=1;k<=n/2&&k<=m/2;k++){
	
         
	for(i=k-1,j=k-1;j<m-k;j++){
		
			printf("%d\n",sz[i][j]);
	}
	for(i=k-1,j=m-k;i<n-k;i++){
		
			printf("%d\n",sz[i][j]);
	}
	for(i=n-k,j=m-k;j>k-1;j--){
		
			printf("%d\n",sz[i][j]);
	}
	for(i=n-k,j=k-1;i>k-1;i--){
		
			printf("%d\n",sz[i][j]);
	}
	}
	if(n%2!=0&&n<=m){
		
		for(j=k-1;j<=m-k;j++){
		
		printf("%d\n",sz[n/2][j]);
	}
	}
    else if(m%2!=0){
		
		for(i=k-1;i<=n-k;i++){
		
		printf("%d\n",sz[i][m/2]);
	}
	}
    return 0;
}
/*************************************
*file 2.cpp                     ******
*author ???                    ****
*date 2013-11-1                    ***
*description ????????        *
*************************************/
int main()
{
	int row, col;              //???????
	cin >> row >> col;
	int i, j, m, n;            //?????????
	int s = row * col, k=0;    //s???????,k????
	int a[200][200];
	for(i = 1; i <= row; i++)
	{
		for(j = 1; j <= col; j++)
			cin >> a[i][j];
	}
	
	//??????i,i???i,col-i+1???row-i+1,col-i+1???row-i+1,i?????i,i?
	for(i = 1; (i <= col - i + 1) && (i <= row - i + 1); i++)
	{
		for(m = i; m <= col - i + 1 && (k - s); m++)     //???k-s?????????????????????????????????
		{
			cout << a[i][m] << endl;
			k++;
		}
		for(m = i + 1; m <= row - i + 1 && (k - s); m++) 
		{
			cout << a[m][col - i + 1] << endl;
			k++;
		}
		for(m = col - i; m >= i && (k - s); m--) 
		{
			cout << a[row - i + 1][m] << endl;
			k++;
		}
		for(m = row - i; m > i && (k - s); m--) 
		{
			cout << a[m][i] << endl;
			k++;
		}
	}
	return 0;
}
//*******************************
// ???? ??????????
// ?? ? ??? 1300012972
// ?? ? 2013.11.6
//*******************************



int main()
{
	int step = 0, row, col, x[4] = {0, 1, 0, -1}, y[4] = {1, 0, -1, 0}, array[100][100], i, j, acc[100][100] = {0}, d = 0;

	cin >> row >> col;

	for (i = 0; i < row; i++)
		for (j = 0; j < col; j++)
			cin >> array[i][j];

	i = 0;
	j = -1;

	while (step < row * col)
	{
		i += x[d];
		j += y[d];

		if (i >= 0 && i < row  && j >= 0 && j < col  && acc[i][j] == 0)
		{
			cout << array[i][j] << endl;
			acc[i][j] = 1;
			step++;
		}
		else 
		{
			i -= x[d];
			j -= y[d];
			d = (d + 1) % 4;
		}
	}

	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;
}
int a[200][200],row,col,f;

void function(int r,int c)
{
    int i,j;
    f=0;
        if(r==1){for(i=1;i<=c;i++){printf("%d\n", a[1][i]);}f=1;}
        if(c==1&&f==0){for(i=1;i<=r;i++){printf("%d\n", a[i][1]);}}
        if(r!=1&&c!=1){
        for(i=1;i<=c;i++){printf("%d\n", a[1][i]);}
        for(i=2;i<=r;i++){printf("%d\n", a[i][c]);}
        for(i=c-1;i>=1;i--){printf("%d\n", a[r][i]);}
        for(i=r-1;i>=2;i--){printf("%d\n", a[i][1]);}
        }
        
        for(i=2;i<=r-1;i++){
            for(j=1;j<=c-2;j++){a[i][j]=a[i][j+1];}
            }
        for(i=1;i<=r-2;i++){
            for(j=1;j<=c-2;j++){a[i][j]=a[i+1][j];}
            }
        if(c-2>=1&&r-2>=1){function(r-2,c-2);}
        
    }

int main()
{
    int i,j;
    scanf("%d %d", &row,&col);
    for(i=1;i<=row;i++){
        for(j=1;j<=col;j++){
            scanf("%d", &a[i][j]);
            } }
    function(row,col);
}
int main()
{
	int h,l,i,j,a,b,c,k=0,num[100][100];
	cin>>h>>l;
	for(i=0;i<h;i++)
		for(j=0;j<l;j++)
			cin>>num[i][j];
	for(i=0;k<h*l;i++){
		for(j=i;(j<l-i)&&(k<h*l);j++){
			cout<<num[i][j]<<endl;k++;}
		for(j=i+1;(j<h-i)&&(k<h*l);j++){
			cout<<num[j][l-1-i]<<endl;k++;}
		for(j=l-2-i;(j>=i)&&(k<h*l);j--){
			cout<<num[h-1-i][j]<<endl;k++;}
		for(j=h-2-i;(j>i)&&(k<h*l);j--){
			cout<<num[j][i]<<endl;k++;}}
	return 0;
}
int main() {
	int row, col;
	scanf("%d%d", &row, &col);
	int data[100][100];
	for(int i = 0; i < row; i++) {
		for(int j = 0; j < col; j++) {
			scanf("%d", &data[i][j]);
		}
	}
	int colLow = 0;
	int rowLow = 0;
	int colHigh = col - 1;
	int rowHigh = row - 1;
	while(rowLow <= rowHigh && colLow <= colHigh) {
		for(int i = colLow; i <= colHigh; i++) {
			printf("%d\n", data[rowLow][i]);
		}
		for(int i = rowLow + 1; i <= rowHigh - 1; i++) {
			printf("%d\n", data[i][colHigh]);
	}
		if(rowHigh != rowLow) {
			for(int i = colHigh; i >= colLow; i--) {
				printf("%d\n", data[rowHigh][i]);
			}
		}
		if(colHigh != colLow) {
			for(int i = rowHigh - 1; i >= rowLow + 1; i--) {
				printf("%d\n", data[i][colLow]);
			}
		}
		colLow++;
		rowLow++;
		colHigh--;
		rowHigh--;
	}
}
void main()
{
	int row,col;
	int i,j,n,time=0,a,b,c,d;
	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++)
		{
			for(a=n;a<col-n;a++)
			{
				printf("%d\n",array[n][a]);
				time++;
			}
			if(time==row*col)
				break;
			for(b=n+1;b<row-n;b++)
			{
				printf("%d\n",array[b][col-n-1]);
				time++;
			}
			if(time==row*col)
				break;
			for(c=col-2-n;c>=n;c--)
			{
				printf("%d\n",array[row-n-1][c]);
				time++;
				
			}
			if(time==row*col)
				break;
			for(d=row-2-n;d>n;d--)
			{
				printf("%d\n",array[d][n]);
				time++;
			}
			if(time==row*col)
				break;
		}
}
int main(){
    int i,j,row,col,rowmin,rowmax,colmin,colmax;
    int a[100][100];
    scanf("%d%d",&row,&col);
    for(i=1;i<=row;i++){
		for(j=1;j<=col;j++){
			scanf("%d",&a[i][j]);
			}
		}
	rowmax=row;
	rowmin=1;
	colmax=col;
	colmin=1;
	while(1){
		if(rowmax<rowmin||colmax<colmin){break;}
		else if(rowmax==rowmin){for(j=colmin;j<=colmax;j++){printf("%d\n",a[rowmin][j]);}}
		else if(colmax==colmin){for(i=rowmin;i<=rowmax;i++){printf("%d\n",a[i][colmin]);}}
		else{
			for(j=colmin;j<=colmax;j++){printf("%d\n",a[rowmin][j]);}
			for(i=rowmin+1;i<=rowmax;i++){printf("%d\n",a[i][colmax]);}
			for(j=colmax-1;j>=colmin;j--){printf("%d\n",a[rowmax][j]);}
			for(i=rowmax-1;i>rowmin;i--){printf("%d\n",a[i][colmin]);}
			}
		rowmax-=1;
	    rowmin+=1;
	    colmax-=1;
	    colmin+=1;
		}
	return 0;
}
int main()
{
	int sz[100][100],i,row,col,j,k=0,min;
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++){
		for(j=0;j<col;j++){
			scanf("%d",&sz[i][j]);
		}
	}
	min=row;
	if(row>col){
		min=col;
	}
	while(k<(min+1)/2){
		for(j=0+k;j<col-k;j++){
			printf("%d\n",sz[0+k][j]);
		}
		for(i=1+k;i<row-k;i++){
			printf("%d\n",sz[i][col-1-k]);
		}
		for(j=col-2-k;j>-1+k;j--){
			if(row-1-k<=0+k){
				break;
			}
			printf("%d\n",sz[row-1-k][j]);
		}
		for(i=row-2-k;i>k;i--){
				if(k>=col-1-k){
				break;
			}
			printf("%d\n",sz[i][k]);
		}
		k+=1;
	}
	
	return 0;
}
int main()
{
		int array[110][110], row, col; //????array???row???col
		int x = 0, y = 0; //x???????????????y????? 
		int m = 0, n = 0; //m???????n?????? 
		cin >> row >> col; //??????? 
		

		
		for ( int i = 0; i < row; i++ )
		{
				for ( int j = 0; j < col; j++ )
				{
						cin >> array[i][j]; //?????? 
				}
		}


		while ( n < col && m < row )
		{  
			if ( y >= col - n )
					break;
				while ( y < col - n )
				{
					cout << array[x][y] << endl;
					y++;
				}
				y--;
				x++;
				
					if ( x >= row - m )
					break;
				while ( x < row - m )
				{
					cout << array[x][y] << endl;
					x++;
				}
				x--;
				y--;
			
				if ( y < n )
								break;
				while ( y >= n )
				{
					cout << array[x][y] << endl;
					y--;
				}
				y++;
				x--;
			
					
				m++;
				if ( x < m )
					break;		
				while ( x >= m )
				{
					cout << array[x][y] << endl;
					x--;
				}
				x++;
				y++;
			
					
				n++;
		}

		return 0;	
}
int times(int x,int y)
{
	int z;
	z=(x<y)?x:y;
	if(z%2) return (z+1)/2;
	else return z/2;
}
void spinout(int b[100][100],int x,int y)
{
	int i,j,k[100][100]={0};
    for(i=0;i<times(x,y);i++)
	{
		for(j=0;j<y;j++)
		{
			if(k[i][j]==0)
			{
				printf("%d\n",b[i][j]);
				k[i][j]=1;
			}
		}
		for(j=0;j<x;j++)
		{
			if(k[j][y-1-i]==0)
			{
				printf("%d\n",b[j][y-1-i]);
				k[j][y-1-i]=1;
			}
		}
        for(j=y-1;j>=0;j--)
		{
			if(k[x-1-i][j]==0)
			{
				printf("%d\n",b[x-1-i][j]);
				k[x-1-i][j]=1;
			}
		}
		for(j=x-1;j>=0;j--)
		{
			if(k[j][i]==0)
			{
				printf("%d\n",b[j][i]);
				k[j][i]=1;
			}
		}
	}
}
void main()
{
	int row,col,i,j,a[100][100];
	scanf("%d %d",&row,&col);
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			scanf("%d",*(a+i)+j);
	spinout(a,row,col);
}
int main(){
	int row, col, matrix[ROW][COL];
	int i, j;
    int xxrow,sxrow,xxcol,sxcol; 
	scanf("%d %d", &row, &col);
	for(i = 0; i < row; i++){
		for(j = 0; j < col; j++){
			scanf("%d", &(matrix[i][j]));
		}
	}
	xxrow= 0;
    sxrow= row-1;
    xxcol=0;
    sxcol=col-1;
	
    while( (xxrow<sxrow) && (xxcol<sxcol) ){
		for(j =xxcol; j <sxcol; j++){
	printf("%d\n", matrix[xxrow][j]);
		}

for(i = xxrow; i < sxrow; i++){
	printf("%d\n", matrix[i][sxcol]);
}

for(j = sxcol; j > xxcol; j--){
	printf("%d\n", matrix[sxrow][j]);
}

for(i = sxrow; i > xxrow; i--){
	printf("%d\n", matrix[i][xxcol]);
}
              xxrow++;
    	      sxrow--;
             xxcol ++;
             sxcol --;
	
	}
    if((xxrow==sxrow)&&(xxcol<sxcol)){
		for(j=xxcol;j<sxcol+1;j++){
			printf("%d\n",matrix[xxrow][j]);
		}
	}
	else if(xxrow<sxrow&&xxcol==sxcol){
		for(i=xxrow;i<sxrow+1;i++){
			printf("%d\n",matrix[i][xxcol]);
		}
	}
	else if((xxrow==sxrow)&&(xxcol==sxcol)){
		printf("%d\n",matrix[xxrow][xxcol]);
	}
	


	return 0;
}
int main()
{
	int row,col,i,j,time=0;
	int a[101][101]={0};
	scanf("%d%d",&row,&col);
	for(i=1;i<=row;i++)
	{
		for(j=1;j<=col;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	for(i=0,j=0;;)
	{
		for(i++,j++;;j++)
		{
			if(a[i][j]==0)break;
			printf("%d\n",a[i][j]);
			time++;
			a[i][j]=0;
		}
		if(time==row*col)break;
		for(j=j-1,i=i+1;;i++)
		{
			if(a[i][j]==0)break;
			printf("%d\n",a[i][j]);
			time++;
			a[i][j]=0;
		}
		if(time==row*col)break;
		for(i--,j--;;j--)
		{			
			if(a[i][j]==0)break;
			printf("%d\n",a[i][j]);
			time++;
			a[i][j]=0;
		}
	    if(time==row*col)break;
		for(j++,i--;;i--)
		{
			if(a[i][j]==0)break;
			printf("%d\n",a[i][j]);
			time++;
			a[i][j]=0;
		}
		if(time==row*col)break;
	}
	return 0;
}
void main()
{
	int a[105][105],row,col,min,i,j;
	int n,x;
	scanf("%d %d",&row,&col);
	for(i=1;i<=row;i++) for(j=1;j<=col;j++) scanf("%d",&a[i][j]);
	if(row<=col) min=row; else min=col;
	if(min%2==0) n=min/2; else n=min/2+1;
	for(x=1;x<=n;x++)
	{
		i=x;
		for(j=x;j<=col-x+1;j++) printf("%d\n",a[i][j]);
		if(row==min&&row%2==1&&x==n) break;
		j=col-x+1;
		for(i=x+1;i<=row-x+1;i++) printf("%d\n",a[i][j]);
		if(col==min&&col%2==1&&x==n) break;
		i=row-x+1;
		for(j=col-x;j>=x;j--) printf("%d\n",a[i][j]);
		if(row==min&&row%2==0&&x==n) break;
		j=x;
		for(i=row-x;i>=x+1;i--) printf("%d\n",a[i][j]);
	}
}
int main(){
    int x[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",&x[i][j]);
        }
    }
    int s=0,a=row-1,b=0,c=col-1;
    while(s<=a&&b<=c){
        if(s<a&&b<c){
            for(i=b;i<c;i++){
                printf("%d\n",x[s][i]);
            }
            for(i=s;i<a;i++){
                printf("%d\n",x[i][c]);
            }
            for(i=c;i>b;i--){
                printf("%d\n",x[a][i]);
            }
            for(i=a;i>s;i--){
                printf("%d\n",x[i][b]);
            }
        }else if(s==a){
            for(i=b;i<=c;i++){
                printf("%d\n",x[s][i]);
            }
        }else{
            for(i=s;i<=a;i++){
                printf("%d\n",x[i][b]);
            }
        }
        s=s+1;
        a=a-1;
        b=b+1;
        c=c-1;
    }
    return 0;
}
int main( )
{
int m,n,t;
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];
if(m<=n)
t=m;
else t=n;
for(int i=0;i<t/2;i++)
{
for(int j=i;j<n-i;j++)
{
cout<<a[i][j]<<endl;
}
for(int j=i+1;j<m-i;j++)
{
cout<<a[j][n-i-1]<<endl;
}
for(int j=i+1;j<n-i;j++)
{
cout<<a[m-1-i][n-1-j]<<endl;
}
for(int j=i+1;j<m-i-1;j++)
{
cout<<a[m-1-j][i]<<endl;
}
}
if(m<=n&&m%2==1)
{
for(int j=(m-1)/2;j<n-(m-1)/2;j++)
cout<<a[(m-1)/2][j]<<endl;
}
if(m>n&&n%2==1)
for(int j=(n-1)/2;j<m-(n-1)/2;j++)
cout<<a[j][(n-1)/2]<<endl;
return 0;
}
int a[10000][10000];
int main(){
 int  row,col,i,j,k=0,r,c,p=0;
 scanf("%d%d",&r,&c);
 for(i=0;i<r;i++){
	 for(j=0;j<c;j++){
       scanf("%d",&a[i][j]);
 }
 }

 for(row=r,col=c;(row>0)&&(col>0);row=row-1,col=col-1){
 	if(p!=r*c){
     for(j=k;j<col;j++){
	   printf("%d\n",a[k][j]);
	   p++; 
     }
 	}else{
	 break;
	 }
     if(p!=r*c){
	 for(i=k;i<row-1;i++){
	   printf("%d\n",a[i+1][col-1]);
	   p++;
	 }
     }else{
	 break;
	 }
	 if(p!=r*c){
	 for(j=col-1;j>k;j--){
	   printf("%d\n",a[row-1][j-1]);
	   p++;
	 }
	 }else{
	 break;
	 }
	 if(p!=r*c){
	   for(i=row-1;i>k+1;i--){
	     printf("%d\n",a[i-1][k]);
	     p++;
	 }
	 }else{
	 break;
	 }
	 k++;
 
 }
return 0;
}
int main()
{
	int M,N,m,n,i,j=0,a[100][100],s=0,k;
	scanf("%d%d",&m,&n);
	for(i=0;i<m;i++)
	{   
	for(j=0;j<n;j++)	
	scanf("%d",&a[i][j]);
	}
	M=m;
	N=n;
	k=m*n;
	for(;;)
	{
       
	   for(i=M-m,j=N-n;j<n;j++)
	   {
		printf("%d\n",a[i][j]); 
		s=s+1;
	   }
			m=m-1;
			j=j-1;
			if(s==k)
				break;
			for(i=M-m;i<=m;i++)
			{
				printf("%d\n",a[i][j]);
				s=s+1;
			}	 
					n=n-1;
					i=i-1;
					if(s==k)
				break;

					for(j=n-1;j>=N-n-1;j--)
					{
						printf("%d\n",a[i][j]);
						s=s+1;
					}
					 j=j+1;
					 if(s==k)
				break;

							for(i=m-1;i>=M-m;i--)
							{
								printf("%d\n",a[i][j]);
                               s=s+1;   
							}
							i=i+1;
						if(s==k)
				break;
					
				
			
		
	}

	

}
//******************
//???2         **
//??????    **
//???2013.11.1 **
//******************
int main()
{
	int row, col, num[200][200], a, b, c, c1, x, y;

	cin >> row >> col;

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

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

			cin >> num[i][j];
	
	x = y = 1;

	c1 = 0;

	c = row * col;

	for ( ;x <= row; )
	{
		for ( a = x; a <= col; a++ )
		{			
			if ( c1 == c ) break;
			
			cout << num[x][a] << "\n";

			c1++;
		}
		a--;

		for ( b = y + 1; b <= row; b++ )
		{
			if ( c1 == c ) break;
			
			cout << num[b][a] << "\n";

			c1++;
		}
		b--;

		for ( a--; a >= x; a-- )
		{			
			if ( c1 == c ) break;
			
			cout << num[b][a] << "\n";

			c1++;
		}
		a++;

		b--;

		for ( ; b > y; b-- )
		{
			if ( c1 == c ) break;
			
			cout << num[b][a] << "\n";

			c1++;
		}
		x++;
		
		y++;
		
		row--;
		
		col--;
	}
	return 0;
}
int main()
{
	int row,col;
	scanf("%d %d",&row,&col);
	int a[100][100];
	int i,t;
	int count=0;
	for(i=0;i<row;i++)
	{
		for(t=0;t<col;t++)
		{
			scanf("%d",&a[i][t]);
		}
	}
	
	int k=0,j=0,m=0;
	if(row%2==0)
	{
	for(k=0;k<=(row/2-1);k++)
	{
		for(j=k;j<=(col-1-k);j++)
		{
			printf("%d\n",a[k][j]);
			count++;
		}
		if(count==row*col)
			break;
		for(m=k+1;m<=row-2-k;m++)
		{
			printf("%d\n",a[m][col-1-k]);
			count++;
		}
			if(count==row*col)
			break;

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

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

	return 0;
}