semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main()
{
	int row,col;
	int i,j;
	int a[100][100];
	int p=0,q=0;
	for(i=0;i<100;i++)
	{
		for(j=0;j<100;j++)
			a[i][j]=-1;
	}
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
			scanf("%d",&a[i][j]);
	}
	if(col==1)
	{
		for(j=0;j<row;j++)
		{
			printf("%d\n",a[j][0]);
			a[0][j]=-1;
		}
	}
	else
	{
	for(i=row-1,j=col-1;i>0,j>0;i--,j--)
	{
		for(;q<=j-1;q++)
		{
			if(a[p][q]!=-1)
			printf("%d\n",a[p][q]);
			a[p][q]=-1;
		}
		for(;p<=i-1;p++)
		{
			if(a[p][q]!=-1)
			printf("%d\n",a[p][q]);
			a[p][q]=-1;
		}
		for(;q>=col-j;q--)
		{
			if(a[p][q]!=-1)
			printf("%d\n",a[p][q]);
			a[p][q]=-1;
		}
		for(;p>=row-i;p--)
		{
			if(a[p][q]!=-1)
			printf("%d\n",a[p][q]);
			a[p][q]=-1;
		}
		p=p+1;
		q=q+1;
	}
	if((q%2==0)&&(p%2==0))
	{
		i=q/2;
		j=p/2;
		if(a[p-j][q-i]!=-1)
		printf("%d",a[p-j][q-i]);
	}
	}
	return 0;
}
int main()
{
	int n,m,a[1000][1000],i,j,s,q=0;
	cin>>n>>m;
	for(i=0;i<n;i++)
		for(j=0;j<m;j++)
			cin>>a[i][j];
	int flag=0;
	for(i=0;;i++)
	{
		for(j=q;j<m-q;j++)
		{
			flag++;
			cout<<endl<<a[i][j];
		}
		if(flag==n*m)
			break;
		j--;
		for(s=i+1;s<n-q;s++)
		{
			flag++;
			cout<<endl<<a[s][j];
		}
		if(flag==n*m)
			break;
		s--;
		for(j=j-1;j>=q;j--)
		{
			flag++;
			cout<<endl<<a[s][j];
		}
		if(flag==n*m)
			break;
		j++;
		for(s=s-1;s>q;s--)
		{
			flag++;
			cout<<endl<<a[s][j];
		}
		if(flag==n*m)
			break;
		q++;
	}
	return 0;
}
int main()
{
	int a, b, n = 1;
	cin >> a >> b;
	int c[101][101];
	for (int i = 1; i <= a; i++)
	for (int j = 1; j <= b; j++)
	cin >> c[i][j];
	while (2 * n <= a && 2 * n <= b)
	{
		for (int i = n; i <= b - n; i++)
		cout << c[n][i] << endl;
		for (int i = n; i <= a - n; i++)
		cout << c[i][b-n+1] << endl;
		for (int i = b - n + 1; i > n; i--)
		cout << c[a-n+1][i] << endl;
		for (int i = a - n+1; i > n; i--)
		cout << c[i][n] << endl;
		n++;
	}
	for (int i = n; i <= b + 1 - n; i++)
	for (int j = n; j <= a + 1 - n; j++)
	cout << c[j][i] << endl;
	return 0;
}
int main()
{
    int array[100][100],col,row,cs=0,i,j,x=0;
    scanf("%d%d",&row,&col);
    
    for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
            scanf("%d",&array[i][j]);
    }
    
    do{
        for(i=cs;i<cs+col-1;i++)
            printf("%d\n",array[cs][i]);
        
        for(i=cs;i<cs+row-1;i++)
            printf("%d\n",array[i][cs+col-1]);
        
        if(i!=cs){
        for(i=cs;i<cs+col-1;i++)
            printf("%d\n",array[cs+row-1][2*cs+col-i-1]);
        }else
        {
            printf("%d\n",array[cs+row-1][cs+col-1]);
            x=1;
        }
        
        if(i!=cs){
        for(i=cs;i<cs+row-1;i++)
            printf("%d\n",array[2*cs+row-i-1][cs]);
        }else if(x==0)
            printf("%d\n",array[cs+row-1][cs]);
        
        cs++;
        col-=2;
        row-=2;
    
    } while(col>0&&row>0);
    
    return 0;
}
int main()
{
	int i,j,x=0,y=0,row,col,k=0;
	int a[100][100];
	int dx[4]={0,1,0,-1};
	int dy[4]={1,0,-1,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=0;i<row*col;i++)
	{
		printf("%d\n",a[x][y]);
		if(k==0 && x+y==col-1)
			k=1;
		else if(k==1 && x-y==row-col)
			k=2;
		else if(k==2 && x+y==row-1)
			k=3;
		else if(k==3 && x-y==1)
			k=0;
		x+=dx[k];
		y+=dy[k]; 
	}
	return 0;
}
int main()
{
	/* Read data */
	int col, row, a[100][100];
	cin >> row >> col;
	for(int i=0; i<row; ++i)
		for(int j=0; j<col; ++j)
			cin >> a[i][j];
	/* Const direction */ 
	const int dir[4][2] = {{0,1},{1,0},{0,-1},{-1,0}};
	/* Parameter Initialization */
	/* State records current direction index, step records step size for 4 directions, curstep is current step size, pos records current position */
	int state=0, step[4] = {col, row-1, col-1, row-2}, curstep=step[state], pos[2] = {0,0}, flag=1;
	/* Main Solver */
	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;
}
void main(){
	int n[100][100],d[100][100], r,c,i,j,f,g;
	scanf("%d %d\n",&r,&c);
	
	for(i=0;i<r;i++){
		scanf("\n");
		for(j=0;j<c;j++){
			scanf("%d",&n[i][j]);
	d[i][j]=1;
	}
	
	}
	i=0;
	j=0;
	g=0;
	for(f=1;f<=r*c;f++){
		printf("%d\n",n[i][j]);
		d[i][j]=0;
		if(g==0){
		if(j<c-1&&d[i][j+1]){
			j++;
		g=0;}
			else if(i<r-1&&d[i+1][j]){
				i++;
			g=0;}
				else if(j>0&&d[i][j-1]){
					j--;
				g=0;}
					else if(i>0&&d[i-1][j]){
						i--;
						g=1;}
		}
		else{
			if(i>0&&d[i-1][j]){
						i--;
						g=1;}
			else if(j<c-1&&d[i][j+1]){
				j++;
			g=0;}

	}
		
}}
int main()
{
	int input[100][100],i,j,k,m,n,output[10000],a=0;
	int row,col;
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
			scanf("%d",&input[i][j]);
	}
	for(i=0;i<row;i++)
	{
		for(j=i;j<col-i;j++)
		{
			output[a++]=input[i][j];
		}
		for(k=i+1;k<row-i;k++)
		{
			output[a++]=input[k][j-1];
		}
		for(m=j-2;m>=i;m--)
		{
			output[a++]=input[k-1][m];
		}
		for(n=k-2;n>i;n--)
		{
			output[a++]=input[n][m+1];
		}
		if(i==k)
		{
			break;
		}
	}
	for(i=0;i<row*col-1;i++)
		printf("%d\n",output[i]);
	printf("%d",output[row*col-1]);
	return 0;
}
/*************************
 ***??:??? 1200012776
 ***????:????????
 ***??:2012?10?30?
 *************************/
int main()
{
	int row, col, sub_rowS, sub_rowE, sub_colS, sub_colE, times = 0, i, j, k, matrix[100][100];
	cin >> row >> col;	//??????
	for (i = 0; i < row; i++)
	{
		for(j = 0; j < col; j++)
		{
			cin >> matrix[i][j];
		}
	}
	for (sub_rowS = 0, sub_rowE = row - 1, sub_colS = 0, sub_colE = col -1; ; sub_rowS++, sub_rowE--, sub_colS++, sub_colE--)	//???????????
	{
		for (i = sub_colS; i <= sub_colE; i++)
		{
			cout << matrix[sub_rowS][i] << endl;	//????????
			times++;
		}
		for (i = sub_rowS + 1; i <= sub_rowE; i++)
		{
			cout << matrix[i][sub_colE] << endl;	//??????sub_colE??sub_rowE-1?
			times++;
		}
		if (times == row * col)	//????????,??
			break;
		for (i = sub_colE - 1; i >= sub_colS; i--)
		{
			cout << matrix[sub_rowE][i] << endl;	//??????sub_rowE??sub_colE-1?
			times++;
		}
		for (i = sub_rowE - 1; i > sub_rowS; i--)
		{
			cout << matrix[i][sub_colS] << endl;	//??????????sub_rowE-2?
			times++;
		}
		if (times == row * col)	//????????,??
			break;
	}
	return 0;
}
int main()
{
   int row;
   int col;
   int i,j,k;
   int t=0;
   int a[200][200];
   scanf("%d%d",&row,&col);
   for(i=0;i<row;i++)
   {
	   for(j=0;j<col;j++)
	   {
		   scanf("%d",&a[i][j]);
	   }
   }
   for(i=0;i<row;i++)
   {
	   for(j=i;j<col-i;j++)
	   {
		  t++;
		  if(t==row*col){
			  printf("%d",a[i][j]);
	return 0;}
		  else {printf("%d\n",a[i][j]);}

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

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

        if (row-1-k-k==1&&col-1-k-k!=1)
        {
            for (i=k,j=k;j<col-1-k;j++)
            {
                printf("%d\n",array[i][j]);
            }
            for (i=k,j=col-1-k;i<row-1-k;i++)
            {
                printf("%d\n",array[i][j]);
            }
            for (i=row-1-k,j=col-1-k;j>k;j--)
            {
                printf("%d\n",array[i][j]);
            }
            break;
        }
        if (row-1-k-k==0)
        {
            for (i=k,j=k;j<=col-1-k;j++)
            {
                printf("%d\n",array[i][j]);
            }
            break;
        }
        if (col-1-k-k==1)
        {            
            for (i=k,j=k;j<col-1-k;j++)
            {
                printf("%d\n",array[i][j]);
            }
            for (i=k,j=col-1-k;i<row-1-k;i++)
            {
                printf("%d\n",array[i][j]);
            }
            for (i=row-1-k,j=col-1-k;j>k;j--)
            {
                printf("%d\n",array[i][j]);
            }
            for (i=row-1-k,j=k;i>k;i--)
            {
                printf("%d\n",array[i][j]);
             }
             break;
        }
        if (col-1-k-k==0)
        {
            for (i=k,j=col-1-k;i<=row-1-k;i++)
            {
                printf("%d\n",array[i][j]);
            }
            break;
        }                
        for (i=k,j=k;j<col-1-k;j++)
        {
            printf("%d\n",array[i][j]);
        }
        for (i=k,j=col-1-k;i<row-1-k;i++)
        {
            printf("%d\n",array[i][j]);
        }
        for (i=row-1-k,j=col-1-k;j>k;j--)
        {
            printf("%d\n",array[i][j]);
        }
        for (i=row-1-k,j=k;i>k;i--)
        {
            printf("%d\n",array[i][j]);
        }
     }
     return 0;
}
/* title:???????? *
 * author:???*
 * time:2011.10.28*/


   


int main()
{
	int array[100][100];
	int row, col, i, j, k, h, m = 0, r1, r2, n = 0;
	cin >> row >> col;
	r1 = row;
	r2 = col;
	for(i = 0; i < row; i++)
		for(j = 0; j < col; j++)
		{
			cin >> array[i][j];
		}
	for(m = 0; m <= r2 / 2 && m <= r1 / 2; m++)
	{
		for(j = m; j < col; j++)
		{
			n++;
			if(n > r1 * r2)
				break;
			cout << array[m][j] << endl;
		}
		for(i = m + 1; i < row; i++)
		{
			n++;
			if(n > r1 * r2)
				break;
			cout << array[i][col - 1] << endl;
		}
		for(k = col - 2; k >= m; k--)
		{
			n++;
			if(n > r1 * r2)
				break;
			cout << array[row - 1][k] << endl;
		}
		for(h = row - 2; h > m; h--)
		{
			n++;
			if(n > r1 * r2)
				break;
			cout << array[h][m] << endl;
		}
		row = row - 1;
		col = col - 1;
	}
	return 0;
}
int main()
{
  int row,col,i,j,u[100][100],a,sum=0;
  scanf("%d%d",&row,&col);
  for(i=0;i<row;i++)
   {
      for(j=0;j<col;j++)
      {
         scanf("%d",&u[i][j]);
       }
   } 
  for(a=0;a<row/2+1;a++)
  {
      for(i=a,j=a;j<col-a;j++)
      {
        printf("%d\n",u[i][j]);
        sum++;
        if(sum==row*col)
             break;
      }
      if(sum==row*col)
             break;
      for(j=col-a-1,i=a+1;i<row-a;i++)
      {
        printf("%d\n",u[i][j]);
        sum++;
        if(sum==row*col)
             break;
       }
       if(sum==row*col)
             break;

      for(i=row-a-1,j=col-a-2;j>=a;j--)
        {
        printf("%d\n",u[i][j]);
        sum++;
       if(sum==row*col)
             break;
       }
       if(sum==row*col)
             break; 
      for(j=a,i=row-a-2;i>a;i--)
        {
        printf("%d\n",u[i][j]);
        sum++;
       if(sum==row*col)
             break;
       }
	   if(sum==row*col)
             break;
  }
  
  return 0;
}
int main(){
	int h,l,i,k,n,hsx,hxx=0,lsx,lxx=0;
	int shu[100][100];
	scanf("%d%d",&h,&l);
	for(i=0;i<h;i++){
		for(k=0;k<l;k++){
			scanf("%d",&(shu[i][k]));
		}
	}
	hsx=h-1;
	lsx=l-1;
	for(n=0;(hsx>hxx)&&(lsx>lxx);n++){
		for(k=lxx;k<lsx;k++){
			printf("%d\n",shu[hxx][k]);
		}
		for(i=hxx;i<hsx;i++){
			printf("%d\n",shu[i][lsx]);
		}
		for(k=lsx;k>lxx;k--){
			printf("%d\n",shu[hsx][k]);
		}
		for(i=hsx;i>hxx;i--){
			printf("%d\n",shu[i][lxx]);
		}
		hsx--;
		hxx++;
		lsx--;
		lxx++;
	}
	    if((hxx==hsx)&&(lsx>lxx)){
			for(k=lxx;k<=lsx;k++){
				printf("%d\n",shu[hxx][k]);
			}
		}
		else if((lxx==lsx)&&(hsx>hxx)){
			for(i=hxx;i<=hsx;i++){
				printf("%d\n",shu[i][lxx]);
			}
		}
		else if((hsx==hxx)&&(lsx==lxx)){
			printf("%d",shu[hxx][lxx]);
		}

	return 0;
}
int main()
{
    int m,n,a[101][101],f[101][101];
    const int dx[4]={0,1,0,-1};
    const int dy[4]={1,0,-1,0};
    cin>>m>>n;
    for (int i=1; i<=m; i++)
        for (int j=1; j<=n; j++)
            cin>>a[i][j];
    for (int i=0; i<=m+1; i++)
        for (int j=0; j<=n+1; j++)
            f[i][j]=1;
    for (int i=1; i<=m; i++)
        for (int j=1; j<=n; j++)
            f[i][j]=0;
    int x=1,y=1,p=0;
    for (int i=1; i<=m*n; i++)
    {
        cout<<a[x][y]<<endl;
        f[x][y]=1;
        if (f[x+dx[p]][y+dy[p]]==0) {x+=dx[p];y+=dy[p];}
        else {p++;if (p==4) p=0;x+=dx[p];y+=dy[p];}
    }
    return 0;
}
int main(){
	int i,j,n,all,row,col,sum;
	int sz[200][200];
	sum=0;
	scanf("%d%d",&row,&col);
	all=row*col;
	for(i=0;i<row;i++){
		for(j=0;j<col;j++){
			scanf("%d",&sz[i][j]);
		}
	}
	for(n=0;;n++){
		for(i=n;i<(col-n);i++)
		{
			printf("%d\n",sz[n][i]);
			sum=sum+1;
			
		}
		if(sum==all) break;
		for(j=n+1;j<(row-n);j++)
		{
			printf("%d\n",sz[j][col-n-1]);
			sum=sum+1;
		
		}
		if(sum==all) break;
		for(i=col-2-n;i>=n;i--)
		{
			printf("%d\n",sz[row-n-1][i]);
			sum=sum+1;
			
		}
		if(sum==all) break;
		for(j=(row-2-n);j>n;j--)
		{
			printf("%d\n",sz[j][n]);
			sum=sum+1;	
		}
		if(sum==all) break;
	}

	return 0;
}
int main()
{
	int row , col ;
	cin >> row >> col ;
	int a[row][col] ;
	for( int i = 0 ; i < row ; i ++ )
		for( int j = 0 ; j < col ; j ++ )
			cin >> a[i][j] ;
	int minrow = 0 , maxrow = row - 1 ,
			mincol = 0 , maxcol = col - 1 , n = 0 , i = 0 , j = 0 , count = 0 ;
	for( ; n > -1 ; n ++ )
	 {
	/*for( ; minrow <= i && i <= maxrow && mincol <= j && j <= maxcol ;
			n % 2 == 0 ? n % 4 == 0 ? j ++ : j -- : n % 4 == 1 ? i ++ : i -- )
		cout << a[i][j] << endl ;*/
		if( n % 2 == 0 )
	{
		if( n % 4 == 0 ) {
			for( ; j <= maxcol ; j ++ )
			{
				cout << a[i][j] << "\n"  ;
				count ++ ;
			}
			minrow ++ ; j -- ; i ++ ; }
		else {
			for( ; j >= mincol ; j -- )
			{
				cout << a[i][j] << "\n" ;
				count ++ ;
			}
			maxrow -- ; j ++ ; i -- ; }
	}
	else
	{
		if( n % 4 == 1 ){
			for( ; i <= maxrow ; i ++ )
			{
				cout << a[i][j] << "\n" ;
				count ++ ;
			}
			maxcol -- ; i -- ; j -- ; }
		else {
			for( ; i >= minrow ; i -- )
			{
				cout << a[i][j] << "\n" ;
				count ++ ;
			}
			mincol ++ ; i ++ ; j ++ ;}
	}
    if( count == row * col ) break ;
	}
	return 0 ;
}
int main()
{
int row,col;
cin>>row>>col;
int shuzu[100][100];
int p=0,q=0,count=0;
for(p=0;p<row;p++)
	for(q=0;q<col;q++){cin>>shuzu[p][q];}
for(;row-count>0&&col-count>0;)
{
p=count;for(q=count;q<col;q++){cout<<shuzu[p][q]<<endl;}
if(row==count+1)return 0;
q=col-1;for(p=count+1;p<row;p++){cout<<shuzu[p][q]<<endl;}
if(col==1+count)return 0;
p=row-1;for(q=col-2;q>=count;q--){cout<<shuzu[p][q]<<endl;}
q=count;for(p=row-2;p>count;p--){cout<<shuzu[p][q]<<endl;}
row--;col--;count++;
}
return 0;
}
int main()
{
	int ROW,COL;
	int array[100][100];
	scanf("%d%d",&ROW,&COL);
	for(int row=0;row<ROW;row++)
	{
		for(int col=0;col<COL;col++)
		{
			scanf("%d",&array[row][col]);
		}
	}
	//????
    int sx_row=0,xx_row=ROW-1,sx_col=0,xx_col=COL-1;

    while((xx_row>sx_row)&&(xx_col>sx_col))
	
	
	{
		for(int i1=sx_row,j1=sx_col;j1<xx_col;j1++)
		{
			
			printf("%d\n",array[i1][j1]);
		}
	    for(int j2=xx_col,i2=sx_row;i2<xx_row;i2++)
		{
		
			printf("%d\n",array[i2][j2]);
		}
	    for(int i3=xx_row,j3=xx_col;j3>sx_col;j3--)
		{
			
		    printf("%d\n",array[i3][j3]);
		}
	    for(int i4=xx_row,j4=sx_col;i4>sx_row;i4--)
		{
		
			printf("%d\n",array[i4][j4]);
		}
	    sx_row++;
	    sx_col++;
	    xx_row--;
	    xx_col--;
	}
	if((sx_row==xx_row)&&(sx_col!=xx_col))
	{
        for(int i=sx_col;i<=xx_col;i++)
		{
			printf("%d\n",array[sx_row][i]);
		}
	}
	else if(sx_col==xx_col)
	{
		for(int j=sx_row;j<=xx_row;j++)
		{
			printf("%d\n",array[j][sx_col]);
		}
	}
	return 0;
}
int main()
{
	int m,n,i,j,s,k,l,t;
	int a[100][100];
	scanf("%d%d",&m,&n);
	s=t=0;
	for(i=0;i<m;i++)
	{
		for(j=0;j<n;j++) 
		{
			scanf("%d",&a[i][j]);
			s=s+1;
		}
	}
	l=m/2;
	if(n<m) l=n/2;
	for(k=0;k<l;k++)
	{
		for(j=k;j<n-k-1;j++) {printf("%d\n",a[k][j]);t=t+1;}
		for(i=k;i<m-k-1;i++) {printf("%d\n",a[i][n-k-1]);t=t+1;}
		for(j=n-k-1;j>k;j--) {printf("%d\n",a[m-k-1][j]);t=t+1;}
		for(i=m-k-1;i>k;i--) {printf("%d\n",a[i][k]);t=t+1;}
	}
	if(t!=s)
	{
		if(m>n){ for(i=k;i<m-k;i++) printf("%d\n",a[i][l]);}
		if(m<n){ for(j=k;j<n-k;j++) printf("%d\n",a[l][j]);}
		if(m==n) printf("%d\n",a[l][l]);
	}
	return 0;
}
int main()
{
    int row,col,n;
    cin >> row >> col;
    n=row*col;
    int array[row][col];
    int i,j;
    for (i=1;i<=row;i++)
    {
        for (j=1;j<=col;j++)
        {
            int a;
            cin >> a;
            array[i-1][j-1]=a;
        }
    }
    int mini=0,minj=0,k;
    for (k=1;k<=n;)
    {   
        if (j!=col)
        {             j=minj;
                      while (j<col)
                      {
                            cout << array[mini][j] << endl;
                            k++;
                            j++;
                      }
        }
        mini++;
        if (k>n)
        {
                break;
        }
        if (j==col)
        {
                   i=mini;
                   while (i<row)
                   {
                         cout << array[i][col-1] << endl;
                         k++;
                         i++;
                   }
        }
        col--;
        if (k>n)
        {
                break;
        }
        if (i==row)
        {
                   j=col-1;
                   while (j>=minj)
                   {
                         cout << array[row-1][j] << endl;
                         k++;
                         j--;
                   }
        }
        row--;
        if (k>n)
        {
                break;
        }
        if (j<minj)
        {
                   i=row-1;
                   while (i>=mini)
                   {
                         cout << array[i][minj] << endl;
                         k++;
                         i--;
                   }
        }
        minj++;
        if (k>n)
        {
                break;
        }
    }
    
    return 0;
}
int main(int argc, char* argv[])
{
	int a[100][100],row,col,i,j,n=0,k=0;
	scanf("%d%d",&row,&col);
	for (i=0;i<row;i++)
	{
		for (j=0;j<col;j++)
			scanf("%d",&a[i][j]);
	}
	while (k!=(row*col))
	{
	for (j=(0+n);j<(col-n);j++)
	{
		printf("%d\n",a[n][j]);
		k++;
	}
     if(k==row*col)break; 
	for (i=(1+n);i<(row-n);i++)
	{
		printf("%d\n",a[i][col-1-n]);
		k++;
	}
	if(k==row*col)break;
	for (j=(col-2-n);j>=(0+n);j--)
	{
		printf("%d\n",a[row-n-1][j]);
		k++;
	}
	if(k==row*col)break;
	for (i=(row-2-n);i>=(1+n);i--)
	{
		printf("%d\n",a[i][n]);
		k++;
	}
	if(k==row*col)break;
	n++;
	}
	return 0;
}
void main()
{
 int n,m,i1,i2,j1,j2,i,a[100][100];
 scanf("%d%d",&n,&m);
 for (i1=0;i1<=n-1;i1++)
	  for(j1=0;j1<=m-1;j1++)
		  scanf("%d",&a[i1][j1]);
i1=0;j1=0;i2=n-1;j2=m-1;
for (;;)
{
	for (i=j1;i<=j2;i++)
		printf("%d\n",a[i1][i]);
	i1++;
	if (i1>i2) break;
    for (i=i1;i<=i2;i++)
		printf("%d\n",a[i][j2]);
	j2--;
	if (j1>j2) break;
    for (i=j2;i>=j1;i--)
		printf("%d\n",a[i2][i]);
	i2--;
	if (i1>i2) break;
    for (i=i2;i>=i1;i--)
		printf("%d\n",a[i][j1]);
	j1++;
	if (j1>j2) break;

}
}
int main()
{
    int i,j,row,cow,a[100][100];
    scanf("%d%d",&row,&cow);
    for(i=0;i<row;i++)
    {
                      for(j=0;j<cow;j++)
                      {
                                        scanf("%d",&a[i][j]);
                      }
                      if(i!=row-1)
                      printf("\n");
    }
    i=0;
    while(row-i-i>1&&cow-i-i>1)
    {
                                   for(j=i;j<cow-i;j++)
                                   {
                                                       printf("%d\n",a[i][j]);
                                   }
                                    for(j=i+1;j<row-i;j++)
                                   {
                                                       printf("%d\n",a[j][cow-i-1]);
                                   }
                                    for(j=cow-2-i;j>=i;j--)
                                   {
                                                       printf("%d\n",a[row-1-i][j]);
                                   }
                                    for(j=row-2-i;j>=i+1;j--)
                                   {
                                                       printf("%d\n",a[j][i]);
                                   }
                                   i++;
    }
    if(row-i-i==1)
    {
                     for(j=i;j<cow-i;j++)
                                   {
                                                       printf("%d\n",a[i][j]);
                                   }
    }
    else if(cow-i-i==1)
    {
                     for(j=i;j<row-i;j++)
                                   {
                                                       printf("%d\n",a[j][i]);
                                   }
    }
    return 0;
}
int main()
{
	int array[100][100], a, b, p, q, i, j, k = 1, x = 1;
	cin >> a >> b;
	for (i = 0; i <= a - 1; i++)
	{
		for (j = 0; j <= b - 1; j++)
		{
			cin >> array[i][j];
		}
	}
	for (q = 0, p = b - 1; p >= 0, q <= a - 1; p--, q++)
	{

		for (i = b - 1 - p; i <= p; i++)
		{
			if (array[q][i] == -1)
			{
				break; k = 0;
			}
			cout << array[q][i] << endl << endl;
			array[q][i] = -1;
		}
		for (i = q + 1; i <= a - 1 - q; i++)
		{
			if (array[i][p] == -1)
			{
				break; k = 0;
			}
			cout << array[i][p] << endl << endl;
			array[i][p] = -1;
		}
		for (i = p - 1; i >= b - 1 - p; i--)
		{
			if (array[a - 1 - q][i] == -1)
			{
				break; k = 0;
			}
			cout << array[a - 1 - q][i] << endl << endl;
			array[a - 1 - q][i] = -1;
		}
		for (i = a - 2 - q; i >= q; i--)
		{
			if (array[i][b - 1 - p] == -1)
			{
				break; k = 0;
			}
			cout << array[i][b - 1 - p] << endl << endl;
			array[i][b - 1 - p] = -1;
		}
		for (i = 0; i <= a - 1; i++)
		{
			for (j = 0; j <= b - 1; j++)
			{
				if (array[i][j] != -1)
					x = x * 0;
			}
		}
		if (x == 1)
			break;
		x = 1;
	}
	return 0;
}
int main ()
{
	int a[100][100]={0},cnt=0,i,j,row,col,l=0;
	cin >> row>>col ;
	cnt = row * col ;
	for(i = 0 ;i < row;i++)
	{
		for(j = 0 ; j <col ;j++)
			cin >> a[i][j] ;
	}
	while(cnt > 0)
	{
		for(j=l;j<(col-l);j++)
		{
			cout << a[l][j]<<endl;
			cnt--;
		}
		if(cnt == 0) break ;
		for (i=(l+1);i<row-l;i++)
		{
			cout << a[i][col-l-1]<<endl;
			cnt--;	
		}
		if(cnt == 0) break ;
		for(j=col-l-2;j>l-1;j--)
		{
			cout << a[row-l-1][j]<<endl;
			cnt-- ;
		}
		if(cnt == 0) break ;
		for(i=row-l-2;i>l;i--)
		{
			cout << a[i][l]<<endl;
			cnt--;
		}
		l++ ;
	}
	return 0 ;
}
int main()
{
	int i,j,m,n,a[100][100]; 
	int shang,xia,zuo,you;
	scanf("%d %d",&m,&n);

	for(i=0;i<m;i++){
		for(j=0;j<n;j++){
			scanf("%d",&a[i][j]);
		}
	}
		shang=0;
		zuo=0;
		xia=m-1;
		you=n-1;
	while(zuo<=you&&(shang<=xia)){
		if(zuo!=you&&shang!=xia){
		
			for(i=shang,j=zuo;j<=you;j++){
				printf("%d\n",a[i][j]);
			}
			for(j=you,i=shang+1;i<=xia;i++){
				printf("%d\n",a[i][j]);
			}
			for(i=xia,j=you-1;j>=zuo;j--){
				printf("%d\n",a[i][j]);
			}
			for(i=xia-1,j=zuo;i>shang;i--){
				printf("%d\n",a[i][j]);
			}
		}
		else if(zuo==you&&shang!=xia){
			for(j=zuo,i=shang;i<=xia;i++){
				printf("%d\n",a[i][j]);
			}
		}
		else if(shang==xia&&zuo!=you){
			for(i=shang,j=zuo;j<=you;j++){
				printf("%d\n",a[i][j]);
			}
		}
		else if(shang==xia&&zuo==you){
			i=shang;j=zuo;
			printf("%d\n",a[i][j]);
		}
		zuo++,shang++,you--,xia--;

			
	}
	

	return 0;
}