semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
struct patient
{
	char id[11];
	int age;
}pa[101],que[101],tran;

int main(int argc, char* argv[])
{
	int i,n,j,old=0;
	scanf("%d",&n);
	j=1;
	for(i=1;i<=n;i++){
		scanf("%s %d",&pa[i].id,&pa[i].age);
		if(pa[i].age>=60){
			que[j]=pa[i];
			old+=1;
			j++;
		}
	}
	for(i=1;i<=old-1;i++){
		for(j=1;j<=old-i;j++){
			if(que[j].age<que[j+1].age){
				tran=que[j];
				que[j]=que[j+1];
				que[j+1]=tran;
			}
		}
		
	}
	j=old+1;
	for(i=1;i<=n;i++){
		if(pa[i].age<60){
			que[j]=pa[i];
			j++;
		}
	}
	for(i=1;i<=n;i++){
		printf("%s\n",que[i].id);
	}
	return 0;
}
int main()
{
	struct a
	{
		char id[10];
		int age;
	}p,q,a[100],old[100],yog[100];
	int n,i=0,x=0,y=0,k,l;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s%d",a[i].id,&a[i].age);
		if(a[i].age>=60)
		{
			old[x]=a[i];
			x++;
		}
		if(a[i].age<60)
		{
			yog[y]=a[i];
			y++;
		}
	}
	for(k=1;k<x;k++)
	{
		for(i=0;i<x-1;i++)
		{
			if(old[i].age<old[i+1].age)
			{
				p=old[i+1];
				old[i+1]=old[i];
				old[i]=p;
			}
		}
	}
	for(i=0;i<x;i++)
	{
		printf("%s\n",old[i].id);
	}
	for(i=0;i<y;i++)
	{
		printf("%s\n",yog[i].id);
	}
	return 0;
}
struct patient{
  char num[11];
  int age;
};
int main()
{
 int n,i;
 scanf("%d",&n);
 struct patient pat1[100],pat2[100];
 for(i=0;i<n;i++){
  scanf("%s %d",pat1[i].num,&pat1[i].age);
  strcpy(pat2[i].num,pat1[i].num);
  pat2[i].age=pat1[i].age;
 }
 int j,e;
 char e_num[11];
 for(j=1;j<n;j++){
  for(i=0;i<n-j;i++){
   if(pat1[i].age<pat1[i+1].age){
    e=pat1[i+1].age;
	strcpy(e_num,pat1[i+1].num);
    pat1[i+1].age=pat1[i].age;
	strcpy(pat1[i+1].num,pat1[i].num);
	pat1[i].age=e;
	strcpy(pat1[i].num,e_num);
   }
  }
 }
 for(i=0;i<n;i++){
	 if(pat1[i].age>=60){
		printf("%s\n",pat1[i].num);
	 }
 }
 for(i=0;i<n;i++){
	 if(pat2[i].age<60){
		printf("%s\n",pat2[i].num);
	 }
 }
 return 0;
}
struct student
{
	char c[20];
	int num;
	struct student*next;
};
struct student*creat(int n)
{
	int i,r;
	struct student*p,*p1,*p2,*p3,*p4;
	p1=(struct student*)malloc(sizeof(struct student));
	scanf("%s %d",p1->c,&p1->num);
	p1->next=NULL;
	p=p1;
	r=0;
	p2=p1;
	for(i=0;i<n-1;i++)
	{
		p4=(struct student*)malloc(sizeof(struct student));
		scanf("%s %d",p4->c,&p4->num);
		if(p4->num>=60)
		{
		for(p2=p,p3=p,r=0;p2!=NULL;)
		{
			if(p4->num>p2->num)
			{
				if(p2==p3)
				{
					p=p4;
					p4->next=p2;
				}
				else
				{
					p3->next=p4;
					p4->next=p2;
				}
				r=1;
				break;
			}
			if(p4->num<=p2->num)
			{
				p3=p2;
				p2=p2->next;
			}
		}
		if(r==0)
		{
			p3->next=p4;
			p4->next=NULL;
		}
		}
		else
		{
			p2=p;
			while(p2!=NULL)
			{
				p3=p2;
				p2=p2->next;
			}
			p3->next=p4;
			p4->next=NULL;
		}

	}
	return p;
}
void print(struct student*p)
{
	struct student*p1;
	p1=p;
	while(p1!=NULL)
	{
		printf("%s\n",p1->c);
		p1=p1->next;
	}
}
void main()
{
	struct student*p,*p1;
	int n;
	scanf("%d\n",&n);
	p=creat(n);
	print(p);
}
int main()
{
    int n,i,j,k,e,age[100],six[100];
j=0;    
char id[100][10];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s",&id[i]);
        scanf("%d",&age[i]);
        if(age[i]>=60){
           six[j]=i;
           j++;
           }
        }
    for(i=j;i>=0;i--){
        for(k=0;k<i-1;k++){
            if(age[six[k]]<age[six[k+1]]){
               e=six[k+1];
               six[k+1]=six[k];
               six[k]=e;
               }
            }
        }
    for(i=0;i<j;i++)
        printf("%s\n",id[six[i]]);
    for(i=0;i<n;i++){
        if(age[i]<60)
           printf("%s\n",id[i]);
        }
    return 0;
}
int main()
{
    int n,k,m,i;
    char a[100][10],over[100][10], below[100][10];
    char h[100][10];
    long int b[100];
    long int c[100]={0};
    long int d[100]={0}; 
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
        scanf("%s %d",a[i],&b[i]);
    }
    
    for(int i=1;i<=n;i++)
    {
        if (b[i]>=60)
          {c[i]=b[i];
          strcpy (over[i],a[i]);}
        else
          {d[i]=b[i];
          strcpy (below[i],a[i]);}
             
    }
for (k=101;k>=60;k--) 
{
    i=1;
    while (i<=n)
    {if (c[i]==k)
    {printf("%s\n",over[i]);}
    i++;
}
}
    i=1;
    while (i<=n)
    {
          if (d[i]!=0)
          printf("%s\n",below[i]);
    i++;
    }
 getchar(); getchar(); getchar(); getchar(); getchar(); getchar(); getchar(); getchar();
}
void main()
{
    struct pat
	{
	   char id[10];
	   int age;
	}pat[201];
    int i,n,j,x=0,y=0;
	scanf("%d\n",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s %d",pat[i].id,&pat[i].age);
		printf("\n");
	}
	for(i=0;i<n;i++)
	{
		if(pat[i].age>=60)
		{	pat[100+x]=pat[i];
		x++;}
		else
		{
			pat[y]=pat[i];
			y++;
		}
	}
	for(i=0;i<x-1;i++)
	{
		for(j=0;j<x-i-1;j++)
		{
			if(pat[100+j].age<pat[101+j].age)
			{
				pat[200]=pat[100+j];
				pat[100+j]=pat[101+j];
				pat[101+j]=pat[200];
			}
		}
	}
	for(i=0;i<x;i++)
		printf("%s\n",pat[100+i].id);
	for(i=0;i<y;i++)
		printf("%s\n",pat[i].id);
}
void main()
{
	int n;
	int a[105];
	char c[105][11];
	int i,j;

	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%s%d",c[i],&a[i]);

	int aa[105]={0};
	int num[105];
	int u=0;
	for(i=0;i<n;i++)
		if(a[i]>=60)
		{
			aa[i]=a[i];
			num[u]=i;
			u++;
		}
	for(i=0;i<n;i++)
		for(j=i+1;j<n;j++)
		{
			if(aa[i]>0&&aa[i]==aa[j])
				aa[i]=0;
		}
	for(i=n;i>0;i--)
	{
		for(j=0;j<i;j++)
		{
			if(aa[j]<aa[j+1])
			{
				int t=aa[j];
				aa[j]=aa[j+1];
				aa[j+1]=t;
/*				char tt[11];
				strcpy(tt,c[i]);
				strcpy(c[i],c[i+1]);
				strcpy(c[i+1],tt);*/
			}
		}
	}
	for(i=0;aa[i]!=0;i++)
	{
		for(j=0;j<n;j++)
		{
			if(a[j]==aa[i])
			{
				printf("%s\n",c[j]);
			}
		}
	}
	int tem=0;
	for(j=0;j<n;j++)
	{
		for(i=0;i<u;i++)
		{
			if(j==num[i])
				tem=1;
		}
		if(tem==0)
			printf("%s\n",c[j]);
		tem=0;
	}
		
}
int main()
{
    int n,b[100],i,r,j=0,k=0,o[100]={0},y[100]={0},l=1,m;
    char a[100][10],old[100][10],young[100][10],str[10];
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {               scanf("%s %d",a[i],&b[i]);
                    if(b[i]>=60)
                    {
                                strcpy(old[j],a[i]);
                                o[j]=b[i];
                                j++;
                    }
                    else
                    {
                                strcpy(young[k],a[i]);
                                y[k]=b[i];
                                k++;
                    }
    }
    for(i=j-1;i>0;i--)
    {
                      for(r=0;r<i;r++)
                      {
                                      if(o[r]<o[r+1])
                                      {
                                                     m=o[r+1];
                                                     strcpy(str,old[r+1]);
                                                     o[r+1]=o[r];
                                                     strcpy(old[r+1],old[r]);
                                                     o[r]=m;
                                                     strcpy(old[r],str);
                                      }
                      }
    }
    for(i=0;i<j;i++)
    printf("%s\n",old[i]);
    for(i=0;i<n-j;i++)
    printf("%s\n",young[i]);
    getchar();
    getchar();
}
struct data
{
	int a[100];
	char num[100][15];
}data;

void main()
{
	int i,b,k=0,j,n;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s %d",data.num[i],&data.a[i]);
		if(data.a[i]>=60) k++;
	}
	for(j=0;j<k;j++)
	{
		b=0;
		for(i=0;i<n;i++)
		{
			if(data.a[i]>data.a[b])
			b=i;
		}
		printf("%s\n",data.num[b]);
		data.a[b]=0;
	}
	for(i=0;i<n;i++)
	{
		if(data.a[i]!=0)
			printf("%s\n",data.num[i]);
	}
}
void main()
{
	int age[100],i,j,k,p=0,n;
	char a[100][10];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s %d",&a[i],&age[i]);
		if(age[i]>=60)p++;
	}
	for(j=1;j<=p;j++)
	{
		k=0;
		for(i=0;i<n;i++)
		{
			if(age[i]>age[k])
				k=i;

		}
		printf("%s\n",a[k]);
		age[k]=0;
	}
	for(i=0;i<n;i++)
	{
		if(age[i]!=0)
		{
			printf("%s\n",a[i]);
		}
	}

}
int main()
{
    int n,i=0,x;
    scanf("%d",&n);
    int age[100];
    char num[100][10];
    for(i=0;i<n;i++)
    {
      scanf("%s %d",num[i],&age[i]);
      if (age[i]<60)
      age[i]=0;
    }
    loop:for(i=0;i<n;i++)
    {  
      x=0;
      if (age[i]>=60)                  
       {   for(int j=0;j<n;j++)
            {  
               if(age[j]>age[i])
                    x=x+1;}
           if (x==0)
           {printf("%s\n",num[i]);
             age[i]=1;
             goto loop;}
       }                  
    }
     for(i=0;i<n;i++)
     {
      if (age[i]==0)
      printf("%s\n",num[i]);                
     } 
     getchar();
     getchar();
}
void main()
{
	int n,a[100],t,b[100],c[100];
	char h[100][10],h1[100][10],h2[100][10],y[10];
	scanf("%d",&n);
	int i,j,k;
	int i1,j1;
	for(i=0;i<n;i++)
	{
		scanf("%s",h[i]);
		scanf("%d",&a[i]);
	}
	i1=0;j1=0;
	for(k=0;k<n;k++)
	{
		if(a[k]>=60)
		{b[i1]=a[k];
		strcpy(h1[i1],h[k]);i1++;}
		else
		{c[j1]=a[k];
		strcpy(h2[j1],h[k]);j1++;}

	}

	for(j=0;j<i1-1;j++)
		for(i=0;i<i1-1-j;i++)
			if(b[i]<b[i+1])
			{
				t=b[i];
				b[i]=b[i+1];
				b[i+1]=t;
				strcpy(y,h1[i]);
				strcpy(h1[i],h1[i+1]);
				strcpy(h1[i+1],y);
			}

			for(i=0;i<i1;i++)
			{
				puts(h1[i]);
			}
			for(i=0;i<j1;i++)
				puts(h2[i]);
}
struct patient
{	char id[11];
	int age;
};

int main()
{	struct patient pt[100];

	int n,i,j,a=0,b=0,tem;
	int age_r[100],time_range[100];
	char temid[11];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s%d",pt[i].id,&pt[i].age);
		if(pt[i].age>=60){
			age_r[a]=i;
			a++;
		}
		else{
			time_range[b]=i;
			b++;
		}
	}
	for(i=1;i<a-1;i++){
		for(j=0;j<a-i;j++){
			if(pt[age_r[j]].age<pt[age_r[j+1]].age){   //?????????????? ???debug?????????
				strcpy(temid,pt[age_r[j]].id);
				strcpy(pt[age_r[j]].id,pt[age_r[j+1]].id);
				strcpy(pt[age_r[j+1]].id,temid);
				tem=pt[age_r[j]].age;
				pt[age_r[j]].age=pt[age_r[j+1]].age;
				pt[age_r[j+1]].age=tem;

			}
		}

	}
	for(i=0;i<a;i++){
		printf("%s\n",pt[age_r[i]].id);
	}
	for(i=0;i<b;i++){
		printf("%s\n",pt[time_range[i]].id);
	}

	return 0;
}
int main()
{
	int n,age[100],i,j;
	char id[100][10];
	scanf("%d",&n);
	int k=0;
	char shuchu[100][10];
	for(i=0;i<n;i++)
	{
		scanf("%s %d",id[i],&age[i]);
		if(age[i]<60)
			strcpy(shuchu[k++],id[i]);
	}
	char mid[100][10];
	int t;
	for(i=0;i<n-1;i++)
	{
		for(j=0;j<n-1-i;j++)
		{
			if(age[j]<age[j+1])
			{
				t=age[j];
				age[j]=age[j+1];
				age[j+1]=t;
				strcpy(mid[j],id[j]);
				strcpy(id[j],id[j+1]);
				strcpy(id[j+1],mid[j]);
			}
		}
	}
	if(age[0]<60)
		goto E;
	else
	{
		for(i=0;age[i]>=60;i++)
			printf("%s\n",id[i]);
	}
E:;	
	for(i=0;i<k;i++)
		printf("%s\n",shuchu[i]);
	return 0;
}
int main()
{
	int n,i,j,old[100]={0},t[100]={0};
	char num[100][10]={0},temp[100][10]={0};
	int x,z=0;
	char y[10]={0};
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
	    scanf("%s %d",num[i],&old[i]);
	}
    for(i=0;i<n;i++)
	{
	  if(old[i]>=60)
	  {
		strcpy(temp[z],num[i]);
	    t[z]=old[i];
		z++;
	  }
	}
    for(i=0;i<z;i++)
	{
	  for(j=z-1;j>i;j--)
	  {
	    if(t[j]>t[j-1])
		{
		   x=t[j];
		   t[j]=t[j-1];
		   t[j-1]=x;
		   strcpy(y,temp[j-1]);
		   strcpy(temp[j-1],temp[j]);
		   strcpy(temp[j],y);
		}
	  }
	}
	for(i=0;i<z;i++)
		printf("%s\n",temp[i]);
	for(i=0;i<n;i++)
	{
		if(old[i]<60)
		printf("%s\n",num[i]);
	}
	return 0;
}
struct oldpeople
{
	char id[20];
	int year;
}old[100],old60[100],cache;
int main()
{
	int n;int i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s %d",old[i].id,&old[i].year);
	}
	int j=0;
	for(i=0;i<n;i++)
	{
		if(old[i].year>=60)
		{	old60[j]=old[i];j++;}
	}
	int k;
	for(i=0;i<j;i++)
	{
		for(k=0;k<j-i;k++)
		{
			if(old60[k].year<old60[k+1].year)
			{
				cache=old60[k+1];
				old60[k+1]=old60[k];
				old60[k]=cache;
			}
		}
	}
	for(i=0;i<j;i++)
	{
		printf("%s\n",old60[i].id);
	}
	for(i=0;i<n;i++)
	{
		if(old[i].year<60)
		printf("%s\n",old[i].id);
	}
	return 0;
}
int n;
struct ceshi
{
	char hao[20];
	int num;
	struct ceshi *next;
};

struct ceshi *charu (struct ceshi *head,struct ceshi *p1)
{
    struct ceshi *p2,*p;
    if (p1->num>=60)
    {
		if (head==Null)
        {head=p1;
        p1->next=Null;}
        else 
		{
        p2=head;
        while ((p1->num<=p2->num)&&(p2->next!=Null))
        {
            p=p2;
            p2=p2->next;
        }
        if (p1->num>=p2->num)
        {
            if (p2==head) {head=p1;p1->next=p2;}
            else {p->next=p1;p1->next=p2;}
        }
        else 
        {
            p2->next=p1;
            p1->next=Null;
	}
     }
    }
	else
	{
	    p=head;
		if (head==Null)
		{
		    head=p1;p1->next=Null;
		}
		else
		{while(p->next!=Null)
		{
		    p=p->next;
		}
		p->next=p1;
		p1->next=Null;}
	}
    return (head);
}

struct ceshi* create()
{
    struct ceshi *p1,*head,*p2;
    int i=0;
	head=Null;
    while (i<n)
    {
        i++;
		p1=(struct ceshi*)malloc(len);
        scanf("%s %d",p1->hao,&p1->num);
        head=charu(head,p1);
    }
    return(head);
}

void print(struct ceshi *head)
{
    struct ceshi *p;
    p=head;
    while(p!=Null)
    {printf("%s\n",p->hao);
    p=p->next;}
}

void main()
{
    struct ceshi *p;
	scanf("%d",&n);
    p=create();
    print(p);    
}
struct example
{
	char id[10];
	int age;
	struct example *next;
};

int i=1,d,n;
struct example *creat(int n)
{struct example *head=NULL;
struct example *p1,*p2;
while(i<=n)
{
	p1=(struct example *)malloc(sizeof(struct example));
	scanf("%s%d",&(*p1).id,&(*p1).age);
if(i==1)
{head=p1;
p2=head;}
else 
p2->next=p1;
p2=p1;
i=i+1;
}
p2->next=NULL;
return(head);
}

struct example *paixu(struct example *head)
{
	char temp1[10]={'\0'};
	int temp2;
	struct example *p1,*p2;
	p1=p2=head;

    for(i=1;i<n;i++)
	{
		p1=head;
		while(p1->next!=NULL)
	{
		p2=p1->next;
		if(p1->age<p2->age&&((p2->age)>=60))
		{strcpy(temp1,p1->id);
		strcpy(p1->id,p2->id);
		strcpy(p2->id,temp1);
		temp2=p1->age;
		p1->age=p2->age;
		p2->age=temp2;
		}
		p1=p1->next;
	}
	}
	return head;
}

void print(struct example *head)
{struct example *s;
s=head;
if(head!=NULL)
do
{printf("%s\n",s->id);
s=s->next;
}while(s!=NULL);
}


void main()
{
	struct example *head=NULL;
	scanf("%d",&n);
	head=creat(n);
	head=paixu(head);
	print(head);
}
struct patient
{
	char num[10];
	int age;
	struct patient *next;
};
int n;
struct patient *creat(void)
{
	struct patient *head;
	struct patient *p1,*p2;
	int num=1;
	head=NULL;
	while(num<=n)
	{
		p1=(struct patient *)malloc(LEN);
		scanf("%s %d",p1->num,&p1->age);
		if (num==1)
			head=p1;
		else
			p2->next=p1;
		p2=p1;
		num++;
	}
	p2->next=NULL;
	return (head);
}
int main()
{
	struct patient *pt,*p,*pre;
	int i,max,num=0;
	scanf("%d",&n);
	pt=creat();
	for (p=pt;p;p=p->next)
	{
		if (p->age>=60)
			num++;
	}
	for (i=1;i<=num;i++)
	{
		max=59;
		for (p=pt;p;p=p->next)
		{
			if (max<p->age)
				max=p->age;
		}
		for (p=pre=pt;p;p=p->next)
		{
			if (p->age!=max)
				pre=p;
			else
				break;
		}
		printf("%s\n",p->num);
		if (p==pt)
			pt=p->next;
		else
			pre->next=p->next;
	}
	for (p=pt;p;p=p->next)
		printf("%s\n",p->num);
	return 0;
}
void main()
{
	struct p
	{
		int k;
		char id[10];
		int age;
	}pa[100]={0,"",0},pb[100]={0,"",0},temp;


	int n;
	int i,j,k,age,na,nb;
	char id[10]={""};

	scanf("%d",&n);

	for(i=0,j=0;i+j<n;)
	{
		scanf("%s%d",&id,&age);
		if(age>=60)
		{
			pa[i].age=age;
			strcpy(pa[i].id,id);
			pa[i].k=i;
			i++;
		}
		else
		{
			pb[j].age=age;
			strcpy(pb[j].id,id);
			pb[j].k=j;
            j++;
		}
	}
	na=i;nb=j;




	for(j=1;j<=n-1;j++)
	{
		for(i=0;i<n-j;i++)
		{
			if(pa[i].age < pa[i+1].age)
			{
				temp.age=pa[i+1].age;strcpy(temp.id,pa[i+1].id);
				pa[i+1].age=pa[i].age;strcpy(pa[i+1].id,pa[i].id);
				pa[i].age=temp.age;strcpy(pa[i].id,temp.id);

			}

		}
	}

	printf("%s",pa[0].id);
	for(i=1;i<=na;i++)
	{
		printf("\n%s",pa[i].id);
	}
	for(j=0;j<=nb;j++)
	{
		puts(pb[j].id);
	}

}
struct patient
{
	char No[10];
	int age;
}p[101];
int main()
{
	int n,i,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%s%d",p[i].No,&p[i].age);
	}
	struct patient t;
	for (i=2;i<=n;i++)
	{
		if (p[i].age>=60)
		{
			for (j=i;j>1;j--)
			{
				if (p[j-1].age<p[j].age)
				{
					t=p[j-1];
					p[j-1]=p[j];
					p[j]=t;
				}
				else
					break;
			}
		}
	}
	for (i=1;i<=n;i++)
		printf("%s\n",p[i].No);
	return 0;
}
struct patient
{
	char id[11];
	int age;
} pat[100];
int main()
{
	int n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s %d", pat[i].id, &pat[i].age);
	}
	int temp=0;
	struct patient e;
	for(i=0;i<n;i++){
		if(pat[i].age>=60){
			e=pat[i];
			int j;
			for(j=i;j>=temp+1;j--){
				pat[j]=pat[j-1];
			}
			pat[temp]=e;
			temp++;
		}
	}
	int k;
	for(k=1;k<=temp;k++){
		for(i=0;i<temp-k;i++){
			if(pat[i].age<pat[i+1].age){
				e=pat[i];
				pat[i]=pat[i+1];
				pat[i+1]=e;
			}
		}
	}
	for(i=0;i<n;i++){
		printf("%s\n",pat[i].id);
	}
	return 0;
}
struct student 
{
	char num[30];
	int sum;
    struct student *next;
};

void main()
{
	int n,i;
	struct student *p1,*p2,*p3,*head;
	scanf("%d",&n);
	for (i=0;i<n;i++)
	{
		p1=(struct student*)malloc(sizeof(struct student));
		if(i==0)
			head=p1;
		scanf("%s%d",p1->num,&p1->sum);
		p1->next=NULL;
		
		
		if (i!=0)
		{
			p3=head;
			if(p1->sum>=60){
				
				while ((p1->sum<=p3->sum) && p3->next!=NULL)
			{
				p2=p3;
				p3=p3->next;
			}
			if (p1->sum > p3->sum)
			{
			     if(head==p3)
				 {
				     head=p1;
				     p1->next=p3;
				 }
			     else
				 {
				    p2->next=p1;
				    p1->next=p3;
				 }
			}
		    else
			{
			    p3->next=p1;
			    p1->next=NULL;
			}
			}
			else{for(p2=head;;p2=p2->next){if(p2->next==NULL)break;}
			    p2->next=p1;
				p1->next=NULL;}
		}
		

	
	}
	p1=head;
    for (i=0;(i<n&&p1!=NULL);i++)
	{
		printf("%s\n",p1->num);
		p1=p1->next;
	}
}
int main()
{
	int n,i,j=0,e,v=0,k,m[100],p[100],b[100];
	char s[100][11],temp[11],d[100][11],f[100][11];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s",s[i]);
		scanf("%d",&m[i]);
	}
	for(i=0;i<n;i++)
	{
		if(m[i]>=60)
		{
			strcpy(d[j],s[i]);
			p[j]=m[i];
			j++;
		}
		else
		{
			strcpy(f[v],s[i]);
			b[v]=m[i];
			v++;
		}
	}
	for(k=1;k<j;k++)
	{
		for(i=0;i<j-k;i++)
		{
			if(p[i]<p[i+1])
			{
				e=p[i+1];
				p[i+1]=p[i];
				p[i]=e;
				strcpy(temp,d[i+1]);
				strcpy(d[i+1],d[i]);
				strcpy(d[i],temp);
			}
		}
	}
	for(i=0;i<j;i++){
		printf("%s\n",d[i]);
	}
	for(i=0;i<v;i++){
		printf("%s\n",f[i]);
	}
	return 0;
}
int main(int argc, char* argv[])
{
	struct people{
		char a[10];
		int year;
	};
	struct people b[100],c[100],d[100],v[100];//yuan  hou
	for(int h=0;h<=99;h++){
		for(int p=0;p<=9;p++){
			b[h].a[p]=	c[h].a[p]=	d[h].a[p]=	v[h].a[p]=0;}
	}
		
	int n,t=0,k=0,o;//lao ren shu
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%s %d",&b[i].a,&b[i].year);
		if(b[i].year>=60){
			t++;
			v[t]=b[i];}
		else{
			k++;
			d[k]=b[i];}
	}
	for(int j=1;j<=t;j++){
				     o=0;
		for(int u=1;u<=t;u++){

			if(v[u].year>v[j].year){
				o++;}
			if(v[u].year==v[j].year&&u<j){
				o++;}
		}
		c[o+1]=v[j];
	}
	for(int l=1;l<=k;l++){
		c[t+l]=d[l];}
	for(int x=1;x<=n;x++){
		printf("%s\n",c[x].a);}

	return 0;
}
struct p
{
	char id[11];
	int y;
	struct p *next;
};
int n;
struct p *creat(void)
{
	struct p *head,*p1,*p2;
	int i;
	scanf("%d",&n);
	p1=p2=(struct p *)malloc(LEN);
	for(i=0;i<n;i++)
	{
		scanf("%s%d\n",p1->id,&p1->y);
		if(i==0)
		{
			head=p1;
		}
		else
		{
			p2->next=p1;
		}
		p2=p1;
		p1=(struct p *)malloc(LEN);
	}
	p2->next=NULL;
	return head;
}
void px(struct p *head)
{
	struct p *p;
	int k,t;
	leap:
	t=0;
	for(p=head;p!=0;)
	{
		if(p->y>=60)
		t=1;
		p=p->next;
	}
	if(t==1)
	{
		p=head;
		k=p->y;
		for(;p!=0;)
		{
			if(p->y>k)
			k=p->y;
			p=p->next;
		}
		for(p=head;p!=0;)
		{
			if(p->y==k)
			{
				printf("%s\n",p->id);
				p->y=0;
			}
			p=p->next;
		}
		goto leap;
	}
	for(p=head;p!=0;)
	{
		if(p->y!=0)
		printf("%s\n",p->id);
		p=p->next;
	}
}
void main()
{
    struct p *p;
    p=creat();
    px(p);
}
int main()
{
    int n,i;
    scanf ("%d",&n);
    struct patient
    {
        char ID[10];
        int age;
        struct patient *next;
        struct patient *pre;
    };
    struct patient *p,*head,*q,*m,*temp;
    p=(struct patient*)malloc(sizeof(struct patient));
    head=p;
    temp=(struct patient*)malloc(sizeof(struct patient));
    for (i=0;i<n;i++)
    {
        scanf ("%s %d",p->ID,&p->age);
        if(i!=n-1)
        {
            p->next=(struct patient*)malloc(sizeof(struct patient));
            p->next->pre=p;
            p->next->next=NULL;
            p=p->next;
        }
    }
    for (p=head;p!=NULL;p=p->next)
    {
        for (q=p->next;q!=NULL;q=q->next)
        {
            if ((p->age < q->age)&&(q->age>=60))
            {
                for (m=q;m!=p;m=m->pre)
                {
                    temp->age=m->age;
                    m->age=m->pre->age;
                    m->pre->age=temp->age;
                    strcpy(temp->ID,m->ID);
                    strcpy(m->ID,m->pre->ID);
                    strcpy(m->pre->ID,temp->ID);
                }
            }
        }
    }
    for (p=head;p!=NULL;p=p->next)
    printf ("%s\n",p->ID);
    return 0;
}
main()
{
 int m=0,n,i,j,t=0;
 int num[100];
 int a[100];
 char string[11];
 char stm[100][11];
 char str[100][11];
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  scanf("%s",stm[i]);
  scanf("%d",&num[i]);
  }
  j=0;
  for(i=0;i<n;i++)
  {
   if(num[i]>=60)
   {
    a[j]=num[i];
    strncpy(str[j],stm[i],10);
    j++;
    t=j-1;
               }               
                  }               
    for(j=0;j<t;j++)
    {
      for(i=0;i<t-j;i++)
      {
        if(a[i]<a[i+1])
        {
          m=a[i];
           a[i]=a[i+1];
           a[i+1]=m;
           strncpy(string,str[i],10);
           strncpy(str[i],str[i+1],10);
           strncpy(str[i+1],string,10);
           }                
        }              
    }              
    for(i=0;i<=t;i++)
      printf("%s\n",str[i]);              
    for(i=0;i<n;i++)
    {
    if(num[i]<60)
    printf("%s\n",stm[i]);
    } 
    getchar();
    getchar();
      }
char id[NUM][LEN],oldid[NUM][LEN],newid[NUM][LEN];
int  age[NUM];
int oldage[NUM],newage[NUM];
	int main(){
	int num;
	int i=0,j=0, k=0,n=0;
	int e_oldage;  
	char e_oldid[LEN];
	scanf("%d", &num);
	for(i = 0; i < num; i++){
		scanf("%s %d ", id[i], &(age[i]));
	}
	for(i=0;i<num;i++){
		if(age[i]>=60){
                oldage[j]= age[i];  
				strcpy(oldid[j], id[i]);			
				j++;
		}else {
			newage[n]= age[i];  
			strcpy(newid[n], id[i]);
			n++;
		}
	}
	for(k = 1 ; k <= j; k++){
		for(i = 0; i < j- k; i++){
   			if(	oldage[i] < oldage[i+1]){
				e_oldage = oldage[i+1];   
				strcpy(e_oldid, oldid[i+1]);

				oldage[i+1] = oldage[i]; 
				strcpy(oldid[i+1], oldid[i]);

				oldage[i] = e_oldage;  
				strcpy(oldid[i], e_oldid);
			}		
		}
	}
	for(i=0;i<j;i++){
		printf("%s\n",oldid[i]);
	}
	for(i=0;i<n;i++){
		printf("%s\n",newid[i]);
	}
	return 0;
}
int main(){
	char a[100][11],c[100][11];
	int i,j,n,b[100],m,e=-1,f=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s %d",&a[i],&b[i]);
	}
	for(i=0;i<n;i++){
		if(b[i]>=60){
			m=0;
			for(j=0;j<n;j++){
				if(b[i]<b[j]||(b[i]==b[j]&&i>j)){
					m++;
			}}
			if(e<m)
				e=m;
			strcpy(c[m],a[i]);
	}}
	e=e+1;
	for(i=0;i<n;i++){
		if(b[i]<60){
			strcpy(c[i-f+e],a[i]);
		}else{
			f++;
	}}
	for(i=0;i<n;i++){
		printf("%s\n",c[i]);
	}
	return 0;
}
struct patient{
	char ID[10];
	int age;
	struct patient *next;
};

struct patient *creat(int n)
{ int i;
  struct patient *head;
  struct patient *p1,*p2;
   p2=p1=(struct patient *)malloc(LEN);
   head=p1;
   scanf("%s %d",p1->ID,&p1->age);
  for(i=1;i<n;i++)
    {  
p1=(struct patient *)malloc(LEN);
 scanf("%s %d",p1->ID,&p1->age);
p2->next=p1;
p2=p1;
     }
     p2->next=NULL;
   return(head);
}

int main()
{
	int i,j,n;
	char a[10];
	scanf("%d",&n);
    struct patient *h,*q,*p;
    h=creat(n);
	for(i=0;i<n;i++)
	 for(q=h;q->next!=NULL;q=q->next)
	 if(q->next->age>=60&&q->next->age>q->age)
	 {
 		strcpy(a,q->ID);strcpy(q->ID,q->next->ID);strcpy(q->next->ID,a);
 		j=q->age;q->age=q->next->age;q->next->age=j;
 	}
    for(p=h;p!=NULL;p=p->next)
     printf("%s\n",p->ID);
}