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

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

int main()
{
	int n,i,temp=0,sum[100000];
	struct stu p;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%ld %d %d",&p.num[i],&p.y[i],&p.m[i]);
		sum[i]=p.m[i]+p.y[i];
	}
	for(i=0;i<n-1;i++){
		if(sum[i]>=sum[i+1]){
			temp=sum[i+1];
			sum[i+1]=sum[i];
			sum[i]=temp;
			temp=p.num[i+1];
			p.num[i+1]=p.num[i];
			p.num[i]=temp;
		}
	}
	printf("%ld %d\n",p.num[n-1],sum[n-1]);
	for(i=0;i<n-2;i++){
		if(sum[i]>=sum[i+1]){
			temp=sum[i+1];
			sum[i+1]=sum[i];
			sum[i]=temp;
			temp=p.num[i+1];
			p.num[i+1]=p.num[i];
			p.num[i]=temp;
		}
	}
	printf("%ld %d\n",p.num[n-2],sum[n-2]);
	for(i=0;i<n-3;i++){
		if(sum[i]>=sum[i+1]){
			temp=sum[i+1];
			sum[i+1]=sum[i];
			sum[i]=temp;
			temp=p.num[i+1];
			p.num[i+1]=p.num[i];
			p.num[i]=temp;
		}
	}
	printf("%ld %d\n",p.num[n-3],sum[n-3]);
	return 0;
}
void main()
{
	int i,j,k,m,n,max;
	struct stu
	{
		int xh;
		int yw;
		int sx;
		int zf;
		struct stu *next;
	};
	struct stu *p1,*p2,*head;
	scanf("%d",&n);
	p2=head=p1=(struct stu *)malloc(sizeof(struct stu));
	scanf("%d %d %d",&p1->xh,&p1->yw,&p1->sx);
	p1->zf=p1->yw+p1->sx;
	for(i=1;i<n;i++)
	{
		p1=(struct stu *)malloc(sizeof(struct stu));
		scanf("%d %d %d",&p1->xh,&p1->yw,&p1->sx);
		p1->zf=p1->yw+p1->sx;
		p2->next=p1;
		p2=p1;
	}
	for(j=0;j<3;j++)
	{
		p1=head;
		max=0;
		for(i=0;i<n;i++)
		{
			max=max>p1->zf?max:p1->zf;
			p1=p1->next;
		}
		p1=head;
		for(i=0;i<n;i++)
		{
			if(max==p1->zf)
			{
				printf("%d %d\n",p1->xh,p1->zf);
				p1->zf=0;
				break;
			}
			p1=p1->next;
		}
	}
}
int main(int argc, char* argv[])
{
	struct student{
		int ID,Ch,Ma;
	}temp;
    int fID=0,fG=0,sID=0,sG=0,tID=0,tG=0;
	int n;
	scanf("%d",&n);
	int i;
	for(i=0;i<n;i++)
	{
		int sum=0;
		scanf("%d%d%d",&temp.ID,&temp.Ch,&temp.Ma);
        sum=temp.Ch+temp.Ma;
        if(sum==fG)
		{
            tG=sG;
			tID=sID;
			sG=sum;
			sID=temp.ID;
		}
		if(sum>fG)
		{
			tG=sG;
			tID=sID;
			sG=fG;
			sID=fID;
			fG=sum;
			fID=temp.ID;
		}
		if(sum<fG&&sum>sG)
		{
			tG=sG;
			tID=sID;
			sG=sum;
			sID=temp.ID;
		}	
		if(sum<sG&&sum>tG)
		{
			tG=sum;
			tID=temp.ID;
		}
	}
	printf("%d %d\n",fID,fG);
	printf("%d %d\n",sID,sG);
	printf("%d %d\n",tID,tG);

	return 0;
}
struct student
{int nn;
int nnn;
int nmn;
int sum;
}st[100002],tmp;
int main()
{int i,j,m,n;
scanf("%d",&n);
for(i=1;i<=n;i++)
{scanf("%d %d %d",&st[i].nn,&st[i].nnn,&st[i].nmn);
st[i].sum=st[i].nnn+st[i].nmn;
}
for(i=1;i<=3;i++)
  {for(j=i+1;j<=n;j++)
      {if(st[i].sum<st[j].sum)
      {tmp=st[i];
  st[i]=st[j];
  st[j]=tmp;
		}
		
	   }
  }
  for(i=1;i<=3;i++)
  {printf("%d %d",st[i].nn,st[i].sum);
  if(i<3)
  printf("\n");
		}
  return 0;
}
struct student{
	int ID;
	int yw;
	int sx;
	} stu[100000];//??????
int main(){
	int num,i,j,sum[100000],t,m;
	cin>>num;
	for(i=1;i<=num;i++){
		cin>>stu[i].ID>>stu[i].yw>>stu[i].sx;
	sum[i]=stu[i].yw+stu[i].sx;
}//?????????
for(i=1;i<4;i++){
	for(j=num;j>1;j--){
		if(sum[j]>sum[j-1]){
			t=sum[j-1];m=stu[j-1].ID;
			sum[j-1]=sum[j];stu[j-1].ID=stu[j].ID;
			sum[j]=t;stu[j].ID=m;
		}
	}
}//????
for(i=1;i<4;i++){
	cout<<stu[i].ID<<' '<<sum[i]<<endl;}
return 0;
}//????
struct student
	{
		int num;
		int chinese;
		int math;
		int total;
	}a[100000];
int main()
{
	int n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&a[i].num,&a[i].chinese,&a[i].math);
		a[i].total=a[i].chinese+a[i].math;
	}
	int max,numm;
	max=a[1].total;
	for(int j=0;j<3;j++)
	{
	for(i=0;i<n;i++)
	{
		if(max<a[i].total)
		{
			max=a[i].total;
			numm=i;
		}
	}
		printf("%d %d\n",numm+1,max);
		a[numm].total=0;
		max=0;
	}
	return 0;
}
int first[3],firsti[3];
struct stu
{
	int num;
	int chinese;
	int math;
	int sum;
	struct stu *next;
	
}	*p1,*p2;
struct stu *creat(int n)
{  struct stu *head=NULL;
   p1=p2=(struct stu*)malloc(sizeof(struct stu));
   while (n--)
   {   scanf("%d %d %d",&p1->num,&p1->chinese,&p1->math);
       if(head==NULL) head=p1;
	   else p2->next=p1;
	   p2=p1;
       p1=(struct stu*)malloc(sizeof(struct stu));
	   
   }
   p2->next=NULL;
return(head);
}
struct stu *sum(struct stu *head,int n)
{  p1=head;
	while(n--)
	{p1->sum=p1->chinese+p1->math;
	p1=p1->next;
	}
	return(head);
}

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

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

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

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

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

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

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

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

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




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

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

		}
	}
	for(i=0;i<3;i++)
		printf("%d %d\n",form[i].num,form[i].sum);
	return 0;
}
void main()
{
     struct student
    {
       int ID;
       int math;
       int chinese;
       int sum;
    };
     int n,i,t,j;
     scanf("%d",&n);
     struct student stu[n];
     for(i=0;i<n;i++)
        scanf("%d %d %d",&stu[i].ID,&stu[i].math,&stu[i].chinese);
     for(i=0;i<n;i++)
        stu[i].sum=stu[i].math+stu[i].chinese;
     for(i=0;i<3;i++)
     {  for(j=i+1;j<n;j++)
          
           if(stu[j].sum>stu[i].sum)
           {t=stu[i].sum;stu[i].sum=stu[j].sum;stu[j].sum=t;
            t=stu[i].ID;stu[i].ID=stu[j].ID;stu[j].ID=t;}
           
       }
     for(i=0;i<3;i++)
     printf("%d %d\n",stu[i].ID,stu[i].sum);
  
}
void main()
{
	int n;
	scanf("%d",&n);
	struct student
	{
		int num;
		int score_1;
		int score_2;
		int sum;
	};
	struct student stu[n];
	int i,j,t;
	for(i=0;i<n;i++)
	{
	    scanf("%d %d %d",&stu[i].num,&stu[i].score_1,&stu[i].score_2);
	    stu[i].sum=stu[i].score_1+stu[i].score_2;
	}
	for(j=0;j<=2;j++)
	{
		for(i=n-1;i>0+j;i--)
		if(stu[i].sum>stu[i-1].sum)
		{
		    t=stu[i].sum,stu[i].sum=stu[i-1].sum,stu[i-1].sum=t;
			t=stu[i].num,stu[i].num=stu[i-1].num,stu[i-1].num=t;
		}
	}
	for(i=0;i<=2;i++)
	printf("%d %d\n",stu[i].num,stu[i].sum);
}
struct person
{
	char num[6];
	int Chinese;
	int math;
	int total;
}stu[100000];

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

	}
	for (j = 0; j < 3; j++)
	{
		max = 0;
		for (i = 0; i < n; i++)
		{
			if (stu[i].total > max)
			{
				max = stu[i].total;
				k = i;
			}	
		}
		cout << stu[k].num << " " << stu[k].total << endl;
		stu[k].total = 0;
	}
	return 0;
}
struct xue
{
	int ID;
	int sx;
	int yw;
	int sum;
}xueshen;

int main()
{
	int n,i,k;
	scanf("%d",&n);
	struct xue *xuesheng;
    xuesheng=(struct xue*)malloc(4*sizeof(int)*n);
	for (i=0;i<n;i++){
		scanf("%d%d%d",&xuesheng[i].ID,&xuesheng[i].sx,&xuesheng[i].yw);
		xuesheng[i].sum=xuesheng[i].sx+xuesheng[i].yw;
	}
	for (i=1;i<4;i++){
		for(k=0;k<n-i;k++){
			if(xuesheng[k].sum>=xuesheng[k+1].sum){
				xueshen=xuesheng[k+1];
				xuesheng[k+1]=xuesheng[k];
				xuesheng[k]=xueshen;
			}
		}
	}
	for (i=1;i<4;i++){
		printf("%d %d\n",xuesheng[n-i].ID,xuesheng[n-i].sum);
	}
	return 0;
}
struct mark
{
	int num;
	int ch;
	int math;
	int sum;
}stu[100000];
int main(int argc, char* argv[])
{
	int i,n;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d",&stu[i].num,&stu[i].ch,&stu[i].math);
		stu[i].sum=stu[i].math+stu[i].ch;
	}
	for(i=0;i<n-1;i++){
		if(stu[i].sum>=stu[i+1].sum){
			stu[100000]=stu[i];
			stu[i]=stu[i+1];
			stu[i+1]=stu[100000];
		}
	}
	for(i=0;i<n-2;i++){
		if(stu[i].sum>=stu[i+1].sum){
			stu[100000]=stu[i];
			stu[i]=stu[i+1];
			stu[i+1]=stu[100000];
		}
	}
	for(i=0;i<n-3;i++){
		if(stu[i].sum>=stu[i+1].sum){
			stu[100000]=stu[i];
			stu[i]=stu[i+1];
			stu[i+1]=stu[100000];
		}
	}
	printf("%d %d\n%d %d\n%d %d\n",stu[n-1].num,stu[n-1].sum,stu[n-2].num,stu[n-2].sum,stu[n-3].num,stu[n-3].sum);
	return 0;
}
struct student
{
       long int ID;
       int math;
       int chinese;
       int add;
}stu[100000];       
main()
{
      long int n;
      int i,j;
      scanf("%d",&n);
      for(i=0;i<n;i++)
      {
        scanf("%d %d %d",&stu[i].ID,&stu[i].math,&stu[i].chinese);
        stu[i].add=stu[i].math+stu[i].chinese;
      }
      for(i=0;i<3;i++)
      {
         for(j=i+1;j<n;j++)
         {
             if(stu[i].add<stu[j].add)
             {
                 int t=stu[i].add;
                 stu[i].add=stu[j].add;
                 stu[j].add=t;
                 long int m=stu[i].ID;
                 stu[i].ID=stu[j].ID;
                 stu[j].ID=m;
             }
         }
         printf("%d %d\n",stu[i].ID,stu[i].add);
      }
      getchar();
      getchar();
}
struct data
{
	int id;
	int cs;
	int ms;
	int s;
};
int cmp(const void *a,const void *b)
{
    return ((struct data*)b)->s - ((struct data*)a)->s;
}
main()
{
	struct data *a;
	int n;
	int i;
	scanf("%d",&n);
	a=(struct data *)malloc(n*sizeof(struct data));
	for (i=0;i<n;i++)
	{
		scanf("%d %d %d",&a[i].id,&a[i].cs,&a[i].ms);
		a[i].s=a[i].cs+a[i].ms;
	}
    qsort(a,n,sizeof(struct data),cmp);
	for (i=0;i<3;i++)
		printf("%d %d\n",a[i].id,a[i].s);
	free(a);
}
int main(int argc, char* argv[])
{
	int a=0,b=0,c=0;
	int an,bn,cn;
	int n,i,sum=0;
	struct student{
		int num,ch,math;
	}students[100000];
	scanf("%d",&n);
	for (i=0; i<n; i++){
		scanf("%d%d%d",&students[i].num, &students[i].ch, &students[i].math);
		sum = students[i].ch + students[i].math;
		if (sum > c){
			c = sum;
			cn = i;
		}
		if (sum > b){
			c = b;
			cn = bn;
			b = sum;
			bn = i;

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






		 
	return 0;
}
struct score
{
	int num;
	int yuwen;
	int shuxue;
}student[100000];
int max(int a,int b)
{
	return (a>b)?a:b;
}
int min(int a,int b)
{
	return (a<b)?a:b;
}
int main()
{
	int max(int a,int b);
	int total[100000];
	int n,i;
	int max1=0,max2=0,max3=0;
	int maxnum1=0,maxnum2=0,maxnum3=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&student[i].num);
		scanf("%d",&student[i].yuwen);
		scanf("%d",&student[i].shuxue);
		total[i]=student[i].yuwen+student[i].shuxue;
		if(total[i]>=max1){
			if(total[i]==max1){
				max3=max2;
				max2=max1;
				max1=total[i];
				maxnum3=maxnum2;
				maxnum2=max(maxnum1,i+1);
				maxnum1=min(maxnum1,i+1);
			}
			else{
				max3=max2;
				max2=max1;
				max1=total[i];
				maxnum3=maxnum2;
				maxnum2=maxnum1;
				maxnum1=i+1;
			}
		}
		else if(total[i]<max1&&total[i]>=max2){
			
			if(total[i]==max2){
				max3=max2;
				max2=total[i];
				maxnum3=max(maxnum2,i+1);
				maxnum2=min(maxnum2,i+1);
			}
			else{
				max3=max2;
				max2=total[i];
				maxnum3=maxnum2;
				maxnum2=i+1;
			}
		}
		else if(total[i]<max2&&total[i]>=max3){
			if(total[i]==max3){
				max3=total[i];
				maxnum3=min(i+1,maxnum3);
			}
			else{
				max3=total[i];
				maxnum3=i+1;
			}
		}		
	}
	printf("%d %d\n",maxnum1,max1);
	printf("%d %d\n",maxnum2,max2);
	printf("%d %d",maxnum3,max3);
	return 0;
}
void main()
{
	struct student
	{
		int num;
		int yu;
		int shu;
		int c;
	} s[100000],k;
	int i,j,n;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&s[i].num,&s[i].yu,&s[i].shu);
		s[i].c=s[i].yu+s[i].shu;
	}
	
/*	for(i=0;i<n-1;i++)
	{
		for(j=0;j<n-1-i;j++)
		{
			if(s[j].c<s[j+1].c)
			{
				k=s[j];
			    s[j]=s[j+1];
				s[j+1]=k;
			}
		}
	}
	for(i=0;i<3;i++)
		printf("%d %d\n",s[i].num,s[i].c);*/
	for(i=0;i<3;i++)
	{
		for(j=i+1;j<n-1;j++)
			if(s[j].c>s[i].c)
			{
				k=s[i];
			    s[i]=s[j];
				s[j]=k;
			}
		printf("%d %d\n",s[i].num,s[i].c);
	}
}
struct stu
{
int num;
int chinese;
int maths;
}stu[100000];

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

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

	}
	
	printf("%d %d\n",s1.num,s1.zf);
	printf("%d %d\n",s2.num,s2.zf);
	printf("%d %d",s3.num,s3.zf);
	
	return 0;
}
struct Student
{
	int num;
	int math;
	int chinese;
}stu[100000];
int main()
{
	int n,i,j,s[100000],t[100000],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);
	}
    for(i=0;i<=(n-1);i++)
	{
		s[i]=stu[i].math+stu[i].chinese;
	    t[i]=s[i];
	}
	int p;
    for(i=0;i<=2;i++)
	{
		for(j=0;j<=(n-i-2);j++)
		{
            if(s[j]>=s[j+1])
			{
				p=s[j];
				s[j]=s[j+1];
				s[j+1]=p;
			}
		}
	}
	int d[3];
	for(i=0;i<=(n-1);i++)
	{
		if(t[i]==s[n-1])
		{
			printf("%d %d",stu[i].num,t[i]);
			d[c]=stu[i].num;
	        printf("\n");
			c=c+1;
            if(c==3)break;
		}
		if(c==3)break;
	}
	for(i=0;i<=(n-1);i++)
	{
        if(t[i]==s[n-2])
		{   
			if(stu[i].num==d[0]||stu[i].num==d[1]||stu[i].num==d[2])break;
			printf("%d %d",stu[i].num,t[i]);
	        d[c]=stu[i].num;
			printf("\n");
			c=c+1;
		    if(c==3)break;
		}
		if(c==3)break;
	}
	for(i=0;i<=(n-1);i++)
	{
        if(t[i]==s[n-3])
		{
			if(stu[i].num==d[0]||stu[i].num==d[1]||stu[i].num==d[2])break;
			printf("%d %d",stu[i].num,t[i]);
            d[c]=stu[i].num;
	        printf("\n");
			c=c+1;
		    if(c==3)break;
		}
		if(c==3)break;
	}
	return 0;
}
int main()
{
	int a[99999],b[99999],c[99999],d[99999];
	int i,n,sum,s;
	scanf("%d",&n);
	for (i=0;i<n;i++)
	{
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
		d[i]=c[i]+b[i];
	}
	for (i=0;i<n;i++)
	{
		if (d[i]>=d[i+1]){
			sum=d[i];
			d[i]=d[i+1];
			d[i+1]=sum;
			s=a[i];
			a[i]=a[i+1];
			a[i+1]=s;
		}
	}
	for (i=0;i<n-1;i++)
	{
		if (d[i]>=d[i+1]){
			sum=d[i];
			d[i]=d[i+1];
			d[i+1]=sum;
			s=a[i];
			a[i]=a[i+1];
			a[i+1]=s;
		}
	}
	
	for (i=0;i<n-2;i++)
	{
		if (d[i]>=d[i+1]){
			sum=d[i];
			d[i]=d[i+1];
			d[i+1]=sum;
			s=a[i];
			a[i]=a[i+1];
			a[i+1]=s;
		}
	}
	printf("%d %d\n%d %d\n%d %d",a[n],d[n],a[n-1],d[n-1],a[n-2],d[n-2]);
	return 0;
}
void swap(int *i,int *j)
{
	int *p=i,t=*i;
	*p=*j;
	p=j;
	*p=t;
}
struct Student
{
	int id;
	int chinese;
	int math;
};
int main()
{
	void swap(int *i,int *j);
	int n,i,first,second,third,one,two,three;
	int *f=&first,*s=&second,*t=&third,*on=&one,*tw=&two,*th=&three;
	struct Student stu[100000];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&stu[i].id,&stu[i].chinese,&stu[i].math);
		int total=stu[i].chinese+stu[i].math,k;
		int *to=&total,*K=&k;
		if(i==0)
		{
			first=total;
			one=i;
		}
		else
		{
			if(i==1)
			{
				if(total>first)
				{
					swap(to,f);
					second=total;
					k=i;
					swap(K,on);
					two=k;
				}
				else
				{
					second=total;
					two=i;
				}
			}
			else
			{
				if(i==2)
				{
					if(total>first)
					{
						swap(to,f);
						swap(to,s);
						third=total;
						k=i;
						swap(K,on);
						swap(K,tw);
						three=k;
					}
					else
					{
						if(total>second&&total<=first)
						{
							swap(to,s);
							third=total;
							k=i;
							swap(K,tw);
							three=k;
						}
						else
						{
							third=total;
							three=i;
						}
					}
				}
				else
				{
					if(total>first)
					{
						swap(to,f);
						swap(to,s);
						swap(to,t);
						k=i;
						swap(K,on);
						swap(K,tw);
						swap(K,th);
					}
					else
					{
						if(total>second)
						{
							swap(to,s);
							swap(to,t);
							k=i;
							swap(K,tw);
							swap(K,th);
						}
						else
						{
							if(total>third)
							{
								swap(to,t);
								k=i;
								swap(K,th);
							}
						}
					}
				}
			}
		}
	}
	printf("%d %d\n",stu[one].id,first);
	printf("%d %d\n",stu[two].id,second);
	printf("%d %d\n",stu[three].id,third);
	return 0;
}
void main()
{
    int i,j,m,n,a[3][2],k;
	struct student
	{
	int num;
	int s1;
	int s2;
	int l;
	}stu[100000];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&stu[i].num,&stu[i].s1,&stu[i].s2);
		stu[i].l=stu[i].s1+stu[i].s2;
	}
	for(i=0;i<3;i++)
	{
		for(m=0,j=0;j<n;j++)
		{
			if(m<stu[j].l)
			{
				m=stu[j].l;
				k=j;
			}
		}
		a[i][0]=k;
		a[i][1]=m;
		stu[k].l=0;
	}
	for(i=0;i<3;i++)
	{
		printf("%d %d\n",a[i][0]+1,a[i][1]);
	}
}