int main()
{
    int n,i,j,k;
    scanf ("%d",&n);
    struct patient
    {
        char num[10];
        int age;
    };
    struct patient p[100],temp;
    for (i=0;i<n;i++)
    scanf ("%s %d",&p[i].num,&p[i].age);
    for (i=0;i<n-1;i++)
    {
        for (j=i+1;j<n;j++)
        {
            if (p[j].age>p[i].age&&p[j].age>=60)
            {
                for (k=j;k>i;k--)
                {
                    temp=p[k];
                    p[k]=p[k-1];
                    p[k-1]=temp;
                }
            }
        }
        printf("%s\n",p[i].num);
    }
    printf("%s\n",p[n-1].num);
    return 0;
}


int i,j,n;
struct st
	{
        char a[20];
		int x;
		struct st *next;
	}*p1,*p2,*p,*head,*pre;
void main()
{
scanf("%d",&n);void f(struct st *);
p1=p2=head=(struct st *)malloc(sizeof(struct st));
	for(i=0;i<n;i++)
	{
		scanf("%s %d",p1->a,&p1->x);
		p1=(struct st *)malloc(sizeof(struct st));p2->next=p1;p2=p1;
	}
	f(head);
p=head;
for(i=0;i<n;i++)
{
	printf("%s\n",p->a);p=p->next;
}
}
void f(struct st *p)
{
for(i=0;i<n-1;i++)
	{
		pre=p1=p2=head;p1=p1->next;
		for(j=0;j<n-1-i;j++)
		{
			if(p1->x>p2->x&&p1->x>=60)
			{
			if(j==0)
			{p2->next=p1->next;p1->next=p2;head=pre=p1;}
			else
			{p2->next=p1->next;p1->next=p2;pre->next=p1;}
			}
			if(j!=0)pre=pre->next;
			p2=pre->next;p1=p2->next;
		}
	}
}


struct patient
{
	char id[10];
	int age;
	struct patient * next;
};
int main()
{
	int n,i;
	struct patient *p,*pre,*pnew,*head1,*head2;
	head1=NULL;
	head2=NULL;
	scanf("%d\n",&n);
	p=(struct patient *)malloc(sizeof(struct patient));
	for(i=0;i<n;i++)
	{
		pnew=(struct patient *)malloc(sizeof(struct patient));
		scanf("%s %d\n",pnew->id,&pnew->age);
		pnew->next=NULL;
		if(pnew->age>=60)
		{
			if(head1==NULL)
			{
				head1=pnew;
			}
			else
			{
				p=head1;
				while(p&&p->age>=pnew->age)
				{
					pre=p;
					p=p->next;
				}
				if(p==head1)
				{
					pnew->next=head1;
					head1=pnew;
				}
				else
				{
					pre->next=pnew;
					pnew->next=p;
				}
			}
		}
		else
		{
			if(head2==NULL)
			{
				head2=pnew;
			}
			else
			{
				p=head2;
				while(p)
				{
					pre=p;
					p=p->next;
				}
				if(p==head2)
				{
					pnew->next=head2;
					head2=pnew;
				}
				else
				{
					pre->next=pnew;
					pnew->next=p;
				}
			}
		}
	}
	p=head1;
	if(head1!=NULL)
	{
		while(p)
		{
			printf("%s\n",p->id);
			p=p->next;
		}
	}
	p=head2;
	if(head2!=NULL)
	{
		while(p)
		{
			printf("%s\n",p->id);
			p=p->next;
		}
	}
	return 0;
}


struct guahao
{
	char num[20];
	int year;
};
int main()
{
	int n,i,m;
	struct guahao temp,*p,*t,*p1;
	scanf("%d",&n);
	m=n;
	struct guahao *bingren=(struct guahao*)malloc(sizeof(struct guahao)*n);
	struct guahao *bingren1=(struct guahao*)malloc(sizeof(struct guahao)*m);
	p=bingren;
	p1=bingren1;
	for(;p<bingren+n;p++,p1++)
	{
		scanf("%s %d",p->num,&p->year);
		*p1=*p;
	}
	p=bingren;
	for(i=0;p<bingren+n-1;p++,i++)
	{
		for(t=bingren;t<bingren+n-1-i;t++)
		{
			if((*t).year<(*(t+1)).year)
			{
				temp=*t;
				*t=*(t+1);
				*(t+1)=temp;
			}
		}
	}
	p=bingren;
	for(;p<bingren+n;p++)
	{
		if((*p).year>=60)
		{
			printf("%s\n",p->num);
		}
	}
	for(p1=bingren1;p1<bingren1+m;p1++)
	{
		if((*p1).year<60)
		{
			printf("%s\n",p1->num);
		}
	}
	free(bingren);
	free(bingren1);
	return 0;
}


struct patient
{
	char id[11];
	int age;
};

void main()
{
	int n;
	scanf("%d\n",&n);
	struct patient *p;
	p=(struct patient *)malloc(len);
	struct patient *a[n],*b[n];
	int anum=0,bnum=0;
	int i,j;
	for(i=0;i<n;i++)
	{
	    scanf("%s %d",p->id,&p->age);
	    if(p->age>=60)
	    {
	    	a[anum]=(struct patient *)malloc(len);
			strcpy(a[anum]->id,p->id);
	    	a[anum]->age=p->age;
	    	anum++;
	    }
		else
		{
			b[bnum]=(struct patient *)malloc(len);
			strcpy(b[bnum]->id,p->id);
	    	b[bnum]->age=p->age;
	    	bnum++;
		}
	}
	for(i=0;i<anum-1;i++)
	{
		for(j=0;j<anum-i-1;j++)
		if(a[j]->age<a[j+1]->age)
		{
			p->age=a[j]->age;
			a[j]->age=a[j+1]->age;
			a[j+1]->age=p->age;
			strcpy(p->id,a[j]->id);
			strcpy(a[j]->id,a[j+1]->id);
			strcpy(a[j+1]->id,p->id);
		}
	}
	for(i=0;i<anum;i++)
	printf("%s\n",a[i]->id);
	for(i=0;i<bnum;i++)
	printf("%s\n",b[i]->id);
}


struct student
{
       char num[11];
       int age;
};

int main(int argc, char *argv[])
{
  int n,i,j;
  scanf("%d",&n);
  struct student pa[n];
  for (i=0;i<=n-1;i++)
      scanf("%s%d",pa[i].num,&pa[i].age);
  struct student temp;
  for (j=n-1;j>=1;j--)
  {
      for (i=0;i<=j-1;i++)
      {
          if (pa[i].age<pa[i+1].age&&!(pa[i].age<60&&pa[i+1].age<60))
          {temp=pa[i];pa[i]=pa[i+1];pa[i+1]=temp;}
      }
  }
  for (i=0;i<=n-1;i++)
  {
      printf("%s",pa[i].num);
      (i<=n-2)?printf("\n"):printf("");
  }
  return 0;
}


struct patient
{
	int age;
	char id[12];
};
void swap(struct patient *a,struct patient *b)
{
	struct patient tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}
int main()
{
	int n,i,j=0,k=0,l;
	scanf("%d",&n);
	struct patient tmp;
	struct patient young[120];
	struct patient old[120];
	for (i=0; i<n; i++)
	{
		scanf("%s",tmp.id);
		scanf("%d",&tmp.age);
		if( tmp.age >= 60 )
			old[j++] = tmp;
		else
			young[k++] = tmp;
	}
	for(i=0; i<j; i++)
	{
		for(l=0; l<j-i-1; l++)
		{
			if( old[l].age < old[l+1].age )
				swap(&old[l],&old[l+1]);
		}
	}
	for(i=0; i<j; i++)
		printf("%s\n",old[i].id);
	for(i=0; i<k; i++)
		printf("%s\n",young[i].id);
	return 0;
}


struct stru
{
	char id[20];
	int age;
	struct stru *next;
}*head,*p,*q;

void creat(int N)
{
	int i;
	p=q=(struct stru *)malloc(LEN);
	head=p;
	scanf("%s %d",p->id,&p->age);
	for(i=1;i<N;i++)
	{
		p=(struct stru *)malloc(LEN);
		scanf("%s %d",p->id,&p->age);
		q->next=p;
		q=p;
	}
	q->next=NULL;
}

void arrange(struct stru *head,int N)
{
	int i,temp;char media[20];
	for(i=0;i<N;i++)
		for(p=head,q=head->next;q!=NULL;p=p->next,q=q->next)
		{
			if(q->age>=60 && q->age>p->age)
			{
				strcpy(media,p->id);
				strcpy(p->id,q->id);
				strcpy(q->id,media);
				temp=p->age;
				p->age=q->age;
				q->age=temp;
			}
		}
}

void print(struct stru *head)
{
	for(p=head;p!=NULL;p=p->next)
		printf("%s\n",p->id);
}

void main()
{
	int N;
	scanf("%d",&N);
	creat(N);
	//print(head);
	arrange(head,N);
	print(head);
}


int main(){

	int n, i, k;

	char id[N][LEN];

	int  age[N];

	scanf("%d", &n);

	for(i = 0; i < n; i++){
		scanf("%s %d", id[i], &(age[i]));
	}

	int e_age;
	char e_id[LEN];
	for(k = 1 ; k <= n ; k++){
		for(int i = 0; i < n - k; i++){
			if( (age[i] < age[i+1]) && !(age[i+1] < 60) ){
				e_age = age[i+1];
				strcpy(e_id, id[i+1]);
				age[i+1] = age[i];
				strcpy(id[i+1], id[i]);
				age[i] = e_age;
				strcpy(id[i], e_id);
			}
		}
	}

	for(i = 0; i < n; i++){
		printf("%s\n", id[i]);
	}

	return 0;
}


struct data{
	int w;
	char c[20];
	int old;
	struct data *next;
	struct data *onext;
};
int main() {
	int i,j,n,max,x;
	scanf("%d",&n);
	struct data *head=(struct data*)malloc(sizeof(struct data));
	struct data *p,*pp,*de;
	pp=head;
	for(i=0;i<n;i++) {
		p=(struct data*)malloc(sizeof(struct data));
		scanf("%s %d",p->c,&p->w);
		p->old=0;
		pp->next=p;
		pp=p;
	}
	struct data *old=(struct data*)malloc(sizeof(struct data));
	pp=head->next;
	de=old;
	x=0;
	for(i=0;i<n;i++) {
		if(pp->w>59) {
			pp->old=1;
			de->onext=pp;
			de=pp;
			x++;
		}
		pp=pp->next;
	}

	for(i=0;i<x;i++) {
		pp=old->onext;
		max=0;
		for(j=0;j<x;j++) {
			if(pp->w>max) {
				max=pp->w;
				de=pp;
			}
			pp=pp->onext;
		}
		printf("%s\n",de->c);
		de->w=-1;
	}
	pp=head->next;
	for(i=0;i<n;i++) {
		if(pp->old==0) printf("%s\n",pp->c);
		pp=pp->next;

	}
}


int main()
{
    int n,i,age,max,t,numold,numyoung;
    char id[101][10],young[101][10];
    int x[101],r[101];
    scanf("%d",&n);
    for (i=0;i<101;i++)
    {
        x[i]=0;
        r[i]=0;
        }
    numold=0;numyoung=0;
    for (i=1;i<=n;i++)
    {
        scanf("%s %d",id[i],&age);
        if (age>=60)
        {
           x[i]=age;
           numold++;
           }
        else
        {
             numyoung++;
             strcpy(young[numyoung],id[i]);
             }
        }
    for (i=1;i<101;i++)
    {
        max=1;
        for (int j=2;j<101;j++)
        {
            if (x[j]>x[max]) max=j;
            }
        x[max]=0;
        t=i;
        r[i]=max;
        max=t;
        }
    for (i=1;i<=numold;i++) printf("%s\n",id[r[i]]);
    for (i=1;i<=numyoung;i++) printf("%s\n",young[i]);
    }


struct pat
{
 char *id;
 int a;
 int o;
 struct pat *next;
};
int n;

int main()
{
    struct pat *create(int n);
    struct pat *arrange(struct pat *head);
    struct pat *head,*p;

    scanf("%d",&n);
    head=create(n);
    head=arrange(head);

    p=head;
    while(p!=NULL)
    {
     printf("%s",p->id);
     if(p->next!=NULL) printf("\n");
     p=p->next;
    }
}

struct pat *create(int n)
{
 struct pat *head,*p1,*p2;
 int i;
 p2=head=MLCP;

 for(i=1;i<=n;i++)
 {
  p1=MLCP;
  p1->id=MLCI;
  scanf("%s %d",p1->id,&p1->a);
  p1->o=i;

  p2->next=p1;
  p2=p1;
 }
 p2->next=NULL;

 return head;
}

struct pat *arrange(struct pat *head)
{
     void sort(struct pat *hn);

     struct pat *p1,*p2,*hn,*n1;

     n1=hn=MLCP;

     p2=head;p1=head->next;
     while(p1!=NULL)
     {
      if(p1->a >=60)
      {
       p2->next=p1->next;
       n1->next=p1;n1=p1;

       p1=p2->next;
      }
      else {p1=p1->next;p2=p2->next;}
     }
     n1->next=NULL;
     sort(hn);

     n1->next=head->next;
     head=hn->next;

     return head;
}

void sort(struct pat *hn)
{
   struct pat *p1,*p2;
   char *tid;
   int ta,to;

   p1=hn->next;
   while(p1!=NULL)
   {
    p2=p1->next;
    while(p2!=NULL)
    {
     if(p2->a > p1->a || (p2->a==p1->a && p2->o < p1->o))
     {
      tid=p2->id;p2->id=p1->id;p1->id=tid;
      ta=p2->a;p2->a=p1->a;p1->a=ta;
      to=p2->o;p2->o=p1->o;p1->o=to;
      }
     p2=p2->next;
    }
    p1=p1->next;
   }
}


struct patient
{
	char id[20];
	int age;
	int num;
};
int main()
{
	int n,i,j;
	char id1[20];
	int age1,u;
	struct patient temp;
	struct patient *p;
	struct patient a[500];
	scanf("%d",&n);
	p=a;
	u=0;
	for(;p<a+n;p++)
	{
		scanf("%s",id1);
		scanf("%d",&age1);
		strcpy(p->id,id1);
		p->age=age1;
		p->num=u;
		u++;
	}
	p=a;
	for(i=n-2;i>=0;i--)
	{
		for(j=0;j<=i;j++)
		{
			if((*(p+j)).age>=60||(*(p+j+1)).age>=60)
			{
		    	if((*(p+j)).age<(*(p+j+1)).age)
				{
			    	temp=*(p+j);
			    	*(p+j)=*(p+j+1);
				    *(p+j+1)=temp;
				}
			}
			else continue;
		}

	}
	p=a;
	for(;p<a+n;p++)
	{

			printf("%s\n",p->id);
	}

	return 0;
}


struct senex
{
       char id[10];
       int age;
       int rec;
} sen[100],t;
int n;

int main()
{
    int i,j,k,l;
    scanf("%d\n",&n);
    for(i=0;i<n;i++)
    {
      scanf("%s%d",sen[i].id,&sen[i].age);
      if(sen[i].age>=60) sen[i].rec=1;
      else sen[i].rec=0;
    }
    for(i=1;i<n;i++)
     for(j=0;j<n-i;j++)
      if(sen[j].rec<sen[j+1].rec)
      {
        t=sen[j];
        sen[j]=sen[j+1];
        sen[j+1]=t;
      }
    k=0;
    while(sen[k].rec==1) k++;
    for(i=1;i<k;i++)
     for(j=0;j<k-i;j++)
      if(sen[j].age<sen[j+1].age)
      {
        t=sen[j];
        sen[j]=sen[j+1];
        sen[j+1]=t;
      }
    //for(i=0;i<n;i++)
     //printf("%d ",sen[i].rec);
    for(i=0;i<n;i++)
     printf("%s\n",sen[i].id);
    scanf("%d",&i);
    return 0;
}


void main()
{
	int n,t,x,i;
	int age[100];
	char c[10],num[100][10];
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%s %d",num[i],&age[i]);

	for(i=0;i<n;i++)
	    if(age[i]>=60)

			for(x=i;x>0;x--)
		           if(age[x]>age[x-1])
				   {   t=age[x];age[x]=age[x-1];age[x-1]=t;
			          strcpy(c,num[x]);strcpy(num[x],num[x-1]);strcpy(num[x-1],c);
				   }

	for(i=0;i<n;i++)
		printf("%s\n",num[i]);
}


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


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


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


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


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


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


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


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


struct patient{
	char name[11];
	int age;
	int order;
};
int main(){
	struct patient peo[NO];
	int n,i,count=0,COUNT,j,k,e,agedata[NO],a=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s",&peo[i].name);
		scanf("%d",&peo[i].age);
	}
	for(i=0;i<n;i++){
		if(peo[i].age>=60){
			count++;
			agedata[a]=peo[i].age;
			a++;
		}
	}//count number of old people
	COUNT=count;
	for(i=0;i<n;i++){
		if(peo[i].age<60){
			peo[i].order=count;
			count++;
		}
	}// record order for young people
	for(k=1;k<COUNT;k++){
		for(j=0;j<COUNT-k;j++){
			if(agedata[j]<agedata[j+1]){
				e=agedata[j+1];
				agedata[j+1]=agedata[j];
				agedata[j]=e;
			}
		}
	}//rearrage age of old people
	for(i=0;i<COUNT;i++){
		for(j=0;j<n;j++){
			if(peo[j].age==agedata[i]){
				peo[j].order=i;
			}
		}
	}// record order for old people

	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if(peo[j].order==i){
				printf("%s\n",peo[j].name);
			}
		}
	}
	return 0;
}


int main()
{
	struct patient{
		char id[10];
		int age;
	}br[100];

	int n,i,j,mid,k;

	char s[10];

	scanf("%d",&n);

	for(i=0;i<n;i++){
		scanf("%s %d",&br[i].id,&br[i].age);

	}

	for(k=0;k<n;k++){
	    for(i=0;i<n;i++){
		    if(br[i].age>=60){
			    for(j=i+1;j<n;j++){
				    if(br[j].age>=60){
						if(br[j].age>br[i].age){
					        mid=br[i].age;
					        br[i].age=br[j].age;
					        br[j].age=mid;

					        strcpy(s,br[i].id);
					        strcpy(br[i].id,br[j].id);
					        strcpy(br[j].id,s);
						}
						break;
					}
				}
			}
		}
	}

	for(i=0;i<n;i++){
		if(br[i].age>=60){
			printf("%s\n",br[i].id);
		}
	}

	for(i=0;i<n;i++){
		if(br[i].age<60){
			printf("%s\n",br[i].id);
		}
	}

	return 0;
}


struct arr
{
	char id[10];
	int age;
	struct arr *next;
};
int n;
struct arr *create(int m)
{
	struct arr *head;
	struct arr *p1,*p2;
	n=1;
	p1=p2=(struct arr *) malloc(LEN);
	scanf("%s %d",&p1->id,&p1->age);
	head=p1;
	while(n<m)
	{
		p1=(struct arr *)malloc(LEN);
		p2->next=p1;
		n++;
		p2=p1;
		scanf("%s %d",&p1->id,&p1->age);
	}
	p1->next=NULL;
	return(head);
}
struct arr *del(struct arr *head,long int dnum)
{
	struct arr *p1,*p2;
	p1=p2=head;
	while(p1!=NULL&&p1->age==dnum)
		{
			head=p1->next;
			p2=head;
			free(p1);
			p1=head;
		}
	while(p1!=NULL)
	{
			p2=p1;
			p1=p1->next;
		while(p1!=NULL&&p1->age==dnum)
		{
			p2->next=p1->next;
			free(p1);
			p1=p2->next;
		}

	}
	return(head);
}
void print(struct arr *head)
{
	struct arr *p;
	p=head;
	while(p!=NULL)
	{
		if(p==head)
		printf("%s\n",p->id);
		else printf("%s\n",p->id);
		p=p->next;
	}
}
void freelist(struct arr *head)
	{
		struct arr *p=head ;
		if(head!=NULL)
		{
		while(p!=NULL)
		{
			head=head->next;
			free(p);
			p=head;
		}
		}
}
void main()
{
	struct arr *head,*p1;
	int m,max=0;
	scanf("%d",&m);
	head=create(m);
	for(;;)
	{
		max=0;
		for(p1=head;p1!=NULL;p1=p1->next)
		{
			max=(max>p1->age)?max:p1->age;
		}
		if(max>=60)
		{
			for(p1=head;p1!=NULL;p1=p1->next)
			{
				if(p1->age==max)
					printf("%s\n",p1->id);
			}
			head=del(head,max);
		}
		else break;
	}
	print(head);
	freelist(head);
}


struct patient{
	char id[10];
	int age;}pat[100];

		int over60[100];
		int below60[100];
		int m,k;
int main(int argc, char* argv[])
{
	void choose(struct patient *p,int n);
	int n,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++){
	scanf("%s%d",pat[i].id,&pat[i].age);}
	choose(pat,n);
	for(j=1;j<=m;j++){
		if(over60[m-j]!=over60[m-j-1]){
	for(i=0;i<n;i++){

		if(pat[i].age==over60[m-j]){
			printf("%s\n",pat[i].id);
	}}}}

	for(i=0;i<n;i++){
		if(pat[i].age<60){
			printf("%s\n",pat[i].id);}}
	return 0;
}
	void choose(struct patient *p,int n){
		void paixu(int *a,int n);
		int i;
		for(i=0,m=0,k=0;i<n;i++){
			if((p+i)->age>=60){
	over60[m]=(p+i)->age;
	m++;}}
		paixu(over60,m);}

	void paixu(int *a,int n){
		int j,i,e;
		for(j=1;j<n;j++){
		for(i=0;i<n-j;i++){
			if(*(a+i)>*(a+i+1)){
				e=*(a+i);
				*(a+i)=*(a+i+1);
				*(a+i+1)=e;}}}}


int main(){
	struct point{
		char id[10];
		int age;
	}patient[100];
	int n;
	int i,j,k;
	int on=0,old[100],flag;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s%d",patient[i].id,&patient[i].age);
	}
	for(j=120;j>=60;j--){
		for(i=0;i<n;i++){
			if(patient[i].age==j){
				printf("%s\n",patient[i].id);
				old[on]=i;
				on++;
			}
		}
	}
	for(i=0;i<n;i++){
		flag=0;
		for(k=0;k<on;k++){
			if(i==old[k]){
				flag=1;
				break;
			}
		}
		if(flag==0){
			printf("%s\n",patient[i].id);
		}
	}
	return 0;
}


struct mouse{
	int weight;
	char color[11];
	struct mouse *next,*before;
};
int main(){
	int i,j,n,max;
	scanf("%d",&n);
	struct mouse *m,*head,*p1,*p2,*fin;
	head=p1=p2=(struct mouse *) malloc(sizeof(struct mouse));
	scanf("%s %d",p1->color,&p1->weight);
	for (i=1;i<=n-1;i++){
		p1=(struct mouse *) malloc(sizeof(struct mouse));
		scanf("%s %d",p1->color,&p1->weight);
		p2->next=p1;p1->before=p2;p2=p1;
	}
	fin=p1;
	p1->next=NULL;
	for (i=1;i<=n-1;i++){
		max=0;p1=head;
		for (j=1;j<=n+1-i;j++){
			if (p1->weight>max) {max=p1->weight;m=p1;}
			p1=p1->next;
		}
		if (m->weight<60) break;
		printf("%s\n",m->color);
		if (m==head) {head=head->next;continue;}
		if (m==fin) {fin=fin->before;fin->next=NULL;continue;}
		if (m!=head && m!=fin) {p1=m->before;p1->next=m->next;m=m->next;m->before=p1;}
	}
	p1=head;
	printf("%s\n",head->color);
	for (;p1->next!=NULL;){
		p1=p1->next;printf("%s\n",p1->color);
	}
}


struct data
{
char id[11];
int age;
struct data *next;
}*p1,*p2,*head,*q1,*q2,*qhead;

void main ()
{
	int i,n,k=0;
	struct data * sort( struct data *head,int n);
	void print(struct data *head);
	scanf ("%d",&n);
	head=p1=p2=(struct data *)malloc(LEN);
	head->next=NULL;
	for (i=0;i<n;i++)
	{
		p1=(struct data *)malloc(LEN);
		scanf ("%s %d",p1->id,&p1->age);
		if ((p1->age)>=60)
			k++;
		p2->next=p1;
		p2=p1;
	}
	p2->next=NULL;
	qhead=q1=q2=(struct data *)malloc(LEN);
	qhead->next=NULL;
	for (i=n;i>n-k;i--)
	{
		head=sort(head,i);
	}
	q2->next=NULL;
	q2->next=head->next;
	free(head);
	print(qhead);
}

struct data * sort(struct data *head,int n)
{
	int max=59,i;
	struct data *p1,*p2,*code,*pre;
	p2=head;
	p1=head->next;
	for (i=0;i<n;i++)
	{
		if ((p1->age)>max)
		{
			max=p1->age;
			code=p1;
			pre=p2;
		}
		p1=p1->next;
		p2=p2->next;
	}
	q1=(struct data *)malloc(LEN);
	strcpy(q1->id,code->id);
	q1->age=code->age;
	q2->next=q1;
	q2=q1;

	if (pre==head)
		head->next=code->next;
	else
		pre->next=code->next;
	free(code);
	return (head);
}

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


main()
{     char temp_0[10],id[100][10];
      int i,j,n,max,age[100],num[100],yes[100],ncount=1,temp,num_1;
      scanf("%d",&n);
      for(i=0;i<n;i++)
      {num[i]=i;
      scanf("%s %d",id[i],&age[i]);
      }
      for(j=0;j<n;j++)                      {
                      for(i=0;i<n-j-1;i++)
                     { if(age[i]<age[i+1])
                                         {  strcpy(temp_0,id[i]);
                                            temp=age[i];
                                            num_1=num[i];
                                            strcpy(id[i],id[i+1]);
                                            age[i]=age[i+1];
                                            num[i]=num[i+1];
                                            age[i+1]=temp;
                                            strcpy(id[i+1],temp_0);
                                            num[i+1]=num_1;                             }
                      }}
   for(i=0;i<n;i++)
   {if(age[i]>=60)
   printf("%s\n",id[i]);
   }
   for(j=0;j<n;j++)
                   {for(i=0;i<n-j-1;i++)
                                      {if(num[i]>num[i+1])
                                       {  strcpy(temp_0,id[i]);
                                            temp=age[i];
                                            num_1=num[i];
                                            strcpy(id[i],id[i+1]);
                                            age[i]=age[i+1];
                                            num[i]=num[i+1];
                                            age[i+1]=temp;
                                            strcpy(id[i+1],temp_0);
                                            num[i+1]=num_1;
                                            }}
                       }
    for(i=0;i<n;i++)
    {if(age[i]<60)
    printf("%s\n",id[i]);}
    getchar();
    getchar();  }


int main()
{

struct point
    {
           char x[10];
           int y;
    }
    sz[100];
    struct po
    {
           char a[10];
           int b;
           int c;
    }
    lnr[100];
    int n,temp;
    int tag=0;
    char tem[100];
    int count=0;

    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
            scanf("%s%d",sz[i].x,&sz[i].y);
    }
    for(int j=0;j<n;j++)
    {
          for(int k=tag;k<n;k++)
          {
                  if(sz[k].y>=60)
                  {
                     lnr[j].c=k;
                     lnr[j].b=sz[k].y;
                     strcpy(lnr[j].a,sz[k].x);
                     tag=k+1;
                     count++;
                     break;
                  }
          }

    }
    for(int l=0;l<count-1;l++)
    {
            for(int m=count-1;m>l;m--)
            {
                    if(lnr[m].b>lnr[m-1].b)
                    {
                          temp=lnr[m-1].b;
                          lnr[m-1].b=lnr[m].b;
                          lnr[m].b=temp;

                          strcpy(tem,lnr[m-1].a);
                          strcpy(lnr[m-1].a,lnr[m].a);
                          strcpy(lnr[m].a,tem);
                    }
            }
    }
    tag=n-1;
    for(int o=n-1;o>count-1;o--)
    {
           for(int p=tag;p>=0;p--)
           {
               if(sz[p].y<60)
               {
                             sz[o].y=sz[p].y;
                             strcpy(sz[o].x,sz[p].x);
                             tag=p-1;
                             break;
               }
           }
    }
    for(int q=0;q<count;q++)
    {
            printf("%s\n",lnr[q].a);
    }
    for(int r=count;r<n;r++)
    {
            printf("%s\n",sz[r].x);
    }
return 0;
}


struct student
{
	char num[1000];
	int age;
	struct student *next;
};
struct student *creat(int n)
{
	struct student *p1,*p2,*head;
	int i;
	for (i = 0;i < n;i++)
	{
		p1 = (struct student*)malloc(len);
		scanf("%s%d",p1->num,&p1->age);
		p1->next = NULL;
		if(i == 0)
		{
			p2 = p1;
			head = p1;
		}
		else
		{
			p2->next = p1;
			p2 = p1;
		}
	}
	return (head);
}
struct student *trans(struct student *head,int n)
{
	struct student *p1,*p2,*p3,*p4,*q;
	int i,j;
	for (i = 0;i<n;i++)
	{
         p1 = head;
	     p2 = p1->next;
         p3 = p2->next;
	     p4 = head;
		for(j = 0;p1->next != NULL;j++)
	{
			if(p2->age >=60)
			{
		if(p1->age < p2->age)
		{
			if(p1 == head)
			{
				p2->next = p1;
				p1->next = p3;
				head = p2;
				q = p1;
				p1 = p2;
				p2 = q;
				p4 = head;
			}
			else if(p2 ->next != NULL)
			{
				p1->next = p3;
				p2->next = p1;
				p4->next = p2;
				q = p1;
				p1 = p2;
				p2 = q;
			}
			else
			{
				p2->next = p1;
				p4 ->next = p2;
				p1->next = 0;
				q = p1;
				p1 = p2;
				p2 = q;
			}
		}
		}
            if(p1 != head)
				p4 = p4->next;
			p1 = p1->next;
			p2 = p2->next;
			if (p3 != NULL)
			    p3 = p3->next;
		}
		q = head;
	}
	return(q);
}

	print(struct student *head)
{
	struct student *p;
	p = head;
	for (;p !=NULL;p = p->next)
		printf("%s\n",p->num);
}
main()
{
	struct student *p;
	int n;
	scanf("%d",&n);
	p = creat(n);
	p = trans(p,n);
	print(p);
}


struct patient
{ char id[11];
  int age,seq;
  struct patient *next;
};
main()
{  int n,n1=0,n2=0,i,j,m,at;
   char id[10];
   struct patient *head1,*head2,*p11,*p12,*p21,*p22,*t,*q;
   scanf("%d",&n);
   head1=NULL;
   head2=NULL;
   for(i=0;i<n;i++)
   {
     scanf("%s%d",id,&at);
     if(at>=60)
     {  if(head1==NULL)
	{
         head1=(struct patient*)malloc(sizeof(struct patient));
	 strcpy(head1->id,id);
	 head1->age=at;
         head1->next=NULL;
	}
	else
	{ for(t=head1,q=t;t!=NULL;q=t,t=t->next)
	  {  if(t->age<at&&t!=head1)
	     {

	      p11=(struct patient *)malloc(sizeof(struct patient));
	      p11->age=at;
	      strcpy(p11->id,id);
              q->next=p11;
	      p11->next=t;
              break;
	     }
	     if(t->age<at&&t==head1)
	     {
              p11=(struct patient *)malloc(sizeof(struct patient));
	      p11->age=at;
	      strcpy(p11->id,id);
              p11->next=head1;
	      head1=p11;
	      break;
	     }
	    /* if(t->age==at)
	     {
              p11=(struct patient *)malloc(sizeof(struct patient));
	      p11->age=at;
	      strcpy(p11->id,id);

	      p11->next=t->next;
              t->next=p11;
              break;
	     } */

	  }
	  if(t==NULL)
          {
            p11=(struct patient *)malloc(sizeof(struct patient));
	    p11->age=at;
	    strcpy(p11->id,id);
            q->next=p11;
            p11->next=NULL;
          }

	}
     }

     if(at<60)
     {  if(head2==NULL)
	{
         head2=(struct patient*)malloc(sizeof(struct patient));
	 strcpy(head2->id,id);
	 head2->age=at;
	 head2->next=NULL;
	 p22=head2;
	}
        else
       {
          p21=(struct patient *)malloc(sizeof(struct patient));
          p21->age=at;
	  strcpy(p21->id,id);
          p22->next=p21;
          p21->next=NULL;
          p22=p21;
       }
     }

   }

   for(t=head1,q=t;t!=NULL;q=t,t=t->next);

    q->next=head2;
   for(t=head1;t->next!=NULL;t=t->next)
   { printf("%s\n",t->id);

   }
   printf("%s",t->id);
}


void bubble_sort(int a[100], char b[100][10], int n)
{
	int i, j, temp;
	char temp_[10]={0}, empty[10]={0};
	for (j=1; j<n; j++)
		for(i=0; i<n-j; i++)
		{
			if (a[i]<a[i+1])
			{
				temp=a[i];
				strcpy(temp_,b[i]);
				a[i]=a[i+1];
				strcpy(b[i], empty);
				strcpy(b[i], b[i+1]);
				a[i+1]=temp;
				strcpy(b[i+1], empty);
				strcpy(b[i+1], temp_);

			}
		}
}

int main()
{
	int age[100], Age_[100]={0}, age_[100];
	int n, i;
	char id[100][10], Id_[100][10]={0}, id_[100][10]={0}, empty[10]={0};
	scanf("%d", &n);
	for(i=0; i<n; i++)
		scanf("%s%d", id[i], &age[i]);
	for(i=0; i<n; i++)
	{
		if(age[i]>=60)
		{
			Age_[i] = age[i];
			strcpy(Id_[i], id[i]);
		}
		else
		{
			age_[i] = age[i];
			strcpy(id_[i], id[i]);
		}
	}
	bubble_sort(Age_, Id_, n);
	for(i=0;i<n; i++)
	{
		if(strcmp(Id_[i], empty)==0)
			continue;
		else
			printf("%s\n", Id_[i]);
	}
	for(i=0;i<n; i++)
	{
		if(strcmp(id_[i], empty)==0)
			continue;
		else
			printf("%s\n", id_[i]);
	}
	return 0;
}


struct person
{
	char id[10];
	int age;
	struct person *next;
};
void main()
{
	int n,i,j;
	struct person *head,*ppre,*pnew,*p;

	scanf("%d",&n);
	pnew=(struct person *)malloc(len);
	scanf("%s %d\n",pnew->id,&pnew->age);
	pnew->next=NULL;
	head=pnew;
	for(i=2;i<=n;i++)
	{
		p=head;
		ppre=head;
		pnew=(struct person *)malloc(len);
	    scanf("%s %d",pnew->id,&pnew->age);
    	pnew->next=NULL;
		if((pnew->age>=60)&&(pnew->age>head->age))
		{
			pnew->next=head;
			head=pnew;
		}
		else
		{
			if (pnew->age>=60)
			{
				p=p->next;
				for(j=2;j<i;j++)
				{
					if(pnew->age>p->age)
					{
						pnew->next=p;
						ppre->next=pnew;
						break;
					}
					p=p->next;
					ppre=ppre->next;
				}
	    	    if(pnew->next==NULL)
		    	    ppre->next=pnew;
			}
			else
			{
				while (p->next!=NULL)
					p=p->next;
				p->next=pnew;
			}
		}
	}
	p=head;
	for(i=0;i<n;i++)
	{
		printf("%s\n",p->id);
		p=p->next;
	}
}


int main()
{
	int	i, j, n, sr=0, jr=0, age, srage[100], jrage[100];
	char num[10], srnum[100][10], jrnum[100][10];
	scanf("%d", &n);
	for(i=0; i<n; i++)
	{
		scanf("%s %d", &num, &age);
		if(age<60)
		{
			strcpy(jrnum[jr],num);
			jrage[jr]=age;
			jr++;
		}
		else
		{
			strcpy(srnum[sr],num);
			srage[sr]=age;
			sr++;
		}
	}
	for(i=sr-1; i>=0; i--)
	{
		for(j=0; j<i; j++)
		{
			if(srage[j]<srage[j+1])
			{
				age=srage[j];
				srage[j]=srage[j+1];
				srage[j+1]=age;
				strcpy(num,srnum[j]);
				strcpy(srnum[j],srnum[j+1]);
				strcpy(srnum[j+1],num);
			}
		}
	}
	for(i=0; i<sr; i++) printf("%s\n", srnum[i]);
	for(i=0; i<jr; i++) printf("%s\n", jrnum[i]);
	return 0;
}


int main()
{
    struct  pa
    {
            char ID[11];
            int age;
            struct pa *next;
    }*head,*p1,*p2,*p3,*p4;
    int tage;
    char tID[11];
    int n,i,j;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
                    p1=(struct pa*)malloc(sizeof(struct pa));
                    if(i==0)
                    head=p1;
                    scanf("%s %d",p1->ID,&p1->age);
                    if(i!=0)
                    p2->next=p1;
                    p2=p1;
    }
    p1->next=NULL;
    p1=head;
    p2=p1->next;
    for(i=0;i<n;i++)//??
    {
                    p3=p1;
                    p4=p2;
                    for(j=0;j<n-1;j++)
                    {
                              if(p3->age<p4->age && p4->age>=60)
                              {
                                                 strcpy(tID,p3->ID);
                                                 tage=p3->age;
                                                 strcpy(p3->ID,p4->ID);
                                                 p3->age=p4->age;
                                                 strcpy(p4->ID,tID);
                                                 p4->age=tage;
                              }
                              p3=p3->next;
                              p4=p4->next;
                    }
    }
    p1=head;
    while(p1!=NULL)
    {
                   printf("%s\n",p1->ID);
                   p1=p1->next;
    }
    return 0;
}


int main(int argc, char *argv[])
{
  struct fy{
         char a[12];
         int k;
         int s;
         struct fy *p;
         }x[100],*head;
  int n,i,j,l,kk,ss;
  char aa[12];
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
     scanf("%s %d",x[i].a,&x[i].k);
     x[i].s=x[i].k>=60?1:0;
     x[i].p=&x[i+1];
  }
  head=&x[0];
  x[n-1].p=NULL;
  for(i=0;i<n;i++)
  {
       for(j=i+1;j<n;j++)
       {
             if(x[i].s==1&&x[j].s==1)
             {
                  if(x[i].k<x[j].k)
                  {
                       kk=x[j].k;
                       ss=x[j].s;
                       strcpy(aa,x[j].a);
                       for(l=j;l>i;l--)
                       {
                           x[l].k=x[l-1].k;
                           x[l].s=x[l-1].s;
                           strcpy(x[l].a,x[l-1].a);
                       }
                         x[i].k=kk;
                  x[i].s=ss;
                  strcpy(x[i].a,aa);
                  }

             }
       }
       if(x[i].s==1)
       printf("%s\n",x[i].a);
  }
  while(head!=NULL)
  {
       if(head->s==0)
       printf("%s\n",head->a);
       head=head->p;
  }
  return 0;
}


struct patient
{	char ID[10];
	int age;
	int a6;
	char Id[10];
};

void main()
{	struct patient bin[N];
	int n,mid;
	char s[10];
	int i=0,j=0,k=0;
	char c[10];
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%s%d",&bin[i].ID,&bin[i].age);

	for(i=0;i<n;i++)
	{	if(bin[i].age>=60)
		{	bin[j].a6=bin[i].age;
			strcpy(bin[j].Id,bin[i].ID);
			j++;
			bin[i].age=0;

		}
	}
	for(k=1;k<j;k++)
	{	for(i=0;i<j-k;i++)
		if(bin[i].a6<bin[i+1].a6)
		{	mid=bin[i].a6;
			bin[i].a6=bin[i+1].a6;
			bin[i+1].a6=mid;

			strcpy(c,bin[i].Id);
			strcpy(s,bin[i+1].Id);
			strcpy(bin[i+1].Id,c);
			strcpy(bin[i].Id,s);
		}
	}
	for(i=0;i<j;i++)
		printf("%s\n",bin[i].Id);

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

}


struct stu{
         char n[30];
         int y;
       };

void sort(struct stu a[],int l, int r)
{
     int i=l,j=r,t=a[(l+r)/2].y;

     struct stu temp;
     while (i<=j)
     {
          while (a[i].y>t) i++;
          while (a[j].y<t) j--;
          if (i<=j)
              {
                  temp=a[i];
                  a[i]=a[j];
                  a[j]=temp;
                  i++;
                  j--;
              }

     }
     if (l<j) sort(a,l,j);
     if (i<r) sort(a,i,r);
}

int main()
{
   int n;
   struct stu a[1000],b[1000],c[1000],temp;
   int i,j,tot=0,totc=0;

   scanf("%d",&n);

   for (i=1;i<=n;i++)
       {
          scanf("%s %d",&a[i].n,&a[i].y);
          if (a[i].y>=60)
             {
                b[++tot]=a[i];
             } else
             {
                c[++totc]=a[i];
             }

       }

   for (i=1;i<tot;i++)
      for (j=2;j<=tot-i+1;j++)
        if (b[j-1].y<b[j].y)
           {
               temp=b[j-1];
               b[j-1]=b[j];
               b[j]=temp;

           }

   for (i=1;i<=tot;i++) printf("%s\n",b[i].n);
   for (i=1;i<=totc;i++) printf("%s\n",c[i].n);

 //  scanf("%d",&n);

   return 0;

}


struct RAT
{
	int weight;
	char color[10];
	struct RAT *next;
};
int N;
int main()
{

    void sort(struct RAT *p);
	int i;
	scanf("%d",&N);

	struct RAT *head,*p1,*p2;
	p1=(struct RAT *)malloc(Len);
	scanf("%s %d",p1->color,&p1->weight);
	p1->next=NULL;
	head=p1;
	p2=p1;

	for (i=1;i<N;i++)
	{
		p1=(struct RAT *)malloc(Len);
		scanf("%s %d",p1->color,&p1->weight);
	    p1->next=NULL;
		p2->next=p1;
		p2=p1;
	}
	sort (head);
	for (p1=head;p1!=NULL;p1=p1->next)
		printf("%s\n",p1->color);

	return 0;
}

void sort(struct RAT *p)
{
	int j,i;
	struct RAT *pt,temp;
	for(j=0;j<N;j++)
		for(pt=p,i=0;i<N-j-1;pt=pt->next,i++)
		{
			if((pt->weight<60&&pt->next->weight>=60)||(pt->weight>=60&&pt->next->weight>=60&&pt->weight<pt->next->weight))
			{
				temp=*pt;
				pt->weight=pt->next->weight;
				strcpy(pt->color,pt->next->color);
				pt->next->weight=temp.weight;
				strcpy(pt->next->color,temp.color);
			}
		}
}


struct P
{
char id[10];
int age;
}
pa[100];
struct P pb[100];
int main(){
	int n,r=0,s=0,i,o,p,j,k;
	scanf("%d",&n);
	struct P temp;
	for(i=0;i<n;i++){
              scanf("%s%d",temp.id,&(temp.age));
			  if(temp.age>=60){
				  pb[r]=temp;
				  r++;
			  }else{
				  pa[s]=temp;
				  s++;
			  }
	}
			  for(o=0;o<r;o++){
				  for(p=0;p<r-o;p++){
					  if(pb[p].age<pb[p+1].age){
						  struct P tmp=pb[p];
						  pb[p]=pb[p+1];
						  pb[p+1]=tmp;
					  }
				  }
			  }
			  for(j=0;j<r;j++){
				  printf("%s\n",pb[j].id);
			  }
			  for(k=0;k<s;k++){
				  printf("%s\n",pa[k].id);
			  }
	return 0;
}


// ??(14-6) ????.cpp : Defines the entry point for the console application.
//

struct patient
{
	char id[20];
	int age;
	int num;
};

int main()
{
	int n;
	scanf("%d",&n);
	int i,j;
	struct patient p[100];
	for(i=1;i<=n;++i)
	{
		scanf("%s%d",&p[i].id,&p[i].age);
		p[i].num=i;
	}
	for(i=1;i<=n-1;++i)
	{
		for(j=i+1;j<=n;++j)
		{
			if(p[j].age>p[i].age)
			{
				struct patient t;
				t=p[i];
				p[i]=p[j];
				p[j]=t;
			}
		}
	}
	for(i=1;p[i].age>=60;++i)
	{
		for(j=i+1;p[j].age==p[i].age;++j)
		{
			if(p[i].num>p[j].num)
			{
				struct patient t;
				t=p[i];
				p[i]=p[j];
				p[j]=t;
			}
		}
		printf("%s\n",p[i].id);
	}
	for(j=i;j<=n;++j)
	{
		int k;
		for(k=j+1;k<=n;++k)
		{
			if(p[j].num>p[k].num)
			{
				struct patient t;
				t=p[j];
				p[j]=p[k];
				p[k]=t;
			}
		}
		printf("%s\n",p[j].id);
	}
	return 0;
}


struct pa{
	char num[15];
	int age;
	struct pa *next;
};
int main()
{
    struct pa *p,*p1,*p2;
	int i=0,n;
	scanf("%d",&n);
	p1=(struct pa *)malloc(LEN);
	scanf("%s%d",p1->num,&p1->age);
	p1->next=NULL;
	p2=p1;
	p=p2;
	for(i=1;i<n;i++){
	    p1=(struct pa *)malloc(LEN);
		scanf("%s%d",p1->num,&p1->age);
		if(p1->age<60){
			while(p2->next!=NULL)
				p2=p2->next;
			p2->next=p1;
			p1->next=NULL;
		}
		else{
			if(p->age<p1->age){
				p1->next=p;
				p=p1;
			}
			else{
				while(p2->next!=NULL&&(p2->next)->age>=p1->age)
				p2=p2->next;
			p1->next=p2->next;
			p2->next=p1;
			}
		}
		p2=p;
	}
	while(p!=NULL){
		printf("%s\n",p->num);
		p=p->next;
	}
	return 0;
}


int main()
{
	struct patient
	{char id[10];
	int age;
	}patient[100],old[100],t;
	int a,i=0,j=0,k=0,r,i1;
	scanf("%d",&a);
	getchar();
	for(i=0;j+i<a;i++)
	{
		scanf("%s%d",patient[i].id,&patient[i].age);
		if(patient[i].age>=60)
		{
			old[j]=patient[i];
			j++;
			i--;
		}
	}
	for(r=0;r<j-1;r++)
		for(k=0;k<j-1-r;k++)
			if(old[k].age<old[k+1].age)
			{t=old[k];old[k]=old[k+1];old[k+1]=t;}
	for(r=0;r<j;r++)
		printf("%s\n",old[r].id);
	for(r=0;r<i;r++)
		printf("%s\n",patient[r].id);
	return 0;
}


struct patient{
  char id[10];
  int age;
}young[100],old[100];

int main(){
   int i,j,n,temp,yn=0,on=0,people[150]={0};
   char t[10];
   scanf("%d",&n);
   for(i=0;i<n;i++){
       scanf("%s%d",t,&temp);
       if(temp>=60){
          strcat(old[on].id,t);
          old[on].age=temp;
          on++;
          people[temp]++;
       }
       else{
          strcat(young[yn].id,t);
          young[yn].age=temp;
          yn++;
       }
   }
   for(i=149;i>=60;i--){
       if(people[i]>0){
          for(j=0;j<on;j++)
             if(old[j].age==i)
                printf("%s\n",old[j].id);
       }
   }
   for(i=0;i<yn;i++)
     printf("%s\n",young[i].id);
}


struct pa
{
	char id[10];
	int age;
}patient[100],patient2[100];

void main()
{
	int i,k,m,n,j,temp;
	char id2[10];
	scanf("%d\n",&n);							//input the patient number

	for(i=0;i<n;i++)							//insert the information of the patients
	{
		scanf("%s %d\n",patient[i].id,&patient[i].age);
	}
	for(i=0,j=0;i<n;)							//deal with the information
	{
		if(patient[i].age>=60)
		{
 			strcpy(patient2[j].id,patient[i].id);
			patient2[j].age=patient[i].age;
												//	printf("%d ",patient2[j].age);
			j++;
			for(k=i;k<n-1;k++)
			{
				strcpy(patient[k].id,patient[k+1].id);
				patient[k].age=patient[k+1].age;
			}
			n--;
		}
		else i++;
	}
//	printf("\n");
//	printf("%d",j);
	for(i=1;i<j;i++)
	{
		for(k=0;k<i;k++)
		{
			if(patient2[i].age>patient2[k].age)
			{
				temp=patient2[i].age;
				strcpy(id2,patient2[i].id);
				for(m=i;m>k;m--)
				{
					patient2[m].age=patient2[m-1].age;
					strcpy(patient2[m].id,patient2[m-1].id);
				}
				patient2[k].age=temp;
				strcpy(patient2[k].id,id2);
			}
//			printf("\n");
//			printf("%d %d ",patient2[i].age,patient2[i+1].age);
		}
	}

	for(i=0;i<j;i++)printf("%s\n",patient2[i].id);
 	for(i=0;i<n;i++)printf("%s\n",patient[i].id);
}


struct pat
{
       char num[10];
       int age;
       int turn;
} pa[100],temp,temp2;

int main()
{
    int i,j,t,s,n,m;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
                     scanf("%s %d",&pa[i].num,&pa[i].age);
                     pa[i].turn=i;
    }
    for(i=1;i<=n;i++)
    {
                     if(pa[i].age>=60)
                     {
                                      for(j=1;j<=i;j++)
                                      {
                                                       if(pa[i].age>pa[j].age)
                                                       {
                                                                              temp=pa[j];
                                                                              pa[j]=pa[i];
                                                                              for(t=i-1;t>j;t--)
                                                                              {
                                                                                pa[t+1]=pa[t];
                                                                              }
                                                                              pa[j+1]=temp;
                                                                              break;
                                                       }
                                      }

                     }

    }
    for(i=1;i<=n;i++)
    {

                                                        puts(pa[i].num);

    }

    return 0;
}


struct patient
{
char ID[10];
int age;
struct patient *next;
};

void sort(struct patient * head,struct patient * q)
{
struct patient *pre=head,*p=pre->next,*s;
s=(struct patient *)malloc(sizeof(struct patient));
s->age=q->age;strcpy(s->ID,q->ID);
s->next=NULL;
if(q->age>=60)
{
while((p!=NULL)&&(q->age<=p->age))
{
pre=p;
p=p->next;
}
pre->next=s;
s->next=p;
}
else
{
while(p!=NULL)
{
pre=p;
p=p->next;
}
pre->next=s;
s->next=p;
}
}

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

}
void main()
{
int n,i;
struct patient *head;
struct patient *p;
head=(struct patient *)malloc(sizeof(struct patient));
head->next=NULL;
scanf("%d",&n);
for (i=1;i<=n;i++)
{
p=(struct patient *)malloc(sizeof(struct patient));
scanf("%s %d",p->ID,&p->age);
sort(head,p);
}
print(head->next);
}


int main(){
	int n;
	int i,j=0;
	scanf("%d",&n);
	char **id=(char**)malloc(sizeof(char*)*n);
	for(i=0;i<n;i++){
		id[i]=(char*)malloc(sizeof(char)*10);
	}
	int p=0;
	int *year=(int*)malloc(sizeof(int)*n);
	for(i=0;i<n;i++){
		scanf("%s %d",id[i],&year[i]);
		if(year[i]>=60){
			p++;
		}
	}
	char **idolder=(char**)malloc(sizeof(char*)*p);
	for(i=0;i<n;i++){
		idolder[i]=(char*)malloc(sizeof(char)*10);
	}
	int *yearolder=(int*)malloc(sizeof(int)*p);
	for(i=0;i<n;i++){
		if(year[i]>=60){
			idolder[j]=id[i];
			yearolder[j]=year[i];
			j++;
		}
	}
	int e;
	char *id1=(char*)malloc(sizeof(char)*10);
	for(i=1;i<=p;i++){
		for(j=0;j<p-i;j++){
			if(yearolder[j+1]>yearolder[j]){
				id1=idolder[j];
				idolder[j]=idolder[j+1];
				idolder[j+1]=id1;
				e=yearolder[j];
				yearolder[j]=yearolder[j+1];
				yearolder[j+1]=e;
			}
		}
	}
	for(i=0;i<p;i++){
		printf("%s\n",idolder[i]);
	}
	for(i=0;i<n;i++){
		if(year[i]<60){
			printf("%s\n",id[i]);
		}
	}

return 0;
}


struct patient
{
	char id[20];
	int age;
};
int main()
{
	int i,j,tem,n,len;
	char id[20];
	struct patient a[200];
	scanf("%d",&n);
	for (i=0;i<n;i++)
		scanf("%s%d",a[i].id,&a[i].age);
	for (i=0;i<n;i++)
	{
		for (j=n-2;j>=i;j--)
			if (a[j+1].age>=60&&a[j+1].age>a[j].age)
			{
				tem=a[j].age;
				a[j].age=a[j+1].age;
				a[j+1].age=tem;
				len=strlen(a[j].id);
				strcpy(id,a[j].id);
				id[len]='\0';
				strcpy(a[j].id,a[j+1].id);
				strcpy(a[j+1].id,id);
			}
		printf("%s\n",a[i].id);
	}
	return 0;
}


struct patient
{
	char id[10];
   short int age;
};
   void main()
   {
     int i,j,k,l,n;
	 struct patient pat[100],temp;
	 struct patient pa[100];
     scanf("%d",&n);
	 for(i=0;i<n;i++)
		 scanf("%s %d",&pat[i].id,&pat[i].age);
	 for(i=0,j=0;i<n;i++)

		 if(pat[i].age>=60)
	 {
       pa[j]=pat[i];
	   j++;
	 }
		 for(k=0;k<j-1;k++)
			 for(l=j-1;l>k;l--)
			    if(pa[l].age>pa[l-1].age)
			  {
                temp=pa[l];
				pa[l]=pa[l-1];
				pa[l-1]=temp;
			  }
      for(k=0;k<j;k++)
		  printf("%s\n",pa[k].id);

     for(i=0;i<n;i++)
		 if(pat[i].age<60)
		printf("%s\n",pat[i].id);
   }


struct patient
{

	char id[10];
	int age;
	struct patient *next;
};

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

struct patient *tiao(struct patient *head,int n)
{
	struct patient *p1;
	int t,i;
	char s[10];
	p1=head;
   for(i=0;i<n;i++)
   {
	   p1=head;
	do
	{
		if(p1->age<(p1->next)->age&&(p1->next)->age>=60)
		{
			t=p1->age;
			p1->age=(p1->next)->age;
			(p1->next)->age=t;
			strcpy(s,p1->id);
			strcpy(p1->id,(p1->next)->id);
			strcpy((p1->next)->id,s);
		}
		p1=p1->next;
	}while(p1->next);
   }

	return(head);
}

void print(struct patient *head)
{
	struct patient *p;
	p=head;

	do
	{
		printf("%s\n",p->id);
		p=p->next;
	}while(p);
}

void main()
{
	struct patient *head;
	int n;
	scanf("%d",&n);
	head=creat(n);
	head=tiao(head,n);
	print(head);
}


struct patient
{
	char name[10];
	int age;
}pat[100];
void main()
{
	int n,i,j=0,k=0,l;
	struct patient b[100];
	struct patient c[100];
	struct patient t;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%s %d",pat[i].name,&pat[i].age);
    for(i=0;i<n;i++)
	{
		if(pat[i].age<60)
		{
			  b[j]=pat[i];
		      j++;
		}
		else
		{
			c[k]=pat[i];
		    k++;
		}
	}
	for(i=0;i<k-1;i++)
		for(l=0;l<k-1-i;l++)
			if(c[l].age<c[l+1].age)
			{
				t=c[l];
				c[l]=c[l+1];
				c[l+1]=t;
			}
	for(i=0;i<k;i++)
		printf("%s\n",c[i].name);
	for(i=0;i<j;i++)
        printf("%s\n",b[i].name);
}


int main()
{
	struct pa
	{
		char ID[10];
        int age;
	}
	*p;
	int n, i, k, num=0, m=0;
	scanf("%d",&n);
	p=(struct pa*)malloc(sizeof(struct pa)*n);
	for(i=0;i<n;i++)
	{
		scanf("%s%d",p[i].ID, &p[i].age);
		if(p[i].age>=60) num++;
	}

	int w=0;
    for(i=0;i<n;i++)
	{
		if(p[i].age>=60)
		{
			struct pa q=p[i];
			for(k=i;k>w;k--)
			{
				p[k]=p[k-1];
			}
			p[w]=q;
			w++;
		}
	}

	for(i=num-1;i>0;i--)
	{
		for(k=0;k<i;k++)
		{
			if(p[k].age<p[k+1].age)
			{
				struct pa q=p[k];
				p[k]=p[k+1];
				p[k+1]=q;
			}
		}
	}
	for(i=0;i<n;i++)
	{
		printf("%s\n",p[i].ID);
	}
	free(p);
	return 0;
}


int main()
{
    int i,j,k,n;
    char a[11];
    int b;
    scanf("%d",&n);
    struct patient
    {
           char num[11];
           int age;
           }pat[100];
    for(i=0;i<n;i++){
                     scanf("%s%d",pat[i].num,&pat[i].age);
                     }
    for(i=0;i<n;i++){
                       for(j=0;j<n-1-i;j++){
                                            if(pat[j].age<pat[j+1].age&&pat[j+1].age>=60){
                                                                        for(k=0;k<10;k++){
                                                                                a[k]=pat[j].num[k];
                                                                                pat[j].num[k]=pat[j+1].num[k];
                                                                                pat[j+1].num[k]=a[k];
                                                                                }

                                                                        b=pat[j].age;
                                                                        pat[j].age=pat[j+1].age;
                                                                        pat[j+1].age=b;
                                                                        }
                                            }
                       }
    for(i=0;i<n;i++){
                       printf("%s\n",pat[i].num);
                       }

    return 0;
    }


struct mice
{
	int wei;
	char color[100];
	struct mice *next;
};
struct mice *creat(int c)
{
	struct mice *head;
	struct mice *p1,*p2;
	struct mice *kok;
	kok=(struct mice*)malloc(LEN);
	kok->wei=0;strcpy(kok->color,"\0");
	int t;
	t=0;
	p1=p2=(struct mice*)malloc(LEN);
	scanf("%s %d",p1->color,&p1->wei);
	head=NULL;
	while(t<c)
	{
		t=t+1;
		if(t==1)
		{head=p1;}
		else
		{
			p2->next=p1;
			p2=p1;
			p1=(struct mice*)malloc(LEN);
			scanf("%s %d",p1->color,&p1->wei);
		}
	}
	p2->next=p1;
    p2=p1;
	p2->next=kok;
return(head);
}
	void mun(struct mice *hoih,int io)
	{
		int i,j,k;
		k=0;
		struct mice *bt;
        bt=hoih;
		char str[100];
			for(i=0;i<io;i++)
	{
		for(j=0;j<io-i;j++)
		{
			if(hoih->wei<(hoih->next)->wei&&(hoih->next)->wei>=60)
			{
				k=hoih->wei;
				hoih->wei=(hoih->next)->wei;
				(hoih->next)->wei=k;
				strcpy(str,hoih->color);
				strcpy(hoih->color,(hoih->next)->color);
				strcpy((hoih->next)->color,str);
			}

			hoih=hoih->next;
		}
		hoih=bt;
	}
    return;
}

void main()
{
	int n,h;
	struct mice *creat(int c);
	struct mice *p,*he;
	scanf("%d",&n);
	p=creat(n);
	he=p;
	void mun(struct mice *hoih,int io);
	mun(p,n);
	p=he;
    	for(h=0;h<n;h++)
		{
			printf("%s\n",p->color);
			p=p->next;
		}
}


struct patient{
	char id[10];
	int age;
	struct patient* next;
	struct patient* last;
};
char temp[10];
int main()
{
	struct patient *p1,*p2,*head,p[N];
	int n,i,j,tmp;
	scanf("%d",&n);
	memset(p,0,sizeof(p));
	head=p+1;
	for(i=1;i<=n;i++)
	{
	 scanf("%s %d",p[i].id,&p[i].age);
	 p[i].last=p+i-1;
	 p[i].next=p+i+1;
	}
	head->last=NULL;
	p[i].next=NULL;
	for(i=n;i>1;i--)
	{
		for(j=1;j<n;j++)
		{
			if((p+j+1)->age>=60&&(p+j+1)->age>(p+j)->age)
			{
				memcpy(temp,(p+j)->id,sizeof(temp));
				memcpy((p+j)->id,(p+j+1)->id,sizeof(temp));
				memcpy((p+j+1)->id,temp,sizeof(temp));
				tmp=(p+j)->age;
				(p+j)->age=(p+j+1)->age;
				(p+j+1)->age=tmp;
			}
		}
	}
	for(;head!=NULL;head=head->next)
	printf("%s\n",head->id);

}


struct
{
int age[100];
char ID[100][11];
}patient,*ppatient;
int main()
{
	ppatient=&patient;
	int n,i,j,k,num,m=0;
	char id[11],ID_1[100][11],age_1[100];
	scanf("%d",&n);
	for(i=0;i<n;i++){
	scanf("%s %d",patient.ID[i],&patient.age[i]);
	}
	j=0;
	for(i=0;i<n;i++){
		if((*ppatient).age[i]>=60){
		strcpy(ID_1[j],(*ppatient).ID[i]);
		age_1[j]=(*ppatient).age[i];
		m+=1;
		j++;
		}
	}
	for(j=m-1;j>0;j--){
		for(k=0;k<j;k++){
			if(age_1[k]<age_1[k+1]){
			strcpy(id,ID_1[k+1]);
			strcpy(ID_1[k+1],ID_1[k]);
			strcpy(ID_1[k],id);
			num=age_1[k+1];
			age_1[k+1]=age_1[k];
			age_1[k]=num;
			}
		}
	}
	for(i=0;i<m;i++){
	printf("%s\n",ID_1[i]);
	}
	for(i=0;i<n;i++){
	if((*ppatient).age[i]<60)
		printf("%s\n",(*ppatient).ID[i]);
	}
	return 0;
}


struct bingren
{
	   char id[10];
	   int o;
}bingren[201];
void main()
{
   int n,i,j,y,m;
   scanf("%d",&n);
   for(i=0;i<n;i++)
   {
	   scanf("%s%d",bingren[i].id,&bingren[i].o);
   }
   for(i=0,j=100;i<n;i++)
   {

	   if(bingren[i].o>=60)
	   {
		   bingren[j]=bingren[i];
		   j++;
	   }
   }
   y=j;
   for(j=0;j<y-1;j++)
   {
	   for(i=100;i<y-j;i++)
	   {
		   if(bingren[i].o<bingren[i+1].o)
		   {
			   bingren[200]=bingren[i];
			   bingren[i]=bingren[i+1];
			   bingren[i+1]=bingren[200];
		   }
	   }
   }
   for(i=100;i<y;i++)
   {
	   printf("%s\n",bingren[i].id);
   }
   for(i=0;i<n;i++)
   {
	   if(bingren[i].o<60)
		   printf("%s\n",bingren[i].id);
   }
}


struct ILL{
	char id[10];
	int age;
};
int main()
{
	struct ILL ill[100];
    int n,i,k,j=0,Age[100],x;
	char a[100][10],b[10];
	scanf("%d",&n);
	for (i=0;i<n;i++){
		scanf("%s",ill[i].id);
	    scanf("%d",&ill[i].age);
	    if (ill[i].age>=60)
		{ strcpy(a[j],ill[i].id);
		  Age[j]=ill[i].age;
		  j++;
		}
	}
	for (i=0;i<j-1;i++){
		for (k=0;k<j-i-1;k++){
			if (Age[k]<Age[k+1]){
				strcpy(b,a[k+1]);
			    strcpy(a[k+1],a[k]);
			    strcpy(a[k],b);
				x=Age[k];
				Age[k]=Age[k+1];
				Age[k+1]=x;
			}
		}
	}
	for (i=0;i<j;i++){
		puts(a[i]);
	}
	for (i=0;i<n;i++){
		if (ill[i].age<60){
			printf("%s\n",ill[i].id);
		}
	}
	return 0;
}


int main()
{
	struct date
	{
		char a[10];
		int num;
		struct date *next;
	};
	struct date *p1,*p2,*head;
	int n,i,temp,j,compare;
	char tem[10];
	scanf("%d",&n);
	head=p1=p2=(struct date *)malloc(len);
	scanf("%s %d",head->a,&head->num);
	head->next=NULL;
	head=p1;
	for(i=2;i<=n;i++)
	{
		p2=(struct date *)malloc(len);
		scanf("%s %d",p2->a,&p2->num);
		p2->next=NULL;
		p1->next=p2;
		p1=p2;
	}
	for(i=n-1;i>=1;i--)
	{
		p1=head;p2=p1->next;
		for(j=1;j<=i;j++)
		{
			compare=strcmp(p1->a,p2->a);
			if(p1->num<60&&p2->num>=60)
			{
				strcpy(tem,p1->a);
				strcpy(p1->a,p2->a);
				strcpy(p2->a,tem);
				temp=p2->num;
				p2->num=p1->num;
				p1->num=temp;
			}
			if(p1->num>=60&&p2->num>=60&&p1->num<p2->num)
			{
				strcpy(tem,p1->a);
				strcpy(p1->a,p2->a);
				strcpy(p2->a,tem);
				temp=p2->num;
				p2->num=p1->num;
				p1->num=temp;
			}
			p1=p2;
			p2=p1->next;
		}
	}
	p1=p2=head;
	for(i=1;i<=n;i++)
	{
		printf("%s\n",p2->a);
		p1=p2;
		p2=p1->next;
	}
	return 0;
}


main()
{
struct patient{
       char id[11];
       int age;
       }ren[100];
struct oldp{
       char idold[11];
       int ageold;
       }oldren[100];
struct youngp{
       char idyoung[11];
       int ageyoung;
       }youngren[100];//?????
int old[100],young[100];
int n,i,t,j,oldindex=0,youngindex=0;
char num[4],idinter[11];
gets(num);
n=atoi(num);
for(i=0;i<n;i++){
   scanf("%s %d",ren[i].id,&ren[i].age);//??id???
   }
for(i=0;i<n;i++){
   if(ren[i].age>=60){
      oldren[oldindex].ageold=ren[i].age;
      strcpy(oldren[oldindex].idold,ren[i].id);
      oldindex+=1;//???????
      }else{
           youngren[youngindex].ageyoung=ren[i].age;
           strcpy(youngren[youngindex].idyoung,ren[i].id);
           youngindex+=1;
            }//???????
   }
for(i=1;i<oldindex;i++){
   for(j=0;j<oldindex-i;j++){
      if(oldren[j].ageold<oldren[j+1].ageold){
        t=oldren[j].ageold;
        oldren[j].ageold=oldren[j+1].ageold;
        oldren[j+1].ageold=t;//????????
        strcpy(idinter,oldren[j].idold);//?????????id?
        strcpy(oldren[j].idold,oldren[j+1].idold);
        strcpy(oldren[j+1].idold,idinter);
        }
      }
   }
for(i=0;i<oldindex;i++){
   printf("%s\n",oldren[i].idold);
   }
for(i=0;i<youngindex;i++){
    printf("%s\n",youngren[i].idyoung);
   }
   }


struct patient {
	int order;
	int age;
	char id[10];
};

int cmp(const void *a, const void *b) {
	const struct patient *pa = (const struct patient *) a;
	const struct patient *pb = (const struct patient *) b;
	if ((pa->age >= 60) && (pb->age < 60)) {
		return -1;
	}
	else if ((pa->age < 60) && (pb->age >= 60)) {
		return 1;
	}
	else if ((pa->age >= 60) && (pa->age != pb->age)) {
		return pb->age - pa->age;
	}
	else {
		return pa->order - pb->order;
	}
}

int main() {
	int i, num;
	struct patient pat[100];

	scanf("%d", &num);
	for (i = 0; i < num; ++i) {
		pat[i].order = i;
		scanf("%s %d", pat[i].id, &(pat[i].age));
	}

	qsort(pat, num, sizeof(struct patient), cmp);

	for (i = 0; i < num; ++i) {
		printf("%s\n", pat[i].id);
	}
}


struct student
{
	char num[200];
	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++)
	{
		p2=(struct student*)malloc(sizeof(struct student));
		if(i==0)
		{head=p2;p3=head;}
		scanf("%s %d",p2->num,&p2->sum);
			p2->next=NULL;
		if(p2->sum>=60){
           if(i==1){
			if(head->sum>=p2->sum){
			  head->next=p2;
			  p2->next=NULL;p3=p2;
			}
			else{p1=head;
			  p2->next=head;
			  head=p2;
			}
		}
	   if(i>1){
		for(p1=head;p1->next!=NULL;p1=p1->next){
			if(p1->sum>=p2->sum&&(p1->next->sum)<p2->sum){
				   p2->next=p1->next;
				   p1->next=p2;
				   break;
				}
			}
		if(p2->next==NULL){
			if(p2->sum>head->sum){
			   p2->next=head;
			     head=p2;
			}
			if(p2->sum<p1->sum){
		            p2->next=NULL;p3=p2;
			    p1->next=p2;
		        }
			}
	   }
		}
		else{
			if(i!=0){
		 p2->next=NULL;
		 p3->next=p2;p3=p2;}
		}
	}
	p1=head;
    for (i=0;(i<n&&p1!=NULL);i++)
	{
		printf("%s\n",p1->num);
		p1=p1->next;
	}
}


struct a
{int year;
 char id[10];
 struct a *next;
};
struct a *create(int n)
{struct a *p1,*p2,*head;
int i;
p1=(struct a*)malloc(len);
scanf("%s%d",p1->id,&p1->year);
p1->next=NULL;
head=p1;
p2=p1;
for(i=1;i<n;i++)
{p1=(struct a*)malloc(len);
scanf("%s%d",p1->id,&p1->year);
p1->next=NULL;
p2->next=p1;
p2=p1;
}
return head;
}
void main()
{
	struct a *head,*p,*q,*t[100];
	int m,i,j=0,k;
	scanf("%d",&m);
	head=create(m);
	p=head;
	for(i=0;i<m;i++)
	{if(p->year>=60){t[j]=p;j++;}
	p=p->next;
	}
	for(k=0;k<j-1;k++)
		for(i=0;i<j-1-k;i++)
			if(t[i]->year<t[i+1]->year)
			{p=t[i];
			t[i]=t[i+1];
			t[i+1]=p;
			}
	for(i=0;i<j;i++)
			printf("%s\n",t[i]->id);
	p=head;
	j=0;
	for(i=0;i<m;i++)
	{if(p->year<60){t[j]=p;j++;}
	p=p->next;
	}
	for(i=0;i<j;i++)
			printf("%s\n",t[i]->id);
}


struct peo{
	char id[11];
	int age;
};

int main(){
	struct peo people[100];
	struct peo sixty[100];

	int n,b=0,i,j,k,e;
	char a[11];

	scanf("%d",&n);

	for(i=0;i<n;i++){
		scanf("%s %d",people[i].id,&people[i].age);
		if(people[i].age>=60){
			sixty[i].age=people[i].age;
			strcpy(sixty[i].id,people[i].id);
			b+=1;
		}else{
			strcpy(sixty[i].id,"0000");
			sixty[i].age=0;
		}
	}

	for(k=0;k<n-1;k++){
		for(i=n-1;i>k;i--){
			if(sixty[i-1].age<sixty[i].age){
				e=sixty[i-1].age;
				sixty[i-1].age=sixty[i].age;
				sixty[i].age=e;
				strcpy(a,sixty[i-1].id);
				strcpy(sixty[i-1].id,sixty[i].id);
				strcpy(sixty[i].id,a);
			}
		}
	}
	for(i=0;i<b;i++){
		printf("%s\n",sixty[i].id);

	}
	for(i=0;i<n;i++){
		if(people[i].age<60){
			printf("%s\n",people[i].id);
		}
	}

	return 0;

}


struct patient
{
	char num[10];
	int age;
}pat[100];
int main()
{
	int n,i,m,k,f,j;
	char e[10];
    m=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s%d",&pat[i].num,&pat[i].age);
		if(pat[i].age>=60){
		    strcpy(e,pat[i].num);
			f=pat[i].age;
			for(k=i;k>m;k--){
				strcpy(pat[k].num,pat[k-1].num);
			}strcpy(pat[m].num,e);
		    pat[m].age=f;
			m++;
		}
	}for(i=0;i<m;i++){
		for(k=0;k<i;k++){
			if(pat[i].age>pat[k].age){
				f=pat[i].age;
			    strcpy(e,pat[i].num);
				for(j=i;j>k;j--){
					pat[j].age=pat[j-1].age;
					strcpy(pat[j].num,pat[j-1].num);
				}pat[k].age=f;
			    strcpy(pat[k].num,e);
			}
		}
	}
	for(i=0;i<n;i++){
		printf("%s\n",pat[i].num);
	}
	return 0;
}


int main()
{
    struct patient_t {
        char id[10];
        int age;
    } patients[100], t;
    int i, j, n;
    scanf("%d", &n);
    for (i=0; i<n; i++) {
        scanf("%s%d", &patients[i].id, &patients[i].age);
    }
    for (i=0; i<n; i++) {
        for (j=n-1; j>i; j--) {
            if (patients[j].age >= 60 &&
                patients[j].age > patients[j-1].age) {
                t = patients[j];
                patients[j] = patients[j-1];
                patients[j-1] = t;
            }
        }
    }
    for (i=0; i<n; i++) {
        printf("%s\n", patients[i].id);
    }
    return 0;
}


struct stu
{
	int w;
	char c[10];
	struct stu *next;
};
int n;
struct stu*creat(int m)
{
	struct stu *head,*p1,*p2,*p3;
	int i;
	n=0;
	p1=p2=(struct stu*)malloc(sizeof(struct stu));
	head=p1;
	p1->next=NULL;
	n=0;
	scanf("%s %d",p1->c,&p1->w);
    for(i=0;i<m-1;i++)
	{   p1=(struct stu*)malloc(sizeof(struct stu));
	scanf("%s %d",p1->c,&p1->w);
	if(p1->w<60)
	{for(p2=head;p2->next!=NULL;p2=p2->next)
			;
		p2->next=p1;
		p1->next=NULL;
	}
	else
	{
    p2=head;
	while((p1->w<=p2->w)&&(p2->next!=NULL))
	{
		p3=p2;
		p2=p2->next;
	}
	if(p1->w>p2->w)
	{
		if(head==p2)
			head=p1;
		else p3->next=p1;
		p1->next=p2;
	}
	else
	{p2->next=p1;p1->next=NULL;
	}
    }
	}
	 return(head);

}
void main()
{
	int m,i;
	struct stu *head,*p;
	scanf("%d",&m);
	head=creat(m);
	p=head;
	for(i=0;i<m;i++)
	{printf("%s\n",p->c);

		p=p->next;
	}

}


struct staff
{
	char id[20];
	int age;
	struct staff*next;
};

void main()
{
	int n,k=0,max=59;
	struct staff*head,*p,*q,*pre;
	scanf("%d",&n);

	struct staff *p1,*p2;

	p1=(struct staff*)malloc(LEN);
	scanf("%s %d",p1->id,&p1->age);
	head=p2=p1;
	if(p1->age>=60) k++;

	while(n-1)
	{
		n--;
		p1=(struct staff *)malloc(LEN);
		scanf("%s %d",p1->id,&p1->age);
		if(p1->age>=60) k++;
		p2->next=p1;
		p2=p1;
	}
	p2->next=NULL;

	//printf("<%d>",k);

	while(k)
	{
		p=head;
		k--;
		while(p)
		{
		  if(p->age>max)
		  {
			max=p->age;
			q=p;
		  }
		  p=p->next;
		}
		printf("%s\n",q->id);
		if(q==head)
		{
			head=q->next;
			free(q);
		}
		else
		{
			if(q->next==NULL)
			{
			  p=head;
			  while(p)
			  {
				  pre=p;
				  p=p->next;
				  if(p==q)
				  {
					free(q);
					pre->next=NULL;
					break;
				  }
			  }
			}

		    else
			{
			  p=head;
			  while(p)
			  {
				pre=p;
				p=p->next;
				if(p==q)
				{
					p=p->next;
					pre->next=p;
					free(q);
					break;
				}
			  }
			}
		}
		max=59;
	}

		p=head;
		while(p)
		{
			printf("%s\n",p->id);
			p=p->next;
		}
}


struct pat
{
       char num[10];
	   int age;
       struct pat *next;
};

struct pat *creat(int n)
{
       struct pat *p1,*p2,*head;
       int i;
	p2=head=p1=(struct pat *)malloc(sizeof(struct pat));
    for(i=0;i<n;i++)
	{
		scanf("%s %d",p1->num,&p1->age);
		if(i==0)
			head=p1;
        p2->next=p1;
		p2=p1;
		p1=(struct pat *)malloc(sizeof(struct pat));
	}
	p2=NULL;
	return head;
}

void array(struct pat *head,int n)
{
     int i,j,ta;
	 char str[10];
     struct pat *p1,*p2;
	 p1=head;
     for(i=0;i<n-1;i++)
     {
       for(j=0;j<n-1-i;j++)
       {
                 p2=p1;
                 p1=p1->next;
                 if((p1->age)>(p2->age)&&(p1->age)>=60)
                 {

                                          strcpy(str,p2->num);
                                          strcpy(p2->num,p1->num);
                                          strcpy(p1->num,str);
                                          ta=p1->age;
										  p1->age=p2->age;
										  p2->age=ta;
                                      }
                     }
       p1=head;
     }
}

void main()
{
      int n;
      scanf("%d",&n);
      struct pat *p;
      p=creat(n);
	  array(p,n);
     int i;
     for(i=0;i<n;i++)
     {
      printf("%s\n",p->num);
      p=p->next;
     }
}


struct person
{
	int age;
	char num[10];

}pat[100],old[100],you[100],exchange;
int main()
{
	int n,i,p,q,result;
	int k=0,t=0;
	int temp;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s",pat[i].num);
		scanf("%d",&pat[i].age);
		if(pat[i].age>=60)
		{
			old[k].age=pat[i].age;
			strcpy(old[k].num,pat[i].num);
			k++;
		}
		else
		{
			strcpy(you[t].num,pat[i].num);
			t++;
		}
	}
	for(p=0;p<k;p++)
	{
		for(q=0;q<k-p;q++)
		{
			if(old[q].age<old[q+1].age)
			{
				exchange.age=old[q].age;
				old[q].age=old[q+1].age;
				old[q+1].age=exchange.age;
				strcpy(exchange.num,old[q].num);
				strcpy(old[q].num,old[q+1].num);
				strcpy(old[q+1].num,exchange.num);
			}
		}
	}
	for(result=0;result<k;result++)
	{
		printf("%s\n",old[result].num);
	}
	for(result=0;result<t;result++)
	{
		printf("%s\n",you[result].num);
	}

	return 0;
}


	struct
	{
	char id[11];
	int nianling;
	}bing[100];

int main()
{
		int n,i,j,e;
	int youxian[100]={0};
	int zhengchang[100]={0};
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		scanf("%s %d", bing[i].id,&bing[i].nianling);
		if(bing[i].nianling>=60)  youxian[i]=bing[i].nianling;
		else zhengchang[i]=bing[i].nianling;
	}
	for(i=1;i<n;i++)
	{
		for(j=0;j<n-i;j++)
		{
			if(youxian[j]<youxian[j+1])
			{
				e=youxian[j+1];
				youxian[j+1]=youxian[j];
				youxian[j]=e;
			}
		}
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(bing[j].nianling==youxian[i])
			{
				printf("%s\n", bing[j].id);
				bing[j].nianling=-1;
				break;
			}
		}
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
		    if(bing[j].nianling==zhengchang[i])
			{
				printf("%s\n", bing[j].id);
				bing[j].nianling=-1;
				break;
			}
		}
	}

	return 0;
}


main()
{
      int n,age[100],a[100],k=0,count=0,c[100],i,j;
      char ID[100][100],id[100][100],string[100];
      scanf("%d",&n);
      for(int i=0;i<n;i++)
          scanf("%s %d",ID[i],&age[i]);
      for(i=0;i<n;i++)
      {
          if(age[i]>=60)
            {
               a[k]=age[i];
               strcpy(id[k],ID[i]);
               count++;
               c[k]=k;
               k++;
            }
      }
      for(k=0;k<count;k++)
      {
          for(int j=k+1;j<count;j++)
          {
          if(a[k]<a[j])
            {
               int t=a[j];
               a[j]=a[k];
               a[k]=t;
               strcpy(string,id[k]);
               strcpy(id[k],id[j]);
               strcpy(id[j],string);
               int p=c[k];
               c[k]=c[j];
               c[j]=p;
            }
           }
      }
      for(k=0;k<count;k++)
      {
         for(int j=k+1;j<count;j++)
         {
            if(a[k]==a[j])
            {
              if(c[k]>c[j])
              {
               int t=a[j];
               a[j]=a[k];
               a[k]=t;
               strcpy(string,id[k]);
               strcpy(id[k],id[j]);
               strcpy(id[j],string);
               int p=c[k];
               c[k]=c[j];
               c[j]=p;
              }
            }
          }
      }
      for(k=0;k<count;k++)
        printf("%s\n",id[k]);
      for(i=0;i<n;i++)
      {
           if(age[i]<60)
             printf("%s\n",ID[i]);
      }
      getchar();
      getchar();
}


struct patient
{
	char ID[10];
	int age;
};

int main()
{
	int n,m;
	int i,j=0,k=0;
	struct patient a[100],b[100],c[100],t[1];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s%d",a[i].ID,&a[i].age);
		if(a[i].age>=60)
		{
			strcpy(b[j].ID,a[i].ID);
			b[j].age=a[i].age;
			j=j+1;
		}
		else
		{
			strcpy(c[k].ID,a[i].ID);
			c[k].age=a[i].age;
			k=k+1;
		}

	}
	m=j;
	for(j=1;j<=m-1;j++)
	{
		for(i=0;i<=m-1-j;i++)
		{
			if(b[i].age<b[i+1].age)
			{
               strcpy(t[0].ID,b[i].ID);
		 	   t[0].age=b[i].age;
			   strcpy(b[i].ID,b[i+1].ID);
			   b[i].age=b[i+1].age;
			   strcpy(b[i+1].ID,t[0].ID);
			   b[i+1].age=t[0].age;
			}
		}
	}
	for(i=0;i<m;i++)
		printf("%s\n",b[i].ID);
	for(i=0;i<k;i++)
		printf("%s\n",c[i].ID);
	return 0;
}


struct patient
{
	char ID[11];    //?????
	int age;
}pa[100];           //?????
int main(int argc, char* argv[])
{
	int n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s %d",pa[i].ID,&pa[i].age);
	}             //??100?????
	struct patient old[100];//????????????60??
	int count=0;
	for(i=0;i<n;i++)
	{
		if(pa[i].age>=60)
		{
			strcpy(old[count].ID,pa[i].ID);
			old[count].age=pa[i].age;
			count++;
			pa[i].age=0;
		}
	}
	int k,j,e;
	char ex[11];
	for(k=1;k<count;k++)
	{
		for(j=0;j<count-k;j++)
		{
			if(old[j].age<old[j+1].age)
			{
				e=old[j+1].age;
				old[j+1].age=old[j].age;
				old[j].age=e;
				strcpy(ex,old[j].ID);
				strcpy(old[j].ID,old[j+1].ID);
				strcpy(old[j+1].ID,ex);
			}
		}
	}
	for(i=0;i<count;i++)
	{
		printf("%s\n",old[i].ID);
	}
	for(i=0;i<n;i++)
	{
		if(pa[i].age!=0)
		{
			printf("%s\n",pa[i].ID);
		}
	}
	return 0;
}


struct patient
{
	char id[10];
	int age;
	int turn;
}pat[100],temp;
void main()
{
	int n,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s%d",pat[i].id,&pat[i].age);
		pat[i].turn=i;
	}
	for(i=0;i<n;i++)
	   if(pat[i].age<60)
	   {
	   	j=i+1;
	   	while((pat[j].age<60)&&(j<n))j++;
	   	if(pat[j].age>=60)
	   	{
	   		temp=pat[i];
	   		pat[i]=pat[j];
	   		pat[j]=temp;
	   	}
	   }
    for(i=0;(pat[i].age>=60)&&(i<n);i++)
       for(j=i+1;j<n;j++)
          if((pat[j].age>pat[i].age)||((pat[i].age==pat[j].age)&&(pat[j].turn<pat[i].turn)))
          {
          	temp=pat[i];
          	pat[i]=pat[j];
          	pat[j]=temp;
          }
    for(i=0;i<n;i++)
       if(pat[i].age<60)
       {
       	for(j=i+1;j<n;j++)
       	  if(pat[i].turn>pat[j].turn)
       	  {
       	  	temp=pat[i];
       	  	pat[i]=pat[j];
       	  	pat[j]=temp;
       	  }
       }
    for(i=0;i<n;i++)
       printf("%s\n",pat[i].id);
}


struct person
{
	char id[20];
	int y;
};
void main()
{
	int n,i,j,m=0,k=0,z;
	struct person t,*s,*o,*y;
	scanf("%d",&n);
	s=(struct person *)malloc(n*sizeof(struct person));
	o=(struct person *)malloc(n*sizeof(struct person));
	y=(struct person *)malloc(n*sizeof(struct person));
	for(i=0;i<n;i++)
	{scanf("%s %d",(*(s+i)).id,&(*(s+i)).y);
		if ((*(s+i)).y>=60)  {*(o+k)=*(s+i);k++;}
		else {*(y+m)=*(s+i);m++;}
	}
    for(i=0;i<k;i++)
	{for(j=k-1;j>i;j--)
			if (o[j].y>o[j-1].y) {t=o[j];o[j]=o[j-1];o[j-1]=t;}
         printf("%s\n",(*(o+i)).id);
    }
    for(i=0;i<m;i++)
      printf("%s\n",(*(y+i)).id);
}


int main(){
	struct patient{
		char id[11];
		int age;
	} patients[100],old[100],young[100],jh;
	int n,i,j,d,k;
        j=-1;
		d=-1;
	scanf("%d",&n);
    for(i=0;i<n;i++){
		scanf("%s %d",patients[i].id,&patients[i].age);
	}
    for(i=0;i<n;i++){
		if(patients[i].age>=60){
             d++;
			old[d]=patients[i];

			}else{
             j++;
			young[j]=patients[i];
			}
	}
	for(k=1;k<=d+1;k++){
     for(i=0;i<d;i++){
		 if(old[i].age<old[i+1].age){
             jh=old[i];
             old[i]=old[i+1];
             old[i+1]=jh;
		 }
	 }
	}
   for(i=0;i<=d;i++){
        printf("%s\n",old[i].id);
   }
   for(i=0;i<=j;i++){
         printf("%s\n",young[i].id);
   }
return 0;
}


struct patient
{
	char ID[10];
	int age;
	struct patient *next;
};
struct patient * insert(struct patient *head,struct patient *another)
{
	struct patient *p0,*p1,*p2;
	p1=head;
	p0=another;
	if(p0->age<60)
	{
		while(p1->next!=NULL)
		{
			p2=p1;
			p1=p1->next;
		}
		p1->next=p0;
		p0->next=NULL;
	}
	else
	{
		while(p1->age>=p0->age&&p1->next!=NULL)
		{
			p2=p1;
			p1=p1->next;
		}
		if(p1->age>=p0->age)
		{
			p1->next=p0;
			p0->next=NULL;
		}
		else
		{
            if(p1==head)
			{
				head=p0;
				p0->next=p1;
			}
			else
			{
				p2->next=p0;
				p0->next=p1;
			}
		}
	}
	return head;
}
void print(struct patient *head)
{
	struct patient *p;
	p=head;
    while(p!=NULL)
	{
		printf("%s\n",p->ID);
		p=p->next;
	}
}
void main()
{
	int n,i;
	struct patient *head,*p;
	scanf("%d",&n);
	head=p=(struct patient *)malloc(len);
	scanf("%s %d",p->ID,&p->age);
    head->next=NULL;
	for(i=1;i<n;i++)
    {
       p=(struct patient *)malloc(len);
	   scanf("%s %d",p->ID,&p->age);
	   head=insert(head,p);
	}
	print(head);
}


struct patient
{
       char id[11];
       int age;
       struct patient *next;
};

int main()
{
    struct patient *head;
    struct patient *create(int n);
    void sort(struct patient *head);
    int n;
    scanf("%d",&n);
    head=create(n);
    sort(head);

    return 0;
}

struct patient *create(int n)
{
       int i;
       struct patient *head,*p1,*p2;
       p1=(struct patient *)malloc(len);
       head=p1;
       p2=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;
                       if(i==(n-1))
                       (p1->next)=NULL;
       }
       return head;
}

void sort(struct patient *head)
{
     int m;
     struct patient *p1,*p2;

     for(;;)
     {
            p1=head;
            p2=head;
            m=0;
            for(;;)
            {
                   if((p1->age)>m) m=(p1->age);
                   if((p1->next)==NULL) break;
                   else p1=(p1->next);
            }
            if(m<60) break;
            p1=head;
            for(;;)
            {
                   if((p1->age)==m)
                   {
                                   printf("%s\n",p1->id);
                                   if(p1==head) head=(p1->next);
                                   else
                                   {
                                       (p2->next)=(p1->next);
                                   }
                                   break;
                   }
                   else
                   {
                       if(p1!=p2)
                       {
                                 p2=p1;
                                 p1=(p1->next);
                       }
                       else p1=(p1->next);
                   }
            }
     }
     p1=head;
     for(;;)
     {
            printf("%s\n",p1->id);
            if((p1->next)==NULL) break;
            else p1=(p1->next);
     }
}


struct bingren{
	char id[20];
	int age;
}bing[100]={'\0', 0};

struct laoren{
	char oid[20];
	int oage;
}lao[100]={'\0', 0};

void main()
{
	int n, i, j=0, l;
	struct laoren temp;
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		scanf("%s", bing[i].id);
		scanf("%d", &bing[i].age);
	}
	for(i=0;i<n;i++)
	{
		if(bing[i].age>=60)
		{
			strcpy(lao[j].oid,bing[i].id);
			lao[j].oage=bing[i].age;
			bing[i].age=-1;
			j++;
		}
		else
			continue;
	}
	for(l=0;l<j;l++)
	{
		for(i=0;i<j-l;i++)
		{
			if(lao[i].oage<lao[i+1].oage)
			{
				temp=lao[i];
				lao[i]=lao[i+1];
				lao[i+1]=temp;
			}
		}
	}
	for(i=0;i<j+1;i++)
	{
		printf("%s\n", lao[i].oid);
	}
	for(i=0;i<n;i++)
	{
		if(bing[i].age>=0)
		{
			printf("%s\n", bing[i].id);
		}
		else
			continue;
	}
}


struct ill
{
       char num[20];
       int age;
       int turn;
       struct ill *next;
};

void run(struct ill *head,int age,int turn,char *num)
{
     struct ill *pre,*p,*s;
     s=(struct ill *)malloc(sizeof(struct ill));
     pre=head;
     p=pre->next;
     strcpy(s->num,num);
     s->turn=turn;
     s->age=age;
     //s->next=NULL;
     for(;p!=NULL;)
     {
                   pre=p;
                   p=p->next;
     }
     pre->next=s;
     s->next=p;
}

int main()
{
    int i,j,k,age,turn,m,n;
    char *num;
    void run(struct ill *head,int age,int turn,char *num);
    num=(char *)malloc(20*sizeof(char));
    struct ill *head,*p,*s,*pre;
    head=(struct ill *)malloc(sizeof(struct ill));
    head->next=NULL;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
                    scanf("%s %d",num,&age);
                    turn=i;
                    run(head,age,turn,num);
    }
    k=0;
    for(p=head->next;p!=NULL;p=p->next)
    {
                                       if(p->age>=60)
                                       {
                                                   k++;
                                       }
    }
    //printf("%d\n",k);
    p=head->next;
    m=100;
    if(k==0)
    {
            for(i=0;i<n;i++)
            {
                            p=head->next;
                            for(;p!=NULL;)
                            {
                                          if(p->turn==i)
                                          {
                                                        puts(p->num);
                                                        //printf("%s %d %d\n",p->num,p->age,p->turn);
                                                        break;
                                          }
                            }
            }
    }
    else if(k==n)
    {
         for(i=0;i<n;i++)
         {
                         p=head->next;
                         m=0;j=100;
                         for(;p!=NULL;)
                         {
                                       if(p->age>m)
                                       {
                                                   m=p->age;
                                                   j=p->turn;
                                       }
                                       else if(p->age==m)
                                       {
                                            if(p->turn<j)
                                            {
                                                         m=p->age;
                                                         j=p->turn;
                                            }
                                       }
                                       p=p->next;
                         }
                         pre=head;
                         p=head->next;
                         for(;p!=NULL;)
                         {
                                       if((p->age==m)&&(p->turn==j))
                                       {
                                                                    puts(p->num);
                                                                    //printf("%s %d %d\n",p->num,p->age,p->turn);
                                                                    pre->next=p->next;
                                                                    break;
                                       }
                                       else
                                       {
                                           pre=p;
                                           p=p->next;
                                       }
                         }
         }
    }
    else
    {
             for(i=0;i<k;i++)
             {
                         p=head->next;
                         m=0;j=100;
                         for(;p!=NULL;)
                         {
                                       if(p->age>m)
                                       {
                                                   m=p->age;
                                                   j=p->turn;
                                       }
                                       else if(p->age==m)
                                       {
                                            if(p->turn<j)
                                            {
                                                         m=p->age;
                                                         j=p->turn;
                                            }
                                       }
                                       p=p->next;
                         }
                         pre=head;
                         p=head->next;
                         for(;p!=NULL;)
                         {
                                       if((p->age==m)&&(p->turn==j))
                                       {
                                                                    puts(p->num);
                                                                    //printf("%s %d %d\n",p->num,p->age,p->turn);
                                                                    pre->next=p->next;
                                                                    break;
                                       }
                                       else
                                       {
                                           pre=p;
                                           p=p->next;
                                       }
                         }
               }
               for(i=0;i<n-k;i++)
               {
                                 m=100;
                                 p=head->next;
                                 for(;p!=NULL;)
                                 {
                                               if(p->turn<m)
                                               {
                                                            m=p->turn;
                                               }
                                               p=p->next;
                                 }
                                 p=head->next;
                                 for(;p!=NULL;)
                                 {
                                               if(p->turn==m)
                                               {
                                                            puts(p->num);
                                                            //printf("%s %d %d\n",p->num,p->age,p->turn);
                                                            p->turn=100;
                                                            break;
                                               }
                                               else
                                               {
                                                   p=p->next;
                                               }
                                 }
               }
    }
    return 0;
}


int main()
{
	int n,a,i,j,sgh,sgh60;
	sgh=0;
	sgh60=0;
	char d[10];
	struct guahao
	{
		char ID[10];
		int age;
	}
	gh[100],gh60[100];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s %d",d,&a);
		if(a>=60)
		{
			strcpy(gh60[sgh60].ID,d);
			gh60[sgh60].age=a;
			sgh60=sgh60+1;
		}else
		{
			strcpy(gh[sgh].ID,d);
			gh[sgh].age=a;
			sgh=sgh+1;
		}
	}
	for(i=1;i<=sgh60;i++)
	{
		for(j=sgh60-1;j>0;j--)
		{
			if(gh60[j].age>gh60[j-1].age)
			{
				a=gh60[j].age;
				gh60[j].age=gh60[j-1].age;
				gh60[j-1].age=a;
				strcpy(d,gh60[j].ID);
				strcpy(gh60[j].ID,gh60[j-1].ID);
				strcpy(gh60[j-1].ID,d);
			}
		}
	}
	for(i=0;i<sgh60;i++)
	{
		printf("%s\n",gh60[i].ID);
	}
	for(i=0;i<sgh;i++)
	{
		printf("%s\n",gh[i].ID);
	}
	return 0;
}


main()
{
      char senior[100][10];
      char junior[100][10];
      char temp[10];
      int  list[100]={0};
      int  se[100];
      int  ju[100];
      int  n,i,j,k,nums,numj,year;

      scanf("%d",&n);
      nums=-1; numj=-1;
      for (i=1;i<=n;i++)
      {
          scanf("%s",temp);
          scanf("%d",&year);
          if (year>=60)
          {
              nums++;
              strcpy(senior[nums],temp);
              se[nums]=year;
              list[nums]=nums;
          }
          else
          {
              numj++;
              strcpy(junior[numj],temp);
              ju[numj]=year;
          }
      }
      for (i=0;i<nums;i++)
          for (j=i+1;j<=nums;j++)
              if ((se[i]<se[j]) ||
                  (se[i]==se[j] && list[i]>list[j]))
              {
                  year=se[i]; se[i]=se[j]; se[j]=year;
                  year=list[i]; list[i]=list[j]; list[j]=year;
                  strcpy(temp,senior[i]);
                  strcpy(senior[i],senior[j]);
                  strcpy(senior[j],temp);
              }
      for (i=0;i<=nums;i++)
      {
          puts(senior[i]);
      }
      for (i=0;i<=numj;i++)
          puts(junior[i]);
      return 0;
}


struct pat
{
	char id[30];
	int age;
	int num;
	int flag;
	struct pat *next;
	struct pat *ns;
};

int n;

void sort(struct pat *head)
{
	int i,j;
	struct pat *q,*p,*max;
	q=head;

	for(i=0;i<n;i++)
	{
		p=head->next;
		while(1)
		{
			if(p->flag)
				break;
			p=p->next;
		}
		max=p;
		while(1)
		{
			if((p->num)>(max->num)&&p->flag)
				max=p;
			p=p->next;
			if(p==NULL)
				break;
		}
		max->flag=0;
		q->ns=max;
		q=q->ns;

	}
	q->ns=NULL;
}

void main()
{
	int i;
	struct pat *head,*p1,*p2,*p;
	scanf("%d",&n);
	head=(struct pat*)malloc(LEN);
	for(i=0;i<n;i++)
	{
		p1=(struct pat*)malloc(LEN);
		scanf("%s %d",p1->id,&p1->age);
		p1->flag=1;
		if(p1->age>=60)
			p1->num=10000*p1->age+n-i;
		else
			p1->num=n-i;
		if(i==0)
		{
			head->next=p1;
			p2=p1;
		}
		else
			p2->next=p1;
		p2=p1;
	}
	p2->next=NULL;

	sort(head);

	p=head->ns;
	for(i=0;i<n;i++)
	{
		printf("%s\n",p->id);
		p=p->ns;
	}
}


void main()
{
	struct patient
	{
	char ID[10];
	int age;
	};
	struct patient pat[100];
	int n,i,j,huan;
	char string[10];
	scanf("%d",&n);
		for(i=0;i<n;i++)
		{
		scanf("%s %d",pat[i].ID,&pat[i].age);
		}

		for(i=0;i<n;i++)
		{
		  if(pat[i].age>=60)
		  {
            for(j=i;j>0;j--)
			{
			 if(pat[j].age>pat[j-1].age)
			 {
				 huan=pat[j].age;
			     pat[j].age=pat[j-1].age;
				 pat[j-1].age=huan;
			 strcpy(string,pat[j].ID);
			  strcpy(pat[j].ID,pat[j-1].ID);
			   strcpy(pat[j-1].ID,string);
			 }
			}
		  }
		}
		for(i=0;i<n;i++)
			printf("%s\n",pat[i].ID);

}


int m=0;
struct patient
{
    char id[32];
    int age;
    struct patient *next;
};
struct patient *find(struct patient *head)
{
   struct patient *p,*ppre;
   p=head;
   while (p&&p->age>=60)
    {
        ppre=p;
        p = p->next;
    }
    return ppre;
}
struct patient *create(int n)
{
     struct patient *head=NULL,*p1,*p2,*p0,*q;
     int i;
     p1=p2=p0=(struct patient*)malloc(Len);
     scanf("%s %d",p1->id,&p1->age);
     if(p1->age>=60) m++;
     p1->next=NULL;
     head=p1=p0;
     p2=p1;
     for(i=1;i<n;i++)
        {
            p1=(struct patient*)malloc(Len);
            scanf("%s %d",p1->id,&p1->age);
            if(p1->age<60)
            {
                p1->next=NULL;
                p2->next=p1;
                p2=p1;
            }
            else if(p1->age>=60)
            {
                m++;
                if(head->age<60)
                {
                    head=p1;
                    p1->next=p0;
                }
                if(head->age>=60)
                {
                  p0=find(head);
                  q=p0->next;
                  p0->next=p1;
                  p1->next=q;
                }
                if((p0=find(head))->next==NULL)
                {
                   p1->next=NULL;
                   p2->next=p1;
                   p2=p1;
                }
            }
        }
         return head;
}
struct patient *arrange(struct patient *head)
{
    struct patient *p1,*p2;
    int t1,i,j;
    char t2[32];
    for(j=0;j<m;j++)
     {
          p1=head;
       for(i=1;i<m-j;i++)
       {
           p2=p1;
           p1=p1->next;
         if(p2->age<p1->age)
         {
              t1=p1->age;
              strcpy(t2,p1->id);
              p1->age=p2->age;
              strcpy(p1->id,p2->id);
              p2->age=t1;
              strcpy(p2->id,t2);
         }
       }
     }
}
void print(struct patient *head)
{
     struct patient *p;
     p = head;
     while (p)
     {
         printf("%s\n",p->id);
         p = p->next;
     }
}
int main()
{
    struct patient *head,*p,*q,*p0;
    int n,m=0,age;
    char id[32];
    scanf("%d",&n);
    head=create(n);
    arrange(head);
    print(head);
}


struct bing
{
	char id[10];
	int age;
	int num;
}bing[100],temp;
int main ()
{
	int i,j,n;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s %d",&bing[i].id,&bing[i].age);
		bing[i].num=i+1;
	}
	for(j=0;j<=n;j++)
	{
		for(i=0;i<n-1;i++)
		{
			if(bing[i+1].age>=60&&bing[i].age<bing[i+1].age)
			{
				temp=bing[i+1];
				bing[i+1]=bing[i];
				bing[i]=temp;
			}
		}
	}
	for(i=0;i<n;i++)
		printf("%s\n",bing[i].id);
	return 0;
}


struct Node;
typedef struct Node *pNode;
struct Node
{
    int x;
	char id[20];
	pNode next;
};

pNode create()/*??head*/
{
	pNode p;
	p=(pNode)malloc(sizeof(struct Node));
	p->next=NULL;
	return p;
}

void sort(pNode head,int n)/*head???????n???*/
{
	pNode p=NULL,q=NULL,s=NULL;
    int i;
	for (i=1;i<=n;i++)
	{
	s=(pNode)malloc(sizeof(struct Node));
	s->next=NULL;
	scanf("%s %d",&s->id,&s->x);
    if (s->x<60)
	{
		p=head;
		while (p->next)
			p=p->next;
		p->next=s;
	}
    else
	{
		q=head;
	    p=head->next;
	    while (p)
		{
			if (p->x<s->x)
				break;
		    q=p;
		    p=p->next;
		}
	    q->next=s;
	    s->next=p;
	}
	}
}

void outputdata(pNode p)/*??head*/
{
    p=p->next;
	while(p->next)
	{
      printf("%s\n",p->id);
	  p=p->next;
    }
	printf("%s\n",p->id);
}

int main()
{
	pNode head;
	int n;
    head=create();
	scanf("%d",&n);
	sort(head,n);
	outputdata(head);

	return 0;
}


int main()
{
struct student
{	char as[10];
	int ag;
};
struct student stu[100];
struct student st[100];
struct student temp;
int n,i,j,k;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%s %d",stu[i].as,&stu[i].ag);
j=0;
for(i=0;i<n;i++){
	if(stu[i].ag>59){
		st[j]=stu[i];
		stu[i].ag=0;
		j++;
	}
}
for(k=1;k<j;k++){
	for(i=0;i<j-k;i++){
		if(st[i].ag<st[i+1].ag){
			temp=st[i];
			st[i]=st[i+1];
			st[i+1]=temp;
		}
	}
}
for(i=0;i<j;i++)
printf("\n%s",st[i].as);
for(i=0;i<n;i++)
	if(stu[i].ag!=0)
	printf("\n%s",stu[i].as);
return 0;
}