struct person
{
	char c[10];
	int a;
	struct person *next;
};
int main()
{
	int i,n;
	struct person *head,*p1,*p2,*p,*p0,*p3;
	scanf("%d",&n);
	i=0;
	head=NULL;
	while(i<n)
	{
		p1=(struct person*)malloc(len);
	    scanf("%s %d",p1->c,&p1->a);
		if(i==0) { head=p1;p2=p1;}
		else
		{
			p2->next=p1;
			p2=p1;
		}
		i++;
	}
	p2->next=NULL;
	for(i=0;i<n;i++)
	{
		p=p0=head;
		while(p!=NULL)
		{
			if(p->a>p0->a) p0=p;
			p=p->next;
		}
		if(p0->a>=60)
		{
			printf("%s\n",p0->c);
			p=head;
			while(p->a!=p0->a)
			{
				p3=p;
				p=p->next;
			}
			if(p==head) head=p->next;
			else p3->next=p->next;
		}
		else
		{
			printf("%s\n",head->c);
			head=head->next;
		}
	}
}


struct bingren
{
	char id[20];
	int nian;
	struct bingren *next;
};
int main()
{
	int n,i;
	struct bingren *p1,*head;
	struct bingren temp;
	char a[20]={'\0'};
	int b=0;
	scanf("%d",&n);
	head=(struct bingren *)malloc(sizeof(struct bingren));
	head->next=NULL;
	scanf("%s%d",head->id,&head->nian);
	p1=head;
	for(i=1;i<n;i++)
	{
		p1->next=(struct bingren *)malloc(sizeof(struct bingren));
		scanf("%s%d",p1->next->id,&p1->next->nian);
		p1->next->next=NULL;
		p1=p1->next;
	}
	p1=head;
	for(i=1;i<n;i++)
	{
		for(;p1->next!=NULL;)
		{
			if(p1->next->nian >= 60 && p1->next->nian > p1->nian )
			{
				b=p1->nian;
				p1->nian=p1->next->nian;
				p1->next->nian=b;
				strcpy(a,p1->id);
				strcpy(p1->id,p1->next->id);
				strcpy(p1->next->id,a);
			}
			p1=p1->next;
		}
		p1=head;
	}
	p1=head;
	for(;p1!=NULL;)
	{
		printf("%s\n",p1->id);
		p1=p1->next;
	}
}


void main()
{
     struct patient
     {
            char ID[16];
            int age;
            int index;
     };
     int n,i,j,t,t1;
     char str[16];
     scanf("%d",&n);
     struct patient pat[n];
     for(i=0;i<n;i++)
       {scanf("%s %d",pat[i].ID,&pat[i].age);
       pat[i].index=i;}
     for(i=0;i<n;i++)
     {    for(j=i+1;j<n;j++)
          {
               if(pat[j].age>=60&&pat[j].age>pat[i].age)
               {strcpy(str,pat[i].ID);
               strcpy(pat[i].ID,pat[j].ID);
               strcpy(pat[j].ID,str);
               t=pat[i].age;
               pat[i].age=pat[j].age;
               pat[j].age=t;
               t1=pat[i].index;
               pat[i].index=pat[j].index;
               pat[j].index=t1;}
               if(pat[i].age>=60&&pat[i].age==pat[j].age)
               {
                        if(pat[i].index>pat[j].index)
                        {strcpy(str,pat[i].ID);
               strcpy(pat[i].ID,pat[j].ID);
               strcpy(pat[j].ID,str);
               t=pat[i].age;
               pat[i].age=pat[j].age;
               pat[j].age=t;
               t1=pat[i].index;
               pat[i].index=pat[j].index;
               pat[j].index=t1;}
               }

          }
     }
     for(i=0;i<n;i++)
     {
                     for(j=i+1;j<n;j++)
                       if(pat[i].age<60&&pat[i].index>pat[j].index)
                     {strcpy(str,pat[i].ID);
                       strcpy(pat[i].ID,pat[j].ID);
                          strcpy(pat[j].ID,str);
                        t=pat[i].age;
                          pat[i].age=pat[j].age;
                        pat[j].age=t;
                           t1=pat[i].index;
                           pat[i].index=pat[j].index;
                             pat[j].index=t1;}
     }
     for(i=0;i<n;i++)

                  puts(pat[i].ID);

}


int main()
{
	int n,i,j,temp,m=0;
	int patage[100];
	struct patient
	{
		char num[20];
		int age;
	};
	struct patient pat[100];
	scanf("%d",&n);

	for(i=0;i<n;i++)
		scanf("%s%d",pat[i].num,&pat[i].age);
	for(i=0,j=0;i<n;i++)
		if(pat[i].age>=60)
		{
			patage[j]=pat[i].age;
			j++;
			m++;
		}
	for(i=0;i<m;i++)
		for(j=0;j<m-i;j++)
		{
			if(patage[j]<patage[j+1])
			{
				temp=patage[j];
				patage[j]=patage[j+1];
				patage[j+1]=temp;
			}
		}
	for(i=0;i<m;i++)
		{
		if(patage[i]==patage[i-1])
			continue;
		for(j=0;j<n;j++)
		    if(pat[j].age==patage[i])
				printf("%s\n",pat[j].num);
		}
	for(i=0;i<n;i++)
	{
		if(pat[i].age>=60)
			continue;
		else
			printf("%s\n",pat[i].num);
	}
	return 0;
}


struct Patient
{
	char num[10];
	int age;
	struct Patient *next;
};
int main()
{
	void paixu(int n,struct Patient *head);
	struct Patient *creat(int n);
	int n,i;
	struct Patient *head;
	scanf("%d",&n);
	head=creat(n);
	paixu(n,head);
	for(i=0;i<n;i++)
	{
		printf("%s\n",head->num);
		head=head->next;
	}

}
struct Patient *creat(int n)
{
	int i;
	struct Patient *head,*thispoint,*nextpoint;
	for(i=0;i<n;i++)
	{
		if(i==0)
		{
			nextpoint=(struct Patient *)malloc(sizeof(struct Patient));
			scanf("%s %d",nextpoint->num,&nextpoint->age);
			head=nextpoint;
			thispoint=head;
		}
		else
		{
			nextpoint=(struct Patient *)malloc(sizeof(struct Patient));
			scanf("%s %d",nextpoint->num,&nextpoint->age);
			thispoint->next=nextpoint;
			thispoint=nextpoint;
		}
	}
	thispoint->next=NULL;
	return head;
}
void paixu(int n,struct Patient *head)
{
	int i,j,k,count;
	struct Patient *p1,*p2,*p3,*p4;
	char tempnum[10],tempnum3[10],tempnum4[10];
	int tempage,tempage3,tempage4;
	p1=head;
	for(i=0;i<n-1;i++)
	{
		if(p1->age<60)
		{
			p2=p1->next;
			for(j=i+1;j<n;j++)
			{
				if(p2->age>59)
				{
					strcpy(tempnum,p2->num);tempage=p2->age;
					p3=p1;p4=p3->next;
					for(k=i;k<j;k++)
					{
						strcpy(tempnum4,p4->num);tempage4=p4->age;
						if(k==i){strcpy(p4->num,p3->num);p4->age=p3->age;}
						else {strcpy(p4->num,tempnum3);p4->age=tempage3;}
						strcpy(tempnum3,tempnum4);tempage3=tempage4;
						p3=p3->next;p4=p4->next;
					}
					strcpy(p1->num,tempnum);p1->age=tempage;
					break;
				}
				else p2=p2->next;
			}
		}
		p1=p1->next;
	}
	p1=head;
	for(i=0,count=0;i<n;i++)
	{
		if(p1->age>59){count++;}
		p1=p1->next;
	}
	p1=head;
	for(i=1;i<count;i++)
	{
		p2=p1;
		for(j=0;j<count-i;j++)
		{
			p3=p2->next;
			if(p2->age<p3->age)
			{
				strcpy(tempnum,p2->num);tempage=p2->age;
				strcpy(p2->num,p3->num);p2->age=p3->age;
				strcpy(p3->num,tempnum);p3->age=tempage;
			}
			p2=p2->next;
		}
	}
}


typedef struct Node
{
	char ID[11];
	int age;
	struct Node *next;
}node;
node *creat(int n)
{
	node *p1,*p2,*head;
	int i;
	p1=p2=(node *)malloc(sizeof(node));
	head=p1;
	for(i=0;i<n;i++)
	{
		p2=p1;
		scanf("%s%d",p1->ID,&p1->age);
		p1=(node *)malloc(sizeof(node));
		p2->next=p1;
	}
	p2->next=NULL;
	return(head);
}
void sort(int x,char *a,node *head)
{
	node *pre=head,*p=pre->next,*s;
	s=(node *)malloc(sizeof(node));
	s->age=x;
	strcpy(s->ID,a);
	s->next=NULL;
	while(p!=NULL&&x<=p->age)
	{
		pre=p;
		p=p->next;
	}
	pre->next=s;
	s->next=p;
}
void print(node *head)
{
	node *p;
	p=head;
	while(p!=NULL)
	{
		printf("%s\n",p->ID);
		p=p->next;
	}
}
void main()
{
	int n;
	node *head1,*head2,*p;
	scanf("%d",&n);
	head1=creat(n);
	head2=(node *)malloc(sizeof(node));
	strcpy(head2->ID," ");
	head2->next=NULL;
	p=head1;
	while(p!=NULL)
	{
		if(p->age>=60)
		    sort(p->age,p->ID,head2);
		p=p->next;
	}
	head2=head2->next;
	print(head2);
	p=head1;
	while(p!=NULL)
	{
		if(p->age<60)
			printf("%s\n",p->ID);
		p=p->next;
	}
}


struct student
{
	char num[10];
	int age;
}line[100];
void main()
{
	int n,i,j,k,temp=0,m,e;
	scanf("%d",&n);
	int a[100]={0},b[100]={0};
	char s[100][10],y[100][10];
	char exchange[10];
	for(i=0;i<n;i++)
	{
		scanf("%s%d",line[i].num,&line[i].age);
	}
	for(i=0;i<n;i++)
	{
		if(line[i].age>=60)
		{
			temp++;
		}
	}
	j=0;
	for(i=0;i<n;i++)
	{
			if(line[i].age>=60)
			{
				strcpy(s[j],line[i].num);
				b[j]=line[i].age;
				j++;
			}

	}
	for(j=0;j<temp;j++)
	{
		for(k=0;k<temp-j;k++)
		{
			if(b[k]<b[k+1])
			{
				e=b[k];
				b[k]=b[k+1];
				b[k+1]=e;
				strcpy(exchange,s[k]);
				strcpy(s[k],s[k+1]);
                strcpy(s[k+1],exchange);
			}
		}
	}
	for(j=0;j<temp;j++)
	{
		printf("%s\n",s[j]);
	}
	m=0;
	for(i=0;i<n;i++)
	{
			if(line[i].age<60)
			{
				strcpy(y[m],line[i].num);
				m++;
			}
	}
    for(j=0;j<n-temp;j++)
	{
	     printf("%s\n",y[j]);
	}

}


struct stu
{char num[20];
int score;
struct stu * next;
};
void sort(struct stu * head,struct stu * q)
{
	struct stu *pre=head,*p=pre->next,*s;
	s=(struct stu *)malloc(sizeof(struct stu));
	s->score=q->score;strcpy(s->num,q->num);
	s->next=NULL;
	if(s->score>=60){
	while((p!=NULL)&&(q->score<=p->score))
	{
		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 stu *head)
{
	struct stu *p;
	int i=0;
	p=head;
	while(p!=NULL)
	{

		printf("%s\n",p->num);
		p=p->next;
	}

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

}


int main()
{
	int i,n,f=0,m=0,j;

	struct
	{
		char id[10];
		int age;
	} bingren[100],t[100],l[100],c;
	scanf("%d",&n);
    for(i=0;i<n;i++)
	{
		scanf("%s%d",&bingren[i].id,&bingren[i].age);
	}
	for(i=0;i<n;i++)
	{
		if(bingren[i].age>=60)
			t[f++]=bingren[i];
		else if(bingren[i].age<60)
		    l[m++]=bingren[i];
	}

	for(i=1;i<f;i++)
	{
		for(j=i;j>0;j--)
		{
		  if(t[j].age>t[j-1].age)
		  {
		  c=t[j];
		  t[j]=t[j-1];
		  t[j-1]=c;
		  }
		}
	}

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

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


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

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


struct patient
{
	char num[10];
	int age;
}a[100];
void main()
{
      int max(int b[],int m);
		int n,i,j=0,c[100],g;
     scanf("%d",&n);
	for (i=0;i<n;i++)
		scanf("%s%d",&a[i].num,&a[i].age);
	for(i=0;i<n;i++)
		c[i]=a[i].age;
 g=max(c,n);
    while (g>=60)
	{
		     for(i=0;i<n;i++)
			 {if (c[i]==g)
			 {
		     printf("%s\n",a[i].num);
			 c[i]=0;
			 }
			 }
		   g=max(c,n);

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

			 if (a[i].age<60)
				 printf("%s\n",a[i].num);
		 }
}
int max(int b[],int m)
{
	int t,s;
  s=b[0];
  for(t=0;t<m;t++)
  {
  if (s<b[t])
	  s=b[t];
  }
  return(s);
}


struct student{
char num[20];
int age;
struct student *next;
};
int n,i;
struct student *create()
{
	struct student *head;
	struct student *p1,*p2;
	head=NULL;
	scanf("%d",&i);
	n=0;
	p1=p2=(struct student *)malloc(len);
	scanf("%s %d",p1->num,&p1->age);
	while(n!=i-1)
	{
		n++;
		if(n==1)
			head=p1;
		else
			p2->next=p1;
		p2=p1;
		p1=(struct student *)malloc(len);
		scanf("%s %d",p1->num,&p1->age);
	}
	p2->next=p1;
	p1->next=NULL;
	return(head);
}
void paixu(struct student *p){
	struct student *p1,*p2;
  char temp[20];
	int temp2;
	for(n=1;n<i;n++){
		p2=p;
	p1=p->next;
	while(p1!=NULL){
			if(p1->age>=60&&p2->age<60){

	strcpy(temp,p1->num);
				strcpy(p1->num,p2->num);
				strcpy(p2->num,temp);
	temp2=p1->	age;
		p1->age=p2->	age;
	p2->age=temp2;
}
			else if(p1->age>p2->age&&p2->age>=60){
				strcpy(temp,p1->num);
				strcpy(p1->num,p2->num);
				strcpy(p2->num,temp);
	temp2=p1->	age;
		p1->age=p2->	age;
	p2->age=temp2;

	}
			p2=p1;
			p1=p1->next;
		}
	}
}
void print(struct student *p)
{
	while(p!=NULL)
	{
		printf("%s",p->num);
		p=p->next;
		if(p!=NULL)
			printf("\n");
	}
}
void main()
{
	struct student *p;
	p=create();
	paixu(p);
	print(p);
}


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

void paixu(struct patient pat[],int n)
{

	struct patient t;
	int i;
	int k;

	for(k=1;k<n;k++){
		for(i=0;i<n-k;i++){
			if(pat[i].age<pat[i+1].age){
				t=pat[i];
				pat[i]=pat[i+1];
				pat[i+1]=t;
			}
		}
	}
}

int main()
{
	struct patient pat;
	struct patient oldpat[100];
	struct patient youngpat[100];

	int n;
	int i;
	int m=0;
	int k=0;

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s %d",pat.ID,&pat.age);
		if(pat.age>=60){
			oldpat[m]=pat;
			m++;
		}else{
			youngpat[k]=pat;
			k++;
		}
	}

	paixu(oldpat,m);

	for(i=0;i<m;i++){
		printf("%s\n",oldpat[i].ID);
	}
	for(i=0;i<k;i++){
		printf("%s\n",youngpat[i].ID);
	}

	return 0;
}


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

struct patient *creat(void)
{
       struct patient *head;
       struct patient *p1,*p2;
       int num;
       scanf("%d",&num);
       p2=NULL;
       p1=(struct patient *)malloc(LEN);
       head=p1;
       while(num>0)
       {
                   p2=p1;
                   scanf("%s %d",&p1->ID,&p1->age);
                   p1=(struct patient *)malloc(LEN);
                   p2->next=p1;
                   num--;
       }
       p2->next=NULL;
       return(head);
}

struct patient *sort(struct patient *head)
{
	struct patient *first;
    struct patient *tail;
	struct patient *p_max;
	struct patient *max;
	struct patient *p;
	first = NULL;
	while (head != NULL)
	{
		for(p=head,max=head; p->next!=NULL; p=p->next)
		{
			if (p->next->age>max->age&&p->next->age>=60)
			{
				p_max = p;
				max = p->next;
			}
		}
		if (first == NULL)
		{
			first = max;
			tail = max;
		}
		else
		{
			tail->next = max;
			tail = max;
		}
		if (max == head)
		{
			head = head->next;
		}
		else
		{
			p_max->next = max->next;
		}
	}
	if (first != NULL)
	{
		tail->next = NULL;
	}
	head = first;
	return head;
}

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

/*?????????????????????????????????????a?b,??b??>a????b>=60????????
???????????????????????60+???60-?????????????????......*/


struct pat
{
      char num[10];
      int age;
}pat[100],str[100],t;
int main()
{

	int n,i,j,a=-1,temp;
	int ch[100];
	char c[100];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s %d",pat[i].num,&pat[i].age);
		if(pat[i].age>=60)
		{
		     a++;
             strcpy(str[a].num,pat[i].num);
			 str[a].age=pat[i].age;
		}
	}
	for(i=a;i>=1;i--)
	{
		for(j=0;j<i;j++)
		{
			if(str[j].age<str[j+1].age)
			{
				t=str[j];
				str[j]=str[j+1];
				str[j+1]=t;
			}
		}
	}
	for(i=0;i<n;i++)
	{
		if(pat[i].age<60)
		{
			a++;
            str[a]=pat[i];
		}
	}
	for(i=0;i<n;i++)
	{
		printf("%s\n",str[i].num);
	}
}


int main()
{
	int n,i,j;
	scanf("%d",&n);
	struct point
	{
		char id[10];
		int age;
	}
	points[100],news[100],tmp;
	for(i=0;i<n;i++)
	{
		scanf("%s %d",&points[i].id,&points[i].age);
	}
	for(i=n-1;i>=0;i--)
	{
		for(j=0;j<i;j++)
		{
			if(points[j+1].age>=60&&points[j+1].age>points[j].age)
			{
				tmp=points[j+1];
				points[j+1]=points[j];
				points[j]=tmp;
			}
		}
	}

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


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

void main ()
{
	int i,n,k=0;
	struct data *p1,*p2,*head;
	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;

	for (i=n;i>n-k;i--)
	{
		head=sort(head,i);
	}
	print(head);
}

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;
	}
	printf("%s\n",code->id);

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

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


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

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

	for(i=0;i<m;i++)
 printf("%s\n",y[i].id);

}


struct huanzhe
{char id[11];
int age;
}sick[110];
int panduan(int *p1,int *p2,int a,int b);
void paixu(int *p3,int *p4,int c);
int main(int argc, char* argv[])
{
	int n,i,pan;
	int ji[110]={1};
	int zhangzhe[110];
	int *pointer1,*pointer2;
	pointer1=ji;
	pointer2=zhangzhe;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s %d",&sick[i].id,&sick[i].age);
	}
	for(i=0;i<n;i++){
		pan=panduan(pointer1,pointer2,sick[i].age,i);
		if(pan){sick[i].age=0;}
	}
	paixu(pointer1,pointer2,ji[0]);
	for(i=1;i<ji[0];i++){
		printf("%s\n",&sick[ji[i]].id);
	}
	for(i=0;i<n;i++){
		if(sick[i].age==0){
			continue;
		}
		printf("%s\n",sick[i].id);
	}
	return 0;
}
int panduan(int *p1,int *p2,int a,int b){
	int jieguo=0;
	if(a>=60){
		*(p1+*p1)=b;
		*(p2+*p1)=a;
		(*p1)++;
		jieguo=1;
	}
	return(jieguo);
}
void paixu(int *p3,int *p4,int c){
	int j,k,temp;
	for(j=0;j<c;j++){
		for(k=1;k<c-1;k++){
			if(*(p4+k)<*(p4+k+1)){
				bian(p3);
				bian(p4);
			}
		}
	}

}


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

int  main()
{
	int n,i;
	scanf("%d",&n);
	struct pat * p[100];
	struct pat * old[100];
	struct pat * young[100],*temp;

	for(i=0;i<n;i++){
		p[i]=(struct pat*)malloc(len);
		scanf("%s %d",p[i]->ID,&p[i]->age);
	}
	int k=0,j=0;
	for(i=0;i<n;i++){
		if(p[i]->age>=60){
			old[k]=p[i];
			k++;
		}
		else{
			young[j]=p[i];
			j++;
		}
	}
	int lenold=k,lenyoung=j;
	for(k=1;k<lenold;k++){
		for(i=0;i<lenold-k;i++){
			if(old[i]->age<old[i+1]->age){
				temp=old[i];
				old[i]=old[i+1];
				old[i+1]=temp;
			}
		}
	}
	for(i=0;i<lenold;i++){
		printf("%s\n",old[i]->ID);
	}
	for(i=0;i<lenyoung;i++){
		printf("%s\n",young[i]->ID);
	}

	return 0;

}


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

void bubble(struct patient * a[],int n);

void main()
{
	int n,i,s=0;
	struct patient p[100]={"0",0};
	struct patient * pt[100];
	scanf("%d",&n);

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

	bubble(pt,n);

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

	for(i=0;i<n;i++)
	{

		if(p[i].age<60)
		{
			printf("%s\n",p[i].ID);

		}

	}

}

void sort2(struct patient * a[],int n)
{
	int i,j,k;
	struct patient * t;
	for(i=0;i<n-1;i++)
	{
		k=i;
		for(j=i+1;j<n;j++)
		{
			if(a[j]->age > a[k]->age)
			{k=j;}
		}
		t=a[k];a[k]=a[i];a[i]=t;
	}
}
void bubble(struct patient * a[],int n)
{
	int i,j;
	struct patient * t;
	for(i=0;i<=n-2;i++)
	{
		for(j=0;j<=n-i-2;j++)
		{
			if(a[j]->age < a[j+1]->age)
			{
				t=a[j];a[j]=a[j+1];a[j+1]=t;
			}
		}
	}
}


struct pa{//patient
	char id[10];
	int age;
	int re;//register
}p[100],po[100],temp;
void main()
{
	int n,i,j,pj=0,oldj=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s%d",p[pj].id,&p[pj].age);
		if(p[pj].age>=60)
		{
			po[oldj]=p[pj];
			po[oldj].re=oldj;
			oldj++;
		}
		else
		{
			p[pj].re=pj;
			pj++;
		}
	}
	for(i=0;i<oldj-1;i++)
	{
		for(j=i+1;j<oldj;j++)
		{
			if ( (po[i].age<po[j].age) || (po[i].age==po[j].age && po[i].re>po[j].re) )
			{
				temp=po[i];
				po[i]=po[j];
				po[j]=temp;
			}
		}
		printf("%s\n",po[i].id);
	}
	printf("%s\n",po[i].id);
	for(i=0;i<pj;i++)
		printf("%s\n",p[i].id);
}


void main(){
	int n,i,j,mid;
	char M[11];
	scanf("%d",&n);
	struct patient{
		char ID[11];
		int age;
	};
	struct patient *per=(struct patient*)malloc(sizeof(struct patient)*n);
	for(i=0;i<n;i++)
		scanf("%s%d",per[i].ID,&per[i].age);
	for(j=0;j<n;j++)
		for(i=0;i<n-1;i++){
			if(per[i].age<60&&per[i+1].age>=60){
				mid=per[i].age;
				strcpy(M,per[i].ID);
				per[i].age=per[i+1].age;
				strcpy(per[i].ID,per[i+1].ID);
				per[i+1].age=mid;
				strcpy(per[i+1].ID,M);
				}
			if(per[i].age>=60&&per[i+1].age>=60&&per[i].age<per[i+1].age){
				mid=per[i].age;
				strcpy(M,per[i].ID);
				per[i].age=per[i+1].age;
				strcpy(per[i].ID,per[i+1].ID);
				per[i+1].age=mid;
				strcpy(per[i+1].ID,M);
				}
	}
	for(i=0;i<n;i++)
		printf("%s\n",per[i].ID);
	free(per);
}


int main()
{
    int n,j,i;
    scanf("%d",&n);
    char a[n][10];
    int b[n];
    for(j=0;j<n;j++)
    scanf("%s %d",a[j],&b[j]);
    for(i=100;i>=60;i--)
    {
                         for(j=0;j<n;j++)
                         {if(b[j]==i)
                         printf("%s\n",a[j]);
                         }
     }

     for(j=0;j<n;j++)
     {
                     if(b[j]<60)
                     printf("%s\n",a[j]);
      }

    getchar();
    getchar();
    getchar();
    getchar();
    getchar();
    getchar();
    getchar();

}


struct information
{
	char ID[10];
	int age;
}*a;
void main()
{
	int n,i,j,max,p,q=0;
	scanf("%d",&n);
	a=(struct information *)malloc(sizeof(struct information)*n);
	for(i=0;i<n;i++) scanf("%s%d",a[i].ID,&a[i].age);
	for(i=0;i<n;i++)
	{
		if(a[i].age>59) q++;
	}
	for(i=0;i<q;i++)
	{
		max=0;
		for(j=0;j<n;j++)
		{
			if(max<a[j].age) {max=a[j].age;p=j;}
		}
		printf("%s\n",a[p].ID);
		a[p].age=0;
	}
	for(i=0;i<n;i++)
	{
		if(a[i].age!=0) printf("%s\n",a[i].ID);
	}
}


int n;
struct patients
{
	char name[11];
	int age;
}pat[100];
struct patold
{
	char name[11];
	int age;
}old[100];
struct patyoung
{
	char name[11];
	int age;
}young[100];
int y=0,o=0;
char nametemp[11];
int agetemp;

int main()
{
	int i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s",&pat[i].name);
		scanf("%d",&pat[i].age);
	}
	for(i=0;i<n;i++)
	{
		if(pat[i].age>=60)
		{
			strcpy(old[o].name,pat[i].name);
			old[o].age=pat[i].age;
			o++;
		}
		else
		{
			strcpy(young[y].name,pat[i].name);
			young[y].age=pat[i].age;
			y++;
		}
	}
	for(i=1;i<o;i++)
	{
		for(j=0;j<o-i;j++)
		{
			if(old[j].age<old[j+1].age)
			{
				agetemp=old[j].age;
				old[j].age=old[j+1].age;
				old[j+1].age=agetemp;
				strcpy(nametemp,old[j].name);
				strcpy(old[j].name,old[j+1].name);
				strcpy(old[j+1].name,nametemp);
			}
		}
	}
	for(i=0;i<o;i++)
		printf("%s\n",old[i].name);
	for(i=0;i<y;i++)
		printf("%s\n",young[i].name);
	return 0;
}


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


struct st
{
	int age,he;
	char num[15];
	struct st *next;
};

struct st *creat(int n)
{
	struct st *head,*p1,*p2;
	int i,h=105;
	p1=(struct st *)malloc(sizeof(struct st));
	p2=p1;
	head=p1;
	for (i=1;i<=n;i++)
	{
		p1=(struct st *)malloc(sizeof(struct st));
		scanf("%s %d",p1->num,&p1->age);
		if (p1->age >= 60)
			p1->he=p1->age*1000+h;
		else p1->he=h;
		p1->next=NULL;
		p2->next=p1;
		p2=p1;
		h--;
	}
	return(head);
}

void paixu(struct st *head)
{
	struct st *max,*p,*p1,*p2,*p3,*p4;
	p1=head;
	while(p1->next)
	{
		p2=p1->next;
		max=p2;
		p4=p2;
		p=p2->next;
		while(p)
		{
			if (p->he > max->he)
			{
				max=p;
				p3=p4;
			}
			p=p->next;
			p4=p4->next;
		}
		if (max>p1->next)
		{
			p3->next=max->next;
			p1->next=max;
			max->next=p2;
		}
		p1=p1->next;
	}
}

void main()
{
	struct st *creat(int n);
	void paixu(struct st *head);
	struct st *head,*p;
	int n;
	scanf("%d",&n);
	head=creat(n);
	paixu(head);
	p=head->next;
	while(p)
	{
		printf("%s\n",p->num);
		p=p->next;
	}
}


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

int main()
{
    void sort(int n,struct p a[101]);
    int n,i;
    struct p a[101];
    scanf("%d\n",&n);
    for(i=0;i<n;i++)
    {
                    scanf("%s %d",&a[i].id,&a[i].age);
    }
    sort(n,a);

    return 0;
}

void sort(int n,struct p a[101])
{
     int i,k=0;
     for(i=0;i<n;i++)
     {
                     if((a[i].age)>k)
                     k=(a[i].age);
     }
     for(;k>59;k--)
     {
                   for(i=0;i<n;i++)
                   {
                                   if((a[i].age)==k)
                                   {
                                                    printf("%s\n",a[i].id);
                                                    (a[i].age)=0;
                                   }
                   }
     }
     for(i=0;i<n;i++)
     {
                     if((a[i].age)!=0)
                     {
                                      printf("%s\n",a[i].id);
                     }
     }
}


int main()
{
	int i,n,t=0,e,num=0,k;
	char z[10];
	struct point
	{
		char ID[10];
		int age;
	}a[100],b[100];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s",&a[i].ID);
		scanf("%d",&a[i].age);
	}
	for(i=0;i<n;i++)
	{
		if(a[i].age>=60)
		{
			num=num+1;
		}
	}
	int f=num;
	for(i=0;i<n;i++)
	{
		if(a[i].age>=60)
		{
			b[t].age=a[i].age;
			strcpy(b[t].ID,a[i].ID);
			t++;
		}
		if(a[i].age<60)
		{
			b[f].age=a[i].age;
			strcpy(b[f].ID,a[i].ID);
			f++;
		}
	}
	for(i=0;i<num;i++)
	{
		for(k=0;k<num-i-1;k++)
		{
			if(b[k].age<b[k+1].age)
			{
				e=b[k].age;
				b[k].age=b[k+1].age;
				b[k+1].age=e;
				strcpy(z,b[k+1].ID);
				strcpy(b[k+1].ID,b[k].ID);
				strcpy(b[k].ID,z);
			}
		}
	}
	for(i=0;i<n;i++)
	{
		printf("%s\n",b[i].ID);
	}

	return 0;

}


struct patient
{
 char id[20];
 int age;
 struct patient *next;
}*head,*p1,*p2;
struct patient *order(int n)
{
 int i,j,t;
 char a[20];
 for(i=0;i<n-1;i++)
 {
  p1=head;p2=p1->next;
   for(j=0;j<n-1-i;j++)
   {
    if(p2->age>=60&&p1->age<p2->age)
     {
       t=p1->age;p1->age=p2->age;p2->age=t;
       strcpy(a,p1->id);strcpy(p1->id,p2->id);strcpy(p2->id,a);
      }
     p1=p1->next;p2=p2->next;
    }
  }
return head;
}
void main()
{
 int n,i;
 scanf("%d",&n);
 p1=head=(struct patient *)malloc(sizeof(struct patient));
 for(i=0;i<n;i++)
 {
  scanf("%s %d",p1->id,&p1->age);
  p2=p1;
  p1=(struct patient *)malloc(sizeof(struct patient));
  p2->next=p1;
  }
 p2->next=NULL;
 p1=order(n);
 while(p1)
 {
  printf("%s\n",p1->id);
  p1=p1->next;
  }
}


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

void main()
{

    struct man * insert(struct man *head,struct man *ill);
	int n,i;
	scanf("%d",&n);
	head=NULL;
	for(i=0;i<n;i++)
	{
		p=(struct man*)malloc(LEN);
		scanf("%s %d",p->id,&p->a);
		head=insert(head,p);
	}

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

struct man * insert(struct man *head,struct man *ill)
{
	struct man *p0,*p1,*p2;
	p1=head;
	p0=ill;
	if(head==NULL)
	{
		head=p0;
		p0->next=NULL;
	}
	else
	{
	  if(p0->a<60)
	  {
			while(p1->next!=NULL)
			{
				p2=p1;
				p1=p1->next;
			}
			p1->next=p0;
			p0->next=NULL;
	  }

	  else if(p0->a>=60)
	  {
		while((p0->a<=p1->a)&&(p1->next!=NULL))
		{
			p2=p1;
			p1=p1->next;
		}
		if(p0->a>p1->a)
		{
			if(head==p1)
				head=p0;
			else
				p2->next=p0;
			p0->next=p1;}
		else
		{
			p1->next=p0;
			p0->next=NULL;
		}

	  }

	}
	return(head);
}


struct person
{char ID[10];
 int age;
}person[100];
void main()
{
	int i,j=-1,k,n,max;
	char s[100][10],a[100];
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%s %d",&person[i].ID,&person[i].age);
	for(i=0;i<n;i++)
	{a[i]=person[i].age;
	  if(person[i].age>=60) j++;}
	for(k=0;k<=j;k++)
	{
  	 max=0;
	 for(i=0;i<n;i++)
 	   max=(max>=a[i])?max:a[i];
	 for(i=0;i<n;i++)
	    if(a[i]==max)
		{printf("%s\n",person[i].ID);
	     a[i]=0;
  	     break;
		}
	}
	for(i=0;i<n;i++)
	if(person[i].age<60) printf("%s\n",person[i].ID);
}


struct ren
{
	char id[12];
	int ye;
	struct ren *next;
};
int main()
{
	int n;
	char c[12];
	int y;
	int r;
	struct ren *p1, *p2,*head;
	int i;
	scanf("%d", &n);
	head = (struct ren *)malloc(sizeof(struct ren));
	scanf("%s %d", c, &y);
	strcpy(head->id, c);
	head->ye = y;
	head->next = 0;
	for (i = 2; i <= n; i++)
	{
		scanf("%s %d", c, &y);
		p1 = (struct ren *)malloc(sizeof(struct ren));
		strcpy(p1->id, c);
		p1->ye = y;
		p1->next = 0;
		if (y < 60)
		{
			p2 = head;
			while (p2->next != 0)
				p2 = p2->next;
			p2->next = p1;
		}
		else
		{
			p2 = head;
			if (y>p2->ye)
			{
				p1->next = head;
				head = p1;
			}
			else
			{
				r = 0;
				while (p2->next != 0)
				{
					if (p2->ye >= y&&p2->next->ye < y)
					{
						r = 1;
						p1->next = p2->next;
						p2->next = p1;
						break;
					}
					p2 = p2->next;
				}
				if (r == 0)
				{
					p2->next = p1;
				}
			}
		}
	}
	p1 = head;
	do
	{
		printf("%s\n", p1->id);
		p1 = p1->next;
	} while (p1 != 0);
}


struct patients
{
	int num;
	char ID[10];
	int age;
};

int main()
{
	int n,i,j,y,o;
    struct patients list[100],young[100],old[100];
	scanf("%d",&n);

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

	y=0;
	o=0;

	for(i=0;i<n;i++)
	{
		if(list[i].age>=60){
			old[o]=list[i];
			o++;
		}else{
			young[y]=list[i];
			y++;
		}
	}

	for(i=1;i<o;i++)
	{
		for(j=0;j<o-i;j++)
		{
			if(old[j].age<old[j+1].age){
				struct patients check;
				check=old[j];
				old[j]=old[j+1];
				old[j+1]=check;
			}
		}
	}

	for(i=0;i<o;i++)
	{
		printf("%s\n",old[i].ID);
	}
	for(i=0;i<y;i++)
	{
		printf("%s\n",young[i].ID);
	}

	return 0;
}


struct node
{
char s[100];
int age,no;
}a[1000],b;
int check(int x,int y)
{
if(a[y].age<60 && a[x].age>=60) return 0;
if(a[y].age>=60 && a[x].age<60) return 1;
if(a[x].age<60 && a[y].age<60 && a[x].no>a[y].no) return 1;
if(a[x].age<60 && a[y].age<60 && a[x].no<a[y].no) return 0;
if(a[x].age>a[y].age) return 0;
if(a[x].age<a[y].age) return 1;
if(a[x].no<a[y].no) return 0;
if(a[x].no>a[y].no) return 1;
return 0;
}
int main()
{
int i,j,n;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%s %d",&a[i].s,&a[i].age);
a[i].no=i;
}
for(i=1;i<n;i++)
 for(j=i+1;j<=n;j++)
  if(check(i,j)==1){b=a[i];a[i]=a[j];a[j]=b;}
for(i=1;i<=n;i++)
printf("%s\n",a[i].s);
return 0;
}


main()
{
	int n,i,j,k,temp,s,max;
         int is_over_sixty_exist=1;
	int age[100]={0},queue[100]={0};
	char id[100][10]={'0'};
	scanf("%d",&n);
	for (i=0;i<n;i++){
		queue[i]=i;
		scanf("%s%d",id[i],&age[i]);
	}
	i=0;
	while (is_over_sixty_exist){
		max=0;
		is_over_sixty_exist=0;
		temp=queue[i];
		for (j=0;j<n;j++){
			if (age[j]>=60&&age[j]>max){
				is_over_sixty_exist=1;
				max=age[j];
				queue[i]=j;
			}
		}
		for (s=i+1;s<n;s++)
			if (queue[s]==queue[i])
				break;
		age[queue[i]]=0;
		if (is_over_sixty_exist){
			if (s!=n){
				for (k=s;k>=i+1;k--)
					queue[k]=queue[k-1];
				queue[i+1]=temp;
			}
		}
		i++;
	}
	for (i=0;i<n;i++)
		printf("%s\n",id[queue[i]]);
}


int main(){
	int n,i;
	scanf("%d",&n);
	struct{
		char id[10];
		int age;
	}br [100],*p,old[100],*q;
	for(p=br;p<br+n;p++){
		scanf("%s%d",&(p->id),&(p->age));
	}
	q=old;
	int js=0;
	for(p=br;p<br+n;p++){
		if(p->age>=60){
			q->age=p->age;
			strcpy(q->id,p->id);
			q++;
			js++;
			p->age=0;
		}
	}
	int  max=0;
	for(i=0;i<js;i++){
		for(q=old;q<old+js;q++){
			if(q->age>(old+max)->age){
				max=q-old;
			}
		}
		printf("%s\n",(old+max)->id);
		(old+max)->age=0;
	}
	for(p=br;p<br+n;p++){
		if(p->age!=0){
			printf("%s\n",p->id);
		}
	}
	return 0;
}


struct bing
{
	char id[20];
	int age;
};
int main()
{
	struct bing b[100],sixup[100],sixdown[100];
	struct bing temp;
	int m;
	int n,l;
	int i,j;
	scanf("%d",&m);
	for(i=0;i<=m-1;i++)
	{
		scanf("%s%d",b[i].id,&b[i].age);
	}
	n=0;l=0;
	for(i=0;i<=m-1;i++)
	{
		if(b[i].age>=60)
		{
			sixup[n]=b[i];
			n++;
		}
		else
		{	sixdown[l]=b[i];
			l++;
		}
	}
	for(i=1;i<=n-1;i++)
	{
		temp=sixup[i];
		for(j=i-1;j>=0;j--)
		{
			if(temp.age>sixup[j].age)
			{
				sixup[j+1]=sixup[j];
				sixup[j]=temp;
			}
			else
			{
				break;
			}
		}
	}
	for(i=0;i<=n-1;i++)
	{
		puts(sixup[i].id);
	}
	for(i=0;i<=l-1;i++)
	{
		puts(sixdown[i].id);
	}
	return 0;
}


struct patient
{
	char id[10];
	int age;
	struct patient *next;
};
int n;
struct patient *creat(int num)  /*????*/
{
	struct patient *head,*p1,*p2;
	n=0;
	p1=p2=(struct patient *)malloc(sizeof(struct patient));
	scanf("%s %d",p1->id,&p1->age);
	head=NULL;
	while(n<(num-1))
	{
		n=n+1;
		if(n==1)head=p1;
		else p2->next=p1;
		p2=p1;
		p1=(struct patient *)malloc(sizeof(struct patient));
		scanf("%s %d",p1->id,&p1->age);
	}
	p2->next=p1;
	p1->next=NULL;
	return(head);
}
struct patient *old(struct patient *head)  /*??????????????old???????????60?????????*/
{
	struct patient *old,*p1,*p2,*p;
	n=0;
	p=head;
	p1=p2=(struct patient *)malloc(sizeof(struct patient));
	old=NULL;
	while(p!=NULL)
	{
		if((n==0)&&(p->age>=60))
		{
			strcpy(p1->id,"");
			strcpy(p1->id,p->id);
			p1->age=p->age;
			old=p1;
			p2=p1;   /*?????????????????*/
			n=1;       /*?????????????????*/
		}
		else if(p->age>=60)
		{
			strcpy(p1->id,"");
			strcpy(p1->id,p->id);
			p1->age=p->age;
			p2->next=p1;
            p2=p1;            /*?????????????p2=p1???????*/
		}
		p1=(struct patient *)malloc(sizeof(struct patient));
		p=p->next;
	}
	p2->next=NULL;
	return(old);
}
struct patient *sort(struct patient *head)   /*?????????????????????????????????????*/
{
	struct patient head0,end0;
	struct patient *p0,*p1,*p2,*p;
	head0.next=head;
	p=head;
	while(p->next!=NULL)
		p=p->next;
	p=p->next=&end0;
	while(p!=head0.next)   /*????????????????p!=head,????p!=head0.next*/
	{
		p0=&head0;
		p1=p0->next;
		p2=p1->next;
		while(p2!=p)
		{
			if((p1->age)<(p2->age))
			{
				p0->next=p2;
				p1->next=p2->next;
				p2->next=p1;
				p0=p2;
				p2=p1->next;
			}
			else
			{
				p0=p1;
				p1=p2;
				p2=p2->next;
			}
		}
		p=p1;
	}
	while(p->next!=&end0)
		p=p->next;
	p->next=NULL;
	return(p1);
}
void print2(struct patient *head)   /*??????????????60????id*/
{
	struct patient *p;
	p=head;
	while(p!=NULL)
	{
	   if(p->age<60) printf("%s\n",p->id),p=p->next;
	   else p=p->next;
	}
}
void print1(struct patient *head)    /*???????????????????????????id*/
{
	struct patient *p;
	p=head;
	while(p!=NULL)
	{
		printf("%s\n",p->id);
		p=p->next;
	}
}
void main()
{
	struct patient *creat(int num);
	struct patient *old(struct patient *head);
    struct patient *sort(struct patient *head);
	void print1(struct patient *head);
	void print2(struct patient *head);
	struct patient *head,*oldp,*sortold;  /*???????????????*sortold?????????????????*/
	int num;
	scanf("%d",&num);
	head=creat(num);
	oldp=old(head);
	sortold=sort(oldp);
	print1(sortold);
	print2(head);
}


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


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


struct patient
{
       char name[20];
       int age;
} line[202], temp;

int main()
{
    int n, i, j;
    scanf("%d", &n);
    for(i=1;i<=n;i++)
    {
        scanf("%s", &line[i].name);
        scanf("%d", &line[i].age);
    }
    for(i=1;i<=n;i++)
    {
       for (j=n;j>i;j--)
       {
           if(line[j].age>=60){
       if(line[j].age>line[j-1].age)
       {
           temp=line[j];
           line[j]=line[j-1];
           line[j-1]=temp;
       }
       }
       }
    }
    for(i=1;i<=n;i++)
    {

            printf("%s\n", line[i].name);

    }
    return 0;
}


int main(){
	struct man
	{
		char a[11];
		int y;
	}man[100];
	int n;
	scanf("%d",&n);
	char b[11];
	int y;
	int i,j;
	char c[100][11];
	int m=0,k=0;
	for(i=0;i<n;i++){
		scanf("%s%d",b,&y);
		if(y>=60){
			strcpy(man[k].a,b);
			man[k].y=y;
			k++;
		}
		else{
			strcpy(c[m],b);
			m++;
		}
	}
	for(i=1;i<k;i++){
		for(j=0;j<k-i;j++){
			int y1,y2;
			y1=man[j].y;
			y2=man[j+1].y;
			if(y1<y2){
				y=man[j+1].y;
				man[j+1].y=man[j].y;
				man[j].y=y;
				strcpy(b,man[j+1].a);
				strcpy(man[j+1].a,man[j].a);
				strcpy(man[j].a,b);
			}
		}
	}
	for(i=0;i<k;i++){
		strcpy(b,man[i].a);
		printf("%s\n",b);
	}
	for(i=0;i<m;i++){
		strcpy(b,c[i]);
		printf("%s\n",b);
	}
	return 0;
}


int num,n=0;
struct pa
{
	char id[10];
	int age;
	int o;
}*p;

int operate()
{
	struct pa *pi,*pj;
	int agem=0,om=0;
	for(pi=p;pi<p+num;pi++)
	{
		if(pi->o==0)
			continue;
		for(pj=p;pj<p+num;pj++)
		{
			if(pj->age<pi->age)
				pi->o++;
		}
		if(pi->o>om)
			om=pi->o;
	}
	return om;
}
void print(int om)
{
	int k;
	struct pa *pi;
	for(k=om;k>=0;k--)
		for(pi=p;pi<p+num;pi++)
		{
			if(pi->o==k)
			{
				if(n==0)
				{
					printf("%s",pi->id);
					n++;
				}
				else
					printf("\n%s",pi->id);
			}
		}
}

main()
{
	scanf("%d",&num);
	struct pa *pi;
	int om;
	p=(struct pa*)malloc(num*sizeof(struct pa));
	for(pi=p;pi<p+num;pi++)
	{
		scanf("%s %d",pi->id,&pi->age);
		if(pi->age>=60)
			pi->o=1;
		else pi->o=0;
	}
	om=operate();
	print(om);
}


struct Ill {
	char a[10];
	int age;
};

int main()
{
	int n, i, k;
	int m,l = 0;
	int j = 0;
	struct Ill illMan[100], illOld[100], temp,illOld1[100];

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

	for (i = 0; i < n; i++) {
		if (illMan[i].age >= 60) {
			illOld1[j] = illMan[i];
			j++;
		}
	}
	for (i = 0; i < j; i++) {
		m = 0;
		for (k = 0; k < j; k++) {
			if (m < illOld1[k].age) {
				m = illOld1[k].age;
			}
		}
		for (k = 0; k < j; k++) {
			if (illOld1[k].age == m) {
				illOld[l] = illOld1[k];
				illOld1[k].age = 0;
				l++;
				break;
			}
		}
	}
	for (i = 0; i < j; i++) {
		printf("%s\n",illOld[i].a);
	}
	for (i = 0; i < n; i++) {
		if (illMan[i].age < 60) {
			printf("%s\n",illMan[i].a);
		}
	}
	return 0;
}


struct sick
{
	char num[10];
	int age;
};
int main()
{
	int i,j,n;
	int s;
	char swap[10];
	struct sick all[100];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s",&all[i].num);
		scanf("%d",&all[i].age);
	}
	for(i=1;i<n;i++){
		for(j=i;j>0;j--){
			if(all[j].age>=60&&all[j].age>all[j-1].age){
				s=all[j].age;
				all[j].age=all[j-1].age;
				all[j-1].age=s;
				strcpy(swap,all[j].num);
				strcpy(all[j].num,all[j-1].num);
				strcpy(all[j-1].num,swap);
			}
			else{
				break;
			}
		}
	}
	for(i=0;i<n;i++){
		puts(all[i].num);
	}
	return 0;
}


int main(){
	int n;
	scanf("%d",&n);
	char id[100][10];
	int age[100];
	int oldno=0;
	int xu[100];
	char shunxu[100][10];
	for(int i=0;i<n;i++){
		scanf("%s %d",id[i],&age[i]);
	}
	for(int j=0;j<n;j++){
		if(age[j]>=60){
			xu[oldno]=age[j];
			strcpy(shunxu[oldno],id[j]);
			oldno++;
		}
	}

	int num=oldno;
	int e;
	char tem[10];
	for(int k=0;k<n;k++){
		if(age[k]<60){
            xu[oldno]=age[k];
			strcpy(shunxu[oldno],id[k]);
			oldno++;
		}
	}
	for(int x=1;x<=num;x++){
		for(int y=0;y<num-x;y++){
			if(xu[y]<xu[y+1]){
				e=xu[y];
				xu[y]=xu[y+1];
				xu[y+1]=e;
				strcpy(tem,shunxu[y]);
				strcpy(shunxu[y],shunxu[y+1]);
				strcpy(shunxu[y+1],tem);
			}
		}
	}
	for(int z=0;z<n;z++){
		printf("%s\n",shunxu[z]);
	}
    return 0;
}


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


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

struct patient *sort(struct patient *head,char d[10],int a)
{
	struct patient *pp,*p,*s;
	p=head;
	pp=p;
	p=p->next;
	s=(struct patient *)malloc(LEN);
	strcpy(s->id,d);
	s->age=a;
	while(p!=NULL&&p->age>=a)
	{
		pp=p;
		p=p->next;
	}
	s->next=p;
	pp->next=s;
}

struct patient *creat(struct patient *hhead,char d[10],int a)
{
	struct patient *p,*pp,*s;
	p=hhead;
	pp=p;
	p=p->next;
	while(p!=NULL)
	{
		pp=p;
		p=p->next;
	}
	s=(struct patient*)malloc(LEN);
	s->age=a;
	strcpy(s->id,d);
	s->next=p;
	pp->next=s;
}

void main()
{
	struct patient *head,*hhead,*p1,*p2;
	int n,a,i;
	char d[10];
	scanf("%d",&n);
	head=(struct patient*)malloc(LEN);
	head->next=NULL;
	hhead=(struct patient*)malloc(LEN);
	hhead->next=NULL;
	for(i=0;i<n;i++)
	{
		scanf("%s %d\n",d,&a);
		if(a>=60)
			sort(head,d,a);
		else creat(hhead,d,a);
	}
	p1=head->next;
	p2=hhead->next;
	while(p1!=NULL)
	{
		printf("%s\n",p1->id);
		p1=p1->next;
	}
	while(p2!=NULL)
	{
		printf("%s\n",p2->id);
		p2=p2->next;
	}
}


struct patient{
	char id[10];
	int age;
}pat[100],order[100],buffer[100],swap;

int main (){

	int i,j=0,m=0,n,k,p,q;
	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){
			order[j]=pat[i];
			j++;}
		}
	for(i=0;i<n;i++){
		if (pat[i].age<60){
		    buffer[m]=pat[i];
			m++;}
		}

	for(p=1;p<j;p++){
		for(q=0;q<j-p;q++){
					if (order[q].age<order[q+1].age){
						swap=order[q+1];
						order[q+1]=order[q];
						order[q]=swap;
					}
				}
			}
			for(q=0;q<j;q++){
			printf("%s",order[q].id);
			printf ("\n");}
			for(i=0;i<m;i++){
			printf("%s",buffer[i].id);
         	printf("\n");}

		}


int main()
{
	struct bingren
	{
		char num[10];
		int age;
	};
	int n;
	scanf("%d",&n);
	struct bingren u[1000];
	int i;
	for(i=0;i<n;i++)
	{
		scanf("%s %d",&u[i].num,&u[i].age);
	}
	struct bingren v[1000];
	int j=0;
    for(i=0;i<n;i++)
	{
		if(u[i].age>59)
		{v[j]=u[i];
		j++;
		}
	}
	int k;
    struct bingren e;
	for(k=1;k<j;k++)
	{
		for(i=0;i<j-k;i++)
		{
			if(v[i].age<v[i+1].age)
			{
				e=v[i+1];
				v[i+1]=v[i];
				v[i]=e;
			}
		}
	}
	for(i=0;i<j;i++)
	{
		printf("%s\n",v[i].num);
	}
		for(i=0;i<n;i++)
		{if(u[i].age<60)
		{printf("%s\n",u[i].num);}
		}
	return 0;
}


struct patient{
 int num;
 char hao[20];
 int age;
 struct patient *next;
};
struct ans{
 int numan;
 char haoan[20];
 int agean;
 struct ans *nextan;
};
void main()
{
	struct patient *head,*p1,*p2;
	struct ans *headan,*ans1,*ans2;
	int i,j,max,n,shu;
	shu=0;
	scanf("%d",&n);
	p1=(struct patient*)malloc(sizeof(struct patient));
	scanf("%s %d",p1->hao,&p1->age);
	p1->num=1;
	head=p1;
	p2=p1;
	for(i=0;i<n-1;i++)
	{
		p1=(struct patient*)malloc(sizeof(struct patient));
		scanf("%s %d",p1->hao,&p1->age);
		p2->next=p1;
		p1->num=i+2;
		p2=p1;
	}
	p2->next=NULL;
	max=0;
	p1=head;
	for(j=0;j<n;j++)
	{
		if(max<p1->age)max=p1->age;
		p1=p1->next;
	}
	p1=head;
	for(j=0;j<n;j++)
	{
		if(max==p1->age)
		{
			ans1=(struct ans*)malloc(sizeof(struct ans));
			strcpy(ans1->haoan,p1->hao);
			printf("%s\n",ans1->haoan);
			ans1->agean=max;
			headan=ans1;
			ans2=ans1;
			p1->num=-1;
			p1->age=-1;
			shu=shu+1;
			break;
		}
		p1=p1->next;
	}
	for(i=0;i<n-1;i++)
	{
		max=0;
		p1=head;
		for(j=0;j<n;j++)
		{
			if(max<p1->age)max=p1->age;
			p1=p1->next;
		}
		if(max<60)break;
		p1=head;
		for(j=0;j<n;j++)
		{
			if(max==p1->age)
			{
				ans1=(struct ans*)malloc(sizeof(struct ans));
				strcpy(ans1->haoan,p1->hao);
				printf("%s\n",ans1->haoan);
				ans1->agean=max;
				headan=ans1;
				ans2=ans1;
				p1->num=-1;
				p1->age=-1;
				shu=shu+1;
				break;
			}
			p1=p1->next;
		}
	}
	for(i=0;i<n-shu;i++)
	{
		max=101;
		p1=head;
		for(j=0;j<n;j++)
		{
			if(max>p1->num&&p1->num!=-1)max=p1->num;
			p1=p1->next;
		}
		p1=head;
		for(j=0;j<n;j++)
		{
			if(max==p1->num)
			{
				ans1=(struct ans*)malloc(sizeof(struct ans));
				strcpy(ans1->haoan,p1->hao);
				printf("%s\n",ans1->haoan);
				ans1->numan=max;
				headan=ans1;
				ans2=ans1;
				p1->num=-1;
				p1->age=-1;
				break;
			}
			p1=p1->next;
		}
		ans2->nextan=NULL;
	}
}


main()
{
 int n,oversix=0,undersix=0,osix[100],usix[100],t;
 char noosix[100][100]={0},nousix[100][100]={0},a[100][100]={0};
 char s[100][100]={0};
 scanf("%d",&n);
 int b[100];
 for(int i=0;i<n;i++)
            {
             scanf("%s %d",a[i],&b[i]);
            }
 for(int i=0;i<n;i++)
            {
             if(b[i]>=60)
                       {
                        oversix++;
                        osix[oversix-1]=b[i];
                        strcpy(noosix[oversix-1],a[i]);
                       }
             else
                       {
                        undersix++;
                        usix[undersix-1]=b[i];
                        strcpy(nousix[undersix-1],a[i]);
                       }
             }
 for(int j=0;j<oversix-1;j++)
             for(int i=0;i<oversix-1-j;i++)
                       if(osix[i]<osix[i+1])
                              {
                               t=osix[i];
                               strcpy(s[i],noosix[i]);
                               osix[i]=osix[i+1];
                               strcpy(noosix[i],noosix[i+1]);
                               osix[i+1]=t;
                               strcpy(noosix[i+1],s[i]);
                              }
 for(int i=0;i<oversix;i++)
 printf("%s\n",noosix[i]);
 for(int i=0;i<undersix;i++)
 printf("%s\n",nousix[i]);
 getchar();
 getchar();
}


int main(){
	int sixty[100];
         	int n,i,j,a;
         struct patient{
	char num[11];
	int age;
         }peo[100];
	scanf("%d",&n);

	for(i=0;i<n;i++){
		scanf("%s %d",peo[i].num,&peo[i].age);
		if(peo[i].age>=60){
			sixty[i]=peo[i].age;

		}else{

			sixty[i]=0;
		}
	}

	for(j=0;j<n-1;j++){
		for(i=n-1;i>j;i--){
			if(sixty[i-1]<sixty[i]){
				a=sixty[i-1];
				sixty[i-1]=sixty[i];
				sixty[i]=a;

			}
		}
	}

	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if(sixty[i]==peo[j].age&&sixty[i]!=sixty[i-1]){      				printf("%s\n",peo[j].num);
			}
		}
	}
	for(i=0;i<n;i++){
		if(peo[i].age<60){
			printf("%s\n",peo[i].num);
		}
	}

	return 0;

}


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

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

	int n,b=0,i,j,k,e;

	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]=people[i].age;

			b+=1;
		}else{

			sixty[i]=0;
		}
	}

	for(k=0;k<n-1;k++){
		for(i=n-1;i>k;i--){
			if(sixty[i-1]<sixty[i]){
				e=sixty[i-1];
				sixty[i-1]=sixty[i];
				sixty[i]=e;

			}
		}
	}

	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if(sixty[i]==people[j].age&&sixty[i]!=sixty[i-1]){
				printf("%s\n",people[j].id);
			}

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

	return 0;

}


struct h{
	char name[11];
	int age;
};
void main(){
	int i,k,n;
	scanf("%d",&n);
	struct h p[100];
	for(i=0;i<n;i++){
		scanf("%s %d",p[i].name,&p[i].age);
	}
	for(k=100;k>59;k--){
		for(i=0;i<n;i++){
			if(k==p[i].age)
				printf("%s\n",p[i].name);
		}
	}
	for(i=0;i<n;i++){
		if(p[i].age<60)
			printf("%s\n",p[i].name);
	}
}


main()
{
           char ID[N][L],IDup60[N][L],IDunder60[N][L],s[L];
           int b,h,i,j,k,l,m,max=0,n,o,p,q,t=0,u=0,YearOld[N],YearOldup60[N],id[N],idup60[N];
           scanf("%d",&n);
           for(h=0;h<n;h++)
           {
                 scanf("%s %d",ID[h],&YearOld[h]);
                 id[h]=0;
           }
           for(i=0;i<n;i++)
           {
                 for(j=0;ID[i][j]!='\0';j++)
                 {
                        id[i]=10*id[i];
                        id[i]=id[i]+(ID[i][j]-'0');
                 }
           }
           for(m=0;m<n;m++)
           {
                 if(YearOld[m]>max)
                 max=YearOld[m];
           }
           for(k=0;k<=max;k++)
           {
                 for(l=0;l<n;l++)
                 {
                        if(YearOld[l]==max-k&&max-k>=60)
                        {
                               YearOldup60[t]=YearOld[l];
                               idup60[t]=id[l];
                               strcpy(IDup60[t],ID[l]);
                               t++;
                        }
                }
          }
          for(b=0;b<n;b++)
          {
                if(YearOld[b]<60)
                {
                       strcpy(IDunder60[u],ID[b]);
                       u++;
                }
          }
          for(p=0;p<t;p++)
          {
                printf("%s\n",IDup60[p]);
          }
          for(q=0;q<u;q++)
          {
                printf("%s\n",IDunder60[q]);
          }
}


struct patient{
	char id[10];
	int age;
};
int main(){
	int j,max,t=1,n,i;
	struct patient p[101];
	scanf("%d",&n);
	for (i=1;i<=n;i++)
		scanf("%s%d",p[i].id,&p[i].age);
	for (;t!=0;){
	max=59;t=0;
	for (i=1;i<=n;i++){
		if (p[i].age>max) {max=p[i].age; t=i;}
	}
	if (t!=0) printf("%s\n",p[t].id);
	p[t].age=0;
	}
	for (i=1;i<=n;i++)
		if (p[i].age!=0) printf("%s\n",p[i].id);
}


struct info
{
	int num;
	char data[10];
	struct info*next;
	int tip;
};

struct info*create(int n)
{
	struct info *p1,*pre,*p2,*head,*tail;
	int i,t;
	head=(struct info*)malloc(sizeof(struct info));
	p1=(struct info*)malloc(sizeof(struct info));
	scanf("%s %d",p1->data,&p1->num);
	head->next=p1;
	p1->next=NULL;
	tail=p1;
	i=0;
	while(i<n-1)
	{
		t=0;
		p1=(struct info*)malloc(sizeof(struct info));
		scanf("%s %d",p1->data,&p1->num);
		p1->next=NULL;
		if(p1->num>=60)
		{
			for(pre=head,p2=head->next;p2!=NULL&&p2->num>=60;pre=pre->next,p2=p2->next)
			{
			if(p2->num<p1->num)
			{
				pre->next=p1;
				p1->next=p2;
			    t=1;
				break;
			}
			}
            if(t==0)
			{
			pre->next=p1;
		    p1->next=p2;
			if(p2==NULL)
			{tail=p1;}
			}
		}
		else
		{
			tail->next=p1;
			tail=p1;
		}
	i++;
	}
	return head;
}
void print(struct info *head)
{
	struct info *p;
	p=head->next;
	while(p!=NULL)
	{
		printf("%s\n",p->data);
	    p=p->next;
	}
}
int main()
{
	int n;
	struct info *head;
	scanf("%d",&n);
	head=create(n);
    print(head);
}


struct patient
{
	char num[11];
	int age;
}sick[101];
int main()
{
	int n,i,j,k,r,s;
	s=0;
	r=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s",sick[i].num);
		scanf("%d",&sick[i].age);
	}
	int old[101]={0};
	int young[101]={0};
	for(i=0;i<n;i++){
		if(sick[i].age>=60){
			for(j=0;j<=s;j++){
				if(sick[i].age>sick[old[j]].age||j==s){
					if(j==s){
						old[s]=i;
						s=s+1;
						break;
					}
					else{
						for(k=s;k>=j;k--){
							old[k+1]=old[k];
						}
						old[j]=i;
						s=s+1;
						break;
					}
				}
			}
		}
		else{
			young[r]=i;
			r=r+1;
		}
	}
	for(i=0;i<s;i++){
		printf("%s\n",sick[old[i]].num);
	}
	for(i=0;i<r;i++){
		printf("%s\n",sick[young[i]].num);
	}

	return 0;
}


struct pt
{
  char id[10];
  int age;
};

void main()
{
  int n,i,j,old;
  struct pt p[100],o[100],tem;
  char cao;
  scanf("%d",&n);
  scanf("%c",&cao);
  old=0;
  for(i=0;i<n;i++)
{

   scanf("%s %d",p[i].id,&p[i].age);
  if(p[i].age>=60) {o[old]=p[i];old++;}
}
for(i=0;i<old-1;i++)
{
  for(j=0;j<old-1;j++)
{
  if(o[j+1].age>o[j].age)
{
  tem=o[j];
  o[j]=o[j+1];
  o[j+1]=tem;
}
}
}
 for(i=0;i<old;i++) printf("%s\n",o[i].id);
 for(i=0;i<n;i++)
{
  if(p[i].age<60)
{
  printf("%s\n",p[i].id);
}
}

}


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

int main()

{
	void bubble(struct patient a[],int len);
	int n,i,old,sum,age,j;
    struct patient a[100];
	struct patient b[100];
	char str[100]={'\0'};
	char str1[100]={'\0'};

	scanf("%d",&n);

	for(i=0,j=0,sum=0;sum<=n;)
	{
		age=0;
		strcpy(str,str1);
		scanf("%s %d",str,&age);

		if(age>=60){strcpy(a[i].num,str);a[i].age=age;i++;sum++;}
		else{strcpy(b[j].num,str);b[j].age=age;j++;sum++;}

	}
	//printf("%d",i);

	bubble(a,i);
	old=i;

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

	return 0;
}

void bubble(struct patient a[],int len)
{
	int i,pass;
	struct patient temp;//temp????????????

	for(pass=1;pass<len;pass++)
	{
		for(i=0;i<len-pass;i++)
		{
			if(a[i].age<a[i+1].age)
			{temp=a[i];a[i]=a[i+1];a[i+1]=temp;}
		}
	}
}


struct patient
{
	char num[10];
	int  age;
} p[100];

void main()
{
	int i,j=0,k=0,t,l,n;
	char other[100][10],a[10];
	struct patient old[100];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%s%d",p[i].num,&p[i].age);
   for(i=0;i<n;i++)
	{
		if(p[i].age>=60)
		{

		  strcpy(old[j].num,p[i].num);
		  old[j].age=p[i].age;
		  j++;
		}
		else
		{
			strcpy(other[k],p[i].num);
			k++;
		}
	}

	for(i=0;i<j-1;i++)
	{
		for(l=0;l<j-1-i;l++)
		{
			if(old[l].age<old[l+1].age)
			{
				t=old[l].age;
                old[l].age=old[l+1].age;
				old[l+1].age=t;

				strcpy(a,old[l].num);
				strcpy(old[l].num,old[l+1].num);
				strcpy(old[l+1].num,a);
			}
		}
	}
	for(i=0;i<j;i++)
	printf("%s\n",old[i].num);
	for(i=0;i<k;i++)
	printf("%s\n",other[i]);
}


void main()
{
	struct person
	{
		char id[10];
		int age;
	} m[100],b[100];
	int n,t,i,j;
	char temp[10];

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

	for(i=0;i<n-1;i++)
		for(j=0;j<n-1-i;j++)
		{
			if(m[j].age<m[j+1].age)
			{
				t=m[j].age;
				m[j].age=m[j+1].age;
				m[j+1].age=t;
				strcpy(temp,m[j].id);
				strcpy(m[j].id,m[j+1].id);
				strcpy(m[j+1].id,temp);
			}
		}
		for(i=0;i<n;i++)
			if(m[i].age>=60) printf("%s\n",m[i].id);
		for(i=0;i<n;i++)
			if(b[i].age<60)	printf("%s\n",b[i].id);

}


struct st
{
	char s[11];
	int n;
	struct st *next;
};
struct st *creat(int m)
{
	struct st *head,*p1,*p2;
	int i;
	for(i=0;i<m;i++)
	{
		p1=(struct st *)malloc(len);
		if(i==0)head=p1;
		else p2->next=p1;
		scanf("%s %d",p1->s,&p1->n);
		p2=p1;
	}
	p2->next=NULL;
	return(head);
}
void line(struct st *head,int m)
{
	struct st *p,*p1,*p2;
	p=head;
	int i,j,t;
	for(i=0;i<m;i++)
	{
		p1=p;
		p2=p1->next;
		for(j=1;j<m;j++)
		{
			char ss[11]={'\0'};
			if(p1->n>=60)
			{
				if(p2->n>p1->n)
				{
					strcpy(ss,p1->s);
					strcpy(p1->s,p2->s);
					strcpy(p2->s,ss);
					t=p1->n;
					p1->n=p2->n;
					p2->n=t;
				}
			}
			else
			{
				if(p2->n>=60)
				{
					strcpy(ss,p1->s);
					strcpy(p1->s,p2->s);
					strcpy(p2->s,ss);
					t=p1->n;
					p1->n=p2->n;
					p2->n=t;
				}
			}
			p1=p1->next;
			p2=p2->next;
		}
	}
	for(i=0;i<m;i++)
	{
		printf("%s\n",p->s);
		p=p->next;
	}
}
void main()
{
	struct st *p;
	void line(struct st *head,int m);
	struct st *creat(int m);
	int m,i,j;
	scanf("%d",&m);
	p=creat(m);
	line(p,m);
}


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


struct patient
{
    char id[15];
	int  age;
	struct patient *ne;
};

struct patient *lian(int n)
{
    int i;
	struct patient *head;
	struct patient *p;
	struct patient *q;

	head=(struct patient *)malloc(sizeof(struct patient));
	scanf("%s%d",head->id,&head->age);
	head->ne=0;
	q=head;
	for(i=1;i<n;i++)
	{
		p=(struct patient *)malloc(sizeof(struct patient));
		scanf("%s%d",p->id,&p->age);
	    p->ne=0;
		q->ne=p;
		q=p;
	}
	return head;
}

int main()
{
    int n,max,i,sign,b=5000;
	struct patient *head;
    struct patient *p;

	scanf("%d",&n);

	head=lian(n);

	for(;;)
	{

	     for(p=head,max=-1,sign=0;p!=NULL;p=p->ne)
		 {
	         if(((p->age)>=60)&&max<(p->age)&&((p->age)<b))
			 {
		    	max=p->age;
		    	sign=1;
			 }
		 }
		 b=max;
	    if(sign==0)
	     	break;
	    for(p=head;p!=NULL;p=p->ne)
		{
	        if((p->age)==max)
			{
				printf("%s\n",p->id);

			}
		}

	}
	for(p=head;p!=NULL;p=p->ne)
	{
	    if((p->age)<60)
			printf("%s\n",p->id);
	}

	return 0;

}


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


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


struct pa{
	char id[10];
	int age;
	struct pa* next;
}*head,*p,*p2;

int main()
{
	int i,j,n,t;
	char tid[10];
	scanf("%d",&n);
	head=(struct pa*)malloc(sizeof(struct pa));
	p=(struct pa*)malloc(sizeof(struct pa));
	scanf("%s %d",p->id,&p->age);
	head->next=p;
	p->next=NULL;
	p2=p;
	for(i=1;i<n;i++)
	{
		p=(struct pa*)malloc(sizeof(struct pa));
		scanf("%s %d",p->id,&p->age);
		p2->next=p;
		p2=p;
		p2->next=NULL;
	}

//	for(p=head->next;p!=NULL;p=p->next)printf("%s\n",p->id);

	for(i=0;i<n;i++)				//???????????, ????GE?????
	{
		for(p=head->next;p->next!=NULL;p=p->next)
		{
			if(p->next->age>=60 && p->next->age>p->age)  //???????..?????????.
			{	t=p->age,p->age=p->next->age,p->next->age=t;
				strcpy(tid,p->id),strcpy(p->id,p->next->id),strcpy(p->next->id,tid);
			}
		}
	}

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

}


struct mouse
{
	char id[10];
	int age;
	struct mouse *next;
};
struct mouse *creat(int n)
{
	struct mouse *head,*p1,*p2;
	int i;
	for(i=0;i<n;i++)
	{
		if(i==1) head=p1;
		if(i>1) p2->next=p1;
		p2=p1;
		p1=(struct mouse *)malloc(sizeof(struct mouse));
		scanf("%s %d",p1->id,&p1->age);
	}
	p2->next=p1;p1->next=NULL;
	return(head);
}
struct mouse *order(struct mouse *head,int n)
{
	struct mouse *p1,*p2;
	int i,j,x;
	char a[10];
	for(i=1;i<n;i++)
	{
		p2=head;p1=p2->next;
		for(j=0;j<n-i;j++)
		{
			if(p2->age<p1->age&&p1->age>=60)
			{
				x=p2->age;p2->age=p1->age;p1->age=x;
				strcpy(a,p2->id);strcpy(p2->id,p1->id);strcpy(p1->id,a);
			}
			p2=p1;p1=p1->next;
		}
	}
	return(head);
}
main()
{
	struct mouse *head,*p;
	int i,n;
	scanf("%d",&n);
	head=creat(n);
	head=order(head,n);
	p=head;
	for(i=0;i<n;i++)
	{
		printf("%s\n",p->id);
		p=p->next;
	}
}


int main()
{
	struct data
	{
		int age;
		char id[10];
	}o[101],y[101],tmp;
	int no=0,ny=0;
	int i,j,n;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>tmp.id>>tmp.age;
		if(tmp.age>=60)
		{
			o[no]=tmp;
			no++;
		}
		else
		{
			y[ny]=tmp;
			ny++;
		}
	}
	for(i=no-1;i>0;i--)
	{
		for(j=0;j<i;j++)
		{
			if(o[j].age<o[j+1].age)
			{
				o[100]=o[j];
				o[j]=o[j+1];
				o[j+1]=o[100];
			}
		}
	}
	for(i=0;i<no;i++)
		cout<<o[i].id<<endl;
	for(i=0;i<ny;i++)
		cout<<y[i].id<<endl;
	return 0;
}


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

void main()
{
int n,i,j,max=59,m,t=0;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%s %d",pa[i].id,&pa[i].age);
for(i=0;i<n;i++)
if(pa[i].age>59)t++;
for(j=0;j<t;j++)
{
for(i=0;i<n;i++)
if(pa[i].age>max)
{
max=pa[i].age;
m=i;
}
printf("%s\n",pa[m].id);
pa[m].age=0;
max=59;
}

for(i=0;i<n;i++)
if(pa[i].age<=59&&pa[i].age!=0)
printf("%s\n",pa[i].id);
}


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


struct data
{
	char id[100];
	int age;
};

int main()
{

	struct data old[1000];
	struct data young[1000];
	struct data temp;
	int n,i,p=0,q=0,len1,len2,k;
	char id[100];
	int age;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s%d",id, &age);
		if(age>=60){
			old[p].age=age;
			strcpy(old[p].id,id);
			p++;
		}else{
			young[q].age=age;
			strcpy(young[q].id,id);
			q++;
		}
	}
	len1=p;
	len2=q;
	for(k=1;k<len1;k++){
		for(i=0;i<len1-k;i++){
			if(old[i].age<old[i+1].age){
				temp=old[i+1];
				old[i+1]=old[i];
				old[i]=temp;
			}
		}
	}
	for(i=0;i<len1;i++){
		printf("%s\n",old[i].id);
	}
	for(i=0;i<len2;i++){
		printf("%s\n",young[i].id);
	}
	return 0;
}


struct hospital
	{
		char ID[11];
		int age;
	}old[100],young[100],all[100],temp;
void sequence(struct hospital matrix[],int n)
{
	int i,j;
	for(i=0;i<n-1;i++)
	{
		for(j=0;j<n-1-i;j++)
		{
			if(matrix[j].age<matrix[j+1].age)
			{
				temp=matrix[j];
				matrix[j]=matrix[j+1];
				matrix[j+1]=temp;
			}
		}
	}
}

	/*
	??????????????????
	{
	int i,j,k;
	for(i=0;i<n-1;i++)
	{
		k=i;
		for(j=i+1;j<n;j++)
		{
			if(matrix[j].age>matrix[k].age)
			{
				k=j;
			}
		}
		if(k!=i)
		{
			temp=matrix[i];
			matrix[i]=matrix[k];
			matrix[k]=temp;
		}
	}
}
*/

int main()
{
	int n;
	scanf("%d",&n);
	int i;
	for(i=0;i<n;i++)
	{
		scanf("%s %d",all[i].ID,&all[i].age);
	}
	int oi=0,yi=0;
	for(i=0;i<n;i++)
	{
		if(all[i].age>=60)
		{
			old[oi]=all[i];
			oi++;
		}
		else
		{
			young[yi]=all[i];
			yi++;
		}
	}
	sequence(old,oi);
	for(i=0;i<oi;i++)
	{
		printf("%s\n",old[i].ID);
	}
	for(i=0;i<yi;i++)
	{
		printf("%s\n",young[i].ID);
	}
	return 0;
}


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

void find(struct pat *head,struct pat *s)
{
	struct pat *pre=head,*p=pre->next;
	while(p!=NULL&&s->age<=p->age)
	{
		pre=p;
		p=p->next;
	}
	pre->next=s;
	s->next=p;
}

void sort(struct pat *head,int x,char name[11])
{
	struct pat *pre=head,*p=pre->next,*s;
	s=(struct pat*)malloc(sizeof(struct pat));
	s->age=x;
	strcpy(s->id,name);
	s->next=NULL;
	if(x>=60) find(head,s);
	else
	{
		while(p!=NULL)
		{
		   pre=p;
		   p=p->next;
		}
	    pre->next=s;
	    s->next=p;
	}
}

int main()
{

	struct pat *head,*p;
	int n,x,i;
	char name[11];
	head=(struct pat*)malloc(sizeof(struct pat));
	head->next=NULL;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s%d",name,&x);
		sort(head,x,name);
	}
	p=head->next;
	while(p!=NULL)
	{
		printf("%s\n",p->id);
		p=p->next;
	}
	return 0;
}


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

int main(){
	int i,n,k,max,count;
	struct patient inter;
	struct patient *p;
	scanf("%d",&n);
	struct patient *sick=(struct patient*)malloc(sizeof(struct patient)*n);//??
	struct patient *waitlist=(struct patient*)malloc(sizeof(struct patient)*n);//??
	count=0;//????
	for(i=0;i<n;i++){
		scanf("%s %d",sick[i].A,&sick[i].age);
	}//??
	p=waitlist;
	for (i=0;i<n;i++)
	{
		if (sick[i].age>=60)
		{
			*p=sick[i];
			p++;
			count++;
		}
	}//????
	for (i=0;i<n;i++)
	{
		if (sick[i].age<60)
		{
			*p=sick[i];
			p++;
		}
	}//?????
	for (i=1;i<count;i++)
	{
		for (k=0;k<count-i;k++)
		{
			if (waitlist[k].age<waitlist[k+1].age)
			{
				inter=waitlist[k+1];
				waitlist[k+1]=waitlist[k];
				waitlist[k]=inter;
			}
		}
	}//????
	for (i=0;i<n;i++)
	{
		printf("%s\n",waitlist[i].A);
	}
	return 0;
}


int main()
{
	int n, i, j, temp, num1 = 0, num2 = 100, age[100], flag[100];
	char id[100][10], str[10];
	cin >> n;
	for (i = 0; i < n; i ++)
	{
		cin.get();
		cin >> id[i] >> age[i];
		if (age[i] < 60)
			flag[i] = num1 ++;
		else
			flag[i] = num2 ++;
	}
	for (i = 0; i < n - 1; i ++)
	{
		for (j = i + 1; j < n; j ++)
		{
			if (age[i] < age[j] && age[j] >= 60)
			{
				temp = flag[i];
				flag[i] = flag[j];
				flag[j] = temp;
				temp = age[i];
				age[i] = age[j];
				age[j] = temp;
				strcpy(str, id[i]);
				strcpy(id[i], id[j]);
				strcpy(id[j], str);
			}
		}
	}
	for (i = 0; i < n - 1; i ++)
	{
		for (j = i + 1; j < n; j ++)
		{
			if (age[i] == age[j] && age[i] >= 60 && age[j] >= 60 && flag[i] > flag[j] || age[i] < 60 && age[j] < 60 && flag[i] > flag[j])
			{
				temp = flag[i];
				flag[i] = flag[j];
				flag[j] = temp;
				temp = age[i];
				age[i] = age[j];
				age[j] = temp;
				strcpy(str, id[i]);
				strcpy(id[i], id[j]);
				strcpy(id[j], str);
			}
		}
	}
	for (i = 0; i < n; i ++)
		cout << id[i] << endl;
	return 0;
}


struct patient
{ char id[10];
  int year;
}pat[100];
int arrange(struct patient peop[],int num);

int main()
{
    int i,j=0,k,n,max;
    struct patient *ppat[100];
    scanf("%d",&n);
    for(i=0;i<n;i++)
                    scanf("%s%d",pat[i].id,&pat[i].year);
    for(i=0;i<n;i++){
                     if(pat[i].year>=60){
                                         ppat[j]=pat+i;j++;
                                         }
                     }

    struct patient *p;
    for(i=0;i<j-1;i++){
                      for(k=0;k<j-1-i;k++){
                                         if((*ppat[k]).year < (*ppat[k+1]).year){
                                                            p=ppat[k];
                                                            ppat[k]=ppat[k+1];
                                                            ppat[k+1]=p;
                                                            }
                                        }
                     }

    for(i=0;i<j;i++)
                    printf("%s\n",ppat[i]->id);
    for(i=0;i<n;i++){
                     if(pat[i].year<60)
                                       printf("%s\n",pat[i].id);
                     }
    return 0;
}


struct Info{
	char sID[10];
	int nAge;
};
void main(){
	int i,n,j,l;
	struct Info t;
	scanf("%d",&n);
	struct Info patients[100];
	struct Info overpatients[100];
	l=0;
	for (i=0;i<n;i++){
		scanf("%s%d",patients[i].sID,&patients[i].nAge);
		if (patients[i].nAge>=60){//?????60?????????
			overpatients[l]=patients[i];
			l++;
		}
	}
	for (i=0;i<l-1;i++)
		for (j=1;j<l-i;j++){
			if (overpatients[j-1].nAge<overpatients[j].nAge){
				t=overpatients[j-1];
				overpatients[j-1]=overpatients[j];
				overpatients[j]=t;
			}
		}
	for (i=0;i<l;i++){
		printf("%s\n",overpatients[i].sID);
	}
	for (i=0;i<n;i++)
		if (patients[i].nAge<60){
			printf("%s\n",patients[i].sID);
		}
}


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]))
              {
                  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);
              }
              else if (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<numj;i++)
//          for (j=i+1;j<=numj;j++)
//              if (strcmp(junior[i],junior[j])>0)
//              {
//                  year= ju[i]; ju[i]=ju[j]; ju[j]=year;
//                  strcpy(temp,junior[i]);
//                  strcpy(junior[i],junior[j]);
//                  strcpy(junior[j],temp);
//              }
      for (i=0;i<=nums;i++)
      {
          //printf("%d ",list[i]);
          puts(senior[i]);
      }
      for (i=0;i<=numj;i++)
          puts(junior[i]);
      return 0;
}


struct patient
{
	char ID[11];
	int age;
	struct patient *next;
}
main()
{
	int i,n;
	struct patient *old,*young,*ot,*yt,*p;
	struct patient *paixu(struct patient* h);
	scanf("%d", &n);
	ot=NULL;
	yt=NULL;
	for(i=0;i<n;i++)
	{
		p=(struct patient *)malloc(len);
		scanf("%s %d",p->ID,&p->age);
		p->next=NULL;
		if (p->age<60)
		{
			if (yt)
				yt->next=p;
			else
				young=p;
			yt=p;
		}
		else
		{
			if(ot)
				ot->next=p;
			else
				old=p;
			ot=p;
		}
	}
	old=paixu(old);
	while(old)
	{
		printf("%s\n",old->ID);
		old=old->next;
	}
	while(young)
	{
		printf("%s\n",young->ID);
		young=young->next;
	}
}
struct patient *paixu(struct patient* h)
{
	struct patient* hh=h,*before,*after;
	h=h->next;
	hh->next=NULL;
	while(h)
	{
		before=hh;
		if(before->age<h->age)
		{
			hh=h;
			after=h->next;
			h->next=before;
			h=after;
		}
		else
		{
			while (before->next)
			{
				if(before->next->age>=h->age)
					before=before->next;
				else
					break;
			}
			after=h->next;
			h->next=before->next;
			before->next=h;
			h=after;
		}
	}
	return hh;
}


int main()
{
    int renshu,nianling[1000][2],bijiao[1000][2];
    char id[1000][1000];

    scanf("%d",&renshu);

    int i,j,k;
    j=0;
    k=0;
    for(i=0;i<renshu;i++)
   {
    scanf("%s%d",id[i],&nianling[i][0]);
    }

    for(i=0;i<renshu;i++)
    {
        if(nianling[i][0]<60);
        else
        {
        nianling[i][1]=i;
        bijiao[k][0]=nianling[i][0];
        bijiao[k][1]=i;
        k++;
        }
    }

   int zhongjian[2],l;
   l=k;
   bijiao[l][0]=10000;

    for(i=0;i<l;i++)
    {
       for(j=0;j<l;j++)
       {
           if(bijiao[j][0]>bijiao[j+1][0])
           {
              zhongjian[0]=bijiao[j+1][0];
              zhongjian[1]=bijiao[j+1][1];
              bijiao[j+1][0]=bijiao[j][0];
              bijiao[j+1][1]=bijiao[j][1];
              bijiao[j][0]=zhongjian[0];
              bijiao[j][1]=zhongjian[1];
           }
           else if(bijiao[j][0]==bijiao[j+1][0]&&bijiao[j][1]<bijiao[j+1][1])
           {
              zhongjian[0]=bijiao[j+1][0];
              zhongjian[1]=bijiao[j+1][1];
              bijiao[j+1][0]=bijiao[j][0];
              bijiao[j+1][1]=bijiao[j][1];
              bijiao[j][0]=zhongjian[0];
              bijiao[j][1]=zhongjian[1];
           }
           else;
       }
    }

      for(i=0;i<l;i++)
    {
       for(j=0;j<renshu;j++)
       {
          if(bijiao[l-1-i][0]==nianling[j][0]&&bijiao[l-i-1][1]==nianling[j][1])
          printf("%s\n",id[j]);
          else;
       }
    }

       for(j=0;j<renshu;j++)
       {
          if(nianling[j][0]<60)
          printf("%s\n",id[j]);
          else;
       }

    getchar();
    getchar();
}


struct patient
{
	char ID[15];
	int age;
	struct patient *next;
};
int n;
struct patient *create()
{
	struct patient *head,*p1,*p2;
	p1=(struct patient*)malloc(LEN);
	scanf("%s %d",p1->ID,&p1->age);
	head=p1;
	p2=p1;
	p1->next=NULL;
	int i=1;
	do
	{
		if(i==n)break;
        p1=(struct patient*)malloc(LEN);
	    scanf("%s %d",p1->ID,&p1->age);
		p2->next=p1;
		p2=p1;
		p1->next=NULL;
		i++;
	}while(1);
	return(head);
}
struct patient *findmax(struct patient *head)
{
    struct patient *max;

	struct patient *p;
	max = head;
	p=head->next;
	while(p)
	{
		if(p->age>max->age)
			max=p;
		p=p->next;
	}
	return(max);
}
struct patient *del(struct patient *head,struct patient *needdel)
{
	struct patient *p,*ppre;
	printf("%s\n",needdel->ID);
	p=head;
	while(p&&needdel!=p)
	{ppre=p;
	p=p->next;}
	if(p==head)
	{
		head=p->next;
		free(p);
	}
	else if (p)
	{
		ppre->next=p->next;
		free(p);
	}

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

	scanf("%d",&n);
	struct patient *head,*p;
	head=create();
	p = head;

	do
	{
		p = findmax(head);
		if(p->age<60)break;
		head=del(head,p);

	}while(1);
	print(head);
}


main()
{
      int n;
      int amount_lao=0,amount_yiban=0;
      char c[11];
      int shuru;
      int i,j,k,s,p;
      struct xinxi
      {
             char id[11];
             int age;
      };
      struct xinxi laoren[100];
      struct xinxi common[100];
      struct xinxi temp;
      scanf("%d",&n);
      for(p=0;p<n;p++)
      {
          scanf("%s %d",c,&shuru);
          if(shuru<60)
          {
              strcpy(common[amount_yiban].id,c);
              common[amount_yiban].age=shuru;
              amount_yiban++;
          }
          else if(shuru>=60)
          {
              strcpy(laoren[amount_lao].id,c);
              laoren[amount_lao].age=shuru;
              amount_lao++;
          }
      }
      for(i=0;i<amount_lao-1;i++)
      {
           for(j=0;j<amount_lao-i-1;j++)
           {
               if(laoren[j].age<laoren[j+1].age)
               {
                    strcpy(temp.id,laoren[j].id);
                    temp.age=laoren[j].age;
                    strcpy(laoren[j].id,laoren[j+1].id);
                    laoren[j].age=laoren[j+1].age;
                    strcpy(laoren[j+1].id,temp.id);
                    laoren[j+1].age=temp.age;
               }
           }
      }
      for(k=0;k<amount_lao;k++)
      {
          puts(laoren[k].id);
          printf("\n");
      }
      for(s=0;s<amount_yiban;s++)
      {
          puts(common[s].id);
          printf("\n");
      }
      getchar();
      getchar();
}


struct sick
{
	char *num;
    int age;
	struct sick *next;
};
struct sick *range(int N)
{
	struct sick *pnew,*ppre,*p,*head,*last;
	pnew=(struct sick *)malloc(len);
	pnew->num=(char *)malloc(100*sizeof(char));
	pnew->next=NULL;
	scanf("%s %d",pnew->num,&pnew->age);
	head=last=pnew;
	int i;
	for(i=2;i<=N;i++)
	{
		pnew=(struct sick *)malloc(len);
	    pnew->num=(char *)malloc(100*sizeof(char));
	    pnew->next=NULL;
		scanf("%s %d",pnew->num,&pnew->age);
		int j;
		if (pnew->age<60)
		{
			last->next=pnew;
			last=pnew;
		}
		else
		{
			if(pnew->age>head->age)
			{
				pnew->next=head;
				head=pnew;
			}
			else
			{
				ppre=head;
				p=head->next;
				for(j=2;p!=NULL;j++)
				{
					if(pnew->age>p->age)
					{
						ppre->next=pnew;
						pnew->next=p;
						break;
					}
					else
					{
						ppre=ppre->next;
						p=p->next;
					}
				}
			}
			if(pnew->next==NULL)
			{
				last->next=pnew;
				last=pnew;
			}
		}
	}
	return(head);
}
void print(struct sick *head,int N)
{
	struct sick *p=head;
	int i;
	for(i=1;i<=N;i++)
	{
		printf("%s\n",p->num);
		p=p->next;
	}
}

void main()
{
	int N;
	scanf("%d",&N);
	struct sick *head=range(N);
	print(head,N);
}


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


long exp(int a)
{
      int def1,expo=1;
      for(def1=1;def1<=a;def1++)
      expo=expo*10;
      return expo;
}
main()
{
      int n,i,j,comp,idlenth,sw=0,test=0,advnum=0,arradv=1,arrdis,cache;
      int bubble,maxage,maxid,maxnum,maxright,print;
      scanf("%d",&n);
      int age[n+1],adv[n+1],ord[n+1],alrscan[n+1],numord[n+1],right[n+1];
      getchar();
      long id[n+1];
      for(i=1;i<=n;i++)
      {
            ord[i]=numord[i]=i;
            alrscan[i]=0;
            right[i]=0;
      }
      for(i=1;i<=n;i++)
      scanf("%d %d",&id[i],&age[i]);
      for(i=1;i<=n;i++)
      {
                       if(age[i]>=60)
                       {
                              adv[i]=1;
                              right[i]+=age[i]*1000;
                              right[i]+=1000000;
                              advnum++;
                       }
                       else
                       adv[i]=0;
      }
      for(i=1;i<=n;i++)
      {

                       right[i]+=n-i+1;
                       alrscan[i]=0;
      }
      for(i=1;i<=n;i++)
      {
                       maxright=0;
                       for(j=1;j<=n;j++)
                       {
                                 if(right[j]>maxright&&alrscan[j]==0)
                                 {maxright=right[j];
                                 maxnum=j;}
                       }
                       ord[i]=maxnum;
                       alrscan[maxnum]=1;
      }
      for(idlenth=1;test!=n;idlenth++)
      {
                      test=0;
                      for(j=1;j<=n;j++)
                      if(id[j]<exp(idlenth-1))
                      test++;
      }
      idlenth--;
      for(i=1;i<=n;i++)
      {
                       for(j=1;j<=idlenth;j++)
                       {

                               if(id[ord[i]]<exp(idlenth-j-1))
                               printf("0");
                       }
                       printf("%d\n",id[ord[i]]);
                       //printf("%d %d %d\n",id[ord[i]],numord[ord[i]],right[ord[i]]);
      }
      /*arrdis=advnum+1;
      for(i=1;i<=n;i++)
      {
                       if(adv[i]==1)
                       {
                                ord[arradv]=i;
                                arradv++;
                       }
                       else
                       {
                                ord[arrdis]=i;
                                arrdis++;
                       }
      }
      //printf("adv=%d,dis=%d",arradv,arrdis);
      for(bubble=advnum;bubble>=1;bubble--);
      {
            for(i=1;i<bubble;i++)
            {
                       if(age[ord[i+1]]>age[ord[i]])
                       {
                                cache=ord[i+1];
                                ord[i+1]=ord[i];
                                ord[i]=cache;
                       }
            }
      }
      for(bubble=n;bubble>=advnum+1;bubble--);
      {
            for(i=advnum+1;i<bubble;i++)
            {
                       if(id[ord[i+1]]>id[ord[i]])
                       {
                                cache=ord[i+1];
                                ord[i+1]=ord[i];
                                ord[i]=cache;
                       }
            }
      }
      for(idlenth=1;test!=n;idlenth++)
      {
                      test=0;
                      for(j=1;j<=n;j++)
                      if(id[j]<exp(idlenth-1))
                      test++;
      }
      idlenth--;
      for(i=1;i<=n;i++)
      {
                       for(j=1;j<=idlenth;j++)
                       {

                               if(id[ord[i]]<exp(idlenth-j-1))
                               printf("0");
                       }
                       printf("%d\n",id[ord[i]]);
      }*/
      getchar();
      getchar();
      return 0;
}


struct rat
{
	char num[11];
	int age;
	struct rat *next;
};

int n;

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

struct rat *sort(struct rat *head,int count)
{
	struct rat *p1,*p2,*p3,*temp;
	int i,j;
	for(j=1;j<=count-1;j++)
	{
		p1=head;
		p2=p1->next;
		p3=p2;
		for(i=0;i<count-j;i++)
		{
			if(p1->age<p2->age)
			{
				temp=p2->next;
				p2->next=p1;
				p1->next=temp;
				if(i==0)
				{
					head=p2;
					p2=temp;
				}
				else
				{
					p3->next=p2;
					p3=p2;
					p2=temp;
				}
			}
			else
			{
				if(i==0)
				{
					p3=head=p1;
					p1=p1->next;
					p2=p2->next;
				}
				else
				{
					p1=p1->next;
					p2=p2->next;
					p3=p3->next;
				}
			}
		}
	}
	return(head);
}

struct rat *del(struct rat *head,int t)
{
	struct rat *p1,*p2;
	int i;
	p1=head;
	for(i=1;i<=t;i++)
	{
		if(p1->age<60)
		{
			if(i==1)
				head=p1;
			p2=p1;
			p1=p1->next;
			continue;
		}
		if(p1->age>=60)
		{
			if(i==1)
			{
				head=p1->next;
				break;
			}
			p2->next=p1->next;
			break;
		}
	}
	return(head);
}

void main()
{
	struct rat *head,*p1,*s,*p2,*p3;
	int i,count=0,t;
	scanf("%d",&n);
	t=n;
	head=creat();
	p1=head;
	p3=p2=(struct rat*)malloc(LEN);
	for(i=1;i<=n;i++)
	{
		if(p1->age>=60)
		{
			if(count==0)
				s=p2;
			p2->age=p1->age;
			strcpy(p2->num,p1->num);
			p3->next=p2;
			p3=p2;
			p2=(struct rat*)malloc(LEN);
			count++;
		}
		p1=p1->next;
	}
	s=sort(s,count);
	for(i=1;i<=count;i++)
	{
		head=del(head,t);
		t=t-1;
	}
	p1=s;
	for(i=1;i<=count;i++)
	{
		printf("%s\n",p1->num);
		p1=p1->next;
	}
	p1=head;
	for(i=1;i<=(n-count);i++)
	{
		printf("%s\n",p1->num);
		p1=p1->next;
	}
}


struct Student
{
    char id[10];
    int age;
}ill[100];

int main()
{
    int i,j,n,q;
    char p[10];
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%s%d",&ill[i].id,&ill[i].age);

    for(j=0;j<n-1;j++)
        for(i=n-1;i>j;i--){
            if(ill[i].age>=60&&ill[i].age>ill[i-1].age){
                strcpy(p,ill[i].id);        q=ill[i].age;
                strcpy(ill[i].id,ill[i-1].id);  ill[i].age=ill[i-1].age;
                strcpy(ill[i-1].id,p);      ill[i-1].age=q;
            }
        }
    for(i=0;i<n;i++)
        printf("%s\n",ill[i].id);
}


typedef struct data *pdata;

struct data
{
	char a[20];
	int b;
	pdata next;
};

pdata sort(int n)
{
pdata p=NULL,q=NULL,s=NULL,head=NULL;
head=(pdata)malloc(sizeof(struct data));
head->next=NULL;
int i;
for (i=0;i<n;i++)
{
s=(pdata)malloc(sizeof(struct data));
scanf("%s %d",s->a,&(s->b));
if(s->b>=60)
{
	q=head;
	p=head->next;
	while (p)
	{
		if(p->b<s->b) break;
		q=q->next;
		p=p->next;
	}
	q->next=s;
	s->next=p;
}
else
{
	q=head;
	p=head->next;
	while(p)
	{
		q=q->next;
		p=p->next;
	}
	q->next=s;
	s->next=NULL;
}
}

return head;
}

int main()
{
	int n,i;
	pdata p,head;
	scanf("%d",&n);
	head=sort(n);
	p=head->next;
	for(i=0;i<n;i++)
	{
		printf("%s\n",p->a);
		p=p->next;
	}
}


struct patient
{
	char a[100];
	int age;
}pat[110],pat1[110];

void bubble(int n)
{
	int i,j;
	struct patient temp;
	for(i=1;i<n;i++)
	{
		for(j=0;j<n-i;j++)
		{
			if(pat1[j].age<pat1[j+1].age)
			{
				temp=pat1[j];
				pat1[j]=pat1[j+1];
				pat1[j+1]=temp;
			}
		}
	}
}

void main()
{
	int n,i,k=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s %d",pat[i].a,&pat[i].age);
		if(pat[i].age>=60)
			pat1[k++]=pat[i];
	}
	bubble(k);
	for(i=0;i<k;i++)
		printf("%s\n",pat1[i].a);
	for(i=0;i<n;i++)
	{
		if(pat[i].age<60)
			printf("%s\n",pat[i].a);
	}
}


int main(){
    struct patient {
    char id[11];
    int age;
    }*p,*p60_up,*p60_low,t;

    int n,i,j,k=0;
    scanf ("%d",&n);
    p = (struct patient *) malloc( sizeof(struct patient) * n );

    for(i=0;i<n;i++){
        scanf("%s",&(p[i].id));
        scanf("%d",&(p[i].age));
    }
    for(i=0;i<=n;i++){
        if(p[i].age>=60){
        k++;
        }
    }
    p60_up = (struct patient *) malloc( sizeof(struct patient) * k );
    p60_low= (struct patient *) malloc( sizeof(struct patient) * (n-k) );

    for(i=0,j=0;i<n;i++){
        if(p[i].age>=60){
           p60_up[j]=p[i];
           j++;
        }
    }for(i=0,j=0;i<n;i++){
        if(p[i].age<60){
           p60_low[j]=p[i];
           j++;
        }
    }
  for( j = 1 ; j <= k ; j++){
       for( i = 0; i < k - j; i++){
            if(p60_up[i].age<p60_up[i+1].age){
                t = p60_up[i+1];
			    p60_up[i+1] = p60_up[i];
			    p60_up[i] = t;
            }
       }
   }

    for(i=0;i<k;i++){
        puts(p60_up[i].id);
    }
    free(p60_up);
    for(i=0;i<n-k;i++){
        puts(p60_low[i].id);
    }
    free(p60_low);

	return 0;
}


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

					strcpy(p,a[i-k].id);
					strcpy(a[i-k].id,a[i-k-1].id);
					strcpy(a[i-k-1].id,p);
				}
			}
		}
	}
	for(i=0;i<n;i++){
		printf("%s\n",a[i].id);
	}
	return 0;
}


struct student
{
	char num[10];
	int o;
	struct student *next;
};

struct student *create(int n)
{
	struct student *head,*p1,*p2;
	int i;
	int scholar(struct student *p);

	p1=(struct student*)malloc(len);
	scanf("%s %d",p1->num,&p1->o);
	p1->next=NULL;

	head=p1;
	p2=p1;
	for(i=1;i<=n-1;i++)
	{
		p1=(struct student*)malloc(len);
		scanf("%s %d",p1->num,&p1->o);
		p1->next=NULL;
		p2->next=p1;
		p2=p1;
	}
	return head;
}

struct student *max(struct student *head)
{
	struct student *p,*m;
	m=head;
	p=head->next;
	while(p)
	{
		if(p->o>m->o) m=p;
		p=p->next;
	}
	return m;
}

void main()
{
	int n;
	struct student *head,*m,*p;
	struct student *create(int n);
	struct student *max(struct student *head);
	scanf("%d",&n);
	head=create(n);
	p=head;
	for(;;)
	{
		m=max(p);
		if(m->o>=60)
		{
			printf("%s\n",m->num);
			m->o=-1;
		}
		else break;
	}
	p=head;
	while(p)
	{
		if(p->o!=-1) printf("%s\n",p->num);
		p=p->next;
	}
}


int main(){
	int n,i,j,t;
	struct ill{
		char num[10];
		int age,id;
	}man[N],ex;
    scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s%d",man[i].num,&man[i].age);
		man[i].id=i;
	}
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if(man[i].age<man[j].age)
			{
				ex=man[i];
			    man[i]=man[j];
				man[j]=ex;
			}
		}
	}
	for(i=0;i<n;i++)
	{
		if(man[i].age<60)
		{
			t=i;
			break;
		}
	}
	for(i=0;i<t;i++)
	{
		for(j=i+1;j<t;j++)
		{
			if(man[i].age==man[j].age&&man[i].id>man[j].id)
			{
				ex=man[i];
			    man[i]=man[j];
				man[j]=ex;
			}
		}
	}
	for(i=t;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if(man[i].id>man[j].id)
			{
				ex=man[i];
			    man[i]=man[j];
				man[j]=ex;
			}
		}
	}
  	for(i=0;i<n;i++)
	{
        printf("%s\n",man[i].num);
	}
	for(i=0;i<n;i++);
	return 0;
}


void main()
{
	int n;
	int i;
	int j;
	struct client
	{
		char num[11];
		int age;
	};
	struct client line[100];
	struct client temp;

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

	for(i=0;i<n-1;i++)
		for(j=0;j<n-1;j++)
		{
			if(line[j].age>=60&&line[j+1].age>=60)
			{
				if(line[j].age<line[j+1].age)
				{
					temp=line[j];
					line[j]=line[j+1];
					line[j+1]=temp;
				}
			}
			if(line[j].age<60 && line[j+1].age>=60)
				{
					temp=line[j];
					line[j]=line[j+1];
					line[j+1]=temp;
				}
		}
	for(i=0;i<n;i++)
		printf("%s\n",line[i].num);

}


struct pa{
	char name[10];
	int age;
	struct pa *next;
};

void sort(struct pa *head,struct pa *s)
{
	struct pa *p1,*p2;
	p1=head->next;
	p2=head;
	while(p1&&p1->age>=s->age)
	{
		p2=p1;
		p1=p1->next;
	}
	p2->next=s;
	s->next=p1;
}

void creat(struct pa *head,struct pa *s)
{
	struct pa *p2,*p1;
	p1=head->next;
	p2=head;
	while(p1)
	{
		p2=p1;
		p1=p1->next;
	}
	p2->next=s;
	s->next=p1;
}

struct pa * input()
{
	int i,n;
	struct pa *s,*head1,*head2,*p1,*p2;
	head1=(struct pa *)malloc(len);
	head2=(struct pa *)malloc(len);
	head1->next=NULL;
	head2->next=NULL;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
        s=(struct pa *)malloc(len);
		scanf("%s%d",s->name,&s->age);
		if(s->age>=60) sort(head1,s);
		else creat(head2,s);
     }
	p1=head1->next;
	p2=head1;
	while(p1)
	{
		p2=p1;
		p1=p1->next;
	}
	p2->next=head2->next;
	return(head1);
}

void print(struct pa *head)
{
	struct pa *p;
	p=head->next;
	while(p)
	{
		printf("%s\n",p->name);
		p=p->next;
	}
}

void main()
{
	struct pa *head;
	head=input();
	print(head);
}


int main()
{
	int *p,*num;
	int n,add;

	scanf ("%d",&n);
	p=(int*)malloc(sizeof (int)*n);
	num=(int*)malloc(sizeof (int)*n);

	for (int i=0;i<=n-1;i++)
	{
		scanf ("%d",p+i);
		*(num+i)=1;
	}

	for (int i=n-2;i>=0;i--)
	{
		add=0;
		for (int k=i+1;k<=n-1;k++)
		{
			if (*(p+i)>=*(p+k)&&*(num+k)>add)
				add=*(num+k);
			//printf ("%d",*(num+k));
			//printf ("%d",add);
		}
		*(num+i)+=add;
	}
	int maxnum=0;
	for (int i=0;i<=n-1;i++)
	{
		if (*(num+i)>maxnum)
			maxnum=*(num+i);
		//printf ("%d",*(num+i));
	}
	printf ("%d",maxnum);

	return 0;
}


int main()
{
	int height[50],flag[50],max,i,j;
	int num ;

	scanf("%d",&num);

	for (i = 0; i < num; i ++)
	{
		scanf("%d",&height[i]);
		flag[i] = 1;
	}
	for (i = 0; i < num; i ++)
	{
		for (j = 0; j < i; j ++)
		{
			if (height[j] >= height[i])
			{
				if (flag[j] + 1 > flag[i])
					flag[i] = flag[j] + 1;
			}
		}
	}

	max = flag[0];
	for (i = 1; i < num; i ++)
	{
		if (flag[i] > max)
			max = flag[i];
	}
	printf("%d\n",max);
	return 0;
}


int h[25],n;
int main()
{
int max(int a,int b);
int k,i;
scanf("%d",&n);
for(i=0;i<n;i++) scanf("%d",&h[i]);
k=max(50000,0);
printf("%d",k);
return 0;
}
int max(int hmax,int b)
{
int x,y,z;
while(h[b]>hmax) b=b+1;
if(b==n)return 0;
x=max(hmax,b+1);
hmax=h[b];
y=1+max(hmax,b+1);
z=x>y?x:y;
return z;
}


int daodan[30];
int res[30];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>daodan[i];
		res[i]=1;
	}
	for(int i=n-1;i>=0;i--)
	{
		for(int j=n-1;j>i;j--)
		{
             if(daodan[i]>=daodan[j])
				 res[i]=max(res[i],res[j]+1);
		}
	}
	for(int i=0;i<n;i++)
	{
		if(res[i]>res[0])
		res[0]=res[i];

	}
	cout<<res[0]<<endl;
	return 0;
}


int main()
{
	int k;
	cin>>k;
	int high[30];
	int num[30]={0};
	int i,j;
	for(i=0;i<k;i++)
	{
		cin>>high[i];
	}
	num[0]=1;
	for(i=1;i<k;i++)
	{
		int max=0;
		for(j=i-1;j>=0;j--)
		{
			if(high[i]<=high[j])
			{
				if(max<num[j])
					max=num[j];
			}
		}
		num[i]=max+1;
	}
	sort(num,num+k);
	printf("%d",num[k-1]);
	return 0;
}


int k[25],n;
int f(int max,int i,int sum)
{
	int p,q=0;
	if(i==n)return sum;
	else
	{
		p=f(max,i+1,sum);
		if(max>=k[i])q=f(k[i],i+1,sum+1);
		return p>q?p:q;
	}
}
void main()
{
	int i;scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&k[i]);
	printf("%d",f(2147483647,0,0));
}


int main()
{
	int f(int x,int y,int b[]);
	int i,k,a[30],max;
	scanf("%d",&k);
	for(i=0;i<k;i++)
		scanf("%d",&a[i]);
	for(i=0,max=0;i<k;i++)
	{
		if(f(i,k,a)>=max)
			max=f(i,k,a);
	}
	printf("%d\n",max);
	return 0;
}
int f(int x,int y,int b[])
{
	int z,i,p,m;
	for(i=x+1,p=0;i<y;i++)
	{
		if(b[i]<=b[x])         //only compare with b[x]
			p++;
	}
	if(p==0)
	{
		z=1;
	}
	else
	{
		for(i=x+1,m=0;i<y;i++)
		{
			if(b[i]<=b[x])
			{
				if(m<=f(i,y,b))
					m=f(i,y,b);      // after m there are f nums<b[i]
			}
		}
		z=m+1;
	}
	return z;
}


int max(int* data,int lens)
{
    int r=*data;
    for(int j=0;j<lens;j++)if(*(data+j)>r)r=*(data+j);
    return r;
}
int f(int* data,int lens,int height)
{
    int tempResult[25];
    if(lens==0)return 0;
    int count=0,tempHeight=0;
    for(int i=0;i<lens;i++)
    {
                       if(data[i]<=height && data[i]>=tempHeight)
                       {tempHeight=data[i];tempResult[count]=f(data+i+1,lens-i-1,data[i]);count++;}

    }
    if(count==0)return 0;
    return max(tempResult,count)+1;
}

int main()
{
    int data[25];
    int n;
    cin>>n;
    for(int i=0;i<n;i++)cin>>data[i];
    cout<<f(data,n,max(data,n));

                 return 0;
}


int main()
{
	int i,j,k,x[30],f[30],temp,max;
	cin >> k;
	for (i=0;i<k;i++)
		cin >> x[i];
	f[0]=1;
	for(i=1;i<k;i++)
	{
		max=1;
		for(j=0;j<i;j++)
		{
			temp =0;
			if(x[i]<=x[j])
				temp = f[j]+1;
			if(temp > max)
				max=temp;
		}
		f[i]=max;
	}
	max=1;
	for(i=0;i<k;i++)
	{
		if(f[i]>max)
			max=f[i];
	}
	cout << max << endl;
	return 0;
}


struct missle
{
	int id;
	int h;
}*p,tmp;
int max = 0;

int maxn(int i ,int n);
int pass (int pre,int aft);

int main()
{
	int k;
	scanf("%d",&k);
	p = (struct missle * ) malloc ( sizeof ( struct missle ) * k );
	int i = 0;
	do
	{
		scanf("%d",&p[i].h);
		p[i].id = i;
		i++;
	}while ( i < k );
	int j;
	for ( i = 0 ; i < k ; i++ )
	{
		j = maxn(i,k);
	}

	printf("%d\n",max);
	free(p);

	return 0;
}

int maxn ( int i , int n )
{
	int max2 = 1;
	int re=1;
	int j;
	if ( i == n - 1 )
	{
		max2 = 1;
	}
	else
	{
		for ( j = i + 1 ; j < n ; j++ )
		{
			re = 1;
			if ( pass ( i , j ) == 1 )
			{
				re +=  maxn(j,n);
				if ( re > max2 )
				{
					max2 = re;
				}
			}
		}
	}
	if ( max2 > max )
	{
		max = max2;
		//printf("%d\n",i);
	}
	return max2;
}

int pass (int pre,int aft)
{
	if (p[pre].h >= p[aft].h)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}


int rec[26];
int k,sum,i,j;
int n[26];
int max(int a,int b)
{
    if (a>b) return(a);
    else return(b);
}
main()
{
    scanf("%d",&k);
    for(i=1;i<=k;i++) scanf("%d",&rec[i]);
    for(i=1;i<=k;i++) n[i]=1;
    for (i=2;i<=k;i++)
        for(j=1;j<i;j++) if (rec[i]<=rec[j]) n[i]=max(n[i],n[j]+1);
    sum=0;
    for(i=1;i<=k;i++) sum=max(sum,n[i]);
    printf("%d",sum);
}


int main()
{
    int missile[25],k;
    int max[25],max1;
    int i,j;
    scanf("%d",&k);
    max[k-1]=1;
    for(i=0;i<k;i++)
        scanf("%d",&missile[i]);
    for(i=k-2;i>=0;i--)
       {
        max[i]=1;
        for(j=i+1;j<k;j++)
            if(missile[i]>=missile[j]&&max[i]<=max[j])
               max[i]=max[j]+1;
       }
    for(i=0,max1=0;i<k;i++)
        if(max[i]>max1)
           max1=max[i];
    printf("%d",max1);
    return 1;
}


main()
{
	int n,i,j,max,m,k;
	scanf("%d",&n);
	static int hight[25],num[25];
	for(i=0;i<=n-1;i++)  scanf("%d",&hight[i]);
    num[0]=1;
	for(i=1;i<=n-1;i++)
	{
		for(j=i-1;j>=0;j--)
		{
			m=0;
			if(hight[j]>=hight[i])
			{
				m=num[j];
				break;
			}
		}
        if(j==-1) num[i]=1;
		for(k=j-1;k>=0;k--)
		{
			if(hight[k]>=hight[i])
			{
				if(num[k]>m) m=num[k];
			}
		}
		if(num[i]==0) num[i]=m+1;
	}
	max=num[n-1];
	for(i=n-2;i>=0;i--)
	{
		if(num[i]>max) max=num[i];
	}
	printf("%d\n",max);
	return 0;
}


int main()
{
	int N;
	int a[30]={0},f[30]={0};
	cin >> N;
	for (int i=0; i< N ; i++)
	{
		cin >> a[i];
		f[i]=1;
	}
	int ans = 0;
	for (int i=1; i<N;i++)
	{
		int mx=0;
		for (int j=0;j<i;j++)
			if (a[j]>=a[i] && f[j]>mx)
				mx = f[j];
		f[i]= mx+1;
		if (ans < f[i]) ans = f[i];
	}
	cout << ans << endl;
	return 0;
}


int a[25],b[25];
int n;
int changdu(int i)
{
    int j,max=1;
    for(j=i+1;j<n;j++)
    {
                      if(a[i]>=a[j])
                      {
                                    b[i]=changdu(j)+1;
                                    if(b[i]>max)
                                    max=b[i];
                                    }
                                    }
    b[i]=max;
    return max;

}
main()
{
      int max=0,i;
      scanf("%d",&n);
      for(i=0;i<n;i++)
      scanf("%d",&a[i]);
      for(i=0;i<n;i++)
      b[i]=changdu(i);
      for(i=0;i<n;i++)
      {
                      if(b[i]>max)
                      max=b[i];
                      }
      printf("%d",max);

      }


typedef struct
{
	int file;
	int reign;
}missile;
void main()
{
	int n,i,j,max=0;
	missile a[30];
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i].file);
	}
	a[n].reign=1;
	for(i=n-1;i>=1;i--)
	{
		a[i].reign=1;
		for(j=i+1;j<=n;j++)
		{
			if(a[j].file<=a[i].file)
			{
				if(a[j].reign+1>a[i].reign)
				{
					a[i].reign=a[j].reign+1;
				}
			}
		}
	}
	for(i=1;i<=n;i++)
	{
		if(a[i].reign>max)
		{
			max=a[i].reign;
		}
	}
	printf("%d",max);
}


int a[26];
int main()
{
    int d(int xz,int p,int q);
    int y,i,n;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
      scanf("%d",&a[i]);
    }
    y=d(10000,1,n);
    printf("%d",y);
}
int d(int xz,int p,int q)
{
    int g,h;
    if (p==q&&a[p]<=xz) return 1;
    else if(p==q&&a[p]>xz) return 0;
    else
    {
         if(xz<a[p]) return(d(xz,p+1,q));
         else
         {
         g=1+d(a[p],p+1,q);
         h=d(xz,p+1,q);
         if(g>h) return(g);
         else return(h);
         }
    }
}


void main()
{
  int n;
  int arr[103],brr[103];
  int i,j,k,max;
  scanf("%d\n",&n);
  for (i=1;i<=n;i++) scanf("%d",&arr[i]);
  for (i=1;i<=n;i++) brr[i]=0;
  max=0;
  for (i=n;i>=1;i--)
  {
    k=0;
    for (j=n;j>i;j--)
    {if ((arr[j]<=arr[i])&&(brr[j]>k)) k=brr[j];}
    brr[i]=k+1;
    if (brr[i]>max) max=brr[i];
  }
  printf("%d\n",max);
}


int k,height[25];
int route(int m)
{
	int i,a=0,max=0;
	for(i=m+1;i<k;i++)
		if(height[i]<=height[m])
			a+=1;
	if(a==0)
	    return 1;
	else
	{
		for(i=m+1;i<k;i++)
			if(height[i]<=height[m]&&route(i)>max)
				max=route(i);
		return (max+1);
	}
}
int main()
{
	int i,ans[25],a=0;
	scanf("%d",&k);
	for(i=0;i<k;i++)
		scanf("%d",&height[i]);
	for(i=0;i<k;i++)
		ans[i]=route(i);
	for(i=0;i<k;i++)
		if(ans[i]>a)
			a=ans[i];
	printf("%d\n",a);
}


// itc online practice nov 13 prob 6
int k;
int height[26];
int len(int num) {
    int temp,max,i;
    if (num==k) {
                return(1);
    } else {
            max=0;
            for (i=num+1;i<=k;i++) {
                if (height[num]>=height[i]) {
                                            temp=len(i);
                                            if (max<temp) {
                                                          max=temp;
                                            }
                }
            }
    }
    return(max+1);
}
main() {
       height[0]=30001;
       scanf("%d",&k);
       int i;
       for (i=1;i<=k;i++) {
           scanf("%d",&height[i]);
       }
       printf("%d",len(0)-1);
       scanf("%d",&k);
}