semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
struct student
{
int id;
int ch;
int math;
};
void main()
{
struct student stu[100000];
int n,i,j,sum=0,id1=0,flag=0;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d %d %d",&stu[i].id,&stu[i].ch,&stu[i].math);
for(i=0;i<3;i++)
{
for(j=0;j<n;j++)
{
if((stu[j].ch+stu[j].math)>sum)
{sum=stu[j].ch+stu[j].math;
id1=stu[j].id;
flag=j;}
}
printf("%d %d\n",id1,sum);
sum=0;
id1=0;
stu[flag].ch=0;
stu[flag].math=0;
flag=0;
}
}
int main()
{
	struct{
		int n;
		int a;
		int b;
	}n[100000];
	int m,i,sum[100000],first,second,third,d,e,f;
	scanf("%d",&m);
	for(i=0;i<m;i++)
	{
		scanf("%d",&n[i].n);
		scanf("%d",&n[i].a);
		scanf("%d",&n[i].b);
		sum[i]=n[i].a+n[i].b;
	}
	if(sum[0]>sum[1]&&sum[0]>sum[2]&&sum[1]>sum[2])
	{
		first=sum[0];
		second=sum[1];
		third=sum[2];
		d=1;
		e=2;
		f=3;
	}
	else if (sum[0]>sum[1]&&sum[1]<sum[2]&&sum[0]>sum[2])
	{
		first=sum[0];
		second=sum[2];
		third=sum[1];
		d=1;
		e=3;
		f=2;
	}
	else if (sum[0]<sum[1]&&sum[1]>sum[2]&&sum[0]>sum[2])
	{
		first=sum[1];
		second=sum[0];
		third=sum[2];
		d=2;
		e=1;
		f=3;
	}
    else if (sum[0]<sum[1]&&sum[1]>sum[2]&&sum[0]<sum[2])
	{
		first=sum[1];
		second=sum[2];
		third=sum[0];
		d=2;
		e=3;
		f=1;
	}
    else if (sum[0]<sum[1]&&sum[1]<sum[2]&&sum[0]<sum[2])
	{
		first=sum[2];
		second=sum[1];
		third=sum[0];
		d=3;
		e=2;
		f=1;
	}
    else if (sum[0]>sum[1]&&sum[1]<sum[2]&&sum[0]<sum[2])
	{
		first=sum[2];
		second=sum[0];
		third=sum[1];
		d=3;
		e=1;
		f=2;
	}
	for(i=3;i<m;i++)
	{
		if(sum[i]>first)
		{
			third=second;
			second=first;
			first=sum[i];
			f=e;
			e=d;
			d=i+1;
		}
		else if (sum[i]<=first&&sum[i]>second)
		{
			third=second;
			second=sum[i];
			f=e;
			e=i+1;
		}
		else if (sum[i]<=second&&sum[i]>third)
		{
			third=sum[i];
			f=i+1;
		}
	}
	printf("%d %d\n",d,first);
	printf("%d %d\n",e,second);
	printf("%d %d\n",f,third);
	return 0;
}
int main()
{
    int a[100001][5];
    int i , j , n, k = 3, max = 0, t=0;
    scanf( "%d",&n );
    for( i = 1 ;i <= n;i++ )
    {scanf("%d%d%d",&a[i][1], &a[i][2], &a[i][3]);
     a[i][4] = a[i][2]  +  a[i][3];
    }
     while( k-- )
     {
     for( i = 1;i <= n ;i++ )
     {
        if( a[i][4] > max  )
        {max = a[i][4] , t = i;} 
     } 
       printf( "%d %d\n",t,a[t][4] );
       a[t][4] = 0;
       max = 0; 
     }
}
int main()
{
	int num[3], chinese[100000], math[100000], sum[100000];
	int m, i, n;
	cin >> n;
	for (i = 0; i < n; i ++)
	{
		cin >> m >> chinese[i] >> math[i];
		sum[i] = chinese[i] + math[i];
	}
	int largest = 0;
	for (i = 0; i < 3; i ++)
	{
		largest = 0;
		for (int j = 0; j < n; j ++)
			if (sum[j] > largest)
			{
				largest = sum[j];
				num[i] = j;
			}
		cout << num[i] + 1 << " " << sum[num[i]] << endl;
		sum[num[i]] = 0;
	}
	return 0;
}
struct Student{//?????
	int nID,nChinese,nMath;
};
void main(){
	int n,i,a1,a2,a3,t1,t2,t3,t;//a1,a2,a3????????ID?t1,t2,t3????
	struct Student students;
	t1=0;
	t2=0;
	t3=0;
	a1=0;
	a2=0;
	a3=0;
	scanf("%d",&n);
	for (i=1;i<=n;i++){
		scanf("%d%d%d",&students.nID,&students.nChinese,&students.nMath);
		t=students.nChinese+students.nMath;
		if (t>t1){//????????????
			t3=t2;
			a3=a2;   //???????????
			t2=t1;
			a2=a1;   //??????????? 
			t1=t;
			a1=students.nID;
		}else
			if (t>t2){//?????????????????????
				t3=t2;
				a3=a2;//???????????
				t2=t;
				a2=students.nID;
			}else
				if (t>t3){
					t3=t;
					a3=students.nID;
				}
	}
	printf("%d%s%d\n",a1," ",t1);
	printf("%d%s%d\n",a2," ",t2);
	printf("%d%s%d\n",a3," ",t3);
}
struct stu
	{
		int num;
		int yuwen;
		int shuxue;
		int sum;
	}score[100000];
int main()
{
	int n,i,a,b,c,a1,b1,c1;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d%d",&score[i].num,&score[i].yuwen,&score[i].shuxue);
		score[i].sum=score[i].shuxue+score[i].yuwen;
	}a=0;
	b=0;
	c=0;
	a1=0;
	b1=0;
	c1=0;
	for(i=0;i<n;i++){
		if(score[i].sum>a){
		    c=b;
			b=a;
			a=score[i].sum;
			c1=b1;
			b1=a1;
			a1=score[i].num;
		}else if(score[i].sum>b){
			c=b;
			b=score[i].sum;
			c1=b1;
			b1=score[i].num;
		}else if(score[i].sum>c){
			c=score[i].sum;
			c1=score[i].num;
		}
	}printf("%d %d\n%d %d\n%d %d",a1,a,b1,b,c1,c);
	return 0;
}
struct stu
{
 int a;
 int b;
 int c;
 struct stu *next;
};
void main()
{
 int i,j,n,t,sum[100000];
 struct stu *head,*p1,*p2;
 scanf("%d",&n);
 p1=(struct stu*)malloc(sizeof(struct stu));
     scanf("%d%d%d",&(p1->a),&(p1->b),&(p1->c));
     sum[0]=p1->b+p1->c;
     head=p1;
	 p2=p1;
 for(i=1;i<n;i++)
  {
     p1=(struct stu*)malloc(sizeof(struct stu));
     p2->next=p1;
     scanf("%d%d%d",&(p1->a),&(p1->b),&(p1->c));
     sum[i]=p1->b+p1->c;
	 p2=p1;
   }
   p2->next=NULL;
  for(i=0;i<3;i++)
   for(j=i+1;j<n;j++)
    if(sum[i]<sum[j])
     {
      t=sum[i];
      sum[i]=sum[j];
      sum[j]=t;
	}
  for(i=0;i<3;i++)
  {
   p1=head;
   while(p1->b+p1->c!=sum[i]&&p1)
    {
     p1=p1->next;
    }
   if(p1)
   {
   printf("%d %d\n",p1->a,sum[i]);
   p1->b=0;
   p1->c=0;
   }
  }
}
int a[100000][3],s[100000],x=0,y=0,z=0,x1=0,y1=0,z1=0;
int main()
{
   int n,i,j;
   scanf("%d",&n);
   for (i=1;i<=n;i++)
   {
	   for (j=0;j<3;j++)
	   {scanf("%d",&a[i][j]);}
		   s[i]=a[i][1]+a[i][2];
   }
   for (i=1;i<=n;i++)
   {
	   if (s[i]>x)
	     { x=s[i];
x1=a[i][0];}
   }
   
 for (i=1;i<=n;i++)
 {
	 if(s[i]>y&&i!=x1)
 { y=s[i];
y1=a[i][0];}
 }
 
for  (i=1;i<=n;i++)
{
	 if(s[i]>z&&i!=x1&&i!=y1)
  {z=s[i];
z1=a[i][0];  }
 }
 
 printf("%d %d\n",x1,x);
    printf("%d %d\n",y1,y);
    printf("%d %d\n",z1,z);

	return 0;
}
struct student
{
	int num;
	int chinese;
	int math;
	int sum;
};
void main()
{
	int n,i,j;
	struct student stu[100000];
	struct student stud;
	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=i+1;j<n;j++)
		{
			if(stu[i].sum<stu[j].sum)
			{
				stud=stu[i];
				stu[i]=stu[j];
				stu[j]=stud;
			}
		}
	}
	for(i=0;i<3;i++)
	{
		printf("%d %d\n",stu[i].num,stu[i].sum);
	}
}
int main()
{
	int n;
	scanf("%d",&n);
	struct student{
		int num;
		int chi;
		int math;
		int sum;
	};
	struct student*fig;
	fig=(struct student*)malloc(sizeof(student)*n);
	int i,a=0,b=0,c=0,numa=0,numb=0,numc=0;
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&(fig+i)->num,&(fig+i)->chi,&(fig+i)->math);
		(fig+i)->sum=(fig+i)->chi+(fig+i)->math;
		if((fig+i)->sum>a)
		{
			c=b;
			numc=numb;
			b=a;
			numb=numa;
			a=(fig+i)->sum;
			numa=(fig+i)->num;
		}
		else if((fig+i)->sum>b)
		{
			c=b;
			numc=numb;
			b=(fig+i)->sum;
			numb=(fig+i)->num;
		}
		else if((fig+i)->sum>c)
		{
			c=(fig+i)->sum;
			numc=(fig+i)->num;
		}
	}
	printf("%d %d\n%d %d\n%d %d\n",numa,a,numb,b,numc,c);
	return 0;

}
int main()
{
	int n,i;
	int fir=0,sec=0,thi=0;
	int fir_n=0,sec_n=0,thi_n=0;
	struct
	{
		int num;
		int ma;
		int cn;
		int score;
	}s;

	scanf("%d",&n);

	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&s.num,&s.ma,&s.cn);
		s.score=s.ma+s.cn;

		if(s.score>fir)
		{
			thi=sec;
			thi_n=sec_n;
			sec=fir;
			sec_n=fir_n;
			fir=s.score;
			fir_n=s.num;
		}

       else if(s.score>sec)
		{
			thi=sec;
			thi_n=sec_n;
			sec=s.score;
			sec_n=s.num;
		}
	   else if(s.score>thi)
		{
			thi=s.score;
			thi_n=s.num;
		}
	}

	printf("%d %d\n",fir_n,fir);
	printf("%d %d\n",sec_n,sec);
	printf("%d %d\n",thi_n,thi);


	return 0;
}
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(int)*4);
 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;
}
int pfCompare( const void*elem1, const void*elem2)
{
    int *p1,*p2;
    p1=(int*)elem1;
    p2=(int*)elem2;
    return (*p2)-(*p1);
}
int main()
{
    int n;
    scanf("%d",&n);
    int a[n],b[n],c[n],d[n],e[n];
    int i;
    for(i=0;i<n;i++)
    {
                    scanf("%d %d %d",&a[i],&b[i],&c[i]);
                    d[i]=b[i]+c[i];
                    e[i]=d[i];
    }
    qsort(e,n,4,pfCompare);
    for(int k=0;k<3;k++)
    {
            for(i=0;i<n;i++)
            if(d[i]==e[k])
            {printf("%d %d\n",a[i],d[i]);
            d[i]=0;
            break;
            }
    }
    getchar();getchar();
}
struct stu
{
	int num;
	struct stu *next;	
};

void main()
{
	int i=0,n,a,b,score,first=0,second=0,third=0;
	struct stu *head,*p,*p1,*p2,*p3;
	scanf("%d",&n);
	head=p=(struct stu *)malloc(sizeof(struct stu));
	while(i++<n)
	{
		scanf("%d %d %d",&(*p).num,&a,&b);
		score=a+b;
if(score>first)
		{
			third=second;second=first;first=score;
			p3=p2;p2=p1;p1=p;
		}
		else if(score>second){third=second;second=score;p3=p2;p2=p;}
		else if(score>third){third=score;p3=p;}
		p=(*p).next=(struct stu *)malloc(sizeof(struct stu));
	}
	printf("%d %d\n%d %d\n%d %d\n",(*p1).num,first,(*p2).num,second,(*p3).num,third);
}
void main()
{
	int n,i;
	int diyi,dier,disan;
	diyi=0;
	dier=0;
	disan=0;
	struct student
	{
		int num;
		int yuwen;
		int shuxue;
		int sum;
	}stu[99999];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&stu[i].num,&stu[i].yuwen,&stu[i].shuxue);
		stu[i].sum=stu[i].yuwen+stu[i].shuxue;
	}
	for(i=0;i<n;i++)
	{
		if(stu[i].sum>stu[diyi].sum){diyi=i;}
	}
	for(i=0;i<n;i++)
	{
		while(i!=diyi)
		{
			dier=i;
			break;
		}
		break;
	}
    for(i=0;i<n;i++)
	{
		if(i!=diyi)
		{
		if(stu[i].sum>stu[dier].sum){dier=i;}
		}
	}
	for(i=0;i<n;i++)
	{
		while(i!=diyi && i!=dier)
		{
			disan=i;
			break;
		}
		break;
	}
	for(i=0;i<n;i++)
	{
		if(i!=diyi && i!=dier)
		{
		if(stu[i].sum>stu[disan].sum){disan=i;}
		}
	}
	printf("%d %d\n",diyi+1,stu[diyi].sum);
	printf("%d %d\n",dier+1,stu[dier].sum);
	printf("%d %d\n",disan+1,stu[disan].sum);
}
struct grade
{
	char ID[20];
	int math,cn;
};

int main(){
	int n,i,j,max,m;
	int *s;
struct grade stu[100000];
	scanf("%d",&n);
	s=(int*)malloc(n*sizeof(int));
	if(n==1){
		scanf("%s %d %d",stu[0].ID,&stu[0].math,&stu[0].cn);
		printf("%s %d",stu[0].ID,stu[0].math+stu[0].cn);
	}
	else if(n==2){
		scanf("%s %d %d",stu[0].ID,&stu[0].math,&stu[0].cn);
		scanf("%s %d %d",stu[1].ID,&stu[1].math,&stu[1].cn);
		if(stu[0].math+stu[0].cn>stu[1].math+stu[1].cn){
			printf("%s %d\n",stu[0].ID,stu[0].math+stu[0].cn);
			printf("%s %d\n",stu[1].ID,stu[1].math+stu[1].cn);
		}else{
			printf("%s %d\n",stu[0].ID,stu[0].math+stu[0].cn);
			printf("%s %d\n",stu[1].ID,stu[1].math+stu[1].cn);
		}
	}
	else if(n>=2){
		for(i=0;i<n;i++){
			scanf("%s %d %d",stu[i].ID,&stu[i].math,&stu[i].cn);
			s[i]=stu[i].math+stu[i].cn;
		}
		for(i=1;i<4;i++){
			max=s[0];
			for(j=1;j<n;j++){
				if(s[j]>max){
					max=s[j];
					m=j;
				}
			}
			printf("%s %d\n",stu[m].ID,max);
			s[m]=0;
		}
	}
	return 0;
}
int main()
{
	struct
	{
		int number;
		float score1;
		float score2;
		float score3;

	}stu[100000],temp;
	int n,i,j;
	cin>>n;
	for(i=0;i<=n-1;i++)
		{
		cin>>stu[i].number>>stu[i].score1>>stu[i].score2;
		stu[i].score3=stu[i].score2+stu[i].score1;
		}
	for(i=n-1;i>=n-3;i--)
		for(j=n-1;j>=n-i;j--)
			if(stu[j-1].score3<stu[j].score3)
			{
				temp=stu[j];
				stu[j]=stu[j-1];
				stu[j-1]=temp;
			}
	cout<<stu[0].number<<" "<<stu[0].score3<<endl;
	cout<<stu[1].number<<" "<<stu[1].score3<<endl;
	cout<<stu[2].number<<" "<<stu[2].score3;
	return 0;
}
struct student
{
    int num;
    int yw;
    int sx;
};
int main()
{
    int n,i,x=0,y=0,z=0;
    scanf("%d",&n);
    struct student a[n];
    int b[n];
    for(i=0;i<n;i++)
        {
            scanf("%d%d%d",&a[i].num,&a[i].yw,&a[i].sx);
            b[i]=a[i].yw+a[i].sx;
        }
    for(i=1;i<n;i++)
        {
            if(b[x]<b[i])
                x=i;
        }
    printf("%d %d\n",a[x].num,b[x]);
    for(i=1;i<n;i++)
        {
            if(i==x) continue;
            if(b[y]<b[i])
                y=i;
        }
    printf("%d %d\n",a[y].num,b[y]);
    for(i=1;i<n;i++)
        {
            if(i==x) continue;
            if(i==y) continue;
            if(b[z]<b[i])
                z=i;
        }
    printf("%d %d\n",a[z].num,b[z]);
    getchar();
    getchar();
}
void main()
{
	struct student
	{
	char a[6];
	int c;
	int m;
	int s;
	struct student * next;
	};
	struct student * head;
	struct student * p1,* p2;
	struct student first={"",0,0,0,0};
	struct student second={"",0,0,0,0};
	struct student third={"",0,0,0,0};
	int n,i,j;
	char ch;
	scanf("%d",&n);
	p1=p2=(struct student * )malloc(LEN);
	for(j=0;j<6;j=j+1)
		p1->a[j]='\0';
	getchar();
	for(j=0;(ch=getchar())!=' ';j=j+1)
		p1->a[j]=ch;
	scanf("%d%d",&p1->c,&p1->m);
	p1->s=p1->c+p1->m;
	head=0;
	for(i=1;i<n;i=i+1)
	{
		if(i==1)
			head=p1;
		else
			p2->next=p1;
		p2=p1;
		p1=(struct student * )malloc(LEN);
		for(j=0;j<6;j=j+1)
			p1->a[j]='\0';
		getchar();
		for(j=0;(ch=getchar())!=' ';j=j+1)
			p1->a[j]=ch;
		scanf("%d%d",&p1->c,&p1->m);
		p1->s=p1->c+p1->m;
	}
	p2->next=0;
	for(p1=head;p1!=0;p1=p1->next)
	{
		if(p1->s>first.s)
		{
			third=second;
			second=first;
			first=* p1;
		}
		else if(p1->s>second.s)
		{
			third=second;
			second=* p1;
		}
		else if(p1->s>third.s)
		{
			third=* p1;
		}
		else 
			continue;
	}
	printf("%s %d\n",first.a,first.s);
	printf("%s %d\n",second.a,second.s);
	printf("%s %d\n",third.a,third.s);
}
int main()
{
	int n,i,j,k,l,sum[100001],temp=0;
	cin>>n;
	struct student
	{
		int ID;
		int chinese;
		int math;
	}person[100001];//???????,??ID?????????
	for(i=1;i<=n;i++)
	{
		cin>>person[i].ID>>person[i].chinese>>person[i].math;
		sum[i]=person[i].chinese+person[i].math;//????
	}
	for(i=1;i<=n;i++)
	{
		if(sum[i]>temp)
		{
			temp=sum[i];
			j=i;//?????
		}
	}
	temp=0;
	for(i=1;i<=n;i++)
	{
		if(sum[i]>temp&&i!=j)//???
		{
			temp=sum[i];
			k=i;
		}
	}
temp=0;
	for(i=1;i<=n;i++)
	{
		if(sum[i]>temp&&i!=j&&i!=k)//???
		{
			temp=sum[i];
			l=i;
		}
	}
	cout<<person[j].ID<<" "<<sum[j]<<endl;
	cout<<person[k].ID<<" "<<sum[k]<<endl;
	cout<<person[l].ID<<" "<<sum[l]<<endl;
	return 0;
}
void main()
{
	int n,i,j,t;
	struct score
	{int num;
	 int verbal;
	 int math;
	 int sum;
	};
	struct score a[4];
	scanf("%d",&n);
	for(i=0;i<=2;i++)
	{
		scanf("%d%d%d",&a[i].num,&a[i].verbal,&a[i].math);
		a[i].sum=a[i].verbal+a[i].math;
	}
	for(i=0;i<=1;i++)
		for(j=1;j<=2-i;j++)
		{
			if(a[i].verbal+a[i].math<a[i+j].verbal+a[i+j].math)
			{
				t=a[i].num;
				a[i].num=a[i+j].num;
				a[i+j].num=t;
				t=a[i].sum;
				a[i].sum=a[i+j].sum;
				a[i+j].sum=t;
			}
		}
	for(i=3;i<n;i++)
	{
		scanf("%d%d%d",&a[3].num,&a[3].verbal,&a[3].math);
		if(a[3].verbal+a[3].math>a[0].sum)
		{
			t=a[1].num;
			a[1].num=a[0].num;
			a[2].num=t;
			a[0].num=a[3].num;
			t=a[1].sum;
			a[1].sum=a[0].sum;
			a[2].sum=t;
			a[0].sum=a[3].verbal+a[3].math;
		}
		else if(a[3].verbal+a[3].math>a[1].sum)
		{
			a[2].num=a[1].num;
			a[1].num=a[3].num;
			a[2].sum=a[1].sum;
			a[1].sum=a[3].verbal+a[3].math;
		}
		else if(a[3].verbal+a[3].math>a[2].sum)
		{
			a[2].num=a[3].num;
			a[2].sum=a[3].verbal+a[3].math;
		}
	}
	for(i=0;i<=2;i++)
		printf("%d %d\n",a[i].num,a[i].sum);
}
struct stu1
{
	long num;
	int score1;
	int score2;
	struct stu1 *next;
};

struct stu1 *creat(void)
{
	int n,i=1;
	
	struct stu1 *h;
	
	struct stu1 *q1,*q2;
	scanf("%d",&n);

	q2=q1=(struct stu1 *)malloc(LEN1);
	
	h=NULL;
	while(i<=n)
	{
		scanf("%ld %d %d",&q1->num,&q1->score1,&q1->score2);
		
		
		if(i==1){h=q1;}
		else{q2=q1;}
		if(i!=n)
		{
		    
		    q1=q2->next=(struct stu1 *)malloc(LEN1);
		}
		else {q1->next=NULL;}
		i++;
	}
	return(h);
}

struct stu1 *turn(struct stu1 *h)
{
	int t=1;
	struct stu1 *p1,*p2;
	int m,n,w;
	for(p1=h,t=1;p1->next!=NULL,t<=3;p1=p1->next,t++)
	{
		p2=p1->next;
		while(p2!=NULL)
		{
			if((p1->score1+p1->score2)<(p2->score1+p2->score2))
			{
				m=p1->num;n=p1->score1;w=p1->score2;
				p1->num=p2->num;p1->score1=p2->score1;p1->score2=p2->score2;
				p2->num=m;p2->score1=n;p2->score2=w;
			}
			p2=p2->next;
		}
		printf("%ld %d\n",p1->num,(p1->score1+p1->score2));
	}
	return(h);
}
/*void print(struct stu1 *h)
{
	int t=1;
	struct stu1 *p;
	p=h;
	for(t=1;t<=3;t++)
	{
		printf("%ld %d\n",p->num,(p->score1+p->score2));
		p=p->next;
	}
}*/
void main()
{
	struct stu1 *ip/*,*is*/;
	ip=creat();
	/*is=*/turn(ip);
	/*print(is);*/
}
main()
{
    struct student
    {int num;
     int sc;
     int sm;
     int score;
    } student[100001];
    int n,i,j,k,m;
    scanf("%d",&n);
    for(i=1;i<=n;i++) {scanf("%d %d %d",&student[i].num,&student[i].sc,&student[i].sm);}
    for(i=1;i<=n;i++) {student[i].score=(student[i].sc+student[i].sm);}
    int x,y,z,r,s,t,a,b,d;
    a=1;
    b=1;
    d=1;
    for(i=n;i>=1;i--) if(student[i].score>=a) {a=student[i].score;x=i;}
    for(i=n;i>=1;i--) 
    {
                      if((i!=x)&&(student[i].score>=b)) {b=student[i].score;y=i;}
    }
    for(i=n;i>=1;i--)
    {
                      if((i!=x)&&(i!=y)&&(student[i].score>=d)) {d=student[i].score;z=i;}
    }
    
    printf("%d %d\n%d %d\n%d %d",student[x].num,student[x].score,student[y].num,student[y].score,student[z].num,student[z].score);
}
int main(int argc, char* argv[])
{
	int i;
	long n;
	int sum[100000];
	int max=0,second=0,third=0;
	int a=0,b=0,c=0;
	scanf("%d",&n);
	struct student
	{
		int id;
		int chi;
		int math;
	};
	struct student wangchong[100000];
	for (i=0;i<n;i++)
	{
		scanf("%d%d%d",&wangchong[i].id,&wangchong[i].chi,&wangchong[i].math);
		sum[i]=wangchong[i].chi+wangchong[i].math;
		if (sum[i]>third)
		{
			if (sum[i]<=second)
			{
				third=sum[i];
		        c=i+1;
			}
			else
			{
				if (sum[i]<=max)
				{
					third=second;
					second=sum[i];
					c=b;
					b=i+1;
				}
				else
				{
					third=second;
					c=b;
					second=max;
					b=a;
					max=sum[i];
					a=i+1;
				}
			}
		}
	}
	printf("%d %d\n%d %d\n%d %d\n",a,max,b,second,c,third);
	return 0;
}
struct linknode *CreateLinkList();
void DisplayLinkList(struct linknode *linklist1);
void qiansan(struct linknode *linklist2);
struct linknode
{
	int id;
	int chinese;
	int math;
	int total;
	int mark;
	struct linknode *next;
};
int main()
{
	qiansan(CreateLinkList());

}
struct linknode *CreateLinkList()
{
	long n,i;
	struct linknode *head,*p;
	scanf("%ld",&n);
	head=(struct linknode *)malloc(sizeof(struct linknode));
	p=head;
	if (p==NULL)
	{
		printf("fail");
		exit(-1);
	}
	for(i=1;i<=n;i++)
	{
		scanf("%d %d %d",&p->id,&p->chinese,&p->math);
		p->total=p->chinese+p->math;
		p->mark=0;
		if (i==n)
			p->next=NULL;
		else
		{
			p->next=(struct linknode *)malloc(sizeof(struct linknode));
			p=p->next;
		}
	}
	return head;
}
void  qiansan(struct linknode *linklist2)
{
   struct linknode *head,*p,*max;

   head=linklist2;
   p=head;
   max=(struct linknode *)malloc(sizeof(struct linknode));
   int j;
   for (j=1;j<=3;j++)
   {
	   p=head;
	   max->total=0;
	   while (p!=NULL)
	   {
		   if (p->total>max->total&&p->mark==0)
		   {
               max=p;
		   }
		   p=p->next;
	   }
	   max->mark=1;
	   printf("%d %d\n",max->id,max->total);
	}
}
struct student
{
	int num;
	int Chinese;
	int math;
	int sum;
};

void main()
{
	int i,n,p,q,r,b=0,c=0,d=0;
	struct student a[100000];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&a[i].num,&a[i].Chinese,&a[i].math);
		a[i].sum=a[i].Chinese+a[i].math;
		if(i==0)
			p=q=r=a[i].sum;
		else
		{
			if(a[i].sum>p)
			{
				r=q;
				q=p;
				p=a[i].sum;
				d=c;
				c=b;
				b=i;
			}
			else if(a[i].sum>q)
			{
				r=q;
				q=a[i].sum;
				d=c;
				c=i;
			}
			else if(a[i].sum>r)
			{
				r=a[i].sum;
				d=i;
			}
		}
	}
	printf("%d %d\n%d %d\n%d %d\n",a[b].num,a[b].sum,a[c].num,a[c].sum,a[d].num,a[d].sum);
}
struct student
{
        int num;
        int sum;
};

int main()
{

   int n,i,j,t,a,b,m;
   int tempSum;
   int tempMax;
   int rank[3]={0};
   scanf("%d",&n);
   struct student * stu;
   stu = (struct student *)malloc(sizeof(struct student) * n);
   for(i=0;i<n;i++)
   {
        tempSum = 0;
           scanf("%d",&stu[i].num);
           stu[i].sum = 0;
           for(j=0;j<2;j++){
            scanf("%d",&tempSum);
            stu[i].sum += tempSum;
           }
   }
   for(b=0;b<3;b++)
   {
       tempMax = 0;
       for(a=b;a<n;a++)
       {
           if(stu[a].sum > tempMax){
            tempMax = stu[a].sum;
            rank[b] = a;
           }
       }
       t = stu[b].num;
       stu[b].num = stu[rank[b]].num;
       stu[rank[b]].num = t;
       t = stu[b].sum;
       stu[b].sum = stu[rank[b]].sum;
       stu[rank[b]].sum = t;
   }
   for(a=0;a<3;a++)
   printf("%d %d\n",stu[a].num,stu[a].sum);

  return 0;
}
struct Stu{
	int stuID;
	int mark;
}stu[3]={0};

int compare(const void *p1,const void *p2)
{
	struct Stu *a;
	struct Stu *b;
	a=(struct Stu*)p1;
	b=(struct Stu*)p2;
	if(a->mark>b->mark) return -1;
	if(a->mark<b->mark) return 1;
	if(a->mark==b->mark) return 0;
}



void main(){
	int n,i;
	int ID,chi,math;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d%d%d",&ID,&chi,&math);
		if(chi+math>stu[2].mark) {
			stu[2].mark=chi+math;
			stu[2].stuID=ID;
		}
		qsort(stu,3,sizeof(struct Stu),compare);
	}
	for(i=0;i<3;i++)
		printf("%d %d\n",stu[i].stuID,stu[i].mark);
}
struct student
   {
      int n;
      int y;
      int s;
   };
int cmp(const void *a,const void *b)
{
return(((struct student *)b)->y > ((struct student *)a)->y?1:-1);
}

main()
{    
    int num;
    scanf("%d",&num);
    struct student s[100000];
    for(int i=0;i<num;i++)
    {
            scanf("%d %d %d",&s[i].n,&s[i].y,&s[i].s);
            s[i].y=s[i].y+s[i].s;        
    }
    qsort(s,num,sizeof(s[0]),cmp);
    for(int i=0;i<3;i++)
     printf("%d %d\n",s[i].n,s[i].y);      
}
struct student
{
	int id;
	int cs;
	int ms;
	int s;
	struct student *next;
};
void main()
{
	int n,i,m=0;
	scanf("%d",&n);
	struct student *head,*p1,*p2;
	p1=p2=(struct student *)malloc(LEN);
	scanf("%d %d %d",&p1->id,&p1->cs,&p1->ms);
	p1->s=p1->cs+p1->ms;
	head=NULL;
	while(p1->id!=n)
	{
		m=m+1;
		if(m==1) head=p1;
		else
		p2->next=p1;
		p2=p1;
		p1=(struct student *)malloc(LEN);
		scanf("%d %d %d",&p1->id,&p1->cs,&p1->ms);
		p1->s=p1->cs+p1->ms;
	}
	p2->next=NULL;
	for(i=0;i<3;i++)
	{
		p1=p2=head;
		do
		{
			p2=p2->next;
			if(p1->s<p2->s)
				p1=p2;
		}while(p2->next!=NULL);
		printf("%d %d\n",p1->id,p1->s);
		p1->s=-1;
	}
}
struct stu
{int n;
 int a;
 int m;
 struct stu *next;
};
int n,l;
struct stu *creat(void)
{
	struct stu *head;
	struct stu *p,*q;
	n=0;
	p=q=(struct stu *)malloc(Len);
	scanf("%d %d %d",&p->n,&p->a,&p->m);
	head=Null;
	for(;n<l-1;)
	{
		n++;
		if(n==1) head=p;
		else q->next=p;
		q=p;
		p=(struct stu *)malloc(Len);
		scanf("%d %d %d",&p->n,&p->a,&p->m);
	}
	q->next=Null;
	return(head);
}
void main()
{
	int s=0;
	struct stu *p,*q,*c,*d,*head;
	scanf("%d",&l);
	head=p=q=creat();
	for(;;)
	{
		if((p->m+p->a)>s) 
		{
			s=p->m+p->a;
			c=p;
			d=q;
		}
		q=p;
		p=q->next;
		if(p->next==Null) break;
	}
	printf("%d %d\n",c->n,s);
	if(d==head)
		head=((c->next)->next);
	else
		d->next=c->next;
	p=q=head;
	s=0;
	for(;;)
	{
		if((p->m+p->a)>s) 
		{
			s=p->m+p->a;
			c=p;
			d=q;
		}
		q=p;
		p=p->next;
		if(p->next==Null) break;
	}
	printf("%d %d\n",c->n,s);
	if(d==head)
		head=p=q=((c->next)->next);
	else
		d->next=c->next;
	p=q=head;
	s=0;
	for(;;)
	{
		if((p->m+p->a)>s) 
		{
			s=p->m+p->a;
			c=p;
			d=q;
		}
		q=p;
		p=p->next;
		if(p->next==Null) break;
	}
	printf("%d %d\n",c->n,s);
}
struct student
{
	int num;
	int chi;
	int math;
int sum;
};
void main()
{
	int n,i,j,max;
	struct student t,*s;
	scanf("%d",&n);
	s=(struct student *)malloc(n*sizeof(struct student));
	for(i=0;i<n;i++)
	{	scanf("%d%d%d",&s[i].num,&s[i].chi,&s[i].math);
	   s[i].sum=s[i].chi+s[i].math;}
	
	max=0;
	for(i=0;i<n;i++)
	{
			if (max<s[i].sum)  {max=s[i].sum;j=i;}
	}
	printf("%d %d\n",s[j].num,s[j].sum);
	s[j].sum=0;	max=0;
		for(i=0;i<n;i++)
	{
			if (max<s[i].sum)  {max=s[i].sum;j=i;}
	}
	printf("%d %d\n",s[j].num,s[j].sum);
	s[j].sum=0;			max=0;
		for(i=0;i<n;i++)
	{
			if (max<s[i].sum)  {max=s[i].sum;j=i;}
	}
	printf("%d %d\n",s[j].num,s[j].sum);
	s[j].sum=0;	
}