semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main()
{
    int row, col;
    int i, j, n, time = 0;
    cin >> row >> col;
    int a[100][100];
    for (i = 0; i < row; i++)
        for (j = 0; j < col; j++)
            cin >> a[i][j];
    for (n = 0; ; n++)
    {
        for (i = n; i < col - n; i++)
        {
            cout << a[n][i] << endl;
            time++;
        }
        if (time == row * col)
            break;
        for (j = n + 1; j < row - n; j++)
        {
            cout << a[j][(col - n - 1)] << endl;
            time++;
        }
        if (time == row * col)
            break;
        for (i = col - 2 - n; i >= n; i--)
        {
            cout << a[row - n - 1][i] << endl;
            time++;
        }
        if (time == row * col)
            break;
        for (j = row - 2 - n; j > n; j--)
        {
            cout << a[j][n] << endl;
            time++;
        }
        if (time == row * col)
            break;
    }
    return 0;
}
int main() {
	int row, col, i, k, j, s = 0;
	int a[100][100] = { 0 };
	cin >> row >> col;
	for (i = 0; i < row; i++) {
		for (j = 0; j < col; j++)
			cin >> a[i][j];
	}
	for (i = 0; i < row / 2 + 1 && i < col / 2 + 1; i++) {//????-1
		for (k = i; k < col - i; k++) {//???i?????
			cout << a[i][k] <<endl;
			s++;
		}
		if (s == row * col)//??????
			break;
		for (k = i + 1; k < row - i; k++) {//???i?????
			cout << a[k][col - i - 1] << endl;
			s++;
		}
		if (s == row * col)
			break;
		for (k = col - i - 2; k >= i; k--) {//???i?????
			cout << a[row - i - 1][k] << endl;
			s++;

		}
		if (s == row * col)
			break;
		for (k = row - i - 2; k > i; k--) {//???i????
			cout << a[k][i] << endl;
			s++;

		}
		if (s == row * col)
			break;

	}

	return 0;
}
int main()
{
	int a[100][100] = {0},r,c,i,j,k = 1;
	cin >> r >> c;
	for(i = 1;i <= r;i++)
	{
		for(j = 1;j <= c;j++)
		{
			cin >> a[i][j];
		}
	}
	while((r >= 2)&&(c >= 2))
	{
		for(i = k;i <= c+k-1;i++)
		{
			cout << a[k][i] << endl;
		}
		for(i = k + 1;i <= r+k-1;i++)
		{
			cout << a[i][c+k-1] << endl;
		}
		for(i = c+k-2;i >= k;i--)
		{
			cout << a[r+k-1][i] << endl;
		}
		for(i = r+k-2;i >= k+1;i--)
		{
			cout << a[i][k] << endl;
		}
		k++;
		r = r - 2;
		c = c - 2;
	}
	if((r == 1)&&(c != 1))
	{
		for(i = k;i <= c+k-1;i++)
		{
			cout << a[k][i] << endl;
		}
	}
	if((c == 1)&&(r != 1))
	{
		for(i = k;i <= r+k-1;i++)
		{
			cout << a[i][c+k-1] << endl;
		}
	}
	if((r == 1)&&(c == 1))
	{
		cout << a[k][k] << endl;
	}
	return 0;
}
int main()
{
	int a[101][101],b[101][101]={0};
	int c[4]={-1,0,1,0},d[4]={0,1,0,-1};
	int m,n,i,j,x,y,t;
	scanf("%d%d",&m,&n);
	for (i=1;i<=m;i++)
		for (j=1;j<=n;j++) 
		{
			scanf("%d",&a[i][j]);
			b[i][j]=1;
		}
	x=y=t=1;
	for (i=1;i<=m*n;i++)
	{
		printf("%d\n",a[x][y]);
		b[x][y]=0;
		if (!b[x+c[t]][y+d[t]]) t=(t+1)%4;
		x+=c[t];
		y+=d[t];
	}
	return 0;
}
//********************************
//*??????? **
//*????? 1300012839 **
//*???2013.11.2**
//********************************
int main()
{
	int row,col,n,m,count=0;                              //?n????m????count??????????
	int array[100][100];
	cin >> n >> m;
	for(row = 0;row < n;row++)                               //????????
	{
		for(col = 0;col < m;col++)   
			cin >> array[row][col];
	}
	int k;
	for(k = 1;k <= n / 2 + 1;k++)                                //k????k?
	{
		for(col = k-1;col <= m - k;col++)                      //????????????????????????????count????????????
		{
				if(count == m * n)break;
				cout << array[k-1][col] << endl;
				count++;
		}
				
		for(row = k;row <= n - k;row++)
		{
			if(count == n * m)break;
		    cout << array[row][m-k] << endl;
			count++;
		}

		for(col = m - k - 1;col >= k - 1;col--)
		{
			if(count == n * m)break;
			cout << array[n-k][col] << endl;
			count++;
		}
        for(row = n - k - 1;row >= k;row--)
		{
			if(count == m * n)break;
			cout << array[row][k-1] << endl;
			count++;
		}
		if(count == n * m)break;
	}
	return 0;
}
int matrix[101][101];

void transform(int , int);

int main()
{
        int m, n;
        int i, j;
        scanf("%d%d", &m, &n);
        for (i = 1; i <= m ; i++)
                for (j = 1; j <= n; j++) {
                        scanf("%d", &matrix[i][j]);
                }
        transform(m, n);

        return 0;
}

void transform(int m, int n)
{
        int total = m * n;
        int index = 0;
        int dir = 0;
        int x = 0, y = 0;
        int times[4] = {0};

        while (index < total) {
                switch(dir) {
                        case 0:
                                x++;y++;
                                while ( y < n - times[1] ) {
                                        printf("%d\n", matrix[x][y]);
                                        y++;
                                        index++;
                                }
                                break;
                        case 1:
                                while ( x < m - times[2]) {
                                        printf("%d\n", matrix[x][y]);
                                        x++;
                                        index++;
                                }
                                break;
                        case 2:
                                while ( y > times[3] + 1 ) {
                                        printf("%d\n", matrix[x][y]);
                                        y--;
                                        index++;
                                }
                                break;
                        case 3:
                                while ( x > times[0] ) {
                                        printf("%d\n", matrix[x][y]);
                                        x--;
                                        index++;
                                }
                                break;
                        default:
                                break;
                }
                if (total - index == 1) {
                        if (dir == 3) x++, y++;
                        printf("%d\n", matrix[x][y]);
                        index++;
                }
                times[dir]++;
                dir = (dir+1)%4;
        }
}
int main()
{
	int col,row,sz[100][100],i,j,m=0,k;
	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)
	{
	 for(k=1;2*k<col+1;k++)
	 {
		   for(j=k-1;j<col-k;j++)
		   {
		    	 printf("%d\n",sz[k-1][j]);
			     m++;	
		   }
		   for(i=k-1;i<row-k;i++)
		   {
		    	 printf("%d\n",sz[i][col-k]);
			     m++;	
		   }
		   for(j=col-k;j>k-1;j--)
		   {
		    	 printf("%d\n",sz[row-k][j]);
			     m++;	
		   }
		   for(i=row-k;i>k-1;i--)
		   {
		       	printf("%d\n",sz[i][k-1]);
			    m++;
		   }
	 }
	 for(i=k-1;i<row,m<row*col;i++,m++)
	 {
		 printf("%d\n",sz[i][k-1]);
	 }
	}
	else
	{
       for(k=1;2*k<row+1;k++)
	   {
		   for(j=k-1;j<col-k;j++)
		   {
		    	 printf("%d\n",sz[k-1][j]);
			     m++;	
		   }
		   for(i=k-1;i<row-k;i++)
		   {
		    	 printf("%d\n",sz[i][col-k]);
			     m++;	
		   }
		   for(j=col-k;j>k-1;j--)
		   {
		    	 printf("%d\n",sz[row-k][j]);
			     m++;	
		   }
		   for(i=row-k;i>k-1;i--)
		   {
		       	printf("%d\n",sz[i][k-1]);
			    m++;
		   }
	   }
	   for(j=k-1;j<col-k,m<row*col;j++,m++)
	   {
	     	 printf("%d\n",sz[k-1][j]);
	   }
	}
	return 0;
}
int main()
{   int a[100][100];
	int row,col,i,j,t1,t2=0;
	scanf("%d %d",&row,&col);
	for(i=0;i<row;i++){
		for(j=0;j<col;j++){
			scanf("%d",&a[i][j]);
		}
	}
    for(t1=0;t1<row;t1++){
		if(t2==row*col){
			break;
		}
		for(j=t1;j<col-t1;j++){
			printf("%d\n",a[t1][j]);
			t2++;
		}
		if(t2==row*col){
			break;
		}
		for(i=t1+1;i<row-t1;i++){
			printf("%d\n",a[i][col-t1-1]);
			t2++;
		}
		if(t2==row*col){
			break;
		}
		for(j=col-t1-2;j>=t1;j--){
			printf("%d\n",a[row-t1-1][j]);
		    t2++;
		}
		if(t2==row*col){
			break;
		}
		for(i=row-t1-2;i>=t1+1;i--){
			printf("%d\n",a[i][t1]);
		    t2++;
		}
		if(t2==row*col){
			break;
		}
	}
	return 0;
}
int main()
{
       int i,j,row,col,k;
       int 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]));
               }
       }
       for(k=0;k<((col+col%2)/2);k++)
       {
			if(k>row-k-1)continue;
			 for(i=k;i<col-k;i++)
                       {
                               printf("%d\n",a[k][i]);
                       }
			if(k+1>row-k-1)continue;
               for(j=k+1;j<=row-k-1;j++)
                       {
                               printf("%d\n",a[j][col-k-1]);
                       }
			if(col-k-2<k)continue;
               for(i=col-k-2;i>=k;i--)
                       {
                               printf("%d\n",a[row-k-1][i]);
                       }
               for(j=row-2-k;j>=k+1;j--)
                       {
                               printf("%d\n",a[j][k]);
                       }
       }
       return 0;
}
int main()
{
    int array[100][100], n, m, i1, i2, j1, j2, s1, s2, t, h, num = 0, k;
    
    cin >> n >> m;
    
    k = n * m;
    
    if(n % 2 == 0) h = n / 2;
    else h = n / 2 + 1;
    
    for(i1 = 0; i1 < n; i1++)
    for(j1 = 0; j1 < m; j1++)
    cin >> array[i1][j1];
    
    for(i1 = 0; i1 < h; i1++)
    {
        for(j1 = i1; j1 < m - i1; j1++)
        {
            if(num >= k) break;
            
            cout << array[i1][j1] << endl;

            s1 = j1;
            
            num++;
        }
        
        for(i2 = i1 + 1; i2 < n - i1; i2++)
        {
            if(num >= k ) break;
            
            cout << array[i2][s1] << endl;
            
            t = i2;
            
            num++;
        }
        
        for(j2 = s1 - 1; j2 >= i1; j2--)
        {
            if(num >= k) break;
            
            cout << array[t][j2] << endl;
            
            s2 = j2;
            
            num++;
        }
        
        for(i2 = t - 1; i2 >= i1 + 1; i2--)
        {
            if(num >= k) break;
            
            cout << array[i2][s2] << endl;
            
            num++;
        }
    }

    return 0;
}
int main()
  { int i,j,k,hang,lie,a[100][100],total,sum=0;//??????????total?????????total=hang*lie? 
       
    scanf("%d %d\n",&hang,&lie);
    total=hang*lie;
    for(i=0;i<=hang-1;i++)
    { for(j=0;j<=lie-1;j++)
      scanf("%d",&a[i][j]);}
    
    
    for(k=1;k<=10000;k++)
    { 
      for(j=k-1;j<=lie-k;j++)
      { printf("%d\n",a[k-1][j]);sum=sum+1;
        if(sum==total)goto end;}
        
      for(i=k;i<=hang-k;i++)
    { printf("%d\n",a[i][lie-k]);
       sum=sum+1;
        if(sum==total)goto end; }
      for(j=lie-k-1;j>=k-1;j--)
      
       { printf("%d\n",a[hang-k][j]);
       sum=sum+1;
        if(sum==total)goto end;}
        
      
      for(i=hang-k-1;i>=k;i--)

     { printf("%d\n",a[i][k-1]);
        sum=sum+1;
        if(sum==total)goto end;  }
       
        }
     end:; 
    return 0; 
     }
int main()
{
	int n,a[100][100]={0},j,m,i,k,p;
	scanf("%d %d",&n,&m);
	for(j=0;j<n;j++)
	{
		for(i=0;i<m;i++)
		{
		scanf("%d",&a[j][i]);
		}
	}
	if(m>n)
	{
		k=n;
	}
	else
	{
		k=m;
	}
		
			for(i=0;i<(k-1)/2;i++)
			{
	
		for(j=i;j<m-i;j++)
		{
			printf("%d\n",a[i][j]);
		}
		for(j=i+1;j<n-i;j++)
		{
			printf("%d\n",a[j][m-i-1]);
		}
		for(j=m-i-2;j>=i;j--)
		{
			printf("%d\n",a[n-1-i][j]);
		}
		for(j=n-i-2;j>i;j--)
		{
			printf("%d\n",a[j][i]);
		}
			}
			if(k%2==0)
			{
				i=(k-1)/2;
			for(j=i;j<m-i;j++)
		{
			printf("%d\n",a[i][j]);
		}
		for(j=i+1;j<n-i;j++)
		{
			printf("%d\n",a[j][m-i-1]);
		}
		for(j=m-i-2;j>=i;j--)
		{
			printf("%d\n",a[n-1-i][j]);
		}
		for(j=n-i-2;j>i;j--)
		{
			printf("%d\n",a[j][i]);
		}
			}
			else
			{
				if(m>n)
				{
					i=(n-1)/2;
					for(j=i;j<m-i;j++)
		{
			printf("%d\n",a[i][j]);
		}
				}
				else
				{
					i=(m-1)/2;
					for(j=i;j<n-i;j++)
		{
			printf("%d\n",a[j][m-i-1]);
		}
				}
			}
			return 0;
}
int main(int argc, char* argv[])
{
	int ROW,COL,row,col,rowxia,rowup,colxia,colup;
	int array[99][99];
	scanf("%d%d",&ROW,&COL);
	for(row=0;row<ROW;row++){
		for(col=0;col<COL;col++){
	scanf("%d",&array[row][col]);}}
	for(rowxia=0,rowup=ROW-1,colxia=0,colup=COL-1;rowxia<rowup&&colxia<colup;rowxia++,colxia++,rowup--,colup--){
	for(row=rowxia,col=colxia;col<colup;col++){
    printf("%d\n",array[row][col]);}
		for(col=colup,row=rowxia;row<rowup;row++){
		printf("%d\n",array[row][col]);}
		for(row=rowup,col=colup;col>colxia;col--){
		printf("%d\n",array[row][col]);}
		for(col=colxia,row=rowup;row>rowxia;row--){
			printf("%d\n",array[row][col]);}}
	if(rowup==rowxia){
		for(col=colxia,row=rowup;col<=colup;col++){
			printf("%d\n",array[row][col]);}}
	else if(colup==colxia){
		for(row=rowxia,col=colup;row<=rowup;row++){
	printf("%d\n",array[row][col]);}}
	return 0;
}
int main(){
   int a[100][100],r,c,m,n;
   scanf("%d%d",&r,&c);
   for(int i=0;i<r;i++){
      for(int j=0;j<c;j++){
          scanf("%d",&a[i][j]);
      }
   }
   for(int k=0;r-k>k&&c-k>k;k++){
      for(m=k,n=k;n<c-k-1;n++){
          printf("%d\n",a[m][n]);
      }
      for(m=k;m<r-k-1;m++){
          printf("%d\n",a[m][n]);
      }
      if (m==k||n==k){
          printf("%d\n",a[m][n]);
          break;
      }
      for(n=c-k-1;n>k;n--){
          printf("%d\n",a[m][n]);
      }
      for(m=r-k-1;m>k;m--){
          printf("%d\n",a[m][n]);
      }
   }
   return 0;
}
int main(){
    int array[100][100],row,col,min,i,j,k;
    scanf("%d%d",&row,&col);
    for(i=0;i<row;i++){
        for(j=0;j<col;j++){
            scanf("%d",&array[i][j]);
        }
    }
    if(row<col){
        min=row;
    }else min=col;
    for(k=0;k<min/2;k++){
        for(j=k;j<col-k-1;j++){
            printf("%d\n",array[k][j]);
        }
        for(j=k;j<row-1-k;j++){
            printf("%d\n",array[j][col-1-k]);
        }
        for(j=col-1-k;j>k;j--){
            printf("%d\n",array[row-1-k][j]);
        }
        for(j=row-1-k;j>k;j--){
            printf("%d\n",array[j][k]);
        }
    }
    if(min%2==1){
        
        if(row<col){
            for(i=min/2;i<(col-min/2);i++){
            printf("%d\n",array[row/2][i]);
           }
        }
        else if(row>col){
            for(i=min/2;i<(row-min/2);i++){
                printf("%d\n",array[i][col/2]);
            }
        }
        else if(row==col){
            printf("%d\n",array[col/2][col/2]);
        }
    }
    return 0;
}
int main()
{
	int a[110][110],row,col,i,j,k,l=0,s=0;;
	scanf("%d %d",&row,&col);
	for(i=0;i<row;i++){
	for(j=0;j<col;j++)scanf("%d",&a[i][j]);}

	for(i=1;l<row*col;i++){
	k=i%4;
	if(k==1){
			if(s<col-s-1)
				for(j=s;j<col-s-1;j++){printf("%d\n",a[s][j]);l++;	if(l==row*col)break;}
			if(s==col-s-1)continue;
}
	
	if(k==2){
			if(s<row-s-1)
				for(j=s;j<row-s-1;j++){printf("%d\n",a[j][col-s-1]);l++;if(l==row*col)break;}
			if(s==row-s-1)continue;
		}
	
	if(k==3){
			if(s<col-s-1)
				for(j=col-s-1;j>s;j--){printf("%d\n",a[row-s-1][j]);l++;if(l==row*col)break;}
			if(s==col-s-1)continue;
		}

	if(k==0){
			if(s<row-s-1)
				for(j=row-s-1;j>s;j--){printf("%d\n",a[j][s]);l++;if(l==row*col)break;}
			if(s==row-s-1&&l==row*col-1){printf("%d\n",a[s][s]);l++;}
			if(s==row-s-1&&l!=row*col-1)continue;
		}
	
	if(k==0)s++;

	}
	return 0;
}
int main()
{
	int array[100][100];
	int x,y,i,k,n;
	i=0;
	k=0;
	scanf("%d%d",&x,&y);
	for(k=0;k<=x-1;k++){
		for(i=0;i<=y-1;i++){
			scanf("%d",&(array[k][i]));
		}
	}
	if(x>=y){
		n=(y-1)/2;
	}else{
		n=(x-1)/2;
	}
	for(i=0;i<=n;i++){
		for(k=i;k<=y-i-1;k++){
			printf("%d\n",array[i][k]);
		}
		for(k=i+1;k<=x-i-1;k++){
			printf("%d\n",array[k][y-i-1]);
		}
		if(n>0&&i<=(x-2)/2){
			for(k=y-i-2;k>=i;k--){
				printf("%d\n",array[x-i-1][k]);
			}
		}else{
			break;
		}
		if(n>0&&i<=(y-2)/2){
			for(k=x-i-2;k>=i+1;k--){
				printf("%d\n",array[k][i]);
			}
		}else{
			break;
		}
	}
	return 0;
}
int main()
{
	int number[100][100];
	int row,col,i,j,a=0,zongshu=0;
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
		{
			scanf("%d",&number[i][j]);
		}
	}
	for(a=0;a>=0;a++)
	{
		for(j=a;j<col-a;j++)
		{
			printf("%d\n",number[a][j]);
			zongshu++;
		}
		if(zongshu==row*col)
		{ 
			break;
		}
		for(i=a+1;i<row-a;i++)
		{
			printf("%d\n",number[i][col-a-1]);
			zongshu++;
		} 
		if(zongshu==row*col)
		{ 
			break;
		}
		for(j=col-2-a;j>=a;j--)
		{
			printf("%d\n",number[row-a-1][j]);
			zongshu++;
		}
		if(zongshu==row*col)
		{ 
			break;
		}
        for(i=row-2-a;i>a;i--)
		{
			printf("%d\n",number[i][a]);
			zongshu++;
		}
		if(zongshu==row*col)
		{ 
			break;
		}
	}
	return 0;
}
int main(int argc, char* argv[])
{
	int a[101][101],i,j,p,n=0,row,col;
	scanf("%d %d",&row,&col);
	for(i=1;i<=row;i++){
		for(j=1;j<=col;j++){
		    scanf("%d",&a[i][j]);
		}
	}


	for(p=1;p<=50;p++){
		for(i=p;i<=col+1-p;i++){
		    printf("%d\n",a[p][i]);
			n++;
		}
		if(n==row*col){
			    break;
		}
		for(i=p+1;i<=row+1-p;i++){
		    printf("%d\n",a[i][col+1-p]);
			n++;
			}
		if(n==row*col){
			    break;
		}
		for(i=col-p;i>=p;i--){
		    printf("%d\n",a[row+1-p][i]);
			n++;
		}		
		if(n==row*col){
			    break;
		}
		for(i=row-p;i>=p+1;i--){
		    printf("%d\n",a[i][p]);
			n++;
		}
		if(n==row*col){
			    break;
			}
	}
	return 0;
}
int main()
{
int m,n,i,j,k,a[100][100],x1,x2,y1,y2,s=0,t=0;
scanf("%d",&m);
scanf("%d",&n);
x1=0;x2=n-1;
y1=0;y2=m-1;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
i=0;j=0;
for(k=0;k<m*n;k++)
{
printf("%d\n",a[i][j]);
if((i==y1)&&(j<x2))
{
j++;
}
else if((j==x2)&&(i<y2))
{
i++;
}
else if((i==y2)&&(j>x1))
{
j--;
}
else if((j==x1)&&(i==y1+1))
{
j++;
x1++;
x2--;
y1++;
y2--;
}
else
{
i--;
}


}

return 0;
}
int main()
{
	int row,col,i,j,k,p,a[101][101],l,h,n;
	cin>>row>>col;
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			cin>>a[i][j];
	l=col,h=row,p=0,n=0;
	while(1){
		for(j=p;j<l-p;j++){
				cout<<a[p][j]<<endl;
				n++;
		}
		if(n==row*col)break;
		for(i=p+1;i<h-p;i++){
			cout<<a[i][l-p-1]<<endl;
			n++;
		}
		if(n==row*col)break;
		for(j=l-2-p;j>=p;j--){
			cout<<a[h-p-1][j]<<endl;
			n++;
		}
		if(n==row*col)break;
		for(i=h-2-p;i>p;i--){
			cout<<a[i][p]<<endl;
			n++;
		}
		if(n==row*col)break;
		p++;
	}
	return 0;
}
int main(){
	int row , col ;
	int a[100][100];
	int i,j;
	int flag=1; 
	cin >> row >> col ;
	int  topBorder=0,bottomBorder=row-1;
	int leftBorder=0,rightBorder=col-1;
	int x=0,y=0;
	for(i=0;i<row;i++){
		for(j=0;j<col;j++){
			cin>>a[i][j];
		}
	}
	for(i=0;i<row*col;i++){
			cout<<a[y][x]<<endl;
		if(flag==1){
			if(x+1>rightBorder){
				flag=2;
				y++;
				topBorder++;
			}
			else{
			x++;
			}
		}
		else if(flag==2){
			if(y+1>bottomBorder){
				flag=3;
				x--;
				rightBorder--;
			}
			else{
				y++;
			}
		}
			else if(flag==3){
				if(x-1<leftBorder)
				{
					flag=4;
					y--;
					bottomBorder--;
				}
				else{
					x--;
				}
			}
			else{
				if(y-1<topBorder){
					flag=1;
					x++;
					leftBorder++;
				}
				else{
					y--;
				}
			}
		}
	return 0;
}
int min(int x,int y)
{
	int z;
	if(x<y) z=x;
	else z=y;
	return (z);
}


void main ()
{
	 int h,i,j,k,l,a,b,temp,flag1,flag2;
	 int f[100][100];
	
	 
	 scanf("%d%d",&a,&b);

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

	 temp=min(a,b);
	 
	 for(i=0;((a-2*i)>0&&(b-2*i)>0);i++)
	 {
		 flag1=0;
		 flag2=0;                                                                                                
		 if((a-2*i)==1) flag1=1;
		 if((b-2*i)==1) flag2=1;
		 
		 /*first heng*/
		 for(j=i;j<b-i;j++)
		 {
			 
			 printf("%d\n",f[i][j]);
		 }
		 
		 /*first shu*/
		 for(j=i+1;j<a-i-1;j++)
		 {
			
			 printf("%d\n",f[j][b-1-i]);
		 }

		 /*second heng*/
		 for(j=b-1-i;j>i-1;j--)
		 {
			 if(flag1==1)break;
			 printf("%d\n",f[a-1-i][j]);
		 }
		 
		 
		 /*second shu*/
		 for(j=a-2-i;j>i;j--)
		 { 
			 if(flag2==1)break;
			 printf("%d\n",f[j][i]);
		 }
	 }
}
int a[1000][1000];
int x=0,y=0,z=0,i=0,m=0,k=0,t=0,n=0,j=0;
int main()
{
scanf("%d %d",&x,&y);
for(i=0;i<x;i++){
    for(m=0;m<y;m++){
         scanf("%d",&a[i][m]);
    }
}
for (n=0;;n++)
  { 
   for (i=n;i<y-n;i++)
   {
    printf("%d\n",a[n][i]);
    t++;
   }
   printf("\n");
   if(t==x*y)break;
   for (j=n+1;j<x-n;j++)
   {
    printf("%d\n",a[j][y-n-1]);
    t++;
   }
   printf("\n");
   if(t==x*y)break;
   for (i=y-2-n;i>=n;i--)
   {
    printf("%d\n",a[x-n-1][i]);
    t++;
   }
   printf("\n");
   if(t==x*y)break;
   for (j=x-2-n;j>n;j--)
   {
    printf("%d\n",a[j][n]);
    t++;
   }
   printf("\n");
   if(t==x*y)break;
  }
  return 0;
}
int main(){
    int m,n,a[100][100],i,j,s=0;
    scanf("%d%d",&m,&n);
    for(i=0;i<m;i++){
            for(j=0;j<n;j++){
                    scanf("%d",&a[i][j]);
                    }
            }
    for(int k=0;k<(m+1)/2&&k<(n+1)/2;k++){
            for(j=k;j<n-k;j++){
                               s++;
                               if(s==m*n)
                                 printf("%d",a[k][j]); 
                               else if(s<m*n)
                                 printf("%d\n",a[k][j]);
                               }
            for(i=k+1;i<m-k;i++){
                                 s++;
                                 if(s==m*n)
                                   printf("%d",a[i][n-k-1]);
                                 else if(s<m*n)
                                   printf("%d\n",a[i][n-k-1]);
                                 }
            for(j=n-k-2;j>k-1;j--){
                                 s++;
                                 if(s==m*n)
                                   printf("%d",a[m-k-1][j]);
                                 else if(s<m*n)
                                   printf("%d\n",a[m-k-1][j]);
                                 }
            for(i=m-k-2;i>k;i--){
                                 s++;
                                 if(s==m*n)
                                   printf("%d",a[i][k]);
                                 else if(s<m*n)
                                   printf("%d\n",a[i][k]);
                                 }
            } 
    return 0;
}
int main()
{
    int flag = 0;
    int time = 0;
    int i, j, k = 0;
    int row, col;
    int a[100][100];
    cin >> row >> col;
    for (i = 0; i < row; i++)
    {
        for (j = 0; j < col; j++)
        {
            cin >> a[i][j];
        }
    }
    for (k = 0; k <= row * col; )
    {
        for (j = time; j < col - time ;j++)
        {
            cout << a[time][j] << endl;
            k ++;
            if (k == row * col)
            {
                flag = 1;
                break;
            }
        }
        if (flag)
        break;
        for (i = 1 + time; i < row - time; i++)
        {
            cout << a[i][col - 1 - time] << endl;
            k++;
            if (k == row * col)
            {
                flag = 1;
                break;
            }
        }
        if (flag)
        break;
        for (j = col - 2 - time ; j > time; j--)
        {
            cout << a[row - 1 - time][j] << endl;
            k ++;
            if (k == row * col)
            {
                flag = 1;
                break;
            }
        }
        if (flag)
        break;
        for (i = row - 1 - time; i > time;i--)
        {
            cout << a[i][time] << endl;
            k ++;
            if (k == row * col)
            {
                flag = 1;
                break;
            }
        }
        if (flag)
        break;
        time ++;
    }
    return 0;
}