semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
void main()
{
	int row,col,a[100][100],b[100][100],time=0;
	int i,j,way;
	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<100;i++)
			for(j=0;j<100;j++)
				b[i][j]=1;
		i=-1;
		j=-1;
		way=0;
		while(time<row*col)
		{
			if(way==0)
			{
				for(i=i+1,j=j+1;j<col&&b[i][j]!=0;j++) 
				{printf("%d\n",a[i][j]);
				 b[i][j]=0;
				 time++;
				}
					
				way=1;	
				
			}
			if(way==1)
			{
				for(j=j-1,i=i+1;(b[i][j]!=0)&&(i<row);i++)
				{
					
					printf("%d\n",a[i][j]);
					b[i][j]=0;
					time++;
					
				}
                way=2;
			}
			if(way==2)
			{
				for(i=i-1,j=j-1;b[i][j]!=0&&j>=0;j--)
				{
					
					printf("%d\n",a[i][j]);
					b[i][j]=0;
					time++;
					
				}
                 way=3;
			}
			if(way==3)
			{
				for(i=i-1,j=j+1;b[i][j]!=0&&i>=0;i--)
				{
					printf("%d\n",a[i][j]);
					b[i][j]=0;
					time++;
				}
                 way=0;
			}
			
		}           
}
int main()
{
	int a[100][100]={0};
	int row=0,col=-1,i,j,m,n,t=1,p=0;
	cin>>m>>n;
	int k=m*n;
	for(i=0;i<m;i++)
		for(j=0;j<n;j++)
			cin>>a[i][j];

	do
	{
		for(i=0;i<n;i++)
		{
			col+=t;
			cout << a[row][col] << endl;

			p++;
		}
		n--;
		m--;
		for(i=0;i<m;i++)
		{
			row+=t;
			cout << a[row][col]<<endl;
			p++;
		}
		t=-t;
	}while (p<k);
	return 0;
}
const int x[5]={0,0,1,0,-1};
const int y[5]={0,1,0,-1,0};
int f[1000][1000];
int main(){
int m,n,k=1;
scanf("%d %d",&m,&n);
for (int i=1; i<=m; i++){
for (int j=1; j<=n; j++){
scanf("%d",&f[i][j]);
}
}
int dx=1,dy=1;
int dm=m,dn=n,cm=1,cn=1;
int count=0;
while (count<(m*n)){
printf("%d\n",f[dx][dy]);
count++;
int tx=dx+x[k];
int ty=dy+y[k];
if ((tx>dm) || (tx<cm) || (ty>dn) || (ty<cn)){
if (k==1) cm++;
else
if (k==2) dn--;
else
if (k==3) dm--;
else
if (k==4) cn++;
k=(k % 4)+1;
tx=dx+x[k];
ty=dy+y[k];
}
dx=tx;
dy=ty;
}
//while(1);
return 0;
}
int sum;
void print(int a[][100],int m1,int n1,int m2,int n2,int k)
{
	int i;
	for(i=n1;i<n2&&k!=sum;i++)
	{
		printf("%d\n",a[m1][i]);
		k+=1;
	}
	for(i=m1+1;i<m2&&k!=sum;i++)
	{
		printf("%d\n",a[i][n2-1]);
		k+=1;
	}
	for(i=n2-2;i>n1&&k!=sum;i--)
	{
		printf("%d\n",a[m2-1][i]);
		k+=1;
	}
	for(i=m2-1;i>m1&&k!=sum;i--)
	{
		printf("%d\n",a[i][n1]);
		k+=1;
	}
	if(n2-n1>2&&m2-m1>2)
		print(a,m1+1,n1+1,m2-1,n2-1,k);
}
void main()
{
	int i,j,m,n,a[100][100];
	scanf("%d %d",&m,&n);
	for(i=0;i<m;i++)
	{
		for(j=0;j<n;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	sum=m*n;
	print(a,0,0,m,n,0);
}
void main()
{
	int array[200][200]={0};
	int r,c;
	int i,j;
	int k=0,l=0;
	
	scanf("%d %d",&r,&c);
	for(i=0;i<r;i++)
		for(j=0;j<c;j++)
		{
			scanf("%d",&array[i][j]);
		}

	if (r%2==0&&c%2==0)
	{
		for(k=0;k<r/2;k++)
		{	
			for(j=k;j<c-1-k;j++)
				printf("%d\n",array[k][j]);
			for(i=k;i<r-1-k&&k<c-1-k;i++)
				printf("%d\n",array[i][c-1-k]);
			for(j=c-1-k;j>k;j--)
				printf("%d\n",array[r-1-k][j]);
			for(i=r-1-k;i>k&&c-1-k>k;i--)
				printf("%d\n",array[i][k]);
		}
	}
	else if (r%2!=0&&c%2==0)
	{
		for(k=0;k<r/2;k++)
		{	
			for(j=k;j<c-1-k;j++)
				printf("%d\n",array[k][j]);
			for(i=k;i<r-1-k&&k<c-1-k;i++)
				printf("%d\n",array[i][c-1-k]);
			for(j=c-1-k;j>k;j--)
				printf("%d\n",array[r-1-k][j]);
			for(i=r-1-k;i>k&&c-1-k>k;i--)
				printf("%d\n",array[i][k]);
		}
		for(j=k;j<=c-1-k;j++)
			printf("%d\n",array[r/2][j]);
		
	}
	else if (r%2==0&&c%2!=0)
	{
    	for(k=0;k<r/2;k++)
		{	
		for(j=k;j<c-1-k;j++)
		    printf("%d\n",array[k][j]);
		for(i=k;i<r-1-k&&k<c-1-k;i++)
			printf("%d\n",array[i][c-1-k]);
		for(j=c-1-k;j>k;j--)
			printf("%d\n",array[r-1-k][j]);
		for(i=r-1-k;i>k&&c-1-k>k;i--)
		{
			printf("%d\n",array[i][k]);
			l=k+1;
		}
		}
		for(i=c-1-l;i<=r-1-l;i++)
			printf("%d\n",array[i][c/2]);
		
	}
	else //if (r%2!=0&&c%2!=0)
	{
	    for(k=0;k<r/2;k++)
		{
			for(j=k;j<c-1-k;j++)
				printf("%d\n",array[k][j]);
			for(i=k;i<r-1-k&&k<c-1-k;i++)
				printf("%d\n",array[i][c-1-k]);
			for(j=c-1-k;j>k;j--)
				printf("%d\n",array[r-1-k][j]);
			for(i=r-1-k;i>k&&c-1-k>k;i--)
			{
				printf("%d\n",array[i][k]);
				l=k+1;
			}
		}
	    if(r>=c)
		{
			for(i=l;i<=r-1-l;i++)
				printf("%d\n",array[i][c/2]);
		}
		else
		{
            for(j=k;j<=c-1-k;j++)
			printf("%d\n",array[r/2][j]);
		}
		
	}

    
}
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;
}
void main()
{
	int a[100][100],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 k;
	for(k=0;k<=row/2-1&&k<=col/2-1;k++)
	{
		for(j=0+k;j<col-k;j++)
		{
			printf("%d\n",a[k][j]);
		}
		for(i=1+k;i<row-k;i++)
		{
			printf("%d\n",a[i][col-1-k]);
		}
		for(j=col-2-k;j>=k;j--)
		{
			printf("%d\n",a[row-1-k][j]);
		}
		for(i=row-2-k;i>=k+1;i--)
		{
			printf("%d\n",a[i][k]);
		}
	}
	if(row>col&&col%2!=0)
	{
		for(i=k;i<row-k;i++)
		{
			printf("%d\n",a[i][col/2]);
		}
	}
	if(row<col&&row%2!=0)
	{
		for(j=k;j<col-k;j++)
		{
			printf("%d\n",a[row/2][j]);
		}
	}
	if(row==col&&row%2!=0)
	{
		printf("%d",a[row/2][col/2]);
	}
}
int main(){
	
int m,n,sz[100][100],x,y,z,a,b,w=0,i;
	
scanf("%d %d",&m,&n);
	
for(int p=0;p<m;p++)
	
{
	
	
for(int q=0;q<n;q++)
	
	
{
	
	
	
scanf("%d",&sz[p][q]);
	
	
}
	
}
	
if(m>n)
	
	
i=n;
	
else
	
	
i=m;
	
for(x=0;x<i/2;x++)
	
{
	
	
for(y=0+x;y<n-1-x;y++)
	
	
{
	
	
	
printf("%d\n",sz[x][y]);
	
	
}
	
	
for(z=0+x;z<m-1-x;z++)
	
	
{
	
	
	
printf("%d\n",sz[z][y]);
	
	
}
	
	
for(a=n-1-x;a>0+x;a--){
	
	
	
printf("%d\n",sz[z][a]);
	
	
}
	
	
for(b=m-1-x;b>0+x;b--)
	
	
{
	
	
	
printf("%d\n",sz[b][a]);
	
	
}
	
}
	
if(m%2==1&&n>=m)
	
{
	
	
w=m/2;
	
	
for(y=w;y<=n-1-w;y++)
	
	
	
printf("%d\n",sz[w][y]);
	
}
	
else if(n%2==1&&m>=n)
	
{
	
	
w=n/2;
	
	
for(x=w;x<=m-1-w;x++)
	
	
	
printf("%d\n",sz[x][w]);

	
}
	
return 0;
}
int main(){
 int a[100][100]={0},h,l,k,j;
scanf("%d%d",&h,&l);
for(k=0;k<h;k++){
 for(j=0;j<l;j++)
scanf("%d",&a[k][j]);
}
int ph=0,pl=0;
printf("%d\n",a[ph][pl]);
a[ph][pl]=0;int cs=h*l;
for(int z=1;z<cs;z++){
    if((ph==0||a[ph-1][pl]==0)&&a[ph][pl+1]!=0){
	   pl=pl+1;
	   printf("%d\n",a[ph][pl]);
	   a[ph][pl]=0;
	}
    else if((pl==l-1||a[ph][pl+1]==0)&&a[ph+1][pl]!=0){
		ph=ph+1;
		printf("%d\n",a[ph][pl]);
		a[ph][pl]=0;
	}
    else if(a[ph+1][pl]==0&&pl!=0&&a[ph][pl-1]!=0){
		pl=pl-1;
		printf("%d\n",a[ph][pl]);
		a[ph][pl]=0;
	}
    else if((a[ph][pl-1]==0||ph==0)&&a[ph-1][pl]!=0){
		ph=ph-1;
		printf("%d\n",a[ph][pl]);
		a[ph][pl]=0;
	}
    else break;
}
return 0;
}
int main()
{
    int n,m;
    int i,j,a,c,b;
    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]);
        }
    }
    if(m>n)
    {
        b=n;
    }
    else
    {
        b=m;
    }
    if(b%2==1)
    {
        c=(b+1)/2;
    }
    else
    {
        c=b/2;
    }
    for(a=0;a<c;a++)
    {
        if(a<m-a)
        {
            for(j=a;j<m-a;j++)
            {
                printf("%d\n",sz[a][j]);
            }
            if(1+a<n-a)
            {
                for(i=1+a;i<n-a;i++)
                {
                     printf("%d\n",sz[i][m-a-1]);
                }
                if(m-a-2>=a)
                {
                    for(j=m-a-2;j>=a;j--)
                    {
                        printf("%d\n",sz[n-a-1][j]);
                    }
                    if(n-a-2>a)
                    {
                         for(i=n-a-2;i>a;i--)
                         {
                             printf("%d\n",sz[i][a]);
                         }
                    }
                }
            }
        }
    }
    return 0;
}
void main()
{
	int i,j,m,n,t,a[100][100];
	scanf("%d%d",&m,&n);
	for(i=0;i<m;i++)for(j=0;j<n;j++)scanf("%d",&a[i][j]);
	for(i=0,j=0;j<n-j&&i<m-i;i++,j++)
	{
		for(t=j;t<n-j;t++)printf("%d\n",a[i][t]);
		for(t=i+1;t<m-i;t++)printf("%d\n",a[t][n-1-j]);
		if(i+1<m-i)for(t=n-j-2;t>=j;t--)printf("%d\n",a[m-i-1][t]);
		if(j+1<n-j)for(t=m-i-2;t>=i+1;t--)printf("%d\n",a[t][j]);
	}
}

//??????????1ms?????
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 col,row,i,j,a[100][100];
 cin>>row>>col;
 for(i=0;i<row;i++)
	 for(j=0;j<col;j++)
		 cin>>a[i][j];
 for(i=0;(row-2*i>0)&&(col-2*i>0);i++)
	 {for(j=i;j<col-i;j++)
		 cout<<a[i][j]<<endl;
      for(j=i+1;j<row-i;j++)
    	 cout<<a[j][col-i-1]<<endl;
      for(j=col-i-2;j>=i&&row-2*i>1;j--)
    	  cout<<a[row-i-1][j]<<endl;
      for(j=row-i-2;j>i&&col-2*i>1;j--)
    	  cout<<a[j][i]<<endl;
	 }
 return 0;
}
void main()
{
	void shuru(int,int);
	int row,col;
	scanf("%d%d",&row,&col);
	shuru(row-1,col-1);
}
void shuru(int x,int y)
{
	void huixing(int (*p)[100],int,int,int);
	int i,j,k,t;
	int a[100][100];
	int (*p)[100];
	p=a;
	for(i=0;i<=x;i++)
	{
		for(j=0;j<=y;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	if(x<y) t=x;
	else t=y;
	for(k=0;k<=t/2;k++)
	{
		huixing(p,k,x,y);
	}
}
void huixing(int (*p)[100],int g,int h,int l)
{
	int i,sum=0;
	for(i=0;i<=l-2*g;i++)
	{
		if(sum<(h-2*g+1)*(l-2*g+1))
		{
			printf("%d\n",*(*(p+g)+g+i));
			sum=sum+1;
		}
	}
	for(i=1;i<=h-2*g;i++)
	{
		if(sum<(h-2*g+1)*(l-2*g+1))
		{
			printf("%d\n",*(*(p+g+i)+l-g));
			sum=sum+1;
		}
	}
	for(i=1;i<=l-2*g;i++)
	{
		if(sum<(h-2*g+1)*(l-2*g+1))
		{
			printf("%d\n",*(*(p+h-g)+l-g-i));
			sum=sum+1;
		}
	}
	for(i=1;i<h-2*g;i++)
	{
		if(sum<(h-2*g+1)*(l-2*g+1))
		{
			printf("%d\n",*(*(p+h-g-i)+g));
			sum=sum+1;
		}
	}
}
int main()
{
	int i,j,row,col,state;
	int sz[100][100],zt[100][100]={0};
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
		{
			scanf("%d",&sz[i][j]);
		}
	}
	state=0;
	i=0;
	j=0;
	if(row>=2&&col>=2)
	{
		while(1)
	{
		if(zt[i][j]==1)
			break;
		else
		{
			if(state==0&&j+1<col&&zt[i][j+1]==0)
			{
			    printf("%d\n",sz[i][j]);
				zt[i][j]=1;
				j++;
			}
			else if(state==0)
			{
				printf("%d\n",sz[i][j]);
				zt[i][j]=1;
				i++;
			    state=1;
			}
			else if(state==1&&i+1<row&&zt[i+1][j]==0)
			{
				printf("%d\n",sz[i][j]);
				zt[i][j]=1;
				i++;
			}
			else if(state==1)
			{
				printf("%d\n",sz[i][j]);
				zt[i][j]=1;
				j--;
				state=2;
			}
			else if(state==2&&j-1>=0&&zt[i][j-1]==0)
			{
				printf("%d\n",sz[i][j]);
				zt[i][j]=1;
				j--;
			}
			else if(state==2)
			{
				printf("%d\n",sz[i][j]);
				zt[i][j]=1;
				i--;
				state=3;
			}
			else if(state==3&&i-1>=0&&zt[i-1][j]==0)
			{
				printf("%d\n",sz[i][j]);
				zt[i][j]=1;
				i--;
			}
			else if(state==3)
			{
				printf("%d\n",sz[i][j]);
				zt[i][j]=1;
				j++;
				state=0;
			}
		}
	}
	}
	else if(row==1&&col==1)
	{
		printf("%d\n",sz[0][0]);
	}
	else if(row==1&&col>=2)
	{
		for (i=0; i<col;i++)
		{
			printf("%d\n",sz[0][i]);
		}
	}
	else if(row>=2&&col==1)
	{
		for(i=0;i<row;i++)
		{
			printf("%d\n",sz[i][0]);
		}
	}
	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;               
	int sz[100][100];
	int i,j;
	scanf("%d%d",&row,&col);
	for(j=0;j<row;j++){
		for(i=0;i<col;i++){
			scanf("%d",&sz[j][i]);
		}
	}

	int n;
	int k,I,J,M,N;
	if(col%2==0&&row%2==0){
		if(col<=row){
			n=col/2;
		}else{
			n=row/2;
		}
		for(k=0;k<n;k++){
			for(I=k;I<col-k-1;I++){
		               printf("%d\n",sz[k][I]);
			}
		         for(J=k;J<row-k-1;J++){
			    printf("%d\n",sz[J][col-k-1]);
			}
			for(M=col-k-1;M>k;M--){
			    printf("%d\n",sz[row-k-1][M]);
			}
		         for(N=row-k-1;N>k;N--){
			    printf("%d\n",sz[N][k]);
			}
		}
	}else{
		if(row<=col){
			n=row/2+1;
			for(k=0;k<n;k++){
			    for(I=k;I<col-k-1;I++){
		             printf("%d\n",sz[k][I]);
				}
			    if(2*k<row-1){
			    	for(J=k;J<row-k-1;J++){
			              printf("%d\n",sz[J][col-k-1]);
				}
			    }else{
				for(J=k;J<=row-k-1;J++){
					printf("%d\n",sz[J][col-k-1]);
				}
				break;
			    }
		             for(M=col-k-1;M>k;M--){
			        printf("%d\n",sz[row-k-1][M]);
			    }
		             for(N=row-k-1;N>k;N--){
			        printf("%d\n",sz[N][k]);
			    }
			}
		}else{
			n=col/2+1;
			for(k=0;k<n;k++){
			    for(I=k;I<col-k-1;I++){
		                 printf("%d\n",sz[k][I]);
			    }
			    if(k!=n-1){
		                 for(J=k;J<row-k-1;J++){
			            printf("%d\n",sz[J][col-k-1]);
				}
			     }else{
				for(J=k;J<=row-k-1;J++){
					printf("%d\n",sz[J][col-k-1]);
				}
				break;
			    }
			    for(M=col-k-1;M>k;M--){
			        printf("%d\n",sz[row-k-1][M]);
			    }
		             for(N=row-k-1;N>k;N--){
			        printf("%d\n",sz[N][k]);
			    }
			}
		}
	}
	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 a[100][100],row,col,i,j,k,n;
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++){
		for(j=0;j<col;j++)
			scanf("%d",&a[i][j]);
	}
	if(row>col) n=2*col;
	else if(row<col) n=2*row;
	else n=2*row-1;
	for(k=0;k<n;k++){
		if(k%4==0){
		    for(i=k/4;i<col-k/4;i++)
				printf("%d\n",a[k/4][i]);
		}
        if(k%4==1){
		    for(i=k/4+1;i<row-k/4;i++)
				printf("%d\n",a[i][col-1-k/4]);
		}
        if(k%4==2){
		    for(i=k/4+1;i<col-k/4;i++)
				printf("%d\n",a[row-1-k/4][col-1-i]);
		}
        if(k%4==3){
		    for(i=k/4+1;i<row-k/4-1;i++)
				printf("%d\n",a[row-i-1][k/4]);
		}
	}
	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 array[100][100], row, col, i, j, l, k, m, t, f[100][100]={0};
	cin >> row >> col;
	for ( i = 0; i < row; i ++)
	{
		for ( j = 0; j < col; j ++)
		{
			cin >> array[i][j];
		}
	}
	i = 0;
	m = -1;
	k = row * col;
	while ( k > 0 )
	{
			for ( j = m + 1; j < col; j ++)
			{
				if ( f[i][j] == 0 )
				{
					cout << array[i][j] <<'\n';
					k --;
					f[i][j] = 1;
				}
				else
					break;
			}
			for ( t = i + 1; t < row; t ++)
			{
				if ( f[t][j - 1] == 0 )
				{
					cout << array[t][j - 1] <<'\n';
					k --;
					f[t][j - 1] = 1;
				}
				else
					break;
			}
			for ( l = j - 2; l >= 0; l --)
			{
				if ( f[t - 1][l] == 0 )
				{
					cout << array[t - 1][l] <<'\n';
					k --;
					f[t - 1][l] = 1;
				}
				else 
					break;
			}
			for ( m = t - 2; m >= 0; m --)
			{
				if ( f[m][l + 1] == 0 )
				{
					cout << array[m][l + 1] <<'\n';
					k --;
					f[m][l + 1] = 1;
				}
				else
					break;
			}
			i ++;
	}
	return 0;
}
//*************************************************
//***???????????***
//***??????***
//***???2012.12.24***
//*************************************************
int main ()
{
	int row,col,i,j,n,a[100][100],c;
	cin >> row >> col;
	c = row * col;
	for (i = 0; i < row; i++)
	{
		for (j = 0; j < col; j++)
		{
			cin >> a[i][j];
		}
	}
	if (row >= col)
		n = (col + 1) / 2;
	else
		n = (row + 1) / 2;
	for (i = 0; i < n; i++)
	{
		for (j = i; j < col - i; j++)
		{
			cout << a[i][j] << endl;
			c --;
		}
		if (c == 0)
			break;
		for (j = i + 1; j < row - i; j++)
		{
			cout << a[j][col - i - 1] << endl;
			c--;
		}
		if (c == 0)
			break;
		for (j = col - i - 2; j >= i; j--)
		{
			cout << a[row - i - 1][j] << endl;
			c--;
		}
		if (c == 0)
			break;
		for (j = row - i - 2; j > i; j--)
		{
			cout << a[j][i] << endl;
			c--;
		}
		if (c == 0)
			break;
	}
	return 0;
}
int main()
{
	int a[200][200],b[200][200];
	int i,j,k,l,s;
	int m,n;
	for(i=0;i<200;i++)
	{
		for(j=0;j<200;j++)
		{
			b[i][j]=0;
		}
	}
	scanf("%d%d",&m,&n);
    for(i=1;i<=m;i++)
	{
		for(j=1;j<=n;j++)
		{
			scanf("%d",&a[i][j]);
			b[i][j]=1;
		}
	}
	i=1;
	j=1;
	s=1;
    for(l=0;l<m*n;l++)
	{
		b[i][j]=0;
		printf("%d\n",a[i][j]);
		if(s==1)
		{
			if(b[i][j+1]==1)
			{
				j=j+1;
			}
			else if(b[i][j+1]==0)
			{
				i=i+1;
				s=2;
			}
		}
		else if(s==2)
		{
			if(b[i+1][j]==1)
			{
				i=i+1;
			}
			else
			{
				j=j-1;
				s=3;
			}
		}
		else if(s==3)
		{
			if(b[i][j-1]==1)
			{
				j=j-1;
			}
			else 
			{
				i=i-1;
				s=4;
			}
		}
		else if(s==4)
		{
			if(b[i-1][j]==1)
			{
				i=i-1;
			}
			else 
			{
				j=j+1;
				s=1;
			}
		}
	}
	return 0;
}