semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main()
{

  int i,j,h,l,x,y,k;
  int a[hang][lie];

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

  k=0;
  x=0;
  i=0;
  while(k<(h*l)){ 
   
      for(j=x;j<l;j++){
	     printf("%d\n",a[i][j]);
		 k++;
		 a[i][j]=-1;
		 y=j;
		 if(a[i][j+1]==-1){
			 break;
		 }
	  }
	  if(k==(h*l)){
         break;
	  }
	  

     for(i=x+1;i<h;i++){
	     printf("%d\n",a[i][y]);
		 k++;
		 a[i][y]=-1;
		 x=i;
		 if(a[i+1][y]==-1){
			 break;
		 }
	  }
	  if(k==(h*l)){
         break;
	  }


	  for(j=y-1;j>=0;j--){
	     printf("%d\n",a[x][j]);
		 k++;
		 a[x][j]=-1;
		 y=j;
		 if(a[x][j-1]==-1){
			 break;
		 }
	  }
	  if(k==(h*l)){
         break;
	  }


	  for(i=x-1;i>=0;i--){
	     printf("%d\n",a[i][y]);
		 k++;
		 a[i][y]=-1;
		 x=i;
		 if(a[i-1][y]==-1){
			 break;
		 }
	  }
	  if(k==(h*l)){
         break;
	  }
	  
  }
	 
 
return 0;
}
int main()
{
	int row,col;
	scanf("%d %d",&row,&col);
	int array[100][100];
	for(int rr=0;rr<row;rr++){
		for(int cc=0;cc<col;cc++){
			scanf("%d",&array[rr][cc]);
		}
	}
	

	for(int t=1;t<100;t++){

		int leftc=t-1;
		int rightc=col-t;
		if(leftc<=rightc){
			if(leftc==rightc){
			}
			for(int c=leftc;c<=rightc;c++){
				if(c==0){
					printf("%d",array[0][0]);
				}else{
					printf("\n%d",array[t-1][c]);
				}
				
			}
		}else{
			break;
		}

	

		int upr=t;
		int downr=row-1-t;

		

		if(upr<=downr){
			for(int r=upr;r<=downr;r++){
				printf("\n%d",array[r][col-t]);
			}
		
		}
		
		if(upr-downr>=2){
			break;
		}

		

		if(leftc<=rightc){
			for(int c=rightc;c>=leftc;c--){
				printf("\n%d",array[row-t][c]);	
			}
		}

		if(leftc==rightc){
			break;
		}

		if(upr<=downr){
			for(int r=downr;r>=upr;r--){
				printf("\n%d",array[r][t-1]);
			}
		}
	}
	return 0;
}
int main(){
	int row,col,Row,Col,sum;
	int array[100][100];
	scanf("%d%d",&row,&col);
	sum=row*col;
	//sum??
	for(Row=0;Row<row;Row++){
		for(Col=0;Col<col;Col++){
			scanf("%d",&array[Row][Col]);
		}
	}
	//??????
	Row=0;Col=-1;
	int r,c;
	row--;
	while(1){
		for(c=0;c<col;c++){
			Col++;
			printf("%d\n",array[Row][Col]);
			sum--;
		}
		if(sum==0)
			break;
		col--;
		//??
		for(r=0;r<row;r++){
			Row++;
			printf("%d\n",array[Row][Col]);
			sum--;
		}
		if(sum==0)
			break;
		row--;
		//??
		for(c=0;c<col;c++){
			Col--;
			printf("%d\n",array[Row][Col]);
			sum--;
		}
		if(sum==0)
			break;
		col--;
		//??
		for(r=0;r<row;r++){
			Row--;
			printf("%d\n",array[Row][Col]);
			sum--;
		}
		if(sum==0)
			break;
		row--;
		//??
	}
	return 0;
}
int main(){
    int a[100][100],n,m,i,j,m1,m2,n1,n2,k;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    k=0;
    m1=0;
    m2=m-1;
    n1=0;
    n2=n-1;
    loop:
    for(j=m1;j<=m2;j++){
        printf("%d\n",a[n1][j]);
        k=k+1;
        if(k==n*m){
            goto end;
        }
    }
    m2=m2-1;
    for(i=n1+1;i<=n2;i++){
        printf("%d\n",a[i][m2+1]);
        k=k+1;
        if(k==n*m){
            goto end;
        }
    }
    n2=n2-1;
    for(j=m2;j>=m1;j--){
        printf("%d\n",a[n2+1][j]);
        k=k+1;
        if(k==n*m){
            goto end;
        }
    }
    m1=m1+1;
    for(i=n2;i>n1;i--){
        printf("%d\n",a[i][m1-1]);
        k=k+1;
        if(k==n*m){
            goto end;
        }
    }
    n1=n1+1;
    goto loop;
    end:
    return 0;
}
int re(int a[100][100],int row,int col,int b[])
{
	int i,j,k=0,p,mm,m;
	for(i=0;i<=row/2;i++)
	{
		for(j=i;j<col-i&&k<row*col;j++)
		{b[k]=a[i][j];
		k++;}

		for(p=i+1;p<row-i&&k<row*col;p++)
		{
			b[k]=a[p][j-1];
			k++;
		}

		for(mm=(col-2-i);mm>=i&&k<row*col;)
		{
			b[k]=a[row-i-1][mm];
			k++;
			mm--;
		}

		for(m=row-2-i;m>i&&k<row*col;m--)
		{
			b[k]=a[m][i];
			k++;
		}
	}

	return k;
}



int main()
{
	int a[100][100],b[10000];
	int row,col,i,j,xx;

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

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

	xx=re(a,row,col,b);
	for(i=0;i<xx;i++)
		printf("%d\n",b[i]);
	return 0;
}
int main(){
	int m[100][100],h,l,i,j,sxh,xxh,zxl,yxl;
	scanf("%d%d",&h,&l);
	for(i=0;i<h;i++){
		for(j=0;j<l;j++){
			scanf("%d",&m[i][j]);
		}
	}

	sxh=0;
	xxh=h-1;
	zxl=0;
	yxl=l-1;

	if(h%2==0&&l%2==0){
    	while(sxh<xxh&&zxl<yxl){
        	for(i=zxl;i<yxl;i++)
    	    	printf("%d\n",m[sxh][i]);
    	    for(i=sxh;i<xxh;i++)
    	    	printf("%d\n",m[i][yxl]);
        	for(i=yxl;i>zxl;i--)
    	    	printf("%d\n",m[xxh][i]);
        	for(i=xxh;i>sxh;i--)
    	    	printf("%d\n",m[i][zxl]);
	    	sxh++;
	    	xxh--;
	    	zxl++;
	    	yxl--;
		}
	}
	else if((h%2==1||l%2==1)&&h>l){
		while(sxh<xxh&&zxl<yxl){
        	for(i=zxl;i<yxl;i++)
    	    	printf("%d\n",m[sxh][i]);
    	    for(i=sxh;i<xxh;i++)
    	    	printf("%d\n",m[i][yxl]);
        	for(i=yxl;i>zxl;i--)
    	    	printf("%d\n",m[xxh][i]);
        	for(i=xxh;i>sxh;i--)
    	    	printf("%d\n",m[i][zxl]);
	    	sxh++;
	    	xxh--;
	    	zxl++;
	    	yxl--;
		}
		for(i=sxh;i<=xxh;i++)
			printf("%d\n",m[i][zxl]);
	}
	else if((h%2==1||l%2==1)&&h<=l){
		while(sxh<xxh&&zxl<yxl){
        	for(i=zxl;i<yxl;i++)
    	    	printf("%d\n",m[sxh][i]);
    	    for(i=sxh;i<xxh;i++)
    	    	printf("%d\n",m[i][yxl]);
        	for(i=yxl;i>zxl;i--)
    	    	printf("%d\n",m[xxh][i]);
        	for(i=xxh;i>sxh;i--)
    	    	printf("%d\n",m[i][zxl]);
	    	sxh++;
	    	xxh--;
	    	zxl++;
	    	yxl--;
		}
		for(i=zxl;i<=yxl;i++)
			printf("%d\n",m[sxh][i]);
	}

	return 0;
}
int main()
{ 
	int row,col;
	int time=0;
	int i,j;
	int a[100][100];
	int x1,x2,y1,y2;
	scanf("%d %d",&row,&col);
	x1=y1=1;
	x2=row;
	y2=col; 
	for(i=1;i<=row;i++)  
	{
		 for(j=1;j<=col;j++) 
			 scanf("%d",&a[i][j]);
	}
	while(time<row*col)
	{
		for(i=y1;i<=y2;i++)
		{
			if (time==row*col) break;
			printf("%d\n",a[x1][i]);
			time++;
		}
		for(i=x1+1;i<=x2;i++)
		{
			if(time==row*col) break;
			printf("%d\n",a[i][y2]);
			time++;
		}
		for(i=y2-1;i>=y1;i--)
		{
			if(time==row*col) break;
			printf("%d\n",a[x2][i]);
			time++;
		}
		for(i=x2-1;i>=x1+1;i--)
		{
			if(time==row*col) break;
			printf("%d\n",a[i][y1]);
			time++;
		}
		x1++;
		x2--;
		y2--;
		y1++;
	}
	return 0;
}
void spread(int A[100][100],int M,int N)
{
	int i;
	int j=0;
	int t[400]={0};
	if(M==1&&N==1)
		printf("%d\n",A[0][0]);
	else
	{
		if(M==1)
			for(i=0;i<N;i++)
			{
			   t[j]=A[0][i];
			   j=j+1;
			}
			else if(N==1)
				for(i=0;i<M;i++)
				{
					t[j]=A[i][0];
				     j=j+1;
				}
			    else
				{
	                for(i=0;i<N-1;i++)
					{
	            	   t[j]=A[0][i];
		               j=j+1;
					}
	                for(i=0;i<M-1;i++)
					{
		               t[j]=A[i][N-1];
		               j=j+1;
					}
	                for(i=N-1;i>0;i--)
					{
		               t[j]=A[M-1][i];
		               j=j+1;
					}
	                for(i=M-1;i>0;i--)
					{
		               t[j]=A[i][0];
		               j=j+1;
					}
				}
	for(i=0;i<j;i++)
		printf("%d\n",t[i]);
	}
}
void main()
{
	int i,j,s;
	int r,c;
	int k;
	int a[100][100];
	scanf("%d%d",&r,&c);
	k=r<c?r:c;
	for(i=0;i<r;i++)
		for(j=0;j<c;j++)
			scanf("%d",&a[i][j]);
		for(i=1;((r>0)&&(c>0));i++)
		{
			spread(a,r,c);
			r=r-2;
			c=c-2;
			for(s=0;s<r;s++)
				for(j=0;j<c;j++)
					a[s][j]=a[s+1][j+1];
		}
}
int main()
{
	int a[101][101];
    int row, col, i, j, k, h, counter = 0, mul;

	cin >> row >> col;
	mul = row * col;
	for (i = 0; i < row; i++)
		for (j = 0; j < col; j++)
			cin >> a[i][j];	
	if (col % 2 == 0)
		h = col / 2;
	else 
        h = col / 2 + 1;
	for (k = 0; k < h; k++)
	{
	    for (i = k, j = k; j < col - k; j++)
		{  
			if (counter < mul)
			    cout << a[i][j] << endl;
			counter++;
		}
		j--;
		for (i = 1 + k; i < row - k; i++)
		{ 
            if (counter < mul)
			    cout << a[i][j] << endl;
			counter++;
        }
		i--;
		for (j = col - 2 - k; j >= k; j--)
		{
		    if (counter < mul)
			    cout << a[i][j] << endl;
			counter++;
		}
		j++;
		for (i = row - 2 - k; i > k; i-- )
		{	
            if (counter < mul)
			    cout << a[i][j] << endl;
			counter++;
		}
		i++;
	}
      return 0;
}
void main()
{
	int row,col,i,j,a[100][100],t,k=0,m=1,c,u;
	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;
	if(col<row)t=2*col+1;
	else t=2*row;
	u=t;
	for(;t!=1;t--)
	{
		if(t%4==u%4)
		{
			for(c=col-k;c!=0;j++)
			{
				printf("%d\n",a[i][j]);
				c--;
			}
			k++;
			j--;
			i++;
		}
		else if(t%4==(u-1)%4)
		{
			for(c=row-m;c!=0;i++)
			{
			    printf("%d\n",a[i][j]);
				c--;
			}
			m++;
			i--;
			j--;
		}
		else if(t%4==(u-2)%4)
		{
			for(c=col-k;c!=0;j--)
			{
				printf("%d\n",a[i][j]);
				c--;
			}
			k++;
			j++;
			i--;
		}
		else if(t%4==(u-3)%4)
		{
			for(c=row-m;c!=0;i--)
			{
			    printf("%d\n",a[i][j]);
				c--;
			}
			m++;
			i++;
			j++;
		}
	}
}
int a[100][100];
void shuchu(int e,int b,int row,int col,int c)
{
	int i,j;
	if(e==0||b==0) ;
	else if(e==1&&b==1)
	{
		printf("%d\n",a[c][c]);
	}
	else if(e==1&&b!=1)
	{
		for(j=c;j<col-c;j++)
		printf("%d\n",a[c][j]);
	}
	else if(e!=1&&b==1)
	{
		for(j=c;j<row-c;j++)
		printf("%d\n",a[j][c]);
	}
	else
	{
		for(i=c;i<col-c;i++)
		printf("%d\n",a[c][i]);
		for(i=c+1;i<row-c;i++)
		printf("%d\n",a[i][col-c-1]);
		for(i=col-c-2;i>=c;i--)
		printf("%d\n",a[row-c-1][i]);
		for(i=row-c-2;i>c;i--)
		printf("%d\n",a[i][c]);
		shuchu(e-2,b-2,row,col,c+1);
	}
}
int main()
{
	 int 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]);
	 	}
	 }
	 shuchu(row,col,row,col,0);
	 return 0; 
}
/*
 * CR.cpp
 *
 *  Created on: 2012-11-15
 *      Author: sony
 */

int a,b;
int x[101][101];
int p;
int sum;
void read(int start,int a,int b)
{
	int v,h;
	int i;
	v = start;h = start;
	if (a == 0 || b == 0)return;
	if (a == 1 && b == 1){cout <<x[v][h] <<endl;return;}
	for (i = 1;i <= b-1;i ++)
	{
		cout <<x[v][h]<<endl;
	    sum ++;
	    if (sum == p)return;
	    h ++;
	}
	for (i = 1;i <= a-1;i ++)
	{
		cout <<x[v][h]<<endl;
		sum ++;
		if (sum == p)return;
		v ++;
	}
	for (i = 1;i <= b-1;i ++)
	{
		cout <<x[v][h]<<endl;
		sum ++;
		if (sum == p)return;
		h --;
	}
	for (i = 1;i <= a-1;i ++)
	{
		cout <<x[v][h]<<endl;
		sum ++;
		if (sum == p)return;
		v --;
	}
	read(v+1,a-2,b-2);

}
int main()
{
    int j,r;
	sum = 0;
    cin >>a >>b;
    p = a*b;
    for (j = 1;j <= a;j ++)
    	for (r = 1;r <= b;r ++)
    		cin >>x[j][r];
    read(1,a,b);
    return 0;
}
//????  ???  12858

int main()
{
	int i,j,c,dirx,diry,x,y,row,col,step;        //dirx,diry????   x,y?????   step????????  
	int a[101][101],b[101][101];     //a??????,b??????????
	cin >> row >> col;
	for (i = 1;i <= row; i++)
		for (j = 1;j <= col; j++)
		{
			cin >> a[i][j];
			b[i][j] = 1;
		}
	x = 1;y = 0;dirx = 0;diry = 1;    //??????????
	step = 0;
	while (step < (col * row))
	{
		while (b[x + dirx][y + diry] == 1)           //?????
		{
			x += dirx;y += diry;
			b[x][y] = 0;
			step++;
			cout << a[x][y] << endl;
		}
		if ((dirx == 1) && (diry == 0))            //???????
		{
			dirx = 0;diry = -1;
		}
		else 
			if ((dirx == 0) && (diry == 1))
			{
				dirx = 1;diry = 0;
			}
			else
				if ((dirx == -1) && (diry == 0))
				{
					dirx = 0;diry = 1;
				}
				else if ((dirx == 0) && (diry == -1))
				{
					dirx = -1;diry = 0;
				}	
	}
    return 0;
}
int main()
{
    int row,col,i,j,a[100][100],b,c=0,n;
	scanf("%d%d",&row,&col);
	b=col*row;
    for(i=0;i<row;i++){
		for(j=0;j<col;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(n=0;n<103;n++){
		for(i=n;i<col-n;i++){
			printf("%d\n",a[n][i]);
			c=c+1;
		}
		if(c==b){
			break;
		}
		for(i=n+1;i<row-n;i++){
			printf("%d\n",a[i][col-n-1]);
			c=c+1;
		}
		if(c==b){
			break;
		}
		for(i=col-n-2;i>=n;i--){
			printf("%d\n",a[row-1-n][i]);
			c=c+1;
		}
		if(c==b){
			break;
		}
		for(i=row-n-2;i>n;i--){
			printf("%d\n",a[i][n]);
			c=c+1;
		}
		if(c==b){
			break;
		}
	}
	return 0;
}
/**
 * @file    2.cpp
 * @author  ???
 * @date    2013-11-5
 * @description
 *          ????????? - ????????
 */
int main()
{
	int col, row, a[100][100], state=0, step[4], curstep, flag=1;
	int dir[4][2] = {{0,1},{1,0},{0,-1},{-1,0}};
	int pos[2] = {0,0};
	cin >> row >> col;
	for(int i=0; i<row; ++i)
		for(int j=0; j<col; ++j)
			cin >> a[i][j];
	step[0] = col;
	step[1] = row-1;
	step[2] = col-1;
	step[3] = row-2;
	curstep = step[state];
	while(curstep > 0){
		for(int i=0+flag; i<curstep; ++i){
			cout << a[pos[0]][pos[1]] << endl;
			pos[0] += dir[state][0];
			pos[1] += dir[state][1]; 
		}
		step[state] = step[state]-2;
		state = (state+1)%4;
		curstep = step[state];
		flag = 0;
	}
	cout << a[pos[0]][pos[1]] << endl;
	return 0;
}
int main()
{
    int i,j,a,b,t[100][100],q=0,s;
    scanf("%d%d",&a,&b);
    s=a*b;
    for(i=0;i<a;i++)
      for(j=0;j<b;j++)
      scanf("%d",&t[i][j]);
      i=q;
    while(s!=0)
    {
      for(j=q;j<b;j++)
      {
       if(s==0)break;
        printf("%d\n",t[i][j]);
        s--;
        }
        j--;
        for(i=i+1;i<a;i++)
        {
          if(s==0)break;
          printf("%d\n",t[i][j]);
          s--;
          }
          i--;
       for(j=b-2;j>=q;j--)
          {
              if(s==0)break;
                 printf("%d\n",t[i][j]);  
                 s--;             
                             }
              j++;
       for(i=a-2;i>=q+1;i--)
          {
                if(s==0)break;
                 printf("%d\n",t[i][j]);  
                 s--; 
                 }
                 i++;
       q++;
       a--;
       b--;
       }
       getchar();
       getchar();
}
int main()
{
	int row,col;
	int i,j,n,time=0;
	cin>>row>>col;
	int a[100][100];
	int (*p)[100]=a;
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			cin>>*(*(p+i)+j);
	for (n=0;;n++)
	{
		for (i=n;i<col-n;i++)
		{
			cout<<*(*(p+n)+i)<<endl;
			time++;//??????????time?????
			}
		if(time==row*col) break;
		for (j=n+1;j<row-n;j++)
		{
			cout<<*(*(p+j)+col-n-1)<<endl;
			time++;
		}
		if(time==row*col) break;
		for (i=col-2-n;i>=n;i--)
		{
			cout<<*(*(p+row-n-1)+i)<<endl;
			time++;
		}
		if(time==row*col) break;
		for (j=row-2-n;j>n;j--)
		{
			cout<<*(*(p+j)+n)<<endl;
			time++;
		}
		if(time==row*col) break;
	}
	return 0;
}
/**
* @file ????????
* @auth zmj
* @date 2013-12-30
* @desc ?????????
*/



int main()
{
	int map[MAX_N][MAX_N];
	int n, m, count;
	int i, j, k;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			scanf("%d", &map[i][j]);
		}
	}

	count = n*m;
	for (k = 0;; k++)
	{
		for (j = k; j < m - k; j++)
		{
			printf("%d\n", map[k][j]);
			count--;
			if (count == 0) return 0;
		}
		for (i = k + 1; i < n - k; i++)
		{
			printf("%d\n", map[i][j-1]);
			count--;
			if (count == 0) return 0;
		}
		for (j = j -2; j > k-1; j--)
		{
			printf("%d\n", map[i - 1][j]);
			count--;
			if (count == 0) return 0;
		}
		for (i = i - 2; i > k; i--)
		{
			printf("%d\n", map[i][k]);
			count--;
			if (count == 0) return 0;
		}
	}
}
int main(){
int tt[100][100];
int r,c;
scanf("%d%d",&r,&c);
for(int x=0;x<r;x++){
	for(int y=0;y<c;y++){
        scanf("%d",&tt[x][y]);
	}
}
int i1=0,i2=c-1,i3=r-1,i4=0,m1=0,m2=1,m3=c-2,m4=r-2,n1=c-1,n2=r-1,n3=0,n4=1,j,s=0,a=1;
while(1){
for(j=m1;j<=n1&&a==1;j++){
	printf("%d\n",tt[i1][j]);
    s+=1;
	if(s==r*c){a=0;}
}
m1++;n1--;i1++;
for(j=m2;j<=n2&&a==1;j++){
	printf("%d\n",tt[j][i2]);
    s+=1;
	if(s==r*c){a=0;}
}
m2++;n2--;i2--;
for(j=m3;j>=n3&&a==1;j--){
	printf("%d\n",tt[i3][j]);
    s+=1;
	if(s==r*c){a=0;}
}
m3--;n3++;i3--;
for(j=m4;j>=n4&&a==1;j--){
	printf("%d\n",tt[j][i4]);
    s+=1;
	if(s==r*c){a=0;}
}
m4--;n4++;i4++;
if(a==0){break;}
}
return 0;
}
int main(){
    int matrix[100][100],i,j,m,n,row,col,counter=0,sum,flag;
    scanf("%d %d",&row,&col);
    sum=row*col;
    for(i=0;i<row;i++){
                       for(j=0;j<col;j++)
                       scanf("%d",&matrix[i][j]);
                       }
    for(flag=0;;flag++){
                        for(j=flag;j<col-flag;j++){
                                                   printf("%d\n",matrix[flag][j]);
                                                   counter++;
                                                   }
                        if(counter==sum)
                        break;
                        for(i=flag+1;i<row-flag;i++){
                                                     printf("%d\n",matrix[i][col-1-flag]);
                                                     counter++;
                                                     }
                        if(counter==sum)
                        break;
                        for(j=col-2-flag;j>=flag;j--){
                                                      printf("%d\n",matrix[row-1-flag][j]);
                                                      counter++;
                                                      }
                        if(counter==sum)
                        break;
                        for(i=row-2-flag;i>flag;i--){
                                                     printf("%d\n",matrix[i][flag]);
                                                     counter++;
                                                     }
                        if(counter==sum)
                        break;
                        }
    return 0;
}
int main()
{
	int sz[100][100],i,j,h,l,zs=0,ys,yx,n,k=0;
	scanf("%d %d",&h,&l);
	ys=l-1;
	yx=h-1;
	n=h*l;
	for(i=0;i<h;i++)
		for(j=0;j<l;j++)
			scanf("%d",&sz[i][j]);
    while(k!=-1)
	{
	for(i=zs,j=zs;j<=ys;j++)
	   {printf("%d\n",sz[i][j]);k++;if(k==n)return 0;}
	for(j=ys,i=zs+1;i<=yx;i++)
	   {printf("%d\n",sz[i][j]);k++;if(k==n)return 0;}
	for(i=yx,j=ys-1;j>=zs;j--)
	   {printf("%d\n",sz[i][j]);k++;if(k==n)return 0;}
	for(i=yx-1,j=zs;i>zs;i--)
	   {printf("%d\n",sz[i][j]);k++;if(k==n)return 0;}
	zs++;ys--;yx--;
	if(k==n)return 0;
	}
return 0;
}
int main()
{
	int a[100][100],b[100][100],j,q,k,i,n,m,row,col;
	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)
	{
		if(col%2==0){
      k=col/2;
	  for(q=1;q<=k;q++){
			
i=0;
for(j=0;j<col-1;j++)     
printf("%d\n",a[i][j]);

j=col-1;
for(i=0;i<row-1;i++)
printf("%d\n",a[i][j]);

i=row-1;
for(j=col-1;j>0;j--)     
printf("%d\n",a[i][j]);

j=0;
for(i=row-1;i>0;i--)
printf("%d\n",a[i][j]); 
	  
	  	  
	  for(i=1,n=0;i<row-1;i++,n++){
		for(j=1,m=0;j<col-1;j++,m++){
         b[n][m]=a[i][j];
		}
	  }
		 for(i=0;i<row;i++){
		for(j=0;j<col;j++){
        a[i][j]=b[i][j];
		}
	}

col=col-2;
row=row-2;
	  }
		}

		else
		{
		
		k=col/2;
		for(q=1;q<=k;q++){
			
i=0;
for(j=0;j<col-1;j++)     
printf("%d\n",a[i][j]);

j=col-1;
for(i=0;i<row-1;i++)
printf("%d\n",a[i][j]);

i=row-1;
for(j=col-1;j>0;j--)     
printf("%d\n",a[i][j]);

j=0;
for(i=row-1;i>0;i--)
printf("%d\n",a[i][j]);  
	  
	  	  
	  for(i=1,n=0;i<row-1;i++,n++){
		for(j=1,m=0;j<col-1;j++,m++){
         b[n][m]=a[i][j];
		}
	  }
		 for(i=0;i<row;i++){
		for(j=0;j<col;j++){
        a[i][j]=b[i][j];
		}
	}

col=col-2;
row=row-2;
		}
		for(i=0;i<row;i++)
           printf("%d\n",a[i][0]) ;
		}
	}


	else
{
		if(row%2==0){
      k=row/2;
	  for(q=1;q<=k;q++){
			
i=0;
for(j=0;j<col-1;j++)     
printf("%d\n",a[i][j]);

j=col-1;
for(i=0;i<row-1;i++)
printf("%d\n",a[i][j]);

i=row-1;
for(j=col-1;j>0;j--)     
printf("%d\n",a[i][j]);

j=0;
for(i=row-1;i>0;i--)
printf("%d\n",a[i][j]); 
	  
	  	  
	  for(i=1,n=0;i<row-1;i++,n++){
		for(j=1,m=0;j<col-1;j++,m++){
         b[n][m]=a[i][j];
		}
	  }
		 for(i=0;i<row;i++){
		for(j=0;j<col;j++){
        a[i][j]=b[i][j];
		}
	}

col=col-2;
row=row-2;
	  }
		}

		else
		{
		
		k=row/2;
		for(q=1;q<=k;q++){
			
i=0;
for(j=0;j<col-1;j++)     
printf("%d\n",a[i][j]);

j=col-1;
for(i=0;i<row-1;i++)
printf("%d\n",a[i][j]);

i=row-1;
for(j=col-1;j>0;j--)     
printf("%d\n",a[i][j]);

j=0;
for(i=row-1;i>0;i--)
printf("%d\n",a[i][j]);
	  
	  	  
	  for(i=1,n=0;i<row-1;i++,n++){
		for(j=1,m=0;j<col-1;j++,m++){
         b[n][m]=a[i][j];
		}
	  }
		 for(i=0;i<row;i++){
		for(j=0;j<col;j++){
        a[i][j]=b[i][j];
		}
	}

col=col-2;
row=row-2;
		}
		for(j=0;j<col;j++)
           printf("%d\n",a[0][j]) ;
		}
	}
		 
		 
		 return 0;
}
int main()
{
	int i,j,a[100][100],k,r,c,row,col,s,a1,a2,t;
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	s=0;
	t=row*col;
	a1=0;
	a2=0;
	r=0;
	c=0;
	for(k=0;k<=100;k++)
	{
		for(c=a2;c<col;c++)
		{
			printf("%d\n",a[r][c]);
			s++;
			if(s==t)
			{
				return 0;
            }
		}
		col--;
		c--;
		a1++;
		for(r=a1;r<row;r++)
		{
			printf("%d\n",a[r][c]);
			s++;	
			if(s==t)
			{
				return 0;
            }
		}
		row--;
		r--;
		for(c=col-1;c>=a2;c--)
		{
			printf("%d\n",a[r][c]);
			s++;	
			if(s==t)
			{
				return 0;
            }
		}
		c++;
		for(r=row-1;r>=a1;r--)
		{
			printf("%d\n",a[r][c]);
			s++;		
			if(s==t)
			{
				return 0;
            }
		}
		r++;
		a2++;
	}
}
void main()
{
	int m,n,i,j,a[100][100],l=0,p,q;
	scanf("%d%d",&m,&n);
	p=m,q=n;
	for(i=0;i<m;i++)
		for(j=0;j<n;j++)
			scanf("%d",&a[i][j]);
	while(p>2&&q>2)
	{
		for(j=l;j<n-l;j++)
			printf("%d\n",a[l][j]);
		for(i=l+1;i<m-l;i++)
			printf("%d\n",a[i][n-l-1]);
		for(j=n-l-2;j>l;j--)
			printf("%d\n",a[m-l-1][j]);
		for(i=m-l-1;i>l;i--)
			printf("%d\n",a[i][l]);
		l++;
		p=m-2*l;
		q=n-2*l;
	}
	if(p==1)
		for(j=l;j<n-l;j++)
			printf("%d\n",a[l][j]);
	else if(q==1)
		for(i=l;i<m-l;i++)
			printf("%d\n",a[i][l]);
		else if(p==2)
		{
			for(j=l;j<n-l;j++)
				printf("%d\n",a[l][j]);
			for(j=n-l-1;j>=l;j--)
				printf("%d\n",a[l+1][j]);
		}
		else if(q==2)
		{
			printf("%d\n",a[l][l]);
			for(i=l;i<m-l;i++)
				printf("%d\n",a[i][l+1]);
			for(i=m-l-1;i>l;i--)
				printf("%d\n",a[i][l]);
		}
}
// *****************************************************************************
//*????????????.cpp
//*??;1300012725
//*?????2013.11
//*?????????????
//******************************************************************************




int main()
{
	int a[200][200];
	int r, c, i, j, p;    //i,j?????????????????????p??????

	cin >> r >> c;    
	for( i = 1; i <= r; i++ )
	{
		for( j = 1; j <= c; j++ )
		{
			cin >> a[i][j];   //??????
		}
	}
	i = 1;
	j = 1;
	while( i <= r && j <= c )
	{
		for( p = j; p <= c; p++ )
		{
			cout << a[i][p] << endl;    //??????????
		}
		for( p = i+1; p <= r;p++ )
		{
			cout << a[p][c] << endl;   //??????????
		}
		for( p = c-1; p >= j && i != r && j != c; p-- )
		{
			cout << a[r][p] << endl;  //??????????
		}
		for( p = r-1; p > i && i != r && j != c; p-- )
		{
			cout << a[p][j] << endl;  //??????????
		}
		i++;
		j++;
		r--;
		c--;                        //???????
	}

	return 0;
}
struct node
{
	int over;
	int data;
};
void main()
{
	int row,col,i,j,point=1,heng=0,zong=0;
	struct node x[102][102];
	scanf("%d%d",&row,&col);

	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
		{
			scanf("%d",&x[i][j].data);
			x[i][j].over=1;
		}
	}
	printf("%d\n",x[0][0].data);
	x[0][0].over=0;
	for(i=1;i<(row*col);)
	{
		if(point%4==1)
		{
			if(x[heng][zong+1].over==1&&(zong+1)<col)
			{
				zong++;
				printf("%d\n",x[heng][zong].data);
				x[heng][zong].over=0;
				i++;
			}
			else
				point++;
		}
		if(point%4==2)
		{
			if(x[heng+1][zong].over==1&&(heng+1)<row)
			{
				heng++;
				printf("%d\n",x[heng][zong].data);
				x[heng][zong].over=0;
				i++;
			}
			else
				point++;
		}
		if(point%4==3)
		{
			if(x[heng][zong-1].over==1&&(zong-1)>=0)
			{
				zong--;
				printf("%d\n",x[heng][zong].data);
				x[heng][zong].over=0;
				i++;
			}
			else
				point++;
		}
		if(point%4==0)
		{
			if(x[heng-1][zong].over==1&&(heng-1)>=0)
			{
				heng--;
				printf("%d\n",x[heng][zong].data);
				x[heng][zong].over=0;
				i++;
			}
			else
				point++;
		}
	}
}