semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
struct stu{
int ID;
int yuwen;
int shuxue;
int sum;
struct stu *next;};

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

int main()
{
 long i,n;
 scanf("%ld",&n);
 struct stu *h,*p,*q1,*q2,*q3;
 h=creat(n);
 int m1,m2,m3;
 for(p=h,m1=p->sum;p!=NULL;p=p->next)
 if(p->sum>m1)  m1=p->sum,q1=p;
 printf("%d %d",q1->ID,q1->sum);
 for(p=h,m2=p->sum;p!=NULL;p=p->next)
 if(p->sum>m2&&p!=q1)  m2=p->sum,q2=p;
 printf("\n%d %d",q2->ID,q2->sum);
 for(p=h,m3=p->sum;p!=NULL;p=p->next)
 if(p->sum>m3&&p!=q1&&p!=q2)  m3=p->sum,q3=p;
 printf("\n%d %d",q3->ID,q3->sum);
}
void main()
{
	struct student
	{
		int ID;
		int chinese;
		int math;
		int total;
	}stu1,stu2,stu3,temp;
	int i,n;
	stu1.total=0;
	stu2.total=0;
	stu3.total=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&temp.ID,&temp.chinese,&temp.math);
		temp.total=temp.chinese+temp.math;
		if(temp.total>stu1.total)
		{
			stu3=stu2;
			stu2=stu1;
			stu1=temp;
		}
		else if(temp.total<=stu1.total&&temp.total>stu2.total)
		{
			stu3=stu2;
			stu2=temp;
		}
		else if(temp.total<=stu2.total&&temp.total>stu3.total)stu3=temp;
	}
	printf("%d %d\n",stu1.ID,stu1.total);
	printf("%d %d\n",stu2.ID,stu2.total);
	printf("%d %d\n",stu3.ID,stu3.total);
}
struct result//??result?????num?????????????
{   int num;
    int chn;
    int math;
    int total;
};
int main()
    {int n,k;
    cin>>n;
    struct result student[n+1];//?result??????student
    for(k=1;k<=n;k++)
        {cin>>student[k].num>>student[k].chn>>student[k].math;//??????
        student[k].total=student[k].chn+student[k].math;//?????
        }
    int i,j;
    struct result temp;
    for(i=1;i<4;i++)
    	for(j=1;j<=n-i;j++)//???????
    	    {if(student[j].total>=student[j+1].total)
    	        {temp=student[j];
    	        student[j]=student[j+1];
    	        student[j+1]=temp;
    	    	}
    	    }
    cout<<student[n].num<<" "<<student[n].total<<endl;
    cout<<student[n-1].num<<" "<<student[n-1].total<<endl;
    cout<<student[n-2].num<<" "<<student[n-2].total<<endl;

    return 0;
    }
int main()
{
    
	int n,i,first,second,third,x,y,z;
	scanf("%d",&n);
	struct mark{
		int ID,chinese,math,sum;
	}*num;
	num=(struct mark*)malloc(sizeof(mark)*n);
	int n1,c1,m1;
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&n1,&c1,&m1);
		num[i].ID =n1;
		num[i].chinese =c1;
		num[i].math=m1;
		num[i].sum=c1+m1;
	}
	for(i=0;i<n;i++)
	{
		if(i==0)
		{
			first=num[i].sum;
			second=num[i].sum;
			third=num[i].sum;
			x=num[i].ID;
			y=num[i].ID;
			z=num[i].ID ;
		}
		else if(i==1)
		{
			if(num[i].sum>first)
			{
				first=num[i].sum;
			    x=num[i].ID;
			}
			else
			{
				third=num[i].sum;
				z=num[i].ID;
			}
			    
		}
		else 
		{
			if(num[i].sum>first)
			{
				third=second;
                z=y;
				second=first;
				y=x;
				first=num[i].sum;
				x=num[i].ID;
			}	
			else if(num[i].sum>second)
			{
				third=second;
			    z=y;
				second=num[i].sum;
				y=num[i].ID;
			}
			else if(num[i].sum>third)
			{
				third=num[i].sum;
				z=num[i].ID;
			}
		}
	}
	printf("%d %d\n%d %d\n%d %d\n",x,first,y,second,z,third);
	return 0;
}
main()
{
      int n,i; 
      struct student
      {
             int num;
             int yuwen;
             int shuxue;
             int zongfen;
      }
      stu[100000];
      struct qiansan
      {
             int num;
             int zongfen;
      }st[3]={{0,0},{0,0},{0,0}};
      scanf("%d",&n);
      for(i=0;i<n;i++)
      {
          scanf("%d",&stu[i].num);
          scanf("%d",&stu[i].yuwen);
          scanf("%d",&stu[i].shuxue);
          stu[i].zongfen=stu[i].yuwen+stu[i].shuxue;
          if(stu[i].zongfen>st[0].zongfen)
          {
              st[2]=st[1];
              st[1]=st[0];
              st[0].zongfen=stu[i].zongfen;
              st[0].num=stu[i].num;
          }
          else if(stu[i].zongfen<=st[0].zongfen&&stu[i].zongfen>st[1].zongfen)
          {
              st[2]=st[1];
              st[1].zongfen=stu[i].zongfen;
              st[1].num=stu[i].num;
          }
          else if(stu[i].zongfen<=st[1].zongfen&&stu[i].zongfen>st[2].zongfen)
          {
              st[2].zongfen=stu[i].zongfen;
              st[2].num=stu[i].num;
          }
      }
      for(i=0;i<3;i++)
      {
          if(i==0)
          printf("%d %d",st[i].num,st[i].zongfen);
          else
          printf("\n%d %d",st[i].num,st[i].zongfen);
      }
      getchar();
      getchar();
}
struct student
{
	char id[20];
	int chinese;
	int math;
	int score;
	struct student *next;
};

int n;

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

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

	}
}

void pri_top3(struct student *head)
{
	struct student *p,*q,*p1,*p2,*p3;
	p1=p2=p3=head;
	p=head->next;
	while(p!=null)
	{
		if(p->score>p1->score)
		{
			p3=p2;p2=p1;p1=p;
		}
		else if((p->score<=p1->score)&&(p->score>p2->score))
		{
			p3=p2;p2=p;
		}
		else if((p->score<=p2->score)&&(p->score>p3->score))
			p3=p;
	
		p=p->next;
		
	}
	printf("%s %d\n",p1->id,p1->score);
	printf("%s %d\n",p2->id,p2->score);
	printf("%s %d\n",p3->id,p3->score);
}

void main()
{
	int m;
	scanf("%d",&m);
	struct student *p=create(m);
	plus(p);
	pri_top3(p);
}
struct student
{
	int num;
	int score1;
	int score2;
	int total;
}stu[100000];
int main()
{
	int n,i,j,k,t;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&stu[i].num,&stu[i].score1,&stu[i].score2);
        stu[i].total=stu[i].score1+stu[i].score2;
	}
	for(i=0;i<3;i++)
	{
		k=i;
		for(j=i+1;j<n;j++)
			if(stu[j].total>stu[k].total)k=j;
		if(k!=i)
		{
			t=stu[i].total;stu[i].total=stu[k].total;stu[k].total=t;
			t=stu[i].num;stu[i].num=stu[k].num;stu[k].num=t;}
	}
	for(i=0;i<3;i++)
	{
		printf("%d %d\n",stu[i].num,stu[i].total);
	}
}
struct student
{
  int ID;
  int chi;
  int math;     
}student[100000];
int main()
{
   int n,i,j,k;
   scanf("%d",&n);
      int a[n];
   for(i=0;i<n;i++)
     {
     scanf("%d %d %d",&student[i].ID,&student[i].chi,&student[i].math);      
      a[i]=student[i].chi+student[i].math;
      }

  for(k=0;k<3;k++)
  {
   for(i=0;i<n;i++)
    {
       for(j=0;j<n;j++)
       {
          if(a[i]<a[j])
             break;          
       } 
       if(j==n&&a[i]>=a[j-1]) 
         {
           printf("%d %d\n",student[i].ID,a[i]);
           a[i]=0;
           break;
         }      
    }  
  } 
   getchar();
   getchar();   
}
void main()
{
	struct student
	{
	
	 int id;
	 int chi;
	 int mat;
	 int sum;
	}stu[100000],t;
	int i,j,n,student_num;
	scanf("%d",&student_num);
	n=student_num;
	for(i=0;i<n;i++)
		scanf("%d%d%d",&stu[i].id,&stu[i].chi,&stu[i].mat);
	for(i=0;i<n;i++)
		stu[i].sum=stu[i].chi+stu[i].mat;
	for(i=0;i<n;i++)
		if(stu[0].sum<stu[i].sum)
			{t=stu[0];stu[0]=stu[i];stu[i]=t;}
		for(i=1;i<n;i++)
		if(stu[1].sum<stu[i].sum)
			{t=stu[1];stu[1]=stu[i];stu[i]=t;}
		for(i=2;i<n;i++)
		if(stu[2].sum<stu[i].sum)
			{t=stu[2];stu[2]=stu[i];stu[i]=t;}
	for(i=0;i<3;i++)
		printf("%d %d\n",stu[i].id,stu[i].sum);
}
int main(int argc, char* argv[])
{
	struct grades{
		int id;
		int yuwen,shuxue;
		int zongfen ;
	}grades[100007];
	int i,n,j,t,s;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&grades[i].id,&grades[i].yuwen,&grades[i].shuxue);
	
		grades[i].zongfen=grades[i].yuwen+grades[i].shuxue;
	}
	for(i=0;i<3;i++)
	{
		for(j=0;j<n-1;j++)
		{
			if(grades[j].zongfen>=grades[j+1].zongfen)
			{
				t=grades[j].zongfen;
				grades[j].zongfen=grades[j+1].zongfen;
				grades[j+1].zongfen=t;
				s=grades[j].id;
				grades[j].id=grades[j+1].id;
				grades[j+1].id=s;
			}
		}
	}
	for(i=n-1;i>=n-3;i--)
	{
		printf("%d %d\n",grades[i].id,grades[i].zongfen);
	}

	return 0;
}
struct Student {
        int ID;
        int chinese;
        int maths;
        int sum;
};
int main() {
        struct Student stu[3],t;        //????????
        stu[0].sum =stu[1].sum =stu[2].sum =0;  //???????0
        int i, n;
        cin >> n;
        for (i = 0; i < n; i++) {
                cin >> t.ID >> t.chinese >> t.maths;
                t.sum = t.chinese + t.maths;
                // ????????????
                if(t.sum>stu[0].sum){
                        stu[2] = stu[1];        //????????????????
                        stu[1] = stu[0];
                        stu[0] = t;
                } else if(t.sum>stu[1].sum){    //???????????
                        stu[2] = stu[1];                //???????????????
                        stu[1] = t;
                } else if(t.sum>stu[2].sum){    //???????????
                        stu[2] = t;                     //??????????
                }
        }
        //?????????????
        for (i = 0; i < 3; i++) {
                cout << stu[i].ID << " " << stu[i].sum << endl;
        }
        return 0;
}
struct student
{
	long id;
	int chinese;
	int math;
	int score;
	struct student *next;
};

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

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

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

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

void sort(struct student *p3,struct student *p4)
{
	int k;
	while(p4!=null)
	{
		if(p3->sum<p4->sum)
		{
			k=p3->num;
			p3->num=p4->num;
			p4->num=k;
			k=p3->sum;
			p3->sum=p4->sum;
			p4->sum=k;
		}
		p4=p4->next;
	}
}
int main()
{
	int n,i,b,c,d;
	struct{
		int sn;
		int chi;
		int mat;
		int sum;
	}a[100000];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d",&a[i].sn,&a[i].chi,&a[i].mat);
		a[i].sum=a[i].chi+a[i].mat;
	}	
	b=n;
	c=n;
	d=n;
	a[n].sum=-100;
	for(i=0;i<n;i++){
		if(a[b].sum>=a[i].sum)b=b;
		else b=i;
	}
	for(i=0;i<n;i++){
		if(i!=b){if(a[c].sum>=a[i].sum)c=c;else c=i;}
		else ;
	} 
	for(i=0;i<n;i++){
		if(i!=c&i!=b){if(a[d].sum>=a[i].sum)d=d;else d=i;}
		else ;
	}
	printf("%d %d\n",a[b].sn,a[b].sum);
	printf("%d %d\n",a[c].sn,a[c].sum);
	printf("%d %d\n",a[d].sn,a[d].sum);
	return 0;
}
struct student
{
	int num;
	int yuwen;
	int shuxue;
	int total;
	struct student *next;
};

void main()
{
	struct student *head,*p1,*p2,*P;
	
	int n,i=0,j=0;

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

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


}
/* Note:Your choice is C IDE */
void main()
{
    struct student
    {
    	int a;
    	int b;
    	int c;
    	int d;
    	int h;
    }s[100000];
    int i,j,k,n,max;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
    	scanf("%d%d%d",&s[i].a,&s[i].b,&s[i].c);
    	s[i].d=s[i].b+s[i].c;
    	s[i].h=-1;
    }
    for(i=1;i<=3;i++)
    {
    	max=0;
    	k=0;
    	for(j=1;j<=n;j++)
    	{
    		if((s[j].d>max)&&(s[j].h==-1))
    		{
    			max=s[j].d;
    			k=j;
    		}
    	}
    	s[k].h=1;
    	printf("%d %d\n",s[k].a,s[k].d);
    }
}
int main()
{
 int n,i,j,p,q,t;
 int a[100000][3];
 scanf("%d",&n);
 for(i=0;i<n;i++){
	 for(j=0;j<3;j++)
   scanf("%d",&a[i][j]);
   a[i][1]=a[i][1]+a[i][2];
 }
 for(p=0;p<3;p++){
  for(q=n-2;q>=0;q--){
   if(a[q][1]<a[q+1][1]){
    for(i=0;i<2;i++){
    t=a[q][i];
    a[q][i]=a[q+1][i];
    a[q+1][i]=t;
    }
   }
  }
 }
	  for(i=0;i<3;i++){
  printf("%d %d\n",a[i][0],a[i][1]);
 }
 return 0;
}
struct stu
{	int id;                
	int chn;
	int math;
	int sum;
};
int main()
{	struct stu indi[100000];
	int n,i,j,rank[3];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d%d",&indi[i].id,&indi[i].chn,&indi[i].math);
		indi[i].sum=indi[i].chn+indi[i].math;
	}
	for(i=0;i<3;i++){
		rank[i]=0;
		for(j=0;j<n;j++){
			if(indi[j].sum>indi[rank[i]].sum)
				rank[i]=j;
		}
		indi[rank[i]].sum=-indi[rank[i]].sum;
	}
	for(i=0;i<3;i++){
		printf("%d %d\n",indi[rank[i]].id,-indi[rank[i]].sum);
	}


	return 0;
}
int main()
{
	struct student
	{
		int num;
		int chinese;
		int math;
		int sum;
	}stu[100001],t;
    int n,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&stu[i].num,&stu[i].chinese,&stu[i].math);
		stu[i].sum=stu[i].chinese+stu[i].math;
	}
    for(i=0;i<3;i++)
	{
		for(j=0;j<n-1-i;j++)
		{
			if(stu[j].sum>=stu[j+1].sum)
			{
				t=stu[j];
				stu[j]=stu[j+1];
				stu[j+1]=t;
			}
		}
	}
	for(i=n-1;i>n-4;i--)
	{
		printf("%d %d\n",stu[i].num,stu[i].sum);
	}
	return 0;
}
struct student
	{
		int num;
		int chinese;
		int math;
	};
	struct student stu[100000];
	int sum[100000];
int main(int argc, char* argv[])
{
	
	int a,b,c,num1,num2,num3;
	int i,n;
	scanf("%d",&n);
    for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&stu[i].num,&stu[i].chinese,&stu[i].math);
	}
	for(i=0;i<n;i++)
	{
		sum[i]=stu[i].chinese+stu[i].math;
	}
	a=sum[0];
	num1=1;
	if(a<sum[1])
	{
		b=a;
		num2=num1;
		a=sum[1];
		num1=2;
	}
	else 
	{
		b=sum[1];
	    num2=2;
	}
    c=0;
	for(i=2;i<n;i++)
	{
        if(a<sum[i])
		{	
			c=b;
            num3=num2;
		    b=a;
			num2=num1;
			a=sum[i];
			num1=i+1;
		}
	    else
			if(b<sum[i])
			{
				c=b;
				num3=num2;
			    b=sum[i];
				num2=i+1;
			}
		    else
				if(c<sum[i])
				{
					c=sum[i];
				    num3=i+1;
				}
	}
	printf("%d %d\n",num1,a);
	printf("%d %d\n",num2,b);
	printf("%d %d\n",num3,c);
	return 0;
}
int main() {
	int n = 0, i = 0, j = 0;
	cin >> n;
	int sum[n];
	struct student {
		int stuid;
		int chin;
		int math;
	} stu[n], t;
	for (i = 0; i < n; i++) {
		cin >> stu[i].stuid >> stu[i].chin >> stu[i].math;
		sum[i] = stu[i].chin + stu[i].math;
	}
	for (i = 0; i < 3; i++)
		for (j = 0; j < n -1; j++)
			if ((stu[j].chin + stu[j].math) >= (stu[j + 1].chin
					+ stu[j + 1].math)) {
				t = stu[j];
				stu[j] = stu[j + 1];
				stu[j + 1] = t;
			}
	for (i = n-1; i > n-4; i--)
		cout << stu[i].stuid << " " << stu[i].chin + stu[i].math << endl;
	return 0;
}
struct student//?????
{
	int NO;
	int chinese;
	int math;
};

int main()
{
	struct student a[100001];
	int n,i,j;
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>a[i].NO>>a[i].chinese>>a[i].math;//??
	for(i=1;i<=3;i++)
		for(j=n-1;j>=i;j--)
			if(a[j].chinese+a[j].math<a[j+1].chinese+a[j+1].math)//??????????
			{
				a[0]=a[j];
				a[j]=a[j+1];
				a[j+1]=a[0];
			}
	for(i=1;i<=3;i++)
		cout<<a[i].NO<<' '<<a[i].chinese+a[i].math<<endl;//??
}
main()
{ int n,i;
   struct h
   {
  int mun;
  int chinese;
  int math;
  struct h *p;
   } ;
struct h *a,*b,*lily; 
scanf("%d",&n);
a=len;
lily=a;
for(i=0;i<n;i++)
{  scanf("%d %d %d",&a->mun,&a->chinese,&a->math);
   b=len;
   a->p=b;
   a=b;
}
b=NULL;
a=lily;
int a1=0,a2=0,a3=0,b1=0,b2=0,b3=0,c;
for(i=0;i<n;i++)
{   c=(a->chinese+a->math);
	if(c>a1){b3=b2;b2=b1;b1=a->mun;a3=a2;a2=a1;a1=c;}
	else if(c>a2){b3=b2;b2=a->mun;a3=a2;a2=c;}
	else if(c>a3){b3=a->mun;a3=c;}
	a=a->p;
}
printf("%d %d\n",b1,a1);
printf("%d %d\n",b2,a2);
printf("%d %d\n",b3,a3);
}
main()
{
      int i,j,k,m=0,n,e,f,g,h;
      int *a,*b,*c;
      scanf("%d",&n);
      a=(int*)malloc(n*sizeof(int));
      b=(int*)malloc(n*sizeof(int));
      c=(int*)malloc(n*sizeof(int));
      for(i=0;i<n;i++)
      scanf("%d %d %d",&a[i],&b[i],&c[i]);
      for(i=0;i<n;i++)
      a[i]=b[i]+c[i];
      for(i=0;i<n;i++)
      b[i]=a[i];
      for(i=0;i<n;i++)
      {
                      if(a[i]>m)
                      m=a[i];
                      }
      for(i=0;i<n;i++)
      {
                      if(b[i]==m)
                      break;
                      }
      printf("%d %d\n",i+1,m);
      b[i]=0;
      a[i]=0;
      m=0;
      for(i=0;i<n;i++)
      {
                      if(b[i]>m)
                      m=b[i];
                      }
      for(i=0;i<n;i++)
      {
                      if(a[i]==m)
                      break;
                      }
      printf("%d %d\n",i+1,m);
      a[i]=0;
      b[i]=0;
      m=0;
      for(i=0;i<n;i++)
      {
                      if(b[i]>m)
                      m=b[i];
                      }
      for(i=0;i<n;i++)
      {
                      if(a[i]==m)
                      break;
                      }
      
      printf("%d %d\n",i+1,m);
     free(a);
     a=0;
     free(b);
     b=0;
     free(c);
     c=0;
     
}
// ????STUDENT_NUM???????????????? 
//?????????ID??????????????????? 
//??????????????????????? 
int n;
struct student
{
	int num;
	int chn;
	int math;
	int ovr;
	struct student *next;
};
struct student *creat()
{
	int i;
	struct student *head;
	struct student *p1,*p2;
	head=(struct student *)malloc(sizeof(struct student));
	p1=p2=head;
	for(i=0;i<n;i++)
	{
		p2=p1;
		p1=(struct student *)malloc(sizeof(struct student));
		p2->next=p1;
		scanf("%d %d %d",&p2->num,&p2->chn,&p2->math);
		p2->ovr=p2->chn+p2->math;
	}
	p2->next=0;
	return (head);
}
int main()
{
	int i;
	int no1,ovr1=0;
	struct student *head;
	struct student *p1,*p2;
	scanf("%d",&n);
	head=creat();
	p1=p2=head;
	for(i=0;i<3;i++)
	{
		p1=head;
		while(p1->next!=0)
		{
			if(p1->ovr>ovr1)
			{
				ovr1=p1->ovr;
				no1=p1->num;
				p2=p1;
			}
			p1=p1->next;
		}
		printf("%d %d\n",no1,ovr1);
		p2->ovr=0;
		ovr1=0;

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

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

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

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


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


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

}
struct student
{
	int number;
	int chinese;
	int math;
	int num;
}stu[100001];
int main ( )
{
	int n, i, j, max[3][2] = {0};
	cin >> n;
	for(i = 0;i < n;i++)//??????????
	{
		cin >> stu[i].number >> stu[i].chinese >> stu[i].math;
		stu[i].num = stu[i].chinese + stu[i].math;
	}
	for(j = 0;j < 3;j++)//??3??????
	{
		for(i = 0;i < n;i++)
		{
			if(stu[i].num > max[j][0])
			{
				max[j][0] = stu[i].num;
				max[j][1] = i + 1;
			}
		}
		stu[max[j][1]-1].num = 0;
	}
	for(j = 0;j < 3;j++)//?????
	{
		cout << max[j][1] << ' ' << max[j][0] << endl;
	}
	return 0;
}
struct stu
{
	char num[15];
	int chi;
	int math;
	int sum;
	struct stu *next;
};
int n;
struct stu *creat(void)
{
	struct stu *head,*p,*g,*h;
	int i,j;
	p=(struct stu*)malloc(LEN);
	scanf ("%s %d %d",p->num,&p->chi,&p->math);
	p->sum=p->chi+p->math;
	for (i=0;;i++)
	{
		if (i==0) {head=p;head->next=NULL;}
		else if (i<3) 
		 { 
			 for (h=head,j=0;j<i;j++)
			 {
				 if (p->sum>h->sum) break;
				 else {g=h; h=h->next;}
			 }
			 if (j==0) {p->next=head;head=p;}
			 else if (j==i) {g->next=p;p->next=NULL;}
			 else {g->next=p;p->next=h;}
		 }
		 else
		{ 
			 for (h=head,j=0;j<3;j++)
			 {
				 if (p->sum>h->sum) break;
				 else {g=h; h=h->next;}
			 }
			 if (j==0) {p->next=head;head=p;}
			 else {g->next=p;p->next=h;}
		 }
		 if (i==n-1) break;
		 p=(struct stu*)malloc(LEN);
		 scanf ("%s %d %d",p->num,&p->chi,&p->math);
		 p->sum=p->chi+p->math;
	}
	return(head);
}
void print(struct stu *head)
{
	struct stu *p;
	int i;
	for (p=head,i=0;i<3;i++,p=p->next)
			printf("%s %d\n",p->num,p->sum);
}
void main()
{
	struct stu *head;
	scanf("%d",&n);
	head=creat();
	print(head);
}
int main()
{
    struct Stu
    {
           int num;
           int sco[2];
           int sum;
    };
   struct Stu stu[5];
   struct Stu temp;
   int i,j,n,m,k;
   scanf("%d",&n);
   if(n>=3)
  {
   for(i=0;i<3;i++)
   {
     scanf("%d%d%d",&stu[i].num,&stu[i].sco[0],&stu[i].sco[1]);
     stu[i].sum=stu[i].sco[0]+stu[i].sco[1];
    }
    for(k=1;k<=n-3;k++)
     {
      scanf("%d%d%d",&stu[3].num,&stu[3].sco[0],&stu[3].sco[1]);
      stu[3].sum=stu[3].sco[0]+stu[3].sco[1];
      m=0;
      for(j=1;j<=2;j++)
      {
        if(stu[m].sum>stu[j].sum||(stu[m].sum==stu[j].sum&&stu[m].num<stu[j].num))
        m=j;
       }
        if(stu[3].sum>stu[m].sum)
        stu[m]=stu[3];
     }
   }
    for(i=0;i<2;i++)
   for(j=i+1;j<3;j++)
   if(stu[i].num>stu[j].num)
   {
     temp=stu[i];
     stu[i]=stu[j];
     stu[j]=temp;
     }
   for(i=0;i<2;i++)
   for(j=i+1;j<3;j++)
   if(stu[i].sum<stu[j].sum)
   {
     temp=stu[i];
     stu[i]=stu[j];
     stu[j]=temp;
     }
    for(i=0;i<3;i++)
    printf("%d %d\n",stu[i].num,stu[i].sum);
    return 0;
}
struct stu
{long num;
int Chi;
int Math;
int Sum;
struct stu *next;
}*p1,*p2;
//????
struct stu * creat(int n)
{struct stu *head=NULL;
int i;
for(i=0;i<n;i++)
{
	p1=(struct stu *)malloc(sizeof(struct stu));
	
	scanf("%d %d %d",&p1->num,&p1->Chi,&p1->Math);
	p1->Sum=p1->Chi+p1->Math;
	if(i==0){ head=p1; p2=p1;}
	else 
		p2->next=p1;
		p2=p1;
}
p2->next=NULL;
return(head);
}

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

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

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

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