semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main()
{    int i ,j ,k,row,col;
     int t = 0 ;
    cin >> row >> col;
    int array[row][col];
    for(i = 0; i <= row - 1;i ++)
    {
      for(j = 0; j <= col - 1; j ++)   
       {      
           cin >> array[i][j];
       }
     }
     for( k = 0;;k ++  )
     {
       for(j = 0 + k; j <= col - 1 - k; j ++)
       {
          cout << array[k][j] << endl;
          t ++; 
          if( t == row *col)
            {  break ;
                }
       }
          if ( t == row*col )
          {
               break;
               }
       for(i = 1 + k; i <= row - 1 - k; i ++)
       {
          cout << array[i][col - 1 - k] << endl;
          t ++;  
          if( t == row *col)
            {  break ;
                }
          }
          if( t == row *col)
            {  break ;
                }
       for(j = col - 2 - k; j >= 0 + k; j --)
       {
          cout << array[row - 1 -k][j] << endl;
          t ++;  
           if( t == row *col)
            {  break ;
                }
       }   
                if( t == row *col)
            {  break ;
                }      
       for(i = row - 2 - k; i >= 1 + k; i --) 
       {   cout << array[i][0+k] << endl;
          t ++ ; 
                   if( t == row *col)
            {  break ;
                }           
       }     
        if( t == row *col)
            {  break ;
                }
}
       return 0 ;
}
int main()
{
	int x,y,m,n,i,j,k=0;
	cin>>x>>y;
	m=x;
	if (x>y)
		m=y;
	m=(m+1)/2;
	int max[x][y];
	for (i=0;i<x;i++)
		for (j=0;j<y;j++)
		{
			cin>>max[i][j];
		}

	for (n=0;n<m;n++)
	{	
		i=n;
		for (j=n;j<y-n;j++)
		 	{
            if (k==x*y)
               break;
             cout<<max[i][j]<<endl;
             k++;
            }
		i=y-n;
		j--;
		for (i=n+1;i<x-n;i++)
		    {
           if (k==x*y)
               break;
             cout<<max[i][j]<<endl;
             k++;
             }
		i--;
		for (j--;j>n-1;j--)
		    {
             if (k==x*y)
               break;
             cout<<max[i][j]<<endl;
             k++;
             }
		j++;
		for (i--;i>n;i--)
             {
             if (k==x*y)
               break;
             cout<<max[i][j]<<endl;
             k++;
             }
		
	
	}
	return 0;
}
void main()
{
	int s[100][100],(*p)[100],i,j,b,a,w,q,k,t;
	scanf("%d %d",&a,&b);
	p=s;
	for(i=0;i<=a-1;i++)
	{
		for(j=0;j<=b-1;j++)
		{
			scanf("%d",*(p+i)+j);
			//printf("%d",*(*(p+i)+j));
		}
	}
	t=0;
	if(b!=1)
	{for(i=0;i<=(a-1)/2;i++)
	{
		for(j=i;j<=b-1-i;j++)
		{
			if(t==0)
			{
				printf("%d",*(*(p+i)+j));
				t=1;
			}
			else
			{printf("\n%d",*(*(p+i)+j));
			if(j==b-i-1)
			{
				for(k=i+1;k<=a-1-i;k++)
				{
					printf("\n%d",*(*(p+k)+j));
					if(k==a-1-i)
					{
						for(q=b-i-2;q>=i;q--)
						{
							printf("\n%d",*(*(p+k)+q));
							if(q==i)
							{
								for(w=a-i-2;w>=i+1;w--)
								{
									printf("\n%d",*(*(p+w)+q));
								}
							}
						}
					}
				}
			}
			}
		}
	}
	}
	else
	{
	for(i=0;i<=a-1;i++)
	{
		for(j=0;j<=b-1;j++)
		{
			if(t!=0)
				printf("\n%d",*(*(p+i)+j));
			else
			{printf("%d",*(*(p+i)+j));
			t=1;}//printf("%d",*(*(p+i)+j));
		}
	}
	}
}
int rt1(int x,int y);
int rt2(int x,int y);
int rt3(int x,int y);
int rt4(int x,int y);
int sz[100][100];
int sr[100][100];
int sc[10000];
int p=0,q=0;
int count=0;
int flag=1;
int main()
{
	int m,n;
	scanf("%d%d",&m,&n);
	int i,j;
	for (i=0;i<100;i++)
	{
		for (j=0;j<100;j++)
		{
			sz[i][j]=1;
		}
	}
    	for (i=0;i<m;i++)
	{
		for (j=0;j<n;j++)
		{
			sz[i][j]=-2;
		}
	}
	for (i=0;i<m;i++)
	{
		for (j=0;j<n;j++)
		{
			scanf("%d",&sr[i][j]);
		}
	}
	sz[0][0]=1;
    
	int limit=m*n;
	while (count<=limit-1)
	{
		switch (flag%4)
		{
		case 1:
        {
				(p,q)=rt1(p,q);
				count=count+1;
				break;
		}
		case 2:
			{
				(p,q)=rt2(p,q);
				count=count+1;
				break;
		}
		case 3:
			{
			    (p,q)=rt3(p,q);
				count=count+1;
				break;
		}
		case 0:
				{
				(p,q)=rt4(p,q);
				count=count+1;
				break;
		}
	}

}
	for (i=0;i<m*n;i++)
	{
		
			printf("%d\n",sc[i]);
		
	} 
	return 0;
}
int rt1(int x,int y)
{
	sz[q][p]=sr[q][p];
	sc[count]=sz[q][p];
	p=x+1;
	q=y;
	if (sz[q][p]>0)
		{
		    flag=flag+1;
			p=p-1;
			q=q+1;
		}
	
	return (p,q);
}
int rt2(int x,int y)
{
	sz[q][p]=sr[q][p];
	sc[count]=sz[q][p];
	p=x;
	q=y+1; 
    if (sz[q][p]>0)
	{
		    flag=flag+1;
			q=q-1;
			p=p-1;
		}

	
	return (p,q);

}
int rt3(int x,int y)
{
	sz[q][p]=sr[q][p];
	sc[count]=sz[q][p];
	p=x-1;
	q=y;
	if (sz[q][p]>0)
	{
		    flag=flag+1;
			p=p+1;
			q=q-1;
		}
	
	return (p,q);
}
int rt4(int x,int y)
{
		sz[q][p]=sr[q][p];
		sc[count]=sz[q][p];
	p=x;
	q=y-1;
	if (sz[q][p]>0)
	{
		    flag=flag+1;
			q=q+1;
			p=p+1;
		}
	
	return (p,q);
}
int main()
{
    int num[100][100];
	int row,col;
	scanf("%d%d",&row,&col);
	int i,j;
	int a=0,b=row-1,c=0,d=col-1;
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
		{
            scanf("%d",&num[i][j]);
		}
	}
	do
	{
	  
        i=a;
		for(j=c;j<=d&&a<=b;j++)
		{
		    printf("%d\n",num[i][j]);
		}
		a=a+1;
        j=d;
        for(i=a;i<=b&&c<=d;i++)
		{
			printf("%d\n",num[i][j]);
		}
		d=d-1;
		i=b;
		for(j=d;j>=c&&a<=b;j--)
		{
			printf("%d\n",num[i][j]);
		}
		b=b-1;
		j=c;
		for(i=b;i>=a&&c<=d;i--)
		{
			printf("%d\n",num[i][j]);
		}
		c=c+1;
		/*
		a=a+1;
		b=b-1;
		c=c+1;
		d=d-1;
		*/
	}
	while(a<=b||c<=d);
	return 0;
}
void print(int a[100][100],int row,int col,int b,int c)
{
	int i;
	for(i=c;i<=col;i++)
		printf("%d\n",a[b][i]);
	for(i=b+1;i<=row;i++)
		printf("%d\n",a[i][col]);
	if(row>b)
	for(i=col-1;i>=c;i--)
		printf("%d\n",a[row][i]);
	if(col>c)
	for(i=row-1;i>=b+1;i--)
		printf("%d\n",a[i][c]);
	row--;
	col--;
	b++;
	c++;
	if(row-b>=0&&col-c>=0)
		print(a,row,col,b,c);
	
}
void main()
{
	int col,row,i,j,a[100][100];
	scanf("%d %d",&row,&col);
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			scanf("%d",&a[i][j]);
	print(a,row-1,col-1,0,0);
}
int main(){
int m,n,i,k,s,q,w,e,r;
scanf("%d%d",&n,&m);
int a[n][m];
for(i=0;i<n;i++){
for(k=0;k<m;k++){
scanf("%d",&(a[i][k]));
}
}
s=0;
for(k=0;s<=m*n;k++){
for(q=k;q<=m-k-1;q++){
printf("%d\n",a[k][q]);
s=s+1;
}
if(s==m*n){
break;
}
for(w=k+1;w<=n-k-1;w++){
printf("%d\n",a[w][m-k-1]);
s=s+1;
}
if(s==m*n){
break;
}
for(e=m-k-2;e>=k;e--){
printf("%d\n",a[n-k-1][e]);
s=s+1;
}
if(s==m*n){
break;
}
for(r=n-k-2;r>=k+1;r--){
printf("%d\n",a[r][k]);
s=s+1;
}
if(s==m*n){
break;
}
}
return 0;
}
void main()
{
	void toy(int b[100][100],int c,int d);
	int a[100][100];
	int n,m,i,j;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
			scanf("%d",&a[i][j]);
	}
	toy(a,n,m);
}
void toy(int b[100][100],int c,int d)
{
	int k,l,t;
	if(c==1)
	{for(k=0;k<d;k++)
	printf("%d\n",b[0][k]);
	}
	else if(c==2)
	{
		for(k=0;k<d;k++)
	printf("%d\n",b[0][k]);
		for(k=d-1;k>=0;k--)
	printf("%d\n",b[1][k]);
	}
	else if(d==1)
	{
		for(k=0;k<c;k++)
	printf("%d\n",b[k][0]);
	}
	else if(d==2)
	{
	for(k=0;k<c;k++)
	printf("%d\n",b[k][0]);
		for(k=c-1;k>=0;k--)
	printf("%d\n",b[k][1]);
	}
	else
	{
		for(k=0;k<d;k++)
	        printf("%d\n",b[0][k]);
		for(k=1;k<c-1;k++)
			printf("%d\n",b[k][d-1]);
		for(k=d-1;k>=0;k--)
         	printf("%d\n",b[c-1][k]);
		for(k=c-2;k>=1;k--)
            printf("%d\n",b[k][0]);
		for(l=0;l<c-2;l++)
		{
			for(t=0;t<d-2;t++)
				b[l][t]=b[l+1][t+1];
		}
		toy(b,c-2,d-2);
	}
}
int sz[100][100];
int main(){
	int n,m,i,j,k,a1,a2,b1,b2;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&sz[i][j]);
		}
	}

	for(k=0;;k++){	
		a1=k;
		a2=m-1-k;
		b1=k;
		b2=n-1-k;
		if(a1>a2||b1>b2){
			break;
		}
		if(a1==a2&&b1!=b2){
			for(i=b1;i<=b2;i++){
				printf("%d\n",sz[i][a1]);
			}
		}else if(b1==b2){
			for(j=a1;j<=a2;j++){
				printf("%d\n",sz[b1][j]);
			}
		}else if(b1==b2&&a1==a2){
			printf("%d\n",sz[b1][a1]);
		}else{
			for(j=a1;j<=a2;j++){
				printf("%d\n",sz[b1][j]);
			}
			for(i=b1+1;i<=b2;i++){
				printf("%d\n",sz[i][a2]);
			}
			for(j=a2-1;j>=a1;j--){
				printf("%d\n",sz[b2][j]);
			}
			for(i=b2-1;i>=b1+1;i--){
				printf("%d\n",sz[i][a1]);
			}
		}
	}
	return 0;
}
int main()
{
    int row,col,i,j,l,p,q,count;
	int a[100][100];
	cin>>row>>col;
	p=(row+1)/2;
	q=(col+1)/2;
	count=0;
	for(i=1;i<=row;i++)
    {
	    for(j=1;j<=col;j++)
		{
		    cin>>a[i][j];
		}
	}  
	if(row<=col&&row%2==1)
	{
		for(i=1;i<=row/2;i++)
		{
	        for(j=i;j<=col-i+1;j++)
			 {cout<<a[i][j]<<endl;count++;}
			 for(l=i+1;l<=row-i+1;l++)
             {cout<<a[l][col-i+1]<<endl;count++;}
			 for(j=col-i;j>=i;j--)
			 {cout<<a[row-i+1][j]<<endl;count++;}
			 for(l=row-i;l>=i+1;l--)
			 {cout<<a[l][i]<<endl;count++;}
		}
		for(j=(row+1)/2;j<=col-(row-1)/2;j++)
		{cout<<a[p][j]<<endl;}
	}
	else if(row>col&&col%2==1)
		{
	    for(i=1;i<=col/2;i++)
		{
	        for(j=i;j<=col-i+1;j++)
			 {cout<<a[i][j]<<endl;count++;}
			 for(l=i+1;l<=row-i+1;l++)
             {cout<<a[l][col-i+1]<<endl;count++;}
			 for(j=col-i;j>=i;j--)
			 {cout<<a[row-i+1][j]<<endl;count++;}
			 for(l=row-i;l>=i+1;l--)
			 {cout<<a[l][i]<<endl;count++;}
		}
		for(i=(col+1)/2;i<=row-(col-1)/2;i++)
		{cout<<a[i][q]<<endl;}
		}
	else
	{
	for(i=1;i<=row/2;i++)
	{
	     if(count==row*col)break;
		 else
		 {
		     for(j=i;j<=col-i+1;j++)
			 {cout<<a[i][j]<<endl;count++;}
			 for(l=i+1;l<=row-i+1;l++)
             {cout<<a[l][col-i+1]<<endl;count++;}
			 for(j=col-i;j>=i;j--)
			 {cout<<a[row-i+1][j]<<endl;count++;}
			 for(l=row-i;l>=i+1;l--)
			 {cout<<a[l][i]<<endl;count++;}
		 }
	}
	}
	return 0;
}
int main()
{
	int x,y,p=1,q=1;
	double a[200][200];
	scanf("%d %d",&x,&y);
	for(p=1;p<=x;p++)
		for(q=1;q<=y;q++)
			scanf("%lf",&a[p][q]);
	for(q=0;q<=y;q++)
	        a[0][q]=0.5;
    for(q=0;q<=y;q++)
          a[x+1][q]=0.5;
    for(p=1;p<=x;p++)
            a[p][0]=0.5;
    for(p=1;p<=x;p++)
            a[p][y+1]=0.5;
	int i=1,j=1;
    while(a[i][j]-floor(a[i][j])==0)
	   {
          printf("%.0lf\n",a[i][j]);
	      a[i][j]=0.5;
        if(a[i][j+1]-floor(a[i][j+1])==0&&a[i+1][j]-floor(a[i+1][j])==0||a[i][j+1]-floor(a[i][j+1])==0&&a[i+1][j]-floor(a[i+1][j])!=0&&a[i-1][j]-floor(a[i-1][j])!=0)
            j=j+1;
		else if(a[i+1][j]-floor(a[i+1][j])==0)
			 i=i+1;
		      else if(a[i][j-1]-floor(a[i][j-1])==0)
			        j=j-1;
			        else if(a[i-1][j]-floor(a[i-1][j])==0)
			              i=i-1;
		                 else break;
	   }
  getchar();
  getchar();
return 0;
}
int main(int argc, char* argv[])
{ 
	int row,col,k,e,i,j,min;
	int 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]);
		}
	}
	if(col>row){
	min=row;
	}else{
	min=col;
	}
	for(e=0;e<min/2+1;e++){
	for(j=e;j<col-e;j++){
		printf("%d\n",sz[e][j]);
	}if(row%2==1&&e+1>row-2-e){
	break;
	}
	for(i=e+1;i<row-e;i++){
		printf("%d\n",sz[i][col-1-e]);
	}
	if(col%2==1&&e>col-2-e){
	break;
	}
	for(j=col-2-e;j>=e;j--){
		printf("%d\n",sz[row-1-e][j]);
	}
	
	for(i=row-2-e;i>e;i--){
		printf("%d\n",sz[i][e]);
	}}
	return 0;
}
int main()
{
	int a[101][101],i,j,k=0,l=1,m,n,c,d;//???????
	cin>>m>>n;//?????????
	c=m,d=n;//?m,n????c,d
	for(i=1;i<=m;i++)
		for(j=1;j<=n;j++)
			cin>>a[i][j];//??????
	j=0;//?j=0
	while(j<c*d)//?j<c*d?
	{
		for(i=l;i<=n;i++)
		{
			if(j>=c*d)break;//??j>=c*d,????
			cout<<a[k+1][i]<<endl;//??a[k+1][i]
			j=j+1;//j=j+1
			
		}
		for(k=i-1,i=l+1;i<=m;i++)
		{
			if(j>=c*d)break;//??j>=c*d,????
			cout<<a[i][k]<<endl;//??a[i][k]
			j=j+1;//j=j+1
			
		}
		for(k=i-1,i=n-1;i>=l;i--)
		{
			if(j>=c*d)break;//??j>=c*d,????
			cout<<a[k][i]<<endl;//??a[k][i]
			j=j+1;//j=j+1
			
		}
		for(k=i+1,i=m-1;i>=l+1;i--)
		{
			if(j>=c*d)break;//??j>=c*d,????
			cout<<a[i][k]<<endl;//??a[i][k]
			j=j+1;//j=j+1
			
		}
		n=n-1;m=m-1;l=l+1;
	}
	return 0;
}
int main(){
    int a,b,c,d,m,n,i,j,k;
    int e[MAX][MAX];
    int q[4]={1,0,-1,0};
    int w[4]={0,1,0,-1};
    scanf("%d%d",&m,&n);
    for(i=0;i<m;i++){
        for(j=0;j<n;j++){
            scanf("%d",&e[i][j]);
        }
    }
    for(i=0,a=q[0],b=w[0],j=0,k=0;i<m*n;i++,j+=b,k+=a){
        printf("%d\n",e[j][k]);
        if(a==q[0]&&b==w[0]&&j+k==n-1){
            a=q[1];
            b=w[1];
        }
         else if(a==q[1]&&b==w[1]&&j-k==m-n){
            a=q[2];
            b=w[2];
        }
         else if(a==q[2]&&b==w[2]&&j+k==m-1){
            a=q[3];
            b=w[3];
        }
           else if(a==q[3]&&b==w[3]&&j==k+1){
            a=q[0];
            b=w[0];
        }
    }
	return 0;
}
int main()
{
	int array[100][100], i, j, row, col, num, s, k;
	scanf("%d %d",&row,&col);
	if(row>0 && row<100 && col>0 && col<100)
	{
		for(i=0; i<row; i++)
		{
			for(j=0; j<col; j++)
				scanf("%d",&array[i][j]);
		}

		for(i=0, j=0, num=0; num<row*col; i++, j++)	//????row*col???????
		{
			for(s=j; s<=(col-j-1); s++)
			{
				printf("%d\n",array[i][s]);//???i????
				num++;
				if(num>=row*col)
					break;
			}
			if(num>=row*col)
				break;
			for(k=i+1; k<(row-i-1); k++)
			{
				printf("%d\n",array[k][col-j-1]);
				num++;			
				if(num>=row*col)
					break;
			}
			if(num>=row*col)
				break;
			for(s=col-j-1; s>j; s--)
			{
				printf("%d\n",array[row-i-1][s]);
				num++;
				if(num>=row*col)
					break;
			}
			if(num>=row*col)
				break;
			for(k=row-i-1; k>i; k--)
			{
				printf("%d\n",array[k][j]);//??????
				num++;
				if(num>=row*col)
					break;
			}
			if(num>=row*col)
				break;

		}
	}
	return 0;
}
int main ()
{
	int a[110][110];
	int row, col, i, j, k, h, l, count, hzz, lzz; // h ?row l? col
	cin >> row >> col;
	for (i = 1; i <= row; i++)
	{
		for (j = 1; j <= col; j++)
		{
			cin >> a[i][j];
		}
	}
	// ??? ???i? ? i ??? lzz?? ??i????? row - i + 1 ? col - ?i - 1?
	// ?lzz?i ? ????i??? col - i + 1?
	// ?hzz?j ? ????j++??? row - j + 1?
	// ?lzz?col - i + 1??lzz-- ??? col - hzz + 1?
	// ?hzz?j? ? hzz???  row - hzz + 2 ?
    // ?????????????
	count = 0;
	h = row;
	l = col;
	hzz = 1;
	lzz = 1;
	i = 1;
	j = 1;
	while (count <= row * col)
	{
		for (lzz = j; lzz <= col - (j - 1); lzz++)   //???????
		{
			cout << a[i][lzz] << endl;
			count++;
			if (count == row * col) return 0; 
		} 
		j = lzz - 1;   //?????????lzz+1
		for (hzz = i + 1; hzz <= row - i + 1; hzz++) // ?????
		{
			cout << a[hzz][j] << endl;
			count++;
        	if (count == row * col) return 0; 
		}
		i = hzz - 1;
		for (lzz = j - 1; lzz >= col - j + 1; lzz--)
		{
			cout << a[i][lzz] << endl;
			count++;
	        if (count == row * col) return 0; 
		}
		j = lzz + 1;
		for (hzz = i - 1; hzz >= row - i + 2; hzz--)
		{
			cout << a[hzz][j] << endl;
            count++;
	        if (count == row * col) return 0; 
		}
		j = j + 1;
		i = hzz + 1;
	}
	return 0;
}
int main (){
    int r,c,i,k,j,p;
    scanf("%d %d",&r,&c);
    int a[1000][1000];
    for(i=0;i<r;i++){
        for(k=0;k<c;k++){
            scanf("%d",&a[i][k]);
        }
    }
    int s=0;
    int h=0;
    i=0;
    j=0;
    p=r*c;
    while(j<p){
     for(i=s,k=h;k<c;k++){
         if(j<p){
         printf("%d\n",a[i][k]);
         j++;
         }
     }
     s++;
     for(i=s,k=c-1;i<r;i++){
         if(j<p){
         printf("%d\n",a[i][k]);
         j++;
         }
     }
     c--;
     for(k=c-1,i=r-1;k>=h;k--){
         if(j<p){
         printf("%d\n",a[i][k]);
         j++;
         }
     }
     r--;
     for(i=r-1,k=h;i>=s;i--){
         if(j<p){
             printf("%d\n",a[i][k]);
             j++;
         }
     }
     h++;
     }
    return 0;
}
int main()
{
	int n,m,M,N,i,t,e,k,s[200][200];
	scanf("%d%d", &N, &M);
	t=M*N;
	e=0;
	for(n=0;n<N;n++)
	{
		for(m=0;m<M;m++)
		{		
			scanf("%d", &s[n][m]);
		}
	}
	for(k=0;k<103;k++)
	{
		for(i=k;i<M-k;i++)
		{
			printf("%d\n", s[k][i]);
			e++;
		}
		if(e==t)
		{
			break;
		}
		for(i=k+1;i<N-k;i++)
		{
			printf("%d\n", s[i][M-k-1]);
			e++;
		}
		if(e==t)
		{
			break;
		}
		for(i=M-k-2;i>k-1;i--)
		{
			printf("%d\n", s[N-k-1][i]);
			e++;
		}
		if(e==t)
		{
			break;
		}
		for(i=N-k-2;i>k;i--)
		{
			printf("%d\n", s[i][k]);
			e++;
		}
		if(e==t)
		{
			break;
		}
	}
	return 0;
}
int main(){
int row,col,i,j,time=0,n,a[100][100],max;
	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){
		max=row;
	}
	else{
		max=col;
	}
	for(n=0;n<max;n++){
		for(j=n;j<col-n;j++){
			printf("%d\n",a[n][j]);
			time++;
		}
			if(time==row*col){
				break;
			}
		for(i=n+1;i<row-n;i++){
			printf("%d\n",a[i][col-n-1]);
			time++;
		}
			if(time==row*col){
				break;
			}
		for(j=col-n-2;j>=n;j--){
			printf("%d\n",a[row-1-n][j]);
			time++;
		}
			if(time==row*col){
				break;
			}
		for(i=row-n-2;i>n;i--){
			printf("%d\n",a[i][n]);
			time++;
		}
			if(time==row*col){
				break;
		}
	}
	return 0;
}
int main(){
	int ROW,COL,a[100][100];
	scanf("%d%d",&ROW,&COL);
	for(int row=0;row<ROW;row++){
		for(int col=0;col<COL;col++){
			scanf("%d",&a[row][col]);
		}
	}
	for(int k=0;k<(ROW<COL?(ROW+1)/2:(COL+1)/2);k++){
		for(int col=k;col<COL-k-1;col++){
			printf("%d\n",a[k][col]);
		}
		for(int row=k;row<ROW-k-1;row++){
			printf("%d\n",a[row][COL-k-1]);
		}
		for(int col=COL-k-1;(col>k)&&(k!=1.0*(ROW+1)/2-1);col--){
			printf("%d\n",a[ROW-k-1][col]);
		}
		for(int row=ROW-k-1;(row>k)&&(k!=1.0*(COL+1)/2-1);row--){
			printf("%d\n",a[row][k]);
		}
	}
	if((ROW%2!=0&&ROW<=COL)||(COL%2!=0&&COL<=ROW)){
		printf("%d",a[ROW-(ROW<COL?(ROW+1)/2:(COL+1)/2)][COL-(ROW<COL?(ROW+1)/2:(COL+1)/2)]);
	}
	return 0;
}
int main()
{
    int row,col;
    int i,j,n,time=0;
    scanf("%d%d",&row,&col);
    int array[R][C];
    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-1;i++)
  {
   printf("%d\n",array[n][i]);
   time++;
  }
  if(time==row*col) break;
  for(j=n+1;j<=row-n-1;j++)
  {
   printf("%d\n",array[j][col-n-1]);
   time++;
  }
  if(time==row*col) break;
  for(i=col-n-2;i>=n;i--)
  {
   printf("%d\n",array[row-n-1][i]);
   time++;
  }
  if(time==row*col) break;
  for(j=row-n-2;j>=n+1;j--)
  {
   printf("%d\n",array[j][n]);
   time++;
  }
  if(time==row*col) break;
 }
 return 0;
}
int rp,re,lp,le;
int a[300][300];
int print(int rp,int re,int lp,int le,int r,int l)
{
	int i,j;
	if(rp>re||lp>le) return 0;
	if(l==lp&&r==rp)
	{
		for(i=rp,j=lp;j<=le;j++)
			printf("%d\n",a[i][j]);
		print(rp+1,re,lp,le,rp+1,le);
		return 0;
	}
	if(l==le&&r==rp)
	{
		for(i=rp,j=le;i<=re;i++)
			printf("%d\n",a[i][j]);
		print(rp,re,lp,le-1,re,le-1);
		return 0;
	}
	if(l==le&&r==re)
	{
		for(i=re,j=le;j>=lp;j--)
			printf("%d\n",a[i][j]);
		print(rp,re-1,lp,le,re-1,lp);
		return 0;
	}
	if(l==lp&&r==re)
	{
		for(i=re,j=lp;i>=rp;i--)
			printf("%d\n",a[i][j]);
		print(rp,re,lp+1,le,rp,lp+1);
		return 0;
	}
}
int main()
{
	
	int r,l;
	scanf("%d %d",&r,&l);
	int i,j;
	for(i=1;i<=r;i++)
		for(j=1;j<=l;j++)
			scanf("%d",&a[i][j]);
	rp=1;
	lp=1;
	re=r;
	le=l;
	print(rp,re,lp,le,1,1);
	return 0;
}
int main()
{
int a[100][100];
int i,j,m,n,k,s=0,x,y;
double l=0;
scanf("%d %d",&m,&n);
for(i=0;i<m;i++)
   {
       for(j=0;j<n;j++)
       scanf("%d",&a[i][j]);         
   }
i=0;
for(j=0;j<n;j++)
   { 
       printf("%d\n",a[i][j]);
       s++;
       if(s==m*n)
       return 0;
   }
i=0;
j=n-1;
for(k=1;k>0;k++)
   {   
       for(x=m-k;x>0;x--)
           {
               i+=(int)pow(-1,l);
               printf("%d\n",a[i][j]);
               s++;
               if(s==m*n)
               return 0;
           }
       for(x=n-k;x>0;x--)         
           {
               j+=(int)pow(-1,l+1);
               printf("%d\n",a[i][j]);
               s++;
               if(s==m*n)
               return 0;
           } 
       l++; 
   }
}
int array[99][99];
int x, y, row, col;
void out(int x0, int y0, int wid, int len)
{
	x = x0;
	y = y0;
	for (; x < x0 + wid; x++)
	{
		cout << array[x][y] << endl;
	}
	x--;
	for (y++; y < y0 + len; y++)
	{
		cout << array[x][y] << endl;
	}
	y--;
	for (x--; x >= x0; x--)
	{
		if (wid == 1)
		{
			break;
		}
		if (len == 1)
		{
			break;
		}
		cout << array[x][y] << endl;
	}
	x++;
	for (y--; y > y0; y--)
	{
		if (wid == 1)
		{
			break;
		}
		if (len == 1)
		{
			break;
		}
		cout << array[x][y] << endl;
	}
	y++;
	if (wid <= 2 || len <= 2)
	{
		1;
	}
	else
	{
		out(x0 + 1, y0 + 1, wid - 2, len - 2);
	}
}

int main()
{
	cin >> row >> col;
	for (y = 0; y < row; y++)
	{
		for (x = 0; x < col; x++)
		{
			cin >> array[x][y];
		}
	}
	out(0, 0, col, row);
	return 0;
}
int main()
{
	int array[100][100];
	int row,col,m,n;
	scanf("%d%d",&m,&n);
	int a,x,y,z=0;
	for(row=0;row<m;row++){
		for(col=0;col<n;col++){
			scanf("%d",&array[row][col]);
		}
	}
	for(a=0;a<m+1/2&&a<n+1/2;a++){
		x=m-a;
		y=n-a;
		for(col=a;col<y;col++){
			printf("%d\n",array[a][col]);
			z+=1;
		}
		if(z>=m*n){
	break;
		}
		for(row=a+1;row<x;row++){
			printf("%d\n",array[row][y-1]);
			z+=1;
		}
		if(z>=m*n){
	break;
		}
		for(col=y-2;col>a-1;col--){
			printf("%d\n",array[x-1][col]);
			z+=1;
		}
		if(z>=m*n){
	break;
		}
		for(row=x-2;row>a;row--){
			printf("%d\n",array[row][a]);
			z+=1;
		}
		if(z>=m*n){
	break;
		}
	}
	return 0;
}
int main()
{
	int i,j,sum=0,c,e,f,m,n,a[100][100];
	scanf("%d %d",&m,&n);
	for(i=0;i<m;i++){
		scanf("%d",&a[i][0]);
		for(j=1;j<n;j++){
			scanf(" %d",&a[i][j]);
		}
	}
	for(c=0,e=m,f=n;;c++,e--,f--){
		for(j=c;j<f;j++){
			printf("%d\n",a[c][j]);
			sum++;
		}
		if(sum==m*n)
			break;
		for(i=c+1;i<e;i++){
			printf("%d\n",a[i][f-1]);
			sum++;
		}
		if(sum==m*n)
			break;
		for(j=f-2;j>c-1;j--){
			printf("%d\n",a[e-1][j]);
			sum++;
		}
		if(sum==m*n)
			break;
		for(i=e-2;i>c;i--){
			printf("%d\n",a[i][c]);
			sum++;
		}
		if(sum==m*n)
			break;
	}
	return 0;
}
int main(){
   int s[100][100];
   int i=0,j,r,R,C,c,q;
   scanf("%d%d",&R,&C);
   for(r=0;r<R;r++){
       for(c=0;c<C;c++){
           scanf("%d",&s[r][c]);
       }
   }
   for(q=0;i<R*C;q++){
       for(j=q;j<C-q;j++){                
           printf("%d\n",s[q][j]);
           i++;
           if(i==R*C)
             return 0;
       }
       for(j=q+1;j<R-q;j++){
           printf("%d\n",s[j][C-1-q]);
           i++;
           if(i==R*C)
             return 0;
       }
       for(j=C-2-q;j>q-1;j--){
           printf("%d\n",s[R-1-q][j]);
           i++;
          if(i==R*C)
          return 0;
       }
       for(j=R-2-q;j>q;j--){
             printf("%d\n",s[j][q]);
             i++;
             if(i==R*C)
             return 0;
       }
       
   }
   return 0;
}
void circle(int list[][100], int row_min, int row_max, int col_min, int col_max)
{
  int i,j;
  if (row_min==row_max || col_min==col_max) {
    for (i=col_min; i<col_max; i++) {
      printf("%d\n",list[row_min][i]);
    }
    for (i=row_min; i<=row_max; i++) {
      printf("%d\n",list[i][col_max]);
    }
  } else {
    for (i=col_min; i<col_max; i++) {
      printf("%d\n",list[row_min][i]);
    }
    for (i=row_min; i<row_max; i++) {
      printf("%d\n",list[i][col_max]);
    }
    for (i=col_max; i>col_min; i--) {
      printf("%d\n",list[row_max][i]);
    }
    for (i=row_max; i>row_min; i--) {
      printf("%d\n",list[i][col_min]);
    }
  }
}

int main() 
{
  int array[100][100];
  int i,j;
  int sumrow,sumcol;
  scanf("%d %d",&sumrow,&sumcol);
  for (i=0; i<sumrow; i++) {
    for (j=0; j<sumcol; j++) {
      scanf("%d",&array[i][j]);
    }
  }

  int row_min=0, row_max=sumrow-1, col_min=0, col_max=sumcol-1;

  while (row_min<=row_max && col_min<=col_max) {
    circle(array, row_min, row_max, col_min, col_max);
    row_min++;
    row_max--;
    col_min++;
    col_max--;
  }
  
  return 0;
}