semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
struct student{
	int a;
	int b;
	int c;//?????????????
};

int main(int argc, char* argv[])
{
	int n,i,j,temp,temp2,sum=0;
	int max1,max2,max3,id1,id2,id3;
	scanf("%d",&n);
	struct student*s=(struct student*)malloc(n*sizeof(struct student));
	int*end=(int*)malloc(n*sizeof(int));//??????????????????????
	for(i=0;i<n;i++){
		scanf("%d %d %d",&s[i].a,&s[i].b,&s[i].c);
		end[i]=s[i].b+s[i].c;
	}
	max1=-100;max2=-100;max3=-100;
	id1=s[0].a;	id2=s[0].a;	id3=s[0].a;
	for(i=0;i<n;i++)
		if(end[i]>max1){
		max1=end[i];
		id1=s[i].a;
		}//?????
	for(i=0;i<n;i++)
		if(end[i]!=max1&&end[i]>max2){
			max2=end[i];
			id2=s[i].a;
		}//?????
	for(i=0;i<n;i++)
		if(end[i]!=max1&&end[i]!=max2&&end[i]>max3){
			max3=end[i];
			id3=s[i].a;
		}//???????(????????????????????????????????)

	for(i=0;i<n;i++){
		if(end[i]==max1){
			printf("%d %d\n",s[i].a,max1);
			sum++;
		}
	}
	for(i=0;i<n;i++){
		if(sum<=2&&end[i]==max2){
			printf("%d %d\n",s[i].a,max2);
			sum++;
		}
	}
	for(i=0;i<n;i++){
		if(sum<=2&&end[i]==max3){
			printf("%d %d\n",s[i].a,max3);
		}
	}//???????????????????????
		
	free(s);
	free(end);

	return 0;
}
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);
}
int sum[99999];
int m[99999];
int main(int argc, char* argv[])
{ 
	int n,i,b,c,a;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&a,&b,&c);
		sum[i]=b+c;
		m[i]=a;
	}
	int j,k,t,x,l=0;
	for(j=0;j<n;j++)
	{
		for(k=n-1;k>j;k--)
		{
			if(sum[k]>sum[k-1])
			{
				t=sum[k-1];
			    sum[k-1]=sum[k];
				sum[k]=t;
				x=m[k-1];
				m[k-1]=m[k];
				m[k]=x;
			}
		}l++;
		if(l==3)
			break;
	}
	for(i=0;i<l;i++)
	{
	printf("%d %d\n",m[i],sum[i]);
	}	
	return 0;
}
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;
}
struct score {
	int id;
	int chinese;
	int maths;
	int sum;
};
int main() {
	score *p[100000], *temp, stu[100000];
	int i, j, n;
	cin >> n;
	for (i = 0; i < n; i++) { //????p????stu??
		p[i] = &stu[i];
		cin >> p[i]->id >> p[i]->chinese >> p[i]->maths;
		p[i]->sum = p[i]->chinese + p[i]->maths;
	}
	for (i = 0; i < 3; i++) //???????????
		for (j = n - 1; j > i; j--)
			if (p[j]->sum > p[j - 1]->sum) { //????????????
				temp = p[j];
				p[j] = p[j - 1];
				p[j - 1] = temp;
			}
	for (i = 0; i < 3; i++) //?????
		cout << p[i]->id << ' ' << p[i]->sum << endl;
	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;
}