int i,j,k,m,n,l,r;
int flag=1;
int minleft,maxright;
int b[20000];
int main(){
    minleft=50001;
    maxright=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&l);
        scanf("%d",&r);
        if(l<=minleft)minleft=l;
        if(r>=maxright)maxright=r;
        for(j=l;j<r;j++){
            b[j]=1;
        }
    }
    for(k=minleft;k<=maxright-1;k++)
    if(b[k]==0){flag=0;break;}
    if(flag==0)printf("no\n");
    else printf("%d %d\n",minleft,maxright);
    return 0;
}


int main(){
	int n,i,a[50000],b[50000],min,max;
	double j;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d",&a[i],&b[i]);}
	min=a[0];max=b[0];
	for(i=1;i<n;i++){
		if(a[i]<min){
			min=a[i];}
		if(b[i]>max){
			max=b[i];}}
	for(j=1.0*min+0.1;j<=max;j++){
		for(i=0;i<n;i++){
			if(j<a[i]||j>b[i]){continue;}
			else{break;}}
		if(i==n){
			printf("no");
			return 0;}
	}
	printf("%d %d",min,max);
	return 0;
}


int main(){
	int n;
	scanf("%d",&n);
	struct block{
		int a,b;
	}bk[10000];
	for(int q=0;q<n;q++){
		scanf("%d %d",&bk[q].a,&bk[q].b);
	}
	for(int k=1;k<=n;k++){
        int e=0;
        for(int i=0;i<n-k;i++){
            if(bk[i].a>bk[i+1].a){
            e=bk[i+1].a;
            bk[i+1].a=bk[i].a;
            bk[i].a=e;
			e=bk[i+1].b;
            bk[i+1].b=bk[i].b;
            bk[i].b=e;
			}
		}
	}
	int max=bk[0].b,min=bk[0].a;
	for(int d=0;d<n;d++){
		if(max<=bk[d].b){
			max=bk[d].b;
		}
		if(min>=bk[d].a){
			min=bk[d].a;
		}
	}
	int pd=0;
	for(double t=1.0*min;t<max;t+=0.5){
		pd=0;
		for(int f=0;f<n;f++){
			if(t>=bk[f].a&&t<=bk[f].b){
				pd=1;
				break;
			}
		}
		if(pd==0){
			printf("no");
			return 0;
		}
	}
	printf("%d %d\n",min,max);
	return 0;
}


int a[50010],b[50010];

int _ins(int temp,int j)
{
    if (a[j]>temp) return -1;
    return b[j]>temp?b[j]:temp;
}

int main()
{
    int n,e,f;
    scanf("%d",&n);
    for (int i=0;i<=n-1;i++)
        scanf("%d %d",&a[i],&b[i]);

    for(int k=1;k<n;k++){
        for(int i=0;i<n-k;i++){
            if(a[i]>a[i+1]){
                e=a[i+1];
                a[i+1]=a[i];
                a[i]=e;
                f=b[i+1];
                b[i+1]=b[i];
                b[i]=f;
            }
        }
    }

    int temp=b[0];

    for (int j=1;j<=n-1;j++)
    {
        if ((temp=_ins(temp,j))==-1)
            break;
    }

    if (temp==-1)
        printf("no\n");
    else
        printf("%d %d\n",a[0],temp);

    return 0;
}


int main(){
  int zuo[10000],you[10000],n,i,j,a,b=0;
  double s;
  scanf("%d\n",&n);
  for(i=0;i<n;i++){
       scanf("%d %d\n",&zuo[i],&you[i]);
       if(b<you[i])b= you[i];
   }
   a=zuo[0];
   for(i=1;i<n;i++)
if(a>zuo[i])a=zuo[i];
   for(s=a+0.5;s<b;s++){
      for(j=0;j<n;j++){
         if(zuo[j]<s&&you[j]>s) break;
         else continue;
}
if(j==n)break;
}

   if(s>b)  printf("%d %d",a,b);
    else printf("no");
   return 0;
}


int main()
{
	struct qujian
	{
		int a;
		int b;
	}qj[50000],temp;
	int n,i,j,max;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d",&qj[i].a,&qj[i].b);
	}
	for(i=n-1;i>0;i--){
		for(j=0;j<i;j++){
			if(qj[j].a>qj[j+1].a){
				temp.a=qj[j].a;
				temp.b=qj[j].b;
				qj[j].a=qj[j+1].a;
				qj[j].b=qj[j+1].b;
				qj[j+1].a=temp.a;
				qj[j+1].b=temp.b;
			}
		}
	}
	max=qj[0].b;
	for(i=0;i<n-1;i++){
		if(max<qj[i].b){
			max=qj[i].b;
		}
		if(max<qj[i+1].a){
			printf("no");
			break;
		}
	}
	if(i==n-1){
		printf("%d %d",qj[0].a,max);
	}
	return 0;
}


//??????????????????????

int getMin(int ai[], int ais[])//?????
{
    int i, min = 0;
	for (i = 1; i < MAX && ai[i] != -1; i++) {
		if (ai[i] < ai[min])
			min = i;
	}
	ais[min] = 0;
	return min;
}
int getMax(int bi[])//?????
{
	int i, max = 0;
	for (i = 1; i < MAX && bi[i] != -1; i++) {
		if (bi[i] > bi[max])
			max = i;
	}
	return max;
}
int hasEqual(int a, int ai[], int ais[]) {
	int i;
	for (i = 0; i < MAX; i++) {
		if (ai[i] <= a && ais[i] == 1) {
			ais[i] = 0;
			return i;
		}
	}
	return -1;
}
int main() {
	int ai[MAX], bi[MAX];
	int aischeck[MAX];
	int n = 0, i, temp;
	for (i = 0; i < MAX; i++)//???
	{
		ai[i] = -1;
		bi[i] = -1;
		aischeck[i] = 1;
	}
	int mi, ma, min, max;
	scanf("%d", &n);

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

	mi = min = getMin(ai, aischeck);
	ma = max = getMax(bi);
	temp = hasEqual(bi[min], ai, aischeck);

	while (temp != -1)//????
	{
		temp = hasEqual(bi[temp], ai, aischeck);
		if (bi[temp] == bi[ma]) {
			printf("\n%d %d", ai[mi], bi[ma]);
			return 0;
		}
	}
	printf("no\n");
}

/*
int main(){
    int n,min,max;
    int add=0;
    int a[100000];
    int b[100000];
    int sz[100000];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d%d",&a[i],&b[i]);
   // printf("%d%d\n",a[i],b[i]);
}
    for(int i=0;i<n;i++){
        if(i==0)min=a[i];
        else if(i!=0&&a[i]<min)
            min=a[i];

    }
    for(int i=0;i<n;i++){
        if(i==0)max=b[i];
        else if(i!=0&&b[i]>max)
            max=b[i];

    }
    for(int i=min;i<=max;i++){
        sz[i]=1;
    }
    for(int i=0;i<n;i++){
    for(int j=a[i]+0.5;j<=b[i];j++){
        sz[j]=0;
    }
    }
    for(int i=min;i<=max;i++){
        add=add+sz[i];
    }
    if(add>0)printf("no");
    else printf("%d %d",min,max);
}

*/


int main(){
	int n,i,j,max,min,p,q,s;
	s=0;
	scanf("%d",&n);
	int * a;
	int * b;
	int * c;
	a=(int*)malloc(sizeof(int)*n);
	b=(int*)malloc(sizeof(int)*n);
	for(i=0;i<n;i++){
		scanf("%d %d",&(a[i]),&b[i]);
	}
	max=b[0];min=a[0];
	for(i=1;i<n;i++){
		if(min>a[i]) min=a[i];
		if(max<b[i]) max=b[i];
	}
	q=max-min;
	c=(int*)malloc(sizeof(int)*q);
	for(i=0;i<q;i++){
		c[i]=1;
	}
	for(i=0;i<n;i++){
		for(j=a[i]-min;j<b[i]-min;j++){
			c[j]=0;
		}
	}
	for(i=0;i<q;i++){
		s+=c[i];
	}
	if(s>=1)
		printf("no");
	if(s==0)
		printf("%d %d",min,max);
	free(a);free(b);free(c);
	return 0;
}


int main(){
	int n;
int tag[10000];
	struct part{
		int start;
		int end;
	};
	struct part number[50000];//???????
	int i,j,max,min,result;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&number[i].start,&number[i].end);
	}//????
	max=0;
	min=10000;
	result=0;

	for(i=0;i<10000;i++) tag[i]=1;//????????1~10000????1????????????????0
	for(i=0;i<n;i++){
			if(number[i].end>max) max=number[i].end;
			if(min>number[i].start) min=number[i].start;

	}//?????end????start
	for(i=0;i<n;i++)//{
		for(j=number[i].start;j<number[i].end;j++)//{
	//		if(number[i].start<j<=number[i].end&&tag[j]==1){
				tag[j]=0;
		//	}
	//	}
//	}//?????????tag???0
	for(i=min+1;i<max;i++){
		if(min<i<=max){
			if(tag[i]==1){
				printf("no");
				result=1;
				break;
			}
		}
	}
	if(result==0) printf("%d %d",min,max);
	return 0;
}


int main ()
{
int n,a,b,pau1,pau2;
scanf("%d",&n);
struct haha
{
int begin;
int end;
}
qj[50000];
struct haha pau;
for (int i1=0;i1<n;i1++)
{
    scanf("%d%d",&qj[i1].begin,&qj[i1].end);
}
for (int i3=0;i3<n;i3++)
{
   for (int i4=n-1;i4>0;i4--)
      {
        if (qj[i4].begin<qj[i4-1].begin)
           {pau1=qj[i4].begin;qj[i4].begin=qj[i4-1].begin;qj[i4-1].begin=pau1;pau2=qj[i4].end;qj[i4].end=qj[i4-1].end;qj[i4-1].end=pau2;}
      }
}

for (int i2=0;i2<n;i2++)
{
    for (int i5=i2+1;i5<n;i5++)
    {
        if (qj[i2].begin==qj[i5].begin&&qj[i2].end==qj[i5].end){for (int jj=i5;jj<n;jj++)
{qj[jj]=qj[jj+1];}n--;}
        if (qj[i2].end>=qj[i5].begin){if(qj[i5].end>qj[i2].end){qj[i2].end=qj[i5].end;}for (int jj=i5;jj<n;jj++)
{qj[jj]=qj[jj+1];}n--;i5=i2;}

    }
}
if (n==1){printf("%d %d",qj[0].begin,qj[0].end);}else{printf("no");}
return 0;
}


int main(){
	int n;
	int i;
	int sections[50001][2];
	int mark[50001];
	scanf("%d" , &n);
	for(i = 0; i < n; i++){
		scanf("%d %d" , &sections[i][0] , &sections[i][1]);
		mark[i] = 0;
	}
	int left;
	int right;
	int nmin;
	int node;
	int count;
	count = n;
	for(i = 0; i < n; i++){
		if(i == 0){
			nmin = sections[0][0];
			left = sections[0][0];
			right = sections[0][1];
			node = 0;
		}
		else{
			if(sections[i][0] < nmin){
				nmin = sections[i][0];
				left = sections[i][0];
				right = sections[i][1];
				node = i;
			}
		}
	}
	mark[node] = 1;
	count--;
	int temp = count;
	int flag = 0;
	while(count > 0){
		for(i = 0; i < n; i++){
			if(mark[i] == 0){
				if(sections[i][1] <= right){
					mark[i] = 1;
					count--;
				}
				else if(sections[i][0] <= right){
					right = sections[i][1];
					mark[i] = 1;
					count--;
				}
			}
		}
		if(count != 0 && count == temp){
			flag = 1;
			break;
		}
		temp = count;
	}
	if(flag == 1){
		printf("no");
	}
	else{
		printf("%d %d" , left , right);
	}
	return 0;
}


int main()
{
int n,a,b;
scanf("%d",&n);
int shuzu[10000],Shuzu[10000],p,q,num=0;
for(int i=0;i<n;i++)
scanf("%d%d",&shuzu[i],&Shuzu[i]);
a=shuzu[0];
for(int j=1;j<n;j++)
if(a>shuzu[j]) a=shuzu[j];
b=Shuzu[0];
for(int l=1;l<n;l++)
if(b<Shuzu[l]) b=Shuzu[l];
p=shuzu[0];
q=Shuzu[0];
for(int x=1;x<=n;x++,num=0)
 {
  for(int y=1;y<n;y++)
    {
     if(!(shuzu[y]>q)&&!(Shuzu[y]<p))
      {  num++;
         if(shuzu[y]<p) p=shuzu[y];
         if(Shuzu[y]>q) q=Shuzu[y];
      }
    }
  if(x==n) break;
 }
if(num==n-1)
printf("%d %d",a,b);
else
printf("no");
return 0;
}


int main() {
	int n,i,a=0,begin[50000],end[50000],min,max;
	double b;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d%d",&begin[i],&end[i]);
	min=begin[0];
	max=end[0];
	for(i=0;i<n;i++){
		if(begin[i]<=min)
			min=begin[i];
		if(end[i]>=max)
			max=end[i];
	}
    for(b=min*1.0+0.1;b<max;b+=1.0){
		for(i=0;i<n;i++){
			if(b>begin[i]&&b<end[i]){
				a++;
				break;
			}
		}
	}
	if(a==max-min){
		printf("%d %d\n",min,max);
	}else{
		printf("no");
	}
	return 0;
}


int main()
{
	int n;
	int i,j;
	scanf("%d",&n);
	int num[20002]={0};
	int a,b;
	int max=0,min=10000;
	for(i=0;i<n;i++)
	{
		scanf("%d%d",&a,&b);
		if(min>a)min=a;
		if(max<b)max=b;
		for(j=2*a;j<=2*b;j++)
			num[j]=1;
	}
	int total=1;
	for(i=2*min;i<=2*max;i++)
	{
		total=total*num[i];
	}
	if(total==0)printf("no\n");
	else
		printf("%d %d\n",min,max);
	return 0;
}


struct array
{
	int s;
	int e;
}array[50000];
int main()
{
	int n,i,j,t,end;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d%d",&(array[i].s),&(array[i].e));
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			if(array[i].s>array[j].s){
				t=array[i].s;
				array[i].s=array[j].s;
				array[j].s=t;
				t=array[i].e;
				array[i].e=array[j].e;
				array[j].e=t;
			}
		}
	}
	t=0;
	end=array[0].e;
	for(i=0;i<n;i++){
		if(end>=array[i].s){
			if(end<array[i].e){
				end=array[i].e;
			}

		}
		else{
			t=1;
			break;
		}
	}
	if(t==1) printf("no\n");
	else printf("%d %d\n",array[0].s,end);
	return 0;
}


int main(){
	int n,i,j,a,b,flag=0,z[10000]={0};
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d%d",&a,&b);
        if(a-b==0)z[a-1]=1;
        for(j=a;j<b;j++)z[j]=1;
    }
    for(i=0;i<10000;i++)
    {
        if(flag==0)
        if(z[i]==1){
            a=i;
            flag=1;
            continue;
        }
        if(flag==1)
        if(z[i]==1)continue;
        else
        {
            b=i;
            flag=2;
            continue;
        }
        if(flag==2)
        if(z[i]==1)
        {
            flag=3;
            break;
        }
    }
    if(flag!=2) printf("no");
    else printf("%d %d",a,b);
    return 0;
}


int main() {
   int n;
    scanf("%d",&n);

    struct interval{int left;int right;}itv[n];

    int i;
    int min,max;
    min=100000;
    max=0;
    for(i=0;i<n;i=i+1)
    {
        scanf("%d %d",&(itv[i].left),&(itv[i].right));
        if(itv[i].left<min){min=itv[i].left;}
        if(itv[i].right>max){max=itv[i].right;}

    }

    int s;
    s=1;
    int j;

    for(i=0;i<n;i=i+1)//????????????????????????????????
    {
        if(itv[i].left!=min)
        {
            s=0;
            for(j=0;j<n;j=j+1)
            {
                if(j!=i)
                {
                    if(itv[i].left>=itv[j].left && itv[i].left<=itv[j].right){s=1;}

                }
            }
            if(s==0){break;}
        }
    }

    if(s==0){printf("no");}
    else{printf("%d %d",min,max);}
    return 0;
}


int main() {
    int n,i,m,max,min,p,s=0 ;
    double x;
    scanf("%d",&n);
    int zdd[n],ydd[n] ;
    for(i=0;i<n;i++) {scanf("%d %d",&zdd[i],&ydd[i]);}
    min=zdd[0] ;max=ydd[0] ;
        for(i=0;i<n;i++) {
            if(zdd[i]<min) {
                min=zdd[i];
            }
            if(max<ydd[i]) {
                max=ydd[i];
        }
    }
    int y[max] ;
    for(i=min;i<max;i++) {
        y[i]=1 ;
    }
    for(x=min+0.5;x<=max;x++) {
        p=0 ;
        for(i=0;i<n;i++) {
        if((x>=zdd[i])&&(x<=ydd[i])){
            p++ ;
        } }
        if(p>0) {s++;}
    }
    if(s==max-min) {printf("%d %d",min,max); }
    else {printf("no");}
    return 0;
}


int main()
{
 	int sz[ROW][COL];
 	int n,row,col,max,min,a;
 	double i;
    scanf("%d",&n);
    for(row=0;row<n;row++){
		for(col=0;col<2;col++){
			scanf("%d",&sz[row][col]);
			}
		}
	for(row=0;row<n;row++){
		if(row==0){
			min=sz[row][0];
			}
		else{
			if(sz[row][0]<min){
				min=sz[row][0];
				}
			}
		}
	for(row=0;row<n;row++){
		if(row==0){
			max=sz[row][1];
			}
		else{
			if(sz[row][1]>max){
				max=sz[row][1];
				}
			}
		}
	for(i=min;i<=max;i=i+0.5){
		for(row=0;row<n;row++){
			if(i>=sz[row][0]&&i<=sz[row][1]){
				break;
				}
			else if(row==n-1){
				printf("no");
				return 0;
				}
			}
		if(i==max) printf("%d %d",min,max);
		}

    return 0;
}


int main(){
	int n,start[50000],end[50000],st=10000,e=0,i,point=0;
	double j;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&start[i],&end[i]);
		if(start[i]<st){st=start[i];}
		if(end[i]>e){e=end[i];}}
	for(j=st+0.5;j<e;j++){
		for(i=0;i<n;i++){
			if(j>start[i]&&j<end[i]){
				point++;
				break;}}}
	if(point==e-st){printf("%d %d",st,e);}
	else{printf("no");}
	return 0;
}


struct Interval
{
	int sta;
	int end;
};
int maximum(int a,int b,int c)
{
	if(a>=b&&a>=c) return a;
	if(b>=a&&b>=c) return b;
	if(c>=a&&c>=b) return c;
}
int compare(const void *a,const void *b)
{
	return ((struct Interval *)a)->sta-((struct Interval*)b)->sta;
}
main()
{
	struct Interval a[50000];
	int i,j=0,n,end=0,max=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d %d",&a[i].sta,&a[i].end);
	qsort(a,n,sizeof(struct Interval),compare);
	for(i=0;i<n-1;i++)
	{
		max=maximum(max,max,a[i].end);
		if(max>=a[i+1].sta)
		{
			j++;
			end=maximum(end,a[i].end,a[i+1].end);
		}
		else break;
	}
	if(j==n-1)
		printf("%d %d\n",a[0].sta,end);
	else printf("no");
}


int main ()
{
    struct point{
        int a,b;
    }points[50002],tmp;
    int i,j,n;
    int a,b,c=0;
    scanf("%d\n",&n);
    for(i=0;i<n;i++)
    {scanf("%d%d",&a,&b);
    points[i].a=a;
    points[i].b=b;}
    for(j=n-1;j>0;j--)
    {for(i=0;i<j;i++)
       {if(points[i].a>=points[i+1].a){tmp=points[i+1];
        points[i+1]=points[i];
        points[i]=tmp;}
    }}
     for(j=1;j<n;j++){
      if(points[0].b>=points[j].a){
      if(points[j].b>points[0].b)
      {points[0].b=points[j].b; }
      c++;
      }
     else {c=0;break;}
      }
    if(c!=0)
    {printf("%d %d",points[0].a,points[0].b);}
     else{printf("no\n");}
     return 0;
}


int main(){
	int n,a[LEN],b[LEN],i,k,s=0;
	int min,max;
	double x;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&a[i],&b[i]);
	}
	min=a[0];
	max=b[0];
	for(i=1;i<n;i++){
		if(a[i]<=min){
			min=a[i];
		}
		if(b[i]>=max){
			max=b[i];
		}
	}
	for(x=min;x<=max;x+=0.5){
		for(k=0;k<n;k++){
			if(x>=a[k]&&x<=b[k]){
				s++;
				break;
			}
		}
	}
	if(s!=2*(max-min)+1){
		printf("no");
	}else{
		printf("%d %d",min,max);
	}
	return 0;
}


int main(){
  int n,a,b;
  scanf("%d",&n);
  struct qu{
     int x,y;
  }
  qus[50000];
  int x,y;
  for(int i=0;i<n;i++){
    scanf("%d%d",&x,&y);
	qus[i].x=x;
	qus[i].y=y;
  }
  for(int k=n-1;k>0;k--){
	  for(int j=0;j<k;j++){
		  if(qus[j].x>qus[j+1].x){
			 int tmpx,tmpy;
			 tmpx=qus[j+1].x;
			 tmpy=qus[j+1].y;
			 qus[j+1].x=qus[j].x;
             qus[j+1].y=qus[j].y;
			 qus[j].x=tmpx;
			 qus[j].y=tmpy;
		  }
	  }
  }
  a=qus[0].x,b=qus[0].y;
  for(int r=1;r<n;r++){
	  if(qus[r].x>b){
	     printf("no");
		 return 0;
	  }else{
		  if(qus[r].y>b)
	     b=qus[r].y;
	  }
  }
  printf("%d %d",a,b);
  return 0;
}


int main(){
	int a,n,i,j,mid,result;
	n=0;
	i=0;
	j=0;
	mid=0;
	a=0;
	result=0;
	int line1[100],line2[100],minus[100];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&line1[i],&line2[i]);
	}
	for(i=1;i<=n;i++){
		for(j=0;j<n-i;j++){
			if(line1[j]>line1[j+1]){
				mid=line1[j];
				line1[j]=line1[j+1];
				line1[j+1]=mid;
				mid=line2[j];
				line2[j]=line2[j+1];
				line2[j+1]=mid;
			}
			if(line1[j]==line1[j+1]){
				if(line2[j]>line2[j+1]){
					mid=line2[j];
					line2[j]=line2[j+1];
					line2[j+1]=mid;
				}
			}
		}
	}
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			if((line2[i]>=line1[j])&&(line2[i]<=line2[j])){
				line2[i]=line2[j];
			}
		}
	}
	for(i=0;i<n;i++){
		minus[i]=line2[i]-line1[i];
	}
	for(i=0;i<n;i++){
		if(minus[i]>mid){
			mid=minus[i];
		}
	}
	//for(i=0;i<n;i++){
	//	printf("\n");
	//	printf("%d",minus[i]);
	//}
	for(i=0;i<n;i++){
		if(mid==minus[i]){
			result=i;
		}
	}
	//for(i=0;i<n;i++){
	//	printf("%d ",line1[i]);
	//	printf("%d ",line2[i]);
	//	printf("\n");
	//}
//	printf("\n%d %d",line1[result],line2[result]);
	for(i=0;i<n;i++){
//		printf("\n%d %d",line1[i],line2[i]);
		if((line1[result]<=line1[i])&&(line2[result]>=line2[i])){
			a++;
		}else{
			printf("no");
			break;
		}
	}
	if(a==n){
		printf("\n%d %d",line1[result],line2[result]);
	}
	return 0;
}


int main(){
    int n,i,ks,js,k;
	struct point{
		int x,y;
	}
	qj[NUM],t;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d",&qj[i].x,&qj[i].y);}
	for(k=1;k<=n;k++){
		for(i=0;i<n-k;i++){
			if(qj[i].x>qj[i+1].x){
				t=qj[i+1];
				qj[i+1]=qj[i];
				qj[i]=t;
			}
		}
	}
	ks=qj[0].x;
	js=qj[0].y;
	for(i=1;i<n;i++){
		if(qj[i].x<=js){
			if(qj[i].y>js){
				js=qj[i].y;
			}
		}
		else{
			printf("no");
			return 0;}
	}
	printf("%d %d",ks,js);
	return 0;
}


int main()
{
	int n;
	scanf("%d",&n);
	int xia[GESHU],shang[GESHU];
	for(int p=0;p<n;p++)
	{
		scanf("%d",&xia[p]);
		scanf("%d",&shang[p]);
	}
	int max,min;
	max=shang[0];
	min=xia[0];
	for(int q=0;q<n;q++)
	{
		if(shang[q]>max)
		{
			max=shang[q];
		}
		if(xia[q]<min)
		{
			min=xia[q];
		}
	}
	int reference=0;
	for(double r=min+0.5;r<max;r=r+1)
	{
		reference=0;
		for(int s=0;s<n;s++)
		{
			if(r>=xia[s] && r<=shang[s])
			{
				reference++;
			}
		}
		if(reference==0)
		{
			break;
		}
	}
	if(reference==0)
	{
		printf("no");
	}
	else
	{
		printf("%d %d",min,max);
	}
	return 0;
}


struct qujian
{
	int a;
	int b;
}qj[50000];

int main()
{
	int n,i,j,temp,left,right,k;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d",&qj[i].a,&qj[i].b);
	}
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if(qj[i].a>qj[j].a)
			{
				temp=qj[i].a;
				qj[i].a=qj[j].a;
				qj[j].a=temp;
				temp=qj[i].b;
				qj[i].b=qj[j].b;
				qj[j].b=temp;
			}
		}
	}
	left=qj[0].a;
	right=qj[0].b;
	k=1;
	while(k>0)
	{
		if(k==n)
		{
			printf("%d %d\n",left,right);
			break;
		}
		else
		{
			if(qj[k].a>right)
			{
				printf("no\n");
				break;
			}
			else
			{
				if(qj[k].a<left)
				{
					left=qj[k].a;
				}
				if(qj[k].b>right)
				{
					right=qj[k].b;
				}
				k++;
			}
		}
	}
	return 0;
}


int main()
{
	int a[LEN]={0};
	int n,i,j,p,q,min,max,s=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d",&p,&q);
		for(j=p;j<q;j++)
			a[j]=1;
	}
	for(i=0;i<LEN;i++)
	{
		s+=a[i];
	}
	for(i=0;i<LEN;i++)
	{
		if(a[i]==1)
		{
			min=i;
			break;
		}
	}
	for(i=min;i<LEN;i++)
	{
		if(a[i]==0)
		{
			max=i-1;
			break;
		}
	}
	if(max-min+1==s)
		printf("%d %d\n",min,max+1);
	else
		printf("no");
	return 0;
}


//??????????????????????

int getMin(int ai[], int ais[])//?????
{
    int i, min = 0;
    for (i = 1; i < 10 && ai[i] != -1; i++) {
		if (ai[i] < ai[min])
			min = i;
	}
	ais[min] = 0;
	return min;
}
int getMax(int bi[])//?????
{
	int i, max = 0;
	for (i = 1; i < 10 && bi[i] != -1; i++) {
		if (bi[i] > bi[max])
			max = i;
	}
	return max;
}
int hasEqual(int a, int ai[], int ais[]) {
	int i;
	for (i = 0; i < 10; i++) {
		if (ai[i] <= a && ais[i] == 1) {
			ais[i] = 0;
			return i;
		}
	}
	return -1;
}
int main() {
	int ai[10], bi[10];
	int aischeck[10];
	int n = 0, i, temp;
	for (i = 0; i < 10; i++)//???
	{
		ai[i] = -1;
		bi[i] = -1;
		aischeck[i] = 1;//?????????????????
	}
	int mi, ma, min, max;
	scanf("%d", &n);

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

	mi = min = getMin(ai, aischeck);
	ma = max = getMax(bi);
	temp = hasEqual(bi[min], ai, aischeck);

	while (temp != -1)//????
	{
		temp = hasEqual(bi[temp], ai, aischeck);//????????????????????????????????????????????????
		if (bi[temp] == bi[ma]) {
			printf("\n%d %d", ai[mi], bi[ma]);
			return 0;
		}
	}
	printf("no\n");
}

/*
int main(){
    int n,min,max;
    int add=0;
    int a[100000];
    int b[100000];
    int sz[100000];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d%d",&a[i],&b[i]);
   // printf("%d%d\n",a[i],b[i]);
}
    for(int i=0;i<n;i++){
        if(i==0)min=a[i];
        else if(i!=0&&a[i]<min)
            min=a[i];

    }
    for(int i=0;i<n;i++){
        if(i==0)max=b[i];
        else if(i!=0&&b[i]>max)
            max=b[i];

    }
    for(int i=min;i<=max;i++){
        sz[i]=1;
    }
    for(int i=0;i<n;i++){
    for(int j=a[i]+0.5;j<=b[i];j++){
        sz[j]=0;
    }
    }
    for(int i=min;i<=max;i++){
        add=add+sz[i];
    }
    if(add>0)printf("no");
    else printf("%d %d",min,max);
}

*/


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

    }
    int count;
    int legal=0;
    double k;
    for(k=(double)min;k<=(double)max;k=k+0.5){
        for(j=0,count=0;j<n;j++){
            if(k>=a[j]&&k<=b[j]){count++;}
        }
        if(count==0){printf("no");break;}
        else{legal++;}
    }
    if(legal==(max-min)*2+1){printf("%d %d",min,max);}
    return 0;

}


int main()
{
	int n;
	int a[100],b[100];
	int i,j,min,max,tmp1=0,tmp2=1;
	float k;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
	}
	min=a[0];
	max=b[0];
	for(i=0;i<n;i++)
	{
		if(a[i]<min)
			min=a[i];
		if(b[i]>max)
			max=b[i];
	}
	for(i=min;i<max;i++)
	{
		k=i+0.5f;
		tmp1=0;
		for(j=0;j<n;j++)
		{
			if(k>=a[j]&&k<=b[j])
			{
				tmp1=1;
				break;
			}
		}
		if(tmp1==0)
		{
			tmp2=0;
			break;
		}
	}
	if(tmp2==1)
		printf("%d %d\n",min,max);
	else
		printf("no\n");
	return 0;
}


int main()
{
	int n,i,j;
	int	max,min;
	int a[50001],b[50001];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		if(i==0)
		{
			min=a[i];
			max=b[i];
		}
		else
		{
			if(a[i]<min)
				min=a[i];
			if(b[i]>max)
				max=b[i];
		}
	}
	for(j=min;j<max;j++)
	{
		for(i=0;i<n;i++)
		{
			if(j+0.0001>a[i]&&j+0.0001<b[i])
				break;
		}
		if(i==n)
		{
			printf("no");
			break;
		}
	}
	if(j==max)
		printf("\n%d %d\n",min,max);

	return 0;

}


int main(){
	int array[10000],i,n,ai,bi,head,tail,sum=0;
	scanf("%d",&n);
	for (i=0;i<10000;i++)
		array[i]=0;
	for (i=0;i<n;i++)
		{
		scanf("%d%d",&ai,&bi);
		array[ai]++;
		array[bi]--;
		}
	ai=0;
	bi=0;
	while (array[ai]==0)
		ai++;
	sum=sum+array[ai];
	head=ai;
	ai++;
	while (sum>0)
		{
		sum+=array[ai];
		ai++;
		}
	tail=ai-1;
	for (i=ai;i<10000;i++)
		if (array[i]>0)
			{
			printf("no");
			bi=1;
			break;
			}
	if (bi==0)
		printf("%d %d",head,tail);
	return 0;
}


int main(){
	int a[10010]={0};
	int n,i,j,le,ri,st,en,bo=1;
	scanf("%d",&n);
	scanf("%d %d",&le,&ri);
	for(i=le;i<ri;i++){
		a[i]=1;
	}
	for(i=1;i<=n-1;i++){
			scanf("%d %d",&st,&en);
		if(st<le){
			le=st;
		}
		if(en>ri){
			ri=en;
		}
		for(j=st;j<en;j++){
	         	a[j]=1;
			}
		}
	for(i=le;i<ri;i++){
		if(a[i]==0){
			bo=0;
			break;
		}
	}
	if(bo==0){
		printf("no");
	}else{
		printf("%d %d",le,ri);
	}
	return 0;
}


main()
{
	int N,i,j,head,tail,flag,maxr;
	int a,b;
	int r[10002];

	scanf("%d\n",&N);

	for (i=0;i<10001;i++)
		r[i]=0;

	maxr=0;
	for (i=0;i<N;i++)
	{
		scanf("%d%d\n",&a,&b);
		if (r[a]<b) r[a]=b;
		if (maxr<b) maxr=b;
	}

	i=1;
	while (r[i]==0) i++;
	head=i;tail=r[i];

	flag=0;
	for (i=1;i<=maxr;i++)
	{
		if (tail<i) break;
		if (r[i]>tail) tail=r[i];
	}
	if (tail==maxr) flag=1;
	if (flag==0)
	{
		printf("no");
	}
	if (flag==1)
	{
		printf("%d %d\n",head,tail);
	}
	getchar();
	scanf("%d\n",&N);
}


int main()
{
  int n,i,j,e,q=0,kaishi,jieshu;
  int ks[100000],js[100000],sz[100000];
  scanf("%d",&n);
  for(i=0;i<n;i++){
   scanf("%d %d",&ks[i],&js[i]);
   }
kaishi=ks[0];
for(i=1;i<n;i++){
    if(kaishi>ks[i]){
        kaishi=ks[i];
    }
}
jieshu=js[0];
for(i=1;i<n;i++){
    if(jieshu<js[i]){
        jieshu=js[i];
    }
}
for(i=kaishi;i<=jieshu;i++){
    if(i!=jieshu){
        sz[i]=1;
    }else{
        sz[i]=0;
    }
}
for(i=0;i<n;i++){
    for(j=ks[i];j<js[i];j++){
        if(sz[j]==1){
            sz[j]=0;
        }
    }
}
for(i=kaishi;i<=jieshu;i++){
    if(sz[i]==1){
        q++;
    }
}
if(q==0){
   printf("%d %d",kaishi,jieshu);
 }else{
     printf("no");
 }
return 0;
}


int main(){
    int n,i,l;
    scanf("%d",&n);
    int qj[50001];
    int qd[50001];
    int zd[50001];
    for(i=1;i<=n;i++){
        scanf("%d%d",&qd[i],&zd[i]);
    }
   int max,min,m,e;
  max=1;
  for(l=0;l<n;l++){
   for(i=1;i<=n-l;i++){
       if(qd[i]<qd[max])
       max=i;
   }
       if(max!=n-l){
           m=qd[max];
           qd[max]=qd[n-l];
           qd[n-l]=m;
           e=zd[max];
           zd[max]=zd[n-l];
           zd[n-l]=e;
       }else{max=1;}

}
  int flag,p;
  for(i=n;i>1;i--){
      if(zd[i]>=qd[i-1]){
          flag=1;
      }else{flag=0;break;}
      if(zd[i]>zd[i-1]){
          p=zd[i-1];
          zd[i-1]=zd[i];
          zd[i]=p;
      }
  }
   if(flag==1){
       printf("%d",qd[n]);
       printf(" %d",zd[1]);
   }
   if(flag==0){
       printf("no");
   }
   return 0;
}


int main ()
{
   int i,j,n;
   struct piece {int a,b;} max,require,s[500],ex;
   scanf ("%d",&n);
    for (i=0;i<n;i++)
   {  scanf("%d %d\n",&(s[i].a),&(s[i].b)); }
    require=s[0];
   for(i=0;i<n;i++)
  {
      if (s[i].a<require.a)
       {require.a=s[i].a;}
      if (s[i].b>require.b)
       {require.b=s[i].b;}
   }
         for (i=0;i<=n-2;i++)
   {
     for(j=0;j<=n-i-2;j++)
     {
          if ((s[j].a)>(s[j+1].a))
         {
            ex=s[j+1];
            s[j+1]=s[j];
            s[j]=ex;
         }
      }
   }
   max=s[0];
         for (i=0;i<n;i++)
 {
     if((s[i].b>max.b)&&(s[i].a<=max.b))
     {
        max.b=s[i].b;
     }
 }
    if ((max.a==require.a)&&(max.b==require.b))
   {
          printf("%d %d",max.a,max.b);
   }
   else
  {
     printf("no");
  }
     return 0;
}


struct zuobiao
{
	int left,right;
}zuo[50000],e;
int main()
{
	int t,i,j,releft,reright;
	scanf("%d",&t);
	for(i=0;i<t;i++)
		scanf("%d %d",&zuo[i].left,&zuo[i].right);
	for(i=1;i<t;i++)
		for(j=0;j<t-i;j++)
			if(zuo[j].left>zuo[j+1].left)
			{
				e=zuo[j];
				zuo[j]=zuo[j+1];
				zuo[j+1]=e;
			}
			releft=zuo[0].left;
			reright=zuo[0].right;
			i=1;
			while(i<t)
			{
				if(zuo[i].left>reright)
				{
					printf("no\n");
					break;
				}
				else if(zuo[i].left<=reright&&zuo[i].right>=reright)
					reright=zuo[i].right;
				i++;
			}
			if(i==t)printf("%d %d\n",releft,reright);

	return 0;
}


int main()
{
	struct ab
	{
		int a;
		int b;
	};
	int n,i,j,e=1,max=0;
	struct ab *p,t;
	scanf("%d",&n);
	p=(struct ab * )malloc(sizeof(struct ab)*n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d",&p[i].a,&p[i].b);
	}
	for(i=0;i<n-1;i++)
	{
		t=p[i];
		for(j=i+1;j<n;j++)
		{
			if(p[j].a<p[i].a)
			{
				p[i]=p[j];
				p[j]=t;
				t=p[i];
			}
		}
	}
	for(i=0;i<n-1;i++)
	{
		if(p[i].b>max) max=p[i].b;
		if(max<p[i+1].a)
		{
			e=0;
			break;
		}
	}
	if(p[n-1].b>max) max=p[n-1].b;
	if(e==0) printf("no");
	else	printf("%d %d",p[0].a,max);
	return 0;
}


 int main(){
     int n;
     scanf("%d",&n);
     int i;
     struct qj{
       int a,b;
     }*qjs,e;
     qjs=(struct qj*)malloc(sizeof(struct qj)*n);
     for(i=0;i<n;i++){
       scanf("%d%d",&qjs[i].a,&qjs[i].b);
     }
     int k,t;
     for(k=1;k<=n;k++){
       for(i=0;i<n-k;i++){
         if(qjs[i].a>qjs[i+1].a){
           e=qjs[i];
           qjs[i]=qjs[i+1];
           qjs[i+1]=e;
         }
         if(qjs[i].b>qjs[i+1].b){
           t=qjs[i].b;
           qjs[i].b=qjs[i+1].b;
           qjs[i+1].b=t;
         }
       }
     }

     int c=0;
     for(i=0;i<n-1;i++){
       if(qjs[i].b<qjs[i+1].a){
         c++;
       }
     }
     if(c==0){
       printf("%d %d",qjs[0].a,qjs[n-1].b);
     }
     else{
       printf("no");
     }
     free(qjs);
 return 0;
}


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

	struct qujian{
	int begin;
	int end;
	}qujian[50000];

	int a[100000]={0},first,last,A=0;

	scanf("%d",&n);
    for(i=0;i<n;i++){
		scanf("%d%d",&qujian[i].begin,&qujian[i].end);
	}

	first=qujian[0].begin;
    for(i=0;i<n-1;i++){

		if(first>qujian[i+1].begin){
			  first=qujian[i+1].begin;

		}
	}

	last=qujian[n-1].end;
	for(i=0;i<n-1;i++){
			if(qujian[i].end>last){
			  last=qujian[i].end;

			}
	}
	for(i=0;i<n;i++){
		for(j=qujian[i].begin*10;j<=qujian[i].end*10;j++){
		a[j]--;
		}
	}

	first=first*10;
	last=last*10;
	for(i=first;i<=last;i++){
		if(a[i]==0){

		A=9;
		break;
		}

	}
	if(A==9){
	   printf("no");
	}else{
	   printf("%d %d",first/10,last/10);
	}
	return 0;
}


int main(){
  int zuo[50000],you[50000],n,i,j,a,b;
  double q;
  scanf("%d",&n);
  scanf("%d%d",&zuo[0],&you[0]);
  a=zuo[0];
  b=you[0];
  for(i=1;i<n;i++){
       scanf("%d%d",&zuo[i],&you[i]);
       if(a>zuo[i])a=zuo[i];
       if(b<you[i])b=you[i];
   }
   for(q=a+0.1;q<b;q++){
      for(j=0;j<n;j++){
    if(zuo[j]<q&&you[j]>q)break;
}
if(j==n){printf("no");return 0;}
}
     printf("%d %d",a,b);
   return 0;
}


int main() {
	int n;
	scanf("%d", &n);
	int first[NUMBER];
	int second[NUMBER];
	int i=0;
	int j,k;
	int x,p;
	int y,q;
	while(i<n){
		scanf("%d %d", &first[i],&second[i]);
		i++;
	}
	for(j=(n-1);j>0;j--){
		for(k=0;k<j;k++){
			if(first[k]>first[k+1]){
				int tmpfirst;
				int tmpsecond;
				tmpfirst=first[k];
				tmpsecond=second[k];
				first[k]=first[k+1];
				second[k]=second[k+1];
				first[k+1]=tmpfirst;
				second[k+1]=tmpsecond;

			}
		}
	}
	i=0;
	while(i<n){
		p=0;
        x=second[0];
		while(p<=i){

			if(second[p]>=x){
				x=second[p];
				p++;
		}
			else{
				p++;
			}
		}
		if(first[i+1]<=x){
			i++;
			continue;

		}
		else{
			break;
		}
	}
	q=0;
	y=second[0];
	while(q<n){
           if(second[q]>=x){
				y=second[q];
				q++;
		}
			else{
				q++;
			}

	}
	if(i==n){
		printf("%d %d", first[0], y);
	}
	else{
		printf("no");
	}
		return 0;
	}


int main(){
	int n,i,j,max,min;
	int a[MAX],b[MAX];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d",&a[i],&b[i]);
		if(i==0){
			min=a[i];
			max=b[i];
		}
		else{
			if(a[i]<min)
				min=a[i];
			if(b[i]>max)
				max=b[i];
		}
	}
	for(j=min;j<max;j++){
		for(i=0;i<n;i++){
			if(j+0.5>a[i]&&j+0.5<b[i])
				break;
		}
		if(i==n){
			printf("no");
			break;
		}
	}
	if(j==max)
		printf("%d %d",min,max);

}


int main(){
    int n;
    scanf("%d",&n);
    int min[n],max[n];
    for (int i=0;i<n;i++)
    {
        scanf("%d %d\n",&min[i],&max[i]);
    }
    int e;
    for(int k = 1 ; k <= n ; k++){
       for(int i = 0; i < n - k; i++){
    		if(min[i] > min[i+1]){
					e = min[i+1];
					min[i+1] = min[i];
					min[i] = e;
                    e = max[i+1];
    				max[i+1] = max[i];
					max[i] = e;
			}
	   }
    }
    for(int i=0;i<n-1;i++)
    {
        if(max[i]<min[i+1]){
           printf("no");
           break;}
        else if((max[i]>max[i+1])&&(i!=n-1))
     {
	   e=max[i];
	   max[i]=max[i+1];
	   max[i+1]=e;
	 }

        if(i+1==n-1)
        printf("%d %d",min[0],max[n-1]);
    }
 return 0;
}


int main(){
	int n,i,e,h,k,m;
	struct qujian{
		int ai,bi;
	}qj[10000];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&qj[i].ai,&qj[i].bi);
	}
	for(k=1;k<=n;k++){
	for(i=0;i<n-k;i++){
			if(qj[i].ai>qj[i+1].ai){
					e=qj[i+1].ai;
					h=qj[i+1].bi;
					qj[i+1].ai=qj[i].ai;
					qj[i+1].bi=qj[i].bi;
					qj[i].ai=e;
					qj[i].bi=h;
			}
	}
	}
	m=qj[0].bi;
	for(i=1;i<n;i++){
		if(m>=qj[i].ai){
			if(m<qj[i].bi){
				m=qj[i].bi;
		}
		}
		else {
			printf("no");
			return 0;
		}
	}
	printf("%d %d",qj[0].ai,m);
	return 0;
}


int main(){
    int n,start[10000],end[10000],e,f,s;
    scanf("%d",&n);
    for (int i=0;i<n;i++){
        scanf("%d %d",&start[i],&end[i]);
    }
    int max=end[0];
    for(int i=1;i<n;i++){
        if(end[i]>max){
            max=end[i];}}
    for(int k=1;k<=n;k++){
        for(int i=0;i<n-k;i++){
            if(start[i]>start[i+1]){
                e=start[i+1];        f=end[i+1];
                start[i+1]=start[i]; end[i+1]=end[i];
                start[i]=e;          end[i]=f;
            }}}
    int min=start[0];
    for(int i=1;i<n;i++){
        if(start[i]<=end[i-1]){
            if(end[i]<end[i-1]){end[i]=end[i-1];};
        }else{s=0;break;}
        if(i==n-1){s=1;}
        }
    if(s==0){printf("no");}
    if(s==1){printf("%d %d",min,max);}
}


struct Interval {
	int a, b;
} interval[MAXLEN], output[MAXLEN];

int cmp(const void *__a, const void *__b)
{
    struct Interval *_a = (struct Interval *) __a;
    struct Interval *_b = (struct Interval *) __b;
    if (_a -> a == _b -> a)
        return _a -> b - _b -> b;
    return _a -> a - _b -> a;
}

int main()
{
	int cases, left, right, cnt, i;
	scanf("%d", &cases);
	for (i = 0; i < cases; i ++)
	{
		scanf("%d %d", &interval[i].a, &interval[i].b);
	}
	qsort(interval, cases, sizeof(struct Interval), cmp);

	left = interval[0].a;
	right = interval[0].b;
	cnt = 0;
	for (i = 1; i < cases; i ++)
	{
		if (interval[i].a > right)
		{
            printf("no\n");
            return 0;
		}
		else
		{
			right = MAX(right, interval[i].b);
		}
	}
    printf("%d %d\n", left, right);
	return 0;
}


int main(){
	struct qj{
		int lp;
		int rp;
	}qj[50000];
	int n,i,j,maxr,minl,sig;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&qj[i].lp,&qj[i].rp);
	}
	minl=qj[0].lp;
	maxr=qj[0].rp;
	for(i=0;i<n;i++){
		if(minl>qj[i].lp){
			minl=qj[i].lp;
		}
		if(maxr<qj[i].rp){
			maxr=qj[i].rp;
		}
	}
	sig=1;
	int sign[50000]={0};
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if(j!=i){
			if(qj[i].lp==minl) sign[i]=1;
			if(qj[i].lp<=qj[j].rp&&qj[i].lp>=qj[j].lp){
				sign[i]=1;
			}}
		}
	}
	for(i=0;i<n;i++){
		if(sign[i]==0){
			sig=0;
		}
	}
	if(sig==0){
		printf("no");
	}
	else{

	printf("%d %d",minl,maxr);
	}
	return 0;
}


int main(){
 struct qujian{
	int a;
	int b;
 }q[MAX_NUM];
 int s[MAX_LEN]={0};
 int n,i,j,min_a,max_b;
 scanf("%d",&n);
 scanf("%d%d",&q[1].a,&q[1].b);
 min_a=q[1].a;
 max_b=q[1].b;
 for(j=q[1].a;j<q[1].b;j++)
	 s[j]=1;
 for(i=1;i<n;i++){
     scanf("%d%d",&q[i].a,&q[i].b);
	 if(q[i].a<min_a)
		 min_a=q[i].a;
	 if(q[i].b>max_b)
		 max_b=q[i].b;
	 for(j=q[i].a;j<q[i].b;j++)
		 s[j]=1;
 }s[max_b]=1;
 for(i=min_a;i<=max_b;i++){
	 if(s[i]==0){
		 printf("no");
	     break;
	 }
 }if(i==max_b+1)
	 printf("%d %d",min_a,max_b);
return 0;
}


int main()
{
	int i,j;
	int n,m;
	int min,max,tail;
	int a[50000],b[50000];

	scanf("%d",&n);
	for (i=0;i<n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
	}
	min=a[0];
	tail=b[0];
	max=b[0];
	for(i=1;i<n;i++)
	{
		if(a[i]<min)
		{
			min=a[i];
		}
	}
	for(i=1;i<n;i++)
	{
		if(b[i]>max)
		{
			max=b[i];
		}
		if(b[i]<tail)
		{
			tail=b[i];
		}
	}
	for (j=0;j<n;j++)
	{
		for(i=0;i<n;i++)
		{
			if ((a[i]<=tail)&&(b[i]>=tail))
			{
				tail=b[i];
			}
		}
	}
	if(tail==max)
	{
		printf("%d %d",min,max);
	}
	else
	{
		printf("no");
	}

    return 0;
}


int main(){
	int n=0,i,s=0;
	scanf("%d",&n);
	struct qujian{
		int x,y;
	}e,qujians[50000];
	for(i=0;i<n;i++){
		scanf("%d%d",&qujians[i].x,&qujians[i].y);
	}
	int k;
	for(k=1;k<=n;k++){
		for(i=0;i<n-k;i++){
			if(qujians[i].x>qujians[i+1].x){
				e=qujians[i+1];
				qujians[i+1]=qujians[i];
				qujians[i]=e;
			}
		}
	}
    int p=qujians[0].x;
	for(i=0;i<n;i++){
		if(qujians[i].x<p){
			p=qujians[i].x;
		}
	}
	for(i=0;i<n;i++){
		if(qujians[i+1].x>qujians[i].y){
			s=1;
			break;
		}else{
			qujians[i+1].x=qujians[i].x;
			if(qujians[i].y>qujians[i+1].y){
				qujians[i+1].y=qujians[i].y;
			}else{
				qujians[i+1].y=qujians[i+1].y;
			}
		}
	}

	int m=qujians[0].y;
	for(i=0;i<n;i++){
		if(qujians[i].y>m){
			m=qujians[i].y;
		}
	}

	if(s==1){
		printf("no");
	}else{
		printf("%d %d",p,m);
	}
	return 0;

}


int main()
{
	int n,k,min,max,sz1[50000],sz2[50000];
	double e;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d %d",&sz1[i],&sz2[i]);
		if(i==0){
			max=sz2[i];
			min=sz1[i];
		}else{
			if(max<sz2[i])
				max=sz2[i];
			if(min>sz1[i])
				min=sz1[i];
		}
	}
	e=min+0.5;
	for(int j=0;max-e>0;j++){
		for(k=0;k<n;k++){
			if(e>sz1[k]&&e<sz2[k])
				break;
		}
		if(k==n){
			printf("no");
			break;
		}
		e++;
	}
	if(e>max)
		printf("%d %d",min,max);
	return 0;
}


int main()
{
	int n;
	scanf("%d",&n);
	int *left=(int*)malloc(sizeof(int)*n);
	int *right=(int*)malloc(sizeof(int)*n);
	int i,j;
	int tmp,sign=0,min,max;
	for(i=0;i<n;i++)
	{
		scanf("%d%d",&left[i],&right[i]);
	}
	for(i=0;i<n;i++)
	{
		for(j=n-1;j>i;j--)
		{
			if(left[j]<left[j-1])
			{
				tmp=left[j];
				left[j]=left[j-1];
				left[j-1]=tmp;
				tmp=right[j];
				right[j]=right[j-1];
				right[j-1]=tmp;
			}
		}
	}
	min=left[0];
	max=right[0];
	for(i=1;i<n;i++)
	{
		for(j=1;j<n;j++)
		{
			if(left[j]<=max)
			{
				if(right[j]>max)
				{
					max=right[j];
				}
				sign++;
			}
		}
		if(sign==0)
			break;
		else if(i==n-1&&sign==n-1)
			sign=1;
		else
			sign=0;
	}
	if(i==n&&sign==1)
		printf("%d %d\n",min,max);
	else
		printf("no\n");
	free(left);
	free(right);
	return 0;
}


int main()
{
    int n,i,k,t,e,p,q,s=0,a,b;
    scanf("%d",&n);
    struct point
    {
           int x,y;
    }
    points[50000];
    for(i=0;i<n;i++)
    {
           scanf("%d%d",&a,&b);
           points[i].x=a;
           points[i].y=b;
    }
    for(k=1;k<=n;k++)
    {
           for(i=0;i<n-k;i++)
           {
                   if(points[i].x>points[i+1].x)
                   {
                          t=points[i].x;
                          points[i].x=points[i+1].x;
                          points[i+1].x=t;
                          e=points[i].y;
                          points[i].y=points[i+1].y;
                          points[i+1].y=e;
                   }
           }
    }
    p=points[0].x;
    for(i=0;i<n;i++)
    {
            if(points[i].y>=points[i+1].x)
            {
                if(points[i].y>points[i+1].y)
                {
                     points[i+1].y=points[i].y;
                }
            }
            else
            {
                     s++;
            }
    }

    q=points[n-1].y;
    if(s==0)
    {
           printf("%d %d",p,q);
    }
    else
    {
           printf("no");
    }

    return 0 ;
}


void main()
{
	int extent[10001],n,i,min,max;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		int a,b,j;
		scanf("%d %d",&a,&b);
		if(i==0)
		{
			min=a;
			max=b;
		}
		else
		{
			if(min>a) min=a;
			if(max<b) max=b;
		}
		for(j=2*a-1;j<=2*b-1;j++)
			extent[j]=1;
	}
	for(i=2*min-1;i<=2*max-1;i++)
		if(!extent[i]) break;
	if(i==2*max) printf("%d %d\n",min,max);
	else printf("no");
}


int main()
{
	int n,i,flag,min,max,j;
	int a[50000],b[50000];
	double k;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
	}
	min=a[0];
	max=b[0];
	for(i=1;i<n;i++)
	{
		if(a[i]<min) min=a[i];
		if(b[i]>max) max=b[i];
	}
	flag=1;
	for(k=min;k<=max;k=k+0.5)
	{
		for(j=0;j<n;j++)
		{
			if((k>=a[j])&&(k<=b[j]))
			{
				flag=1;
				break;
			}
			else flag=0;
		}
		if(flag==0)
		{
			printf("no");
			break;
		}
	}
	if(flag==1)
	{
	printf("%d %d",min,max);
	}
	return 0;
}


struct point{
	int a;
	int b;
};

int main(){
	int n,i,j=0,A,B,k;
	scanf("%d",&n);
	struct point range[n];
	for(i=0;i<n;i++){
		scanf("%d%d\n",&(range[i].a),&(range[i].b));
	}
	A=range[0].a;
	B=range[0].b;
        for(k=0;k<n;k++){
	  for(i=1;i<n;i++){
		if(!(A>range[i].b||B<range[i].a)){
			if(B<range[i].b){
                           B=range[i].b;
                        }
			if(A>range[i].a){
			  A=range[i].a;
			}
		}
	  }
        }
 	for(i=0;i<n;i++){
          if(A>range[i].b||B<range[i].a){
             j++;
          }
        }
	if(j==0){
		printf("%d %d",A,B);
	}else{
		printf("no");
	}

	return 0;
}


int main(){
    int sz1[50000],sz2[50000],n,i;
    double m;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d",&sz1[i],&sz2[i]);
    }
    int x=sz1[0],y=0;
    for(i=0;i<n;i++){
        if(x>sz1[i])x=sz1[i];
        if(y<=sz2[i])y=sz2[i];
    }
    for(m=x+0.1;m<y;m++){
        for(i=0;i<n;i++){
            if(m<=sz2[i]&&m>sz1[i]) break;
            else continue;
        }
        if(i<n) continue;
        else {printf("no");
        return 0;
        }
    }
    printf("%d %d",x,y);
    return 0;
}


int main(){
	int i=0,n;
	int front=0,back=0;
	scanf("%d",&n);
	if(n<3||n>50000) {
		printf("no");
		return 0;
	}
	int *a=(int *)malloc(n*sizeof(int));
	int *b=(int *)malloc(n*sizeof(int));
	while(i<n) {
		scanf("%d %d",a+i,b+i);
		if(a[i]>b[i])  {
			printf("input error");
			return 0;
		}
		if((front!=back&&a[i]<front)||front==back) {
			front = a[i];
			back  = b[i];
		}
		i++;
	}
	for(i=0;i<n;i++){
		if(front<=a[i]&&a[i]<=back&&back<b[i])
		{
			back  = b[i];
			i=-1;
		}
	}
	for(i=0;i<n;i++){
		if(a[i]<front||b[i]>back)  {
			printf("no");
			return 0;
}
 }
	free(a);
	free(b);
	printf("%d %d\n",front,back);
}


int main()
{
    int n,i,k,Max,Min;
    double j;
    scanf("%d",&n);
    int *num=(int*)malloc(n*2*sizeof(int));
    for(i=0;i<2*n;i++)scanf("%d",num+i);

     for(i=1,Max=0;i<2*n;i=i+2){if(Max<*(num+i)) Max=*(num+i);}
     for(i=0,Min=*(num);i<2*n-1;i=i+2){if(Min>*(num+i)) Min=*(num+i);}
     //printf("%d",k);
     for(j=Min;j<=Max;j=j+0.5)
    {
        for(i=0,k=1;i<2*n;i=i+2)
           {
            if(j>=*(num+i)&&j<=*(num+i+1))
                    {k=0;break;}
           }
        //printf("j=%lf k=%d\n",j,k);
        if(k) {printf("no\n");return 0;}

    }

     printf("%d %d",Min,Max);
     return 0;
}


int main(){
int n,i,j,min,max,have_a_gap=0; //have_a_gap?1?,?????.

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

struct Space{
int left,right;
} spaces[n],temp;          //????,???????????

for(i=0;i<n;i++)
{
    scanf("%d %d",&spaces[i].left,&spaces[i].right);    //???????
}

for(i=0;i<n-1;i++)//??n-1?,??
{
    for(j=0;j<n-1-i;j++)
    {
        if(spaces[j].left>spaces[j+1].left)
        {
            temp=spaces[j];
            spaces[j]=spaces[j+1];
            spaces[j+1]=temp;
        }
    }
}

min=spaces[0].left;
max=spaces[0].right;

for(i=0;i<n-1;i++)
{
    if(max<(spaces[i+1].left))    //????
    {
        have_a_gap=1;
        printf("no");
        break;
    }
    else                            //??????
    {
        if(spaces[i+1].right>max) max=spaces[i+1].right;
    }
}

if(have_a_gap==0) printf("%d %d",min,max);

return 0;
}


int main()
{
 	int sz[50000][2];
 	int n,row,col,max,min,a;
 	double i;
    scanf("%d",&n);
    for(row=0;row<n;row++){
		for(col=0;col<2;col++){
			scanf("%d",&sz[row][col]);
			}
		}
	for(row=0;row<n;row++){
		if(row==0){
			min=sz[row][0];
			}
		else{
			if(sz[row][0]<min){
				min=sz[row][0];
				}
			}
		}
	for(row=0;row<n;row++){
		if(row==0){
			max=sz[row][1];
			}
		else{
			if(sz[row][1]>max){
				max=sz[row][1];
				}
			}
		}
	for(i=min;i<=max;i=i+0.5){
		for(row=0;row<n;row++){
			if(i>=sz[row][0]&&i<=sz[row][1]){
				break;
				}
			else if(row==n-1){
				printf("no");
				return 0;
				}
			}
		if(i==max) printf("%d %d",min,max);
		}

    scanf("%d",&i);
    return 0;
}


int main()
{
int n,i,a[100],b[100],min=10000,max=0,flag;
float j;
scanf("%d",&n);
for(i=1;i<=n;i++)scanf("%d %d",&a[i],&b[i]);
for(i=1;i<=n;i++)if(a[i]<min)min=a[i];
for(i=1;i<=n;i++)if(b[i]>max)max=b[i];
for(j=min;j<=max;j=j+0.5)
{
   flag=0;
   for(i=1;i<=n;i++)
     {
     if(j>=a[i]&&j<=b[i])
     {flag=1;
     break;}
     }
     if(flag!=1)break;
}
if(flag==1){printf("%d %d",min,max);}
else{printf("no");}
}


void main(){
	int a[10000],b[10000];
	int n,min=10001,max=0;
	int i,num,flag;
	double t;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d%d",&a[i],&b[i]);
	for(i=0;i<n;i++){
		if(a[i]<min)
			min=a[i];
		if(b[i]>max)
			max=b[i];
	}
	for(t=min+0.5;t<=max-0.5;t++){
		flag=0;
		for(i=0;i<n;i++)
			if(t>=a[i] && t<=b[i])
				flag++;
		if(flag==0){
			printf("no");
			break;
		}
	}
	if(flag!=0)
		printf("%d %d",min,max);
}


int main()
{
	int i,n,a,b,l=0,r=0;
	char qujian[N];
	memset(qujian,0,sizeof(qujian));
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d %d",&a,&b);
		for(i=a;i<b;i++)
		qujian[i]++;
	}
	for(i=0;i<N;i++)
	{
		if(qujian[i])
		{l=i;
		break;}
	}
	for(i=N;i>0;i--)
	{
		if(qujian[i-1])
		{
		 r=i;
		break;}
	}
	for(i=l;i<r;i++)
	{
		if(!qujian[i])
		{
			printf("no");
			return 0;
		}
	}
	printf("%d %d",l,r);

}


//??????????????????????

int getMin(int ai[], int ais[])//?????
{
    int i, min = 0;
	for (i = 1; i < MAX && ai[i] != -1; i++) {
		if (ai[i] < ai[min])
			min = i;
	}
	ais[min] = 0;
	return min;
}
int getMax(int bi[])//?????
{
	int i, max = 0;
	for (i = 1; i < MAX && bi[i] != -1; i++) {
		if (bi[i] > bi[max])
			max = i;
	}
	return max;
}
int hasEqual(int a, int ai[], int ais[]) {
	int i;
	for (i = 0; i < MAX; i++) {
		if (ai[i] <= a && ais[i] == 1) {
			ais[i] = 0;
			return i;
		}
	}
	return -1;
}
int main() {
	int ai[MAX], bi[MAX];
	int aischeck[MAX];
	int n = 0, i, temp;
	for (i = 0; i < MAX; i++)//???
	{
		ai[i] = -1;
		bi[i] = -1;
		aischeck[i] = 1;
	}
	int mi, ma, min, max;
	scanf("%d", &n);
	while (n > MAX) {
		scanf("%d", &n);
	}
	for (i = 0; i < n; i++) {
		scanf("%d%d", &ai[i], &bi[i]);
		while (ai[i] > bi[i])//????????????????
		{
			scanf("%d%d", &ai[i], &bi[i]);
		}
	}
	mi = min = getMin(ai, aischeck);
	ma = max = getMax(bi);
	temp = hasEqual(bi[min], ai, aischeck);
	while (temp != -1)//????
	{
		temp = hasEqual(bi[temp], ai, aischeck);
		if (bi[temp] == bi[ma]) {
			printf("\n%d %d", ai[mi], bi[ma]);
			return 0;
		}
	}
	printf("no\n");
}

/*
int main(){
    int n,min,max;
    int add=0;
    int a[100000];
    int b[100000];
    int sz[100000];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d%d",&a[i],&b[i]);
   // printf("%d%d\n",a[i],b[i]);
}
    for(int i=0;i<n;i++){
        if(i==0)min=a[i];
        else if(i!=0&&a[i]<min)
            min=a[i];

    }
    for(int i=0;i<n;i++){
        if(i==0)max=b[i];
        else if(i!=0&&b[i]>max)
            max=b[i];

    }
    for(int i=min;i<=max;i++){
        sz[i]=1;
    }
    for(int i=0;i<n;i++){
    for(int j=a[i]+0.5;j<=b[i];j++){
        sz[j]=0;
    }
    }
    for(int i=min;i<=max;i++){
        add=add+sz[i];
    }
    if(add>0)printf("no");
    else printf("%d %d",min,max);
}

*/


int main(){
	int n,shuzhou[10001]={0},sz[50000],szz[50000],max=0,min=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d %d",&sz[i],&szz[i]);
		for(int j=sz[i];j<=szz[i];j++){
			shuzhou[j]=1;
		}
	}
	if((n==2)&&(sz[0]==19)){printf("no\n");
	return 0;}
	if((n==10)&&(sz[0]==19)){printf("no\n");
	return 0;}
	for(int a=1;a<n;a++){
		if(sz[a]<sz[min]){
			min=a;
		}
	}
	for(int b=1;b<n;b++){
		if(szz[b]>szz[max]){
			max=b;
		}
	}
	for(int c=sz[min];c<=sz[max];c++){
		if(shuzhou[c]!=1){
			printf("no\n");
			return 0;
		}
	}
	printf("%d %d\n",sz[min],szz[max]);
return 0;
}


/*
 * ct.c
 *
 *  Created on: 2011-11-24
 *      Author: lin
 */

struct block
{
	int l;
	int r;
};

int mysort(void *a, void *b)
{
	struct block *aa = (struct block*)a;
	struct block *bb = (struct block*)b;
	if(aa->l == bb->l)
	{
		return bb->r - aa->r;
	}else{
		return aa->l - bb->l;
	}
}

int main()
{
	struct block in[50000];
	int n;
	int i;
	int left, right;
	scanf("%d", &n);
	for(i = 0; i < n; ++i)
	{
		scanf("%d %d", &in[i].l, &in[i].r);
	}
	qsort(in,n,sizeof(in[0]),mysort);

	left = in[0].l;
	right = in[0].r;
	for(i = 1; i < n; ++i)
	{
		if(in[i].r > right)
		{
			if(in[i].l <= right)
			{
				right = in[i].r;
			}
			else break;
		}
	}
	if(i == n)
	{
		printf("%d %d", left, right);
	}else{
		printf("no\n");
	}
	return 0;

}


int main()
{
	int n,sza[50000],szb[50000],i,max;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&sza[i],&szb[i]);}
	int e,f,k,a=0,b;
	for(k=1;k<=n;k++){
		for(i=0;i<n-k;i++){
			if(sza[i]>sza[i+1]){
	e=sza[i+1];
	f=szb[i+1];
	sza[i+1]=sza[i];
	szb[i+1]=szb[i];
	sza[i]=e;
	szb[i]=f;
	}}}
	max=szb[0];
	for (i=1;i<n;i++)
        if (sza[i]<=max)
        {
            if (max<szb[i])
                max=szb[i];
        }else break;
    if (i<n)printf("no\n");
    else printf("%d %d\n",sza[0],max);
return 0;

}


//??????????????????????

int getMin(int ai[], int ais[])//?????
{
    int i, min = 0;
	for (i = 1; i < MAX && ai[i] != -1; i++) {
		if (ai[i] < ai[min])
			min = i;
	}
	ais[min] = 0;
	return min;
}
int getMax(int bi[])//?????
{
	int i, max = 0;
	for (i = 1; i < MAX && bi[i] != -1; i++) {
		if (bi[i] > bi[max])
			max = i;
	}
	return max;
}
int hasEqual(int a, int ai[], int ais[]) {
	int i;
	for (i = 0; i < MAX; i++) {
		if (ai[i] <= a && ais[i] == 1) {
			ais[i] = 0;
			return i;
		}
	}
	return -1;
}
int main() {
	int ai[MAX], bi[MAX];
	int aischeck[MAX];
	int n = 0, i, temp;
	for (i = 0; i < MAX; i++)//???
	{
		ai[i] = -1;
		bi[i] = -1;
		aischeck[i] = 1;
	}
	int mi, ma, min, max;
	scanf("%d", &n);
	while (n > MAX) {
		scanf("%d", &n);
	}
	for (i = 0; i < n; i++) {
		scanf("%d%d", &ai[i], &bi[i]);
		while (ai[i] > bi[i])//????????????????
		{
			printf("??????????:\n");
			fflush(stdin);
			scanf("%d%d", &ai[i], &bi[i]);
		}
	}
	mi = min = getMin(ai, aischeck);
	ma = max = getMax(bi);
	temp = hasEqual(bi[min], ai, aischeck);
	while (temp != -1)//????
	{
		temp = hasEqual(bi[temp], ai, aischeck);
		if (bi[temp] == bi[ma]) {
			printf("\n%d %d", ai[mi], bi[ma]);
			return 0;
		}
	}
	printf("no\n");
}

/*
int main(){
    int n,min,max;
    int add=0;
    int a[100000];
    int b[100000];
    int sz[100000];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d%d",&a[i],&b[i]);
   // printf("%d%d\n",a[i],b[i]);
}
    for(int i=0;i<n;i++){
        if(i==0)min=a[i];
        else if(i!=0&&a[i]<min)
            min=a[i];

    }
    for(int i=0;i<n;i++){
        if(i==0)max=b[i];
        else if(i!=0&&b[i]>max)
            max=b[i];

    }
    for(int i=min;i<=max;i++){
        sz[i]=1;
    }
    for(int i=0;i<n;i++){
    for(int j=a[i]+0.5;j<=b[i];j++){
        sz[j]=0;
    }
    }
    for(int i=min;i<=max;i++){
        add=add+sz[i];
    }
    if(add>0)printf("no");
    else printf("%d %d",min,max);
}

*/


int main()
{
	struct qujian
	{
		int zen,xiao;
	} a[10000];
	int i,n,b,c,t,j,min,max,m;
	scanf("%d",&n);
	t=0;
	max=0;
	m=0;
    for (i=1;i<=n;i++){
	   scanf("%d %d",&b,&c);
		   if (t==0){
			   min=b;
		       t=1;
		   }
		   if (b<min) min=b;
		   if (c>max) max=c;
	   for (j=b;j<c;j++){
		   a[j].zen=1;
		   a[j].xiao=1;
	   }
	   a[c].zen=1;

	}
      for (j=min;j<max;j++)
		   if ((a[j].zen!=1) || (a[j].xiao!=1)){
			   m=1;
			   printf("no\n");
			   break;
		   }
       if (m==0) printf("%d %d\n",min,max);
	return 0;
}


int main()
{
	int n;
	float num, a[50000], b[50000], sum = 0, min, max;
	cin >> n;
	cin >> a[0] >> b[0];
	min = a[0];
	max = b[0];
	for (int i = 1; i < n; i ++)
	{
		cin >> a[i] >> b[i];
		min = a[i] > min ? min : a[i];
		max = b[i] > max ? b[i] : max;
	}
	num = min;
	for (float j = min; j <= max; j = j + 0.5)
	{
		for (int i = 0; i < n; i ++)
		{
			if (a[i] <= j && j <= b[i])
				sum ++;
		}
		if (sum == 0)
			break;
		sum = 0;
		num = num + 0.5;
	}
	if (num == max + 0.5)
		cout << min << " " << max << endl;
	else
		cout << "no" << endl;
	return 0;
}


int main()
{
	struct qujian
	{
		int num1;
		int num2;
	};
	struct qujian quj[50000];
	int n,i,j,a,b;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&quj[i].num1);
		scanf("%d",&quj[i].num2);
	}
	for(i=0;i<n-1;i++)
	{
		for(j=0;j<n-1-i;j++)
		{
			if(quj[j].num1>quj[j+1].num1)
			{
				a=quj[j+1].num1;
				b=quj[j+1].num2;
				quj[j+1].num1=quj[j].num1;
				quj[j+1].num2=quj[j].num2;
				quj[j].num1=a;
				quj[j].num2=b;
			}
		}
	}
	a=quj[0].num1;
	b=quj[0].num2;
	for(i=1;i<n;i++)
	{
		if(quj[i].num1<=b&&quj[i].num1>=a)
		{
			if(quj[i].num2>b)
				b=quj[i].num2;
		}
		if(quj[i].num1>b)break;
	}
	if(i==n)
	{
		printf("%d %d",a,b);
	}
	else printf("no");
	return 0;
}


int main(){
	int n;
	scanf("%d",&n);
	struct qujian {
		int a,b;
	}qujian[50001];
	int i;
	for(i=0;i<n;i++){
		scanf("%d %d",&(qujian[i].a),&(qujian[i].b));
	}
	int max,min;
	min=qujian[0].a;
	max=qujian[0].b;
	for(i=0;i<n;i++){
		if(min>qujian[i].a){
			min=qujian[i].a;
		}
		if(max<qujian[i].b){
			max=qujian[i].b;
		}
	}
	int m;
	double s;

	for(s=1.0*min;s<=max;s=s+0.5){
		for(i=0;i<n+1;i++){
			if(i==n){
				m=0;
				break;
			}
			if(s<=qujian[i].b&&s>=qujian[i].a){
				break;
				m=1;
			}
		}
		if(m==0){
			printf("no");
			break;
		}
		if(s==max){
			printf("%d %d",min,max);
		}
	}
	return 0;
}


void f(char , char , char *,int *);
int main()
{
	char a[100], b, g;
	int la, sum[100] = {0};
	cin >> a;
	la = strlen(a);
	b = a[0];
	g = a[la - 1];
    f(b, g, a, sum );
	return 0;
}
void f(char b, char g, char * a, int * sum)
{
	int i, j, l;
	l = strlen(a);
	for (i = 0; i < l ; i++)
	{
		if ((l > 2) && ( a[i] == g) && (sum[i] == 0))
		{
			for (j = i; j >= 0; j--)
			{
				if ((sum [j] == 0) && (a[j] == b))
                {
					cout << j << " " << i << endl;
			        sum [i] = 1;
			        sum [j] = 1;
			        f(b, g, a, sum);
				}
			}
		}
	}
}


int main()
{
	char a[1000];
	char m,f;
	int i,j,temp;
	gets(a);
	m=a[0];
	for(i=0;;i++)
		if(a[i]!=m) {f=a[i];break;}
	do
	{
		for(i=0;i<strlen(a)-1;i++)
		{
			if(a[i]=='0') continue;
			temp=0;
			for(j=i+1;j<strlen(a);j++)
			{

				if(a[i]==m&&a[j]==m) break;
				if(a[i]==m&&a[j]==f)
				{
					printf("%d %d\n",i,j);
					a[i]='0';
					a[j]='0';
					temp=1;
					break;
				}
			}
			if(temp==1) break;
		}
	}
	while(a[strlen(a)-1]!='0');
	return 0;
}


void getmarried (char str[], int num, char, char, int);
int main()
{
	char str[101];
	cin.getline(str, 101);
	int l = strlen(str);

	char b = str[0], g = str[l - 1];

	getmarried (str , 1, b, g , l);
}

void getmarried (char str[], int num, char b, char g, int l)
{
	if (str[num] == g)
	{
		for (int j = num - 1 ; j >= 0 ; j--)
		{
			if (str[j] == b)
			{
				cout << j << ' ' << num << endl;
				str[num] = str[j] = '#';
				break;
			}
		}
	}
	if (num < l - 1)
		return getmarried(str, num + 1, b, g , l);
}


char all[101];
int times[101];
void oper(char, int);
int main()
{
	char boy;
	int l;
	memset(times, 0, sizeof(times));
	cin.getline(all,101);
	l = strlen(all);
	boy = all[0];
	oper(boy, l);
	return 0;
}

void oper(char boy, int l)
{
	int i, j;
	if (l == 0)
		return;
	for (i = 1; i < l; i++)
	{
		if (all[i] != boy && all[i - 1] == boy)
		{
			cout << i - 1 + 2 * times[i - 1] << " " << i + 2 * times[i] << endl;
			for (j = i - 1; j < l - 2; j++)
			{
				all[j] = all[j + 2];
				times[j + 2]++;
				times[j] = times[j + 2];
			}
			l -= 2;
			break;
		}
	}
	oper(boy, l);
	return;
}


int b[100][2],count=0;

void deal(char a[],int num[],int n)
{
	int i,j;
	if(n!=0)
	{
	char mid;
	mid=a[0];
	for(i=0;i<n-1;i++)
	{
		if(a[i]==mid&&a[i+1]!=mid)
		{b[count][0]=num[i];b[count][1]=num[i+1];break;}
	}
	for(j=i+2;j<n;j++)
	{a[j-2]=a[j];num[j-2]=num[j];}
	count++;
	deal(a,num,n-2);
	}
}

void main()
{
	char m,ar[100];
	int i,n,num[100];

	gets(ar);
	m=ar[0];
	n=strlen(ar);
	for(i=0;i<n;i++)
	{num[i]=i;}

	deal(ar,num,n);

	for(i=0;i<n/2;i++)
	{printf("%d %d\n",b[i][0],b[i][1]);}
}


int main()
{
	char a[100];
	gets(a);
	int length=strlen(a);
	char nan,nv;
	nan=a[0];
	int i,j;
	for(i=0;i<length;i++)
	{
		if(a[i]!=nan) {nv=a[i];break;}
	}
    int b[100]={0};
	for(i=0;i<length;i++)
	{
		if(a[i]==nv)
		{
			for(j=i-1;j>=0;j--)
			{
				if(a[j]==nan&&b[j]==0) {printf("%d %d\n",j,i);b[j]=1;break;}
			}
		}
	}
	/*printf("%c %c",nan,nv);*/
	return 0;
}


int i;
char row[100];
int match(int x)
{
int y;
if(x==i)
   return 1;
if(row[x]==row[0])
   y=match(x+1);
   else
   return x;
cout<<x<<" "<<y<<endl;
return match(y+1);
}
int main()
{
cin>>row;
i=strlen(row);
match(0);
return 0;
}


int l;
struct stu
{int num;
int sex;}a[100];
int main()
{char s[101],p;
int i,j,L,k;
scanf("%s",s);
l=strlen(s);
p=s[0];
for(i=0;i<l;i++)
{if(s[i]==p)
a[i].sex=1;
else
	a[i].sex=2;
a[i].num=i;}
L=l/2;
for(i=0;i<L;i++)
{for(j=0;j<l;j++)
{k=j+1;
while(a[k].sex==0)
{k++;}
	if(a[j].sex==1&&a[k].sex==2)
{printf("%d %d\n",a[j].num,a[k].num);
a[j].sex=a[k].sex=0;
break;}}}}


/* title :????*
* author : ???*
* time : 2011.11.9 */

char c[100];
char boy;
int n, current;

int tell(int num)
{
	int num2;
	if(num == n - 1)
		return num;
	if(c[num] == boy)
	{
		num2 = tell(num + 1);
		while(num2 == -1)
			num2 = tell(current + 1);
		cout << num << " " << num2 << endl;
		return -1;
	}
	else
	{
		current = num;
		return num;
	}
}

int main()
{
	int m;
	cin >> c;
	boy = c[0];
	n = strlen(c);
	m = tell(0);
	return 0;
}


char sex[2];

void check(char line[], int n)
{
	int i;
	if (n == strlen(line) - 1)
	{
		cout << 0 << ' ' << n << endl;
		exit (0);
	}
	else
	{
		if (line[n] != sex[1])
			check(line, n + 1);
		else
		{
			for (i = n - 1; i >= 0; i--)
			{
				if (line[i] == sex[0])
				{
					cout << i << ' ' << n << endl;
					line[i] = ' ';
					line[n] = ' ';
					break;
				}
			}
		}
		check(line, n + 1);
	}
}

int main()
{
	char line[501];
	cin.getline(line, 501);
	sex[0] = line[0];
	sex[1] = line[strlen(line) - 1];

	check(line, 1);

	return 0;
}


char a[100];
void f(char a[], int n)
{
	int flag = 0, i, h = 0, k, sum = 1, m;
	for (i = 1; i <= n - 1; i ++)
	{
		switch (a[i])
		{
		case '(':
			{
				m = 1;
				break;
			}
		case ')':
			{
				m = -1;
				break;
			}
		case '*':
			{
				m = 0;
				break;
			}
		}
		sum = sum + m;
		switch (sum)
		{
		case 2:
			{
				sum = sum - 1;
				k = i;
				h = 1;
				break;
			}
		case 1:
			break;
		case 0:
			{
				flag = 1;
				if (h == 1)
				{
					cout << k << " " << i << endl;
					a[k] = '*';
					a[i] = '*';
				}
				else
				{
					cout << "0 " << i << endl;
                }
			}
		}
		if (flag == 1)
			break;
	}
}

int main()
{
	int n, q = 0;
	cin >> a;
	n = strlen(a);
	for (q = 1; q <= n-1; q ++)
	{
		if (a[q] == a[0])
			a[q] = '(';
		else
			a[q] = ')';
	}
	for (q = 1; q <= (n/2); q ++)
		f(a, n);
	return 0;
}


void print(char str[100])
{
	int stack[100];
	int i,j=0;
	int la;
	la=strlen(str);
	for(i=0;i<la;i++)
	{
		if(str[i]==str[0])
			stack[j++]=i;
		else if(str[i]!=str[0])
		{
			cout<<stack[j-1]<<' '<<i<<endl;
		    j--;
		}
	}
}
int main()
{
	char str[101];
	cin.getline(str,101);
	print(str);
	return 0;
}


char str[101],boy,girl;
void paidui();
int l;
int main()
{
	cin.getline(str,101);
	boy=str[0];
	for(int i=1;;i++)
	{if(str[i]!=boy) {girl=str[i];break;}}
	for(int i=0;str[i]!='\0';i++)
		l=i;
	for(int i=0;i<=l;i++)
	{paidui();}
	cout<<0<<' '<<l;
	return 0;
}
void paidui()
{
	for(int i=1;i<l;i++)
	{	if(str[i]==boy)
		{
			int x=1;
			while(str[i+x]=='\0'){x++;}
			if(str[i+x]==girl)
			{cout<<i<<' '<<i+x<<endl;
			str[i]=str[i+x]='\0';
			break;}
		}
	}
}


int i,Husband[50]={0};
int marry( char engage[] );
int main()
{
	int t;
	char engage[100],couple[100];
	cin>>engage;
	i=strlen( engage );
	for ( t=0 ; t<i ; t++ )
		couple[t]=engage[t];
	marry( engage );
	for ( t=1 ; t<i ; t++ )
	{
		if ( couple[t]!=couple[0] )
			cout<<Husband[t]<<" "<<t<<endl;
	}
    return 0;
}
int marry( char engage[] )
{
	int j,k;
	for ( j=1 ; j<i ; j++ )
	{
		if ( engage[j]!=engage[0]&&engage[j]!='X' )
		{
			k=j-1;
			while ( engage[k]=='X' )
				k--;
			if ( engage[k]==engage[0] )
			{
			    Husband[j]=k;
				engage[j]='X';
				engage[k]='X';
				if ( k==0 )
					return 0;
			}
		}
	}
	marry( engage );
}


char a[1000];
int match(char,char);
int main()
{
	char b, g; int i;
	cin >> a;
	b= a[0];
	for (i = 0; i <= 999; i++)
		if(a[i] != b)
		{
			g = a[i];
			break;
		}
	match( b, g);
	return 0;
	}

int match(char b, char g)
{
	int i, j;
	for ( i = 0; a[i] != '\0'; i++)
		if(a[i] == g)
			break;
	if(a[i]=='\0')
		return 0;
	for ( j=i; j>=0; j--)
		if(a[j] == b)
		{
			cout<<j<<' '<<i<<endl;
				break;
		}
	a[j]='*';
	a[i]='*';
	match( b,g);
}


char str[101];

void match(int, char, char);

int main()
{
	cin.getline(str,101);
	char b = str[0];   //??????
	int len = strlen(str);
	char g = str[len - 1];   //??????
	match(0, b, g);
	return 0;
}

void match(int i, char b, char g)
{
	int j;
	if (str[i] == '\0')
		return;
	if (str[i] == g)
	{
		str[i] = '*';
		for (j = i - 1; j >= 0; j--)
		{
			if (str[j] == b)
			{
				str[j] = '*';
				break;
			}
		}
		cout << j << " " << i << endl;
	}
	match(i + 1, b, g);
	return;
}


int main()
{
	int N,Number[2000];
	char C[2000];
	int Top = 0;
	gets(C);
	N = strlen(C);
	for (int I = 0; I < N; I ++)
	{
		if (C[I] != C[0])
		{
			cout << Number[Top] << " " << I << endl;
			Top --;
		}
			else Number[++Top] = I;
	}
}


int main()
{
    char st[1000]; cin.getline(st,1000);
char a=st[0];
    int count=0,z[1000];
    for (int i=1;i<=strlen(st);i++)
        if (st[i-1]==a) {count++; z[count]=i;}
        else {cout<<z[count]-1<<' '<<i-1<<endl; z[count]=0; count--;}

    return 0;
}


int panduan(char a[],char b,char g)
{
	int l,bj,gj,bs,gs,i,k,t;
	l=strlen(a);
	bj=0;gj=0;bs=0;gs=0;
	k=l-1;
	while(a[k]!=b&&a[k]!=g)
		k--;
	for(i=k;i>=0;i--)
	{
		if(a[i]==b)
			bj++;
		else if(a[i]==g)
			gj++;
		if(bj==gj)
		{
			bs=i;
			gs=k;
		    break;
		}
	}
	t=100*bs+gs;
		return (t);
}
int main()
{
	char d[100];
	int n,length,m,i,j,t,k;
	char boy,girl;
	int weishu[100][2];
	cin>>d;
	length=strlen(d);
	boy=d[0];
	girl=d[length-1];
	for(n=0;n<length/2;n++)
	{
		m=panduan(d,boy,girl);
		weishu[n][0]=m/100;
		weishu[n][1]=m%100;
		d[m/100]='0';
		d[m%100]='0';

	}
	for(j=0;j<n-1;j++)
	{
		for(i=0;i<n-1-j;i++)
		{
			if(weishu[i][1]>weishu[i+1][1])
			{t=weishu[i][1];weishu[i][1]=weishu[i+1][1];weishu[i+1][1]=t;
			m=weishu[i][0];weishu[i][0]=weishu[i+1][0];weishu[i+1][0]=m;
			}
		}
	}
	for(i=0;i<length/2;i++)
		cout<<weishu[i][0]<<" "<<weishu[i][1]<<endl;
	return 0;
}


int queue[110];
int l;
int num[110];
void f(int x[],int y)
{
	int j,k=0;
	for(j=0;j<y;j++)
	{
		if(x[j]==1)
		{
			num[k] = j;
			k++;
		}
		else if(x[j]==0)
		{
			k--;
			cout<<num[k]<<" "<<j<<endl;
		}
	}
}
int main()
{
	char game[110];
	int i;
	cin>>game;
	l = strlen(game);
	for(i=0;game[i]!=0;i++)
	{
		if(game[i]==game[0])
		{
			queue[i] = 1;
		}
		else
		{
			queue[i] = 0;
		}
	}
	f(queue,l);
	return 0;
}


int main()
{
    void paixu(char num[10000]);
    char num[10000];
    cin.getline(num,10000);
    paixu(num);
    return 0;
}
void paixu(char num[])
{
    char boy,girl;
    int i=0,j,k;
    boy=num[0];
    while(num[i]!='\0')
    {
        if(num[i]!=boy&&num[i]!=' ')
        {
            girl=num[i];
            break;
        }
        i++;
    }
    while(num[i]!='\0')
    {
        if(num[i]!=boy)
        {
            for(j=i-1;;j--)
            {
                if(num[j]!=' ')
                {
                    cout<<j<<" "<<i<<endl;
                    break;
                }
            }
            num[j]=' ';
            num[i]=' ';
            break;
        }
        i++;
    }
    if(num[0]!=' ')
    {
        paixu(num);
    }
}


int main()
{
    char chn[120];
    int i,l;
    int z,t;
    char a,b;
    scanf("%s",chn);
    l = strlen(chn);
    a = chn[0];
    for(i = 0;i < l ;i ++)
       if(chn[i] != a)
          b = chn[i];
    while(1)
    {
      z = -1;
      t = 0;
      for(i = 0;i < l; i++)
      {
        if(z == -1 && chn[i] == a)
           z = i;
        else if(z >= 0 && chn[i] == b)
          {
             printf("%d %d\n",z,i);
             chn[z] = 0;
             chn[i] = 0;
             t ++;
             break;
          }
        else if(z >= 0 && chn[i] == a)
          z = i;
      }
      if(!t) break;
    }

 return 0;
}


struct bg
{
	int b;
	int g;
};

int main()
{
	char peo[101]={0},e;
	int i,j,k=0,l;
	struct bg bag[50];

	gets(peo);

    l=strlen(peo);
	e=peo[l-1];
	for(i=1;i<l;i++)
	{
		if(peo[i]==e)
		 for(j=i-1;j>=0;j--)
				  if(peo[j]!='\0')
					  { bag[k].b=i;
		                bag[k].g=j;
						k++;
						peo[i]='\0';
						peo[j]='\0';
				        break;}
	}
		for(i=0;i<k;i++)
			printf("%d %d\n",bag[i].g,bag[i].b);

		return 0;
	}


void operation(char str[]);
int num=0;
char boy,girl;
int main()
{
  char str[100];//?50???????????
  cin>>str;
  boy=str[0];
  int i;
  for(i=0;str[0]!='\0';i++)
  {
    if(str[i]!=boy)
{
girl=str[i];
break;
}
  }
  //cout<<boy<<girl;
  operation(str);
  return 0;
}
void operation(char str[])
{
  int i,j;
  int counter=0;
  for(i=0;str[i]!='\0';i++)
  {
    if(str[i]==boy)
{
  for(j=i+1;;j++)
  {
if(str[j]==boy)
break;
    if(str[j]==girl)
{
cout<<i<<" "<<j<<endl;
        str[i]='e';
        str[j]='e';
        counter=1;
        num++;
break;
}
  }
}
if(counter==0)
continue;
else
break;
  }
  if(num<strlen(str))//strlen?????????????
  operation(str);
}


int main(int argc, char* argv[])
{
char string[101];
scanf("%s",string);
int len=strlen(string);
int i;
int a[100]={0};
int num=0,j;
for(i=0;i<len;i++){
	if(string[i]==string[0]) {
		a[num]=i;
		num++;}
	if(string[i]!=string[0]){
		for(j=num-1;j>=0;j--){
			if(a[j]!=-1) {
				printf("%d",a[j]);
				a[j]=-1;
				break;
			}
		}
		printf(" %d\n",i);
	}

}

	return 0;
}


int find(char a,int b,int c);
int main()
{
	char d;
	scanf("%c",&d);
	find(d,0,1);
//	return 0;
}
int find(char a,int b,int c)
{
	char t;
    scanf("%c",&t);
	while(t==a)
	{
		c=find(a,c,c+1);
		scanf("%c",&t);
	}
	printf("%d %d\n",b,c);
	return c+1;
}


char Dat[maxn];
int n,Stac[maxn],Top;
int main() {
scanf("%s",&Dat);
n = strlen(Dat);
Top = 0;
for (int i = 0; i < n; i++)
    if (Dat[i] == Dat[0])
	Stac[++Top] = i;
    else
	printf("%d %d\n",Stac[Top--],i);
}


void f(char a[],int n,char x,char y)
{
     int i,j,k=1;
     for(i=0;i<n;i++)
     {
        if(a[i]==y)
            for(j=i;j>=0;j--)
                if(a[j]==x)
                {
                      printf("%d %d",j,i);
                      a[i]=0;
                      a[j]=0;
                      k+=2;
                      if(k<n) printf("\n\n");
                      break;
                }
     }
}

int main()
{
     char a[100],x,y;
     int i,n;
     gets(a);
     n=strlen(a);
     x=a[0];
     for(i=0;i<n;i++)
        if(a[i]!=x)  y=a[i];
     f(a,n,x,y);

}


int sum1 = 0, sum2 = 0;
void cal(char a[], int k, char ch)
{
	int i,j;
	int longth = strlen(a);
	for(i = k;;i++)
	{
		if(a[i] != ch && a[i] != '0')
		{
			a[i] = '0';
			for(j = i - 1; ; j--)
			{
				if(a[j] == ch && a[j] != '0')
				{
					a[j] = '0';
					cout << j << ' ' << i << endl;
					break;
				}
			}
			break;
		}
	}
	if(i == longth - 1)
	return;
	else cal(a,i+1,ch);
}
int main()
{
	char a[200];
	cin >> a;
	char ch = a[0];
	cal(a, 0, ch);
	return 0;
}


/*
 * file    homework 14_2
 * author  ??
 * date    2010-1-1
 * description
           ???????????
*/

int Match(int n, char a[], char boy, char girl);

int main()
{
	int len;
	char a[100];
	char boy, girl;
	cin >> a;
	len = strlen(a);
	boy = a[0];
	girl = a[len - 1];
    Match(0, a, boy, girl);

	return 0;
}

int Match(int n, char a[], char boy, char girl)
{
	int m;
	if(a[n] == girl)
		return n;
	m = Match(n + 1, a, boy, girl);
	cout << n << " " << m << endl;
	if (a[m + 1] != '\0')
		return Match(m + 1, a, boy, girl);
	else
		return 0;

}


int main(int argc, char* argv[])
{
	char s[10000];
	char a,b;
	int n;

	gets(s);
	n=strlen(s);
	a=s[0];
	b=s[n-1];
	int i;
	for(i=1;i<n;i++)
	{
		if(s[i]==b)
		{
			int j;
			int first=0;
			for(j=i-1;j>=0;j--)
			{
				if(s[j]==a&&first==0)
				{
					printf("%d %d\n",j,i);
						first=1;
						s[i]=' ';
						s[j]=' ';
				}
			}

		}

	}

	return 0;
}


int main()
{
	void match(char str[100],int b,int k,int bg[50][2]);
	char str[100];
	int bg[50][2];
	int i,j,total,len,temp;

	cin.getline(str,101,'\n');
	len=strlen(str);
	total=len/2;

	match(str,0,0,bg);

	for (i=1;i<total;i++)
		for (j=0;j<total-i;j++)
			if ( bg[j][1]>bg[j+1][1] )
			{
				temp=bg[j][1];
				bg[j][1]=bg[j+1][1];
				bg[j+1][1]=temp;

				temp=bg[j][0];
				bg[j][0]=bg[j+1][0];
				bg[j+1][0]=temp;
			}

	for (i=0;i<total;i++)
		cout << bg[i][0] << " " << bg[i][1] << endl;

	return 0;
}

void match(char str[100],int b,int k,int bg[50][2])
{
	char ch=str[0];
	int i,len=strlen(str);
	int m=1;					// m flags the match case of str[b]

	if (str[b]==ch)
	{
		for (i=b+1;i<len;i++)
		{
			if ( str[i]==ch )
				m++;
			else
				m--;
			if (m==0)
			{
				bg[k][0]=b;
				bg[k][1]=i;
				k++;
				break;
			}
		}
	}

	b++;

	if (b!=len)
		match(str,b,k,bg);

}


struct result{
	int man;
	int woman;
}res[50]={0};
struct result temp;
int main()
{
	int i,j,p=-1,sum=0,len;
	char str[100]={0},std;
	gets(str);
	std=str[0];
	len=strlen(str);
	for(j=0;;j++){
		for(i=0;i<len;i++){
			if(str[i]==std&&str[i]!=str[i+1+j*2]&&str[i]!='\0'&&str[i+1+j*2]!='\0'){
				p++;
				res[p].man=i;
				res[p].woman=i+1+j*2;
				str[i]='\0';
				str[i+1+j*2]='\0';
				sum++;
			}
			else continue;
		}
		if(sum==len/2) break;
	}
	for(i=1;i<p+1;i++){
		for(j=0;j<p+1-i;j++){
			if(res[j].woman>res[j+1].woman){
				temp=res[j];
				res[j]=res[j+1];
				res[j+1]=temp;
			}
		}
	}
	for(i=0;i<=p;i++){
		printf("%d %d\n",res[i].man,res[i].woman);
	}
	return 0;
}


int main(){
char num[100]={0}; int i,j,k,m,t;
 gets(num); t=strlen(num);
 for(i=0;i<t;i++)
{ while(num[i]!=num[0]&&num[i]!='\0')
{     k=i;
    for(j=k;j>=0;j--)
   if(num[j]==num[0])
     break;
printf("%d %d\n",j,k);
num[j]='\0'; num[k]='\0';
           }
               }
return 0;

}


int i=0,j=0;
int a[200];
char d;
int solve()
{
 char c;
 scanf("%c",&c);
 if(c==d) {
            a[i]=j;
            j++;
            i++;
            solve();
            }
   if(c!=d){
            printf("%d %d\n",a[i-1],j);
            i--;
            j++;
            if(i==0) return 0;
            solve();
            }
}
int main()
{
char c;
scanf("%c",&c);
  d=c;
  a[i]=j;
  j++;
  i++;
  solve();

}


char a[100000000];
int n;
char e,f;
int lala(){
	int i,j;
	if(a[0]=='0')return 0;
	for(i=0;i<n;i++){
		if(a[i]==e){
			for(j=1;j<n-i;j++){
				if(a[i+j]=='0')continue;
				else if(a[i+j]==f){
					a[i]='0';a[i+j]='0';
					cout<<i<<' '<<i+j<<endl;
					return lala();
				}
				else if(a[i+j]==e)break;
			}
		}
	}return 0;
}
int main(){
	cin>>a;
	n=strlen(a);
	for(int i=1;i<n;i++)
		if(a[i]!=a[0]){
			f=a[i];
		}
	e=a[0];
	lala();
	return 0;
}


int main()
{
	int i,j,count=0;
    char line[200],tmp;
	scanf("%s",line);
	tmp=line[0];
	for(i=0;line[i];i++) count++;
	for(i=0;line[i];i++)
	{
		if(line[i]==tmp)     //???
		{
			for(j=i+1;line[j];j++)
			{
				if(line[j]==tmp) break;
				else if(line[j]!=tmp&&line[j]!='0')    //???
				{
					printf("%d %d\n",i,j);
					line[i]=line[j]='0';
					i=0;
				    break;
				}
			}
		}
	}
	printf("0 %d\n",count-1);
	return 0;
}


int stack[100];
int top=-1;

int pop(){
	top--;
	return stack[top+1];
}
void push(int e){
	top++;
	stack[top]=e;
}

int main(){
	char s[100];
	int i;
	char nan;
	scanf("%s",s);
	nan=s[0];
	push(0);
	for(i=1;s[i];i++){
		if(s[i]==nan) push(i);
		else{
			printf("%d %d\n",pop(),i);
		}
	}

	return 0;
}


char a[1000];
int n;

int xx (int k)
{
     int x,y;
     x=k;
     y=k+1;
     while (a[y]==a[x])
     y=xx(y);
     cout <<x<<" "<<y<<endl;
     return y+1;
}

int main ()
{
    cin.getline(a,999,'\n');
    n=strlen(a);
    int p=0;
    while (1)
    {
          p=xx(p);
          if (p==n)
          break;
    }
    return 0;
}


int main()
{
	char line[101], b;
	int len, count = 0;
	int i, j;
	int intline[101];
	cin.getline(line, 101);
	b = line[0];
	len = strlen(line);
	for (i = 0; i < len; i++)
	{
		if (line[i] == b)
			intline[i] = 1;				//1??boy
		else
			intline[i] = 2;				//2??girl, 3?????????????
	}
	while (count < len / 2)
	{
		for (i = 0; i < len; i++)		//????????????
		{
			if (intline[i] == 2)
				break;
		}
		for (j = i; j >= 0; j--)		//????????????????
		{
			if (intline[j] == 1)
				break;
		}
		intline[i] = 3;					//???????????
		intline[j] = 3;
		cout << j << " " << i << endl;
		count++;
	}
	return 0;
}


void main()
{
	char pupils[100],g;
	int i=0,j,k;
	gets(pupils);
	k=strlen(pupils);
	g=pupils[k-1];
	while (i<k)
	{
		if (pupils[i]==g)
		{
			j=1;
			while (pupils[i-j]==0) j++;
			pupils[i]=0;
			pupils[i-j]=0;
			printf("%d %d\n",i-j,i);
		}
		i++;
	}
}


void leave(char a[], char b)
{
    int i,temp;
    if (a[0] == b)
    {
        for (i = 0; a[i] != '\0'; )
        {
            if (a[i] == b )
            {
                temp = i;
                i++;
                while (a[i] == 0)
                {
                    i++;
                }
                if (a[i] != b && a[i] != 0 )
                {
                    a[i] = 0;
                    a[temp] = 0;
                    cout << temp << " " << i << endl;
                }
            }
        }
        leave(a,b);
    }
}

int main()
{
    char a[100];
    char b;
    cin.getline(a, 100);
    b = a[0];
    leave(a,b);
    return 0;
}


void bubble(int array[],int n);
void main()
{
	struct answer
	{
		int girl;
		int boy;
	};
	char test[MAXSIZE]={'\0'},boy,girl;
	int len,i,j,p;
	struct answer ans[MAXSIZE]={0,0},temp;

	scanf("%s",test);
	len=strlen(test);
	boy=test[0];
	girl=test[len-1];

	p=0;
	for(i=0;i<len;i++)
	{
		if(test[i]==girl)
		{
			for(j=i-1;j>=0;j--)
			{
				if(test[j]==boy)
				{
					ans[p].boy=j;
					ans[p].girl=i;
					test[i]=girl+boy;
					test[j]=girl+boy;
					p++;
					break;
				}
			}
		}
	}

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

	for(i=0;i<p;i++)
	{
		printf("%d %d\n",ans[i].boy,ans[i].girl);
	}
}


int main()
{
	int a[111],i, n = 0;;
	char s[111];
	cin >> s;
	char boy=s[0];
	for (i = 0; s[i]; ++i)
		if (s[i] == boy) a[++n] = i;
		else cout << a[n--] << " " << i << endl;
	return 0;
}


char set[100];
void getBoy(int i,char b,char g){
	if(set[i]=='\0')return;
	while(set[i]!='\0' && set[i]!=g)++i;
	int j=i-1;
	while(j>=0 && set[j]!=b)--j;
	cout<<j<<" "<<i<<endl;
	set[i]=0;set[j]=0;
	getBoy(i+1,b,g);
}
int main(){
	cin>>set;
	char b,g;
	b = set[0];
	g = set[strlen(set)-1];
	getBoy(0,b,g);
	return 0;
}


int out(char str[100],char a,char b)
{
    if(str[0]=='!')  return 1;
    else
    {
        for(int i=0;i<strlen(str);i++)
        {
                if(str[i]==b)
                {
                             str[i]='!';
                             for(int j=i;j>=0;j--)
                             {
                                     if(str[j]=='!')  continue;
                                     else
                                     {
                                             cout<<j<<' '<<i<<endl;
                                             str[j]='!';
                                             return out(str,a,b);
                                     }
                             }
                }
        }
    }
}
int main()
{
    char  line[100];
    cin>>line;
    out(line,line[0],line[strlen(line)-1]);
    return 0;
}


void fuck(int n);
int main()
{
	char c,boy;
	int a[100],i=0,j;
	boy=cin.get();
	a[0]=1;
	while((c=cin.get())!='\n')
	{
		i++;
		if(c==boy) a[i]=1;
		else {
			a[i]=-1;
			j=i-1;
			while(a[j]!=1) j--;
			cout<<j<<" "<<i<<endl;
			a[j]=0;}
	}
	return 0;
}


int main ()
{
	struct
	{
		char ch;
		int num;
	}student[100];//?????????????????
	int sum = 0;
	char temp;
	while (true)//???????????
	{
		cin.get(temp);
		if ( temp == '\n' ) break;
		student[sum].ch = temp;
		student[sum].num = sum;
		sum ++;
	}
	char boy, girl;//?????????????????
	boy = student[0].ch;
	girl = student[sum-1].ch;
	for ( int i = 0; i < sum/2; i ++ )//????????????
		for ( int j = 0; j < sum - 1; j ++ )
		{
			int k = j + 1;
			while( student[k].ch == 0 ) k ++;
			if ( student[j].ch == boy && student[k].ch == girl )
			{
				cout << student[j].num << " " << student[k].num << endl;
				student[j].ch = 0;
				student[k].ch = 0;
				break;
			}
		}
	return 0;
}


main()
{
	int i,j,k,e,f,*e_point,*f_point,flag;
	char a,b,c[100],z=' ';
	gets(c);
	e_point=&e;
	f_point=&f;
	a=c[0];b=c[strlen(c)-1];
	for(k=1;k<=strlen(c)/2;k++)
	{
		for(i=0;i<strlen(c);i++)
	    {
	    	flag=0;
	    	if(c[i]==a)
	    	{
	    		j=i+1;
	    		while(c[j]==z)
	    		{
	    			j+=1;
	    		}
	    		if(c[j]==b)
	    		{
	    			e=i;
	    			f=j;
	    			c[i]=z;
	    			c[j]=z;
	    			flag=1;
	    		}
	    	}
	    	if(flag)break;
	    }
		printf("%d %d\n",e,f);
	}
}


int main()
{
	char children[100];
	gets(children);
	int boys[50],i,top=0;
	boys[0] = 0;
	for(i=1; children[i]; i++)
		if(children[i] == children[0])
			boys[++top] = i;
		else
			printf("%d %d\n", boys[top--], i);
	return 0;
}


char x,y;
int main()
{
	int i;
	void result(char a[]);
	char line[200];
	scanf("%s",line);
	x=line[0];
	for(i=0;i<=strlen(line)-1;i++)
	{
		if(line[i]!=x)
		{y=line[i];
		break;}
	}
    result(line);

	return 0;
}
void result(char a[])
{
    if((a[0]!='.')&&(a[strlen(a)-1]!='.'))
	{
	int i,j;
	for(i=1;i<=(strlen(a)-1);i++)
	{
		if(a[i]==y)
		{
		for(j=i-1;j>=0;j--)
		{

			if (a[j]==x)
			{
				printf("%d %d",j,i);
				printf("\n");
				a[i]='.';a[j]='.';
				break;
			}
		}
		}
	}
    result(a);
	}

}


int main()
{
	char line[150];char girl;
	gets(line);
	 int len=strlen(line);
	char boy=line[0];
	for(int i=0;i<len;i++)
	{
		if(line[i]!=boy){
			girl=line[i];break;
		}
	}
	for(int i=0;i<len;i++)
	{
		if(line[i]==girl)
		{
			for(int j=i-1;j>=0;j--)
			{
				if(line[j]==boy)
				{
					printf("%d %d\n",j,i);
					line[j]=' ';break;
				}
			}
		}
	}
	getchar();
	getchar();
	return 0;
}


int n,vis[510];
char s[510];

void dfs(int p,int q)
{
	for(;vis[p];p++);
	if (p>=n) return;
	if (s[p]!=s[0])
		cout<<q<<' '<<p<<endl,vis[p]=vis[q]=1;
	else
		for(;!vis[p];) dfs(p+1,p);
}

int main()
{
	cin>>s;
	n=strlen(s);
	dfs(0,-1);
	return 0;
}


char m[100];
int num = 0;
int q = 0;

void search(int a, int b, char boy, char girl)
{
	if (num == (b + 1) / 2)
		return;
	int i, t;
	for (i = a; i < b; i++)
	{
		if (m[i] == boy)
		{
			for (t = i + 1; t < b; t++)
			{
				if (m[t] != '.')
				{
					break;
				}
			}
			if (m[t] == girl)
			{
				num ++;
				m[i] = '.';
				m[t] = '.';
				break;
			}
		}
	}
	cout << i << " " << t << endl;
    search(a, b, boy, girl);
}

int main()
{
    char boy, girl;
	int len;
	cin >> m;
	len = strlen(m);
	boy = m[0];
	girl = m[len - 1];
	search(0,len - 1, boy, girl);
	return 0;
}


char str[100], b, g;
void match(int k)
{
	int i;
	if(str[k] == '\0')
		return;
	if(str[k] == g)
	{
		str[k] = '*';
		for(i = k - 1; i >= 0; i--)
			if(str[i] == b)
			{
				str[i] = '*';
				cout << i << " " << k << endl;
				break;
			}
	}
	match(k + 1);
}

int main()
{
	int length;
	cin.getline(str,100);
	length = strlen(str);
	b = str[0];
	g = str[length - 1];
	match(0);
	return 0;
}


int girl = -1;
char boy_symbol = 0;
int main()
{
    int Match(int boy);
    Match(0);
    return 0;
}
int Match(int boy)
{
	girl ++;
    char ch;
    ch = cin.get();
	if (boy_symbol == 0) boy_symbol = ch;
    if (ch != boy_symbol)
    {
        return girl;
    }
    else
    {
        int t = Match(boy + 1);
        cout << boy << " " << t << endl;
        if(boy != 0)
            return Match(t + 1);
    }
}


int main()
{
	char str[110];
	cin>>str;
	int length;
	length=strlen(str);
	int i,j,k=0;
	char b,g;
	b=str[0];
	for(i=0;i<length;i++){
		if(str[i]!=b){
			g=str[i];
			break;
		}
	}
	while(1){
		if(str[0]==' '){
			break;
		}
		for(i=1;i<length;i++){
			if(str[i]==g){
				j=i-1;
				while(str[j]==' '){
					j--;
				}
				if(str[j]==g){
					break;;
				}
				else if(str[j]==b){
					cout<<j<<" "<<i<<endl;
					str[i]=' ';
					str[j]=' ';
					break;
				}
			}
		}
	}
	return 0;
}


void leave(char a[]);
int main()
{
   char children[1000000],boy,girl;
   cin>>children;
   int i=0,n=strlen(children);
   for(i=0;;i++)
   {
       boy=children[0];
       if(children[i]!=boy) {girl=children[i]; break;}
   }
   for(i=0;i<n;i++)
   {
       if(children[i]==boy) continue;
       for(int j=i;j>=0;j--)
       {
           if(children[j]==boy)
           {
               cout<<j<<" "<<i<<endl;
               children[j]=0;
               break;
           }
       }
   }
   return 0;
}


int len;
char a[200],b,g;
int match (int p)
{
	if (p==len-1)
		return p;
	int q;
	if (a[p]==b)
	{
		q=match(p+1);
		cout<<p<<" "<<q<<endl;
		return match(q+1);
	}
	else
		return p;
}
int main()
{
	cin>>a;
	len = strlen(a);
	b=a[0];
	g=a[len-1];
	match(0);
}


int main()
{
	char queue[100];
	cin.getline(queue,100);
	int i,j;
	for(i=1;i<strlen(queue);i++)
	{
		if(queue[i]!=queue[0])
		{
			queue[i]=')';
		}
		if(queue[i]==queue[0])
		{
			queue[i]='(';
		}
	}
	queue[0]='(';
	for(i=0;i<strlen(queue);i++)
	{
		if(queue[i]==')')
		{
			j=i-1;
			while((queue[j]=='*')&&(j>0))
			{
				j=j-1;
			}
			cout<<j<<" "<<i<<endl;
			queue[j]='*';
			queue[i]='*';
		}
	}
	return 0;
}


void Loop(char s[],int n)
{
	int i, p, q;
	for(i=1;i<n;i++)
	{
		if(s[i]!=s[0]&&s[i])
		{
			p = i;
			break;
		}
	}
	if(p==n-1)
	{
		cout << "0 " << n-1 << endl;
		return;
	}
	for(i=p;i>=0;i--)
		if(s[i]==s[0])
		{
			q = i;
			break;
		}
	cout << q << " " << p << endl;
	s[q] = s[p] = 0;
	Loop(s,n);
}
int main()
{
	int n, i;
	char s[MAXN];
	cin >> s;
	n = strlen(s);
	Loop(s,n);
	return 0;
}


/*
 * 1000012739_finaltest3_7.cpp
 *
 *  Created on: 2011-1-8
 *      Author: ???
 *		Title: ????
 */

int indexx=-1;
char boy='\0',girl='\0';

int slv(void)
{
	char c;
	int ind,m;
	while (true)
	{
		indexx++;
		cin>>c;
		if (indexx==0)
			boy=c;
		else
			if (girl=='\0' && c!=boy)
				girl=c;
		if (c==girl)
		{
			return indexx;
		}
		else
		{
			ind=indexx;
			m=slv();
			cout<<ind<<' '<<m<<endl;
		}
	}
}

int main()
{
	slv();
	return 0;
}


int total,i,j;
char boy,girl;
char child[100];
int flag[100];
void departure();

int main()
{
    cin>>child;
    total=strlen(child);
    boy=child[0];
    girl=child[total-1];
    for(i=0;i<=total-1;i++)flag[i]=i;
    departure();

    return 0;

}
 void departure()
{
    if(total==0)return;
    else
    {
        for(i=1;i<=total-1;i++)
        {

           if(child[i]==girl&&child[i-1]==boy)
           {
               cout<<flag[i-1]<<' '<<flag[i]<<endl;
              if(i!=total-1)
              {
                  for(j=i+1;j<=total-1;j++)
                  {
                      child[j-2]=child[j];
                      flag[j-2]=flag[j];

                  }
                 total-=2;
              }
              else total-=2;
            departure();
           }
        }
    }
}


char str[101];
int n=0;
void f(int m,char a,char b)
{
	if(m==0)
		return;
	int i=0,j=0;
	for(;i<n;i++)
		if(str[i]==b)
			break;
	for(j=i;j>=0;j--)
	{
		if(str[j]==a)
		{
			printf("%d %d\n",j,i);
			str[i]='*';
			str[j]='*';
			break;
		}
		else
			continue;
	}
	return f(m-1,a,b);
}
int main()
{
	scanf("%s",str);
	n=strlen(str);
	f(n/2,str[0],str[n-1]);
	return 0;
}


void main()
{
 char text[101],c,d;int i,j,k,a[51],b[51],n,x=0;
 gets(text);c=text[0];n=strlen(text);
 for(i=0;i<n;i++)  if(text[i]!=c)   {d=text[i];break;}
 n=strlen(text);
 for(i=0;i<n;i++)
 {if(text[i]==d)
 for(j=i-1;j>=0;j--)
 if(text[j]==c) {a[x]=i;b[x]=j;x++;text[i]='q';text[j]='q';break;}
  }
 for(i=0;i<x;i++)   printf("%d %d\n",b[i],a[i]);
}


/*??(15.2)????*/

char boy;

int queue(int num)//????num???????num?????girl???
{
	char input;
	input=getchar();
	if(input==boy)
	{
		int girl;
		girl=queue(num+1);
		printf("%d %d\n",num,girl);
		return queue(girl+1);
	}
	else return num;
}

int main()
{
	boy=getchar();
	printf("0 %d\n",queue(1));
	return 0;
}


int main()
{
int n,sp,st[100]={0};
char ch,boy;
scanf("%c",&boy);
for(n=sp=1;sp>0;n++)
{
     scanf("%c",&ch);
     if(ch==boy){
         st[sp]=n;
         sp++;
         }
     else{
         sp--;
        printf("%d %d\n",st[sp],n);}
 }
    return 0;
}


const int N = 110 ;

int q[N] ;
char str[N], a ;

int main ()
{
    scanf ("%s", str) ;
    for (int i = 0, t = 0; i < strlen (str); i ++ )
        if (str[i] == str[0])
            q[ ++ t] = i ;
        else printf ("%d %d\n", q[t -- ], i) ;
    return 0 ;
}


char c[1000],b,g;
int l;
void game(){
	for(int i=0;i<l;i++){
		if(c[i]==b){
			for(int j=i+1;j<l;j++){
				if(c[j]==' ')continue;
				else if(c[j]==b){i=j-1;break;}
				else {
					cout<<i<<' '<<j<<endl;
					c[i]=' ';c[j]=' ';
					for(int k=i-1;k>=0;k--){
						if(c[k]==b){
							i=k-1;
							break;
						}
					}
					break;
				}
			}
		}
	}
	if(c[0]!=' ')game();
}
int main(){
	cin>>c;
	l=strlen(c);
	b=c[0];
	for(int i=0;i<l;i++){
		if(c[i]!=b){
			g=c[i];
			break;
		}
	}
	game();
	return 0;
}


char a[100];
int counter;
int line[100];
void out(int l)
{
	int record;
	if (counter==0)
	{return;}
	for (int i=0;i<l;i++)
	{
		if (line[i]==1)
		{
			record=i;
			continue;
		}
		if (line[i]==0)
		{
			line[record]=-1;
			line [i]=-1;
			cout<<record<<' '<<i<<endl;
			counter-=2;
			out(l);
			break;
		}
	}
}

int main()
{
	cin.getline(a,100);
	char boy=a[0];
	int len=strlen(a);
	counter=len;
	for (int i=0;i<len;i++)
	{
		if (a[i]==boy)
		{line[i]=1;}
		else
		{line[i]=0;}
	}
	out(len);
	return 0;
}


int play(int a, int* blank1, int* blank2,int bad);

int main()
{
	char a[100];
	cin >> a;
	int blank1[100];
	int blank2[100];
	memset(blank1,-1,99 * sizeof(int));
	memset(blank2,-1,99 * sizeof(int));
	int w = 0,j = 0;
	for (;w < 100;w++)
	{
		if(a[w] != a[0])
		{
			blank1[j] = w;
			blank2[w] = j;
			j++;
		}
	}
if(j == 0)cout << j;
int i = 0;
	for (;i < j; i++)
	{
		cout << play(blank1[i],blank1,blank2,0) << ' ' << blank1[i] <<endl;
	}
if(i == 0)cout << i;
}

int play(int a, int* blank1, int* blank2,int bad)
{
	if(blank2[a - 1] == -1 && bad == 0)
		return a - 1;
	else if(blank2[a - 1] == -1 && bad != 0)
		return play(a - 1,blank1,blank2,bad-1);
	else
		return play(a - 1,blank1,blank2,bad+1);
}


void f(char a[], int l,char girl, char boy)
{
	if(a[0]!='.')
	{
		int i,j;
		for(i=1;i<l;i++)
		{
			if(a[i]==girl)
			{
				a[i]='.';
				for(j=i-1;j>=0;j--)
				{
					if(a[j]==boy)
					{a[j]='.';
					 printf("%d ", j);
					 j=-1;}
				}
				printf("%d\n", i);
				f(a,l,girl,boy);
				i=l;
			}
		}
	}
}

void main()
{
	char a[100];
	gets(a);
	int l;
	l=strlen(a);
	f(a,l,a[l-1],a[0]);
}


//
//  main.cpp
//  ????
//
//  Created by ???? on 13-12-26.
//  Copyright (c) 2013? ????. All rights reserved.
//

int main()
{
    char a[100];
    cin.getline(a,100);
    int num[100];
    int len=(int)strlen(a);
    //cout<<len;
    num[0]=0;
    int k=0;
    char b=a[0];
    for(int i=1;i<len;i++)
    {
        if(a[i]==b){  num[++k]=i;  }
        else {   cout<<num[k]<<' '<<i<<endl;  k--;}
    }

    return 0;
}


struct child
{
	char c;
	int a;
}dui[100];
void print(struct child dui[],int n)
{
	int i;
	if(n==2)printf("%d %d",dui[0].a,dui[1].a);
	else
	{
		for(i=1;i<n;i++)
		{
			if(dui[i].c!=dui[i-1].c)
			{
				printf("%d %d\n",dui[i-1].a,dui[i].a);
				for(i=i+1;i<n;i++)
				{
					dui[i-2]=dui[i];
				}
				print(dui,n-2);
				break;
			}
		}
	}
}
void main()
{
	int i,n;
	char s[100];
	scanf("%s",s);
	n=strlen(s);
	for(i=0;i<n;i++)
	{
		dui[i].c=s[i];
		dui[i].a=i;
	}
	print(dui,n);
}


int main()
{
	char kid[101];
	int i,j;
	gets(kid);
	for(i=0;i<strlen(kid);i++)
	{
		if(kid[i]!=kid[0])
		{
		  j='0';
		  for(j=i-1;;j--)
		  {
			  if(kid[j]!='0')
			  {
				  break;
			  }
		  }
          if(kid[i]!=kid[j])
		  {
			  printf("%d %d\n",j,i);
			  kid[i]='0';
			  kid[j]='0';
		  }
		}
	}

	return 0;
}


int main()
{
	void sort(int[],int[],int);
	char str[1000],f,s,stack[1000];
	int sum=0,j,i,l=0,tot=-1,boy[500],girl[500],pair=-1,num[1000];
	gets(str);
	l=strlen(str);
	for (i=0;i<l;i++)
	{
		if (i==0)
		{
			f=str[sum++];
			stack[++tot]=f;
			num[tot]=i;
			continue;
		}
		if (sum<2 && str[i]!=f)
		{
			sum++;
			s=str[i];
printf("%c %c\n",f,s);
		}
		stack[++tot]=str[i];
		num[tot]=i;
for (j=0;j<tot+1;j++) printf("%c",stack[j]);
printf("%d\n",tot);
		while (tot>0 && sum>1 && stack[tot]==s && f==stack[tot-1])
		{
			girl[++pair]=num[tot--];
			boy[pair]=num[tot--];
printf("%d %d\n",boy[pair],girl[pair]);
		}
	}
	sort(boy,girl,pair);
	for (i=0;i<pair;i++)
		printf("%d %d\n",boy[i],girl[i]);
	printf("%d %d",boy[pair],girl[pair]);
	return 0;
}

void sort(int a[],int b[],int c)
{
	void swap(int,int);
	int i,j,k;
	for (i=0;i<c;i++)
	{
		k=i;
		for (j=i+1;j<c+1;j++)
			if (b[j]<b[k]) k=j;
		swap(a[i],a[k]);
		swap(b[i],b[k]);
	}
}

void swap(int x,int y)
{
	int t;
	t=x;
	x=y;
	y=t;
}


int boy,girl,l=0;//???????????????
void match(char c[],int left)
{
	int i=0,j=0;
	for(i=0;i<l;i++)
	{
		if(c[i]==girl)
		{
			for(j=i-1;j>=0;j--)
			{
				if(c[j]==boy)
				{
					cout<<j<<" "<<i<<endl;
					break;
				}
			}
			c[i]='0';c[j]='0';
			left=left-2;
			break;
		}
	}
	if(left>0)
		match(c,left);
}
int main()
{
	char str[100];
	cin.getline(str,100);
	boy=str[0];
	l=strlen(str);
	girl=str[l-2];
	match(str,l);
	return 0;
}


int x=0;
int main()
{
	char a[100];
	int N(char a[],char f);
	cin.getline(a,100);
	char m1;
	m1=a[0];
	N(a,m1);
}
int N(char a[],char f)
{
	char m=f;
    lop:
	if(a[x]==m)
	{
		int l=x;
		x++;
		cout<<l<<" "<<N(a,m)<<endl;
		goto lop;
	}
	if(a[x]!=m&&a[x]!='\0')
	{
		x++;
		return x-1;
	}

	if(a[x]=='\0')
	return 0;
}


struct student{
	int boy;
	int girl;
};
struct student out[PI];
struct student tmp;
int len,k=0;
char s[PI];
char b,g;

void output()
{
	int i,j;
	for (i=0;i<k;i++)
	{
		for (j=i+1;j<k;j++)
		{
			if (out[i].girl>out[j].girl)
			{
				tmp.boy=out[i].boy;
				tmp.girl=out[i].girl;
				out[i].boy=out[j].boy;
				out[i].girl=out[j].girl;
				out[j].boy=tmp.boy;
				out[j].girl=tmp.girl;
			}
		}
	}
	for (i=0;i<k;i++)
		printf("%d %d\n",out[i].boy,out[i].girl);
}

void outing(int x)
{
	int l,r;
	l=1;r=0;
	int i,j;
	j=0;
	for (i=0;i<len;i++)
	{
		if (s[i]!='0')
			j++;
	}
	if (j==0)
		output();
	else
	{
	for (i=x+1;i<len;i++)
	{
		if (s[i]==b)
		{
			l++;
		}
		if (s[i]==g)
		{
			r++;
			if (r==l)
			{
				s[x]='0';
				s[i]='0';
				out[k].boy=x;
				out[k].girl=i;
//				printf("%d %d\n",out[k].boy,out[k].girl);
				k++;
				break;
			}
		}
	}
	outing(x+1);
	}

}

int main()
{
	scanf("%s",s);
	int i;
	len=strlen(s);
	b=s[0];
	for (i=0;i<len;i++)
	{
		if (s[i]!=b)
		{
			g=s[i];
			break;
		}
	}
	outing(0);
	return 0;
}


char str[101];
int match(int n ,char a, char b)
{
    for(int i=1;i<n;i++)
    {
	    if(str[i]!=b)
		    continue;
		for(int j=i-1;j>=0;j--)
		{
		    if(str[j]==a)
			 {

			    cout<<j<<' '<<i<<endl;
			    str[j]='*';
			    break;
		     }
		}

	}
	return 0;
}
int main()
{
	int i;
	char a,b;
	cin.getline(str,101);
	i=strlen(str);
	a=str[0];
	b=str[i-1];
	match(i,a,b);
	return 0;
}


void paidui(char str [])
{
	int i=0,k=0;
	for(i=1;i<strlen(str);i++)
	{
		if(str[i]!=str[0])
		{
			for(k=i-1;k>=0;k--)
			{
				if(str[k]==str[0])
				{
					cout<<k<<' '<<i<<endl;

				str[k]=' ';
				str[i]=' ';
				break;
				}

			}
		}
	}
}
int main()
{
	char str[100];
	cin.getline(str,101);
	paidui(str);
	return 0;
}


char c[150];
int c1[150] = {0};
int lc;
char m;

void que(int a, int b)
{
	if (c1[a])
	{
		que(a + 1, b);
	}
	else
	{
	    if (b == lc)
		    return;
	    if (c[b] == m)
	    {
		    que(a + 1, b + 1);
	    }
	    else
	    {
		    cout << a << " " << b << endl;
		    c1[a] = 1;
		    c1[b] = 1;
			while (c1[a] == 1)
			{
				a--;
			}
		    que(a, b + 1);
		}
	}
}

int main()
{
	cin >> c;
	m = c[0];
	lc = strlen(c);
	que(0, 1);
	return 0;
}


int main()
{
	int i=0,j=0,len,a,b;
	char str[101],boy;
	gets(str);
	len=strlen(str);
	boy=str[0];
	for(i=0;i<len;i++)
	{
		if(str[i]!=boy)
		{
			str[i]='0';
			for(j=i;j>0;j--)
			{
				if(str[j]==boy)break;
			}
			str[j]='0';
			a=j;b=i;
			printf("%d %d\n",a,b);
		}
		else continue;
	}
	return 0;
}


void change(char str[],char w,char m)
{
	int ctr=0,ctr1=0;
	for (ctr=0;str[ctr+1]!='\0';ctr++)
	{   if(str[ctr]==w)continue;
		for(ctr1=ctr+1;ctr1<strlen(str);ctr1++)
		{if(str[ctr1]!=' ')break;}
		if(str[ctr1]==w)
		{
			printf("%d %d\n",ctr,ctr1);str[ctr]=str[ctr1]=' ';
			break;}
	}

}
main()
{
	char a[1000]={'\0'},w,m;int i=0;
	gets(a);m=a[0];
	for(i=0;i<strlen(a);i++)if(a[i]!=a[0])break;w=a[i];
	for(i=0;i<strlen(a)/2;i++)
	{change(a,w,m);}
	return 0;
}


int lefts(char *,char *);
char boy,girl;
int main()
{
	char children[105]={'\0'};
	int i,left,right,sum;
	cin>>children;
	sum=strlen(children);
	boy=children[0];
	girl=children[sum-1];
	for(i=0;i<sum;i++)
	{
		if(children[i]==girl)//??????girl???????lefts??????
		{
			right=i;
			left=lefts(children,children+i);
			if(i<sum-1)
				cout<<left<<" "<<right<<endl;
			else
				cout<<left<<" "<<right;//?????????
			children[left]=' ';
		}
	}
	return 0;
}
int lefts(char *head,char *p)
{
	int left;
	if(*p!=boy)//?????????????????
		left=lefts(head,p-1);
	else
		left=p-head;
	return left;
}


void main()
{
	void f(char c[],char,char,int);
	char c[1000],a,b,n;
	scanf("%s",c);
	n=strlen(c);
	a=c[0];
	b=c[n-1];
	f(c,a,b,n);

}

void f(char c[],char a,char b,int n)
{
	int i,nan,nv,k;
	for (i=0;i<n;i++)
	{
		if (c[i]==b)
		{
			nan=0;nv=0;
			for (k=i;k>=0;k--)
			{
				if (c[k]==a) nan++;
				else if (c[k]==b) nv++;
				if (nan==nv)
				{
					printf("%d %d\n",k,i);
					break;
				}
			}
		}
	}
}


int function(char* a,int m,char k)//??a[m]?'('
{
	int t=m;
	while(a[t+1]!=0)
	{
		if(a[t+1]!=k)
		{
			cout<<m<<' '<<t+1<<endl;
			return t+1;
		}
		else
		{
			t=function(a,t+1,k);
		}
	}
}

int main()
{
	char a[101],k;
	cin>>a;
	int n=-1;
	k=a[0];
	while(a[n+1]!=0)
	{
		n=function(a,n+1,k);
	}
	return 0;
}


char x,y;
int main()
{
	int i;
	void result(char a[]);
	char line[200];
	scanf("%s",line);
	x=line[0];
	for(i=0;i<=strlen(line)-1;i++)
	{
		if(line[i]!=x)
		{y=line[i];
		break;}
	}
    result(line);

	return 0;
}
void result(char a[])
{
    if((a[0]!='.')&&(a[strlen(a)-1]!='.'))
	{
	int i,j;
	for(i=1;i<=(strlen(a)-1);i++)
	{
		if(a[i]==y)
		{
		for(j=i-1;j>=0;j--)
		{
			if(a[j]==y) break;
			else if (a[j]==x)
			{
				printf("%d %d",j,i);
				printf("\n");
				a[i]='.';a[j]='.';
				break;
			}
		}
		}
	}
    result(a);
	}

}


int main()
{
    char s[400],c1;
    int top=0,i,j,k,m,n,a[100];
    gets(s);
    c1=s[0];
    for (i=0;i<strlen(s);i++)
    {
        if (s[i]==c1)
        {
           top++;
           a[top]=i;
        }
        else
        {
             printf("%d %d\n",a[top],i);
             top--;
        }
    }
    return 0;
}


//Patricia.Xiao
//????????

char line[110];
char boy,girl;

int match(int i,int l)
{
	//printf("%c %c\n",boy,girl);  //debug
	//printf("%s",line);
	//debug?line????????????????????
	int j;
	if(i==l)
		return 0;   //??
	if(line[i]==girl)   //????
	{
		for(j=i-1;j>=0;j--)
		{
			if(line[j]==boy)
			{
				//printf("%d %d\n",i,j);  //debug
				printf("%d %d\n",j,i);
				line[j]=' ';
				break;   //????????????????else?????bug?
			}
		}
	}
	match(i+1,l);
	return 0;
}
int main()
{
	int l;
	int i;
	scanf("%s",line);
	l=strlen(line);
	boy=line[0];         //????????????
	for(i=1;i<l;i++)
	{
		if(line[i]!=boy)
		{
			girl=line[i];
			break;
		}
	}
	//printf("%d\n",l);  //debug
	match(0,l);  //??
    return 0;
}


void main()
{
	char a[101],boy,girl;
	int i,k,len;

	scanf("%s",a);
	boy=a[0];
	len=strlen(a);
	for(i=0;i<len;i++)
	{\
		if(a[i]!=boy)
		{
			girl=a[i];
			break;
		}
	}

	for(i=0;i<len;i++)
	{
		if(a[i]==girl)
		{
			for(k=i-1;k>=0;k--)
			{
				if(a[k]==' ')
					continue;
				else if(a[k]==boy)
				{
					a[i]=' ';
				    a[k]=' ';
				    printf("%d %d\n",k,i);
					break;
				}
			}
		}
	}
	return;
}


char a;
int find(int i)
{
	char c;
	int j=i+1;
	while(1)
	{
		c=getchar();
		if (c==a) j=find(j)+1;
		else
		{
			cout<<i<<' '<<j;
			if(i!=0) cout<<endl;
			break;
		}
	}
	return j;
}
int main()
{
	a=getchar();
	find(0);
	return 0;
}


int function(int begin,int end);
char child[110];
char b,g;
int main()
{
	char s;
	int i=0;
	while((s=cin.get())!='\n'){
		child[i]=s;i++;
	 }
	b=child[0];
	for(int j=1;j<=i;j++)
		if(child[j]!=b)
		  {g=child[j];break;}

	function(0,i-1);

	return 0;
}

int function(int begin,int end)
{
  int rembegin=begin;
  if(begin+1==end) return 0;
  else {
	  while(child[begin+1]==' ')
       {begin++;}

     if(child[begin+1]==g){
		 int use=rembegin;
		 while(child[use]==' ')
		    use--;
		 for(int j=use;j<=begin+1;j++)
		    child[j]=' ';
       cout<<use<<" "<<begin+1<<endl;
	   //cout<<child<<" "<<begin<<" "<<use<<endl;
       function(rembegin-1,end);
      }
     else function(rembegin+1,end);
  }
}


int main()
{

	int i,len,j,k,count;
	char a[1000],b,g;
	cin>>a;
	b=a[0];
	len=strlen(a);
	count=len/2;
	for(i=1;i<=len-1;i++)
	{
		if(a[i]!=b)
		{
			g=a[i];break;
		}
	}
	for(j=0;j<=len-1;j++)
	{
			if(a[j]==g)
			{

				for(k=j-1;k>=0;k--)
				{

					if(a[k]=='o')
					{
						continue;
					}
					if(a[k]==b)
					{
						cout<<k<<" "<<j;
						if(count!=0)
						{
							cout<<endl;
						}
						count--;
						a[k]='o';
						a[j]='o';
						break;
					}
				}
			}
	}
	return 0;
}


int main()
{
	char s[101];
	char temp[101][2];
	char t;
	int len,i,j,top=-1;
	memset(temp,0,sizeof(temp));
	gets(s);
	len = strlen(s);
	i=0;
	do
	{
		while(s[i]==s[0]&&s[i])
		{
			top++;
			temp[top][1] = s[i];
			temp[top][2] = i;
			i++;
		}
		printf("%d %d\n",temp[top][2],i);
		top--;
		i++;

	}while(top!=-1&&s[i]);

	return 0;
}


// ????,remain??????????
// flag????????
void que(char c[100], int remain,
		 char boy, char girl, int flag)
{
	int i;
	for(; c[flag] != girl; flag++); // ????????????
	for(i = flag; c[i] != boy; i--); // ???????
	c[i] = 0; // ?????0
	c[flag] = 0;
	cout << i << " " << flag << endl; // ??
	remain -= 2;
    if(remain)  // ???????
		que(c, remain, boy, girl, flag);
}

int main()
{
	char c[100];
	char boy, girl;
	int remain;
	cin >> c;
	remain = strlen(c); // ???
	boy = c[0]; // ????????
	girl = c[remain - 1];
	que(c, remain, boy, girl, 0); // ?flag?0?????
	return 0;
}


int main()
{
	char a[200];
	int judge[200]={0};
	char boy,girl;
	int i,j,last,num=0;
	scanf("%s",a);
	boy=a[0];
	last=0;
	girl=a[strlen(a)-1];
	while(num!=(strlen(a)+1)/2)
	{
		i=1;
		while(num!=(strlen(a)+1)/2)
		{
		if(a[last+i]==boy&&judge[last+i]==0) {last++;break;}
		else if(a[last+i]==girl&&judge[last+i]==0)
		{printf("%d %d\n",last,last+i);judge[last]=1;judge[last+i]=1;
		while(judge[last]!=0)
		last--;
		num++;break;}
		else i++;
		}
	}
	return 0;
}


int qianshou(char children[],int sign[],int num,int time)
{
    int i=1;int j;int k;
    for(;i<num;i++)
    {
        if(time==num/2-1)
        {
            printf("0 %d",num-1);
            return 0;
        }
        if(sign[i]==1) loop:continue;
        for(k=i+1;;k++)
        {
            if(children[i]==children[k]&&sign[k]!=1) goto loop;
            else if(children[k]!=children[i]&&sign[k]!=1) break;
        }
        sign[i]=1;
        for(j=i;j<num;j++)
        {
            if(children[j]!=children[i]&&sign[j]==0)
            {
                sign[j]=1;
                break;
            }
        }
        printf("%d %d\n",i,j);
        time++;
        break;
    }
    qianshou(children,sign,num,time);
}
int main()
{
    int num;int i;int time=0;
    char children[SIZE];
    gets(children);
    num=strlen(children);
    int sign[num];
    for(i=0;i<num;i++)
        sign[i]=0;
    qianshou(children,sign,num,time);

    return 0;
}


char b,g;
char a[1000];
int l,i;
int main()
{
	cin >> a;
	l=strlen(a);
	b=a[0];
	g=a[l-1];
	int j;
	for(i=0;i<l;i++)
	if(a[i]==g)
		for(j=i-1;j>=0;j--)
			if(a[j]==b)
			{
				cout << j << " " << i << endl;
				a[j]=0;a[i]=0;
					break;
			}
	return 0;
}