semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main()
{
    int a[100][100], b[100][100], row, col, p, q, dir;
    cin >> row >> col;
    for (int i = 0; i < 100; i++)
    {
        for (int i1 = 0; i1 < 100; i1++)
        {
            b[i][i1] = 1;
        }
    }
    for (int i = 0; i < row; i++)
    {
        for (int i1 = 0; i1 < col; i1++)
        {
            cin >> a[i][i1];
            b[i][i1] = 0;
        }
    }
    p = 0;
    q = 0;
    dir = 1;
    for (int i = 0; i < row * col; i++)
    {
        cout << a[p][q] << endl;
        b[p][q] = 1;
            switch(dir)
            {
                case 1:
                if (b[p][q+1] == 0) q++;
                else
                {
                    p++;
                    dir = 2;
                }
                break;
                case 2:
                if (b[p+1][q] == 0) p++;
                else
                {
                    q--;
                    dir = 3;
                }
                break;
                case 3:
                if (b[p][q-1] == 0) q--;
                else
                {
                    p--;
                    dir = 4;
                }
                break;
                case 4:
                if (b[p-1][q] == 0) p--;
                else
                {
                    q++;
                    dir = 1;
                }
                break;
            }
    }

    return 0;
}
int main()
{
    int a[100][100],row,col,i,j,m,k,n,x,y,s=0;
    scanf("%d%d",&row,&col);
    for(i=0;i<row;i++)
    {
                      for(j=0;j<col;j++)
                      {scanf("%d",&a[i][j]);
                      }}
                      i=row-1;
                      j=col-1;
                      for(k=0;k<100;k++)
                      {x=k;
                      y=k;
                      m=k;
                      n=k;
                                        for(x=k;x<=j-k;x++)
                                        {printf("%d\n",a[k][x]);
                                        s++;}
                                        if(s==(i+1)*(j+1))
                                        {break;}
                                        for(y=k+1;y<=i-k;y++)
                                        {printf("%d\n",a[y][j-k]);
                                        s++;}
                                        if(s==(i+1)*(j+1))
                                       { break;}
                                        for(m=j-k-1;m>=k;m--)
                                        {printf("%d\n",a[i-k][m]);
                                        s++;}
                                        if(s==(i+1)*(j+1))
                                        {break;}
                                        for(n=i-k-1;n>=k+1;n--)
                                        {printf("%d\n",a[n][k]);
                                        s++;}
                                        if(s==(i+1)*(j+1))
                                        {break;}}
                                        return 0;}
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]);}
		}
 }
scanf("%d %d",&m,&n);		
 return 0;
}
int main()
{
 int row,col,i,j,k,c=0,h;
 cin>>row>>col;
 cout<<endl;
 k=row*col;
 int a[row][col],b[row+2][col+2];
 for(i=0;i<=row-1;i++)
 {for(j=0;j<=col-1;j++)
  {cin>>a[i][j];}
 }
 for(i=1;i<=row;i++)
 {for(j=1;j<=col;j++)
  {b[i][j]=1;}
 }
 for(i=0;i<=col+1;i++)
 {b[0][i]=0;b[row+1][i]=0;}
 for(j=1;j<=row;j++)
 {b[j][0]=0;b[j][col+1]=0;}
 i=0;
 j=0;
 h=1;
 while(1>0)
 {if(h%4==1&&c<k)
  {do
   {cout<<a[i][j]<<endl;
    b[i+1][j+1]=0;
    c=c+1;
    j=j+1;
   }while(b[i+1][j+1]!=0);
   h=h+1;
   i=i+1;
   j=j-1;
  }
  if(h%4==2&&c<k)
  {do
   {cout<<a[i][j]<<endl;
    b[i+1][j+1]=0;
    c=c+1;
    i=i+1;
   }while(b[i+1][j+1]!=0);
   h=h+1;
   j=j-1;
   i=i-1;
  }
  if(h%4==3&&c<k)
  {do
   {cout<<a[i][j]<<endl;
    b[i+1][j+1]=0;
    c=c+1;
    j=j-1;
   }while(b[i+1][j+1]!=0);
   h=h+1;
   i=i-1;
   j=j+1;
  }
  if(h%4==0&&c<k)
  {do
   {cout<<a[i][j]<<endl;
    b[i+1][j+1]=0;
    c=c+1;
    i=i-1;
   }while(b[i+1][j+1]!=0);
   h=h+1;
   j=j+1;
   i=i+1;
  }
  if(c==k) break;
 }
return 0;
}
int main(){
	int m,n,sz[100][100],x,y,z,a,b,w=0,i;
	int bz[100][100],flag=0;
	//bz????????flag=0?????=1?????=2?????=3????
	scanf("%d %d",&m,&n);
	for(int p=0;p<=m+1;p++)
		for(int q=0;q<=n+1;q++)
			bz[q][p]=1;//????
	for(int p=1;p<=m;p++)
	{
		for(int q=1;q<=n;q++)
		{
			scanf("%d",&sz[q][p]);  
			bz[q][p]=0;
		} 
	}
	x=1;y=1;
	while(w<m*n)
	{
		printf("%d\n",sz[x][y]);
		bz[x][y]=1;
		w++;
		switch(flag)
		{
		case 0:
			if(bz[x+1][y]==1)
			{
				flag=1;//???
				y++;
			}
			else
				x++;
			break;
		case 1:
			if(bz[x][y+1]==1)
			{
				flag=2;//???
				x--;
			}
			else
				y++;
			break;
		case 2:
			if(bz[x-1][y]==1)
			{
				flag=3;//???
				y--;
			}
			else
				x--;
			break;
		case 3:
			if(bz[x][y-1]==1)
			{
				flag=0;//???
				x++;
			}
			else
				y--;
			break;
		}
	}
	return 0;
}
int main()
{
	int a[100][100],b[10000],i,j,r,c,k=0,row,col,p;
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			scanf("%d",&a[i][j]);
	r=row;
	c=col;
	if(r>=c){
	for(c=col;c>col/2;c--)
	{
		p=0;
		for(j=col-c;j<c;j++)
		{
			b[k]=a[row-r][j];
			k++;
			p++;
		}
		if(p==0)
			break;
		else
			p=0;
		for(j=row-r+1;j<r;j++)
		{
			b[k]=a[j][c-1];
			k++;
			p++;
		}
		if(p==0)
			break;
		else
			p=0;
		for(j=c-2;j>=col-c;j--)
		{
			b[k]=a[r-1][j];
			k++;
        	p++;
		}	
		if(p==0)
			break;
		else
			p=0;
		for(j=r-2;j>row-r;j--)
		{
			b[k]=a[j][col-c];
			k++;
            p++;
		} 
		if(p==0)
			break;
		else
			p=0;
        r--;
	}
	}
	if(r<c){
    for(r=row;r>row/2;r--)
	{
		p=0;
		for(j=col-c;j<c;j++)
		{
			b[k]=a[row-r][j];
			k++;
            p++;
		}
		if(p==0)
			break;
		else
			p=0;
		for(j=row-r+1;j<r;j++)
		{
			b[k]=a[j][c-1];
			k++;
            p++;
		}
		if(p==0)
			break;
		else
			p=0;
		for(j=c-2;j>=col-c;j--)
		{
			b[k]=a[r-1][j];
			k++;
            p++;
		}
		if(p==0)
			break;
		else
			p=0;
		for(j=r-2;j>row-r;j--)
		{
			b[k]=a[j][col-c];
			k++;
            p++;
		}
		if(p==0)
			break;
		else
			p=0;
        c--;
	}
	}
	printf("%d",b[0]);
	for(i=1;i<k;i++)
		printf("\n%d",b[i]);
	return 0;
}
int main()
{

int i,j,m,n,a[101][101],k=0;
	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;k!=m*n;i++)
	{
		for(j=i;j<n-i;j++)
		{
		printf("%d\n",a[i][j]);
		k++;
		if(k==m*n)
		break;
		}
		if(k==m*n)
		break;

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

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

        for(j=m-i-2;j>i;j--)
		{
		printf("%d\n",a[j][i]);
		k++;
		if(k==m*n)
		break;
		}
		if(k==m*n)
		break;
	}
	return 0;
}
int main()
{
	int array[110][110];
	int row, col;
	int rowup = 0, rowdown = 0, colleft = 0, colright = 0;

	cin >> row >> col;
	for (int i = 1; i <= row; i++)
	{
		for (int j = 1; j <= col; j++)
		{
			cin >> array[i][j];
		}
	}

	while (1)
	{
		for (int k = colleft + 1; k <= col - colright; k++)
		{
			cout << array[rowup + 1][k] << endl;
		}
		rowup++;
		if (rowup + rowdown >= row)
			break;

		for (int k = rowup + 1; k <= row - rowdown; k++)
		{
			cout << array[k][col - colright] << endl;
		}
		colright++;
		if (colright + colleft >= col)
			break;

		for (int k = col - colright; k >= colleft + 1; k--)
		{
			cout << array[row - rowdown][k] << endl;
		}
		rowdown++;
		if (rowup + rowdown >= row)
			break;

		for (int k = row - rowdown; k >= rowup + 1; k--)
		{
			cout << array[k][colleft + 1] << endl;
		}
		colleft++;
		if (colright + colleft >= col)
			break;
	}
	return 0;
}
int main(int argc, char* argv[])
{int a[100][100],row,col,i,j,n=0;
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			scanf("%d",&a[i][j]);
	j=0;
	do
	{
		for(i=0+j;i<col-j;i++)
		{
			printf("%d\n",a[j][i]);
			n++;
		}if(n==row*col)break;
		for(i=j+1;i<row-j;i++)
		{
			printf("%d\n",a[i][col-1-j]);
			n++;
		}if(n==row*col)break;
		for(i=col-2-j;i>0+j;i--)
		{
			printf("%d\n",a[row-j-1][i]);
			n++;
		}if(n==row*col)break;
		for(i=row-j-1;i>0+j;i--)
		{
			printf("%d\n",a[i][j]);
			n++;
		}if(n==row*col)break;
		j++;
	}
	while(n!=row*col);
	return 0;
}
int main()
{
int i,j,k=0,b=1,h=1,l=1,x,y,a[100][100];
scanf("%d%d",&x,&y);
for(i=1;i<=x;i++)
{for(j=1;j<=y;j++)
{scanf("%d",&a[i][j]);}}
while(k<x*y-1)
{switch(b)
 {case 1:
  {for(i=h;i<=y-h;i++)
   {printf("%d\n",a[h][i]);}
   b=2;
   k+=y-2*h+1;break;}
  case 2:
  {for(i=l;i<=x-l;i++)
   {printf("%d\n",a[i][y-l+1]);}
   b=3;
   k+=x-2*l+1;break;}
  case 3:
  {for(i=y-h+1;i>=h+1;i--)
   {printf("%d\n",a[x-h+1][i]);}
   b=4;
   k+=y-2*h+1;
   h++;break;}
  case 4:
  {for(i=x-l+1;i>=l+1;i--)
   {printf("%d\n",a[i][l]);}
   b=1;
   k+=x-2*l+1;
   l++;break;}}}
if(x==y)
{printf("%d",a[h][l]);}
else if(b==2){printf("%d",a[h][y-h+1]);}
else if(b==3){printf("%d",a[x-l+1][y-l+1]);}
else if(b==4){printf("%d",a[x-h+1][h]);}
else if(b==1){printf("%d",a[l][l]);}
return 0;
}
int main()
{
	int an[100][100];
	int i,j,m,n,k,s;
	scanf("%d%d",&n,&m);
	for(j=0;j<n;j++)
	{
		for(i=0;i<m;i++) scanf("%d",&an[i][j]);
	}
	s=0;
    for(k=0;k<m/2&&k<n/2;k++)
		{
            for(i=k;i<m-k-1;i++) printf("%d\n",an[i][k]);
		    for(j=k;j<n-k-1;j++) printf("%d\n",an[m-k-1][j]);
			for(i=m-k-1;i>k;i--) printf("%d\n",an[i][n-k-1]);
			for(j=n-k-1;j>k;j--) printf("%d\n",an[k][j]);
			s=s+2*(m+n-4*k-2);
		}
	if(s!=m*n)
	{
		if(m<n) { for(j=k;j<n-k;j++) printf("%d\n",an[k][j]);}
		if(m>n) { for(i=k;i<m-k;i++) printf("%d\n",an[i][k]);}
		if(m==n) printf("%d\n",an[k][k]);
	}
    return 0;
}
int main()
{
  int array[100][100],s[10000],row,col,i,j,k,l,h,a,b,c;
  scanf("%d%d",&row,&col);
  for(i=0;i<row;i++)
  {
    for(j=0;j<col;j++)
     {
        scanf("%d",&array[i][j]);
     }
  }
  b=row;
  c=col;
  if(b>c)
  {
   a=b;
   b=c;
   c=a;
   }
  a=b;
  if(a%2==0)
  {
    l=a/2;
  }
  else
  {
   l=a/2+1;
   }
  k=0;
  for(h=0;h<l;h++)
  {
    for(j=h;j<col-h;j++)
     {
      s[k]=array[h][j];
      k++;
     }
    for(i=h+1;i<row-h;i++)
    {
    s[k]=array[i][col-1-h];
    k++;
    }
    for(j=col-2-h;j>=h;j--)
    {
    s[k]=array[row-1-h][j];
    k++;
    }
    for(i=row-2-h;i>h;i--)
   {
    s[k]=array[i][h];
    k++;
    }
  }
for(k=0;k<row*col;k++)
{
  printf("%d\n",s[k]);
}
return 0;
}
int main(){
	int row,col;
	cin>>row>>col;
	int a[105][105];
	memset(a,-1,sizeof(a));//???????
	int x=0,y=0,st=1;
	for(int i=0;i<row;i++)//??
		for(int j=0;j<col;j++)
			cin>>a[i][j];
	while(true){
		if(st==1){//?
			cout<<a[x][y]<<endl;
			a[x][y]=-1;
			y++;
			if(a[x][y]==-1){//??
				st=2;
				y--;
				x++;
				if(a[x][y]==-1)//??
					break;
			}
		}
		else if(st==2){//?
			cout<<a[x][y]<<endl;
			a[x][y]=-1;
			x++;
			if(a[x][y]==-1){
				st=3;
				x--;
				y--;
				if(a[x][y]==-1)
					break;
			}
		}
		else if(st==3){//?
			cout<<a[x][y]<<endl;
			a[x][y]=-1;
			y--;
			if(y<0){//??
				y=0;
				st=4;
				x--;
			}
			if(a[x][y]==-1){
				st=4;
				y++;
				x--;
				if(a[x][y]==-1)
					break;
			}
		}
		else if(st==4){//?
			cout<<a[x][y]<<endl;
			a[x][y]=-1;
			x--;
			if(a[x][y]==-1){
				st=1;
				x++;
				y++;
				if(a[x][y]==-1)
					break;
			}
		}
	}

	return 0;
}
void main()
{
	int row,col,i,j,x=0,n;
	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(n=0;;n++)
	{
		for(i=n;i<col-n;i++)
		{
			printf("%d\n",a[n][i]);
			x++;
		}
		for(j=n+1;j<row-n;j++)
		{
			printf("%d\n",a[j][col-n-1]);
			x++;
		}
		if(x==row*col)
			break;
		for(i=col-n-2;i>n-1;i--)
		{
			printf("%d\n",a[row-n-1][i]);
			x++;
		}
		for(j=row-n-2;j>n;j--)
		{
			printf("%d\n",a[j][n]);
			x++;
		}
	}
}
/*????????
 ?????
 ??????
 ???????????????*/


int main()
{
    int hang,lie;
    cin>>hang>>lie;//?????
    int a[100][100];
    int i,j;
    for(i=1;i<=hang;i++)
    {
        for(j=1;j<=lie;j++) cin>>a[i][j]; //????
    }
    int sum=0,quan=1;

    while(sum<hang*lie)
    {
        for(i=quan;i<=lie-quan+1;i++) {cout<<a[quan][i]<<endl; sum++;} if(sum==hang*lie) break; //????????????????????????
        for(i=quan+1;i<=hang-quan+1;i++){cout<<a[i][lie-quan+1]<<endl; sum++;} if(sum==hang*lie) break;
        for(i=lie-quan;i>=quan;i--) {cout<<a[hang-quan+1][i]<<endl; sum++;} if(sum==hang*lie) break;
        for(i=hang-quan;i>=quan+1;i--){cout<<a[i][quan]<<endl; sum++;} if(sum==hang*lie) break;
        quan++;
    }

    return 0;
}
void main()
{
	int i,j,r,c,num=0,a[100][100],k;
	scanf("%d%d",&r,&c);
	for(i=0;i<r;i++)
		for(j=0;j<c;j++)
			scanf("%d",&a[i][j]);
	k=r*c;
	for(i=0;;i++)
	{
		for(j=i;j<=c-1-i;j++)
		{
			printf("%d\n",a[i][j]);
			num=num+1;
			if(num==k)
				break;
		}
		if(num==k)
				break;
		for(j=i+1;j<=r-1-i;j++)
		{
			printf("%d\n",a[j][c-i-1]);
			num=num+1;
			if(num==k)
				break;
		}
		if(num==k)
				break;
		for(j=c-i-2;j>=i;j--)
		{
			printf("%d\n",a[r-1-i][j]);
			num=num+1;
			if(num==k)
				break;
		}
		if(num==k)
				break;
		for(j=r-i-2;j>=(i+1);j--)
		{
			printf("%d\n",a[j][i]);
			num=num+1;
			if(num==k)
				break;
		}
		if(num==k)
				break;
	}
	
}
int main()
{
 int ROW,COL,b[100][100],row,col;
 scanf("%d",&ROW);
 scanf("%d",&COL);
 for(row=0;row<ROW;row++)
 {
  for(col=0;col<COL;col++)
  {
   scanf("%d",&(b[row][col]));
  }
 }
 row=0;
 col=0;
 int i=0,k=0;
 while(i<ROW&&k<COL)
 {
  for(col=k;col<COL-k;col++)
  {
   if(b[row][col]!=0)
   {
    printf("%d\n",b[row][col]);
    b[row][col]=0;
   }
   else
   {
    return 0;
   }
  }
  col--;
  for(row=1+i;row<ROW-i;row++)
  {
   if(b[row][col]!=0)
   {
    printf("%d\n",b[row][col]);
    b[row][col]=0;
   }
   else
   {
    return 0;
   }
  }
  row--;
  for(col=col-1;col>=k;col--)
  {
   if(b[row][col]!=0)
   {
    printf("%d\n",b[row][col]);
    b[row][col]=0;
   }
   else
   {
    return 0;
   }
  }
  col++;
        i++;
  for(row=row-1;row>=i;row--)
  {
   if(b[row][col]!=0)
   {
    printf("%d\n",b[row][col]);
    b[row][col]=0;
   }
   else
   {
    return 0;
   }
  }
  row++;
  k++;
 }
 return 0;
}
int main()
{
	int a[100][100]={0},row,col,i=0,j=0,t=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]);
	}
	i=0;
	j=0;
	do
	{
		for(j=t;j<col-t;j++)
			printf("%d\n",a[i][j]);
   		j-=1;
		if(2*s+1==row) break;
        for(i=s+1;i<row-s;i++)
			printf("%d\n",a[i][j]);
		i-=1;
	    t+=1;
		if(col==t+s) break;
	    for(j=col-t-1;j>=s;j--)
			printf("%d\n",a[i][j]);
		j+=1;
	    s+=1;
		if(row==s+t) break;
	    for(i=row-s-1;i>=t;i--)
			printf("%d\n",a[i][j]);
		i+=1;
		if(col==2*t) break;
	}
	while(t!=col && s!=row);
	return 0;
}
int main()
{
	int row,col,k=1,l=0,i,j;
	scanf("%d %d",&row,&col);
	int sz[100][100];
	for(i=0;i<row;i++){
		for(j=0;j<col;j++){
			scanf("%d",&sz[i][j]);
		}
	}
	if(row==1&&col==1)
		printf("%d",sz[0][0]);
	else{
		for(i=0;i<row*col;)
		{
				for(j=l;j<col-l;j++)
				{
					printf("%d\n",sz[l][j]);	
					i++;if(i==row*col) break;
				}
			if(i==row*col) break;
				for(j=l+1;j<row-1-l;j++)
				{
					printf("%d\n",sz[j][col-1-l]);
					i++;if(i==row*col) break;
				}  if(i==row*col) break;
				for(j=col-1-l;j>=l;j--)
				{
					printf("%d\n",sz[row-1-l][j]);
					i++;if(i==row*col) break;
				}  if(i==row*col) break;
				for(j=row-2-l;j>l;j--)
				{
					printf("%d\n",sz[j][l]);
					i++;if(i==row*col) break;
				}  if(i==row*col) break;
					l++;

		}
	}
	return 0;
}
int main()
{
	int m,n,i,j,k,a,b,c;
	int sz[100][100];
	scanf("%d %d",&m,&n);
	for(i=0;i<m;i++)
	{
		for(j=0;j<n;j++)
		{
			scanf("%d",&sz[i][j]);
		}
	}
	for(i=0,a=0,b=1,j=0,k=0;i<m*n;i++,j+=a,k+=b)
	{
        printf("%d\n",sz[j][k]);
		if(a==0&&b==1&&j+k==n-1)
		{
			a=1;
			b=0;
		}
		else if(a==1&&b==0&&j-k==m-n)
		{
			a=0;
			b=-1;
		}
		else if(a==0&&b==-1&&j+k==m-1)
		{
			a=-1;
			b=0;
		}
		else if(a==-1&&b==0&&j-k==1)
		{
			a=0;
			b=1;
		}
	}
	return 0;
}
int main()
{
	int col,row,n,t,j,m,i,k,l;
	int a[101][101]={0},b[101][101]={0};
	scanf("%d %d",&row,&col);
	for (i=1;i<=row;i++)
		for (j=1;j<=col;j++)
			scanf("%d",&a[i][j]);
	for (i=1;i<=row;i++)
	{
		b[i][0]=1;
		b[i][col+1]=1;
	}
	for (j=1;j<=col;j++)
	{
		b[0][j]=1;
		b[row+1][j]=1;
	}
	m=0;i=1;j=1;
	while (m<col*row)
	{
		printf("%d\n",a[i][j]);
		m=m+1;
		b[i][j]=1;
		if (b[i-1][j]==1)
		{
			if (b[i][j-1]==1)
			{
				if (b[i][j+1]==0)
					j++;
				else
					i++;
			}
			else 
				if (b[i+1][j]==0)
					i++;
				else
					j--;
		}
		else
			if (b[i][j-1]==0)
				j--;
			else
				i--;
	}
return 0;
}
int main()
{
	int row,col;
    scanf("%d %d",&row,&col);
    int sz[100][100];
    int p,q;
    for(p=0;p<row;p++)
	{
		for(q=0;q<col;q++)
		{
			scanf("%d",&sz[p][q]);
		}
	}

	int ROW,COL;
    int row1=0,row2=row-1;
    int col1=0,col2=col-1;
    for(;(row1<=row2)&&(col1<=col2);)
	{
		if((row1<=row2)&&(col1<=col2))
		{
	    	for(COL=col1;COL<=col2;COL++)
			{
			printf("%d\n",sz[row1][COL]);
			}
            row1=row1+1;    
		}
		if((row1<=row2)&&(col1<=col2))
		{
	    	for(ROW=row1;ROW<=row2;ROW++)
			{
			printf("%d\n",sz[ROW][col2]);
			}
		   	col2=col2-1;
		}
		if((row1<=row2)&&(col1<=col2))
		{
            for(COL=col2;COL>=col1;COL--)
			{
			printf("%d\n",sz[row2][COL]);
			}
		    row2=row2-1;
		}
		if((row1<=row2)&&(col1<=col2))
		{
            for(ROW=row2;ROW>=row1;ROW--)
			{
			printf("%d\n",sz[ROW][col1]);
			}
		    col1=col1+1;
		}
	}
    return 0;
}
int main(){
int row,col;
int a[110][110];
int i,j;
int r,l,u,d,cntr,cntc,g;

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

r=0;
u=0;
l=row-1;
d=col-1;
cntr=0;
cntc=0;
i=0;
j=0;
g=0;

for(g=0;(g<=row/2+1)&&(g<=col/2+1);g++){
   while ((cntr!=row)&&(cntc!=col)&&(cntr%2==0)&&(cntr-cntc==0)){
   printf("%d\n",a[i][j]);
   if (j==d){
   r++;
           cntr++;
   i++;
}
else if(j!=d){
    j++;
}

   }
  
   while((cntr!=row)&&(cntc!=col)&&(cntc%2==0)){
       printf("%d\n",a[i][j]);
   if (i==l){
    d--;
            cntc++;
j--;
}
    else{
i++;
}
}
while((cntr!=row)&&(cntc!=col)&&(cntr%2!=0)){
printf("%d\n",a[i][j]);
if (j==u){
u++;
cntr++;
i--;
}
else{ 
j--;
}

}
while((cntr!=row)&&(cntc!=col)&&(cntc%2!=0)){
printf("%d\n",a[i][j]);
if (i==r){
l--;
cntc++;
j++;
}
else{ 
i--;
} 
}
}

return 0;
}
void main()
{
	int a[100][100];
	int rowm,coln,i,j,row,col;
	rowm=1;
	coln=0;
	scanf("%d %d",&row,&col);
	for(i=1;i<=row;i++)
		for(j=1;j<=col;j++)
			scanf("%d",&a[i][j]);
		i=1;j=0;
	while(1){	
		if(coln>=col) break;
		for(i=rowm,j++;j<=col;j++) 
			printf("%d\n",a[i][j]);
		coln++;
		if(rowm>=row) break;
		for(j=col,i++;i<=row;i++)
			printf("%d\n",a[i][j]);
		rowm++;
		if(coln>=col) break;
		for(i=row,j--;j>=coln;j--)
			printf("%d\n",a[i][j]);
		col--;
		if(rowm>=row) break;
		for(j=coln,i--;i>=rowm;i--)
			printf("%d\n",a[i][j]);
		row--;		
	}
}
int main()
{
	int row,col,i,j,k,l,m;
	int a[100][100];
	int b[10000];
	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 ; i++ )
	{
		for( j=i ; j<col-i ; j++ )
		{
			cout<<a[i][j]<<endl;
			if( j==col-i-1 )
			{
				for( k=i+1 ; k<row-i ; k++ )
				{
					cout<<a[k][j]<<endl;
					if( k==row-i-1 )
					{
						for( l=col-i-2 ; l>=i ; l-- )
						{
							cout<<a[k][l]<<endl;
							if( l==i )
							{
								for( m=row-i-2 ; m>i ; m-- )
								{
									cout<<a[m][l]<<endl;
								}
							}
						}
					}
				}
			}
		}
	}
}
void main()
   {int a,s,k,i,j,x[100][100],row,col;
    scanf("%d", &row);
	scanf("%d", &col);
	a=0;
	for (i=1;i<=row;i++)
	{for (j=1;j<=col;j++)
	scanf("%d", &x[i][j]);}
     for (k=1;k<=(row+1)/2&&k<=(col+1)/2;k++)
	 {if (k<=row/2&&k<=col/2) s=0;
	  else s=1;
	  for (i=k;i<=col-k+1;i++,a++)
	  {printf("%d\n", x[k][i]);
	  }if (a>=col*row)  break;
	  for (j=k+1;j<=row-k;j++,a++)
	  {printf("%d\n", x[j][col-k+1]);
	  }if (a>=col*row)  break;
	  for (i=col-k+1;i>=k;i--,a++)
	  {printf("%d\n", x[row-k+1][i]);
	  }if (a>=col*row)  break;
	  for (j=row-k;j>k;j--,a++)
	  {printf("%d\n", x[j][k]);
	  
	 }if (a>=col*row)  break;
	 }
     

   }
int main()
{
    int m,n;
    scanf("%d%d",&m,&n);
    int sz[m+2][n+2];
    for(int i=0;i<m+2;i++)
    {
        for(int k=0;k<n+2;k++)
        {
            sz[i][k]=0;
        }
    }
    for(int i=1;i<m+1;i++)
    {
        for(int k=1;k<n+1;k++)
        {
            scanf("%d",&sz[i][k]);
        }
    }
    int i=1,j=1;
    while(i<m+1&&j<n+1)
    {
        printf("%d\n",sz[i][j]);
        sz[i][j]=0;
        if(sz[i][j+1]!=0&&sz[i][j-1]==0&&sz[i-1][j]==0)
        {
            j++;
        }
        else if(sz[i+1][j]!=0&&sz[i][j+1]==0&&sz[i-1][j]==0)
        {
            i++;
        }
        else if(sz[i+1][j]==0&&sz[i][j-1]!=0&&sz[i][j+1]==0)
        {
            j--;
        }
        else if(sz[i][j-1]==0&&sz[i+1][j]==0&&sz[i-1][j]!=0)
        {
            i--;
        }   
        else if(sz[i][j-1]==0&&sz[i+1][j]==0&&sz[i-1][j]==0&&sz[i][j+1]==0)
        {
            break;
        }
    }
    return 0;
}
int main()
{
	int a[100][100] = { 0 } , b[10000] = { 0 } ;
	int r , l ;
	int i , j = 0 , k = 0 ;
	cin >> r >> l ;
    int n = 0 , s = r - 1 , e = l - 1 , w = 0 ;
	for ( i = 0 ; i < r ; i++ )
		for ( j = 0 ; j < l ; j++ )
			cin >> a[i][j] ;
    i = 0 ;
	while ( i <=  r * l )
	{
		k = n ; j = w ;
		for ( j = w ; j <= e ; j++ )
		{
			cout << a[k][j] << endl ;
			i++ ;
			if ( i == r * l )
				break ;
		}// j = e + 1
		if ( i == r * l )
			break ;
		j-- ;
		for ( k = n + 1 ; k <= s - 1 ; k++ )
		{
			cout << a[k][j] << endl ;
			i++ ;
			if ( i == r * l )
			break ;
		}// j=e , k = s - 1 ;
		if ( i == r * l )
			break ;
		for ( j = e ; j >= w ; j-- )
		{
			cout << a[k][j] << endl ;
			i++ ;
			if ( i == r * l )
			break ;
		} // j = w - 1
		if ( i == r * l )
			break ;
		j++ ;
		for ( k = s - 1 ; k >= n + 1 ; k-- )
		{
			cout << a[k][j] << endl ;
			i++ ;
			if ( i == r * l )
			break ;
		}
		// k = n
		if ( i == r * l )
			break ;
		n++ ; s-- ; e-- ; w++ ;
	}
	return 0 ;
}