semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
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;
}
int main()
{
	int num[3],sum[3];
	int i,j,k,t,n,m;
	num[0]=num[1]=num[2]=sum[0]=sum[1]=sum[2]=-10000000;
	scanf("%d",&n);
	for(m=0;m<n;m++)
	{
		scanf("%d%d%d",&i,&j,&k);
		j+=k;
		if(sum[2]<j)
		{
			sum[2]=j;
			num[2]=i;
			if(sum[2]>sum[1])
			{
				t=sum[2];
				sum[2]=sum[1];
				sum[1]=t;
				t=num[2];
				num[2]=num[1];
				num[1]=t;
				if(sum[1]>sum[0])
				{
					t=sum[0];
					sum[0]=sum[1];
					sum[1]=t;
					t=num[0];
					num[0]=num[1];
					num[1]=t;
				}
			}
		}
	}
	for(i=0;i<3;i++)
		printf("%d %d\n",num[i],sum[i]);
	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;
}
int main()
{
	int n,i,num[100000],j,grade1[100000],grade2[100000],grade[100000],t1,t2;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&num[i],&grade1[i],&grade2[i]);
		grade[i]=grade1[i]+grade2[i];
	}
	for(j=1;j<4;j++)
	{
		for(i=0;i<n-j;i++)
		{
			if(grade[i]>=grade[i+1])
			{
				t1=grade[i];
				grade[i]=grade[i+1];
				grade[i+1]=t1;
				t2=num[i];
				num[i]=num[i+1];
				num[i+1]=t2;
			}
		}
	}
	printf("%d %d\n%d %d\n%d %d",num[n-1],grade[n-1],num[n-2],grade[n-2],num[n-3],grade[n-3]);
}
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 stu
{
	int id;
	int c;
	int m;
	int t;
};
int main()
{
	int n,i,j,K;
	struct stu a[4]={0};
	struct stu b[4]={0};
	struct stu temp={0};
    scanf("%d",&n);
	for(i=0;i<=(n-1);i++)
	{
		if(i<=2)
		{scanf("%d%d%d",&a[i].id,&a[i].c,&a[i].m);
		a[i].t=a[i].c+a[i].m;
		b[i]=a[i];}
		else
        {
			scanf("%d%d%d",&a[3].id,&a[3].c,&a[3].m);
             a[3].t=a[3].c+a[3].m;
		     b[3]=a[3];
			 //a[3]="\0";
		     for(K=0;K<=3;K++)
			 {
		       for(j=0;j<=3;j++)
			   {
			      if(b[j].t<b[j+1].t)
				{	temp=b[j];
                   b[j]=b[j+1];
			    	b[j+1]=temp;
				  }
			   }
			 }
		}
	}

	for(i=0;i<=2;i++)
	{
		printf("%d %d\n",b[i].id,b[i].t);
	}

}
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) ;
}
int main()
{  
	int n,i,m;
	int a,b,c;
	int j,k,v;
	int sum[100000];
	int max1=0,max2=0,max3=0;
	int A[100000][1];
	scanf ("%d",&n);
	for (i=1;i<=n;i++)
	{
		scanf ("%d %d %d",&m,&A[i][0],&A[i][1]);
		sum[i]=A[i][0]+A[i][1];
	}
	for (j=1;j<=n;j++)
	{
		if (sum[j]>max1)
		{max1=sum[j];
		a=j;}
	}
	for (k=1;k<=n;k++)
	{
		
			if (sum[k]>max2&&k!=a)
			{max2=sum[k];
			b=k;}
		
	}
	for (v=1;v<=n;v++)
	{
		if (sum[v]<max2)
		{
			if (sum[v]>max3)
			{max3=sum[v];
			c=v;}
		}
	}
	printf ("%d %d\n",a,max1);
	printf ("%d %d\n",b,max2);
	printf ("%d %d",c,max3);

	  return 0;
}
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);
}
struct st
	{int I;
	int c;
	int m;
	}
	st[100000];

	int main()
{

	
		int n,i,j,k=0,a,b;
	
		scanf("%d",&n);

	
		for (i=0;i<n;i++)
	
		{
		
			scanf("%d %d %d",&st[i].I,&st[i].c,&st[i].m);

		}
		for (i=0;i<3;i++)
		{   
			for(j=0;j<n;j++)

			{
				if (k<st[j].c+st[j].m)
				{
					k=st[j].c+st[j].m;
					a=st[j].I;
					b=j;

		

				}
			}
			
		
			st[b].c=0;
			st[b].m=0;
		
			printf("%d %d",a,k);
			if (i<2)
				printf("\n");
			k=0;

		



		}


	}
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 s[100001];
int main()
{
	int n,i,j;
	scanf("%d",&n);
	struct{
		int id,chin,math,su;
	}s[100001];
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&s[i].id,&s[i].chin,&s[i].math);
        s[i].su=s[i].chin+s[i].math;
	}
	for(i=0;i<3;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if(s[i].su<s[j].su)
			{
				s[100000]=s[i];
				s[i]=s[j];
				s[j]=s[100000];
			}
		}
	}
	printf("%d %d\n%d %d\n%d %d",s[0].id,s[0].su,s[1].id,s[1].su,s[2].id,s[2].su);
	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 ace
{
	char id[10];
	int a;
	int b;
}o[3],r;


void main()
{
	int n,i,s[3],m,j,v;
	char z[10];
	scanf("%d",&n);

	scanf("%s %d %d",o[0].id,&o[0].a,&o[0].b);
	scanf("%s %d %d",o[1].id,&o[1].a,&o[1].b);
	scanf("%s %d %d",o[2].id,&o[2].a,&o[2].b);
	s[0]=o[0].a+o[0].b;
	s[1]=o[1].a+o[1].b;
	s[2]=o[2].a+o[2].b;
	for(i=0;i<2;i++)
	{
		for(j=i+1;j<3;j++)
		{
			if(s[i]<s[j])
			{
				strcpy(z,o[i].id);
				strcpy(o[i].id,o[j].id);
				strcpy(o[j].id,z);
				v=s[i];
				s[i]=s[j];
				s[j]=v;
			}
		}
	}
	for(i=0;i<n-3;i++)
	{
		scanf("%s %d %d",r.id,&r.a,&r.b);
        m=r.a+r.b;
		if(m>s[0] )
		{o[2]=o[1];s[2]=s[1];o[1]=o[0];s[1]=s[0];o[0]=r;s[0]=m;}
		else if(m<=s[0] && m>s[1])
		{o[2]=o[1];s[2]=s[1];o[1]=r;s[1]=m;}
		else if(m<=s[1] && m>s[2])
		{o[2]=r;s[2]=m;}
	}
	printf("%s %d\n",o[0].id,s[0]);
	printf("%s %d\n",o[1].id,s[1]);
	printf("%s %d\n",o[2].id,s[2]);




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