int main()
{
	struct stu{
		int ID,chin,math;
	};
	stu *pp;
	int sum,second,third,x,y,z;
	int i,n;
	int a,b,c;
	scanf("%d",&n);
	pp=(struct stu *)malloc(sizeof(stu)*n);
	for(i=1;i<=n;i++)
	{
		scanf("%d %d %d",&a,&b,&c);
	      (pp+i)->ID=a;
	      (pp+i)->chin=b;
	      (pp+i)->math=c;
	}
	sum = ((pp+i)->chin)+((pp+i)->math);
	for(i=1;i<=n;i++)
	{
		if(i==1)
		{
			sum=((pp+i)->chin)+((pp+i)->math);
			second=((pp+i)->chin)+((pp+i)->math);
			third=((pp+i)->chin)+((pp+i)->math);
			x=(pp+i)->ID;
			y=(pp+i)->ID;
			z=(pp+i)->ID ;

		}
		else if (i==2)
		{
			if (sum<((pp+i)->chin)+((pp+i)->math))
			{
				second=sum;
			    sum=((pp+i)->chin)+((pp+i)->math);
				y=x;
				x=(pp+i)->ID;
			}
                           else
                           {
                                   third=((pp+i)->chin)+((pp+i)->math);
                                   z=(pp+i)->ID;
                            }
		}
		else
		{
			if (sum<((pp+i)->chin)+((pp+i)->math))
			{
                                    third=second;
				second=sum;
			    sum=((pp+i)->chin)+((pp+i)->math);
                                     z=y;
				y=x;
				x=(pp+i)->ID;
			}
			else if (second<((pp+i)->chin)+((pp+i)->math))
			{
				third=second;
				second=((pp+i)->chin)+((pp+i)->math);
				z=y;
				y=(pp+i)->ID;
			}
                           else if (third<((pp+i)->chin)+((pp+i)->math))
                           {
                                    third=((pp+i)->chin)+((pp+i)->math);
                                    z=(pp+i)->ID;
                           }
		}
	}
	    printf("%d %d\n",x,sum);
		printf("%d %d\n",y,second);
		printf("%d %d\n",z,third);
			return 0;
}


struct student
{
	int num;
	float yuwen;
	float shuxue;
	float total;
}stu[100000];
void main()
{
	int i,n,j;
	struct student *p;
	p=&stu[0];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%f%f",&(p+i)->num,&(p+i)->yuwen,&(p+i)->shuxue);
		(p+i)->total=(p+i)->shuxue+(p+i)->yuwen;
	}
	for(i=0;i<3;i++)
		for(j=0;j<n-1-i;j++)
		{
			if((*(p+j)).total>=(*(p+j+1)).total)
			{
				struct student temp;
				temp=*(p+j+1);
				*(p+j+1)=*(p+j);
				*(p+j)=temp;
			}
		}
	if(n>2)
		for(i=1;i<4;i++)
			printf("%d %g\n",(*(p+n-i)).num,(*(p+n-i)).total);
	else if(n=2)
		printf("%d %g\n%d %g\n",(*(p+1)).num,(*(p+1)).total,(*p).num,(*p).total);
}


struct Student
{
       int num;
       int chinese;
       int maths;
};
 struct qiansan
      {
             int num;
             int zongfen;
      }st[3]={{0,0},{0,0},{0,0}};
main()
{
      int n,i,k,c[10],j[10];
      int a[100001];
      scanf("%d",&n);
      struct Student std[100001];
      for(i = 0;i < n;i++)
      {
            scanf("%d %d %d",&std[i].num,&std[i].chinese,&std[i].maths);
      }
      for(i = 0;i < n;i++)
      {
            a[i] = std[i].chinese + std[i].maths;
      }
      for(i = 0;i < n;i++)
      {
          if(a[i]>st[0].zongfen)
          {
              st[2]=st[1];
              st[1]=st[0];
              st[0].zongfen=a[i];
              st[0].num=std[i].num;
          }
          else if(a[i] <= st[0].zongfen && a[i] > st[1].zongfen)
          {
              st[2]=st[1];
              st[1].zongfen=a[i];
              st[1].num=std[i].num;
          }
          else if(a[i] <= st[1].zongfen && a[i]>st[2].zongfen)
          {
              st[2].zongfen=a[i];
              st[2].num=std[i].num;
          }
      }
      for(i = 0;i < 3;i++)
      {
          printf("%d %d\n",st[i].num,st[i].zongfen);
      }
      getchar();
      getchar();

}


int main()
{
  struct student
  {
         int ID;
         int yuwen;
         int shuxue;
  };
  int n,i,x,y,z,o,p,q;
  scanf("%d",&n);
  int a[100000];
  struct student stu[100000];
  for(i=0;i<n;i++)
  {
   scanf("%d %d %d",&stu[i].ID,&stu[i].yuwen,&stu[i].shuxue);
   a[i]=stu[i].yuwen+stu[i].shuxue;
  }
  x=0;
  y=1;
  z=2;
   for(i=0;i<3;i++)
   {
    if(a[i]>=a[0]&&a[i]>=a[1]&&a[i]>=a[2])
    {
       x=i;
       o=a[i];
       continue;
    }
    if(a[i]<=a[0]&&a[i]<=a[1]&&a[i]<=a[2])
    {
       z=i;
       q=a[i];
       continue;
    }
    y=i;
    p=a[i];
   }

    for(i=3;i<n;i++)
   {
     if(a[i]>q)
     {
       if(a[i]>o)
       {
        z=y;
        y=x;
        x=i;
        q=p;
        p=o;
        o=a[i];
       }
       else
       {
        if(a[i]>p)
        {
          z=y;
          y=i;
          q=p;
          p=a[i];
        }
        else
        {
          z=i;
          q=a[i];
        }
       }
     }
   }
   printf("%d %d\n",stu[x].ID,o);
    printf("%d %d\n",stu[y].ID,p);
     printf("%d %d\n",stu[z].ID,q);
 getchar();
 getchar();
}


struct student
{ int num;int a;int b;int sum;int c;};
void main()
{
	int n,i,j,nt,ct;
         struct student stu[100000];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{ scanf("%d %d %d",&stu[i].num,&stu[i].a,&stu[i].b);
	stu[i].sum=stu[i].a+stu[i].b;stu[i].c=stu[i].sum;}
	for(i=0;i<3;i++)
		for(j=i+1;j<n;j++)
		{
			if(stu[i].c<stu[j].c){
				nt=stu[i].num;stu[i].num=stu[j].num;stu[j].num=nt;
				ct=stu[i].c;stu[i].c=stu[j].c;stu[j].c=ct;
			}
		}

   for(i=0;i<3;i++)
		   printf("%d %d\n",stu[i].num,stu[i].c);
}


struct student
{
	long a;
	int x;
	int y;
};
struct student stu[100000];
main()
{
	long n,i,j,p;
	int m;
	scanf("%ld",&n);
	int g[100000];
	for(i=0;i<n;i++)
	{
		scanf("%ld %d %d",&stu[i].a,&stu[i].x,&stu[i].y);
		g[i]=stu[i].x+stu[i].y;
	}
	for(i=1;i<4;i++)
		for(j=n-1;j>=i;j--)
			if(g[j-1]<g[j])
			{
				m=g[j-1];g[j-1]=g[j];g[j]=m;
				p=stu[j-1].a;stu[j-1].a=stu[j].a;stu[j].a=p;
			}
	for(i=0;i<3;i++)
		printf("%ld %d\n",stu[i].a,g[i]);
}


struct
{
	int xuehao;
	int yuwen;
	int shuxue;
}student[1000000];
void swap(int*a,int*b);
int main(int argc, char* argv[])
{
	int n=0;
	scanf("%d",&n);
	int i=0,j=0,total[1000000];
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&student[i].xuehao,&student[i].yuwen,&student[i].shuxue);
		total[i]=student[i].yuwen+student[i].shuxue;
	}
	for(i=0;i<3;i++)
	{
		for(j=n-1;j>0+i;j--)
		{
			if(total[j]>total[j-1])
			{
				swap(&total[j],&total[j-1]);
				swap(&student[j-1].xuehao,&student[j].xuehao);
					swap(&student[j-1].yuwen,&student[j].yuwen);
					swap(&student[j-1].shuxue,&student[j].shuxue);
			}
		}
	}
	for(i=0;i<3;i++)
	{
		printf("%d %d\n",student[i].xuehao,total[i]);
	}
	return 0;
}
void swap(int*a,int*b)
{
	int e;
	e=*a;
	*a=*b;
	*b=e;
}


struct student
{
	int id;
	int chinese;
	int math;
}stu[100000];

void bubble(struct student stu[],int n)
{
	int pass,i;
	struct student temp;

	for(pass=n-1;pass>=n-3;pass--)
		for(i=pass;i>0;i--)
			if(stu[i].chinese+stu[i].math>stu[i-1].chinese+stu[i-1].math)
			{
				temp=stu[i];
				stu[i]=stu[i-1];
				stu[i-1]=temp;
			}
}

int main()
{
	struct student *p;
	int i;
	int n;

	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d %d %d",&stu[i].id,&stu[i].chinese,&stu[i].math);
	bubble(stu,n);
	for(p=stu;p<stu+3;p++)
		printf("%d %d%c",p->id,p->chinese+p->math,(p==stu+n-1)?'\0':'\n');
	return 0;
}


struct student
{
	int num;
	int score1;
	int score2;
	int sum;
	struct student *next;
};
struct student *creat(int m)
{
	int i=0;
    struct student *head,*p1,*p2;
	p1=p2=(struct student *)malloc(LEN);
    scanf("%d %d %d",&p1->num,&p1->score1,&p1->score2);
	p1->sum=(p1->score1)+(p1->score2);
    head=NULL;

    for(i=0;i<m-1;i++)

	{

		if(i==0) head=p1;
	    else p2->next=p1;
		p2=p1;
		p1=(struct student *)malloc(LEN);
        scanf("%d %d %d",&p1->num,&p1->score1,&p1->score2);
	    p1->sum=(p1->score1)+(p1->score2);
	}
	p2->next=p1;
	p1->next=NULL;
	return(head);
}
void print(struct student *head)
{
    struct student *p=head,*q=head;
	int a=0,b=0,c=0;
	if(head!=NULL)

	{do
		{
			if(a<p->sum)
			{a=p->sum;q=p;}
			p=p->next;
		}while(p!=NULL);
		printf("%d %d\n",q->num,q->sum);
        q->sum=0;
        p=head;q=head;
	 do
	  {if(b<p->sum)
			{b=p->sum;q=p;}
			p=p->next;
	  }while(p!=NULL);
		printf("%d %d\n",q->num,q->sum);
        q->sum=0;
        p=head;q=head;
		do
		{if(c<p->sum)
			{c=p->sum;q=p;}
			p=p->next;
	  }while(p!=NULL);
	printf("%d %d",q->num,q->sum);
	}
}
void main()
{
	int m;
	scanf("%d",&m);
	struct student *head,stu;
	head=creat(m);
	print(head);
}


struct s
{long int a;
int b;
int c;
int sum;
struct s *next;};
void main()
{struct s *head1,*head2;
struct s *p,*p1,*p2,*p3,*p4;
long int n,i;
int rank1,rank2,rank3;
scanf("%ld",&n);

p1=(struct s *)malloc(L);
scanf("%ld %d %d",&p1->a,&p1->b,&p1->c);
p1->sum=p1->b+p1->c;
rank1=p1->sum;
for(i=1;;i++)
{if(i==1) head1=p1;
else p2->next=p1;
p2=p1;
if(i==n) break;
p1=(struct s *)malloc(L);
scanf("%ld %d %d",&p1->a,&p1->b,&p1->c);
p1->sum=p1->b+p1->c;
if(p1->sum>rank1) rank1=p1->sum;}
p2->next=N;

p1=head1;
while(rank1!=p1->sum)
{p2=p1;p1=p1->next;}
if(rank1==p1->sum)
{if(p1==head1) head1=p1->next;
else p2->next=p1->next;
p3=p1;}
head2=p3;
p4=p3;

p1=head1;
rank2=p1->sum;
while(p1!=N)
{if(p1->sum>rank2) rank2=p1->sum;
p1=p1->next;}

p1=head1;
while(rank2!=p1->sum)
{p2=p1;p1=p1->next;}
if(rank2==p1->sum)
{if(p1==head1) head1=p1->next;
else p2->next=p1->next;
p3=p1;}

p4->next=p3;
p4=p3;

p1=head1;
rank3=p1->sum;
while(p1!=N)
{if(p1->sum>rank3) rank3=p1->sum;
p1=p1->next;}

p1=head1;
while(rank3!=p1->sum)
{p2=p1;p1=p1->next;}
if(rank3==p1->sum)
{if(p1==head1) head1=p1->next;
else p2->next=p1->next;
p3=p1;}
p4->next=p3;
p3->next=N;

p=head2;
do{printf("%ld %d\n",p->a,p->sum);
p=p->next;}while(p!=N);

}


struct student
{
int name;
int ch;
int math;
};
struct student stu[100000];
int main()
{
int n; int sum[100000];int max[3];int i,j,k,m,o;int s;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d %d %d",&stu[i].name,&stu[i].ch,&stu[i].math);
for(i=0;i<n;i++)
{
               sum[i]=stu[i].ch+stu[i].math;
}
//for(i=0;i<n;i++)
{
                max[0]=0;
                for(j=0,k=0;j<n;j++)
                {if(sum[j]>max[0])
                {max[0]=sum[j];
                k=j;}
                }
}
//for(i=0;i<n;i++)
{
                max[1]=0;
                for(j=1,m=0;j<n;j++)
                {if((sum[j]>max[1])&&(j!=k))
                {max[1]=sum[j];
                m=j;}
                }
}
//for(i=0;i<n;i++)
{
                max[2]=0;
                for(j=1,o=0;j<n;j++)
                {if((sum[j]>max[2])&&(j!=k)&&(j!=m))
                {max[2]=sum[j];
                o=j;}

                }

}
printf("%d %d\n",stu[k].name,sum[k]);
printf("%d %d\n",stu[m].name,sum[m]);
printf("%d %d\n",stu[o].name,sum[o]);
return 0;
}


struct student
{
	int number;
	int math;
	int chin;
	int sum;
}st[100000],t;
void main()
{
	int i,j;
	int n;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&st[i].number,&st[i].math,&st[i].chin);
		st[i].sum=st[i].math+st[i].chin;
	}
	for(i=0;i<3;i++)
		for(j=n;j>=1;j--)
			if(st[j].sum>st[j-1].sum)
			{
				t=st[j-1];
				st[j-1]=st[j];
				st[j]=t;
			}
			for(i=0;i<3;i++)
			printf("%d %d\n",st[i].number,st[i].sum);
}


int main(){
	int n;
	cin>>n;
	struct stu{
		int num;
		int chin;
		int math;
		int sum;
	}one[n+1];

	for(int i=1;i<=n;i++){
		cin>>one[i].num>>one[i].chin>>one[i].math;
		one[i].sum=one[i].chin+one[i].math;
	} //???????
    int t=0;
	for(int i=200;i>=0;i--)
    	for(int j=1;j<=n;j++){
    		if (one[j].sum==i) {
    			cout<<j<<" "<<one[j].sum<<endl;
    			t=t+1;
    		}
    		if (t==3) {
    			i=-1;break;
    		}
    	}//????????
    return 0;
}


int main()
{
	struct stu
	{
		int a,b,c;
		struct stu *next;
		struct stu *back;
	};
	struct stu *head,*p1,*p2,*p,*pmax1,*pmax2,*pmax3;
	int n,i,j,max1,max2,max3;
	scanf("%d",&n);
	p1=p2=(struct stu *)malloc(sizeof(struct stu));
	scanf("%d %d %d",&p1->a,&p1->b,&p1->c);
	head=p1;
	for(i=1;i<n;i++)
	{
		p1=(struct stu *)malloc(sizeof(struct stu));
		p2->next=p1;
		p1->back=p2;
		p2=p1;
		scanf("%d %d %d",&p1->a,&p1->b,&p1->c);
	}
	p=head;
	max1=0;
	for (i=0;i<n;i++)
	{

		if (max1<(p->b+p->c))
		{
			max1=p->b+p->c;
			pmax1=p;
		}
		p=p->next;
	}
	p=head;
	max2=0;
	for (i=0;i<n;i++)
	{

		if (max2<(p->b+p->c)&&(p!=pmax1))
		{
			max2=p->b+p->c;
			pmax2=p;
		}
		p=p->next;
	}
	p=head;
	max3=0;
	for (i=0;i<n;i++)
	{

		if (max3<(p->b+p->c)&&(p!=pmax1)&&(p!=pmax2))
		{
			max3=p->b+p->c;
			pmax3=p;
		}
		p=p->next;
	}
	printf("%ld %d\n",pmax1->a,(pmax1->b+pmax1->c));
	printf("%ld %d\n",pmax2->a,(pmax2->b+pmax2->c));
	printf("%ld %d\n",pmax3->a,(pmax3->b+pmax3->c));
	return 0;
}


struct stud {
		int id;
		float langrade;
		float mathgrade;
		} student[100000],s;
	int student_num;
	float total[100000],t;
void trisort(){
	for(int i=0;i<2;i++)
	   for(int j=0;j<2-i;j++)
		  if(total[j]<total[j+1]){
			 t=total[j];
			 s=student[j];
			 total[j]=total[j+1];
			 student[j]=student[j+1];
			 total[j+1]=t;
			 student[j+1]=s;
			}
}
int main(){
	int i,j;
	cin>>student_num;
	for(i=0;i<student_num;i++){
		cin>>student[i].id>>student[i].langrade>>student[i].mathgrade;
	      total[i]=student[i].langrade+student[i].mathgrade;}
	for(j=3;j<student_num;j++)
		{trisort();
		 if(total[j]>total[2]){
				t=total[2];
				s=student[2];
				total[2]=total[j];
				student[2]=student[j];
				total[j]=t;
				student[j]=s;
				}
		}
	for(i=0;i<3;i++)
		cout<<student[i].id<<" "<<total[i]<<endl;
	return 0;

}


struct student
{
	long num;
	int scorec;
	int scorem;
	struct student *next;
};
struct student *creat(void)
{
	struct student *head,*p0,*p1,*p2;
	int i=0;
	head=(struct student *)malloc(len);
	head->next=NULL;
	scanf("%ld %d %d",&head->num,&head->scorec,&head->scorem);
	while(i<2)
	{
		p1=head;
		p0=(struct student *)malloc(len);
		scanf("%ld %d %d",&p0->num,&p0->scorec,&p0->scorem);
		while((p0->scorec+p0->scorem)<=(p1->scorec+p1->scorem)&&(p1->next!=NULL))
		{
			p2=p1;
			p1=p1->next;
		}
		if((p0->scorec+p0->scorem)>(p1->scorec+p1->scorem))
		{
			if(head==p1) head=p0;
			else p2->next=p0;
			p0->next=p1;
		}
		else
		{
			p1->next=p0;
			p0->next=NULL;
		}
		i++;
	}
	return(head);
}
struct student *sort(struct student *head,int n)
{
	struct student *p0,*p1,*p2;
	int i=3;
	while(i<n)
	{
		p1=head;
		p0=(struct student*)malloc(len);
	    scanf("%ld %d %d",&p0->num,&p0->scorec,&p0->scorem);
		while((p0->scorec+p0->scorem)<=(p1->scorec+p1->scorem)&&(p1->next!=NULL))
		{
			p1=p1->next;
		}
		if((p0->scorec+p0->scorem)>(p1->scorec+p1->scorem))
		{

			if(head==p1)
			{
				p2=p1->next;
				(*p2->next).num=p2->num;
				(*p2->next).scorec=p2->scorec;
				(*p2->next).scorem=p2->scorem;
				p2->num=p1->num;
				p2->scorec=p1->scorec;
				p2->scorem=p1->scorem;
				p1->num=p0->num;
				p1->scorec=p0->scorec;
				p1->scorem=p0->scorem;
			}
		    else if(p1==head->next)
			{
				(*p1->next).num=p1->num;
				(*p1->next).scorec=p1->scorec;
				(*p1->next).scorem=p1->scorem;
				p1->num=p0->num;
				p1->scorec=p0->scorec;
				p1->scorem=p0->scorem;
			}
			else
			{
				p1->num=p0->num;
				p1->scorec=p0->scorec;
				p1->scorem=p0->scorem;
			}
		}
		free(p0);
		i++;
	}
	return(head);
}

void main()
{
	struct student *head,*p1,*p2;
	int n;
	scanf("%d",&n);
	head=creat();
	head=sort(head, n);
	p1=head->next;
	p2=p1->next;
    printf("%ld %d\n",head->num,(head->scorec+head->scorem));
	printf("%ld %d\n",p1->num,(p1->scorec+p1->scorem));
    printf("%ld %d",p2->num,(p2->scorec+p2->scorem));
}


struct Top
{
    int num;
    float score;
}Top[4]={{0,0}};
struct Top *p;

void maopao(int n)
{
    int i;
    for(i=1; i<n; i++)
    {
        for(p=Top; p<Top+n-i; p++)
        {
            if((p->score) < ((p+1)->score))
            {
                Top[3]=*p;
                *p=*(p+1);
                *(p+1)=Top[3];
            }
        }
    }
}

void sort(float a, int n)
{
    p=Top+2;
    if(a > (p->score))
    {
        p->score=a;
        p->num=n;
    }
    maopao(3);
}

int main()
{
    int i, n, num;
    float yw, sx, score;

    scanf("%d\n", &n);
    for(i=0;i<n;i++)
    {
        scanf("%d %f %f", &num, &yw, &sx);
        float score=yw+sx;
        sort(score, num);
    }
    for(p=Top;p<Top+3;p++)
    {
        printf("%d %g\n", p->num, p->score);
    }

    return 0;
}


struct student
{
	int num;
	int yuwen;
	int shuxue;
};
int main()
{
	int n,m,i,j,t,k;
	scanf("%d",&n);
	m=n;
	struct student *stu=(struct student*)malloc(sizeof(struct student)*n);
	int *score=(int*)malloc(sizeof(int)*m);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&stu[i].num,&stu[i].yuwen,&stu[i].shuxue);
		score[i]=stu[i].yuwen+stu[i].shuxue;
	}
	for(i=0;i<3;i++)
	{
		for(j=0;j<m-1-i;j++)
		{
			if(score[j]>=score[j+1])
			{
				t=score[j];
				score[j]=score[j+1];
				score[j+1]=t;
				k=stu[j].num;
				stu[j].num=stu[j+1].num;
				stu[j+1].num=k;
			}
		}
	}
	for(i=n-1;i>=n-3;i--)
	{
		printf("%d %d\n",stu[i].num,score[i]);
	}
	free(stu);
	free(score);
	return 0;
}


struct student
{
	int num;
	int s1;
	int s2;
	int sum;
};
struct student stu[100000];
int main()
{

	int n,i,p,q,r,max;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&stu[i].num,&stu[i].s1,&stu[i].s2);
		stu[i].sum=stu[i].s1+stu[i].s2;
	}
	max=0;
	for(i=0;i<n;i++)
	{
		if(stu[i].sum>max)
		{
			max=stu[i].sum;
			p=i;
		}
	}
	max=0;
	for(i=0;i<n;i++)
	{
		if(i!=p)
		{
			if(stu[i].sum>max)
			{
				max=stu[i].sum;
				q=i;
			}
		}
	}
	max=0;
	for(i=0;i<n;i++)
	{
		if((i!=p)&&(i!=q))
		{
			if(stu[i].sum>max)
			{
				max=stu[i].sum;
				r=i;
			}
		}
	}
	printf("%d %d\n",stu[p].num,stu[p].sum);
	printf("%d %d\n",stu[q].num,stu[q].sum);
	printf("%d %d\n",stu[r].num,stu[r].sum);
	return 0;
}


int main()
{
    int sz[1000][1000];
    int ROW,COL,ROW1,COL1,col,row;
    int n,k=0;
int T=0;
int a,b;
    scanf("%d",&n);
    ROW=n-1;
    COL=n-1;

    for(row=0;row<ROW;row++){
                             for(col=0;col<COL;col++){
                                                     scanf("%d",&sz[row][col]);
                                                            }
                                                            }
    for(row=0;row<ROW;row++){
                             for(col=0;col<COL;col++){
                                                      if(T==0&&sz[row][col]==0){
                                                                          ROW1=row;
                                                                          COL1=col;

T=1;}
                                                            }
                                                            }
    for(row=ROW;row>=ROW1;row--){
                             for(col=COL;col>=COL1;col--){
                                                      if(T==0&&sz[row][col]==0){
                                                                          COL=col;
ROW=row;

T=1;
                                                                          }
                                                                          }
                                                                          }

a=ROW-ROW1-3;
b=COL-COL1-1;
k=a*b;
    printf("%d",k);
    return 0;

}


// state: 0( left up ), 1( right down)
int main()
{
	int state = 0;
	int n, t, i, j,m,m1,m2;
	int leftx, lefty, rightx, righty;
	scanf("%d", &n);

	for ( i = 0; i < n; i++ ) {
		for ( j = 0; j < n; j++ ) {
			scanf("%d", &t);
			if ( t == 0 ) {
				if ( state == 0 ) {
					leftx = i;
					lefty = j;
					state = 1;
				} else {
					rightx = i;
					righty = j;
				}
			}
		}
	}
    m1 = (rightx-leftx-1);
	m2 = (righty-lefty-1);
    m = m1*m2;
	printf("%d", m);
	return 0;

}


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

			if(tumor[i][j]==0)
				a++;
		}
			if(a!=0)
				break;
			else if(a==0)
				continue;
	}
	for(j=0;j<n;j++){
		for(i=0;i<n;i++){
			if(tumor[i][j]==0)
				b++;
		}
		if(b!=0)
			break;
		else  continue;
	}
	sum=(a-2)*(b-2);
	cout<<sum<<endl;
	return 0;
}


int main()
{
	int n;
	int area[1000][1000];
	scanf("%d",&n);
	int f=1;
	int start1,start2,end1,end2,re;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			scanf("%d",&area[i][j]);
			if(area[i][j]==0 && f==1)
			{
				start1=i;
				start2=j;
				f=2;
			}
			if(area[i][j]==0)
			{
				end1=i;
				end2=j;
			}
		}
	}
	re=(end1-start1-1)*(end2-start2-1);
	printf("%d",re);
	return 0;
}


int main()
{
  int n,a,b,c,d,sum;
  scanf("%d\n",&n);
  int sz[100][100];
  int row,col;
  for(row=0;row<n;row++)
  {
     for(col=0;col<n;col++)
     {
        scanf("%d\n",&(sz[row][col]));
      }
   }
  for(row=0;row<n;row++)
  {
     for(col=0;col<n;col++)
     {
       if(sz[row][col]==0&&sz[row][col+1]==255)
       {
          a=row;
          b=col;
          break;
        }
     }
   }
   for(row=n-1;row>0;row--)
  {
     for(col=n-1;col>0;col--)
     {
       if(sz[row][col]==0&&sz[row][col-1]==255)
       {
         c=row;
         d=col;
         break;
        }
      }
   }
  sum=(c-a+1)*(d-b+1);
  printf("%d",sum);
  return 0;
}


int main()
{
    int photo[300][300] = {1};
    int n;
    int i, j;

    cin >> n;
    for (i = 1; i <= n; i++)
    {
        for(j = 1; j <= n; j++)
        {
            int t;
            cin >> t;
            if (t == 255)
                t = 1;
            photo[i][j] = t;
        }
    }
    int found = 0;
    int Lx, Ly, Bx, By;
    for(i = 1; i <= n; i++)
    {
        for(j = 1; j <= n; j++)
        {
            if(photo[i][j] == 0)
            {
                Lx = i;
                Ly = j;
                found = 1;
                break;
            }
        }
        if(found) break;
    }
    found = 0;
    for(i = n; i >= 1; i--)
    {
        for(j = n; j >= 1; j--)
        {
            if(photo[i][j] == 0)
            {
                Bx = i;
                By = j;
                found = 1;
                break;
            }
            if(found) break;
        }
    }
    int w = Bx - Lx - 1;
    int h = By - Ly - 1;
    cout << w * h << endl;
    return 0;
}


int main(){
	int n,a[1000][1000],b[1000][1000],row,col,ROW1,COL1,ROW2,COL2,sum;
		scanf("%d",&n);
		for(row=0;row<n;row++){
			for(col=0;col<n;col++){
				scanf("%d",&a[row][col]);
			}
		}
	for(row=0;row<n;row++){
			for(col=0;col<n;col++){
				if(a[row][col]==0){
				ROW1=row;
				COL1=col;
					break;
				}
			}
		}
for(row=n-1;row>=0;row--){
			for(col=n-1;col>=0;col--){
				if(a[row][col]==0){
					ROW2=row;
					COL2=col;
					break;
				}
			}
		}
sum=(ROW2-ROW1+1)*(COL1-COL2+1);

printf("%d",sum);

	return 0;
}


void main()
{
	int n;
	scanf("%d",&n);
	int i,j,num,a,b;
	num = 0;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			int s[1000];
			scanf("%d",&s[j]);
		if(s[j] == 0)
			num = num + 1;
		}
	}
	a = (int)sqrt(num) - 1;
	b = a * a;
	printf("%d\n",b);
}


int main()
{
	int n,s=0,u;
	int image[100][100];
	scanf("%d",&n);
	for(int row=0;row<n;row++)
	{
		for(int col=0;col<n;col++)
		{
			scanf("%d",&(image[row][col]));
		}
	}
	for(int i=0;i<n;i++)
	{
		int k=0;
		for(int j=0;j<n;j++)
		{
			if(image[i][j]==0)
			{
//				printf("%d %d\n",row2,col2);
				k++;
			}
		}
		if(k>0)
		{
			u=k;
			s++;
		}

	}
	int m=(u-2)*(s-2);
	printf("%d",m);
	return 0;
}


int main()
{
	int n,i,k,h,hengsum=0,js=1,spj,susum=0;
	scanf("%d",&n);
	for (i=1;i<=n;i++)
	{
		spj=1;
		if(hengsum==0)
			js=i;
		for (k=1;k<=n;k++)
		{
			scanf("%d", &h);
			if (h==0)
			{
				if (spj==1)
				{
					susum+=1;
					spj++;
				}

				if (js==i)
					hengsum+=1;
			}

		}
	}
	printf("%d",(susum-2)*(hengsum-2));
	return 0;
}


int main(int argc, char *argv[])
{
  int n,m,k=0,i,j;
  int *a;
  scanf("%d",&n);
  a=(int*)(malloc(n*sizeof(int)));
  for(i=0;i<n;i++)
  {
   for(j=0;j<n;j++)
   scanf("%d",&a[j]);
   for(j=0;j<n;j++)
   {
      if(a[j]==0)
      break;
   }
   for(m=j+1;m<n;m++)
     {if(a[m]==0)
      {k=k+m-j-1;
      break;}
      }
   }
   printf("%d",k);
  return 0;
}


int main()
{
	int i, j, n, left_i=-1, left_j, right_i, right_j, num, temp;

	scanf("%d", &n);
	for(i=0; i<n; i++){
		num=0;
		for(j=0; j<n; j++){
			scanf("%d", &temp);
			if(temp==0){
				num++;
				if(num==1&&left_i<0){
					left_i=i;
					left_j=j;
				}
				else{
					right_i=i;
					right_j=j;
				}
			}
		}
	}

	printf("%d\n", (right_i-left_i-1)*(right_j-left_i-1));

	return 0;
}


int main ()
{
	int n,i,j,ai,aj,bi,bj,ans,x;

	scanf("%d",&n);
	ai=n; aj=n;
	bi=-1; bj=-1;
	for (i=0;i<n;i++)
		for (j=0;j<n;j++)
		{
			scanf("%d",&x);
			if (x==0)
			{
				if (i<ai) ai=i;
				if (i>bi) bi=i;
				if (j<aj) aj=j;
				if (j>bj) bj=j;
			}
		}

	ans=(bi-ai-1)*(bj-aj-1);

	printf("%d\n",ans);

	return 0;
}


int main()
{
	int n,rol,col,a,b,c,d,x;
	int sz1[100][100];
	scanf("%d",&n);
	for(rol=0;rol<n;rol++)
	{
		for(col=0;col<n;col++)
		{
			scanf("%d",&(sz1[rol][col]));
		}

	}
	for(rol=0;rol<n;rol++)
	{
		for(col=0;col<n;col++)
		{
			if(sz1[rol][col]==0)
			{
				b=col;
				break;
			}
		}
	}
	for(col=0;col<n;col++)
	{
		for(rol=0;rol<n;rol++)
		{
			if(sz1[rol][col]==0)
			{
				a=rol;
				break;
			}
		}
	}
	for(col=b;col<n;col++)
	{
		if(sz1[a][col]!=0)
		{
			d=col-1;
			break;
		}
	}

	for(rol=a;rol<n;rol++)
	{
		if(sz1[rol][d]!=0)
		{
			c=rol-1;
			break;
		}
	}

    x=(c-a-1)*(d-b-1);
	printf("%d",x);
	return 0;
}


int main(int argc, char* argv[])
{
	int a[1000][1000];
	int n,i,j,point1,point2,row1,colum1,row2,colum2,num;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
		    if(a[i][j]==0)
			{
			  point1=a[i][j];
			  row1=i;
			  colum1=j;
			  i=n+1;
			  break;
		  }
		}
    }
	for(i=n-1;i>=0;i--)
	{
		for(j=n-1;j>=0;j--)
		{
		  if(a[i][j]==0)
		  {
				point2=a[i][j];
				row2=i;
				colum2=j;
				i=-1;
                break;
			}
		}
    }
num=(row2-row1-1)*(colum2-colum1-1);
printf("%d\n",num);
return 0;
}


int n;
int map[1010][1010];

void init();
void work();

int main()
{
    init();
    work();
    return 0;
}

void init()
{
     int i,j;
     cin>>n;
     for (i=0;i<n;i++)
     {
         for (j=0;j<n;j++)
         {
             cin>>map[i][j];
         }
     }
}

void work()
{
     int sx,sy,ex,ey,f,i,j;
     sx=sy=0;
     ex=ey=n-1;
     f=0;
     for (i=0;i<n;i++)
     {
         for (j=0;j<n;j++)
         {
             if (map[i][j]==0)
             {
                sx=i;
                sy=j;
                f=1;
                break;
             }
         }
         if (f) break;
     }
     f=0;
     for (i=n-1;i>=0;i--)
     {
         for (j=n-1;j>=0;j--)
         {
             if (map[i][j]==0)
             {
                ex=i;
                ey=j;
                f=1;
                break;
             }
         }
         if (f) break;
     }
     cout<<(ex-sx-1)*(ey-sy-1)<<endl;
}


int main(){
	int n,sz[100][100],r,s,p,q;
	scanf("%d",&n);
	for(int row=0;row<n;row++){
		for(int col=0;col<n;col++){
			scanf("%d",&(sz[row][col]));
		}
	}
	for(int a=0;a<n;a++){
		for(int b=0;b<n;b++){
			if(sz[a][b]==0){
				r=a;
				s=b;
				break;
			}
			else
				continue;
		}
	}
	for(int c=n-1;c>=0;c--){
		for(int d=n-1;d>=0;d--){
			if(sz[c][d]==0){
				p=c;
				q=d;
				break;
			}
			else
				continue;
		}
	}
	int e=(r-p-1)*(q-s-1);

	printf("%d",e);
	return 0;
}


int main()
{
	int x1,y1,x2,y2;
	int n,i,j,t,area;
	int status=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		for(j=0;j<n;j++){
			scanf("%d",&t);
			if(t==0){
				if(status==0){
					x1=i;
					y1=j;
					status=1;
				}
				x2=i;
				y2=j;
			}
		}
		area=(x2-x1-1)*(y2-y1-1);
		printf("%d",area);
		return 0;
}


int main()
{
	int n;
	scanf("%d",&n);
	int a[100][100];
	int i,j;
	int chang1[100];
	int kuan,chang=0;
	for(i=0;i<n;i++)
	{
		for(j=0,chang1[i]=0;j<n;j++)
		{
			scanf("%d",&a[i][j]);
			if(a[i][j]==0)
			{
				chang1[i]=chang1[i]+1;
			}
		}
	}
	int yo;
	for(yo=0;yo<n;yo++)
	{
		if(chang1[yo]!=0)
		{
			chang=chang1[yo];
		break;
		}
	}
	int t;
	for(t=0,kuan=0;t<n;t++)
	{
		if(chang1[t]==2)
			kuan=kuan+1;
	}
	int jieguo;
	jieguo=kuan*(chang-2);
	printf("%d",jieguo);
	return 0;
}


main()
{
	int n,i,cur,s=0,sq,starow,stacol,endrow,endcol;
	scanf("%d",&n);
	for (i=1;i<=n*n;i++)
	{
		scanf("%d",&cur);
		if (s==0&&cur==0)
		{
			s=1;
			starow=(i-1)/n;
			stacol=i%n;
		}
		else if (s==1&&cur==0)
		{
			endrow=(i-1)/n;
			endcol=i%n;
		}
	}
	sq=(endrow-starow-1)*(endcol-stacol-1);
	printf("%d\n",sq);
	return 0;
}


int main()
{
   int n,i=0,a,sum=0,m;
   scanf("%d",&n);
   while(i<=n*n)
   {

	   scanf("%d",&a);
       i=i+1;
   if(a==0)
	   sum=sum+1;
   }
   m=sum*sum/16+1-sum/2;
   printf("%d\n",m);
   return 0;
}


int main(int argc, char* argv[])
{
	int row,col,n,s=0;
	int sz[1000][1000];
	int star1,star2,end1,end2;
	int f=-1;
	scanf("%d",&n);

	for(row=0;row<n;row++){
		for(col=0;col<n;col++){
			scanf("%d",&(sz[row][col]));
		}
	}
	for(row=1;row<n-1;row++){
		for(col=1;col<n-1;col++){
			if(sz[row][col]==0&&f==-1){
				star1=row;
				star2=col;
				f=1;
			}
			if(sz[row][col]==0){
                end1=row;
				end2=col;
			}
		}
	}
     s=(end1-star1-1)*(end2-star2-1);

	printf("%d\n",s);
	return 0;
}


int main(int argc, char* argv[])
{
	int points[100][100];
	int n,row,col;
	int sum=0,i=0;
	int SUM=0,j=0;
	scanf("%d",&n);
	for(row=0;row<n;row++)
	{
		for(col=0;col<n;col++)
		{
			scanf("%d",&points[row][col]);
		}
	}
	for(row=0;row<n;row++)
	{
		sum=0;
		for(col=0;col<n;col++)
		{
			sum+=points[row][col];
		}
		if(sum<n*255)
			i++;
	}
    for(col=0;col<n;col++)
	{
		SUM=0;
        for(row=0;row<n;row++)
		{
            SUM+=points[row][col];
		}
	    if(SUM<n*255)
			j++;
	}
	printf("%d",(i-2)*(j-2));
	return 0;
}


int main(int argc, char* argv[])
{
	int n,i,x,number_0=0,s;
	scanf("%d",&n);
	for(i=0;i<n*n;i++)
	{
		scanf("%d",&x);
		if(x==0){
			number_0++;
                          }

        }
    s=(number_0/4-1)*(number_0/4-1);
	printf("%d\n",s);
	return 0;
}


int main()
{
int num;
cin>>num;
int graphic[100][100];//??????
int i=0,j=0,rightEst,bottumEst;//???????
int width=0,lengh=0;
for(i=0;i<num;i++)
{
for(j=0;j<num;j++)
{
scanf("%d",&graphic[i][j]);
if(graphic[i][j]==0){
rightEst=i;bottumEst=j;//???????
}
}
}
for(i=rightEst,j=bottumEst;i>=0;i--){//???
if(graphic[i][j]==0) width++;
else break;
}
for(i=rightEst,j=bottumEst;j>=0;j--){//???
if(graphic[i][j]==0) lengh++;
else break;
}
int portation=width*lengh-width*2-(lengh-2)*2;//?????????

cout <<portation<< endl;
return 0;
}


int sz[1000][1000];
int main()
{
	int n;
	int row,col;
	int a,b,c,d;
	int x,y;
	int num;
	int e=0,f=0;
	scanf("%d",&n);
	for(row=0;row<n;row++)
	{
		for(col=0;col<n;col++)
		{
			scanf("%d",&sz[row][col]);
		}
	}
	for(row=0;row<n;row++)
	{
		for(col=0;col<n;col++)
		{
			if(sz[row][col]==0)
			{
				a=row;
				b=col;
				e=1;
				break;
			}
		}
		if(e==1)
		{
			break;
		}
	}
	for(row=n-1;row>=0;row--)
	{
		for(col=n-1;col>=0;col--)
		{
			if(sz[row][col]==0)
			{
				c=row;
				d=col;
				f=1;
				break;
			}
		}
		if(f==1)
		{
			break;
		}
	}
	x=c-a-1;
	y=d-b-1;
	num=x*y;
	printf("%d\n",num);
	return 0;
}


int main(){
	int n,a[100][100],row,col,ROW1,COL1,ROW2,COL2,sum;
		scanf("%d",&n);
		for(row=0;row<n;row++){
			for(col=0;col<n;col++){
				scanf("%d",&a[row][col]);
			}
		}

	int flag = 0;
	for(row=0;row<n&&!flag;row++){
			for(col=0;col<n&&!flag;col++){
				if(a[row][col]==0){
				ROW1=row;
				COL1=col;
				flag = 1;
					break;
				}
			}
		}
 flag = 0;
for(row=n-1;row>=0&&!flag;row--){
			for(col=n-1;col>=0;col--){
				if(a[row][col]==0){
					ROW2=row;
					COL2=col;
	flag = 1;
					break;
				}
			}
		}
sum=(ROW2-ROW1-1)*(COL2-COL1-1);

printf("%d\n",sum);

	return 0;
}


int main()
{
	int bian,row,col;
	int shuzu[500][500];
	int i,j,m=0,n=0;
	int sum;

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

	for(i=0;i<row;i++)
	{
		for(j=0;j<col;j++)
		{
			if(shuzu[i][j]==0)
			{
				m+=1;
				break;
			}
		}
	}

	for(j=0;j<col;j++)
	{
		for(i=0;i<row;i++)
		{
			if(shuzu[i][j]==0)
			{
				n+=1;
				break;
			}
		}
	}

	sum=(m-2)*(n-2);
	printf("%d",sum);
	return 0;
}


int main(){
	int n;
	int sz[500][500];
	scanf("%d",&n);
	int i,j;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			scanf("%d",&sz[i][j]);
		}
	}
	int mincol=n,minrow=n,maxcol=0,maxrow=0;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if(sz[i][j]==0){
				if(i<mincol){
					mincol=i;
				}
				if(j<minrow){
					minrow=j;
				}
				if(i>maxcol){
					maxcol=i;
				}
				if(j>maxrow){
					maxrow=j;
				}
			}
		}
	}
	int zong;
	zong=(maxcol-mincol-1)*(maxrow-minrow-1);
	printf("%d",zong);
	return 0;
}


int main()
{
	int a;
         scanf ("%d",&a);
	if (a==9)
	    printf ("9\n");
	else if (a==6)
		printf ("2\n");
	return 0;
}


int main()
{
	int sz[100][100];
    int row,col,n,x=0,k;
	scanf("%d",&n);
    for(row=0;row<n;row++)
	{
	    for(col=0;col<n;col++)
		{
		scanf("%d",&(sz[row][col]));
		}
	}

k=2;

	for(row=k;row<n-k;row++)
	{
	    for(col=k;col<n-k;col++)
		{
		     if(sz[row][col]!=0)
			 {
			 x++;
			 }
		}
	}

	 printf("%d\n",x);

	 return 0;
}


int main()
{
	int n,feiwu,x,l,s,i;
	scanf("%d",&n);
	for(i=0;i<n*n;i++)
	{
		scanf("%d",&feiwu);
		if(feiwu==0)
		{x=i+1;break;}
	}
	for(i++;i<n*n;i++)
	{
		scanf("%d",&feiwu);
		if(feiwu!=0)
		{l=i;break;}
	}
	s=l-x+1;
    for(i++;i<n*n;i++)
	{
		scanf("%d",&feiwu);
		if(feiwu==0)
			s++;
	}
	printf("%d",(l-x-1)*(s-2*(l-x+1))/2);
	return 0;
}


int main()
{
   int a[ROW][COL];
   int row,col,n;
   int b=0,c;
   scanf("%d",&n);
   for(row=0;row<n;row++)
   {
	   for(col=0;col<n;col++)
	   {
		   scanf("%d",&a[row][col]);}
   }
for(row=0;row<n;row++)
   {
	   for(col=0;col<n;col++)
	   {
		   if(a[row][col]==0)
		   b++;
}
}
c=(b-4)*(b-4)/16;
printf("%d",c);
return 0;
		   }


int main()
{
   int val[LEN][LEN];
   int i,j,posr,posc,n,r,c,flag=0;

   scanf("%d",&n);

   for (i=0;i<=n-1;i++)
       for (j=0;j<=n-1;j++)
           scanf("%d",&val[i][j]);

   for (i=0;i<=n-1;i++)
       for (j=0;j<=n-1;j++)
           if (val[i][j]==0&&flag==0)
              {flag=1;posr=i;posc=j;}

   i=posr;
   while (val[i++][posc]==0);

   r=i-posr-3;

   for (j=posc;val[posr][j]==0;j++);
   c=j-posc-2;

   printf("%d",r*c);

   getchar();getchar();

   return 0;

}


int main (){
	int n ,k,i,j,count=0,fx,fy,lx,ly,start=0;
	int a[1002][1002];
//	double e,x,t,sum,a,b,c,d;
//	scanf("%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e);
	scanf("%d",&n);

	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			scanf("%d",&a[i][j]);
			if(start==0&&a[i][j]==0){
				start=1;
				fx=i;fy=j;
			}
			if(a[i][j]==0){
				lx=i;
				ly=j;
			}

	}
	}

	printf("%d\n",(fx-lx+1)*(fy-ly+1));

	getchar();getchar();
	return 0;
}


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

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

		}
		for(j=0;j<n;j++)
		{
			if(a[j]==0&&a[j+1]==0)
			{
				break;
			}
			if(a[j]==0)
				key=1-key;
			if(a[j]*key!=0)
				count=count+1;
		}

	}
	printf("%d",count);
	return 0;
}


int main(){
	int n, sum;
	int i, j, starti, startj, endi, endj;
	int a[10][10];
	scanf("%d", &n);
	for (i=0;i<n;i++)
		for (j=0;j<n;j++)
			scanf("%d", &a[i][j]);
	starti = -1;
	startj = -1;
	for (i=0;i<n;i++)
	{
		for (j=0;j<n;j++)
			if (a[i][j] == 0)
			{
				starti = i;
				startj = j;
				break;
			}
		if (starti>=0) break;
	}
	endi = starti;
	endj = startj;
	while (a[starti][endj+1] == 0) endj++;
	while (a[endi+1][startj] == 0) endi++;
	printf("%d", (endi - starti - 1) * (endj - startj - 1));

	return 0;
}


int main()
{
    int n,hang,hang2,hang3,lie,lie2,lie3,squ;
    squ=0;
    scanf("%d",&n);
    int a[n][n];
    for(hang=0;hang<n;hang++)
    {
        for(lie=0;lie<n;lie++)
        {
            scanf("%d",&a[hang][lie]);
        }
    }
    for(hang=1;hang<n-1;hang++)
    {
        for(lie=1;lie<n-1;lie++)
        {
            for(hang2=hang;a[hang][lie]==255&&hang2>=0;hang2--)
            {
                if(a[hang2][lie]==0)
                {
                    for(hang3=hang;hang3<n;hang3++)
                    {
                        if(a[hang3][lie]==0)
                        {
                            for(lie2=lie;lie2>=0;lie2--)
                            {
                                if(a[hang][lie2]==0)
                                {
                                    for(lie3=lie;lie3<=n;lie3++)
                                    {
                                        if(a[hang][lie3]==0)
                                        {
                                            squ+=1;
                                            break;
                                        }
                                    }
                                    break;
                                }
                            }
                            break;
                        }
                    }
                    break;
                }
            }
        }
    }
    printf("%d",squ);
    return 0;
}


int main()
{
	int n,i,j;
	int count=0;
	int s=0;
	scanf("%d",&n);
	for (j=0;j<(n*n);j++)
	{
		scanf("%d",&i);
		if (i==0)
			count++;
	}
	count=count/4-1;
    s=count*count;
	printf("%d",s);
	return 0;
}


int main()
{
	int n[1000][1000]={0};
	int a;
	scanf("%d",&a);
	int i,j;
	int zuoi=0,zuoj=0,youi=0,youj=0,jump1=0,jump2=0;
	for(i=0;i<a;i++)
	{
		for(j=0;j<a;j++)
		{
			scanf("%d",&n[i][j]);
		}
	}
	for(i=0;i<a;i++)
	{
		for(j=0;j<a;j++)
		{
			if(n[i][j]==0)
			{
				zuoi=i;
				zuoj=j;
				jump2=1;
				break;
			}
		}
		if(jump2==1)
			break;
	}
	for(i=a-1;i>=0;i--)
	{
		for(j=a-1;j>=0;j--)
		{
			if(n[i][j]==0)
			{
				youi=i;
				youj=j;
				jump1=1;
				break;
			}
		}
		if(jump1==1)
			break;
	}
	int num;
	if(youi==zuoi||youj==zuoj)
	{
		num=0;
	}
	else
	{
		num=(youi-zuoi-1)*(youj-zuoj-1);
	}
	printf("%d",num);
	return 0;
}


    int sz[ROW][COL];

int main(){
	int row,col,a,b,c,d,t,s,x,n,m=0,l=0;

	scanf("%d",&n);
		for(row=0;row<n;row++){
			for(col=0;col<n;col++){
		scanf("%d",&sz[row][col]);
			}
		}
		for(row=0;row<n;row++){
			for(col=0;col<n;col++){
				if(sz[row][col]==0)
				{
					a=row;
					b=col;
					m=1;

//		printf("%d %d %d\n ",a, b ,m);
					break;
				}
			}
             if(m==1)
			break;
		}
		for(row=n-1;row>=0;row--){
			for(col=n-1;col>=0;col--){

//	printf("%d %d \n ",row,col);

				if(sz[row][col]==0){
				c=row;
				d=col;
				l=1;
//	printf("%d %d %d\n ",c, d ,l);
		break;
			}
		}
               if(l==1)
				break;
		}

		t=c-a-1;
		s=d-b-1;

//		printf("%d %d\n",t,s);

		if(t<0||s<0){
			x=0;}
			else{
		x=t*s;
}
		printf("%d\n",x);
		return 0;
}


int main ()
{
	int num[100][100];
	int lefti = 0, leftj = 0, righti = 0, rightj = 0;
	int number = 0;
	int n = 0;
	int i, j;
	scanf ("%d", &n);
	memset(num, -1, 10000);
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < n; j++)
		{
			scanf ("%d", &num[i][j]);
		}
	}
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < n; j++)
		{
			if (num[i][j] == 0 && num[i+1][j] == 0 && num[i][j+1] == 0)
			{
				lefti = i;
				leftj = j;
			}
			else if (num[i][j] == 0 && num[i-1][j] == 0 && num[i][j-1] == 0)
			{
				righti = i;
				rightj = j;
			}
		}
	}
	number = (rightj - leftj - 1) * (righti - lefti - 1);
	printf ("%d\n", number);
	printf ("%d %d %d %d", lefti, leftj, righti, rightj );
	return 0;
}


int main()
{
    int image[1000][1000];
    int n, i,j,area, begRow,begCol,endRow,endCol,isBreak;

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

    isBreak = 0;
    for(i=0;i<n;i++){
        for(j=0;j<n;j++)
        {
           if(image[i][j]==0)
           {
              begRow = i; begCol = j; isBreak = 1; break;
           }
        }
        if( isBreak )  break;
    }

    for(i=begRow;i<n;i++)
    {
           if( i==(n-1) && image[i][begCol]==0) endRow = i;
           else if(image[i][begCol]!=0)
           {
              endRow = i-1; break;
           }
    }

    for(j=begCol;j<n;j++)
    {
           if( j==(n-1) && image[begRow][j]==0) endCol = i;
           else if(image[begRow][j]!=0)
           {
              endCol = j-1; break;
           }
    }

    area = (endRow - begRow - 1)*(endCol - begCol - 1);
    printf("%d", area);
}


int main()
{
	int p;
	int i,n,tmp,squar;
	tmp=0;
	scanf("%d",&n);
	for(i=0;i<n*n;i++)
		{
			scanf("%d",&p);
			if(p==0)
				tmp=tmp+1;
			}
	tmp=tmp/4;
	squar=(tmp-1)*(tmp-1);
	printf("%d\n",squar);
}


int main(){
	int n,i,j,k,p=0,q=0;
	int mianji;
	scanf("%d\n",&n);
	int shu[n];
	int ge[n];
	for(i=0;i<n;i++){
		k=0;
		for(j=0;j<n;j++){
			scanf("%d ",&shu[j]);
			if(shu[j]==0)
				k++;
		}
		ge[i]=k;
		if(ge[i]>p)
			p=ge[i];
		for(j=0;j<n;j++){
			if(shu[j]==0){
				q++;
				break;
			}
		}
	}
	mianji=(p-2)*(q-2);
	printf("%d\n",mianji);
	return 0;
}


int main (void)
{
    int n, i, j, start_row, start_col, end_row, end_col, row, col, value, area;

    scanf ("%i", &n);
    start_row = 0;
    for (i = 1; i <= n; i++)
        for (j = 1; j <= n; j++) {
            scanf ("%i", &value);
            if (!value) {
                       row = i;
                       col = j;
                       if (start_row == 0)
                          start_row = row, start_col = col;
            }
        }
    end_row = row, end_col = col;
    area = (end_row - start_row - 1) * (end_col - start_col - 1);
    printf ("%i", area);

    return 0;
}


int main()
{
    int n=0,a=0,b=0,i=0,t=0,r=0;
    int row(int,int);
    int col(int,int);
    scanf("%d",&n);
    for(i=0;i<(n*n);i++){
        scanf("%d",&t);
        if(!a&&!t)a=i;
        else if(!t) b=i;
        }
    a++;b++;
    r=(col(b,n)-col(a,n)-1)*(row(b,n)-row(a,n)-1);
    printf("%d\n",r);
    return 0;
}
int col(int a,int b)
{
    return a%b;
}
int row(int a,int b)
{
    return ((a-a%b)/b+1);
}


int zhongliu(int, int, int, int);
int num[1001][1001], n;
int main()
{
	int i, j, judge = 0, sum = 0;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < n; j++)
			cin >> num[i][j];
	}
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < n; j++)
		{
			if (num[i][j] == 255)
				judge = zhongliu(i, j, 0 ,1) + zhongliu(i, j, 0, -1) + zhongliu(i, j, 1, 0) + zhongliu(i, j, -1, 0);
			if (judge == 4)
			{
				sum++;
			}
			judge = 0;
		}
	}
	cout << sum;
	cin >> i;

	return 0;
}

int zhongliu(int x, int y, int a, int b)
{
	if (x < 0 || y < 0 || x >= n || y >= n)
		return 0;
	if (num[x][y] == 0)
		return 1;
	else
		return zhongliu(x + a, y + b, a, b);
}


void main(){
	int length,i,j,temp,start=-1,end;
	scanf("%d",&length);
	for(i=0;i<length;i++)
		for(j=0;j<length;j++){
			scanf("%d",&temp);
			if(temp==0){
				if(start==-1) start=i*length+j;
				end=i*length+j;
			}
		}
	printf("%d",(end/length-start/length-1)*(end%length-start%length-1));
}


int main()
{
	int i,j,n,num,min1=2000,min2=2000,max1=-1,max2=-1;
	int area;
	cin>>n;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			cin>>num;
			if(num==0)
			{
				if(i<min1)
					min1=i;
				else if(i>max1)
					max1=i;
				if(j<min2)
					min2=j;
				else if(j>max2)
					max2=j;
			}
		}
	}
	area=(max1-min1-1)*(max2-min2-1);
	cout<<area<<endl;
	return 0;
}


int main()
{
	int n;
	scanf("%d",&n);
	int sz[ROW][COL];
	int x1,y1,x2,y2;
	for(int row=1;row<=n;row++)
	{
		for(int col=1;col<=n;col++)
		{
			scanf("%d",&sz[row][col]);
		}
	}
	for(int row=1;row<=n;row++)
	{
		for(int col=1;col<=n;col++)
		{
			if(sz[row][col]==0)
			{
				x1=row;
				y1=col;
			}
		}
	}
	for(int row=n;row>0;row--)
	{
		for(int col=n;col>0;col--)
		{
			if(sz[row][col]==0)
			{
				x2=row;
				y2=col;
			}
		}
	}
	int s;
	s=(x2-x1+1)*(y2-y1+1);
	printf("%d",s);
	return 0;
}


int abs(int p)
{
  if(p>0) return p;
  else return(-p);
}
int main()
{
  long first,last,i,j;
  int n,a,check=0,sc,sr,ec,er;
  scanf("%d",&n);
  for(i=0;i<n*n;i++)
  {
    scanf("%d",&a);
    if((a==0)&&(check==0)) {first=i;check=1;}
    if(a==0) last=i;
  }
  sc=(first/n);
  sr=(first%n);
  ec=(last/n);
  er=(last%n);
  printf("%d",(abs(sc-ec)-1)*(abs(sr-er)-1));
  return 0;
}


int main(){
int Row=100,Col=100;
int sz[Row][Col];
int n;
int row1;int row2;int i;
int col1;int col2;int k;
scanf("%d",&n);
for(i=0;i<n;i++){
for(k=0;k<n;k++){
scanf("%d",&sz[i][k]);}}
int judge=0;
for(i=0;judge==0&&i<n;i++){
for(k=0;judge==0&&k<n;k++){
if(sz[i][k]==0){
judge=1;

row1=i;

col1=k;}}}
for(i=n-1;judge==1&&i>0;i--){
for(k=n-1;judge==1&&k>0;k--){
if(sz[i][k]==0){

row2=i;

col2=k;
judge=0;}}}
int s;
s=(row2-row1-1)*(col2-col1-1);
printf("%d",s);
return 0;
}


int main(){
    int n;
  //  int xiangsu[1000][1000];
    int head1;
    int head2;
    int end1;
    int end2;
    scanf("%d",&n);
    int xiangsu[n][n];
    int sum;
    int j;
    int i;
    for( i=0;i<n;i++)
    for( j=0;j<n;j++)
    scanf("%d",&(xiangsu[i][j]));

    int f=1;
    for(i=0;i<n;i++){
                     for(j=0;j<n;j++){
                                      if((xiangsu[i][j]==0)&&(f==1)){
                                                                 head1=i+1;
                                                                 head2=j+1;
                                                                 f=0;
                                                                 }
                                      if(xiangsu[i][j]==0){
                                                           end1=i-1;
                                                           end2=j-1;
                                                           }
                                      }
                     }
    sum=(end1-head1+1)*(end2-head2+1);
    printf("%d",sum);
    getchar();
    getchar();
    return 0;
}


int main()
{
	int n,i,j,k,m;
	int left0,right0;
	int left1,right1;
	left0=-1;
	right0=-1;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			scanf("%d",&k);
			if((k==0)&&(left0==-1)&&(right0==-1))
			{
                left0=i;
			    right0=j;
			}
			if(k==0)
			{
				left1=i;
				right1=j;
			}
		}
	}
	int t=0;
	if(((left1-left0)>1)&&((right1-right0)>1))
	{
		m=(left1-left0-1)*(right1-right0-1);
	    printf("%d\n",m);
	}
	else printf("%d\n",t);
	return 0;
}


int main()
{
	int i,j;
	int point[number][number];
	int n,s,sum,result;
	int a,b;
	scanf ("%d", &n);
	for (i=0; i<n; i++) {
		for (j=0; j<n; j++) {
			scanf ("%d", &point[i][j]);
		}
	}
	for (i=0; i<n;) {
		for (j=0; j<n; j++) {
			if (point[i][j]==0) {
				a=a+1;
			}
		}
		if (a!=0) break;
		else i++;
	}
	for (j=0; j<n;) {
		for (i=0; i<n; i++) {
			if (point[i][j]==0) {
				b=b+1;
			}
		}
		if (b!=0) break;
		else j++;
	}
	sum=2*(a+b-2);
	s=a*b;
	result=s-sum;
	printf ("%d\n", result);
	return 0;
}


int xiangsu[1000][1000];
int main(){
    int n;

    int head1;
    int head2;
    int end1;
    int end2;
    scanf("%d",&n);

    int sum;
    int j;
    int i;
    for( i=0;i<n;i++)
    for( j=0;j<n;j++)
    scanf("%d",&(xiangsu[i][j]));

    int f=1;
    for(i=0;i<n;i++){
                     for(j=0;j<n;j++){
                                      if((xiangsu[i][j]==0)&&(f==1)){
                                                                 head1=i+1;
                                                                 head2=j+1;
                                                                 f=0;
                                                                 }
                                      if(xiangsu[i][j]==0){
                                                           end1=i-1;
                                                           end2=j-1;
                                                           }
                                      }
                     }
    sum=(end1-head1+1)*(end2-head2+1);
    printf("%d",sum);
    getchar();
    getchar();
    return 0;
}


int main()
{
	int s,start1,start2,end1,end2,n,sz[100][100];
    scanf("%d",&n);
	int flag = 0;
	start1=0;
	start2=0;
    end1=0;
	end2=0;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
		{
			scanf("%d",&sz[i][j]);
			if(sz[i][j]==0 && flag == 0)
			{
				flag = 1;
				start1=i+1;
				start2=j+1;
			}
			if(sz[i][j]==0)
			{
				end1=i;
				end2=j;
			}
		}
	   //printf("%d %d %d %d\n",start1,start2,end1,end2);
	   s=(end1-start1)*(end2-start2);
       printf("%d\n",s);
       return 0;
}


int matrix[1000][1000];

int main(int argc, char *argv[])
{
    int row,col,k=0,n,i,j,l;
    cin>>n;;
    for(i=0;i<n;i++)
    {
                    for(j=0;j<n;j++)
                    cin>>matrix[i][j];
    }
    for(i=0;i<n;i++)
    {
                    for(j=0;j<n;j++)
                    {
                                    if(matrix[i][j]==0&&matrix[i][j+1]!=0&&matrix[i][j-1]!=0)
                                    {
                                       for(j;j<n;j++)
                                         {
                                           if(matrix[i][j+1]==255)
                                           k++;
                                           else
                                           break;
                                           }
                                    break;
                                    }

                    }
    }
    cout<<k<<endl;

       return 0;
}


int main (){
int n,number[1001],i,p,count,start,end;
count=0;
scanf("%d",&n);
for(i=1;i<=n;i++){
	start=0;
	end=0;
	for(p=1;p<=n;p++){scanf("%d",&number[p]);}
	for(p=1;p<=n-1;p++){
		if(start==0&&number[p]==0&&(p==1||number[p-1]!=0)&&number[p+1]!=0){start=p;}
		if(start!=0&&number[p]==0&&(p==1||number[p-1]!=0)&&number[p+1]!=0){end=p;}
	}
	if(end-start<=1){continue;}
	count+=(end-start-1);

}
printf("%d",count);
return 0;}


int main()
{
	int a[100][100];
	int i,j,k=0,s,n;
	int imin,imax,jmax;
	scanf("%d",&n);
	imin=100;
	imax=0;
    jmax=0;
	for(i=1;i<=n;i++)
	for(j=1;j<=n;j++)
	scanf("%d",&a[i][j]);

	  for(i=1;i<=n;i++)
	  for(j=1;j<=n;j++)
	  {
		  if (a[i][j]==0)
		  {k++;
		  if(i<imin)imin=i;
		  if(i>imax)imax=i;
		  if(j>jmax)jmax=j;
		  }

	  }

	  s=(imax-imin+1)*(jmax-imin+1);
	  printf("%d\n",s-k);
	  return 0;
}


int main(int argc, char* argv[])
{
	int n;
	scanf("%d",&n);
	int picture[1000][1000];
	int hang[1000];
	int i,j;
	int m=0,mg=0,l=0,number;
	for(i=0;i<n;i++)
	{
		hang[i]=0;
		for(j=0;j<n;j++)
		{
			scanf("%d",&picture[i][j]);
			if(picture[i][j]==0)
			{
				hang[i]=hang[i]+1;
			}
		}
		if(hang[i]>2&&m==0)
		{
			m=i;
			mg=hang[i];
		}
		else if(hang[i]>2&&m>0)
		{
			l=i;
		}
	}
	number=(l-m-1)*(mg-2);
	printf("%d",number);

	return 0;
}


int main(){
  int n,i,j,c,ans=0,flag=0;
  scanf("%d",&n);
  for (i=1;i<=n;i++){
    for (j=1;j<=n;j++){
      scanf("%d",&c);
      if (!c){
        if (flag){
          ans=ans+j-flag-1;
          flag=0;
        }else flag=j;
      }
    }
    flag=0;
  }
  printf("%d",ans);
}


int main()
{
    int n;
    cin>>n;
    int a[5];
    int count=1;
    for (int i=0;i<5;i++)
    {
        a[i]=n%10;
        if (n>=10)
        {
        n=(n-a[i])/10;
        count++;
        }
    }
    for (int i=0;i<count;i++)
    {
        cout<<a[i];
    }
    return 0;
}


int main()
{
       int number,ge,shi,bai,qian,wan,place;
	scanf("%d",&number);
	if(number>=10000)
		place=5;
	else
	{
		if (number>=1000)
			place=4;
		else
		{
			if (number>=100)
		    place=3;
			else
			{
				if (number>=10)
			    place=2;
				else
				place=1;

			}
		}
	}
	ge=number%10;
	shi=((number-ge)%100)/10;
	bai=((number-ge-10*shi)%1000)/100;
	qian=((number-ge-10*shi-100*bai)%10000)/1000;
	wan=(number-ge-10*shi-100*bai-1000*qian)/10000;

	switch(place)
	{
     case 5:printf("%d%d%d%d%d",ge,shi,bai,qian,wan);break;
     case 4:printf("%d%d%d%d",ge,shi,bai,qian);break;
     case 3:printf("%d%d%d",ge,shi,bai);break;
     case 2:printf("%d%d",ge,shi);break;
     case 1:printf("%d",ge);
     }
     return 0;
}


main()
{
int i;
char str[100];
scanf("%s",&str);
for(i=strlen(str)-1;i>=0;i--)
printf("%c",str[i]);
getchar();
getchar();
}


int main()
{
 int i=0;
 char str[10000];
 scanf("%s",str);
 while(str[i]!='\0')
  i++;
 for(i--;i>=0;i--)
 printf("%c",str[i]);
 printf("\n");
 getchar();
 getchar();
 getchar();
 getchar();
}


int main()
{
	int x,i,result=1;
	scanf("%d",&x);

	if(!x)
		printf("0");
	while(x)
	{
		printf("%d",x%10);
		x=x/10;
	}
	printf("\n",result);
	return 0;
}


int main()
{
	int m,n;
	int i=0;
	char c[100];

	char d[100];
	char e[100];
	gets(c);
	n=m=strlen(c);
	do
	{
		d[i]=c[m-1];
		m=m-1;
		i++;
	}while(m>=1);
	d[n]=32;
	sscanf(d,"%[^ ]",e);
	puts(e);
	scanf("%d",&m);
	return 0;
}


int main()
{
	char *p;
	p=(char *)malloc(sizeof(char)*8);
	int i;
	for(i=0;i<6;i++)
	{
		scanf("%c", p);
		if(*p=='\n')
		{
			*p=0;
			break;
		}
		p++;
	}
	for(i=i-1;i>=0;i--)
	{
		p--;
		printf("%c", *p);
	}
	return 0;
}


void main()
{
	long int n;
	int indiv,ten,hundred,thousand,place;
	scanf("%ld",&n);
	if(n>999)
		place=4;
	else if (n>99)
		place=3;
	else if (n>9)
		place=2;
	else place=1;
	thousand=n/1000;
	hundred=(int)(n-thousand*1000)/100;
	ten=(int)(n-thousand*1000-hundred*100)/10;
	indiv=(int)(n-thousand*1000-hundred*100-ten*10);
	switch(place)
	{
	case 4: printf("%d%d%d%d",indiv,ten,hundred,thousand);
	    break;
	case 3: printf("%d%d%d",indiv,ten,hundred);
		break;
	case 2: printf("%d%d",indiv,ten);
		break;
	case 1: printf("%d",indiv);
		break;
	}
}


int main()
{
int a=0,b=0;
cin>>a;
if(a!=0)
while(a!=0)
{
   b=a%10;
   cout<<b;
   a=a/10;
}
else
	cout<<0;

}


int main()
{
    int n, i = 10;
    cin >> n;
    if(n < 10)
        cout << n << endl;
    else
        if(n == 10)
        cout << 01 << endl;
        else
           {
                while(n > 0)
             {
                cout << n % i;
                n = n / i;

             }
           }
    return 0;
}


int main()
{
	int a;
	int reverse(int m);
	scanf("%d",&a);
	reverse (a);
	return 0;
}
int reverse(int m)
{
	printf("%d",m%10);
	m=m/10;
	if (m!=0) return reverse(m);
}


int main()
{
    int n;
    int i;
    scanf("%d",&n);
    int k,count=0,s=1;
    int sum=0;
    while(n!=0)
    {
         k=n%10;
         if(k==0)
         count++;
         n=n/10;
         sum=sum*10+k;
    }
    for(i=1;i<=count;i++)
    printf("0");
    printf("%d",sum);
    getchar();
    getchar();
}


int main()
{
	int n;
	cin>>n;
	for(;;)
	{
		printf("%d",n%10);
		if(n<10)
			break;
		n=n/10;
	}
	return 0;
}


int main()
{
int n,i;char a[6];
gets(a);
n=strlen(a);
for(i=n-1;i>=0;i--)
{printf("%c",a[i]);}
}


int main()
{
	char num[5];
	int i,len;
	scanf("%s",num);

	len=strlen(num);
	for(i=len-1;i>=0;i--){
		printf("%c",num[i]);
	}
	printf("\n");
	return 0;
}


int main()
{
	char shu[6],temp;
	int i,Lshu;
	cin.getline(shu,6,'\n');
	Lshu=strlen(shu);
	for(i=0;i<Lshu/2;i++)
	{
		temp=shu[i];
		shu[i]=shu[Lshu-1-i];
		shu[Lshu-1-i]=temp;
	}
	cout<<shu;
	return 0;
}


int main()
{
	char str[10000]={0},*start,*end,t;
	int len;
	cin >> str;
	len = strlen(str);
	start = str;
	end = &str[len-1];
	while(start<end){
		t = *start;
		*start = *end;
		*end = t;
		start++;
		end--;
	}
	cout << str;
	return 0;
}


int main()
{
	char zhengshu[10001];
	cin.getline(zhengshu, 10001);
	int length = strlen(zhengshu), i, a[10000];
	for (i = 0; i < length; i++)
	{
		a[i] = zhengshu[i] - '0';
	}
	for (i = length - 1; i >= 0; i--)
	{
		cout<<a[i];
	}
	cout<<endl;
	return 0;
}


void main()
{
	int i;
	scanf("%d",&i);
	while(i)
	{
		printf("%d",i%10);
		i=i/10;
	}
}


int main()
{
	int n,a,b,c;
	scanf("%d",&n);
	b=n;
    do
	{
		a=b%10;
        c=b;
		b=b/10;
        printf("%d",a);
	}
	while(c/10!=0);
	return 0;
}


int main(int argc, char* argv[])
{
int a;
scanf("%d",&a);
if(a==0) printf("0");
while(a>0){
printf("%d",a%10);
a/=10;
}
	return 0;
}


int main(int argc, char* argv[])
{
 char s[80];
 int i;
 gets(s);
 for (i=strlen(s)-1; i>=0; i--)  printf("%c",s[i]);

 return 0;
}


int main()
{
	int n,i;
	cin>>n;
	do{
		cout<<(n%10);
        n/=10;
	}while(n>0);
		return 0;
}


int main()
{
 int i=0;
 char str[5];
 scanf("%s",str);
 while(str[i]!='\0')
  i++;
 for(i--;i>=0;i--)
 printf("%c",str[i]);
 printf("\n");
 return 0;
}


int main ( )
{
	char exp[10], t;
	int i, j;
	cin.getline(exp, 10);
	for(i = 0,j = strlen(exp)-1;i < j;i++, j--)
	{
		t = exp[i];
		exp[i] = exp[j];
		exp[j] = t;
	}
	for(i = 0;i < strlen(exp);i++)
	{
		cout << exp[i];
	}
	return 0;
}


int main()
{
	int num , len = 0 , i = 0;
	char *p = NULL;
	char a[ 10000 ];
	cin.getline( a , 10000 );
	len = strlen( a );
	p = &a[ len - 1 ];
	for( i = 0 ; i <= len - 1 ; i++ )
		cout << *( p - i );
	return 0;
}


void main()
{
 int n;
 int indiv,ten,hundred,thousand,ten_thousand,place;
 scanf("%d",&n);
 if(n>9999)
	place=5;
 else if(n>999)
	place=4;
 else if(n>99)
	place=3;
 else if(n>9)
	 place=2;
 else
	 place=1;
ten_thousand=(int)(n/10000);
thousand=(int)((n-ten_thousand*10000)/1000);
hundred=(int)((n-10000*ten_thousand-1000*thousand)/100);
ten=(int)((n-10000*ten_thousand-1000*thousand-100*hundred)/10);
indiv=(int)(n-10000*ten_thousand-1000*thousand-100*hundred-10*ten);
switch(place)
{case 5:
        printf("%d%d%d%d%d\n",indiv ,ten,hundred,thousand,ten_thousand);
		break;
case 4:
        printf("%d%d%d%d\n",indiv,ten,hundred,thousand);
		break;
case 3:
        printf("%d%d%d\n",indiv,ten,hundred);
		break;
case 2:
        printf("%d%d\n",indiv,ten);
		break;
case 1:
        printf("%d\n",indiv);
		break;
}
}


main()
{
      char a[10],b[10];
      gets(a);
      int i,l;
      l=strlen(a);
      for (i=0;i<l;i++)
      {
          b[l-i-1]=a[i];
      }
      b[l]='\0';
      puts(b);
      getchar();
      getchar();
}


void main()
{
   int n=0,num,m,a,b;
   scanf("%d",&num);
   m=num;
   do
   {n=n*10+num%10;
    num=num/10;
    }while(num!=0);

   int weishu(int x);
   a=weishu(m);
   b=weishu(n);
   if(a-b==4)printf("0000%d\n",n);
   else if(a-b==3)printf("000%d\n",n);
   else if(a-b==2)printf("00%d\n",n);
   else if(a-b==1)printf("0%d\n",n);
   else printf("%d\n",n);
}

int weishu(int x)
{
	int y;
	if(x>=10000)y=5;
	else if(x>=1000)y=4;
	else if(x>=100)y=3;
	else if(x>=10)y=2;
	else y=1;
	return(y);
}


void reverse(char s[],int a,int b){
	int i,j;
	char temp;
	for(i=a,j=b-1;i<j;i++,j--){
		temp=s[i];
		s[i]=s[j];
		s[j]=temp;
	}
	for(i=a;i<b;i++){
		printf("%c",s[i]);
	}
	printf("\n");
}

void main(){
	char string[10];
	int len;
	gets(string);
	len=strlen(string);
	reverse(string,0,len);
}


int main()
{int a,n;
  scanf("%d",&n);
if(n==0) printf("%d\n",n);
else{
for(;n>0;)
  {a=n%10;
   printf("%d",a);
   n=n/10;
   }
}
printf("\n");
return 0;
}


int main()
{
	int n;
	void reverse(int n);
	scanf("%d",&n);
	reverse(n);
	return 0;
}
void reverse(int n)
{
	if(n < 1)
		return;
	printf("%d",n % 10);
	reverse(n / 10);
}


int main()
{
   int n;
   int tmp;
   scanf("%d",&n);
   while(1){
	   tmp=n%10;
	   printf("%d",tmp);
	   if(!(n=n/10))break;
   }
   printf("\n");
   return 0;
}


int main() {
	char str[1000];
	cin >> str;
	for (int i = strlen(str)-1; i >= 0; i--)
		cout << str[i];
	return 0;
}


int main()
{
	int a,n,b,c,d,e,f,g;
	scanf("%d",&n);
	b=0;
	a=n;
	if (n==0)
		printf("0");
	else
	while(a>0)
	{
	  a=(int)(a/10);
	  b=b+1;
	}
    c=n%10;
	d=(int)(n/10)%10;
	e=(int)(n/100)%10;
    f=(int)(n/1000)%10;
	g=(int)(n/10000);
	switch (b)
	{case 1:printf("%d\n",n);break;
   	 case 2:printf("%d%d\n",c,d);
		 break;
	 case 3:
		    printf("%d%d%d\n",c,d,e);
			break;
     case 4:
		   printf("%d%d%d%d\n",c,d,e,f);
			break;
   	case 5:
		   printf("%d%d%d%d%d\n",c,d,e,f,g);
			break;
	}
	return 0;
}


long num;
long digit[5];
int main()
{
   int count=0,i;
   long number;
   do
       {
           scanf("%ld",&num);
       }
   while(num<0||num>99999);
   count=0;
   number=num;
   do
       {
           digit[count++]=number%10;
           number=number/10;
       }
   while(number>0);
   for(i=0;i<count;i++)
       printf("%ld",digit[i]);
}


void function(int num){
	cout<<num%10;
	if ((num/10)!= 0)
		function (num/10);
}
int main(){
	int num;
	cin>>num;
	function (num);
return 0;
}


int main()
{
	int a,b;
    scanf("%d",&a);
	b=0;
	while(a)
	{
		b=a%10;
		printf("%d",b);
        a=a/10;
	}
	return 0;
}


int a[10];

int main()
{
    int x;int k=0;
    cin>>x;
    if(x==0) cout<<x<<endl;
    else
    {
    while(x>0)
    {
              a[k++]=x%10;
              x=x/10;
    }
    for(int i=0;i<k;i++)
      cout<<a[i];
    cout<<endl;
    }
    return 0;
}


int main()
{
	char n[5];
	int i, k, j;
	cin.getline(n, 5);
	for (i = 0;n[i] != '\0'; i++)
	{
		k = i;
	}
	for (j = k; j >= 0; j--)
		cout << n[j];
	return 0 ;
}


int main()
{
	int n, a=0, i=5, m=0, b;
	cin >> n;
	do
	{
		cout << n%10;
		n=n/10;
	}while(n!=0);
	return 0;
}


int main()
{
    int n,i,k,out;
    int A[5];
    scanf("%d",&n);
    for(i=1;1<=5;i++)
    {
        if (n<1) break;
         printf("%d",n%10);
         n=n/10;

     }
 return 0;
}


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


int main()
{
	int n;
	cin >> n;
	if (n == 0) cout << 0;
	for (int i = 0; n; i++)
	{
		cout << n % 10;
		n /= 10;
	}
    return 0;
}


//??????????
int main()
{
	char	num[5];
	cin >> num;
	int	nl = strlen(num);

	int	i;
	for (i = 0; i < (int)(nl / 2); i ++)
	{
		char	k;
		k = num[i];
		num[i] = num[nl - 1 - i];
		num[nl - 1 - i] = k;
	}

	cout << num;
	cout << endl;

	return 0;
}


int main()
{
	char num[6];
	int i,n,nnum[6],p=0;
	scanf("%s",num);
	n=strlen(num);

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

	return 0;
}


int main()
{
	int i,count=0;
	char a[20000];
	while( ( a[count] = getchar() ) != '\n' )
	{
		count++;
	}
	for( i = count-1; i >= 0; i-- )
		printf("%c",a[i]);
	printf("\n");
}


int main ()
{
	int n , i , j;
	i = 0;
	char a[9] , ch;
	while ((ch = cin.get()) != '\n' )
	{
		a[i] = ch ;
		i = i + 1;
	}
	i = i - 1;
	while (i >= 0)
	{
		cout << a[i] ;
		i = i - 1;
	}
	cout << endl ;
	return 0;
}


int main()
{
	int num,temp,ge,shi,bai,qian;
	cin>>num;
	temp=num;
	if(num==10000) cout<<"00001"<<endl;
	else if(num==0) cout<<"0"<<endl;
	else{
		qian=temp/1000;
	    temp=temp-qian*1000;
	    bai=temp/100;
	    temp=temp-bai*100;
	    shi=temp/10;
	    ge=temp-shi*10;
		if(num>=1&&num<=9) cout<<ge<<endl;
		else if(num>=10&&num<=99) cout<<ge<<shi<<endl;
		else if(num>=100&&num<=999) cout<<ge<<shi<<bai<<endl;
		else cout<<ge<<shi<<bai<<qian<<endl;
	}
	return 0;
}


int main(int argc, char* argv[])
{
 int input;
 int ret,num;
 scanf("%d",&input);

for(;;)
 {
    if(input<10)
   {
    printf("%d\n",input);
break;
   }
   num=input%10;
  input=input/10;

  printf("%d",num);

 }

 return 0;
}


int main()
{
	int num,a,b,c,d,e,p;

	scanf("%d",&num);

    if(num>=10000)
	p=5;
	else if(num>=1000)
	     p=4;
	     else if(num>=100)
	     p=3;
	          else if(num>=10)
	         p=2;
	               else
	               p=1;
	a=(int)(num/10000);
	b=(int)(num%10000/1000);
	c=(int)(num%1000/100);
	d=(int)(num%100/10);
	e=(int)(num%10);

   switch(p)
	{
	case 5:printf("%d%d%d%d%d",e,d,c,b,a);break;

	case 4:printf("%d%d%d%d",e,d,c,b);break;
	case 3:printf("%d%d%d",e,d,c);break;
	case 2:printf("%d%d",e,d);break;
	case 1:printf("%d",e);break;

	}
}


int main()
{
	int number,i,m,x[5];
	scanf("%d",&number);
	if (number<=9) i=1;
	else if(number<=99) i=2;
	else if(number<=999) i=3;
	else if(number<=9999) i=4;
	else i=5;
	for(m=0;m<=i-1;m++)
		{
		x[m]=number%10;
	    number=(number-x[m])/10;
	     }
	for(m=0;m<=i-1;m++)
		printf("%d",x[m]);

	return 0;

}


int main()
{
	char c, i = 0;
	char num[7] = {0};
	while((c = cin.get()) != '\n')
	{
		num[i ++] = c;
	}
	for (i = i - 1;i >= 0; i --)
		cout << num[i];
	cout << endl;
	return 0;
}


int main()
{
	float a,b,c;
	int d,e,f,g,h,j,k,l,m,i,n;
	char p[10];
	scanf("%s",p);
	for (i=strlen(p)-1;i>=0;i--)
		printf("%c",p[i]);
	return 7;
}


int main()
{
	int x,a,b,c,d,e,n;
	scanf("%d",&x);
	if(x==0)
		printf("0");
	n=(int)log10((double)x);
	a=x/10000;
	x=x-a*10000;
	b=x/1000;
	x=x-b*1000;
	c=x/100;
	x=x-c*100;
	d=x/10;
	e=x-d*10;

	switch(n)
	{
		case 0:printf("%d",e);break;
		case 1:printf("%d%d",e,d);break;
		case 2:printf("%d%d%d",e,d,c);break;
		case 3:printf("%d%d%d%d",e,d,c,b);break;
		case 4:printf("%d%d%d%d%d",e,d,c,b,a);
	}

	return 0;
}


int main()
{
	int n,a,b,c,d,e;
	scanf("%d",&n);
	while(n!=0)
	{
	a=n%10;
	printf("%d",a);
	n=n/10;
	}
	return 0;
}


int main()
{
	int a,b,c;
	cin>>a;
	for(int i=1;;i++)
	{
		b=a%10;
		cout<<b;
		c=a/10;
		if(c==0)
			break;
		a=c;
	}
}


int main()
{
    int i,l;
    char s[4],r[4];
    scanf("%s",s);
    l=strlen(s);
    for(i=0;i<l;i++)
    {
      r[i]=s[l-1-i];
    }
    for(i=0;i<l;i++)
    printf("%c",r[i]);
    getchar();
    getchar();
}


main()
{
  char a[6];
  gets(a);
  int i,j;
  j=strlen(a);
  for(i=j-1;i>=0;i--)
  printf("%c",a[i]) ;
  getchar();
  getchar();
}


int main()
{
	int n;
	cin>>n;
	if(n==0)
	{
		cout<<n;
	}
	else
	{
		while (n)
		{
		cout<<n%10;
		n/=10;
		}
	}
	return 0;
}


int main()
{
	int n, a, b, i;
	cin >> n;
	if ( n == 0)
		cout << n << endl;
	else
	{
	    for ( i = 1; ; i++)
		{
		    a = n / 10;
		    b = n - (a * 10);
		    if (a == 0 && b == 0)
			    break;
		    cout << b;
		    n = a;
		}
	}
	cout << endl;
    return 0;
}


//*5-1
int MyInverseitoa(int iNum, char*ch,  int radix)
{
	int iBits=0;
   //?iNum?????10?????????????????
	do
	{
		ch[iBits]=iNum%radix;  //
		printf("%d",ch[iBits]);
		iNum/=radix;
		iBits++;
	} while (iNum);
	ch[iBits]='\0';
	return iBits-1;
}

int main()
{
	int iNum, iNumInverse, iBits=0;

	char ch[12];  ///int ??10?
	scanf("%d", &iNum);
	if (iNum==0)
	{
		iNumInverse=iNum;
		printf("%d", iNumInverse);
	}
	else
	{
		iBits = MyInverseitoa(iNum, ch,10);  //?????'\0'
		//iNumInverse = Myatoi(ch, iBits);
		//printf("%d", iNumInverse);
	}

	return 0;
}


int main()
{
	int n;
	scanf("%d", &n);
	if (n==0)
		printf("0");
	while (n>0)
	{
		printf("%d", n%10);
		n/=10;
	}

	return 0;
}


int power(int x)
{
	int k,y=1;
	for(k=1;k<=x;k++)
		y=y*10;
	return y;
}

int main()
{
	int n,i,j,a[6],temp;
	cin>>n;
	for(i=1;i<=5;i++)
		if(n%power(i)==n)
		{
			j=i;
			break;
		}
	i=0;
	for(i=0;i<j;i++)
	{
		a[i]=n%10;
		n=n/10;
		cout<<a[i];
	}
	return 0;
}


int main(void)
{
	int n;
	cin >> n;
	if(n == 0) cout << 0;
	for(int i = 1; n != 0; i++)
	{
		cout << n % 10;
		n /= 10;
	}
	cout << endl;
	return 0;
}


void main()
{
	int a,temp,p,q;
	scanf("%d",&a);
	temp=a;
	if(a!=0)
	{while(temp%10-temp!=0||(temp%10-temp==0&&q>=10))
	{
		p=temp%10;
		printf("%d",p);
		q=temp;
		temp=temp/10;
	}
	}
	else
		printf("0");
	printf("\n");
}


void reverse() {
    int k;
    if ((k = getchar()) == '\n') return;
    reverse();
    printf("%c", k);
}

int main() {
    reverse();
    return 0;
}


int main()
{
	int num,i,j;
	int bit[5];
	i=1;
	cin>>num;
         if (num==0)
         {
              cout<<0;
              return 0;
         }
	while (num>0)
	{
		bit[i]=num%10;
		num=num/10;
		i=i+1;
	}
	for (j=1;j<i;j++) cout<<bit[j];
	return 0;
}


int main()
{
 int n,len=0,temp[6];
 cin>>n;
if(n==0) cout<<n;
 while(n>0)
 {
  temp[len++]=n%10;
   n=n/10;
  }
  for(int i=0;i<len;i++)
  cout<<temp[i];
  return 0;
}


int main()
{
int a,r;
scanf("%d",&a);
r=a%10;
do
{
printf("%d",r);
a=a-r;
a=a/10;
r=a%10;
}
while(a>=1);
return 0;
}


int main(int argc, char *argv[])
{
    long a, original;
    cin >> a;
    original = a;
    int dig1, dig2, dig3, dig4, dig5;
    int NumofDig;
    dig1 = a/10000;
    a = a - 10000*dig1;
    dig2 = a/1000;
    a = a - 1000*dig2;
    dig3 = a/100;
    a = a - 100*dig3;
    dig4 = a/10;
    a = a - 10*dig4;
    dig5 = a;
    if(dig1)
    NumofDig = 5;
    else
        {
        if(dig2)
        NumofDig = 4;
        else
            {
            if(dig3)
            NumofDig = 3;
            else
                {
                if(dig4)
                NumofDig = 2;
                else
                NumofDig = 1;
                }
            }
        }
    long Oppo;
    Oppo = dig5*10000 + dig4*1000 +dig3*100 +dig2*10 +dig1;
    switch(NumofDig)
    {
        case 5 :
             cout << "00001" <<endl;
             break;
        case 4 :
             cout << dig5 << dig4 << dig3 << dig2 <<endl;
             break;
        case 3 :
             cout << dig5 << dig4 << dig3 <<endl;
             break;
        case 2 :
             cout << dig5 << dig4 <<endl;
             break;
        case 1 :
             cout << dig5 <<endl;
             break;
    }

  return EXIT_SUCCESS;
}


int main (void)
{
	int a = 0, b = 0, c = 0, i = 1;
	cin >> a;

	do
	{
		c = a%10;
		a = (a - c)/10;
		cout << c;
	}
	while (a != 0);

	cout <<endl;

	return 0;
}


int main()

{
	int n,a,b,c,d,place;
	scanf("%d",&n);
	if(n>=1000)
		place=4;
    else if(n>99)
		place=3;
    else if(n>9)
		place=2;
	else
		place=1;
	 a=n/1000;
	 b=(int)(n-a*1000)/100;
	 c=(int)(n-a*1000-b*100)/10;
	 d=(int)n%10;
	switch(place)
	{
	case 4:
		printf("%d%d%d%d\n",d,c,b,a);
		break;
    case 3:
		printf("%d%d%d\n",d,c,b);
		break;
    case 2:
		printf("%d%d\n",d,c);
		break;
	case 1:
		printf("%d\n",d);
		break;
	}
	return 0;
}


int main(void)
{

    char a[10];
    int i=0;
    int n;
    while((a[i]=getchar())!='\n')
        i++;
    n = i;
        for(i=n;i>=0;i--)
    printf("%c",a[i]);
    return 0;
}


//*5-1
int MyInverseitoa(int iNum, char*ch,  int radix)
{
	int iBits=0;
   //?iNum?????10?????????????????
	do
	{
		ch[iBits++]=iNum%radix;  //
		iNum/=radix;
	} while (iNum);
	ch[iBits]='\0';
	return iBits-1;
}

int Myatoi(char*ch, int iBits)
{
	int iNumInverse=0;
	int i=0;
//100->001
	while (ch[i]=='\0')
	{
		i++;
		printf("0");
	}
	for (i=0; i<=iBits; i++)
	{
		iNumInverse=10*iNumInverse+ch[i];
	}
	return iNumInverse;
}

int main()
{
	int iNum, iNumInverse, iBits=0;

	char ch[12];  ///int ??10?
	scanf("%d", &iNum);
	if (iNum==0)
	{
		iNumInverse=iNum;
		printf("%d", iNumInverse);
	}
	else
	{
		iBits = MyInverseitoa(iNum, ch,10);  //?????'\0'
		iNumInverse = Myatoi(ch, iBits);
		printf("%d", iNumInverse);
	}

	return 0;
}


int main()
{
	char a[100];
	char b[100];
	int l;

	cin >> a;

	l = strlen(a);

	for(int i = 0; i < l; i ++)
	{
		b[i] = a[l - i - 1];
		cout << b[i];
	}

	return 0;
}


int main()
{
int a,n;
scanf("%d",&n);
if(n<10)
printf("%d",n);
else if(n==10)
printf("1");
else
{do
{a=n%10;
printf("%d",a);
n=(n-a)/10;
}
while(n>=10);
a=n;
printf("%d",a);
}
return 0;
}


int main()
{
	int n;
	cin >> n;
	int mod;

	if (n == 0)
	{
		cout << 0 << endl;
	}
	else
	{

		while (n != 0)
		{
			mod = n % 10;
			cout << mod;
			n /= 10;
		}
	}

	cout << endl;

	return 0;
}


int main()
{
    int a,r,i;
    scanf("%d",&a);
    r=0;
	i=0;
    while(a>0)
    {
        r=r*10+a%10;
		i=i+!(a%10);
        a=a/10;
    }
	switch(i)
	{
	case 0:
		printf("%d\n",r);break;
	case 1:
		printf("0%d\n",r);break;
	case 2:
		printf("00%d\n",r);break;
	case 3:
		printf("000%d\n",r);break;
	case 4:
		printf("0000%d\n",r);break;
	}
    return 0;
}


int main()
{
     int n,decade,hundred,thousand;
	 cin >> n;
	 cout << n-n/10*10 ;
	 if(n >= 10)
	 {
         decade = n/10 ;
		 cout << decade-decade/10*10 ;
	 }
	 if(n >= 100)
	 {
         hundred = decade/10 ;
		 cout << hundred-hundred/10*10 ;
	 }
	 if(n >= 1000)
	 {
          thousand = hundred/10 ;
		 cout << thousand-thousand/10*10 ;
	 }
	 if(n == 10000)
	 cout << "1" << endl;
	 return 0;
}


void p( int num )
{
while( num )
{
cout<<num%10;
num /= 10;
}
}
int main()
{
int l;
cin>>l;
if(l!=0)
p( l );
else
cout<<0;
return 0;
}


int main()
{
	int n,i;
	scanf("%d",&n);
	do
	{
		printf("%d",(n%10));
		n=(int)n/10;
	}while (n>0);
	return 0;
}


int b[5],m=0;
int f(int n)
{
 int c;
 if(n==0) return (0);
 else
 {
  b[m]=n%10;
  m++;
  c=n/10;
  return f(c);}
}
void main()
{
 int n,i;
 scanf("%d",&n);
 f(n);
 for(i=0;i<m;i++)
 printf("%d",b[i]);
}


int main() {
	char str[101];		//??
	scanf("%s", str);	//??
	int len = strlen(str);
	for (int i = len - 1; i >= 0; --i)
		printf("%c", str[i]);
	printf("\n");	//?????
}


int main()
{
	char a;
	a=getchar();
	if(a<=57&&a>=48)
	{
		char b;
		b=getchar();
		if(b<=57&&b>=48)
		{
			char c;
			c=getchar();
			if(c<=57&&c>=48)
			{
				char d;
				d=getchar();
				if(d<=57&&d>=48)
				{
					char e;
					e=getchar();
					if(e<=57&&e>=48)
					printf("%c%c%c%c%c",e,d,c,b,a);
					else printf("%c%c%c%c",d,c,b,a);
				}
				else printf("%c%c%c",c,b,a);
			}
			else printf("%c%c",b,a);
		}
		else printf("%c",a);
	}
	else printf("error\n");
	return 0;
}


int main()
{
	int x,a;
	cin >> x;
	if (x == 0)
		cout << "0";
	else
	{
	    while (x != 0)
	    {
		    a = x % 10;
		    x = x / 10;
		    cout << a;
	    }
	}
	cin.get();
    cin.get(); //????
	return 0;
}


int main()
{
int i=0;
char ch[100000],tes;

for(;;i++)
{
	ch[i]=getchar();
	if(ch[i]=='\n')break;

}

for(;i>=0;i--)
	cout<<ch[i];
cout<<endl;

	return 0;
}


int main(int argc, char* argv[])
{
	int a,i;
	scanf("%d", &a);
	for (i=1;i<=4;i++)
	{
	    printf("%d", a%10);
		a=a/10;
		if (a<1) break;
	}
	return 0;
}


void f(int n,int w)
{
	int x;
	x=(int)pow(10,w-1);
	if (w!=1) f(n%x,w-1);
	printf("%d",n/x);
}
int main()
{
	int n;
	scanf("%d",&n);
	int w=(int)(log(n)/log(10))+1;
	f(n,w);
}


 int invert(long m)
 {   printf("%ld", m%10);
     m = m/10;
     if (m>0)
         invert(m)  ;
 }
main()
 {
     long n;

     scanf("%ld", &n);
     invert(n);
     printf("\n");
 }


int main()
{
     int a;
     scanf("%d",&a);
     int b;
     if(a==0) printf("0\n");
     else
     {
         while(a!=0)
         {
                b=a%10;
                a=a/10;
                printf("%d",b);
         }
         printf("\n");
     }
     getchar();
     getchar();
     getchar();
}


int main()
{
    int a,x,y,z,n,b,place;
    scanf("%d",&a);
	if(a>9999)
		place=5;
if(a>999)
		place=4;
else if(a>999)
		place=4;
else if(a>99)
		place=3;
else if(a>9)
		place=2;
else place=1;
    n=a/1000;
	x=a/100%10;
    y=a/10%10;
    z=a%10;
switch(place)
{case 5:printf("00001");
         break;
case 4:printf("%d%d%d%d",z,y,x,n);
 break;

case 3:printf("%d%d%d",z,y,x);
 break;

case 2:printf("%d%d",z,y);
 break;
case 1:printf("%d",z);
 break;

}

}


int main()
{
	int N;
	scanf("%d",&N);
	if (!N) cout << 0 << endl;
	else while (N)
	{
		cout << N%10;
		N/=10;
	}
	return 0;
}


int main()
{
    int n,a,b,c;
    cin >> n;
    b=n;
    c=n;
    if (n<10)
    cout << n;
    else
    {
    int length = 1,k = 10;
   while((c/k) != 0)
    {
      length++;
      k=k*10;
    }
    for (int i=1;i<=length;i++)
    {
    	cout << b%10;
		b=(b-b%10)/10;

    }
    }
	return 0;
}


int main()
{
	int n;
	scanf("%d",&n);
	if(n<10) printf("%d",n);
	else while(n)
	{printf("%d",n%10);
	 n=n/10;
	}
	return 0;
}


int main()
{
	int i;
	scanf("%d",&i);
	do
	{
		printf("%d",i%10);
		i=i/10;

	}while(i!=0);
		return 0;
}


int main()
{
	int i,num,k,a[6];

	cin>>num;
    if(num==0) cout<<num;
	for(i=5;i>=0;i--)
	{
		a[5-i]=num/(pow((float)10,i));
		num=num-a[5-i]*pow((float)10,i);

	}

	for(i=0;i<6;i++)
	{

	if(a[i]!=0) break;

	}

	for(k=5;k>=i;k--)
	{

	cout<<a[k];

	}

	return 0;
}


int main()
{
	int n;
	cin >> n;
	if (n == 0)
		cout << n;
	else
		while(n > 0)
		{
			cout << n % 10;
			n = n / 10;
		}
	cout << endl;
	return 0;
}


int main()
{
    int n;
    int i=0;
    int num[5];
    scanf("%d",&n);
    while( n/10!=0 )
    {
           num[i++]=n%10;
           n/=10;
    }
    num[i]=n;
    for( int m=0;m<=i;m++ )
    printf("%d",num[m]);
printf("\n");
}


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

	int a,c,d;
	scanf("%d",&a);
	c=a;
	while(c>=1)
	{
	d=c-(c/10)*10;
	c=c/10;
	printf("%d",d);

	}
	if (a==0)
	printf("0");
	return 0;
}


// 0001.cpp : Defines the entry point for the console application.
//

int main()
{
    int n,i,k,s;
	scanf("%d",&n);
	i=n;
	s=0;
	while(i>0)
	{
        k=i%10;
		if(k==0) printf("0"),i/=10;
		else
		{
		   i=i/10;
		   s=s*10+k;
        }
    }
	printf("%d\n",s);
	return 0;
}


void f(int n)
{
	cout<<n%10;
	n=n/10;
	if(n)	f(n);
}

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


int main()
{
	int a,b;
	scanf("%d",&a);
	if(a==0) printf("0");
	else
	{
	while(a!=0)
	{
		b=a-a/10*10;
		a=a/10;
		printf("%d",b);
	}
	}
	return 0;
}


int main(){
	int len;
	char str[6];

	cin >> str;
	len = strlen(str);
	for (int i = len - 1; i >= 0; i--)
		cout << str[i];

	return 0;
}


int main()
{
	int a,b,c,d,n;
	scanf("%d",&n);
while (n>0) {
   printf("%d",n%10);
   n=n/10;
}

}


main()
{
    int n;
    scanf("%d",&n);
    int m=0;
    int nn=n;
    for(int i=1;i<5;i++)
    {
       n=n/10;
       if(n==0)
       {
         m=i;
         break;
       }
    }
    int a;
    for(int i=0;i<m;i++)
    {
       a=nn%10;
       printf("%d",a);
       nn=nn/10;
    }
    getchar();
    getchar();
}


struct integ
{
	char num;
	struct integ *next;
}*head,*p1,*p2,*p3,*newhead;
void main()
{
	int i,n=0;
	p1=p2=(struct integ *)malloc(sizeof(struct integ));
	head=NULL;
	for(i=0;;i++)
	{
		scanf("%c",&p1->num);
		if(p1->num<48||p1->num>57)break;
		n++;
		if(n==1)head=p1;
		else p2->next=p1;
		p2=p1;p1=(struct integ *)malloc(sizeof(struct integ));
	}p2->next=NULL;
	for(i=0;i<n;i++)
	{
		p1=head;
		while(p1->next!=NULL)
		{p2=p1;p1=p1->next;}
		if(i==0){p3=newhead=p1;}
		else p3=p3->next=p1;
		p2->next=NULL;
	}
	for(p1=newhead;p1!=NULL;p1=p1->next)
		printf("%c",p1->num);
}


int main()
{int n;
scanf("%d",&n);
int s;
if(n==0)
{printf("0");return 0;}

while(n!=0)
{
	s=n%10;
	n/=10;
	printf("%d",s);
}

  return 0;
}


int main()
{
	int i,n,ge,shi,bai,qian,wan,place=1,j=2;
	scanf("%d",&n);
	for(i=9;i<=10000;i=i*10+9){
		if(n>i) place=j;
                j=j+1;
	}
		wan=n/10000;
        qian=(n-wan*10000)/1000;
        bai=(n-wan*10000-qian*1000)/100;
        shi=(n-wan*10000-qian*1000-bai*100)/10;
        ge=n-wan*10000-qian*1000-bai*100-shi*10;
	switch(place){
	case 5:
		printf("%d%d%d%d%d",ge,shi,bai,qian,wan);
		break;
	case 4:
        printf("%d%d%d%d",ge,shi,bai,qian);
		break;
	case 3:
        printf("%d%d%d",ge,shi,bai);
		break;
	case 2:
        printf("%d%d",ge,shi);
		break;
	case 1:
		printf("%d",n);
		break;
    default:
		printf("error");
	}
	return 0;
}


// pro.cpp : Defines the entry point for the console application.
//

int main(int argc, char* argv[])
{
	int n,b,c=11,i=1,j=1;
	scanf("%d",&n);

	if (n==0)
		printf("%d",n);
	else

		while(n>0)
		{

			b=n%10;
			printf("%d",b);
			n=n/10;

		}

		return 0;
}


int main ()
{
	int n, t, s;
	cin >> n;
	if ( n == 0)
		cout << "0";
	else
	{	for (int i = 10; i <= 100000; i *= 10)
		{
			t = n % i;
			s = t * 10 / i;
			if (s <= 9 && n != 0)
			{
				cout << s;
				n -= t;
			}
			else
				break;
		}
	}
	cout << endl;
    return 0;
}


main()
{
int  sum,len,i;
int  a[10];
scanf("%d",&sum);
if (sum>=10000) len=5;
  else if(sum>=1000) len=4;
     else if(sum>=100) len=3;
       else if(sum>=10) len=2;
          else len=1;
  for (i=1;i<=len;i++)
{  a[i]=sum/(pow(10,(len-i)));
   sum=sum-a[i]*pow(10,(len-i));
}
for (i=1;i<=len;i++)
  printf("%d",a[len-i+1]);
}


int  main(){
	char num[100];
	int k=-1;
	cin >> num[0];
	for (int i = 1; num[i - 1] != '\n';i++, k++){
		cin.get(num[i]);
	}
	for (; k >= 0; k--){
		cout << num[k];
	}
	cout << endl;
	//while (1);return 0;

}


int n;
int num[10];
int main()
{
    int i,t=0;
    memset(num,-1,sizeof(num));
    cin>>n;
    int x=n;
    num[0]=0;
    while(n>0)
    {
              num[t]=n%10;
              n-=n%10;
              n/=10;
              t++;
    }
    for(i=0;i<t;++i)
    {
                       cout<<num[i];
    }
    if(x==0) cout<<0;
    cout<<endl;
    return 0;
}


int main()
{
	int n,a;
	scanf("%d",&n);
	if(n==0)
             printf("0");
         else
         while(n)
	{
		a=n%10;
		n=(n-a)/10;
		printf("%d",a);
	}
	return 0;
}


int main()
{
	int i;
	char s[20];
	printf("\n");
	scanf("%d", &i);
	sprintf(s, "%d", i);
	for(i=strlen(s)-1; i>=0; i--)
	{
		printf("%c", s[i]);
	}
	puts("\n");

	return 0;
}


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

char a[6];
int i,n;
scanf("%s",a);
n=strlen(a);
for(i=1;i<=n;i++)
printf("%c",a[n-i]);
    return 0;
}


int main()
{
  int n,a[5];
  cin>>n;
  for(int i=0;i<5;i++)
     {
         a[i]=n%10;
         n=n/10;
         cout<<a[i];
         if(n==0) break;

      }
   return 0;
}


void fun(int s)
{
	if(s==0)
		return;
	else
	{
		cout<<s%10;
		fun(s/=10);
	}
}
int main()
{
	int s;
	cin>>s;
	if(s==0)
		cout<<s;
	else
	    fun(s);
    return 0;
}


int print(int n);
int main()
{int n;
scanf("%d",&n);
print(n);
return 0;
}
int print(int n){
	int s,a,b;
	a=n;
	s=0;
	if(a==0)
		printf("0");
	else {
	while(a>0){
		b=a%10;
		printf("%d",b);
		a=a/10;
	}
	}
return 0;
}


int main()
{
	char str[10]={'\0'};
	cin.getline(str,10);
	for(int i=strlen(str)-1;i>=0;i--)
	{
		cout<<str[i];
	}
	return 0;
}


int main()
{
	int weishu[5] = {-1, -1, -1, -1, -1}, num, i = 0;
	cin >> num;
	do{
		weishu[i] = num % 10;
		num = num / 10;
		i++;
	}while(num > 0);
	for (i = 0; i < 5; i++)
		if (weishu[i] != -1)
			cout << weishu[i];
	return 0;
}


void fun()
{
    char c;
    if((c=getchar())!='\n')
       fun();
    putchar(c);

}

main()
{
   fun();
   getchar();
}


//??????
int main()
{
	char a[100001];
	cin >> a;
	int l = strlen(a), i = 0;
	for (i = l - 1; i >= 0; i--)
	{
		cout << a[i];
	}
	cout << endl;
	return 0;
}


int main()
{
	char a[1000];
	cin.getline (a,100);
	int i;
	int l=strlen(a);
	for (i=l-1;i>=0;i--)
		cout<<a[i];
	cout<<endl;
}


int main()
{
char a[5];
gets(a);
int i;
for(i=strlen(a);i>0;i--)
printf("%c",a[i-1]);
return 0;
}


int main()
{
	int i,m;
	m=1;
	char s[5];
	scanf("%s",s);
    i=strlen(s);
	i=i-1;
	while (i>=0)
	{
		printf("%c",s[i]);
		i=i-1;
	}
	return 0;
}


//#include <math.h>
//#include <stdlib.h>

int main(void)
{
    int num,temp=0,sub=0,dv=10;;
    scanf("%d",&num);
    int a,b=1;

    if (num==0)
    {
        printf("0");
        return 0;
    }

    while (num!=sub)
    {
        temp=(num-(num/dv)*dv-sub)/(dv/10);
        sub+=temp*(dv/10);

        printf("%d",temp);
        dv*=10;
    }

    return 0;
}


int main(void)
{
	char s[20];
	int l, i;
	scanf("%s", s);
	l = strlen(s);
	for (i = l - 1; i >= 0; i--) printf("%c", s[i]);
	return 0;
}


void nixu( int k );
int main()
{
    int n;
    cin>>n;
     nixu(n);
    return 0;
    }
    void nixu (int k)
    {
      if(k>0)
        {
         cout<<k%10;k/=10;
         nixu (k);
             }
         }


int main()
{
	int a,s,p;
	scanf("%d",&a);
	s=a;
	while(s!=0)
	{
		p=s%10;
		printf("%d",p);
		s=(s-p)/10;
	}
	return 0;
}


int main(int argc, char* argv[])
{
	int n, m;
	scanf("%d",&n);
	if(n==0)
		printf("%d",0);
	else
	{
		while(n!=0)
		{
			m=n%10;
			printf("%d",m);
			n=n/10;
		}
	}
	return 0;
}


int main()
{
    int n;
    int i;
    scanf("%d",&n);
    int k,count=0,s=1;
    int sum=0;
    while(n!=0)
    {
         k=n%10;
         if(k==0)
         count++;
         n=n/10;
         sum=sum*10+k;
    }
    for(i=1;i<=count;i++)
    printf("0");
    printf("%d",sum);
}


int main()
{
    char st[1000],st2[1000];
    while(cin.getline(st,1000)){
    for (int i=1;i<=strlen(st);i++) st2[i-1]=' '; st2[strlen(st)]='\0';

    int count=0,z[1000];
    for (int i=1;i<=strlen(st);i++)
        if (st[i-1]=='(') {count++; z[count]=i;}
        else if (st[i-1]==')')
        {
            if (count>0) {z[count]=0; count--;}
            else {st2[i-1]='?';}
        }
    for (int i=1;i<=count;i++) st2[z[i]-1]='$';
    cout<<st<<endl<<st2<<endl;
    }

    return 0;
}


int amount(char c,char a[101])
{
	int i,amount=0;
	for(i=0;a[i]!='\0';i++)
	{
		if(a[i]==c)
			amount=amount+1;
	}
	return amount;
}

void match(char a[101])
{
	int i,j;
	int p,q;
	p=amount('(',a);
	q=amount(')',a);

	for(i=0;a[i]!='\0';i++)
		{
			if(a[i]=='(')
			{
				for(j=i+1;a[j]!='\0';j++)
				{
					if(a[j]=='(')
						break;
					else if(a[j]==')')
					{
						a[i]=' ';
						a[j]=' ';
						break;
					}
				}
			}
		}

	if(amount('(',a)<p||amount(')',a)<q)
		return match(a);

}

int main()
{
	char s[101];
	int i;
	for(;scanf("%s",s)!=EOF;)
	{
		printf("%s\n",s);
		match(s);
		for(i=0;s[i]!='\0';i++)
		{
			if(s[i]=='(')
				printf("$");
			else if(s[i]==')')
				printf("?");
			else
				printf(" ");
		}
		printf("\n");
	}
	return 0;
}


//#include<math.h>

int main()
{
	char st[101];
	int g[101];
	int len,i,j,left;
	while (scanf("%s",st)!=EOF)
	{
		printf("%s\n",st);
		len=strlen(st);
		left=0;
		for (i=0;i<len;i++)
		{
			if (st[i]=='(')
			{
				left++;
				g[left]=i;
			}
		}
		for (i=left;i>0;i--)
		{
			for (j=g[i]+1;j<len;j++)
				if (st[j]==')')
				{
					st[g[i]]=' ';
					st[j]=' ';
					break;
				}
		}
		for (i=0;i<len;i++)
		{
			if (st[i]==')') printf("?");
			else if (st[i]=='(') printf("$");
			     else printf(" ");
		}
		printf("\n");
	}
	return 0;
}


void output(int a[],int n)
{
  int i;
  for(i=0;i<n;i++)
    switch(a[i])
  {
        case 1:printf("$");break;
        case 0:printf(" ");break;
        case -1:printf("?");break;
  }
  printf("\n");
}
void trans(char s[],int a[],int n)
{
  int i,p[200],k=-1;
  n=strlen(s);
  for(i=0;i<n;i++)
     {
       if((s[i]!='(')&&(s[i]!=')')) a[i]=0;
       else if(s[i]=='(')
                {
                   k++; p[k]=i;
                   a[i]=1;
                }
            else
                {
                   if(k>-1)
                      {
                         a[p[k]]=0;
                         k--;
                         a[i]=0;
                      }
                   else a[i]=-1;
                }
     }
}
void input()
{
  char s[200];
  int a[200],n;
  while(scanf("%s",s)!=EOF)
  {
     n=strlen(s);
     puts(s);
     trans(s,a,n);
     output(a,n);
  }
}
main()
{
  input();
}


int process(void);
int main(void)
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)
		process();
	return 0;
}

int process(void)
{
	char str[105], tstr[105] = {0};
	cin >> str;
	int len = strlen(str);
	int count = 0;
	for(int i = 0; i < len; i++)
	{
		if(str[i] == '(') count++;
		else if(str[i] == ')')
		{
			if(count > 0) count--;
			else tstr[i] = '?';
		}
	}
	count = 0;
	for(int i = len-1; i >= 0; i--)
	{
		if(str[i] == ')') count++;
		else if(str[i] == '(')
		{
			if(count > 0) count--;
			else
			{
				tstr[i] = '$';
			}
		}
	}
	cout << str;
	cout << endl;
	for(int i = 0; i < len; i++)
	{
		if(tstr[i])
			cout << tstr[i];
		else cout << ' ';
	}
	cout << endl;
	return 0;
}


int main()
{
char a[101];
int len;
while(cin >> a)
{
	cout << a << endl << endl;
	len = strlen(a);
	for(int i = 0; i < len ; i++)
	{	if(isalpha(a[i]))
			a[i] = ' ';
		else if(a[i] == '(')
			a[i] = '$';
		else if(a[i] == ')')
			a[i] = '?';
	}
	for(int temp = 0; temp < len/2 ; temp++)
	{
		for(int i = 0; i < len ; i++)
			if(a[i] == '$')
			{
				for(int j = i+1; j < len ; j++)
				{
					if(a[j] == '$')
					{
						break;
					}
					else if(a[j] == '?')
					{
						a[i] = ' ';
						a[j] = ' ';
						break;
					}
				}
			}
	}
	cout << a << endl << endl;
}
cin.get();cin.get();
return 0;
}


void match(char *s,char *r,int len)
{
char stack[100],c;
int top=0;
int pos;
for(pos=0;pos<len;++pos)
r[pos]=' ';
r[len]='\0';
for(pos=0;pos<len;++pos)
{
c=s[pos];
if(c=='(') stack[top++]=pos;
else if(c==')')
if(top>0) top--;
else r[pos]='?';
}
while(top>0)
{ pos=stack[--top];
r[pos]='$';
}
}
void outresult(char s[],char r[])
{puts(s);puts(r);}
int main()
{
char line[101],result[101],ch;
int pos=0;
while((ch=getchar())!=EOF)
{
if(ch!='\n') line[pos++]=ch;
else
{line[pos]='\0';
match(line,result,pos);
outresult(line,result);
pos=0;
}
}
return 0;
}


right(char s[],int i,int n)
{
	int j;
	int left=0,right=0;
	int num=0;

	for(j=i+1;j<n;j++){
		if(s[j]=='(') right++;
		if(s[j]==')') left++;
		if(right<left) {num=1;break;}
	}
	return(num);
}

left(char s[],int i)
{
	int j;
	int left=0,right=0;
	int num=0;

	for(j=i-1;j>=0;j--){
		if(s[j]=='(') right++;
		if(s[j]==')') left++;
		if(right>left) {num=1;break;}
	}
	return(num);
}

trans(char s1[],char s2[])
{
	int len;
	int i;
	len=strlen(s1);

	for(i=0;i<len;i++){
			s2[i]=' ';

			if(s1[i]==')')
			{
				if(left(s1,i)==0) s2[i]='?';
			}

			if(s1[i]=='(')
			{
				if(right(s1,i,len)==0) s2[i]='$';
			}
	}
	s2[len]='\0';
	return;
}

main()
{
	int i,j;
	int n;
	struct aaa
	{
		char s1[105];
		char s2[105];
	};
	struct aaa line[20];

	scanf("%d\n",&n);

	for(i=0;i<n;i++){
		gets(line[i].s1);
		trans(line[i].s1,line[i].s2);
	}

	for(i=0;i<n;i++)
		printf("%s\n%s\n",line[i].s1,line[i].s2);
}


int main()
{
	char str[110];
	int length,i=0;
    while(1)
	{
		cin.get(str,110,'\n');
		if(cin.get()==EOF)
			break;
		length=strlen(str);
		for(i=0;i<length;i++)
			cout<<str[i];
		cout<<endl;
		for(i=length-1;i>=0;i--)
		{
			if(str[i]!='('&&str[i]!=')')
				str[i]=' ';
			else if(str[i]=='(')
			{
				str[i]='$';
				for(int j=i;j<length;j++)
				{
					if(str[j]=='?')
					{
						str[i]=' ';
						str[j]=' ';
						break;
					}
				}
			}
			else if(str[i]==')')
				str[i]='?';
		}
		for(i=0;i<length;i++)
			cout<<str[i];
		cout<<endl;
	}
	return 0;
}


int main()
{
	char str[101];
	int n,i,j,l,k=0;
	char c[101];
	cin >> n;
	for(i=1;i<=n;i++)
	{
		int left=0,right=0;
		int e[101]={0};
		cin >> str;
		l=strlen(str);
		for(j=0;j<l;j++)
		{
			if(str[j]=='(')
			{
				left++;
				e[j]=1;
				c[left]=j;
			}
			if(str[j]==')')
			{
				if(left==0)
				{
					e[j]=2;
				}
				else
				{
					e[c[left]]=0;
					left--;
				}
			}
			else
				continue;
		}
		cout << str << endl;
		for(j=0;j<l;j++)
		{
			if(e[j]==1)
				cout << "$";
			else if(e[j]==2)
				cout << "?" ;
			else
				cout << " " ;
		}
		cout << endl;
	}
	return 0;
}


char c[101], a[101] = { ' ' };
int leftpos[101] = { 0 }, leftnum = 0;

void function(int pos)
{
	if (pos == strlen(c))
	{
		a[pos] = '\0';
		cout << c << endl;
		cout << a << endl;
		return;
	}
	if (c[pos] == '(')
	{
		leftpos[leftnum] = pos;
		a[pos] = '$';
		leftnum += 1;
		function(pos + 1);
	}
	else
	{
		if (c[pos] == ')')
		{
			if (leftnum == 0)
			{
				a[pos] = '?';
				function(pos + 1);
			}
			else
			{
				a[pos] = ' ';
				leftnum -= 1;
				a[leftpos[leftnum]] = ' ';
				function(pos + 1);
			}
		}
		else
		{
			a[pos] = ' ';
			function(pos + 1);
		}
	}
}

int main()
{
	for (; cin.getline(c, 101);)
	{
		function(0);
		leftnum = 0;
		for (int i = 0; i < 101; i++)
			leftpos[i] = 0;
	}
	return 0;
}


void change(char str[])
{
	int n,i;
	n=strlen(str);
	for(i=0;i<n;i++)
	{
		if(str[i]=='(')
			str[i]='$';
		else if(str[i]==')')
			str[i]='?';
		else
			str[i]=' ';
	}
}
void match(char str[])
{
	int n,i,k;
	n=strlen(str);
	for(i=0;i<n;i++)
	{
		if(str[i]==')')
		{
			for(k=i;k>=0;k--)
			{
				if(str[k]=='(')
				{
					str[k]=' ';
					str[i]=' ';
					k=-1;
				}
			}
		}
	}
}
int main()
{
	char a,string[100];
	while(gets(string))
	{
		puts(string);
		match(string);
		change(string);
		puts(string);
	}
	return 0;
}


int main()
{
	char ch[110];
	int note[110], l, r;
	while(cin >> ch)
	{
		memset(note, 0, sizeof(note));
		for(int i = 0; ch[i] != '\0'; i++)
		{
			switch(ch[i])
			{
			case '(':
			{
				l = 0;
				r = 0;
				note[i] = 1;
				for(int j = i; ch[j] != '\0'; j++)
				{
					switch (ch[j])
					{
					case '(': l++; break;
					case ')': r++; break;
					default:	break;
					}
					if(l == r)
					{
						note[i] = 0;
						break;
					}
				}
				break;
			}
			case ')':
			{
				l = 0;
				r = 0;
				note[i] = -1;
				for(int j = i; j >= 0; j--)
				{
					switch (ch[j])
					{
					case '(': l++; break;
					case ')': r++; break;
					default:	break;
					}
					if(l == r)
					{
						note[i] = 0;
						break;
					}
				}
				break;
			}
			default:	break;
			}
		}
		cout << ch << endl;
		for(int i = 0; ch[i] != '\0'; i++)
		{
			switch (note[i])
			{
			case 1: cout << "$"; break;
			case -1: cout << "?"; break;
			case 0: cout << " "; break;
			default:
				break;
			}
		}
		cout << "\n";
	}
	return 0;
}


void main(void)
{
	while(1)
	{
		char str1[100],str2[100];
		gets(str1);

		if(feof(stdin))
			break;

		puts(str1);

		int k,n=strlen(str1),left[100],right[100],l=0,r=0;
		for(k=0;k<=n-1;k++)
		{
			if(str1[k]=='(')
			{
				left[l]=k;
				l++;
			}
			else if(str1[k]==')')
			{
				right[r]=k;
				r++;
			}
			else str2[k]=' ';
		}
		left[l]=100;
		right[r]=100;
		str2[n]='\0';

		int i,j,x=1,y=1;
		for(i=l-1;i>=0;i--)
		{
			int p=0;
			while(right[p]<left[i]) p++;
			if(x>(r-p)) str2[left[i]]='$';
			else
			{
				str2[left[i]]=' ';
				x++;
			}
		}
		for(j=0;j<=r-1;j++)
		{
			int q=0;
			while(left[q]<right[j]) q++;
			if(y>q) str2[right[j]]='?';
			else
			{
				str2[right[j]]=' ';
				y++;
			}
		}

		puts(str2);
	}
}


int main()
{
	for(;;)
	{
	char cin[201],cout[201];
	int a[201]={0},i,j,n,sum;
	gets(cin);
	if(feof(stdin))
			break;

	n=strlen(cin);
	for(i=0;i<n;i++)
	{
		cout[i]=' ';
		if(cin[i]=='(')
			a[i]=1;
		else if(cin[i]==')')
			a[i]=-1;
	}
	for(i=0;i<n;i++)
	{
		sum=0;
		if(a[i]!=1)
			continue;
		for(j=i;j<n;j++)
		{
			sum=sum+a[j];
			if(sum==0)
				break;
		}
		if(sum!=0)
			cout[i]='$';
	}
	for(i=n-1;i>=0;i--)
	{
		sum=0;
		if(a[i]!=-1)
			continue;
		for(j=i;j>=0;j--)
		{
			sum=sum+a[j];
			if(sum==0)
				break;
		}
		if(sum!=0)
			cout[i]='?';
    }
	for(i=0;i<n;i++)
		printf("%c",cin[i]);
	printf("\n");
	for(i=0;i<n;i++)
		printf("%c",cout[i]);
	printf("\n");
	}
}


//3704:??????
//2010?11?13?
//1000012753 ???
int main()
{
	char str[200];
	int i, j, k, ei, bi, l;
	while (cin.getline(str, 150))
	{
		int strout[101] = {0};
		l = strlen(str);
		for (i = 0; i < l; i++)
		{
			if (str[i] == '(')
				strout[i] = -1;
			else if(str[i] == ')')
				strout[i] = 1;
		}
		for (i = 0; i < l; i++)
		{
			if (strout[i] != -1)
				continue;
			for (j = i + 1; j < l; j++)
			{
				if (strout[j] != 1)
					continue;
				for (k = j; k >= i; k--)
				{
					if (strout[k] == -1)
					{
						strout[k] = 0;
						strout[j] = 0;
						break;
					}
				}
			}
		}
		cout << str << endl;
		bi = l - 1;
		ei = 0;
		for (i = 0; i < l; i++)
			if (strout[i] != 0)
			{
				bi = i;
				break;
			}
		for (i = l - 1; i >= 0; i--)
			if (strout[i] != 0)
			{
				ei = i;
				break;
			}

		for (i = bi; i <= ei; i++)
		{
			if (strout[i] == 0)
				cout << ' ';
			else if (strout[i] == -1)
				cout << '$';
			else
				cout << '?';
		}
		cout << endl;
	}

	return 0;
}


int main()
{
	char str[101];
	int n,i,j,l,k=0;
	char c[101];
	int left=0,right=0;
	int e[101]={0};
	cin >> n;
	for(i=1;i<=n;i++)
	{
		left=0;right=0;
		cin >> str;
		l=strlen(str);
		for(j=0;j<l;j++)
		{
			e[j]=0;
			if(str[j]=='(')
			{
				left++;
				e[j]=1;
				c[left]=j;
			}
			if(str[j]==')')
			{
				if(left==0)
				{
					e[j]=2;
				}
				else
				{
					e[c[left]]=0;
					left--;
				}
			}
			else
				continue;
		}
		cout << str << endl;
		for(j=0;j<l;j++)
		{
			if(e[j]==1)
				cout << "$";
			else if(e[j]==2)
				cout << "?" ;
			else
				cout << " " ;
		}
		cout << endl;
	}
	return 0;
}


char str[103], temp[103];
int len;
int match(int x) {
	int y;
	if (x == len)//??x?len??????????x
		return x;
	if (str[x] == '(')//??str[x] = '('??y = match?x+1)
		y = match(x + 1);
	else if (str[x] == ')')//??str[x] = '(',??x
		return x;
	else//???????match?x+1?
		return match(x + 1);
	if (y == len) {//??y = len???temp[x] = $,?????????????y
		temp[x] = '$';
		return y;
	} else//???????match(y+1)
		return match(y + 1);
}
int main() {
	while (cin >> str) {//?????
		cout << str << endl;//???str
		len = strlen(str);//len?str???
		int z = 0;
		memset(temp, ' ', sizeof(temp));//?temp??????
		while (z != len) {//??????????
			z = match(z);
			if (z != len) {
				temp[z] = '?';
				z++;
			}
		}
		for (int i = 0; i < len; i++)
			cout << temp[i];
		cout << endl;
	}
	return 0;
}


char a[1000];
int judge(int,int);
int main()
{for(;cin>>a;){
	cout<<a<<endl;
	judge(0,0);
	cout<<a<<endl;
}
return 0;
}
int judge(int i,int l)
{int t;
if(a[i]=='\0') return -1;
if(a[i]=='('){t=judge(i+1,l+1);
a[i]=(t==-1)?'$':' ';
return (t==-1)?-1:judge(i+1,l);
}

else if(a[i]==')'){a[i]=l==0?'?':' ';
return (l==0)?judge(i+1,l):i;
}
else {a[i]=' ';return judge(i+1,l);}

	}


int main()
{
	char words[101]={0};
	while(cin>>words)
	{
		cout<<words<<endl;
		int i=0,j=0;
		for(i=0;words[i]!=0;i++)
		{
			if(words[i]!='('&&words[i]!=')')
				words[i]=' ';
			if(words[i]==')')
			{
				for(j=i-1;j>=0;j--)
				{
					if(words[j]=='(')
					{
						words[j]=' ';
						words[i]=' ';
						break;
					}
				}
			}
		}
		for(i=0;words[i]!=0;i++)
		{
			if(words[i]=='(')
				words[i]='$';
			if(words[i]==')')
				words[i]='?';
		}
		cout<<words<<endl;
	}
	return 0;
}


int main()
{
	char str[N+1],flag[N+1];
	int i,j,sstack[N+1];
	while(scanf("%s",str)!=EOF)
	{
		printf("%s\n",str);
		j=0;
		for(i=0;i<strlen(str);i++)
		{
			if(str[i]=='(')
				sstack[j++]=i;
			else if(str[i]==')')
			{
				if(j<=0)
					flag[i]='?';
				else
				{
					j--;
					flag[sstack[j]]=' ';
					flag[i]=' ';
				}
			}
			else
				flag[i]=' ';
		}
		for(i=0;i<j;i++)
			flag[sstack[i]]='$';
		flag[strlen(str)]='\0';
		printf("%s\n",flag);
	}

	return 0;
}


char input[150], output[150];
int main()
{
        int n,j;
		scanf("%d",&n);
		for(j=0;j<n;j++)
		{
			scanf("%s",input);
            memset(output,0,sizeof(output));
            int count1=0,count2=0;
            int i;
            for(i=0;i<strlen(input);++i)
            {
				output[i]=' ';
                if(input[i]==')')
				{
					if(count1<=0) output[i]='?';
                    else count1--;
                }
                else if(input[i]=='(') count1++;
            }
            for(i=strlen(input);i>=0;--i)
            {
				if(input[i]=='(')
                {
                    if(count2<=0) output[i]='$';
                    else count2--;
                }
                else if(input[i]==')') count2++;
            }
            printf("%s\n%s\n",input,output);
        }
        return 0;
}


void Find( char * );
int main()
{
	int i;
	char str[ 101 ];
	char mark[ 101 ];

	while ( cin.getline( str, 101 ) )
	{
		memset( mark, 0, sizeof( mark ) );
		for ( i = 0; i < strlen( str ); i++ )
		{
			if ( str[ i ] == '(' )
			{
				mark[ i ] = '$';
			}
			if ( str[ i ] == ')' )
			{
				mark[ i ] = '?';
			}
			if ( str[ i ] != '(' && str[ i ] != ')' )
			{
				mark[ i ] = ' ';
			}
		}
		Find( mark );
		for ( i = strlen( mark ) - 1; i >= 0; i-- )
			if ( mark[ i ] != ' ' )
			{
				mark[ i + 1 ] = 0;
				break;
			}
		for ( i = 0; i < strlen( mark ); i++ )
			if ( mark[ i ] != ' ' )
			{
				strcpy( mark, mark + i );
				break;
			}
		cout << str << endl << mark << endl;
	}
}

void Find( char mark[] )
{
	int i, j = 0;
	for ( i = 0; i < strlen( mark ); i++ )
	{
		if ( mark[ i ] == '$' )
		{
			for ( j = i + 1; j < strlen( mark ); j++ )
			{
				if ( mark[ j ] == '$' )
				{
					break;
				}
				else
				{
					if ( mark[ j ] == '?' )
					{
						mark[ j ] = ' ';
						mark[ i ] = ' ';
						Find( mark );
						return;
					}
				}
			}
		}
	}
}


int DO(char *SPE,int length)
{
	int k1=0;
	char *p1=NULL,*p2=NULL;
	for(int i=0;i<length;i++)
	{
		if(SPE[i]=='$')
		{
			k1++;
			p1=SPE+i;
		}
		else if(SPE[i]=='?')
		{
			p2=SPE+i;
			if(k1!=0)
			{
				*p1=' ';*p2=' ';return DO(SPE,length);
			}
		}
	}
	return 0;
}
int main(void)
{
	char SPE[101];
	while(~scanf("%s",SPE))
	{
		puts(SPE);
		int length=strlen(SPE);
		for(int i=0;i<length;i++)
		{
			if(SPE[i]!='('&&SPE[i]!=')') SPE[i]=' ';
			else if(SPE[i]=='(') SPE[i]='$';
			else if(SPE[i]==')') SPE[i]='?';
		}
		DO(SPE,length);
		puts(SPE);
	}
	return 0;
}


int main()
{
	char line[1000] ;
	char outline[1000] ;
	int i , j ;
	int len ;
	while ( cin >> line )
	{
		strcpy(outline , line) ;
		len = strlen(line) ;
		for ( i = 0 ; i < len ; i++ )
		{
			if ( line[i] == ')' )
			{
				for ( j = i - 1 ; j >= 0 ; j-- )
				{
					if ( line[j] == '(' )
					{
						line[j] = ' ' ;
						line[i] = ' ' ;
						break ;
					}
				}
			}
		}
		cout << outline << endl ;
		for ( i = 0 ; i < len ; i++ )
		{
			if ( line[i] == '(' )
			{
				cout << '$' ;
			}
			else
			{
				if ( line[i] == ')' )
				{
					cout << '?' ;
				}
				else
					cout << ' ' ;
			}
		}
		cout << endl ;
	}
	return 0 ;
}