int main() {
	int row, col;
	scanf("%d%d", &row, &col);
	int data[100][100];
	for(int i = 0; i < row; i++) {
		for(int j = 0; j < col; j++) {
			scanf("%d", &data[i][j]);
		}
	}
	int colLow = 0;
	int rowLow = 0;
	int colHigh = col - 1;
	int rowHigh = row - 1;
	while(rowLow <= rowHigh && colLow <= colHigh) {
		for(int i = colLow; i <= colHigh; i++) {
			printf("%d\n", data[rowLow][i]);
		}
		for(int i = rowLow + 1; i <= rowHigh - 1; i++) {
			printf("%d\n", data[i][colHigh]);
	}
		if(rowHigh != rowLow) {
			for(int i = colHigh; i >= colLow; i--) {
				printf("%d\n", data[rowHigh][i]);
			}
		}
		if(colHigh != colLow) {
			for(int i = rowHigh - 1; i >= rowLow + 1; i--) {
				printf("%d\n", data[i][colLow]);
			}
		}
		colLow++;
		rowLow++;
		colHigh--;
		rowHigh--;
	}
}


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

			}
			if(time==row*col)
				break;
			for(d=row-2-n;d>n;d--)
			{
				printf("%d\n",array[d][n]);
				time++;
			}
			if(time==row*col)
				break;
		}
}


int main(){
    int i,j,row,col,rowmin,rowmax,colmin,colmax;
    int a[100][100];
    scanf("%d%d",&row,&col);
    for(i=1;i<=row;i++){
		for(j=1;j<=col;j++){
			scanf("%d",&a[i][j]);
			}
		}
	rowmax=row;
	rowmin=1;
	colmax=col;
	colmin=1;
	while(1){
		if(rowmax<rowmin||colmax<colmin){break;}
		else if(rowmax==rowmin){for(j=colmin;j<=colmax;j++){printf("%d\n",a[rowmin][j]);}}
		else if(colmax==colmin){for(i=rowmin;i<=rowmax;i++){printf("%d\n",a[i][colmin]);}}
		else{
			for(j=colmin;j<=colmax;j++){printf("%d\n",a[rowmin][j]);}
			for(i=rowmin+1;i<=rowmax;i++){printf("%d\n",a[i][colmax]);}
			for(j=colmax-1;j>=colmin;j--){printf("%d\n",a[rowmax][j]);}
			for(i=rowmax-1;i>rowmin;i--){printf("%d\n",a[i][colmin]);}
			}
		rowmax-=1;
	    rowmin+=1;
	    colmax-=1;
	    colmin+=1;
		}
	return 0;
}


int main(){
	int row, col, matrix[ROW][COL];
	int i, j;
    int xxrow,sxrow,xxcol,sxcol;
	scanf("%d %d", &row, &col);
	for(i = 0; i < row; i++){
		for(j = 0; j < col; j++){
			scanf("%d", &(matrix[i][j]));
		}
	}
	xxrow= 0;
    sxrow= row-1;
    xxcol=0;
    sxcol=col-1;

    while( (xxrow<sxrow) && (xxcol<sxcol) ){
		for(j =xxcol; j <sxcol; j++){
	printf("%d\n", matrix[xxrow][j]);
		}

for(i = xxrow; i < sxrow; i++){
	printf("%d\n", matrix[i][sxcol]);
}

for(j = sxcol; j > xxcol; j--){
	printf("%d\n", matrix[sxrow][j]);
}

for(i = sxrow; i > xxrow; i--){
	printf("%d\n", matrix[i][xxcol]);
}
              xxrow++;
    	      sxrow--;
             xxcol ++;
             sxcol --;

	}
    if((xxrow==sxrow)&&(xxcol<sxcol)){
		for(j=xxcol;j<sxcol+1;j++){
			printf("%d\n",matrix[xxrow][j]);
		}
	}
	else if(xxrow<sxrow&&xxcol==sxcol){
		for(i=xxrow;i<sxrow+1;i++){
			printf("%d\n",matrix[i][xxcol]);
		}
	}
	else if((xxrow==sxrow)&&(xxcol==sxcol)){
		printf("%d\n",matrix[xxrow][xxcol]);
	}

	return 0;
}


void main()
{
	int a[105][105],row,col,min,i,j;
	int n,x;
	scanf("%d %d",&row,&col);
	for(i=1;i<=row;i++) for(j=1;j<=col;j++) scanf("%d",&a[i][j]);
	if(row<=col) min=row; else min=col;
	if(min%2==0) n=min/2; else n=min/2+1;
	for(x=1;x<=n;x++)
	{
		i=x;
		for(j=x;j<=col-x+1;j++) printf("%d\n",a[i][j]);
		if(row==min&&row%2==1&&x==n) break;
		j=col-x+1;
		for(i=x+1;i<=row-x+1;i++) printf("%d\n",a[i][j]);
		if(col==min&&col%2==1&&x==n) break;
		i=row-x+1;
		for(j=col-x;j>=x;j--) printf("%d\n",a[i][j]);
		if(row==min&&row%2==0&&x==n) break;
		j=x;
		for(i=row-x;i>=x+1;i--) printf("%d\n",a[i][j]);
	}
}


int main()
{
	int row,col;
	scanf("%d %d",&row,&col);
	int a[100][100];
	int i,t;
	int count=0;
	for(i=0;i<row;i++)
	{
		for(t=0;t<col;t++)
		{
			scanf("%d",&a[i][t]);
		}
	}

	int k=0,j=0,m=0;
	if(row%2==0)
	{
	for(k=0;k<=(row/2-1);k++)
	{
		for(j=k;j<=(col-1-k);j++)
		{
			printf("%d\n",a[k][j]);
			count++;
		}
		if(count==row*col)
			break;
		for(m=k+1;m<=row-2-k;m++)
		{
			printf("%d\n",a[m][col-1-k]);
			count++;
		}
			if(count==row*col)
			break;

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

		}
			if(count==row*col)
			break;
	}
	}
	else
	{

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

	return 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;
}


/*
 * 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 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;
}


int main()
{int i,e,array[100][100],col,row,n=0;
	scanf("%d %d",&row,&col);
	for(i=0;i<row;i++)
	{	for(e=0;e<col;e++)
			scanf("%d",&array[i][e]);
	}
	i=0;
	while(n<col*row)
	{	for(e=0;e<col;e++)
		{
			if(array[i][e]!=0)
			{	printf("%d\n",array[i][e]);
				array[i][e]=0;
				n++;
			}
		}
		for(e=0;e<row;e++)
		{	if(array[e][col-1-i]!=0)
			{	printf("%d\n",array[e][col-1-i]);
				array[e][col-1-i]=0;
				n++;
			}
		}
		for(e=1;e<=col;e++)
		{	if(array[row-i-1][col-e]!=0)
			{	printf("%d\n",array[row-1-i][col-e]);
				array[row-1-i][col-e]=0;
				n++;
			}
		}
		for(e=1;e<=row;e++)
		{	if(array[row-e][i]!=0)
			{	printf("%d\n",array[row-e][i]);
				array[row-e][i]=0;
				n++;
			}
		}
		i++;

	}
	return 0;
}


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


void main()
{
	int a[105][105];
	int flag=1,loci=0,locj=0,row,col,upwall=0,downwall,rightwall,leftwall=-1,i,j;
	scanf("%d %d",&row,&col);
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			scanf("%d",&a[i][j]);
	rightwall=col;
	downwall=row;
	for(i=1;i<row*col;){
		if(locj+1<rightwall&&flag==1){printf("%d\n",a[loci][locj++]);i++;}
		else if(locj-1>leftwall&&flag==2){printf("%d\n",a[loci][locj--]);i++;}
		else if(loci+1<downwall&&flag==3){printf("%d\n",a[loci++][locj]);i++;}
		else if(loci-1>upwall&&flag==4){printf("%d\n",a[loci--][locj]);i++;}
		else if(locj+1==rightwall&&flag==1){
			rightwall--;
			flag=3;
		}
		else if(locj-1==leftwall&&flag==2){
			leftwall++;
			flag=4;
		}
		else if(loci+1==downwall&&flag==3){
			downwall--;
			flag=2;
		}
		else if(loci-1==upwall&&flag==4){
			upwall++;
			flag=1;
		}
	}
	printf("%d\n",a[loci][locj]);
}


int main(int argc, char *argv[])
{
    int x[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",&x[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++)
    {
//the 1st we will try to output the num in row=0
    for (i=k,j=k;j<col-1-k;j++)//x[0][0]~x[0][col-2]
    {
        printf("%d\n",x[i][j]);
    }
//the 2nd output the num in  col=col-1
    for (i=k,j=col-1-k;i<row-1-k;i++)//x[0][col-1]~x[row-2][col-1]
    {
        printf("%d\n",x[i][j]);
    }

//the 3rd output the num in row=row-1
    for (i=row-1-k,j=col-1-k;j>k;j--)//x[row-1][col-1]~x[row-1][1]
    {
        printf("%d\n",x[i][j]);
    }

//the 4th outoput the num in col=0
    for (i=row-1-k,j=k;i>k;i--)//x[row-1][0]~x[1][0]
    {
        printf("%d\n",x[i][j]);
    }

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

  return 0;
}


int  main()
{
	int row,col,k,j;
	int time=0;
	cin>>row>>col;
	int arr[100][100];
	for(k=0;k<row;k++)
		for(j=0;j<col;j++)
		{
			cin>>arr[k][j];
		}
        int i=0;
	while(time<row*col)
	{

		for(k=i;k<col-i&&time<row*col;k++)
		{
			cout<<arr[i][k]<<endl;
			time++;
		}
		for(k=i+1;k<row-i&&time<row*col;k++)
		{
			cout<<arr[k][col-i-1]<<endl;
			time++;
		}
		for(k=col-i-2;k>=i&&time<row*col;k--)
		{
			cout<<arr[row-i-1][k]<<endl;
			time++;
		}
		for(k=row-i-2;k>i&&time<row*col;k--)
		{
			cout<<arr[k][i]<<endl;
			time++;
		}
		i++;
	}
	return 0;
}


int main()
{
	int row, col, array[100][100], i, j, k, min, flag;
	cin >> row >> col;
	for (i = 1; i <= row; i++)
	{
		for (j = 1; j <= col; j++)
		{
			cin >> array[i][j];
		}
	}

    min = (row < col) ? row : col;
	for (k = 0; 2 * k < min; k++)
	{
		flag = 0;
		for (i = 1 + k; i <= col - k; i++)
			cout << array[1 + k][i] << endl;
		for (j = 2 + k; j <= row - k; j++)
		{cout << array[j][col - k] << endl; flag=1;}
		if(flag)
		{flag=0;
		for (i = col - k - 1; i >= 1 + k; i--)
		{cout << array[row - k][i] << endl;flag=1;}
		if(flag)
		for (j =row - k - 1; j >= 1 + k + 1; j--)
			cout << array[j][1 + k] << endl;
		}
	}
	return 0;
}


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++;
   }
   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)break;
   for (i=col-2-n;i>=n;i--)
   {
    printf("%d\n",array[row-n-1][i]);
    time++;
   }
   if(time==row*col)break;
   for (j=row-2-n;j>n;j--)
   {
    printf("%d\n",array[j][n]);
    time++;
   }
   if(time==row*col)break;
  }

  return 0;
}


int main()
{
	int row,col,array[100][100],sum=0;
	int i,j;
	scanf("%d%d",&row,&col);

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

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


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


int main()
{
	int i,j,k,l,r,c,a[100][100];
	scanf("%d %d",&r,&c);
	for(i=0;i<r;i++)
	{
		for(j=0;j<c;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	l=0;
	k=1;
	if(r==1&&c==1)
		printf("%d",a[0][0]);
	else
	{
	for(j=0;;)
	{
		switch (k)
		{
		case 1: goto p1;break;
		case 2: goto p2;break;
		case 3: goto p3;break;
		case 4: goto p4;
		}
p1:{
		for(i=l;i<c-l;i++)
		{
			printf("%d\n",a[l][i]);
			j++;
			if(j==r*c)
				goto out;
		}
		goto end;
   }
p2:{
		for(i=l+1;i<r-l-1;i++)
		{
			printf("%d\n",a[i][c-l-1]);
			j++;
			if(j==r*c)
				goto out;
		}
		goto end;
   }
p3:{
		for(i=c-l-1;i>=l;i--)
		{
			printf("%d\n",a[r-l-1][i]);
			j++;
			if(j==r*c)
				goto out;
		}
		goto end;
   }
p4:{
		for(i=r-l-2;i>l;i--)
		{
			printf("%d\n",a[i][l]);
			j++;
			if(j==r*c)
				goto out;
		}
		goto end;
   }
end:
	{
		k++;
		if(k>4)
		{
			k=1;
			l++;
		}
	}
	}
	}
out:;
	return 0;
}


int main()
{
	int array[101][101], pos[101][101] = {0};
	int row, col, i, j, count = 0, n;
	cin >> row >> col;
	n = row * col;
	for (i = 0; i < row; i++)
	{
		for (j = 0; j < col; j++)
		{
			cin >> array[i][j];
			pos[i][j] = 1;
		}
	}
	i = 0;
	j = 0;
	while (1)
	{
		while (pos[i][j+1] != 0)
		{
			cout << array[i][j] << endl;
			pos[i][j] = 0;
			j++;
			count++;
		}
		if (count == n - 1) break;
		while (pos[i+1][j] != 0)
		{
			cout << array[i][j] << endl;
			pos[i][j] = 0;
			i++;
			count++;
		}
		if (count == n - 1) break;
		while (j >= 0 && pos[i][j-1] != 0)
		{
			cout << array[i][j] << endl;
			pos[i][j] = 0;
			j--;
			count++;
		}
		if (count == n - 1) break;
		while (i >= 0 && pos[i-1][j] != 0)
		{
			cout << array[i][j] << endl;
			pos[i][j] = 0;
			i--;
			count++;
		}
		if (count == n - 1) break;
	}
	for (i = 0; i < row; i++)
	{
		for (j = 0; j < col; j++)
		{
			if (pos[i][j] == 1)
			{
				cout << array[i][j] << endl;
			}
		}
	}
	return 0;
}


int main()
{    int i ,j ,k,row,col;
     int t = 0 ;
    cin >> row >> col;
    int array[row][col];
    for(i = 0; i <= row - 1;i ++)
    {
      for(j = 0; j <= col - 1; j ++)
       {
           cin >> array[i][j];
       }
     }
     for( k = 0;;k ++  )
     {
       for(j = 0 + k; j <= col - 1 - k; j ++)
       {
          cout << array[k][j] << endl;
          t ++;
          if( t == row *col)
            {  break ;
                }
       }
          if ( t == row*col )
          {
               break;
               }
       for(i = 1 + k; i <= row - 1 - k; i ++)
       {
          cout << array[i][col - 1 - k] << endl;
          t ++;
          if( t == row *col)
            {  break ;
                }
          }
          if( t == row *col)
            {  break ;
                }
       for(j = col - 2 - k; j >= 0 + k; j --)
       {
          cout << array[row - 1 -k][j] << endl;
          t ++;
           if( t == row *col)
            {  break ;
                }
       }
                if( t == row *col)
            {  break ;
                }
       for(i = row - 2 - k; i >= 1 + k; i --)
       {   cout << array[i][0+k] << endl;
          t ++ ;
                   if( t == row *col)
            {  break ;
                }
       }
        if( t == row *col)
            {  break ;
                }
}
       return 0 ;
}


int rt1(int x,int y);
int rt2(int x,int y);
int rt3(int x,int y);
int rt4(int x,int y);
int sz[100][100];
int sr[100][100];
int sc[10000];
int p=0,q=0;
int count=0;
int flag=1;
int main()
{
	int m,n;
	scanf("%d%d",&m,&n);
	int i,j;
	for (i=0;i<100;i++)
	{
		for (j=0;j<100;j++)
		{
			sz[i][j]=1;
		}
	}
    	for (i=0;i<m;i++)
	{
		for (j=0;j<n;j++)
		{
			sz[i][j]=-2;
		}
	}
	for (i=0;i<m;i++)
	{
		for (j=0;j<n;j++)
		{
			scanf("%d",&sr[i][j]);
		}
	}
	sz[0][0]=1;

	int limit=m*n;
	while (count<=limit-1)
	{
		switch (flag%4)
		{
		case 1:
        {
				(p,q)=rt1(p,q);
				count=count+1;
				break;
		}
		case 2:
			{
				(p,q)=rt2(p,q);
				count=count+1;
				break;
		}
		case 3:
			{
			    (p,q)=rt3(p,q);
				count=count+1;
				break;
		}
		case 0:
				{
				(p,q)=rt4(p,q);
				count=count+1;
				break;
		}
	}

}
	for (i=0;i<m*n;i++)
	{

			printf("%d\n",sc[i]);

	}
	return 0;
}
int rt1(int x,int y)
{
	sz[q][p]=sr[q][p];
	sc[count]=sz[q][p];
	p=x+1;
	q=y;
	if (sz[q][p]>0)
		{
		    flag=flag+1;
			p=p-1;
			q=q+1;
		}

	return (p,q);
}
int rt2(int x,int y)
{
	sz[q][p]=sr[q][p];
	sc[count]=sz[q][p];
	p=x;
	q=y+1;
    if (sz[q][p]>0)
	{
		    flag=flag+1;
			q=q-1;
			p=p-1;
		}

	return (p,q);

}
int rt3(int x,int y)
{
	sz[q][p]=sr[q][p];
	sc[count]=sz[q][p];
	p=x-1;
	q=y;
	if (sz[q][p]>0)
	{
		    flag=flag+1;
			p=p+1;
			q=q-1;
		}

	return (p,q);
}
int rt4(int x,int y)
{
		sz[q][p]=sr[q][p];
		sc[count]=sz[q][p];
	p=x;
	q=y-1;
	if (sz[q][p]>0)
	{
		    flag=flag+1;
			q=q+1;
			p=p+1;
		}

	return (p,q);
}


void print(int a[100][100],int row,int col,int b,int c)
{
	int i;
	for(i=c;i<=col;i++)
		printf("%d\n",a[b][i]);
	for(i=b+1;i<=row;i++)
		printf("%d\n",a[i][col]);
	if(row>b)
	for(i=col-1;i>=c;i--)
		printf("%d\n",a[row][i]);
	if(col>c)
	for(i=row-1;i>=b+1;i--)
		printf("%d\n",a[i][c]);
	row--;
	col--;
	b++;
	c++;
	if(row-b>=0&&col-c>=0)
		print(a,row,col,b,c);

}
void main()
{
	int col,row,i,j,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]);
	print(a,row-1,col-1,0,0);
}


int main()
{
    int row,col,i,j,l,p,q,count;
	int a[100][100];
	cin>>row>>col;
	p=(row+1)/2;
	q=(col+1)/2;
	count=0;
	for(i=1;i<=row;i++)
    {
	    for(j=1;j<=col;j++)
		{
		    cin>>a[i][j];
		}
	}
	if(row<=col&&row%2==1)
	{
		for(i=1;i<=row/2;i++)
		{
	        for(j=i;j<=col-i+1;j++)
			 {cout<<a[i][j]<<endl;count++;}
			 for(l=i+1;l<=row-i+1;l++)
             {cout<<a[l][col-i+1]<<endl;count++;}
			 for(j=col-i;j>=i;j--)
			 {cout<<a[row-i+1][j]<<endl;count++;}
			 for(l=row-i;l>=i+1;l--)
			 {cout<<a[l][i]<<endl;count++;}
		}
		for(j=(row+1)/2;j<=col-(row-1)/2;j++)
		{cout<<a[p][j]<<endl;}
	}
	else if(row>col&&col%2==1)
		{
	    for(i=1;i<=col/2;i++)
		{
	        for(j=i;j<=col-i+1;j++)
			 {cout<<a[i][j]<<endl;count++;}
			 for(l=i+1;l<=row-i+1;l++)
             {cout<<a[l][col-i+1]<<endl;count++;}
			 for(j=col-i;j>=i;j--)
			 {cout<<a[row-i+1][j]<<endl;count++;}
			 for(l=row-i;l>=i+1;l--)
			 {cout<<a[l][i]<<endl;count++;}
		}
		for(i=(col+1)/2;i<=row-(col-1)/2;i++)
		{cout<<a[i][q]<<endl;}
		}
	else
	{
	for(i=1;i<=row/2;i++)
	{
	     if(count==row*col)break;
		 else
		 {
		     for(j=i;j<=col-i+1;j++)
			 {cout<<a[i][j]<<endl;count++;}
			 for(l=i+1;l<=row-i+1;l++)
             {cout<<a[l][col-i+1]<<endl;count++;}
			 for(j=col-i;j>=i;j--)
			 {cout<<a[row-i+1][j]<<endl;count++;}
			 for(l=row-i;l>=i+1;l--)
			 {cout<<a[l][i]<<endl;count++;}
		 }
	}
	}
	return 0;
}


int main(int argc, char* argv[])
{
	int row,col,k,e,i,j,min;
	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(col>row){
	min=row;
	}else{
	min=col;
	}
	for(e=0;e<min/2+1;e++){
	for(j=e;j<col-e;j++){
		printf("%d\n",sz[e][j]);
	}if(row%2==1&&e+1>row-2-e){
	break;
	}
	for(i=e+1;i<row-e;i++){
		printf("%d\n",sz[i][col-1-e]);
	}
	if(col%2==1&&e>col-2-e){
	break;
	}
	for(j=col-2-e;j>=e;j--){
		printf("%d\n",sz[row-1-e][j]);
	}

	for(i=row-2-e;i>e;i--){
		printf("%d\n",sz[i][e]);
	}}
	return 0;
}


int main()
{
	int array[100][100], i, j, row, col, num, s, k;
	scanf("%d %d",&row,&col);
	if(row>0 && row<100 && col>0 && col<100)
	{
		for(i=0; i<row; i++)
		{
			for(j=0; j<col; j++)
				scanf("%d",&array[i][j]);
		}

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

		}
	}
	return 0;
}


int main ()
{
	int a[110][110];
	int row, col, i, j, k, h, l, count, hzz, lzz; // h ?row l? col
	cin >> row >> col;
	for (i = 1; i <= row; i++)
	{
		for (j = 1; j <= col; j++)
		{
			cin >> a[i][j];
		}
	}
	// ??? ???i? ? i ??? lzz?? ??i????? row - i + 1 ? col - ?i - 1?
	// ?lzz?i ? ????i??? col - i + 1?
	// ?hzz?j ? ????j++??? row - j + 1?
	// ?lzz?col - i + 1??lzz-- ??? col - hzz + 1?
	// ?hzz?j? ? hzz???  row - hzz + 2 ?
    // ?????????????
	count = 0;
	h = row;
	l = col;
	hzz = 1;
	lzz = 1;
	i = 1;
	j = 1;
	while (count <= row * col)
	{
		for (lzz = j; lzz <= col - (j - 1); lzz++)   //???????
		{
			cout << a[i][lzz] << endl;
			count++;
			if (count == row * col) return 0;
		}
		j = lzz - 1;   //?????????lzz+1
		for (hzz = i + 1; hzz <= row - i + 1; hzz++) // ?????
		{
			cout << a[hzz][j] << endl;
			count++;
        	if (count == row * col) return 0;
		}
		i = hzz - 1;
		for (lzz = j - 1; lzz >= col - j + 1; lzz--)
		{
			cout << a[i][lzz] << endl;
			count++;
	        if (count == row * col) return 0;
		}
		j = lzz + 1;
		for (hzz = i - 1; hzz >= row - i + 2; hzz--)
		{
			cout << a[hzz][j] << endl;
            count++;
	        if (count == row * col) return 0;
		}
		j = j + 1;
		i = hzz + 1;
	}
	return 0;
}


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


int main()
{
    int row,col;
    int i,j,n,time=0;
    scanf("%d%d",&row,&col);
    int array[R][C];
    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-1;i++)
  {
   printf("%d\n",array[n][i]);
   time++;
  }
  if(time==row*col) break;
  for(j=n+1;j<=row-n-1;j++)
  {
   printf("%d\n",array[j][col-n-1]);
   time++;
  }
  if(time==row*col) break;
  for(i=col-n-2;i>=n;i--)
  {
   printf("%d\n",array[row-n-1][i]);
   time++;
  }
  if(time==row*col) break;
  for(j=row-n-2;j>=n+1;j--)
  {
   printf("%d\n",array[j][n]);
   time++;
  }
  if(time==row*col) break;
 }
 return 0;
}


int rp,re,lp,le;
int a[300][300];
int print(int rp,int re,int lp,int le,int r,int l)
{
	int i,j;
	if(rp>re||lp>le) return 0;
	if(l==lp&&r==rp)
	{
		for(i=rp,j=lp;j<=le;j++)
			printf("%d\n",a[i][j]);
		print(rp+1,re,lp,le,rp+1,le);
		return 0;
	}
	if(l==le&&r==rp)
	{
		for(i=rp,j=le;i<=re;i++)
			printf("%d\n",a[i][j]);
		print(rp,re,lp,le-1,re,le-1);
		return 0;
	}
	if(l==le&&r==re)
	{
		for(i=re,j=le;j>=lp;j--)
			printf("%d\n",a[i][j]);
		print(rp,re-1,lp,le,re-1,lp);
		return 0;
	}
	if(l==lp&&r==re)
	{
		for(i=re,j=lp;i>=rp;i--)
			printf("%d\n",a[i][j]);
		print(rp,re,lp+1,le,rp,lp+1);
		return 0;
	}
}
int main()
{

	int r,l;
	scanf("%d %d",&r,&l);
	int i,j;
	for(i=1;i<=r;i++)
		for(j=1;j<=l;j++)
			scanf("%d",&a[i][j]);
	rp=1;
	lp=1;
	re=r;
	le=l;
	print(rp,re,lp,le,1,1);
	return 0;
}


int array[99][99];
int x, y, row, col;
void out(int x0, int y0, int wid, int len)
{
	x = x0;
	y = y0;
	for (; x < x0 + wid; x++)
	{
		cout << array[x][y] << endl;
	}
	x--;
	for (y++; y < y0 + len; y++)
	{
		cout << array[x][y] << endl;
	}
	y--;
	for (x--; x >= x0; x--)
	{
		if (wid == 1)
		{
			break;
		}
		if (len == 1)
		{
			break;
		}
		cout << array[x][y] << endl;
	}
	x++;
	for (y--; y > y0; y--)
	{
		if (wid == 1)
		{
			break;
		}
		if (len == 1)
		{
			break;
		}
		cout << array[x][y] << endl;
	}
	y++;
	if (wid <= 2 || len <= 2)
	{
		1;
	}
	else
	{
		out(x0 + 1, y0 + 1, wid - 2, len - 2);
	}
}

int main()
{
	cin >> row >> col;
	for (y = 0; y < row; y++)
	{
		for (x = 0; x < col; x++)
		{
			cin >> array[x][y];
		}
	}
	out(0, 0, col, row);
	return 0;
}


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


void circle(int list[][100], int row_min, int row_max, int col_min, int col_max)
{
  int i,j;
  if (row_min==row_max || col_min==col_max) {
    for (i=col_min; i<col_max; i++) {
      printf("%d\n",list[row_min][i]);
    }
    for (i=row_min; i<=row_max; i++) {
      printf("%d\n",list[i][col_max]);
    }
  } else {
    for (i=col_min; i<col_max; i++) {
      printf("%d\n",list[row_min][i]);
    }
    for (i=row_min; i<row_max; i++) {
      printf("%d\n",list[i][col_max]);
    }
    for (i=col_max; i>col_min; i--) {
      printf("%d\n",list[row_max][i]);
    }
    for (i=row_max; i>row_min; i--) {
      printf("%d\n",list[i][col_min]);
    }
  }
}

int main()
{
  int array[100][100];
  int i,j;
  int sumrow,sumcol;
  scanf("%d %d",&sumrow,&sumcol);
  for (i=0; i<sumrow; i++) {
    for (j=0; j<sumcol; j++) {
      scanf("%d",&array[i][j]);
    }
  }

  int row_min=0, row_max=sumrow-1, col_min=0, col_max=sumcol-1;

  while (row_min<=row_max && col_min<=col_max) {
    circle(array, row_min, row_max, col_min, col_max);
    row_min++;
    row_max--;
    col_min++;
    col_max--;
  }

  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 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 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 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;
}


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 n,t,m;
     scanf("%d\n",&n);
     int sz[n];
     for(int i=1;i<=n;i++){
         scanf("%d",&(sz[i]));
     }
     for(int i=n;i>1;i--){
         printf("%d ",sz[i]);
     }
     printf("%d",sz[1]);
     return 0;
 }


int main()
{
	void inv(int array[ ],int k);
	int i,n,a[100],*p;
	scanf("%d",&n);
	for(p=a;p<a+n;p++)
		scanf("%d",p);
	inv(a,n);
	printf("%d",*a);
	for(p=a+1;p<a+n;p++)
        printf(" %d",*p);
}

    void inv(int array[ ],int k)
	{
		int temp,j,m;
        m=k/2;
		for(j=0;j<m;j++)
		{
			temp=*(array+k-j-1);
			*(array+k-j-1)=*(array+j);
			*(array+j)=temp;
		}
		return;
	}


int main(){
    int sz[100];
    int n;
    int e;
    int a,b;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
            scanf("%d",&(sz[i]));}
    b=n/2;
    for(int k=0;k<b;k++){
            a=n-k-1;
            e=sz[a];
            sz[a]=sz[k];
            sz[k]=e;
            }

    for(int i=0;i<n;i++){
            printf("%d",sz[i]);
            if(i<n-1){printf(" ");
            }
            }
    return 0;

    }


int function(int* a,int n)
{
	if(n!=1)
	function(a+1,n-1);
	cout<<a[0]<<' ';
	return 0;
}

int main()
{
	int n,a[100];
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	function(a+1,n-1);
	cout<<a[0];
	return 0;
}


int main(){
	int n;
	cin>>n;
	int a[100];
	int *p=a,*q=a;
	for(;p<a+n;p++)
		cin>>*p;
	int temp;
	for(p--;q<p;q++,p--)
	{
		temp=*q;
		*q=*p;
		*p=temp;
	}
	p=a;
	cout<<*p++;
	for(;p<a+n;p++)
		cout<<" "<<*p;
}


/*
 * reverse.cpp
 *
 *  Created on: 2012-10-26
 *      Author: 12001
 */

int main()
{
	int n;
	int a[100];
	cin >> n;
	for (int i=0;i<n;i++){
		cin >> a[i];
	}
	for (int i=0;i<n/2;i++){
		int tmp=a[i];
		a[i]=a[n-1-i];
		a[n-1-i]=tmp;
	}
	for (int i=0;i<n;i++){
		cout << a[i];
		if (i==n-1)
			cout << endl;
		else
			cout << ' ';
	}
	return 0;
}


int main(){
int n,k;
int i;
int sz[100];
scanf("%d",&n);
i=0;
k=n-1;
while(i<n){
scanf("%d",&sz[i]);
i++;
}
while(k>=0){
    if(k!=0){
    printf("%d ",sz[k]);}
    else{printf("%d",sz[k]);}
    k--;
}
return 0;
}


int main(){
	int n,i,e;
	scanf("%d",&n);
	int sz[101];
	i=0;e=n-1;
	while(i<n){
		scanf("%d",&sz[i]);
		i++;
	}
	while(e>0&&e<n){
		printf("%d ",sz[e]);
		e--;
}
printf("%d",sz[e]);

	return 0;
}


int mark=0;
int main()
{
    int sum;
	void print(int);
	cin>>sum;
	print(sum-1);
	return 0;
}
void print(int num)
{
	int temp;
	cin>>temp;
	if(num==0)
	{
		mark=1;
		cout<<temp;
		return;
	}
	else
		print(num-1);
    if(mark)
		cout<<" "<<temp;

}


int main(int argc, char* argv[])
{
int n;
scanf("%d",&n);
int a[100];
int i;
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
for(i=n-1;i>0;i--){
printf("%d ",a[i]);
}
printf("%d\n",a[i]);
	return 0;
}


int main()
{
int i,n;
int num [100];
scanf("%d",&n);
i=0;
while(i<n){
	scanf("%d",&num [i]);
	i++;
}
i=n-1;
while(i>0){
	printf("%d ",num [i]);
	i--;
}
printf("%d",num [0]);
return 0;
}


int main()
{
	void nixu(int,int a[]);
	int i,a[100]={0},n;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	nixu(n,a);
	return 0;
}

void nixu(int n,int a[])
{
	if(n==1) cout<<a[0];
	else
	{
	cout<<a[n-1]<<' ';
	nixu(n-1,a);
	}
}


void NX();
int n;
int sz[100],nx[100];
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&sz[i]);
    }
    NX();
    for(int i=0;i<n;i++){
        if(i<n-1){
        printf("%d ",nx[i]);
        }else{
            printf("%d",nx[i]);
        }
    }
    return 0;
}
void NX(){
    int j;
    j=0;
    for(int i=n-1;i>=0;i--){
        nx[j]=sz[i];
        j++;
    }
}


void get(int);
int i=1;
int main()
{
	int n;
	cin>>n;
	get(n);
	return 0;
}
void get(int n)
{
  int a,m;
  cin>>a;i++;
  if(i<n)get(n);
  else if(i==n){cin>>m;cout<<m;}
  cout<<" "<<a;
}


int main(void)
{
	int a[100],n;
	cin >>n;
	for (int i=0;i<=n-1;i++)
	{
		cin >>a[i];
	}
	for (int i=n-1;i>=0;i--)
	{
		cout <<a[i];
		if (i!=0) cout <<" ";
	}
	return 0;
}


int main()
{
	int a[100],n,i,count=0;
	int *pt=a;
	scanf("%d",&n);
	for(i=0;i<n;i++,pt++)
		scanf("%d",pt);
	for(i=n-1;i>=0;i--)
	{
		if(count==0)
		{
			printf("%d",*(a+i));
			count++;
		}
		else
			printf(" %d",*(a+i));
	}
	printf("\n");
	return 0;
}


int main(int argc, char* argv[])
{
	int i,n,t;
	int *p;
	p=(int *)malloc(sizeof(int)*100);
	scanf("%d",&n);
	for (i=0;i<n;i++)
	{
		scanf("%d",&t);
        *(p+i)=t;
	}
	printf ("%d",*(p+n-1));
	for (i=n-2;i>=0;i--)
	{
		printf(" %d",*(p+i));
	}
	free(p);
	return 0;
}


int a[110],m;
void f(int n)
{

    if(n==1)
   {
            cout<<a[m-1];

    }
   else
   {
       f(n-1);
      cout<<" "<<a[m-n];
   }
}
int main()
{

    cin>>m;
    for(int i=0;i<m;i++)
    {
        cin>>a[i];

    }
   f(m);

return 0; }


int main(int argc, char* argv[])
{
	int n,i,b;
	scanf("%d",&n);
	int a[1000];
	for(i=1;i<=n;i++)
	{
		scanf("%d",&b);
		a[i]=b;
	}
	for(i=n;i>1;i--)
	{
		b=a[i];
		printf("%d ",b);
	}
	b=a[1];
	printf("%d",b);
	return 0;
}


void main()
{
	int *a,i,j,k,m,n,*p;
	scanf("%d",&n);
	a=(int *)malloc(n*sizeof(int));
	p=(int *)malloc(n*sizeof(int));
	for(i=0;i<n;i++)
		scanf("%d",(a+i));

	for(i=n-1,j=0;i>-1,j<n;i--,j++)
		*(p+j)=*(a+i);
	printf("%d",*p);
	for(j=1;j<n;j++)
		printf(" %d",*(p+j));

}


void main()
{
	int i,j,n,*num,t;
	scanf("%d",&n);
	t=n/2;
	num=(int*) malloc (sizeof(int)*n);
	for (i=0;i<n;i++)
		scanf("%d",&num[i]);
	for (i=0;i<t;i++)
	{
		j=num[i];
		num[i]=num[n-1-i];
		num[n-1-i]=j;
	}
	for (i=0;i<n;i++)
	{
		printf("%d",num[i]);
		if(i<n-1) printf(" ");
	}
	free(num);
}


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

int main(){
    int n,line[150];

    cin>>n;
    for (int i=0; i<n; i++) {
        cin>>line[i];
    }
    int * p_1=line;
    for (int i=0; i<=((int)n/2)-1; i++) {
        swap(*(p_1+i), *(p_1+n-i-1));
    }
    cout<<* (p_1);
    for (int j=1; j<n; j++) {
        cout<<' '<<* (p_1+j);
    }
    return 0;
}


//
//  main.cpp
//  nixu
//
//  Created by blues cookie on 12-12-9.
//  Copyright (c) 2012? blues cookie. All rights reserved.
//

int main(int argc, const char * argv[])
{
    int n,i,j,k;
    cin>>n;
    int a[n+3];
    int *p=a;
    for(i=0;i<n;i++) cin>>a[i];//????
    for(i=0;i<n/2;i++)//??
    {
        j=*(p+i);
        *(p+i)=*(p+n-i-1);
            *(p+n-i-1)=j;
    }
    for(i=0;i<n-1;i++) cout<<*(a+i)<<' ';
    cout<<*(a+n-1);
    return 0;

}


int main()
{
    int a[100]={0};
    int n,i;
    cin>>n;
    int *p=a;
    for(i=n-1;i>=0;i--)
    cin>>a[i];
    for(p=a;p<a+n-1;p++)
    cout<<*p<<" ";
    cout<<a[n-1];
    getchar();
    getchar();
    return 0;
}


int main()
{
    int num[1000],rev_num[1000];
    int n,m,i;
    cin>>n;
    m=n-1;
    for (i=0;i<n;i++)
        cin>>num[i];
    for (i=0;i<n;i++)
        rev_num[m--]=num[i];
    for (i=0;i<n-1;i++)
        cout<<rev_num[i]<<" ";
        cout<<rev_num[i];

        return 0;
}


int main(int argc, char *argv[])
{
    int n,i;
    scanf("%d",&n);
    int a[n];
    for(i=1;i<=n;i++)
    scanf("%d",&a[i-1]);
    for(i=n-1;i>=1;i--)
    printf("%d ",a[i]);
    printf("%d",a[0]);

    return 0;
}


int main()
{
int n;
cin>>n;
int a[n],b[n];
for(int i=0;i<n;i++)
{cin>>a[i];}
for(int j=0;j<n;j++)
{
	b[j]=a[n-j-1];
}
cout<<b[0];
for(int k=1;k<n;k++)
{cout<<" "<<b[k];}
	return 0;
}


void main()
{
	void change(int *a,int n);
	int i,n,a[100],*p=a;
	scanf("%d",&n);
	for(i=0;i<n;i++,p++)
		scanf("%d",p);
	printf("\n");
	p=a;
	change(p,n);
	for(p=a;p<a+n-1;p++)
		printf("%d ",*p);
	printf("%d",*p);
}

void change(int *a,int n)
{
	int *i,*p,*j,m,temp;
	m=(n-1)/2;
	p=a+m;
	i=a;
	j=i+n-1;
	for(;i<=p;i++,j--)
	{
		temp=*i;
		*i=*j;
		*j=temp;
	}

}


int main(){
     int shur[100],shu[100];
     int n,i;
     scanf("%d",&n);
      for(i=0;i<=n;i++){
scanf("%d",&shur[i]);
shu[n-i]=shur[i];
}
for(i=1;i<=n;i++){
if(i==n){printf("%d",shu[i]);break;}
printf("%d ",shu[i]);
}
return 0;
}


int main()
{
	int n=0;
    scanf("%d",&n);
	int sz[100];
	int x;
	for(int i=0;i<n;i++){
		scanf("%d",&x);
	    sz[i]=x;}
	for(int j=n-1;j>=0;j--){
		if(j!=0)
		{
			printf("%d ",sz[j]);
		}
		else
		{
			printf("%d",sz[j]);
		}
	}
	return 0;
}


int main()
{
int n;
scanf ("%d",&n);
int shuzu[n],Shuzu[n];
for(int k=0;k<n;k++)
scanf ("%d",&shuzu[k]);
for(int i=0;i<n;i++)
Shuzu[i]=shuzu[n-1-i];
for (int r=0;r<n-1;r++)
printf ("%d ",Shuzu[r]);
printf ("%d",Shuzu[n-1]);
return 0;
}


int main(){

int n,*m,i,j,tmp;
scanf("%d",&n);
m=(int *)malloc(sizeof(int)*n);

for(i=0;i<n;i++){
scanf("%d",m+i);
}
for(i=0,j=n-1;i<j;i++,j--){
tmp=m[i];
m[i]=m[j];
m[j]=tmp;
}
printf("%d",m[0]);
for(i=1;i<n;i++){
printf(" %d",m[i]);
}
return 0;
}


int main() {
	int n;
	cin >> n;
	int a[n],b[n];
	for(int i=0;i<n;i++)
	cin >> a[i];
	for(int i=0;i<n;i++)
	{
      b[i]=a[n-1-i];
      if(i==0)
	  cout << b[i];
	  if(i>0)
	  cout << " " << b[i];
    }
	return 0;
}


void diverse( int x )//??
{
	int c , p = x ;
	char ch ;
	cin >> c ;
	cin.get( ch ) ;
	if ( ch == '\n' )
	{
		cout << c ;
		if ( x != 0 )
			cout << ' ' ;
		return ;
	}
	else
	{
		p++ ;
		diverse( p ) ;
	}
	cout << c ;
	if ( x != 0 )
		cout << ' ' ;
}
int main()
{
	int n ;
	cin >> n ;
	cin.get() ;//???
	int x = 0 ;
	diverse( 0 ) ;
	return 0 ;
}


void reverse(int *p,int n)
{
	int temp,i,j;
	for(i=0,j=n-1;i<j;i++,j--)
	{
		temp=*(p+i);
		*(p+i)=*(p+j);
		*(p+j)=temp;
	}
}

void main()
{
	int n,i,*p;
	scanf("%d",&n);
	p=(int *)malloc(sizeof(int));
	for(i=0;i<n;i++)
		scanf("%d",p+i);
	reverse(p,n);
	for(i=0;i<n;i++)
	{
		printf("%d",*(p+i));
		if(i!=n-1)
			printf(" ");
		else
			printf("\n");
	}
}


void main()
{
	int i,n;
	int a[100];
	scanf("%d",&n);
	int* p=a;
	for(i=0;i<n;i++)
		scanf("%d",p++);
	int* q=a;
	p--;
	int *end=p;
	while(q<=p)
	{
		int temp=*p;
		*p=*q;
		*q=temp;
		q++;
		p--;
	}
	p=a;
	printf("%d",*(p++));
	for(;p<=end;p++)
		printf(" %d",*p);
}


/*
Name:???
ID:1200012842
Email:443972553@qq.com
*/
void swap(int *data,int a,int b)
{
     int t=data[a];
     data[a]=data[b];
     data[b]=t;
     }
int main()
{
    int n;
    cin>>n;
    int data[101];
    for (int i=0;i<n;i++)
        cin>>data[i];
    for (int i=0;i<n/2;i++)
        swap(data,i,n-1-i);
    cout<<data[0];
    for (int i=1;i<n;i++)
        cout<<' '<<data[i];
    return 0;
    }


/*ÎÒÕæÏëÖ±½Ó·´×ÅÊä³öÁË¡¡µ«ÊÇÄÇÌ«²»µÀµÂÁËÍÛ¹þ¹þ¹þ*/
int main()
{
	int tmp,t,n,a[100];
	cin>>n;
	t=n/2-1;
	for (int i=0; i<=n-1; ++i) cin>>a[i];
	for (int i=0; i<=t; ++i)
	{
		tmp=a[n-1-i];
		a[n-1-i]=a[i];
		a[i]=tmp;
	}
	cout<<a[0];
	for (int i=1; i<=n-1; ++i) cout<<' '<<a[i];
	return 0;
}


int main() {
	int n=0;
	cin>>n;
	int a[n];
	for(int i=1;i<=n;i=i+1)
		cin>>a[n+1-i];
	cout<<a[1];
	for(int j=2;j<=n;j=j+1)
		cout<<" "<<a[j];
	return 0;
}


int main()
{
	int n=0,i=0,j=0,p=0;
	int arrey[100]={0};
	cin>>n;
	for(i=0;i<n;i++)
		cin>>arrey[i];
	for(i=0,j=n-1;i<j;i++,j--)
	{
		p=arrey[i];
		arrey[i]=arrey[j];
		arrey[j]=p;
	}
	for(i=0;i<n-1;i++)
		cout<<arrey[i]<<" ";
	cout<<arrey[n-1]<<endl;
	return 0;
}


int main()
{
	int n=0,i=0,temp=0;
	cin>>n;
	int a[n];
	for(i=0;i<n;i++)
		cin>>a[i];
	for(i=0;i<floor(n*0.5);i++)
	{
		temp=a[n-1-i];
		a[n-1-i]=a[i];
		a[i]=temp;
	}
	for(i=0;i<n;i++)
	{
		if(i<n-1)cout<<a[i]<<' ';
		else cout<<a[i]<<endl;
	}
	return 0;
}


int main()
{
	int n,i;
	cin>>n;
	int x[n+1];
	for(i=n;i>=1;i--)
	cin>>x[i];
	for(i=1;i<n+1;i++)
	{
		if(i==1)
		cout<<x[i];
		else
		cout<<" "<<x[i];
	}
	return 0;
}


int main()
{
	int n,i;
	int A[100];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		A[i]=a;
	}
	for(i=n-1;i>=0;i--){
		if(i>0)
		printf("%d ",A[i]);
		else
			printf("%d",A[i]);
	}
	return 0;
}


int main()
{
	int n;
	int a[100];
	scanf("%d",&n);
	for (int i=0; i<n; i++)
	{
		scanf("%d",&a[i]);
	}
	while (n--)
	{
		printf("%d",a[n]);
		if (n!=0)
		{
			printf(" ");
		}
	}
	return 0;
}


void main()
{
	int i,n,*a,*b;
	scanf("%d",&n);
	a=(int*)malloc(sizeof(int)*n);
	b=(int*)malloc(sizeof(int)*n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(i=0;i<n;i++)
		b[i]=a[n-i-1];
	for(i=0;i<n-1;i++)
		printf("%d ",b[i]);
	printf("%d\n",b[n-1]);
	return;
}


int main(int argc, char* argv[])
{
	int n,i;
	scanf("%d",&n);
	int m[NUMBER];
	for(i=0;i<n;i++){
	scanf("%d",&m[i]);
	}
	int q;
	printf("%d",m[n-1]);
	for(q=n-2;q>=0;q--){
	printf(" %d",m[q]);
	}
	return 0;
}


int main()
{
    int *p=NULL;
    int n;
    int init[100];
    cin>>n;
    cin>>init[0];
    p=&init[0];

    for(int i=1; i<n ;i++)
    cin>>*(p+i);

    for(int i=1;i<n;i++)
    cout<<*(p+n-i)<<' ';
    cout<<*p;

    return 0;
}


void invert(int ip[],int n)
{

    int i;
    int s=1;

    for(i=0;i<n;i++)
    {
        if(s==1){printf("%d",ip[n-1-i]);s=0;}
        else{printf(" %d",ip[n-1-i]);}

    }
    return;

}

int main() {

    int n;
    scanf("%d",&n);
    int ip[n];
    int i;
    for(i=0;i<n;i++)
    {
        scanf("%d",&(ip[i]));
    }
    invert(ip,n);

    return 0;
}


int print();
int main()
{
	int m;
	char c;
	cin>>m;
	c=cin.get();
	print();
	return 0;
}
int print()
{
	int a;
	char c='\0';
	cin>>a;
	c=cin.get();
	if(c!='\n')
		print();
	if(c!='\n')
		cout<<c;
	cout<<a;
	return 0;
}


void Exchange(int A[],int n);

int main(){
    int n;
    scanf("%d",&n);
    int A[n];
    Exchange(A,n);
    return 0;
}

void Exchange(int A[],int n){
    for(int i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    printf("%d",A[n-1]);
    for(int j=n-2;j>=0;j--){
        printf(" %d",A[j]);
    }
}


int a[10000];
int p;
void oppo(int n);
void printa(int n);
int main(){
	int n;
	scanf("%d",&n);
	oppo(n);
	printa(n);
	return 0;
}

void oppo(int n){
	for(int i1=0;i1<n;i1++){
		scanf("%d",&(a[i1]));
	}
	for(int i2=0;i2<n;i2++){
		for(int j=0;j<n-i2-1;j++){
			p=a[j];a[j]=a[j+1];a[j+1]=p;
		}
	}
}

void printa(int n){
	for(int i3=0;i3<n;i3++){
		if(i3==0){
			printf("%d",a[i3]);
		}else{
		printf(" %d",a[i3]);
		}
	}
}


int main(void)
{
int i,n;
scanf("%d\n",&n);
int num[n];
for(i=0;i<n;i++)
scanf("%d",&num[i]);
for(i=1;i<n;i++)
printf("%d ",num[n-i]);
printf("%d",num[0]);
return 0;
}


/*
 *???: reverse_array.cpp
 *??: ???
 *????: 2012-12-09
 *??: ????
 */

int main()
{
	int n;
	int array[MAXN];
	int *begin,*end; //??????

	cin >> n;
	for (int i=0;i<n;i++)
		cin >> array[i];
	begin=array; end=array+n-1;
	while (begin<end){
		int tmp = *begin;
		*begin = *end;
		*end = tmp;
		begin++;
		end--;
	}
	for (int i=0;i<n;i++){
		if (i) cout << ' ';
		cout << array[i];
	}
	cout << endl;
	return 0;
}


int main()
{
	int a[100];
	int n;
	int *p=a;
	cin>>n;
	for(;p<a+n;p++)
		cin>>*p;
	for(p=a+n-1;p>a;p--)
		cout<<*p<<" ";
	cout<<*p;

}


int main()
{
	int n;cin>>n;
	int a[n];int tr,i;
	for( i=0;i<n;i++)cin>>a[i];
	i--;
	for(int j=0;j<i;j++,i--)
	{
		tr=a[j];a[j]=a[i];a[i]=tr;
	}
	for( i=0;i<n;i++){
		if(i==0)cout<<a[i];
		else cout<<" "<<a[i];
	}
return 0;
}


int main()
{
    int i;
    int n;
    int buf;
    int *array;
    scanf("%d", &n);
    array = (int *)malloc(n * sizeof(int));
    for (i = 0; i < n; i++) {
        scanf("%d", array + i);
    }
    for (i = n - 1; i >= 0; i--) {
        if (i != n - 1) {
            printf(" ");
        }
        printf("%d", *(array + i));
    }
    return 0;
}


void main()
{
	struct number
	{
		int num;
		struct number * next;
	};
	struct number * head=0,* p;
	int n,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		p=(struct number *)malloc(sizeof(struct number));
		scanf("%d",&p->num);
		if(i==1)p->next=0;
		else p->next=head;
		head=p;
	}
	if(head!=0)
	{
		for(i=1;i<=n;i++)
		{
			printf("%d",p->num);
			if(i<n)printf(" ");
			else printf("\n");
			p=p->next;
		}
	}
}


int main()
{
	int n,e,sz[100];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&sz[i]);
	}
	for(int k=1;k<=n;k++){
	for(int i=0;i<n-k;i++){
		e=sz[i];
		sz[i]=sz[i+1];
		sz[i+1]=e;
	}
	}
	for(int j=0;j<n;j++){
		if(j<n-1)
			printf("%d ",sz[j]);
		else
			printf("%d",sz[j]);
	}
	return 0;
}


int main(int argc, char* argv[])
{
	int yuan[100];
	int xin[100];
	int n,i,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&yuan[i]);
	for(i=1;i<=n;i++)
	{
       j=n-i+1;
	   xin[j]=yuan[i];
	}
	printf("%d",xin[1]);
	for(j=2;j<=n;j++)
	printf(" %d",xin[j]);
	return 0;
}


int main()
{
	int n;
	scanf("%d",&n);
	int a[100];
	for(int i=0;i<n;i++)
	{
		int x;
		scanf("%d",&x);
		a[i]=x;
	}
	int *pi=a;
	int *pj=a+n;
	int t;
	for(;pi<pj;pi++,pj--)
	{
		t=*pi;
		*pi=*pj;
		*pj=t;
	}
	for(int k=1;k<n;k++)
	{
		printf("%d ",a[k]);
	}
         printf("%d",a[n]);
	return 0;
}


int main()
{
	int n;
	cin >> n;				//n?????
	int first [100] = {0};
	for (int i = 0;i <= n-1;i++)
	{
		cin >> first[i];
	}
	for (int i = 0;i <= n-1;i++)
	{
		if (i != n-1)
			cout << first[n-1-i] <<" ";
		else
			cout << first[n-1-i];
	}
	cin.get();
	cin.get();
	return 0;
}


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

	cout << a[n-1];
	for (i = n-2; i >= 0; i--)
		cout <<' '<<a[i];

	cout << endl;

	return 0;
}


int main() {
	int N;
	cin >>N;
	const int n=N;
	int a[n];
	for (int i=0;i<=n-1;i++)
	{
		cin >>a[i];
	}
	int b[n];
	for (int i=0;i<=n-1;i++)
	{
		b[i]=a[n-i-1];
	}
	for (int i=0;i<=n-1;i++)
	{
		cout <<b[i];
		if (i<n-1)
			cout <<" ";
	}
	return 0;
}


void reverse(int n)
{
    if(n>0)
    {
        int c;
        char d;
        cin>>c;
        d=getchar();
        reverse(n-1);
        cout<<d<<c;}
}
int main()
{
    int n;
    cin>>n;
    reverse(n);
    return 0;
}


int main(){
	int n;
	int number[NUMBER];
	scanf("%d", &n);
	int i=0;
	int a;
	while(i<n){
		scanf("%d", &a);
		number[i]=a;
		i++;
	}
	while((n-1)>=0){
		if((n-1)>0){
			printf("%d ", number[n-1]);
		n--;
		}
		else{
			printf("%d", number[0]);
			n--;
		}
	}
	return 0;
	scanf("%d",1);
}


int main(int argc, char* argv[])
{
int n,i;
scanf("%d",&n);
int sz[100];
for(i=1;i<=n;i++){
	if(i<n){
		scanf("%d ",&sz[i]);
	}else{
		scanf("%d",&sz[i]);
	}
}
for(i=n;i>=1;i--){
    if(i>1){
		printf("%d ",sz[i]);
	}else{
		printf("%d",sz[i]);
	}
}

   return 0;
}


int main()
{
 int n,i,num[100],result[100];
 cin>>n;
 for (i=0;i<n;i++)
 {
  cin>>num[i];
 }
 for (i=0;i<n;i++)
 {
  result[n-1-i]=num[i];
 }
 for (i=0;i<n-1;i++)
 {
  cout<<result[i]<<" ";
 }
 cout<<result[i]<<endl;
 return 0;
}


int main()
{
	int n,i;
	scanf("%d",&n);
	int *sz=(int*)malloc(sizeof(int)*n);
	int *sf=(int*)malloc(sizeof(int)*n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&sz[i]);
		sf[n-1-i]=sz[i];
	}
	for(i=0;i<n;i++)
	{
		if(i<n-1)
		{
			printf("%d ",sf[i]);
		}
		if(i==n-1)
		{
			printf("%d",sf[i]);
		}
	}
	return 0;
}


int main()
{
    int n,i;
    scanf("%d",&n);
     int *Stack= (int *)malloc(n*sizeof(int));
     for(i=0;i<n;i++) scanf("%d",Stack+i);
     for(i=n-1;i>=0;i--){if(i==0)printf("%d",*(Stack+i));else printf("%d ",*(Stack+i));}
     return 0;

}


void main()
{
	void inv(int x[],int b);
	int n;
	scanf("%d",&n);
    int i,a[100];
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	inv(a,n);
	for(i=0;i<n-1;i++)
	{	printf("%d ",a[i]); }
	printf("%d",a[n-1]);
}
void inv(int x[],int b)
{
	int temp,i,j,m=b/2;
	for(i=0;i<m;i++)
	{
		j=b-1-i;
		temp=x[i];x[i]=x[j];x[j]=temp;
	}
	return;
}


void nixu(int a[],int n)
{
	for(int i=n-1;i>0;i--)
	{
		cout<<a[i]<<" ";
	}
	cout<<a[0];
}
int main()
{
	int n;
	cin>>n;
	int a[100];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		cin.get();
	}
	nixu(a,n);
	return 0;
}


/*
 * nb.cpp
 *
 *  Created on: 2013-12-5
 *      Author: de
 */
int main(){
int n,i,t;
cin>>n;
int a[n];
for(i=0;i<n;i++)cin>>a[i];
int *p=NULL,*q=NULL;
p=a;
for(p=a,q=a+n-1;p<q;p++,q--)
{
t=*p;
*p=*q;
*q=t;
}
p=a;
cout<<*p;
for(p=a+1;p<a+n;p++)
cout<<" "<<*p;
return 0;
}


int main()
{
   int n;
   scanf("%d",&n);
   int sz[n];
   for(int i=0;i<n;i++)
   {
     scanf("%d",&(sz[i]));
   }
   for(int j=n-1;j>=0;j--)
   {
    if(j==0)
     {
        printf("%d",sz[j]);
     }
    else
     {
        printf("%d ",sz[j]);
     }
   }
   return 0;
}


void reverse(int* array, int len){
	int i = 0, j = len - 1;
	while( i < j ){
		int temp = array[i];
		array[i] = array[j];
		array[j] = temp;
		i++;
		j--;
	}
}

int main(){
	int len = 0;
	scanf("%d", &len);

	int * array = (int*)malloc(len * sizeof(int));
	int i = 0;
	while( i < len){
		scanf("%d", array + i);
		i++;
	}
	reverse(array, len);

	i = 0;
	while( i < len - 1 ){
		printf("%d ", array[i]);
		i++;
	}
        printf("%d", array[i]);

	return 0;
}


int main()
{   int n;
    cin>>n;
    int num[n];
    int i;
    int a;
    for(i=0;i<n;i++)
        {   cin>>a;
        num[i]=a;
         }
    for(i=(n-1);i>=0;i--)
          {if(i>0)  cout<<num[i]<<' ';
          else cout<<num[i];
          }
    return 0;
}


int main(){
	int n,i,e;
	scanf("%d",&n);
    int *shuzu=(int*)malloc(sizeof(shuzu)* n);
	for(i=0;i<n;i++){
		scanf("%d",&shuzu[i]);
	}
	for(i=0;i<n/2;i++){
		e=shuzu[i];
		shuzu[i]=shuzu[n-1-i];
		shuzu[n-1-i]=e;
	}
	for(i=0;i<n-1;i++){
		printf("%d ",shuzu[i]);
	}
	printf("%d",shuzu[n-1]);
	return 0;
}


int a[100];
void c(int n)
{
	int i;
	for(i=0;i<n;i++)
		cin>>a[i];
}
void b(int n)
{
	int i;
	for(i=n-1;i>0;i--)
		cout<<a[i]<<" ";
	cout<<a[0];
}
int main()
{
	int n;
	cin>>n;
	c(n);
	b(n);
	return 0;
}


int main(int argc, char* argv[])
{
	int a[100],b[100],i,n;
    scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(i=0;i<n;i++){

			b[i]=a[n-1-i];
                      if(i<n-1)
			printf("%d ",b[i]);
                      else if (i=n-1)
                            printf("%d",b[i]);}
	return 0;
}


int main()
{
	int n, a[100];
	int *p = a;
	cin >> n;
	while (p < a + n)
	{
		cin >> *p++;
	}
	p--;
	while (p > a)
	{
		cout << *p-- << " ";
	}
	cout << *p;
	return 0;
}


void sx(int b[],int n);
void nx(int a[],int b[],int n);
int main(){
	int i=0,q,M[1001]={0},N[1001]={0};
	scanf("%d\n",&q);
	sx(M,q);
	nx(N,M,q);
	for(i=0;i<q-1;i++){
	printf("%d ",N[i]);
	}
	printf("%d",N[q-1]);
	return 0;
}
void sx(int b[],int n){
	int i;
		for(i=0;i<n;i++){
		scanf("%d",&b[i]);
		}
}
void nx(int a[],int b[],int n){
	int i;
		for(i=n-1;i>-1;i--){
		a[i]=b[n-i-1];
		}
}


int main()
{
	int n,i,j,num[50]={0};
	int *p;
	p=num;
	cin>>n;
	for(p=num+0;p<num+n;p++)
		cin>>*p;
	p=num+n-1;
	cout<<*p;
	for(p=num+n-2;p>=num+0;p--)
		cout<<" "<<*p;
	cout<<endl;
	return 0;
}


void inv(int x[],int n)
{
     int temp,i,j,m=(n-1)/2;
     for(i=0;i<=m;i++)
     {
                     j=n-1-i;
                     temp=x[i];x[i]=x[j];x[j]=temp;
                     }
                     return;
                     }
int main()
{
    int i,n,a[100];
    scanf("%d",&n);
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    inv(a,n);
    for(i=0;i<n-1;i++)
    printf("%d ",a[i]);

    printf("%d",a[n-1]);
     return 0;
}


/*
 * point1002.cpp
 *
 *  Created on: 2013-12-4
 *      Author: weng
 */

int main()
{
	int n , t ;
	cin >> n ;
	int a[n] ;
	int * p = NULL , * q = NULL ;
	for( p = a ; p < a + n ; p ++ )
		cin >> * p ;
	p = a ;
	q = a + n - 1 ;
	for( ; p < q ; p ++ , q -- )
	{
		t = * p ;
		* p = * q ;
		* q = t ;
	}
	p = a ;
	cout << * p ++ ;
	for( ; p < a + n ; p ++ )
		cout << " " << * p ;
	cout << endl ;
	return 0 ;
}


int a[100],sz[100];
void change(int sz[],int n);
int main()
{
	int n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&sz[i]);
	}
	change(sz,n);
	for(i=0;i<n-1;i++)
	{
		printf("%d ",a[i]);
	}
	printf("%d",a[n-1]);
	return 0;
}
void change(int sz[],int n)
{
	for(int i=0;i<n;i++)
	{
		a[i]=sz[n-1-i];
	}
}


int main(){
    int n;
    scanf("%d\n",&n);
    int zx[n];
    int dx[n];
    for(int i=1;i<=n;i++){
        scanf("%d",&zx[i]);
    }
    for(int j=1;j<=n;j++){
        dx[j]=zx[n-j+1];
    }
    for(int j=1;j<n;j++){
        printf("%d ",dx[j]);
    }
    printf("%d",dx[n]);
    return 0;
}


int i=0;//???????????????
int num=1;
void nixu(int n)
{

	int a;
	cin>>a;
	i++;
	if(i!=n)
	{
		nixu(n);
	}
	if(num!=n)
	{
	cout<<a<<' ';
         num++;
	}
	else
	{
		cout<<a;
	}

}
int main()
{
	int n;
	cin>>n;
	getchar();
	nixu(n);
	return 0;
}


int main(){
    int sz[98];
    int n;
    scanf("%d\n",&n);

    for(int i=0;i<n;i++){
        scanf("%d ",&(sz[i]));}
    int end[98];

    for(int m=0;m<n-1;m++){
        end[m]=sz[n-1-m];
        printf("%d ",end[m]);}
     end[n-1]=sz[0];
     printf("%d",end[n-1]);

     return 0;
}


int main()
{
    int s[100],n;
    cin>>n;
    for(int i=0;i<n;i++)
    cin>>s[i];
    int *p=&s[n];
    while(n>1)
    {
               p--;
               n--;
               cout<<*p<<' ';
    }p--;
    cout<<*p<<endl;
    return 0;
}


void shuchu(){
	int a;
	char b;
	cin>>a;
	cin.get(b);
	if(b!='\n'){
		shuchu();
		cout<<b<<a;//??????
	    }
	    if(b=='\n')cout<<a;
	}
int main(){
	int m;
	cin>>m;
	shuchu();

	return 0;
	}


int main(int argc, char* argv[])
{
	int n,i;
	scanf("%d",&n);
	int *A,*B;
	A=(int *)malloc(sizeof(int)*n);
	B=(int *)malloc(sizeof(int)*n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&A[i]);
		B[n-1-i]=A[i];
	}
	for(i=0;i<n;i++)
	{
		if(i<(n-1))
		printf("%d ",B[i]);
		else
			printf("%d",B[i]);

	}

	return 0;
}


int main ()
{
	int a[100]={0};
	int n;
	cin>>n;
	int *p=a;
	for (int i=0;i<n;i++)
		cin>>*p++;
	for (int i=0;i<n;i++)
	{
		if (i!=0)
			cout<<" ";
		cout<<*--p;
	}

	return 0;
}


int main(){
	int a[100],*p=NULL;
	int n;
	cin>>n;
	for(p=a;p<n+a;p++)
		cin>>*p;
	for(p=a+n-1;p>a;p--){
		cout<<*p<<" ";
	}
	p=a;
	cout<<*p;
}


int main()
{
 int m;
 cin>>m;
 const int n=m;
 int a[n+1];
 for(int i=n;i>=1;i--)cin>>a[i];
 for(int i=1;i<n;i++)cout<<a[i]<<' ';
 cout<<a[n];
 return 0;
}


int read();
void updown();
void print();
int a[100],b[100],n;
int main()
{
    read();
    updown();
    print();
    return 0;
}
int read()
{
    int i;
    scanf("%d",&n);
    for (i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    return 0;
}
void updown()
{
    int i;
    for (i=1;i<=n;i++)
    {
        b[i]=a[n-i+1];
    }
    return;
}
void print()
{
    int i;
    for (i=1;i<n;i++)
    {
        printf("%d ",b[i]);
    }
    printf("%d",b[n]);
    return;
}


int main(int argc, char* argv[])
{
	int i,n,j,a[100]={0};
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(j=100;j>=0;j--)
	{
		if(j>=n)
			continue;

		else if(j<n&&j>0)
			printf("%d ",a[j]);
		else if(j==0)
		printf("%d",a[0]);
	}

	return 0;
}


int main()
{
	int n;
	scanf("%d",&n);
	int *num;
	num=(int*)malloc(n);
	int j,a;
	for(j=1;j<=n;j++)
	{
		scanf("%d",&a);
			*(num+j)=a;
	}
	for(j=n;j>1;j--)
	{
		printf("%d ",*(num+j));
	}
	printf("%d\n",*(num+1));
	return 0;
}


int main()
{
	int n,zheng[100];
	int i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&zheng[n-i-1]);
	}
	for(i=0;i<n;i++){
		if(i<n-1){
			printf("%d ",zheng[i]);
		}else if(i==n-1){
			printf("%d",zheng[i]);
		}
	}
	return 0;
}


void main()
{
	int i,n;scanf("%d",&n);
	int *p=(int *)calloc(1,100*sizeof(int));
	for(i=0;i<n;i++)
		scanf("%d",p+i);
	for(i--;i>=0;i--)
	{
		if(i==0) printf("%d",*(p+i));
		else printf("%d ",*(p+i));
	}
}


int data[1000] = {0};
int n = 0, m = 0;

int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> data[i];
	for(int i = 1; i <= n / 2; i++)
	{
		int j = data[i];
		data[i] = data[n - i + 1];
		data[n - i + 1] = j;
	}
	cout << data[1];
	for(int i = 2; i <= n; i++) cout << ' ' << data[i];
}


int i;
void f(int n)
{
	int a;
	cin>>a;
	if(n==1)
		cout<<a<<" ";
	else
	{
		f(n-1);
		cout<<a;
		if(n!=i)
			cout<<" ";
	}
}
int main()
{
	int n;
	cin>>n;
	i=n;
	f(n);
	return 0;
}


int main(int argc, const char * argv[])
{
    int n;
    scanf("%d", &n);
    int od[n], i;
    for (i=0; i<n; i++) {
        scanf("%d", &(od[i]));
    }
    int abod[n], j, k;
    for (j=0; j<n; j++) {
        abod[j]=od[n-j-1];
    }
    for (k=0; k<n-1; k++) {
        printf("%d ", abod[k]);
    }
    printf("%d", abod[n-1]);
    return 0;
}


int main()
{
	int n,i,*p;
	scanf("%d",&n);
	p=(int *)malloc(n*sizeof(int));
	for(i=0;i<n;i++)
	{
		scanf("%d",p);
		p++;
	}
	p--;
	for(;i>0;i--,p--)
	{
		if(i==n)
			printf("%d",*p);
		else
			printf(" %d",*p);
	}
	return 0;
}


int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	int *p=a;
	for(int i=n-1;i>=1;i--)
		cout<<*(p+i)<<" ";
	cout<<*p;
	return 0;
}


//
//  8.cpp
//  poj
//
//  Created by ChuPan,Wong on 10/25/13.
//  Copyright (c) 2013 ChuPan,Wong. All rights reserved.
//

int main(){
    int n;
    int* num;
    int i,j;
    scanf("%d", &n);
    num = (int*)malloc(sizeof(int)*n);
    j = n; i = 0;
    while (j--) {
        scanf("%d", &num[i]);
        i++;
    }
    for (i = 0; i <= (n-1)/2; i++) {
        j = num[i];
        num[i] = num[n-1-i];
        num[n-1-i] = j;
    }
    for (i = 0; i < n; i++) {
        if(i!=0)
            printf(" ");
        printf("%d", num[i]);
    }
    printf("\n");
    return 0;
}


int main()
{
	int n,s[100],sum;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&s[i]);
	}
	sum=n;
	for(int j=1;j<n;j++){
		printf("%d ",s[sum-j]);
	}
	printf("%d",s[0]);
	return 0;
}


int main(int argc, char* argv[])
{
	int n,j,i,a[100];
    scanf("%d",&n);
	for(i=0;i<n;i++)
	{
	  scanf("%d",&a[i]);
	}
	  for(j=n-1;j>=1;j--)
	 {
		  printf("%d ",a[j]);

	  }

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

	return 0;
}


int main(){
	int n,i=0;
	int z[100];
	scanf("%d",&n);
	while(i<n){
		scanf("%d",&z[i]);
		i++;
	}
	i=1;
	while(i<=n){
		if(i<n){
		    printf("%d ",z[n-i]);
		}else{
			printf("%d",z[n-i]);
		}
		i++;
	}
	return 0;
}


int main()
{
	int a[100] = {0};
	int n,temp;
	cin>>n;
	for (int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for (int j=0;j<n/2;j++)
	{
		temp = a[j];
		a[j] = a[n-1-j];
		a[n-1-j] = temp;
	}
	for (int i=0;i<n;i++)
	{
		if (i==n-1)
		{
			cout<<a[i]<<endl;
		}
		else
		{
			cout<<a[i]<<' ';
		}
	}
	cout<<endl;
	return 0;
}


int main() {
    int n,i,j,sz[100],chance[100];
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&sz[i]);
	for(j=0;j<n-1;j++){
		chance[j]=sz[i-1];
		printf("%d ",chance[j]);
		i--;
	}
	j+=1;
	chance[j]=sz[i-1];
	printf("%d",chance[j]);
	return 0;
}


int n, a[100];
void io(int num) {
	cin >> a[num];
	if (num == 0) {
		io(1);
		cout << a[0];
	} else if (num == n - 1)
		cout << a[n - 1] << ' ';
	else {
		io(num + 1);
		cout << a[num] << ' ';
	}
}
int main() {
	cin >> n;
	io(0);
	return 0;
}


int main()
{
 int * array;
 int n,i,buffer;
 scanf("%d",&n);
 array=(int *)malloc(sizeof(int) * n);
 for (i=0;i<n;i++)
 {
  scanf("%d",(array+i));
 }
 for (i=0;i<=(n-1)/2;i++)
 {
  buffer=* (array+i);
  * (array+i)=* (array+(n-i-1));
  * (array+(n-i-1))=buffer;
 }
 int first;
 first=1;
 for (i=0;i<n;i++)
 {
  if (first)
  {
   printf("%d",* (array+i));
   first=0;
  }
  else
  {
   printf(" %d",* (array+i));
  }
 }
 free(array);
 return 0;
}


int dfs(int m,int dep)
{
    int t;
    cin>>t;
    if (m==dep) {cout<<t;return 0;}
    dfs(m+1,dep);
    cout<<' '<<t;
    return 0;
}
int main()
{
    int n;
    cin>>n;
    dfs(1,n);

    return 0;
}


void run(int *p,int n){
	if(n!=1) cout<<*p<<" ";
	else{
		cout<<*p;
		return;
		}
	run(p-1,n-1);
	return;
	}
int main(){
	int a[110],n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		}
	//??????????
	run(a+n-1,n);
	return 0;
	}


int main(int argc, char* argv[])
{
	int i,A[N],B[N],n;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
       scanf("%d",&A[i]);
	}
	printf("%d",A[n-1]);
	for(i=1;i<n;i++)
	{
		B[i]=A[n-1-i];

	printf(" %d",B[i]);
	}
	return 0;
}


int main()
{
    void f(int a);
    int n,num;
    cin>>n;
    cin>>num;
    f(n-1);
    cout<<num;
    return 0;
}
void f(int a)
{
     int num;
     cin>>num;
     if(a>0)
     {
     f(a-1);
     cout<<num<<" ";
     }
}


int main()
{
	int n;
	cin>>n;
	int c[100];
	for(int i=1;i<=n;i++)
		{
			int a;
			cin>>a;
			c[n-i]=a;
	}
	for(int t=1;t<=(n-1);t++)
	cout<<c[t-1]<<' ';
	cout<<c[n-1];

	return 0;
}


void main()
{
	int *p,*hd;int i,n;scanf("%d",&n);
	hd=p=(int *)malloc(n*sizeof(int));
	for(i=0;i<n;i++,p++)
	{scanf("%d",p);}
	for(p=hd+n-1,i=0;i<n;i++,p--)
	{if(i==0) printf("%d",*p);
	else printf(" %d",*p);}

}


int main()
{
	int n;
	cin>>n;
	int tem;
	int *p=NULL;
	int a[n];
	p=a;
	for(int i=0;i<n;i++)
	{
		cin>>p[i];
	}
	for(int i=0,j=n-1;i<j;i++,j--)
	{
		tem=*(p+i);
		*(p+i)=*(p+j);
		*(p+j)=tem;
	}
	for(int i=0;i<n;i++)
	{
		cout<<*(p+i);
		if(i!=n-1) cout<<' ';
	}
}


int main()
{
    int n;
    int a[100]={0};
    cin>>n;
    for (int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        a[i]=x;
   }
   for (int i=n-1;i>0;i--)
   cout<<a[i]<<" ";
   cout<<a[0];
   return 0;
}


int main(){
  int n,i,sz[100];

 scanf("%d",&n);

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

for(int i=n-1;i>0;i--){
	printf("%d ",sz[i]);
	}
	printf("%d",sz[0]);

return 0;
}


void daoxu(int n);
int main()
{
	int n;
	cin>>n;
	int b;
	cin>>b;
	daoxu(n-1);
	cout<<b;   //???????

	return 0;
}
void daoxu(int n)  //??
{
	int a;
	cin>>a;
	if(n==1)cout<<a<<' ';
	else {daoxu(n-1);
	cout<<a<<' ';}
}


int a[100001];
void swap(int n,int m)
{
	int t=a[n];
	a[n]=a[m];
	a[m]=t;
}
int main()
{
	int m,n,i,j;
	cin>>n;
	for(i=1;i<=n;i++)
	cin>>a[i];
	for(i=1,j=n;i<=j;i++,j--)
	swap(i,j);
	for(i=1;i<n;i++)
	cout<<a[i]<<' ';
	cout<<a[n];
	return 0;
}


/*
 * duanwenpaixu.cpp
 *
 *  Created on: 2013-12-5
 *      Author: ???
 */
int main()
{
	int a[100];
	int n;
	int *p=NULL;
	cin>>n;
	for(p=a;p<=&a[n-1];p++)
		cin>>*p;
	for(;p>a+1;)
		cout<<*--p<<' ';
	cout<<*--p;
	return 0;

}


int main(int argc, char* argv[])
{
	int n;
	scanf("%d",&n);
	int org[100],opp[100];
	int i;
	for(i=0;i<n;i++)
	{
		scanf("%d",&org[i]);
	}
	for(i=0;i<n;i++)
	{
		opp[i]=0;
	}
	for(i=0;i<n;i++)
	{
		opp[n-1-i]=org[i];
	}
	int k;
	for(k=0;k<n-1;k++)
	{
		printf("%d ",opp[k]);
	}
	printf("%d",opp[n-1]);
	return 0;
}


void function(int len,int rem);
int main()
{
	int len,rem;
	cin>>len;
	rem=len;
	function(len,rem);

	return 0;
}

void function(int len,int rem)
{ int num;
  if(len>0){
  cin>>num;
  function(len-1,rem);
     if(len==rem)cout<<num;
	 else cout<<num<<" ";
  }
}


int main(int argc, char* argv[])
{
	int n,i,a[N];
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	i--;
	printf("%d",a[i]);
	i--;
	for(;i>=0;i--)
 	    printf(" %d",a[i]);
	return 0;
}


int main(void)
{
	int n,a[100];
	int *a_pointer=NULL;
	cin>>n;
	a_pointer=a;
	for(int i=0;i<n;i++) cin>>*a_pointer++;
	*a_pointer--;
	for(int i=0;i<n-1;i++) cout<<*a_pointer--<<' ';
	cout<<*a_pointer;
	return 0;
}


int main ()
{
	int a[100] = {0};
	int num;
	int cur;
	int *temp = &cur;
	cin >> num;
	for ( int i = 0; i < num; i ++ )
		cin >> *(a+i);
	for ( int i = 0; i < num/2; i ++ )
	{
		*temp = *(a+i);
		*(a+i) = *(a+num-i-1);
		*(a+num-i-1) = *temp;
	}
	cout << *a;
	for ( int i = 1; i < num; i ++ )
		cout << " " << *(a+i);
	return 0;
}


struct N{
int a;
struct N* next;
};
int main(){
	int *p,*q,n,a[100],x;
 scanf("%d",&n);
 for(p=a;p<a+n;p++){
                    scanf("%d",p);}
                    for(p=a,q=a+n-1;p<a+n/2;p++,q--){
                                         x=*p;
                                         *p=*q;
                                         *q=x;
                                         }
 for(p=a;p<a+n;p++){
                    if(p==a){printf("%d",*p);}

                    else{printf(" %d",*p);}
                    }
 scanf("%d",&n);
 return 0;
}


int main(){
    int N;
    cin>>N;
    int * ar;
    if(NULL==(ar=(int *) malloc(N*sizeof(int)))){
        perror("error...");
        exit(1);
    }
    for(int i=0;i<N;i++) cin>>*(ar+i);
    for(int i=0;i<N;i++) {
        cout<<*(ar+N-i-1);
        if(i!=N-1) cout<<' ';
    }
    free(ar);
    ar=NULL;
    return 0;
}


/*
 * zhizheng.cpp
 *?? - ????
 *  Created on: 2012-12-11
 *      Author: ???
 */
int n,N,temp,i;
int *p=NULL,*q=NULL;
int main(){
	cin>>n;
	const int N=n;
	int a[N];
	for(i=0;i<n;i++)
	cin>>a[i];
	for(p=a,q=a+n-1;p<q;p++,q--)
	{
		temp=*p;
		*p=*q;
		*q=temp;
	}
	for(p=a;p<a+n-1;p++)
		cout<<*p<<' ';
	cout<<*p<<endl;
	return 0;
}


int main()
{
	int a,b[100],i;
	scanf("%d",&a);
	for(i=a;i>0;i--)
	{
		scanf("%d",&(b[i-1]));
	}
	for(i=0;i<a;i++)
	{
		switch(a-1-i)
		{
		case 0:
			printf("%d",b[i]);
			break;
		default:
			printf("%d ",b[i]);
			break;
		}
	}
	return 0;
}


int main(int argc, char* argv[])
{
	int a[100];
	int i;
	int n;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);

	}
	for(i=n-1;i>0;i--)
	{
		printf("%d ",a[i]);
	}
	i=0;
	printf("%d\n",a[i]);

	return 0;
}


void jiaohuan(int*,int*);
int main(){
	int yuan[101];
	int i,n;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&(yuan[i]));
	}
	for(i=0;i<n/2;i++){
		jiaohuan(&(yuan[i]),&(yuan[n-1-i]));
	}
	for(i=0;i<n-1;i++){
		printf("%d ",yuan[i]);
	}
	printf("%d",yuan[n-1]);
	return 0;
}
void jiaohuan(int*a,int*b){
	int e=*a;
		*a=*b;
		*b=e;
}


int main()
{
	int n;
	cin>>n;
	int a[105];
	int i=0;
    int b;
	while(i<n)
	{
		cin>>a[i];
        i++;
	}
	int c=n-1;
	while(c>=1 && c<=(n-1))
	{
		cout<<a[c];
		cout<<" ";
		c--;
	}
	cout<<a[0];
	return 0 ;
}


void main()
{
	int n,a[MAX];
	int *p;
	scanf("%d",&n);
	for(p=a;p<a+n;p++)
		scanf("%d",p);

	for(p=a+n-1;p>=a;p--){
		if(p==a+n-1)
			printf("%d",*p);
		else
			printf(" %d",*p);
	}
	printf("\n");
}


int num[10][10] , newnum[10][10] ;
void change(int , int);
int main()
{
	int m , n , i , j , k;
	cin >> m >> n ;
	memset(num,0,sizeof(num));
	num[5][5] = m ;
	for ( i = 1 ; i <= n ; i++ )
	{
		memset(newnum,0,sizeof(newnum));
		for ( j = 1 ; j <= 9 ; j++ )
			for (k = 1 ; k <= 9 ; k++ )
				change(j,k);
		for ( j = 1 ; j <= 9 ; j++ )
			for (k = 1 ; k <= 9 ; k++ )
				num[j][k] += newnum[j][k] ;
	}
	for ( i = 1 ; i <= 9 ; i++ )
	{
		for ( j = 1 ; j <= 9 ; j++ )
		{
			if ( j == 1 ) cout << num[i][j] ;
			else cout << " " << num[i][j] ;
		}
		cout << endl ;
	}
	return 0 ;
}
void change(int a , int b)
{
	int i , j ;
	for ( i = a-1 ; i <= a+1 ; i++ )
		for ( j = b-1 ; j <= b+1 ; j++ )
			newnum[a][b] += num[i][j] ;
}


int main()
{
	int bat[5][11][11] = {0};
	int days;
	cin >> bat[0][5][5] >> days;
	for (int i = 1; i <= days ; i++)
	{
		for (int row = 1 ; row <= 9 ; row++)
		{
			for (int col = 1 ; col <= 9 ; col++)
			{
				if (bat[i-1][col][row] != 0)
				{
					bat[i][col][row] += 2 * bat[i-1][col][row];
					bat[i][col-1][row-1] += bat[i-1][col][row];
					bat[i][col-1][row] += bat[i-1][col][row];
					bat[i][col-1][row+1] += bat[i-1][col][row];
					bat[i][col][row-1] += bat[i-1][col][row];
					bat[i][col][row+1] += bat[i-1][col][row];
					bat[i][col+1][row-1] += bat[i-1][col][row];
					bat[i][col+1][row] += bat[i-1][col][row];
					bat[i][col+1][row+1] += bat[i-1][col][row];
				}
			}
		}
	}
	for (int i = 1 ; i <= 9 ; i++)
	{
		cout << bat[days][i][1];
		for(int j = 2; j <= 9 ; j++)
			cout << ' ' << bat[days][i][j];
		cout << endl;
	}
	return 0;
}


int m;
int num(int, int, int);
int main(void)
{
    int n, i, j;
    cin >> m >> n;
    for( i = 1 ; i < 10 ; i++ )
    {
        for( j = 1 ; j < 9 ; j++ )
            cout << num(n, i, j) << " ";
        cout << num(n, i, 9) << endl;
    }
    return 0;
}
int num(int a, int x, int y)
{
    if( a == 0 )
    {
        if( x == 5 && y == 5 )
            return m;
        else
            return 0;
    }
    else
        return num(a - 1, x, y) * 2 + num(a - 1, x - 1, y - 1) + num(a - 1, x - 1, y) + num(a - 1, x - 1, y + 1) + num(a - 1, x, y - 1) + num(a - 1, x, y + 1) + num(a - 1, x + 1, y - 1) + num(a - 1, x + 1, y) + num(a - 1, x + 1, y + 1);
}


int map[10][10],add[10][10],m,n;
//????
void Generate(int x,int y){
	int v = map[x][y];
	for(int i = -1;i<=1;i++){
		for(int j = -1;j<=1;j++){
			if(i==0&&j==0) add[x+i][y+j]+=v*2;
			else add[x+i][y+j]+=v;
			}
		}
	return;
	}
int main(){
	cin>>m>>n;
	memset(map,0,sizeof(map));
	map[5][5] = m;
	for(int k = 0;k<n;k++){
		memset(add,0,sizeof(add));
		for(int i = 1;i<10;i++){
			for(int j = 1;j<10;j++){
				if(map[i][j]!=0) Generate(i,j);
				}
			}
		for(int i = 1;i<10;i++){
			for(int j = 1;j<10;j++){
				map[i][j]=add[i][j];
				}
		}
		}
	for(int i = 1;i<10;i++){
		for(int j = 1;j<10;j++){
			if(j!=1) cout<<" "<<map[i][j];
			else cout<<map[i][j];
			}
		cout<<endl;
		}
	return 0;
	}


int main()
{
 	int m,n,row,col,i;
 	int sz[11][11],by[11][11];
 	scanf("%d %d",&m,&n);
 	for(row=1;row<=9;row++){
			for(col=1;col<=9;col++){
				sz[row][col]=0;
				by[row][col]=0;
				}
			}
	sz[5][5]=m;
	by[5][5]=m;
	for(i=1;i<=n;i++){
	for(row=1;row<=9;row++){
		for(col=1;col<=9;col++){
			if(sz[row][col]!=0){
				by[row][col]=sz[row][col]+by[row][col];
				by[row-1][col]+=sz[row][col];
				by[row-1][col-1]+=sz[row][col];
				by[row-1][col+1]+=sz[row][col];
				by[row][col-1]+=sz[row][col];
				by[row][col+1]+=sz[row][col];
				by[row+1][col]+=sz[row][col];
				by[row+1][col-1]+=sz[row][col];
				by[row+1][col+1]+=sz[row][col];
				}
			}
		}
	for(row=1;row<=9;row++){
		for(col=1;col<=9;col++){
			sz[row][col]=by[row][col];
			}
		}
    }
    for(row=1;row<=9;row++){
		for(col=1;col<=9;col++){
			if(col!=9) printf("%d ",sz[row][col]);
			else printf("%d\n",sz[row][col]);
			}
		}

    return 0;
}


int m,n;
int num(int a,int b,int c)
{
    int i,j;
    if((a==0)||(a==10)||(b==0)||(b==10))
    return 0;
    else if(c==0)
    {
       if (a==5&&b==5)
       return m;
       else return 0;
    }
    else
    {
       int d=num(a,b,c-1);
       for(i=a-1;i<=a+1;i++)
       {
          for(j=b-1;j<=b+1;j++)
          d=d+num(i,j,c-1);
       }
       return d;
    }
}
int main()
{
    int i,j,s;
    scanf("%d %d",&m,&n);
    for(i=1;i<=9;i++)
    {
        for(j=1;j<=9;j++)
        {
            s=num(i,j,n);
            if(j==9)
            printf("%d\n",s);
            else printf("%d ",s);
         }
    }
    return 0;

}


int main()
{
	int i,j,k,m, n, count[9][9],temp[9][9];
	memset(count,0,sizeof(count));
	memset(temp,0,sizeof(count));
	cin >> m >> n;
	count[4][4] = m;
	for ( i = 0; i < n; i++)
	{
		for ( j = 0; j <9; j++)
			for ( k = 0; k < 9;k++)
			{
				if ( count[j][k] != 0 )
				{
					temp[j-1][k] +=count[j][k];
					temp[j+1][k]+=count[j][k];
					temp[j-1][k-1]+=count[j][k];
					temp[j-1][k+1]+=count[j][k];
					temp[j][k-1]+=count[j][k];
					temp[j][k+1]+=count[j][k];
					temp[j+1][k+1]+=count[j][k];
					temp[j+1][k-1]+=count[j][k];
					temp[j][k] += count[j][k]*2;
				}
			}
		for ( j = 0; j <9; j++)
			for ( k = 0; k < 9;k++)
				count[j][k] = temp[j][k];
		memset(temp,0,sizeof(temp));
	}
	for ( j = 0; j <9; j++)
	{
		for ( k = 0; k < 8;k++)
			cout << count[j][k] <<' ';
		cout << count[j][8] << endl;
	}
	return 0;
}


int board[9][9]={0};
int temp[9][9]={0};
void spread();
void turn();
int main()
{
    int zhongxin;
    cin >> zhongxin;
    board[4][4] = zhongxin;
    int days;
    cin >> days;
    int i,j;
    for (i=1;i<=days;i++)
    {
        spread();
        turn();
    }
    for (i=0;i<9;i++)
    {
        cout << board[i][0];
        for (j=1;j<9;j++)
        {
            cout << " " << board[i][j] ;
        }
        cout << endl;
    }
    return 0;
}

void spread()
{
     int i,j;
        for (i=0;i<9;i++)
        {
            for (j=0;j<9;j++)
            {
                temp[i][j]+=2*board[i][j];
                if (i>0)
                {
                        temp[i-1][j]+=board[i][j];
                }
                if (j>0)
                {
                        temp[i][j-1]+=board[i][j];
                }
                if (i<8)
                {
                        temp[i+1][j]+=board[i][j];
                }
                if (j<8)
                {
                        temp[i][j+1]+=board[i][j];
                }
                if (i<8&&j<8)
                {
                        temp[i+1][j+1]+=board[i][j];
                }
                if (i<8&&j>0)
                {
                        temp[i+1][j-1]+=board[i][j];
                }
                if (i>0&&j<8)
                {
                        temp[i-1][j+1]+=board[i][j];
                }
                if (i>0&&j>0)
                {
                        temp[i-1][j-1]+=board[i][j];
                }
            }
        }
}
void turn()
{
     int i,j;
     for (i=0;i<9;i++)
     {
         for (j=0;j<9;j++)
         {
             board[i][j] = temp[i][j];
         }
     }
     memset(temp, 0, sizeof(temp));
}


int m, n;

int main()
{
	int produce(int x, int y, int n);
	cin >> m >> n;
	for(int i = 1; i <= 9; i ++)
	{
		cout << produce(i, 1, n);
		for (int j = 2; j <= 9; j ++)
			cout << " " << produce(i, j, n);
		cout << endl;
	}
	return 0;
}

int produce(int x, int y, int day)
{
	if(x == 0 || y == 0 || x == 10|| y == 10) return 0;
	else if(day == 0)
	{
		if(x == 5 && y == 5) return m;
		else return 0;
	}
	else return
		(produce(x - 1, y, day - 1) + produce(x + 1, y, day - 1)
		+ produce(x, y - 1, day - 1) + produce(x, y + 1, day - 1)+
		produce(x, y , day - 1) * 2) + produce(x - 1, y - 1, day - 1)
		+ produce(x - 1, y + 1, day - 1) + produce(x + 1, y - 1, day - 1)
		+ produce(x + 1, y + 1, day - 1);
}


int board[11][11] = {0}, temp[11][11] = {0};

void increase(int day)
{
     if (day == 0)
     {
             return;
     }
     int i, j;
     for (i = 1; i < 10; i++)
     {
         for (j = 1; j < 10; j++)
         {
             temp[i + 1][j + 1] += board[i][j];
             temp[i + 1][j - 1] += board[i][j];
             temp[i - 1][j - 1] += board[i][j];
             temp[i - 1][j + 1] += board[i][j];
             temp[i - 1][j] += board[i][j];
             temp[i + 1][j] += board[i][j];
             temp[i][j - 1] += board[i][j];
             temp[i][j + 1] += board[i][j];
             temp[i][j] += board[i][j];
         }
     }
     for (i = 1; i < 10; i++)
     {
         for (j = 1; j < 10; j++)
         {
             board[i][j] = temp[i][j];
         }
     }
     return increase(day - 1);
}

int main()
{
    int num, day,i,j;
    cin >> num >> day;
    board[5][5] = num;
    temp[5][5] = num;
    increase(day);
    for (i = 1; i < 10; i++)
    {
         for (j = 1; j < 9; j++)
         {
             cout << temp[i][j] << " ";
         }
         cout << temp[i][j] << endl;
     }
    return 0;
}


//
//  main.cpp
//  ????????
//
//  Created by ?? on 12-12-15.
//  Copyright (c) 2012? ??. All rights reserved.
//

int board[9][9] = {0};
void production(int days)
{
    int separation[9][9], i, j;
    if (days == 0)
        return;
    else
    {
        for (i = 0; i < 9; i++)
            for (j = 0; j < 9; j++)
            {
                board[i][j] *= 10;
                separation[i][j] = (board[i][j] - 2 * board[i][j] / 10) / 8;
                board[i][j] = 2 * board[i][j] / 10;
            }
        for (i = 0; i < 9; i++)
            for (j = 0; j < 9; j++)
            {
                board[i + 1][j] += separation[i][j];
                board[i - 1][j] += separation[i][j];
                board[i][j + 1] += separation[i][j];
                board[i][j - 1] += separation[i][j];
                board[i + 1][j + 1] += separation[i][j];
                board[i - 1][j + 1] += separation[i][j];
                board[i + 1][j - 1] += separation[i][j];
                board[i - 1][j - 1] += separation[i][j];
            }
        production(days - 1);
    }
}
int main()
{
    int num, days, i, j;
    cin >> num >> days;
    board[4][4] = num;
    production(days);
    for (i = 0; i < 9; i++)
        for (j = 0; j < 9; j++)
        {   if (j == 8)
                cout << board[i][j] <<endl;
            else
                cout << board[i][j] << " ";
        }
    return 0;
}


int board[11][11] = {0}, temp[11][11] = {0};

void increase(int day)
{
     if (day == 0)
     {
             return;
     }
     int i, j;
     for (i = 1; i < 10; i++)
     {
         for (j = 1; j < 10; j++)
         {
             temp[i + 1][j + 1] += board[i][j];
             temp[i + 1][j - 1] += board[i][j];
             temp[i - 1][j - 1] += board[i][j];
             temp[i - 1][j + 1] += board[i][j];
             temp[i - 1][j] += board[i][j];
             temp[i + 1][j] += board[i][j];
             temp[i][j - 1] += board[i][j];
             temp[i][j + 1] += board[i][j];
             temp[i][j] += board[i][j];
         }
     }
     memcpy(board, temp, sizeof(int)*121);
     return increase(day - 1);
}

int main()
{
    int num, day,i,j;
    cin >> num >> day;
    board[5][5] = num;
    temp[5][5] = num;
    increase(day);
    for (i = 1; i < 10; i++)
    {
         for (j = 1; j < 9; j++)
         {
             cout << temp[i][j] << " ";
         }
         cout << temp[i][j] << endl;
     }
    return 0;
}


int main()
{
	int m=0,n=0;
	int i=0,j=0;
	int col_num=0,row_num;
	int In[9][9]={{0}};
	int Out[9][9]={{0}};
	int Temp[9][9]={{0}};
	int around[8][2]={{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};
	scanf("%d %d",&m,&n);
	In[4][4]=m;
	for(i=0;i<n;i++)
	{
		if(i!=0)
		{
			memcpy(In,Out,81*sizeof(int));
			memset(Out,0,81*sizeof(int));
		}
		for(row_num=4-i;row_num<=4+i;row_num++)
		{
			for(col_num=4-i;col_num<=4+i;col_num++)
			{
				Out[row_num][col_num]=Out[row_num][col_num]+2*In[row_num][col_num];
				for(j=0;j<8;j++)
				{
					Out[row_num+around[j][0]][col_num+around[j][1]]=Out[row_num+around[j][0]][col_num+around[j][1]]+In[row_num][col_num];
				}
			}
		}
	}
	for(row_num=0;row_num<9;row_num++)
	{
		for(col_num=0;col_num<9;col_num++)
		{
			if(col_num!=8)
			{
				printf("%d ",Out[row_num][col_num]);
			}
			else
			{
				printf("%d\n",Out[row_num][col_num]);
			}
		}
	}
}


main()
{
      int **squre1;
      int **squre2;
      squre1=(int**)calloc(len,sizeof(int*));
      squre2=(int**)calloc(len,sizeof(int*));
      for(int i=0;i<9;i++)
      {
              squre1[i]=(int*)calloc(len,sizeof(int));
              squre2[i]=(int*)calloc(len,sizeof(int));
      }
      int day;
      scanf("%d%d",&squre1[4][4],&day);
      for(int n=0;n<day;n++)
      {
              for(int i=4-n;i<=4+n;i++)
              for(int j=4-n;j<=4+n;j++)
              for(int x=i-1;x<=i+1;x++)
              for(int y=j-1;y<=j+1;y++)
              if(n%2==0)
              squre2[x][y]=0;
              else
              squre1[x][y]=0;

              for(int i=4-n;i<=4+n;i++)
              for(int j=4-n;j<=4+n;j++)
              for(int x=i-1;x<=i+1;x++)
              for(int y=j-1;y<=j+1;y++)
              {
                      if(x==i&&y==j)
                      {if(n%2==0)
                      squre2[x][y]+=2*squre1[i][j];
                       else
                        squre1[x][y]+=2*squre2[i][j];
                        }
                        else
                        if(n%2==0)
                        squre2[x][y]+=squre1[i][j];
                        else
                        squre1[x][y]+=squre2[i][j];
                        }

      }

      if(day%2==0)
      for(int i=0;i<len;i++)
      {
              int count=0;
              for(int j=0;j<len;j++)
              {
                      if(count==0)
                      {printf("%d",squre1[i][j]);
                      count=1;}
                      else
                      printf(" %d",squre1[i][j]);
              }
              printf("\n");
      }
      else
      for(int i=0;i<len;i++)
      {
              int count=0;
              for(int j=0;j<len;j++)
              {
                      if(count==0)
                      {printf("%d",squre2[i][j]);
                      count=1;}
                      else
                      printf(" %d",squre2[i][j]);
              }
              printf("\n");
      }

}


void Find( int matrix[][9], int n );
int main()
{

	int matrix[ 9 ][ 9 ];
	int i, j;
	int m, n;
	for ( i =0; i < 9; i++ )
	{
		for ( j =0; j < 9; j++ )
			matrix[ i ][ j ] = 0;
	}

	cin >> m >> n;

	matrix[ 4 ][ 4 ] = m;
	Find( matrix, n );

	for ( i = 0; i < 9; i++ )
	{
		cout << matrix[ i ][ 0 ];
		for ( j = 1; j < 9; j++ )
		{
			cout <<" " << matrix[ i ][ j ];
		}
		cout << endl;
	}
}

void Find( int matrix[][9], int n)
{
	int i, j;
	int temp[9][9];
	memset( temp,0,sizeof(temp));
	if ( n == 0 )
		return;
	for ( i = 1; i < 8; i++ )
	{
		for ( j = 1; j < 8; j++ )
		if ( matrix[ i ][ j ] != 0 )
		{
			temp[ i ][ j ] =  2 * matrix[ i ][ j ]+temp[ i ][ j ];

			temp[ i + 1 ][ j ] =  matrix[ i ][ j ] + temp[ i + 1 ][ j ];

			temp[ i - 1 ][ j ] = matrix[ i ][ j ] + temp[ i - 1 ][ j ];

			temp[ i ][ j + 1 ] =  matrix[ i ][ j ] + temp[ i ][ j + 1 ];

			temp[ i ][ j - 1 ] =  matrix[ i ][ j ] + temp[ i ][ j - 1 ];
			temp[ i + 1 ][ j - 1 ] =  matrix[ i  ][ j  ] + temp[ i + 1 ][ j - 1 ];
			temp[ i + 1 ][ j + 1 ] = matrix[ i  ][ j ] + temp[ i + 1 ][ j + 1 ];
			temp[ i - 1 ][ j - 1 ] = matrix[ i ][ j ] + temp[ i - 1 ][ j - 1 ];
			temp[ i - 1 ][ j + 1 ] = matrix[ i ][ j ] + temp[ i - 1 ][ j + 1 ];
		}
	}

	for ( i = 0; i < 9; i++ )
		for ( j = 0; j < 9; j++ )
			matrix[ i ][ j ] = temp[ i ][ j ];
	Find( matrix, n - 1 );
}


int main()
{
	int board[9][9],temp[9][9];
	int n;
	memset(board,0,81*sizeof(int));
	cin>>board[4][4]>>n;
	while(n--)
	{
		memset(temp,0,81*sizeof(int));
		for(int i=1;i<8;i++)
		{
			for(int j=1;j<8;j++)
			{
				if(board[i][j]>0)
				{
					temp[i][j]+=(2*board[i][j]);
					temp[i-1][j-1]+=board[i][j];
					temp[i-1][j]+=board[i][j];
					temp[i-1][j+1]+=board[i][j];
					temp[i][j-1]+=board[i][j];
					temp[i][j+1]+=board[i][j];
					temp[i+1][j-1]+=board[i][j];
					temp[i+1][j]+=board[i][j];
					temp[i+1][j+1]+=board[i][j];
				}
			}
		}
		for(int i=0;i<9;i++)
		{
			for(int j=0;j<9;j++)
			{
				board[i][j]=temp[i][j];
			}
		}
	}
	for(int i=0;i<9;i++)
	{
		cout<<board[i][0];
		for(int j=1;j<9;j++)
		{
			cout<<' '<<board[i][j];
		}
		cout<<endl;
	}
	return 0;
}


int main()
{
	int grids[9][9] = {0}, daysLeft, history[81][3], historyCount = 0, x, y;
	cin >> grids[4][4];
	for (cin >> daysLeft; daysLeft > 0; daysLeft--)
	{
		historyCount = 0;
		for (y = 0; y < 9; y++)
			for (x = 0; x < 9; x++)
				if (grids[x][y])
				{
					history[historyCount][0] = x;
					history[historyCount][1] = y;
					history[historyCount][2] = grids[x][y];
					historyCount++;
				};
		for (int i = 0; i < historyCount; i++)
		{
			x = history[i][0];
			y = history[i][1];
			int val = history[i][2];
			if (x > 0)
			{
				grids[x - 1][y] += val;
				if (y > 0)
					grids[x - 1][y - 1] += val;
				if (y < 8)
					grids[x - 1][y + 1] += val;
			}
			if (x < 8)
			{
				grids[x + 1][y] += val;
				if (y > 0)
					grids[x + 1][y - 1] += val;
				if (y < 8)
					grids[x + 1][y + 1] += val;
			}
			if (y > 0)
				grids[x][y - 1] += val;
			if (y < 8)
				grids[x][y + 1] += val;
			grids[x][y] += val;
		}
	}
	for (y = 0; y < 9; y++)
	{
		cout << grids[0][y];
		for (x = 1; x < 9; x++)
			cout << ' ' << grids[x][y];
		cout << endl;
	}
	return 0;
}


int m[L+5][L+5]={0},tmp[L+5][L+5]={0};
int i=0,j=0,k=0;
int n;
main()
{
      scanf("%d%d",&m[4][4],&n);
      for(k=1;k<=n;k++)
      {
                         memset(tmp,0,sizeof(tmp));
      for(i=0;i<=L-1;i++)
      {
                          for(j=0;j<=L-1;j++)
                          {
                                             tmp[i][j]=2*m[i][j]+m[i-1][j-1]+m[i][j-1]+m[i+1][j-1]+m[i+1][j]+m[i-1][j]+m[i+1][j+1]+m[i][j+1]+m[i-1][j+1];
                          }
      }
      for(i=0;i<=L-1;i++)
      {
                          for(j=0;j<=L-1;j++)
                          {
                                             m[i][j]=tmp[i][j];
                          }
      }
      }
      for(i=0;i<=L-1;i++)
      {
           printf("%d %d %d %d %d %d %d %d %d\n",m[i][0],m[i][1],m[i][2],m[i][3],m[i][4],m[i][5],m[i][6],m[i][7],m[i][8]);
      }
      getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();getchar();
}


const int N = 9;

int n,m;
int a[N+1][N+1];

void dfs(int x, int y, int s, int d)
{
	if (x<1 || x>N || y<0 || y>N) return;
	if (d==m)
	{
		a[x][y] += s;
		return;
	}
	dfs(x,y,s*2,d+1);
	for (int dx=-1;dx<=1;dx++)
		for (int dy=-1;dy<=1;dy++)
			if (dx!=0 || dy!=0)
				dfs(x+dx,y+dy,s,d+1);
}

int main()
{
	scanf("%d%d",&n,&m);
	memset(a,0,sizeof a);
	dfs(5,5,n,0);
	for (int i=1;i<=N;i++)
	{
		for (int j=1;j<N;j++) printf("%d ",a[i][j]);
		printf("%d\n",a[i][N]);
	}

	return 0;
}


//*****************************************
//* ?????(11.8) ???????? **
//* ?????? 1300012741 **
//* ???2013.10.16 **
//*****************************************

void	bacteria( int, int[9][9] );

int main()
{
	int numBacteria, numDay;
	int container[9][9] = { 0 };
	int i, j;

	cin >> numBacteria >> numDay;
	container[4][4] = numBacteria;

	bacteria( numDay, container );

	for ( i = 0; i < 9; i++ )
	{
		for ( j = 0; j < 9; j++ )
		{
			cout << container[i][j];
			if ( j != 8 )
				cout << " ";
		}
		cout << endl;
	}

	return 0;
}

void bacteria( int numDay, int container[9][9] )
{
	int i, j;
	int tempContainer[9][9] = { 0 };

	if ( !numDay )
		return;
	else
		bacteria( numDay - 1, container );

	for ( i = 0; i < 9; i++ )
		for ( j = 0; j < 9; j++ )
			if ( container[i][j] )
			{
				tempContainer[i - 1][j] += container[i][j];
				tempContainer[i + 1][j] += container[i][j];
				tempContainer[i][j - 1] += container[i][j];
				tempContainer[i][j + 1] += container[i][j];
				tempContainer[i - 1][j - 1] += container[i][j];
				tempContainer[i - 1][j + 1] += container[i][j];
				tempContainer[i + 1][j - 1] += container[i][j];
				tempContainer[i + 1][j + 1] += container[i][j];
				tempContainer[i][j] += 2 * container[i][j];
			}
	for ( i = 0; i < 9; i++ )
		for ( j = 0; j < 9; j++ )
			if ( tempContainer[i][j] )
				container[i][j] = tempContainer[i][j];

	return;
}


int main(int argc, char* argv[])
{

	const int sz=9;
	int k,i,j,m,n,fx,fy;
	int a[sz][sz],b[sz][sz];
	scanf("%d%d",&m,&n);
	memset (a,0,sizeof (a));
	a[sz/2][sz/2]=m;
	for (k=0;k<n;k++)
	{
		memset(b,0,sizeof (b));
	for (i=1;i<sz-1;i++)
	{
		for (j=1;j<sz-1;j++)
		{
			b[i][j]+=a[i][j];
			for (fx=-1;fx<=1;fx++)
			{
				for (fy=-1;fy<=1;fy++)
				b[i+fx][j+fy]+=a[i][j];
			}
		}
	}

memcpy (a,b, sizeof (a));
}
for (i=0;i<sz;i++)
{
	for (j=0;j<sz-1;j++)
		printf ("%d ",a[i][j]);
	printf ("%d\n",a[i][sz-1]);
}
return 0;
}


/**
 * @file   2.cpp
 * @author 3ÂË¼½ü
 * @date   2013-12-04
 * @description
 *         ¼ÆËã¸ÅÂÛ×÷ò??oàyìa(11.8) Ï¸¾ú?Ä·±Ö3óëà©é?
 */

int a[10][10];
void func(int day);

int main()
{
	int day;
	cin >> a[5][5] >> day;

	func(day);

	for (int i = 1; i <= 9; ++i)
	{
		for (int j = 1; j <= 8; ++j)
			cout << a[i][j] << " ";
		cout << a[i][9] << endl;
	}
	return 0;
}

void func(int day)
{
	if (day == 0) return;
	int b[10][10] = {0};
	for (int i = 1; i <= 9; ++i)
		for (int j = 1; j <= 9; ++j)
			if (a[i][j])
			{
				b[i][j] += a[i][j];
				for (int p = i - 1; p <= i + 1; ++p)
					for (int q = j - 1; q <= j + 1; ++q)
						b[p][q] += a[i][j];
			}

	for (int i = 1; i <= 9; ++i)
		for (int j = 1; j <= 9; ++j)
			a[i][j] = b[i][j];

	func(day - 1);
}


int maze[9][9];
int day = 0;
void search(int n)
{
	while(day != n)
	{
		day++;
		int add[9][9];
		memset(add, 0, sizeof(add));
		for (int i = 4 - day + 1; i <= 4 + day - 1; i++)
			for (int j = 4 - day + 1; j <= 4 + day - 1; j++)
			{
				add[i+1][j] += maze[i][j];
				add[i-1][j] += maze[i][j];
				add[i+1][j+1] += maze[i][j];
				add[i-1][j-1] += maze[i][j];
				add[i+1][j-1] += maze[i][j];
				add[i-1][j+1] += maze[i][j];
				add[i][j+1] += maze[i][j];
				add[i][j-1] += maze[i][j];
				add[i][j] +=  maze[i][j];
			}
		for (int i = 4 - day; i <= 4 + day; i++)
			for (int j = 4 - day; j <= 4 + day; j++)
			{
				maze[i][j] += add[i][j];
			}
	}
	return;
}
int main()
{
	int m, n;
	cin >> m >> n;
	maze[4][4] = m;
	search(n);
	for (int i = 0; i < 9; i++)
	{
		cout << maze[i][0];
		for (int j = 1; j < 9; j++)
			cout << " " << maze[i][j];
		cout << endl;
	}
	return 0;
}


void change(int [][9]);
int main()
{
	int m, n, i, j;
	int matrix[9][9] = {0};
	cin >> m >> n;
	matrix[4][4] = m;
	for (i = 0; i < n; i++)
	{
		change(matrix);
	}
	for (i = 0; i < 9; i++)
	{
		cout << matrix[i][0];
		for (j = 1; j < 9; j++)
		{
			cout << ' ' << matrix[i][j];
		}
		cout << endl;
	}
	return 0;
}
void change(int matrix[9][9])
{
	int i, j;
	int plus[9][9] = {0};
	for (i = 0; i < 9; i++)
	{
		for (j = 0; j < 9; j++)
		{
			if (matrix[i][j] > 0)
			{
				plus[i][j] += matrix[i][j];
				plus[i - 1][j] += matrix[i][j];
				plus[i][j - 1] += matrix[i][j];
				plus[i + 1][j] += matrix[i][j];
				plus[i][j + 1] += matrix[i][j];
				plus[i - 1][j - 1] += matrix[i][j];
				plus[i - 1][j + 1] += matrix[i][j];
				plus[i + 1][j + 1] += matrix[i][j];
				plus[i + 1][j - 1] += matrix[i][j];
			}
		}
	}
	for (i = 0; i < 9; i++)
	{
		for (j = 0; j < 9; j++)
		{
			matrix[i][j] += plus[i][j];
		}
	}
}


int main()
{
	int row,col,i,a[N][N],b[N][N],n,d;
	for(row=0;row<N;row++)
		for(col=0;col<N;col++)
           a[row][col]=0;

	scanf("%d %d",&a[4][4],&d);

	for(i=0;i<d;i++)
	{
		for(row=0;row<N;row++)
		for(col=0;col<N;col++)
           b[row][col]=0;

	      for(row=0;row<N;row++)
		  {
		       for(col=0;col<N;col++)
			   {
                    if(a[row][col]!=0)
					{
                        b[row-1][col-1]+=a[row][col];
						b[row][col-1]+=a[row][col];
						b[row+1][col-1]+=a[row][col];
						b[row-1][col]+=a[row][col];
						b[row+1][col]+=a[row][col];
						b[row-1][col+1]+=a[row][col];
						b[row][col+1]+=a[row][col];
						b[row+1][col+1]+=a[row][col];
						a[row][col]*=2;

					}
			   }
		  }
          for(row=0;row<N;row++)
		  {
			  for(col=0;col<N;col++)
			  {
				  a[row][col]=a[row][col]+b[row][col];
			  }
		  }

	}

	for(row=0;row<N;row++)
	{
		for(col=0;col<N-1;col++)
		{
			printf("%d ",a[row][col]);
		}
		printf("%d\n",a[row][N-1]);
	}
	return 0;
}