semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main()
{
	const int max = 100;
	int row, col, i, j;
	cin >> row;
	cin >> col;
	int num[max + 2][max + 2];
	for(i = 0; i < max + 2; i++)
	{
		for(j = 0; j < max + 2; j++)
		{
			num[i][j] = -1;
		}
	}
	for(i = 1; i <= row; i++)
	{
		for(j = 1; j <= col; j++)
		{
			cin >> num[i][j];
		}
	}
	int flag = 0;
	int maxnum = row * col;
	int count = 0;
	i = 1;
	j = 1;
	while(1)
	{
		if(flag == 0)
		{			
			while(num[i][j] != -1)
			{
				cout << num[i][j] << endl;
				num[i][j] = -1;
				count++;
				j++;
			}
			j--;
			i++;
			flag = 1;
		}
		else
		{
			if(flag == 1)
			{
				while(num[i][j] != -1)
				{
					cout << num[i][j] << endl;
					num[i][j] = -1;
					count++;
					i++;
				}
				i--;
				j--;
			    flag = 2;
			}
			else {
				if(flag == 2)
				{
					while(num[i][j] != -1)
					{
						cout << num[i][j] << endl;
						num[i][j] = -1;
						count++;
						j--;
					}
					j++;
					i--;
					flag = 3;
				}
				else
				{
					while(num[i][j] != -1)
					{
						cout << num[i][j] << endl;
						num[i][j] = -1;
						count++;
						i--;
					}
					i++;
					j++;
					flag = 0;
				}
			}
		}
		if(count == maxnum) break;
	}
	return 0;
}
int main()
{
	int row, col, n = 0;
	int i, j;
	int a[100 + 10][100 + 10] = {0};
	cin >> row >> col;
	for (i = 0; i < row; i ++)
		for (j = 0; j < col; j ++)
		cin >> a[i][j];
	i = 0; j = 0;
	int buttom = row, right = col, left = 0, top = 0;
	for (;;)
	{
		while(j <= right - 1) 
		{n ++; cout << a[i][j ++] << endl;}
		if (n == col * row) break;
		j --; i ++; top ++;
		while(i <= buttom - 1) 
		{n ++; cout << a[i ++][j] << endl;}
		if (n == col * row) break;
		i --; j --; right --;
		while(j >= left) 
		{n ++; cout << a[i][j --] << endl;}
		if (n == col * row) break;
		j ++; i --; buttom --;
		while(i >= top) 
		{n ++; cout << a[i --][j] << endl;}
		if (n == col * row) break;
		i ++; j ++; left ++;
	}
	return 0;
}
int main(){
	int i,j,t,row,col;
	int a[100][100];
	
	scanf("%d%d",&row,&col);
	if(row>=col){
		t=col/2;
	}
	else{
		t=row/2;
	}
	for(i=0;i<row;i++){
		for(j=0;j<col;j++){
			scanf("%d",&a[i][j]);
		}
		
	}
	int rmax=row-1,rmin=0,cmax=col-1,cmin=0;


//	printf("%d",t);

	for(i=0;i<t;i++){
		for(j=cmin;j<cmax;j++){
			printf("%d\n",a[rmin][j]);
		}
		for(j=rmin;j<rmax;j++){
			printf("%d\n",a[j][cmax]);
		}
		for(j=cmax;j>cmin;j--){
			printf("%d\n",a[rmax][j]);
		}
		for(j=rmax;j>rmin;j--){
			printf("%d\n",a[j][cmin]);
		}
		rmax-=1;
		rmin+=1;
		cmax-=1;
		cmin+=1;
	}

	if(col%2!=0&&row>=col){
		for(i=t;i<row-t;i++){
			printf("%d\n",a[i][col/2]);
		}
	}
	else if(row%2!=0&&row<=col){
		for(i=t;i<col-t;i++){
			printf("%d\n",a[row/2][i]);
		}
	}

	return 0;
}
int main()
{
	int a,b;
	cin>>a>>b;
	int n[a][b];
	int s=0,e=b-1,p=0,q=a-1;
	for(int i=0;i<a;i++)
		for(int j=0;j<b;j++)
			cin>>n[i][j];
	
	if(s==e)
				for(int i=p;i<=q;i++)
					cout<<n[i][0]<<endl;
			else if(p==q) for(int i=s;i<=e;i++)
				cout<<n[0][i]<<endl;

	
	while(s<e&&p<q)
	{
		for(int i=s;i<e;i++){
			cout<<n[p][i]<<endl;

		}

		for(int i=p;i<q;i++)
					{cout<<n[i][e]<<endl;}
		for(int i=e;i>s;i--)
					{cout<<n[q][i]<<endl;}
		for(int i=q;i>p;i--)
					{cout<<n[i][s]<<endl;}
		s++;
		e--;
		p++;
		q--;
	if(s==e){for(int i=p;i<=q;i++)
		{cout<<n[i][s]<<endl;}
	break;
	}
	if(p==q){for(int i=s;i<=e;i++)

		{cout<<n[p][i]<<endl;}
	break;
	}

	}
	
	
	return 0;

}
int main()
{
	int n,m,i,j,r,k;
	int 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]);
		printf("\n");
		for(r=0,k=0;;r++)
		{
			for(i=r,j=r;j<=n-r-1;j++)
			{
				k++;
				printf("%d\n",a[i][j]);
			}
			if(k==m*n)break;
			for(i=r+1,j=n-1-r;i<=m-1-r;i++)
			{
				k++;
				printf("%d\n",a[i][j]);
			}
			if(k==m*n)break;
			for(i=m-1-r,j=n-r-2;j>=r;j--)
			{
				k++;
				printf("%d\n",a[i][j]);
			}
			if(k==m*n)break;
			for(i=m-2-r,j=r;i>=r+1;i--)
			{
				k++;
				printf("%d\n",a[i][j]);
			}
			if(k==m*n)break;
		}
	return 0;
}
int main(){
    int h, l;
    scanf("%d %d",&h, &l);
    int sz[h][l];
    for(int i=0;i<h;i++){
        for(int j=0;j<l;j++){
            scanf("%d",&sz[i][j]);
        }
    }
    int qs_h=0, qs_l=0;
    int zz_h=h-1, zz_l=l-1;
    while(qs_h<=zz_h&&qs_l<=zz_l){
        if(qs_h!=zz_h&&qs_l!=zz_l){
            for(int i=qs_l;i<=zz_l;i++){
                printf("%d\n",sz[qs_h][i]);
            }
            for(int i=qs_h+1;i<=zz_h;i++){
                printf("%d\n",sz[i][zz_l]);
            }
            for(int i=zz_l-1;i>=qs_l;i--){
                printf("%d\n",sz[zz_h][i]);
            }
            for(int i=zz_h-1;i>=qs_h+1;i--){
                printf("%d\n",sz[i][qs_l]);
            }
        }//???????
        if(qs_h==zz_h&&qs_l!=zz_l){
            if(h%2==1){
                for(int i=qs_l;i<=zz_l;i++){
                    printf("%d\n",sz[qs_h][i]);
                }
            }//???
            if(h%2==0){
                for(int i=zz_l;i>=qs_l;i--){
                    printf("%d\n",sz[qs_h][i]);
                }
            }//???
        }//????
        if(qs_h!=zz_h&&qs_l==zz_l){
            for(int i=qs_h;i<=zz_h;i++){
                printf("%d\n",sz[i][qs_l]);
            }
        }//????
        if(qs_h==zz_h&&qs_l==zz_l){
            printf("%d\n",sz[qs_h][zz_h]);
        }//????
        qs_h++;
        qs_l++;
        zz_l--;
        zz_h--;
    }
    return 0;
}
int main()
{
	int x,y,k,sum;
	int a[100][100];
	int i,j;
	int count;
	scanf("%d %d",&x,&y);
	count=0;
	for(i=0;i<x;i++)
	{
		for(j=0;j<y;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	sum=x*y;
	i=0;
	j=0;
	k=0;
	while(count<sum)
	{
		for(j=0+k;j<y;j++)
		{
			printf("%d\n",a[i][j]);
		}
			count+=y-k;
		if(count==sum)
			break;
		for(i=1+k;i<x;i++)
		{
			printf("%d\n",a[i][j-1]);
		}
			count+=x-1-k;
		if(count==sum)
			break;
		y--;
		for(j=y-1;j>=k;j--)
		{
			printf("%d\n",a[i-1][j]);
		}
			count+=y-k;
		if(count==sum)
			break;
		x--;
		for(i=x-1;i>k;i--)
		{
			printf("%d\n",a[i][j+1]);
		}
			count+=x-1-k;
		k++;
		i=k;
	}
	}
void main()
{
	int a[100][100],i,j,t,row,col;
	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<col;i++)
	{
		for(j=i;j<=col-1;j++)
			{t=a[i][j];
				printf("%d\n",a[i][j]);
			}
		for(j=i+1;j<=row-1;j++)
			{t=a[j][col-1];
				printf("%d\n",a[j][col-1]);
			}
		if(i>=row-1)
			break;
		if(i>=col-1)
			break;
		for(j=col-2;j>=i;j--)
			{t=a[row-1][j];
				printf("%d\n",a[row-1][j]);
			}
	
		
		for(j=row-2;j>i;j--)
			{t=a[j][i];
				printf("%d\n",a[j][i]);
			}
		row--;
		col--;
	}
}
int main(){
	int row,col,i,k,j,m,n;
	scanf("%d%d",&row,&col);
	'\n';
	int sz[100][100],a[10000];
	for(i=0;i<row;i++){
		for(k=0;k<col;k++){
			scanf("%d",&sz[i][k]);
		}
		'\n';
	}
	j=0;
	for(i=0;i<col-1;i=i+2){
		m=i/2;
		for(k=m;k<col-m-1;k++){
			a[j]=sz[m][k];
			j++;
		}
		for(k=m;k<row-m-1;k++){
			a[j]=sz[k][col-m-1];
			j++;
		}
		for(k=col-m-1;k>m;k--){
			a[j]=sz[row-m-1][k];
			j++;
		}
		for(k=row-m-1;k>m;k--){
			a[j]=sz[k][m];
			j++;
		}
	}
	if(col%2==1){
		m=i/2;
		for(k=m;k<row-m;k++){
			a[j]=sz[k][(col-1)/2];
			j++;
		}
	}
	for(i=0;i<row*col-1;i++){
		printf("%d\n",a[i]);
	}
	printf("%d",a[row*col-1]);
	return 0;
}
int main()
{
	int l,m,n,k,i,j,sum,p,q;
	int s[150][150]={0};
	int a[150][150]={0};
	scanf("%d %d",&m,&n);
	for (i=0;i<m;i++)
	 for (j=0;j<n;j++) 
     {
         scanf("%d",&a[i][j]);
         s[i][j]=1;
         }
	 sum=m*n;i=0;j=0;p=0;q=1;
	 while (sum>0)
	 {
           k=0;
           while (s[i][j]==1)
           {
                 printf("%d\n",a[i][j]);
                 s[i][j]=0;sum--;
                 i+=p;
                 j+=q;
                 }
         if ((p==0)&&(q==1)&&(k==0)) 
         {
                           p=1;
                           q=0;
                           i=i+1;
                           j=j-1;
                           k=1;
                           }
                           
         if ((p==1)&&(q==0)&&(k==0))
         {
              p=0;
              q=-1;
              i=i-1;
              j=j-1;k=1;
              }
         if ((p==0)&&(q==-1)&&(k==0))
         {
                           p=-1;
                           q=0;
                           j=j+1;
                           i=i-1;k=1;
                           }
         if ((p==-1)&&(q==0)&&(k==0))
         {
                           p=0;
                           q=1;
                           j=j+1;
                           i=i+1;
                           k=1;
                           }
                           }

return 0;
}
int main()
{
	int s[100][100]={0},re[100][100]={0},h=0,l=0,dh=0,dl=0,i=0,j=0,k=0,x[4]={0,1,0,-1},y[4]={1,0,-1,0};//hê&#199;DDêy lê&#199;áDêy ij&#182;&#188;ê&#199;&#209;-&#187;·&#191;&#216;&#214;&#198;±&#228;á&#191;   sê&#199;?&#230;·&#197;&#213;aD&#169;êy×&#214;?&#196;êy×é  reê&#199;&#188;&#199;&#194;&#188;&#213;aD&#169;êy×&#214;óD&#195;&#187;óD±&#187;×&#223;?&#189;?&#196;êy×é x[4]ê&#199;?&#227;ò&#198;&#182;??&#196;ê±oòDDêy?&#196;±&#228;&#187;??&#196;&#207;òá&#191;y[4]ê&#199;?&#227;ò&#198;&#182;??&#196;ê±oòáDêy±&#228;&#187;??&#196;&#207;òá&#191; 
	  cin>>h>>l;
	  for(i=1;i<=h;i++)
	     for(j=1;j<=l;j++)
	         {cin>>s[i][j];re[i][j]=1;}
	  dh=1;
	  dl=1;
	  k=0;
	  cout<<s[1][1]<<endl;
	  re[1][1]=0;
	  for(i=1;i<=h*l-1;i++)//&#191;aê&#188;±éàú
	    {
		    if(re[dh+x[k]][dl+y[k]]==1)
		    {
			    re[dh+x[k]][dl+y[k]]=0;
				dh+=x[k];
				dl+=y[k];
				cout<<s[dh][dl]<<endl;	
				continue;
			}
			if(re[dh+x[k]][dl+y[k]]==0)
			{
			   k=(k+1)%4;//&#187;&#187;·&#189;&#207;ò
			    re[dh+x[k]][dl+y[k]]=0;
				dh+=x[k];
				dl+=y[k];
				cout<<s[dh][dl]<<endl;	
				continue;  
			}
		} 
	  return 0;
}
int judge(int a[101][101],int m,int n,int i,int j){
	if(i==0&&j<n-1) return 2;
	if(j==n-1&&i<m-1) return 3;
	if(i==m-1&&j>0) return 4;
	if(j==0&&i>1) return 1;
	if(a[i-1][j]!=-1&&a[i][j-1]==-1) return 1;
	if(a[i][j+1]!=-1) return 2;
	if(a[i+1][j]!=-1) return 3;
	if(a[i][j-1]!=-1) return 4;
	return 0;
}
void main(){
	int m,n,i,j,a[101][101];
	int judge(int a[101][101],int n,int m,int i,int j);
	scanf("%d%d",&m,&n);
	for(i=0;i<m;i++)
		for(j=0;j<n;j++) scanf("%d",&a[i][j]);
	i=j=0;
	if(m==1&&n==1) printf("%d\n",a[0][0]);
	else{
	while(judge(a,m,n,i,j)!=0){
		if(a[i][j]>0) printf("%d\n",a[i][j]);
		else break;
		a[i][j]=-1;
		switch (judge(a,m,n,i,j)){
		case 1:i--;break;
		case 2:j++;break;
		case 3:i++;break;
		case 4:j--;break;
			}
		};
	if(a[i][j]>0) printf("%d\n",a[i][j]);
	}
}
//#define s 100
int main(){
	int row ,col;
	int ew[100][100];
	int a,b,p,q;
	int i,j;
	int e,f;
	int m,n;
	int min=0;
	scanf("%d%d",&row,&col);
	e=row/2;
	f=col/2;
	for(i=0;i<=row-1;i++)
	{
		for(j=0;j<=col-1;j++)
		{
			scanf("%d",&ew[i][j]);
		}
	}
	if(row%2==0&&col%2==0)
	{
		if(e>f)
		{
			min=f;
		}
		if(e<=f)
		{
			min=e;
		}
	}
	if(row%2==1&&col%2==1){
		if(e+1>f+1)
		{
			min=f+1;
		}
		if(e+1<=f+1)
		{
			min=e+1;
		}
	}
	
	
	if(row%2==1&&col%2==0)
	{
		if(e+1>f)
		{
			min=f;
		}
		if(e+1<=f)
		{
			min=e+1;
		}
	}
	if(row%2==0&&col%2==1)
	{
		if(e>f+1)
		{
			min=f+1;
		}
		if(e<=f+1)
		{
			min=e;
		}
	}
	if((row%2==0&&col%2==0)||((row%2==1&&col%2==0)&&(e+1>f))||((row%2==0&&col%2==1)&&(f+1>e)))
	{	
		
		
		
		for(i=0;i<=min-1;i++)
		{
			for(a=i;a<=col-i-2;a++)
			{
				printf("%d\n",ew[i][a]);
			}
			for(b=i;b<=row-i-2;b++)
			{
				printf("%d\n",ew[b][col-1-i]);
			}
			for(p=col-i-1;p>=i+1;p--)
			{
				printf("%d\n",ew[row-i-1][p]);
			}for(q=row-1-i;q>=i+1;q--)
			{
				printf("%d\n",ew[q][i]);
			}
			
		}
	}
	
	if( ((col%2==1)&&(row%2==0)&&(f+1<=e)) || ((col%2==1)&&(row%2==1)&&(f+1<=e+1)))
	{
		
		
		for(i=0;i<=min-2;i++)
		{
			for(a=i;a<=col-i-2;a++)
			{
				printf("%d\n",ew[i][a]);
			}
			for(b=i;b<=row-i-2;b++)
			{
				printf("%d\n",ew[b][col-1-i]);
			}
			for(p=col-i-1;p>=i+1;p--)
			{
				printf("%d\n",ew[row-i-1][p]);
			}for(q=row-1-i;q>=i+1;q--)
			{
				printf("%d\n",ew[q][i]);
			}
			
		}
		
		
		for(m=min-1;m<=row-min;m++)
		{
			printf("%d\n",ew[m][f]);
		}
	}
	
	if(   ((row%2==1)&&(col%2==0)&&(e+1<=f))   ||    (  (row%2==1)     &&  (col%2==1) && (e+1<f+1) )    )
	{
		for(i=0;i<=min-2;i++)
		{
			for(a=i;a<=col-i-2;a++)
			{
				printf("%d\n",ew[i][a]);
			}
			for(b=i;b<=row-i-2;b++)
			{
				printf("%d\n",ew[b][col-1-i]);
			}
			for(p=col-i-1;p>=i+1;p--)
			{
				printf("%d\n",ew[row-i-1][p]);
			}for(q=row-1-i;q>=i+1;q--)
			{
				printf("%d\n",ew[q][i]);
			}
			
		}
		for(n=min-1;n<=col-min;n++)
		{
			printf("%d\n",ew[e][n]);
		}
	}
				
				
				
				return 0;
				}
int main(int argc, char* argv[])
{
	int a[100][100],b[10000],c[4];
	int m,n,e,i,j,t,k,l,p;
	scanf ("%d%d\n",&m,&n);
	for(i=0;i<m;i++)
		for(j=0;j<n;j++)
			scanf ("%d",&a[i][j]);
	for(i=0;i<m;i++)
		for(j=0;j<n;j++)
		{	
			c[0]=i;
		        c[1]=j;
		        c[2]=m-i-1;
		        c[3]=n-j-1;
                t=c[0];			
		for (k=0;k<4;k++)
			if (c[k]<t)
				t=c[k];
			if (i==t)
				p=j-t+1;
			else if (j==n-t-1)
				p=n-t-1-t+i-t+1;
			else if (i==m-t-1)
				p=n-t-1-t+m-t-1-t+n-t-1-j+1;
			else if (j==t)
				p=n-t-1-t+m-t-1-t+n-t-1-t+m-t-1-i+1;
		for (l=0,e=0;l<t;l++)	
			e=e+2*(m-2*l-1)+2*(n-2*l-1);
		if (t==0)
			e=0;
	   	    b[e+p-1]=a[c[0]][c[1]];
		}
		for (i=0;i<m*n;i++)
		printf ("%d\n",b[i]);
	return 0;
}
int main()
{
	int i,j,row,col,row0=0,col0=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]);
	while(row0>=0)
	{
		if(row0+1==row)
		{
			for(i=col0;i<col;i++)
				printf("%d\n",a[row0][i]);
		    break;
		}
		if(col0+1==col)
		{
			for(i=row0;i<row;i++)
				printf("%d\n",a[i][col0]);
			break;
		}
        if(row0+1==row&&col0+1==col)
		{
			printf("%d\n",a[row0][col0]);
			break;
		}
		for(i=col0;i<col;i++)
			printf("%d\n",a[row0][i]);
		for(i=row0+1;i<row;i++)
			printf("%d\n",a[i][col-1]);
		for(i=col-2;i>=col0;i--)
			printf("%d\n",a[row-1][i]);
		for(i=row-2;i>=row0+1;i--)
			printf("%d\n",a[i][col0]);
		row0++;
		col0++;
		row--;
		col--;
		if(row0>row-1||col0>col-1)
			break;
		
	}
	return 0;
}
int main()
{
	int row, col, num[100][100], count;
	int r, l;
	int i, j, k;
	cin >> row >> col;
	count = row * col;
	for (i = 1; i <= row; i++)   // i???
	{
		for (j = 1; j <= col; j++)  // j???
		{
			cin >> num[i][j];
		}
	} // end for
	int r1, r2, l1, l2;
	r1 = 1;
	r2 = row;
	l1 = 1; 
	l2 = col;
	while ((r1 <= r2) && (l1 <= l2))
	{
		int flag = 0;
		for (l = l1; l <= l2; l++)
		{
			cout << num[r1][l];
			count--;   // count?????????
			if (count != 0)
			{
				cout << endl;
			}
			else
			{
				flag = 1;
			}
		}
		if (flag)
		{
			break;
		}
		for (r = r1 + 1; r <= r2; r++)
		{
			cout << num[r][l2];
			count--;
			if (count != 0)
			{
				cout << endl;
			}
			else
			{
				flag = 1;
			}
		}
		if (flag)
		{
			break;
		}
		for (l = l2 - 1; l >= l1; l--)
		{
			cout << num[r2][l];
                                                                 			count--;
			if (count != 0)
			{
				cout << endl;
			}
			else
			{
				flag = 1;
			}
		}
		if (flag)
		{
			break;
		}
		for (r = r2 - 1; r > r1; r--) 
		{
			cout << num[r][l1];
			count--;
			if (count != 0)
			{
				cout << endl;
			}
			else 
			{
				flag = 1;
			}
		}
		if (flag)
		{
			break;
		}
		else 
		{
			r1++;
			r2--;
			l1++;
			l2--;
		}
	}  // end while
	return 0;
}
int main()
{
	int row,col,m,n,p,q,i,j;
	int a[100][100];
	scanf("%d %d",&row,&col);
	for(i=0;i<=row-1;i++)
		for(j=0;j<=col-1;j++)
			scanf("%d",&a[i][j]);
	m=0;
	p=0;
	n=row-1;
	q=col-1;

	while((n-m>1)&&(q-p)>1)
	{
		for(i=p;i<=q;i++)
			printf("%d\n",a[m][i]);
		for(i=m+1;i<=n;i++)
			printf("%d\n",a[i][q]);
		for(i=q-1;i>=p;i--)
			printf("%d\n",a[n][i]);
		for(i=n-1;i>=m+1;i--)
			printf("%d\n",a[i][p]);
		m++;
		p++;
		n--;
		q--;
	}
	if(n==m)
	{
		for(i=p;i<=q;i++)
			printf("%d\n",a[m][i]);
	}
	else if(n==m+1)
	{
		for(i=p;i<=q;i++)
			printf("%d\n",a[m][i]);
		for(i=q;i>=p;i--)
			printf("%d\n",a[n][i]);
	}
	else if(p==q)
	{
		for(i=m;i<=n;i++)
			printf("%d\n",a[i][p]);
	}
	else if(q==p+1)
	{
	    for(i=p;i<=q;i++)
			printf("%d\n",a[m][i]);
		for(i=m+1;i<=n;i++)
			printf("%d\n",a[i][q]);
		for(i=q-1;i>=p;i--)
			printf("%d\n",a[n][i]);
		for(i=n-1;i>=m+1;i--)
			printf("%d\n",a[i][p]);
	}
		return 0;
}
/*????
????????????????row?col?
???row??????col???????????????
??????row?col??0<row<100, 0<col<100?
????
????????????????????
????
4 4
 1  2  3 4
12 13 14 5
11 16 15 6
10  9  8 7
*/
int main(){
	int n,m,sum=0;
	int str[100][100];
	cin>>n>>m;
	for(int i=0;i<n;i++)
	for(int j=0;j<m;j++)
		cin>>str[i][j];
	for(int k=0;k<(n+1)/2;k++){
	for(int k1=k;k1<m-k;k1++){
		cout<<str[k][k1]<<endl;
		sum++;
		if(sum==n*m)
			return 0;}
	for(int k2=k+1;k2<n-k;k2++){
		cout<<str[k2][m-k-1]<<endl;
	          sum++;
			if(sum==n*m)
				return 0;}
	for(int k3=m-k-2;k3>=k;k3--){
		cout<<str[n-k-1][k3]<<endl;
		          sum++;
				if(sum==n*m)
					return 0;}
	for(int k4=n-k-2;k4>k;k4--){
		cout<<str[k4][k]<<endl;
		          sum++;
				if(sum==n*m)
					return 0;}
	}
	return 0;
}
int main()
{
    int a[110][110],row,col,i,j=0,k=0,geshu=0,zong;
    scanf("%d %d",&row,&col);
    zong=row*col;
    for(i=0;i<row;i++)
    {
                      for(j=0;j<col;j++)
                      {
                                        scanf("%d",&a[i][j]);
                      }
    }
    j=0;i=0;
    while(col>=1&&row>=1)
    {
                         if(geshu==zong) break;
                         for(j=k;j<col;j++)
                         {
                                           printf("%d\n",a[k][j]);
                                           geshu+=1;
                         }
                         if(geshu==zong) break;
                         for(i=k+1;i<=(row-1);i++)
                         {
                                           printf("%d\n",a[i][col-1]);
                                           geshu+=1;
                         }
                         if(geshu==zong) break;
                         for(j=col-2;j>=k;j--)
                         {
                                                printf("%d\n",a[row-1][j]);
                                                geshu+=1;
                         }
                         if(geshu==zong) break;
                         for(i=row-2;i>=(k+1);i--)
                         {
                                                 printf("%d\n",a[i][k]);
                                                 geshu+=1;
                         }
                         row-=1;
                         col-=1;
                         k+=1;
                         
    }
    return 0;
}
void Matrix(int a[100][100],int srow,int scol,int erow,int ecol)
{
	int i,j;
	for(i=scol;i<=ecol;i++)
		printf("%d\n",a[srow][i]);
	for(i=srow+1;i<=erow;i++)
		printf("%d\n",a[i][ecol]);
	if(erow>srow)
		for(i=ecol-1;i>=scol;i--)
			printf("%d\n",a[erow][i]);
	if(ecol>scol)
		for(i=erow-1;i>=srow+1;i--)
			printf("%d\n",a[i][scol]);
	if(erow-srow>=2&&ecol-scol>=2)
		Matrix(a,srow+1,scol+1,erow-1,ecol-1);
}
main()
{
	int a[100][100],i,j,m,n;
	scanf("%d %d",&m,&n);
	for(i=0;i<m;i++)
		for(j=0;j<n;j++)
			scanf("%d",&a[i][j]);
	Matrix(a,0,0,m-1,n-1);
}
int main()
{
 int row,col;
 int i,j,n,time=0;
 scanf("%d%d",&row,&col);
 int array[100][100];
 for(i=0;i<row;i++)
  for(j=0;j<col;j++)
   scanf("%d",&array[i][j]);
  for (n=0;;n++)
  { 
   for (i=n;i<col-n;i++)
   {
    printf("%d\n",array[n][i]);
    time++; 
	if(time!=0)
	{
		printf("\n");
	}
   }
   if(time==row*col)break;

   for (j=n+1;j<row-n;j++)
   {
    printf("%d\n",array[j][col-n-1]);
    time++;
		if(time!=row*col)
	{
		printf("\n");
	}
   }
   if(time==row*col)break;
   for (i=col-2-n;i>=n;i--)
   {
    printf("%d\n",array[row-n-1][i]);
    time++;
		if(time!=row*col)
	{
		printf("\n");
	}
   }
   if(time==row*col)break;
   for (j=row-2-n;j>n;j--)
   {
    printf("%d\n",array[j][n]);
    time++;
		if(time!=row*col)
	{
		printf("\n");
	}
   }
   if(time==row*col)break;
  }
  return 0;
}
int main()
{
	int m,n,i,j,A,B,C,D;
	int 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]);
		}
	}
	A=n-1;
	B=m-1;
	C=0;
	D=1;
	int sum,k=0;
	sum=m*n;
	i=0;
	j=0;
	if(m==1&&n==1)
	{
		printf("%d",a[0][0]);
	}
	else
	{
		if(m==1&&n!=1)
		{
			for(i=0;i<n-1;i++)
			{
				printf("%d\n",a[0][i]);
			}
			printf("%d",a[0][i]);
		}
		else 
		{
			if(n==1&&m!=1)
			{
				for(i=0;i<m-1;i++)
				{
					printf("%d\n",a[i][0]);
				}
				printf("%d",a[i][0]);
			}
			else
			{
				while(k<sum)
				{
					for(j=C;j<=A;j++)
					{
						if(k!=sum-1)
						{
							printf("%d\n",a[i][j]);
							k++;
						}
						else
						{
							printf("%d",a[i][j]);
							goto end;
						}
					}
					j--;
					A--;
					for(i=D;i<=B;i++)
					{
						if(k!=sum-1)
						{
							printf("%d\n",a[i][j]);
							k++;
						}
						else
						{
							printf("%d",a[i][j]);
							goto end;
						}
					}
					i--;
					B--;
					for(j=A;j>=C;j--)
					{
						if(k!=sum-1)
						{
							printf("%d\n",a[i][j]);
							k++;
						}
						else
						{
							printf("%d",a[i][j]);
							goto end;
						}
					}
					j++;
					C++;
					for(i=B;i>=D;i--)
					{
						if(k!=sum-1)
						{
							printf("%d\n",a[i][j]);
							k++;
						}
						else
						{
							printf("%d",a[i][j]);
							goto end;
						}
					}
					i++;
					D++;
				}
			}
		}
	}
end:	return 0;
}
int main()
{
	int a[100][100];
	int h,s,i,j,m,z=0;
	scanf("%d%d",&h,&s);
	m=h*s;
	for(i=0;i<h;i++)
	{
		for(j=0;j<s;j++)
			scanf("%d",&a[i][j]);
	}
	for(i=0;;i++)
	{
		for(j=i;j<s-i;j++)
		{
			printf("%d\n",a[i][j]);
			z++;
		}
		if(z==m)break;
		for(j=i+1;j<h-i;j++)
		{
			printf("%d\n",a[j][s-1-i]);
			z++;
		}
		if(z==m)break;
		for(j=s-i-2;j>=i;j--)
		{
            printf("%d\n",a[h-i-1][j]);
			z++;
		}
		if(z==m)break;
		for(j=h-i-2;j>i;j--)
		{
			printf("%d\n",a[j][i]);
			z++;
		}
		if(z==m)break;
	}
}
int main()
{
 int row,col;
 int i,j,n;
 int t=0;
 int array[100][100];
 scanf("%d %d",&row,&col);
 for(i=0;i<row;i++)
  for(j=0;j<col;j++)
   scanf("%d",&array[i][j]);
  for (n=0;n<row;n++)
  { 
   for (i=n;i<col-n;i++)
   {
    printf("%d\n",array[n][i]);
    t++;
   }
   printf("\n");
   if(t==row*col)
	   break;
   for (j=n+1;j<row-n;j++)
   {
    printf("%d\n",array[j][col-n-1]);
    t++;
   }
   printf("\n");
   if(t==row*col)
	   break;
   for (i=col-2-n;i>=n;i--)
   {
    printf("%d\n",array[row-n-1][i]);
    t++;
   }
   printf("\n");
   if(t==row*col)
	   break;
   for (j=row-2-n;j>n;j--)
   {
    printf("%d\n",array[j][n]);
    t++;
   }
   printf("\n");
   if(t==row*col)
	   break;
  }
  return 0;
}
int main()
{
	int m,n,i,j,num[100][100];
	int flag = -1;
	scanf("%d %d",&m,&n);
	for(i=0;i<m;i++)
	{
		for(j=0; j<n; j++)
		{
			scanf("%d", &num[i][j]);
		}
		//num[i][n] = -10;

	}

	//for(j = 0; j<=n; j++)
	//{
		//num[m][j] = -10;
	//}


	i = 0;
	j = 0;
	flag = 1;
	while(1)
	{
		if(num[i][j] != -10)
		{
			printf("%d\n", num[i][j]);
			num[i][j] = -10;
		}
		else
		{
			break;
		}
		
		if(flag == 1)
		{
			if(j+1<n && num[i][j+1] != -10)
			{
				j++;
			}
			else if(i+1 <m )
			{
				i++;
				flag = 2;
			}
		}
		else if(flag == 2)
		{
			if(i+1<m && num[i+1][j] != -10)
			{
				i++;
			}
			else if(j-1 >=0)
			{
				j--;
				flag = 3;
			}
		}
		else if(flag == 3)
		{
			if(j-1>=0 &&  num[i][j-1] != -10)
			{
				j--;
			}
			else if(i-1 >=0 )
			{
				i--;
				flag = 4;
			}
		}
		else if (flag ==4)
		{
			if( i-1>=0 && num[i-1][j] != -10)
			{
				i--;
			}
			else if(j+1 <n)
			{
				j++;
				flag = 1;
			}
		}
		
	}
	
	return 0;
}
int a[104][104],n=0;
int row,col,i,j,s;

int out(int ai,int aj,int bi,int bj)
{
     int i,j;
     for (i=aj;i<=bj;i++) {printf("%d\n",a[ai][i],n); n++;}
     for (i=ai+1;i<=bi;i++) {printf("%d\n",a[i][bj],n);n++;}
     if (ai!=bi) {for (i=bj-1;i>aj;i--) {printf("%d\n",a[bi][i],n);n++;} }
     if (aj!=bj) {for (i=bi;i>ai;i--) {printf("%d\n",a[i][aj],n);n++;} }
    // printf("   %d******%d  %d \n",n,ai,aj);
     if (n!=s) out(ai+1,aj+1,bi-1,bj-1);
     return 0;
    }
    
int main()
{
    scanf("%d %d",&row,&col);
    s=row*col;
    for (i=1;i<=row;i++)
    {
        for(j=1;j<=col;j++)
        {
                           scanf("%d",&a[i][j]);
        }}
    out(1,1,row,col);
    return 0;
}