semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main(){
    int row,col,i,j,k,l,x,p,r,q,a,b=1;
    int sz[100][100];
    scanf("%d%d",&row,&col);
    for(i=0;i<row;i++){
        for(j=0;j<col;j++){
            scanf("%d",&(sz[i][j]));
        }
    }
    if(row>=col){
        if(col%2==0){
        a=col/2;
        for(k=0;k<a;k++){
                
                for(l=k;l<(col-1-k);l++){
                    printf("%d\n",sz[k][l]);
                }
                
                for(p=k;p<(row-1-k);p++){
                    printf("%d\n",sz[p][col-k-1]);
                }
                
                for(q=(col-k-1);q>k;q--){
                    printf("%d\n",sz[row-k-1][q]);
                }

                for(r=(row-k-1);r>k;r--){
                    printf("%d\n",sz[r][k]);
                }
            }

        }
        else{
        a=col/2;
        for(k=0;k<a;k++){
                
                for(l=k;l<(col-1-k);l++){
                    printf("%d\n",sz[k][l]);
                }
                
                for(p=k;p<(row-1-k);p++){
                    printf("%d\n",sz[p][col-k-1]);
                }
                
                for(q=(col-k-1);q>k;q--){
                    printf("%d\n",sz[row-k-1][q]);
                }

                for(r=(row-k-1);r>k;r--){
                    printf("%d\n",sz[r][k]);
                }
            }
           for(x=a;x<(row-a);x++){
                    printf("%d\n",sz[x][a]);
                }
        }
        
        
    }

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

                for(r=(row-k-1);r>k;r--){
                    printf("%d\n",sz[r][k]);
                }
            }

        }
        else{
        a=row/2;
        for(k=0;k<a;k++){
                
                for(l=k;l<(col-1-k);l++){
                    printf("%d\n",sz[k][l]);
                }
                
                for(p=k;p<(row-1-k);p++){
                    printf("%d\n",sz[p][col-k-1]);
                }
                
                for(q=(col-k-1);q>k;q--){
                    printf("%d\n",sz[row-k-1][q]);
                }

                for(r=(row-k-1);r>k;r--){
                    printf("%d\n",sz[r][k]);
                }
            }
           for(x=a;x<(col-a);x++){
                    printf("%d\n",sz[a][x]);
                }
        }
        
        
    }


    
    
    return 0;
}
//********************************
//*???????????   **
//*????? 1300012845 **
//*???2013.11.2  **
//********************************
int main ()//???
{
	int x[104][104]={0}, y[10001]={0}, N ;
	int row, col, i, j, k, l=1, min ;
	cin >> row >> col;
	for ( i=1; i <=row; i++ )
	{
		for ( j=1; j <=col; j++ )
			cin >> x[i][j];//?????x??
	}
	i=1, j=1;
	N= row * col;
	if ( row > col )
		min = col;
	else 
		min = row;
	for (k=1; k <= min; k++ )//????1
	{
		for ( j=k; j <= col -k; j++ )//????????
		{
			if ( l>N )
				break;//break??
			y[l] = x[k][j]; //?????y??
			l++;
		}
		for ( i=k; i <= row -k; i++ )//????????
		{
			if ( l>N )
				break;
			y[l] = x[i][col-k+1];
			l++;
		}
		for ( j=col-k+1; j>=k+1; j-- )//??????????
		{
			if ( l>N )
				break;
			y[l] = x[row-k+1][j];
			l++;
		}
		for ( i=row-k+1; i>=k+1; i--)//??????????
		{
			if ( l>N )
				break;
			y[l] = x[i][k];
			l++;
		}
	}
	if (col==row && col % 2!=0 )
		y[N] = x [(col + 1)/2][(col + 1)/2];
	for (l=1; l <= N; l++)//??
		cout << y[l] << endl;
	return 0;
}
int main(){
	int row,col,i,j,d=1,count=0,f[110][110],vis[110][110];
	memset(vis,0,sizeof(vis));
	scanf("%d%d",&row,&col);
	for(i=1;i<=row;i++){
		for(j=1;j<=col;j++){
			scanf("%d",&f[i][j]);
		}
	}
	/*for(i=0;i<row;i++){
		for(j=0;j<col;j++){
			printf("f=%d\n",f[i][j]);
		}
	}*/
	i=1;j=1;
	for(;;){
		printf("%d\n",f[i][j]);
		count++;
		if(count>=row*col)break;
		vis[i][j]=1;
		if(d==1){
			if((j+1>col)||vis[i][j+1]){
				d=2;i++;
				continue;
			}
			else{j++;}
		}
		if(d==2){
			if((i+1>row)||vis[i+1][j]){
				d=3;j--;
				continue;
			}
			else{i++;}
		}
		if(d==3){
			if((j<2)||vis[i][j-1]){
				d=4;i--;
				continue;
			}
			else{j--;}
		}
		if(d==4){
			if((i<1)||vis[i-1][j]){
				d=1;j++;
				continue;
			}
			else{i--;}                 
		}
		
	}
	scanf("%d",&i);

	return 0;
}
int main()
{
  int row,col;
  int sz[100][100];
  int k,i,j;
  int a,b,c,d;
 
  scanf("%d %d",&row,&col);
 
  for(k=0;k<row;k++)
  {
    for(i=0;i<col;i++)
 {
   scanf("%d",&sz[k][i]);
 }
  }
 
  a=0;
  b=col-1;
  c=row-1;
  d=0;
 
  while(a<c&&d<b)//????????\n
  {
    for(i=d; i<b; i++)
  printf("%d\n",sz[a][i]);
 for(j=a; j<c; j++)
  printf("%d\n",sz[j][b]);
 for(i=b; i>d; i--)
  printf("%d\n",sz[c][i]);
 for(j=c; j>a; j--)
  printf("%d\n",sz[j][d]);
 a++;
 b--;
 c--;
 d++;
  }
  /*
  * ????????????????
  * ????????????????????????????????
  */
if(a==c && b==d)
{
 printf("%d\n",sz[a][b]);
}
  if(b==d && a!=c)
  {
    for(i=a; i<=c; i++)
  printf("%d\n",sz[i][b]);
  }
  if(a==c && b!=d)
  {
    for(i=d; i<=b; i++)
  printf("%d\n",sz[a][i]);
  }
  return 0;
}
int main()
{
	int n, m, i, j, a[101][101], round, count;
	cin >> n >> m;
	for (i=1; i<=n; i++)
		for (j=1; j<=m; j++)
			cin >> a[i][j];
	i=1;
	j=1;
	round=0;
	count=0;										//??????
	while (count<n*m)								//????????
	{
		while (j<=m-round)
		{
			cout << a[i][j] << endl;
			count++;
			j++;
		}
		if (count>=n*m) break;
		j--;
		i++;										//????
		while (i<=n-round)
		{
			cout << a[i][j] << endl;
			count++;
			i++;
		}
		if (count>=n*m) break;
		i--;
		j--;										//????
		while (j>=round+1)
		{
			cout << a[i][j] << endl;
			count++;
			j--;
		}
		if (count>=n*m) break;
		j++;
		i--;										//????
		while (i>=round+2)
		{
			cout << a[i][j] << endl;
			count++;
			i--;
		}
		if (count>=n*m) break;
		i++;
		j++;										//????
		round++;									//???????
	}
	return 0;										//main???????0
}
int main()
{
	int array[100][100], flag[100][100] = {{0}, {0}}, row, col, i, j, rowstart, colstart;
	cin >> row >> col;
	for (i = 1; i <= row; i++)
	{
		for (j = 1; j <= col; j++)
		{
			cin >> array[i][j];
			flag[i][j] = 1;
		}
	}
	rowstart = colstart = 1;
	do
	{
		for (i = colstart; i <= col; i++)
		{
			if (flag[rowstart][i] == 0 || array[rowstart][i] == 0)
			{
				break;
			}
			cout << array[rowstart][i] << endl;
			flag[rowstart][i] = 0;
		}
		rowstart++;
		for (i = rowstart; i <= row; i++)
		{
			if (flag[i][col] == 0 || array[i][col] == 0)
			{
				break;
			}
			cout << array[i][col] << endl;
			flag[i][col] = 0;
		}
		col--;
		for (i = col; i >= colstart; i--)
		{
			if (flag[row][i] == 0 || array[row][i] == 0)
			{
				break;
			}
			cout << array[row][i] << endl;
			flag[row][i] = 0;
		}
		row--;
		for (i = row; i >= rowstart; i--)
		{
			if (flag[i][colstart] == 0 || array[i][colstart] == 0)
			{
				break;
			}
			cout << array[i][colstart] << endl;
			flag[i][colstart] = 0;
		}
		colstart++;
		if (row == rowstart && col == colstart)
		{
			cout << array[row][col];
		}
	}while (row > rowstart || col > colstart);
	return 0;
}
int main(){
 int a,b,c,n,i,m,j,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]));
	 }
 }
 c=0;
   for(i=0;c<n*m;i++){
	 a=i%4;
	 b=i/4;
	 if(a==0){
       for(j=b;j<n-b;j++){
           printf("%d\n",sz[b][j]);
		   c=c+1;
	   }
	 }
     if(a==1){
       for(j=b+1;j<m-b;j++){
           printf("%d\n",sz[j][n-1-b]);
           c=c+1;
	   }
	 }
     if(a==2){
       for(j=n-2-b;j>=b;j--){
           printf("%d\n",sz[m-1-b][j]);
           c=c+1;
	   }
	 }
     if(a==3){
       for(j=m-2-b;j>b;j--){
           printf("%d\n",sz[j][b]);
		   c=c+1;
	   }
	 }
   }
	 return 0;
 }
int main()
{
  int m , n , i , j , x , t , num ;
  cin>>m>>n;
  num = m*n;
  int a[m][n];
  for ( i=0;i<=m-1;i++ )
   {
     for ( j=0;j<=n-1;j++ )
      {
        cin>>x;
        a[i][j]=x;
      }
    }
  t=0;
 while (num!=0)
 {
  if ((t%4==0)&&(num!=0))
   {
     for( j=0;j<=n-1;j++ )
      {
        num--;
        if ( num!=0)
        {
        cout<<a[0][j]<<endl;
        }
        else
        {
        cout<<a[0][j];
        }
      }
    for (i=0;i<=m-2;i++)
      {
        for (j=0;j<=n-1;j++)
        {
        a[i][j]=a[i+1][j];
        }
      }
     m--;
     t++;
    }
   if ((t%4==1)&&(num!=0))
   {
    for ( i=0;i<=m-1;i++ )
     {
       num--;
       if (num!=0)
       {
       cout<<a[i][n-1]<<endl;
       }
       else
       {
        cout<<a[i][n-1];
        }
     }
    n--;
    t++;
    }
    if ((t%4==2)&&(num!=0))
    {
      for (j=n-1;j>=0;j-- )
       {
         num--;
         if (num!=0)
         {
         cout<<a[m-1][j]<<endl;
         }
         else
         {
         cout<<a[m-1][j];
         }
       }
      m--;
      t++;
    }
    if ((t%4==3)&&(num!=0))
   {
     for( i=m-1;i>=0;i--)
      {
        num--;
        if (num!=0)
       {
        cout<<a[i][0]<<endl;
       }
        else
       {
        cout<<a[i][0];
       }
      }
    for (j=0;j<=n-2;j++)
      {
       for ( i=0;i<=m-1;i++ )
        {
        a[i][j]=a[i][j+1];
        }
      }
     n--;
     t++;
    }
  }
return 0;
}
int main()
{ 
   int i,j,n,m,k,N=0;
   scanf("%d%d",&n,&m);
   int a[100][100];
   for(i=0;i<n;i++){
   for(j=0;j<m;j++){
   scanf("%d",&a[i][j]);
      }
    }
   for(k=0;;k++){
   for(j=k;j<=m-1-k;j++){
   printf("%d\n",a[k][j]);
   N++;
       }
   printf("\n");
   if(N==n*m)break;
   for(i=k+1;i<=n-1-k;i++){
   printf("%d\n",a[i][m-1-k]);
   N++;
       }
   printf("\n");
   if(N==n*m)break;
   for(j=m-2-k;j>=k;j--){
   printf("%d\n",a[n-1-k][j]);
   N++;
       }
   printf("\n");
   if(N==n*m)break;
   for(i=n-2-k;i>=k+1;i--){
   printf("%d\n",a[i][k]);
   N++;
       }
   printf("\n");
   if(N==n*m)
   break;
   }
   return 0;
}
/*
 * 1000012795-??????????.cpp
 *     ??????????
 *  Created on: 2010-12-30
 *      Author: ??
 */
int a[100][100]={0};//????????
void cut(int m,int n)//??????????????
{
	int i,j;
	if(m==0||n==0)//???????m=0||n=0????
		return ;
	if(m==1)//?????m=1??????????????
	{
		for(i=0;i<n;i++)
			cout<<a[0][i]<<endl;
		return ;
	}
	if(n==1)//?????n=1??????????????
	{
		for(i=0;i<m;i++)
			cout<<a[i][0]<<endl;
		return ;
	}
	for(i=0;i<n;i++)//?????????
		cout<<a[0][i]<<endl;
	for(i=1;i<m;i++)
		cout<<a[i][n-1]<<endl;
	for(i=n-2;i>=0;i--)
		cout<<a[m-1][i]<<endl;
	for(i=m-2;i>0;i--)
		cout<<a[i][0]<<endl;
	for(i=0;i<m-2;i++)//????????????????
		for(j=0;j<n-2;j++)
		{
			a[i][j]=a[i+1][j+1];
		}
	cut(m-2,n-2);//?????????
}
int main()
{
	int m,n,i,j;
	cin>>m>>n;
	for(i=0;i<m;i++)
		for(j=0;j<n;j++)
			cin>>a[i][j];
	 cut(m,n);
	 return 0;
}
int main()
{
	int sz[100][100],row,col,i,k,x=0,y=0,n=1;
		cin>>row>>col;
		for(i=0;i<row;i++)
		{
			for(k=0;k<col;k++)
			{
				cin>>sz[i][k];
			}
		}
		while(n<=row*col)
		{
			for(k=y;k<(col-y-1);k++)
			{
				cout<<sz[x][k]<<"\n";
				n++;
				if(n>row*col)
					break;
			}
			for(i=x;i<(row-x-1);i++)
			{
				cout<<sz[i][col-y-1]<<"\n";
				n++;
				if(n>row*col)
					break;
			}
			for(k=col-y-1;k>y;k--)
			{
				cout<<sz[row-x-1][k]<<"\n";
				n++;
				if(n>row*col)
					break;
			}
			for(i=row-x-1;i>x;i--)
			{
				cout<<sz[i][y]<<"\n";
				n++;
				if(n>row*col)
					break;
			}
			if(x==(row-1)/2&&x==y&&row==col&&row%2==1)
			{	
				cout<<sz[x][y]<<"\n";
				n++;
			}
			x++;
			y++;
		}
	return 0;
}
int main()
{
	int r,c,a[100][100],b[10000]={0},i=0,j=0,p=0,q=0;
	int z1,z2,z3,z4;
	scanf("%d",&r);
    scanf("%d",&c);
	z1=z2=0,z3=r-1,z4=c-1;
	for(i=0;i<r;i++){
	for(j=0;j<c;j++){
	scanf("%d",&a[i][j]);}}
	if(c==1||r==1){
	for(i=0;i<r;i++){
	for(j=0;j<c;j++){
		printf("%d\n",a[i][j]);}}}
	else{
	b[0]=a[0][0];
	i=0,j=1;
    for(p=1;p<(c*r);p++){
		switch(q){
		case 0:b[p]=a[i][j];j++;break;
			case 1:b[p]=a[i][j];i++;break;
				case 2:b[p]=a[i][j];j--;break;
					case 3:b[p]=a[i][j];i--;break;
					default:break;}
		if(j==z4&&i==z1&&q==0){q=1;z1++;}
		else if(i==z3&&j==z4&&q==1){q=2;z4--;}//??????
		else if(j==z2&&i==z3&&q==2){q=3;z3--;}
		else if(i==z1&&j==z2&&q==3){q=0;z2++;}
	}
	for(q=0;q<(c*r);q++){
		printf("%d\n",b[q]);}}
		
		
}
//#define main xmain


int a[MAX][MAX];


int main()
{
	int m, n, i, j;
	scanf("%d %d", &m, &n);

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

	int rs = 0, re = m - 1;
	int cs = 0, ce = n - 1;
	while (re >= rs && ce >= cs) {
		if (re > rs) {
			if (ce > cs) {
				for (j=cs; j<=ce; j++) {
					printf("%d\n", a[rs][j]);
				}
				for (i=rs+1; i<=re; i++) {
					printf("%d\n", a[i][ce]);
				}
				for (j=ce-1; j>=cs; j--) {
					printf("%d\n", a[re][j]);
				}
				for (i=re-1; i>rs; i--) {
					printf("%d\n", a[i][cs]);
				}
			}
			else if (ce == cs) {
				for (i=rs; i<=re; i++) {
					printf("%d\n", a[i][cs]);
				}
			}
		}
		else if (re == rs) {
			for (j=cs; j<=ce; j++) {
				printf("%d\n", a[rs][j]);
			}
		}
		re--;
		rs++;
		ce--;
		cs++;
	}
	return 0;
}




int mn[][2] = {
	{23, 23},
	{44, 44},
	{23, 44},
	{44, 23},
	{3, 4},
	{4, 3},
	{1, 1},
	{1, 99},
	{99, 1},
	{99, 99}
};

int xn = 0;

int max_files = sizeof(mn) / sizeof(mn[0]);

char * output_dir = "data";

int rnd(int min, int max) 
{
    return min + ((rand() << 15) | rand()) % (max - min + 1);
}

void swap(int *a, int *b) {
	int t;
	t = *a;
	*a = *b;
	*b = t;
}

void fill(int a[][MAX], int m, int n) {
	int i, j, count = rnd(1,10);
	for (i=0; i<m; i++) {
		for (j=0; j<n; j++) {
			a[i][j] = count++;
		}
	}
	for (i=0; i<m; i++) {
		for (j=0; j<n; j++) {
			int i1 = rnd(0, m-1);
			int j1 = rnd(0, n-1);
			int i2 = rnd(0, m-1);
			int j2 = rnd(0, n-1);
			swap(&a[i1][j1], &a[i2][j2]);
		}
	}
}

void print(int a[][MAX], int m, int n) {
	int count = 0;
	for (int i=0; i<m; i++) {
		for (int j=0; j<n; j++) {
			printf("%d", a[i][j]);
			if (j == n-1) 
				printf("\n");
			else
				printf(" ");
		}
	}
}

void xbuild()
{
	printf("%d %d\n", mn[xn][0], mn[xn][1]);
	fill(a, mn[xn][0], mn[xn][1]);
	print(a, mn[xn][0], mn[xn][1]);
	xn++;
}
int main()
{
	int n,m,a[100][100],i,j,t;
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++)
	  for (j=1;j<=m;j++)
	  scanf("%d",&a[i][j]);
	int k=n,l=m;
	i=1;
	j=1;
	do
	{
		for (t=j;t<=l;t++) printf("%d\n",a[i][t]);
		i++;
		if (i>k) break;
		for (t=i;t<=k;t++) printf("%d\n",a[t][l]);
		l--;
		if (l<j) break;
		for (t=l;t>=j;t--) printf("%d\n",a[k][t]);
		k--;
		if (i>k) break;
		for (t=k;t>=i;t--) printf("%d\n",a[t][j]);
		j++;
		if (l<j) break;
    }
	while((i<=k)&&(j<=l));
	return 0;
}
/*
 * 6.cpp
 *
 *  Created on: 2012-11-9
 *      Author: AK
 */
int main(){
	int row,col,i,j,head,bottom,left,right;
	cin>>row>>col;
	int a[100][100];
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			{cin>>a[i][j];}
	head=0,bottom=row-1,left=0,right=col-1;i=0;
	for(;head<=bottom&&left<=right;){
		if(head>bottom||left>right) break;
		for(j=left;j<=right;j++)
			cout<<a[i][j]<<endl;
		j--;
		head++;
		if(head>bottom||left>right) break;
		for(i=head;i<=bottom;i++)
			cout<<a[i][j]<<endl;
		i--;
		right--;
		if(head>bottom||left>right) break;
		for(j=right;j>=left;j--)
			cout<<a[i][j]<<endl;
		j++;
		bottom--;
		if(head>bottom||left>right) break;
		for(i=bottom;i>=head;i--)
			cout<<a[i][j]<<endl;
		i++;
		left++;
	}
	return 0;
}
int main (){
 int h,l,i,k,a,s[H][L];
 scanf("%d %d",&h,&l);
 
 for(i=0;i<h;i++){
     for(k=0;k<l;k++){
      scanf("%d",&(s[i][k]));
      
      
      }
      } 
 if(h<=l){
          a=2*h-1;
          }else{
          a=2*l;
          }           
 for(i=0;i<a;i++){
      if(i%4==0){
         for(k=i/4;k<=l-1-i/4;k++){
             printf("%d\n",s[i/4][k]);
             
             }
      }else if(i%4==1){
         for(k=i/4+1;k<=h-1-i/4;k++){
             printf("%d\n",s[k][l-1-i/4]);
             
             }
      }else if(i%4==2){
         for(k=l-2-i/4;k>=i/4;k--){
             printf("%d\n",s[h-1-i/4][k]);
                      
             }      
      }else{
         for(k=h-2-i/4;k>=(i+1)/4;k--){
             printf("%d\n",s[k][i/4]);         
             
             }  
      }     
}                                                   
 return 0;
}
int main ()
{
    int a[105][105];
    int m,n;
    cin>>n>>m;
    for(int i = 0; i < n; i ++)
        for(int j = 0; j < m; j ++)
            cin>>a[i][j];
    int k = 0;
    for(int t = 0; t < m * n; k ++)
    {
        for(int j1 = k; j1 < m - k; j1 ++)
        {
            cout<<a[k][j1]<<endl;
		    t ++;
        }
        for(int i1 = k + 1; i1 < n - k; i1 ++)
        {
            cout<<a[i1][m - 1 - k]<<endl;
            t ++;
        }
        if( (k + 1 <= n - 1 - k) && ( m - 2 - k >= k) )
        { 
            for(int j = m - 2 - k; j >= k; j --)
            {
                cout<<a[n - 1 - k][j]<<endl;
                t ++;
            }
            for(int i = n - 2 - k; i >= k + 1; i --)
            {
                cout<<a[i][k]<<endl;
                t ++;
            }
        } 
    }		
	return 0;
}
int main()
{
        int a[100][100],i,k,t,m,n;
        scanf("%d%d",&m,&n);
        for(i=0;i<m;i++)
        {
                for(k=0;k<n;k++)
                {
                        scanf("%d",&a[i][k]);
                }
        }
        for(t=0;t<(m+1)/2&&t<(n+1)/2;t++)
        {
                for(i=t,k=t;k<n-t;k++)
                {
                        printf("%d\n",a[i][k]);
                }
                if(t!=m-t-1)
                {
                        for(k=n-t-1,i=t+1;i<m-t;i++)
                        {
                                printf("%d\n",a[i][k]);
                        }
                    if(t!=n-t-1)
                        {
                        for(i=m-t-1,k=n-t-2;k>=t;k--)
                                {
                                printf("%d\n",a[i][k]);
                                }
                        for(k=t,i=m-t-2;i>t;i--)
                                {
                                printf("%d\n",a[i][k]);
                                }
                        }
                }
        }
        return 0;
}
int main(){
int sz[155][155];

int i,j,p,q,c=0,a,b,col,row;

scanf("%d%d",&row,&col);
for(i=0;i<row;i++)
{ 
	for(j=0;j<col;j++)
	{
	 scanf("%d",&(sz[i][j]));
	}
}
p=0,q=0,a=col,b=row;
while(1)
{
for(i=p,j=p;j<=p+a-1;j++)
{
if(c>=col*row)
break;
printf("%d\n",sz[i][j]); c++;

}
for(j=p+a-1,i=q+1;i<=q+b-2;i++)
{
if(c>=col*row)
break;
printf("%d\n",sz[i][j]); c++;

}
for(i=q+b-1,j=p+a-1;j>=p;j--)
{
if(c>=col*row)
break;
printf("%d\n",sz[i][j]); c++;

}
for(j=p,i=q+b-2;i>=q+1;i--)
{
if(c>=col*row)
break;
printf("%d\n",sz[i][j]); c++;

}

a-=2,b-=2;
p++,q++;
if(c>=col*row)
break;
}

return 0;
}
int main()
{
    int a[100][100], vis[100][100] = {0};
    int row, col, n, x = -1, y = 0;
    cin >> row >> col;
    for (int i = 0; i < row; i++)
        for (int j = 0; j < col; j++)
        {
            cin >> a[j][i];
        }
    n = row * col;
    while (n)
    {
        while (!vis[x + 1][y] && x + 1 < col)
        {
            x++;
            vis[x][y] = 1;
            cout << a[x][y] << endl;
            n--;
        }
        while (!vis[x][y + 1] && y + 1 < row)
        {
            y++;
            vis[x][y] = 1;
            cout << a[x][y] << endl;
            n--;
        }
        while (!vis[x - 1][y] && x > 0)
        {
            x--;
            vis[x][y] = 1;
            cout << a[x][y] << endl;
            n--;
        }
        while (!vis[x][y - 1] && y > 0)
        {
            y--;
            vis[x][y] = 1;
            cout << a[x][y] << endl;
            n--;
        }
    }
   
    
    return 0;
}
int main()
{
	int a[101][101];
	int m,n,i,j,s,t;
	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)
	{
		s=n;
	}
	else
	{
		s=m;
	}
	i=1;
	if(s%2==0)
	{	for(t=1;t<=s/2;t++)
		{
			for(j=t;j<=n-t+1;j++)
			{
				printf("%d\n",a[i][j]);
			}
			for(i=1+t;i<=m+1-t;i++)
			{
				printf("%d\n",a[i][j-1]);
			}
			i=i-1;
			for(j=n-t;j>=t;j--)
			{
				printf("%d\n",a[i][j]);
			}
			j=j+1;
			for(i=m-t;i>=t+1;i--)
			{
				printf("%d\n",a[i][j]);
			}
			i=i+1;
		}
	}
	else
	{
		i=1;
		for(t=1;t<=(s-1)/2;t++)
		{
			for(j=t;j<=n-t+1;j++)
			{
				printf("%d\n",a[i][j]);
			}
			for(i=1+t;i<=m+1-t;i++)
			{
				printf("%d\n",a[i][j-1]);
			}
			i=i-1;
			for(j=n-t;j>=t;j--)
			{
				printf("%d\n",a[i][j]);
			}
			j=j+1;
			for(i=m-t;i>=t+1;i--)
			{
				printf("%d\n",a[i][j]);
			}
			i=i+1;
		}
		if(m<n)
		{
			for(j=(s+1)/2;j<=(n-(s-1)/2);j++)
			{
				printf("%d\n",a[(s+1)/2][j]);
			}
		}
		else
		{
			for(i=(s+1)/2;i<=(m-(s-1)/2);i++)
			{
				printf("%d\n",a[i][(s+1)/2]);
			}
		}
	}
	return 0;
}
int main()
{
    int array[100][100],i,j,k,n,col,row;
    scanf("%d""%d",&row,&col);
    for (i=0;i<row;i++)
    {
        for (j=0;j<col;j++)
        {
            scanf("%d",&array[i][j]);
        }
    }
    if (col>row)
        n=row;
    else if (col<row)
        n=col;
    else if (col==row)
        n=row;
    n=n/2-1;

    for (k=0;k<=n;k++)
    {
    for (i=k,j=k;j<col-1-k;j++)
    {
        printf("%d\n",array[i][j]);
    }
    for (i=k,j=col-1-k;i<row-1-k;i++)
    {
        printf("%d\n",array[i][j]);
    }
    for (i=row-1-k,j=col-1-k;j>k;j--)
    {
        printf("%d\n",array[i][j]);
    }
    for (i=row-1-k,j=k;i>k;i--)
    {
        printf("%d\n",array[i][j]);
    }

    }
    if (col>row&&row%2==1)
    {
                                    k=row/2;
                                    for (i=k,j=k;j<=col-1-k;j++)
                                    {
                                        printf("%d\n",array[i][j]);
                                    }
    }
    else if (col<row&&col%2==1)
    {
                                    k=col/2;
                                    for (i=k,j=k;i<=row-1-k;i++)
                                    {
                                        printf("%d\n",array[i][j]);
                                    }
    }
    else if (col==row&&col%2==1&&row%2==1)
    {
                 k=col/2;
                 printf("%d\n",array[k][k]);
    }
    else k=k;
    

  return 0;
}
int main()
{ 
int row,col,rowsx,rowxx,colsx,colxx;
   scanf("%d%d",&row,&col);
   int sz[100][100];
   for(int i=0;i<row;i++)
   {
      for(int j=0;j<col;j++)
      {
          scanf("%d",&sz[i][j]);
      }
   }
   rowsx=row-1;
   rowxx=0;
    colsx=col-1;
    colxx=0;
    while(rowxx<=rowsx&&colxx<=colsx)
    {
       if(rowxx==rowsx){
          for(int o=colxx;o<=colsx;o++)
          {
             printf("%d\n",sz[rowxx][o]);
          }
          break;
       }
       if(colsx==colxx){
          for(int p=rowxx;p<=rowsx;p++)
          {
             printf("%d\n",sz[p][colxx]);
          }
          break;
       }             
                       
       for(int k=colxx;k<=colsx;k++){
          printf("%d\n",sz[rowxx][k]);
          }
       for(int l=rowxx+1;l<=rowsx;l++){
          printf("%d\n",sz[l][colsx]);
          }
       for(int m=colsx-1;m>=colxx;m--){
          printf("%d\n",sz[rowsx][m]);
          }
       for(int n=rowsx-1;n>rowxx;n--){
          printf("%d\n",sz[n][colxx]);
          }
       rowsx--;
       rowxx++;
       colsx--;
       colxx++;
    }
return 0;
}
int main()
{
	int row,col,i,j,array[101][101],count=0;
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			scanf("%d",&array[i][j]);
		int num=row+col-1;
		for(i=1;i<=num;i++)
		{
			if(count==row*col)
				break;
			else
				switch(i%4)
				{
				case 1:
					{
						for(j=i/4;j<col-i/4;j++)
						{
							printf("%d\n",array[i/4][j]);
							count+=1;
						}
						break;
					}
				case 2:
					{
						for(j=i/4+1;j<row-i/4;j++)
						{
							printf("%d\n",array[j][col-i/4-1]);
							count+=1;
						}
						break;
					}
				case 3:
					{
						for(j=col-2-i/4;j>=i/4;j--)
						{
							printf("%d\n",array[row-1-i/4][j]);
							count+=1;
						}
						break;
					}
				case 0:
					{
						for(j=row-1-i/4;j>=i/4;j--)
						{
							printf("%d\n",array[j][i/4-1]);
							count+=1;
						}
						break;
					}
				}
			}
		return 0;
}