semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main(){
    char word[3][51];
    int i,j,a=0;
    int b=0;
    for (i=0;i<2;i++){
        scanf("%s",word[i]);
        }
    for(i=0;i<50;i++){
                      if(word[0][i]!='\0'){
                                        a++;
                                        }
                                        else{
                                             break;
                                             }
                                        }
    for(i=0;i<50;i++){
                      if(word[0][0]==word[1][i]){
                      for(j=0;j<a;j++){
                                       if(word[0][j]==word[1][i+j]){
                                                                    b++;
                                                                    }
                                                                    }
                                                                    if(b==a){
                                                                            printf("%d",i);  
                                                                            }
                                                                            else{
                                                                                 b=0;
                                                                                 } 
                                                                    }
                                                                    }
                                                                                          
                                                                                                                                      return 0;
                                                                                                                                            
                                                   }
void main()
{
	char a[50],b[50];
	int i,j,k=0,l,x,y;
	scanf("%s %s",a,b);
	x=strlen(a);
	y=strlen(b);
	for(i=0;i<=(y-x);i++)
		if(b[i]=a[0])
		{   l=1;
		    k=i;
			for(j=i+1;l<x;j++,l++)
				if(a[l]!=b[j])
				{
					k=0;
					break;
				}
            if(l==x)
			{
				printf("%d",k);
				break;
			}
		}
}
int main()
{
  char str[101];
//strcpy(str,"avx hexavxavxyeh");
  int i,j,t,p=1;
 gets(str); 
  for(i=0;i<=50;i++)
  {
	  if(str[i]==' ') {
		  t=i;
	  break;}
  }
  for(i=t+1;i<strlen(str);i++)
 {
    for(j=0;j<t+1;j++)
	{ 
		if(j==t&&p==1)
	  {printf("%d\n",i-t-1);
		goto l;}
	 else if(str[i+j]==str[j]&&p==1)
			p=1;	  
	 else if(str[i]==str[0])
		  p=1;
	 else p=0;
	}
  }
l: return(0);
}
int dingwei(char s[],char w[])
{
	int len,i,j;
	len=strlen(s);
	for(i=0;;i++)
	{
		for(j=0;j<len&&s[j]==w[i+j];j++)
			;
		if(j==len)
			return i;
	}
}
main()
{
	char c1[51]={'\0'},c2[51]={'\0'};
	scanf("%s%s",c1,c2);
	printf("%d\n",dingwei(c1,c2));
	return 0;
}
int main()
{
	char s[N],w[N];
	int dis_len;
	int i,j,sum=1;
	scanf("%s",&s);
	scanf("%s",&w);
	dis_len=strlen(w)-strlen(s)+1;
	for(i=0;i<dis_len;i++)
	{
		for(j=0;j<strlen(s);j++)
		{
			if(s[j]!=w[i+j])
			{
				sum=0;
				break;
			}
		}
		if(sum==1)
		{
			printf("%d\n",i);
			break;
		}
		else
		{
			sum=1;
		}
	}
	return 0;
}
main()
{int i,j,k,m,n,t;
 char a[50];char b[50];
 scanf("%s %s",a,b);
 for(i=0;;i++)
  {for(j=0;;j++)
    {if(a[i]==b[j])
       {t=j;m=i;n=j;
        for(m=i,n=j;;)
         {if(a[m]==b[n])
             {m++;n++;}
          if((m-i)==(strlen(a))) break;
         }
       }
      else continue;
      
      if((m-i)==(strlen(a))) break;
    
     }
     if((m-i)==(strlen(a))) break;
  }
  printf("%d",t);
}
int main(){
	char s[50];
	char w[50];
	char sw[50];
	int schangdu;
	int wchangdu;
	int i,j;
	int m;
	int tag=0;
	scanf ("%s",s);
	scanf ("%s",w);
	schangdu=strlen(s);
	wchangdu=strlen(w);
	for(i=0;i<wchangdu;i++){
		for(j=i;j<i+schangdu;j++){
			sw[j-i]=w[j];
		}
		sw[schangdu]=0;
			m=strcmp(s,sw);
			if(m==0){
				printf("%d",i);
				tag=1;
				break;
			}
			if(tag==1){
				break;
			}
	    if(tag==1){
			break;
		}
	}
	return 0;
}
int main(){
	char z[100];
	char q[50],p[50];
	int j=0;
	int sum,i,k,n,m=0,l=0;
	gets(z); 
   
   
//	for(i=0;z[i]!='')

	n=strlen(z);
	
	for(i=0;i<=n-1;i++){
		if(z[i]!=' '){
			p[i]=z[i];
			m++;
		}
		if(z[i]==' '){
			break;
		}
	}
	for(i=m+1;i<=n-1;i++){
		q[j]=z[i];
		j++;
		l++;
	
	}
	for(i=0;i<l;i++)
	{
		if(q[i]==p[0])
		{
			sum=1;
			for(k=i+1;k<=i+m-1;k++)
			{
				if(q[k]==p[k-i])
				{
					sum++;
				}
				else
					break;
			}
			if(sum==m)
			{
				printf("%d",i);
				break;
			}
		}
	}
	return 0;
}
void main()
{
	int i;
	char s[100],w[100],*p,*q;
	scanf("%s %s",s,w);
	p=s;q=w;
	while(*p!=*q)
	q++;
	for(i=0;i<strlen(s);i++,p++,q++)
		if(*p!=*q)break;
		if(i==strlen(s))
			printf("%d",q-w-strlen(s));
}
int main(int argc, char* argv[])
{
	char s[50],w[50];
	int i,j,k,p=0,m;
	scanf("%s %s",s,w);
	for(i=0;w[i]!='\0';i++){
		if(w[i]==s[0]){
			for(k=i+1,j=1;s[j]!='\0';j++,k++){
				if(w[k]==s[j]){
					p=1;
					m=i;
				}
				else{
					break;
					p=0;
				}
			}
		}
		if(p==1){
			printf("%d",m);
			break;
		}
	}

	

	
	return 0;
}
int main()
{
	char a[51],b[51];
	int l1,l2,i,j;
	scanf("%s%s",a,b);
	l1=strlen(a);
	l2=strlen(b);
	for(i=0;i<l1;i++)
	{
		if(b[i]!=a[0])
			continue;
		else 
		{
			for(j=i;j<=i+l2-1;j++)
			{
				if(a[j-i]!=b[j])
					break;
			}
			if(j>i+l2-1)
				break;
		}
	}
	printf("%d",i);
	return 0;
}
int main(int argc, char* argv[])
{
    int i,j,l,count=0;
	char y[50],x[50];
	scanf ("%s",x);
	scanf ("%s",y);
	l=strlen(x);
    for (i=0,j=0;i<l;){
		if (x[i]==y[j]){
			i++;
			j++;
		}
		else {
			j++;
			count++;
		}
	}
    printf("%d",count);
	
	return 0;
}
int main(){
	char word1[100],word2[100],*p1,*p2;
	int i=0,len,j,num=0,a=0;
	scanf("%s%s",word1,word2);
	p1=word1;
	len=strlen(word1);
	for(p2=word2;*p2!='\0';p2++)
	{
		i++;
		for(j=0;j<len;j++)
		{
			if(*p2+j==*p1+j)
			{
				num++;
			}
			if(num==len)
			{
				a=i-1;
				break;
			}
		}
		if(a!=0)
		{
			break;
		}
	}
	printf("%d",a);
	return 0;
}
int main()
{
	char a[1000],b[1000];
	int i,j,k,p;
	scanf("%s %s",a,b);
	for(i=0;b[i]!=0;i++)
	{
		int same=0;
		if(a[0]==b[i])
		{
			same=1;
			for(j=1;a[j]=0;j++)
			{
				if(a[j]!=b[i+j]) {same=0 ;break;}
			}
			if(same==1) {
				printf("%d",i);
				break;
			}
		}
	}
	return 0;
}
int main()
{
  int i,lenw,lens,a=100,j;
  char s[50],w[50];
  scanf("%s%s",&s,&w);
  lenw=strlen(w);
  lens=strlen(s);
  for(i=0;i<lenw;i++)
  {
      for(j=0;j<lens;j++)
      {
              if(w[i+j]!=s[j])break;
              if(w[i+j]==s[j]) a=i; break;

      }
      if(a==i) break;
   }          
      printf("%d",a);                             

  return 0;

}
void main()
{
	char a[100],b[100],*p;
	int i,j,q=0,t;
	scanf("%s%s",a,b);
	for(p=b,t=0;p<b+strlen(b);p++,t++)
	{
		if(*p==*a)
		{
			for(j=1;j<strlen(a);j++,p++)
			{
				if(*p=!*(a+j))
				{
					q=1;
					break;
				}
				if(q==0)
				{
					printf("%d\n",t);
					break;
				}
			}
		}
	}
}
int main(){
  int array[100][100];
  int row,col,c;
  int i=0,j=0;
  scanf("%d%d",&row,&col);
  for(i=0;i<row;i++){
	  for(j=0;j<col;j++){
		  scanf("%d",&(array[i][j]));
	  }
  }
if(col==1&&row!=1){
	  i=0;
	  for(i=0;i<row;i++){
		  printf("%d\n",array[i][0]);
	  }
  }
  if(row==1&&col!=1){
	  j=0;
	  for(j=0;j<col;j++){
		  printf("%d\n",array[0][j]);
	  }
  }
 if(col==1&&row==1){

    printf("%d\n",array[0][0]);
	
  }

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

}
if((row%2!=0&&col%2==0)||(row%2!=0&&col%2!=0)){
	i=c;
	for(i=c;i<col-c;i++){
		printf("%d\n",array[(row-1)/2][i]);
	}
}
	i=c;
if(col%2!=0&&row%2==0){
	i=c;
	for(i=c;i<row-c;i++){
		printf("%d\n",array[i][(col-1)/2]);
	}
}
}

  return 0;
}
//********************************
//*???????????
//*??? ?? 1300012814  **
//*???2013.10,30  **
//********************************
int main()
{
	int a[101][101], row, col, num = 0, m = 1, n = 0;               //?????row????col????num????????????m?????????n????????

	cin >> row  >>col;                                               //??????
	for (int i = 0; i <= row + 1;i++)
	{
		for (int j = 0; j <= col + 1; j++)
		{
			if (i == 0||j == 0||i == row + 1||j == col +1)
				a[i][j] = 0;
			else  cin >> a[i][j];
		}
	}                                                               //????????????????????????????0
	int i = 1, j = 1;                                              
	while (num < col * row)                                         //???????????????
	{
	cout << a[i][j] <<endl;
	a[i][j] = 0;
	num++;                                                         //??a[i][j]??????num++???????????0
	if (a[i + n][m + j] == 0)                                      //??????????0?????????
	{
  if (m != 0)
  {
   n = m;
   m = 0;
  }                                                                //m?????????????????????
  else
  {
  m = -n;
  n = 0;
  }                                                                //n?????????????????????
	} 
  i = i + n;               
  j = j + m;                                                       //???????????
		}

	return 0;
}
int dir[4][2]={0,1, 1,0, 0,-1, -1,0};
int k,row,col,a[200][200];

int main(){
	scanf("%d%d",&row,&col);
	for (int i=0;i<row;++i)
		for (int j=0;j<col;++j) scanf("%d",&a[i][j]);
	int k=0,i=0,j=0,i1,j1;
	while (1>0){
		printf("%d\n",a[i][j]);
		a[i][j]=-1;
		i1=i+dir[k][0];
		j1=j+dir[k][1];
		if (i1>=0 && i1<row && j1>=0 && j1<col && a[i1][j1]!=-1){
			i=i1;j=j1;
			continue;
		}
		k=(k+1)%4;
		i1=i+dir[k][0];
		j1=j+dir[k][1];
		if (i1>=0 && i1<row && j1>=0 && j1<col && a[i1][j1]!=-1){
			i=i1;j=j1;
			continue;
		}
		break;
	}
}
int main()
{
	int a[100][100] = {0}, row, col, i, j, b[100][100] = {0}, num = 0;
    cin >> row >> col;
    for (i = 0; i <= row - 1; i++)
		{
			for (j = 0; j <= col - 1; j++)
			cin >> a[i][j];
		}
	i = 0;
	j = 0;
	while (1)
	{
		while (j != col && b[i][j] == 0)
		{
			cout << a[i][j] << endl;
			b[i][j] = 1;
			num++;
			j++;
		}
		j--;
		i++;
		while (i != row && b[i][j] == 0)
		{
			cout << a[i][j] << endl;
			b[i][j] = 1;
			num++;
			i++;
		}
		i--;
		j--;
		while (j != -1 && b[i][j] == 0)
		{
			cout << a[i][j] << endl;
			b[i][j] = 1;
			num++;
			j--;
		}
		j++;
		i--;
		while (i != -1 && b[i][j] == 0)
		{
			cout << a[i][j] << endl;
			b[i][j] = 1;
			num++;
			i--;
		}
		i++;
		j++;
		if (num == row * col)
			break;
	}
 return 0;
}
int main () 
{
int a[100][100];
int row, col, i=0, j=0, left=0, right=0, up=0, down=0;
int x=0;
scanf("%d%d",&row,&col);
down=row;
right=col;
for (; i<row; i++) 
{
for (j=0; j<col; j++) 
{
scanf("%d",&a[i][j]);
}
}
i=0,j=0;
for (; ; ) 
{
for (; j<right; j++) 
{
printf("%d\n",a[i][j]);
x++;
}
j--;
if (x>=col*row) 
{
break;
}
i++;
for (; i<down; i++) 
{
printf("%d\n",a[i][j]);
x++;
}
i--;
if (x>=col*row) 
{
break;
}
j--;
for (; j>=left; j--) 
{
printf("%d\n",a[i][j]);
x++;
}
j++;
if (x>=col*row) 
{
break;
}
i--;
for (; i>up; i--) 
{
printf("%d\n",a[i][j]);
x++;
}
if (x>=col*row) 
{
break;
}
i++;
j++;
right--;
left++;
up++;
down--;
}
return 0;
}
int main()
{
	int r, c, *a, l, m, n, i, up, dn, le, ri,k=1,end=0;
	scanf("%d%d", &r, &c);
	l = r*c;
	up = 1;
	dn = r;
	le = 1;
	ri = c;
	a = (int*)malloc(sizeof(int)*(l + 1));
	for (i = 1; i <= l; i++)
	{
		scanf("%d", &*(a + i));
	}
	printf("%d", *(a + 1));
	do
	{
		for (n = le; n <= ri; n++)
		{
			if (up == 1 && n == 1)
				continue;
			printf("\n%d", *(a + (up - 1)*c + n));
			k++;
			if (k == l)
				end = 1;
		}
		up++;
		if (end == 1)
			break;
		for (m = up; m <= dn; m++)
		{
			printf("\n%d", *(a + (m - 1)*c + ri));
			k++;
			if (k == l)
				end = 1;
		}
		ri--;
		if (end == 1)
			break;
		for (n = ri; n >= le; n--)
		{
			printf("\n%d", *(a + (dn - 1)*c + n));
			k++;
			if (k == l)
				end = 1;
		}
		dn--;
		if (end == 1)
			break;
		for (m = dn; m >= up; m--)
		{
			printf("\n%d", *(a + (m - 1)*c + le));
			k++;
			if (k == l)
				end = 1;
		}
		le++;
		if (end == 1)
			break;
	} while(k!=l);
}
/*
 * bianli2.cpp
 *
 *  Created on: 2011-11-5
 *      Author: 1100012857
 */

int main()
{
    int row,col,i,j;
    int a[100][100];
    cin>>row>>col;
    for (i=0;i<=row-1;i++)
    {
        for (j=0;j<=col-1;j++)
        {
            cin>>a[i][j];
        }
    }
    int lu_x=0,lu_y=0,rd_x=row-1,rd_y=col-1;
    while(lu_x<rd_x&&lu_y<rd_y)
    {
		   for (j=lu_y;j<=rd_y;j++)
			   cout<<a[lu_x][j]<<endl;
		   for (i=lu_x+1;i<=rd_x;i++)
			   cout<<a[i][rd_y]<<endl;
		   for (j=rd_y-1;j>=lu_y;j--)
			   cout<<a[rd_x][j]<<endl;
		   for (i=rd_x-1;i>=lu_x+1;i--)
			   cout<<a[i][lu_y]<<endl;
		   lu_x++;lu_y++;rd_x--;rd_y--;
    }
    if(lu_x==rd_x)
    {
    	for (j=lu_y;j<=rd_y;j++)  cout<<a[lu_x][j]<<endl;
    }
    else
    {
    	for (i=lu_x;i<=rd_x;i++)  cout<<a[i][rd_y]<<endl;
    }
    return 0;
}
int main()
{
    int a[200][200];
    int row ,col;
    int i,j;
    cin>>row>>col;
    for(i=1;i<=row;i++)
    {
        for(j=1;j<=col;j++)
        {
            cin>>a[i][j];
        }
    }
    int upm,downm,right,left;
    upm=1;
    downm=row;
    right=col;
    left=1;
    int time=0;
    while(1)
    {
      for(j=left;j<=right;j++)
      {
        cout<<a[upm][j];
        if(time<row*col-1)
            cout<<endl;
        time=time+1;

      }
      if(time==row*col)
        break;

      for(i=upm+1;i<=downm;i++)
      {
        cout<<a[i][right];
        if(time<row*col-1)
            cout<<endl;
        time=time+1;
      }
      if(time==row*col)
        break;

      for(j=right-1;j>=left;j--)
      {
          cout<<a[downm][j];
          if(time<row*col-1)
            cout<<endl;
          time=time+1;

      }
      if(time==row*col)
        break;


          for(i=downm-1;i>upm;i--)
        {
           cout<<a[i][left];
           if(time<row*col-1)
            cout<<endl;
           time=time+1;
        }

   if(time==row*col)
        break;




      upm=upm+1;
      downm=downm-1;
      right=right-1;
      left=left+1;
    }






    return 0;
}
void main()
{
	int n,m,i,j,x,y,pos;
	int p[200][200]={0};
	int a[200][200];
	int f[10][2];
	f[0][0]=0; f[0][1]=1;
	f[1][0]=1; f[1][1]=0;
	f[2][0]=0; f[2][1]=-1;
	f[3][0]=-1; f[3][1]=0;
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++)
		for (j=1;j<=m;j++)
		{
			p[i][j]=1;
			scanf("%d",&a[i][j]);
		}
	x=1; y=1; pos=0;
	for (i=1;i<=n*m;i++)
	{
		printf("%d\n",a[x][y]);
		p[x][y]=0;
		if (!p[x+f[pos][0]][y+f[pos][1]])
		  pos=(pos+1)%4;	
		x=x+f[pos][0];
		y=y+f[pos][1];
	}
}
int main()
{
    int n , m , i , j , n0 , m0 , p , q , a[102][102] ; 
    cin >> n >> m ; 
    for (i = 1 ; i <= n ; i ++ )
        for (j = 1 ; j <= m ; j ++ )
            cin >> a[i][j] ; 
    n0 = n / 2 + n % 2 ; 
    m0 = m / 2 + m % 2 ; 
    if (n0 > m0)
         q = m0 ; 
    else 
         q = n0 ; 
    for (p = 1 , n0 = 1 , m0 = 1 ; p <= q ; p ++ , n0 ++ , m0 ++ , n -- , m -- )
    {
        if (m == m0)
        {
              for (i = n0 ; i <= n ; i ++ )
                  cout << a[i][m] << endl ; 
              break ; 
              }
        if (n == n0)
        {
              for (j = m0 ; j <= m ; j ++ )
                  cout << a[n][j] << endl ; 
              break ; 
              }
        for (j = m0 ; j <= m - 1 ; j ++ )
            cout << a[n0][j] << endl ; 
        for (i = n0 ; i <= n - 1 ; i ++ )
            cout << a[i][m] << endl ; 
        for (j = m ; j >= m0 + 1 ; j -- )
            cout << a[n][j] << endl ; 
        for (i = n ; i >= n0 + 1 ; i -- )
            cout << a[i][m0] << endl ; 
            }
    return 0 ; 
}
int main()
{
  int row,col;  
  int b,c,d,e,k,i;
  int a[100][100];
  scanf("%d%d",&row,&col);
  for(k=0;k<row;k++)
  {
    for(i=0;i<col;i++)
    {
		scanf("%d",&a[k][i]);
	}
  }
  b=0;
  d=0;
  c=col-1;
  e=row-1;
  for(;b<=c&&d<=e;b++,d++,c--,e--)
  {
	if(b!=c&&d!=e)
    {
	  for(i=b;i<c;i++)
		printf("%d\n",a[d][i]);	  
	  for(i=d;i<e;i++)   
		printf("%d\n",a[i][c]);	  
	  for(i=c;i>b;i--)      
		printf("%d\n",a[e][i]);	  
	  for(i=e;i>d;i--)    
		printf("%d\n",a[i][b]);      
	 }
     else if(b==c)
     {
		for(i=d;i<=e;i++)        
			printf("%d\n",a[i][b]);			
	  }
      else if(d==e)
      {
		for(i=b;i<=c;i++)
			printf("%d\n",a[d][i]);			
	   }
	
  }
return 0;
}
int main()
{
	int row,col,i,j;
	cin>>row>>col;
	int a[row][col];
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			cin>>a[i][j];
	int n=0;//n??????1


	while((n<row/2)&&(n<col/2))//??????????
	{
		for(j=n;j<=col-2-n;j++)
			cout<<a[n][j]<<endl;
		for(i=n;i<=row-2-n;i++)

			cout<<a[i][col-1-n]<<endl;

		for(j=col-1-n;j>=1+n;j--)

	   cout<<a[row-1-n][j]<<endl;

		for(i=row-1-n;i>=1+n;i--)
			cout<<a[i][n]<<endl;
		n++;
	}
	//??????????
		for(j=n;j<=col-1-n;j++)
			cout<<a[n][j]<<endl;
		if(row-1-2*n>0)//???????????
		{
		for(i=n+1;i<=row-1-n;i++)
		cout<<a[i][col-1-n]<<endl;

		if(col-2-2*n>0)//??????????
		{
		for(j=col-2-n;j>=n;j--)
			cout<<a[row-1-n][j];
		}
		}
}
int main(){
    int r,c;
    scanf("%d %d",&r,&c);
    int sz[100][100];
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            scanf("%d",&sz[i][j]);
            }
        }
    int i=0,j=0;
    int p=0,q=0;
    int n=0;
    while(i<=r/2&&j<=c/2){
    while(q<c-j){
         printf("%d\n",sz[p][q]);
         q++;
         n++;
         }
    if(n>=r*c){
         break;
         }
         q=q-1;
         p=p+1;
    while(p<r-i){
         printf("%d\n",sz[p][q]);
         p++;
         n++;
         }
    if(n>=r*c){
         break;
         }
         p=p-1;
         q=q-1;
    while(q>=j){
         printf("%d\n",sz[p][q]);
         q--;
         n++;
         }
    if(n>=r*c){
         break;
         }
         q=q+1;
         p=p-1;
         i=i+1;
    while(p>=i){
          printf("%d\n",sz[p][q]);
          p--;
          n++;
          }
    if(n>=r*c){
         break;
         }
          p=p+1;
          q=q+1;
          j=j+1;
    }
    return 0;
    }
int main()
{
	int m,n,h=1,v=0,i,j;
	int array[100][100];
	while(cin>>m>>n)
	{
		memset(array,0,sizeof(array));
		for(i=1;i<=m;i++)
			for(j=1;j<=n;j++)
				cin>>array[i][j];
		h=1;v=0;
		while(m>0&&n>0)
		{
			if(m!=1&&n!=1)
			{
				for(i=1;i<=n;i++)
				{
					v++;
					cout<<array[h][v]<<endl;
				}
				for(i=1;i<=m-1;i++)
				{
					h++;
					cout<<array[h][v]<<endl;
				}
				for(i=1;i<=n-1;i++)
				{
					v--;
					cout<<array[h][v]<<endl;
				}
				for(i=1;i<=m-2;i++)
				{
					h--;
					cout<<array[h][v]<<endl;
				}
				m=m-2;
				n=n-2;
			}
			else if(m==1)
			{
				for(i=1;i<=n;i++)
				{
					v++;
					cout<<array[h][v]<<endl;
				}
				m=m-2;
				n=n-2;
			}
			else
			{
				v++;
				for(i=1;i<=m;i++)
				{
					cout<<array[h][v]<<endl;
					h++;
				}
				m=m-2;
				n=n-2;
			}
		}
	}
	return 0;
}
int main()
{
	int row,col,row1,row2,col1,col2,array[100][100],i,j,i1,i2,j1,j2;
	scanf("%d %d",&row,&col);
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
		{
			scanf("%d",&(array[i][j]));
		}
	}
	col1=0;
	col2=col-1;
	row1=0;
	row2=row-1;
	while((row2-row1>0)&&(col2-col1>0))
	{
		for(i1=col1;i1<col2;i1++)
			printf("%d\n",array[row1][i1]);
		for(j1=row1;j1<row2;j1++)
			printf("%d\n",array[j1][col2]);
		for(i2=col2;i2>col1;i2--)
			printf("%d\n",array[row2][i2]);
		for(j2=row2;j2>row1;j2--)
			printf("%d\n",array[j2][col1]);
		col1++;
		col2--;
		row1++;
		row2--;
	}
	if((row2-row1==0)&&(col2-col1!=0))
	{
		for(i=col1;i<=col2;i++)
		{
			printf("%d\n",array[row1][i]);
		}
	}
	if((col2-col1==0)&&(row2-row1!=0))
	{
		for(j=row1;j<=row2;j++)
		{
			printf("%d\n",array[j][col1]);
		}
	}
	if((col2-col1==0)&&(row2-row1==0))
		printf("%d\n",array[row1][col1]);
	return 0;
}
int main()
{
	int i,j,row,col,state;
	int sz[100][100],zt[100][100]={0};
	scanf("%d%d",&row,&col);
	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
		{
			scanf("%d",&sz[i][j]);
		}
	}
	state=0;
	i=0;
	j=0;
	while(1)
	{
		if(zt[i][j]==1)
			break;
		else
		{
			if(state==0&&j+1<col&&zt[i][j+1]==0)
			{
			    printf("%d\n",sz[i][j]);
				zt[i][j]=1;
				j++;
			}
			else if(state==0)
			{
				if(row>1)
				{
					printf("%d\n",sz[i][j]);
				    zt[i][j]=1;
				    i++;
			        state=1;
				}
				else
				{
	                printf("%d\n",sz[i][j]);
					break;
				}
			}
			else if(state==1&&i+1<row&&zt[i+1][j]==0)
			{
				printf("%d\n",sz[i][j]);
				zt[i][j]=1;
				i++;
			}
			else if(state==1)
			{
				if(col>1)
				{
					printf("%d\n",sz[i][j]);
				    zt[i][j]=1;
				    j--;
				    state=2;
				}
				else
				{
                    printf("%d\n",sz[i][j]);
					break;
				}
			}
			else if(state==2&&j-1>=0&&zt[i][j-1]==0)
			{
				printf("%d\n",sz[i][j]);
				zt[i][j]=1;
				j--;
			}
			else if(state==2)
			{
				printf("%d\n",sz[i][j]);
				zt[i][j]=1;
				i--;
				state=3;
			}
			else if(state==3&&i-1>=0&&zt[i-1][j]==0)
			{
				printf("%d\n",sz[i][j]);
				zt[i][j]=1;
				i--;
			}
			else if(state==3)
			{
				printf("%d\n",sz[i][j]);
				zt[i][j]=1;
				j++;
				state=0;
			}
		}
	}
	return 0;
}
/**
????2.cpp
?  ?????
?  ??11.01
?  ??????????
*/
  

int main()
{
	int row, col, a[100][100];
    int i, j, n, num = 0, tot;

	cin >> row >> col; 
	tot = row * col;
	for(i = 0;i < row;i++)
		for(j = 0;j < col;j++)
			cin >> a[i][j];
    
	for(n = 0;n < 1 + row / 2;n++)
	{
		for(i = n;i < col - n;i++)
		{
			cout << a[n][i] << endl;
			num++;
		}
		if(num == tot)break;
		for(j = n + 1;j < row - n;j++)
		{
			cout << a[j][col - n - 1] << endl;
			num++;
		}
		if(num == tot)break;
		for(i = col - 2 - n;i >= n;i--)
		{
			cout << a[row - n - 1][i] << endl;
			num++;
		}
		if(num == tot)break;
		for(j = row - 2 - n;j > n;j--)
		{
			cout << a[j][n] << endl;
			num++;
		}
		if(num == tot)break;

	}
	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;
		for(j=i+1;j<=r-1-i;j++)
		{
			printf("%d\n",a[j][c-i-1]);
			num=num+1;
			
		}
		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;
		for(j=r-i-2;j>=(i+1);j--)
		{
			printf("%d\n",a[j][i]);
			num=num+1;
			
		}
		if(num==k)
				break;
	}
	
}
int main()
{
    int 	arrey [100][100];
	int i, j, k, times, all;
	int row, col;
	
	cin >> row >> col;
	for(i = 0; i < row; i ++)
		for(j = 0; j < col ; j ++)
			cin >> arrey[i][j];
		k = 0;
		times = 0;
		all = row * col;
		do{
			i = k;
			j = k;
			for( ; j <= col - 1; j ++)
			{
				cout <<  arrey[i][j] << endl;
				times ++;
			}
			--j;
			if( times == all)
						break;
		     for(++i ; i <= row - 1;i ++)
					{
				 cout << arrey[i][j] << endl;
						times ++;}
			--i;
			if( times == all)
						break;
					for( --j;j >= k; j --)
					{
						cout << arrey[i][j] << endl;
						times ++;
					}
					if( times == all)
						break;
					++j;
					for(--i ;i > k; i --)
					{
						cout << arrey[i][j] << endl;
						times ++; 
					}
			if( times == all)
						break;
					col --;
					row --;
					k ++;
		}while(1);
			return 0;
}
inline void T(int N,int M,int row,int col,int array[][100])
{
	if (N>row||M>col)
	{
		return;
	}
	for (int j=M;j<=col;j++)
	{
		if (array[N][j]!= INT_MAX)
		{
			cout<<array[N][j]<<endl; 
			array[N][j] = INT_MAX;
		}
	}
	for (int i=N+1;i<=row;i++)
	{
		if (array[i][col]!=INT_MAX)
		{
			cout<<array[i][col]<<endl;
			array[i][col] = INT_MAX;
		}
	} 
	for(int j=col-1;j>=M;j--)
	{
		if (array[row][j]!=INT_MAX)
		{
			cout<<array[row][j]<<endl;
			array[row][j] = INT_MAX;
		}
	}
	for (int i=row-1;i>=N+1;i--)
	{
		if (array[i][M]!=INT_MAX)
		{
			cout<<array[i][M]<<endl;
			array[i][M] = INT_MAX;
		}
	}
	T(N+1,M+1,row-1,col-1,array);
}
int main()
{
	int array[100][100] = {0};
	int row , col;
	cin>>row>>col;
	for (int i=0;i<row;i++)
	{
		for (int j=0;j<col;j++)
		{
			cin>>array[i][j];
		}
	}
	T(0,0,row-1,col-1,array);
	return 0;
}