semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
void f(int a[100][100],int m,int p,int q)
{
   int n=0,i,j,w,*pt;
   w=(p+1)*(q+1);
   for(j=1;;j++)
   {
	   for(pt=&a[m][m];pt<=&a[m][p];pt++)
	   { printf("%d\n",*pt); n++;}
	   if(n==w) break;
	   for(i=m+1;i<=q;i++)
	   {printf("%d\n",a[i][p]);n++;}
	   if(n==w) break;
	   for(pt=&a[q][p-1];pt>=&a[q][m];pt--)
	   {printf("%d\n",*pt);n++;}
	   if(n==w) break;
	   for(i=q-1;i>=m+1;i--)
	   { printf("%d\n",a[i][m]);n++;}
	   if(n==w) break;
	   m++;
	   p--;
	   q--;
   }

}
void main()
{
	int row,col,i,j,a[100][100],m=0,p,q;
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
			scanf("%d",&a[i][j]);
	}
	p=col-1;
	q=row-1;
	f(a,m,p,q);
}
int main()
{
	int hangshu, lieshu, array[101][101], i, j;
	cin >> hangshu >> lieshu;
	for (i = 0; i < hangshu; i++)
		for (j = 0; j < lieshu; j++)
			cin >> array[i][j];
	int count = 0;
	int total = hangshu * lieshu;
	lieshu--; hangshu--;
	for (i = 0; i <= hangshu; i++)
	{
		for (j = i; j <= lieshu - i; j++)
		{
			cout << array[i][j] << endl;
			count++;
		}
		if (count == total)
			break;
		for (j = i + 1; j <= hangshu - i; j++)	
		{
			cout << array[j][lieshu - i] << endl;
			count++;
		}
		if (count == total)
			break;
		for (j = lieshu - i - 1; j >= i; j--)
		{
			cout << array[hangshu - i][j] << endl;
			count++;
		}
		if (count == total)
			break;
		for (j = hangshu - i - 1; j >= i + 1; j--)
		{
			cout << array[j][i] << endl;
			count++;
		}
		if (count == total)
			break;
	}
	return 0;
}
int main(int argc, char *argv[])
{int array[100][100];
int row,col,i,j,rowmin,rowmax,colmin,colmax;
scanf("%d%d",&row,&col);
for(i=0;i<row;i++)
for(j=0;j<col;j++)
scanf("%d",&array[i][j]);
rowmin=0;
rowmax=row-1;
colmin=0;
colmax=col-1;
while(colmin<colmax&&rowmin<rowmax){
for(i=colmin;i<colmax;i++)        
printf("%d\n",array[rowmin][i]); 
for(i=rowmin;i<rowmax;i++)
printf("%d\n",array[i][colmax]);       
for(i=colmax;i>colmin;i--)
printf("%d\n",array[rowmax][i]);
for(i=rowmax;i>rowmin;i--)
printf("%d\n",array[i][colmin]);
rowmin++;
rowmax--;
colmin++;
colmax--;}
if(rowmin==rowmax&&colmin<colmax)
{for(i=colmin;i<=colmax;i++)
printf("%d\n",array[rowmin][i]);}
else if(rowmin<rowmax&&colmin==colmax)
{for(i=rowmin;i<=rowmax;i++)
printf("%d\n",array[i][colmin]);
     }
else if(rowmin==rowmax&&colmin==colmax)
printf("%d\n",array[rowmin][colmax]);
  
  return 0;
}
int main()
{
    int n,k,i=0,j=0,m=0,h=0,g=0,s=0,t=0;
    int an[100][100];
	scanf("%d %d",&n,&k);
    for(i=0;i<n;i++){
       for(j=0;j<k;j++){
       scanf("%d",&an[i][j]);
       }
     }
     if(n>k) s=k;
     else  s=n;
     for(m=0;m<((s+2)/2);m++){
         for(i=m,j=m;j<k-m-1;j++){
             printf("%d\n",an[m][j]);
           }
         for(i=m;i<n-m-1;i++){
              printf("%d\n",an[i][k-m-1]); 
           }
         for(h=k-m-1;h>m;h--){
            printf("%d\n",an[n-m-1][h]);
            if(m==s/2&&s%2!=0){
			  break;
			 }
          }
         for(g=n-m-1;g>m;g--){
         	 printf("%d\n",an[g][m]);
			 if(m==s/2&&s%2!=0){
			  break;
			 }
           }
       }
       if(n==k&&n%2!=0){
       	t=(n-1)/2;
	     printf("%d",an[t][t]);
       }
       return 0;
}
int main()
{
	int row,col,m,n,i,b,c;
	int a[100][100];
	scanf("%d%d",&row,&col);
	for(m=0;m<row;m++){
		for(n=0;n<col;n++){
			scanf("%d",&a[m][n]);
		}
	}

	int p[4]={0,1,0,-1},q[4]={1,0,-1,0};
	
	for(i=0,c=p[0],b=q[0],m=0,n=0;i<row*col;m=m+c,n=n+b,i++){
		printf("%d\n",a[m][n]);
		if(c==p[0]&&b==q[0]&&m+n==col-1){
			c=p[1];
			b=q[1];
		}
		else if(c==p[1]&&b==q[1]&&m-n==row-col){
			c=p[2];
			b=q[2];
		}
		else if(c==p[2]&&b==q[2]&&m+n==row-1){
			c=p[3];
			b=q[3];
		}
		else if(c==p[3]&&b==q[3]&&m==n+1){
			c=p[0];
			b=q[0];
		}
	}
	return 0;
}
int sum(int a,int b,int c){
	int d=0,e;
	for(e=1;e<=c;e++){
		d=a+a+b+b-4*(2*e-1)+d;
	}
  return d;
}

int min(int a,int b,int c,int d){
	if(a<b)
	  b=a;
	if(b<c)
	  c=b;
	if(c<d)
	  d=c;

  return d;
}

int main(){
	int a[100][100],s[10000];
	int row,col,i,j,b,c,d,e;
	int f,g,h;
    scanf("%d%d",&row,&col);
	for(i=1;i<=row;i++){
		for(j=1;j<=col;j++){
			scanf("%d",&a[i][j]);
			b=col-j;
			c=row-i;
			d=min(i-1,j-1,b,c);
			e=sum(row,col,d);
			f=i-d;
			g=j-d;
            if(f==1&&g>=1)
				h=e+g;
			else if(g==(col-2*d)&&f<=(row-2*d))
				h=e+f+g-1;
			else
				h=e+row+col-1-4*d+col-2*d-g+row-2*d-f;

			s[h]=a[i][j];
		}
	}

	for(i=1;i<=row*col;i++)
		printf("%d\n",s[i]);

return 0;
}
int main() {
	int row,col;
	int sz[100][100];
	scanf("%d %d",&row,&col);
	for(int i=0;i<row;i++){
		for(int j=0;j<col;j++){
			scanf("%d",&sz[i][j]);
		}
	}
	int xx_row=0;
	int sx_row=row-1;
	int xx_col=0;
	int sx_col=col-1;
	while((xx_row<sx_row)&&(xx_col<sx_col)){
		for(int i=xx_col;i<sx_col;i++){
			printf("%d\n",sz[xx_row][i]);
		}
		for(int j=xx_row;j<sx_row;j++){
			printf("%d\n",sz[j][sx_col]);
		}
		for(int k=sx_col;k>xx_col;k--){
			printf("%d\n",sz[sx_row][k]);
		}
		for(int p=sx_row;p>xx_row;p--){
			printf("%d\n",sz[p][xx_col]);
		}
		xx_row++;
		sx_row--;
		xx_col++;
		sx_col--;
	}
	if(xx_row==sx_row){
		if(xx_col!=sx_col){
		     for(int i=xx_col;i<=sx_col;i++){
			     printf("%d\n",sz[xx_row][i]);
			 }
		}
	}
	if(xx_col==sx_col){
		for(int j=xx_row;j<=sx_row;j++){
			printf("%d\n",sz[j][xx_col]);
		}
	}
	return 0;
}
//*********************************************
//** ??: ???????? **
//** ??: ??? 1300012722 **
//** ??: 2013.11.1 **
//*********************************************
int main()
{
	int row, col, n, i, j, count = 0, sum;     //??????row,???col, ??????????????????n????????count 
	int array[120][120],times;                 //??????,????times
	cin >> row >> col;                         //?????????
	sum = row * col;                           //???????????sum
	for (i = 1; i <= row; i++)
		for (j = 1; j <= col; j++)
			cin >> array[i][j];                //???????row??col????????????
	i = 1;
	j = 1;                                     //?i?j????????????array[1][1]
	while (1)                  
	{
		n = i;
		for (j = n; j <= col - n + 1; j++)
		{
			cout << array[i][j] << endl;       //???????????
			count++;
		}
		j--;
		i++;
		if (count >= sum)
			break;                             //???????????????
		for ( ; i <= row - n + 1; i++)
		{
		    cout << array[i][j] << endl;       //????????????
			count++;
		}
		if (count >= sum)
			break;                             //???????????????
		i--;
		j--;
        for ( ; j >= n; j--)
		{
			cout << array[i][j] << endl;       //????????????
	        count++;
		}
		if (count >= sum)
			break;                             //???????????????
		j++;
		i--;
        for ( ; i > n; i--)
		{
	    	cout << array[i][j] << endl;       //??????????? 
			count++;
		}
		if (count >= sum)
	    	break;                             //???????????????
		i++;
		j++;
	}
	return 0;
}
int main()
{
	int i,j,det[100][100],ROW,COL,row1,row2,col1,col2,count=0;
	scanf("%d%d",&ROW,&COL);
	for(j=0;j<ROW;j++){
		for(i=0;i<COL;i++){
			scanf("%d",&det[j][i]);
		}
	}
	row1=0;
	row2=ROW-1;
	col1=0;
	col2=COL-1;
	while(row2>=row1&&col2>=col1){
		for(i=col1;i<=col2;i++){
			printf("%d\n",det[row1][i]);
			count++;
		} //verforward
		
		if(count==ROW*COL){
			break;
		}
		for(j=(row1+1);j<=row2;j++){
			printf("%d\n",det[j][col2]);
			count++;
		} //hordown
		
		if(count==ROW*COL){
			break;
		}
		for(i=col2-1;i>=col1;i--){
			printf("%d\n",det[row2][i]);
			count++;
		} //verbackward
		
		if(count==ROW*COL){
			break;
		}
		for(j=(row2-1);j>=(row1+1);j--){
			printf("%d\n",det[j][col1]);
			count++;
		} //horup

		col1++;
		col2--;
		row1++;
		row2--;
	}
	return 0;
}
int main()
{
	int row,col,a[100][100],i,j,sum,m=0;
	scanf("%d%d",&row,&col);
	sum=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++)
		{
			printf("%d\n",a[i][j]);
			m++;
		}
		if(m==sum)
			break;
		i++;
		j--;
		for(;i<row-(col-j-1);i++)
		{
			printf("%d\n",a[i][j]);
			m++;
		}
		if(m==sum)
			break;
		j--;
		i--;
		for(;j>=row-i-1;j--)
		{
			printf("%d\n",a[i][j]);
			m++;
		}
		if(m==sum)
			break;
		i--;
		j++;
		for(;i>j;i--)
		{
			printf("%d\n",a[i][j]);
			m++;
		}
		if(m==sum)
			break;
	}
}
int main()
{int row,col;
int i,j;
cin>>row>>col;
int a[101][101];
for(i=0;i<row;i++)
{
 for(j=0;j<col;j++)
 {
  cin>>a[i][j];
 }
}
int x;
for(x=0;x<=row&&x<=col;x++)
{
	i=x;
	if(x<=col-1-x)
	{
	for(j=x;j<=col-1-x;j++)
	{
		cout<<a[i][j]<<endl;
	}
	}
	else {break;}
	j=j-1;
	if(x+1<=row-1-x)
	{
		for(i=x+1;i<=row-1-x;i++)
		{
			cout<<a[i][j]<<endl;
		}
	}
	else {break;}
	i=row-1-x;
	if(x<=col-2-x)
	{
	for(j=col-2-x;j>=x;j--)
	{
		cout<<a[i][j]<<endl;
	}
	}
	else {break;}
	j=x;
	if(x+1<=row-2-x)
	{
		for(i=row-2-x;i>=x+1;i--)
		{
			cout<<a[i][j]<<endl;
		}
	}
	else {break;}
}
return 0;
}
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
int n, m, a[110][110], v[110][110];

int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; ++ i)
        for (int j = 0; j < m; ++ j)
            cin >> a[i][j];
    int x = 0, y = 0, cnt = 0, now = 0;
    while (cnt < n * m)
    {
        ++ cnt;
        v[x][y] = 1;
        cout << a[x][y] << endl;
        if (x + dx[now] < 0 || x + dx[now] >= n || y + dy[now] < 0 || y + dy[now] >= m)
            now = (now + 1) % 4;
        else
            if (v[x+dx[now]][y+dy[now]] == 1)
                now = (now + 1) % 4;
        x += dx[now];
        y += dy[now];
    }
    return 0;
}
int main()
{
	int a[100][100],row ,col;
	cin>>row>>col;
	for(int i=0;i<row;i++)             //????
		for(int j=0;j<col;j++)
			cin>>a[i][j];
	int flag=0;       //??
	for(int i=0;;i++)
	{
		for(int j=i;j<=col-i-1;j++)       //??
		{
			cout<<a[i][j]<<endl;
			flag+=1;
		}
		if(flag==row*col)
				break;
		for(int j=i+1;j<=row-i-1;j++)      //??
		{
			cout<<a[j][col-i-1]<<endl;
			flag+=1;
		}
		if(flag==row*col)
				break;
		for(int j=col-i-2;j>=i+1;j--)        //??
		{
			cout<<a[row-i-1][j]<<endl;
			flag+=1;
		}
		if(flag==row*col)
				break;
		for(int j=row-i-1;j>=i+1;j--)          //??
		{
			cout<<a[j][i]<<endl;
			flag+=1;
		}
		if(flag==row*col)
				break;
	}
	return 0;
}
void main()
{
	int a[100][100];
	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]);
	int s_row=0,s_col=0,e_row=row-1,e_col=col-1;
	while(1)
	{
		if (s_row>e_row)
			break;
		for (i=s_col;i<=e_col;i++)
			printf("%d\n",a[s_row][i]);
		s_row++;
		if (s_col>e_col)
			break;
		for (i=s_row;i<=e_row;i++)
			printf("%d\n",a[i][e_col]);
		e_col--;
		if (s_row>e_row)
			break;
		for (i=e_col;i>=s_col;i--)
			printf("%d\n",a[e_row][i]);
		e_row--;
		if (s_col>e_col)
			break;
		for (i=e_row;i>=s_row;i--)
			printf("%d\n",a[i][s_col]);
		s_col++;
	}
}
int main()
{
	int m,n;
	int h,l,i;
	int sz[100][100];
	scanf("%d%d",&m,&n);
	for(h=0;h<m;h++)
	{
		for(l=0;l<n;l++)
		{
			scanf("%d",&(sz[h][l]));
		}
	}
	for(i=0;i<(m+1)/2&&i<(n+1)/2;i++)
	{
	    for(l=i;l<n-1-i;l++)
		{
			printf("%d\n",sz[i][l]);
		}
	    for(h=i;h<=m-1-i;h++)
		{
			printf("%d\n",sz[h][n-1-i]);
		}
	    for(l=n-2-i;l>=i;l--)
		{
			if(i!=m-1-i&&i!=n-1-i)
			{
				printf("%d\n",sz[m-1-i][l]);
			}
		}
		for(h=m-2-i;h>=1+i;h--)
		{
			if(i!=m-1-i&&i!=n-1-i)
			{
		    	printf("%d\n",sz[h][i]);
			}
		}
	}
	return 0;
}
int main()
{
	int array[101][101],row,col;
	int i=0,j=0,sum=0;
	cin>>row>>col;
	for(i=0;i<row;i++){
		for(j=0;j<col;j++){
		cin>>array[i][j];
		}}//????
	int n=0;
	for(n=0;;n++){
		for(j=n;j<=col-n-1;j++){
			cout<<array[n][j]<<endl;
			sum++;//???
		}
		if(sum==row*col)break;
		for(i=n+1;i<=row-1-n;i++){
		cout<<array[i][col-n-1]<<endl;
		sum++;
		}//???
	    if(sum==row*col)break;
		for(j=col-n-2;j>=n;j--){
		cout<<array[row-1-n][j]<<endl;
		sum++;
		}//???
			if(sum==row*col)break;
			for(i=row-2-n;i>=n+1;i--){
			cout<<array[i][n]<<endl;
			sum++;
			}//???
				if(sum==row*col)break;
	}
	return 0;
}
int main(){
    int x,y;
    scanf("%d%d",&y,&x);
    int sz[x][y];
    int c,d;
    c=x*y;
    d=0;
    for(int b=0;b<y;b++){
        for(int a=0;a<x;a++){
            scanf("%d",&sz[a][b]);
        }
    }
    for(int i=0;i!=-1;i++){
    for(int a=i;a<x-i;a++){
        printf("%d\n",sz[a][i]);
        sz[a][i]=0;
        d++;
    }
    if(d==c){
        break;
    }
    for(int b=i+1;b<y-i;b++){
        printf("%d\n",sz[x-i-1][b]);
        sz[x-i-1][b]=0;
        d++;
    }
    if(d==c){
        break;
    }
    for(int a=x-i-2;a>=i;a--){
        printf("%d\n",sz[a][y-i-1]);
        sz[a][y-i-1]=0;
        d++;
    }
    if(d==c){
        break;
    }
    for(int b=y-i-2;b>i;b--){
        printf("%d\n",sz[i][b]);
        sz[i][b]=0;
        d++;
    }
    if(d==c){
        break;
    }
    }
    return 0;
}
int main()
{
    int a[100][100];
	int row,col,i,j,h;
	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=-1;	
	for(h=0;;h++)
	{
		for(j++;j<col-h;j++)
		{
			printf("%d\n",a[i][j]);
		}
		j--;
		if(i>=row-h-1)
			break;
		for(i++;i<row-h;i++)
		{
			printf("%d\n",a[i][j]);
		}
		i--;
		if(j<h+1)
			break;
		for(j--;j>=h;j--)
		{
		    printf("%d\n",a[i][j]);
		}
		j++;
		if(i<h+2)
			break;
		for(i--;i>=h+1;i--)
		{
		    printf("%d\n",a[i][j]);
		}
		i++;
		if(j>=col-h-1)
			break;
	}


	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;j++){
    scanf("%d",&m1[i][j]);}
    scanf("\n");
}
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 sz[100][100],row,col;
	scanf("%d %d",&row,&col);
	for(int i=0;i<row;i++){
		for(int j=0;j<col;j++){
			scanf("%d",&sz[i][j]);
		}
	}
	int xx_row=0,sx_row=row-1;
	int xx_col=0,sx_col=col-1;
	int k,n;
	while(xx_row<sx_row&&xx_col<sx_col){
    	for(k=xx_col;k<=sx_col-1;k++){
	    	printf("%d\n",sz[xx_row][k]);
		}
		for(n=xx_row;n<=sx_row-1;n++){ 
		    printf("%d\n",sz[n][sx_col]);
		}
        for(k=sx_col;k>=xx_col+1;k--){
	    	printf("%d\n",sz[sx_row][k]);
		}
		for(n=sx_row;n>=xx_row+1;n--){
	    	printf("%d\n",sz[n][xx_col]);
		}
	xx_col++;
	sx_col--;
	xx_row++;
	sx_row--;
	}
	if(sx_row==xx_row){
		for(k=xx_col;k<=sx_col;k++){
			printf("%d\n",sz[sx_row][k]);
		}
	}else
		if(xx_row==sx_col){
			for(n=xx_row;n<=sx_row;n++){
				printf("%d\n",sz[n][sx_col]);
			}
		}
		return 0;
}
int main()
{
	int row,col,x,y,a[100][100],flag=0,i,k;
	scanf("%d%d",&row,&col);
	for(x=0;x<row;x++){
		for(y=0;y<col;y++){
			scanf("%d",&a[x][y]);}
	}
	k=(row>col)?col:row;
    for(i=0;i<k;i++){
		for(y=i;y<col-i;y++){
			printf("%d\n",a[i][y]);
			flag++;}
          if(flag==row*col)
			  break;
		for(x=i+1;x<row-i;x++){
			printf("%d\n",a[x][col-1-i]);
	    	flag++;}
		if(flag==row*col)
			  break;
		for(y=col-2-i;y>=i;y--){
			printf("%d\n",a[row-1-i][y]);
	    	flag++;}
		if(flag==row*col)
			  break;
		for(x=row-2-i;x>i;x--){
			printf("%d\n",a[x][i]);
	    	flag++;}
		if(flag==row*col)
			  break;
	}
	return 0;
}
int main()
{
	int i, j, k;
	int sz[100][100];
	int row,col;
	scanf("%d %d",&row,&col);
	for(i=0;i<row;i++){
		for(j=0;j<col;j++){
			scanf("%d",&sz[i][j]);
		}
	}
	for(k=0;k<(col+1)/2;k++){
		for(i=k,j=k;j<col-k;j++){
			printf("%d\n",sz[i][j]);
		}
		if(2*k==row-1){break;}
		for(i=k+1,j=col-k-1;i<row-k;i++){
			printf("%d\n",sz[i][j]);
		}
		if(2*k==col-1){break;}
		for(i=row-k-1,j=col-k-2;j>=k;j--){
			printf("%d\n",sz[i][j]);
		}
		if(2*k==row-2){break;}
		for(j=k,i=row-k-2;i>k;i--){
			printf("%d\n",sz[i][j]);
		}
		if(2*k==col-2){break;}
	}
	return 0;
}
int main()
{
	int a[100][100], row, col;
	cin >> row >> col;
	for (int i = 0; i < row; i++)
		for (int j = 0; j < col; j++)
			cin >> a[i][j];
	int r = 0, c = 0, num = 0, n = row * col, row0 = 0, col0 = 0;
	while (true)
	{
		for (; c < col; c++)
		{
			cout << a[r][c] <<endl;
			num++;
		}
		if (num == n)
			break;
		row0++;
		c--;
		r++;
		for (; r < row; r++)
		{
			cout << a[r][c] << endl;
			num++;
		}
		if (num == n)
			break;
		col--;
		r--;
		c--;
		for (; c >= col0; c--)
		{
			cout << a[r][c] << endl;
			num++;
		}
		if (num == n)
			break;
		row--;
		c++;
		r--;
		for (; r >= row0; r--)
		{
			cout << a[r][c] << endl;
			num++;
		}
		if (num == n)
			break;
		col0++;
		r++;
		c++;
	}
	cin >> row;
	return 0;
}
int row,col,array[MAXN][MAXN],sign[MAXN][MAXN];

int main(){
	memset(array,0,sizeof(array));
	memset(sign,0,sizeof(sign));
	cin>>row>>col;
	for(int i=0;i<row;i++){
		for(int j=0;j<col;j++) cin>>array[i][j]; 
	}
	int num=0,sxy=0,cxy=0,mrow=0,mcol=0;;//0==x,1==y;0==left->right/down;1==right/up
	while(num<row*col){
		if(sxy==0){
			while(mcol<col&&mcol>=0){
				if(sign[mrow][mcol]==0)	{
					cout<<array[mrow][mcol]<<endl;
					num++;
				}
				sign[mrow][mcol]=1;
				if(cxy==0){
					if(mcol+1<col&&sign[mrow][mcol+1]==0) mcol++;
					else break;
				}
				else{
					if(mcol-1>=0&&sign[mrow][mcol-1]==0) mcol--;
					else break;
				}
			}
			sxy=1;
		}
		else{
			while(mrow<row&&mrow>=0){
				if(sign[mrow][mcol]==0){
					cout<<array[mrow][mcol]<<endl;
					num++;
				}
				sign[mrow][mcol]=1;
				if(cxy==0){
					if(mrow+1<row&&sign[mrow+1][mcol]==0) mrow++;
					else break;
				}
				else{
					if(mrow-1>=0&&sign[mrow-1][mcol]==0) mrow--;
					else break;
				}
			}
			sxy=0;
			cxy=(cxy) ? 0 : 1;
		}
	}
}
int main()
{
 int m,n,a[100][100];
 int p,i,j,k,q,s,ys,hs;
 scanf("%d%d",&m,&n);
 for(i=1;i<=m;i++)
  {
   for(j=1;j<=n;j++)
   {
	scanf("%d",&a[i][j]);
   }
  }
 if(m<=n)
 {
   p=m/2;
   ys=m%2;
   hs=1;
 }
 else 
 {
   p=n/2;
   ys=n%2;
   hs=2;
 }
 for(i=1;i<=p;i++)
 {
	for(j=i;j<=n-i;j++)
	{
		printf("%d\n",a[i][j]);
    }
	for(k=i;k<=m-i;k++)
	{
		printf("%d\n",a[k][n+1-i]);
	}
	for(q=n-i+1;q>=i+1;q--)
	{
		printf("%d\n",a[m+1-i][q]);
	}
	for(s=m+1-i;s>=i+1;s--)	
	{
		printf("%d\n",a[s][i]);
	}
 }
 if(ys==1)
 {
		if(hs==1)
		{
			for(i=(m+1)/2;i<=n-(m-1)/2;i++)
			{
				printf("%d\n",a[(m+1)/2][i]);
			}
		}
		if(hs==2)
		{
			for(i=(n+1)/2;i<=m-(n-1)/2;i++)
			{
				printf("%d\n",a[i][(n+1)/2]);
			}
		}
 }
 return 0;
}
void main(){
     int i,j,xr,sr,xc,sc,row,col,matrix[ROW][COL];
	 scanf("%d%d",&row,&col);
	 for(i=0;i<row;i++)
		 for(j=0;j<col;j++)
			 scanf("%d",&matrix[i][j]);
     xr=0;
	 sr=row-1;
	 xc=0;
	 sc=col-1;
	 while(xr<sr&&xc<sc){
	      for(j=xc;j<sc;j++)
			  printf("%d\n",matrix[xr][j]);
		  for(i=xr;i<sr;i++)
			  printf("%d\n",matrix[i][sc]);
          for(j=sc;j>xc;j--)
			  printf("%d\n",matrix[sr][j]);
		  for(i=sr;i>xr;i--)
			  printf("%d\n",matrix[i][xc]);
		  xr++;
		  sr--;
		  xc++;
		  sc--;
	 }
	 if(xr==sr&&xc==sc)
		 printf("%d",matrix[xr][xc]);
	 else {
		 if(xr==sr)
		 for(j=xc;j<=sc;j++)
			  printf("%d\n",matrix[xr][j]);
	     if(xc==sc)
            for(i=xr;i<=sr;i++)
				printf("%d\n",matrix[i][sc]);
	 }
}
// homework : ????????
// name     : ???



int main()
{
	int array[100][100];
	int row, col;
	cin >> row >> col;
	for( int i = 0; i < row; i++ )
	{
		for( int j = 0; j < col; j++ )
		{
			cin >> array[i][j];
		}
	}
	for( int row1 = 0, row2 = row - 1,col1 = 0, col2 = col - 1; col1 <= col2 && row1 <= row2; row1++, row2--, col1++, col2-- )
	{
		if( col1 == col2 && row1 == row2 ) 
		{
			cout << array[row1][col1] << endl;
			break;
		}
		if( row1 == row2 )
		{
			for( int i =col1; i <= col2; i++ )
				cout << array[row1][i] << endl;
			break;
		}
		if( col1 == col2 )
		{
			for( int i = row1; i <= row2; i++ )
				cout << array[i][col1] << endl;
			break;
		}
		for( int i = col1; i < col2; i++ )
			cout << array[row1][i] << endl;
		for( int i = row1; i < row2; i++ )
			cout << array[i][col2] << endl;
		for( int i = col2; i > col1; i-- )
			cout << array[row2][i] << endl;
		for( int i = row2; i > row1; i-- )
			cout << array[i][col1] << endl;
	}
	
	return 0;
}
int x,y,x1,y1;
void next()
{
	if((x1==0)&&(y1==1))
	{
		x1=1;
		y1=0;
	}
	else if((x1==1)&&(y1==0))
	{
		x1=0;
		y1=-1;
	}
	else if ((x1==0)&&(y1==-1))
	{
		x1=-1;
		y1=0;
	}
	else if((x1==-1)&&(y1==0))
	{
		x1=0;
		y1=1;
	}
}
void main()
{
	int a[200][200]={0},row,col,i,j,count;
    scanf("%d%d",&row,&col);
	for(i=1;i<=row;i++)
	{
		for(j=1;j<=col;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	x1=0;
	y1=1;
	for(x=1,y=0,count=1;count<=row*col;)
	{
		x=x+x1;
		y=y+y1;
		if(a[x][y]==0)
		{
			x=x-x1;
			y=y-y1;
			next();
		}
		else
		{
			printf("%d\n",a[x][y]);
			a[x][y]=0;
			count++;
		}
	}
}
/*
 * ????????.cpp
 *
 *  Created on: 2012-12-27
 *      Author: i
 */
int a[103][103]={0},n=0,m=0;
void shuchu(int hang,int lie){
	int i=0;
	if((n%2==0&&hang>=n/2)||(m%2==0&&lie>=m/2)){}
	else if(m%2==1&&lie==m/2)for(i=hang;i<n-hang;i++)cout<<a[i][lie]<<endl;
	else if(n%2==1&&hang==n/2)for(i=lie;i<m-lie;i++)cout<<a[hang][i]<<endl;
	else{
		for(i=lie;i<m-lie;i++)cout<<a[hang][i]<<endl;
		for(i=hang+1;i<n-hang;i++)cout<<a[i][m-lie-1]<<endl;
		for(i=m-lie-2;i>=lie;i--)cout<<a[n-hang-1][i]<<endl;
		for(i=n-hang-2;i>=hang+1;i--)cout<<a[i][lie]<<endl;
		shuchu(hang+1,lie+1);
	}
}
int main(){
	int i=0,j=0;
	cin>>n>>m;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cin>>a[i][j];
		}
	}
	shuchu(0,0);
	return 0;
}
int main()
{
	int m,n,i,j,k,p,q,flag=0,t;
	int a[123][123];
	scanf("%d%d",&m,&n);
	for(i=0;i<m;i++)
		for(j=0;j<n;j++)
		{
			scanf("%d",&a[i][j]);
		}
		for(t=0;t<123;t++)
		{
			for(i=t;i<n-t;i++)
			{
				if(a[t][i]==-123||flag==1)
					
				{flag=1;break;}
				printf("%d\n",a[t][i]);
				a[t][i]=-123;
			}
			for(j=t+1;j<m-t;j++)
			{
				if(a[j][i-1]==-123||flag==1)
					
				{flag=1;break;flag=1;}
				printf("%d\n",a[j][i-1]);
				a[j][i-1]=-123;
			}
			for(p=i-2;p>=t;p--)
			{
				if(a[j-1][p]==-123||flag==1)
					
				{flag=1;break;flag=1;}
				printf("%d\n",a[j-1][p]);
				a[j-1][p]=-123;
			}
			for(q=j-2;q>t;q--)
			{
				if(a[q][t]==-123||flag==1)
					{flag=1;break;flag=1;}
				printf("%d\n",a[q][t]);
				a[q][t]=-123;
			}
			if(flag==1)
			break;
		}
		return 0;
}
int main()
{
	int a[105][105];
	int row,col,i,j,t=0,temp=0,count=0;
	scanf("%d%d",&row,&col);
	int sum=row*col;
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			scanf("%d",&a[i][j]);
	while(1)
	{
		for(i=t;i<col-t;i++)
		{
			printf("%d\n",a[t][i]);
			count++;
		}
		if(count==sum)
			break;
		for (i=t+1;i<row-t;i++)
		{
			printf("%d\n",a[i][col-t-1]);
			count++;
		}
		if(count==sum)
			break;
		for (i=col-2-t;i>=t;i--)
		{
			printf("%d\n",a[row-t-1][i]);
			count++;
		}
        if(count==sum)
			break;
		for (i=row-2-t;i>t;i--)
		{
			printf("%d\n",a[i][t]);
            count++;
		}
        if(count==sum)
			break;
		t++;
	}
	return 0;
}
void f(int x,int y,int a[][100])
{
   int i,j; 
   if(x*y==0||x<0||y<0)                               //??????? 
     return;
   if(x==1||y==1)
   {
     for(i=0;i<x;i++)
       for(j=0;j<y;j++)
       { 
         cout<<a[i][j]<<endl;
       }
   return; 
   } 
   int b[100][100]; 
   for(j=0;j<y;j++)                      //???? 
     cout<<a[0][j]<<endl;
   for(i=1;i<x;i++)
     cout<<a[i][y-1]<<endl;
   for(j=y-2;j>=0;j--)
     cout<<a[x-1][j]<<endl;
   for(i=x-2;i>0;i--)
     cout<<a[i][0]<<endl;
   for(i=1;i<x-1;i++) 
     for(j=1;j<y-1;j++)
       {
         b[i-1][j-1]=a[i][j];             
       }

   f(x-2,y-2,b);                        //???????? 
   return; 
} 

int main()
{
int x,y,a[100][100],i,j;
cin>>x>>y;                                 //???? 
for(i=0;i<x;i++)
  for(j=0;j<y;j++) 
    cin>>a[i][j];
if(x==1||y==1)
  for(i=0;i<x;i++)
    for(j=0;j<y;j++) 
      cout<<a[i][j]<<endl;
else 
   f(x,y,a); 
return 0; 
}