semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main(){
   int i,j,m,n,k,b,c;
   scanf("%d%d",&m,&n);
   int a[m][n];
   for(i=0;i<m;i++){
       for(j=0;j<n;j++){
          scanf("%d",&a[i][j]);
          }
       }
   if(m>n){
   b=n;
}
   else{
   b=m;
}
    if(b%2==0){
    c=b/2;
}
    else{
    c=b/2+1;
}
       for(k=0;k<c;k++){
             for(j=k;j<n-k-1;j++){
                 printf("%d\n",a[k][j]);
                 }
             for(i=k;i<m-k-1;i++){
                 printf("%d\n",a[i][n-k-1]);
                }
          if((b%2==0)||(b%2!=0&&k!=c-1)){
          for(j=n-k-1;j>k;j--){
             printf("%d\n",a[m-k-1][j]);
             }
             }
          if((b%2==0)||(b%2!=0&&k!=c-1)){
          for(i=m-k-1;i>k;i--){
             printf("%d\n",a[i][k]);
             }
             }
          }
          if(m==n&&m%2==1){
             printf("%d\n",a[c-1][c-1]);
          } 
          if(m<n&&m%2==1){
             printf("%d",a[c-1][n-c]);
             }
          if(m>n&&n%2==1){
             printf("%d",a[m-c][c-1]);
             }
          scanf("%d",&n);  
   return 0;
}
int main(){
    int row,col,k,i,j;
    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]);
        }
    }
    for(k=0; row-k>k && col-k>k; k++) {
        for (i=k,j=k; j<col-k-1; j++) {
            printf("%d\n", sz[i][j]);
        }
        for (; i<row-k-1; i++) {
            printf("%d\n", sz[i][j]);
        }
        if (i==k || j==k) {
            printf("%d\n", sz[i][j]);
            break;
        }
        for (; j>k; j--) {
            printf("%d\n", sz[i][j]);
        }
        for (; i>k; i--) {
            printf("%d\n", sz[i][j]);
        }
    }
    return 0;
}
int main()
{
	int i,h,l,j,hb=0,lb=0,lans=0,hs,ls,n=0,ans[10000],a[100][100],z=0;
	scanf("%d%d",&h,&l);
	for(i=0;i<h;i++)
		for(j=0;j<l;j++)
			scanf("%d",&a[i][j]);
		hs=h-1;
        ls=l-1;
		while(1)
		{
			for(i=lb;i<=ls;i++){
			ans[lans++]=a[hb][i];
			n++;
				if(n==h*l)
				{z=1;
					break;
				}
		}
			if(z==1)break;
			for(i=hb+1;i<=hs;i++){ 
			ans[lans++]=a[i][ls];
			n++;
				if(n==h*l)
				{z=1;
					break;
				}
		}
			if(z==1)break;
		    for(i=ls-1;i>=lb;i--){
			ans[lans++]=a[hs][i];
			n++;
				if(n==h*l)
				{z=1;
				break;
				}
		}
			if(z==1)break;
	     	for(i=hs-1;i>=hb+1;i--){
			ans[lans++]=a[i][lb];
			n++;
				if(n==h*l)
				{z=1;
				break;
				}
		}
			if(z==1)break;
		hb++;
		hs--;
		lb++;
		ls--;
		}
		for(i=0;i<lans;i++)
			printf("%d\n",ans[i]);


	

				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;
}
/*
 * 1204.cpp
 *
 *  Created on: 2012-12-4
 *      Author: wangyinzhi
 */
int a[100][100],b[10000],x,y,k=0;
int cube(int c,int x,int y)
{
	if(x<=0||y<=0) return 0;
	for(int i=c;i<y;i++){
		b[k]=a[c][i];
		k++;

	}
	for(int j=c+1;j<x;j++){
		b[k]=a[j][y-1];
		k++;

	}
	for(int r=y-2;r>=c;r--){
		b[k]=a[x-1][r];
		k++;

	}
	for(int s=x-2;s>=c+1;s--){
		b[k]=a[s][c];
		k++;

	}
	cube(c+1,x-1,y-1);

}
int main(){
	int row,col,i,j,n;
	cin>>row>>col;
	n=row*col;
	for(i=0;i<row;i++){
		for(j=0;j<col;j++){
			cin>>a[i][j];
		}
	}
	cube(0,row,col);
	for(i=0;i<n;i++){
	cout<<b[i]<<endl;
		}
	return 0;
}
int main()
{
int row,col,i,j;
int ss[100][100];
scanf("%d %d",&row,&col);
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",&(ss[i][j]));
}
}
for(int k=0;k<(col+1)/2&&k<(row+1)/2;k++)
{
for(j=k;j<col-k;j++)
{
printf("%d\n",ss[k][j]);
}
if(k+1 >= row-k)
break;
for(i=k+1;i<row-k;i++)
{
printf("%d\n",ss[i][col-k-1]);
}
if(col-k-2 < k)
break;
        for(j=col-k-2;j>=k;j--)
{
printf("%d\n",ss[row-k-1][j]);
}
if(row-k-2 < k+1)
break;
for(i=row-k-2;i>=k+1;i--)
{
printf("%d\n",ss[i][k]);
}
}
    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 b[10000];
void bianli(int a[100][100],int m,int n)
{
	int i,j,k=0;
	int *p;
	p=b;
	for(i=0;k<(m+1)*(n+1);i++)
	{
		for(j=i;j<=n-i;j++)
		{
			*p=a[i][j];
			p++;
			k++;
		}
		for(j=i+1;j<=m-i;j++)
		{
			*p=a[j][n-i];
			p++;
			k++;
		}
		for(j=n-i-1;j>=i;j--)
		{
			*p=a[m-i][j];
			p++;
			k++;
		}
		for(j=m-i-1;j>i;j--)
		{
			*p=a[j][i];
			p++;
			k++;
		}

	}

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

}
//???????????????
//?????11.4
//????wayne
int main()
{ 
	int row,col,n,m,a[101][101];    //n,m???????????
	int i,j,row1,row2,col1,col2;    //row1???i???????,row2????????col1,col2
	cin>>row>>col;
    for (i=1;i<=row;i++)
		for (j=1;j<=col;j++)
			cin>>a[i][j];          //????
	for (i=row,j=col;i>=1&&j>=1;i=i-2,j=j-2)  //????????????????
	{
	     	row1=(row-i)/2+1;
		    row2=row-(row-i)/2;
		    col1=(col-j)/2+1;
		    col2=col-(col-j)/2;       //????row1,row2,col1,col2
		if ((i!=1&&j!=1)||(i==1&&j==1))
		{
	     	for (m=col1;m<=col2;m++)
			     cout<<a[row1][m]<<endl;  //??????
		    for (n=row1+1;n<=row2;n++)
			     cout<<a[n][col2]<<endl;  //??????
		    for (m=col2-1;m>=col1;m--) 
			     cout<<a[row2][m]<<endl;  //??????
		    for (n=row2-1;n>=row1+1;n--) 
		         cout<<a[n][col1]<<endl;  //??????
		}
		else                                //???????????????1???????
		{
			if (i==1) 
			{
               	for (m=col1;m<=col2;m++)
			         cout<<a[row1][m]<<endl;  
			}
			else 
			{
				for (n=row1;n<=row2;n++)
					cout<<a[n][col1]<<endl;
			}
		}
	}
	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;
}
void main()
{
	int m,n,a[100][100],i,j;
	scanf("%d%d",&m,&n);
	for(i=0;i<m;i++)
	{
		for(j=0;j<n;j++)
			scanf("%d",&a[i][j]);
	}
	for(j=1;j<=n/2+1||j<=m/2+1;j++)
	{
		for(i=j-1;i<n+1-j;i++)
			printf("%d\n",a[j-1][i]);
		for(i=j;i<m+1-j;i++)
			printf("%d\n",a[i][n-j]);
		if(j>=m+1-j)
			break;
		for(i=n-j-1;i>=j-1;i--)
			printf("%d\n",a[m-j][i]);
		if(n-j-1<j-1)
			break;
		for(i=m-j-1;i>=j;i--)
			printf("%d\n",a[i][j-1]);
	}

}
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]);
		
	}
}
void main()
{
	int row,col,i,j;
	int 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]);}
	for(;row>1&&col>1;)
	{for(j=0;j<col;j++)
		printf("%d\n",a[0][j]);
	for(i=1;i<row;i++)
		printf("%d\n",a[i][col-1]);
	for(j=col-2;j>=0;j--)
		printf("%d\n",a[row-1][j]);
	for(i=row-2;i>=1;i--)
		printf("%d\n",a[i][0]);
	for(i=0;i<row-2;i++)
	{for(j=0;j<col-2;j++)
	a[i][j]=a[i+1][j+1];}
	row=row-2;
	col=col-2;
	}
	if(row==1)
	{for(i=0;i<col;i++)
	printf("%d\n",a[0][i]);
	}
	else 
	{for(i=0;i<row;i++)
	printf("%d\n",a[i][0]);
	}
}
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 a,b,i,j,matrix[100][100];
	scanf("%d%d",&a,&b);
	for(i=0;i<a;i++)
	{
		for(j=0;j<b;j++)
		{
			scanf("%d",&matrix[i][j]);
			getchar();
		}
	}
	while(a>0&&b>0)
	{
		for(i=0;i<b;i++)
			printf("%d\n",matrix[0][i]);
		for(i=1;i<a;i++)
			printf("%d\n",matrix[i][b-1]);
		if(b>1&&a>1)
		{
			for(i=b-2;i>=0;i--)
				printf("%d\n",matrix[a-1][i]);
			for(i=a-2;i>=1;i--)
				printf("%d\n",matrix[i][0]);
		}
		for(i=0;i<a-2;i++)
		{
			for(j=0;j<b-2;j++)
				matrix[i][j]=matrix[i+1][j+1];
		}
		a=a-2;
		b=b-2;
	}
	return 0;
}
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,i,j;
	cin>>row>>col;
	int a[row+2][col+2];
	for(i=0;i<row+2;i++)	{		for(j=0;j<col+2;j++)		{			a[i][j]=0;		}	}
	//memset(a,0,sizeof(a));
	for(i=1;i<=row;i++)
	{
		for(j=1;j<=col;j++)
		{
			cin>>a[i][j];
		}
	}
	i=1;j=1;
	while(1)
	{
		if(a[i][j+1]!=0&&a[i][j-1]==0&&a[i-1][j]==0)
		{
			cout<<a[i][j]<<endl;
			
			a[i][j]=0;
			j++;
			continue;
		}
		if(a[i+1][j]!=0&&a[i-1][j]==0&&a[i][j+1]==0)
		{
			cout<<a[i][j]<<endl;
			
			a[i][j]=0;i++;continue;
		}
		if(a[i][j-1]!=0&&a[i][j+1]==0&&a[i+1][j]==0)
		{
			cout<<a[i][j]<<endl;
			
			a[i][j]=0;j--;continue;
		}
		if(a[i-1][j]!=0&&a[i+1][j]==0&&a[i][j-1]==0)
		{
			cout<<a[i][j]<<endl;
			
			a[i][j]=0;i--;continue;
		}
		else
{cout<<a[i][j]<<endl;
		break;}
	}
	return 0;
}
int main()
{
	int m, n, a[100][100], visit[100][100] = {0};
	int i, j;
	int count = 0;
	int type;							//1??????????2??????????3????4???

	cin >> m >> n;
	for (i = 1; i <= m; i++)
		for (j = 1; j <= n; j++)
			cin >> a[i][j];

	i = 1, j = 1, type = 1;				//?(1,1)???,??????
	while (count < m * n)				//????????
	{
		cout << a[i][j] << endl;
		visit[i][j] = 1;
		count++;
		if (type == 1)					//???????????????(i,j)?
		{	
			if (j < n && visit[i][j + 1] == 0)			//???????
				j++;
			else										//??????
			{
				type = 2;
				i++;
			}
			continue;
		}
		if (type == 2)
		{	
			if (i < m && visit[i + 1][j] == 0)
				i++;
			else
			{
				type = 3;
				j--;
			}
			continue;
		}
		if (type == 3)
		{	
			if (j > 1 && visit[i][j - 1] == 0)
				j--;
			else
			{
				type = 4;
				i--;
			}
			continue;
		}
		if (type == 4)
		{	
			if (i > 1 && visit[i - 1][j] == 0)
				i--;
			else
			{
				type = 1;
				j++;
			}
			continue;
		}
	}
	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 main()
{
   int a[288][288];
   int n,m,i,j,t,x,y;
   scanf("%d%d",&n,&m);
   for (i=1;i<=n;i++)
   for (j=1;j<=m;j++)
   scanf("%d",&a[i][j]);
   x=n,y=m;
   i=1;
   j=1;
   do
   {
   for (t=j;t<=y;t++) 
   printf("%d\n",a[i][t]);
   i=i+1;
   if (i>x) 
   break;
   for (t=i;t<=x;t++) 
   printf("%d\n",a[t][y]);
   y=y-1;
   if (y<j) 
   break;
   for (t=y;t>=j;t--) 
   printf("%d\n",a[x][t]);
   x=x-1;
   if (i>x) break;
   for (t=x;t>=i;t--) 
   printf("%d\n",a[t][j]);
   j=j+1;
   if (y<j) break;
   }
   while ((i<=x)&&(j<=y));
}
void main()
{
	void f(int n,int m);
	int n,m;
	scanf("%d %d",&n,&m);
	f(n,m);
}

void f(int n,int m)
{
	int a[100][100];int i=0,j=0,b=0,p,t=1,s=0;
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	p=m*n;i=0;j=0;
while(1)
{
	for(;j<m;j++)
	{
		printf("%d\n",a[i][j]);b++;if(b==p) break;
	}
	i++;j--;
	if(b==p) break;
	for(;i<n;i++)
	{
		printf("%d\n",a[i][j]);b++;if(b==p) break;
	}
	j--;i--;
	if(b==p) break;
	for(;j>=s;j--)
	{
		printf("%d\n",a[i][j]);b++;if(b==p) break;
	}
	if(b==p) break;
	j++;i--;
	for(;i>=t;i--)
	{
		printf("%d\n",a[i][j]);b++;if(b==p) break;
	}
	j++;
	if(b==p) break;i++;m--;n--;s++;t++;
}
}
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 ;
	cin >> row >> col ;
	int N = row * col ;
	//???????
	int array[100][100] ;
	for ( int r = 0 ; r < row ; r++ )
		for ( int c = 0 ; c < col ; c++ )
			cin >> array[r][c] ;
	//????????????
	int r = 0 , c = 0 ;
	int K = 0 ;
	while ( 1 )//????????????
	{
		
		//????
		for ( int j = c ; j <= col - 1 ; j++ )
		{
			cout << array[r][j] << endl ;
			K++ ;
		}
		if ( r < row - 1 )
			r++ ;//????????
		if ( K == N ) break ; //??????????
		//????
		for ( int i = r ; i <= row - 1 ; i++ )
		{
			cout << array[i][col-1] << endl ;
			K++ ;
		}
		if ( c < col - 1 )
			col-- ;//?????????
		if ( K == N ) break ; //??????????
		//????
		for ( int j = col - 1 ; j >= c ; j-- )
		{
			cout << array[row-1][j] << endl ;
			K++ ;
		}
		if ( r < row - 1 )
			row-- ;//?????????
		if ( K == N ) break ; //??????????
		//????
		for ( int i = row - 1 ; i >= r ; i-- )
		{
			cout << array[i][c] << endl ;
			K++ ;
		}
		if ( c < col - 1 )
			c++ ;
		if ( K == N ) break ; //??????????
	}

	return 0 ;
}
// ( > w < ) finished~
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;	
}