semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int a[2000][2000];

void print(int h,int l)
{
    int i,j;
	for(j=0;j<l;j++)
	{printf("%d\n",a[0][j]);}
	for(i=1;i<h;i++)
	{printf("%d\n",a[i][l-1]);}
	for(j=l-2;j>=0;j--)
	{printf("%d\n",a[h-1][j]);}
	for(i=h-2;i>0;i--)
	{printf("%d\n",a[i][0]);}
}
void gai(int h,int l)
{
	int i,j;
	for(i=0;i<h-1;i++)
	{
		for(j=0;j<l-2;j++)
		{
			a[i][j]=a[i][j+1];
		}
	}
	for(j=0;j<l-2;j++)
	{
		for(i=0;i<h-2;i++)
		{
			a[i][j]=a[i+1][j];
		}
	}
}

void main()
{
	int i,j,h,l;
	scanf("%d %d",&h,&l);
	for(i=0;i<h;i++)
	{
		for(j=0;j<l;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	for( ;(h>1&&l>1);h=h-2,l=l-2)
	{
		print(h,l);
	    gai(h,l);
	}
	
	if(h==1&&l>1)
	{
		for(j=0;j<l;j++) printf("%d\n",a[0][j]);
	}
	else if(l==1&&h>1)
	{
        for(i=0;i<h;i++) printf("%d\n",a[i][0]);
	}
	else if(h==1&&l==1)
	{
		printf("%d\n",a[0][0]);
	}
}
int main(){
	int sz[100][100];
	int m,n;
	scanf("%d %d",&m,&n);
	int i,j,p,m1,n1;
	for(i=0;i<m;i++){
		for(j=0;j<n;j++){
			scanf("%d",&sz[i][j]);
			}
	}
	int a = m > n ? n : m;

	for(p=0;p<a/2;p++){
		for(m1=p,n1=p;n1<n-1-p;n1++){
		    printf("%d\n",sz[m1][n1]);
		}
		//printf("--> end\n");
        for(n1=n-1-p,m1=p;m1<m-1-p;m1++){
			printf("%d\n",sz[m1][n1]);
		}
		//printf("|v end\n");
		if(m-1-p!=p)
		{
			for(m1=m-1-p,n1=n-1-p;n1>p;n1--){
				printf("%d\n",sz[m1][n1]);
			}
			//printf("<--- end\n");
		}
		if(n-1-p!=p)
		{
			for(n1=p,m1=m-1-p;m1>=p+1;m1--){
				printf("%d\n",sz[m1][n1]);
			}
			//printf("^| end\n");
		}
	}
	//printf("p=%d\n", p);
	if (m-1-p == p) {
		for (int i = p; i <= n-1-p; i++) 
			printf("%d\n", sz[p][i]);
	} else if (n-1-p == p) {
		for (int i = p; i <= m-1-p; i++)
			printf("%d\n", sz[i][p]);
	}
	return 0;
}
//********************************
//*???????????   **
//*?????? 1300012713 **
//*???2013.11.01  **
//********************************
int main() 
{ 
	int row, col, a[100][100];
	int time = 0;
	cin >> row >> col;
	for(int x = 1; x <= row; x++) 
	{
		for(int y = 1; y <= col; y++)
		{
			cin >> a[x-1][y-1];
		}
	}
	for(int i = 0;time< row*col;i++)
	{
		for(int j = i; j <= col-i-1 && time < row*col; j++)
		{   cout << a[i][j];
		    if(time < row*col-1) cout << "\n";
			time++;}
		for(int k = i + 1; k <= row-i-1 && time < row*col; k++)
		{   cout << a[k][col-i-1];
		    if(time < row*col-1) cout << "\n";
			time++;}
		for(int l = col-i-2; l>=i && time < row*col; l--)
		{   cout << a[row-i-1][l];
		    if(time < row*col-1) cout << "\n";
			time++;}
		for(int m = row-i-2; m>i && time < row*col; m--)
		{   cout << a[m][i];
		    if(time < row*col-1) cout << "\n";
			time++;} 
	}
	return 0;
}
int main()
{
	int row,col,i,j,a[100][100],xxrow,sxrow,xxcol,sxcol;
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++){
		for(j=0;j<col;j++)
			scanf("%d",&a[i][j]);
	}
	xxrow=0;
	sxrow=row-1;
	xxcol=0;
	sxcol=col-1;
    for(;1;){
		if(xxrow==sxrow&&xxcol<=sxcol){
			for(i=xxcol;i<=sxcol;i++)
				printf("%d\n",a[xxrow][i]);
			break;
		}
		else if(xxcol==sxcol&&xxrow<sxrow){
			for(i=xxrow;i<=sxrow;i++)
				printf("%d\n",a[i][xxcol]);
			break;
		}
		if(xxcol>sxcol||xxrow>sxrow)
			break;
		for(i=xxcol;i<=sxcol-1;i++)
			printf("%d\n",a[xxrow][i]);
		for(i=xxrow;i<=sxrow-1;i++)
			printf("%d\n",a[i][sxcol]);
		for(i=sxcol;i>=xxcol+1;i--)
			printf("%d\n",a[sxrow][i]);
		for(i=sxrow;i>=xxrow+1;i--)
			printf("%d\n",a[i][xxcol]);
		xxrow++;
		xxcol++;
		sxrow--;
		sxcol--;
	}
	return 0;
}
int main(){
int m,n,sz[100][100],x,y,z,f,g,w,k;
scanf("%d %d",&m,&n);
for(int p=0;p<m;p++){
    for(int q=0;q<n;q++){
	   scanf("%d",&sz[p][q]);
	}
}
for( x=0;x<m/2&&x<n/2;x++){
for( y=x;y<n-1-x;y++){
   printf("%d\n",sz[x][y]);
}
for( z=x;z<m-1-x;z++){
   printf("%d\n",sz[z][y]);
}
for( f=n-1-x;f>x;f--){
   printf("%d\n",sz[z][f]);
}
for( g=m-1-x;g>x;g--){
   printf("%d\n",sz[g][f]);
}
}
if(m%2==1&&n>=m){
   w=m/2;
   for(k=w;k<n-w;k++){
   printf("%d\n",sz[w][k]);
   }
}
else if(n%2==1&&m>n){
   w=n/2;
   for(k=w;k<m-w;k++){
      printf("%d\n",sz[k][w]);
   }
}
return 0;
}
int main()
{
	int row,col;
	scanf("%d %d",&row,&col);
	int array[100][100];
    for(int i=0;i<row;i++)
	{
		for(int j=0;j<col;j++)
		{
			scanf("%d",&array[i][j]);
		}
	}
	int k,r,sum;
	sum=row*col;
	r=-1;
	while(r<10000)
	{
		if(sum==1)
		{
			printf("%d",array[r+1][r+1]);   
			sum--;
		}
		if(sum==0)
		{
			break;
		}
		r++;
		if(col>1)
		{
		    for(k=r;k<col-1;k++)
			{
			    printf("%d\n",array[r][k]);
			    sum--;
				if(sum==0)
				{
			        break;
				}
			}
		}
		if(sum==0)
		{
			break;
		}
		if(row>1)
		{
		    for(k=r;k<row-1;k++)
			{
			    printf("%d\n",array[k][col-1]);
			    sum--;
				if(sum==0)
				{
			        break;
				}
			}
		}
		if(sum==0)
		{
			break;
		}
		if(col>1)
		{
		    for(k=col-1;k>r;k--)
			{
			    printf("%d\n",array[row-1][k]);
			    sum--;
				if(sum==0)
				{
			        break;
				}
			}
		}
		if(sum==0)
		{
			break;
		}
		if(row>1)
		{
		    for(k=row-1;k>r;k--)
			{
			    printf("%d\n",array[k][r]);
			    sum--;
				if(sum==0)
				{
			        break;
				}
			}
		}
		if(sum==0)
		{
			break;
		}
		col--;
		row--;
	}
	return 0;
}
int main()
{
    int i,j,r,c,rs,cs; 
	int Shuzu[row][col];
	scanf("%d %d",&r,&c);
    for(i=0;i<r;i++){
		for(j=0;j<c;j++){
		    scanf("%d",&Shuzu[i][j]);
		}
	}
	/*printf("%d\n",Shuzu[0][0]);*/
	for(i=rs=0,j=cs=0;;){
		if(Shuzu[i][j]==0) break;
	    printf("%d\n",Shuzu[i][j]);
		Shuzu[i][j]=0;
		if(i==rs&&j<c-1&&j>cs-1){j++;}
		else if(i==rs&&j==c-1){i++;r--;}
		else if(i<r&&i>rs&&j==c-1){i++;}
		else if(i==r&&j==c-1){j--;cs++;}
		else if(i==r&&j>cs-1&&j<c-1){j--;}
		else if(i==r&&j==cs-1){i--;rs++;}
		else if(i>rs&&i<r&&j==cs-1){i--;}
		else if(i==rs&&j==cs-1){j++;c--;}
	}
	return 0;
}
int main()
{
 int u[100][100];
 int m,n,i,j,x,y,k;
 scanf("%d",&m);scanf("%d",&n);
    for(i=0;i<m;i++){
       for(j=0;j<n;j++){
           scanf("%d",&(u[i][j]));
       }
    }
   y=(m<n)?m:n;
   x=y/2;
   if(y%2==0){
   for(k=0;k<x;k++){
	   for(j=k;j<=n-2-k;j++){
		   i=k;
		   printf("%d\n",u[i][j]);
	   }
           for(i=k;i<=m-2-k;i++){
		   j=n-1-k;
		   printf("%d\n",u[i][j]);
	   }
           for(j=n-1-k;j>=k+1;j--){
		   i=m-1-k;
		   printf("%d\n",u[i][j]);
	   }
           for(i=m-1-k;i>=k+1;i--){
		   j=k;
		   printf("%d\n",u[i][j]);
	   }
   }
   }
   else{
   for(k=0;k<x;k++){
	   for(j=k;j<=n-2-k;j++){
		   i=k;
		   printf("%d\n",u[i][j]);
	   }
           for(i=k;i<=m-2-k;i++){
		   j=n-1-k;
		   printf("%d\n",u[i][j]);
	   }
           for(j=n-1-k;j>=k+1;j--){
		   i=m-1-k;
		   printf("%d\n",u[i][j]);
	   }
           for(i=m-1-k;i>=k+1;i--){
		   j=k;
		   printf("%d\n",u[i][j]);
	   }
   }
   if(m<=n){
    for(j=x;j<=n-1-x;j++){
	    printf("%d\n",u[x][j]);
    }
   }
   if(m>n){
    for(i=x;i<=m-1-x;i++){
	    printf("%d\n",u[i][x]);
    }
   }
   }
   return 0;
}
int main(){
int row,col;
int array[100][100];
int i,j,a,b,c,d=0;
scanf("%d%d",&row,&col);
for(i=0;i<=row-1;i++){
	for(j=0;j<=col-1;j++){
       scanf("%d",&array[i][j]);}
}
c=0; 
for(a=0;2*a<=row&&2*a<=col;a++){
    for(b=a;b<=col-1-a;b++){
		printf("%d\n",array[c][b]);
		d++;}
	if(d==row*col)
	break;
	b=b-1;
	for(c=a+1;c<=row-1-a;c++){
		printf("%d\n",array[c][b]);
	d++;}
	if(d==row*col)
	break;
	c=c-1;
	for(b=col-2-a;b>=a;b--){
		printf("%d\n",array[c][b]);
	d++;}
	if(d==row*col)
	break;
	b=b+1;
	for(c=row-2-a;c>=a+1;c--){
       printf("%d\n",array[c][b]);
	d++;}
	if(d==row*col)
	break;
	c=c+1;
}
return 0;
}
//????????


int main()
{
	int a[100][100],row ,col;
	cin>>row>>col;
	for(int i=0;i<row;i++)             //????
		for(int j=0;j<col;j++)
			cin>>a[i][j];
	int flag=0;       //??
	for(int i=0;;i++)
	{
		for(int j=i;j<=col-i-1;j++)       //??
		{
			cout<<a[i][j]<<endl;
			flag+=1;
			if(flag==row*col)
				break;
		}
		if(flag==row*col)
				break;
		for(int j=i+1;j<=row-i-1;j++)      //??
		{
			cout<<a[j][col-i-1]<<endl;
			flag+=1;
			if(flag==row*col)
				break;
		}
		if(flag==row*col)
				break;
		for(int j=col-i-2;j>=i+1;j--)        //??
		{
			cout<<a[row-i-1][j]<<endl;
			flag+=1;
			if(flag==row*col)
				break;
		}
		if(flag==row*col)
				break;
		for(int j=row-i-1;j>=i+1;j--)          //??
		{
			cout<<a[j][i]<<endl;
			flag+=1;
			if(flag==row*col)
				break;
		}
		if(flag==row*col)
				break;
	}
	return 0;
}
int main(){
	int row,col;
	scanf("%d %d",&row,&col);
	int array[100][100];
    int i,j;
	for(i=0;i<row;i++){
		for(j=0;j<col;j++){
			scanf("%d" ,&array[i][j]);
		}
	}
	int n,N;
	int time=0;
	int m1,m2;
	m1=(int)ceil(1.0*row/2);
	m2=(int)ceil(1.0*col/2);
	if(m1<m2){
		N=m1;
	}
	else{
		N=m2;
	}
	for(n=0;n<N;n++){
		for(j=n;j<col-n;j++){
			if(time<row*col){
			printf("%d\n",array[n][j]);
			time++;
			}
		}
		for(i=n+1;i<row-n;i++){
			if(time<row*col){
			printf("%d\n",array[i][col-n-1]);
			time++;
			
			}
		}
		for(j=col-n-2;j>=n;j--){
			if(time<row*col){
			printf("%d\n",array[row-n-1][j]);
			time++;
			
			}
		}
		for(i=row-n-2;i>n;i--){
			if(time<row*col){
			printf("%d\n",array[i][n]);
			time++;
			
			}
		}
	}
	return 0;
}
int main(void)
{
	int m,n,i,j,k,t=0,a[101][101]={0},x[4]={0,1,0,-1},y[4]={1,0,-1,0};
	cin>>m>>n;
	for(i=1;i<=m;i++)
		for(j=1;j<=n;j++)
			cin>>a[i][j];
	i=1,j=0,k=0;
	while(a[i+x[k]][j+y[k]]!=0)
	{
		cout<<a[i+x[k]][j+y[k]];
		t++;
		a[i+x[k]][j+y[k]]=0;
		if(t<m*n) cout<<endl;
		i+=x[k],j+=y[k];
		if(a[i+x[k]][j+y[k]]==0) k=(k+1)%4;
	}
}
int main()
{
    int array[200][200],row,col,i,j,cnt = 0,sum = 0;
    cin >> row >> col;
    for (i = 0;i < row;i++)
        for (j = 0;j < col;j++)
        {
            cin >> array[i][j];
        }
    i = 0;
    j = 0;
    while (cnt < row * col)
        {
              for (;j <= col - 1 - sum;j++)
              {
                  cnt++;
                  if (cnt <= row * col)
                  cout << array[i][j] << endl;
                  else 
                  break;
              }
                  j--;
                  i++;
                  for (;i <= row - 1 - sum;i++)
                  {
                      cnt++;
                      if (cnt <= row * col)
                      cout << array[i][j] << endl;
                      else 
                      break;
                  }
                      i--;
                      j--;
                      for (;j >= sum;j--)
                      {
                          cnt++;
                          if (cnt <= row * col)
                          cout << array[i][j] << endl;
                          else 
                          break;
                      }
                          i--;
                          j++;
                          for (;i > sum;i--)
                          {
                              cnt++;
                              if (cnt <= row * col)
                              cout << array[i][j] << endl;
                              else 
                              break;
                          }
                              i++;
                              j++;
                              sum++;
        }
    
    
    return 0;
}
int main(){
 int a,b=0,b1=0,c,d,e,f,g,i,k,t,raw,col,x,y;
 int array[100][100];
 scanf("%d %d",&raw,&col);
 c=raw*col;
 for(i=0;i<raw;i++){
   for(t=0;t<col;t++){
     scanf("%d",&a);
     array[i][t]=a;
  }
 }
 for(i=0;b<c;i++){ 
     for(t=i;t<col-i;t++){
       if(b<c){
       printf("%d\n",array[i][t]);
       }
       b=b+1;
       }
     
       for(e=i+1;e<raw-i;e++){
         if(b<c){
         printf("%d\n",array[e][col-i-1]);
         }
         b=b+1;
         }
        
       for(f=col-2-i;f>=i;f--){
         if(b<c){
         printf("%d\n",array[raw-1-i][f]);
         }
         b=b+1;
         }
      
       for(g=raw-2-i;g>i;g--){
         if(b<c){
         printf("%d\n",array[g][i]);
         }
         b=b+1;
        
         }
       } 
    
 scanf("%d\n",&array[x][y]);
 return 0;
}
void main()
{
	int m,n,i,j,min=1;
	int 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]);
	if(m>n) min=n;
	else min=m;
	for(i=0;i<min;i++)
	{
		for(j=0;j<n;j++)
		{
			if(a[i][j]>-1000)
			{
				printf("%d\n",a[i][j]);
				a[i][j]=-10000;
			}
			else continue;
		}
		for(j=0;j<m;j++)
		{
			if(a[j][n-1-i]>-1000)
			{
				printf("%d\n",a[j][n-1-i]);
				a[j][n-1-i]=-10000;
			}
			else continue;
		}
		for(j=n-1;j>=0;j--)
		{
			if(a[m-1-i][j]>-1000)
			{
				printf("%d\n",a[m-1-i][j]);
				a[m-1-i][j]=-10000;
			}
			else continue;
		}
		for(j=m-1;j>=0;j--)
		{
			if(a[j][i]>-1000)
			{
				printf("%d\n",a[j][i]);
				a[j][i]=-10000;
			}
			else continue;
		}
	}
}
int main()
{
	int col,row,i,j,*org,*p,m,n,count=0,total;
	scanf("%d %d",&row,&col);
	org=(int*)malloc(row*col*sizeof(int));
	p=org;
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
		{
			scanf("%d",p+i*col+j);
		}
		total=row*col;
		i=0;j=0;
   
	do	
	{
		m=i;n=j;
		for(;n<col-j;n++)
		{printf("%d\n",*(p+m*col+n));count++;}
		n--;
		if(count==total)break;
		for(m=i+1;m<row-i;m++)
		{printf("%d\n",*(p+m*col+n));count++;}
		m--;
		if(count==total)break;
		for(n=n-1;n>=j;n--)
		{printf("%d\n",*(p+m*col+n));count++;}
		n++;
		if(count==total)break;
		for(m=m-1;m>=i+1;m--)
		{printf("%d\n",*(p+m*col+n));count++;}
		m++;
		if(count==total)break;
		j++;i++;
	}while(1);
		
	free(org);
}
int a[102][102];
int flag[102][102];
int row;
int col;



int go(int f,int i,int j,int count)
{    
	if(count!=col*row)
		
{		cout<<a[i][j]<<endl;
			flag[i][j]=1;
			
	if(f==0)
	{
		if(flag[i][j+1]==0)
		             go(f,i,j+1,count+1);
		else  go((f+1)%4,i+1,j,count+1);
	}
		
	 if(f==1) 
		{
			if(flag[i+1][j]==0)
				go(f,i+1,j,count+1);
			else  go((f+1)%4,i,j-1,count+1);
	   }
	 if(f==2)
	{
		if(flag[i][j-1]==0)
		     go(f,i,j-1,count+1);
		else go((f+1)%4,i-1,j,count+1);
	}
	 if(f==3)
		{
			if(flag[i-1][j]==0)
				go(f,i-1,j,count+1);
			else
				go((f+1)%4,i,j+1,count+1);
    	}
}
	
	      return 0;

}
int main()
{
	
	
	int i;
	int j;
	cin>>row>>col;
	int turn=0;
	
	for(i=1;i<=row;i++)
		for(j=1;j<=col;j++)
		{
			cin>>a[i][j];
		}
	for(i=0;i<=col+1;i++)
	{
		flag[0][i]=1;
		flag[row+1][i]=1;
	}
	for(i=0;i<=row+1;i++)
	{
		flag[i][0]=1;
		flag[i][col+1]=1;
	}
	  

	go(0,1,1,0);
}
int main()
{
       int row,col,i,j,a,b,c,k,temp;
       int sz[100][100];
       scanf("%d%d",&row,&col);
       if(row>col)
               temp=col;
       else
               temp=row;
       for(i=0;i<row;i++){
               for(j=0;j<col;j++){
                       scanf("%d",&sz[i][j]);}}
       for(a=0;a<((temp+1)/2);a++){
               for(i=a;i<col;i++){
                       printf("%d\n",sz[a][i]);}
               col-=1;
               for(j=a+1;j<row;j++){
                       printf("%d\n",sz[j][col]);}
               row-=1;
			   if(row==a)
                       break;
               for((k=col-1);k>=a;k--){
                       printf("%d\n",sz[row][k]);}
               b=k+1;
				if(col==a)
                       break;
             
               for((c=row-1);c>=a+1;c--){
                               printf("%d\n",sz[c][b]);}

       }
       return 0;
}
void main()
{
    int num=0,firh=0,lash,firl=0,lasl,i,j,row,col,a[105][105];
    scanf("%d %d",&row,&col);
    for(i=0;i<row;i++)
    for(j=0;j<col;j++)
    	scanf("%d",&a[i][j]);
    lash=row-1;lasl=col-1;
    while(num<=(row*col))
    {
    	for(i=firl;i<=lasl;i++)
    	{printf("%d\n",a[firh][i]);num++;}
    	if(num==row*col) break;
    	firh++;
    	for(i=firh;i<=lash;i++)
    	{printf("%d\n",a[i][lasl]);num++;}
    	if(num==row*col) break;
    	lasl--;
    	for(i=lasl;i>=firl;i--)
    	{printf("%d\n",a[lash][i]);num++;}
    	if(num==row*col) break;
    	lash--;
    	for(i=lash;i>=firh;i--)
    	{printf("%d\n",a[i][firl]);num++;}
    	if(num==row*col) break;
    	firl++;
    }
}
int main()
{
	int sz[100][100],i,j,row,k,col;
	scanf("%d %d",&row,&col);
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
		{
			scanf("%d",&sz[i][j]);
		}
	}
	for(i=0;i<row-1-i&&i<col-1-i;i++)
	{
		for(j=i;j<col-1-i;j++)
			printf("%d\n",sz[i][j]);
		for(j=i;j<row-1-i;j++)
			printf("%d\n",sz[j][col-1-i]);
		for(j=col-1-i;j>i;j--)
			printf("%d\n",sz[row-1-i][j]);
		for(j=row-1-i;j>i;j--)
			printf("%d\n",sz[j][i]);
	}
	if(i==row-i-1&&i==col-i-1)
		printf("%d\n",sz[i][i]);
	if(i==row-1-i&&i<col-i-1)
	{
		for(k=i;k<col-i;k++)
			printf("%d\n",sz[i][k]);
	}
	if(i<row-1-i&&i==col-1-i)
	{
		for(k=i;k<row-i;k++)
			printf("%d\n",sz[k][i]);
	}
	return 0;
}
int main(){
	int row,col,m,n;
	int sz[105][105],e[105][105];
	scanf("%d %d",&m,&n);
	for(row=0;row<m;row++){
		for(col=0;col<n;col++){
			scanf("%d",&sz[row][col]);
		}
	}
	while(m>0&&n>0){
		if(m>1&&n>1){
		    for(col=0;col<n;col++){
			    printf("%d\n",sz[0][col]);
			}
		    for(row=1;row<m;row++){
			    printf("%d\n",sz[row][n-1]);
			}
		    for(col=n-2;col>=0;col--){
			    printf("%d\n",sz[m-1][col]);
			}
		    for(row=m-2;row>=1;row--){
			    printf("%d\n",sz[row][0]);
			}
		    for(row=0;row<m;row++){
		        for(col=0;col<n;col++){
				    e[row][col]=sz[row][col];
				}
			}
		}else if(m==1){
			for(col=0;col<n;col++){
			    printf("%d\n",sz[0][col]);
			}
		}else{
			for(row=0;row<m;row++){
				printf("%d\n",sz[row][0]);
			}
		}
		m-=2;
		n-=2;
		for(row=0;row<m;row++){
			for(col=0;col<n;col++){
				sz[row][col]=e[row+1][col+1];
            }
		}
	}
	return 0;
}
int main()
{
 int array[100][100],row,col,i,k,j,t=0;
 scanf("%d%d",&row,&col);
    int m=row*col;
 for(i=0;i<row;i++)
 {
  for(k=0;k<col;k++)
  {
   scanf("%d",&array[i][k]);
  }
 }

 for(j=0;;j++)
 {

  for(k=j;k<=col-1-j;k++)
  {
   printf("%d\n",array[j][k]);
   t++;
  }
  if(t==m) break;

  for(i=j+1;i<=row-1-j;i++)
  {
   printf("%d\n",array[i][col-j-1]);
   t++;
  }
  if(t==m) break;

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

  for(i=row-j-2;i>j;i--)
  {
   printf("%d\n",array[i][j]);
   t++;
  }
  if(t==m) break;
 }

    return 0;
}
int main()
{
	int sz[100][100];
	int row,col,i,j,a=0;
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
		{
			scanf("%d",&sz[i][j]);
		}
	}

	while(a<row-1&&a<col-1)
	{
		for(i=a,j=a;j<col-1;j++)
		{
			printf("%d\n",sz[i][j]);
		}
		for(j=col-1,i=a;i<row-1;i++)
		{

			printf("%d\n",sz[i][j]);
		}
		for(i=row-1,j=col-1;j>a;j--)
		{
			printf("%d\n",sz[i][j]);
		}
		for(j=a,i=row-1;i>a;i--)
		{
			printf("%d\n",sz[i][j]);
		}
		col--;
	    row--;
		a++;
	}
	if(a==row-1)
	{
		for(i=a,j=a;j<col;j++)
			printf("%d\n",sz[i][j]);
	}
	else if(a==col-1)
	{
		for(j=a,i=a;i<row;i++)
			printf("%d\n",sz[i][j]);
	}
	                                                                        
	return 0;
}
int main(){
	int r,c,i,j,e,k,m,n,l;
	int s[101][101];
	scanf("%d%d",&r,&c);
	for(i=0;i<r;i++){
		for(j=0;j<c;j++){
			scanf("%d",&s[i][j]);
		}
	}
	e=r*c;
	for(i=0;;i++){
		for(k=i;k<c-i;k++){
			printf("%d\n",s[i][k]);
			e--;
			if(e==0)
				return 0;
		}
		for(m=i+1;m<r-i;m++){
			printf("%d\n",s[m][c-1-i]);
			e--;
			if(e==0)
				return 0;
		}
		for(n=c-2-i;n>=i;n--){
			printf("%d\n",s[r-1-i][n]);
			e--;
			if(e==0)
				return 0;
		}
		for(l=r-2-i;l>i;l--){
			printf("%d\n",s[l][i]);
			e--;
			if(e==0)
				return 0;
		}
	}
	return 0;
}
int a[105][105];
int main()
{
	int m,n;
	int dx[4]={0,1,0,-1};
	int dy[4]={1,0,-1,0};
	int inow=1,jnow=1;
	int f=0;
	cin>>m>>n;
	for(int i=1;i<=m;i++)
		for(int j=1;j<=n;j++)
			cin>>a[i][j];
	while(1){
		cout<<a[inow][jnow]<<endl;
		a[inow][jnow]=0;
		if(a[inow+dx[f]][jnow+dy[f]]>0){
			inow=inow+dx[f];
			jnow=jnow+dy[f];
		}
		else{
			f=(f+1)%4;
			if(a[inow+dx[f]][jnow+dy[f]]==0)
				break;
			else{
				inow=inow+dx[f];
				jnow=jnow+dy[f];
			}		
		}	
	}
	return 0;		
}
int main()
{
	int a[110][110],i,j,row,col;
	cin>>row>>col;
	for (i=0;i<row;i++)
	{
		for (j=0;j<col;j++)
		{
			cin>>a[i][j];
		}
	}
	int num=0,n=0;
	for (n=0;n<=500;n++)
	{
		for (int i1=n;i1<=col-n-1;i1++)
		{
			cout<<a[n][i1]<<endl;
			num+=1;
		}
		if (num>=row*col)
			break;
		for (int i2=n+1;i2<=row-n-1;i2++)
		{
			cout<<a[i2][col-n-1]<<endl;
			num++;
		}
		if (num>=row*col)
			break;
		for (int i3=col-n-2;i3>=n;i3--)
		{
			cout<<a[row-n-1][i3]<<endl;
			num++;
		}
		if (num>=row*col)
			break;
		for (int i4=row-n-2;i4>n;i4--)
		{
			cout<<a[i4][n]<<endl;
			num++;
		}
		if (num>=row*col)
			break;
	}
	return 0;
}
//============================================================================
// Name        : ex4.6.cpp
// Author      : Zhang Yu
// Version     :
// Copyright   : Your copyright notice
// Description : ????????
//============================================================================

int array[100][100];

int main() {
	int row;
	cin >>row;
	int col;
	cin >>col;
	for (int i=0;i<=row-1;++i)
		for (int j=0;j<=col-1;++j)
			cin >>array[i][j];
	int row0=0;
	int col0=0;
	int row1=row;
	int col1=col;
	for (;;)
	{
		for (int j=col0;j<=col1-1;++j)//????????
			cout <<array[row0][j]<<endl;
		++row0;//?????????
		for (int k=row0;k<=row1-1;++k)//????????
			cout <<array[k][col1-1]<<endl;
		--col1;//?????????
		for (int p=col1-1;row1-1>=row0 && p>=col0;--p)//????????
			cout <<array[row1-1][p]<<endl;
		--row1;//?????????
		for (int q=row1-1;col0<=col1-1 &&q>=row0;--q)//????????
			cout <<array[q][col0]<<endl;
		++col0;//?????????
		if (row0>=row1||col0>=col1)
			break;
	}
	return 0;
}
int main()
{
    int row,col,r,c;
	int i,j,times;
	int x,y;
	int a[120][120];

	scanf("%d%d",&row,&col);
	for(i=1;i<=row;i++)
		for(j=1;j<=col;j++)
			scanf("%d",&a[i][j]);
	
    r=row;
	c=col;
	times=0;
	x=1;
    y=0;
	while(times<r*c)
	{
		if(col!=0)
		{
			for(i=1;i<=col;i++)
			{
				printf("%d\n",a[x][y+i]);
				times++;
			}
			y+=col;
			row--;
	        if(times==r*c)
				  col=row=0;
		}
		if(row!=0)
		{
		    for(i=1;i<=row;i++)
			{
			    printf("%d\n",a[x+i][y]);
				times++;
				
			}
			x+=row;
			col--;
            if(times==r*c)
				  col=row=0;
		}
		if(col!=0)
		{
		    for(i=1;i<=col;i++)
			{
			    printf("%d\n",a[x][y-i]);
				times++;
				
			}	
			y-=col;
			row--;
            if(times==r*c)
				  col=row=0;
		}
		if(row!=0)
		{
		    for(i=1;i<=row;i++)
			{
			    printf("%d\n",a[x-i][y]);
				times++;
			}
			x-=row;
			col--;
            if(times==r*c)
				  col=row=0;            
		}
	}
  
	return 0;
}
int main()
{
	int  a[100][100],n,m,i,j,k,p,q,sum=0;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	p=(n-1)/2;
	q=(m-1)/2;
	for(k=0;k<=p&&k<=q;k++)
	{
		for(i=k,j=k;j<m-k;j++)
		{
			sum++;
			printf("%d\n",a[i][j]);
			if(sum==n*m)
			{
				goto end;
			}
		}
		for(j=m-1-k,i=k+1;i<n-k;i++)
		{
			
			sum++;
			printf("%d\n",a[i][j]);
			if(sum==n*m)
			{
				goto end;
			}
		}
		
		for(i=n-1-k,j=m-k-2;j>=k;j--)
		{
			sum++;
			printf("%d\n",a[i][j]);
			if(sum==n*m)
			{
				goto end;
			}
		}
	
		for(j=k,i=n-k-2;i>=k+1;i--)
		{
			sum++;
			printf("%d\n",a[i][j]);
			if(sum==n*m)
			{
				goto end;
			}
		}
	}
	end:
	return 0;
}
int main(){
    int row,col,r,c,a[100][100],s,n;
    scanf("%d%d",&row,&col);
    s=0;
    for(r=0;r<row;r++){
        for(c=0;c<col;c++){
            scanf("%d",&a[r][c]);
        }
    }for(n=0;n<100;n++){
        for(c=n;c<col-n;c++){
            printf("%d\n",a[n][c]);
            s++;
        }
        printf("\n");
        if(s==row*col){
            break;
        }for(r=n+1;r<row-n;r++){
            printf("%d\n",a[r][col-1-n]);
            s++;
        }printf("\n");
        if(s==row*col)
        break;
        for(c=col-2-n;c>=n;c--){
            printf("%d\n",a[row-1-n][c]);
            s++;
        }
        printf("\n");
        if(s==row*col)
        break;
        for(r=row-2-n;r>n;r--){
            printf("%d\n",a[r][n]);
            s++;
        }printf("\n");
        if(s==row*col){
            break;
        }
    }
    return 0;
}
int main()
{
	int k,i,j,row,col;
    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<=row/2 && k<=col/2;k++)
	{


			for(j=k;j<=col-1-k;j++)
			{
				printf("%d\n",array[k][j]);
			}

		
			for(i=k+1;i<=row-k-1;i++)
			{
				printf("%d\n",array[i][col-1-k]);
			}
		
		

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

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