struct stu
{int n;
 int a;
 int m;
 struct stu *next;
};
int n,l;
struct stu *creat(void)
{
	struct stu *head;
	struct stu *p,*q;
	n=0;
	p=q=(struct stu *)malloc(Len);
	scanf("%d %d %d",&p->n,&p->a,&p->m);
	head=Null;
	for(;n<l-1;)
	{
		n++;
		if(n==1) head=p;
		else q->next=p;
		q=p;
		p=(struct stu *)malloc(Len);
		scanf("%d %d %d",&p->n,&p->a,&p->m);
	}
	q->next=Null;
	return(head);
}
void main()
{
	int s=0;
	struct stu *p,*q,*c,*d,*head;
	scanf("%d",&l);
	head=p=q=creat();
	for(;;)
	{
		if((p->m+p->a)>s)
		{
			s=p->m+p->a;
			c=p;
			d=q;
		}
		q=p;
		p=q->next;
		if(p->next==Null) break;
	}
	printf("%d %d\n",c->n,s);
	if(d==head)
		head=((c->next)->next);
	else
		d->next=c->next;
	p=q=head;
	s=0;
	for(;;)
	{
		if((p->m+p->a)>s)
		{
			s=p->m+p->a;
			c=p;
			d=q;
		}
		q=p;
		p=p->next;
		if(p->next==Null) break;
	}
	printf("%d %d\n",c->n,s);
	if(d==head)
		head=p=q=((c->next)->next);
	else
		d->next=c->next;
	p=q=head;
	s=0;
	for(;;)
	{
		if((p->m+p->a)>s)
		{
			s=p->m+p->a;
			c=p;
			d=q;
		}
		q=p;
		p=p->next;
		if(p->next==Null) break;
	}
	printf("%d %d\n",c->n,s);
}


struct student
{
	int num;
	int chi;
	int math;
int sum;
};
void main()
{
	int n,i,j,max;
	struct student t,*s;
	scanf("%d",&n);
	s=(struct student *)malloc(n*sizeof(struct student));
	for(i=0;i<n;i++)
	{	scanf("%d%d%d",&s[i].num,&s[i].chi,&s[i].math);
	   s[i].sum=s[i].chi+s[i].math;}

	max=0;
	for(i=0;i<n;i++)
	{
			if (max<s[i].sum)  {max=s[i].sum;j=i;}
	}
	printf("%d %d\n",s[j].num,s[j].sum);
	s[j].sum=0;	max=0;
		for(i=0;i<n;i++)
	{
			if (max<s[i].sum)  {max=s[i].sum;j=i;}
	}
	printf("%d %d\n",s[j].num,s[j].sum);
	s[j].sum=0;			max=0;
		for(i=0;i<n;i++)
	{
			if (max<s[i].sum)  {max=s[i].sum;j=i;}
	}
	printf("%d %d\n",s[j].num,s[j].sum);
	s[j].sum=0;
}


int main () {
	int n,c,m;
	cin>>n;
	struct student
	{
		int id;
		int total;
	};                      //?????
	struct student stu[n+1];//??????
	int i,j;
	for(i=0;i<n;i++){
	   cin>>stu[i].id>>c>>m;
	   stu[i].total=c+m;//?????????
	}
	for(i=n-1;i>n-4;i--)
		for(j=n-1;j>n-i-1;j--)
		{
            if(stu[j].total>stu[j-1].total){
            	stu[n]=stu[j];
            	stu[j]=stu[j-1];
            	stu[j-1]=stu[n];
            }
		}//????
	for(i=0;i<3;i++){
		if(i<n)
	    cout<<stu[i].id<<" "<<stu[i].total<<endl;//?????
	}
	return 0;
}


struct stu* create();
int compare (const void * a, const void * b);
int main()
{
	int i,j=0,n;
	scanf("%d", &n);
	struct stu{
			int num;
			int chi;
			int math;
			int total;
	};
	struct stu *p=(struct stu*)calloc( n,sizeof(struct stu) );
	struct stu *a=p;
	int *tot=(int *)calloc( n, sizeof(int) );
	for(i=0;i<n;i++){
		scanf("%d %d %d", &p->num, &p->chi, &p->math);
		*(tot+i) = p->total = p->chi + p->math;
		p++;
	}
	qsort(tot, n, sizeof(int), compare);
	for(i=0;i<3;i++,j=0){
		while( (a+(j++))->total != *(tot+i) )
			;
		printf("%d %d\n", (a+j-1)->num, (a+j-1)->total);
		(a+j-1)->total=-1;
	}

	return 0;

}

int compare (const void * a, const void * b)
{
  return ( *(int*)b - *(int*)a );
}


struct student
{
	int number;
	int ch;
	int ma;
	int sum;
	int key;

}stu[100000];
void main()
{
	int n,i,max=0,l=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&stu[i].number,&stu[i].ch,&stu[i].ma);
		stu[i].sum=stu[i].ch+stu[i].ma;
		stu[i].key=0;
	}
	for(i=0;i<n;i++)
		if(max<stu[i].sum&&stu[i].key==0)
		{
			max=stu[i].sum;
			l=i;
		}
	printf("%d %d\n",l+1,max);
	max=0;
	stu[l].key=1;
	l=0;
    for(i=0;i<n;i++)
		if(max<stu[i].sum&&stu[i].key==0)
		{
			max=stu[i].sum;
			l=i;
		}
	printf("%d %d\n",l+1,max);
	max=0;
	stu[l].key=1;
	l=0;
	for(i=0;i<n;i++)
		if(max<stu[i].sum&&stu[i].key==0)
		{
			max=stu[i].sum;
			l=i;
		}
	printf("%d %d\n",l+1,max);
	max=0;
	stu[l].key=1;
	l=0;
}


int main()
{
	struct student{
		long num;
		long chinese;
		long maths;
		long sum;
	}t[100000],l;
	long n,i,j,k,tmp;
	scanf("%ld",&n);
	for(i=0;i<n;i++)
	{
		scanf("%ld %ld %ld",&t[i].num,&t[i].chinese,&t[i].maths);
	}
    for(i=0;i<n;i++)
	{
		t[i].sum=t[i].chinese+t[i].maths;
	}
	for(i=0;i<3;i++)
	{
        k=i;
		for(j=i+1;j<n;j++)
		{
			if(t[j].sum>t[k].sum)
				k=j;
		}
		l=t[k];
                  t[k]=t[i];
                  t[i]=l;
	}
	for(i=0;i<3;i++)
	{
	    printf("%ld %ld\n",t[i].num,t[i].sum);
	}
	return 0;
}


// ??????????

struct record
{
	int stuID;
	short YuWen;
	short math;
	short total;
};

struct YyxNode
{
	struct record m_rec;
	struct YyxNode *next;
};

struct YyxLink
{
	int n;
	struct YyxNode *head;
	struct YyxNode *tail;
};

struct YyxLink *CreateNewLink()
{
	struct YyxLink *newLn;
	if((newLn=(struct YyxLink*)malloc(sizeof(struct YyxLink)))==NULL){
		printf("Error: memory out! (1)\n");
		exit(-1);
	}
	newLn->n = 0;
	newLn->head = NULL;
	newLn->tail = NULL;

	return newLn;
}

struct YyxLink *AddNode(struct YyxLink *ln, const struct record *rec)
{
	struct YyxNode *newNode;
	if((newNode=(struct YyxNode*)malloc(sizeof(struct YyxNode)))==NULL){
		printf("Error: memory out! (2)\n");
		exit(-1);
	}
	newNode->m_rec = *rec;
	newNode->next = NULL;
	if(ln->n==0){
		ln->head = newNode;
		ln->tail = newNode;
	}else{
		ln->tail->next = newNode;
		ln->tail = newNode;
	}
	ln->n ++;

	return ln;
}

int myCompare(const struct record *rec1, const struct record *rec2)
{
	return rec2->total - rec1->total;
}

struct YyxNode *Search(struct YyxLink *ln, const struct record *rec)
{
	struct YyxNode *nd = ln->head;
	while(nd!=NULL && myCompare(&nd->m_rec, rec))
		nd = nd->next;

	return nd;
}

struct YyxLink *ClearLink(struct YyxLink *ln)
{
	struct YyxNode *delNode = ln->head;
	struct YyxNode *nextNode;
	while(delNode != NULL){
		nextNode = delNode->next;
		free(delNode);
		delNode = nextNode;
	}
	ln->n = 0;
	ln->head = NULL;
	ln->tail = NULL;

	return ln;
}

int main()
{
	struct YyxLink *mainLn;
	struct record stu;
	int n;
	int i;
	struct record *max1, *max2, *max3;
	struct YyxNode *temp;
	mainLn = CreateNewLink();
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d %d %d", &stu.stuID,
			&stu.YuWen, &stu.math);
		stu.total = stu.YuWen + stu.math;
		AddNode(mainLn, &stu);
	}

	max1=max2=max3= &mainLn->head->m_rec;
	temp = mainLn->head;
	while(temp!=NULL){
		if(max1->total<temp->m_rec.total)
			max1 = &temp->m_rec;
		temp = temp->next;
	}
	temp = mainLn->head;
	if (max2==max1){
		temp = mainLn->head->next;
		max2 = &temp->m_rec;
	}
	while(temp!=NULL){
		if(max2->total<temp->m_rec.total)
			if(max1!=&temp->m_rec)
				max2 = &temp->m_rec;
		temp = temp->next;
	}
	temp = mainLn->head;
	while(&temp->m_rec==max1||&temp->m_rec==max2)
		temp = temp->next;
	max3 = &temp->m_rec;
	while(temp!=NULL){
		if(max3->total<temp->m_rec.total)
			if(max1!=&temp->m_rec&&max2!=&temp->m_rec)
			max3 = &temp->m_rec;
		temp = temp->next;
	}

	printf("%d %d\n", max1->stuID, max1->total);
	printf("%d %d\n", max2->stuID, max2->total);
	printf("%d %d\n", max3->stuID, max3->total);

//	getchar();getchar();getchar();
	free(ClearLink(mainLn));

	return 0;
}


struct student
{
	int xuehao;
	int yuwen;
	int shuxue;
	int zongfen;
}stu[100000];
int main(int argc, char* argv[])
{
	int n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&stu[i].xuehao,&stu[i].yuwen,&stu[i].shuxue);
		stu[i].zongfen=stu[i].yuwen+stu[i].shuxue;
	}
	int max1=2,max2=1,max3=0,num1=0,num2=0,num3=0;
	for(i=0;i<n;i++)
	{
		if(stu[i].zongfen>max1)
		{
			max3=max2;
			num3=num2;
			max2=max1;
			num2=num1;
			max1=stu[i].zongfen;
			num1=i;
		}else if(stu[i].zongfen<=max1&&stu[i].zongfen>max2)
		{
			max3=max2;
			num3=num2;
			max2=stu[i].zongfen;
			num2=i;
		}else if(stu[i].zongfen<=max2&&stu[i].zongfen>max3)
		{
			max3=stu[i].zongfen;
			num3=i;
		}
	}
	printf("%d %d\n",stu[num1].xuehao,stu[num1].zongfen);
	printf("%d %d\n",stu[num2].xuehao,stu[num2].zongfen);
	printf("%d %d\n",stu[num3].xuehao,stu[num3].zongfen);
	return 0;
}


struct student
{
	int num,z;
}a,max1,max2,max3;

void main()
{
	int i,n,x,y;
	scanf("%d",&n);
	max1.z=-1;
	max2.z=-1;
	max3.z=-1;
	for (i=0;i<n;i++)
	{
		scanf("%d %d %d",&a.num,&x,&y);
		a.z=x+y;
		if (a.z>max1.z)
		{
			max3=max2;
			max2=max1;
			max1=a;
		}
		else if (a.z>max2.z)
		{
			max3=max2;
			max2=a;
		}else if (a.z>max3.z)
		{
			max3=a;
			max3=a;
		}
	}
	printf("%d %d\n%d %d\n%d %d\n",max1.num,max1.z,max2.num,max2.z,max3.num,max3.z);
}


struct student
{
int num;
int chn;
int math;
int sum;
};

int main()
{
int n;
int i, j, e;
int x;
struct student a[100000];
scanf("%d", &n);
for(i=0; i<n; i++)
{
scanf("%d %d %d", &a[i].num, &a[i].chn, &a[i].math);
a[i].sum=a[i].chn+a[i].math;
}
for(i=1; i<=3; i++)
   {
    for(j=n-i-1; j>=0; j--)
      {
       if(a[j].sum<a[j+1].sum)
          {
           x=a[j+1].sum;
           a[j+1].sum=a[j].sum;
           a[j].sum=x;
           e=a[j+1].num;
           a[j+1].num=a[j].num;
           a[j].num=e;
          }
      }
   }
for(i=0; i<=2; i++)
{
 printf("%d %d\n", a[i].num, a[i].sum);
}
return 0;
}


int main()
{
	struct stu
	{
		char id[9];
		int chn;
		int math;
		int both;
		struct stu *next;
	};
	int n,i;
	scanf("%d",&n);
	struct stu *head,*p1,*p2;
	for(i=0;i<n;i++)
	{
		if(i==0)
		{
			head=(struct stu*)malloc(sizeof(struct stu));
			p1=head;
		}
		else
		{
			p1->next=(struct stu*)malloc(sizeof(struct stu));
			p1=p1->next;
		}
		scanf("%s%d%d",p1->id,&p1->chn,&p1->math);
		p1->both=p1->chn+p1->math;
	}
	p1->next=NULL;
	int max;
	for(i=0;i<3;i++)
	{
		max=head->both;
	    p1=head;
		do
		{
		   p1=p1->next;
		   if(max<p1->both)
		   {
			 max=p1->both;
			 p2=p1;
		   }
		}while(p1->next!=NULL);
		printf("%s %d\n",p2->id,p2->both);
		p2->both=0;
	}
	return 0;
}


struct student
{
       char num[10];
       int grade[2];
};
struct student stu[100000];
int main()
{
    int n,sum[100000],i,count,max,j;
    count = 1;

    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
      sum[i]=0;
      scanf("%s %d %d",stu[i].num,&stu[i].grade[0],&stu[i].grade[1]);
      sum[i]= stu[i].grade[0]+stu[i].grade[1];
    }
    while(count <=2)
    {
      max =0;
      for(i=0;i<n;i++)
      {
        if(sum[i]>max)
       {
        max = sum [i];
        j=i;
       }
      }
      printf("%s %d\n",stu[j].num,sum[j]);
      count++;
      sum[j]=0;
    }
    max = 0;
    for(i=0;i<n;i++)
      {
        if(sum[i]>max)
       {
        max = sum [i];
        j=i;
       }
      }
      printf("%s %d",stu[j].num,sum[j]);
    getchar();
    getchar();
}


void main()
{
	struct student
	{int num;
	int score1;
	int score2;
	}stu[100000];
         long int n;
	int i,score[100000],max[3]={0},a[3];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&stu[i].num,&stu[i].score1,&stu[i].score2);
        score[i]=stu[i].score1+stu[i].score2;
	}
	for(i=0;i<n;i++)
	{
		if(max[0]<score[i]){max[0]=score[i];a[0]=stu[i].num;}
    }

     for(i=0;i<n;i++)
	 {if(stu[i].num==a[0])continue;
	 else if(max[1]<score[i]){max[1]=score[i];a[1]=stu[i].num;}
	 }

	 for(i=0;i<n;i++)
	 {if(stu[i].num==a[1]||stu[i].num==a[0])continue;
	 else if(max[2]<score[i]){max[2]=score[i];a[2]=stu[i].num;}
	 }
	 for(i=0;i<3;i++)
	 {
		 printf("%d %d\n",a[i],max[i]);
	 }
}


struct Student
{
	int number;
	int math;
	int chinese;
	int total;
	struct Student *next;

};

void main()
{
	int i=0,n,max;

	struct Student *linkHead, *linkTail, *student,*ppre,*pmax,*premax;

	scanf("%d",&n);

	linkHead = linkTail = NULL;
	//????????????
while(i<n)
{
	student = (struct Student *)malloc(Len);

	scanf("%d %d %d",&student->number, &student->math, &student->chinese);

	student->total=student->math+student->chinese;

	student->next = NULL;
	if (linkTail == NULL)
	//????????????
	linkHead = linkTail = student;
	else
	{

	//?????????????????????
	linkTail->next = student;
	linkTail = student;

	}

	i++;

}

i=0;

while(i<3)
{
student=linkHead;
ppre=student;

max=0;
pmax=linkHead;
premax=linkHead;

while(student != NULL )
{

	if(student->total>max)
	{
		max=student->total;
		pmax=student;
		premax=ppre;
	}
	ppre=student;
	student=student->next;

}

	printf("%d %d\n", pmax->number, pmax->total);

	if(pmax==linkHead)            //????????????
			linkHead=student->next;
	else premax->next=pmax->next;  //???i??????????????i?????????????????????????????????????????flag?????????????????

	i++;

}

}


struct student
{
	long num;
	int math;
	int chinese;
	struct student *next;
};

long stu_num;
struct student *max1,*max2,*max3;

struct student *creat(void)
{
	struct student *head,*p1,*p2;
	long n;
	p1=p2=(struct student *)malloc(LEN);
	scanf("%ld%d%d",&p1->num,&p1->math,&p1->chinese);
	head=NULL;
	n=0;
	while(n<stu_num-1)
	{
		n++;
		if(n==1)
			head=p1;
		else
			p2->next=p1;
		p2=p1;
		p1=(struct student *)malloc(LEN);
		scanf("%ld%d%d",&p1->num,&p1->math,&p1->chinese);
	}
	p2->next=p1;
	p1->next=NULL;
	return(head);
}

void Max1(struct student *head,long stu_num)
{
	struct student *q1;
	q1=head;
	max1=head;
	for(;q1!=NULL;)
		if((max1->math+max1->chinese)<(q1->math+q1->chinese))
		{
			max1=q1;
			q1=q1->next;
		}
		else
            q1=q1->next;
	printf("%ld %d\n",max1->num,max1->math+max1->chinese);
}

void Max2(struct student *head,long stu_num)
{
	struct student *q2;
	q2=head;
	if(head!=max1)
		max2=head;
	else
		max2=q2->next;
	for(;q2!=NULL;)
		if((max2->math+max2->chinese)<(q2->math+q2->chinese)&&q2!=max1)
		{
			max2=q2;
			q2=q2->next;
		}
		else
            q2=q2->next;
	printf("%ld %d\n",max2->num,max2->math+max2->chinese);
}

void Max3(struct student *head,long stu_num)
{
	struct student *q3;
	q3=head;
	for(;q3!=NULL;)
		if(q3==max1||q3==max2)
			q3=q3->next;
		else
		{
			max3=q3;
			break;
		}
	q3=head;
	for(;q3!=NULL;)
		if((max3->math+max3->chinese)<(q3->math+q3->chinese)&&q3!=max1&&q3!=max2)
		{
			max3=q3;
			q3=q3->next;
		}
		else
            q3=q3->next;
	printf("%ld %d\n",max3->num,max3->math+max3->chinese);
}

void main()
{
	struct student *head;
	scanf("%ld",&stu_num);
	head=creat();
	Max1(head,stu_num);
	Max2(head,stu_num);
	Max3(head,stu_num);
}


	struct student
	{
		int num;
		int chi;
		int math;
		int sum;
		struct student *next;
	};

    struct student *creat(int n)
	{
		int i;
	struct student *head,*p1,*p2;

	p1=(struct student*)malloc(sizeof(struct student));
	scanf("%d %d %d",&p1->num,&p1->chi,&p1->math);
	p1->sum=p1->chi+p1->math;

	head=p1;
	p2=p1;

	for(i=1;i<n;i++)
	{
		p1=(struct student*)malloc(sizeof(struct student));
		scanf("%d %d %d",&p1->num,&p1->chi,&p1->math);
		p1->sum=p1->chi+p1->math;
		p2->next=p1;
		p2=p1;
	}
	p2->next=NULL;

	return(head);
	}

	void main()
	{
		struct student *head,*p1;
		struct student *max1,*max2,*max3;
		int n,max;

	    scanf("%d",&n);

		head=creat(n);

		p1=head;
		max=0;
		while(p1!=NULL)
		{
			if(p1->sum>max)
			{
				max=p1->sum;
				max1=p1;
			}
			p1=p1->next;
		}
		printf("%d %d\n",max1->num,max1->sum);

		p1=head;
		max=0;
		while(p1!=NULL)
		{
			if(p1->sum>max&&p1!=max1)
			{
				max=p1->sum;
				max2=p1;
			}
			p1=p1->next;
		}
		printf("%d %d\n",max2->num,max2->sum);

		p1=head;
		max=0;
		while(p1!=NULL)
		{
			if(p1->sum>max&&p1!=max1&&p1!=max2)
			{
				max=p1->sum;
				max3=p1;
			}
			p1=p1->next;
		}
		printf("%d %d\n",max3->num,max3->sum);
	}

		/*if(n<3)
		{
			int max=0;                //???????????????????????????p=a?????????...
			if(*/


int main(int argc, char* argv[])
{
    int n,num,math,china,z,i;
	int num1=2,num2=1,num3=0,m1=0,m2=0,m3=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&num);
		scanf("%d",&math);
		scanf("%d",&china);
		z=math+china;
		if(z>num3)
		{
			num1=num2;
			m1=m2;
			num2=num3;
			m2=m3;
			num3=z;
			m3=i;

		}
		else if(z>num2)
		{
			num1=num2;
			m1=m2;
			num2=z;
			m2=i;
		}
		else if(z>num1)
		{
			num1=z;
			m1=i;
		}
	}
	printf("%ld %ld\n",m3,num3);
	printf("%ld %ld\n",m2,num2);
    printf("%ld %ld\n",m1,num1);
	return 0;
}


int main(int argc, char* argv[])
{
	int n,i,j,ta,tb,ts,tnum;
	int	*a,*b,*s,*num;
	scanf("%d",&n);
	a=(int*)malloc(sizeof(int)*n);
	b=(int*)malloc(sizeof(int)*n);
	s=(int*)malloc(sizeof(int)*n);
	num=(int*)malloc(sizeof(int)*n);

	for(i=1;i<=n;i++)
	{
		scanf("%d%d%d",&num[i],&a[i],&b[i]);
		s[i]=a[i]+b[i];
    }
    for(j=0;j<3;j++){
		for(i=n;i>1;i--){
		if(s[i]>s[i-1])
		{
			ta=a[i-1];tb=b[i-1];ts=s[i-1];tnum=num[i-1];
			a[i-1]=a[i];b[i-1]=b[i];s[i-1]=s[i];num[i-1]=num[i];
			a[i]=ta;b[i]=tb;s[i]=ts;num[i]=tnum;
		}
		}
	}
    printf("%d %d\n%d %d\n%d %d\n",num[1],s[1],num[2],s[2],num[3],s[3]);
	return 0;
}


struct Student
{
    int num;
    int Chi;
    int Math;
    int sum;
};
struct Student stud[100000],temp;
int main()
{
   int n,i,j;
   cin>>n;
   for(i=0;i<n;i++)
   {
       cin>>stud[i].num>>stud[i].Chi>>stud[i].Math;
       stud[i].sum=stud[i].Chi+stud[i].Math;
   }
   if(n==2)
   {
       if(stud[0].sum<stud[1].sum)
       {
               temp=stud[0];
               stud[0]=stud[1];
               stud[1]=temp;
           }
   }
   else
   {
       for(i=0;i<3;i++)
   {
       for(j=n-1;j>i;j--)
       {
           if(stud[j].sum>stud[j-1].sum)
           {
               temp=stud[j];
               stud[j]=stud[j-1];
               stud[j-1]=temp;
           }
       }
   }
   }

   if(n==2)
   {

       cout<<stud[0].num<<' '<<stud[0].sum<<endl;

       cout<<stud[1].num<<' '<<stud[1].sum;
   }
   for(i=0;i<2;i++)
   {
       cout<<stud[i].num<<' '<<stud[i].sum<<endl;
   }
   cout<<stud[2].num<<' '<<stud[2].sum;
    return 0;
}


int main()
{
	int n,i,j;
	cin>>n;
	struct student
	{
		int num;
		int yuwen;
		int shuxue;
		int sum;
	}stu[100000];
	for(i=0;i<n;i++)
	{
		cin>>stu[i].num>>stu[i].yuwen>>stu[i].shuxue;
		stu[i].sum=stu[i].yuwen+stu[i].shuxue;
	}
	int max=0,maxj=0;
	if(n>=3)
	{
	for(i=0;i<n;i++)
	if(stu[i].sum>max)
	{
		max=stu[i].sum;
		maxj=i;
	}
	cout<<stu[maxj].num<<' '<<stu[maxj].sum<<endl;
	stu[maxj].sum=0;max=0;
	for(i=0;i<n;i++)
		if(stu[i].sum>max)
		{
			max=stu[i].sum;
			maxj=i;
		}
		cout<<stu[maxj].num<<' '<<stu[maxj].sum<<endl;
		stu[maxj].sum=0;max=0;
		for(i=0;i<n;i++)
			if(stu[i].sum>max)
			{
				max=stu[i].sum;
				maxj=i;
			}
			cout<<stu[maxj].num<<' '<<stu[maxj].sum<<endl;
	}
	else
	{
		if(stu[0].sum>stu[1].sum)
			cout<<stu[0].num<<' '<<stu[0].sum<<endl<<stu[1].num<<' '<<stu[1].sum;
		else cout<<stu[1].num<<' '<<stu[1].sum<<endl<<stu[0].num<<' '<<stu[0].sum;
	}
			return 0;
}


struct student
{
	int num;
	int chinese;
	int math;
	struct student * next;
};
int m;
struct student * creat(int n)
{
	struct student * head;
	struct student * p1,*p2;
	m=0;
	p1=p2=(struct student*)malloc(sizeof(struct student));
	scanf("%d%d%d",&p1->num,&p1->chinese,&p1->math);
	head=NULL;
	while(n--)
	{
		m=m+1;
		if(m==1)
			head=p1;
		else
			p2->next=p1;
		p2=p1;
		p1=(struct student *)malloc(sizeof(struct student));
		scanf("%d%d%d",&p1->num,&p1->chinese,&p1->math);
	}
	p2->next=NULL;
	return(head);
}
		struct student * del(struct student * head,int num)
		{
			struct student *p1,*p2;
			p1=head;
			while(num!=p1->num&&p1->next!=NULL)
			{
				p2=p1;
				p1=p1->next;
			}
			if(num==p1->num)
			{
				if(p1==head)
					head=p1->next;
				else
					p2->next=p1->next;
				m=m-1;
			}
			return(head);
		}
int main()
{
	int max=0;
	int n,j;
	scanf("%d",&n);
	struct student *head,*p1,*p2;
	head=creat(n);
	for(j=0;j<3;j++)
	{
 		p1=head;
		p2=head;
		max=0;
		while(p1->next!=NULL)
		{
			if((p1->chinese+p1->math)>max)
			max=p1->chinese+p1->math,p2=p1;
				p1=p1->next;
		}
		printf("%d %d\n",p2->num,(p2->chinese+p2->math));
		head=del(head,p2->num);
	}
}


void main()
{
struct student{
int i;
int x;
int y;
int m;
struct student *next;
};
int n,j,k;
struct student *head,*p1,*p2,*p0;
scanf("%d",&n);
p1=(struct student*) malloc(LEN);
scanf("%d%d%d",&p1->i,&p1->x,&p1->y);
p1->m=p1->x+p1->y;
p2=(struct student*) malloc(LEN);
scanf("%d%d%d",&p2->i,&p2->x,&p2->y);
p2->m=p2->x+p2->y;
if(p1->m>p2->m)
{head=p1;p1->next=p2;p2->next=0;}
else{p0=p1;p1=p2;p2=p0;head=p1;p1->next=p2;p2->next=0;}
p0=(struct student*) malloc(LEN);
scanf("%d%d%d",&p0->i,&p0->x,&p0->y);
p0->m=p0->x+p0->y;
while((p0->m<=p1->m)&&(p1->next!=0))
{
p2=p1;p1=p1->next;
}
if(p0->m>p1->m)
{
	if(head==p1) head=p0;else p2->next=p0;
	p0->next=p1;
}
else
{
	p1->next=p0;p0->next=0;
}
for(j=3;j<n;j++)
{
p0=(struct student*) malloc(LEN);
scanf("%d%d%d",&p0->i,&p0->x,&p0->y);
p0->m=p0->x+p0->y;
for(k=0,p1=head;k<=2;k++)
{if(p0->m>p1->m) break; p1=p1->next;}
if (k==3) continue;
p1=p2=head;
while(p0->m<=p1->m)
{
p2=p1;p1=p1->next;
}
if(p0->m>p1->m)
{
	if(head==p1) head=p0;else p2->next=p0;
	p0->next=p1;
}
else
{
	p1->next=p0;p0->next=0;
}
}
for(p1=head,j=0;j<3;j++)
{
	printf("%d %d\n",p1->i,p1->m);
    p1=p1->next;
}
}


struct student
{
	int number;
	int math;
	int chinese;
	int total;
};
int main()
{
	struct student a[100000];
	int n,i,sf=0,ss=0,st=0,f,s,t;
	scanf("%d",&n);
	for (i=0;i<n;i++)
	{
		scanf("%d%d%d",&a[i].number,&a[i].math,&a[i].chinese);
		a[i].total=a[i].math+a[i].chinese;
		if (a[i].total>sf)
		{
			t=s; st=ss;
			s=f; ss=sf;
			f=i; sf=a[i].total;
		}
		else
			if (a[i].total>ss)
			{
				t=s; st=ss;
				s=i; ss=a[i].total;
			}
			else
				if (a[i].total>st)
				{
					t=i; st=a[i].total;
				}
	}
	printf("%d %d\n",f+1,sf);
	printf("%d %d\n",s+1,ss);
	printf("%d %d\n",t+1,st);
	return 0;
}


void main()
{
    int n,i,k,max,m,c;
	int a[100000];
	struct student
	{ int num;
	int math;
	int b;
	}stu1;

	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&stu1.num,&stu1.math,&stu1.b);
		a[i]=stu1.math+stu1.b;
	}

	max=a[0];
	for(i=1;i<n;i++)
	{
		if(a[i]>max)
		{max=a[i];
		k=i;}
	}
	printf("%d %d\n",k+1,a[k]);
	a[k]=0;
	max=a[0];
    for(i=1;i<n;i++)
	{
		if(a[i]>max)
		{max=a[i];
		m=i;}
	}
    printf("%d %d\n",m+1,a[m]);
	a[m]=0;
	max=a[0];
    for(i=1;i<n;i++)
	{
		if(a[i]>max)
		{max=a[i];
		c=i;}
	}
    printf("%d %d",c+1,a[c]);
}


int main()
{

    struct student
    {
       int id;
       int chinese;
       int math;
       int total;
       };

    long int n;
    int temp;
    int max = 0, max_1 = 0, max_2 = 0;
    struct student *p, *p_ori, *p_end, *q;
    struct student *p_max, *p_max_1, *p_max_2;

    scanf("%ld",&n);
    p = (struct student *)malloc(n*sizeof(struct student));
    p_ori = p;
    p_end = p+n;

    for (;p<p_end;p++)
    {
        scanf("%d",&(p->id));
        scanf("%d",&(p->chinese));
        scanf("%d",&(p->math));
        p->total = p->chinese + p->math;
        }

    p = p_ori;
    for (;p<p_end;p++)
    {
        if (p->total > max)
        { max = p->total;
          p_max = p;}
        }

    p=p_ori;
    for (;p<p_end;p++)
    {
        if (p->total > max_1 && p!=p_max)
        { max_1 = p->total;
          p_max_1 = p;}
        }

    p=p_ori;
    for (;p<p_end;p++)
    {
        if (p->total > max_2 && p!=p_max && p!=p_max_1)
        { max_2 = p->total;
          p_max_2 = p;}
        }

    printf("%d %d\n",p_max->id,p_max->total);
    printf("%d %d\n",p_max_1->id,p_max_1->total);
    printf("%d %d\n",p_max_2->id,p_max_2->total);

getchar();
getchar();
    }


struct data
{
	int num[100000],a[100000],b[100000],sum[100000];
}data;

int main(int argc, char* argv[])
{
	int i,n,x=0,y=0,z=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&data.num[i],&data.a[i],&data.b[i]);
		data.sum[i]=data.a[i]+data.b[i];
	}
	for(i=0;i<n;i++)
	{
		if(data.sum[i]>data.sum[x])
		{
			z=y;
			y=x;
			x=i;
			continue;
		}
		if(data.sum[i]<=data.sum[x]&&data.sum[i]>data.sum[y])
		{
			z=y;
			y=i;
			continue;
		}
		if(data.sum[i]<=data.sum[y]&&data.sum[i]>data.sum[z])
			z=i;
	}
	printf("%d %d\n",data.num[x],data.sum[x]);
	printf("%d %d\n",data.num[y],data.sum[y]);
	printf("%d %d",data.num[z],data.sum[z]);
}


struct student
{
	int ID;
	int yuwen;
	int shuxue;
	int zongfen;
};

int main()
{
	int n,i,j,e;
	scanf("%d",&n);
	struct student*stu=(struct student*)malloc(sizeof(struct student)*n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&stu[i].ID,&stu[i].yuwen,&stu[i].shuxue);
		stu[i].zongfen=stu[i].yuwen+stu[i].shuxue;
	}
	for(i=1;i<4;i++)
	{
		for(j=0;j<n-i;j++)
		{
			if(stu[j].zongfen>=stu[j+1].zongfen)
			{
				e=stu[j].zongfen;
				stu[j].zongfen=stu[j+1].zongfen;
				stu[j+1].zongfen=e;
				e=stu[j].ID;
				stu[j].ID=stu[j+1].ID;
				stu[j+1].ID=e;
			}
		}
	}

	printf("%d %d\n%d %d\n%d %d\n",stu[n-1].ID,stu[n-1].zongfen,stu[n-2].ID,stu[n-2].zongfen,stu[n-3].ID,stu[n-3].zongfen);
	return 0;
}


struct student
{
	int num;
	int yuwen;
	int math;
	int total;
	struct student *next;
};
long m,n,k;
struct student *creat(void)
{
	struct student *head;
	struct student *p1,*p2,*p3;
	m=0;head=0;
	while(m<n)
	{
	m=m+1;
	p1=(struct student *)malloc(sizeof(struct student));
	scanf("%d %d %d",&p1->num,&p1->yuwen,&p1->math);
    p1->total=p1->yuwen+p1->math;
	p2=head;
	if(m==1){head=p1;p1->next=0;}
	else
	{
		k=0;
		while(p1->total<=p2->total&&p2->next!=0&&k<=3)
		{
			p3=p2;
			p2=p2->next;k++;
		}
		if(p1->total>p2->total&&k<=3)
		{
			if(head==p2)head=p1;
			else p3->next=p1;
			p1->next=p2;
		}
		else
		{
			p2->next=p1;p1->next=0;
		}
	}
	}
	return(head);
}

void main()
{
	struct student *head,*p,*px;
	int t1=0,t2;
	scanf("%ld",&n);
	head=creat();
	p=head;
	while(t1<3)
	{
		printf("%d %d\n",p->num,p->total);
		p=p->next;
		t1++;
	}
}


struct stu{
	long int num[100000];
	int y[100000];
	int m[100000];
};

int main()
{
	int n,i,temp=0,sum[100000];
	struct stu p;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%ld %d %d",&p.num[i],&p.y[i],&p.m[i]);
		sum[i]=p.m[i]+p.y[i];
	}
	for(i=0;i<n-1;i++){
		if(sum[i]>=sum[i+1]){
			temp=sum[i+1];
			sum[i+1]=sum[i];
			sum[i]=temp;
			temp=p.num[i+1];
			p.num[i+1]=p.num[i];
			p.num[i]=temp;
		}
	}
	printf("%ld %d\n",p.num[n-1],sum[n-1]);
	for(i=0;i<n-2;i++){
		if(sum[i]>=sum[i+1]){
			temp=sum[i+1];
			sum[i+1]=sum[i];
			sum[i]=temp;
			temp=p.num[i+1];
			p.num[i+1]=p.num[i];
			p.num[i]=temp;
		}
	}
	printf("%ld %d\n",p.num[n-2],sum[n-2]);
	for(i=0;i<n-3;i++){
		if(sum[i]>=sum[i+1]){
			temp=sum[i+1];
			sum[i+1]=sum[i];
			sum[i]=temp;
			temp=p.num[i+1];
			p.num[i+1]=p.num[i];
			p.num[i]=temp;
		}
	}
	printf("%ld %d\n",p.num[n-3],sum[n-3]);
	return 0;
}


void main()
{
	int i,j,k,m,n,max;
	struct stu
	{
		int xh;
		int yw;
		int sx;
		int zf;
		struct stu *next;
	};
	struct stu *p1,*p2,*head;
	scanf("%d",&n);
	p2=head=p1=(struct stu *)malloc(sizeof(struct stu));
	scanf("%d %d %d",&p1->xh,&p1->yw,&p1->sx);
	p1->zf=p1->yw+p1->sx;
	for(i=1;i<n;i++)
	{
		p1=(struct stu *)malloc(sizeof(struct stu));
		scanf("%d %d %d",&p1->xh,&p1->yw,&p1->sx);
		p1->zf=p1->yw+p1->sx;
		p2->next=p1;
		p2=p1;
	}
	for(j=0;j<3;j++)
	{
		p1=head;
		max=0;
		for(i=0;i<n;i++)
		{
			max=max>p1->zf?max:p1->zf;
			p1=p1->next;
		}
		p1=head;
		for(i=0;i<n;i++)
		{
			if(max==p1->zf)
			{
				printf("%d %d\n",p1->xh,p1->zf);
				p1->zf=0;
				break;
			}
			p1=p1->next;
		}
	}
}


int main(int argc, char* argv[])
{
	struct student{
		int ID,Ch,Ma;
	}temp;
    int fID=0,fG=0,sID=0,sG=0,tID=0,tG=0;
	int n;
	scanf("%d",&n);
	int i;
	for(i=0;i<n;i++)
	{
		int sum=0;
		scanf("%d%d%d",&temp.ID,&temp.Ch,&temp.Ma);
        sum=temp.Ch+temp.Ma;
        if(sum==fG)
		{
            tG=sG;
			tID=sID;
			sG=sum;
			sID=temp.ID;
		}
		if(sum>fG)
		{
			tG=sG;
			tID=sID;
			sG=fG;
			sID=fID;
			fG=sum;
			fID=temp.ID;
		}
		if(sum<fG&&sum>sG)
		{
			tG=sG;
			tID=sID;
			sG=sum;
			sID=temp.ID;
		}
		if(sum<sG&&sum>tG)
		{
			tG=sum;
			tID=temp.ID;
		}
	}
	printf("%d %d\n",fID,fG);
	printf("%d %d\n",sID,sG);
	printf("%d %d\n",tID,tG);

	return 0;
}


struct student
{int nn;
int nnn;
int nmn;
int sum;
}st[100002],tmp;
int main()
{int i,j,m,n;
scanf("%d",&n);
for(i=1;i<=n;i++)
{scanf("%d %d %d",&st[i].nn,&st[i].nnn,&st[i].nmn);
st[i].sum=st[i].nnn+st[i].nmn;
}
for(i=1;i<=3;i++)
  {for(j=i+1;j<=n;j++)
      {if(st[i].sum<st[j].sum)
      {tmp=st[i];
  st[i]=st[j];
  st[j]=tmp;
		}

	   }
  }
  for(i=1;i<=3;i++)
  {printf("%d %d",st[i].nn,st[i].sum);
  if(i<3)
  printf("\n");
		}
  return 0;
}


	struct student
	{
		int num;
		int chinese;
		int math;
		int total;
	}a[100000];
int main()
{
	int n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&a[i].num,&a[i].chinese,&a[i].math);
		a[i].total=a[i].chinese+a[i].math;
	}
	int max,numm;
	max=a[1].total;
	for(int j=0;j<3;j++)
	{
	for(i=0;i<n;i++)
	{
		if(max<a[i].total)
		{
			max=a[i].total;
			numm=i;
		}
	}
		printf("%d %d\n",numm+1,max);
		a[numm].total=0;
		max=0;
	}
	return 0;
}


int first[3],firsti[3];
struct stu
{
	int num;
	int chinese;
	int math;
	int sum;
	struct stu *next;

}	*p1,*p2;
struct stu *creat(int n)
{  struct stu *head=NULL;
   p1=p2=(struct stu*)malloc(sizeof(struct stu));
   while (n--)
   {   scanf("%d %d %d",&p1->num,&p1->chinese,&p1->math);
       if(head==NULL) head=p1;
	   else p2->next=p1;
	   p2=p1;
       p1=(struct stu*)malloc(sizeof(struct stu));

   }
   p2->next=NULL;
return(head);
}
struct stu *sum(struct stu *head,int n)
{  p1=head;
	while(n--)
	{p1->sum=p1->chinese+p1->math;
	p1=p1->next;
	}
	return(head);
}

int main()
{int n,i,check=0;
struct stu *head,*f1,*f2,*f3;
f1=(struct stu*)malloc(sizeof(struct stu));
scanf("%d",&n);
head=creat(n);
head=sum(head,n);
p1=head;     if(n==1)  {printf("%d %d\n",p1->num,p1->sum);return 0;}

for(i=0,f1=head;i<n;i++,p1=p1->next)
if(f1->sum<p1->sum)  f1=p1;
     p1=head;
	   for(i=0;i<n;i++)
	   {p2=p1;p1=p1->next;
	   if(head==f1) {head=p1;break;}
		else if(p1==f1)
		  {
			p2->next=p1->next;
		  }
	   }
p1=head;
for(i=0,f2=head;i<n-1;i++,p1=p1->next)
    if(f2->sum<p1->sum)  f2=p1;
  if(n==2)   {printf("%d %d\n",f1->num,f1->sum);
          printf("%d %d\n",f2->num,f2->sum);
		  return 0;
  }
  p1=head;
	   for(i=0;i<n-1;i++)
	   {p2=p1;p1=p1->next;
	   if(head==f2) {head=p1;break;}
		else if(p1==f2)
		  {
			p2->next=p1->next;
		  }
	   }
p1=head;
for(i=0,f3=head;i<n-2;i++,p1=p1->next)
    if(f3->sum<p1->sum)  f3=p1;
   printf("%d %d\n",f1->num,f1->sum);
   printf("%d %d\n",f2->num,f2->sum);
   printf("%d %d\n",f3->num,f3->sum);

return 0;
}


struct student
{
	int num;
	int yu;
	int shu;
	int sum;
} stu[100000];
int main()
{
	int n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d",&stu[i].num, &stu[i].yu, &stu[i].shu);
		stu[i].sum=stu[i].shu+stu[i].yu;
	}
	int k,e;
	for(k=0;k<3;k++){
		for(i=n-2;i>=k;i--){
			if(stu[i].sum<stu[i+1].sum){
				e=stu[i].sum;
				stu[i].sum=stu[i+1].sum;
				stu[i+1].sum=e;
				e=stu[i].num;
				stu[i].num=stu[i+1].num;
				stu[i+1].num=e;
			}
		}
	}
	for(i=0;i<3;i++){
		printf("%d %d\n",stu[i].num,stu[i].sum);
	}
	return 0;
}


int main()
{
    struct student
    {
       int num;
       int chinese;
       int mathematics;
       int sum;
       }temp;
    struct student stu[100000];
    int i,j,n;
    scanf("%d",&n);
    for (i=0;i<n;i++){
        scanf("%d %d %d",&stu[i].num,&stu[i].chinese,&stu[i].mathematics);
        stu[i].sum=stu[i].chinese+stu[i].mathematics;
        }
    for (i=0;i<3;i++){
        for (j=0;j<n-i-1;j++){
            if (stu[j].sum>=stu[j+1].sum){
                temp=stu[j];
                stu[j]=stu[j+1];
                stu[j+1]=temp;
                }
            }
        }
    for (i=n-1;i>=n-3;i--){
        printf("%d %d\n",stu[i].num,stu[i].sum);}
    return 0;
    }


int main(){
	int n;
	scanf("%d",&n);
	struct score{
		int id;
		int yw;
		int sx;
	} stu [100000];
	int i,j;
	for(i=0;i<n;i++){
		scanf("%d%d%d",&stu[i].id,&stu[i].yw,&stu[i].sx);
	}
	for(j=1;j<=3;j++){
		int e,max=0;
		for(i=0;i<=n-j;i++){
			if((stu[i].yw+stu[i].sx)>(stu[max].yw+stu[max].sx)){
				max=i;
			}
		}
		if(max!=n-j){
			e=stu[max].yw;
			stu[max].yw=stu[n-j].yw;
			stu[n-j].yw=e;

			e=stu[max].sx;
			stu[max].sx=stu[n-j].sx;
			stu[n-j].sx=e;

			e=stu[max].id;
			stu[max].id=stu[n-j].id;
			stu[n-j].id=e;
		}
	}
	for(i=n-1;i>=n-2;i--){
		printf("%d %d\n",(stu[i].id),(stu[i].yw+stu[i].sx));
	}
	printf("%d %d",(stu[n-3].id),(stu[n-3].yw+stu[n-3].sx));
	return 0;
}


struct student
{int num;
 int score1;
 int score2;
} stu[100000];

void main()
{
	int n,i,sum[100000],max=0,j,k,l;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{scanf("%d%d%d",&stu[i].num,&stu[i].score1,&stu[i].score2);
	sum[i]=stu[i].score1+stu[i].score2;}
	for(i=0;i<n;i++)
		if(sum[i]>max){max=sum[i];j=i;}
	max=0;
	for(i=0;i<n;i++)
		if(sum[i]>max&&i!=j){max=sum[i];k=i;}
	max=0;
	for(i=0;i<n;i++)
		if(sum[i]>max&&i!=j&&i!=k){max=sum[i];l=i;}
	printf("%d %d\n%d %d\n%d %d\n",stu[j].num,sum[j],stu[k].num,sum[k],stu[l].num,sum[l]);
}


void main()
{
	int n,i,j,k,max=0,smax=0,tmax=0,id[3]={0},a,b,c;
   struct student
{
int No;
int yuwen;
int math;
}stu[100000];
scanf("%d",&n);
for(i=0;i<n;i++)
{
	scanf("%d",&stu[i].No);
    scanf("%d",&stu[i].yuwen);
	scanf("%d",&stu[i].math);
}
for(i=0;i<n;i++)
{

		if(max<stu[i].yuwen+stu[i].math)
                {
			max=stu[i].yuwen+stu[i].math;
		id[0]=stu[i].No;}
}
for(i=0;i<n;i++)
{
	if(smax<stu[i].yuwen+stu[i].math&&i!=id[0]-1)
		{smax=stu[i].yuwen+stu[i].math;
	   id[1]=stu[i].No;}
}

for(i=0;i<n;i++)
{
	if(tmax<stu[i].yuwen+stu[i].math&&i!=id[0]-1&&i!=id[1]-1)
		{tmax=stu[i].yuwen+stu[i].math;
	   id[2]=stu[i].No;}
}

a=id[0];
b=id[1];
c=id[2];

printf("%d %d\n",a,max);
printf("%d %d\n",b,smax);
printf("%d %d\n",c,tmax);

}


struct stu
{
	char num[15];
	int chinese;
	int math;
	int sum;
	struct stu *next;
};
int n;
struct stu *creat(void)
{
	struct stu *head,*p,*g,*h;
	int i,j;
	p=(struct stu*)malloc(LEN);
	scanf ("%s %d %d",(*p).num,&(*p).chinese,&(*p).math);
	(*p).sum=((*p).chinese+(*p).math);
	for (i=0;;i++)
	{
		if (i==0) {head=p;(*p).next=NULL;}
		else if (i<4)
		 {
			 for (h=head,j=0;j<i;j++)
			 {
				 if ((*p).sum>(*h).sum) break;
				 else {g=h; h=(*h).next;}
			 }
			 if (j==0) {(*p).next=head;head=p;}
			 else if (j==i) {(*g).next=p;(*p).next=NULL;}
			 else {(*g).next=p;(*p).next=h;}
		 }
		 else
		{
			 for (h=head,j=0;j<3;j++)
			 {
				 if ((*p).sum>(*h).sum) break;
				 else {g=h; h=(*h).next;}
			 }
			 if (j==0) {(*p).next=head;head=p;}
			 else {(*g).next=p;(*p).next=h;}
		 }
		 if (i==n-1) break;
		 p=(struct stu*)malloc(LEN);
		 scanf ("%s %d %d",(*p).num,&(*p).chinese,&(*p).math);
		 (*p).sum=((*p).chinese+(*p).math);
	}
	return(head);
}
void print(struct stu *head)
{
	struct stu *p;
	int i;
	for (p=head,i=0;i<3;i++,p=(*p).next)
			printf("%s %d\n",(*p).num,(*p).sum);
}
void main()
{
	struct stu *head;
	scanf("%d",&n);
	head=creat();
	print(head);
}


struct statistics
	{
		int num;
		int chinese;
		int math;
		int sum;
	} form[100000],temp;
int main()
{

	int n;
	scanf("%d",&n);
	int i,j;
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&form[i].num,&form[i].chinese,&form[i].math);
		form[i].sum=form[i].chinese+form[i].math;
	}
	for(i=0;i<3;i++)
	{
		int k=i;
		for(j=i+1;j<n;j++)
		{
			if(form[j].sum>form[k].sum)
			{
				k=j;
			}
		}
		if (k!=i)
		{
			temp=form[i];
			form[i]=form[k];
			form[k]=temp;

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


void main()
{
     struct student
    {
       int ID;
       int math;
       int chinese;
       int sum;
    };
     int n,i,t,j;
     scanf("%d",&n);
     struct student stu[n];
     for(i=0;i<n;i++)
        scanf("%d %d %d",&stu[i].ID,&stu[i].math,&stu[i].chinese);
     for(i=0;i<n;i++)
        stu[i].sum=stu[i].math+stu[i].chinese;
     for(i=0;i<3;i++)
     {  for(j=i+1;j<n;j++)

           if(stu[j].sum>stu[i].sum)
           {t=stu[i].sum;stu[i].sum=stu[j].sum;stu[j].sum=t;
            t=stu[i].ID;stu[i].ID=stu[j].ID;stu[j].ID=t;}

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

}


void main()
{
	int n;
	scanf("%d",&n);
	struct student
	{
		int num;
		int score_1;
		int score_2;
		int sum;
	};
	struct student stu[n];
	int i,j,t;
	for(i=0;i<n;i++)
	{
	    scanf("%d %d %d",&stu[i].num,&stu[i].score_1,&stu[i].score_2);
	    stu[i].sum=stu[i].score_1+stu[i].score_2;
	}
	for(j=0;j<=2;j++)
	{
		for(i=n-1;i>0+j;i--)
		if(stu[i].sum>stu[i-1].sum)
		{
		    t=stu[i].sum,stu[i].sum=stu[i-1].sum,stu[i-1].sum=t;
			t=stu[i].num,stu[i].num=stu[i-1].num,stu[i-1].num=t;
		}
	}
	for(i=0;i<=2;i++)
	printf("%d %d\n",stu[i].num,stu[i].sum);
}


struct person
{
	char num[6];
	int Chinese;
	int math;
	int total;
}stu[100000];

int main()
{
	int n, i, max, j, k, temp = 0,tnum = 0;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> stu[i].num;
		cin >> stu[i].Chinese;
		cin >> stu[i].math;
		stu[i].total = stu[i].math + stu[i].Chinese;

	}
	for (j = 0; j < 3; j++)
	{
		max = 0;
		for (i = 0; i < n; i++)
		{
			if (stu[i].total > max)
			{
				max = stu[i].total;
				k = i;
			}
		}
		cout << stu[k].num << " " << stu[k].total << endl;
		stu[k].total = 0;
	}
	return 0;
}


struct xue
{
	int ID;
	int sx;
	int yw;
	int sum;
}xueshen;

int main()
{
	int n,i,k;
	scanf("%d",&n);
	struct xue *xuesheng;
    xuesheng=(struct xue*)malloc(4*sizeof(int)*n);
	for (i=0;i<n;i++){
		scanf("%d%d%d",&xuesheng[i].ID,&xuesheng[i].sx,&xuesheng[i].yw);
		xuesheng[i].sum=xuesheng[i].sx+xuesheng[i].yw;
	}
	for (i=1;i<4;i++){
		for(k=0;k<n-i;k++){
			if(xuesheng[k].sum>=xuesheng[k+1].sum){
				xueshen=xuesheng[k+1];
				xuesheng[k+1]=xuesheng[k];
				xuesheng[k]=xueshen;
			}
		}
	}
	for (i=1;i<4;i++){
		printf("%d %d\n",xuesheng[n-i].ID,xuesheng[n-i].sum);
	}
	return 0;
}


struct mark
{
	int num;
	int ch;
	int math;
	int sum;
}stu[100000];
int main(int argc, char* argv[])
{
	int i,n;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d",&stu[i].num,&stu[i].ch,&stu[i].math);
		stu[i].sum=stu[i].math+stu[i].ch;
	}
	for(i=0;i<n-1;i++){
		if(stu[i].sum>=stu[i+1].sum){
			stu[100000]=stu[i];
			stu[i]=stu[i+1];
			stu[i+1]=stu[100000];
		}
	}
	for(i=0;i<n-2;i++){
		if(stu[i].sum>=stu[i+1].sum){
			stu[100000]=stu[i];
			stu[i]=stu[i+1];
			stu[i+1]=stu[100000];
		}
	}
	for(i=0;i<n-3;i++){
		if(stu[i].sum>=stu[i+1].sum){
			stu[100000]=stu[i];
			stu[i]=stu[i+1];
			stu[i+1]=stu[100000];
		}
	}
	printf("%d %d\n%d %d\n%d %d\n",stu[n-1].num,stu[n-1].sum,stu[n-2].num,stu[n-2].sum,stu[n-3].num,stu[n-3].sum);
	return 0;
}


struct student
{
       long int ID;
       int math;
       int chinese;
       int add;
}stu[100000];
main()
{
      long int n;
      int i,j;
      scanf("%d",&n);
      for(i=0;i<n;i++)
      {
        scanf("%d %d %d",&stu[i].ID,&stu[i].math,&stu[i].chinese);
        stu[i].add=stu[i].math+stu[i].chinese;
      }
      for(i=0;i<3;i++)
      {
         for(j=i+1;j<n;j++)
         {
             if(stu[i].add<stu[j].add)
             {
                 int t=stu[i].add;
                 stu[i].add=stu[j].add;
                 stu[j].add=t;
                 long int m=stu[i].ID;
                 stu[i].ID=stu[j].ID;
                 stu[j].ID=m;
             }
         }
         printf("%d %d\n",stu[i].ID,stu[i].add);
      }
      getchar();
      getchar();
}


struct data
{
	int id;
	int cs;
	int ms;
	int s;
};
int cmp(const void *a,const void *b)
{
    return ((struct data*)b)->s - ((struct data*)a)->s;
}
main()
{
	struct data *a;
	int n;
	int i;
	scanf("%d",&n);
	a=(struct data *)malloc(n*sizeof(struct data));
	for (i=0;i<n;i++)
	{
		scanf("%d %d %d",&a[i].id,&a[i].cs,&a[i].ms);
		a[i].s=a[i].cs+a[i].ms;
	}
    qsort(a,n,sizeof(struct data),cmp);
	for (i=0;i<3;i++)
		printf("%d %d\n",a[i].id,a[i].s);
	free(a);
}


int main(int argc, char* argv[])
{
	int a=0,b=0,c=0;
	int an,bn,cn;
	int n,i,sum=0;
	struct student{
		int num,ch,math;
	}students[100000];
	scanf("%d",&n);
	for (i=0; i<n; i++){
		scanf("%d%d%d",&students[i].num, &students[i].ch, &students[i].math);
		sum = students[i].ch + students[i].math;
		if (sum > c){
			c = sum;
			cn = i;
		}
		if (sum > b){
			c = b;
			cn = bn;
			b = sum;
			bn = i;

		}
		if (sum > a){
			b = a;
			bn =an;
			a = sum;
			an = i;
		}
	}
	printf("%d %d\n",students[an].num,a);
	printf("%d %d\n",students[bn].num,b);
	printf("%d %d\n",students[cn].num,c);

	return 0;
}


struct score
{
	int num;
	int yuwen;
	int shuxue;
}student[100000];
int max(int a,int b)
{
	return (a>b)?a:b;
}
int min(int a,int b)
{
	return (a<b)?a:b;
}
int main()
{
	int max(int a,int b);
	int total[100000];
	int n,i;
	int max1=0,max2=0,max3=0;
	int maxnum1=0,maxnum2=0,maxnum3=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&student[i].num);
		scanf("%d",&student[i].yuwen);
		scanf("%d",&student[i].shuxue);
		total[i]=student[i].yuwen+student[i].shuxue;
		if(total[i]>=max1){
			if(total[i]==max1){
				max3=max2;
				max2=max1;
				max1=total[i];
				maxnum3=maxnum2;
				maxnum2=max(maxnum1,i+1);
				maxnum1=min(maxnum1,i+1);
			}
			else{
				max3=max2;
				max2=max1;
				max1=total[i];
				maxnum3=maxnum2;
				maxnum2=maxnum1;
				maxnum1=i+1;
			}
		}
		else if(total[i]<max1&&total[i]>=max2){

			if(total[i]==max2){
				max3=max2;
				max2=total[i];
				maxnum3=max(maxnum2,i+1);
				maxnum2=min(maxnum2,i+1);
			}
			else{
				max3=max2;
				max2=total[i];
				maxnum3=maxnum2;
				maxnum2=i+1;
			}
		}
		else if(total[i]<max2&&total[i]>=max3){
			if(total[i]==max3){
				max3=total[i];
				maxnum3=min(i+1,maxnum3);
			}
			else{
				max3=total[i];
				maxnum3=i+1;
			}
		}
	}
	printf("%d %d\n",maxnum1,max1);
	printf("%d %d\n",maxnum2,max2);
	printf("%d %d",maxnum3,max3);
	return 0;
}


struct stu
{
int num;
int chinese;
int maths;
}stu[100000];

void main()
{
int i,j,n,sum[100000],max=0,m;
scanf("%d\n",&n);
for(i=0;i<n;i++)
{
scanf("%d %d %d\n",&stu[i].num,&stu[i].chinese,&stu[i].maths);
}
for(i=0;i<n;i++)
{
sum[i]=stu[i].chinese+stu[i].maths;
}
for(j=0;j<3;j++)
{
for(i=0;i<n;i++)
{
if(sum[i]>max)
{max=sum[i];
m=i;}
}
printf("%d %d\n",stu[m].num,sum[m]);
sum[m]=0;
max=0;
}
}


 struct student
  {
	  long num;
	  int scorec;
	  int scorem;
	  struct student *next;
  };
 struct student *creat(long n)
 {
	 struct student *head,*p1,*p2;
	 p1=(struct student*)malloc(LEN);
	 scanf("%ld %d %d",&p1->num,&p1->scorec,&p1->scorem);
	 long s=n-1;
	 p1->next=NULL;
	 head=p1;
	 p2=p1;
	 do
	 {
		 p1=(struct student*)malloc(LEN);
         scanf("%ld %d %d",&p1->num,&p1->scorec,&p1->scorem);
         p1->next=NULL;
		 p2->next=p1;
		 p2=p1;
		 s=s-1;
	 }while(s);
	 return(head);
 }
void main()
{
  struct student *head,*p,*q,stu1,stu2,stu3;
  long n,k1=-1,k2=-1,k3=-1,i,j;
  int l;
  scanf("%ld",&n);
  head=creat(n);
  for(p=head,i=0;p!=NULL;p=p->next,i++)
  {
	  l=0;
	  for(q=head,j=0;q!=NULL;q=q->next,j++)
		  if((q->scorec+q->scorem)>(p->scorec+p->scorem)||(((q->scorec+q->scorem)==(p->scorec+p->scorem))&&j<i))
		  {
			  l=l+1;
			  if(l>3)break;
		  }
      if(l==0)
	  {
		  k1=i;
		  stu1.num=p->num;stu1.scorec=p->scorec;stu1.scorem=p->scorem;
	  }
	  if(l==1)
	  {
		  k2=i;
          stu2.num=p->num;stu2.scorec=p->scorec;stu2.scorem=p->scorem;
	  }
	  if(l==2)
	  {
		  k3=i;
          stu3.num=p->num;stu3.scorec=p->scorec;stu3.scorem=p->scorem;
	  }
	  if(k1!=-1&&k2!=-1&&k3!=-1)break;
  }
  printf("%ld %d\n",stu1.num,stu1.scorec+stu1.scorem);
  printf("%ld %d\n",stu2.num,stu2.scorec+stu2.scorem);
  printf("%ld %d",stu3.num,stu3.scorec+stu3.scorem);
}


struct stu
{
	int num;
	int yw;
	int sx;
	int zf;
}s1,s2,s3,s;
int main()
{

	int n,i;
	s1.zf=s2.zf=s3.zf=-1;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&s.num,&s.yw,&s.sx);
		s.zf=s.yw+s.sx;
		if(s.zf>s1.zf)
		{
			s3=s2;
			s2=s1;
			s1=s;
		}
		else if(s.zf>s2.zf)
		{
			s3=s2;
			s2=s;
		}
		else if(s.zf>s3.zf)
		{
			s3=s;
		}

	}

	printf("%d %d\n",s1.num,s1.zf);
	printf("%d %d\n",s2.num,s2.zf);
	printf("%d %d",s3.num,s3.zf);

	return 0;
}


void swap(int *i,int *j)
{
	int *p=i,t=*i;
	*p=*j;
	p=j;
	*p=t;
}
struct Student
{
	int id;
	int chinese;
	int math;
};
int main()
{
	void swap(int *i,int *j);
	int n,i,first,second,third,one,two,three;
	int *f=&first,*s=&second,*t=&third,*on=&one,*tw=&two,*th=&three;
	struct Student stu[100000];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&stu[i].id,&stu[i].chinese,&stu[i].math);
		int total=stu[i].chinese+stu[i].math,k;
		int *to=&total,*K=&k;
		if(i==0)
		{
			first=total;
			one=i;
		}
		else
		{
			if(i==1)
			{
				if(total>first)
				{
					swap(to,f);
					second=total;
					k=i;
					swap(K,on);
					two=k;
				}
				else
				{
					second=total;
					two=i;
				}
			}
			else
			{
				if(i==2)
				{
					if(total>first)
					{
						swap(to,f);
						swap(to,s);
						third=total;
						k=i;
						swap(K,on);
						swap(K,tw);
						three=k;
					}
					else
					{
						if(total>second&&total<=first)
						{
							swap(to,s);
							third=total;
							k=i;
							swap(K,tw);
							three=k;
						}
						else
						{
							third=total;
							three=i;
						}
					}
				}
				else
				{
					if(total>first)
					{
						swap(to,f);
						swap(to,s);
						swap(to,t);
						k=i;
						swap(K,on);
						swap(K,tw);
						swap(K,th);
					}
					else
					{
						if(total>second)
						{
							swap(to,s);
							swap(to,t);
							k=i;
							swap(K,tw);
							swap(K,th);
						}
						else
						{
							if(total>third)
							{
								swap(to,t);
								k=i;
								swap(K,th);
							}
						}
					}
				}
			}
		}
	}
	printf("%d %d\n",stu[one].id,first);
	printf("%d %d\n",stu[two].id,second);
	printf("%d %d\n",stu[three].id,third);
	return 0;
}


struct stu{
int ID;
int yuwen;
int shuxue;
int sum;
struct stu *next;};

struct stu *creat(long n)
{long i;
 struct stu *p,*q,*head;
 p=(struct stu *)malloc(LEN);
 head=q=p;
 scanf("%d %d %d",&p->ID,&p->yuwen,&p->shuxue),p->sum=p->shuxue+p->yuwen;
 for(i=1;i<n;i++)
 { p=(struct stu *)malloc(LEN);
   scanf("%d %d %d",&p->ID,&p->yuwen,&p->shuxue),p->sum=p->shuxue+p->yuwen;
   q->next=p,q=p;}
 p->next=NULL;
 return(head);
}

int main()
{
 long i,n;
 scanf("%ld",&n);
 struct stu *h,*p,*q1,*q2,*q3;
 h=creat(n);
 int m1,m2,m3;
 for(p=h,m1=p->sum;p!=NULL;p=p->next)
 if(p->sum>m1)  m1=p->sum,q1=p;
 printf("%d %d",q1->ID,q1->sum);
 for(p=h,m2=p->sum;p!=NULL;p=p->next)
 if(p->sum>m2&&p!=q1)  m2=p->sum,q2=p;
 printf("\n%d %d",q2->ID,q2->sum);
 for(p=h,m3=p->sum;p!=NULL;p=p->next)
 if(p->sum>m3&&p!=q1&&p!=q2)  m3=p->sum,q3=p;
 printf("\n%d %d",q3->ID,q3->sum);
}


void main()
{
	struct student
	{
		int ID;
		int chinese;
		int math;
		int total;
	}stu1,stu2,stu3,temp;
	int i,n;
	stu1.total=0;
	stu2.total=0;
	stu3.total=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&temp.ID,&temp.chinese,&temp.math);
		temp.total=temp.chinese+temp.math;
		if(temp.total>stu1.total)
		{
			stu3=stu2;
			stu2=stu1;
			stu1=temp;
		}
		else if(temp.total<=stu1.total&&temp.total>stu2.total)
		{
			stu3=stu2;
			stu2=temp;
		}
		else if(temp.total<=stu2.total&&temp.total>stu3.total)stu3=temp;
	}
	printf("%d %d\n",stu1.ID,stu1.total);
	printf("%d %d\n",stu2.ID,stu2.total);
	printf("%d %d\n",stu3.ID,stu3.total);
}


struct result//??result?????num?????????????
{   int num;
    int chn;
    int math;
    int total;
};
int main()
    {int n,k;
    cin>>n;
    struct result student[n+1];//?result??????student
    for(k=1;k<=n;k++)
        {cin>>student[k].num>>student[k].chn>>student[k].math;//??????
        student[k].total=student[k].chn+student[k].math;//?????
        }
    int i,j;
    struct result temp;
    for(i=1;i<4;i++)
    	for(j=1;j<=n-i;j++)//???????
    	    {if(student[j].total>=student[j+1].total)
    	        {temp=student[j];
    	        student[j]=student[j+1];
    	        student[j+1]=temp;
    	    	}
    	    }
    cout<<student[n].num<<" "<<student[n].total<<endl;
    cout<<student[n-1].num<<" "<<student[n-1].total<<endl;
    cout<<student[n-2].num<<" "<<student[n-2].total<<endl;

    return 0;
    }


int main()
{

	int n,i,first,second,third,x,y,z;
	scanf("%d",&n);
	struct mark{
		int ID,chinese,math,sum;
	}*num;
	num=(struct mark*)malloc(sizeof(mark)*n);
	int n1,c1,m1;
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&n1,&c1,&m1);
		num[i].ID =n1;
		num[i].chinese =c1;
		num[i].math=m1;
		num[i].sum=c1+m1;
	}
	for(i=0;i<n;i++)
	{
		if(i==0)
		{
			first=num[i].sum;
			second=num[i].sum;
			third=num[i].sum;
			x=num[i].ID;
			y=num[i].ID;
			z=num[i].ID ;
		}
		else if(i==1)
		{
			if(num[i].sum>first)
			{
				first=num[i].sum;
			    x=num[i].ID;
			}
			else
			{
				third=num[i].sum;
				z=num[i].ID;
			}

		}
		else
		{
			if(num[i].sum>first)
			{
				third=second;
                z=y;
				second=first;
				y=x;
				first=num[i].sum;
				x=num[i].ID;
			}
			else if(num[i].sum>second)
			{
				third=second;
			    z=y;
				second=num[i].sum;
				y=num[i].ID;
			}
			else if(num[i].sum>third)
			{
				third=num[i].sum;
				z=num[i].ID;
			}
		}
	}
	printf("%d %d\n%d %d\n%d %d\n",x,first,y,second,z,third);
	return 0;
}


main()
{
      int n,i;
      struct student
      {
             int num;
             int yuwen;
             int shuxue;
             int zongfen;
      }
      stu[100000];
      struct qiansan
      {
             int num;
             int zongfen;
      }st[3]={{0,0},{0,0},{0,0}};
      scanf("%d",&n);
      for(i=0;i<n;i++)
      {
          scanf("%d",&stu[i].num);
          scanf("%d",&stu[i].yuwen);
          scanf("%d",&stu[i].shuxue);
          stu[i].zongfen=stu[i].yuwen+stu[i].shuxue;
          if(stu[i].zongfen>st[0].zongfen)
          {
              st[2]=st[1];
              st[1]=st[0];
              st[0].zongfen=stu[i].zongfen;
              st[0].num=stu[i].num;
          }
          else if(stu[i].zongfen<=st[0].zongfen&&stu[i].zongfen>st[1].zongfen)
          {
              st[2]=st[1];
              st[1].zongfen=stu[i].zongfen;
              st[1].num=stu[i].num;
          }
          else if(stu[i].zongfen<=st[1].zongfen&&stu[i].zongfen>st[2].zongfen)
          {
              st[2].zongfen=stu[i].zongfen;
              st[2].num=stu[i].num;
          }
      }
      for(i=0;i<3;i++)
      {
          if(i==0)
          printf("%d %d",st[i].num,st[i].zongfen);
          else
          printf("\n%d %d",st[i].num,st[i].zongfen);
      }
      getchar();
      getchar();
}


struct student
{
	char id[20];
	int chinese;
	int math;
	int score;
	struct student *next;
};

int n;

struct student *create(int m)
{
	struct student *head;
	struct student *p1,*p2;
	n=0;
	p1=p2=(struct student *)malloc(length);

	head=null;
	while(n<m)
	{
		scanf("%s %d %d",p1->id,&p1->chinese,&p1->math);
		n=n+1;
		if(n==1) head=p1;
		else p2->next=p1;
		p2=p1;
		p1=(struct student *)malloc(length);

	}
	p2->next=null;
	return head;
}

void plus(struct student *head)
{
	struct student *p,*q;
	p=head;
	if(head!=null)
	{
		do
		{
			p->score=p->chinese+p->math;

			p=p->next;

		}
		while(p!=null);

	}
}

void pri_top3(struct student *head)
{
	struct student *p,*q,*p1,*p2,*p3;
	p1=p2=p3=head;
	p=head->next;
	while(p!=null)
	{
		if(p->score>p1->score)
		{
			p3=p2;p2=p1;p1=p;
		}
		else if((p->score<=p1->score)&&(p->score>p2->score))
		{
			p3=p2;p2=p;
		}
		else if((p->score<=p2->score)&&(p->score>p3->score))
			p3=p;

		p=p->next;

	}
	printf("%s %d\n",p1->id,p1->score);
	printf("%s %d\n",p2->id,p2->score);
	printf("%s %d\n",p3->id,p3->score);
}

void main()
{
	int m;
	scanf("%d",&m);
	struct student *p=create(m);
	plus(p);
	pri_top3(p);
}


struct student
{
	int num;
	int score1;
	int score2;
	int total;
}stu[100000];
int main()
{
	int n,i,j,k,t;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&stu[i].num,&stu[i].score1,&stu[i].score2);
        stu[i].total=stu[i].score1+stu[i].score2;
	}
	for(i=0;i<3;i++)
	{
		k=i;
		for(j=i+1;j<n;j++)
			if(stu[j].total>stu[k].total)k=j;
		if(k!=i)
		{
			t=stu[i].total;stu[i].total=stu[k].total;stu[k].total=t;
			t=stu[i].num;stu[i].num=stu[k].num;stu[k].num=t;}
	}
	for(i=0;i<3;i++)
	{
		printf("%d %d\n",stu[i].num,stu[i].total);
	}
}


struct student
{
  int ID;
  int chi;
  int math;
}student[100000];
int main()
{
   int n,i,j,k;
   scanf("%d",&n);
      int a[n];
   for(i=0;i<n;i++)
     {
     scanf("%d %d %d",&student[i].ID,&student[i].chi,&student[i].math);
      a[i]=student[i].chi+student[i].math;
      }

  for(k=0;k<3;k++)
  {
   for(i=0;i<n;i++)
    {
       for(j=0;j<n;j++)
       {
          if(a[i]<a[j])
             break;
       }
       if(j==n&&a[i]>=a[j-1])
         {
           printf("%d %d\n",student[i].ID,a[i]);
           a[i]=0;
           break;
         }
    }
  }
   getchar();
   getchar();
}


void main()
{
	struct student
	{

	 int id;
	 int chi;
	 int mat;
	 int sum;
	}stu[100000],t;
	int i,j,n,student_num;
	scanf("%d",&student_num);
	n=student_num;
	for(i=0;i<n;i++)
		scanf("%d%d%d",&stu[i].id,&stu[i].chi,&stu[i].mat);
	for(i=0;i<n;i++)
		stu[i].sum=stu[i].chi+stu[i].mat;
	for(i=0;i<n;i++)
		if(stu[0].sum<stu[i].sum)
			{t=stu[0];stu[0]=stu[i];stu[i]=t;}
		for(i=1;i<n;i++)
		if(stu[1].sum<stu[i].sum)
			{t=stu[1];stu[1]=stu[i];stu[i]=t;}
		for(i=2;i<n;i++)
		if(stu[2].sum<stu[i].sum)
			{t=stu[2];stu[2]=stu[i];stu[i]=t;}
	for(i=0;i<3;i++)
		printf("%d %d\n",stu[i].id,stu[i].sum);
}


int main(int argc, char* argv[])
{
	struct grades{
		int id;
		int yuwen,shuxue;
		int zongfen ;
	}grades[100007];
	int i,n,j,t,s;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&grades[i].id,&grades[i].yuwen,&grades[i].shuxue);

		grades[i].zongfen=grades[i].yuwen+grades[i].shuxue;
	}
	for(i=0;i<3;i++)
	{
		for(j=0;j<n-1;j++)
		{
			if(grades[j].zongfen>=grades[j+1].zongfen)
			{
				t=grades[j].zongfen;
				grades[j].zongfen=grades[j+1].zongfen;
				grades[j+1].zongfen=t;
				s=grades[j].id;
				grades[j].id=grades[j+1].id;
				grades[j+1].id=s;
			}
		}
	}
	for(i=n-1;i>=n-3;i--)
	{
		printf("%d %d\n",grades[i].id,grades[i].zongfen);
	}

	return 0;
}


struct student
{
	long id;
	int chinese;
	int math;
	int score;
	struct student *next;
};

struct student *creat(void)
{
	int num;
	struct student *head,*p,*q;
	q=NULL;
	head=(struct student *)malloc(len);
	p=head;
	scanf("%d",&num);
	while(num>0)
	{
		q=p;
		scanf("%ld%d%d",&p->id,&p->chinese,&p->math);
		p->score=p->chinese+p->math;
		p=(struct student *)malloc(len);
		q->next=p;
		num--;
	}
	p->next=NULL;
	return (head);
}

void main()
{
	int i;
	struct student *p,*head,*max[3];
	head=creat();
	p=head;
	for(i=0;i<=2;i++)
	{
		max[i]=(struct student *)malloc(len);
		max[i]->score=0;
	}
	for(;p!=NULL;p=p->next)
	{
		if(p->score>max[0]->score)
		{
			max[2]=max[1];
			max[1]=max[0];
			max[0]=p;
		}
		else if(p->score>max[1]->score)
		{
			max[2]=max[1];
			max[1]=p;
		}
		else if(p->score>max[2]->score)
		{
			max[2]=p;
		}
	}
		for(i=0;i<=2;i++)
	{
		printf("%ld %d\n",max[i]->id,max[i]->score);
	}
}


struct student
{
	int num;
	int ch;
	int ma;
	int sum;
	struct student *next;
};
int N;
int n;

struct student *creat(void)
{
	struct student *head;
	struct student *p1,*p2;
	n=0;
	p1=p2=(struct student *)malloc(LEN);
	scanf("%d %d %d",&p1->num,&p1->ch,&p1->ma);
	p1->sum=p1->ch+p1->ma;
	head=null;
	while(n<N-1)
	{
		n=n+1;
		if(n==1)
			head=p1;
		else
			p2->next=p1;
		p2=p1;
		p1=(struct student *)malloc(LEN);
		scanf("%d %d %d",&p1->num,&p1->ch,&p1->ma);
		p1->sum=p1->ch+p1->ma;
	}
	p2->next=null;
	return(head);
}

void main()
{
	scanf("%d",&N);
	struct student *head,*p1,*p2;
	head=creat();
	p1=head->next;
	p2=p1->next;
	void sort(struct student *p3,struct student *p4);
	sort(head,p1);
	sort(p1,p2);
	sort(p2,p2->next);
	p2->next=null;
	p1=head;
	while(p1!=null)
	{
	    printf("%d %d\n",p1->num,p1->sum);
		p1=p1->next;
	}
}

void sort(struct student *p3,struct student *p4)
{
	int k;
	while(p4!=null)
	{
		if(p3->sum<p4->sum)
		{
			k=p3->num;
			p3->num=p4->num;
			p4->num=k;
			k=p3->sum;
			p3->sum=p4->sum;
			p4->sum=k;
		}
		p4=p4->next;
	}
}


int main()
{
	int n,i,b,c,d;
	struct{
		int sn;
		int chi;
		int mat;
		int sum;
	}a[100000];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d",&a[i].sn,&a[i].chi,&a[i].mat);
		a[i].sum=a[i].chi+a[i].mat;
	}
	b=n;
	c=n;
	d=n;
	a[n].sum=-100;
	for(i=0;i<n;i++){
		if(a[b].sum>=a[i].sum)b=b;
		else b=i;
	}
	for(i=0;i<n;i++){
		if(i!=b){if(a[c].sum>=a[i].sum)c=c;else c=i;}
		else ;
	}
	for(i=0;i<n;i++){
		if(i!=c&i!=b){if(a[d].sum>=a[i].sum)d=d;else d=i;}
		else ;
	}
	printf("%d %d\n",a[b].sn,a[b].sum);
	printf("%d %d\n",a[c].sn,a[c].sum);
	printf("%d %d\n",a[d].sn,a[d].sum);
	return 0;
}


struct student
{
	int num;
	int yuwen;
	int shuxue;
	int total;
	struct student *next;
};

void main()
{
	struct student *head,*p1,*p2,*P;

	int n,i=0,j=0;

	scanf("%d\n",&n);
	p1=p2=head=(struct student *)malloc(LEN);
	for(i=0;i<n;i++)
	{
		p2=p1;
		scanf("%d%d%d",&p1->num,&p1->yuwen,&p1->shuxue);
		p1->total=p1->yuwen+p1->shuxue;
		p2->next=p1=(struct student *)malloc(LEN);
	}

	p2->next=head;
	p1=head;

	for(i=0;;)
	{
		if(j==3)break;
		head=p1;
		P=p1;
		p1=head->next;
		while(p1!=head)
		{
			if (p1->total>P->total) P=p1;
			else if(p1->total==P->total && p1->num<P->num) P=p1;
			p1=p1->next;
		}
		printf("%d %d\n", P->num,P->total);
		while(p1->next!=P) p1=p1->next;
		p1->next=P->next;//??P??
		j++;
	}

}


struct stu
{	int id;
	int chn;
	int math;
	int sum;
};
int main()
{	struct stu indi[100000];
	int n,i,j,rank[3];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d%d",&indi[i].id,&indi[i].chn,&indi[i].math);
		indi[i].sum=indi[i].chn+indi[i].math;
	}
	for(i=0;i<3;i++){
		rank[i]=0;
		for(j=0;j<n;j++){
			if(indi[j].sum>indi[rank[i]].sum)
				rank[i]=j;
		}
		indi[rank[i]].sum=-indi[rank[i]].sum;
	}
	for(i=0;i<3;i++){
		printf("%d %d\n",indi[rank[i]].id,-indi[rank[i]].sum);
	}

	return 0;
}


int main()
{
	struct student
	{
		int num;
		int chinese;
		int math;
		int sum;
	}stu[100001],t;
    int n,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&stu[i].num,&stu[i].chinese,&stu[i].math);
		stu[i].sum=stu[i].chinese+stu[i].math;
	}
    for(i=0;i<3;i++)
	{
		for(j=0;j<n-1-i;j++)
		{
			if(stu[j].sum>=stu[j+1].sum)
			{
				t=stu[j];
				stu[j]=stu[j+1];
				stu[j+1]=t;
			}
		}
	}
	for(i=n-1;i>n-4;i--)
	{
		printf("%d %d\n",stu[i].num,stu[i].sum);
	}
	return 0;
}


struct student
	{
		int num;
		int chinese;
		int math;
	};
	struct student stu[100000];
	int sum[100000];
int main(int argc, char* argv[])
{

	int a,b,c,num1,num2,num3;
	int i,n;
	scanf("%d",&n);
    for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&stu[i].num,&stu[i].chinese,&stu[i].math);
	}
	for(i=0;i<n;i++)
	{
		sum[i]=stu[i].chinese+stu[i].math;
	}
	a=sum[0];
	num1=1;
	if(a<sum[1])
	{
		b=a;
		num2=num1;
		a=sum[1];
		num1=2;
	}
	else
	{
		b=sum[1];
	    num2=2;
	}
    c=0;
	for(i=2;i<n;i++)
	{
        if(a<sum[i])
		{
			c=b;
            num3=num2;
		    b=a;
			num2=num1;
			a=sum[i];
			num1=i+1;
		}
	    else
			if(b<sum[i])
			{
				c=b;
				num3=num2;
			    b=sum[i];
				num2=i+1;
			}
		    else
				if(c<sum[i])
				{
					c=sum[i];
				    num3=i+1;
				}
	}
	printf("%d %d\n",num1,a);
	printf("%d %d\n",num2,b);
	printf("%d %d\n",num3,c);
	return 0;
}


int main() {
	int n = 0, i = 0, j = 0;
	cin >> n;
	int sum[n];
	struct student {
		int stuid;
		int chin;
		int math;
	} stu[n], t;
	for (i = 0; i < n; i++) {
		cin >> stu[i].stuid >> stu[i].chin >> stu[i].math;
		sum[i] = stu[i].chin + stu[i].math;
	}
	for (i = 0; i < 3; i++)
		for (j = 0; j < n -1; j++)
			if ((stu[j].chin + stu[j].math) >= (stu[j + 1].chin
					+ stu[j + 1].math)) {
				t = stu[j];
				stu[j] = stu[j + 1];
				stu[j + 1] = t;
			}
	for (i = n-1; i > n-4; i--)
		cout << stu[i].stuid << " " << stu[i].chin + stu[i].math << endl;
	return 0;
}


struct student//?????
{
	int NO;
	int chinese;
	int math;
};

int main()
{
	struct student a[100001];
	int n,i,j;
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>a[i].NO>>a[i].chinese>>a[i].math;//??
	for(i=1;i<=3;i++)
		for(j=n-1;j>=i;j--)
			if(a[j].chinese+a[j].math<a[j+1].chinese+a[j+1].math)//??????????
			{
				a[0]=a[j];
				a[j]=a[j+1];
				a[j+1]=a[0];
			}
	for(i=1;i<=3;i++)
		cout<<a[i].NO<<' '<<a[i].chinese+a[i].math<<endl;//??
}


main()
{ int n,i;
   struct h
   {
  int mun;
  int chinese;
  int math;
  struct h *p;
   } ;
struct h *a,*b,*lily;
scanf("%d",&n);
a=len;
lily=a;
for(i=0;i<n;i++)
{  scanf("%d %d %d",&a->mun,&a->chinese,&a->math);
   b=len;
   a->p=b;
   a=b;
}
b=NULL;
a=lily;
int a1=0,a2=0,a3=0,b1=0,b2=0,b3=0,c;
for(i=0;i<n;i++)
{   c=(a->chinese+a->math);
	if(c>a1){b3=b2;b2=b1;b1=a->mun;a3=a2;a2=a1;a1=c;}
	else if(c>a2){b3=b2;b2=a->mun;a3=a2;a2=c;}
	else if(c>a3){b3=a->mun;a3=c;}
	a=a->p;
}
printf("%d %d\n",b1,a1);
printf("%d %d\n",b2,a2);
printf("%d %d\n",b3,a3);
}


// ????STUDENT_NUM????????????????
//?????????ID???????????????????
//???????????????????????
int n;
struct student
{
	int num;
	int chn;
	int math;
	int ovr;
	struct student *next;
};
struct student *creat()
{
	int i;
	struct student *head;
	struct student *p1,*p2;
	head=(struct student *)malloc(sizeof(struct student));
	p1=p2=head;
	for(i=0;i<n;i++)
	{
		p2=p1;
		p1=(struct student *)malloc(sizeof(struct student));
		p2->next=p1;
		scanf("%d %d %d",&p2->num,&p2->chn,&p2->math);
		p2->ovr=p2->chn+p2->math;
	}
	p2->next=0;
	return (head);
}
int main()
{
	int i;
	int no1,ovr1=0;
	struct student *head;
	struct student *p1,*p2;
	scanf("%d",&n);
	head=creat();
	p1=p2=head;
	for(i=0;i<3;i++)
	{
		p1=head;
		while(p1->next!=0)
		{
			if(p1->ovr>ovr1)
			{
				ovr1=p1->ovr;
				no1=p1->num;
				p2=p1;
			}
			p1=p1->next;
		}
		printf("%d %d\n",no1,ovr1);
		p2->ovr=0;
		ovr1=0;

	}
	return 0;
}


struct student
{
int name;
int ch;
int math;
}stu[100000];

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

                max[0]=0;
                for(j=0,k=0;j<n;j++)
                {if(sum[j]>max[0])
                {max[0]=sum[j];
                k=j;}
                }

   max[1]=0;
                for(j=1,m=0;j<n;j++)
                {if((sum[j]>max[1])&&(j!=k))
                {max[1]=sum[j];
                m=j;}
                }

                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]);

}


struct student
{
	int number;
	int chinese;
	int math;
	int num;
}stu[100001];
int main ( )
{
	int n, i, j, max[3][2] = {0};
	cin >> n;
	for(i = 0;i < n;i++)//??????????
	{
		cin >> stu[i].number >> stu[i].chinese >> stu[i].math;
		stu[i].num = stu[i].chinese + stu[i].math;
	}
	for(j = 0;j < 3;j++)//??3??????
	{
		for(i = 0;i < n;i++)
		{
			if(stu[i].num > max[j][0])
			{
				max[j][0] = stu[i].num;
				max[j][1] = i + 1;
			}
		}
		stu[max[j][1]-1].num = 0;
	}
	for(j = 0;j < 3;j++)//?????
	{
		cout << max[j][1] << ' ' << max[j][0] << endl;
	}
	return 0;
}


struct stu
{
	char num[15];
	int chi;
	int math;
	int sum;
	struct stu *next;
};
int n;
struct stu *creat(void)
{
	struct stu *head,*p,*g,*h;
	int i,j;
	p=(struct stu*)malloc(LEN);
	scanf ("%s %d %d",p->num,&p->chi,&p->math);
	p->sum=p->chi+p->math;
	for (i=0;;i++)
	{
		if (i==0) {head=p;head->next=NULL;}
		else if (i<3)
		 {
			 for (h=head,j=0;j<i;j++)
			 {
				 if (p->sum>h->sum) break;
				 else {g=h; h=h->next;}
			 }
			 if (j==0) {p->next=head;head=p;}
			 else if (j==i) {g->next=p;p->next=NULL;}
			 else {g->next=p;p->next=h;}
		 }
		 else
		{
			 for (h=head,j=0;j<3;j++)
			 {
				 if (p->sum>h->sum) break;
				 else {g=h; h=h->next;}
			 }
			 if (j==0) {p->next=head;head=p;}
			 else {g->next=p;p->next=h;}
		 }
		 if (i==n-1) break;
		 p=(struct stu*)malloc(LEN);
		 scanf ("%s %d %d",p->num,&p->chi,&p->math);
		 p->sum=p->chi+p->math;
	}
	return(head);
}
void print(struct stu *head)
{
	struct stu *p;
	int i;
	for (p=head,i=0;i<3;i++,p=p->next)
			printf("%s %d\n",p->num,p->sum);
}
void main()
{
	struct stu *head;
	scanf("%d",&n);
	head=creat();
	print(head);
}


     int main()
{
    struct Stu
    {
           int num;
           int sco[2];
           int sum;
    };
   struct Stu stu[5];
   struct Stu temp;
   int i,j,n,m,k;
   scanf("%d",&n);
   if(n>=3)
  {
   for(i=0;i<3;i++)
   {
     scanf("%d%d%d",&stu[i].num,&stu[i].sco[0],&stu[i].sco[1]);
     stu[i].sum=stu[i].sco[0]+stu[i].sco[1];
    }
    for(k=1;k<=n-3;k++)
     {
      scanf("%d%d%d",&stu[3].num,&stu[3].sco[0],&stu[3].sco[1]);
      stu[3].sum=stu[3].sco[0]+stu[3].sco[1];
      m=0;
      for(j=1;j<=2;j++)
      {
        if(stu[m].sum>stu[j].sum||(stu[m].sum==stu[j].sum&&stu[m].num<stu[j].num))
        m=j;
       }
        if(stu[3].sum>stu[m].sum)
        stu[m]=stu[3];
     }
   }
    for(i=0;i<2;i++)
   for(j=i+1;j<3;j++)
   if(stu[i].num>stu[j].num)
   {
     temp=stu[i];
     stu[i]=stu[j];
     stu[j]=temp;
     }
   for(i=0;i<2;i++)
   for(j=i+1;j<3;j++)
   if(stu[i].sum<stu[j].sum)
   {
     temp=stu[i];
     stu[i]=stu[j];
     stu[j]=temp;
     }
    for(i=0;i<3;i++)
    printf("%d %d\n",stu[i].num,stu[i].sum);
    return 0;
}


struct stu
{long num;
int Chi;
int Math;
int Sum;
struct stu *next;
}*p1,*p2;
//????
struct stu * creat(int n)
{struct stu *head=NULL;
int i;
for(i=0;i<n;i++)
{
	p1=(struct stu *)malloc(sizeof(struct stu));

	scanf("%d %d %d",&p1->num,&p1->Chi,&p1->Math);
	p1->Sum=p1->Chi+p1->Math;
	if(i==0){ head=p1; p2=p1;}
	else
		p2->next=p1;
		p2=p1;
}
p2->next=NULL;
return(head);
}

struct stu *Bigthree(struct stu *head)
{int t;
	struct stu *max,*premax,*New,*Newhead=NULL;
	for(t=0;t<3;t++)
	{
		premax=NULL;
		max=head;
		p2=head;
		p1=head->next;
		while(p1!=NULL)
		{
			if((p1->Sum)>(max->Sum))
			{premax=p2;
				max=p1;
			}
			p2=p2->next;
			p1=p1->next;
		}
		if(max == head)
			head = head->next;
		else premax->next=max->next;
		max->next=NULL;
		if(t==0){Newhead=max;
		New=Newhead;}

		else
		New=New->next=max;
	}
	New->next=NULL;
	return(Newhead);
}

//???????????
void output(struct stu *head)
{struct stu *p;
	for(p=head;p!=NULL;printf("%d %d\n",p->num,p->Sum),p=p->next);
}

void main()
{int n;
struct stu *head;
scanf("%d",&n);
	head=creat(n);
	head=Bigthree(head);
	output(head);
}


int main(int argc, char* argv[])
{
	int n,i,j,a,zf[100000];
	struct student
	{
		int name;
		int yw;
		int sx;

	}stu[100000];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d%d",&stu[i].name,&stu[i].yw,&stu[i].sx);
		zf[i]=stu[i].yw+stu[i].sx;
	}
	for(j=1;j<4;j++){
		for(i=0;i<n-j;i++){
			if(zf[i]>=zf[i+1]){
				a=zf[i];
				zf[i]=zf[i+1];
				zf[i+1]=a;
				a=stu[i].name;
				stu[i].name=stu[i+1].name;
				stu[i+1].name=a;
			}
		}
	}
	for(i=n-1;i>=n-3;i--){
	printf("%d %d\n",stu[i].name,zf[i]);
	}
	return 0;
}


struct student{
	int No;
	int Chinese;
	int math;
	int score;
}stu[100000];

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

         for(i=0;i<n;i++){
		scanf("%d %d %d",&stu[i].No,&stu[i].Chinese,&stu[i].math);
		stu[i].score=stu[i].Chinese+stu[i].math;
	}

	for(j=n-1;j>n-4;j--){
	    for(i=0;i<j;i++){
	        if(stu[i+1].score<stu[i].score||stu[i+1].score==stu[i].score){
			a=stu[i+1].score;
			stu[i+1].score=stu[i].score;
			stu[i].score=a;
			b=stu[i+1].No;
			stu[i+1].No=stu[i].No;
			stu[i].No=b;
			}
		}
	}
	for(i=n-1;i>n-4;i--){
		printf("%d %d\n",stu[i].No,stu[i].score);
	}

	return 0;
}


void main()
{
	struct stu
	{int a,b,c;};
	int i,n,j=0;scanf("%d",&n);
	struct stu *hd,*p;
	hd=p=(struct stu*)malloc(100000*sizeof(struct stu));
	for(i=0;i<n;i++,p++)
	{scanf("%d %d %d",&p->a,&p->b,&p->c);}
	int max=0;
nxt:	for(p=hd,i=0;i<n;i++,p++)
	{
		if(p->b+p->c>max) {max=p->b+p->c;}
	}
	for(p=hd,i=0;i<n;i++,p++)
	{
		if(p->b+p->c==max) {printf("%d %d\n",p->a,p->b+p->c);p->b=0;p->c=0;max=0;j++;break;}
	}
	if(j<=2) goto nxt;

}


int main()

{
    int n,i,j,k,z,x;
    scanf("%d",&n);
    struct Student
    {
       int num;
       int yuwen;
       int shuxue;
       int zongfen;
    }stu[n];

    for(i=0;i<n;i++)
    {
        scanf("%d%d%d",&stu[i].num,&stu[i].yuwen,&stu[i].shuxue);
        stu[i].zongfen=stu[i].yuwen+stu[i].shuxue;
    }

    for(j=0;j<3;j++)
    {
        for(k=0;k<n-1;k++)
        {
            if(stu[k].zongfen>stu[k+1].zongfen)
            {
               z=stu[k+1].zongfen;
               stu[k+1].zongfen=stu[k].zongfen;
               stu[k].zongfen=z;
               x=stu[k+1].num;
               stu[k+1].num=stu[k].num;
               stu[k].num=x;
            }
            else if(stu[k].zongfen==stu[k+1].zongfen&&stu[k].num<stu[k+1].num)
            {
               z=stu[k+1].zongfen;
               stu[k+1].zongfen=stu[k].zongfen;
               stu[k].zongfen=z;
               x=stu[k+1].num;
               stu[k+1].num=stu[k].num;
               stu[k].num=x;
            }
            else;
        }
    }

    for(j=0;j<3;j++)
    {
        printf("%d %d\n",stu[n-1-j].num,stu[n-1-j].zongfen);
    }

    getchar();
    getchar();

}


struct student
{
	int id;
	int china;
	int math;
	int total;
}stu[M],temp;
int main()
{
	int n,i,j,count;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&stu[i].id,&stu[i].china,&stu[i].math);
		stu[i].total=stu[i].china+stu[i].math;
	}
	for(i=0;i<3;i++)
	{
		temp=stu[i];
		count=i;
		for(j=i+1;j<n;j++)
		{
			if(stu[j].total>temp.total)
			{
				temp=stu[j];
				count=j;
			}
		}
		stu[count]=stu[i];
		stu[i]=temp;
	}
	for(i=0;i<3;i++)
		printf("%d %d\n",stu[i].id,stu[i].total);
	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;
	while(p1->num<m)
	{
		i++;
		if(i==1) 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=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 student
{
	int num;
	int score1;
	int score2;
	int sum;
}stu[100000],max,secondmax,thirdmax;
int main()
{
	max.sum=secondmax.sum=thirdmax.sum=0;
	int i,n;
	scanf("%d",&n);
	for (i=0;i<n;i++)
	{
		scanf("%d %d %d",&stu[i].num,&stu[i].score1,&stu[i].score2);
		stu[i].sum=stu[i].score1+stu[i].score2;
	}
	for (i=0;i<n;i++)
	{
		if (stu[i].sum>max.sum)
			max=stu[i];
	}
	for (i=0;i<n;i++)
	{
		if (stu[i].sum<max.sum&&stu[i].sum>secondmax.sum)
			secondmax=stu[i];
	}
	for (i=0;i<n;i++)
	{
		if (stu[i].sum==max.sum&&stu[i].num!=max.num)
		{
			secondmax=stu[i];
			break;
		}
	}
	for (i=0;i<n;i++)
	{
		if (stu[i].sum<secondmax.sum&&stu[i].sum>thirdmax.sum)
			thirdmax=stu[i];
	}
	for (i=0;i<n;i++)
	{
		if (stu[i].sum==secondmax.sum&&stu[i].num!=max.num&&stu[i].num!=secondmax.num)
		{
			thirdmax=stu[i];
			break;
		}
	}
	printf("%d %d\n%d %d\n%d %d",max.num,max.sum,secondmax.num,secondmax.sum,thirdmax.num,thirdmax.sum);
	return 0;
}


void main()
{
	int n,i,y,s,z,x,a,b,c,ax,bx,cx;
    scanf("%d",&n);a=0;b=0;c=0;ax=0;bx=0;cx=0;
	for(i=1;i<=n;i++)
	{

		scanf("%d %d %d",&x,&y,&s);
		z=y+s;
		if(c>=z) continue;
		else if(b>=z) {c=z; cx=x;}
		else if(a>=z) {c=b;cx=bx; b=z; bx=x;}
		else {c=b; cx=bx; b=a; bx=ax; a=z;ax=x;}
    }
	printf("%d %d\n",ax,a);
	printf("%d %d\n",bx,b);
	printf("%d %d\n",cx,c);
}


int main()
{
    int n,i,score[100000],max1=0,m1=0,max2=0,m2=0,max3=0,m3=0;
    scanf("%d",&n);
    struct stu{
           int No;
           int yw;
           int math;
           }s[100000];
    for(i=0;i<n;i++){
                     scanf("%d%d%d",&s[i].No,&s[i].yw,&s[i].math),
                     score[i]=s[i].yw+s[i].math;
                     if(score[i]>max1){
                                       max3=max2;
                                       max2=max1;
                                       max1=score[i];
                                       m3=m2;
                                       m2=m1;
                                       m1=i;
                                       continue;
                                       }
                     if(score[i]<=max1&&score[i]>max2){
                                        max3=max2;
                                        max2=score[i];
                                        m3=m2;
                                        m2=i;
                                        continue;
                                        }
                     if(score[i]<=max2&&score[i]>max3){
                                        max3=score[i];
                                        m3=i;
                                        continue;
                                        }
                     }
    printf("%d %d\n%d %d\n%d %d\n",s[m1].No,max1,s[m2].No,max2,s[m3].No,max3);

    return 0;
    }


int cmp(const void *a,const void *b)
    {
         return(*(int*)a-*(int*)b);
    }
int main()
{
    struct student
    {
           int num;
           int chinese;
           int maths;
           int amount;
    };
    struct student stu[100000];
    int a[100000],n,l,j,k;
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    {
        scanf("%d %d %d",&stu[i].num,&stu[i].chinese,&stu[i].maths);
        a[i]=stu[i].chinese+stu[i].maths;
    }
    qsort(a,n,sizeof(a[0]),cmp);
    for(int h=n-1;h>=0;h--)
    {
            if (a[n-1]==stu[h].chinese+stu[h].maths)
            {l=stu[h].num;}
    }
     for(int g=n-1;g>=0;g--)
    {
            if (a[n-2]==stu[g].chinese+stu[g].maths&&(g+1)!=l)
            {j=stu[g].num;}
    }
     for(int f=n-1;f>=0;f--)
    {
            if (a[n-3]==stu[f].chinese+stu[f].maths&&(f+1)!=j&&(f+1)!=l)
            {k=stu[f].num;}
    }
    printf("%d %d\n",l,a[n-1]);
    printf("%d %d\n",j,a[n-2]);
    printf("%d %d\n",k,a[n-3]);
}


int main()
{
    struct ss{
		int num,yu,sh;
		int sum;
	};
	int n,i;
	struct ss *stu;

	scanf("%d",&n);
	stu=(struct ss *)malloc(sizeof(ss)*n);
	for(i=0;i<n;i++)
	{int num1,yu1,sh1;
	(stu+i)->num=0;
	(stu+i)->yu=0;
	(stu+i)->sh=0;
	(stu+i)->sum=0;
	scanf("%d %d %d",&num1,&yu1,&sh1);
    (stu+i)->num=num1;
	(stu+i)->yu=yu1;
	(stu+i)->sh=sh1;
    (stu+i)->sum=yu1+sh1;
	}
	for(i=1;i<n;i++)
	{int t;
	if((stu+0)->sum<(stu+i)->sum)
	{t=(stu+0)->sum;
     (stu+0)->sum=(stu+i)->sum;
	 (stu+i)->sum=t;
	 t=(stu+0)->num;
	 (stu+0)->num=(stu+i)->num;
	 (stu+i)->num=t;}}
	for(i=2;i<n;i++)
	{int t;
	if((stu+1)->sum<(stu+i)->sum)
	{t=(stu+1)->sum;
     (stu+1)->sum=(stu+i)->sum;
	 (stu+i)->sum=t;
	 t=(stu+1)->num;
	 (stu+1)->num=(stu+i)->num;
	 (stu+i)->num=t;}}
	for(i=3;i<n;i++)
	{int t;
	if((stu+2)->sum<(stu+i)->sum)
	{t=(stu+2)->sum;
     (stu+2)->sum=(stu+i)->sum;
	 (stu+i)->sum=t;
	 t=(stu+2)->num;
	 (stu+2)->num=(stu+i)->num;
	 (stu+i)->num=t;}}
	for(i=0;i<3;i++)
	{	printf("%d %d\n",(stu+i)->num,(stu+i)->sum);}
    free(stu);
	return 0;
}


int pfCompare(const void* elem1,const void* elem2)
{
     int d;
     d=*((int*)elem2)-*((int*)elem1);
     return d;
}
struct student
    {
           long int ID;
           long int c;
           long int m;
    };
int main()
{
    long int n,i,j,k;
    int b[100000];
    int e[3];
    scanf("%d",&n);
   struct student a[100000];
   for(i=0;i<n;i++)
   {
                   scanf("%d %d %d",&a[i].ID,&a[i].c,&a[i].m);
   }
   for(i=0;i<n;i++)
   {
                   b[i]=a[i].c+a[i].m;
   }
   qsort(b,n,sizeof(long int),pfCompare);
   for(i=0;i<n;i++)
   {
                   if(b[0]==a[i].c+a[i].m)
                   {
                                          e[0]=a[i].ID;
                                           j=i;
                                           break;
                   }
  }
  for(i=0;i<n;i++)
   {
                   if((b[1]==a[i].c+a[i].m)&&i!=j)
                   {
                                                  e[1]=a[i].ID;
                                                     k=i;
                                                    break;
                   }
  }
  for(i=0;i<n;i++)
   {
                   if((b[2]==a[i].c+a[i].m)&&i!=j&&i!=k)
                   {
                                                        e[2]=a[i].ID;
                                                         break;
                   }
  }
   for(i=0;i<=2;i++)
   {
                    printf("%d %d\n",e[i],b[i]);
   }
   getchar();
   getchar();
   getchar();
}


struct student
{
 int a;
 int b;
 int c;
 int d;
 struct student *next;
};
 int n;
 struct student *creat(int i)
 {
	 struct student *head,*p1,*p2;
	 n=0;
	 p1=p2=(struct student *)malloc(sizeof(struct student));
	 scanf("%d %d %d",&p1->a,&p1->b,&p1->c);
	 p1->d=p1->c+p1->b;
	 head=NULL;
	 while(n<i-1)
	 {
      n=n+1;
	  if(n==1)head=p1;
	  else p2->next=p1;
	  p2=p1;
	  p1=(struct student *)malloc(sizeof(struct student));
      scanf("%d %d %d",&p1->a,&p1->b,&p1->c);
      p1->d=p1->c+p1->b;
	 }
	 p2->next=NULL;
	 return(head);
 }
void del(struct student *ahead,int num)
 { struct student *p1,*p2;
    p1=ahead;
   while(num!=p1->d&&p1->next!=NULL)
   {p2=p1;p1=p1->next;}
   if(num==p1->d)
   {
	   if(p1==ahead){printf("%d %d\n",p1->a,p1->d);ahead=p1->next;}
   else{printf("%d %d\n",p1->a,p1->d);p2->next=p1->next;}
   }
}
void print(struct student *head)
{
	int i;
	 struct student *p;
	 for(i=0;i<3;i++)
	 {
		 p=head;
     int max=p->d;
	 while(p->next!=NULL)
	 {
		 p=p->next;
		 if(max<p->d)
			 max=p->d;
	 }
	 del(head,max);
	 }
}
void main()
{
	int i;
	scanf("%d",&i);
   struct student *ahead;
   ahead=creat(i);
   print(ahead);
}


struct student
{
	int num;
	int chi;
	int math;
	int total;
	struct student *next;

};
struct student* creat(int n)
{
	struct student *p1,*p2,*head;
	int i;
	p1=p2=(struct student*) malloc(len);
	head=NULL;
	i=0;
	while(i<n)
	{
		scanf("%d %d %d",&p1->num,&p1->chi,&p1->math);
		i=i+1;
		if(i==1)
			head=p1;
		else p2->next=p1;
		p2=p1;
		p1=(struct student*)malloc(len);
	}
	p2->next=NULL;
	return(head);
}
void sum(struct student*head)
{
	struct student*p1;
    p1=head;
	while(p1)
	{
		p1->total=p1->chi+p1->math;
		p1=p1->next;

	}
}
struct student* choose(struct student*head)
{
	struct student*p1,*p2;
	p1=head;
	p2=p1;
	while(p1->next)
	{
		if(p2->total<(p1->next)->total)
			p2=p1->next;
		p1=p1->next;

	}
	printf("%d %d\n",p2->num,p2->total);
	return(p2);
}
struct student* del(struct student*head,struct student*p2)
{
	struct student *p1;
	p1=head;
	if(p2==head)
	{
		head=p2->next;
		return(head);
	}
	else
	{
		while(p1->next!=p2)
	{
		p1=p1->next;
	}
		p1->next=p2->next;
	}
	return(head);

}
void main()
{
	struct student *head,*p;
	int n;
	scanf("%d",&n);
	if(n>=3)
	{
	head=creat(n);
	sum(head);
	p=choose(head);
	head=del(head,p);
	p=choose(head);
	head=del(head,p);
	p=choose(head);
	}
	else if(n=2)
	{
		head=creat(n);
	sum(head);
	p=choose(head);
	head=del(head,p);
	p=choose(head);

	}
	else
	{

		head=creat(n);
	sum(head);
	p=choose(head);
	}

}


struct info
{
	int num;
	int chin;
	int math;
	struct info *next;
};
struct info *create(int n)
{
	int i;
	struct info *head,*p1,*p2;
	p1=(struct info*)malloc(sizeof(struct info));
	scanf("%d %d %d",&p1->num,&p1->chin,&p1->math);
	p1->next=NULL;
	head=p1;
	p2=p1;
	i=1;
	do
	{
		p1=(struct info*)malloc(sizeof(struct info));
		scanf("%d %d %d",&p1->num,&p1->chin,&p1->math);
		p1->next=NULL;
	    p2->next=p1;
	    p2=p1;
		i++;
	}while(i<n);
    return(head);
}
void arrange(struct info *head)
{
	int m,no1,no2,no3;
	struct info *p;
	p=head;
	m=0;
	while(p)
	{
	if (p->chin+p->math>m)
	{m=p->chin+p->math;no1=p->num;}
	p=p->next;
	}
	printf("%d %d\n",no1,m);
	m=0;
	p=head;
	no2=p->num;
	while(p)
	{
	if (p->chin+p->math>m&&p->num!=no1)
	{m=p->chin+p->math;no2=p->num;}
	p=p->next;
	}
	printf("%d %d\n",no2,m);
	m=0;
	p=head;
	no3=p->num;
	while(p)
	{
	if (p->chin+p->math>m&&p->num!=no1&&p->num!=no2)
	{m=p->chin+p->math;no3=p->num;}
	p=p->next;
	}
	printf("%d %d\n",no3,m);
}
int main()
{
	int n;
	struct info *head;
	scanf("%d",&n);
	head=create(n);
    arrange(head);
}


void main()
{
	long n;
	scanf("%ld",&n);
	struct student
{
	int num;
	int chi;
	int math;
	int sum;
}stu[100000];
	int i;
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&stu[i].num,&stu[i].chi,&stu[i].math);
		stu[i].sum=stu[i].chi+stu[i].math;
	}
	struct student blank;
	for(i=0;i<n;i++)
	{
		if(stu[i].sum>stu[0].sum)
		{
			blank=stu[0];
			stu[0]=stu[i];
			stu[i]=blank;
		}
	}
	for(i=1;i<n;i++)
	{
		if(stu[i].sum>stu[1].sum)
		{
			blank=stu[1];
			stu[1]=stu[i];
			stu[i]=blank;
		}
	}
	for(i=2;i<n;i++)
	{
		if(stu[i].sum>stu[2].sum)
		{
			blank=stu[2];
			stu[2]=stu[i];
			stu[i]=blank;
		}
	}
	for(i=0;i<=2;i++)
		printf("%d %d\n",stu[i].num,stu[i].sum);
}


 struct student
{int id;
 int chinese;
 int maths;
 int total;
};
void main()
{
	int n,i;
    struct student s,s1,s2,s3;
	scanf("%d",&n);
	s2.total=s1.total=s3.total=-1;
	for(i=0;i<n;i++)
	{	scanf("%d %d %d",&s.id,&s.chinese,&s.maths);
		s.total=s.chinese+s.maths;
		if(s.total>s1.total)
		{	s3=s2;
		    s2=s1;
			s1=s;
		}
		else if(s.total>s2.total)
		{	s3=s2;
		    s2=s;
		}
		else if(s.total>s3.total)
			s3=s;
	}

	printf("%d %d\n",s1.id,s1.total);
	printf("%d %d\n",s2.id,s2.total);
	printf("%d %d\n",s3.id,s3.total);

}


struct student
{
	int num;
	float yuwen;
	float shuxue;
	float zongfen;
}stu[student_num],*p[3];
void main()
{
	void paixu(struct student *a,int n);
	int i,n;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%f%f",&stu[i].num,&stu[i].yuwen,&stu[i].shuxue);
		stu[i].zongfen=stu[i].yuwen+stu[i].shuxue;
	}
	paixu(stu,n);
	for(i=0;i<3;i++)printf("%d %.0f\n",p[i]->num,p[i]->zongfen);
}
void paixu(struct student *a,int n)
{
	int i,j;
	float x[3];
	for(i=0;i<3;i++)
	{
		for(j=1,p[i]=a;j<n;j++)if(p[i]->zongfen<(a+j)->zongfen)p[i]=a+j;
		x[i]=p[i]->zongfen;
		p[i]->zongfen=0;
	}
	for(i=0;i<3;i++)p[i]->zongfen=x[i];
}


void main(int argc, char* argv[])
{
struct student
{
    int No;
	int chinese;
	int math;
	int total;
} stu[100000];
    int i,j,x,y,z,n;
	scanf("%d",&n);
	for(i=0;i<n;i++){
        scanf("%d",&stu[i].No);
        scanf("%d",&stu[i].chinese);
        scanf("%d",&stu[i].math);
		stu[i].total=stu[i].chinese+stu[i].math;
	}
	for(j=0;j<3;j++){
    x=0;
	for(i=0;i<n;i++){
			if(	stu[i].total>x){
				x=stu[i].total;
				y=stu[i].No;
				z=i;
			}
	}
	printf("%d %d\n",y,x);
	stu[z].total=0;
	}
}


struct stud
{
	int n;
	int chinese;
	int math;
	int total;
	struct stud *next;
};
int tol;
struct stud *creat(void)
{
	struct stud *head,*p1,*p2;
	int i=1;
	p1=p2=(struct stud *)malloc(sizeof(struct stud));
	head=p1;
	for(i=1;i<tol;i++)
	{
		scanf("%d%d%d",&p1->n,&p1->chinese,&p1->math);
		p1->total=(p1->math+p1->chinese);
		p1=(struct stud *)malloc(sizeof(struct stud));
		p2->next=p1;
		p2=p1;
	}
	scanf("%d%d%d",&p1->n,&p1->chinese,&p1->math);
	p1->total=(p1->math+p1->chinese);
	p2->next=p1;
	p1->next=0;
	return head;//???????
}
int max(struct stud *head,int max1,int max2)
{
	struct stud *p1;
	int maxtotal=head->total,max_index;
	for(p1=head;p1!=0;p1=p1->next)
	{
		if(p1->total>maxtotal&&p1->n!=max1&&p1->n!=max2)
		{
			maxtotal=(p1->total);
			max_index=(p1->n);
		}
	}
	if(maxtotal!=max1)
		printf("%d %d\n",max_index,maxtotal);
	return max_index;
}
void main()
{
	struct stud *head;
	int max1,max2;
	scanf("%d",&tol);
	head=creat();
	max1=max(head,0,0);
	max2=max(head,max1,0);
	max(head,max1,max2);
}


int n;

struct stu
{
	int xh;
	int yw;
	int sx;
	int all;
	struct stu*next;
};
struct stu *a,*b,*c,q,t,r;
struct stu*creat()
{
	struct stu *head;
	struct stu *p1,*p2;
	int i;
	p1=p2=(struct stu*)malloc(sizeof(struct stu));
	scanf("%d%d%d",&p1->xh,&p1->yw,&p1->sx);
	p1->all=p1->yw+p1->sx;
	head=p1;
	a=b=c=head;
	for(i=1;i<n;i++)
	{
		p2->next=p1;
		p2=p1;
		p1=(struct stu*)malloc(sizeof(struct stu));
		scanf("%d%d%d",&p1->xh,&p1->yw,&p1->sx);
		p1->all=p1->yw+p1->sx;
		if(p1->all>a->all)
		{
			c=b;
			b=a;
			a=p1;
		}
		else

			if(p1->all>b->all)
			{
				c=b;
			    b=p1;
			}
			else
			{
				if(p1->all>c->all)
					c=p1;
			}

	}p2->next=NULL;
	return head;
}

void main()
{

	struct stu *p;
	a=&q;b=&t;c=&r;
	scanf("%d",&n);
	p=creat();
	printf("%d %d\n%d %d\n%d %d\n",a->xh,a->all,b->xh,b->all,c->xh,c->all);
}


int main()
{
    int n;
    scanf ("%d",&n);
    struct student
    {
        int num;
        int chinese;
        int maths;
    };
    struct student a[100000],temp;
    int i;
    for (i=0;i<n;i++)
    {
        scanf("%d",&a[i].num);
        scanf("%d",&a[i].chinese);
        scanf("%d",&a[i].maths);
    }

    for (i=1;i<n;i++)
    {
        if ((a[i].chinese+a[i].maths)>(a[0].chinese+a[0].maths))
        {
            temp=a[0];
            a[0]=a[i];
            a[i]=temp;
        }
    }
    printf("%d %d\n",a[0].num,a[0].chinese+a[0].maths);

    for (i=2;i<n;i++)
    {
        if ((a[i].chinese+a[i].maths)>(a[1].chinese+a[1].maths))
        {
            temp=a[1];
            a[1]=a[i];
            a[i]=temp;
        }
    }
    printf("%d %d\n",a[1].num,a[1].chinese+a[1].maths);

    for (i=3;i<n;i++)
    {
        if ((a[i].chinese+a[i].maths)>(a[2].chinese+a[2].maths))
        {
            temp=a[2];
            a[2]=a[i];
            a[i]=temp;
        }
    }
    printf("%d %d\n",a[2].num,a[2].chinese+a[2].maths);
    return 0;
}


int n;

struct student
{
	int num;
	int chinese;
	int math;
	int total;
	struct student *next;
};
struct student *creat(int n)
{
	struct student *head;
	struct student *p1,*p2;
	int i;
	if(n==0)
	{
		head=NULL;
		return(head);
	}
	else
	{
		p1=(struct student*)malloc(LEN);
		scanf("%d %d %d",&p1->num,&p1->chinese,&p1->math);
		p1->next=NULL;
		head=p1;
		p2=p1;
		for(i=1;i<n;i++)
		{
			p1=(struct student*)malloc(LEN);
			scanf("%d %d %d",&p1->num,&p1->chinese,&p1->math);
			p1->next=NULL;
			p2->next=p1;
			p2=p1;
		}
		return(head);
	}

}
void top3(struct student *head)
{
	struct student *p,*p1;
	int max=0;
	p=head;
	do
	{
		p->total=(p->chinese)+(p->math);
		if((p->total)>max)
		{
			max=p->total;
			p1=p;
		}
		p=p->next;
	}while(p!=NULL);
	printf("%d %d\n",p1->num,p1->total);
	p1->total=0;
	p=head;
	max=0;
	do
	{
		if((p->total)>max)
		{
			max=p->total;
			p1=p;
		}
		p=p->next;
	}while(p!=NULL);
	printf("%d %d\n",p1->num,p1->total);
	p1->total=0;
	p=head;
	max=0;
	do
	{
		if((p->total)>max)
		{
			max=p->total;
			p1=p;
		}
		p=p->next;
	}while(p!=NULL);
	printf("%d %d\n",p1->num,p1->total);
	p1->total=0;
	max=0;

}
void main()
{
	struct student *head;
	scanf("%d",&n);
	head=creat(n);
	top3(head);
}


struct stu
{
	int num;
	int ch;
	int math;
	struct stu* next;
};

void main()
{
	int n,m=0,max=0,max2=0,max3=0,no=0,no2=0,no3=0;
	struct stu*p;
	scanf("%d",&n);
	struct stu*p1,*p2,*head;
	p1=(struct stu*)malloc(LEN);
	scanf("%d%d%d",&p1->num,&p1->ch,&p1->math);
	head=NULL;

	while(n-1)
	{
		m=m+1;
		if(m==1)
			head=p1;
		else
			p2->next=p1;
	     p2=p1;
		 p1=(struct stu*)malloc(LEN);
	     scanf("%d%d%d",&p1->num,&p1->ch,&p1->math);
	     n--;
	}
	p2->next=NULL;

	p=head;
	while(p)
	{
		p->ch=p->math+p->ch;
	    p=p->next;
	}

	p=head;
	while(p)
	{
		if(p->ch>max)
		{
		  max=p->ch;
		  no=p->num;
		}
		p=p->next;
	}
	printf("%d %d\n",no,max);

	p=head;
	while(p)
	{
		if(p->ch<=max&&p->ch>max2&&p->num!=no)
		{
		  max2=p->ch;
		  no2=p->num;
		}
		p=p->next;
	}
	printf("%d %d\n",no2,max2);

	p=head;
	while(p)
	{
		if(p->ch<=max2&&p->ch>max3&&p->num!=no&&p->num!=no2)
		{
		  max3=p->ch;
		  no3=p->num;
		}
		p=p->next;
	}
	printf("%d %d",no3,max3);

}


int main()
{
int n,i,j,k;
struct student
{
	int num;
	int chi;
	int math;
	int sum;
}score[100000],temp;
scanf("%d",&n);
for(i=0;i<n;i++)
{
	scanf("%d %d %d",&score[i].num,&score[i].chi,&score[i].math);
	score[i].sum=score[i].chi + score[i].math;
}
	for(i=0;i<4;i++)
	{
		k=i;
		for(j=i+1;j<n;j++)
			if(score[j].sum>score[k].sum) k=j;
		temp=score[k];score[k]=score[i];score[i]=temp;
	}
printf("%d %d",score[0].num,score[0].sum);printf("\n");
printf("%d %d",score[1].num,score[1].sum);printf("\n");
printf("%d %d",score[2].num,score[2].sum);
return 0;
}


struct statistics
	{
		int num;
		int chinese;
		int math;
		int sum;
	} form[100000],temp;
int main()
{

	int n;
	scanf("%d",&n);
	int i,j;
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&form[i].num,&form[i].chinese,&form[i].math);
		form[i].sum=form[i].chinese+form[i].math;
	}
	for(i=0;i<3&&i<n-1;i++)
	{
		int k=i;
		for(j=i+1;j<n;j++)
		{
			if(form[j].sum>form[k].sum)
			{
				k=j;
			}
		}
		if (k!=i)
		{
			temp=form[i];
			form[i]=form[k];
			form[k]=temp;

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


struct info
	{
		char num[10];
		int chn;
		int math;
		struct info *next;
	};
int n,all;
struct info *setup(void)
{
	struct info *head,*p1,*p2;
	n=0;
	while(n<all)
	{
		p1=(struct info*)malloc(sizeof(struct info));
		scanf("%s %d %d",p1->num,&p1->chn,&p1->math);
		n+=1;
		if(n==1)head=p1;
		else p2->next=p1;
		p2=p1;
	}
	p2->next=NULL;
	return(head);
}
void main()
{

	struct info *p;
	int i,first=0,second=0,third=0;
	char fnum[10],snum[10],tnum[10];
	scanf("%d",&all);
	p=setup();
	do
	{
		if(TOTAL>first)
		{
			third=second;
			second=first;
			first=TOTAL;
			strcpy(tnum,"");
			strcat(tnum,snum);
			strcpy(snum,"");
			strcat(snum,fnum);
			strcpy(fnum,"");
			strcat(fnum,p->num);
		}
		else if(TOTAL>second)
		{
			third=second;
			second=TOTAL;
			strcpy(tnum,"");
			strcat(tnum,snum);
			strcpy(snum,"");
			strcat(snum,p->num);
		}
		else if(TOTAL>third)
		{
			third=TOTAL;
			strcpy(tnum,"");
			strcat(tnum,p->num);
		}
		p=p->next;
	}while(p!=NULL);
	printf("%s %d\n%s %d\n%s %d\n",fnum,first,snum,second,tnum,third);
}


struct stud
{
	int num;
	int score,score1,score2;
	struct stud *next;
}head,end;
void create(int n)
{
	int i;
	struct stud *p1,*p2;
	head.next=NULL;
	for (i=0;i<=n-1;i++)
	{
		p1=(struct stud *)malloc(sizeof(struct stud));
		if (!i) head.next=p1;
		else p2->next=p1;
		scanf("%d",&p1->num);
		scanf("%d",&p1->score1);
		scanf("%d",&p1->score2);
		p1->score=p1->score1+p1->score2;
		p2=p1;
	}
	p2->next=&end;
}
void find()
{
	struct stud *max1,*max2,*max3,*p1,*swap;		//max1 is the max
	max1=head.next;
	max2=max1->next;
	max3=max2->next;
	p1=max3->next;
	if ( max1->score < max2->score )
	{
		swap=max1;
		max1=max2;
		max2=swap;
	}
	if ( max2->score < max3->score )
	{
		swap=max2;
		max2=max3;
		max3=swap;
	}
	if ( max1->score < max2->score )
	{
		swap=max1;
		max1=max2;
		max2=swap;
	}
	while (p1!=&end)
	{
		if ( p1->score > max3->score ) max3=p1;
		if ( max3->score > max2->score )
		{
			swap=max3;
			max3=max2;
			max2=swap;
		}
		if ( max2->score > max1->score )
		{
			swap=max1;
			max1=max2;
			max2=swap;
		}
		p1=p1->next;
	}
	printf("%d %d\n",max1->num,max1->score);
	printf("%d %d\n",max2->num,max2->score);
	printf("%d %d\n",max3->num,max3->score);
}
void main()
{
	int n;
	scanf("%d",&n);
	create(n);
	find();
}


struct stu
{
	int num;
	int chinese;
	int math;
	int sum;
	struct stu *next;
};

void main()
{
	void max(struct stu*);
	int n,i;
	struct stu *p,*q,*head;
	scanf("%d\n",&n);
	head=(struct stu*)malloc(sizeof(struct stu));
	p=(struct stu*)malloc(sizeof(struct stu));
	head->next=p;
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&p->num,&p->chinese,&p->math);
		p->sum=p->chinese+p->math;
		q=(struct stu*)malloc(sizeof(struct stu));
		p->next=q;
		p=q;
	}
	p->next=NULL;
	max(head);
	max(head);
	max(head);
}

void max(struct stu*head)
{
	struct stu *p,*k,*r,*q;
	int max=0;
	p=head;
	while(p->next!=NULL)
	{
		r=p;
		p=p->next;
		if(p->sum>max)  max=p->sum,k=r,q=p;
	}
	printf("%d %d\n",q->num,q->sum);
	k->next=q->next;
	free(q);
}


int main(){
	struct student{		//????student
		int StudentNumber;	//??
		int ChineseGrades;	//????
		int MathGrades;	    //????
		int Total;			//???
	};
	struct student Stu[100000],sTemp;	//??????Stu?sTemp
	int n,i,j;	//n??????i?j?????
	cin>>n;	//??????
	for (i=0;i<=n-1;i++){	//????????????????????????
		cin>>Stu[i].StudentNumber>>Stu[i].ChineseGrades>>Stu[i].MathGrades;
		Stu[i].Total=Stu[i].ChineseGrades+Stu[i].MathGrades;
	}
	for (i=0;i<=2;i++){	//?????????????????????
		for (j=n-1;j>=i+1;j--){
			if (Stu[j].Total>Stu[j-1].Total){
				sTemp=Stu[j];
				Stu[j]=Stu[j-1];
				Stu[j-1]=sTemp;
			}
		}
	}
	cout<<Stu[0].StudentNumber<<" "<<Stu[0].Total;	//?????
	for (i=1;i<=2;i++){
		cout<<endl;
		cout<<Stu[i].StudentNumber<<" "<<Stu[i].Total;
	}
	return 0;
}


struct student
{
        int num;
        int sum;
}stu[100000];

int main()
{

   int n,i,j,t,a,b,m;
   int tempSum;
   int tempMax;
   int rank[3]={0};
   scanf("%d",&n);
   //struct student * stu;
   //stu = (struct student *)malloc(sizeof(struct student) * n);
   for(i=0;i<n;i++)
   {
        tempSum = 0;
           scanf("%d",&stu[i].num);
           stu[i].sum = 0;
           for(j=0;j<2;j++){
            scanf("%d",&tempSum);
            stu[i].sum += tempSum;
           }
   }
   for(b=0;b<3;b++)
   {
       tempMax = 0;
       for(a=b;a<n;a++)
       {
           if(stu[a].sum > tempMax){
            tempMax = stu[a].sum;
            rank[b] = a;
           }
       }
       t = stu[b].num;
       stu[b].num = stu[rank[b]].num;
       stu[rank[b]].num = t;
       t = stu[b].sum;
       stu[b].sum = stu[rank[b]].sum;
       stu[rank[b]].sum = t;
   }
   for(a=0;a<3;a++)
   printf("%d %d\n",stu[a].num,stu[a].sum);

  return 0;
}


struct stu
{
   float num;
   float chi,mat,total;
   struct stu *next;
};
struct stu *creat(int n)
{
   int i;

   struct stu *head,*p1,*p2;
        for(i=0;i<n;i++)
   {
           p1=(struct stu*)malloc(sizeof(struct stu));
           scanf("%f %f %f",&p1->num,&p1->chi,&p1->mat);
           p1->total=p1->chi+p1->mat;
           if (i==0)
           {head=p2=p1;}
           else
           {p2->next=p1;p2=p1;}
   }
   p2->next=0;
   return(head);

}

void main()
{
        int n,i,j;
		float max;
        struct stu *head,*maxi,*p;
        scanf("%d",&n);
        head=creat(n);

        for(i=0;i<3;i++)
        {
            	p=head;maxi=head;
				max=head->total;
			for(j=0;j<n-1;j++)
			{
				p=p->next;
				if(p->total>max)
				{max=p->total;maxi=p;}
			}

			printf("%g %g\n",maxi->num,maxi->total);
            maxi->total=0;
        }
}


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


struct Student
{
long id;
int chn;
int mth;
int total;
};
void main()
{
struct Student *p1,*top1,*top2,*top3,*temp;
int i;
long int n;
scanf("%ld",&n);

top1=(struct Student*)malloc(sizeof(struct Student));
top2=(struct Student*)malloc(sizeof(struct Student));
top3=(struct Student*)malloc(sizeof(struct Student));
temp=(struct Student*)malloc(sizeof(struct Student));
scanf("%d %d %d",&top1->id,&top1->chn,&top1->mth);
top1->total=top1->chn + top1->mth;
scanf("%d %d %d",&top2->id,&top2->chn,&top2->mth);
top2->total=top2->chn + top2->mth;
if(top2->total>top1->total)
{
temp=top2;
top2=top1;
top1=temp;
}
scanf("%d %d %d",&top3->id,&top3->chn,&top3->mth);
top3->total=top3->chn + top3->mth;
if(top3->total>top2->total)
{
temp=top3;
top3=top2;
top2=temp;
}
if(top2->total>top1->total)
{
temp=top2;
top2=top1;
top1=temp;
}
for(i=3;i<n;i++)
{
p1=(struct Student*)malloc(sizeof(struct Student));
scanf("%d %d %d",&p1->id,&p1->chn,&p1->mth);
p1->total=p1->chn + p1->mth;
if (top1->total< p1->total) {top3=top2;top2=top1;top1=p1;continue;}
if (top2->total< p1->total) {top3=top2;top2=p1;continue;}
if (top3->total< p1->total) {top3=p1;continue;}
free (p1);
}
printf("%d %d\n%d %d\n%d %d\n",top1->id,top1->total,top2->id,top2->total,top3->id,top3->total);
}


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

int main(int argc, char* argv[])
{
	int i , n ;
	int max1=0,max2=0,max3=0;
	int maxid1=0,maxid2=0,maxid3=0;

	scanf("%d", &n );
	for ( i = 0 ; i < n ; i ++ )
	{
		scanf("%d %d %d", &stu[i].id , &stu[i].chinese ,&stu[i].math );
		stu[i].sum = stu[i].math + stu[i].chinese;
		if ( stu[i].sum > max1 )
		{
			max3 = max2 ;
			max2 = max1 ;
			max1 = stu[i].sum ;
			maxid3 = maxid2 ;
			maxid2 = maxid1 ;
			maxid1 = stu[i].id;
		}
		else if ( stu[i].sum > max2 )
		{
			max3 = max2 ;
			max2 = stu[i].sum ;
			maxid3 = maxid2 ;
			maxid2 = stu[i].id ;
		}
		else if ( stu[i].sum > max3 )
		{
			max3 = stu[i].sum ;
			maxid3 = stu[i].id ;
		}
	}
	printf("%d %d\n%d %d\n%d %d" , maxid1,max1,maxid2,max2,maxid3,max3);
	return 0;
}


struct stu
{
	int num;
	int yu;
	int shu;
	int tol;
	struct stu *next;
};
int n;

struct stu *creat(void)
{
	struct stu *p1,*p2,*head,*p;
	int i,k;
	p1=p2=(struct stu *)malloc(sizeof(struct stu));
	scanf("%d %d %d",&p1->num,&p1->yu,&p1->shu);
	p1->tol=p1->yu+p1->shu;
	p1->next=0;
	head=p1;
	p=p1;
	p1=(struct stu *)malloc(sizeof(struct stu));
	for(i=1;i<n;i++)
	{
		p=head;
		p2=p1;
		k=0;
		scanf("%d %d %d",&p1->num,&p1->yu,&p1->shu);
		p1->tol=p1->yu+p1->shu;
		while(p!=0&&p->tol>=p1->tol)
		{
			p2=p;
			p=p->next;
			k++;
		}
		if(k<=3)
		{
		if(p==head)
		{
			head=p1;
			p1->next=p;
		}
		if(p==0)
		{
			p2->next=p1;
			p1->next=0;
		}
		if(p!=head&&p!=0)
		{
			p2->next=p1;
			p1->next=p;
		}
		}
		p1=(struct stu *)malloc(sizeof(struct stu));
	}
	return head;
}
void main()
{
	struct stu *head,*p;
	int i=0;
	scanf("%d",&n);
	head=creat();
	p=head;
	while(i<3)
	{
		printf("%d %d\n",p->num,p->tol);
		i++;
		p=p->next;
	}
}


int main()
{
	int i,n,math,chinese,std_num;
	int first,second,third;
	int score[3]={-1,-1,-1};
	scanf("%d",&n);
	first=0;second=0;third=0;
    for(i=0;i<n;i++){
        scanf("%d",&std_num);
        scanf("%d",&chinese);
        scanf("%d",&math);
        if (chinese+math>score[0]){
           third =second;
           second=first;
           score[2]=score[1];
           score[1]=score[0];
           first = std_num;
           score[0]=chinese+math;
        }
        else if(chinese+math>score[1]){
                third=second;
                score[2]=score[1];
                second=std_num;
                score[1]=math+chinese;
             }
        else if(chinese+math>score[2]){
                third=std_num;
                score[2]=math+chinese;
             }
    }
    printf("%d %d\n",first,score[0]);
    printf("%d %d\n",second,score[1]);
    printf("%d %d\n",third,score[2]);
    return 0;
}


struct student
{
long num;
int chi;
int math;
int add;
};
struct student stu[100000];
void main()
{
int m,k,n,i,j;
scanf("%d",&n);
for(i=0;i<n;i++)
 {
 scanf("%ld %d %d",&stu[i].num,&stu[i].chi,&stu[i].math);
 stu[i].add=stu[i].chi+stu[i].math;
 }
for(j=0;j<3;j++)
 for(i=n-1;i>0;i--)
 {
 if(stu[i].add>stu[i-1].add)
 {
 k=stu[i].add;stu[i].add=stu[i-1].add;stu[i-1].add=k;
 m=stu[i].num;stu[i].num=stu[i-1].num;stu[i-1].num=m;
 }
 }
for(i=0;i<3;i++)
printf("%ld %d\n",stu[i].num,stu[i].add);
}


int main()
{
	struct student
	{
		int num;
		int chinese;
		int math;
		int sum;
	}stu[100000],t;

         int n;
	int i;
	int k;

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d",&stu[i].num,&stu[i].chinese,&stu[i].math);
                  stu[i].sum=stu[i].chinese+stu[i].math;
	}

         for(k=n-1;k>n-4;k--){
		for(i=0;i<k;i++){
			if(stu[i].sum>=stu[i+1].sum){
				t=stu[i];
                                    stu[i]=stu[i+1];
                                    stu[i+1]=t;
			}
		}
	}

        printf("%d %d\n",stu[n-1].num,stu[n-1].sum);
        printf("%d %d\n",stu[n-2].num,stu[n-2].sum);
        printf("%d %d\n",stu[n-3].num,stu[n-3].sum);

	return 0;
}