semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main()
{
      int row,col,i,j,d=0,count=0;
      int de[]={0,1,2,3};
      scanf("%d%d",&row,&col);
      int a[row][col],b[row][col];
      for(i=0;i<row;i++)
      {
              for(j=0;j<col;j++){scanf("%d",&a[i][j]);b[i][j]=1;}       
      }
      i=0;j=0;
      for(count=0;count<row*col;count++)
      {
                   printf("%d\n",a[i][j]);
                   b[i][j]=0;
                   switch(de[d])
                   {
                    case 0: j++;break;
                    case 1: i++;break;
                    case 2: j--;break;
                    case 3: i--;break;         
                   }
                   if(i<0||i>=row||j<0||j>=col||b[i][j]==0)
             {
                 switch(de[d])
                   {
                    case 0: j--;i++;break;
                    case 1: i--;j--;break;
                    case 2: j++;i--;break;
                    case 3: i++;j++;break;         
                   }
                 d=(d+1)%4;    
             }                       
      }
return 0;
}
//********************************
//*???2.???????? **
//*?????? 1300017623 **
//*???2013.11.1  **
//********************************
int main()
{
	int a[100][100];
	int row, col, i, j;
	cin >> row >> col;
	int i1 = 0, i2 = row - 1, j1 = 0, j2 = col - 1;
	for (i = 0; i < row ; i++)
		for (j = 0; j < col; j++)
			cin >> a[i][j];
	while (1)
	{
		for (j = j1; j <= j2; j++)
			cout << a[i1][j] << endl;
		i1++;
		if (i1 > i2)
			break;
		for (i = i1; i <= i2; i++)
			cout << a[i][j2] << endl;
		j2--;
		if (j1 > j2)
			break;
		for (j = j2; j >= j1; j--)
			cout << a[i2][j] << endl;
		i2--;
		if (i1 > i2)
			break;
		for (i = i2; i >= i1; i--)
			cout << a[i][j1] << endl;
		j1++;
		if(i1 > i2)
			break;
	}

		return 0;
}
int main()
{
	int a[100][100],h,l,i,j,e,b,c,d,t=0;
	scanf("%d %d",&h,&l);
	for(i=0;i<h;i++)
	{
		for(j=0;j<l;j++)
	        scanf("%d",&a[i][j]);
	}
	for(e=0,b=0,c=l,d=h;e<h,b<l,c>=0,d>=0;e++,b++,c--,d--)
	{
	    for(i=e,j=b;j<c;j++)
		printf("%d\n",a[i][j]);
		t+=c-b;
		if(t>=h*l)
			break;
	    for(j=c-1,i=e+1;i<d;i++)
		printf("%d\n",a[i][j]);
		if(t>=h*l)
			break;
		t+=d-e-1;
	    for(i=d-1,j=c-2;j>b-1;j--)
		printf("%d\n",a[i][j]);
		if(t>=h*l)
			break;
		t+=c-b-1;
	    for(j=b,i=d-2;i>e;i--)
		printf("%d\n",a[i][j]);
		t+=d-e-2;
		if(t>=h*l)
			break;
	}
	return 0;
}
int main()
{
	int number[100][100],row=0,col=0,aleft=0,aright=0,bup=0,bdown=0,count=0;      //????
	cin >>row >>col;
	for (int i=0;i<row;i++)                        //????
	{
		for (int j=0;j<col;j++)
			cin >>number[i][j];
	}
	aright=col-1;
	bdown=row-1;
	while(1)                                        //??????????????
	{
		if (count==row*col) break;
		for (int i=aleft;i<=aright;i++)
		{cout <<number[bup][i]<<endl;count++;}
		bup++;
		if (count==row*col) break;
		for (int i=bup;i<=bdown;i++)
		{cout <<number[i][aright]<<endl;count++;}
		aright--;
		if (count==row*col) break;
		for (int i=aright;i>=aleft;i--)
		{cout <<number[bdown][i]<<endl;count++;}
		bdown--;
		if (count==row*col) break;
		for (int i=bdown;i>=bup;i--)
		{cout <<number[i][aleft]<<endl;count++;}
		aleft++;
	}
	return 0;
}
int main()
{
	int a[100][100],m,n,i,j,s=0;
	int (*p)[100];
	p=a;
	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;(i<(m+1)/2)&&(i<(n+1)/2);i++)
	{
		for(j=i;j<n-i;j++)
		{   	
			if(s<n*m)
			printf("%d",*(*(p+i)+j));  
			if(s<n*m-1)
			printf("\n");
			s++;
		}
		for(j=i+1;j<m-i;j++)
		{
			if(s<n*m)
			printf("%d",*(*(p+j)+n-1-i));
		    if(s<n*m-1)
			printf("\n");
			s++;
		}
		for(j=n-i-2;j>=i;j--)
		{
			if(s<n*m)
			printf("%d",*(*(p+m-1-i)+j));		    
			if(s<n*m-1)
			printf("\n");
			s++;		
		}
		for(j=m-i-2;j>i;j--)
		{
			if(s<n*m)
			printf("%d",*(*(p+j)+i));
			if(s<n*m-1)
			printf("\n");
			s++;
		}
	}
     return 0;
}
int main()
{
	int a[100][100],i,j,n,m,flag[100][100]={0},k=0,l=0,num=0,sign=1;
	cin>>n>>m;
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			cin>>a[i][j];
		}
	}
	while(num<m*n)
	{
		cout<<a[k][l]<<endl;
		flag[k][l]=1;
		num++;
		if(sign==1)
		{
			if(l!=m-1&&flag[k][l+1]==0)
			{
				l++;
			}
			else
			{
				sign=2;
				k++;
				continue;
			}
		}
		if(sign==2)
		{
			if(k!=n-1&&flag[k+1][l]==0)
			{
				k++;
			}
			else
			{
				sign=3;
				l--;
				continue;
			}
		}
		if(sign==3)
		{
			if(l!=0&&flag[k][l-1]==0)
			{
				l--;
			}
			else
			{
				sign=4;
				k--;
				continue;
			}
		}
		if(sign==4)
		{
			if(m!=0&&flag[k-1][l]==0)
			{
				k--;
			}
			else
			{
				sign=1;
				l++;
				continue;
			}
		}
	}
	return 0;
}
int main()
{
    
    int row,col;
    cin>>row>>col;
    
    cout<<dec;
    int a[101][101];
    for (int i=1;i<=row;i++) 
        for (int j=1;j<=col;j++)
            cin>>a[i][j];
   
    for (int i=1;i<=row/2 && i<=col/2;i++)
    {
          for (int j=i;j<=col-i;j++) cout<<a[i][j]<<endl;
          for (int j=i;j<=row-i;j++) cout<<a[j][col-i+1]<<endl;
          for (int j=col-i+1;j>=i+1;j--) cout<<a[row-i+1][j]<<endl;
          for (int j=row-i+1;j>=i+1;j--) cout<<a[j][i]<<endl;
    }
          
    if (row%2==1 && row<=col) for (int j=row/2+1;j<=col-row/2;j++) cout<<a[row/2+1][j]<<endl;   
    if (col%2==1 && row>col) for (int j=col/2+1;j<=row-col/2;j++) cout<<a[j][col/2+1]<<endl;   
 
    
    return 0;
}
int main()
{
	int a[100][100]={0},row,col,i=0,j=0,t=0,s=0,isRow,isCol;
	scanf("%d %d",&row,&col);
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
			scanf("%d",&a[i][j]);
	}
	i=0;
	j=0;
	do
	{
		for(j=t;j<col-t;j++)
			printf("%d\n",a[i][j]);
		j-=1;
		isRow = 0;
		for(i=s+1;i<row-s;i++)
		{
			printf("%d\n",a[i][j]);
			isRow = 1;
		}
		if( isRow== 0 )  break;
		i-=1;
		t+=1;
		isCol = 0;
		for(j=col-t-1;j>=s;j--)
		{
			printf("%d\n",a[i][j]);
			isCol = 1;
		}
		if( isCol== 0 )  break;

		j+=1;
		s+=1;
		for(i=row-s-1;i>=t;i--)
			printf("%d\n",a[i][j]);
		i+=1;
	}
	while(t!=col && s!=row);
	return 0;
}
int main()
{
	int n,m;
	int sz[100][100],i,j,a=0,b=0,c=0,d=0,k,kk,kkk,kkkk;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			scanf("%d",&sz[i][j]);
		}
	}
	while(1)
	{
		k=0;
		kk=0;
		kkk=0;
		kkkk=0;
		for(i=a+1;i<=m-c;i++)
		{
			printf("%d\n",sz[b+1-1][i-1]);
			k=1;
		}
		if(k==0)
		{
			break;
		}
		c++;
		for(i=b+2;i<=n-d;i++)
		{
			printf("%d\n",sz[i-1][m-(c-1)-1]);
			kk=1;
		}
		if(kk==0)
		{
			break;
		}
		d++;
		for(i=m-c;i>=a+1;i--)
		{
			printf("%d\n",sz[n-(d-1)-1][i-1]);
			kkk=1;
		}
		if(kkk==0)
		{
			break;
		}
		a++;
		for(i=n-d;i>=b+2;i--)
		{
			printf("%d\n",sz[i-1][a-1]);
			kkkk=1;
		}
		b++;
		if(kkkk==0)
		{
			break;
		}
	}
	return 0;
}
int main()
{
	int i,j,m,n,r,c,k,sz[100][100],time=0;

	scanf("%d%d",&r,&c);

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

	for(i=0,j=0,m=r-1,n=c-1;i<=m&&j<=n;i++,j++,m--,n--){
		for(k=j;k<=n;k++){
			printf("%d\n",sz[i][k]);
			time+=1;
		
		}

		if(time==r*c)break;

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

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

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

	}	
		
	   
	
	
	
	return 0;
}
int main(){
	int s[100][100], a, b, i, j, xx_a, xx_b, sx_a, sx_b , n;
	scanf("%d %d", &a, &b);
	xx_a=0;
	xx_b=0;
	sx_a=a-1;
	sx_b=b-1;
	for(i=0;i<a;i++){
		for(j=0;j<b;j++){
			scanf("%d", &s[i][j]);}}
	while(sx_a>xx_a&&sx_b>xx_b){
		for(j = xx_b; j < sx_b; j++){
			printf("%d\n", s[xx_a][j]);}
		for(i = xx_a; i < sx_a; i++){
			printf("%d\n", s[i][sx_b]);}
		for(j = sx_b; j > xx_b; j--){
			printf("%d\n", s[sx_a][j]);}
		for(i = sx_a; i > xx_a; i--){
			printf("%d\n", s[i][xx_b]);}
		sx_a--;
		sx_b--;
		xx_a++;
		xx_b++;}
	if((a*b)%2!=0){
		if(a<b){
			for(j = xx_a;j <= sx_b;j++){
				printf("%d\n", s[xx_a][j]);}}
		else{
			for(j = xx_b;j <= sx_a;j++){
				printf("%d\n", s[j][xx_b]);}}}
	else if((b%2==0)&&(a%2!=0)&&(b>a)){
		for(j = xx_a;j <= sx_b;j++){
			printf("%d\n", s[xx_a][j]);}}
	else if((a%2==0)&&(b%2!=0)&&(a>b)){
		for(j = xx_b;j <= sx_a;j++){
			printf("%d\n", s[j][xx_b]);}}
	return 0;
}
int main()
{
	int row,col,k=1,num=0,i,j;
	int sz[100][100]={0};
	scanf("%d%d",&i,&j);
	for(row=0;row<i;row++)
	{
		for(col=0;col<j;col++)
		{
			scanf("%d",&sz[row][col]);
		}
	}
	row=-1;
	for(num=0;num<i*j;)
	{
		row+=1;
		for(col=k-1;col<=j-k;col++)
		{
			printf("%d\n",sz[row][col]);
			num+=1;
		}
		col-=1;
		if(num>=i*j)
			break;
		for(row=k;row<=i-k;row++)
		{
			printf("%d\n",sz[row][col]);
		    num+=1;
		}
		row-=1;
        if(num>=i*j)
			break;
		k=k+1;
		for(col=j-k;col>=k-2;col--)
		{
			printf("%d\n",sz[row][col]);
		    num+=1;
		}
		col+=1;
		if(num>=i*j)
			break;
		for(row=i-k;row>=k-1;row--)
		{
			printf("%d\n",sz[row][col]);
			num+=1;
		}
		if(num>=i*j)
			break;
	}
	return 0;
}
int main()
{
	int a[101][101],r,c,b[10000];//??a??????????b????????????
	cin>>r>>c;
	for(int i=0;i<=r-1;i++)//????
		for(int j=0;j<=c-1;j++)
		{
			cin>>a[i][j];
		}
		int e=1,w1=0,w2=0,w3=0,w4=0,p=1;;
		for(int k=1;k<=100000;k++)//?????????????b?
		{
			if(e==1)//??????
			{
				for(int i=w4;i<=c-1-w2;i++)
				{
					b[p]=a[w1][i];
					p=p+1;
				}
				w1++;
				e=2;
				if(w2+w4==c||w1+w3>r)
				{
					for(int j=1;j<=p-1;j++)
						cout<<b[j]<<endl;
					break;
				}
			}
			if(e==2)//??????
			{
				for(int i=w1;i<=r-1-w3;i++)
				{
					b[p]=a[i][c-1-w2];
					p++;
				}
				w2++;
				e=3;
				if(w2+w4>c||w1+w3==r)
				{
					for(int j=1;j<=p-1;j++)
						cout<<b[j]<<endl;
					break;
				}
			}
			if(e==3)//??????
			{
				for(int i=c-w2-1;i>=w4;i--)
				{
					b[p]=a[r-w3-1][i];
					p++;
				}
				w3++;
				e=4;
				if(w2+w4==c||w1+w3>r)
				{
					for(int j=1;j<=p-1;j++)
						cout<<b[j]<<endl;
					break;
				}
			}
			if(e==4)//??????
			{
				for(int i=r-w3-1;i>=w1;i--)
				{
					b[p]=a[i][w4];
					p++;
				}
				w4++;
 				e=1;
				if(w2+w4>c||w1+w3==r)
				{
					for(int j=1;j<=p-1;j++)
						cout<<b[j]<<endl;
					break;
				}
			}
		}
		return 0;
}
int main()
{
    int row,col,a[100][100]={0},k,i,j;
	scanf("%d %d",&row,&col);
	
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			scanf("%d",&a[i][j]);

   i=0;
   j=0;
   k=1;
   printf("%d\n",a[0][0]);
   a[0][0]=0;
   while(1)
   {
   while(1)
   {
	   if(a[i][j+1]!=0)
	   {
		   j++;
	   printf("%d\n",a[i][j]);
	   k++;
	   a[i][j]=0;
	   }
	   else
		   break;
   }
   if(k==row*col)
   {
	   break;
   }
   while(1)
     {
	    if(a[i+1][j]!=0)
		{
			i++;
		printf("%d\n",a[i][j]);
	   k++;
	   a[i][j]=0;
		}
	   else
		   break;
   }
	 if(k==row*col)
	 {
		 break;
	 }
	 while(1)
	 {
	   if(j==0)
		   break;
	   else if(a[i][j-1]!=0)
	   {
		   j--;
	   printf("%d\n",a[i][j]);
	   k++;
	   a[i][j]=0;
	   }
	   else
		   break;
   }
	 if(k==row*col)
		 break;
	 while(1)
	 {
	   if(a[i-1][j]!=0)
	   {
		   i--;
	   printf("%d\n",a[i][j]);
	   k++;
	   a[i][j]=0;
	   }
	   else
		   break;
   }
	 if(k==row*col)
	 {
		 break;
	 }
   }
	
	return 0;
	}
int main(){
    int m,n,x,y,c,d,e,f,g;
	int a[100][100];
	scanf("%d %d",&n,&m);
	g=m*n;
	c=0;
	d=0;
	e=0;
	f=0;
	for(y=0;y<n;y++){
		for(x=0;x<m;x++){
			scanf("%d",&a[x][y]);
		}
	}

    while(g!=0){	
	if(g!=0){
		if(c+d!=m-1){
			for(x=c;x<m-d;x++){
				printf("%d\n",a[x][e]);
				g--;
			}
			e++;
		}else{
			printf("%d\n",a[c][e]);
			g--;
			e++;
		}
	}
	
	if(g!=0){
		if(e+f!=n-1){
			for(y=e;y<n-f;y++){
				printf("%d\n",a[m-d-1][y]);
				g--;
				
			}
			d++;
		}else{
			printf("%d\n",a[m-d-1][e]);
            d++;
			g--;
		}
	}
	
	if(g!=0){
		if(c+d!=m-1){
			for(x=m-d-1;x>=c;x--){
				printf("%d\n",a[x][n-f-1]);
				g--;
			}
			f++;
		}else{
			printf("%d\n",a[c][n-f-1]);
			g--;
			f++;
		}
	}
	if(g!=0){
		if(e+f!=n-1){
			for(y=n-f-1;y>=e;y--){
				printf("%d\n",a[c][y]);
				g--;
				
			}
			c++;
		
		}else{
			printf("%d\n",a[c][e]);
			c++;
			g--;
		}
	}
	}
	
	

	return 0;
}
/*????????
 * bookfee.cpp
 *
 *  Created on: 2011-12-23
 *      Author: WJ
 */

int main() {
	int a[101][101], i, j, row, col;
	cin >> row >> col;
	for (i = 0; i < row; i++)
		for (j = 0; j < col; j++)
			cin >> a[i][j];
	int up = 0, down = row - 1, left = 0, right = col - 1; //??????????
	int c = row * col;//????????????????
	while (c > 0) {
		for (j = left; j <= right; j++) {
			cout << a[up][j] << endl;
		}
		c -= right-left + 1;
		if (c <= 0)
			break;
		up++;

		for (i = up; i <= down; i++) {
			cout << a[i][right] << endl;
		}
		c -= down - up + 1;
		if (c <= 0)
			break;
		right--;

		for (j = right; j >= left; j--) {
			cout << a[down][j] << endl;
		}
		c -= right - left + 1;
		if (c <= 0)
			break;
		down--;

		for (i = down; i >= up; i--) {
			cout << a[i][left] << endl;
		}
		c -= down - up + 1;
		if (c <= 0)
			break;
		left++;
	}
	return 0;
}
int main()
{
    int m,n;
    int q;
    scanf("%d %d",&m,&n);
    q=m*n;
    int sz[100][100];
    int i,j;
    for(i=0;i<m;i++)
    {
         for(j=0;j<n;j++)
        {scanf("%d",&sz[i][j]);}
    }
     int x;
     int p=0;
    for(x=0;x<=(m/2+1)&&x<=(n/2+1);x++)
    {
     for(j=x;j<=(n-x-1)&&x<=(n-x-1)&&p<q;j++)
     {printf("%d\n",sz[x][j]);
     p++;}
     for(i=x+1;i<=(m-x-1)&&(x+1)<=(m-x-1)&&p<q;i++)
     {printf("%d\n",sz[i][n-x-1]);
     p++;}
     for(j=(n-x-2);j>=x&&x<=(n-x-2)&&p<q;j--)
     {printf("%d\n",sz[m-1-x][j]);
     p++;}
     for(i=(m-2-x);i>=(x+1)&&(x+1)<=(m-2-x)&&p<q;i--)
     {printf("%d\n",sz[i][x]);
     p++;}
    }
    return 0;
}
int main()
{
	int row,col;
	scanf("%d %d",&row,&col);
	int sz[100][100];
	int i,j;
	for(i=0;i<row;i++){
		for(j=0;j<col;j++){
			scanf("%d",&sz[i][j]);
		}
	}
	int n,time=0;
	i=0,j=0;
	for(n=0;;n++){
		for(;j<col-n;j++){
			printf("%d\n",sz[i][j]);
			time++;
			}
		if(time==row*col){
				break;
			}
		j--;
		i++;
		for(;i<row-n;i++){
			printf("%d\n",sz[i][j]);
			time++;
			}
		if(time==row*col){
				break;
			}
		i--;
		j--;
		for(;j>n-1;j--){
			printf("%d\n",sz[i][j]);
			time++;
			}
		if(time==row*col){
				break;
			}
		j++;
		i--;
		for(;i>n;i--){
			printf("%d\n",sz[i][j]);
			time++;
			}
		if(time==row*col){
				break;
			}
		i++;
		j++;
	}
	return 0;
}
int main()
{
	int p,row,col,i,k,j,a[100][100];     //row:?,col:?
	cin>>row>>col;
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
			cin>>a[i][j];
	}
	if(col>row)
		p=row/2+row%2;
	else
		p=col/2+col%2;
	for(i=0;i<p;i++)      
	{
	for(k=i;k<col-i;k++)
		cout<<a[i][k]<<endl;
	for(k=i+1;k<row-i;k++)
		cout<<a[k][col-i-1]<<endl;
    if(i!=row-i-1)
	{
	for(k=col-i-2;k>=i;k--)
		cout<<a[row-i-1][k]<<endl;
	}
	if(i!=col-i-1)
	{
	for(k=row-i-2;k>i;k--)
		cout<<a[k][i]<<endl;
	}
	}
	return 0;
	}
//***************************
//**???2.cpp
//**??????
//**???2013.11.1
//**?????????????
//***************************
int main()
{
	int a[100][100];
	int row, col;
	int n = 0; // n??????????

	cin >> row >> col;
	for (int i = 1; i <= row; i++)
		for (int j = 1; j <= col; j++)
			cin >> a[i][j];
	for (int i = 1; i <= (row + 1) / 2; i++)
		for (int j = i; j <= col + 1 - i; j++) // ???????
		{
			if (n == row * col) break; // ???????????????
			cout << a[i][j] << endl;
			n++; // ???????????
			if (j == col + 1 - i)
				for (int k = i + 1; k <= row + 1 - i; k++) // ????????????
				{
					if (n == row * col) break;
					cout << a[k][j] << endl;
					n++;
					if (k == row + 1 - i)
						for (int l = col - i; l >= i; l--) // ?????????????
						{
							if (n == row * col) break;
							cout << a[k][l] << endl;
							n++;
							if (l == i)
								for (int m = row - i; m >= 1 + i; m--) // ????????????
								{
									if (n == row * col) break;
									cout << a[m][l] << endl;
									n++;
								} // ?????????????i??????????????i???????????????????
						}
				}
		}
	return 0;	
}
///********************************
//*???????????   **
//*?????? 1300012745 **
//*???2013.11.1  **
//********************************
int main()
{
	int a[100][100], row, col, i, j,  //row????col????i,j????????row,col???????????????????????????????????? 
		r, c;     // r,c????????????????
	cin >> row >> col;
	for (i = 0; i <= row - 1; i++)    //??????????????
		for (j = 0; j <= col - 1; j++)
			cin >> a[i][j];
	r = 0;
	c = -1;         //??????????????????????????????????
	while ((row >= 2) && (col >= 2))     //?????????2??????????????????????????????????
	{
		for (i = 1; i <= col; i++)       //????col?????????
		{
			c++;
			cout << a[r][c] << endl;
		}
		for (i = 1; i <= row - 1; i++)     //??row-1????????
		{
			r++;
			cout << a[r][c] << endl;
		}
		for (i = 1; i <= col - 1; i++)  //???col-1
		{
			c--;
			cout << a[r][c] << endl;
		}
		for (i = 1; i <= row - 2; i++)   //??row-2?????????????????
		{
			r--;
			cout << a[r][c] << endl;
		}
		col-=2;      //???????????????2??2?
		row-=2;
	}
	if ((row == 1) && (col != 1))      //?????????????????????????????????????????????????????
		for (i = 1; i <= col; i++)   //?????????
		{
			c++;
			cout << a[r][c] << endl;
		}
	if ((col == 1) && (row != 1))   //???????
	{
		c++;
		for (i = 1; i <= row; i++)
		{
			cout << a[r][c] << endl;
			r++;
		}
	}
	if ((row == 1) && (col == 1))   //??????????????row?col???????
		cout << a[r][c+1];
	cin.get();cin.get();
	return 0;
}
int main()
{
	int row,col;
	int i,j;
	int matrix[100][100];

	/*????*/
	cin>>row>>col;
	for (i=1;i<=row;i++)
	{
		for (j=1;j<=col;j++)
		{
			cin>>matrix[i][j];
		}
	}

	/*?????*/
	int k;
	cout<<matrix[1][1];
	for (k=2;k<=col;k++)
	{
		cout<<endl<<matrix[1][k];
	}

	/*??????*/
	int xlength=col-1;
	int ylength=row-1;
	int t;
	char flag='d';
	i=1;j=col;
	while (  ( (flag=='u'||flag=='d')&&(ylength!=0) )
		    ||
			 ( (flag=='l'||flag=='r')&&(xlength!=0) )  )
	{

		switch (flag)
		{
		case 'd':
			for (t=1;t<=ylength;t++)
			{
				i++;
				cout<<endl<<matrix[i][j];
			}
			flag='l';
			ylength--;
			break;
		case 'l':
			for (t=1;t<=xlength;t++)
			{
				j--;
				cout<<endl<<matrix[i][j];
			}
			flag='u';
			xlength--;
			break;
		case 'u':
			for (t=1;t<=ylength;t++)
			{
				i--;
				cout<<endl<<matrix[i][j];
			}
			flag='r';
			ylength--;
			break;
		case 'r':
			for (t=1;t<=xlength;t++)
			{
				j++;
				cout<<endl<<matrix[i][j];
			}
			flag='d';
			xlength--;
			break;
		}
	}
	return 0;
}
int main()
{
	int n,row,col;
	int i,j,a[ROW][COL]={0},time=0;
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	/*
	int width = col;
	int height = row;
	for ( int i = 0; i <= (row - 1) / 2; i++){
		if ( height <= 0 || width <= 0 )
			break;

		for( int j = 0; j < width; j++)
			printf("%d\n", a[i][j+i]);
		if ( height == 1)
			break;
		for( int j = 1; j < height - 1; j++)
			printf("%d\n", a[j+i][i+width-1]);
		for( int j = width - 1; j >= 0; j--)
			printf("%d\n", a[i+height-1][j+i]);
		if( width == 1)
			break;
		for( int j = height - 2; j > 0; j--)
			printf("%d\n", a[j+i][i]);
		width -= 2;
		height -= 2;
		
	}
	*/

	for(n=0; n <= ( row - 1)/2;n++)
	{
		for(i=n;i<col-n;i++)
		{
			printf("%d\n",a[n][i]);
		}
		if ( 2*n +1 == row)
			break;
		for(i=n+1;i<row-n-1;i++)
		{
			printf("%d\n",a[i][col-n-1]);
		}
		for(j=col-n-1;j>=n;j--)
		{
			printf("%d\n",a[row-n-1][j]);
		}
		if ( 2*n +1 == col)
			break;
		for(j=row-n-2;j>n;j--)
		{
			printf("%d\n",a[j][n]);
		}
	}
	return 0;
}
int main()
{
	int row,col,i,j,k;
	int array[100][100];
	cin>>row>>col;
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			cin>>array[i][j];
	if(row%2==0)
		for(k=0;k<row/2;k++)
		{
			if(col-k-1==k)
			{
				for(i=k;i<row-k;i++)
					cout<<array[i][k]<<endl;
				break;
			}
			else
			{if(col-k-1!=k)
				for(i=k;i<col-k-1;i++)
					cout<<array[k][i]<<endl;
			if(k!=row-k-1)
				for(i=k;i<row-k-1;i++)
					cout<<array[i][col-k-1]<<endl;
			else
				cout<<array[k][col-k-1]<<endl;
			if(col-k-1!=k&&k!=row-k-1)
				for(i=col-k-1;i>k;i--)
					cout<<array[row-k-1][i]<<endl;
			if(k!=row-k-1&&col-k-1!=k)
				for(i=row-k-1;i>k;i--)
					cout<<array[i][k]<<endl;}
		}
	else
		for(k=0;k<row/2+1;k++)
		{
			if(col-k-1==k)
			{
				for(i=k;i<row-k;i++)
					cout<<array[i][k]<<endl;
				break;
			}
			else
			{if(col-k-1!=k)
				for(i=k;i<col-k-1;i++)
					cout<<array[k][i]<<endl;
			if(k!=row-k-1)
				for(i=k;i<row-k-1;i++)
					cout<<array[i][col-k-1]<<endl;
			else
				cout<<array[k][col-k-1]<<endl;
			if(col-k-1!=k&&k!=row-k-1)
				for(i=col-k-1;i>k;i--)
					cout<<array[row-k-1][i]<<endl;
			if(k!=row-k-1&&col-k-1!=k)
				for(i=row-k-1;i>k;i--)
					cout<<array[i][k]<<endl;}
		}
	return 0;
}
int main()
{ 
  int row,col,a[100][100],i,j,k,b[100][100];
  cin>>row>>col;
  for(i=0;i<=row-1;i++)
   for(j=0;j<=col-1;j++)
    {cin>>a[i][j];
    b[i][j]=0;}
  if(row==1)
   {for(i=0;i<=col-1;i++)  cout<<a[0][i]<<endl;}
else{
  for(i=0;i<=(col-1)/2;i++)
   {for(k=i;k<=col-i-1;k++)
    {if(b[i][k]==0) {cout<<a[i][k]<<endl;b[i][k]=1;}}
    for(k=i+1;k<=row-2-i;k++)
    {if(b[k][col-1-i]==0) {cout<<a[k][col-1-i]<<endl;b[k][col-1-i]=1;}}
    for(k=col-1-i;k>=i;k--)
    {if(b[row-1-i][k]==0) {cout<<a[row-1-i][k]<<endl;b[row-1-i][k]=1;}}
    for(k=row-2-i;k>=i+1;k--)
    {if(b[k][i]==0) {cout<<a[k][i]<<endl;b[k][i]=1;}}
   }}
 return 0;}
int main()
{
	int row,col,array[100][100][2]={0};  //?????????????????????????????????????????????????????????
	int i,j,time=0;
	cin>>row>>col;
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			cin>>array[i][j][0];
	for(i=0;i<=row/2;i++)  //??????????
	{
		if(time==row*col)
			break;
		for(j=0;j<col;j++)  //??????????????????????????????
		{
			if(array[i][j][1]==0)
			{
				cout<<array[i][j][0]<<endl;
			    array[i][j][1]=1;
				time++;
			}
		}
		for(j=0;j<row;j++)   //????????????????col-1-i(??????)
		{
			if(array[j][col-1-i][1]==0)
			{
				cout<<array[j][col-1-i][0]<<endl;
			    array[j][col-1-i][1]=1;
				time++;
			}
		}
		for(j=col-1;j>=0;j--)  //????????????????row-1-i
		{ 
			if(array[row-1-i][j][1]==0)
			{
				cout<<array[row-1-i][j][0]<<endl;
			    array[row-1-i][j][1]=1;
				time++;
			}
		}
		for(j=row-1;j>=0;j--)  //???????????
		{
			if(array[j][i][1]==0)
			{
				cout<<array[j][i][0]<<endl;
			    array[j][i][1]=1;
				time++;
			}
		}
	}
	return 0;
}
int main()
{
	int a[100][100]={0},row,col,x1,x2,y1,y2,i,j;
	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++)
	{   
		if(i>=((row+1)/2)) break;
        if(i>=((col+1)/2)) break;
		x1=i;x2=row-i-1;y1=i;y2=col-i-1;
		for(y1=y1;y1<=y2;y1++)
		{
			printf("%d\n",a[x1][y1]);
		}
		y1=i;
	
		for(x1=x1+1;x1<=x2;x1++)
		{
			printf("%d\n",a[x1][y2]);
		}
		x1=i;
		if(x1<x2)
		for(y2=y2-1;y2>=y1;y2--)
		{
			printf("%d\n",a[x2][y2]);
		}
        y2=col-1-i;
		if(y1<y2)
		for(x2=x2-1;x2>x1;x2--)
		{
			printf("%d\n",a[x2][y1]);
		}
	
	}
	return 0;
}
int main(){
	int row,col,array[100][100],i,j,l,t,count1,count2;    //??????????100?100???????
	cin>>row>>col;       //??row?col
	for(i=0;i<row;i++)      //????
		for(j=0;j<col;j++)
			cin>>array[i][j];
   for(i=row-1,j=col-1,t=0,count1=row,count2=col;count1>0&&count2>0;count1=count1-2,count2=count2-2,t++)    //???????t??????????count1?count2??????????????????????
	   {
	   /*cout<<"****"<<"count1="<<count1<<' '<<"count2="<<count2<<' '<<"t="<<t<<endl;
	   cout<<"l1="<<l<<endl;*/
	   for(l=t;l<j-t;l++)         //???????????
		   {cout<<array[t][l]<<endl;
		   /*cout<<"***";*/
		   }
	   /*cout<<"l2="<<l<<endl;*/
	   for(l=t;l<i-t;l++)      //??????
		   {cout<<array[l][j-t]<<endl;
		   /*cout<<"***2";*/}
	   if(count1!=1)
	   for(l=j-t;l>t;l--)        //??????
		   {cout<<array[i-t][l]<<endl;
	   /*cout<<"***3";*/}
	   else if(count2!=1)cout<<array[i-t][j-t];
	   if(count2!=1)
	   for(l=i-t;l>t;l--)    //??????
	   { cout<<array[l][t]<<endl;
	   /*cout<<"***4";*/}
	      else if(count1!=1)cout<<array[i-t][t];
	   if(count1==1&&count2==1)
		   cout<<array[t][j-t];
	   /*cout<<'*'<<"count1="<<count1<<' '<<"count2="<<count2<<' '<<"t="<<t<<endl;*/
	   }
   /*cout<<"**"<<"count1="<<count1<<' '<<"count2="<<count2<<' '<<"t="<<t<<endl;*/
   return 0;
}