semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main()
{int i,e,array[100][100],col,row,n=0;
	scanf("%d %d",&row,&col);
	for(i=0;i<row;i++)
	{	for(e=0;e<col;e++)
			scanf("%d",&array[i][e]);
	}
	i=0;
	while(n<col*row)
	{	for(e=0;e<col;e++)
		{	
			if(array[i][e]!=0)
			{	printf("%d\n",array[i][e]);
				array[i][e]=0;
				n++;
			}
		}
		for(e=0;e<row;e++)
		{	if(array[e][col-1-i]!=0)
			{	printf("%d\n",array[e][col-1-i]);
				array[e][col-1-i]=0;
				n++;
			}
		}
		for(e=1;e<=col;e++)
		{	if(array[row-i-1][col-e]!=0)
			{	printf("%d\n",array[row-1-i][col-e]);
				array[row-1-i][col-e]=0;
				n++;
			}
		}
		for(e=1;e<=row;e++)
		{	if(array[row-e][i]!=0)
			{	printf("%d\n",array[row-e][i]);
				array[row-e][i]=0;
				n++;
			}
		}
		i++;

	}
	return 0;
}
int main()
{
	int row,col;
	int array[100][100];
	int i,j,count,n;
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
		{
			scanf("%d",&array[i][j]);
		}
	}
	count=0;
	for(n=0;;n++)
	{
		for(i=n;i<col-n;i++)
		{
			printf("%d\n",array[n][i]);
			count++;
		}
		for(j=n+1;j<row-n;j++)
		{
			printf("%d\n",array[j][col-n-1]);
			count++;
		}
		if (count==row*col) break;
		for(i=col-2-n;i>=n;i--)
		{
			printf("%d\n",array[row-n-1][i]);
			count++;
		}
		for(j=row-2-n;j>n;j--)
		{
			printf("%d\n",array[j][n]);
			count++;
		}
	}
	return 0;
}
int main(){
    int h,l;
	int i,j,n,t=0;
	int sz[100][100];
	scanf("%d%d",&h,&l);
	for(i=0;i<h;i++){
		for(j=0;j<l;j++){
			scanf("%d",&sz[i][j]);
		}
	}
	for(n=0;;n++){
		for(i=n,j=n;j<l-n;j++){
			printf("%d\n",sz[i][j]);
			t++;
		}
		if(t==h*l){
			break;}
		for(j=l-1-n,i=1+n;i<h-n;i++){
			printf("%d\n",sz[i][j]);
			t++;
		}
		if(t==h*l){
			break;}
		for(i=h-1-n,j=l-2-n;j>=n;j--){
			printf("%d\n",sz[i][j]);
			t++;
		}
		if(t==h*l){
			break;}
		for(j=n,i=h-2-n;i>n;i--){
			printf("%d\n",sz[i][j]);
			t++;
		}
		if(t==h*l){
			break;}
	}
	return 0;
}
void main()
{
	int array[100][100]={0},i,j,row,col,h=0,n,k,r,c,m;
	scanf("%d%d",&row,&col);
	r=row;
	c=col;
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
		{
			scanf("%d",&array[i][j]);
		}
	}
	if(r<=c)
	{
		n=(r*2-1)/4;
		m=2*r-1;
	}
	else
	{
		n=(c*2)/4;
		m=c*2;
	}
	
		for(k=0;k<n;k++)
		{
			for(i=h,j=h;j<col;j++)
			{
				printf("%d\n",array[i][j]);
			}
			for(j=col-1,i=h+1;i<row;i++)
			{
				printf("%d\n",array[i][j]);
			}
			for(i=row-1,j=col-2;j>=h;j--)
			{
				printf("%d\n",array[i][j]);
			}
			for(j=h,i=row-2;i>=h+1;i--)
			{
				printf("%d\n",array[i][j]);
			}
			h++;
			col--;
			row--;
		}

		if(m%4==1)
		{
			for(i=h,j=h;j<col;j++)
			{
				printf("%d\n",array[i][j]);
			}
		}
		if(m%4==2)
		{
			for(i=h,j=h;j<col;j++)
			{
				printf("%d\n",array[i][j]);
			}
			for(j=col-1,i=h+1;i<row;i++)
			{
				printf("%d\n",array[i][j]);
			}
		}
		if(m%4==3)
		{
			for(i=h,j=h;j<col;j++)
			{
				printf("%d\n",array[i][j]);
			}
			for(j=col-1,i=h+1;i<row;i++)
			{
				printf("%d\n",array[i][j]);
			}
			for(i=row-1,j=col-2;j>=h;j--)
			{
				printf("%d\n",array[i][j]);
			}
		}
	
	
}
int main()
{
	int i=0,j=0,row=0,col=0,count=0,k=0,l=0,m=0;
	int a[110][110]={0};
	cin>>row>>col;
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
		{
			cin>>a[i][j];
		}
	}//????????
	int total = row * col;
	for(i=0;count < total;i++)//???????????row?col??????
	{
		for(j=i;j<col-i;j++)
		{
			cout<<a[i][j]<<'\n';
			count++;
		}
		if(count >= total)
			break;
		for(k=i+1;k<row-i;k++)
		{
			cout<<a[k][col-i-1]<<'\n';
			count++;
		}
		if(count >= total)
			break;
		for(l=col-i-2;l>=i;l--)
		{
			cout<<a[row-i-1][l]<<'\n';
			count++;
		}
		if(count >= total)
			break;
		for(m=row-i-2;m>=i+1;m--)
		{
			cout<<a[m][i]<<'\n';
			count++;
		}//??????????????,????????????????????
	}
	return 0;
}
void main()
{
	int a[105][105];
	int flag=1,loci=0,locj=0,row,col,upwall=0,downwall,rightwall,leftwall=-1,i,j;
	scanf("%d %d",&row,&col);
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			scanf("%d",&a[i][j]);
	rightwall=col;
	downwall=row;
	for(i=1;i<row*col;){
		if(locj+1<rightwall&&flag==1){printf("%d\n",a[loci][locj++]);i++;}
		else if(locj-1>leftwall&&flag==2){printf("%d\n",a[loci][locj--]);i++;}
		else if(loci+1<downwall&&flag==3){printf("%d\n",a[loci++][locj]);i++;}
		else if(loci-1>upwall&&flag==4){printf("%d\n",a[loci--][locj]);i++;}
		else if(locj+1==rightwall&&flag==1){
			rightwall--;
			flag=3;
		}
		else if(locj-1==leftwall&&flag==2){
			leftwall++;
			flag=4;
		}
		else if(loci+1==downwall&&flag==3){
			downwall--;
			flag=2;
		}
		else if(loci-1==upwall&&flag==4){
			upwall++;
			flag=1;
		}
	}
	printf("%d\n",a[loci][locj]);
}
void main()
{
	int m,n;
	scanf("%d %d",&m,&n);
	int a[100][100];
	int i,j;
	for(i=0;i<m;i++)
	{
		for(j=0;j<n;j++)
			scanf("%d",&a[i][j]);
	}
	int hd/*?????*/,hu/*?????*/,lr/*?????*/,ll/*?????*/;

	if(m%2==0 && m<=n)                     //???????? ??????????
	{
	for(i=0,j=0;i<=(m/2-1);i++,j++)           //????????? ???????? ????????
	{
	for(lr=j;lr<(n-j);lr++)
		printf("%d\n",a[i][lr]);
	for(hd=i+1;hd<(m-i);hd++)
		printf("%d\n",a[hd][n-1-j]);
	for(ll=n-2-j;ll>=j;ll--)
		printf("%d\n",a[m-1-i][ll]);
	for(hu=m-2-i;hu>i;hu--)
		printf("%d\n",a[hu][j]);
	}
	}


	if(n%2==0 && m>n)
	{
	for(i=0,j=0;j<=(n/2-1);i++,j++)
	{
	for(lr=j;lr<(n-j);lr++)
		printf("%d\n",a[i][lr]);
	for(hd=i+1;hd<(m-i);hd++)
		printf("%d\n",a[hd][n-1-j]);
	for(ll=n-2-j;ll>=j;ll--)
		printf("%d\n",a[m-1-i][ll]);
	for(hu=m-2-i;hu>i;hu--)
		printf("%d\n",a[hu][j]);
	}
	}

	if(m>n && n%2!=0)
	{
	for(i=0,j=0;j<=((n-1)/2-1);i++,j++)
	{
	for(lr=j;lr<(n-j);lr++)
		printf("%d\n",a[i][lr]);
	for(hd=i+1;hd<(m-i);hd++)
		printf("%d\n",a[hd][n-1-j]);
	for(ll=n-2-j;ll>=j;ll--)
		printf("%d\n",a[m-1-i][ll]);
	for(hu=m-2-i;hu>i;hu--)
		printf("%d\n",a[hu][j]);
	}
	for(j=(n-1)/2;j<m-(n-1)/2;j++)
		printf("%d\n",a[j][(n-1)/2]);
	}

	if(m<=n && m%2!=0)
	{
	for(i=0,j=0;i<=((m-1)/2-1);i++,j++)
	{
	for(lr=j;lr<(n-j);lr++)
		printf("%d\n",a[i][lr]);
	for(hd=i+1;hd<(m-i);hd++)
		printf("%d\n",a[hd][n-1-j]);
	for(ll=n-2-j;ll>=j;ll--)
		printf("%d\n",a[m-1-i][ll]);
	for(hu=m-2-i;hu>i;hu--)
		printf("%d\n",a[hu][j]);
	}
	for(i=(m-1)/2;i<n-(m-1)/2;i++)
		printf("%d\n",a[(m-1)/2][i]);
	}

}
int main(){
   int r,c;
    scanf("%d%d",&r,&c); 
    int sz[r][c];
    for(int i=0;i<r;i++){for(int k=0;k<c;k++){scanf("%d",&sz[i][k]);}}
    int a ;
    if(r>c){a=c;}
    else {a=r;}int x=0;
    for (int i=0;i<a/2;i++){for (int m=x;m<c-x;m++){printf("%d\n",sz[x][m]);}
                             for(int m=x+1;m<r-x;m++){printf("%d\n",sz[m][c-1-x]);}
                             for(int m=c-2-x;m>x;m--){printf("%d\n",sz[r-1-x][m]);}
                             for(int m=r-1-x;m>x;m--){printf("%d\n",sz[m][x]);}
                             x++;
         }
       if(c>=r&&r%2!=0){for(int i=r/2;i<c-r/2;i++){printf("%d\n",sz[r/2][i]);}}
                            if(r>c&&c%2!=0){for(int i=c/2;i<r-c/2;i++){printf("%d\n",sz[i][c/2]);}
         }
         
        
         return 0;
}
int main()
{
   int a[102][102],b[102][102];
   int m,n,x,y,i,j;
   scanf("%d%d",&n,&m);
   for(i=0;i<n;i++)
      for(j=0;j<m;j++)
         scanf("%d",&a[i][j]);
   
   int k=1;
   x=0;y=0;
   printf("%d\n",a[0][0]);
   b[0][0]=1;
   while(k<m*n)
   {
        while((y+1<m)&&(b[x][y+1]==0))
        {
            y++;
            k++;
            b[x][y]=1;
            printf("%d\n",a[x][y]);
        }
        while((x+1<n)&&(b[x+1][y]==0))
        {
            x++;
            k++;
            b[x][y]=1;
            printf("%d\n",a[x][y]);
        }
        while((y-1>=0)&&(b[x][y-1]==0))
        {
            y--;
            k++;
            b[x][y]=1;
            printf("%d\n",a[x][y]);
        }
        while((x-1>=0)&&(b[x-1][y]==0))
        {
            x--;
            k++;
            b[x][y]=1;
            printf("%d\n",a[x][y]);
        }
    }
    return 1;
}
int main(int argc, char *argv[])
{
    int x[100][100],i,j,k,n,col,row;
    scanf("%d""%d",&row,&col);
    for (i=0;i<row;i++)
    {
        for (j=0;j<col;j++)
        {
            scanf("%d",&x[i][j]);
        }
    }
    if (col>row)
        n=row;
    else if (col<row)
        n=col;
    else if (col==row)
        n=row;
    n=n/2-1;

    for (k=0;k<=n;k++)
    {
//the 1st we will try to output the num in row=0
    for (i=k,j=k;j<col-1-k;j++)//x[0][0]~x[0][col-2]
    {
        printf("%d\n",x[i][j]);
    }
//the 2nd output the num in  col=col-1
    for (i=k,j=col-1-k;i<row-1-k;i++)//x[0][col-1]~x[row-2][col-1]
    {
        printf("%d\n",x[i][j]);
    }

//the 3rd output the num in row=row-1
    for (i=row-1-k,j=col-1-k;j>k;j--)//x[row-1][col-1]~x[row-1][1]
    {
        printf("%d\n",x[i][j]);
    }

//the 4th outoput the num in col=0
    for (i=row-1-k,j=k;i>k;i--)//x[row-1][0]~x[1][0]
    {
        printf("%d\n",x[i][j]);
    }

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

  return 0;
}
int main(){
 int b[100][100],Row,Col,n,i,k,l,row,col,s=0;
 scanf("%d %d",&Row,&Col);
 for(row=0;row<Row;row++){
    for(col=0;col<Col;col++){
     scanf("%d",&b[row][col]);
                            }
                      }
for(i=1;s<Row*Col;i=i+1){
  s=s+(Row+Col-4*i+4)*2-4;
                          }
 n=i-1;
 s=0;
 for(k=1;k<=n;k++){
    for(l=k-1;l<=Col-k&&s!=Row*Col;l++){
       printf("%d\n",b[k-1][l]);
        s=s+1;
                           }
    for(l=k;l<=Row-k&&s!=Row*Col;l++){
        printf("%d\n",b[l][Col-k]);
        s=s+1;
                          }
   for(l=Col-k-1;l>=k-1&&s!=Row*Col;l--){ 
       printf("%d\n",b[Row-k][l]);
       s=s+1;
                            }
   for(l=Row-k-1;l>=k&&s!=Row*Col;l--){
     printf("%d\n",b[l][k-1]);
     s=s+1;
                           }
       }
return 0;
}
int  main()
{
	int row,col,k,j;
	int time=0;
	cin>>row>>col;
	int arr[100][100];
	for(k=0;k<row;k++)
		for(j=0;j<col;j++)
		{
			cin>>arr[k][j];
		}
        int i=0;
	while(time<row*col)
	{

		for(k=i;k<col-i&&time<row*col;k++)
		{
			cout<<arr[i][k]<<endl;
			time++;
		}
		for(k=i+1;k<row-i&&time<row*col;k++)
		{
			cout<<arr[k][col-i-1]<<endl;
			time++;
		}
		for(k=col-i-2;k>=i&&time<row*col;k--)
		{
			cout<<arr[row-i-1][k]<<endl;
			time++;
		}
		for(k=row-i-2;k>i&&time<row*col;k--)
		{
			cout<<arr[k][i]<<endl;
			time++;
		}
		i++;
	}
	return 0;
}
int main()
{
    int a[4][2]={0,1,1,0,0,-1,-1,0};
    int i,n,m,j,p;
    int map[200][200];
    int x,y;
    scanf("%d%d",&n,&m);
    for(i=0;i<=n+1;i++)
    for(j=0;j<=m+1;j++)
    map[i][j]=-1;
    for(i=1;i<=n;i++)
    for(j=1;j<=m;j++)
    scanf("%d",&map[i][j]);
    x=1;y=1;p=0;
    printf("%d",map[1][1]);
    map[1][1]=-1;
    while(1)
    {
            if(map[x+a[p][0]][y+a[p][1]]!=-1)
            {
                                             x+=a[p][0];
                                             y+=a[p][1];
                                             printf("\n%d",map[x][y]);
                                             map[x][y]=-1;
            }
            else
            {
                p=(p+1)%4;
                if(map[x+a[p][0]][y+a[p][1]]!=-1)
            {
                                             x+=a[p][0];
                                             y+=a[p][1];
                                             printf("\n%d",map[x][y]);
                                             map[x][y]=-1;
            }
            else
            break;
            }
    }
    //getch();
    return 0;
}
int dat[102][102];
_Bool use[102][102];
int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
int main()
{
    int n,m;
    int l1,l2,i,j,d;
    scanf("%d%d",&m,&n);
    for (l1=1;l1<=m;l1++)
        for (l2=1;l2<=n;l2++)
            scanf("%d",&dat[l1][l2]);
    for (l1=1;l1<=m;l1++)
        use[l1][0]=use[l1][n+1]=1;
    for (l1=1;l1<=n;l1++)
        use[0][l1]=use[m+1][l1]=1;
    i=1;
    j=1;
    d=0;
    while (1)
        {
        printf("%d\n",dat[i][j]);
        use[i][j]=1;
        for (l1=1;l1<=4;l1++)
            if (use[i+dir[d][0]][j+dir[d][1]]==1)
                d=(d+1)%4;
            else
                {
                    i+=dir[d][0];
                    j+=dir[d][1];
                    break;
                }
        if (l1==5)
            break;
        }
    return 0;
}
int main()
{
	int row, col, array[100][100], i, j, k, min, flag;
	cin >> row >> col;
	for (i = 1; i <= row; i++)
	{
		for (j = 1; j <= col; j++)
		{
			cin >> array[i][j];
		}
	}
    
    min = (row < col) ? row : col;
	for (k = 0; 2 * k < min; k++)
	{
		flag = 0;
		for (i = 1 + k; i <= col - k; i++)
			cout << array[1 + k][i] << endl;
		for (j = 2 + k; j <= row - k; j++)
		{cout << array[j][col - k] << endl; flag=1;}
		if(flag)
		{flag=0;
		for (i = col - k - 1; i >= 1 + k; i--)
		{cout << array[row - k][i] << endl;flag=1;}
		if(flag)
		for (j =row - k - 1; j >= 1 + k + 1; j--)
			cout << array[j][1 + k] << endl;
		}
	}
	return 0;
}
int main()
{
int m1[100][100],i,j,k,a,b,c=0,d,e,x=-1;
scanf("%d %d\n",&a,&b);
e=a;d=b;
for(i=0;i<a;i++)
{
  for(j=0;j<b-1;j++){
    scanf("%d",&m1[i][j]);}
    scanf("%d\n",&m1[i][b-1]);
}
for(k=1;k<100000;k++){
x=x+1;
for(j=x;j<b-x;j++)
{
printf("%d\n",m1[x][j]);
c+=1;
}
if(c==d*e)break;
for(i=x+1;i<a-x;i++)
{
printf("%d\n",m1[i][b-x-1]);
c+=1;
}
if(c==d*e)break;
for(j=2+x;j<b+1-x;j++)
{
printf("%d\n",m1[a-1-x][b-j]);
c+=1;
}
if(c==d*e)break;
for(i=2+x;i<a-x;i++)
{
printf("%d\n",m1[a-i][x]);
c+=1;
}
if(c==e*d)break;
}
return 0;
}
int main()
{
	int row, col, u, v, w, x, y;
	cin >> row >> col;
	int a = 0, b;
	int c = 1, d;
	int num[150][150] = {0};
	for (u = 0; u <= row - 1; u++)
	{
		for (v = 0; v <= col - 1; v++)
		{
			scanf("%d", &num[u][v]);
		}
	}
	b = col - 1;
	d = row - 1;
	for (u = 0; u <= (row - 1) / 2; u++)
	{
			if (u>b) break;
		    for (v = u; v <= b; v++)
			{
			    cout << num[u][v] << endl;
			}
		    for (w = u + 1; w <= d; w++)
			{
			    cout << num[w][b] << endl;
			}
		    for (x = b - 1; x >= u; x--)
			{
				if (u < d)
			    cout << num[d][x] << endl;
			}
		    for (y = d - 1; y >= u + 1; y--)
			{
				if (u < b)
			    cout << num[y][u] << endl;
			}
			b--;
			d--;
	}
	return 0;
}



/*


a=0;b=m-1;c=0;d=n-1;
while (a<=b && c<=d)
{
print(..);
a++;b--;c++;d--;
}

*/
//********************************
//*???????????   **
//*?????? 1300012861 **
//*???2013.11.01  **
//********************************
int main()
{
	int a[102][102], i, j, k, row, col; 
	cin >> row >> col; 
	for ( i = 0; i < row; i++ )
	{
		for ( j = 0; j < col; j++ )
		{
			cin >> a[i][j]; 
		}
	}
	if ( row <= col )
	{
		if ( row < 2 )
		{
			for ( j = 0; j < col; j++ )
				cout << a[0][j] << endl; 
		}
		if ( row >= 2 )
		{
			for ( i = 0; i < row / 2; i++ )
			{
				for ( j = i; j < col - i; j++ )
				{
					cout << a[i][j] << endl; 
				}
				j--; 
				for ( k = i + 1; k < row - i; k++ )
				{
					cout << a[k][j] << endl; 
				}
				k--; 
				for ( j = j - 1; j >= i; j-- )
				{
					cout << a[k][j] << endl;  
				}
				j++; 
				for ( k = k - 1; k > i; k-- )
				{
					cout << a[k][j] << endl; 
				}
			}
			if ( row % 2 != 0 )
			{
				for ( j = i; j < col - i; j++ )
				{
					cout << a[i][j] << endl; 
				}
			}
		}
	}
	if ( col < row )
	{
		if ( col < 2 )
		{
			for ( i = 0; i < row; i++ )
				cout << a[i][0] << endl; 
		}
		if ( col >= 2 )
		{
			for ( i = 0; i < col / 2; i++ )
			{
				for ( j = i; j < col - i; j++ )
				{
					cout << a[i][j] << endl; 
				}
				j--; 
				for ( k = i + 1; k < row - i; k++ )
				{
					cout << a[k][j] << endl; 
				}
				k--; 
				for ( j = j - 1; j >= i; j-- )
				{
					cout << a[k][j] << endl; 
				}
				j++; 
				for ( k = k - 1; k > i; k-- )
				{
					cout << a[k][j] << endl; 
				}
			}
			if ( col % 2 != 0 )
			{
				for ( k = i; k < row - i; k++ )
				{
					cout << a[k][j+1] << endl; 
				}
			}
		}
	}
	return 0;
}
int main()
{
	int a[100][100]={0},i,j,m,n,s,t,u,v;
	scanf("%d%d",&m,&n);
	for(i=0;i<m;i++)
	{
		for(j=0;j<n;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	i=0;
	j=0;
	s=0;
	t=0;
	u=0;
	v=0;
	for(;;)
	{
	do
	{
		printf("%d\n",a[i][j]);
		j=j+1;
	}
	while (j!=n-s);
	j=j-1;
	s=s+1;
	i=i+1;
	if (v+t+1==m) break;
	do
	{
		printf("%d\n",a[i][j]);
		i=i+1;
	}
	while (i!=m-t);
	i=i-1;
	t=t+1;
	j=j-1;
	if (u+s==n) break;
	do
	{
		printf("%d\n",a[i][j]);
		j=j-1;
	}
	while (j!=u-1);
	u=u+1;
	j=j+1;
	i=i-1;
	if (v+t+1==m) break;
	do
	{
		printf("%d\n",a[i][j]);
		i=i-1;
	}
	while (i!=v);
	v=v+1;
	i=i+1;
	j=j+1;
	if (u+s==n) break;
	}
	return 0;
}
/*
 * ????????.cpp
 *
 *  Created on: 2011-11-4
 *      Author: ???
 */

void hxprint(int a[][100],int n,int m){//??????????????????
	int i,j,b[100][100];
	if(n==0||m==0){//??????0???
		return;
	}
	else{
		for(j=0;j<m;j++)//????????
			cout<<a[0][j]<<endl;
		for(i=1;i<n;i++)
			cout<<a[i][m-1]<<endl;
		if(n==1||m==1) return;//?????????
		else{
			for(j=m-2;j>=0;j--)//????????????
				cout<<a[n-1][j]<<endl;
			for(i=n-2;i>=1;i--)
				cout<<a[i][0]<<endl;
			for(i=0;i<n-2;i++)
				for(j=0;j<m-2;j++){
					b[i][j]=a[i+1][j+1];
				}
			hxprint(b,n-2,m-2);//?????????
		}
	}
}
int main(){
	int i,j,a[100][100],n,m;
	cin>>n>>m;
	for(i=0;i<n;i++)
		for(j=0;j<m;j++)
			cin>>a[i][j];
	hxprint(a,n,m);
	return 0;
}
int main()
{
 int row,col;
 int i,j,n,time=0;
 scanf("%d %d",&row,&col);
 int array[100][100];
 for(i=0;i<row;i++){
  for(j=0;j<col;j++){ 
   scanf("%d",&array[i][j]);
 }
 }
  for (n=0;;n++)
  { 
   for (i=n;i<col-n;i++)
   {
    printf("%d\n",array[n][i]);
    time++;
   }
   printf("\n");
   if(time==row*col)break;
   for (j=n+1;j<row-n;j++)
   {
    printf("%d\n",array[j][col-n-1]);
    time++;
   }
 
   if(time==row*col)break;
   for (i=col-2-n;i>=n;i--)
   {
    printf("%d\n",array[row-n-1][i]);
    time++;
   }
   if(time==row*col)break;
   for (j=row-2-n;j>n;j--)
   {
    printf("%d\n",array[j][n]);
    time++;
   }
   if(time==row*col)break;
  }
  
  return 0;
}
int main()
{
	int row,col,array[100][100],sum=0;
	int i,j;
	scanf("%d%d",&row,&col);
	
	for(i=0;i<row;i++){
		for(j=0;j<col;j++){
			scanf("%d",&array[i][j]);
		}
	}
	
	for(i=0;i<row;i++){
		for(j=i;j<=col-i-1;j++){
			printf("%d\n",array[i][j]);
			sum++;
		}
		if(sum==row*col)
			break;
		for(j=i+1;j<=row-i-1;j++){
			printf("%d\n",array[j][col-i-1]);
			sum++;
		}
		if(sum==row*col)
			break;
		for(j=col-i-1-1;j>=i;j--){
			printf("%d\n",array[row-i-1][j]);
			sum++;
		}
		if(sum==row*col)
			break;
		for(j=row-i-1-1;j>=i+1;j--){
			printf("%d\n",array[j][i]);
			sum++;
		}
		if(sum==row*col)
			break;
	}
	return 0;
}
int main(int argc, char* argv[])
{
	int row,col,n,i,j,a[100][100];
	int sum=0;
	scanf("%d %d",&row,&col);
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
		{
			scanf("%d",&(a[i][j]));
		}
	}
	for(n=0;n<=row;n++)
	{
		for(i=n;i<col-n;i++)
		{
			printf("%d\n",a[n][i]);
			sum++;
		}
		if(sum==row*col)break;
		for(j=n+1;j<row - n;j++)
		{
			printf("%d\n",a[j][col-(n+1)]);
			sum++;
		}
		if(sum==row*col)break;
		for(i=col-(n+1)-1;i>=n;i--)
		{
			printf("%d\n",a[row-(n+1)][i]);
			sum++;
		}
		if(sum==row*col)break;
		for(j=row-(n+1)-1;j>n;j--)
		{
			printf("%d\n",a[j][n]);
			sum++;
		}
		if(sum==row*col)break;
	}
	return 0;
}
int main()
{
	int i,j,k,l,r,c,a[100][100];
	scanf("%d %d",&r,&c);
	for(i=0;i<r;i++)
	{
		for(j=0;j<c;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	l=0;
	k=1;
	if(r==1&&c==1)
		printf("%d",a[0][0]);
	else
	{
	for(j=0;;)
	{
		switch (k)
		{
		case 1: goto p1;break;
		case 2: goto p2;break;
		case 3: goto p3;break;
		case 4: goto p4;
		}
p1:{
		for(i=l;i<c-l;i++)
		{
			printf("%d\n",a[l][i]);
			j++;
			if(j==r*c)
				goto out;
		}
		goto end;
   }
p2:{
		for(i=l+1;i<r-l-1;i++)
		{
			printf("%d\n",a[i][c-l-1]);
			j++;
			if(j==r*c)
				goto out;
		}
		goto end;
   }
p3:{
		for(i=c-l-1;i>=l;i--)
		{
			printf("%d\n",a[r-l-1][i]);
			j++;
			if(j==r*c)
				goto out;
		}
		goto end;
   }
p4:{
		for(i=r-l-2;i>l;i--)
		{
			printf("%d\n",a[i][l]);
			j++;
			if(j==r*c)
				goto out;
		}
		goto end;
   }
end:
	{
		k++;
		if(k>4)
		{
			k=1;
			l++;
		}
	}
	}
	}
out:;
	return 0;
}
void main()
{
	int row,col,a[100][100],i,j,p,q,k;
	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)
		q=row;
	else
		q=col;
	p=(q+1)/2;
	if(row==col||q%2==0)
	{
		for(k=0;k<p;k++)
		{
		for(j=k;j<col-k;j++)
			printf("%d\n",a[k][j]);
		for(i=k+1;i<row-k;i++)
			printf("%d\n",a[i][col-1-k]);
		for(j=col-2-k;j>=k;j--)
			printf("%d\n",a[row-1-k][j]);
		for(i=row-2-k;i>k;i--)
			printf("%d\n",a[i][k]);
		}
	}
	if(row!=col&&q%2!=0)
	{
		if(col>row)
		{
			if(q==1)
			{
				for(j=0;j<col;j++)
					printf("%d\n",a[0][j]);
			}
			else 
			{
				for(k=0;k<p-1;k++)
				{
		          for(j=k;j<col-k;j++)
			        printf("%d\n",a[k][j]);
		          for(i=k+1;i<row-k;i++)
			        printf("%d\n",a[i][col-1-k]);
		          for(j=col-2-k;j>=k;j--)
			        printf("%d\n",a[row-1-k][j]);
		          for(i=row-2-k;i>k;i--)
			        printf("%d\n",a[i][k]);
				}
				for(j=p-1;j<col-p+1;j++)
					printf("%d\n",a[p-1][j]);
			}
		}
		if (row>col)
		{
			if(q==1)
			{
				for(i=0;i<row;i++)
					printf("%d\n",a[i][0]);
			}
			else
			{
				for(k=0;k<p-1;k++)
				{
		          for(j=k;j<col-k;j++)
			        printf("%d\n",a[k][j]);
		          for(i=k+1;i<row-k;i++)
			        printf("%d\n",a[i][col-1-k]);
		          for(j=col-2-k;j>=k;j--)
			        printf("%d\n",a[row-1-k][j]);
		          for(i=row-2-k;i>k;i--)
			        printf("%d\n",a[i][k]);
				}
				for(j=p-1;j<row-p+1;j++)
					printf("%d\n",a[j][p-1]);
			}
		}
	}
}
int main ()
{
	int m,n,i,j,g,h,k,l;
	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]);
		}
	}
	    g=0;
		j=0;
		h=0;
		l=0;
	for(i=0;i<m;i++)
	{
		
		for(j=i;j<n-i;j++)
		{
        if(l==m*n)
		{break;}
			
		
		    printf("%d\n",a[i][j]);
			l++;
       if(l==m*n)
		{break;}
			
	}
		j=n-i-1;
		for(g=i+1;g<m-i;g++)
		{
        if(l==m*n)
		{break;}
			
		
			printf("%d\n",a[g][j]);
			l++;
        if(l==m*n)
		{break;}

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


	}
	return 0;
}
int main()
{
	int array[101][101], pos[101][101] = {0};
	int row, col, i, j, count = 0, n;
	cin >> row >> col;
	n = row * col;
	for (i = 0; i < row; i++)
	{
		for (j = 0; j < col; j++)
		{
			cin >> array[i][j];
			pos[i][j] = 1;
		}
	}
	i = 0;
	j = 0;
	while (1)
	{
		while (pos[i][j+1] != 0)
		{
			cout << array[i][j] << endl;
			pos[i][j] = 0;
			j++;
			count++;
		}
		if (count == n - 1) break;
		while (pos[i+1][j] != 0)
		{
			cout << array[i][j] << endl;
			pos[i][j] = 0;
			i++;
			count++;
		}
		if (count == n - 1) break;
		while (j >= 0 && pos[i][j-1] != 0)
		{
			cout << array[i][j] << endl;
			pos[i][j] = 0;
			j--;
			count++;
		}
		if (count == n - 1) break;
		while (i >= 0 && pos[i-1][j] != 0)
		{
			cout << array[i][j] << endl;
			pos[i][j] = 0;
			i--;
			count++;
		}
		if (count == n - 1) break;
	}
	for (i = 0; i < row; i++)
	{
		for (j = 0; j < col; j++)
		{
			if (pos[i][j] == 1)
			{
				cout << array[i][j] << endl;
			}
		}
	}
	return 0;
}