struct student{
	int No;
	int yuwen;
	int shuxue;
	int sum;
};

int main(){

	int n,i,k,e,f;

	scanf("%d",&n);

	struct student *stu=(struct student*)malloc(sizeof(int)*4*n);

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

	for(k=0;k<3;k++){
		for(i=n-1;i>k;i--){
			if(stu[i-1].sum<stu[i].sum){
			e=stu[i-1].sum;
			stu[i-1].sum=stu[i].sum;
			stu[i].sum=e;
			f=stu[i-1].No;
			stu[i-1].No=stu[i].No;
			stu[i].No=f;
			}
		}
	}
	for(i=0;i<3;i++){
		printf("%d %d\n",stu[i].No,stu[i].sum);
	}

	return 0;
}


struct student
{
	int id;
	int score1;
	int score2;
	struct student *next;
};
struct student *head;
struct student *creat(int x)
{
	struct student *p1,*p2;
	p1=p2=(struct student *)malloc(LEN);
    scanf("%d %d %d",&p1->id,&p1->score1,&p1->score2);
	head=0;
	while(p1->id<x)
	{
		if(p1->id==1)
			head=p1;
		else p2->next=p1;
		p2=p1;
		p1=(struct student *)malloc(LEN);
		scanf("%d %d %d",&p1->id,&p1->score1,&p1->score2);
		if(p1->id==x){
			p2->next=p1;
			p2=p1;
		}
	}
	p2->next=0;
	return(head);
}
void main()
{
	int n;
	struct student *p,*q,*j,*k;
	scanf("%d",&n);
	creat(n);
	p=q=head;
	do{
		if((p->score1+p->score2)>(q->score1+q->score2))
			q=p;
		p=p->next;
	}while(p!=0);
	p=j=head;
	do{
		if((p->score1+p->score2)>(j->score1+j->score2)&&p!=q)
			j=p;
		p=p->next;
	}while(p!=0);
	p=k=head;
	do{
		if((p->score1+p->score2)>(k->score1+k->score2)&&p!=q&&p!=j)
			k=p;
		p=p->next;
	}while(p!=0);
	printf("%d %d\n",q->id,(q->score1+q->score2));
	printf("%d %d\n",j->id,(j->score1+j->score2));
	printf("%d %d",k->id,(k->score1+k->score2));
}


struct student
	{
		int num;
		int chi;
		int mat;
		int sum;
	}stu[100000];
void main()
{

	int i,n,max=0,m,k;
	scanf("%d",&n);
	for(i=0;i<n;i++) {scanf("%d %d %d",&stu[i].num,&stu[i].chi,&stu[i].mat);stu[i].sum=stu[i].chi+stu[i].mat;}
	for(k=0;k<3;k++)
	{
		for(i=0;i<n;i++) if(stu[i].sum>max) {max=stu[i].sum;m=i;}
		printf("%d %d\n",stu[m].num,stu[m].sum);
		stu[m].sum=0;
		max=0;
	}
}


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


struct student
{
	char xuehao[100];
	int yuwen;
	int shuxue;
	int sum;
};

int main()
{
	int n,i,j,l,m;
    struct student stu[100000];
	struct student temp;

	scanf("%d",&n);

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

	for(j=1;j<4;j++)
	{
		for(m=0;m<n-j;m++)
		{
			if(stu[m].sum>=stu[m+1].sum)
			{
				temp=stu[m];
				stu[m]=stu[m+1];
				stu[m+1]=temp;
			}
		}
	}

	for(l=n-1;l>n-4;l--)
		printf("%s %d\n",stu[l].xuehao,stu[l].sum);

	return 0;
}


void main()
{
	int i,n,m;
	scanf("%d\n",&n);
	int j,b[100000]={0},t,s;
	struct student
	{
		int num;
		int lang;
		int math;
	};
	struct student a[100000];
	for(i=0;i<n;i++) scanf("%d %d %d\n",&a[i].num,&a[i].lang,&a[i].math);
    for(i=0;i<n;i++) b[i]=a[i].lang+a[i].math;
    for(j=0;j<3;j++)
		for(i=1;i<n-j;i++)
			if(b[j]<b[j+i])
			{t=b[j];b[j]=b[j+i];b[j+i]=t;}
    for(j=0;j<3;j++)
        for(i=0;i<n;i++)
		{
			m=a[i].lang+a[i].math;
			if(m==b[j] && i!=s) {printf("%d %d\n",a[i].num,m);s=i;break;}
		}
}


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

}


struct student
{
	int num,cn,math,sum,rank;
	struct student *next;
};
int n;

struct student * creat(void)
{
	int i=1;
	struct student *head;
	struct student *p1,*p2;
	p1=p2=(struct student *)malloc(LEN);
	scanf("%d %d %d",&p1->num,&p1->cn,&p1->math);
	head=p1;
	do
	{
		p2=p1;
		if(i==n)
			break;
		p1=(struct student *) malloc(LEN);
		scanf("%d %d %d",&p1->num,&p1->cn,&p1->math);
		p2->next=p1;
		i++;
	}while(1);
	p2->next=0;
	return(head);
}

void count(struct student *head)
{
	int max=0;
	struct student *p1;
	n=1;
	p1=head;
	do
	{
		p1->sum=p1->cn+p1->math;
		if(max<p1->sum)
			max=p1->sum;
		if(p1->next==0)
			break;
		p1=p1->next;
	}while(1);
	p1=head;
	do
	{
		if(p1->sum==max)
		{
			p1->rank=n;
			n++;
		}
		if(n>3)break;
		if(p1->next==0)
		{
			p1=head;
			max--;
		}
		else
		p1=p1->next;
	}while(1);
}

void print(struct student *head)
{
	struct student *p1;
	n=1;
	p1=head;
	do
	{
		if (p1->rank==n)
		{
			printf("%d %d\n",p1->num,p1->sum);
			n++;
		}
		if(n>3)
			break;
		if(p1->next==0)
			p1=head;
		else p1=p1->next;
	}while(1);
}

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


/*
 * statistics of scores.cpp
 *
 *  Created on: 2011-12-11
 *      Author: Administrator
 */
struct stu
	{
		int Num;
		int scoreC;
		int scoreM;
		int all;
	};
	struct stu stu[100005];
void fsort(int first,int last)
{
	int chosen1,chosen2,p,q;
	if(first>=last){return;}
	chosen1=stu[first].all;
	chosen2=stu[first].Num;
	p=first;q=last;
    while(p<q)
    {
    	while((p<q)&&(stu[q].all>=chosen1)){q--;}
    	if(p<q){stu[p].all=stu[q].all;stu[p].Num=stu[q].Num;p++;}
    	while((p<q)&&(stu[p].all<chosen1)){p++;}
    	if(p<q){stu[q].all=stu[p].all;stu[q].Num=stu[p].Num;q--;}
    }
    stu[p].all=chosen1;stu[p].Num=chosen2;
    fsort(first,p-1);
    fsort(p+1,last);
}
int main()
{
	int m,i;//????
	cin>>m;
	for(i=1;i<=m;i++)//????
	{
		cin>>stu[i].Num>>stu[i].scoreC>>stu[i].scoreM;
		stu[i].all=stu[i].scoreC+stu[i].scoreM;
	}
	fsort(1,m);
	cout<<stu[m].Num<<" "<<stu[m].all<<endl;//?????
	cout<<stu[m-1].Num<<" "<<stu[m-1].all<<endl;
	cout<<stu[m-2].Num<<" "<<stu[m-2].all<<endl;
	return 0;
}


struct Student
{
    int num;
    int chinese;
    int math;
}sdu[99999];

int main()
{
    int N,i,j,s,t,m;
    scanf("%d",&N);
    for(i=0;i<N;i++)
        scanf("%d%d%d",&sdu[i].num,&sdu[i].chinese,&sdu[i].math);

    for(j=0;j<3;j++){
        for(i=0;i<N-j-1;i++)
            if((sdu[i].chinese+sdu[i].math)>=(sdu[i+1].chinese+sdu[i+1].math)){
                s=sdu[i].num;t=sdu[i].chinese;m=sdu[i].math;
                sdu[i].num=sdu[i+1].num;sdu[i].chinese=sdu[i+1].chinese;sdu[i].math=sdu[i+1].math;
                sdu[i+1].num=s;sdu[i+1].chinese=t;sdu[i+1].math=m;
            }
    }
    for(i=0;i<3;i++)
    printf("%d %d\n",sdu[N-1-i].num,sdu[N-1-i].chinese+sdu[N-1-i].math);
}


struct stu
{
  int id;
  int eng;
  int math;
  int sum;
  struct stu *next;
}*head,*p1,*p2;
struct stu *order(int n)
{
 int i,j,t;
 p1=head;
 for(i=0;i<3;i++)
 {
   p2=p1->next;
   for(j=i+1;j<n;j++)
   { if(p1->sum<p2->sum)
    {
      t=p1->id;p1->id=p2->id;p2->id=t;
      t=p1->sum;p1->sum=p2->sum;p2->sum=t;
     }
   p2=p2->next;}
  p1=p1->next;
  }
 return head;
}
void main()
{
 int n,i;
 scanf("%d",&n);
 p1=head=(struct stu *)malloc(sizeof(struct stu));
 for(i=0;i<n;i++)
  {
    scanf("%d %d %d",&p1->id,&p1->eng,&p1->math);
    p1->sum=p1->eng+p1->math;
    p2=p1;
    p1=(struct stu *)malloc(sizeof(struct stu));
    p2->next=p1;
   }
 p2->next=NULL;
 p1=order(n);
 for(i=0;i<3;i++)
 {
  printf("%d %d\n",p1->id,p1->sum);
  p1=p1->next;
  }
}


struct student
	{
		int num;
		int chinese;
		int math;
		int sum;
	}work[100001];
void qsort(int left,int right)
{
	if (left>=right) return;
	int pindex=left,rindex=right;
   work[0]=work[left];
   while (pindex<rindex)
   {
	while ((pindex<rindex)&&(work[rindex].sum>=work[0].sum))
	 rindex--;
	if (pindex<rindex){work[pindex]=work[rindex];pindex++;}
	while ((pindex<rindex)&&(work[pindex].sum<work[0].sum))
		 pindex++;
	if (pindex<rindex){work[rindex]=work[pindex];rindex--;}
   }
   work[pindex]=work[0];
   qsort(left,pindex-1);
   qsort(pindex+1,right);
}
int main()
{
	int n,i;
	cin>>n;
	for (i=1;i<=n;i++)
	{
      cin>>work[i].num>>work[i].chinese>>work[i].math;
      work[i].sum=work[i].chinese+work[i].math;
	}
	qsort(1,n);
	for (i=0;i<=2;i++)
	cout<<work[n-i].num<<" "<<work[n-i].sum<<endl;
	return 0;
}


int main()
{
	struct student
	{
		int num, ch, ma, grade;
    }sum[100000], h, m, t;
	int i, n;
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d", &sum[i].num, &sum[i].ch, &sum[i].ma);
	    sum[i].grade=sum[i].ch+sum[i].ma;
	}
	h.grade=m.grade=t.grade=0;
	for(i=0;i<n;i++)
	{
		if(sum[i].grade>h.grade)
		{
			t=m;
			m=h;
			h=sum[i];
		}
		else if(sum[i].grade>m.grade)
		{
			t=m;
			m=sum[i];
		}
		else if(sum[i].grade>t.grade)
			t=sum[i];
	}
	printf("%d %d\n%d %d\n%d %d\n", h.num, h.grade, m.num, m.grade, t.num, t.grade);
	return 0;
}


struct student
{
	int num;
	double chi;
	double math;
	double total;
};
int main()
{
	struct student stu[100000];
	struct student temp;
	int n,i,j,k;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%lf%lf",&stu[i].num,&stu[i].chi,&stu[i].math);
		stu[i].total=stu[i].chi+stu[i].math;
	}
	for(i=0;i<3;i++)
	{
		k=i;
		for(j=i;j<n;j++)
		{
			if(stu[k].total<stu[j].total)
			{
				k=j;
			}
		}
		if(k!=i)
		{
			temp=stu[i];
			stu[i]=stu[k];
			stu[k]=temp;
		}
	}
	for(i=0;i<3;i++)
	{
		printf("%d %.0lf\n",stu[i].num,stu[i].total);
	}

	return 0;
}


struct student
{
    int id;
    int c;
    int m;
    int t;
    } a[SIZE];
int cmp(const void*p1,const void*p2)
{
    struct student*p3=(struct student*)p1;
    struct student*p4=(struct student*)p2;
    return -p3->t+p4->t;
}
int main(void)
{
    int n, i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {scanf("%d%d%d",&a[i].id,&a[i].c,&a[i].m);a[i].t=a[i].m+a[i].c;}
    qsort(a,n,sizeof(a[0]),cmp);
    for(i=0;i<3;i++)
    printf("%d %d\n", a[i].id, a[i].c+a[i].m);
    return 0;
}


int main ( ) {
	int N , i ;
	cin >> N ;
	int Max1 = 0 , Max2 = 0 , Max3 = 0 , Nb[4] ;
	struct student {
		int Number ;
		int Chinese ;
		int Math ;
		int Total ;
	}people[111111];
	for ( i = 1 ; i <= N ; i ++ ) {
		cin >> people[i].Number >> people[i].Chinese >> people[i].Math ;
		people[i].Total = people[i].Chinese + people[i].Math ;
	}
	for ( i = 1 ; i <= N ; i ++ ) {
		if ( Max1 < people[i].Total ){
			Nb[1] = i ;
			Max1 = people[i].Total ;
		}
	}
	for ( i = 1 ; i <= N ; i ++ ) {
		if ( ( Max2 < people[i].Total ) && ( i != Nb[1] ) ){
			Nb[2] = i ;
			Max2 = people[i].Total ;
		}
	}
	for ( i = 1 ; i <= N ; i ++ ) {
		if ( ( Max3 < people[i].Total ) && ( i != Nb[1] ) && ( i != Nb[2] ) ){
			Nb[3] = i ;
			Max3 = people[i].Total ;
		}
	}
	for ( i = 1 ; i <= 3 ; i ++ ) {
	cout << people[Nb[i]].Number << " " << people[Nb[i]].Total ;
	if ( i < 3 )
		cout << endl ;
	}
	return 0 ;
}


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

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


struct stu
	{
		int id;
		int ch;
		int mt;
		int total;
	};
	struct stu stu_1[100000];
	struct stu top1={0,0,0,0},top2={0,0,0,0},top3={0,0,0,0};

int main()
{	int n,i;
	struct stu tem;
	scanf("%d",&n);

	for(i=0;i<n;i++){
		scanf("%d %d %d",&(stu_1[i].id),&(stu_1[i].ch),&(stu_1[i].mt));
		stu_1[i].total=stu_1[i].ch+stu_1[i].mt;
		if(stu_1[i].total>top1.total){
			top3=top2;top2=top1;top1=stu_1[i];
		}
		else if(stu_1[i].total>top2.total){
			top3=top2;top2=stu_1[i];
		}
		else if(stu_1[i].total>top3.total){
			top3=stu_1[i];
		}
		else;
		}
		printf("%d %d\n",top1.id,top1.total);
		if((top2.id)!=0)
			printf("%d %d\n",top2.id,top2.total);
		if((top3.id)!=0)
			printf("%d %d\n",top3.id,top3.total);

	return 0;
}


struct student{
  int num;
  int chin;
  int math;
  int sum;
}tem_stu;
int main()
{
 int n,i;
 scanf("%d",&n);
 struct student *stu;
 stu=(struct student*)malloc(n*sizeof(struct student));
 for(i=0;i<n;i++){
  scanf("%d%d%d",&stu[i].num,&stu[i].chin,&stu[i].math);
  stu[i].sum=stu[i].chin+stu[i].math;
 }
 int j;
 for(j=1;j<4;j++){
  for(i=0;i<n-j;i++){
   if(stu[i].sum>=stu[i+1].sum){
         tem_stu=stu[i+1];
         stu[i+1]=stu[i];
	stu[i]=tem_stu;
   }
  }
 }

 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);
 free(stu);
 return 0;
}


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

struct student *creat(int n)
{
	struct student *head,*p1,*p2;
	int i;
	p1=p2=(struct student *)malloc(LEN);
	scanf("%d %d %d",&p1->num,&p1->chi,&p1->math);
    head=p1;
	for(i=2;i<=n;i++)
	{
		p1=(struct student *)malloc(LEN);
		scanf("%d %d %d",&p1->num,&p1->chi,&p1->math);
	    p2->next=p1;
		p2=p1;

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

void main()
{
	struct student *head,*p,*p1,*p2,*p3;
	int n,m1,m2,m3,k;
	scanf("%d",&n);
	head=creat(n);
	p=head;
	m1=m2=m3=0;
	if(head!=NULL)
	{
		do
		{
            k=p->chi+p->math;
			if(k>m1)
			{	m1=k;p1=p;}
			p=p->next;
		}
		while(p!=NULL);
		p=head;
		do
		{
			k=p->chi+p->math;
			if((k>m2)&&(p!=p1))
			{	m2=k;p2=p;}
			p=p->next;
		}
		while(p!=NULL);
		p=head;
		do
		{
			k=p->chi+p->math;
			if((k>m3)&&(p!=p1)&&(p!=p2))
			{	m3=k;p3=p;}
			p=p->next;
		}
		while(p!=NULL);
	}
	printf("%d %d\n%d %d\n%d %d\n",p1->num,m1,p2->num,m2,p3->num,m3);
}


void main()
{
   struct stu
   {int num;
   	int chi;
   	int mat;
   }stu[100000];
   int n,i,max1,max2,max3,maxn1,maxn2,maxn3;
   int sum[100000];
   scanf("%d",&n);
   for(i=0;i<n;i++)
   {scanf("%d",&stu[i].num);
   	scanf("%d",&stu[i].chi);
   	scanf("%d",&stu[i].mat);
   	sum[i]=stu[i].chi+stu[i].mat;
   }
    max1=sum[0];
    maxn1=stu[0].num;
    for(i=1;i<n;i++)
    {
        if(sum[i]>max1)
        {
            max1=sum[i];
            maxn1=stu[i].num;
        }
    }
       printf("%d %d\n",maxn1,max1) ;
    max2=sum[0];
    maxn2=stu[0].num;
        for(i=1;i<n;i++)
    {
        if(sum[i]>max2&&i!=maxn1-1)
        {
            max2=sum[i];
            maxn2=stu[i].num;
        }
    }
       printf("%d %d\n",maxn2,max2) ;
    max3=sum[0];
    maxn3=stu[0].num;
        for(i=1;i<n;i++)
    {
        if(sum[i]>max3&&i!=maxn1-1&&i!=maxn2-1)
        {
            max3=sum[i];
            maxn3=stu[i].num;
        }
    }
       printf("%d %d\n",maxn3,max3) ;
}


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

void main()
{
	struct student *creat();
	struct student *head,*p,*q1,*q2,*q3;
	int a;
	scanf("%ld",&n);
	head=creat();
	p=head;
	a=0;
	while(p!=NULL)
	{
		if(p->sum>a)
		{
			a=p->sum;
			q1=p;
		}
		p=p->next;
	}
	p=head;
	a=0;
	while(p!=NULL)
	{
		if(p->sum>a&&p!=q1)
		{
			a=p->sum;
			q2=p;
		}
		p=p->next;
	}
	p=head;
	a=0;
	while(p!=NULL)
	{
		if(p->sum>a&&p!=q1&&p!=q2)
		{
			a=p->sum;
			q3=p;
		}
		p=p->next;
	}
	printf("%d %d\n",q1->num,q1->sum);
	printf("%d %d\n",q2->num,q2->sum);
	printf("%d %d\n",q3->num,q3->sum);
}

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


int sum[1000000];
struct student{
	   int id;
	   int Gra[2];
	   }stu[1000000];
int main()
{
       int n;

      cin>>n;
      for(int i=0;i<n;i++)
        {
    	  cin>>stu[i].id>>stu[i].Gra[0]>>stu[i].Gra[1];
    	  sum[i]=stu[i].Gra[0]+stu[i].Gra[1];
        }
      int max=0,imax=0;
      for(int i=0;i<3;i++)
      {    max=0;
    	  for(int j=0;j<n;j++)
    		  if(max<sum[j])  {max=sum[j];imax=j;}

    	  cout<<stu[imax].id<<" "<<sum[imax]<<endl;
    	  sum[imax]=0;

      }

     return 0;
}


struct student
{
	int id;
	int c;
	int m;
	int s;
	struct student *next;
};
struct student *creat(void)
{
	struct student *head,*p1,*p2;
	int n,i;
	p1=p2=(struct student*)malloc(LEN);
    scanf("%d",&n);
	head=NULL;
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&p1->id,&p1->c,&p1->m);
		p1->s=p1->c+p1->m;
		if(i==0)head=p1;
		else p2->next=p1;
		p2=p1;
		p1=(struct student *)malloc(LEN);
	}
	p2->next=NULL;
    return (head);
}
void exchange(struct student *x,struct student *y)
{
	int t;
	t=x->id;x->id=y->id;y->id=t;
	t=x->c;x->c=y->c;y->c=t;
	t=x->m;x->m=y->m;y->m=t;
	t=x->s;x->s=y->s;y->s=t;
}
void main()
{
	struct student *p,*q,*head;
	int temp,i;
	head=p=creat();
	for(p=head,i=0;p->next!=NULL,i<3;p=p->next,i++)
	{
		temp=p->s;
		for(q=p->next;q!=NULL;q=q->next)
		{
			if(p->s<q->s)temp=q->s;
			if(p->s!=temp)exchange(p,q);
		}
	}
	for(p=head,i=0;i<3;p=p->next,i++)
		printf("%d %d\n",p->id,p->s);
}


int n,max1,xue1,max2,xue2,max3,xue3;
struct chengji
{
    int xh;
    int yw;
    int sx;
    int zf;
    struct chengji *next;
};

void create()
{
    struct chengji *head;
    struct chengji *p1;
    int i=0;
    while(i<n)
    {   i++;
    	if (i==1) head=p1;
    	p1=(struct chengji *)malloc(len);
    	      scanf("%d %d %d",&p1->xh,&p1->yw,&p1->sx);
    	      p1->zf=p1->yw+p1->sx;
    	      if ((p1->zf)>max1)
    	      {
    	           xue3=xue2;
    	           max3=max2;
    	           xue2=xue1;
    	           max2=max1;
    	           xue1=p1->xh;
    	           max1=p1->zf;

    	      }
    	      else
    	      {if ((p1->zf)>max2&&(p1->zf)<=max1)
    	      {
    	          xue3=xue2;
    	          max3=max2;
    	          xue2=p1->xh;
    	          max2=p1->zf;
    	      }
    	      else {if ((p1->zf)>max3&&(p1->zf)<=max2)
    	      {
    	          xue3=p1->xh;
    	          max3=p1->zf;
    	      }}}

        p1=p1->next;
    }
}

void main()
{
    scanf("%d",&n);
    max1=0,max2=0,max3=0;
    create();
    printf("%d %d\n",xue1,max1);
    printf("%d %d\n",xue2,max2);
    printf("%d %d",xue3,max3);
}


int stu [100000];
int main(int argc, char* argv[])
{
	int n,i,j,y,t,m;
	struct s{
		int a;
		int b;
		int c;
	}stu[100000];

	scanf ("%d",&n);
	for (i=0;i<n;i++)
	{
		scanf ("%d%d%d",&stu[i].a,&stu[i].b,&stu[i].c);

	}
	for (i=0;i<3;i++)
	{
		for (j=i+1;j<n;j++)
		{
			if ((stu[j].b+stu[j].c)>(stu[i].b+stu[i].c))
			{
				y=stu[i].b;t=stu[i].c;m=stu[i].a;
				stu[i].b=stu[j].b;
				stu[j].b=y;
				stu[i].c=stu[j].c;
				stu[j].c=t;
				stu[i].a=stu[j].a;
				stu[j].a=m;
			}
		}
	}
	for (i=0;i<3;i++)
	{
		printf ("%d %d\n",stu[i].a,(stu[i].b+stu[i].c));
	}
	return 0;
}


int main()
{
    long n,i;
    int high[4]={0};
    long higher[4];
    struct student
    {
          long num;
          int yuwen;
          int shuxue;
          int total;
    }stu[100000];
    scanf("%d",&n);
    for (i=1;i<=n;i++)
    {
        scanf("%d %d %d",&stu[i].num,&stu[i].yuwen,&stu[i].shuxue);
        stu[i].total=stu[i].yuwen+stu[i].shuxue;
        if (stu[i].total>high[1])
        {
            high[1]=stu[i].total;
            higher[1]=i;
        }
    }
    for (i=1;i<=n;i++)
        if (stu[i].total<=high[1]&&stu[i].total>high[2]&&i!=higher[1])
        {
             high[2]=stu[i].total;
             higher[2]=i;
        }
    for (i=1;i<=n;i++)
        if (stu[i].total<=high[2]&&stu[i].total>high[3]&&i!=higher[1]&&i!=higher[2])
        {
             high[3]=stu[i].total;
             higher[3]=i;
        }

    for (i=1;i<4;i++)
        printf("%d %d\n",higher[i],high[i]);
   }


int main()
{
	long int n,a[100000][2];
	int i,j,t,s;
	struct Student
	{int num;
	int yu;
	int shu;
	};
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		struct Student studenti;
		scanf("%d%d%d",&studenti.num,&studenti.yu,&studenti.shu);
		a[i][0]=studenti.num;
		a[i][1]=studenti.yu+studenti.shu;
	}
	for(i=0;i<3;i++)
	{	for(j=0;j<n-1-i;j++)
		{if(a[j][1]>=a[j+1][1])
		{t=a[j][1];a[j][1]=a[j+1][1];a[j+1][1]=t;
	s=a[j][0];a[j][0]=a[j+1][0];a[j+1][0]=s;
	}
		}
	}
   for(i=1;i<=3;i++)
	  printf("%d %d\n",a[n-i][0],a[n-i][1]);
   return 0;
}


int main ()
{
	struct student
	{
		int num;
		int ch;
		int ma;
		int sum;
	};
	struct student *p;
	int n, i, j, t1, t2, a1=0, a2=0, a3=0, k1, k2, k3;
	scanf ("%d", &n);
	p=(struct student *)malloc (n*sizeof (struct student));
	for (i=0; i<n; i++)
	{ scanf ("%d%d%d", &p[i].num, &p[i].ch, &p[i].ma);
	p[i].sum= p[i].ch+p[i].ma; }
	/*for (j=0; j<n-1; j++)
		for (i=0; i<n-1-j; i++)
			if (p[i].sum<p[i+1].sum)
			{ t1=p[i].num; p[i].num=p[i+1].num; p[i+1].num=t1;
			t2=p[i].sum; p[i].sum=p[i+1].sum; p[i+1].sum=t2; }*/
	for (i=0; i<n; i++)
		if (p[i].sum>a1) { k1=i; a1=p[i].sum; }
	for (i=0; i<n; i++)
		if (p[i].sum<=a1 && p[i].sum>a2 && i!=k1) { k2=i; a2=p[i].sum; }
	for (i=0; i<n; i++)
		if (p[i].sum<=a2 && p[i].sum>a3 && i!=k1 && i!=k2) { k3=i; a3=p[i].sum; }
	printf ("%d %d\n%d %d\n%d %d\n", p[k1].num, p[k1].sum, p[k2].num, p[k2].sum, p[k3].num, p[k3].sum);
	/*for (i=0; i<3; i++)
		printf ("%d %d\n", p[i].num, p[i].sum);*/
	return 0;
}


int main()
{int n,sum[100000],a,b,c;
 struct xues{int a,b,c;} s[100000];
 scanf ("%d",&n);
 int i;
 for(i=0;i<n;i++){
	 scanf("%d%d%d",&s[i].a,&s[i].b,&s[i].c);
	 sum[i]=s[i].b+s[i].c;
 }
 int fir=0,sec=0,thi=0;
 for(i=0;i<n;i++){
     if(fir<sum[i]){
	    thi=sec;
		sec=fir;
		fir=sum[i];
		c=b;
		b=a;
		a=s[i].a;
	 }
	 else if(sec<sum[i]){
	 thi=sec;
	 sec=sum[i];
	 fir=fir;
	 a=a;
	 c=b;
	 b=s[i].a;
	 }
	 else if(thi<sum[i]){
	 fir=fir;
	 sec=sec;
	 thi=sum[i];
	 a=a;
	 b=b;
	 c=s[i].a;
	 }
 }
 printf("%d %d\n%d %d\n%d %d",a,fir,b,sec,c,thi);
	return 0;
}


struct student
{	int ID;
	int ch;
	int ma;
};

void main()
{	struct student re[N];
	int n;
	int i=0,j=0,rec;
	int total[N];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{	scanf("%d%d%d",&re[i].ID,&re[i].ch,&re[i].ma);
		total[i]=re[i].ch+re[i].ma;
	}

	int max=total[0];

	for(i=0;i<n;i++)
	{	if(max<total[i])
		{	max=total[i];
			rec=i;
		}
		if(i==n-1)
		{	printf("%d %d\n",re[rec].ID,total[rec]);
			total[rec]=0;
			i=0;
			max=total[0];
			j++;
		}

		if(j==3)
			break;
	}

}


typedef struct {
	int d;
	int score;
} student;

int main()
{
	int n, i, temp1, temp2;
	student a[100002];
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d%d%d", &a[i].d, &temp1, &temp2);
		a[i].score = temp1 + temp2;
	}

	student max1, max2, max3;
	max1.d = max2.d = max3.d = -1;
	max1.score = max2.score = max3.score = 0;

	for (i = 0; i < n; i++) {
		if (a[i].score > max1.score) {
			max3 = max2;
			max2 = max1;
			max1 = a[i];
		}
		else if (a[i].score > max2.score) {
			max3 = max2;
			max2 = a[i];
		}
		else if (a[i].score > max3.score) {
			max3 = a[i];
		}
	}

	printf("%d %d\n", max1.d, max1.score);
	if (max2.d != -1)
		printf("%d %d\n", max2.d, max2.score);
	if (max3.d != -1)
		printf("%d %d\n", max3.d, max3.score);
	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<n;i++)printf("%d %d\n",form[i].num,form[i].sum);
return 0;}


struct stu
{
	long xh;
	int yw;
	int sx;
	int zh;
	struct stu *next;
};
struct stu *scan()
{
	long n;
	long num=0;
	struct stu *head,*p1,*p2;
	p1=p2=(struct stu *)malloc(sizeof (struct stu));
	scanf("%ld",&n);
//	head=0;
	head=p1;
    while(num<n)
	{
		scanf("%ld",&p1->xh);
		scanf("%d",&p1->yw);
		scanf("%d",&p1->sx);
		p1->zh=p1->yw+p1->sx;
        p2=p1;
		p1=(struct stu *)malloc(sizeof (struct stu));
		p2->next=p1;
		p1->next=0;
		num++;
	}
	return(head);
}
struct stu *del(struct stu *head,int max)
{
	struct stu *p1,*p2;
	p1=head;
	while(max!=p1->zh&&p1->next!=0)
	{
		p2=p1;
		p1=p1->next;
	}
	if(max==p1->zh)
	{
		if(p1==head)
		{
			head=p1->next;
		}
		else
		{
			p2->next=p1->next;
		}
	}
	return (head);
}
void print(struct stu *head)
{
	struct stu *p,*p1,*p2,*p3,*w;
	int max=0,num=0;
    while(num<3)
	{
		for(p=head;p!=0;p=p->next)
		{
			if(p->zh>max)
			{
				max=p->zh;
				w=p;
			}
		}
		num++;
		if(num==1)
		{
			p1=w;
			head=del(head,max);
			max=0;
		}
		if(num==2)
		{
			p2=w;
			head=del(head,max);
			max=0;
		}
		if(num==3)
		{
			p3=w;
		}
	}
	printf("%ld %d\n%ld %d\n%ld %d\n",p1->xh,p1->zh,p2->xh,p2->zh,p3->xh,p3->zh);
}
void main()
{
	struct stu *head;
	head=scan();
	print(head);
}


/*
 * xue sheng cheng ji tong ji.cpp
 *
 *  Created on: 2010-12-26
 *      Author: taoshibo
 */
int main() {
	int n = 0, i = 0, j = 0;
	cin >> 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;
	}
	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;
}


int main()
{
    int id,chinese,math,total;

	int n,i,a=0,b=0,c=0,x=0,y=0,z=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
        scanf("%d%d%d",&id,&chinese,&math);
		total=chinese+math;
		if(total>a)
		{
			c=b;
			z=y;
			b=a;
			y=x;
            a=total;
			x=id;

		}
		else if(total<=a&&total>b)
		{
			c=b;
			z=y;
			b=total;
			y=id;
		}
		else if(total<=b&&total>c)
		{
			c=total;
			z=id;
		}

	}

    printf("%d %d\n",x,a);
	printf("%d %d\n",y,b);
    printf("%d %d\n",z,c);
	return 0;
}


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


void main()
{

struct student
{
int num;
int a;
int b;
}stu[100000];

int n,i,sum=0,max1=0,max2=0,max3=0,t=0;
scanf("%d",&n);

for(i=0;i<n;i++)
{
scanf("%d %d %d",&stu[i].num,&stu[i].a,&stu[i].b);
sum=stu[i].a+stu[i].b;
if (sum>max1) {max3=max2;max2=max1;max1=sum;}
else if ((sum<max1)&&(sum>max2)){max3=max2;max2=sum;}
else if ((sum<max2)&&(sum>max3)){max3=sum;}
}

for(i=0;i<n;i++)
{
sum=stu[i].a+stu[i].b;
if (sum==max1) {printf("%d %d\n",stu[i].num,max1);t++;}
}

for(i=0;i<n;i++)
{
sum=stu[i].a+stu[i].b;
if ((sum==max2)&&(t<3)) {printf("%d %d\n",stu[i].num,max2);t++;}
}

for(i=0;i<n;i++)
{
sum=stu[i].a+stu[i].b;
if ((sum==max3)&&(t<3)) {printf("%d %d\n",stu[i].num,max3);t++;}
}

}


struct student
{
	char num[30];
	float chi;
	float mat;
	float tot;
	struct student *next;
};

struct student * creat(struct student *head,struct student *stud)
{
	struct student *p0,*p1,*p2;
	p1=head;
	p0=stud;
	if(head==NULL)
	{head=p0;p0->next=NULL;}
	else
	{while((p0->tot<=p1->tot)&&(p1->next!=NULL))
		{p2=p1;p1=p1->next;}
	 if(p0->tot>=p1->tot)
	 {if(head==p1) head=p0;
	  else p2->next=p0;
	  p0->next=p1;}
	 else
	 {p1->next=p0;p0->next=NULL;}
	}
	return(head);
}

struct student * compare(struct student *head,struct student *stud)
{
	struct student *p0,*p1,*p2;
	int i;
	p1=head;
	p0=stud;
	while((p0->tot<=p1->tot)&&(p1->next!=NULL))
		{p2=p1;p1=p1->next;}
	if((p0->tot>p1->tot)||((p0->tot=p1->tot)&&(p1->next!=NULL)))
	{
      if(head==p1) head=p0;
	  else p2->next=p0;
	  p0->next=p1;
	  p1=head;
	  for(i=0;i<2;i++)
	  {p1=p1->next;}
	  p1->next=NULL;

	}

	return(head);
}

void print(struct student * head)
{
	struct student *p;
	int i;
	p=head;
	for(i=0;i<3;i++)
	{
		printf("%s %g\n",p->num,p->tot);
		p=p->next;
	}
}

void main()
{
	struct student *head;
	struct student *stu;
	int n,i;
	head=NULL;
	scanf("%d",&n);
	for(i=0;i<3;i++)
	{   stu=(struct student *)malloc(LEN);
		scanf("%s %f %f",&stu->num,&stu->chi,&stu->mat);
		stu->tot=stu->chi+stu->mat;
		head=creat(head,stu);

	}
	for(i=3;i<n;i++)
	{
		stu=(struct student *)malloc(LEN);
		scanf("%s %f %f",&stu->num,&stu->chi,&stu->mat);
		stu->tot=stu->chi+stu->mat;
		head=compare(head,stu);

	}
	print(head);
}


int main()
{
    struct student
    {
        int ID;
        int yuwen;
        int shuxue;
        int zongfen;
    };
    struct student student[100000];
    int n,i,max,maxID;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        scanf("%d %d %d",&student[i].ID,&student[i].yuwen,&student[i].shuxue);
    for(i=1;i<=n;i++)
        student[i].zongfen=student[i].yuwen+student[i].shuxue;
    for(int j=1;j<=3;j++)
    {
        maxID=1;
        max=student[1].zongfen;
        for(i=2;i<=n;i++)
            if(student[i].zongfen>max)
            {
                maxID=student[i].ID;
                max=student[i].zongfen;
            }
        printf("%d %d\n",maxID,max);
        student[maxID].zongfen=0;
    }
}


/*
 * ????????.cpp
 *
 *  Created on: 2010-12-24
 *      Author: wangwei
 */
struct student
{
	int id;
	int chinese;
	int math;
	int together;
}stu[100000],t;
int main()
{
	int n,i,j;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>stu[i].id>>stu[i].chinese>>stu[i].math;
		stu[i].together=stu[i].chinese+stu[i].math;
	}
	for(i=0;i<3;i++)
		for(j=i;j<n;j++)
		{
			if(stu[i].together<stu[j].together)
			{
				t=stu[i];
				stu[i]=stu[j];
				stu[j]=t;
			}
		}
			for(i=0;i<3;i++)
			{
				cout<<stu[i].id<<' '<<stu[i].together<<endl;
			}
			return 0;
}


int max=0;

struct student
{ char id[20];
  int chinese;
  int math;
  int sum;
  int flag;
  struct student *next;
};
struct student *h;
int n,i;
struct student *creat()
{
	struct student *head,*p1,*p2;
	i=0;
	p1=p2=(struct student*)malloc(LEN);
	scanf("%s %d %d",p1->id,&p1->chinese,&p1->math);
	p1->sum=p1->chinese+p1->math;
	p1->flag=0;
	head=NULL;
	while(i<n)
	{
		i=i+1;
		if(i==1) head=p1;
		else p2->next=p1;
		p2=p1;
		p1=(struct student*)malloc(LEN);
		scanf("%s %d %d",p1->id,&p1->chinese,&p1->math);
		p1->sum=p1->chinese+p1->math;
		p1->flag=0;
	}
	p2->next=NULL;
	return(head);
}
struct student *compare()
{
	struct student *p1,*p3;
	p1=h;
	max=p1->sum;
    do
	{
		if(p1->sum>max&&(p1->flag==0))
			max=p1->sum;
		p1=p1->next;
	}while(p1->next!=NULL);
	p1=h;
	do
	{
		if (p1->sum==max&&(p1->flag==0))
		{
			p3=p1;
			p1->flag=1;
			break;
		}
		p1=p1->next;
	}while(p1->next!=NULL);
	return(p3);

}
void main()
{   int j;
	struct student *p;
	scanf("%d",&n);
	h=creat();
	for(j=1;j<=3;j++)
	{
		p=compare();
		printf("%s %d\n",p->id,p->sum);
	}
}


int main()
{
	struct student{int id,chin,math,z;}p[100000];
	int id,math,chin,z,i,n,f,s,t,id1,id2,id3;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&id,&chin,&math);
		p[i].id=id;
		p[i].math=math;
		p[i].chin=chin;
	}

	for(i=0;i<n;i++)
	{
		id=p[i].id;
		math=p[i].math;
		chin=p[i].chin;
		z=math+chin;

		if(i==0)
		{
			f=s=t=z;
			id1=id2=id3=id;
		}
		else if(i==1)
		{
			if(z>f)
			{
				t=s;id3=id2;s=f;id2=id1;f=z;id1=id;
			}
			else
			{
				t=s=z;id2=id3=id;
			}
		}
		else
		{
			if(z>f)
			{
				t=s;id3=id2;s=f;id2=id1;f=z;id1=id;
			}
			else if(z>s)
			{
				t=s;id3=id2;s=z;id2=id;
			}
			else if(z>t)
			{
				t=z;id3=id;
			}
		}
	}
	printf("%d %d\n",id1,f);
	printf("%d %d\n",id2,s);
	printf("%d %d\n",id3,t);
	return 0;
}


int main()
{
struct student
{int ID;
int YW;
int SX;
};
struct student stu[100000];
int ZF[100000];
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
        scanf("%d",&stu[i].ID);
        scanf("%d",&stu[i].YW);
        scanf("%d",&stu[i].SX);
        ZF[i]=stu[i].YW+stu[i].SX;
}
int a=0,b=0,c=0,A=0,B=0,C=0;
for(int i=0;i<n;i++)
{
        if(ZF[i]>a)
        {
        c=b;C=B;b=a;B=A;a=ZF[i];A=i;}
        else if(ZF[i]>b)
        {c=b;C=B;b=ZF[i];B=i;}
        else if(ZF[i]>c)
        {c=ZF[i];C=i;}
}
printf("%d %d\n",stu[A].ID,a);
printf("%d %d\n",stu[B].ID,b);
printf("%d %d\n",stu[C].ID,c);
getchar();
getchar();
}


main()
{
struct stdudent
{
       int ID;
       int a;
       int b;
       int c;

       }d[100000];
       int first,second,third;
       int n,i,j;
       int w,h,l;
       int k;
       scanf("%d",&n);
       for(i=0;i<n;i++)
       {
                       scanf("%d %d %d",&d[i].ID,&d[i].a,&d[i].b);
                       d[i].c=d[i].a+d[i].b;

                       }
                       first=0;
                       second=1;
                       third=2;
                       w=d[0].c;
                       h=d[1].c;
                       l=d[2].c;
                       if(w<h&&(h>l))
                       {
                       first=1;
                       if(w>l)
                       {
                       second=0;
                       third=2;
                       }
                       else
                       {
                       second=2;
                       third=0;
                       }
                       }
                       else if(l>w)
                       {
                         first=2;
                         if(w>h)
                         {
                                second=0;
                                third=1;
                                }
                                else
                                third=0;

                        }

                       for(j=3;j<n;j++)
                       {
                       k=d[j].c;
                       w=d[first].c;
                       h=d[second].c;
                       l=d[third].c;
                       if(k>w)
                       {
                       third=second;
                       second=first;
                       first=j;
                       }
                       else if(k>h)
                       {
                            third=second;
                            second=j;
                        }
                        else if(k>l)
                        third=j;
                                       }
printf("%d %d\n",d[first].ID,d[first].c);
printf("%d %d\n",d[second].ID,d[second].c);
printf("%d %d\n",d[third].ID,d[third].c);
  getchar();
  getchar();
      }


struct score
{
	int ID;
	int chinese;
	int math;
};
void main()
{
	int n,i,*sum,max,p=0;
	//struct score s[100000];
	struct score *s;
	scanf("%d",&n);
	s=(struct score *)malloc(sizeof(struct score)*n);
	sum=(int *)malloc(sizeof(int)*n);
	for(i=0;i<n;i++)
		scanf("%d%d%d",&s[i].ID,&s[i].chinese,&s[i].math);
	for(i=0;i<n;i++) *(sum+i)=s[i].chinese+s[i].math;
	max=sum[0];
	for(i=0;i<n;i++)
	{
		if(max<*(sum+i)) {max=*(sum+i);p=i;}
	}
	printf("%d %d\n",s[p].ID,*(sum+p));
	if(n>1)
	{
	    max=*sum;*(sum+p)=0;p=0;
	    for(i=0;i<n;i++)
		{
		    if(max<*(sum+i)) {max=*(sum+i);p=i;}
		}
 	    printf("%d %d\n",s[p].ID,*(sum+p));
		if(n>2)
		{
	        max=*sum;*(sum+p)=0;p=0;
	        for(i=0;i<n;i++)
			{
		        if(max<*(sum+i)) {max=*(sum+i);p=i;}
			}
	        printf("%d %d\n",s[p].ID,*(sum+p));
		}
	}
}


struct stu{
	int a;
	int b;
	int c;
	struct stu *next;
};
void main()
{
	int n,i,j,max;
	struct stu *head,*p1,*p2;
	scanf("%d",&n);
    for(i=0;i<n;i++)
	{
		if(i==0)
		{
			head=p1=p2=(struct stu*)malloc(sizeof(struct stu));
			scanf("%d %d %d",&p1->a,&p1->b,&p1->c);
			head=p1;
			p2=p1;
		}
		else
		{
			p1=(struct stu*)malloc(sizeof(struct stu));
			scanf("%d %d %d",&p1->a,&p1->b,&p1->c);
			p2->next=p1;
			p2=p1;
		}
	}
	p2->next=NULL;

	for(j=0;j<3;j++)
	{
		max=0;
		p1=head;
		for(i=0;p1->next!=NULL;i++)
		{
			if(p1->b+p1->c>max)max=p1->b+p1->c;
			p1=p1->next;
		}
		p1=head;
		for(i=0;p1->next!=NULL;i++)
		{
			if(p1->b+p1->c==max)
			{
				printf("%d %d\n",p1->a,max);
				p1->b=0;
				p1->c=0;
				p1=p1->next;
				break;
			}
			else p1=p1->next;
		}
	}
}


struct student
{
	int num;
	int chinese;
	int maths;
	struct student *next;
};
int n,max0;
struct student *creat(void)
{
	struct student *head,*p1,*p2;
    int i;
	p1=p2=(struct student *)malloc(sizeof(struct student));
	head=p1;
	for(i=1;i<n;i++)
	{
		scanf("%d%d%d",&p1->num,&p1->chinese,&p1->maths);
		p1=(struct student *)malloc(sizeof(struct student));
		p2->next=p1;
		p2=p1;
	}
	scanf("%d%d%d",&p1->num,&p1->chinese,&p1->maths);
	p2->next=p1;
	p1->next=NULL;
	return head;
}
/*struct student *sort(struct student *head)
{
	struct student *p1,*p2,*temp;
	temp=(struct student *)malloc(sizeof(struct student));
	for(p1=head;p1!=NULL;p1=p1->next)
    for(p2=p1->next;p2!=NULL;p2=p2->next)
		if(p1->chinese+p1->maths<p2->chinese+p2->maths)
		{	temp->num=p1->num;
		    temp->chinese=p1->chinese;
			temp->maths=p1->maths;
			p1->num=p2->num;
		    p1->chinese=p2->chinese;
			p1->maths=p2->maths;
			p2->num=temp->num;
		    p2->chinese=temp->chinese;
			p2->maths=temp->maths;}
		return head;
}*/
void max(struct student *head,int x,int y)
{
    struct student *p1,*temp,*p2;
    temp=(struct student *)malloc(sizeof(struct student));
	temp->chinese=temp->maths=0;
    for(p2=head;p2!=NULL;p2=p2->next)
		if(p2->chinese+p2->maths==x)break;
	for(p1=head;p1!=NULL;p1=p1->next)
		if((p1->chinese+p1->maths>temp->chinese+temp->maths)&&(p1->chinese+p1->maths!=x||p1->chinese+p1->maths==x&&p1->num!=p2->num)&&(p1->chinese+p1->maths!=y))
		{
			temp->chinese=p1->chinese;
				temp->maths=p1->maths;
				temp->num=p1->num;
		}
		max0=temp->chinese+temp->maths;
     printf("%d %d\n",temp->num,max0);
}
main()
{
	struct student *head;
	int max1,max2;
	scanf("%d",&n);
    head=creat();
	max(head,0,0);
	max1=max0;
	max(head,max1,0);
	max2=max0;
    max(head,max1,max2);
}


struct person
{
	int num;
	int chinese;
	int math;
	int total;
}student[110000];

int main()
{
	int n, i, max1=0, count1=0, max2=0, count2=0, max3=0, count3=0, number=0, sum=0;
	scanf("%d", &n);
	for(i=0; i<n; i++)
	{
		scanf("%d", &student[i].num);
		scanf("%d", &student[i].chinese);
		scanf("%d", &student[i].math);
	}
	for(i=0; i<n; i++)
	{
		student[i].total=student[i].chinese+student[i].math;
	}
	for(i=n-1; i>=0; i--)
	{
		if(student[i].total>=max1)
		{
			max1=student[i].total;
			count1=i;
		}
	}
	number=student[0].num;
	sum=student[0].total;
	student[0].num=student[count1].num;
	student[0].total=student[count1].total;
	student[count1].num=number;
	student[count1].total=sum;
	number=0;
	sum=0;
	for(i=n-1; i>=1; i--)
	{
		if(student[i].total>=max2)
		{
			max2=student[i].total;
			count2=i;
		}
	}
	number=student[1].num;
	sum=student[1].total;
	student[1].num=student[count2].num;
	student[1].total=student[count2].total;
	student[count2].num=number;
	student[count2].total=sum;
	number=0;
	sum=0;
	for(i=n-1; i>=2; i--)
	{
		if(student[i].total>=max3)
		{
			max3=student[i].total;
			count3=i;
		}
	}
	number=student[2].num;
	sum=student[2].total;
	student[2].num=student[count3].num;
	student[2].total=student[count3].total;
	student[count3].num=number;
	student[count3].total=sum;
	for(i=0; i<3; i++)
	{
		printf("%d %d\n", student[i].num, student[i].total);
	}
	return 0;
}


struct student
{
	int num;
	int yuwen;
	int shuxue;
	struct student *next;
};
int n;
  struct student *creat(int m)
  {
	  struct student *head;
	  struct student *p1,*p2;
	  n=0;
	  p1=p2=(struct student*)malloc(LEN);
	  scanf("%d%d%d",&p1->num,&p1->yuwen,&p1->shuxue);
	  head=NULL;
	  while(m--)
	  {
		  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->yuwen,&p1->shuxue);
	  }
	  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;
		  n=n-1;
	  }
	  return(head);

  }
  void main()
  {
	  struct student *head,*p1,*p2;
	  int max=0,i,m;
	  scanf("%d",&m);
	  printf("\n");
	  head=creat(m);
	  for(i=0;i<3;i++)
	  {
	       p1=p2=head;
		   max=0;
 	       while(p1->next!=NULL)
		   {
	         if((p1->yuwen+p1->shuxue)>max)
		     max=p1->yuwen+p1->shuxue,p2=p1;
		      p1=p1->next;
		   }
	    printf("%d %d\n",p2->num,(p2->yuwen+p2->shuxue));
	    head=del(head,p2->num);
	  }
  }


	typedef struct S{
		int ID;
		int c;
		int m;
		int a;
	}S;

int mycmp(const void*e1,const void*e2){
	return ((S*)e2)->a - ((S*)e1)->a;
}

void main()
{
	struct S stu[100010];
	int i,j,n;
	scanf("%d",&n);
	for (i = 0;i < n;i++){
		scanf("%d%d%d",&(stu + i)->ID,&(stu + i)->c,&(stu + i)->m);
		(stu + i)->a = (stu + i)->c + (stu + i)->m;
	}
	qsort(stu,n,sizeof(*(stu)),mycmp);
	for (i = 0;i <= 2;i++)
		printf("%d %d\n",(stu + i)->ID,(stu + i)->a);
}


struct w
{int id;
int ch;
int ma;
int sum;
struct w *next;
};
int i,n,k=1,max,s=0;
struct w *head,*p1,*p2;
struct w *make(void)
{
	head=null;
	scanf("%d",&n);
	p1=p2=(struct w *)malloc(len);
	scanf("%d %d %d",&p1->id,&p1->ch,&p1->ma);
	for(k=1;k<n;k++)
	{
		if(k==1)head=p1;
		else p2->next=p1;
		p2=p1;
		p1=(struct w *)malloc(len);
		scanf("%d %d %d",&p1->id,&p1->ch,&p1->ma);
	}
	p2->next=p1;//???
	p1->next=head;//????
	return head;
}
void main()
{
	head=make();

	while(s<3)
	{
		for(i=1;i<=n;i++)
		{if(i==n)p1=null;
		else
		{p1->sum=p1->ch+p1->ma;
		p1=p1->next;
		}
		}
       p1=head;max=0;
		for(i=1;i<=n;i++)
		{if((p1->sum)>max)
		max=p1->sum;
		p1=p1->next;
		}
		p1=head;
		for(i=1;i<=n;i++)
		{p2=p1;
                               p1=p1->next;
		if(p1->ch+p1->ma==max)
		{printf("%d %d\n",p1->id,p1->sum);
		if(p1==head)
			head=p1->next;
		else p2->next=p1->next;
		break;}
		}
		s++;
	}
}


struct student
	{
	   int number;

	   int total;
	};
int main()
{

	int n;
	cin>>n;
	struct student a[n];
	int i,j,t;
	for(i=0;i<n;i++)
	{int b,c;
		cin>>a[i].number>>b>>c;
		a[i].total=b+c;
	}

	for(i=0;i<3;i++)
	{
		for(j=i;j<n;j++)
		{
			if(a[j].total>a[i].total)
			{
				t=a[i].total;a[i].total=a[j].total;a[j].total=t;
				t=a[i].number;a[i].number=a[j].number;a[j].number=t;
			}
		}

	}
	for(i=0;i<3;i++)
		cout<<a[i].number<<' '<<a[i].total<<endl;
	return 0;
}


struct student
{int id;
 int chin;
 int math;
 int sum;
}stu[100000];
int main()
{
    int n,i,j,tem,temp;
    scanf("%d",&n);
    for(i=0;i<n;i++){
                     scanf("%d%d%d",&stu[i].id,&stu[i].chin,&stu[i].math);
                     stu[i].sum=stu[i].chin+stu[i].math;
                     }
    int max[3]={0};
    for(i=1;i<n;i++){
                     if(stu[i].sum>stu[max[0]].sum){
                                                   tem=max[0];temp=max[1];
                                                   max[0]=i;max[1]=tem;max[2]=temp;
                     }else{
                           if(stu[i].sum>stu[max[1]].sum){
                                                   tem=max[1];
                                                   max[1]=i;max[2]=tem;
                     }else{
                           if(stu[i].sum>stu[max[2]].sum)
                                                   max[2]=i;}
                     }
                     }

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

    return 0;
}


struct stu
{
	int num;
	int ch;
	int mt;
	int sum;
	struct stu*next;
};

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

	while(n-1)
	{
		p1=(struct stu*)malloc(LEN);
		scanf("%d %d %d",&p1->num,&p1->ch,&p1->mt);
		p1->sum=p1->ch+p1->mt;
		p2->next=p1;
		p2=p1;
		//printf("%d %d %d\n",p1->num,p1->ch,p1->mt,p1->sum);
		n--;
	}
	p2->next=NULL;

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

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

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


struct student
{
	char num[10];
	float a,b,c;
	int t;
	struct student *next;
};
int n;
struct student *head;

struct student *creat()
{
	struct student *p1,*p2;
    int i;
	i=0;
	p1=p2=(struct student *)malloc(len);
	scanf("%s %f %f",&p1->num,&p1->a,&p1->b);
	p1->c=p1->a+p1->b;
	p1->t=0;
	head=null;
	while (i<n-1)
	{
		i++;
		if (i==1) head=p1;
		   else p2->next=p1;
		p2=p1;
		p1=(struct student *)malloc(len);
        scanf("%s %f %f",&p1->num,&p1->a,&p1->b);
		p1->c=p1->a+p1->b;
	    p1->t=0;
	}
    p2->next=p1;
	p1->next=null;
	return(head);
}

void max()
{
	struct student *p1,*p2;
	float mm=0;
	p1=head;
	for (;p1!=null;)
	{
		if (p1->c>mm&&p1->t==0)
		{
			mm=p1->c;
			p2=p1;
		}
		p1=p1->next;
	}
	printf("%s %g\n",p2->num,p2->c);
	p2->t=1;
}

main()
{
	int i,j;
	struct student *p;
	void max();
	scanf("%d",&n);
	creat();
	max();
    max();
	max();
}


struct student
{
	int num;
	int ch;
	int math;
	int total;
	struct student *next;
};
int n;
int t;
struct student *creat(void)
{
	struct student *head;
	struct student *p1,*p2;
	int i;
	scanf("%d",&n);
	head=p1=p2=(struct student*)malloc(LEN);
	scanf("%d%d%d",&p1->num,&p1->ch,&p1->math);
	p1->total=p1->ch+p1->math;
	for (i=2;i<=n;i++)
	{
		p1=(struct student*)malloc(LEN);
		scanf("%d%d%d",&p1->num,&p1->ch,&p1->math);
		p1->total=p1->ch+p1->math;
		p2->next=p1;
		p2=p1;

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

void print(struct student *head)
{
	struct student *p;
	int max;
	p=head;
	max=p->total;
	p=p->next;
	while(p->next!=NULL)
	{
		if(p->total>max)
		{
			max=p->total;
			t=p->num;
		}
		p=p->next;
	}
	printf("%d %d\n",t,max);
}

struct student *del(struct student *head, int a)
{
	struct student *p1,*p2;
	p1=head;
	while (a!=p1->num&&p1->next!=NULL)
	{
		p2=p1;
		p1=p1->next;
	}
	if(p1==head)
	{
		head=p1->next;
	}
	else
	{
		p2->next=p1->next;
	}
	return(head);
}

void main()
{
	struct student *head1,*head2,*head3;
	head1=creat();
	print(head1);
	head2=del(head1,t);
	print(head2);
	head3=del(head2,t);
	print(head3);
}


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


main()
{
      int n;
      int i,j,k,s,p;
      struct student
      {int id;
      int yuwen;
      int shuxue;
      int zongfen;
      };
      struct student stu[100000];
      struct student temp;
      scanf("%d",&n);
      for(p=0;p<n;p++)
      {
          scanf("%d %d %d",&stu[p].id,&stu[p].yuwen,&stu[p].shuxue);
          stu[p].zongfen=stu[p].yuwen+stu[p].shuxue;
      }
      for(j=0;j<3;j++)
      {
          for(i=0;i<n-1-j;i++)
          {
              if(stu[i].zongfen>=stu[i+1].zongfen)
              {
                  temp.id=stu[i].id;
                  temp.yuwen=stu[i].yuwen;
                  temp.shuxue=stu[i].shuxue;
                  temp.zongfen=stu[i].zongfen;
                  stu[i].id=stu[i+1].id;
                  stu[i].yuwen=stu[i+1].yuwen;
                  stu[i].shuxue=stu[i+1].shuxue;
                  stu[i].zongfen=stu[i+1].zongfen;
                  stu[i+1].id=temp.id;
                  stu[i+1].yuwen=temp.yuwen;
                  stu[i+1].shuxue=temp.shuxue;
                  stu[i+1].zongfen=temp.zongfen;
              }
          }
      }
      for(k=n-1;k>n-4;k--)
      {
          printf("%d %d\n",stu[k].id,stu[k].zongfen);
      }
}


struct Student{
		int no;
		int chinese;
		int math;
		int total;
	};
int main()
{
	struct Student stu[100000],t;
	int n,i,j,max,order;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d%d",&stu[i].no,&stu[i].chinese,&stu[i].math);
		stu[i].total=stu[i].chinese+stu[i].math;
	}
	for(i=0;i<3;i++){
		max=stu[i].total;
		order=i;
		for(j=i+1;j<n;j++){
			if(stu[j].total>max){
				max=stu[j].total;
				order=j;
			}
		}
		if(order!=i){
			t=stu[i];stu[i]=stu[order];stu[order]=t;
		}
		printf("%d %d\n",stu[i].no,stu[i].total);
	}
	return 0;
}


int main()
{
	int n,i,j,b,c;
	struct student
	{
		int id;
		int score;
	}stu[100000],t;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>stu[i].id>>b>>c;
		stu[i].score=b+c;
	}
	for(i=0;i<3;i++)
	{
		for(j=n-1;j>i;j--)
		{
			if(stu[j].score>stu[j-1].score)
			{
				t=stu[j];
				stu[j]=stu[j-1];
				stu[j-1]=t;
			}
		}
	}
	for(i=0;i<3;i++)
	{
		cout<<stu[i].id<<' '<<stu[i].score<<endl;
	}
	return 0;
}


struct student
{
	int num ;
	int chinese ;
	int math ;
	int sum ;
}s[100001] , first , second , third ; //??????? ?? ?? ??

int main()
{
	int n , i , temp1 , temp2 ;
	cin >> n ;
	for (i = 0 ; i < n ; i++)
	{
		cin >> s[i].num >> s[i].chinese >> s[i].math ;
		s[i].sum = s[i].chinese + s[i].math ;   //??=?????
	}
	first.sum = 0 , second.sum = 0 , third.sum = 0 ; //???????
	for (i = 0 ; i < n ; i++)
	{
		if (first.sum < s[i].sum)
		{
			first = s[i] ;
			temp1 = i ;     //?????????
		}
	}
	for (i = 0 ; i < n ; i++)
	{
		if (second.sum < s[i].sum && s[i].num != s[temp1].num) //????????????????????????????
		{
			second = s[i];
			temp2 = i ;
		}
	}
	for (i = 0 ; i < n ; i++)
		if (third.sum < s[i].sum && s[i].num != s[temp1].num && s[i].num != s[temp2].num)  //?????
			third = s[i];
	cout << first.num << " " << first.sum << endl ;
	cout << second.num << " " << second.sum << endl ;
	cout << third.num << " " << third.sum << endl ;
	return 0 ;
}


struct student
{
	int num;
	int chn;
	int math;
	int score;
} stu[100000];

main()
{
	int n,i,a,b,c;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d",&stu[i].num,&stu[i].chn,&stu[i].math);
		stu[i].score=stu[i].chn+stu[i].math;
	}

	if(stu[0].score>=stu[1].score){
		if(stu[1].score>=stu[2].score){
			a=0;
			b=1;
			c=2;
		}
		else if(stu[0].score>=stu[2].score){
			a=0;
			b=2;
			c=1;
		}
		else{
			a=2;
			b=0;
			c=1;
		}
	}
	else{
		if(stu[0].score>=stu[2].score){
			a=1;
			b=0;
			c=2;
		}
		else if(stu[1].score>=stu[2].score){
			a=1;
			b=2;
			c=0;
		}
		else{
			a=2;
			b=1;
			c=0;
		}
	}
	for(i=3;i<n;i++){
		if(stu[i].score>stu[a].score){
			c=b;
			b=a;
			a=i;
		}
		else if(stu[i].score>stu[b].score){
			c=b;
			b=i;
		}
		else if(stu[i].score>stu[c].score){
			c=i;
		}
	}

	printf("%d %d\n%d %d\n%d %d\n",stu[a].num,stu[a].score,stu[b].num,stu[b].score,stu[c].num,stu[c].score);
}


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


int main()
{
    struct score
    {
           int ID;
           int c;
           int m;
           };
           int n,k,t,r;
           int j;
           scanf("%d",&n);
           int sum[100000];
           struct score s[100000];
           for(int i=1;i<=n;i++)
           {
                        scanf("%d %d %d",&s[i].ID,&s[i].c,&s[i].m);
                        sum[i]=s[i].c+s[i].m;
                        }
                        for(j=1;j<=3;j++)
                        {
                                         for(k=j;k<=n;k++)
                                         {
                                                            if(sum[k]>sum[j])
                                                            {            t=sum[j];
                                                                         sum[j]=sum[k];
                                                                         sum[k]=t;
                                                                         r=s[j].ID;
                                                                         s[j].ID=s[k].ID;
                                                                         s[k].ID=r;
                                                                         }
                                                                         }
                                                                         }
                                                                         for(int u=1;u<=3;u++)
                                                                         {
                                                                                printf("%d %d\n",s[u].ID,sum[u]);
                                                                                }
                                                                                getchar();
                                                                                getchar();
                                                                                }


struct student
{
	int id;
	int chinese;
	int math;
	int total;
};
int main()
{
	struct student stu[100000];
	struct student max[3]={0,0,0,0,0,0,0,0,0,0,0,0};
	int n,i;
	scanf("%d",&n);
	for (i=0;i<n;i++)
	{
		scanf("%d %d %d\n",&stu[i].id,&stu[i].chinese,&stu[i].math);
		stu[i].total = stu[i].chinese + stu[i].math;
	}
	for (i=0;i<n;i++)
	{
		if (stu[i].total > max[1].total)
		{
			max[1]=stu[i];
		}
	}
	for (i=0;i<n;i++)
	{
		if (stu[i].total > max[2].total && stu[i].total <= max[1].total && stu[i].id!=max[1].id)
		{
			max[2]=stu[i];
		}
	}
	for (i=0;i<n;i++)
	{
		if (stu[i].total > max[3].total && stu[i].total <= max[2].total && stu[i].id!=max[2].id && stu[i].id!=max[1].id)
		{
			max[3]=stu[i];
		}
	}
	for (i=1;i<4;i++)
	{
		printf("%d %d\n",max[i].id,max[i].total);
	}
	return 0;
}


void main()
{
struct student
{
int a;int math;int chi;int sum;struct student*next;
};
int n,i;int max;
struct student *p1,*p2,*head;
scanf("%d",&n);
head=NULL;
for(i=0;i<n;i++)
    {
       if(i==0) head=p1=(struct student*)malloc(LEN);
       else       {
                   p1->next=(struct student*)malloc(LEN);p1=p1->next;
                    }
     scanf("%d%d%d",&p1->a,&p1->math,&p1->chi);
    p1->sum=(p1->math)+(p1->chi);
    }
p1->next=NULL;
for(i=0;i<3;i++)
{
p1=head;max=p1->sum;
do
{p1=p1->next;
if(p1->sum>max) {max=p1->sum;p2=p1;}
}while(p1->next!=NULL);
printf("%d %d\n",p2->a,p2->sum);
p2->sum=0;
}
}


int main (int argc, char *argv[])
{
 int n;
 scanf("%d",&n);
 struct
 { int id;int yuwen;int shuxue;}stu[1000001];
 int grade[100000];
 int i,a,b;
 int m1=0,m2=0,m3=0;
 int m1id,m2id,m3id;
 for(i=0;i<n;i++)
 {
	 scanf("%d",&stu[i].id);
	 scanf("%d",&stu[i].yuwen);
	 scanf("%d",&stu[i].shuxue);
	 grade[i]=stu[i].yuwen+stu[i].shuxue;
 }
 for(i=0;i<n;i++)
 { if(grade[i]>m1)
 {m1=grade[i];
    a=i;
    m1id=stu[i].id;}
 }
 printf("%d ",m1id);
 printf("%d\n",m1);

 for(i=0;i<n;i++)
 { if((grade[i]>m2)&&(i!=a))
 {m2=grade[i];
    b=i;
    m2id=stu[i].id;}
	}
 printf("%d ",m2id);
 printf("%d\n",m2);
 for(i=0;i<n;i++)
 { if((grade[i]>m3)&&(i!=a)&&(i!=b))
 { m3=grade[i];
   m3id=stu[i].id;
 }
 }
 printf("%d ",m3id);
 printf("%d\n",m3);
 return 0;
}


struct Student
{	int num;
	int ch;
	int math;
	int sum;
};
int main()
{
	struct Student stu[4],temp;
	int i,j,k,n;
	scanf("%d",&n);
	for(i=0;i<3;i++)
	{
		scanf("%d %d %d",&stu[i].num,&stu[i].ch,&stu[i].math);
	    stu[i].sum=stu[i].ch+stu[i].math;
	}
	for(i=0;i<2;i++)
	{
		k=i;
		for(j=i+1;j<3;j++)
			if(stu[j].sum>stu[i].sum)
			{k=j;
			temp=stu[k];
			stu[j]=stu[i];
			stu[i]=temp;}
	}
      //  for(i=0;i<3;i++)
		//  printf("%d %d\n",stu[i].num,stu[i].sum);
	for(i=3;i<n;i++)
	{
		scanf("%d %d %d",&stu[3].num,&stu[3].ch,&stu[3].math);
	    stu[3].sum=stu[3].ch+stu[3].math;
		if(stu[3].sum>stu[0].sum)
		{
			stu[2]=stu[1];
			stu[1]=stu[0];
			stu[0]=stu[3];
		}
		else if(stu[3].sum>stu[1].sum)
		{
			stu[2]=stu[1];
			stu[1]=stu[3];
		}
		else if(stu[3].sum>stu[2].sum)
			stu[2]=stu[3];
	}
	for(i=0;i<3;i++)
		printf("%d %d\n",stu[i].num,stu[i].sum);
    return 0;
}


struct stu
{
	int a;
	int b;
	int c;
	int d;
	struct stu *next;
};
int n;
struct stu *creat(void)
{
	struct stu *head,*p1,*p2;
	int i=1;
	head=NULL;
	p2=p1=(struct stu *)malloc(LEN);
	scanf("%d%d%d",&p1->a,&p1->b,&p1->c);
	p1->d=p1->b+p1->c;
	while(1)
	{
		if(i==1)
			head=p1;
		else
			p2->next=p1;
		p2=p1;
		if(i>=n) break;
		p1=(struct stu *)malloc(LEN);
		scanf("%d%d%d",&p1->a,&p1->b,&p1->c);
		p1->d=p1->b+p1->c;
		i++;
	}
	p2->next=NULL;
	return(head);
}
void main()
{
	struct stu *z,*p3,*p[100007],*q;
	int i=0,j,m;
	scanf("%d",&n);
	z=creat();
	p3=p[i]=z;
	while(p3!=NULL)
	{
		i++;
		p[i]=p3->next;
		p3=p[i];
	}
	m=i;
	q=p[0];
	for(i=0;i<4;i++)
	{
		for(j=0;j<m-1-i;j++)
		{
			if(p[j]->d>=p[j+1]->d)
			{
				q=p[j];
				p[j]=p[j+1];
				p[j+1]=q;
			}
		}
	}
	for(i=1;i<4;i++)
	{
	printf("%d %d\n",p[m-i]->a,p[m-i]->d);
	}
}


struct student
{
	int num;
	int all;
}person[99999];
int main()
{
	int n,i,j,k,x,y;;
	struct student temp1,temp2;
	scanf("%d",&n);
	for(i=2;i>=0;i--)
	{
		scanf("%d %d %d",&person[i].num,&x,&y);
		person[i].all=x+y;
	}
	for(i=3;i<=n-1;i++)
	{
		scanf("%d %d %d",&person[i].num,&x,&y);
		person[i].all=x+y;
		k=person[i].all;
		if(k>person[0].all) {temp1=person[0]; temp2=person[1];  person[0]=person[i];person[1]=temp1;person[2]=temp2; continue;}
		if(k<=person[0].all&&k>person[1].all) {temp1=person[1];person[1]=person[i];person[2]=temp1;  continue;}
		if(k<=person[1].all&&k>person[2].all) {person[2]=person[i]; continue;}
		if(k<person[2].all) {continue;}
	}
	printf("%d %d\n",person[0].num,person[0].all);
	printf("%d %d\n",person[1].num,person[1].all);
	printf("%d %d",person[2].num,person[2].all);
	return 0;
}


struct stu
{
       int id;
       int shu;
       int yu;
       int he;
};
struct stu stu[100000];
int main()
{
    int n,i,max,sec,th;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
     scanf("%d%d%d",&stu[i].id,&stu[i].shu,&stu[i].yu);
     stu[i].he=stu[i].shu+stu[i].yu;
     }
     max=1;
     for(i=1;i<n;i++)
     {
       if(stu[max].he<stu[i+1].he)
       max=i+1;
       }
       printf("%d %d\n",stu[max].id,stu[max].he);
        stu[max].he=0;
        sec=1;
     for(i=1;i<n;i++)
      {
         if(stu[sec].he<stu[i+1].he)
         sec=i+1;
         }
          printf("%d %d\n",stu[sec].id,stu[sec].he);
         stu[sec].he=0;
         th=1;
         for(i=1;i<n;i++)
         {
           if(stu[th].he<stu[i+1].he)
           th=i+1;
           }
           printf("%d %d\n",stu[th].id,stu[th].he);
           getchar();
           getchar();
}


int main()
{
	struct Student
	{
		int ID;
		int Chinese;
		int Math;
		int sum;
	}student[100000];
    int i,j,n;
	struct Student t;
	scanf("%d", &n);
    for(i=0;i<n;i++)
		scanf("%d%d%d",&student[i].ID,&student[i].Chinese,&student[i].Math);
	for(i=0;i<3;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if(student[i].Chinese+student[i].Math<student[j].Chinese+student[j].Math)
			{
				t=student[i];
				student[i]=student[j];
				student[j]=t;
			}
		}
    }
	for(i=0;i<3;i++)
	{
		printf("%d %d\n",student[i].ID,student[i].Chinese+student[i].Math);
	}
    return 0;
}


struct student{
	int id;
	int chi;
	int math;
	int total;
	struct student *next;
};
int student_num;

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

void main()
{
	struct student *head,*p;
	int i,n=0,first,second,third,firstid,secondid,thirdid;
	head=creat();
	first=0;
	second=0;
	third=0;
	p=head;
	for(i=1;i<=student_num;i++){
		if (p->total>first){
			third=second;second=first;first=p->total;
			thirdid=secondid;secondid=firstid;firstid=p->id;
		}
		else if (p->total<=first&&p->total>second){
			third=second;second=p->total;
			thirdid=secondid;secondid=p->id;
		}
		else if (p->total<=second&&p->total>third){
			third=p->total;
			thirdid=p->id;
		}
		p=p->next;
	}

	printf("%d %d\n%d %d\n%d %d\n",firstid,first,secondid,second,thirdid,third);

}


int main()
{
	struct student
	{
		char ID[10];
		int m;
		int c;

	}tmp;
    int max1=0,max2=0,max3=0;
	int a1=0,a2=0,a3=0;
	int n,i;

	scanf("%d",&n);

	for(i=1;i<=n;i++)
	{
      scanf("%s %d %d",tmp.ID,&(tmp.m),&(tmp.c));
	  if((tmp.m+tmp.c)>max1)
	{
		max3=max2;
		max2=max1;
		max1=tmp.m+tmp.c;
		a3=a2;
		a2=a1;
		a1=i;
	}
    else if((tmp.m+tmp.c)==max1)
	{
		max3=max2;
		max2=max1;
		max1=tmp.m+tmp.c;
		a3=a2;
		a2=i;
	}
	else if((tmp.m+tmp.c)<max1 && (tmp.m+tmp.c)>max2)
	{
		max3=max2;
		max2=tmp.m+tmp.c;
		a3=a2;
		a2=i;
	}

	else if((tmp.m+tmp.c)==max2)
	{
		max3=max2;
		a3=atoi(tmp.ID);
	}
	else if((tmp.m+tmp.c)<max2 && (tmp.m+tmp.c)>max3)
	{
		max3=tmp.m+tmp.c;
		a3=i;
	}
	}

	printf("%d %d\n",a1,max1);
	printf("%d %d\n",a2,max2);
	printf("%d %d\n",a3,max3);

	return 0;
}


int main(int argc, char* argv[])
{
	struct test {
		int ID,chinese,maths,sum;
	} ss[100000];
	int i,n;
	scanf ("%d",&n);
	for (i=1;i<=n;i++)
	{
		scanf ("%d%d%d",&ss[i].ID,&ss[i].chinese,&ss[i].maths);
		ss[i].sum=ss[i].chinese+ss[i].maths;
	}
	struct score {
		int ID,sum;
	} s[5];
	s[1].sum=0;
	s[2].sum=0;
	s[3].sum=0;
	for (i=0;i<=n;i++)
	{
		if (ss[i].sum>s[1].sum)
		{
			s[3].ID=s[2].ID;
			s[3].sum=s[2].sum;
			s[2].ID=s[1].ID;
			s[2].sum=s[1].sum;
			s[1].ID=ss[i].ID;
			s[1].sum=ss[i].sum;
		}
		else if (ss[i].sum>s[2].sum)
		{
			s[3].ID=s[2].ID;
			s[3].sum=s[2].sum;
			s[2].ID=ss[i].ID;
			s[2].sum=ss[i].sum;
		}
		else if (ss[i].sum>s[3].sum)
		{
			s[3].ID=ss[i].ID;
			s[3].sum=ss[i].sum;
		}
	}
	for (i=1;i<=3;i++)
	{
		printf ("%d %d\n",s[i].ID,s[i].sum);
	}
	return 0;
}


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


struct student
{
       int ID;
       int Chinese;
       int Math;
       int Score;
};
main()
{
      int n,i,first=0,ifirst,second=0,isecond,third=0,ithird;
      scanf("%d",&n);
      struct student STUDENT_NUM[n];
      for(i=0;i<n;i++)
      {
                      scanf("%d %d %d",&STUDENT_NUM[i].ID,&STUDENT_NUM[i].Chinese,&STUDENT_NUM[i].Math);
                      STUDENT_NUM[i].Score=STUDENT_NUM[i].Chinese+STUDENT_NUM[i].Math;
      }
      for(i=0;i<n;i++)
      {
                      if(first<STUDENT_NUM[i].Score)
       {
                                     first=STUDENT_NUM[i].Score;
                                     ifirst=i;
       }
      }
      for(i=0;i<n;i++)
      {
                      if(second<STUDENT_NUM[i].Score&&STUDENT_NUM[i].Score<=first&&i!=ifirst)
                      {
                                     second=STUDENT_NUM[i].Score;
                                     isecond=i;
                      }
      }
      for(i=0;i<n;i++)
      {
                      if(third<STUDENT_NUM[i].Score&&STUDENT_NUM[i].Score<=second&&i!=ifirst&&i!=isecond)
                      {
                                     third=STUDENT_NUM[i].Score;
                                     ithird=i;
                      }
      }
      printf("%d %d\n",STUDENT_NUM[ifirst].ID,first);
      printf("%d %d\n",STUDENT_NUM[isecond].ID,second);
      printf("%d %d\n",STUDENT_NUM[ithird].ID,third);

}


void main()
{
	int n,i,j,max,k;
	struct stu
	{
		int num;
		int chinese;
		int maths;
		int all;
	}stu[100000];
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d%d%d",&stu[i].num,&stu[i].chinese,&stu[i].maths);
	for(i=0;i<n;i++)
		stu[i].all=stu[i].chinese+stu[i].maths;

	for(k=0;k<3;k++)
	{
	    max=stu[0].all;
	    for(i=0;i<n;i++)
		{
		   if(stu[i].all>max)
		   {
			max=stu[i].all;
			j=i;
		   }
		}

	printf("%d %d\n",stu[j].num,stu[j].all);
	stu[j].all=0;
	}
}


struct grade
{
	int num;
	int chinese;
	int math;
	int all;
}stu[100000];
int main()
{
	int n,i,e,f,g,a,b,c;
	e=0;
	f=0;
	g=0;
	a=0;
	b=0;
	c=0;
	scanf("%d",&n);
	for(i=0;i<=n-1;i++){
		scanf("%d%d%d",&stu[i].num,&stu[i].chinese,&stu[i].math);
		stu[i].all=stu[i].chinese+stu[i].math;
	}
	for(i=0;i<=n-1;i++){
		if(stu[i].all>e){
			e=stu[i].all;
			a=i;
		}
	}
	for(i=0;i<=n-1;i++){
		if(stu[i].all<=e&&stu[i].all>f&&i!=a){
			f=stu[i].all;
			b=i;
		}
	}
	for(i=0;i<=n-1;i++){
		if(stu[i].all<=f&&stu[i].all>g&&i!=a&&i!=b){
			g=stu[i].all;
			c=i;
		}
	}
	printf("%d %d\n",stu[a].num,stu[a].all);
	printf("%d %d\n",stu[b].num,stu[b].all);
	printf("%d %d\n",stu[c].num,stu[c].all);
	return 0;
}


void main()
{
	struct student
	{
	long int num;
	int score1;
	int score2;
	};
	struct student stu[100000];
	long int n;
	int i,j,k,m,a=0,b=0,c=0,A,B,C;
	A=B=C=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&stu[i].num,&stu[i].score1,&stu[i].score2);
		k=stu[i].score1+stu[i].score2;
		if(k>c)
		{
			c=k;
			C=stu[i].num;
		}
		if(c>b)
		{
			m=c;
			c=b;
			b=m;
			m=C;
			C=B;
			B=m;
		}
		if(b>a)
		{
			m=b;
			b=a;
			a=m;
			m=B;
			B=A;
			A=m;
		}
	}
	printf("%d %d\n%d %d\n%d %d",A,a,B,b,C,c);
}


struct stu
{
	int num;
	int ch;
	int math;
	int total;
} a[100000];
struct str
{
	int num;
	int total;
} b[100000];

main()
{
	int i,n,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{scanf("%d %d %d\n",&a[i].num,&a[i].ch,&a[i].math);
	b[i].num=a[i].num;
	b[i].total=a[i].ch+a[i].math;}
	for(i=0; i<3; i++)
	{
		for(j=i+1;j<n;j++)
		if (b[i].total<b[j].total)
		{
			b[n]=b[i];
			b[i]=b[j];
			b[j]=b[n];
		}
	}
	for(i=0;i<3;i++)
	printf("%d %d\n",b[i].num,b[i].total);
}


long int n;
struct stu
{
	long int num,chi,mat,tot;
};
int comp(const void *a , const void *b)
{
	return ((struct stu*)b)->tot-((struct stu*)a)->tot;
}
struct stu a[100000],b;
int main()
{
	int i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&a[i].num,&a[i].chi,&a[i].mat);
		a[i].tot=a[i].chi+a[i].mat;
	}
	qsort(a,n,sizeof(struct stu),comp);
	for(i=0;i<3;i++)
	printf("%d %d\n",a[i].num,a[i].tot);
	return 0;
}


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

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

int m;
m=0;
struct student *head;
struct student *p1,*p2;
p1=p2=(struct student *)malloc(len);
scanf("%d %d %d",&p1->num,&p1->chi,&p1->math);
p1->sum=p1->chi+p1->math;
head=p1;
while(m<n-1)
{m=m+1;
p1=(struct student *)malloc(len);
scanf("%d %d %d",&p1->num,&p1->chi,&p1->math);
p1->sum=p1->chi+p1->math;
p2->next=p1;
p2=p1;
}
p2->next=0;

struct student *max,*p;

for(i=0;i<3;i++)
{ max=head;
  p=p2=head;
  p1=p2;
  for(j=0;j<n-i;j++)
  { if(p1->sum>max->sum)
	   {max=p1;
	   p=p2;}
	 p2=p1;
	 p1=p2->next;}
  p1=p2=head;
  printf("%d %d\n",max->num,max->sum);
   if(max->num==head->num)
	   head=p1->next;
   else p->next=max->next;
}

}


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.num=max2.num;
			max3.z=max2.z;
			max2.num=max1.num;
			max2.z=max1.z;
			max1.num=a.num;
			max1.z=a.z;
		}
		else if (a.z>max2.z)
		{
			max3.num=max2.num;
			max3.z=max2.z;
			max2.num=a.num;
			max2.z=a.z;
		}else if (a.z>max3.z)
		{
			max3.num=a.num;
			max3.z=a.z;
		}
	}
	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 yuwen;
    	int math;
    }temp,stu[100050];

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

    	for(i=0;i<n;i++)
    	{
    		scanf("%d %d %d",&stu[i].num,&stu[i].yuwen,&stu[i].math);
    	    stu[i].math=stu[i].yuwen+stu[i].math;
    	}
    	for(i=0;i<3;i++)
    	{
    		k=i;
    		for(j=i+1;j<n;j++)
    		if(stu[j].math>stu[k].math)
    		k=j;
    		temp=stu[k];stu[k]=stu[i];stu[i]=temp;
    	}
    	for(i=0;i<3;i++)
    	printf("%d %d\n",stu[i].num,stu[i].math);
    }


struct student
{
	int num,a,b;
	struct student *next;
};
int n;
struct student *create(void)
{
	struct student *head;
	struct student *p1,*p2;
	int i;
	i=1;
	p1=p2=(struct student*)malloc(LEN);
	scanf("%d %d %d",&p1->num,&p1->a,&p1->b);
	head=NULL;
	while(1)
	{
		if(i==1)
			head=p1;
		else
			p2->next=p1;
		p2=p1;
		if(i==n)
			break;
		p1=(struct student*)malloc(LEN);
		scanf("%d %d %d",&p1->num,&p1->a,&p1->b);
		i++;
	}
	p2->next=NULL;
	return(head);
}
void main()
{
	struct student *head,*h,*x;
	scanf("%d",&n);
	head=create();
	h=x=head;
	int (*p)[2],m,j,s,i;
	p=(int(*)[2])calloc(100000,2*sizeof(int));
	for(i=0;i<n;i++)
	{
		p[i][1]=h->a+h->b;
        p[i][0]=h->num;
		h=x->next;
		x=h;
	}
	for(i=0;i<3;i++)
		for(j=0;j<n-i-1;j++)
			if(p[j][1]>=p[j+1][1])
			{
				m=p[j][1];
				p[j][1]=p[j+1][1];
				p[j+1][1]=m;
                s=p[j][0];
				p[j][0]=p[j+1][0];
				p[j+1][0]=s;
			}
	for(i=n-1;i>n-4;i--)
		printf("%d %d\n",p[i][0],p[i][1]);
}


struct student
{
	int id;
	int chinese;
	int math;
	int sum;
	struct student* next;
};
int n;
struct student *creat()
{
	struct student *head,*p1,*p2;
	p1=p2=(struct student*)malloc(len);
	scanf("%d",&n);
	scanf("%d%d%d",&p1->id,&p1->chinese,&p1->math);
	p1->sum=p1->chinese+p1->math;
	head=NULL;
	for(;p1->id<n;)
	{
		if(p1->id==1) head=p1;
		p1=(struct student*)malloc(len);
		scanf("%d%d%d",&p1->id,&p1->chinese,&p1->math);
		p1->sum=p1->chinese+p1->math;
		p2->next=p1;
		p2=p1;
	}
	p2->next=NULL;
	return(head);
}
void main()
{
	struct student *head,*p1,*p2,*p3,*p;
	head=creat();
	for(p=head,p1=head,p2=head,p3=head;p!=NULL;p=p->next)
	{
		if(p->sum>p1->sum)
		{
			p3=p2;
			p2=p1;
			p1=p;
		}
		else if(p->sum>p2->sum)
		{
			p3=p2;
			p2=p;
		}
		else if(p->sum>p3->sum)
		{
			p3=p;
		}
	}
	printf("%d %d\n",p1->id,p1->sum);
	printf("%d %d\n",p2->id,p2->sum);
	printf("%d %d\n",p3->id,p3->sum);
}


struct student
{char num[10];
 int chinese;
 int math;
 int sum;
 struct student *next;
};
int n;

struct student *creat(int n)
{
	struct student *head,*p1,*p2;
    p1=p2=(struct student *)malloc(LEN);
    scanf("%s %d %d",p1->num,&p1->chinese,&p1->math);
    p1->sum=p1->chinese+p1->math;
    head=NULL;
	int t=n;
while(n>1)
{
	if(n==t) head=p1;
	else p2->next=p1;
	p2=p1;
	p1=(struct student *)malloc(LEN);
	scanf("%s %d %d",p1->num,&p1->chinese,&p1->math);
    p1->sum=p1->chinese+p1->math;
	n--;
}
    p2->next=NULL;
    return(head);
}

void main()
{
	int n,i;struct student *first,*second,*third;
	int fir_index,sec_index,thr_index;
	scanf("%d",&n);struct student *head,*p1;struct student stu;
    head=creat(n);
	first=head;second=head;third=head;
    for(p1=head;p1->next!=NULL;p1=p1->next)
	{
			if(p1->sum>first->sum)
			{
			    third=second;second=first;first=p1;
			}
			else if(p1->sum>second->sum)
			{
                third=second;second=p1;
			}
            else if(p1->sum>third->sum)
			{
                third=p1;
			}
	}
	printf("%s %d\n",first->num,first->sum);
    printf("%s %d\n",second->num,second->sum);
    printf("%s %d\n",third->num,third->sum);
}


struct info
{
	char id[10];
	float ch;
	float ma;
	float tot;
	struct info * next;
};

void main()
{
	struct info * head, * pre, * p,* t;
	int i,j,n;
	scanf("%d",&n);
	head=pre=p=LEN;
	for(i=0;i<2;i++)
	{
		p->tot=0;
		p=LEN;
		pre->next=p;
		pre=p;
	}
	p->tot=0;
	p->next=NULL;
	for(i=0;i<n;i++)
	{
		p=LEN;
		scanf("%s %f %f",p->id,&p->ch,&p->ma);
		p->tot=p->ch+p->ma;
		if(p->tot>head->tot)
		{
			p->next=head;
			head=p;
		}
		else
		{   pre=head;
		     t=head->next;
			for(j=1;j<=2;j++)
			{
			if(p->tot>t->tot)
			{   pre->next=p;
			    p->next=t;break;
			}
			pre=t;
			t=t->next;
			}

		}
	}
	    p=head;
		for(i=0;i<3;i++)
	 {
		 printf("%s %g\n",p->id,p->tot);
		 p=p->next;
	 }

}


int main()
{
	struct student
{
	int idnum,yunum,shunum;
}stu[100000];
	int n,i,max=0,ndmax=0,rdmax=0,l=0;
	scanf("%d",&n);
	int chengji[100000]={0};
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&stu[i].idnum,&stu[i].yunum,&stu[i].shunum);
		chengji[i]=chengji[i]+stu[i].yunum;
		chengji[i]=chengji[i]+stu[i].shunum;
	}
	for(i=0;i<n;i++)
	{
		if(chengji[i]>max)max=chengji[i];
	}
	for(i=0;i<n;i++)
	{
		if(max==(stu[i].yunum+stu[i].shunum))
		{
			l=l+1;
			if(l<=3)printf("%d %d\n",stu[i].idnum,max);
		}
	}
	for(i=0;i<n;i++)
	{
		if((chengji[i]<max)&&(chengji[i]>ndmax))ndmax=chengji[i];
	}
    for(i=0;i<n;i++)
	{
		if(ndmax==(stu[i].yunum+stu[i].shunum))
		{
			l=l+1;
			if(l<=3)printf("%d %d\n",stu[i].idnum,ndmax);
		}
	}
	for(i=0;i<n;i++)
	{
		if((chengji[i]<ndmax)&&(chengji[i]>rdmax))rdmax=chengji[i];
	}
	for(i=0;i<n;i++)
	{
		if(rdmax==(stu[i].yunum+stu[i].shunum))
		{
			l=l+1;
			if(l<=3)printf("%d %d\n",stu[i].idnum,rdmax);
		}
	}
	return 0;
}


int main()
{
    int Student_Num;
    cin>>Student_Num;
//??
    struct A
    {
        int ID;
        int chinese;
        int math;
        int total;
    }student[100000+10],a[3];
//?????
    for(int i=0;i<=Student_Num-1;i++)
    {
        cin>>student[i].ID;
        cin>>student[i].chinese;
        cin>>student[i].math;
        student[i].total=student[i].math+student[i].chinese;
    }
//????
    a[0]=a[1]=a[2]=student[0];
    for(int i=0;i<=Student_Num-1;i++)
    {
        if(student[i].total>a[0].total)a[0]=student[i];
    }
    for(int i=0;i<=Student_Num-1;i++)
    {
        if(student[i].total>a[1].total&&student[i].total<=a[0].total&&student[i].ID!=a[0].ID)a[1]=student[i];
    }
    for(int i=0;i<=Student_Num-1;i++)
    {
        if(student[i].total>a[2].total&&student[i].total<=a[1].total&&student[i].ID!=a[0].ID&&student[i].ID!=a[1].ID)a[2]=student[i];
    }
//??
    for(int i=0;i<=2;i++)
    {
        cout<<a[i].ID<<" "<<a[i].total<<endl;
    }
//??
    return 0;
}


struct stu
{
	int num;
	int ch;
	int ma;
};

int main()
{
	int n,i,j,score[100000],max[2];
	struct stu STU[100000];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&STU[i].num,&STU[i].ch,&STU[i].ma);
		score[i]=STU[i].ch+STU[i].ma;
	}
	for(j=0;j<3;j++)
	{
		for(i=0;i<n;i++)
		{
			if(score[i]>max[1])
			{
				max[0]=STU[i].num;
				max[1]=score[i];
			}
		}
		printf("%d %d\n",max[0],max[1]);
		max[1]=0;
		int temp=max[0];
		score[temp-1]=0;
	}
	return 0;
}


struct Student
{
	int num;
	int chi;
	int math;
	int total;
}person[100000],first[3]={{0,0,0,0},{0,0,0,0},{0,0,0,0}};
int main()
{
	long n;
	int i,j;
	scanf("%ld",&n);

	for(i=0;i<n;i++)
	{
		scanf("%ld%d%d",&person[i].num,&person[i].chi,&person[i].math);
		person[i].total=person[i].chi+person[i].math;
		if(person[i].total>first[0].total){first[1]=first[0];first[0]=person[i];}
		else
			if(person[i].total>first[1].total){first[2]=first[1];first[1]=person[i];}
			else
				if(person[i].total>first[2].total){first[2]=person[i];}
	}
	for(j=0;j<3;j++)
	{
		printf("%ld %d\n",first[j].num,first[j].total);
	}
}


struct stu
{
	long num;
	int score1;
	int score2;
	struct stu *next;
};
struct stu *creat(void)
{
	int n,i=1;
	struct stu *head;
	struct stu *p1,*p2;
	scanf("%d",&n);
	p1=p2=(struct stu*)malloc(len);
	head=NULL;
	while(i<=n)
	{
		scanf("%ld %d %d",&p1->num,&p1->score1,&p1->score2);
		if(i==1)head=p1;
		else p2=p1;
		if(i!=n)p1=p2->next=(struct stu*)malloc(len);
		else p1->next=NULL;
		i++;
	}
	return(head);
}
void turn(struct stu *head)
{
	int t=1,r=1,a;
	struct stu *q1,*q2,*p3,*p1,*p2;
	for(q1=p3=p2=head;q1->next!=NULL,t<=3;t++)
	{
		a=0;
		for(q2=p1=q1->next,r=1;q2!=NULL;q2=q2->next,r++)
		{

			if((q1->score1+q1->score2)<(q2->score1+q2->score2))
			{
		         q1=q2;p2=p1;a=1;
			}
			if(r!=1)p1=p1->next;
		}
		printf("%ld %d\n",q1->num,q1->score1+q1->score2);
		if(a==1)
		{
			p2->next=q1->next;
			q1=head;
		}
		else
		{
			q1=p3->next;
			p3=q1;
		}
	}
}
void main()
{
	struct stu *ip;
	ip=creat();
	turn(ip);
}


struct stu
{
	long num,ch,ma,tot;

	struct stu *next;
};

int main()
{
	int n,numt,cht,mat;
	scanf("%d",&n);
	struct stu *head,*now,*neww,*max;
	int i;
	for (i=1;i<=n;i++)
		{
			neww=(struct stu*) malloc (sizeof(struct stu));
			neww->next=0;
		    if (i==1)
               {head=neww;
                now=neww;}
            else
		       {
                now->next=neww;
                now=neww;
               }
            scanf("%ld %ld %ld",&now->num,&now->ch,&now->ma);
		    now->tot=now->ch  +   now->ma;
		}
  for (i=1;i<=3;i++)
  {
    now=head;
    max=now;
    while (now->next!=0)
          {
              if (max->tot<now->tot) max=now;
              now=now->next;
          }
    printf("%d %d\n",max->num,max->tot);
    max->tot=-1;
  }
  //  scanf("%ld %ld %ld",&now->num,&now->ch,&now->ma);

return 0;
}


int main()
{
	struct stu{
		int chi;
		int ma;
		int sum;
		int i;
	};
	struct stu m[100000],temp;
	int j,n;
	scanf("%d",&n);
	struct stu *p=m;
	struct stu *q;
	for(;p<m+n;p+=1)
	{
		scanf("%d%d%d",&(*p).i,&(*p).chi,&(*p).ma);
		(*p).sum=(*p).chi+(*p).ma;
	}
	for(p=m;p<m+n-1;p++)
	{
		for(q=p+1;q<m+n;q++)
		{
			if((*p).sum < (*q).sum)
			{
				temp=*p;
				*p=*q;
				*q=temp;
			}
		}
		if(p==m+2)
			break;
	}// max is m[0]
	for(p=m;p<m+3;p++)
	{
		printf("%d %d\n",(*p).i,(*p).sum);
	}
	return 0;
}


struct w
{int id;
int ch;
int ma;
int sum;
struct w *next;
struct w *pre;
}*head,*p1,*p2;
int i,n,k=1,max,s=0;
struct w *make(void)
{
	head=null;
	scanf("%d",&n);
	p1=p2=(struct w *)malloc(len);
	scanf("%d %d %d",&p1->id,&p1->ch,&p1->ma);
	for(k=1;k<n;k++)
	{
		if(k==1){head=p1;p1->pre=null;}
		else {p2->next=p1;p1->pre=p2;}
		p2=p1;
		p1=(struct w *)malloc(len);
		scanf("%d %d %d",&p1->id,&p1->ch,&p1->ma);
	}
	p2->next=p1;
	p1->next=head;
	return head;
}
void main()
{
	head=make();max=0;
	while(s<3)
	{
		max=0;
		for(i=1;i<=n;i++)
		{
			if(i==n)p1=null;
		    else
		    {
				p1->sum=p1->ch+p1->ma;
		        p1=p1->next;
		    }
		}
		p1=head;
		for(i=1;i<=n;i++)
		{
			if((p1->sum)>max)
		    max=p1->sum;
		    p1=p1->next;
		}
		p1=head;
		for(i=1;i<=n;i++)
		{
			p2=p1;
			p1=p1->next;
		    if(p2->ch+p2->ma==max)
			{
			    printf("%d %d\n",p2->id,p2->sum);
			    if(p2==head)
			    {
					head=p2->next;
					p2=head;
				}
			else
			{
				p2=p2->pre;
				p1=p1->next;
				p2->next=p1;
			}
			break;
		    }
		}
		s++;
	}
}


struct student
{
    long int id;
    int yuwen;
    int shuxue;
    int total;
    struct student *next;
};
long int n;

int main()
{
    struct student *p0,*p1,*p2,*head,*p;
    int i;
    scanf ("%ld\n",&n);
    p0=(struct student *)malloc(sizeof(struct student));
    scanf ("%ld %d %d",&p0->id,&p0->yuwen,&p0->shuxue);
    p0->total=p0->yuwen+p0->shuxue;
    head=p0;p1=p0;
    p0=(struct student *)malloc(sizeof(struct student));
    scanf ("%ld %d %d",&p0->id,&p0->yuwen,&p0->shuxue);
    p0->total=p0->yuwen+p0->shuxue;
    if (p0->total<=p1->total)
    {
        p1->next=p0;
        p1=p0;
    }
    else
    {
        head=p0;
        p0->next=p1;
    }
    p0=(struct student *)malloc(sizeof(struct student));
    scanf ("%ld %d %d",&p0->id,&p0->yuwen,&p0->shuxue);
    p0->total=p0->yuwen+p0->shuxue;
    if (p0->total<=p1->total)
    {
        p1->next=p0;
        p2=p0;
    }
    else if (p0->total>p1->total&&p0->total<=head->total)
    {
        head->next=p0;
        p0->next=p1;
        p2=p1;
        p1=p0;
    }
    else if (p0->total>head->total)
    {
        p0->next=head;
        p2=p1;p1=head;head=p0;
    }
    p2->next=NULL;
    for (i=3;i<n;i++)
    {
        p0=(struct student *)malloc(sizeof(struct student));
        scanf ("%ld %d %d",&p0->id,&p0->yuwen,&p0->shuxue);
        p0->total=p0->yuwen+p0->shuxue;
        if (p0->total>p2->total)
        {
            if(p0->total<=p1->total)
            {
                p1->next=p0;
                p0->next=NULL;
                p2=p0;
            }
            else if (p0->total>p1->total&&p0->total<=head->total)
            {
                head->next=p0;
                p0->next=p1;
                p1->next=NULL;
                p1=p2;p0=p1;
            }
            else if (p0->total>head->total)
            {
                p0->next=head;
                p1->next=NULL;
                p2=p1;p1=head;head=p0;
            }
        }
    }
    p=head;
    for (i=0;i<3;i++)
    {
        printf("%ld %d\n",p->id,p->total);
        p=p->next;
    }
}


struct student
{
       char num[10];
       int yuwen;
       int shuxue;
       int sum;
};
int main()
{
    int n,i;
    scanf("%d",&n);
    struct student a[100000];
    struct student s[3];
        struct student k;
    for(i=0;i<n;i++)
    {
                    scanf("%s %d %d",a[i].num,&a[i].yuwen,&a[i].shuxue);
                    a[i].sum=a[i].yuwen+a[i].shuxue;
    }
    s[0]=a[0];
    s[1]=a[0];
    s[1].sum=0;
    s[2]=a[0];
    s[2].sum=0;
    for(i=1;i<n;i++)
    {
              if(a[i].sum>s[2].sum&&a[i].sum<=s[1].sum){s[2]=a[i];}
              if(a[i].sum>s[1].sum&&a[i].sum<=s[0].sum){s[2]=s[1];s[1]=a[i];}
              if(a[i].sum>s[0].sum)  {s[2]=s[1];s[1]=s[0];s[0]=a[i];}

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


struct student
{
	int id;
	int math_grade;
	int chi_grade;
	int sum;
}stu[100000];
void main()
{
	int i,j,n,max,temp1,temp2;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&stu[i].id);
		scanf("%d",&stu[i].math_grade);
		scanf("%d",&stu[i].chi_grade);
	}
	for(i=0;i<n;i++)
	stu[i].sum=stu[i].math_grade+stu[i].chi_grade;
	for(i=0;i<3;i++)
	{
		max=stu[i].sum;
		for(j=i+1;j<n;j++)
		{
           if(stu[j].sum>max)
		   {
			   temp1=stu[i].id;
               stu[i].id=stu[j].id;
               stu[j].id=temp1;
			   temp2=stu[i].sum;
               stu[i].sum=stu[j].sum;
               stu[j].sum=temp2;
			   max=stu[i].sum;
		   }
		}
	}
	for(i=0;i<2;i++)
		printf("%d %d\n",stu[i].id,stu[i].sum);
	printf("%d %d",stu[2].id,stu[2].sum);
}


struct student
{
	int num;
	int score1;//????
	int score2;//????
	int total;
};
struct student stu[100000];
int main()
{
   	long i,m;
	scanf("%ld",&m);
	struct student *p=stu;
	for(i=0;i<m;i++,p++)
	{
		scanf("%d%d%d",&(p->num),&(p->score1),&(p->score2));
		p->total=(p->score1+p->score2);
	}
	int max1,max2,max3,a1=0,a2=0,a3=0;
	max1=stu[0].total;
	for(i=0;i<m;i++)
	{
		if(stu[i].total>max1)	{max1=stu[i].total;a1=i;}
	}
	max2=stu[0].total;
	for(i=0;i<m;i++)
	{

		if(stu[i].total>max2&&i!=a1)	{max2=stu[i].total;a2=i;}
	}
	max3=stu[0].total;
	for(i=0;i<m;i++)
	{

		if(stu[i].total>max3&&stu[i].total<max2)	{max3=stu[i].total;a3=i;}
	}
	printf("%d %d\n",stu[a1].num,stu[a1].total);
	printf("%d %d\n",stu[a2].num,stu[a2].total);
	printf("%d %d",stu[a3].num,stu[a3].total);
	return 0;
}


int main()
{
	struct Student
	{
		int num;
		int ch;
		int math;
	}stu[100000];
	int n,i,x=0,m=0,k=0,j,a[100000]={0};
	scanf("%d",&n);
	for(i=0;i<n-1;i++)
	{
		scanf("%d %d %d\n",&stu[i].num,&stu[i].ch,&stu[i].math);
	    a[i]=stu[i].ch+stu[i].math;
	}
	for(j=0;j<3;j++)
	{
		for(i=0;i<n;i++)
	{

	   		if(a[i]>m)
		    {
			m=a[i];
		    x=stu[i].num;
			k=i;
			}

	}
	printf("%d %d\n",x,m);	a[k]=0;
            m=0;x=0;
    }
	return 0;
}


int main (){
    int n, i, k;

    struct stu{
           int id;
           int chn;
           int math;
           int total;
           };
    struct stu a[100001];

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

    for (i=0; i<n; i++){
        scanf ("%d %d %d", &a[i].id, &a[i].chn, &a[i].math);
        (a[i].total)=(a[i].chn)+(a[i].math);
    }

    for (k=1; k<5; k++){
        for (i=0; i<n-k; i++){
            if ((a[i].total)>=(a[i+1].total)){
            a[100000].id=a[i].id;
            a[100000].total=a[i].total;
            a[i].id=a[i+1].id;
            a[i+1].id=a[100000].id;
            a[i].total=a[i+1].total;
            a[i+1].total=a[100000].total;}
        }
    }

    printf("%d %d\n", a[n-1].id, a[n-1].total);
    printf("%d %d\n", a[n-2].id, a[n-2].total);
    printf("%d %d\n", a[n-3].id, a[n-3].total);

    return 0;
    }


struct student
{
	int No;
	int chinese;
	int math;
	int all;
}stu[STUDENT_NUM],temp;

void main()
{
	int n;
	scanf("%d",&n);
	int i,k;
	for(i=0;i<n;i++){
		scanf("%d%d%d",&stu[i].No,&stu[i].chinese,&stu[i].math);
		stu[i].all=stu[i].chinese+stu[i].math;
	}
	for(k=1;k<4;k++){
		for(i=0;i<n-k;i++){
			if(stu[i].all>=stu[i+1].all){
				temp=stu[i+1];
				stu[i+1]=stu[i];
				stu[i]=temp;
			}
		}
	}
	for(i=n-1;i>n-4;i--){
		printf("%d %d\n",stu[i].No,stu[i].all);
	}
}


struct student{
	int num;
	int chinese;
	int math;
};

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

}


struct student
{
	int num;
	int chi;
	int math;
};

int main()
{
	int n,i,e=0,f=0,g=0,a=0,b=0,c=0;
	scanf("%d",&n);
	struct student*stu=(struct student*)malloc(sizeof(int)*3*n);
	int*sz=(int*)malloc(sizeof(int)*n);
    for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&stu[i].num,&stu[i].chi,&stu[i].math);
    	sz[i]=stu[i].chi+stu[i].math;
	}
    for(i=0;i<n;i++)
	{
		if(sz[i]>sz[a])
		{
			a=i;
			e=stu[i].num;
		}
	}
	printf("%d %d\n",e,sz[a]);
    for(i=0;i<n;i++)
	{
		if(i==a)
		{
			continue;
		}
		if(sz[i]>sz[b])
		{
			b=i;
			f=stu[i].num;
		}
	}
	printf("%d %d\n",f,sz[b]);
    for(i=0;i<n;i++)
	{
		if(i==a||i==b)
		{
			continue;
		}
		if(sz[i]>sz[c])
		{
			c=i;
			g=stu[i].num;
		}
	}
    printf("%d %d",g,sz[c]);
	free(sz);
	return 0;
}


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


 struct student
 { int id;
   int a;
   int b;
   int zong;
 };
 struct student ren[100000];

 int main()
 {int n,i,fen,flag=0,j;

  scanf("%d\n",&n);
   for(i=0;i<=n-1;i++)
   { scanf("%d",&ren[i].id);
    scanf("%d",&ren[i].a);
    scanf("%d",&ren[i].b);
    ren[i].zong=ren[i].a+ren[i].b;
   }

   for(fen=200;fen>=100;fen--)
   { for(i=0;i<=n-1;i++)
      if(fen==ren[i].zong)
      {printf("%d %d\n",ren[i].id,ren[i].zong);
       flag=flag+1;
       if(flag==3)goto end;

      }
      }
      end:
  getchar();

}


struct student
{
	char id[10];
	int ch;
	int ma;
};

int main(int argc, char* argv[])
{
	int n,i,max,sec,min,total[100000];
	scanf("%d",&n);
	struct student stu[100000];
	for(i=0;i<n;i++)
	{
		scanf("%s%d%d",stu[i].id, &stu[i].ch, &stu[i].ma);
		total[i]=stu[i].ch + stu[i].ma;
	}

	max = 0;

	for(i=0;i<n;i++)
	{
		if(total[i]>total[max])
			max = i;
	}

    printf("%s %d\n",stu[max].id, total[max]);

	for(i=0;i<n;i++)
	{
		if(total[i]==total[max])
		{
			total[i]=0;
			break;
		}
	}

	sec = 0;
	for(i=0;i<n;i++)
	{
		if(total[i]>total[sec])
			sec=i;
	}

	printf("%s %d\n", stu[sec].id, total[sec]);

	for(i=0;i<n;i++)
	{
		if(total[i]==total[sec])
		{
			total[i]=0;
			break;
		}
	}

	min = 0;
	for(i=0;i<n;i++)
	{
		if(total[i]>total[min])
			min=i;
	}

	printf("%s %d\n", stu[min].id, total[min]);
	return 0;
}


struct stu
{int num;
 int score1;
 int score2;
}stu[100000];
void main()
{
	int i,j,n,a[100000],max;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&stu[i].num,&stu[i].score1,&stu[i].score2);
		a[i]=stu[i].score1+stu[i].score2;
	}
	for(j=0;j<3;j++)
	{
     max=0;
	 for(i=0;i<n;i++)
	 	max=(max>=a[i])?max:a[i];
	 for(i=0;i<n;i++)
	    if(a[i]==max)
		{printf("%d %d\n",stu[i].num,a[i]);
	     a[i]=0;
  	     break;
		}
	}
}


struct stu
{
	int id;
	int sum;
	struct stu *next;
};

void main()
{
	struct stu *head,*p1,*p2,*p0;
	int n,i,ch,ma,len;
	scanf("%d",&n);
	len = sizeof (struct stu);

	p1 = p2 = (struct stu*)malloc(len);

	head = p1;
	scanf("%d%d%d",&p1->id,&ch,&ma);
	p1->sum = ch + ma;
	p1->next = 0;

	for (i=2;i<=n;i++)
	{
        p0 = (struct stu*)malloc(len);
		scanf("%d %d %d",&p0->id,&ch,&ma);
		p0->sum = ch + ma;

		p1=p2=head;
		while ( (p0->sum <= p1->sum) && (p1->next != 0) )
		{
			p2 = p1;
			p1 = p1->next;
		}
		if (p0->sum > p1->sum)
		{
			if (head == p1)
				head = p0;
			else p2->next = p0;
			p0->next = p1;
		}
		else
		{
			p1->next = p0;
			p0->next = 0;
		}
		if (i>3)
		{
			p1 = head->next;
			p1 = p1->next;
			p1->next = 0;
		}
	}
	p1 = head;
	while (p1!=0)
	{
    	printf("%d %d\n",p1->id,p1->sum);
		p1 = p1->next;
	}
}


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


struct Student
{
	int id;
	int c;
	int m;
	int sum;
};
void main()
{
	struct Student temp,s1,s2,s3;
	int i,n;
	s1.sum=s2.sum=s3.sum=-1;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&temp.id,&temp.c,&temp.m);
		temp.sum=temp.c+temp.m;
		if(temp.sum>s1.sum)
		{
			s3=s2;
			s2=s1;
			s1=temp;
		}
		else if (temp.sum>s2.sum)
		{
			s3=s2;
			s2=temp;
		}
		else if(temp.sum>s3.sum)
		{
			s3=temp;
		}
	}
	printf("%d %d\n%d %d\n%d %d\n",s1.id,s1.sum,s2.id,s2.sum,s3.id,s3.sum);
}


int main(){
	int n,i,max1=0,num1=0,max2=0,num2=0,max3=0,num3=0;
	struct stu{
		int num;
		int chn;
		int mat;
		int sum;
	}sco[100000];
	cin>>n;
	for(i=0;i<n;i++){
		cin>>sco[i].num>>sco[i].chn>>sco[i].mat;
		sco[i].sum=sco[i].chn+sco[i].mat;
	}
	for(i=0;i<n;i++){
		if(sco[i].sum>max1){
			max3=max2;
			num3=num2;
			max2=max1;
			num2=num1;
			max1=sco[i].sum;
			num1=i;

		}
		else{
			if(sco[i].sum>max2){
						max3=max2;
						num3=num2;
						max2=sco[i].sum;
						num2=i;
						}
			else {
				if(sco[i].sum>max3){
							max3=sco[i].sum;
							num3=i;
						}
			}
	}
	}
		cout<<num1+1<<' '<<max1<<endl;
		cout<<num2+1<<' '<<max2<<endl;
		cout<<num3+1<<' '<<max3<<endl;
	return 0;
}


struct grade
{
    int No;
	int chinese;
	int math;
	int sum;
}student[100000],s;
int main()
{
	int n,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++){
	scanf("%d %d %d",&student[i].No,&student[i].chinese,&student[i].math);
    student[i].sum=student[i].chinese+student[i].math;
	}
    for(i=0;i<3;i++){
		for(j=i+1;j<n;j++){
			if(student[i].sum<student[j].sum){
			    s=student[i];
				student[i]=student[j];
				student[j]=s;
			}
		}
	}
	for(i=0;i<3;i++){
	printf("%d %d\n",student[i].No,student[i].sum);
	}
    return 0;
}


int main()
{
    int n;
    scanf ("%d",&n);
    struct student
    {
        int num;
        int chinese;
        int maths;
    };
    struct student a[100000],temp;
    int i,b[100000]={0};
    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;
}


struct data
{
	long int num;
	int point1;
	int point2;
	int sum;
	struct data*next;
};
struct data*creat(long int n)
{
	long int i=0;
	struct data*p1,*p2,*head;
	p1=p2=(struct data*)malloc(sizeof(struct data));
	scanf("%ld %d %d",&p1->num,&p1->point1,&p1->point2);
	p1->sum=p1->point1+p1->point2;
	head=NULL;
	while(i<n)
	{
		i=i+1;
		if(i==1) head=p1;
		else p2->next=p1;
		p2=p1;
		p1=(struct data*)malloc(sizeof(struct data));
		scanf("%ld %d %d",&p1->num,&p1->point1,&p1->point2);
		p1->sum=p1->point1+p1->point2;
	}
	p2->next=NULL;
	return(head);
}
struct data*max(struct data*head)
{
	struct data *p1,*max;
	max=head;
	p1=head;
	do
	{
		if(p1->sum>max->sum) max=p1;
		p1=p1->next;
	}while(p1!=NULL);
	return(max);
}
struct data*del(struct data*head,struct data*max)
{
	struct data *p1,*p2;
	p1=head;
	while(max!=p1)
	{
		p2=p1;
		p1=p1->next;
	}
	if(p1==head)
		head=p1->next;
	else
	{
		p2->next=p1->next;
	}
	return(head);
}
void main()
{
	struct data*a,*b,*c,*head;
	long int n;
	scanf("%ld",&n);
	head=creat(n);
	a=max(head);
	printf("%ld %d\n",a->num,a->sum);
	head=del(head,a);
	b=max(head);
	printf("%ld %d\n",b->num,b->sum);
	c=max(del(head,b));
	printf("%ld %d\n",c->num,c->sum);
}


typedef struct
{
	int ID;
	int chinese;
	int math;
	int sum;
}Student;

Student topThree[3];
int studentNum;

void initialise()
{
	for(int i = 0; i < 3; i ++)
	{
		topThree[i].sum = -1;
	}
}

void updateTopThree(Student stu)
{
	for(int i = 0; i < 3; i ++)
	{
		if(stu.sum > topThree[i].sum)
		{
			for(int j = 2; j > i; j --)
			{
				topThree[j] = topThree[j-1];
			}

			topThree[i] = stu;

			break;
		}
	}
}

void getStudentData()
{
	Student temp;

	scanf("%d", &studentNum);
	for(int i = 0; i < studentNum; i ++)
	{
		scanf("%d %d %d", &temp.ID, &temp.chinese, &temp.math);
		temp.sum = temp.chinese + temp.math;
		updateTopThree(temp);
	}
}

void printStudentData()
{
	for(int i = 0; i < 3 && i < studentNum; i ++)
	{
		printf("%d %d\n", topThree[i].ID, topThree[i].sum);
	}
}

int main()
{
	initialise();
	getStudentData();
	printStudentData();

	return 0;
}


struct Student
{
	int num;
	int chn;
	int mth;
	int sum;
};
struct Scr
{
	int num;
	int sum;
};

int main()
{
	struct  Student stu[100000];
	struct  Scr  scr[3];
	int n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&stu[i].num,&stu[i].chn,&stu[i].mth);
		stu[i].sum=stu[i].chn+stu[i].mth;
	}
	scr[0].num=stu[0].num;
	scr[0].num=stu[0].num;
	for(i=1;i<n;i++)
    {
        if(stu[i].sum>scr[0].sum)
		{
			scr[0].num=stu[i].num;
			scr[0].sum=stu[i].sum;
		}
    }
	scr[1].num=stu[0].num;
	scr[1].num=stu[0].num;
	for(i=1;i<n;i++)
    {
		if(i!=scr[0].num-1)
		{
			if(stu[i].sum>scr[1].sum)
			{
				scr[1].num=stu[i].num;
				scr[1].sum=stu[i].sum;
			}
		}
    }
	scr[2].num=stu[0].num;
	scr[2].num=stu[0].num;
	for(i=1;i<n;i++)
    {
		if(i==scr[0].num-1||i==scr[1].num-1)
			continue;
		else
		{
			if(stu[i].sum>scr[2].sum)
			{
				scr[2].num=stu[i].num;
				scr[2].sum=stu[i].sum;
			}
		}
    }
	for(i=0;i<3;i++)
	{
		printf("%d %d\n",scr[i].num,scr[i].sum);
	}
	return  0;
}


struct stu
{
	int num;
	int chi;
	int math;
	int s;
	struct stu *next;
};
struct stu *creat(int n)
{
	int i;
	struct stu *head;
	struct stu *p1,*p2;
	p1=p2=(struct stu *)malloc(LEN);
	scanf("%d %d %d",&p1->num,&p1->chi,&p1->math);
	head=p1;
	for(i=1;i<n;i++)
	{
	    p1=(struct stu*)malloc(sizeof(struct stu));
		scanf("%d %d %d",&p1->num,&p1->chi,&p1->math);
		p2->next=p1;
		p2=p1;
	}
	p2->next=NULL;
	return (head);
}
void main()
{
	int i,n,t,m;
	struct stu *head,*p1,*p2;
	scanf("%d",&n);
	head=creat(n);
	p1=head;
	for(i=0;i<n;i++)
	{
		p1->s=p1->chi+p1->math;
		p1=p1->next;
	}
	p1=head;
	p2=p1->next;
	for(i=0;i<3;i++)
	{
		while(p2!=NULL)
		{
			if(p2->s>p1->s)
			{
				t=p2->s;
				p2->s=p1->s;
				p1->s=t;
				m=p2->num;
				p2->num=p1->num;
				p1->num=m;
			}p2=p2->next;
		}printf("%d %d\n",p1->num,p1->s);
		if(i==2)break;
		p1=p1->next;p2=p1->next;
	}
}


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

int main()
{
	int n;
	scanf("%d",&n);
	struct student *stu=(struct student *)malloc(sizeof(int)*4*n);
	int i;
	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++){
		stu[i].total=stu[i].chinese+stu[i].math;
	}

	int t_1,t_2;
	int j,k;
	for(k=1;k<4;k++){
		for(j=0;j<n-k;j++){
			if(stu[j].total>=stu[j+1].total){
		    	         t_1=stu[j+1].total;
			         stu[j+1].total=stu[j].total;
			         stu[j].total=t_1;
				t_2=stu[j+1].num;
				stu[j+1].num=stu[j].num;
				stu[j].num=t_2;
			}
		}
	}

	for(i=n-1;i>n-4;i--){
		printf("%d %d\n",stu[i].num,stu[i].total);
	}

    return 0;
}


struct student
{
	long int num;
	int Chinese;
	int Maths;
	int total;
};
void main()
{
	struct student stu[100000];
	struct student tempt;
	int n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d",&stu[i].num,&stu[i].Chinese,&stu[i].Maths);
		stu[i].total=stu[i].Chinese+stu[i].Maths;
	}
	if(stu[2].total>stu[1].total){
		tempt=stu[1];
		stu[1]=stu[2];
		stu[2]=tempt;
	}
	if(stu[1].total>stu[0].total){
		tempt=stu[0];
		stu[0]=stu[1];
		stu[1]=tempt;
	}
    if(stu[2].total>stu[1].total){
		tempt=stu[1];
		stu[1]=stu[2];
		stu[2]=tempt;
	}
	for(i=3;i<n;i++){
		if(stu[i].total>stu[2].total){
			stu[2]=stu[i];
			if(stu[2].total>stu[1].total){
				tempt=stu[1];
			    stu[1]=stu[2];
		        stu[2]=tempt;
				if(stu[1].total>stu[0].total){
					tempt=stu[0];
		            stu[0]=stu[1];
	                stu[1]=tempt;
				}
			}
		}
	}
	printf("%d %d\n",stu[0].num,stu[0].total);
	printf("%d %d\n",stu[1].num,stu[1].total);
	printf("%d %d\n",stu[2].num,stu[2].total);
}