void input(int *p1, int *p2, int **pA, int **pB)
{
int i;
scanf("%d %d", p1, p2);
*pA=(int*)malloc((*p1)*sizeof(int));
*pB=(int*)malloc((*p2)*sizeof(int));
 for (i=0; i<*p1; i++)
scanf("%d", *pA+i);
 for (i=0; i<*p2; i++)
scanf("%d", *pB+i);
}
void sort(int p, int *pX)
{
 int i, j, temp;
 for (i=0; i<p; i++)
 {
  for (j=p-1; j>i; j--)
  {
   if (pX[j]<pX[j-1])
   {
    temp=pX[j];
    pX[j]=pX[j-1];
    pX[j-1]=temp;
   }
  }
 }
}
void combine(int p1, int p2, int *pA, int *pB, int **pC)
{
 *pC=(int*)malloc((p1+p2)*sizeof(int));
 int i;
 for (i=0; i<p1; i++)
     (*pC)[i]=pA[i];
 for (i=0; i<p2; i++)
     (*pC)[p1+i]=pB[i];
 free(pA);
 free(pB);
}
void output(int p, int *pC)
{
 int i;
 for (i=0; i<p-1; i++)
     printf("%d ", pC[i]);
 printf("%d\n", pC[p-1]);
 free(pC);
}
main()
{
 int p1, p2, *pA, *pB, *pC;
 input(&p1, &p2, &pA, &pB);
 sort(p1, pA);
 sort(p2, pB);
 combine(p1, p2, pA, pB, &pC);
 output(p1+p2, pC);
}


int a,b,c[100],d[100];
void size()
{scanf("%d %d",&a,&b);
}
void num(int s,int j[])
{int i;
for(i=0;i<s;i++)
{scanf("%d",&j[i]);}
}
void arrange(int s,int j[])
{int i,k,temp;
for(k=0;k<s-1;k++)
{for(i=0;i<s-k-1;i++)
{if(j[i+1]<=j[i]){temp=j[i];j[i]=j[i+1];j[i+1]=temp;}
}
}
}
void plus(int x,int m[],int y,int n[])
{int i;
arrange(x,m);arrange(y,n);
printf("%d",m[0]);
for(i=1;i<x;i++){printf(" %d",m[i]);}
for(i=0;i<y;i++){printf(" %d",n[i]);}
}
void main()
{
	size();
	num(a,c);
	num(b,d);
	plus(a,c,b,d);
}


/*
 * ????addition-of-big-int.cpp
 * ??????
 * ????:2012-11-27
 * ??????????????
 */

int la=0,lb=0,l=0,a[100],b[100],combine[200]; //??????la,lb,??a,b,combine

void input();                                 //????input
void seq();                                   //????seq
void sequence(int x[100]);                    //????sequence
void com(int a[100],int b[100]);              //????com
void output(int combine[200]);                //????output

int main(){                                   //???
	input();                              //??
	seq();                                //??
	com(a,b);                             //???a,b?????combine
	output(combine);                      //??combine
	return 0;                             //?????
}
void input(){                                 //??input
	cin>>la>>lb;                          //????a,b???la,lb
	for(int i=0;i<la;i++)                 //????a
		cin>>a[i];
	for(int i=0;i<lb;i++)                 //????b
		cin>>b[i];
}
void seq(){                                   //??seq
	l=la;
	sequence(a);                          //??a
	l=lb;
	sequence(b);                          //??b
}
void sequence(int x[100]){                    //????sequence
	int temp=0;                           //????temp
	for(int i=1;i<l;i++)                  //??????
		for(int j=1;j<=l-i;j++)
			if(x[j-1]>x[j])
			{
				temp=x[j];
				x[j]=x[j-1];
				x[j-1]=temp;
			}
}
void com(int a[100],int b[100]){              //????com
	memcpy(combine,a,la*4);
	memcpy(combine+la,b,lb*4);
}
void output(int combine[200]){                //??output
	cout<<combine[0];                     //???????combine
	for(int i=1;i<la+lb;i++)
		cout<<" "<<combine[i];
}


int output(int b[],int a)
{
	sort(b,b+a);
	for (int i=0;i<a-1;i++)
	cout << b[i] << ' ';
	cout << b[a-1];
}
int main()
{
	int a,b;
	cin >> a >> b;
	int input(int a,int s);
	input(a,b);
	return 0;
}
int input(int a,int s)
{
	int b[1000],c[1000];
	for (int i=0;i<a;i++)
	cin >> b[i];
	for (int i=0;i<s;i++)
	cin >> c[i];
	output(b,a);
	cout << ' ';
	output(c,s);
}


int main()
{
	void sr(int a[100],int b[100],int x,int y);
	void px(int a[100],int x);
	void hb(int a[100],int b[100],int c[200],int x,int y);
	void sc(int a[200],int x);
	int a[100],b[100],c[200],x,y;
	scanf("%d%d",&x,&y);
	sr(a,b,x,y);
	px(a,x);
	px(b,y);
	hb(a,b,c,x,y);
	sc(c,x+y);
	return 0;
}
void sr(int a[100],int b[100],int x,int y)
{
	int i;
	for(i=0;i<x;i++)
	{
	scanf("%d",&a[i]);
	}
	for(i=0;i<y;i++)
	{
	scanf("%d",&b[i]);
	}
}
void px(int a[100],int x)
{
	int i,j,temp;
	for(i=x-1;i>0;i--)
	{
		for(j=0;j<i;j++)
		{
			if(a[j]>a[j+1])
			{
				temp=a[j];
				a[j]=a[j+1];
				a[j+1]=temp;
			}
		}
	}
}
void hb(int a[100],int b[100],int c[200],int x,int y)
{
	int i;
	for(i=0;i<x+y;i++)
	{
		if(i<x)
			c[i]=a[i];
		else
			c[i]=b[i-x];
	}
}
void sc(int c[200],int x)
{
	int i;
	for(i=0;i<x;i++)
	{
		if(i==0)
			printf("%d",c[i]);
		else
			printf(" %d",c[i]);
	}
}


int compare(const void * elem1, const void * elem2)
{
      return (*(int *)elem1) - (*(int *) elem2);
}
int main()
{
      int N,M,i;
      scanf("%d%d",&N,&M);
      int a[N],b[M];
      for(i=0;i<N;i++)
      {
              scanf("%d",&a[i]);
      }
      for(i=0;i<M;i++)
      {
              scanf("%d",&b[i]);
      }
       qsort(a,N,sizeof(int),compare);
       for(i=0;i<N-1;i++)
       {
              printf("%d ",a[i]);

       }
       printf("%d ",a[i]);
        qsort(b,M,sizeof(int),compare);
       for(i=0;i<M-1;i++)
       {
              printf("%d ",b[i]);

       }
       printf("%d\n",b[i]);

       return 0;
}


int m,n,a[1000],b[1000];
void init(){
	cin>>m>>n;
	for(int i=0;i<m;i++)cin>>a[i];
	for(int i=0;i<n;i++)cin>>b[i];
}
void sort(){
	for(int i=0;i<m-1;i++)
		for(int j=m-1;j>i;j--)
			if(a[j]<a[j-1]){
				int t=a[j-1];
				a[j-1]=a[j];
				a[j]=t;
			}
	for(int i=0;i<n-1;i++)
		for(int j=n-1;j>i;j--)
			if(b[j]<b[j-1]){
				int t=b[j-1];
				b[j-1]=b[j];
				b[j]=t;
			}
}
void combine(){
	for(int i=m;i<m+n;i++)a[i]=b[i-m];
}
void print(){
	for(int i=0;i<m+n;i++){
		if(i)cout<<' ';
		cout<<a[i];
	}
	cout<<endl;
}
int main(){
	init();
	sort();
	combine();
	print();
	return 0;
}


int main()
{void st(int s[],int i);
void cha(int s[],int i);
void pp(int s[],int ss[],int m,int n);
int m,n;
int s[100]={0};
int ss[100]={0};
scanf("%d %d\n",&m,&n);
st(s,m);
st(ss,n);
cha(s,m);
cha(ss,n);
pp(s,ss,m,n);
return 0;
}
void st(int k[],int i)
{int j;
for(j=1;j<=i;j++)
scanf("%d",&k[j]);
}
void cha(int k[],int i)
{int j,m,temp;
for(j=1;j<i;j++)
{for(m=j+1;m<=i;m++)
     {if(k[m]<k[j])
          {temp=k[m];k[m]=k[j];k[j]=temp;}
      }
}
}
void pp(int s[],int ss[],int m,int n)
{int i=2;
	printf("%d",s[1]);
for(i=2;i<=m+n;i++)
{if(i<=m)
printf(" %d",s[i]);
else
printf(" %d",ss[i-m]);
}
}


int main()
{
   int a[50]={0},b[50]={0},c[100]={0};int i,j;
   int *p1=&i,*p2=&j;
void input(int a[],int b[],int *p1,int *p2);
  input(a,b,p1,p2);

void sort(int a[],int *p1);
sort(a,p1);
sort(b,p2);
void connect(int a[],int b[],int c[],int *p1,int *p2);
connect(a,b,c,p1,p2);
void output(int c[],int *p1,int *p2);
output(c,p1,p2);
return 0;
}

void input(int a[],int b[],int *p1,int *p2)
{
    int i;
scanf("%d %d",p1,p2);

for(i=0;i<*p1;i++)
scanf("%d",&a[i]);
for(i=0;i<*p2;i++)
scanf("%d",&b[i]);

}

void sort(int a[],int *p1)
{  int i,j,k,t;
  for(i=0;i<*p1-1;i++)
         { k=i;
  for(j=i+1;j<*p1;j++)
    if(a[k]>a[j])  k=j;
     if(k!=i)
     {  t=a[k];a[k]=a[i];a[i]=t; }
        }

}

void connect(int a[],int b[],int c[],int *p1,int *p2)
{  int i,k=0;
   for(i=0;i<*p1;i++)
    c[i]=a[i];
  for(i=*p1;i<*p1+*p2;i++,k++)
    c[i]=b[k];

}

void output(int c[],int *p1,int *p2){
int i,k;
k=*p1+*p2;
for(i=0;i<k-1;i++)
printf("%d ",c[i]);
printf("%d",c[k-1]);

}


int a[1000];
int b[1000];
int m,n;
void init()//???
{
    cin>>m>>n;
    int i,j;
    for (i=1;i<=m;i++)
    {
        cin>>a[i];
    }
    for (i=1;i<=n;i++) cin>>b[i];
}

void s()//??
{
    sort(a,a+m+1);
    sort(b,b+n+1);
}
void merge()//??
{
    int i;
    for (i=1;i<=n;i++)
    a[i+m]=b[i];
}
void print()//??
{
    int i;
    for (i=1;i<=m+n;i++)
    {
        cout<<a[i];
        if (i<m+n) cout<<' ';
    }
    cout<<endl;
}
int main()
{
    init();
    s();
    merge();
    print();
    return 0;
}


int main()
{
	void take(int x[1000],int l);
	void rank(int x[1000],int l);
	void com(int a[1000],int b[1000],int c[2000],int al,int bl);
	void prin(int c[2000],int l);
	int a[1000];
	int b[1000];
	int c[2000];
	int al,bl;
	scanf("%d%d",&al,&bl);
	take(a,al);
	take(b,bl);
	rank(a,al);
	rank(b,bl);
	com(a,b,c,al,bl);
	prin(c,al+bl);
	return 0;
}
void take(int x[1000],int l)
{
	int i;
	for(i=0;i<l;i++)
	{
		scanf("%d",&x[i]);
	}
}
void rank(int x[1000],int l)
{
	int i,j,temp;
	if(l!=1)
	{
	for(i=l-2;i>=0;i--)
	{
		for(j=0;j<=i;j++)
		{
			if(x[j]>x[j+1])
			{
				temp=x[j];
				x[j]=x[j+1];
				x[j+1]=temp;
			}
		}
	}
	}
}
void com(int a[1000],int b[1000],int c[2000],int al,int bl)
{
	int i;
	for(i=0;i<al;i++)
	{
		c[i]=a[i];
	}
	for(i=al;i<al+bl;i++)
	{
		c[i]=b[i-al];
	}
}
void prin(int c[2000],int l)
{
	int i;
	printf("%d",c[0]);
	for(i=1;i<l;i++)
	{
		printf(" %d",c[i]);
	}
}


int x[200],y[200],m,n;
void sca(void)
{
    int i;
	scanf("%d%d",&m,&n);
	for(i=0;i<m;i++)
	{
	    scanf("%d",&x[i]);
	}
	for(i=0;i<n;i++)
	{
	    scanf("%d",&y[i]);
	}
}

void bubble(int a[],int n)          //Êý×éÃ°ÅÝ £¬nÎªÊý×é³¤¶È
{
    int i,j,b;
    for(i=1;i<n;i++)
    {
        for(j=0;j<n-i;j++)
        {
            if(a[j]>a[j+1])
            {
                b=a[j];
                a[j]=a[j+1];
                a[j+1]=b;
            }
        }
    }
}

void bing(int a[],int l1,int b[],int l2)
{
    int i,j,z[500];
	for(i=0;i<l1;i++)
	    z[i]=a[i];
	for(j=0;i<(l1+l2);j++,i++)
	    z[i]=b[j];
	printf("%d",z[0]);
	for(i=1;i<(l1+l2);i++)
		printf(" %d",z[i]);

}

int main()
{
    sca();
	bubble(x,m);
	bubble(y,n);
    bing(x,m,y,n);
	return 0;
}


void input(int *M,int *N,int a[],int b[])
{
	scanf("%d %d",M,N);
	int i;
	for(i=0;i<*M;i++)
		scanf("%d",&a[i]);
	for(i=0;i<*N;i++)
		scanf("%d",&b[i]);
	//return M,N;
	return;
}

void sort(int array[],int n)
{
	int i,j,k,t;
	for(i=0;i<n-1;i++)
	{
		k=i;
		for(j=i+1;j<n;j++)
			if(array[j]<array[k])
				k=j;
		t=array[k];
		array[k]=array[i];
		array[i]=t;
	}

}

void merge(int M,int N,int a[],int b[],int c[])
{
	int i;
	for(i=0;i<M;i++)
		c[i]=a[i];
	for(i=0;i<N;i++)
		c[i+M]=b[i];
}

void output(int M,int N,int c[])
{
	int i;
	for(i=0;i<M+N-1;i++)
		printf("%d ",c[i]);
	printf("%d",c[M+N-1]);
}

int main()
{
	int M,N,a[100000],b[100000];
	input(&M,&N,a,b);
	sort(a,M);
	sort(b,N);

	int c[100000];
	merge(M,N,a,b,c);
	output(M,N,c);

	return 0;
}


int main()
{
    int *input(int n),*a,*b,*c,n1,n2;
    void paixu(int *a,int n),display(int *c,int n);
    int *hebing(int *a,int *b,int n1,int n2);
    scanf("%d %d",&n1,&n2);
    a=input(n1);
    b=input(n2);
    printf("\n");
    paixu(a,n1);
    paixu(b,n2);
    c=hebing(a,b,n1,n2);
    display(c,n1+n2);
    return 0;
}

int *input(int n)
{
    int *p,i;
    p=(int*)malloc(n*sizeof(int));
    for(i=0;i<n;i++)
    {
                    scanf("%d",&p[i]);
    }
    return (p);
}

void paixu(int *a,int n)
{
     int i,j,t;
     for(i=0;i<n;i++)
     {
                     for(j=i;j<n;j++)
                     {
                                     if(a[j]<a[i])
                                     {
                                                  t=a[j];
                                                  a[j]=a[i];
                                                  a[i]=t;
                                     }
                     }
     }
}

int *hebing(int *a,int *b,int n1,int n2)
{
     int *p,i,j;
     p=(int*)malloc((n1+n2)*sizeof(int));
     for(i=0;i<n1;i++)
     {
                      p[i]=a[i];
     }
     for(j=0;j<n2;j++)
     {
                      p[n1+j]=b[j];
     }
     return (p);
}

void display(int *c,int n)
{
     int i;
     for(i=0;i<n;i++)
     {
                     if(i) printf(" ");
                     printf("%d",c[i]);
     }
}


int main()
{
	void shuru(int array[100],int x);
	void paixu(int array[100],int x);
	int i,m,n,a[100],b[100];
	scanf("%d%d",&m,&n);
	shuru(a,m);
	shuru(b,n);
	paixu(a,m);
	paixu(b,n);

	for(i=0;i<m;i++)
	{
		printf("%d ",a[i]);
	}
	for(i=0;i<n-1;i++)
	{
		printf("%d ",b[i]);
	}
	printf("%d",b[n-1]);
}
void shuru(int array[100],int x)
{
	int i;
	for(i=0;i<x;i++)
	{
		scanf("%d",&array[i]);
	}
}
void paixu(int array[100],int x)
{
	int i,j,b;
	for(j=1;j<x;j++)
	{
		for(i=0;i<x-j;i++)
		{
			if(array[i]>array[i+1]){b=array[i];array[i]=array[i+1];array[i+1]=b;}
		}
	}
}


void input(int num[],int a[])
{
	int j;
    scanf("%d%d",&num[0],&num[1]);
	for(j=0;j<num[0]+num[1];j++)scanf("%d",&a[j]);
}
void order(int num[],int a[])
{
	int j,k,temp;
	for(j=0;j<num[0];j++)
	{
		for(k=num[0]-1;k>0;k--)
		{
			if(a[k]<a[k-1])
			{
				temp=a[k];
				a[k]=a[k-1];
				a[k-1]=temp;
			}
		}
	}
	for(j=num[0];j<num[0]+num[1];j++)
	{
		for(k=num[0]+num[1]-1;k>num[0];k--)
		{
			if(a[k]<a[k-1])
			{
				temp=a[k];
				a[k]=a[k-1];
				a[k-1]=temp;
			}
		}
	}
}
void print(int num[],int a[])
{
	int i;
	for(i=0;i<num[0]+num[1]-1;i++)
		printf("%d ",a[i]);
	printf("%d",a[num[0]+num[1]-1]);
}
void main()
{
	int a[40],num[2];
	input(num,a);
	order(num,a);
	print(num,a);
}


void getnum( int a[], int b[] ); //get the two arrays
void sort( int a[], int len ); // sort the array
void combine ( int a[], int b[], int len1, int len2 ); //combine two arrays
int len1, len2;

int main()
{
		int a[1000] = {0}, b[1000] = {0};

		getnum( a, b );
		sort(a,len1);
		sort(b,len2);
		combine( a, b, len1, len2 );

		return 0;
}

void getnum( int a[], int b[] )
{
		cin >> len1 >> len2;

		for ( int i = 0; i < len1; i++ )
			cin >> a[i];
		for ( int j = 0; j < len2; j++ )
			cin >> b[j];

		return;
}

void sort( int a[], int len )
{
		int temp = 0;

		for ( int i = 0; i < len - 1; i++ )
		{
				for ( int j = 0; j < len - i - 1; j++ )
				{
						if ( a[j] > a[j+1] )
						{
								temp = a[j];
								a[j] = a[j+1];
								a[j+1] = temp; //put the biggest to the end
						}
				}
		}
		return;
}

void combine ( int a[], int b[], int len1, int len2 )
{
		int pin = 0;

		for ( int i = len1; i < len1 + len2; i++ )
		{
				a[i] = b[i-len1];
		}

		for ( int j = 0; j < len1 + len2; j++ )
		{
				if ( pin == 0 )
				{
					cout << a[j];
					pin = 1;
				}
				else
					cout << " " << a[j];
		}
		return;
}


int readin(int n,int *a);
int px(int n,int *a);
int sc(int n1,int *a,int n2,int *b);

int t,i,j,a[1000],b[1000];

int main()
{
    int n1,n2; cin>>n1>>n2;
    readin(n1,a);
    px(n1,a);
    readin(n2,b);
    px(n2,b);
    sc(n1,a,n2,b);
    return 0;
}
int readin(int n,int *a)
{
    memset(a,0,sizeof(a));
    for (i=1;i<=n;i++) cin>>a[i];
}
int px(int n,int *a)
{
    for (i=1;i<n;i++)
        for (j=i+1;j<=n;j++)
            if (a[i]>a[j])
            {
                t=a[i]; a[i]=a[j]; a[j]=t;
            }
}
int sc(int n1,int *a,int n2,int *b)
{
    for (int i=1;i<=n1;i++) cout<<a[i]<<' ';
    for (int i=1;i<=n2-1;i++) cout<<b[i]<<' '; cout<<b[n2];
}


int Compare(const void *elem1,const void *elem2)
{
	return *((int *)elem1)-*((int *)elem2);
}
int main()
{
	int m,n;
		int i;
	scanf("%d %d",&m,&n);
int a[m],b[n];
	for(i=0;i<m;i++)
	{
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;i++)
	{
		scanf("%d",&b[i]);
	}
	qsort(a,m,sizeof(int),Compare);
	qsort(b,n,sizeof(int),Compare);
	for(i=0;i<m;i++)
	{
		printf("%d ",a[i]);
	}
	for(i=0;i<n-1;i++)
	{
		printf("%d ",b[i]);
	}
	printf("%d",b[n-1]);
}


void shuru(int a[],int b[]);
void paixu(int a[]);
void hebing(int a[],int b[]);
void shuchu(int a[]);
void main()
{
	int a[100]={0}, b[100]={0};
	shuru(a,b);
	paixu(a); paixu(b);
	hebing(a,b);
	shuchu(a);
}

void shuru(int a[],int b[])
{
	int m, n, i;
	scanf("%d %d",&m,&n);
	for(i=0; i<m; i++)
		scanf("%d",&a[i]);
	for(i=0; i<n; i++)
		scanf("%d",&b[i]);
}

void paixu(int a[])
{
	int i, j, temp, len=0;
	for(i=0; a[i]!=0; i++)
		len++;
	for(j=1; j<len; j++)
	{
		for(i=0; i<len-j; i++)
		{
			if(a[i]>a[i+1])
			{
				temp=a[i];
				a[i]=a[i+1];
				a[i+1]=temp;
			}
		}
	}
}

void hebing(int a[],int b[])
{
	int i, lena=0, lenb=0;
	for(i=0; a[i]!=0; i++)
		lena++;
	for(i=0; b[i]!=0; i++)
		lenb++;
	for(i=0; i<lenb; i++)
		a[i+lena]=b[i];
}

void shuchu(int a[])
{
	int i;
	printf("%d",a[0]);
	for(i=1; a[i]!=0; i++)
		printf(" %d",a[i]);
}


void output(int n,int m,int a[],int b[])
{
  int i;
  printf("%d",a[0]);
  for(i=1;i<n;i++)
	  printf(" %d",a[i]);
  for(i=0;i<m;i++)
	  printf(" %d",b[i]);
}
void swap(int a[],int i,int j)
{
   int temp;
   temp=a[i];
   a[i]=a[j];
   a[j]=temp;
}
void quicksort(int a[],int l,int r)
{
  int m,i,j;
  i=l; j=r; m=a[i];
  while(i<=j)
  {
     while((a[i]<m)&&(i<r)) i++;
	 while((a[j]>m)&&(j>l)) j--;
	 if(i<=j)
	 {
        swap(a,i,j);
		i++;
		j--;
	 }
  }
  if(i<r) quicksort(a,i,r);
  if(j>l) quicksort(a,l,j);
}
void input()
{
  int i,n,m,a[100],b[100];
  scanf("%d%d",&n,&m);
  for(i=0;i<n;i++)
	  scanf("%d",&a[i]);
  for(i=0;i<m;i++)
	  scanf("%d",&b[i]);
  quicksort(a,0,n-1);
  quicksort(b,0,m-1);
  output(n,m,a,b);
}
main()
{
  input();
}


int arr(int a[],int x,int b[],int y)
{
  int i;
  for(i=0;i<x;i++)
   scanf("%d",&a[i]);
  for(i=0;i<y;i++)
   scanf("%d",&b[i]);
   return 0;
}
int arr1(int a[],int x,int b[],int y)
{
  int i,j,tmp;
  for(i=0;i<x-1;i++)
  for(j=i+1;j<x;j++)
  if(a[i]>a[j])
  {
    tmp=a[i];
    a[i]=a[j];
    a[j]=tmp;
  }
  for(i=0;i<y-1;i++)
  for(j=i+1;j<y;j++)
  if(b[i]>b[j])
  {
    tmp=b[i];
    b[i]=b[j];
    b[j]=tmp;
  }
  return 0;
}
int arr2(int a[],int x,int b[],int y,int c[])
{
   int i,j;
   for(i=0;i<x;i++)
   c[i]=a[i];
   for(;i<x+y;i++)
   c[i]=b[i-x];
   return 0;
}
int arr3(int c[],int t)
{
    int i;
    for(i=0;i<t;i++)
    {
      printf("%d",c[i]);
      if(i<t-1) printf(" ");
      }
     return 0;
}
  int main()
{
      int x,y;
      int a[100],b[100],c[200];
      scanf("%d%d",&x,&y);
      arr(a,x,b,y);
      arr1(a,x,b,y);
      arr2(a,x,b,y,c);
      arr3(c,x+y);
      return 0;
}


int m,n;
void main()
{
	void input(int num1[],int num2[]);
	void change(int num1[],int num2[]);
	void pai(int num1[],int num2[]);
	void output(int num1[]);
	int num1[100],num2[100];
	input(num1,num2);
	change(num1,num2);
	pai(num1,num2);
	output(num1);
}
void input(int num1[],int num2[])
{
	int i;
	scanf("%d %d",&m,&n);
	for(i=0;i<m;i++)
		scanf("%d",&num1[i]);
	for(i=0;i<n;i++)
		scanf("%d",&num2[i]);
}
void change(int num1[],int num2[])
{
	int i,j,t;
	for(i=0;i<m-1;i++)
		for(j=0;j<m-i-1;j++)
		{
			if(num1[j]>num1[j+1])
			{
				t=num1[j];
				num1[j]=num1[j+1];
				num1[j+1]=t;
			}
		}
	for(i=0;i<n-1;i++)
		for(j=0;j<n-i-1;j++)
		{
			if(num2[j]>num2[j+1])
			{
				t=num2[j];
				num2[j]=num2[j+1];
				num2[j+1]=t;
			}
		}
}
void pai(int num1[],int num2[])
{
	int i;
	for(i=0;i<n;i++)
		num1[m+i]=num2[i];
}
void output(int num1[])
{
	int i;
	for(i=0;i<m+n-1;i++)
		printf("%d ",num1[i]);
	printf("%d",num1[m+n-1]);
}


int a[100],b[100];
int m,n;

void input()
{
	int i,j;
	scanf("%d%d",&m,&n);
	scanf("\n");
	for(i=0;i<m;i++)
		scanf("%d ",&a[i]);
	for(j=0;j<n-1;j++)
		scanf("%d ",&b[j]);
	scanf("%d",&b[n-1]);
	return;
}

void sort(int array[],int k)
{
	int i,j,t;
	for(j=0;j<k;j++)
		for(i=0;i<k-j;i++)
			if(array[i]>array[i+1])
			{
				t=array[i];
				array[i]=array[i+1];
				array[i+1]=t;
			}
			return;
}

void combine()
{
    int i,j=0;
	for(i=m;i<m+n;i++)
	{
		a[i]=b[j];
		j++;
	}
	return;
}

void output()
{
	int i;
	for(i=0;i<m+n-1;i++)
	printf("%d ",a[i]);
	printf("%d",a[m+n-1]);
	return;
}

int main()
{
	input();
	sort(a,m-1);
	sort(b,n-1);
	combine();
	output();
	return 0;
}


int compare(const void *a,const void *b)
{
    return *(int*)a-*(int*)b;
}
void Do(int m,int n)
{
    int a[m],b[n];
    int i;
    for(i=0;i<m;i++)
    scanf("%d",&a[i]);
    for(i=0;i<n;i++)
    scanf("%d",&b[i]);
    qsort(a,m,4,compare);
    qsort(b,n,4,compare);
    for(i=0;i<m;i++)
    printf("%d ",a[i]);
    for(i=0;i<n-1;i++)
    printf("%d ",b[i]);
    printf("%d\n",b[n-1]);
}
main()
{
    int m,n;
    scanf("%d %d",&m,&n);
    Do(m,n);
}


int n,m;
void change(int a[]);
int main()
{
	int a[1000]={0},b[1000]={0};
	int i;
	int first=0;
	cin>>n>>m;
	for(i=0;i<n;i++)
		cin>>a[i];
	for(i=0;i<m;i++)
		cin>>b[i];
	change(a);
	for(i=0;i<n;i++)
		cout<<a[i]<<" ";
	n=m;
	change(b);
	for(i=0;i<m;i++)
	{
		if(first==1)
			cout<<" "<<b[i];
		if(first==0)
		{
			cout<<b[i];
		first=1;
		}
	}
	cout<<endl;
	return 0;
}
void change(int a[])
{
	int t;
	int i,j;
	for(i=0;i<n-1;i++)
		for(j=0;j<n-i-1;j++)
		{
			if(a[j]>a[j+1])
			{
				t=a[j];
				a[j]=a[j+1];
				a[j+1]=t;
			}
		}
}


int a[100],b[100],anum,bnum;
void scan(){
	int i;
	scanf("%d %d",&anum,&bnum);
	for(i=0;i<anum;i++)scanf("%d",a+i);
	for(i=0;i<bnum;i++)scanf("%d",b+i);
}
void mysort(){
	int temp,i,j;
	for(i=0;i<anum-1;i++)
		for(j=1;j<anum-i;j++)
			if(a[j]<a[j-1]){
				temp=a[j];
				a[j]=a[j-1];
				a[j-1]=temp;
			}
	for(i=0;i<bnum-1;i++)
		for(j=1;j<bnum-i;j++)
			if(b[j]<b[j-1]){
				temp=b[j];
				b[j]=b[j-1];
				b[j-1]=temp;
			}
}
void print(){
	int i;
	for(i=0;i<anum;i++)printf("%d ",a[i]);
	for(i=0;i<bnum;i++)printf("%d%c",b[i],i==bnum-1?'\n':' ');
}
void main()
{
	scan();
	mysort();
	print();
}


void mysort(int*pn, int n)
{
	int i,j;
	int temp;
	for (j=0; j<n; j++)
	{
		for (i=j+1; i<n; i++)
		{
			if (pn[j]>pn[i])
			{
				temp =pn[j];
				pn[j]=pn[i];
				pn[i]=temp;
			}
		}
	}
}

void merge(int *pn, int n, int *pm, int m)
{
	int i;
	printf("%d", pn[0]);
	for (i=1; i<n; i++)
	{
		printf(" %d", pn[i]);
	}
	for (i=0; i<m; i++)
	{
		printf(" %d", pm[i]);
	}
}
int main(int argc, char* argv[])
{
	int m, n, i, *pm, *pn;
	scanf("%d%d",&m, &n);
	pm= (int*)calloc(m, sizeof(int));
	pn= (int*)calloc(n,sizeof(int));

	for (i=0; i<m; i++)
	{
		scanf("%d",&(pm[i]));
	}
	for (i=0; i<n; i++)
	{
		scanf("%d",&(pn[i]));
	}

	mysort(pm, m);
	mysort(pn, n);
	merge(pm, m, pn, n);

	free(pm);
	free(pn);
	return 0;
}


void sort(int array[],int n)
{int i,j,k,t;
 for(i=0;i<n-1;i++)
	{k=i;
	for(j=i+1;j<n;j++)
		if(array[j]<array[k])k=j;
	t=array[k];array[k]=array[i];array[i]=t;
	}
}
void link(int array1[],int array2[],int m,int n)
{int i;
 for(i=m;i<m+n;i++)
	 array1[i]=array2[i-m];
}

main()
{int a[40],b[20],n1,n2,i;
 scanf("%d %d",&n1,&n2);
 for(i=0;i<n1;i++)
	scanf("%d",&a[i]);
 for(i=0;i<n2;i++)
    scanf("%d",&b[i]);
 sort(a,n1);
 sort(b,n2);
 link(a,b,n1,n2);
	for(i=0;i<n1+n2-1;i++)
		printf("%d ",a[i]);
	if(i==n1+n2-1)printf("%d",a[i]);
}


void pai(int a[],int m);
void shuru(int a[10],int b[10],int m,int n);
void shuchu(int c[20],int m,int n);
void hubing(int c[20],int a[10],int b[10],int m,int n);
void main(){
	int a[10],b[10],c[20];
	int m,n;
    scanf("%d%d",&m,&n);
	shuru(a,b,m,n);
	pai(a,m);
	pai(b,n);
	hubing(c,a,b,m,n);
	shuchu(c,m,n);
}
void hubing(int c[20],int a[10],int b[10],int m,int n){
	int i;
	for(i=0;i<m;i++)
		c[i]=a[i];
	for(i=0;i<n;i++)
		c[m+i]=b[i];
}

void shuru(int a[10],int b[10],int m,int n){
	int i;
	for(i=0;i<m;i++)
		scanf("%d",&a[i]);
	for(i=0;i<n;i++)
		scanf("%d",&b[i]);
	printf("\n");

}
void shuchu(int c[20],int m,int n){
	int i;
	for(i=0;i<(m+n-1);i++)
		printf("%d ",c[i]);
printf("%d",c[m+n-1]);
}

void pai(int a[],int m){
	int i,j,t;
	for(j=0;j<m-1;j++)
		for(i=0;i<m-1-j;i++)
			if(a[i]>a[i+1])
			{
				t=a[i];
				a[i]=a[i+1];
				a[i+1]=t;
			}
}


void rank(int n,int c)
{
	int num[10],i,j;
	for(i=0;i<n;i++)
	{
		scanf("%d",&num[i]);
	}
	for(i=0;i<n-1;i++)
	{
		for(j=0;j<n-i-1;j++)
		{
			int a;
			if(num[j]>num[j+1])
			{
				a=num[j];
				num[j]=num[j+1];
				num[j+1]=a;
			}
		}
	}
	for(i=0;i<n;i++)
	{
		printf("%d",num[i]);
		if(i!=n-1)
		{
			printf(" ");
		}
	}
	if(c!=2)
	{
		printf(" ");
	}
}
void count()
{
	int b[2],i;
	scanf("%d %d",&b[0],&b[1]);
	for(i=1;i<=2;i++)
	{
		rank(b[i-1],i);
	}
}
int main()
{
	void rank(int n,int c);
	void count();
	count();
	return 0;
}


void read(int n1,int n2,int s1[],int s2[]);
void bubble_sort(int s[],int n);
void write(int n1,int n2,int s1[],int s2[]);
int main()
{
    int n1,n2,s1[101],s2[101];
    scanf("%d%d",&n1,&n2);
    read(n1,n2,s1,s2);
    bubble_sort(s1,n1);
    bubble_sort(s2,n2);
    write(n1,n2,s1,s2);

}
void read(int n1,int n2,int s1[],int s2[])
{
    int i;

    for(i=0;i<n1;i++) scanf("%d",&s1[i]);
    for(i=0;i<n2;i++) scanf("%d",&s2[i]);
}
void bubble_sort(int s[],int n)
{
    int i,j,t;
    for(i=0;i<n-1;i++)
        for(j=0;j<n-i-1;j++)
            if(s[j]>s[j+1])
            {
                t=s[j];
                s[j]=s[j+1];
                s[j+1]=t;
            }
}
void write(int n1,int n2,int s1[],int s2[])
{
    int i;
    printf("%d",s1[0]);
    for(i=1;i<n1;i++) printf(" %d",s1[i]);
    for(i=0;i<n2;i++) printf(" %d",s2[i]);
}


int n,m;
int a[1000],b[1000];
void qsort(int l,int r)
{
    int i,j,k,x;
    i=l;j=r;
    k=0;
    x=a[(i+j)/2];
    while (i<=j)
    {
        while (a[i]<x) i++;
        while (x<a[j]) j--;
        if (i<=j)
        {
            k=a[i];a[i]=a[j];a[j]=k;
            i++;j--;
        }
    }
    if (i<r) qsort(i,r);
    if (l<j) qsort(l,j);
}

void qsort2(int l,int r)
{
    int i,j,k,x;
    i=l;j=r;
    k=0;
    x=(i+j)/2;
    while (i<j)
    {
        while (b[i]<b[x]) i++;
        while (b[x]<b[j]) j--;
        if (i<=j)
        {
            k=b[i];b[i]=b[j];b[j]=k;
            i++;j--;
        }
    }
    if (i<r) qsort2(i,r);
    if (l<j) qsort2(l,j);
}

void input()
{
    int i;
    cin >>n >>m;
    for (i=1;i<=n;i++)
        cin >>a[i];
    for (i=1;i<=m;i++)
        cin >>b[i];
}

void output()
{
    int i;
    for (i=1;i<=n;i++)
    cout <<a[i]<<" ";
    for (i=1;i<m;i++)
    cout <<b[i]<<" ";
    cout <<b[m]<<endl;
}

int main()
{
    input();
    qsort(1,n);
    qsort2(1,m);
    output();
    return 0;
}


int input( int *s, int n )
{
    int i = 0;
    for ( i = 0; i < n; i++ )
        scanf("%d", &s[i]);
    return 0;
}

int sort( int *s, int n )
{
    int i = 0, j = 0;
    for ( i = 0; i < n; i++ )
    {
        for ( j = 1; j < n; j++ )
        {
            if ( s[j-1] > s[j] )
            {
                int temp = s[j-1];
                s[j-1] = s[j];
                s[j] = temp;
            }
        }
    }
    return 0;
}

int combine( int *s1, int *s2, int n1, int n2, int *s )
{
    int i = 0;
    for ( i = 0; i < n1; i++ )
        s[i] = s1[i];
    for ( i = 0; i < n2; i++ )
        s[i+n1] = s2[i];
    return 0;
}

int output( int *s, int n )
{
    int i = 0;
    if ( n <= 0 )
        return 0;
    printf("%d", s[0]);
    for ( i = 1; i < n; i++ )
        printf(" %d", s[i]);
}

int main()
{
    int n1 = 0, n2 = 0;
    scanf("%d %d", &n1, &n2);
    int s1[1000]= {0};
    int s2[1000]= {0};
    input(s1,n1);input(s2,n2);
    sort(s1,n1);sort(s2,n2);
    int s[2000]={0};
    combine(s1,s2,n1,n2,s);
    output(s,n1+n2);
    return 0;
}


int main()
{
    int n,m,a[100]={0},b[100]={0};
	scanf("%d%d",&n,&m);
	void type(int array[],int n);
	void order(int array[],int q);
	void join(int array1[],int array2[],int q1,int q2);
	void out(int array[],int q1,int q2);
	type(a,n);
	type(b,m);
	order(a,n);
	order(b,m);
	join(a,b,n,m);
	out(a,n,m);
}

int type(int array[],int n)
{
	int c;
	for (c=0;c<n;c++)
	{
		scanf("%d",&array[c]);
	}
}

int order(int array[],int q)
{
	int i,j,t;
	for (i=0;i<q-1;i++)
	{
		for (j=0;j<q-1;j++)
		{
			if (array[j]>=array[j+1])
			{
				t=array[j+1];
				array[j+1]=array[j];
				array[j]=t;
			}
		}
	}
}

int join(int array1[],int array2[],int q1,int q2)
{
	int k;
	for (k=0;k<q2;k++)
	{
		array1[q1+k]=array2[k];
	}
}

int out(int array[],int q1,int q2)
{
	int k;
	for (k=0;k<q1+q2-1;k++)
	{
		printf("%d ",array[k]);
	}
	printf("%d\n",array[q1+q2-1]);
}


void changeplace(int n,int a[])
{
	int i,j,x;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n-i-1;j++)
		{
			if(a[j]>=a[j+1])
			{
				x=a[j];
				a[j]=a[j+1];
				a[j+1]=x;
			}
		}

	}
}
main()
{
	int n1,n2,k;
	scanf("%d%d",&n1,&n2);
	int *p=(int*)malloc(n1*sizeof(int));
	int *q=(int*)malloc(n2*sizeof(int));
	for(k=0;k<n1;k++)
	scanf("%d",&p[k]);
	for(k=0;k<n2;k++)
	scanf("%d",&q[k]);
	changeplace(n1,p);
	changeplace(n2,q);
	for(k=0;k<n1;k++)
	printf("%d ",p[k]);
	for(k=0;k<n2-1;k++)
	printf("%d ",q[k]);
	printf("%d",q[n2-1]);

}


/*void f()
{
	scanf("%d %d",&num1,num2);
	int i;
	for(i=0;i<num1;i++)
	{
		scanf("%d",&word1[i]);
	}
	printf("\n");
	for(i=0;i<num2;i++)
	{
		scanf("%d",&word2[i]);
	}
	printf("\n");
}
void g()
{
	f();
	int j,k,temp;
	for(j=1;j<=num1*num1;j++)
	{
		for(k=0;k<num1-1;k++)
		{
			if(num1[k]>=num1[k+1])
			{
				temp=num1[k];
				num1[k]=num1[k+1];
				num1[k+1]=temp;
			}
		}
	}
	for(j=1;j<=num2*num2;j++)
	{
		for(k=0;k<num2-1;k++)
		{
			if(num2[k]>=num2[k+1])
			{
				temp=num2[k];
				num2[k]=num2[k+1];
				num2[k+1]=temp;
			}
		}
	}
}
void A()
{
	f();
	g();
	int zjword[300],l;
	for(l=0;l<num1+num2;l++)
	{
		if(l<num1)
		{
			zjword[l]=word1[l];
		}else{
			zjword[l]=word2[l-num1];
		}
	}
}
void B()
{
	f();
	g();
	A();
	int m;
	for(m=0;m<num1+num2;m++)
	{
		if(m!=num1+num2-2)
		printf("%d ",zjword[m]);
		else printf("%d",zjword[m]);
	}
}*/
int main()
{
	int word1[100],word2[100];
    int num1,num2;
	scanf("%d %d",&num1,&num2);
	int i;
	for(i=0;i<num1;i++)
	{
		scanf("%d",&word1[i]);
	}
	printf("\n");
	for(i=0;i<num2;i++)
	{
		scanf("%d",&word2[i]);
	}
	printf("\n");
	int j,k,temp;
	for(j=1;j<=num1*num1;j++)
	{
		for(k=0;k<num1-1;k++)
		{
			if(word1[k]>=word1[k+1])
			{
				temp=word1[k];
				word1[k]=word1[k+1];
				word1[k+1]=temp;
			}
		}
	}
	for(j=1;j<=num2*num2;j++)
	{
		for(k=0;k<num2-1;k++)
		{
			if(word2[k]>=word2[k+1])
			{
				temp=word2[k];
				word2[k]=word2[k+1];
				word2[k+1]=temp;
			}
		}
	}
	int zjword[300],l;
	for(l=0;l<num1+num2;l++)
	{
		if(l<num1)
		{
			zjword[l]=word1[l];
		}else{
			zjword[l]=word2[l-num1];
		}
	}
	int m;
	for(m=0;m<num1+num2;m++)
	{
		if(m!=num1+num2-1)
		printf("%d ",zjword[m]);
		else printf("%d",zjword[m]);
	}
	return 0;
}


void pai(int a[],int m);
void shuru(int a[10],int b[10],int m,int n);
void main(){
	int a[10],b[10];
	int m,n;
    scanf("%d%d",&m,&n);
	shuru(a,b,m,n);
}

void shuru(int a[10],int b[10],int m,int n){
	int i;
	for(i=0;i<m;i++)
		scanf("%d",&a[i]);
	for(i=0;i<n;i++)
		scanf("%d",&b[i]);
	printf("\n");
	pai(a,m);
	pai(b,n);
	for(i=0;i<m;i++)
		printf("%d ",a[i]);
	for(i=0;i<n-1;i++)
		printf("%d ",b[i]);
                  printf("%d",b[n-1]);

}

void pai(int a[],int m){
	int i,j,t;
	for(j=0;j<m-1;j++)
		for(i=0;i<m-1-j;i++)
			if(a[i]>a[i+1])
			{
				t=a[i];
				a[i]=a[i+1];
				a[i+1]=t;
			}
}


int n,m;
int main()
{
    void shuru(int x[],int y[]);
    void paixu(int x[],int y[]);
    void hebin(int x[],int y[]);
    void shuchu(int x[]);
    int a[200],b[100];
    shuru(a,b);paixu(a,b);hebin(a,b);shuchu(a);
    return 0;
}
void shuru(int x[],int y[])     //??????
{
     int i;
     cin>>n>>m;
     for(i=0;i<n;i++)cin>>x[i];
     for(i=0;i<m;i++)cin>>y[i];
}
void paixu(int x[],int y[])    //??
{
     int i,j,temp;
     for(i=0;i<n-1;i++)
        for(j=i+1;j<n;j++)
        if(x[i]>x[j]){temp=x[i];x[i]=x[j];x[j]=temp;}
     for(i=0;i<m-1;i++)
        for(j=i+1;j<m;j++)
        if(y[i]>y[j]){temp=y[i];y[i]=y[j];y[j]=temp;}
}
void hebin(int x[],int y[])    //??
{
     int i,j;
     for(i=n,j=0;i<n+m;i++,j++)
       x[i]=y[j];
}
void shuchu(int x[])           //??
{
     for(int i=0;i<n+m-1;i++)
     cout<<x[i]<<' ';
     cout<<x[n+m-1];

}


void input(int *n1,int data1[],int *n2,int data2[])
{
     cin>>*n1>>*n2;
     for (int i=0;i<*n1;++i)
         cin>>data1[i];
     for (int i=0;i<*n2;++i)
         cin>>data2[i];
     return;
     }
void bubblesort(int n,int data[])
{
     for (int i=n-1;i>0;--i)
         for (int j=0;j<i;++j)
             if (data[j]>data[j+1])
             {
                int temp=data[j];
                data[j]=data[j+1];
                data[j+1]=temp;
                }
     return;
     }
int combine(int n1,int data1[],int n2,int data2[],int data3[])
{
     for (int i=0;i<n1;++i)
         data3[i]=data1[i];
     for (int i=n1;i<n1+n2;++i)
         data3[i]=data2[i-n1];
     return n1+n2;
     }
void print(int n,int data[])
{
     cout<<data[0];
     for (int i=1;i<n;++i)
         cout<<' '<<data[i];
     cout<<endl;
     return;
     }
int main()
{
    int n1,n2,a1[101],a2[101],a3[201];
    input(&n1,a1,&n2,a2);
    bubblesort(n1,a1);
    bubblesort(n2,a2);
//    print(n1,a1);
//    print(n2,a2);
    int n3=combine(n1,a1,n2,a2,a3);
    print(n3,a3);
    return 0;
    }


void input(int m,int a[100])//??
{
     int i;
     for(i=0;i<m;i++)
     cin>>a[i];
}
void arrange(int m,int a[100])//??
{
     int i,j,c;
     for(i=1;i<m;i++)
       for(j=0;j<m-i;j++)
       {
         if(a[j]>a[j+1])
         {
           c=a[j];
           a[j]=a[j+1];
           a[j+1]=c;
         }
       }
}
void  puttogether(int a,int b,int m[2][100])//??
{
      int i;
      for(i=0;i<b;i++)
      m[0][a+i]=m[1][i];
}
void output(int a,int m[100])//??
{
     int i;
     cout<<m[0];
     for(i=1;i<a;i++)
     cout<<" "<<m[i];
}
int main()
{
    int a,b;
    cin>>a>>b;
    int number[2][100];
    input(a,number[0]);
    input(b,number[1]);
    arrange(a,number[0]);
    arrange(b,number[1]);
    puttogether(a,b,number);
    output(a+b,number[0]);
    cin>>a;
    return 0;
}


int m,n,a[20],b[20];
void len()
{
	int i;
	scanf("%d %d",&m,&n);
	for(i=0;i<m;i++)
		scanf("%d",&a[i]);
	for(i=0;i<n;i++)
		scanf("%d",&b[i]);
}
void change(int x,int z[20])
{
	int i,j,middle;
	for(i=0;i<x-1;i++)
	{
		for(j=0;j<x-1;j++)
		{
			if(z[j]>z[j+1])
			{
			middle=z[j];
			z[j]=z[j+1];
			z[j+1]=middle;
			}
		}
	}
}
void prin()
{
	int i;
    for(i=0;i<m;i++)
	printf("%d ",a[i]);
	for(i=m;i<m+n-1;i++)
		printf("%d ",b[i-m]);
	if(i=m+n-1)
	printf("%d",b[n-1]);
}
void main()
{ len();

	change(m,a);
	change(n,b);
	 prin();

}


int old=0;

struct seqs//????
{
	char id[11];
	int age;
	struct seqs *next;
};

struct seqs *build(int l)//?????????l
{
	int i;
    struct seqs *head,*newnode,*p;
	head=(struct seqs *)malloc(len);//???????
    scanf("%s %d",head->id,&head->age);//????????
	p=head;//???p??????
	if(head->age>=60)
		old++;
    for(i=1;i<l;i++)//???????????????????
	{
        newnode=(struct seqs *)malloc(len);//?????
        scanf("%s %d",newnode->id,&newnode->age);//??????
		if(newnode->age<60)
		{
		    p->next=newnode;//??????????
		    p=newnode;//???p??????
		}
		else
		{
			old++;
			newnode->next=head;
			head=newnode;
		}
	}
	p->next=NULL;//????????
	return head;
}

struct seqs *rebuild(struct seqs *headx)//????
{
	int i;
    struct seqs *head,*newnode,*p,*px;

	newnode=(struct seqs *)malloc(len);  newnode->next=NULL;//????????
    strcpy(newnode->id,headx->id);
	newnode->age=headx->age;//????????????
	p=newnode;//???p?????????
    px=headx->next;
    for(i=1;i<old;i++)//???????????????????
	{
        newnode=(struct seqs *)malloc(len);//?????
		strcpy(newnode->id,px->id);
		newnode->age=px->age;
		newnode->next=p;//??????????
		p=newnode;//???p??????
		px=px->next;
	}
	head=p;//??head
	return head;
}
void bubble(struct seqs *head,int l)
{
	struct seqs *p;
	int i,j,temp;
	char t[11]={0};
	for(i=1;i<l;i++)
		for(p=head,j=0;j<l-i;j++,p=p->next)
			if(p->age < p->next->age)
	 		{
                strcpy(t,p->id);
				strcpy(p->id,p->next->id);
                strcpy(p->next->id,t);
                temp=p->age;
     			p->age=p->next->age;
				p->next->age=temp;
 			}
}
void main()
{
    int n,i,j;
	struct seqs *p,*px;
	scanf("%d",&n);
	p=build(n);
	px=rebuild(p);
	bubble(px,old);
    while(px!=NULL)//????
	{
		printf("%s\n",px->id);
		px=px->next;
	}
	for(i=0;i<old;i++)
	    p=p->next;
    while(p!=NULL)//????
	{
		printf("%s\n",p->id);
		p=p->next;
	}

}


void main()
{
	int n;
	scanf("%d\n",&n);
	struct patient
	{
		char num[10];
		int age;
	}pa[100],pao[100],pay[100],blank;
	int i,j=0,k=0;
	for(i=0;i<n;i++)
	{
		scanf("%s",pa[i].num);
		scanf("%d",&pa[i].age);
		if(pa[i].age>=60)
			pao[j++]=pa[i];
		else
			pay[k++]=pa[i];
	}
	int t;
	for(i=0;i<j;i++)
	{
		for(t=i+1;t<j;t++)
		{
			if(pao[t].age>pao[i].age)
			{
				blank=pao[i];
				pao[i]=pao[t];
				pao[t]=blank;
			}

		}
	}
	for(i=0;i<j;i++)
	{
		if(pao[i].age!=pao[i-1].age)
		{
			for(t=0;t<n;t++)
				if(pa[t].age==pao[i].age)
					printf("%s\n",pa[t].num);
		}
	}
	for(i=0;i<k;i++)
		printf("%s\n",pay[i].num);
}


int n;
struct student
{
	int a;
	struct student *next;
	char num[20];
};

struct student *creat()
{
	struct student *head,*headtwo,*p1,*p2,*p3,*p4;
	p1=(struct student *)malloc(sizeof(struct student));
	scanf("%s",p1->num);
	scanf("%d",&p1->a);
	head=(struct student *)malloc(sizeof(struct student));
	head->next=p1;
	p2=head;
	p1->next=NULL;
	headtwo=(struct student *)malloc(sizeof(struct student));p4=headtwo;p4->next=NULL;
	int i,t=0;
	for (i=0;i<n-1;i++)
	{
		t=0;
		p3=(struct student *)malloc(sizeof(struct student));
		scanf("%s",p3->num);
	    scanf("%d",&p3->a);
		if(p3->a>=60)
		{
			p2=head;
			p1=head->next;
			while(p1!=NULL)
			{
				if(p3->a>p1->a)
				{
					p3->next=p1;p2->next=p3;t=1;break;
				}
				p2=p1;
				p1=p1->next;
			}
			if(t==0) {p2->next=p3;p3->next=NULL;}
		}
		if(p3->a<60)
		{
			p4->next=p3;
			p4=p3;
			p4->next=NULL;
		}
	}
	p1=head;
	while(p1->next!=NULL)
	{
		p1=p1->next;
	}
	p1->next=headtwo->next;
	return head;
}
void main()
{
	scanf("%d",&n);
	struct student *head,*p;
	head=creat();
	p=head->next;
	while (p!=NULL)
	{
		printf("%s\n",p->num);
		p=p->next;
	}
}


int main(){
	int n,i,j;
	char id[NUM][LEN];
	int nl[NUM];
	char id_old[NUM][LEN],id_young[NUM][LEN];
	int nl_old[NUM];
	int a=0,b=0;
	scanf("%d",&n);
	char ids[LEN];
	for(i=0;i<n;i++){
		scanf("%s %d",&id[i],&nl[i]);
		if(nl[i]>=60){
			strcpy(id_old[a],id[i]);
			nl_old[a]=nl[i];
			a++;
		}
		else{
			strcpy(id_young[b],id[i]);
			b++;
		}
	}
	int e;
	for(i=1;i<=a;i++){
		for(j=0;j<a-i;j++){
			if(nl_old[j]<nl_old[j+1]){
				e=nl_old[j+1];
				nl_old[j+1]=nl_old[j];
				nl_old[j]=e;
				strcpy(ids,id_old[j+1]);
				strcpy(id_old[j+1],id_old[j]);
				strcpy(id_old[j],ids);
			}
		}
	}
	for(i=0;i<a;i++){
		printf("%s\n",id_old[i]);
	}
	for(i=0;i<b;i++){
		printf("%s\n",id_young[i]);
	}
	return 0;
}


int main()
{
	int n,i,s=0,j=0,k=0;
	struct patient{
		int age;
		char id[10];
	}patient[100],old[100],young[100],temp;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>patient[i].id>>patient[i].age;
		if(patient[i].age>=60)
		{
			old[k]=patient[i];
			k++;
		}
		else
		{
			young[s]=patient[i];
			s++;
		}
	}
	for(i=k-1;i>0;i--)
	{
		for(j=0;j<i;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<k;i++)
		cout<<old[i].id<<endl;
	for(i=0;i<s;i++)
		cout<<young[i].id<<endl;
	return 0;
}


struct patient
{
	char id[20];
	int age;
};
int main()
{
	int i,n,j,max,num=0;
	struct patient a[110],t;
	scanf("%d",&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>=60)
			num++;
	}
	for(i=0;i<num;i++)
	{
		max=i;
		for(j=i;j<n;j++)
		{
			if(a[j].age>a[max].age)
			{
				max=j;
			}
		}
		t=a[max];
		for(j=max;j>i;j--)
			a[j]=a[j-1];
		a[i]=t;
	}
	for(i=0;i<n;i++)
		printf("%s\n",a[i].id);
	return 0;
}


int n;
struct student
{
	int a;
	char num[20];
		struct student *next;
};

struct student *creat()
{
	struct student *head,*headtwo,*p1,*p2,*p3,*p4;
	p1=(struct student *)malloc(len);
	scanf("%s%d",p1->num,&p1->a);
	head=(struct student *)malloc(len);
	head->next=p1;
	p2=head;
	p1->next=NULL;
	headtwo=(struct student *)malloc(len);
	p4=headtwo;
	p4->next=NULL;
	int i,t=0;
	for (i=0;i<n-1;i++)
	{
		t=0;
		p3=(struct student *)malloc(len);
		scanf("%s%d",p3->num,&p3->a);
		if(p3->a>=60)
		{
			p2=head;
			p1=head->next;
			while(p1!=NULL)
			{
				if(p3->a>p1->a)
				{
					p3->next=p1;
					p2->next=p3;
					t=1;
					break;
				}
				p2=p1;
				p1=p1->next;
			}
			if(t==0) {p2->next=p3;p3->next=NULL;}
		}
		if(p3->a<60)
		{
			p4->next=p3;
			p4=p3;
			p4->next=NULL;
		}
	}
	p1=head;
	while(p1->next!=NULL)
	{
		p1=p1->next;
	}
	p1->next=headtwo->next;
	return head;
}
void main()
{
	scanf("%d",&n);
	struct student *head,*p;
	head=creat();
	p=head->next;
	while (p!=NULL)
	{
		printf("%s\n",p->num);
		p=p->next;
	}
}


void main()
{
	struct people
	{
		char num[10];
		int age;
	}peo[100],pai[100],temp;

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

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

	for(i=0;i<n;i++)
	{
		if(peo[i].age>=60)
		{
			pai[j]=peo[i];
			j++;
		}
	}

	for(i=0;i<n;i++)
	{
		if(peo[i].age<60)
		{
			pai[j]=peo[i];
			j++;
		}
	}

	for(k=0;k<j-1;k++)
	{
		for(i=0;i<j-1-k;i++)
		{
			if((pai[i].age<pai[i+1].age)&&(pai[i+1].age>=60))
			{
				temp=pai[i];
				pai[i]=pai[i+1];
				pai[i+1]=temp;
			}
		}
	}

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


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


struct queue
{
	char ID[11];
	int age;
	struct number * next;
};
int r=1;
struct queue * AppendNewNode(int n);

void main()
{
    int n,i,j,a[100]={0},temp;
	char temp_2[11]={""};
	struct queue *head, *p,*pf,*temp_1;

	scanf("%ld",&n);

	head=AppendNewNode(n);
    p=head;
  while(p!=NULL)
	{
		scanf("%s %d\n",&p->ID,&p->age);
		p=p->next;
	}
  p=head;
 // p=p->next;
   //  printf("%d\n",p->age);
for(i=0;i<n;i++)
	{
		a[i]=p->age;
		p=p->next;
	}
     //printf("%d\n",a[1]);
 p=head;
 pf=head;
		for(i=0;i<n;i++)
		{
			for(j=0;j<n-1-i;j++)
			{
				if(a[j+1]>=60&&a[j]<a[j+1]) {
					temp=a[j];a[j]=a[j+1];a[j+1]=temp;
				pf=p->next;temp=p->age;p->age=pf->age;pf->age=temp;strcpy(temp_2,p->ID);strcpy(p->ID,pf->ID);strcpy(pf->ID,temp_2);p=p->next;
				}
				else {p=p->next;}
			}
		   p=head;
		}

	p=head;
   //  printf("%d\n",p->age);

	while(p!=NULL)
	{
		printf("%s\n",p->ID);
		p=p->next;

	}

}

struct queue * AppendNewNode(int n)
{

	struct queue *head=NULL, *newNode, *thisNode;
	do{
		newNode=(struct number *) malloc(sizeof(struct queue));
		if(r==1)
		{
			head=newNode;
			thisNode=head;
		}
		else
			thisNode->next=newNode;
		if(r<=n)
		{
			thisNode=newNode;
			r++;
		}
	}while(r<=n);
	thisNode->next=NULL;
	return(head);
}


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

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


struct student
{
	char str[10];
	int a;

	struct student *next;
};

struct student *creat(int n)
{
	int i=0;
	struct student *head;
	struct student *p1,*p2;

	p1=p2=(struct student *)malloc(LEN);
	scanf("%s %d",&p1->str,&p1->a);
    head=NULL;
	while(i<n-1)
	{
		i=i+1;
		if(i==1) head=p1;
		else p2->next=p1;
		p2=p1;
		p1=(struct student *)malloc(LEN);
		scanf("%s %d",&p1->str,&p1->a);
	}
	p2->next=p1;
	p2=(struct student *)malloc(LEN);
	p2=p1;
	p2->next=NULL;

	return(head);
}
void main()
{
	int n,i,j;
	struct student *head,*p1,*p2,*p3,*p4,*p5,*p6;
	scanf("%d",&n);
	head=creat(n);

	char c[10];
	int t;

  for(i=0;i<n;i++)
  {
	  p1=head;
	  p2=p1->next;

	for(j=0;j<n-1-i;j++)
	{
		 if(p2->a>59 && p2->a>p1->a)

			 {
				strcpy(c,p2->str);
				strcpy(p2->str,p1->str);
				strcpy(p1->str,c);
				t=p1->a;
				p1->a=p2->a;
				p2->a=t;
				 }

			 p1=p1->next;
			 p2=p2->next;

	 }

  }
  p5=head;

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

	  { printf("%s\n",p5->str);}
	  p5=p5->next;
  }
}


typedef struct
{
	char id[11];
	int age;
}MAN;

void sort(MAN* array, int nSize)
{
  int i,j;
  for(i = 0; i < nSize ; i++)
  {
	  for(j = nSize - 1; j > i; j--)
	  {
		  if( array[j].age >= 60 && array[j].age > array[j-1].age)
		  {
			  MAN temp = array[j];
			  array[j]= array[j-1];
			  array[j-1] = temp;
		  }
	  }
  }
}
int main()
{
   int i, n;
   MAN * array = 0;
   double ava, maxgap = 0;

   scanf("%d", &n);
   array = (MAN*)malloc(n * sizeof(MAN));
   for(i = 0; i < n ; i++)
   {
	   scanf("%s %d", array[i].id, &(array[i].age));
   }

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

   free(array);
   return 0;
}


struct ill
{
 char id[11];
 int age;
 struct ill*next;
};
struct ill*creat(int n)
{struct ill*head,*p1,*p2;
 int i;
 head=NULL;
 for(i=0;i<n;i++)
 {p1=(struct ill*)malloc(sizeof(struct ill));
  scanf("%s %d",p1->id,&p1->age);
  if(i==0)head=p1;
  else p2->next=p1;
  p2=p1;
 }
 p2->next=NULL;
 return(head);
}
struct ill* arrang(struct ill*head)
{int t,tt;
 char s[11],ss[11];
 struct ill*p,*q,*m,*h;
 for(p=head;p!=NULL;p=p->next)
 {
	 if(p->age>=60)
	 {
      for(m=p,q=p->next;q!=NULL;q=q->next)
      if(q->age > m->age && m->age>=60 ) m=q;
	  {t=tt=p->age; strcpy(s,p->id); strcpy(ss,p->id);
	   for(h=p->next;h!=m->next;h=h->next)
	   {tt=h->age; strcpy(ss,h->id);
	    h->age=t; strcpy(h->id,s);
        t=tt; strcpy(s,ss);
	   }
      p->age=t; strcpy(p->id,s);
	  }
	 }
 }
 return(head);
}
void main()
{int n;
 struct ill*head,*h;
 scanf("%d",&n);
 head=creat(n);
 head=arrang(head);
 for(h=head;h!=NULL;h=h->next)
	 if(h->age>=60)  printf("%s\n",h->id);
 for(h=head;h!=NULL;h=h->next)
	 if(h->age<60)  printf("%s\n",h->id);
}


struct person{
	char str[10];
	int age;
}per[100],per1[100],per2[100];

int main(int argc, char* argv[])
{
	int n,i,j=0,k=0,x=0,t;
	char e[10];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s %d",per[i].str,&per[i].age);
		if(per[i].age>=60){
			strcpy(per1[j].str,per[i].str);
			per1[j].age=per[i].age;
			j++;
		}
		else{
			strcpy(per2[k].str,per[i].str);
			per2[k].age=per[i].age;
			k++;
		}
	}
	for(x=0;x<j;x++){
		for(i=0;i<j-x;i++){
			if(per1[i].age<per1[i+1].age){
				strcpy(e,per1[i].str);
				strcpy(per1[i].str,per1[i+1].str);
				strcpy(per1[i+1].str,e);
				t=per1[i].age;
				per1[i].age=per1[i+1].age;
				per1[i+1].age=t;
			}
		}
	}
	for(i=0;i<j;i++){
		printf("%s\n",per1[i].str);
	}
	for(i=0;i<k;i++){
		printf("%s\n",per2[i].str);
	}

	return 0;
}


int main()
{
	int n,i,age[MAX+10],num[MAX+10];
	char id[MAX+10][ID_DIGITS+1]={0};
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s%d",id[i],&age[i]);
		num[i]=i;
	}
	int flag,tempnum,tempage,j;
	char tempid[ID_DIGITS+1];
	for(i=0;i<n-1;i++){
		for(j=n-1;j>i;j--){
			flag=0;
			if(age[j]>=60&&age[j-1]<60)flag=1;
			else if(age[j]>=60&&age[j-1]>=60){
				if(age[j]>age[j-1])flag=1;
				else if(age[j]==age[j-1]){
					if(num[j]<num[j-1])flag=1;
				}
			}
			else if(age[j]<60&&age[j-1]<60){
				if(num[j]<num[j-1])flag=1;
			}
			if(flag){
				tempnum=num[j];
				num[j]=num[j-1];
				num[j-1]=tempnum;
				tempage=age[j];
				age[j]=age[j-1];
				age[j-1]=tempage;
				strcpy(tempid,id[j]);
				strcpy(id[j],id[j-1]);
				strcpy(id[j-1],tempid);
			}
		}
	}
	for(i=0;i<n;i++){
		printf("%s\n",id[i]);
	}
	return 0;
}


int main(int argc, char* argv[])
{
	struct patient{
		char ID[10];
		int age;
	}pat[100],old[100];
	int n,i,j,k=0,a;
	char b[10];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s%d",pat[i].ID,&pat[i].age);
		if(pat[i].age>=60){
			strcpy(old[k].ID,pat[i].ID);
			old[k].age=pat[i].age;
			k++;
		}
	}
	for(i=0;i<k-1;i++){
		for(j=0;j<k-1-i;j++){
			if(old[j].age<old[j+1].age){
				a=old[j].age;
				old[j].age=old[j+1].age;
				old[j+1].age=a;
				strcpy(b,old[j].ID);
				strcpy(old[j].ID,old[j+1].ID);
				strcpy(old[j+1].ID,b);
			}
		}
	}
	for(i=0;i<k;i++)
		printf("%s\n",old[i].ID);
	for(i=0;i<n;i++){
		if(pat[i].age<60){
			printf("%s\n",pat[i].ID);
		}
	}
	return 0;
}


int main()
{
	int n,i,pass;
	struct patient
	{
		char id[L];
		int age;
	}men[M],temp;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%s%d",men[i].id,&men[i].age);
	for(pass=1;pass<n;pass++)
	{
		for(i=n-1;i>pass-1;i--)
		{
			if(men[i].age>=60&&men[i].age>men[i-1].age)
			{
				temp=men[i];
				men[i]=men[i-1];
				men[i-1]=temp;
			}
		}
	}
	for(i=0;i<n;i++)
	{
		printf("%s\n",men[i].id);
	}
	return 0;
}


struct sick
{char name[10];
int age;
};
int main()
{
	int n,i,count=0,j;
	struct sick s[100],a[100],t;
	char b[3];
	gets(b);
	n=atoi(b);
	for(i=0;i<n;i++)
		scanf("%s %d",s[i].name,&s[i].age);
	if(n==1)
		printf("%s",s[0].name);
	else
	{for(i=0;i<n;i++)
		if(s[i].age>=60)
		{a[count]=s[i];
		count++;
		}
		for(i=0;i<count-1;i++)
			for(j=0;j<count-1-i;j++)
				if(a[j].age <a[j+1].age )
				{t=a[j];a[j]=a[j+1];a[j+1]=t;}
	for(i=0;i<count;i++)
		printf("%s\n",a[i].name);
	for(i=0;i<n;i++)
		if(s[i].age<60)
			printf("%s\n",s[i].name);
	}
		return 0;
}


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


int main()
{ struct peo
  { char num[10];
    int old;
    struct peo *next;
   };
  struct peo *p,*p1,*p2,*p3,*head1,*head2,*head3;
  int n,i,j,k;
  p=p1=p2=p3=head1=head2=head3=(struct peo *)malloc

(sizeof(struct peo));
  scanf("%d\n",&n);
  for (i=1;i<=n;i++)
   { scanf("%s%d",&p1->num,&p1->old);
     if (i==1) head1=p1;
     else p2->next=p1;
     p2=p1;
     p1=(struct peo *)malloc(sizeof(struct peo));
    }
  for (i=1;i<=n;i++)
  { p1=head1;p2=head1;
    for (j=1;j<=(n+1-i);j++)
     {if (p1->old>p2->old&&p1->old>=60) {p2=p1;}
      p1=p1->next;}
    if (i==1) head2=p2;
    else p->next=p2;
    p=p2;
    p1=head1;p3=head1;
    for (j=1;j<=(n-i+1);j++)
     {if (p1->num==p2->num) {if (j==1) head1=p1->next;
                             else p3->next=p1->next;}
      p3=p1;p1=p1->next;
      }
   }
 p=head2;
 for (i=1;i<=n;i++)
  {printf("%s\n",p->num);p=p->next;}

}


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

patient pat[100];

int cmp(const void*, const void*);

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

    qsort(pat,n,sizeof(patient),cmp);

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

int cmp(const void *_p1, const void *_p2)
{
    patient *p1 = (patient*)_p1;
    patient *p2 = (patient*)_p2;
    if (p1->age>=60 && p1->age<60)
        return -1;
    else if (p1->age<60 && p2->age >= 60)
        return 1;
    else if (p1->age>=60 && p2->age >= 60)
        return p2->age - p1->age;
    else
        return 0;
}


struct ill
{
    char id[100];
	int age;
	struct ill *next;
};
void main()
{
	struct ill *creat(int x);
	struct ill *p,*head;
	char *w[1000];
	char *temp1;
	int n,i,j=0,k,temp;
	int *q;
	scanf("%d",&n);
    p=creat(n);
	head=p;
	q=(int *)malloc(n*sizeof(int));
	for(i=0;i<n;i++)
	{
		if((*p).age>=60) {*(q+j)=(*p).age;*(w+j)=(*p).id;j++;}
		p=(*p).next;
	}
	k=j;
loop:for(i=0;i<j-1;i++)
	{
		if(*(q+i)<*(q+i+1))
		{
			temp=*(q+i);*(q+i)=*(q+i+1);*(q+i+1)=temp;
			temp1=*(w+i);*(w+i)=*(w+i+1);*(w+i+1)=temp1;
		}
	}
	for(i=0;i<j-1;i++)
	{
		if(*(q+i)<*(q+i+1)) goto loop;
	}
	for(i=0;i<j;i++)
	{printf("%s\n",*(w+i));}
	p=head;
	for(i=0;i<n;i++)
	{
		if((*p).age>=60) goto lop;
		else
		{printf("%s\n",(*p).id);}
lop:p=(*p).next;
	}

}
struct ill *creat(int x)
{
	struct ill *head,*p1,*p2;
	int i;
	p1=(struct ill *)malloc(sizeof(struct ill));
	scanf("%s %d",(*p1).id,&(*p1).age);
	p2=p1;
	head=p1;
	for(i=0;i<x;i++)
	{
	p1=(struct ill *)malloc(sizeof(struct ill));
	scanf("%s %d",(*p1).id,&(*p1).age);
	(*p2).next=p1;
	p2=p1;
	}
    (*p2).next=NULL;
	return(head);
}


struct student
{
	char num[10];
    int age;
}stu[100];

int main()
{
	char c;
    int n,i,j;
    struct student*pstu=stu,e;
    pstu=&stu[0];

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

    }
    for(j=0;j<n;j++){if(stu[j].age>=60){
                     for(i=j;i>0;i--){
                                        if(stu[i].age>stu[i-1].age){
                                                                  e=*(pstu+i);
                                                                  *(pstu+i)=*(pstu+i-1);
                                                                  *(pstu-1+i)=e;}
                                        }
                     }}
    for(i=0;i<n;i++){
                     printf("%s\n",(pstu+i)->num);}
return 0;

}


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


struct pa
	{
		char id[11];
		int age;
		struct pa *next;
	};
struct pa *insert(struct pa *head,struct pa * new1)
{
	struct pa *p0,*p1,*p2;
	p1=head;
	p0=new1;
	if(head==NULL)
	{
		head=p0;
		p0->next=NULL;
	}
	else if(p0->age>=60)
	{
		while((p1->age>=p0->age)&&(p1->next!=NULL))
		{
			p2=p1;
			p1=p1->next;
		}
		if(p0->age>p1->age)
		{
			if(head==p1)
				head=p0;
			else
				p2->next=p0;
			p0->next=p1;
		}
		else
		{
			p1->next=p0;
			p0->next=NULL;
		}
	}
	else
	{
		p1=head;
		while(p1!=NULL)
		{
			p2=p1;
			p1=p1->next;
		}
		p2->next=p0;
		p0->next=NULL;
	}
	return(head);
}
void main()
{
	struct pa *p,*head;
	int n,i;
	head=NULL;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		p=(struct pa *)malloc(sizeof(struct pa));
		scanf("%s%d\n",p->id,&p->age);
		head=insert(head,p);
	}
	p=head;
	while(p!=NULL)
	{
		printf("%s\n",p->id);
		p=p->next;
	}
}


void main()
{
	int i,j=0,k=0,n,n1=-1,n2=-1,old=0;
	char xiao[100][10];
	struct bingren
	{
		char id[10];
		int age;
	};
	struct bingren a[100];
	struct bingren b[100];
	struct bingren t;
	scanf("%d",&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>=60)
		{
           b[j]=a[i];

		   n1++;

		   j++;
		}
		else
		{
			strcpy(xiao[k],a[i].id);
			k++;
			n2++;
		}
	}
	for(i=0;i<n1;i++)
	{
		for(j=0;j<n1-i;j++)
		{
           if(b[j].age<b[j+1].age)
		   {
			   t=b[j];
			   b[j]=b[j+1];
			   b[j+1]=t;
		   }
		}

	}

    for(i=0;i<=n1;i++)
		printf("%s\n",b[i].id);
	for(i=0;i<=n2;i++)
		printf("%s\n",xiao[i]);
}


struct patient
{
	char id[10];
	int age;
	struct patient * next;
};
int n;
struct patient * creat(int x)
{
	struct patient * head;
	struct patient *p1,*p2;
	n=0;
	p1=p2=(struct patient *)malloc(LEN);
	scanf("%s %d\n",p1->id,&p1->age);
	head=NULL;
	while(n!=x)
	{
		n=n+1;
		if(n==1)head=p1;
		else p2->next=p1;
		p2=p1;
		p1=(struct patient *)malloc(LEN);
        scanf("%s %d\n",p1->id,&p1->age);
	}
	p2->next=NULL;
	return(head);
}
void main()
{
    int m,i,j,v,t,*b;
	struct patient *head,*p1;
	b=(int*)malloc(100*sizeof(int));
    scanf("%d\n",&m);
	head=creat(m);
	p1=head;
	for(i=0;i<m;i++) {*(b+i)=p1->age;p1=p1->next;}
	for(j=0;j<m-1;j++)
	   for(i=0;i<m-1-j;i++)
		   if(*(b+i)<*(b+i+1))
		   {t=*(b+i);*(b+i)=*(b+i+1);*(b+i+1)=t;}
    for(i=0;i<m;i++) if(*(b+i)<60) {v=i;break;}
	p1=head;
	for(j=0;j<v;j++)
	{
		p1=head;
		while(p1!=NULL)
		{
			if(p1->age==*(b+j) && (j==0 || *(b+j)!=*(b+j-1))) printf("%s\n",p1->id);
			p1=p1->next;
		}
	}
	p1=head;
	while(p1 != NULL)
	{
		if(p1->age<60) printf("%s\n",p1->id);
		p1=p1->next;
	}
}


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

struct a * insert(struct a * head,struct a * s)/*??????????????????????*/
{
	struct a *p0,*p1,*p2;
	p1=head;/*???*/
	p0=s;/*??????*/
	if(head==NULL)/*?????*/
	{head=p0;p0->next=NULL;}
	else{
	//while((p0->age<p1->age)&&(p1->next!=NULL))
	while((p0->age<=p1->age)&&(p1->next!=NULL))
	{p2=p1;p1=p1->next;}/*??????*/
	if(p0->age>p1->age)/*???*/
	{
		if(head==p1)head=p0;
		else p2->next=p0;
		p0->next=p1;
	}
	else{p1->next=p0;p0->next=NULL;}/*????????*/
	}
	return(head);

}

struct a *creat(struct a * head, struct a * s)/*???????????????????*/
{
    struct a *t;
	if(head==NULL)
	{head=s;s->next=NULL;}
	else
	{  for(t=head;t->next!=NULL;t=t->next);/*????*/
	       t->next=s;                       /*??*/
	       s->next=NULL;
	}
	return(head);

}

void main()
{
	struct a *head1,*head2,*s,*p;
	int i,n;
	scanf("%d",&n);
	head1=NULL;
	head2=NULL;
	for(i=0;i<=n-1;i++)
	{   s=LEN;
	    scanf("%s %d",s->id,&s->age);
	    s->next=NULL;
		if(s->age>=60)
		 head1=insert(head1,s);/*???????????????*/
		if(s->age<60)
		 head2=creat(head2,s);/*?????????????*/
	}
	for(p=head1;p!=NULL;p=p->next)
		printf("%s\n",p->id);
	for(p=head2;p!=NULL;p=p->next)/*????????????????*/
		printf("%s\n",p->id);
}


struct mao
    {
	char name[10];
	int age;
    }pat[100];
int main()
{
    int max (int age[100],int n);
	int n,i,k;
int age[100];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s %d",pat[i].name,&pat[i].age);
		if(pat[i].age>=60)
        age[i]=200+pat[i].age;
        else
        age[i]=101-i;
	}
	for(i=0;i<n;i++)
	{
                    k=max (age,n);
                    printf("%s\n",pat[k].name);
    }
    return 0;
}
int max (int age[100],int n)
{
	int a=0,j=0,k=0;
	for(j=0;j<n;j++)
	{
		if(age[j]>a)
		{
			a=age[j];
			k = j;
		}
	}
	age[k]=0;
	return k;
}


struct patient
{
	char No[10];
	int age;
}grp1[100],grp2[100],grp3[100];
int main()
{
	int n;
	scanf("%d",&n);
         int i;
	for(i=0;i<n;i++)
	{
		scanf("%s%d",&grp1[i].No,&grp1[i].age);
	}
         for(i=0;i<n;i++)
	{
		grp2[i].age=-1;
		grp3[i].age=-1;
	}
         for(i=0;i<n;i++)
	{
		if(grp1[i].age>=60)
		{
			strcpy(grp2[i].No,grp1[i].No);
			grp2[i].age=grp1[i].age;
		}
		if(grp1[i].age<60)
		{
			strcpy(grp3[i].No,grp1[i].No);
			grp3[i].age=grp1[i].age;
		}
	}
         char y[10];
	int x;
	int k,m;
	for(k=1;k<n;k++)
	{
		for(m=0;m<n-k;m++)
		{
			if(grp2[m].age<grp2[m+1].age)
			{
				x=grp2[m+1].age;
				grp2[m+1].age=grp2[m].age;
				grp2[m].age=x;
				strcpy(y,grp2[m+1].No);
				strcpy(grp2[m+1].No,grp2[m].No);
				strcpy(grp2[m].No,y);
			}
		}
	}
         for(i=0;i<n;i++)
	{
		if(grp2[i].age!=-1)
			printf("%s\n",grp2[i].No);
	}
         for(i=0;i<n;i++)
	{
		if(grp3[i].age!=-1)
			printf("%s\n",grp3[i].No);
	}
	return 0;
}


struct student{
	char num[20];
	int score;
	struct student * next;
};
int n=0;
struct student * creat(int numb);
void print(struct student *head);
struct student *maopao(struct student *head);
int main()
{
	int n;
	char ch;
	struct student *head;
	scanf("%d%c",&n,&ch);
	head=creat(n);
	head=maopao(head);
	print(head);
	free(head);
}

struct student * creat(int numb) /*?????*/
{
	struct student *head;       /*?????*/
	struct student *p1,*p2;     /*??????*/
	n=0;
	p1=p2=(struct student *)malloc(LEN);      /*????????(struct student *)?(void*)??malloc??????
	(struct student *)?*/
	scanf("%s %d",&p1->num,&p1->score);      /*????????*/
	head=NULL;
	while(n<numb-1)     /*??????*/
	{
		n=n+1;         /*?????*/
		if(n==1)
		{
			head=p1;     /*?????????p1???head*/
		}
		else
		{
			p2->next=p1;     /*???p1??p2*/
		}
		p2=p1;      /*p2????*/
		p1=(struct student*)malloc(LEN);   /*????????*/
		scanf("%s %d",&p1->num,&p1->score);    /*???????*/
	}
	p2->next=p1;   /*????????next??NULL*/
	p1->next=NULL;
	return(head);   /*?????*/
}

struct student *maopao(struct student *head)
{
	struct student *p0,*p1,*p2,*tem;
	int temp=0,i,j;
	p0=head;
	p1=head;
	p2=head;
	if(head==NULL)
	{
		return(head);
	}
	else if(p0->next==NULL)
	{
		return(head);
	}
	else if(p0->next!=NULL)
	{
	for(i=0;i<n;i=i+1)
	{
		for(j=0;j<n-1;j=j+1)
		{
			if(p1->score<p1->next->score&&j!=0&&p1->next->score>=60)
			{
				tem=p1->next;
				p2->next=p1->next;
				p1->next=tem->next;
				tem->next=p1;
				p2=p2->next;
			}
else if(p1->score<p1->next->score&&j==0&&p1->next->score>=60)
			{
				tem=p1->next;
				p0=tem;
				p2=tem;
				p1->next=tem->next;
				tem->next=p1;
				p2=p1;
				p1=p1->next;
			}
			else
			{
				p2=p1;
				p1=p1->next;
			}
		}
		temp=temp+1;
		p1=p0;
		p2=p0;
	}
	}
	return(p0);
}

void print(struct student *head)      /*????*/
{
	struct student *p,*tempo;      /*??????*/
	p=head;   /*??head??????*/
	if(head!=NULL)   /*????????*/
	{
		do
		{
		tempo=p->next;
	    printf("%s\n",p->num);
		p=tempo;
		}while(p!=NULL);   /*?p?????????*/
	}
}


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

main()
{
    int n,i,j,a=0,b=0;
    struct patient *p1,*p2,*head1=NULL,*head2=NULL,*q1,*q2,*temp,*last;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        p1=(struct patient*)malloc(LEN);
        scanf("%s %d",p1->id,&p1->age);
        q1=p1;
             if(p1->age>=60)
             {
               if(head1==NULL){head1=p1;p2=p1;p1->next=NULL;}
               else
               {
                 a=a+1;
                 temp=head1;last=head1;
                 for(j=0;j<a;j++)
                 {
                    if(p1->age>temp->age)
                    {
                      if(j==0){p1->next=head1;head1=p1;break;}
                      else{last->next=p1;p1->next=temp;break;}
                    }
                  last=temp;temp=temp->next;
                 }
                 if(j==a){last->next=p1;p1->next=NULL;}
               }
             }
             if(p1->age<60)
             {
               if(head2==NULL){head2=q1;q2=q1;q1->next=NULL;}
               else{b=b+1;q1->next=NULL;q2->next=q1;q2=q1;}
             }
    }
    p1=head1;q1=head2;
    for(i=0;i<=a;i++){printf("%s\n",p1->id);p1=p1->next;}
    for(i=0;i<=b;i++){printf("%s\n",q1->id);q1=q1->next;}
}


struct people
{
	char ID[10];
	int age;
};
void main()
{
	int n, i, t;
    struct people peo[100];
	struct people old[100];
	void bubble(struct people a[100], int n);

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

	t = 0;
	for(i=0; i<n; i++)
	{
		if(peo[i].age>=60)
		{
			strcpy(old[t].ID, peo[i].ID);
			old[t].age = peo[i].age;
			t++;
		}
		else
			continue;
	}
	bubble(old, t);
	for(i=0; i<t; i++)
		printf("%s\n", old[i].ID);

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

}

void bubble(struct people a[100], int n)
{
	int i, j;
	struct people t;
	for(i=1; i<n; i++)
		for(j=0; j<n-i; j++)
		{
			if(a[j].age<a[j+1].age)
			{
				t = a[j];
				a[j] = a[j+1];
				a[j+1] = t;
			}
		}
}


int n,i;
struct man
{
 char num[10];
 int age;
 int nu;
}stu[100];
int f(char *a,int b,int n1,char *c,int d,int n2)
{int sum;
 if(b>=60&&d>=60)
 {if(b>d)
 sum=1;
 else if(b<d)
  sum=-1;
 else
  sum=n2-n1;
 }
 else if(b>=60&&d<60)
  sum=1;
    else if(b<60&&d>=60)
        sum=-1;
 else
        sum=n2-n1;
 return(sum);
}
void main()
{scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%s %d",stu[i].num,&stu[i].age);
stu[i].nu=i+1;}
int j,k;
struct man t;
for(i=0;i<n-1;i++)
{k=i;
for(j=i+1;j<n;j++)
if(f(stu[i].num,stu[i].age,stu[i].nu,stu[j].num,stu[j].age,stu[j].nu)<0)
{k=j;
t=stu[i];stu[i]=stu[k];stu[k]=t;}
}
for(i=0;i<n;i++)
printf("%s\n",stu[i].num);
}


struct stu
{
	char name[20];
	int age;
	int order;
	struct stu *next;
};
int main()
{
	struct stu *p,*q,*t,*r,*head;
	int n,i,j;
	scanf("%d",&n);
	head=(struct stu *)malloc(l);
	q=head;
	for(i=0;i<n;i++)
	{
		p=(struct stu *)malloc(l);
		scanf("%s %d",p->name,&p->age);
		p->order=i;
		q->next=p;
		q=p;
	}
	q->next=NULL;
	for(i=0;i<n-1;i++)
		for(p=head,j=0;j<n-1-i;j++,p=p->next)
		{
			q=p->next;
			t=q->next;
			if((q->age==t->age&&q->order>t->order)||(q->age<60&&t->age<q->age&&q->order>t->order)||(t->age<60&&t->age>q->age&&q->order>t->order)||(t->age>=60&&t->age>q->age))
			{
				r=t->next;
				t->next=q;
				p->next=t;
				q->next=r;
			}
		}
	p=head->next;
	while(p!=NULL)
	{
		printf("%s\n",p->name);
		p=p->next;
	}
}


struct Patient{
	char id[10];
	int age;
	struct Patient *next;
	struct Patient *pre;
};
struct Patient *creat(int x);
struct Patient *sort(struct Patient *);
void print(struct Patient *);

int main()
{
	struct Patient *patient,*patient2;
	int n,i;
	scanf("%d",&n);
	patient=creat(n);
	patient2=sort(patient);
	print(patient2);
}

struct Patient *creat(int x){
struct Patient *p1,*p2,*head,*p;
int i;
	head = NULL;
	for (i=0;i<x;i++){
		p1 = (struct Patient *)malloc(Len);
		if (i==0) {head = p1;head->pre = NULL;}
		else {p2->next = p1;p1->pre = p2;}
		p2 = p1;
		scanf("%s%d",p1->id,&p1->age);
	}
	p1->next = NULL;
	return head;
}

struct Patient *sort(struct Patient *head){
struct Patient *p1,*p2,*temp,*p;
temp = (struct Patient *)malloc(Len);
	p1 = p2 =head;
	while (p1){
		if (p1->age>=60){
			p2 = p1->next;
		    while (p2){
				if (p2->age>p1->age){
					temp->age = p2->age;
					strcpy(temp->id,p2->id);
					p = p2;
					while (p->pre != p1){
						strcpy(p->id,p->pre->id);
						p->age = p->pre->age;
						p = p->pre;
					}
					strcpy(p->id,p1->id);
					p->age = p1->age;
					p1->age = temp->age;
					strcpy(p1->id,temp->id);
		         }
		         p2 = p2->next;
			}
		}
		p1 = p1->next;
	}
  return head;
}

void print(struct Patient *head){
struct Patient *p1,*p2,*p;
p = head;
	while (p){
		if (p->age>=60){
			printf("%s\n",p->id);
		}
		p = p->next;
	}
	p = head;
	while (p){
		if (p->age<60){
			printf("%s\n",p->id);
		}
		p = p->next;
	}
}


struct people
{
	char num[10];
	int age;
	struct people *next;
};
void main()
{
	struct people *head,*p0,*p,*s;
	head=(struct people *)malloc(sizeof(struct people));
	head->next=NULL;
	int n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		p0=head;
		p=p0->next;
		s=(struct people *)malloc(sizeof(struct people));
		s->next=NULL;
		scanf("%s %d",s->num,&s->age);
		while(p!=NULL&&((s->age>=60&&s->age<=p->age)||s->age<60))
		{
			p0=p;
			p=p->next;
		}
		p0->next=s;
		s->next=p;
	}
	p=head->next;
	while(p!=NULL)
	{
		printf("%s\n",p->num);
		p=p->next;
	}
}


struct f
{
	char *id;
	char id_[11];
	int age;
	struct f*next;
};
struct in
{
	struct f*old;
	struct f*young;
	int num;
};
int main()
{
	int n,num_;
	scanf("%d",&n);
	struct f *p2,*p3;
	struct in *p1;
	struct in*cr(int x);//?????????????????????
	p1=cr(n);
	p3=p1->young;
	p2=p1->old;
	num_=p1->num;
	void sort (struct f*p,int x);
	sort(p2,num_);
	while(p2)
	{
		printf("%s\n",p2->id);
		p2=p2->next;
	}
	while(p3)
	{
		printf("%s\n",p3->id);
		p3=p3->next;
	}
}
struct in*cr(int x)
{
	struct f* head1,*head2,*p;
	int k=0;
	struct in *p3;
	p3=(struct in *)malloc(sizeof (struct in));
	head1=(struct f*)malloc(sizeof (struct f));
	head2=(struct f*)malloc(sizeof (struct f));
	p3->old=head1;//??????????????
	p3->young=head2;
	struct f*p4,*p5,*p6,*p7;
	p4=head1;
	p6=head2;
	int i;
	for(i=0;i<x;i++)
	{
		p=(struct f*)malloc(sizeof (struct f));
		scanf("%s %d",p->id_,&p->age);
		if(p->age>=60)//????????????
		{
			p4->age=p->age;
			p4->id=p->id_;
			p5=p4;
			p4=(struct f*)malloc(sizeof (struct f));
			p5->next=p4;
			k++;
		}
		else//??????????????
		{
			p6->age=p->age;
			p6->id=p->id_;
			p7=p6;
			p6=(struct f*)malloc(sizeof (struct f));
			p7->next=p6;
		}
	}
	p5->next=0;
	p7->next=0;
	p3->num=k;
	return p3;//?????
}
void sort (struct f*p,int x)
{
	int i,j,k1;
	char *k2;
	struct f*p1,*p2;
	for(i=0;i<x-1;i++)//???????????
		for(p1=p,j=0;i+j<x-1;j++,p1=p1->next)
		{
			p2=p1->next;
			if(p2->age>p1->age)
			{
				k1=p2->age;
				p2->age=p1->age;
				p1->age=k1;
				k2=p2->id;
				p2->id=p1->id;
				p1->id=k2;
			}
		}
}


struct s
{
	char a[100];
	int b;
	struct s *next;
};
void main()
{
	struct s *p1,*p2,*p0,*head,*insert(struct s *head,struct s *stud),*h;
	int i,j,k,m,n,t,x;
	scanf("%d",&n);
	head=0;
	p1=(struct s *)malloc(sizeof(struct s));h=(struct s *)malloc(sizeof(struct s));
	p2=head=p1;
	p1->next=0;k=0;j=0;
	scanf("%s %d",p1->a,&p1->b);x=0;
	if(p1->b<60)
	{
	p2=h=p1;
	x=1;
	}

	else
		p2=h;
	for(i=0;i<n-1;i++)
	{
		p0=(struct s *)malloc(sizeof(struct s));
		scanf("%s %d",p0->a,&p0->b);
		if(p0->b>=60)
		{
		head=insert(head,p0);
		k++;
		}
		else
		{
			p2->next=p0;
			p2=p0;
			j++;
		}

	}
	p1=head;
	if(x==0)
		i=-1;
	else
		i=0;
	for(;i<k;i++)
	{
		printf("%s\n",p1->a);
			p1=p1->next;
	}
	if(x==0)
	{p2=h->next;
	i=0;}
	else
	{p2=h;i=-1;}
	for(;i<j;i++)
	{
		printf("%s\n",p2->a);
		p2=p2->next;
	}

}
struct s *insert(struct s *head,struct s *stud)
{
	struct s *p0,*p1,*p2;
	p1=head;
	p0=stud;
	if(head==0)
	{
		head=p0;p0->next=0;
	}
	else
	{while((p0->b<=p1->b)&&(p1->next!=0))
	{p2=p1;
	p1=p1->next;}
	if(p0->b>p1->b)
	{if(head==p1)head=p0;
	else p2->next=p0;
	p0->next=p1;}
	else
	{p1->next=p0;p0->next=0;}
	}
	return(head);
}


struct patient{
		char id[10];
		int age;
	};
void bubble(struct patient p[],int m);
void main()
{

	struct patient p[200];
	int n,i,t=100;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s %d",p[i].id,&p[i].age);
		if(p[i].age>=60)
		{
			p[t]=p[i];
			t++;
			p[i].age=0;
		}
	}
	bubble(p,t);
	for(i=100;i<t;i++)
	{
		printf("%s\n",p[i].id);
	}
	for(i=0;i<n;i++)
	{
		if(p[i].age!=0)
			printf("%s\n",p[i].id);
	}
}
void bubble(struct patient p[],int m)
{
	int i,j;
	struct patient temp;
	for(j=101;j<m;j++)
	{
		for(i=100;i<m+100-j;i++)
		{
			if(p[i].age<p[i+1].age)
			{
				temp=p[i];
				p[i]=p[i+1];
		    	p[i+1]=temp;
			}
		}
	}
}


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

	int n, i, j, k;
	struct patient p[100];

	scanf("%d", &n);

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

	for(i=1; i<n; i++)
	{
		if (p[i].age >= 60)
		{
			j=0;
			while(j<i && p[j].age >= p[i].age) j++;
			if (j < i)
			{
				struct patient tmp = p[i];
				for(k=i;k>j;k--)
					p[k] = p[k-1];
				p[j]=tmp;
			}
		}
	}

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

	return 0;
}


struct info
{
	char num[10];
	int age;
};
struct info1
{
	char num1[10];
	int age1;
};
int main(int argc, char* argv[])
{
	struct info patient[101];
	struct info1 old[101];
	int n;
	scanf("%d",&n);
	int i,j;
	for(i=0,j=0;i<n;i++){
		scanf("%s %d",&patient[i].num,&patient[i].age);
		if(patient[i].age>=60){
			strcpy(old[j].num1,patient[i].num);
			old[j].age1=patient[i].age;
			j++;
		}
	}
	int m=j;
	for(j=1;j<m;j++){
		for(i=0;i<m-j;i++){
			if(old[i].age1<old[i+1].age1){
				old[100]=old[i];
				old[i]=old[i+1];
				old[i+1]=old[100];
			}
		}
	}
	for(i=0;i<m;i++){
		printf("%s\n",old[i].num1);
	}
	for(i=0;i<n;i++){
		if(patient[i].age<60){
			printf("%s\n",patient[i].num);
		}
	}
	return 0;
}


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


struct hospital
{
	char ID [13];
	int age;
	struct hospital *next;
};
int main()
{
	void change(struct hospital *);
	int n;
	scanf("%d",&n);
	int i;
	struct hospital *p,*head;
	p=(struct hospital *)malloc(sizeof(struct hospital));
	head=p;
	for(i=0;i<n-1;i++)
	{
		scanf("%s %d",p->ID,&p->age);
		p->next=(struct hospital *)malloc(sizeof(struct hospital));
		p=p->next;
	}
	scanf("%s %d",p->ID,&p->age);
    p->next=NULL;
	for(i=0;i<n;i++)
	{
	for(p=head;p->next!=NULL;p=p->next)
	{
		if(p->age<60&&p->next->age>=60)
		{
			change(p);
		}
		if(p->age>=60&&p->next->age>=60&&p->next->age>p->age)
		{
			change(p);
		}
	}
	}
	for(p=head;p!=NULL;p=p->next)
	{
		printf("%s\n",p->ID);
	}
	return 0;
}
void change(struct hospital *p)
{
	int tempage;
	char tempID[13];
	struct hospital *later=p->next;
	tempage=later->age;
	strcpy(tempID,later->ID);
	later->age=p->age;
	strcpy(later->ID,p->ID);
	p->age=tempage;
	strcpy(p->ID,tempID);
}


struct Patient{
	char id[10];
	int age,arranged;

};

int main()
{
	int n,i,t=0,j;
	struct Patient pai[100],orderd[100];
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>pai[i].id>>pai[i].age;
		pai[i].arranged=0;
	}
	for(i=0;i<n;i++)
	{
		if(pai[i].age>=60)
		{
			orderd[t]=pai[i];
			pai[i].arranged =1;
			t++;
		}
	}
	for(i=0;i<t;i++)
	{
		for(j=0;j<t-1-i;j++)
		{
			if(orderd[j].age<orderd[j+1].age)
			{
				struct Patient temp=orderd[j];
				orderd[j]=orderd[j+1];
				orderd[j+1]=temp;
			}
		}
	}
 	for(i=0;i<n;i++)
	{
		if(pai[i].arranged==0)
		{
			orderd[t]=pai[i];
			t++;
		}
	}
	for(i=0;i<n;i++)
	{
		cout<<orderd[i].id<<endl ;
	}

	return 0;
}


void main()
{
	int n, age[100]={0}, i, j, k, old[101]={0}, oldn, youngn;
	char id[101][20]={0}, oldid[101][20]={0}, youngid[101][20]={0};
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%s%d",id[i],&age[i]);
	for(i=1,j=1,k=1;i<=n;i++)
	{
		if(age[i]>=60)
		{
			old[j]=age[i];
			strcpy(oldid[j],id[i]);
			j++;
		}
		else
		{
			strcpy(youngid[k],id[i]);
			k++;
		}
	}
	oldn=j;
	youngn=k;
	for(i=1;i<=oldn;i++)
	{
		for(j=1;j<=oldn-i;j++)
		{
			if(old[j]<old[j+1])
			{
				old[100]=old[j];
				old[j]=old[j+1];
				old[j+1]=old[100];
				strcpy(oldid[101],oldid[j]);
				strcpy(oldid[j],oldid[j+1]);
				strcpy(oldid[j+1],oldid[101]);
			}
		}
	}
	for(i=1;i<oldn;i++)
		printf("%s\n",oldid[i]);
	for(k=1;k<youngn;k++)
		printf("%s\n",youngid[k]);
}


struct Inf
{
	char c[10];
	int a;
};
int main()
{
	int n,o=0,y=0,t,i,j;
	char temp[10];
	struct Inf inf[100],old[100],young[100];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s%d",inf[i].c,&inf[i].a);
		if(inf[i].a>=60)
		{
			strcpy(old[o].c,inf[i].c);
			old[o].a=inf[i].a;
			o++;
		}
		else
		{
			strcpy(young[y].c,inf[i].c);
			young[y].a=inf[i].a;
			y++;
		}
	}
	for(j=1;j<o;j++)
	{
		for(i=0;i<o-j;i++)
		{
			if(old[i].a<old[i+1].a)
			{
				strcpy(temp,old[i].c);
				strcpy(old[i].c,old[i+1].c);
				strcpy(old[i+1].c,temp);
				t=old[i].a;
				old[i].a=old[i+1].a;
				old[i+1].a=t;
			}
		}
	}
	for(i=0;i<o;i++)
	{
		printf("%s\n",old[i].c);
	}
	for(i=0;i<y;i++)
	{
		printf("%s\n",young[i].c);
	}
	return 0;
}


struct patience
{
       int shunxu;
       char id[10];
       int age;
       } pa[100];
int main()
{
    int n,i,j,p=60,q=0;
    scanf("%d",&n);
    int a[n];
    int b[n],c[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>=60)
					 {
                                       q++;
                                       }
                     }
    do{
    for(i=0;i<n;i++)
	{
                     if(pa[i].age>=p)
					 {
                                      p=pa[i].age;
                                      }
                     }
    for(i=0;i<n;i++)
	{
                     if(pa[i].age==p){
                                      printf("%s\n",pa[i].id);
                                      pa[i].age=0;
                                      }
                     }
    p=60;
    q--;
    }
	while(q>0);
    for(i=0;i<n;i++)
	{
                     if(pa[i].age<60 && pa[i].age>0){
                                     printf("%s\n",pa[i].id);
                                     }
                                     }
    return 0;
}


struct pat
{
	char num[11];
	int age;
	struct pat *next;
};
void main()
{
	int n,i;
	scanf("%d",&n);
	struct pat *head,*p1,*p2,*pre;
	p1=(struct pat *)malloc(sizeof(struct pat));
	scanf("%s %d",p1->num,&p1->age);
	head=p1;
	p1->next=NULL;
	for(i=1;i<n;i++)
	{
		p1=(struct pat *)malloc(sizeof(struct pat));
	    scanf("%s %d",p1->num,&p1->age);
		if(p1->age<60)
		{
			p2=head;
			while(p2)
			{
				if(p2->next==NULL)
				{
					p2->next=p1;p1->next=NULL;break;
				}
				p2=p2->next;
			}
		}
		else if(p1->age>=60)
		{p2=head;
		while(p2)
		{
			if(p2==head&&p1->age>p2->age)
			{
				head=p1;p1->next=p2;break;
			}
			else if(p1->age>p2->age)
			{
				pre->next=p1;p1->next=p2;break;
			}
			else if(p2->next==NULL)
			{
				p2->next=p1;p1->next=NULL;break;
			}
			else {pre=p2;p2=p2->next;}
		}
		}
	}
	p1=head;
	while(p1)
	{
		printf("%s\n",p1->num);
		p1=p1->next;
	}

}


main()
{
	int i,n,a[100],j;
	struct patient
	{
		char id[10];
		int age;
	}
	s[100];

	scanf("%d",&n);
    for (i=0;i<n;i++)
	{
		scanf("%s%d",s[i].id,&s[i].age);
    }
	while (1)
	{
		int max=0;
		for (i=0;i<n;i++)
	{
		if (s[i].age>s[max].age)
			max=i;
    }
	if (s[max].age>=60)
	{
		printf("%s\n",s[max].id);
        s[max].age=0;
	}
	else break;
	}
	for (i=0;i<n;i++)
	if (s[i].age>0)
		printf("%s\n",s[i].id);

}


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

              p11->next=head1;
	      head1=p11;
	      break;
	     }
	   }
	  if(t==NULL)
          {
            q->next=p11;
            p11->next=NULL;
          }
	}
     }

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

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


struct people
{
	int order;
	char ID[10];
    int age;
}per[100];
struct old
{
	int orders;
	char IDs[10];
	int ages;
}elder[100];
int main()
{
	int n,i,j,t,m,q,r;
	char p[10];
	int b[100],c[100];
    scanf("%d",&n);
	for(i=0;i<=(n-1);i++)
	{
		per[i].order=i;
		scanf("%s %d",per[i].ID,&per[i].age);
		b[i]=strlen(per[i].ID);
	}
	t=0;
	for(i=0;i<=(n-1);i++)
	{
        if(per[i].age>=60)
		{
			elder[t].orders=t;
			strcpy(elder[t].IDs,per[i].ID);
			elder[t].ages=per[i].age;
			t=t+1;
			per[i].age=(-1);
		}
	}
    for(i=0;i<=(t-1);i++)
	{
		for(j=0;j<=(t-i-1);j++)
		{
			if(elder[j].ages<elder[j+1].ages)
			{
				m=elder[j].ages;
				strcpy(p,elder[j].IDs);
				q=elder[j].orders;
				strcpy(elder[j].IDs,elder[j+1].IDs);
				elder[j].ages=elder[j+1].ages;
				elder[j].orders=elder[j+1].orders;
				elder[j+1].ages=m;
				strcpy(elder[j+1].IDs,p);
				elder[j+1].orders=q;
			}
		}
	}
	for(i=0;i<=(t-1);i++)
	{
       for(j=0;j<=(t-1-j);j++)
	   {
		   if(elder[j].ages==elder[j+1].ages)
		   {
			   if(elder[j].orders>elder[j+1].orders)
			   {
				    m=elder[j].ages;
			    	strcpy(p,elder[j].IDs);
			    	q=elder[j].orders;
			    	strcpy(elder[j].IDs,elder[j+1].IDs);
			    	elder[j].ages=elder[j+1].ages;
			    	elder[j].orders=elder[j+1].orders;
			    	elder[j+1].ages=m;
			     	strcpy(elder[j+1].IDs,p);
			    	elder[j+1].orders=q;
			   }
		   }
	   }
	}
    for(i=0;i<=(t-1);i++)
	{
         printf("%s\n",elder[i].IDs);
	}
	for(i=0;i<=(n-1);i++)
	{
		if(per[i].age!=(-1))
		{
			printf("%s\n",per[i].ID);
		}
	}
	return 0;
}


int main()
{
    struct br
	{
		char id[10];
		int age;
	} *patients,t;
	int n,i,j;
	scanf("%d",&n);
	patients=(struct br *)malloc(sizeof(struct br)*n);

    for (i=0; i<n; i++) {
        scanf("%s%d", patients[i].id, &patients[i].age);
    }
	for (i=0; i<n; i++) {
        for (j=n-1; j>i; j--) {
            if (patients[j].age >= 60 &&
                patients[j].age > patients[j-1].age) {
                t = patients[j];
                patients[j] = patients[j-1];
                patients[j-1] = t;
            }
        }
    }

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

    return 0;
}


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

int main()
{
	int n,i,j=0,max=0;
	struct myturn patient[100];
	scanf("%d",&n);			//	???????
	for(i=0;i<n;i++){
		scanf("%s%d",&patient[i].ID,&patient[i].age);
		if(patient[i].age>max) max=patient[i].age;			//	?????????
	}
	if(max>=60){		 // ??????max??????????
		for(max;max>=60;max--){
			for(i=0;i<n;i++){
				if(patient[i].age==max) {
					printf("%s\n",patient[i].ID);			//???????????0???flag?
					patient[i].age=0; j++;}	}	}	}
	for(i=0;i<n;i++){		// ??????ID?
		if(patient[i].age!=0){ printf("%s",patient[i].ID);
		j++;
		if(j<n) printf("\n");}
	}
	return 0;
}


int main(){
    struct old{
        char ID[10];
        int age;
    };
    struct old ill[100];
    struct old t1[100];
    struct old t2[100];
    struct old t;
    int n,i,j=0,k=0,num60=0,num0=0,b[100]={0},p,num=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s",ill[i].ID);
        scanf("%d",&ill[i].age);
        if(ill[i].age>=60){
            t1[j]=ill[i];
            j++;
            num60++;
        }
        else{
            t2[k]=ill[i];
            k++;
            num0++;
        }
    }
    for(i=0;i<num60;i++){
        p=0;
        for(j=0;j<num60;j++){
            if(t1[j].age>p&&b[j]==0){
                p=t1[j].age;
                num=j;
            }
        }
        printf("%s\n",t1[num].ID);
        b[num]=1;
    }
    for(i=0;i<num0;i++){
        printf("%s\n",t2[i].ID);
    }
    return 0;
}


int main()
{
	struct patient{char id[10];int a;}patients[100];
	struct old{char ido[10];int ao;}olds[100];
	struct young{char idy[10];int ay;}youngs[100];
	int n,y=0,o=0,so=0,sy=0,e;
	scanf("%d",&n);
	char f[10];
	for(int j=0;j<n;j++)
	{
		scanf("%s",patients[j].id);
		scanf("%d",&patients[j].a);
		if(patients[j].a<60)
		{
			strcpy(youngs[y].idy,patients[j].id);
			youngs[y].ay=patients[j].a;
			y++;
		}
		if(patients[j].a>=60)
		{
			strcpy(olds[o].ido,patients[j].id);
			olds[o].ao=patients[j].a;
			o++;
		}
	}
		for(int r=o-1;r>0;r--)
		{
			for(int i=0;i<r;i++)
			{
				if(olds[i].ao<olds[i+1].ao)
				{
					e=olds[i+1].ao;
					olds[i+1].ao=olds[i].ao;
					olds[i].ao=e;
					strcpy(f,olds[i+1].ido);
					strcpy(olds[i+1].ido,olds[i].ido);
					strcpy(olds[i].ido,f);
				}
			}
		}
		for(int l=0;l<=o-1;l++)
		{
			printf("%s\n",olds[l].ido);
		}
		for(int m=0;m<=y-1;m++)
		{
			printf("%s\n",youngs[m].idy);
		}
	return 0;
}


 struct pat
{
  char id[10];
  int age;
  struct pat *next;
 };
 void main()
 {
	 struct pat *head,*p;
	 int i,n;
     void search(struct pat *head,int n);
	 scanf("%d",&n);
	 head=(struct pat*)malloc(sizeof(struct pat));
	 p=head;p->next=NULL;
	 scanf("%s %d",p->id,&p->age);
	 for(i=1;i<n;i++)
	 {
		 p->next=(struct pat*)malloc(sizeof(struct pat));
		 p=p->next;
		 scanf("%s %d",p->id,&p->age);
		 p->next=NULL;
	 }
	 search(head,n);
 }
  void search(struct pat *head,int n)
 {
	 int i,j=0,k=0;
	 struct pat *t,*m,*p,*head1,*head2;
	 struct pat *sort(struct pat *head1,int j);
	 void print(struct pat *head1,struct pat *head2,int j,int k);
	 p=head;
	 t=(struct pat*)malloc(sizeof(struct pat));
	 m=(struct pat*)malloc(sizeof(struct pat));
     for(i=0;i<n;i++)
	 {
		 if(p->age>=60)
		 {
			 j++;
			 if(j==1) head1=t;
			 strcpy(t->id,p->id);t->age=p->age;
		     t->next=(struct pat*)malloc(sizeof(struct pat));
		     t=t->next;t->next=NULL;
		 }
		 else
		 {
			 k++;
			 if(k==1) head2=m;
			 strcpy(m->id,p->id);m->age=p->age;
		     m->next=(struct pat*)malloc(sizeof(struct pat));
		     m=m->next;m->next=NULL;
		 }
		 p=p->next;
	 }
	 sort(head1,j);
	 print(head1,head2,j,k);
  }
  struct pat *sort(struct pat *head1,int j)
  {
	 int i,l,t;
	 char a[10];
	 struct pat *p1,*p2;
     for(i=0;i<j-1;i++)
	 {
		 p1=head1;
		 for(l=0;l<j-i-1;l++)
		 {
			p2=p1;p1=p1->next;
           if(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);
		   }
		 }
	 }
	 return(head1);
  }
  void print(struct pat *head1,struct pat *head2,int j,int k)
  {
	int i;
	struct pat *p;
    p=head1;
    for(i=0;i<j;i++)
	{
		printf("%s\n",p->id);
		p=p->next;
	}
	p=head2;
	for(i=0;i<k;i++)
	{
			printf("%s\n",p->id);
			p=p->next;
	}
  }


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

void main()
{
   struct bing  peo[120],old[120],young[120],temp;
   int i,j,n,num1=0,num2=0;

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

	for(i=0;i<n;i++)
	{
		if(peo[i].age>=60)
		{
			old[num1]=peo[i];
			num1=num1+1;
		}
		else
		{
			young[num2]=peo[i];
			num2=num2+1;
		}
	}

	for(i=0;i<num1-1;i++)
		for(j=0;j<num1-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<num1;i++)
		printf("%s\n",old[i].id);
	for(i=0;i<num2;i++)
		printf("%s\n",young[i].id);

}


struct point{
		char id[10];
		int age;
	}old[100],small[100];

int main(){
	int n,i,j,o=0,s=0,t,m;
//	char x[10];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		char x[10]={'\0'};
		t=0;
		scanf("%s %d",x,&t);
		if(t>=60){
			strcpy(old[o].id,x);
			old[o].age=t;
			o++;

		}else{
			strcpy(small[s].id,x);
			small[s].age=t;
			s++;
		}
	}
	char p[10];
	for(i=0;i<o;i++){
		for(j=1;j<o-i;j++){
			if(old[i].age>=old[i+j].age){
				m=old[i+j].age;
				old[i+j].age=old[i].age;
				old[i].age=m;
				strcpy(p,old[i+j].id);
				strcpy(old[i+j].id,old[i].id);
				strcpy(old[i].id,p);
			}
		}
	}

	for(i=o-1;i>=0;i--){
		printf("%s\n",old[i].id);
	}
	for(i=0;i<s;i++){
		printf("%s\n",small[i].id);
	}
}


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

	for(i=0;i<n;i++)
	{
		if(pa[i].old>=60)
		{
			pao[j]=pa[i];
				j++;
		}
		else
		{
			pay[k]=pa[i];
			k++;
		}
	}

	for(i=0;i<j-1;i++)
		for(t=0;t<j-1-i;t++)
			if(pao[t].old<pao[t+1].old)
			{
				temp=pao[t];
				pao[t]=pao[t+1];
				pao[t+1]=temp;
			}

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


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


struct man
{
 char num[10];
 int age;
 int nu;
 struct man *next;
};
int f(char *a,int b,int n1,char *c,int d,int n2)
{int sum;
 if(b>=60&&d>=60)
 {if(b>d)
 sum=1;
 else if(b<d)
  sum=-1;
 else
  sum=n2-n1;
 }
 else if(b>=60&&d<60)
  sum=1;
    else if(b<60&&d>=60)
        sum=-1;
 else
        sum=n2-n1;
 return(sum);
}
struct man *insert(struct man *head,struct man *stud,int n)
{struct man *p0,*p1,*p2;
p1=head;
p0=stud;
scanf("%s %d",p0->num,&p0->age);
p0->nu=n+1;
p0->next=NULL;
if(head==NULL)
head=p0;
else
{while((f(p0->num,p0->age,p0->nu,p1->num,p1->age,p1->nu)<0)&&(p1->next!=NULL))
{p2=p1;
p1=p1->next;}
if(f(p0->num,p0->age,p0->nu,p1->num,p1->age,p1->nu)>0)
{if(head==p1)head=p0;
else p2->next=p0;
p0->next=p1;}
else
{p1->next=p0;}
}
return(head);
}
void print(struct man *head,int n)
{struct man *p;
int k;
p=head;
for(k=0;k<n;k++)
{printf("%s\n",p->num);
p=p->next;}
}
void main()
{
	int n,k;
struct man *head,*stu;
head=NULL;
scanf("%d",&n);
for(k=0;k<n;k++)
{stu=(struct man *)malloc(LEN);
	head=insert(head,stu,k);
}
print(head,n);
}


struct sick
{
	int age;
	char id[100];
	struct sick *next;
};
struct sick *insert(struct sick *head,struct sick *new1)
{
	struct sick *p0,*p1,*p2,*p;
	p1=head;
	p0=new1;
	if(head==NULL)
	{
		head=p0;
		p0->next=NULL;
	}
	else
	{
	 	if(p0->age<60)
		{
			p1=head;
			while(p1!=NULL)
			{
				p2=p1;
				p1=p1->next;
			}
			p2->next=p0;
			p0->next=NULL;
		}
		else
		{
		   while((p1->age>=p0->age)&&(p1->next!=NULL)) /*?????????????????*/
		   {
			p2=p1;
			p1=p1->next;
		   }
		   if(p0->age>p1->age)      /*?????????????????*/
		   {
			 if(head==p1)
				head=p0;
			 else
				p2->next=p0;
			 p0->next=p1;
		   }
	 	   else
		   {
			p1->next=p0;
			p0->next=NULL;
		   }
		}
	}
	return(head);
}
void main()
{
	struct sick *head,*p;
	int n,i;
	head=NULL;  /*head????NULL????,????????*/
	scanf("%d",&n);
	struct sick *insert(struct sick *head,struct sick *new1);/*??*/
	for(i=0;i<n;i++)
	{
		p=(struct sick*)malloc(sizeof(struct sick));
        scanf("%s %d",p->id,&p->age);
		head=insert(head,p);
	}
	p=head;
	do
	{
		printf("%s\n",p->id);
		p=p->next;
	}while(p!=NULL);
}


void main()
{int n,i,j,t;
scanf("%d",&n);
struct patient
{char id[10];
int age;
struct patient *next;
} *p1,*p2,*head,*p[100],*temp;
p1=p2=head=(struct patient *)malloc(sizeof(struct patient));
scanf("%s%d",p1->id,&p1->age);
for(i=2;i<=n;i++)
{p1=(struct patient *)malloc(sizeof(struct patient));
scanf("%s%d",p1->id,&p1->age);
p2->next=p1;
p2=p1;
}
p2->next=NULL;
  for(t=0,p1=head;p1!=NULL;p1=p1->next)
    if(p1->age>=60)
	{  p[t]=p1;
	   t++;
	}

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

for(i=0;i<=t-1;i++)
printf("%s\n",p[i]->id);

for(p1=head;p1!=NULL;p1=p1->next)
if(p1->age<60)
 printf("%s\n",p1->id);

}


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

struct patient
{
char str[10];
int age;
}pat[100],pat2[100],patt;

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

for(i=0;i<n;i++)
if (pat[i].age>=60) {pat2[j]=pat[i];j++;t++;}

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

for(i=0;i<t;i++)
printf("%s\n",pat2[i].str);

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

}


void main()
{
	int n;
	scanf("%d",&n);
	struct patient
	{
		char name[16];
		int age;
	};
	struct patient p[n];
	int i,j;
	for(i=0;i<n;i++)
	scanf("%s %d",p[i].name,&p[i].age);
	struct patient q[n];
	for(i=0,j=0;i<n;i++)
	if(p[i].age>=60)strcpy(q[j].name,p[i].name),q[j].age=p[i].age,j++;
	int k,t;
	char s[16];
	for(k=0;k<j;k++)
	{
		for(i=0;i<j-k-1;i++)
		if(q[i].age<q[i+1].age)
		strcpy(s,q[i].name),strcpy(q[i].name,q[i+1].name),strcpy(q[i+1].name,s),
		t=q[i].age,q[i].age=q[i+1].age,q[i+1].age=t;
	}
	for(i=0;i<n;i++)
	if(p[i].age<60)strcpy(q[j].name,p[i].name),q[j].age=p[i].age,j++;
	for(i=0;i<n;i++)
	puts(q[i].name);
	putchar('\n');
}


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


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

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


struct bing
{
	char id[10];
	int age;
}person[100],old[100];

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


struct bin
{
	char ID[10];
	int age;
	struct bin *next;
};
void main()
{
	struct bin *head,*p,*p1,*p2,*p3;
	int m,n,i,j,k;
	scanf("%d",&n);
	p=(struct bin*)malloc(sizeof(struct bin));
	scanf("%s%d",&p->ID,&p->age);
	head=p3=p;
	p->next=0;
	for(i=1;i<n;i++)
	{
		p=(struct bin*)malloc(sizeof(struct bin));
	    scanf("%s%d",&p->ID,&p->age);
		if(p->age<60)
		{
			p3->next=p;
			p->next=0;
			p3=p;
		}
		else
		{
			if(p->age>head->age)
			{
				p->next=head;
				head=p;
			}
			else if(p->age<=p3->age)
			{
			    p3->next=p;
			    p->next=0;
			    p3=p;
			}
			else
			{
				p1=head;
				p2=p1->next;
				while(p2->age>=p->age)
				{
					p1=p1->next;
					p2=p2->next;
				}
				p1->next=p;
				p->next=p2;
			}
		}
	}
	for(;head!=0;head=head->next)
	{
		printf("%s\n",head->ID);
	}
}


void main()
{
	  int n,m,i,j,max,l,sign=0;
	  scanf("%d",&n);
      struct tt
	  {
		  char pp[10];
		  int age;
		  struct tt *next;
	  };
	  struct tt *head,*p1,*p2,*p3;
	  head=(struct tt * )malloc(LEN);
	  p1=head; p2=head;
	  scanf("%s",head->pp);
	  scanf("%d",&head->age);
	  for(i=1;i<n;i++)
	  {
		  p1=(struct tt * )malloc(LEN);;
		  p2->next=p1;
		  scanf("%s",p1->pp);
	      scanf("%d",&p1->age);
		  p2=p1;
	  }
	  p2->next=NULL;
      for(i=1;i<=n;i++)
	  {
		  if(sign==1)
		  {
			  printf("%s\n",head->pp);
			  head=head->next;
		  }
		  else if(sign==0)
		  {
		     max=(-1);
		     for(p2=NULL,p1=head;p1!=NULL;p1=p1->next)
			 {
			      if(p1->age>max) {max=p1->age; p3=p2;}
			      p2=p1;
			 }
			 if(max<60) {sign=1; i--; continue;}
			 else if(max>=60)
			 {
                 if(p3==NULL)
				 {
					 printf("%s\n",head->pp);
			         head=head->next;
				 }
				 else
				 {
					 p1=p3->next;
					 printf("%s\n",p1->pp);
					 p3->next=p1->next;
				 }
			 }
		 }
	  }
}


main()
{
   struct h
   {
      char name[11];
	  int mun;
	  struct h *next;
   } *p,*q,*head,*s,*t,*last;
int n;
scanf("%d",&n);
 q=len;
 s=head=q;
 scanf("%s %d", head->name,&head->mun);
 q->next=NULL;
 last=q;
 int i;
 for(i=0;i<n-1;i++)
 {
  s=head;
  q=len;
  q->next=NULL;
  scanf("%s %d", q->name,&q->mun);
  if(q->mun>=60)
  {
	  while((s!=NULL)&&((q->mun)<=(s->mun)))
	  {
		  t=s;
          s=s->next;
	  }
  if(s==head) {q->next=head;head=q;}
     else
	 {
		 if(t==last) last=q;
		 t->next=q;q->next=s;
	 }

 }
  else
 {
	  last->next=q;
	  last=q;
 }
 }

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

}


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->o==0)
				continue;
			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);
}


void main()
{
	int n,age[100],i,j,m=0,p,h;
	char hao[100][10],mid[10];
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%s %d",hao[i],&age[i]);
	for(i=0;i<n;i++)
		if(age[i]>=60)
		{
			m=m+1;
			for(j=i;j>=m;j--)
			{
				strcpy(mid,hao[j]);
				strcpy(hao[j],hao[j-1]);
				strcpy(hao[j-1],mid);
				h=age[j];
				age[j]=age[j-1];
				age[j-1]=h;
			}
		}

	for(i=0;i<m;i++)
		for(j=0;j<m-i-1;j++)
			if(age[j]<age[j+1])
			{
				strcpy(mid,hao[j]);
				strcpy(hao[j],hao[j+1]);
				strcpy(hao[j+1],mid);
				h=age[j];
				age[j]=age[j+1];
				age[j+1]=h;
			}

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


struct patient
{
	char ID[10];
	int age;
}pat[100];
int main()
{
	struct patient t;
	struct patient num[100];
	int n,i,j,a=1;
	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)
	   { num[a-1]=pat[i];
		 a++;}
    }
	for(i=0;i<a-2;i++)
	{ for(j=0;j<a-2-i;j++)
	if(num[j].age<num[j+1].age)
	  { t=num[j];
	    num[j]=num[j+1];
	    num[j+1]=t;}
	}
    for(i=0;i<a-1;i++)
    printf("%s\n",num[i].ID);
	for(i=0;i<n;i++)
	{ if(pat[i].age<60)
	  printf("%s\n",pat[i].ID);}

  return 0;
}


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