semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main() {
	int row ,col,a[100][100];
	int i,j,k;
	int n=0;
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i=i+1){
		for(j=0;j<col;j=j+1){
			scanf("%d",&a[i][j]);
		}
	}
	for(k=0;k<=100;k=k+1){
		for(i=k;i<col-k;i=i+1){
			if(n!=row*col){
			printf("%d\n",a[k][i]);
			n=n+1;
			}
		
		}
		for(i=k+1;i<row-k;i=i+1){	if(n!=row*col){
		
			printf("%d\n",a[i][col-1-k]);
			n=n+1;}
		}
		for(i=col-2-k;i>=k;i=i-1){	if(n!=row*col){
		
			printf("%d\n",a[row-1-k][i]);
			n=n+1;}
		}
		for(i=row-2-k;i>=1+k;i=i-1){	if(n!=row*col){
		
			printf("%d\n",a[i][k]);
			n=n+1;}
		}
	}
	return 0;
}
int main(){
	int row,col,array[100][100],i,j,t[100][100],n,a;
	scanf("%d %d",&row,&col);
	for(i=0;i<row;i++){
		for(j=0;j<col;j++){
			scanf("%d",&array[i][j]);
			t[i][j]=1;
		}
	}
	i=0;
	j=-1;
	a=0;
	for(n=0;a<row*col;n++){
		if(n%4==0){
			for(j=j+1;j<col&&t[i][j]==1;j++){
				printf("%d\n",array[i][j]);
				a++;
				t[i][j]=0;
			}
			j--;
		}else if(n%4==1){
			for(i=i+1;i<row&&t[i][j]==1;i++){
				printf("%d\n",array[i][j]);
				a++;
				t[i][j]=0;
			}
			i--;
		}else if(n%4==2){
			for(j=j-1;j>=0&&t[i][j]==1;j--){
				printf("%d\n",array[i][j]);
				a++;
				t[i][j]=0;
			}
			j++;
		}else if(n%4==3){
			for(i=i-1;i>=0&&t[i][j]==1;i--){
				printf("%d\n",array[i][j]);
				a++;
				t[i][j]=0;
			}
			i++;
		}
	}
	return 0;
}
int main(int argc, char* argv[])
{
	int array[100][100];
	int n,row,col,i,j,k=0,r,t,x=0;
	float m;
	scanf("%d",&row);
	scanf("%d",&col);
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
		{
	    	scanf("%d",&array[i][j]);
		}
	}
	if(row>col)
	{
		n=col;
	}
	else n=row;
	m=(float)n;
		while(k<m/2)
		{
			for(j=k;j<col-k;j++)
			{
				if(x!=row*col)
				{
					printf("%d\n",array[k][j]);
					x++;
				}
			}
			for(i=k+1;i<row-1-k;i++)
			{
				if(x!=row*col)
				{
					printf("%d\n",array[i][col-k-1]);
					x++;
				}
			}
			for(t=col-k-1;t>k;t--)
			{
				if(x!=row*col)
				{
					printf("%d\n",array[row-k-1][t]);
					x++;
				}
			}
			for(r=row-1-k;r>k;r--)
			{
				if(x!=row*col)
				{
					printf("%d\n",array[r][k]);
					x++;
				}
			}
			k++;
		}
	return 0;
}
int		arr[100][100] = {0};
int		pos[120][120] = {0};
int		rr, cc;

void	bianli(int, int, int, int);

int main()
{
	int	i, j;
	cin >> rr;
	cin >> cc;

	for(i = 0; i < rr; i ++)
	{
		for (j = 0; j < cc; j ++)
		{
			cin >> arr[i][j];
			pos[i][j] = 1;
		}
	}

	bianli(0, 0, 0, 1);
return 0;
}

//0 ??? 1 ??? 
void	bianli(int k, int ii, int jj, int s)
{
	if(pos[ii][jj] == 0)
	{
		return;
	}


	int i, j;
	//??
	if(k == 0)
	{
		//?? 
		if(s == 0)
		{
			for (j = jj; j >= 0; j --)
			{
				if(pos[ii][j] == 1)
				{
					cout << arr[ii][j] << endl;
					pos[ii][j] = 0;
				}
				else
				{
					bianli(1, ii - 1, j + 1, 0);
					return;
				}
			}
			bianli(1, ii - 1, 0, 0);
			return;
		}
		//?? 
		else
		{
			for (j = jj; j < cc; j ++)
			{
				if(pos[ii][j] == 1)
				{
					cout << arr[ii][j] << endl;
					pos[ii][j] = 0;
				}
				else
				{
					bianli(1, ii + 1, j - 1, 1);
					return;
				}
			}
			bianli(1, ii + 1, cc - 1, 1);
			return;
		}
	}		
	//??
	else
	{
		//?? 
		if(s == 0)
		{
			for (i = ii; i >= 0; i --)
			{
				if(pos[i][jj] == 1)
				{
					cout << arr[i][jj] << endl;
					pos[i][jj] = 0;
				}
				else
				{
					bianli(0, i + 1, jj + 1, 1);
					return;
				}
			}
			bianli(0, 0, jj + 1, 1);
			return;
		}
		
		//?? 
		else
		{
			for (i = ii; i < rr; i ++)
			{
				if(pos[i][jj] == 1)
				{
					cout << arr[i][jj] << endl;
					pos[i][jj] = 0;
				}
				else
				{
					bianli(0, i - 1, jj - 1, 0);
					return;
				}
			}
			bianli(0, rr - 1, jj - 1, 0);
			return;
		}
	}

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



return 0;
}
int main(){
    int visit[105][105];
    int num[105][105];
    int i,j,row,col;
    scanf("%d %d",&row,&col);
    for(i = 0; i < row; i++){
            for(j = 0; j < col; j++){
                    visit[i][j] = 0;
                    scanf("%d",&num[i][j]);
            }
    }
    int direct = right;
    int x = 0,y = 0;
    while(1){
             if(x < 0||x >= row||y < 0||y >= col||visit[x][y] == 1){break;}
             visit[x][y] = 1;
             printf("%d\n",num[x][y]);
             switch(direct){        //??????????????? 
                     case up:       //??????????????? 
                          if(x - 1 < 0||visit[x - 1][y] == 1){
                               direct = (direct + 1) % 4;
                          }
                          break;
                     case down:
                          if(x + 1 >= row||visit[x + 1][y] == 1){
                               direct = (direct + 1) % 4;
                          }
                          break;
                     case left:
                          if(y - 1 < 0||visit[x][y - 1] == 1){
                               direct = (direct + 1) % 4;
                          }
                          break;
                     case right:
                          if(y + 1 >= col||visit[x][y + 1] == 1){
                               direct = (direct + 1) % 4;
                          }
                          break;
                     default:break;
             }
             switch(direct){
                     case up:x--;break;
                     case down:x++;break;
                     case left:y--;break;
                     case right:y++;break; 
                     default:break;
             }
    }
    return 0;
}
int main(){
	int sz[100][100],sc[10000];
	int m,n,i,j,a,t,k;
	

	scanf("%d%d",&m,&n);
	for(i=1;i<=m;i++){
		for(j=1;j<=n;j++){
			scanf("%d",&sz[i][j]);
		}
	}
	j=1;
	for(k=1;k<=n-n/2;k++){
	for(i=k;i<=n-k+1;i++){
		sc[j]=sz[k][i];
		j++;
	}
	for(i=k;i<=m-k;i++){
			sc[j]=sz[i+1][n-k+1];
			j++;
		}
	for(i=n-k;i>=k;i--){
		sc[j]=sz[m-k+1][i];
		j++;
	}
	for(i=m-k;i>=k+1;i--){
		sc[j]=sz[i][k];
		j++;          
	}
    }
	for(i=1;i<=m*n;i++){
		printf("%d\n",sc[i]);
	}
	
	
return 0;
}
int main(){
int i,j,k,sz[h][h],max,row,col,e,t;
int m,l;
    scanf("%d%d",&row,&col);
      for(i=1;i<=row;i++){
          for(j=1;j<=col;j++)
           scanf("%d",&sz[i][j]);
	  }
	  if(row==1||col==1){
		  for(i=1;i<=row;i++){
          for(j=1;j<=col;j++)
           printf("%d\n",sz[i][j]);
	  }    }else{
           if(row%2!=0&&col%2!=0){
			   if(col>row){
        t=(row+1)/2;
			   }else if(row>=col){
			   t=(col+1)/2;
			   }
			   max=t;
		   }else{
	if(col>row){
           e=row/2;
	}
	else  if(row>=col){
		e=col/2;
	}
	max=e;
}
for(k=1;k<=max;k++){
for(j=k;j<=col-k;j++)
printf("%d\n",sz[k][j]);
for(i=k;i<=row-k;i++)
printf("%d\n",sz[i][col-k+1]);
for(j=col-k+1;j>=k+1;j--)
printf("%d\n",sz[row+1-k][j]);
for(i=row-k+1;i>=k+1;i--)
printf("%d\n",sz[i][k]);

m=k;
}
if(row%2!=0&&col%2==0){
for(l=m+1;l<=(col-m);l++){
	printf("%d\n",sz[(row+1)/2][l]);
}
}
else if(row%2==0&&col%2!=0){
for(l=m+1;l<=(row-m);l++){
	printf("%d\n",sz[l][(col+1)/2]);
}
}
 else if(row%2!=0&&col%2!=0){
	

printf("%d\n",sz[(row+1)/2][(col+1)/2]);
	}
	 
		
}
return  0;



}
/*
 * 1104-1.cpp
 *
 *  Created on: 2011-11-5
 *      Author: Administrator
 */
int main(){
	int row,col;
	cin>>row>>col;
	int a[row][col];
	int i,j,k,m,s=0;
	m=row*col;
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			cin>>a[i][j];




	for(i=0;i<row/2;i++){
		for(j=i;j<col-i-1;j++){
			if(s>=m)
										break;
			else{
				cout<<a[i][j]<<endl;
				s++;}

		}


		for(k=i;k<row-i-1;k++){
			if(s>=m)
								break;
			else{

			cout<<a[k][col-i-1]<<endl;
				s++;}

		}


		for(j=col-i-1;j>i;j--){
			if(s>=m)
								break;
			else{
				cout<<a[row-1-i][j]<<endl;
				s++;}

		}

		for(k=row-i-1;k>i;k--){
			if(s>=m)
								break;
			else{
				cout<<a[k][i]<<endl;
				s++;}


		}





	}
	if(row%2){
		for(j=row/2;j<col-row/2;j++)
			cout<<a[row/2][j]<<endl;
	}

	return 0;

}
int main()
{
    int m,n,time=0;
    cin>>m>>n;
    int a[m][n];
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<n;j++)
        cin>>a[i][j];
    }

    for(int i=0;;i++)
    {
        for(int j=i;j<=n-1-i;j++)
        {
            cout<<a[i][j]<<endl;
            time++;
        }
        if(time==m*n)break;

        for(int j=i+1;j<=m-1-i;j++)
        {
            cout<<a[j][n-i-1]<<endl;
            time++;
        }
        if(time==m*n)break;

        for(int j=n-i-2;j>=i;j--)
        {
            cout<<a[m-i-1][j]<<endl;
            time++;
        }
        if(time==m*n)break;

        for(int j=m-i-2;j>=i+1;j--)
        {
            cout<<a[j][i]<<endl;
            time++;
        }
        if(time==m*n)break;
    }
    return 0;
}
void main()
{
	int i,j,t,a[100][100],m,n;
	scanf("%d%d",&m,&n);
	for(i=0;i<m;i++)for(j=0;j<n;j++)scanf("%d",&a[i][j]);
	for(i=0,j=0;i<(m/2+m%2)&&j<(n/2+n%2);i++,j++)
	{
		for(t=j;t<n-j;t++)printf("%d\n",a[i][t]);
		for(t=i+1;t<m-i;t++)printf("%d\n",a[t][n-j-1]);
		if(i<m/2)for(t=n-j-2;t>=j;t--)printf("%d\n",a[m-i-1][t]);
		if(j<n/2)for(t=m-i-2;t>=i+1;t--)printf("%d\n",a[t][j]);
	}
}

//??????????rp??
int main(){
 int array[100][100],i,j,a,b,b1,c,c1,d,e,f,f1,g,g1,h,row,col,sz[10000]={0},n=0,s=0,p,k=0;
 scanf("%d %d",&row,&col);
    for (i=0;i<row;i++){
  for (j=0;j<col;j++){
   scanf("%d",&array[i][j]);
   s++;
  }
 }
 while (n<=s){
  for (k=0;k<col;k++){
  a=k;
  b1=k;
          for(b=b1;b<col-k;b++){
           sz[n]=array[a][b];
     n++;
    }
     d=col-k-1;
     for (c=k+1;c<row-k;c++){
   sz[n]=array[c][d];
   n++;
   }
  e=row-k-1;
  f1=col-2-k;
           for (f=f1;f>=k;f--){
     sz[n]=array[e][f];
     n++;
     }
  h=k;
  g1=row-2-k;
        for (g=g1;g>=1+k;g--){
     sz[n]=array[g][h];
     n++;
     }
  
  }
 }
     for (p=0;p<s;p++){
   printf("%d\n",sz[p]);
  }

return 0;
}
void main()
{
     int r,c,i,j,a[100][100],n,t=0;
	 scanf("%d%d",&r,&c);
	 for(i=0;i<r;i++)
		 for(j=0;j<c;j++)
			 scanf("%d",&a[i][j]);

     for(n=0;;n++)
	 {
	     for(j=n;j<c-n;j++,t++)
			 printf("%d\n",a[n][j]);
		 if(t>=r*c)break;
	     for(i=n+1;i<r-n;i++,t++)
			 printf("%d\n",a[i][c-1-n]);
		 if(t>=r*c)break;
         for(j=c-2-n;j>=n;j--,t++)
			 printf("%d\n",a[r-n-1][j]);
		 if(t>=r*c)break;
         for(i=r-2-n;i>n;i--,t++)
             printf("%d\n",a[i][n]);
		 if(t>=r*c)break;
	 }
	 
}
//**********************************
//*  ????homework_10.cpp       *
//*  ??????1200012884        * 
//*  ?????2012?10?31?      *
//*  ?????????????    *
//**********************************

int main()
{
	int a[101][101];
	int row, col, i, j, count = 0, time;
	cin >> row >> col;
	for (i = 0;i < row;i++)
		for (j = 0;j < col;j++)
			cin >> a[i][j];
	i = -1;
	j = -1;
	time = row * col;
	for (;;)
	{
		i++;
	for (j += 1;j < col;j++)
		{
			cout << a[i][j] << endl;
			time--;
				}
			if (time == 0)
				break;

	j--;
	
	for (i += 1;i < row;i++)
		{
			cout << a[i][j] << endl;
			time--;
				}
			if (time == 0)
				break;

	i--;

	for (j -= 1;j >= count;j--)
		{
			cout << a[i][j] << endl;
			time--;
				}
			if (time == 0)
				break;

	j++;
	
			count++;
	for (i -= 1;i >= count;i--)
		{
			cout << a[i][j] << endl;
			time--;
				}
			if (time == 0)
				break;

	row--;
	col--;

	}
	return 0;
}
int main()
{
	int a[100][100]={0},i,j,row,col,p,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(p=0;;p++){
		for(j=p;j<=col-p-1;j++){
			printf("%d\n",a[p][j]);
			sum=sum+1;
		}
		if(sum==row*col)
			break;
		for(i=p+1;i<=row-p-1;i++){
			printf("%d\n",a[i][col-p-1]);
			sum=sum+1;
		}
		if(sum==row*col)
			break;
		for(j=col-p-2;j>=p;j--){
			printf("%d\n",a[row-p-1][j]);
			sum=sum+1;
		}
		if(sum==row*col)
			break;
		for(i=row-p-2;i>=p+1;i--){
			printf("%d\n",a[i][p]);
			sum=sum+1;
		}
		if(sum==row*col)
			break;
	}
	return 0;
}
int mat[102][102];
int unvis[102][102];

int main()
{
	int n,r,c,i,j,d;
	int dir[4][2] ={{0,1},{1,0},{0,-1},{-1,0}};
	scanf("%d%d",&r,&c);
	for(i = 0;i < r ;i ++)
		for(j = 0; j < c; j++)
		{
			scanf("%d",&mat[i][j]);
			unvis[i][j] = 1;
		}
	n = r * c;
	r = 0;
	c = 0;
	d = 0;
	while(n)
	{
		unvis[r][c] = 0;
		printf("%d\n",mat[r][c]);
		i = r + dir[d][0];
		j = c + dir[d][1];
		if(i >=0 && j>=0 && unvis[i][j])
		{
			r = i;
			c = j;
		}
		else
		{
			d = (d + 1) % 4;
			r = r + dir[d][0];
			c = c + dir[d][1];
		}
		n--;
	}
	
	return 0;
}
//****************************************
//*??? 
//*????? 1100012996       *
//*???2011.10.26**
//****************************************

int main()
{
	int row, col, i, j, l, k;
	cin >> row >> col;
	int a[100][100];
	for (i = 0; i < row; i++)
		for (j = 0; j < col; j++)
		{
			cin >> a[i][j];
		}
	l = 0;
	k = 1;
	if (row == 1 && col == 1)
	{
		cout << a[0][0];
	}
	else
	{
		for (j = 0; j < row * col; )
		{
			switch(k)
			{
			case 1:
				for (i = l; i < col - l; i++)
				{
					cout << a[l][i] << endl;
					j++;
				}
				k++;
				break;
			case 2:
				for (i = l + 1; i < row - 1 - l; i++)
				{
					cout << a[i][col - 1 - l] << endl;
					j++;
				}
				k++;
				break;
			case 3:
				for (i = col - l - 1; i >= l; i--)
				{
					cout << a[row - l - 1][i] << endl;
					j++;
				}
				k++;
				break;
			case 4:
				for (i = row - l - 2; i > l; i--)
				{
					cout << a[i][l] << endl;
					j++;
				}
				k++;
				break;
			default:
				k = 1;
				l++;
				break;
			}
		}
	}
	return 0;
}
int main()
{
	int i,j,n,m,k,q,p;
	int a[100][100];
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
			scanf("%d",&a[i][j]);
	}
	for(i=0;i<((n+1)/2);i++)
	{
		for(j=i;j<m-i;j++)
			printf("%d\n",a[i][j]);
	
		for(k=i+1;k<(n-i)&&i<(m-i);k++)
			printf("%d\n",a[k][m-1-i]);
	
		for(p=(m-i-2);p>=i&&(i+1)<(n-i);p--)
			printf("%d\n",a[n-i-1][p]);
	
		for(q=n-i-2;q>i&&(m-i-2)>=i;q--)
	        printf("%d\n",a[q][i]);
		
	
	}
	return 0;
}
void main()
{
	int a[100][100],i,j,k;
	int x,y,row,col;
	scanf("%d%d",&row,&col);
	for(i=1;i<=row;i++)
	{
		for(j=1;j<=col;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	x=0; y=row*col;
	for(k=0;;k++){
	for(j=1+k;j<=(col-k);j++)
	{
		printf("%d\n",a[1+k][j]);
		x++;
		if(x==y)  break;
	}
	if(x==y)  break;
	for(i=2+k;i<=(row-k);i++)
	{
		printf("%d\n",a[i][col-k]);//??
		x++;
		if(x==y)  break;
	}
	if(x==y)  break;
	for(j=(col-1-k);j>k;)
	{
		printf("%d\n",a[row-k][j]);//??
		j=j-1;
		x++;
		if(x==y)  break;
	}
	if(x==y)  break;
	for(i=(row-1-k);i>(1+k);)
	{
		printf("%d\n",a[i][1+k]);//??
		i=i-1;
		x++;
		if(x==y)  break;
	}
	if(x==y)  break;
	}
}
void main()
{
	int m,n,m1,m2,n1,n2;
	int i,j,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]);

    m1=m-1;
	n1=n-1;
	m2=0;
	n2=0;
	while(m1>m2&&n1>n2)
	{
		for(i=m2,j=n2;j<n1;j++)
			printf("%d\n",a[i][j]);

	    for(i=m2,j=n1;i<m1;i++)
		    printf("%d\n",a[i][j]);

	    for(i=m1,j=n1;j>n2;j--)
		    printf("%d\n",a[i][j]);

	    for(i=m1,j=n2;i>m2;i--)
		    printf("%d\n",a[i][j]);
		m1--;
		n1--;
		m2++;
		n2++;
	}
	if(m1==m2&&n1==n2)
		printf("%d\n",a[m1][n1]);
	else if(m1==m2)
		for(j=n2;j<=n1;j++)
			printf("%d\n",a[m1][j]);
		else
			for(i=m2;i<=m1;i++)
			    printf("%d\n",a[i][n1]);
}
int main(){
	int a[100][100]={0},row,col,num=0;
	cin>>row>>col;
	for(int i=0;i<row;i++){
		for(int j=0;j<col;j++){
			cin>>a[i][j];
		}
	}
	for(int i=0;;i++){
		if(num>=row*col)break;
		int b,x,y,z;
		for(b=i;b<col-i;b++){
			cout<<a[i][b]<<endl;
			num++;
		}
		if(num>=row*col)break;
		for(x=i+1;x<row-i;x++){
			cout<<a[x][b-1]<<endl;
			num++;                 
		}
		if(num>=row*col)break;
		for(y=col-i-2;y>=i;y--){
			cout<<a[row-i-1][y]<<endl;
			num++;                    
		}
		if(num>=row*col)break;
		for(z=row-i-2;z>i;z--){
			cout<<a[z][i]<<endl;
			num++;                   
		}
	}
	
	return 0;
}
//***********************************
//*   ????????              *
//*   ??????                  *
//*   ?????2011?11?5?       *
//***********************************


int main()
{
	int array[100][100];
	int row, col, i, j, p, count;
	cin >> row >> col;//???????
	for(i = 0; i < row; i ++)
	{
		for(j = 0; j < col; j ++)
		{
			cin >> array[i][j];//??????
		}
	}
	p = 0;//p???????????
	count = 0;//count?????????
	i = 0;
	j = 0;
	while(1)
	{
		for(j = count; j < col - count; j ++)
		{
			cout << array[i][j] << endl;
			p = p + 1;
		}//??????
		if(p == row * col)
			break;
		for(i = count + 1; i < row - count; i ++)
		{
			cout << array[i][j - 1] << endl;
			p = p + 1;
		}//??????
		if(p == row * col)
			break;
		for(j = col - count - 2; j >= count; j --)
		{
			cout << array[i - 1][j] << endl;
			p = p + 1;
		}//??????
		if(p == row * col)
			break;
		for(i = row - count - 2; i > count; i --)
		{
			cout << array[i][j + 1] << endl;
			p = p + 1;
		}//??????
		i = i + 1;
		if(p == row * col)
			break;//??????????????,??
		count = count + 1;
	}
	return 0;
}
int main ()
{
    int s[100][100];
    int row,col;
    int n=0,m=0,k;
    int a=0,b=1;
    int i,j;
    scanf ("%d %d", &row, &col);
    for (i=0;i<=row-1;i++)
    {
        for (j=0;j<=col-1;j++)
        {
            scanf ("%d", &s[i][j]);
        }
    }
    k=row*col;
    for (i=1;i<=k;i++)
    {
        printf ("%d\n", s[n][m]);
        if (n==b-1 && m<col-1)
        {
                    m=m+1;
        }
        else if (n<row-1 && m==col-1) 
             {
                         n=n+1;
             }
             else if (n==row-1 && m==col-1)
                  {
                               m=m-1;
                  }
                  else if (n==row-1 && m<col-1 && m>a)
                       {
                                    m=m-1;
                       }
                       else if (n==row-1 && m==a)
                            {
                                         n=n-1;
                                         
                            }
                            else if (n<row-1 && m==a && b<n)
                                 {
                                             n=n-1;
                                 }
                                 else if (n==b && m==a)
                                      {
                                               m=m+1;
                                               a=a+1;
                                               b=b+1;
                                               row=row-1;
                                               col=col-1;
                                       }  
    }
    
    return 0;
}
int main()
{int n,m,v[100][100],z,d;
 scanf("%d %d",&m,&n);
 for(int i=0;i<=m-1;i++)
   {for(int j=0;j<=n-1;j++)
       {scanf("%d",&(v[i][j]));}
   }
  
   
int p=0,u=n;  
if(m>n){u=m;} 
for(int i=0;i<=u;i++)
  {   
      for(int d=i;d<=n-i-1;d++)
        {
        printf("%d\n",v[i][d]);
         p++;if(p==m*n){break;}
        } 
        if(p==m*n){break;}
      for(int a=i+1;a<=m-i-1;a++)
       {
         printf("%d\n",v[a][n-1-i]);
          p++;if(p==m*n){break;}
        }
      if(p==m*n){break;}
      for(int b=n-i-2;b>=i;b--)
        {
        printf("%d\n",v[m-i-1][b]);
        p++;if(p==m*n){break;}
        }
       if(p==m*n){break;}
     for(int c=m-i-2;c>=i+1;c--)
     {
        printf("%d\n",v[c][i]);
       p++;
       if(p==m*n){break;}
     }  
     if(p==m*n){break;}
  }  
return 0; 

}
int main (){
	int n,m,a=0,b=0,c,d=0,e=0;
	int sz[100][100],i,j;
	scanf("%d %d",&n,&m);
	c=n*m;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&sz[i][j]);
		}
	}
	while(d<c){
		for(b=b;b<m-e;b++){
			printf("%d\n",sz[a][b]);
			d++;
		}
		if(d>=c){
			break;
		}
		b=b-1;
		for(a=a+1;a<n-e;a++){
			printf("%d\n",sz[a][b]);
			d++;
		}
		if(d>=c){
			break;
		}
		a=a-1;
		for(b=b-1;b>=e;b--){
			printf("%d\n",sz[a][b]);
			d++;
		}
		if(d>=c){
			break;
		}
		b=b+1;
		for(a=a-1;a>=e+1;a--){
			printf("%d\n",sz[a][b]);
			d++;
		}
		if(d>=c){
			break;
		}
		a=a+1;
		b=b+1;
		e++;
	}

	return 0;
}
//  ????????



int main()
{
    int m,n;
    cin>>m>>n;
    int a[m+1][n+1];
    for (int i=1;i<=m;i++)
    {
        for (int j=1;j<=n;j++)
            cin>>a[i][j];
    }
    int min;
    if (m>=n) min=n;
    else min=m;
    for (int i=1;i<=(1+min)/2;i++)
    {
        for (int j=i;j<=n+1-i;j++)
        {
            if (a[i][j]!=-1)
            {
                cout<<a[i][j]<<endl;
                a[i][j]=-1;
            }
        }
        
        for (int j=i+1;j<=m+1-i;j++)
        {
            if (a[j][n+1-i]!=-1)
            {
                cout<<a[j][n+1-i]<<endl;
                a[j][n+1-i]=-1;
            }
        }
        
        for (int j=n-i;j>i;j--)
        {
            if (a[m+1-i][j]!=-1)
            {
                cout<<a[m+1-i][j]<<endl;
                a[m+1-i][j]=-1;
            }
            
        }
        
        for (int j=m+1-i;j>i;j--)
        {
            if (a[j][i]!=-1)
            {
                cout<<a[j][i]<<endl;
                a[j][i]=-1;
            }
        }
    }
    
    return 0;
}
int main()
{
	int row=0,col=0;
	cin>>row>>col;
	int array[101][101];
	int i=0,j=0,k=0;
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			cin>>array[i][j];
	for(k=0;(row-2*k>2)&&(col-2*k>2);k++){
		for(j=k;j<col-k;j++)
			cout<<array[k][j ]<<endl;
		for(i=k+1;i<row-k;i++)
			cout<<array[i][col-1-k]<<endl;
		for(j=col-2-k;j>=k;j--)
			cout<<array[row-1-k][j]<<endl;
		for(i=row-2-k;i>=k+1;i--)
			cout<<array[i][k]<<endl;
	}
	if(row==col){
		for(j=k;j<col-k;j++)
			cout<<array[k][j ]<<endl;
		for(i=k+1;i<row-k;i++)
			cout<<array[i][col-1-k]<<endl;
		for(j=col-2-k;j>=k;j--)
			cout<<array[row-1-k][j]<<endl;
		for(i=row-2-k;i>=k+1;i--)
			cout<<array[i][k]<<endl;
	}
	else{
		for(j=k;j<col-k;j++)
			cout<<array[k][j ]<<endl;
		for(i=k+1;i<row-k;i++)
			cout<<array[i][col-1-k]<<endl;
	}
	return 0;
}
/*
 * c.cpp
 * ???1100012870;
 * ???????
 *  Created on: 2011-11-3
 *      Author: Li Wenpeng
 */
int main()
{
	int a[150][150],b[150][150];
	int m,n,i,j,x,y;
	memset(b,0,sizeof(b));        //?b????
	cin>>m>>n;
	for(i=1;i<=m;i++)             //??
		for(j=1;j<=n;j++){
			cin>>a[i][j];
			b[i][j]=1;
		}
	x=0;y=1;i=1;j=1;              //??a?1??1?
	cout<<a[1][1]<<endl;
	b[1][1]=0;
	while(x+y!=0){                //???????????
		if(b[i+x][j+y]>0) {
			cout<<a[i+x][j+y]<<endl;
			i=i+x;
			j=j+y;
			b[i][j]=0;
			continue;
		};                              //????????
		if (b[i+1][j]>0){x=1;y=0;continue;}
		if (b[i-1][j]>0){x=-1;y=0;continue;}
		if (b[i][j+1]>0){x=0;y=1;continue;}
		if (b[i][j-1]>0){x=0;y=-1;continue;}
		break;
	}
	return 0;
}
int main()
{int sz[100][100];
int hang,lie;
scanf("%d %d",&hang,&lie);
for(int a=0;a<hang;a++){
	for(int b=0;b<lie;b++){
	  scanf("%d",&sz[a][b]);
	}
}
int c,d,e,f;
int hs=0,ls=0;
int hz=hang-1,lz=lie-1;
while(hs<=hz&&ls<=lz)
{if(hs!=hz&&lz!=ls)
	{for(c=ls;c<=lz-1;c++){
	  printf("%d\n",sz[hs][c]);
	}
	for(d=hs;d<=hz-1;d++){
	  printf("%d\n",sz[d][lz]);
	}
	for(e=lz;e>=ls+1;e--){
	  printf("%d\n",sz[hz][e]);
	}
    for(f=hz;f>=hs+1;f--){
	  printf("%d\n",sz[f][ls]);
}}

else{for(int m=hs;m<=hz;m++){
	  for(int n=ls;n<=lz;n++){
	    printf("%d\n",sz[m][n]);
	}
}}
	hs++;
	ls++;
	hz--;
	lz--;
}
	
return 0;
}