semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main () {
	int n,c,m;
	cin>>n;
	struct student
	{
		int id;
		int total;
	};                      //?????
	struct student stu[n+1];//??????
	int i,j;
	for(i=0;i<n;i++){
	   cin>>stu[i].id>>c>>m;
	   stu[i].total=c+m;//?????????
	}
	for(i=n-1;i>n-4;i--)
		for(j=n-1;j>n-i-1;j--)
		{
            if(stu[j].total>stu[j-1].total){
            	stu[n]=stu[j];
            	stu[j]=stu[j-1];
            	stu[j-1]=stu[n];
            }
		}//????
	for(i=0;i<3;i++){
		if(i<n)
	    cout<<stu[i].id<<" "<<stu[i].total<<endl;//?????
	}
	return 0;
}
struct stu* create();
int compare (const void * a, const void * b);
int main()
{
	int i,j=0,n;
	scanf("%d", &n);
	struct stu{
			int num;
			int chi;
			int math;
			int total;
	};	
	struct stu *p=(struct stu*)calloc( n,sizeof(struct stu) );
	struct stu *a=p;
	int *tot=(int *)calloc( n, sizeof(int) );
	for(i=0;i<n;i++){
		scanf("%d %d %d", &p->num, &p->chi, &p->math);
		*(tot+i) = p->total = p->chi + p->math;
		p++;	
	}
	qsort(tot, n, sizeof(int), compare);
	for(i=0;i<3;i++,j=0){
		while( (a+(j++))->total != *(tot+i) )
			;
		printf("%d %d\n", (a+j-1)->num, (a+j-1)->total);
		(a+j-1)->total=-1;
	}
	
	return 0;

}

int compare (const void * a, const void * b)
{
  return ( *(int*)b - *(int*)a );
}
struct student
{
	int number;
	int ch;
	int ma;
	int sum;
	int key;

}stu[100000];
void main()
{
	int n,i,max=0,l=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&stu[i].number,&stu[i].ch,&stu[i].ma);
		stu[i].sum=stu[i].ch+stu[i].ma;
		stu[i].key=0;
	}
	for(i=0;i<n;i++)
		if(max<stu[i].sum&&stu[i].key==0)
		{
			max=stu[i].sum;
			l=i;
		}
	printf("%d %d\n",l+1,max);
	max=0;
	stu[l].key=1;
	l=0;
    for(i=0;i<n;i++)
		if(max<stu[i].sum&&stu[i].key==0)
		{
			max=stu[i].sum;
			l=i;
		}
	printf("%d %d\n",l+1,max);
	max=0;
	stu[l].key=1;
	l=0;
	for(i=0;i<n;i++)
		if(max<stu[i].sum&&stu[i].key==0)
		{
			max=stu[i].sum;
			l=i;
		}
	printf("%d %d\n",l+1,max);
	max=0;
	stu[l].key=1;
	l=0;
}
int main()
{
	int n,i,j,b,c,d,t,z;
	struct a
	{
		int num;
		int b;
		int c;
		int d;
	}a[4];
	scanf("%d",&n);
	for(i=0;i<3;i++){
		scanf("%d %d %d",&a[i].num,&a[i].b,&a[i].c);
		a[i].d=a[i].b+a[i].c;
	}
	for(j=0;j<2;j++){
		for(i=0;i<2-j;i++){
			if(a[i].d<a[i+1].d){
				t=a[i].d;
				z=a[i].num;
				a[i].d=a[i+1].d;
				a[i].num=a[i+1].num;
				a[i+1].d=t;
				a[i+1].num=z;
			}
		}
	}
	for(i=3;i<n;i++){
		scanf("%d %d %d",&a[3].num,&a[3].b,&a[3].c);
		a[3].d=a[3].b+a[3].c;	
	            if(a[3].d>a[0].d){
				a[2]=a[1];
				a[1]=a[0];
				a[0]=a[3];
			}
			else if(a[3].d>a[1].d){
				a[2]=a[1];
				a[1]=a[3];
			}
			else if(a[3].d>a[2].d){
				a[2]=a[3];
		}
	}
	printf("%d %d\n",a[0].num,a[0].d);
	printf("%d %d\n",a[1].num,a[1].d);
	printf("%d %d\n",a[2].num,a[2].d);
	return 0;
}
int main()
{
	struct student{
		long num;
		long chinese;
		long maths;
		long sum;
	}t[100000],l;
	long n,i,j,k,tmp;
	scanf("%ld",&n);
	for(i=0;i<n;i++)
	{
		scanf("%ld %ld %ld",&t[i].num,&t[i].chinese,&t[i].maths);
	}
    for(i=0;i<n;i++)
	{
		t[i].sum=t[i].chinese+t[i].maths;
	}
	for(i=0;i<3;i++)
	{
        k=i;
		for(j=i+1;j<n;j++)
		{
			if(t[j].sum>t[k].sum)
				k=j;
		}
		l=t[k];
                  t[k]=t[i];
                  t[i]=l;
	}
	for(i=0;i<3;i++)
	{
	    printf("%ld %ld\n",t[i].num,t[i].sum);
	}
	return 0;
}
// ??????????

struct record
{
	int stuID;
	short YuWen;
	short math;
	short total;
};

struct YyxNode
{
	struct record m_rec;
	struct YyxNode *next;
};

struct YyxLink
{
	int n;
	struct YyxNode *head;
	struct YyxNode *tail;
};

struct YyxLink *CreateNewLink()
{
	struct YyxLink *newLn;
	if((newLn=(struct YyxLink*)malloc(sizeof(struct YyxLink)))==NULL){
		printf("Error: memory out! (1)\n");
		exit(-1);
	}
	newLn->n = 0;
	newLn->head = NULL;
	newLn->tail = NULL;

	return newLn;
}

struct YyxLink *AddNode(struct YyxLink *ln, const struct record *rec)
{
	struct YyxNode *newNode;
	if((newNode=(struct YyxNode*)malloc(sizeof(struct YyxNode)))==NULL){
		printf("Error: memory out! (2)\n");
		exit(-1);
	}
	newNode->m_rec = *rec;
	newNode->next = NULL;
	if(ln->n==0){
		ln->head = newNode;
		ln->tail = newNode;
	}else{
		ln->tail->next = newNode;
		ln->tail = newNode;
	}
	ln->n ++;

	return ln;
}

int myCompare(const struct record *rec1, const struct record *rec2)
{
	return rec2->total - rec1->total;
}

struct YyxNode *Search(struct YyxLink *ln, const struct record *rec)
{
	struct YyxNode *nd = ln->head;
	while(nd!=NULL && myCompare(&nd->m_rec, rec))
		nd = nd->next;
	
	return nd;
}

struct YyxLink *ClearLink(struct YyxLink *ln)
{
	struct YyxNode *delNode = ln->head;
	struct YyxNode *nextNode;
	while(delNode != NULL){
		nextNode = delNode->next;
		free(delNode);
		delNode = nextNode;
	}
	ln->n = 0;
	ln->head = NULL;
	ln->tail = NULL;

	return ln;
}

int main()
{
	struct YyxLink *mainLn;
	struct record stu;
	int n;
	int i;
	struct record *max1, *max2, *max3;
	struct YyxNode *temp;
	mainLn = CreateNewLink();
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d %d %d", &stu.stuID, 
			&stu.YuWen, &stu.math);
		stu.total = stu.YuWen + stu.math;
		AddNode(mainLn, &stu);
	}
	
	max1=max2=max3= &mainLn->head->m_rec;
	temp = mainLn->head;
	while(temp!=NULL){
		if(max1->total<temp->m_rec.total)
			max1 = &temp->m_rec;
		temp = temp->next;
	}
	temp = mainLn->head;
	if (max2==max1){
		temp = mainLn->head->next;
		max2 = &temp->m_rec;
	}
	while(temp!=NULL){
		if(max2->total<temp->m_rec.total)
			if(max1!=&temp->m_rec)
				max2 = &temp->m_rec;
		temp = temp->next;
	}
	temp = mainLn->head;
	while(&temp->m_rec==max1||&temp->m_rec==max2)
		temp = temp->next;
	max3 = &temp->m_rec;
	while(temp!=NULL){
		if(max3->total<temp->m_rec.total)
			if(max1!=&temp->m_rec&&max2!=&temp->m_rec)
			max3 = &temp->m_rec;
		temp = temp->next;
	}

	printf("%d %d\n", max1->stuID, max1->total);
	printf("%d %d\n", max2->stuID, max2->total);
	printf("%d %d\n", max3->stuID, max3->total);

//	getchar();getchar();getchar();
	free(ClearLink(mainLn));

	return 0;
}
int k[99999];

int x[99999];
int main()
{
	int n,i ,a,b,c,j,r,t,m=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&a,&b,&c);k[a-1]=b+c;x[i]=a;
	}
	for(j=n-1;j>=0;j--)
	{
		for(r=0;r<j;r++)
		{
			if(k[r]>=k[r+1])
			{
				t=k[r+1];
				k[r+1]=k[r];
				k[r]=t;
				t=x[r+1];
                x[r+1]=x[r];
				x[r]=t;
			}
		
		}	m++;
		if(m>3) break;
	}                     
		
		printf("%d %d\n%d %d\n%d %d\n",x[n-1],k[n-1],x[n-2],k[n-2],x[n-3],k[n-3]);
		return 0;
}
struct student
{
	int xuehao;
	int yuwen;
	int shuxue;
	int zongfen;
}stu[100000];
int main(int argc, char* argv[])
{
	int n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&stu[i].xuehao,&stu[i].yuwen,&stu[i].shuxue);
		stu[i].zongfen=stu[i].yuwen+stu[i].shuxue;
	}
	int max1=2,max2=1,max3=0,num1=0,num2=0,num3=0;
	for(i=0;i<n;i++)
	{
		if(stu[i].zongfen>max1)
		{
			max3=max2;
			num3=num2;
			max2=max1;
			num2=num1;
			max1=stu[i].zongfen;
			num1=i;
		}else if(stu[i].zongfen<=max1&&stu[i].zongfen>max2)
		{
			max3=max2;
			num3=num2;
			max2=stu[i].zongfen;
			num2=i;
		}else if(stu[i].zongfen<=max2&&stu[i].zongfen>max3)
		{
			max3=stu[i].zongfen;
			num3=i;
		}
	}
	printf("%d %d\n",stu[num1].xuehao,stu[num1].zongfen);
	printf("%d %d\n",stu[num2].xuehao,stu[num2].zongfen);
	printf("%d %d\n",stu[num3].xuehao,stu[num3].zongfen);
	return 0;
}
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=max2;
			max2=max1;
			max1=a;
		}
		else if (a.z>max2.z)
		{
			max3=max2;
			max2=a;
		}else if (a.z>max3.z)
		{
			max3=a;
			max3=a;
		}
	}
	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 chn;
int math;
int sum;
};

int main()
{
int n;
int i, j, e;
int x;
struct student a[100000];
scanf("%d", &n);
for(i=0; i<n; i++)
{
scanf("%d %d %d", &a[i].num, &a[i].chn, &a[i].math);
a[i].sum=a[i].chn+a[i].math;
}
for(i=1; i<=3; i++)
   {
    for(j=n-i-1; j>=0; j--)
      {
       if(a[j].sum<a[j+1].sum)
          {
           x=a[j+1].sum;
           a[j+1].sum=a[j].sum;
           a[j].sum=x;
           e=a[j+1].num;
           a[j+1].num=a[j].num;
           a[j].num=e;
          }
      }
   }
for(i=0; i<=2; i++)
{
 printf("%d %d\n", a[i].num, a[i].sum);
}
return 0;
}
int main()
{
	struct stu
	{
		char id[9];
		int chn;
		int math;
		int both;
		struct stu *next;
	};
	int n,i;
	scanf("%d",&n);
	struct stu *head,*p1,*p2;
	for(i=0;i<n;i++)
	{
		if(i==0) 
		{
			head=(struct stu*)malloc(sizeof(struct stu));
			p1=head;
		}
		else
		{
			p1->next=(struct stu*)malloc(sizeof(struct stu));
			p1=p1->next;
		}
		scanf("%s%d%d",p1->id,&p1->chn,&p1->math);
		p1->both=p1->chn+p1->math;
	}
	p1->next=NULL;
	int max;
	for(i=0;i<3;i++)
	{
		max=head->both;
	    p1=head;
		do
		{
		   p1=p1->next;
		   if(max<p1->both)
		   {
			 max=p1->both;
			 p2=p1;
		   }
		}while(p1->next!=NULL);
		printf("%s %d\n",p2->id,p2->both);
		p2->both=0;
	}
	return 0;
}
struct student
{
       char num[10];
       int grade[2];
};
struct student stu[100000];
int main()
{
    int n,sum[100000],i,count,max,j;
    count = 1;
    
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
      sum[i]=0;
      scanf("%s %d %d",stu[i].num,&stu[i].grade[0],&stu[i].grade[1]);
      sum[i]= stu[i].grade[0]+stu[i].grade[1];
    }
    while(count <=2)
    { 
      max =0;
      for(i=0;i<n;i++)
      {
        if(sum[i]>max)
       {
        max = sum [i];
        j=i;
       }
      }
      printf("%s %d\n",stu[j].num,sum[j]);
      count++;
      sum[j]=0;
    }
    max = 0;
    for(i=0;i<n;i++)
      {
        if(sum[i]>max)
       {
        max = sum [i];
        j=i;
       }
      }
      printf("%s %d",stu[j].num,sum[j]);
    getchar();
    getchar();
}
void main()
{
	struct student
	{int num;
	int score1;
	int score2;
	}stu[100000];
         long int n;
	int i,score[100000],max[3]={0},a[3];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{	
		scanf("%d%d%d",&stu[i].num,&stu[i].score1,&stu[i].score2);
        score[i]=stu[i].score1+stu[i].score2;
	}
	for(i=0;i<n;i++)
	{
		if(max[0]<score[i]){max[0]=score[i];a[0]=stu[i].num;}
    }

     for(i=0;i<n;i++)
	 {if(stu[i].num==a[0])continue;
	 else if(max[1]<score[i]){max[1]=score[i];a[1]=stu[i].num;}
	 }

	 for(i=0;i<n;i++)
	 {if(stu[i].num==a[1]||stu[i].num==a[0])continue;
	 else if(max[2]<score[i]){max[2]=score[i];a[2]=stu[i].num;}
	 }
	 for(i=0;i<3;i++)
	 {
		 printf("%d %d\n",a[i],max[i]);
	 }
}
struct Student
{
	int number;
	int math;
	int chinese;
	int total;
	struct Student *next;


};

void main()
{
	int i=0,n,max;

	struct Student *linkHead, *linkTail, *student,*ppre,*pmax,*premax;
	

	scanf("%d",&n);

	linkHead = linkTail = NULL;
	//????????????
while(i<n)
{
	student = (struct Student *)malloc(Len);
    			 
	scanf("%d %d %d",&student->number, &student->math, &student->chinese);
 
	student->total=student->math+student->chinese;

	student->next = NULL;
	if (linkTail == NULL)
	//????????????
	linkHead = linkTail = student;
	else 
	{
	
	//?????????????????????
	linkTail->next = student;
	linkTail = student;

	}
	
	i++;
	
}

i=0;

while(i<3)
{
student=linkHead;
ppre=student;

max=0;
pmax=linkHead;
premax=linkHead;



while(student != NULL )
{
	
	if(student->total>max) 
	{
		max=student->total;
		pmax=student;
		premax=ppre;
	}	
	ppre=student;
	student=student->next;
	
}		
		
	printf("%d %d\n", pmax->number, pmax->total);
	
	
	if(pmax==linkHead)            //????????????
			linkHead=student->next;
	else premax->next=pmax->next;  //???i??????????????i?????????????????????????????????????????flag?????????????????

		
	i++;	
	


}

	

}
struct student
{
	long num;
	int math;
	int chinese;
	struct student *next;
};

long stu_num;
struct student *max1,*max2,*max3;

struct student *creat(void)
{
	struct student *head,*p1,*p2;
	long n;
	p1=p2=(struct student *)malloc(LEN);
	scanf("%ld%d%d",&p1->num,&p1->math,&p1->chinese);
	head=NULL;
	n=0;
	while(n<stu_num-1)
	{
		n++;
		if(n==1)
			head=p1;
		else
			p2->next=p1;
		p2=p1;
		p1=(struct student *)malloc(LEN);
		scanf("%ld%d%d",&p1->num,&p1->math,&p1->chinese);
	}
	p2->next=p1;
	p1->next=NULL;
	return(head);
}

void Max1(struct student *head,long stu_num)
{
	struct student *q1;
	q1=head;
	max1=head;
	for(;q1!=NULL;)
		if((max1->math+max1->chinese)<(q1->math+q1->chinese))
		{
			max1=q1;
			q1=q1->next;
		}
		else
            q1=q1->next;
	printf("%ld %d\n",max1->num,max1->math+max1->chinese);
}


void Max2(struct student *head,long stu_num)
{
	struct student *q2;
	q2=head;
	if(head!=max1)
		max2=head;
	else
		max2=q2->next;
	for(;q2!=NULL;)
		if((max2->math+max2->chinese)<(q2->math+q2->chinese)&&q2!=max1)
		{
			max2=q2;
			q2=q2->next;
		}
		else
            q2=q2->next;
	printf("%ld %d\n",max2->num,max2->math+max2->chinese);
}


void Max3(struct student *head,long stu_num)
{
	struct student *q3;
	q3=head;
	for(;q3!=NULL;)
		if(q3==max1||q3==max2)
			q3=q3->next;
		else
		{
			max3=q3;
			break;
		}
	q3=head;
	for(;q3!=NULL;)
		if((max3->math+max3->chinese)<(q3->math+q3->chinese)&&q3!=max1&&q3!=max2)
		{
			max3=q3;
			q3=q3->next;
		}
		else
            q3=q3->next;
	printf("%ld %d\n",max3->num,max3->math+max3->chinese);
}


void main()
{
	struct student *head;	
	scanf("%ld",&stu_num);
	head=creat();
	Max1(head,stu_num);
	Max2(head,stu_num);
	Max3(head,stu_num);
}
struct student       
	{
		int num;
		int chi;
		int math;
		int sum;
		struct student *next;
	};

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

	head=p1;
	p2=p1;
	
	for(i=1;i<n;i++)
	{
		p1=(struct student*)malloc(sizeof(struct student));
		scanf("%d %d %d",&p1->num,&p1->chi,&p1->math);
		p1->sum=p1->chi+p1->math;
		p2->next=p1;
		p2=p1;
	}
	p2->next=NULL;

	return(head);
	}
    
	void main()
	{
		struct student *head,*p1;
		struct student *max1,*max2,*max3;
		int n,max;
		
	    scanf("%d",&n);
		
		head=creat(n);
		
		p1=head;
		max=0;		
		while(p1!=NULL)
		{
			if(p1->sum>max)
			{
				max=p1->sum;
				max1=p1;
			}
			p1=p1->next;
		}
		printf("%d %d\n",max1->num,max1->sum);

		p1=head;
		max=0;
		while(p1!=NULL)
		{
			if(p1->sum>max&&p1!=max1)
			{
				max=p1->sum;
				max2=p1;
			}
			p1=p1->next;
		}
		printf("%d %d\n",max2->num,max2->sum);

		p1=head;
		max=0;
		while(p1!=NULL)
		{
			if(p1->sum>max&&p1!=max1&&p1!=max2)
			{
				max=p1->sum;
				max3=p1;
			}
			p1=p1->next;
		}
		printf("%d %d\n",max3->num,max3->sum);
	}


		/*if(n<3)      
		{
			int max=0;                //???????????????????????????p=a?????????...
			if(*/
int main(int argc, char* argv[])
{
    int n,num,math,china,z,i;
	int num1=2,num2=1,num3=0,m1=0,m2=0,m3=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&num);
		scanf("%d",&math);
		scanf("%d",&china);
		z=math+china;
		if(z>num3)
		{
			num1=num2;
			m1=m2;
			num2=num3;
			m2=m3;
			num3=z;
			m3=i;
			
		}
		else if(z>num2)
		{
			num1=num2;
			m1=m2;
			num2=z;
			m2=i;
		}
		else if(z>num1)
		{
			num1=z;
			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 argc, char* argv[])
{
	int n,i,j,ta,tb,ts,tnum;
	int	*a,*b,*s,*num;
	scanf("%d",&n);
	a=(int*)malloc(sizeof(int)*n);
	b=(int*)malloc(sizeof(int)*n);
	s=(int*)malloc(sizeof(int)*n);
	num=(int*)malloc(sizeof(int)*n);
	
	for(i=1;i<=n;i++)
	{
		scanf("%d%d%d",&num[i],&a[i],&b[i]);
		s[i]=a[i]+b[i];
    }
    for(j=0;j<3;j++){
		for(i=n;i>1;i--){
		if(s[i]>s[i-1])
		{
			ta=a[i-1];tb=b[i-1];ts=s[i-1];tnum=num[i-1];
			a[i-1]=a[i];b[i-1]=b[i];s[i-1]=s[i];num[i-1]=num[i];
			a[i]=ta;b[i]=tb;s[i]=ts;num[i]=tnum;
		}
		}		
	}
    printf("%d %d\n%d %d\n%d %d\n",num[1],s[1],num[2],s[2],num[3],s[3]);
	return 0;
}
struct Student
{
    int num;
    int Chi;
    int Math;
    int sum;
};
struct Student stud[100000],temp;
int main()
{
   int n,i,j;
   cin>>n;
   for(i=0;i<n;i++)
   {
       cin>>stud[i].num>>stud[i].Chi>>stud[i].Math;
       stud[i].sum=stud[i].Chi+stud[i].Math;
   }
   if(n==2)
   {
       if(stud[0].sum<stud[1].sum)
       {
               temp=stud[0];
               stud[0]=stud[1];
               stud[1]=temp;
           }
   }
   else
   {
       for(i=0;i<3;i++)
   {
       for(j=n-1;j>i;j--)
       {
           if(stud[j].sum>stud[j-1].sum)
           {
               temp=stud[j];
               stud[j]=stud[j-1];
               stud[j-1]=temp;
           }
       }
   }
   }
   
   if(n==2)
   {
      
     
       cout<<stud[0].num<<' '<<stud[0].sum<<endl;
     
       cout<<stud[1].num<<' '<<stud[1].sum;
   }
   for(i=0;i<2;i++)
   {
       cout<<stud[i].num<<' '<<stud[i].sum<<endl;
   }
   cout<<stud[2].num<<' '<<stud[2].sum;
    return 0;
}
struct point{
           int id,a,b,c;
           }s[100000],tmp;
int main(int argc, char *argv[])
{
    
    int i,n;
    scanf("%d",&n);
    for(i=0;i<n;i++)
	{
        scanf("%d %d %d",&s[i].id,&s[i].a,&s[i].b);
        s[i].c=s[i].a+s[i].b;
    }
	for(i=1;i<n;i++)
	{
		if(s[i].c>s[0].c)
		{
			tmp=s[0];
			s[0]=s[i];
			s[i]=tmp;
		}
	}
	for(i=2;i<n;i++)
	{
		if(s[i].c>s[1].c)
		{
			tmp=s[1];
			s[1]=s[i];
			s[i]=tmp;
		}
	}
	for(i=3;i<n;i++)
	{
		if(s[i].c>s[2].c)
		{
			tmp=s[2];
			s[2]=s[i];
			s[i]=tmp;
		}
	}
	for(i=0;i<3;i++)
	{
		printf("%d %d\n",s[i].id,s[i].c);
	}
  return 0;
}
int main()
{
	int n,i,j;
	cin>>n;
	struct student
	{
		int num;
		int yuwen;
		int shuxue;
		int sum;
	}stu[100000];
	for(i=0;i<n;i++)
	{
		cin>>stu[i].num>>stu[i].yuwen>>stu[i].shuxue;
		stu[i].sum=stu[i].yuwen+stu[i].shuxue;
	}
	int max=0,maxj=0;
	if(n>=3)
	{
	for(i=0;i<n;i++)
	if(stu[i].sum>max)
	{
		max=stu[i].sum;
		maxj=i;
	}
	cout<<stu[maxj].num<<' '<<stu[maxj].sum<<endl;
	stu[maxj].sum=0;max=0;
	for(i=0;i<n;i++)
		if(stu[i].sum>max)
		{
			max=stu[i].sum;
			maxj=i;
		}
		cout<<stu[maxj].num<<' '<<stu[maxj].sum<<endl;
		stu[maxj].sum=0;max=0;
		for(i=0;i<n;i++)
			if(stu[i].sum>max)
			{
				max=stu[i].sum;
				maxj=i;
			}
			cout<<stu[maxj].num<<' '<<stu[maxj].sum<<endl;
	}
	else 
	{
		if(stu[0].sum>stu[1].sum)
			cout<<stu[0].num<<' '<<stu[0].sum<<endl<<stu[1].num<<' '<<stu[1].sum;
		else cout<<stu[1].num<<' '<<stu[1].sum<<endl<<stu[0].num<<' '<<stu[0].sum;
	}
			return 0;
}
struct student
{
	int num;
	int chinese;
	int math;
	struct student * next;
};
int m;
struct student * creat(int n)
{
	struct student * head;
	struct student * p1,*p2;
	m=0;
	p1=p2=(struct student*)malloc(sizeof(struct student));
	scanf("%d%d%d",&p1->num,&p1->chinese,&p1->math);
	head=NULL;
	while(n--)
	{
		m=m+1;
		if(m==1)
			head=p1;
		else
			p2->next=p1;
		p2=p1;
		p1=(struct student *)malloc(sizeof(struct student));
		scanf("%d%d%d",&p1->num,&p1->chinese,&p1->math);
	}
	p2->next=NULL;
	return(head);
}
		struct student * del(struct student * head,int num)
		{
			struct student *p1,*p2;
			p1=head;
			while(num!=p1->num&&p1->next!=NULL)
			{
				p2=p1;
				p1=p1->next;
			}
			if(num==p1->num)
			{
				if(p1==head)
					head=p1->next;
				else
					p2->next=p1->next;
				m=m-1;
			}
			return(head);
		}
int main()
{
	int max=0;
	int n,j;
	scanf("%d",&n);
	struct student *head,*p1,*p2;
	head=creat(n);
	for(j=0;j<3;j++)
	{
 		p1=head;
		p2=head;
		max=0;
		while(p1->next!=NULL)
		{
			if((p1->chinese+p1->math)>max)
			max=p1->chinese+p1->math,p2=p1;
				p1=p1->next;
		}		
		printf("%d %d\n",p2->num,(p2->chinese+p2->math));
		head=del(head,p2->num);
	}
}
void main()
{
struct student{
int i;
int x;
int y;
int m;
struct student *next;
};
int n,j,k;
struct student *head,*p1,*p2,*p0;
scanf("%d",&n);
p1=(struct student*) malloc(LEN);
scanf("%d%d%d",&p1->i,&p1->x,&p1->y);
p1->m=p1->x+p1->y;
p2=(struct student*) malloc(LEN);
scanf("%d%d%d",&p2->i,&p2->x,&p2->y);
p2->m=p2->x+p2->y;
if(p1->m>p2->m)
{head=p1;p1->next=p2;p2->next=0;}
else{p0=p1;p1=p2;p2=p0;head=p1;p1->next=p2;p2->next=0;}
p0=(struct student*) malloc(LEN);
scanf("%d%d%d",&p0->i,&p0->x,&p0->y);
p0->m=p0->x+p0->y;
while((p0->m<=p1->m)&&(p1->next!=0))
{
p2=p1;p1=p1->next;	
}
if(p0->m>p1->m)
{
	if(head==p1) head=p0;else p2->next=p0;
	p0->next=p1;
}
else 
{
	p1->next=p0;p0->next=0;
}
for(j=3;j<n;j++)
{
p0=(struct student*) malloc(LEN);
scanf("%d%d%d",&p0->i,&p0->x,&p0->y);
p0->m=p0->x+p0->y;
for(k=0,p1=head;k<=2;k++)
{if(p0->m>p1->m) break; p1=p1->next;}
if (k==3) continue;
p1=p2=head;
while(p0->m<=p1->m)
{
p2=p1;p1=p1->next;	
}
if(p0->m>p1->m)
{
	if(head==p1) head=p0;else p2->next=p0;
	p0->next=p1;
}
else 
{
	p1->next=p0;p0->next=0;
}
}
for(p1=head,j=0;j<3;j++)
{
	printf("%d %d\n",p1->i,p1->m);
    p1=p1->next;
}
}
struct student
{
	int number;
	int math;
	int chinese;
	int total;
};
int main()
{
	struct student a[100000];
	int n,i,sf=0,ss=0,st=0,f,s,t;
	scanf("%d",&n);
	for (i=0;i<n;i++)
	{
		scanf("%d%d%d",&a[i].number,&a[i].math,&a[i].chinese);
		a[i].total=a[i].math+a[i].chinese;
		if (a[i].total>sf)
		{
			t=s; st=ss;
			s=f; ss=sf;
			f=i; sf=a[i].total;
		}
		else 
			if (a[i].total>ss)
			{
				t=s; st=ss;
				s=i; ss=a[i].total;
			}
			else 
				if (a[i].total>st)
				{
					t=i; st=a[i].total;
				}
	}
	printf("%d %d\n",f+1,sf);
	printf("%d %d\n",s+1,ss);
	printf("%d %d\n",t+1,st);
	return 0;
}
void main()
{
    int n,i,k,max,m,c;
	int a[100000];
	struct student
	{ int num;
	int math;
	int b;
	}stu1;
   
    
	
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&stu1.num,&stu1.math,&stu1.b);
		a[i]=stu1.math+stu1.b;
	}
	
	max=a[0];
	for(i=1;i<n;i++)
	{
		if(a[i]>max)
		{max=a[i];
		k=i;}
	}
	printf("%d %d\n",k+1,a[k]);
	a[k]=0;
	max=a[0];
    for(i=1;i<n;i++)
	{
		if(a[i]>max)
		{max=a[i];
		m=i;}
	}
    printf("%d %d\n",m+1,a[m]);
	a[m]=0;
	max=a[0];
    for(i=1;i<n;i++)
	{
		if(a[i]>max)
		{max=a[i];
		c=i;}
	}
    printf("%d %d",c+1,a[c]);
}
int main()
{
    
    struct student
    {
       int id;
       int chinese;
       int math;
       int total;
       };
       
    long int n;
    int temp;
    int max = 0, max_1 = 0, max_2 = 0;
    struct student *p, *p_ori, *p_end, *q;
    struct student *p_max, *p_max_1, *p_max_2;
    
    scanf("%ld",&n);
    p = (struct student *)malloc(n*sizeof(struct student));
    p_ori = p;
    p_end = p+n;
    
    for (;p<p_end;p++)
    {
        scanf("%d",&(p->id));
        scanf("%d",&(p->chinese));
        scanf("%d",&(p->math));
        p->total = p->chinese + p->math;
        }
        
    p = p_ori;
    for (;p<p_end;p++)
    {
        if (p->total > max) 
        { max = p->total;
          p_max = p;}
        }
    
    p=p_ori;    
    for (;p<p_end;p++)
    {
        if (p->total > max_1 && p!=p_max) 
        { max_1 = p->total;
          p_max_1 = p;}
        }
        
    p=p_ori;    
    for (;p<p_end;p++)
    {
        if (p->total > max_2 && p!=p_max && p!=p_max_1) 
        { max_2 = p->total;
          p_max_2 = p;}
        }
        

    printf("%d %d\n",p_max->id,p_max->total);
    printf("%d %d\n",p_max_1->id,p_max_1->total);
    printf("%d %d\n",p_max_2->id,p_max_2->total);
        
getchar();
getchar();
    }
struct data
{
	int num[100000],a[100000],b[100000],sum[100000];
}data;

int main(int argc, char* argv[])
{
	int i,n,x=0,y=0,z=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&data.num[i],&data.a[i],&data.b[i]);
		data.sum[i]=data.a[i]+data.b[i];
	}
	for(i=0;i<n;i++)
	{
		if(data.sum[i]>data.sum[x])
		{
			z=y;
			y=x;
			x=i;
			continue;
		}
		if(data.sum[i]<=data.sum[x]&&data.sum[i]>data.sum[y])
		{
			z=y;
			y=i;
			continue;
		}
		if(data.sum[i]<=data.sum[y]&&data.sum[i]>data.sum[z])
			z=i;
	}
	printf("%d %d\n",data.num[x],data.sum[x]);
	printf("%d %d\n",data.num[y],data.sum[y]);
	printf("%d %d",data.num[z],data.sum[z]);
}
struct student
{
	int ID;
	int yuwen;
	int shuxue;
	int zongfen;
};

int main()
{
	int n,i,j,e;
	scanf("%d",&n);
	struct student*stu=(struct student*)malloc(sizeof(struct student)*n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&stu[i].ID,&stu[i].yuwen,&stu[i].shuxue);
		stu[i].zongfen=stu[i].yuwen+stu[i].shuxue;
	}
	for(i=1;i<4;i++)
	{
		for(j=0;j<n-i;j++)
		{
			if(stu[j].zongfen>=stu[j+1].zongfen)
			{
				e=stu[j].zongfen;
				stu[j].zongfen=stu[j+1].zongfen;
				stu[j+1].zongfen=e;
				e=stu[j].ID;
				stu[j].ID=stu[j+1].ID;
				stu[j+1].ID=e;
			}
		}
	}
	
	printf("%d %d\n%d %d\n%d %d\n",stu[n-1].ID,stu[n-1].zongfen,stu[n-2].ID,stu[n-2].zongfen,stu[n-3].ID,stu[n-3].zongfen);
	return 0;
}