semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main()
{
	int x[100][100];
	int a,b;
	scanf("%d %d",&a,&b);
	int m,n;
	for(m=0;m<a;m++)
	{
		for(n=0;n<b;n++)
		{
			scanf("%d",&x[m][n]);
		}
	}
	int xx_row=0,sx_row=a-1;
	int xx_col=0,sx_col=b-1;
	int i,j;
	while((xx_row<sx_row)&&(xx_col<sx_col))
	{
		for(j=xx_col;j<sx_col;j++)
		{
			printf("%d\n",x[xx_row][j]);
		}
		for(i=xx_row;i<sx_row;i++)
		{
			printf("%d\n",x[i][sx_col]);
		}
		for(j=sx_col;j>xx_col;j--)
		{
			printf("%d\n",x[sx_row][j]);
		}
		for(i=sx_row;i>xx_row;i--)
		{
			printf("%d\n",x[i][xx_col]);
		}
		xx_row++;
		sx_row--;
		xx_col++;
		sx_col--;
	}
	if((xx_row==sx_row)&&(xx_col==sx_col))                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
	{
		printf("%d\n",x[xx_row][xx_col]);
	}
	if((xx_row==sx_row)&&(xx_col!=sx_col))
	{
		for(i=xx_col;i<=sx_col;i++)
		{	printf("%d\n",x[xx_row][i]);}
	}
	if((xx_col==sx_col)&&(xx_row!=sx_row))
	{
		for(i=xx_row;i<=sx_row;i++)
		{	printf("%d\n",x[i][xx_col]);}
	}
	return 0;
}
int a[999][999];
int f1(int x,int y);
int f2(int x,int y);
int f3(int x,int y);
int f4(int x,int y);
int main()
{
	int n,m,i,j;
for (i=0;i<=998;i++) for (j=0;j<=998;j++) a[i][j]=-9876;
	cin>>n>>m;
	for (i=1;i<=n;i++) for (j=1;j<=m;j++) cin >>a[i][j];
	f1(1,1);
	return 0;
}
int f1(int x,int y)
{
	cout<<a[x][y]<<endl;
	a[x][y]=-9876;
	while (1)
	{
		if (a[x][y+1]!=-9876)
		{
			y++;
			cout <<a[x][y]<<endl;
			a[x][y]=-9876;
		}
		else if (a[x+1][y]!=-9876) return (f2(x+1,y));
		else return 0;
	}
}
int f2(int x,int y)
{
	cout<<a[x][y]<<endl;
	a[x][y]=-9876;
	while (1)
	{
		if (a[x+1][y]!=-9876)
		{
			x++;
			cout <<a[x][y]<<endl;
			a[x][y]=-9876;
		}
		else if (a[x][y-1]!=-9876) return (f3(x,y-1));
		else return 0;
	}
}
int f3(int x,int y)
{
	cout<<a[x][y]<<endl;
	a[x][y]=-9876;
	while (1)
	{
		if (a[x][y-1]!=-9876)
		{
			y--;
			cout <<a[x][y]<<endl;
			a[x][y]=-9876;
		}
		else if (a[x-1][y]!=-9876) return (f4(x-1,y));
		else return 0;
	}
}
int f4(int x,int y)
{
	cout<<a[x][y]<<endl;
	a[x][y]=-9876;
	while (1)
	{
		if (a[x-1][y]!=-9876)
		{
			x--;
			cout <<a[x][y]<<endl;
			a[x][y]=-9876;
		}
		else if (a[x][y+1]!=-9876) return (f1(x,y+1));
		else return 0;
	}
}
void main()
{
	int row,col,i,j,a[100][100],counter;
	scanf("%d %d",&row,&col);
	counter=row*col;
	for(i=0;i<row;i++){
		for(j=0;j<col;j++) scanf("%d",&a[i][j]);
	}
	row-=1;col-=1;
	for(i=0;i<=row/2;i++)
	{
		for(j=i;j<=col-i;j++){
			printf("%d\n",a[i][j]);
			counter--;
			if(counter==0) goto end;
		}
		j--;
		for(i+=1;i<=row-(col-j);i++){
			printf("%d\n",a[i][j]);
			counter--;
			if(counter==0) goto end;
		}
		i--;
		for(j-=1;j>=row-i;j--){
			printf("%d\n",a[i][j]);
			counter--;
			if(counter==0) goto end;
		}
		j++;
		for(i-=1;i>j;i--){
			printf("%d\n",a[i][j]);
			counter--;
			if(counter==0) goto end;
		}
	}
    end:
	;
}
int main()
{
int row,col;
int i,j,m,span=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 (m=0;;m++)
   {
    for (i=m;i<col-m;i++)
    {
     printf("%d\n",array[m][i]);
     span++;
    }
    printf("\n");
    if(span==row*col)break;
    for (j=m+1;j<row-m;j++)
    {
     printf("%d\n",array[j][col-m-1]);
     span++;
    }
    printf("\n");
    if(span==row*col)break;
    for (i=col-2-m;i>=m;i--)
    {
     printf("%d\n",array[row-m-1][i]);
     span++;
    }
    printf("\n");
    if(span==row*col)break;
    for (j=row-2-m;j>m;j--)
    {
     printf("%d\n",array[j][m]);
     span++;
    }
    printf("\n");
    if(span==row*col)break;
   }
   return 0;
}
int main(){
    int i,j,k,n=0,row,col,sz[100][100],xz[10000];
    scanf("%d %d\n",&row,&col);
    for(i=0;i<row;i++){
        for(j=0;j<col;j++){
            scanf("%d ",&sz[i][j]);
        }
    }
   for(k=0;n<row*col;k++){
        i=0+k;
        for(j=0+k;j<col-k;j++){
            xz[n]=sz[i][j];
            n++;
        }
        for(j--,i=1+k;i<row-k;i++){
            xz[n]=sz[i][j];
            n++; 
        }
        for(i--,j=col-2-k;j>=0+k;j--){
             xz[n]=sz[i][j];
             n++;
        }
        for(j++,i=row-2-k;i>=1+k;i--){
             xz[n]=sz[i][j];
             n++;
        }
   }
    for(n=0;n<row*col;n++){
    printf("%d\n",xz[n]);
    }
    return 0;
    
}
int main(){
	int m,n,ab[100][100],i,s,k=0;
	    scanf("%d %d",&m,&n);
		for(i=0;i<m;i++){
			for(s=0;s<n;s++){
				scanf("%d",&ab[i][s]);
			}
		}
		for(i=0;k<m*n;i++){
			for(s=i;s<n-i&&k<m*n;s++){
				printf("%d\n",ab[0+i][s]);
				k++;
			}
			for(s=1+i;s<m-i&&k<m*n;s++){
				printf("%d\n",ab[s][n-1-i]);
				k++;
			}
				for(s=n-2-i;s>=0+i&&k<m*n;s=s-1){
					printf("%d\n",ab[m-1-i][s]);
                      k++;
				}
					  for(s=m-2-i;s>=i+1&&k<m*n;s=s-1){
						  printf("%d\n",ab[s][i]);
						  k++;
					  }
				}
	return 0;
}
int main(){
	int a[100][100];
	int row,col,i,j,rowsx,rowxx,colsx,colxx;
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++){
		for(j=0;j<col;j++){
		    scanf("%d",&a[i][j]); 	
		}
	}
    rowsx=row-1;
	rowxx=0;
	colsx=col-1;
	colxx=0;
	while(rowsx>rowxx && colsx>colxx){    
	    for (j=colxx;  j <colsx;j++){ 
             printf("%d\n",a[rowxx][j]); 
		} 
       for (i=rowxx;  i <rowsx;i++){ 
             printf("%d\n",a[i][colsx]); 
		} 
	   for (j=colsx;  j >colxx;j--){ 
             printf("%d\n",a[rowsx][j]); 
		} 
       for (i=rowsx;  i >rowxx;i--){ 
             printf("%d\n",a[i][colxx]); 
		} 
	   rowsx--;
	   rowxx++;
	   colsx--;
	   colxx++;
	}
	
	if(row%2==1||col%2==1){
		if(rowxx==rowsx){
		    for (j=colxx;  j <=colsx;j++){ 
             printf("%d\n",a[rowxx][j]); 
			} 
		}
		else{
		    for (i=rowxx;  i <=rowsx;i++){ 
             printf("%d\n",a[i][colsx]); 
			} 
		}
	}

return 0;
}
int main(){
    int col,row,i,k,a,e,x;
    int sz[100][100];
    scanf("%d%d",&row,&col);
    for(k=0;k<row;k++){
        for(i=0;i<col;i++){
            scanf("%d",&sz[k][i]);
        }
    }
    k=0;i=-1;e=0;
    for(x=0;;x=x+2){a=0;
       for(i=i+1;i<col;i++){
           printf("%d\n",sz[k][i]);a++;e++;
           if(a==col-x){break;}
       }
       if(e==row*col){break;}
       a=0;
       for(k=k+1;k<row;k++){
           printf("%d\n",sz[k][i]);a++;e++;
           if(a==row-1-x){break;}
       }
       if(e==row*col){break;}
       a=0;
       for(i=i-1;i>=0;i--){
           printf("%d\n",sz[k][i]);a++;e++;
           if(a==col-1-x){break;}
       }
       if(e==row*col){break;}
       a=0;
       for(k=k-1;k>=0;k--){
            printf("%d\n",sz[k][i]);a++;e++;
            if(a==row-2-x){break;}
       }
       if(e==row*col){break;}
    }
return 0;
}
int main(){
    int row,col,i,j,g,k,p,num,time=0;
    int sz[110][110];
    scanf("%d%d",&row,&col);
    num=row*col;
    for(i=0;i<row;i++){
        for(j=0;j<col;j++){
            scanf("%d",&sz[i][j]);        }}  
    for(i=0;;i++){
        for(j=i;j<col-i;j++){
            printf("%d\n",sz[i][j]);time++;}
          if(time==num){break;}
        for(g=1+i;g<row-i;g++){
            printf("%d\n",sz[g][col-1-i]);time++;}
          if(time==num){break;}    
        for(k=col-2-i;k>=i;k--){
            printf("%d\n",sz[row-1-i][k]);time++;}
          if(time==num){break;}
        for(p=row-2-i;p>i;p--){
            printf("%d\n",sz[p][i]);time++;}
          if(time==num){break;}
    }
}
int main()
{
	int a[100][100];
	int m,n,i,j,k;
    scanf("%d %d",&m,&n);
    for(i=0;i<m;i++)
    {
    	for(j=0;j<n;j++)
    	{
    		scanf("%d",&a[i][j]);
    	}
    }
    for(k=0;2*k<m&&2*k<n;k++)
    {
    	for(i=k,j=k;j<n-k-1;j++)
    	{
    		printf("%d\n",a[i][j]);
    	}
    	for(;i<m-k-1;i++)
    	{
    		printf("%d\n",a[i][j]);
    	}
    	if(i==k||j==k)
    	{
    		printf("%d\n",a[i][j]);
    		break;
    	}
    	for(;j>k;j--)
    	{
    		printf("%d\n",a[i][j]);
    	}
    	for(;i>k;i--)
    	{
    		printf("%d\n",a[i][j]);
    	}
    }
    return 0;
}
int main()
{
	int row, col, h, l, left, up;                         //????a
	int a[110][110];
	cin >> row >> col;                                    //?????

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

	l = 0;                                                //???
	h = 0;
	left = 0;
	up = 0;
	while ( left < col && up < row )                      //???????????????????
	{
    	for ( l = left; l < col - 1; l++ )                //???????????
		{
	    	cout << a[h][l] << endl;
		}
	    for ( h = up; h < row - 1; h++ )
		{
		    cout << a[h][l] << endl;
		}
		if ( ( up + 1 ) >= row )                          //???????????
		{
			cout << a[h][col - 1];
			break;
		}
		if ( ( left + 1 ) >= col )
		{
			cout << a[row - 1][l];
			break;
		}
    	for ( ; l > left; l-- )
		{
	    	cout << a[h][l] << endl;
		}
	    for ( ; h > up; h-- )
		{
	    	cout << a[h][l] << endl;
		}
		left++;                                           //????????
		up++;
		col--;
		row--;
		h = up;
	}
	return 0;
}
int main()
{
	int shuzu[100][100];
	int i,j,row,col;
	scanf("%d %d",&row,&col);
	for(i=0;i<row;i++){
		for(j=0;j<col;j++){
				scanf("%d",&shuzu[i][j]);
				}
				}
	int row_xx=0,row_sx=row-1,col_xx=0,col_sx=col-1;
	while(row_sx>row_xx&&col_sx>col_xx){
		for(j=col_xx;j<col_sx;j++)
			printf("%d\n",shuzu[row_xx][j]);
		for(i=row_xx;i<row_sx;i++)
			printf("%d\n",shuzu[i][col_sx]);
		for(j=col_sx;j>col_xx;j--)
			printf("%d\n",shuzu[row_sx][j]);
		for(i=row_sx;i>row_xx;i--)
			printf("%d\n",shuzu[i][col_xx]);
		col_xx++;
		row_xx++;
		col_sx--;
		row_sx--;
	}
	if(row_xx==row_sx&&col_xx<col_sx){
		for(j=col_xx;j<=col_sx;j++){
			printf("%d\n",shuzu[row_xx][j]);
		}
	}
	else if(col_xx==col_sx&&row_xx<row_sx){
		for(i=row_xx;i<=row_sx;i++){
			printf("%d\n",shuzu[i][col_xx]);
		}
	}
	if(row%2!=0&&col%2!=0&&((row>1&&col>1)||(row==1&&col==1))){
		printf("%d\n",shuzu[(row-1)/2][(col-1)/2]);
	}

	return 0;
}
int main()
{
	int row, col;
	int i, j;
	int Array[100][100];
	int startRow = 0, startCol = 0, endRow, endCol;
	int step = 1;

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

	endRow = row - 1;
	endCol = col - 1;
	while(startRow <= endRow && startCol <= endCol)
	{
		switch(step)
		{
		case 1:
			for(j = startCol; j <= endCol; j++)
				printf("%d\n", Array[startRow][j]);
			step++;
			startRow++;
			break;
		case 2:
			for(i = startRow; i <= endRow; i++)
				printf("%d\n", Array[i][endCol]);
			step++;
			endCol--;
			break;
		case 3:
			for(j = endCol; j >= startCol; j--)
				printf("%d\n", Array[endRow][j]);
			step++;
			endRow--;
			break;
		case 4:
			for(i = endRow; i >= startRow; i--)
				printf("%d\n", Array[i][startCol]);
			step = 1;
			startCol++;
			break;
		}
	}	
	return 0;
}
int main(){
int array[110][110],result[10000],ROW,COL,n=0,i=0,k=0,j=0,s=0;
		scanf("%d %d",&ROW,&COL);
		for(i=0;i<ROW;i++){
			for(j=0;j<COL;j++){
				scanf("%d",&array[i][j]);
				s++;
			}
		}

		for(k=0,n=0;n<s;k++){
			if (k%4==0){
				for(j=k/4;j<COL-k/4;j++,n++){
				result[n]=array[k/4][j];
				}
			}else if(k%4==1){
				for(j=k/4+1;j<ROW-k/4;j++,n++){
				result[n]=array[j][COL-k/4-1];
				}
			}else if(k%4==2){
				for(j=COL-k/4-2;j>=k/4;j--,n++){
				result[n]=array[ROW-k/4-1][j];
				}
			}else if(k%4==3){
				for(j=ROW-k/4-2;j>k/4;j--,n++){
				result[n]=array[j][k/4];
				}
			}
		}
		for(n=0;n<s;n++){
			printf("%d\n",result[n]);
		}
		return 0;
}
int main()
{
 int row,col;
 int i,j,k,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 (k=0;;k++)
 {
          for (i=k;i<col-k;i++)
          {
            printf("%d\n",array[k][i]);
            time++;
          
          if(time==row*col)break;}
if(time==row*col)break;
          for (j=k+1;j<row-k;j++)
          { 
            printf("%d\n",array[j][col-k-1]);
            time++;
          
          if(time==row*col)break;}if(time==row*col)break;
          for (i=col-2-k;i>=k;i--)
          {
            printf("%d\n",array[row-k-1][i]);
            time++;
          
          if(time==row*col)break;}if(time==row*col)break;
          for (j=row-2-k;j>k;j--)
          { 
            printf("%d\n",array[j][k]);
            time++;
          
          if(time==row*col)break;
}if(time==row*col)break;
 }
return 0;
}
int main(){
int sz[100][100],m,n,i,j,k,time;
time=0;
scanf("%d%d",&m,&n);
for(i=0;i<m;i++){
	for(j=0;j<n;j++){
		scanf("%d",&sz[i][j]);
	}
}
for(k=0;k<=1000000;k++){if(time==n*m){break;}

for(i=k;i<n-k;i++){
	
	if(time==n*m){break;}
	printf("%d\n",sz[k][i]);time++;
	
}
for(i=1+k;i<m-k;i++){
	
	if(time==n*m){break;}
	printf("%d\n",sz[i][n-1-k]);time++;
    
}
for(i=n-2-k;i>=k;i--){
	
	if(time==n*m){break;}
	printf("%d\n",sz[m-1-k][i]);time++;
	
}
for(i=m-2-k;i>=1+k;i--){

	if(time==n*m){break;}
	printf("%d\n",sz[i][k]);time++;
	
}

	
}
return 0;}
void f(int a[100][100],int m,int p,int q)
{
   int n=0,i,j,w,*pt;
   w=(p+1)*(q+1);
   for(j=1;;j++)
   {
	   for(pt=&a[m][m];pt<=&a[m][p];pt++)
	   { printf("%d\n",*pt); n++;}
	   if(n==w) break;
	   for(i=m+1;i<=q;i++)
	   {printf("%d\n",*(*(a+i)+p));n++;}
	   if(n==w) break;
	   for(pt=&a[q][p-1];pt>=&a[q][m];pt--)
	   {printf("%d\n",*pt);n++;}
	   if(n==w) break;
	   for(i=q-1;i>=m+1;i--)
	   { printf("%d\n",*(*(a+i)+m));n++;}
	   if(n==w) break;
	   m++;
	   p--;
	   q--;
   }

}
void main()
{
	int row,col,i,j,a[100][100],m=0,p,q;
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
			scanf("%d",&a[i][j]);
	}
	p=col-1;
	q=row-1;
	f(a,m,p,q);
}
int main()
{
    int a,b,i,j,k,l,m,p;
	int f[num][num];
	p=0;
	scanf("%d %d",&a,&b);
	for(i=0;i<a;i++)
	{
		for(j=0;j<b;j++)
		{
			scanf("%d",&f[i][j]);
		}
	}
	for(i=0;;i++)
	{
		if(p==a*b)
			break;
		for(j=i;j<b-i;j++)
		{
			p++;
			if(p<a*b)
			{
			printf("%d\n",f[i][j]);
			}
			else
			{
			printf("%d",f[i][j]);
			break;
			}
		}
		if(p==a*b)
			break;
		for(k=i+1;k<a-i;k++)
		{
			p++;
			if(p<a*b)
			{
			printf("%d\n",f[k][b-1-i]);
			}
			else
			{
			printf("%d",f[k][b-1-i]);
			break;
			}
		}
		if(p==a*b)
			break;
		for(l=b-2-i;l>i-1;l--)
		{
			p++;
			if(p<a*b)
			{
			printf("%d\n",f[a-1-i][l]);
			}
			else
			{
			printf("%d",f[a-1-i][l]);
			break;
			}
		}
		if(p==a*b)
			break;
		for(m=a-2-i;m>i;m--)
		{
				p++;
			if(p<a*b)
			{
			printf("%d\n",f[m][i]);
			}
			else
			{
			printf("%d",f[m][i]);
			break;
			}
		}
		if(p==a*b)
			break;
	}
   return 0;
}
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 sz[100][100],m,n,row,col,e,p,k,q;

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

	for (p=0;p<row;p++)
	{
        for (q=0;q<col;q++)
		{
			scanf ("%d",&sz[p][q]);
		}
	}

	if (col<row) e=col/2+1;
	else e=row/2+1;

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

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

	return 0;
}
int main ()
{
	int r,c,i,j,t,n;
	t=0;
	int a[100][100]={0};
	scanf("%d%d",&r,&c);


	for(i=0;i<r;i++)
	{
		for(j=0;j<c;j++)
		{
			scanf("%d",&(a[i][j]));
		}
	}

	int c0=c,r0=r;
	int i0=0,j0=0;

	while(1)
	{
		printf("%d",a[i0][j0]);
		t++;

		if(t==r*c)
		{
			break;
		}
		i=i0;
		for(j=j0+1;j<j0+c0;j++)
		{
			printf("\n%d",a[i][j]);
			t++;
		}
		if(t==r*c)
		{
			break;
		}
		r0--;
		j--;
		for(i=i+1;i<i0+r0+1;i++)
		{
			printf("\n%d",a[i][j]);
			t++;
		}

		if(t==r*c)
		{
			break;
		}
		c0--;
		i--;

		for(j=j-1;j>=j0;j--)
		{
			printf("\n%d",a[i][j]);
			t++;
		}

		if(t==r*c)
		{
			break;
		}
		r0--;
		j++;
		for(i=i-1;i>i0;i--)
		{
			printf("\n%d",a[i][j]);
			t++;
		}
		if(t==r*c)
		{
			break;
		}
		else
		{
			printf("\n");
		}
		c0--;
		i0=i+1;
		j0++;
	}
	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 a,b,n=0,q,i,k,m,o;
		int sz[100][100];
		scanf("%d",&a);
		scanf("%d",&b);
		o=0;
		int x=0;
		m=a*b;
		for(i=0;i<a;i++)
		{
			for(k=0;k<b;k++)
			{
				scanf("%d",&sz[i][k]);
			}
		}
	if(a%2!=0)
		{
			q=a+1;
			
		}
		while(1)
		{
			if(b-2*n>0)
			{
			for(k=n;k<b-n;k++)
			{
					printf("%d\n",sz[n][k]);
			}
			}
			if(b-2*n<=0)
			{
				break;
			}
			n++;
			if(a-2*n>=0)
			{
			for(k=n;k<=a-n;k++)
			{
					printf("%d\n",sz[k][b-n]);
			}
			}
			
			if(a-2*n<0)
			{
				break;
			}
			if(b-2*n>=0)
			{
			for(k=b-n-1;k>=n-1;k--)
			{
					printf("%d\n",sz[a-n][k]);
			}	
			}

			if(b-2*n<0)
			
			{
				break;
			}
			if(a-1-2*n>=0)
			{
			for(k=a-n-1;k>n-1;k--)
			{
					printf("%d\n",sz[k][n-1]);
			}
			}
			if(a-2*n-1<0)
			{
				break;
			}
			
		}
	
		return 0;
	}
int a[100][100];
int main()
{
	int row,c,i,j,d,x,l,r,s,t,y;
	scanf("%d%d",&row,&c);
	for(i=0;i<row;i++)
	{
		for(j=0;j<c;j++)
			scanf("%d",&a[i][j]);
	}
	d=1;
	r=c-1;
	x=0;
	l=row-1;
	s=1;
	y=0;
	t=0;
	printf("%d\n",a[0][0]);
	for(i=1;i<row*c;i++)
	{
		if(d==1)
		{
			if(t==r)
			{
				r=r-1;
				d=-1;
			}
		}
		else if(d==-1)
		{
			if(y==l)
			{
				l=l-1;
				d=2;
			}
		}
		else if(d==2)
		{
			if(t==x)
			{
				x=x+1;
				d=-2;
			}
		}
		else if(d==-2)
		{
			if(y==s)
			{
				s=s+1;
				d=1;
			}
		}
		if(d==1)
			t=t+1;
		else if(d==-1)
			y=y+1;
		else if(d==2)
			t=t-1;
		else if(d==-2)
			y=y-1;
		printf("%d\n",a[y][t]);
	}
}
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;
	}
}
int main()
{
	int array[100][100];
	int row,col,i,j,k,n;
	scanf("%d%d",&row,&col);
	if(row>col){
		n=(col+1)/2;
	}
	else{
		n=(row+1)/2;
	}
	for(i=0;i<row;i++){
		for(j=0;j<col;j++){
			scanf("%d",&(array[i][j]));
		}
	}
	for(k=1;k<=n;k++){
		for(i=k-1,j=k-1;j<=col-k;j++){
			printf("%d\n",array[i][j]);
		}
		for(j=col-k,i=k;i<=row-k;i++){
			printf("%d\n",array[i][j]);	
		}
		if(row-k>k-1){
			for(i=row-k,j=col-k-1;j>=k-1;j--){
				printf("%d\n",array[i][j]);
			}
		}
		if(k-1<col-k){
			for(j=k-1,i=row-k-1;i>=k;i--){
				printf("%d\n",array[i][j]);
			}
		}
	}
	return 0;
}
//#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 row, col;
	cin >> row >> col;
	int a[row][col];
	int i, j;
	int t = 0;                             //?????t? 
	for ( i = 0; i < row; i++ )
		for ( j = 0; j < col; j++ )
			cin >> a[i][j];
	
	while ( (row > 2 * t) && (col > 2 * t) )
	{
		for ( i = t; i <= col - t - 1; i++ )
			cout << a[t][i] << endl;          //???? 
			
		for ( i = t + 1; i <= row - t - 1; i++ )
			cout << a[i][col - t - 1] << endl;    //???? 
		
		if ( col == 2 * t + 1 || row == 2 * t + 1) break;
		
		for ( i = col - t - 2; i >= t + 1; i-- )
			cout << a[row - t - 1][i] << endl;    //???? 
			
		for ( i = row - t - 1; i >= t + 1; i-- )
			cout << a[i][t] << endl;          //???? 
		
		t++; 
	}
	
	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;
}