semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
//??????????????????????


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,k=0;
	int a[10000],b[10000],c[10000],d[10000];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
	}
	for(i=0;i<n;i++)
	{
		int e=1;
		for(j=0;j<n;j++)
		{
			if((a[i]>a[j]&&b[i]<b[j]||a[i]>=a[j]&&b[i]<b[j]||a[i]>a[j]&&b[i]<=b[j])&&i!=j)
			{
				e=0;
				break;
			}
		}
		if(e)
		{
			c[k]=a[i];
			d[k]=b[i];
			k++;
		}
		
	}
	for(i=1;i<=k;i++)
	{
		for(j=0;j<k-i;j++)
		{

			if(c[j]>c[j+1]||(c[j]==c[j+1]&&d[j]>d[j+1]))
			{
				int f,g;
				f=c[j];
				c[j]=c[j+1];
				c[j+1]=f;
				g=d[j];
				d[j]=d[j+1];
				d[j+1]=g;
			}
		}
	}
	int isbreak=0;
	for(i=0;i<k;i++)
	{
		if(d[i]<c[i+1])
		{
			isbreak=1;
			printf("no");
			break;
		
		}
	}
	if(isbreak==0)
	{
		printf("%d %d",c[0],d[k-1]);
	}
	return 0;
}
int main(){
int n,i,k,max=0,min=10000,sum=0;
int a[10000],b[10000],c[10000];
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(i=2*min-1;i<2*max;i++){
c[i]=1;
}
for(i=0;i<n;i++){
	for(k=2*a[i]-1;k<2*b[i];k++){
		c[k]=0;
	}
}
for(i=2*min-1;i<2*max;i++){
	if(c[i]==1){
		printf("no");
		return 0;
	}
}

printf("%d %d",min,max);
	return 0;
}
int main()
{
    int n,j,i,k,m,a,t;
    int s[1300][2];
    scanf("%d",&n);m=0;
    for (i=0;i<n;i++) 
    scanf("%d %d",&s[i][1],&s[i][2]);
     for (i=0;i<n;i++)
      for (j=i+1;j<n;j++)
      if (s[i][1]>s[j][1])
      {
                          a=s[i][1];
                          s[i][1]=s[j][1];
                          s[j][1]=a;
                           a=s[i][2];
                          s[i][2]=s[j][2];
                          s[j][2]=a;
                          }
      t=s[0][2];                    
      for (i=0;i<n-1;i++)
      if (t<s[i+1][1]) 
      {
                           printf("no");
                           exit(0);
                           }
      else if (t<s[i+1][2]) t=s[i+1][2];
           printf("%d %d",s[0][1],t);
 
                 return 0;
                 }
int main(){
int i,j,n,q,t,t1,t2;
int a[10001],b[10001];
scanf("%d",&n);
q=0;
for (i=1;i<=n;i++)
scanf("%d%d",&a[i],&b[i]);
for (i=1;i<=n;i++)
for (j=1;j<=n-1;j++)
if (a[j]>a[j+1]){
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
t=b[j];
b[j]=b[j+1];
b[j+1]=t;
}
t1=a[1];
t2=b[1];
for (i=2;i<=n;i++){
if ((b[i]<t1)||(t2<a[i]))
q=q+1;
if (a[i]<t1)
t1=a[i];
if (b[i]>t2)
t2=b[i];
}
if (q==0) 
 printf("%d %d",t1,t2);
else printf("no");
return 0;
}
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,i,j,sum,c,d,temp,e,f,g;
	scanf("%d",&n);
	temp=0;
	int a[50000],b[50000];
	for(i=0;i<n;i++)
	{
		scanf("%d %d",&a[i],&b[i]);
	}
	c=a[0];
	d=b[0];
	a[0]=10001;
	for(i=0;i<n;i++)
	{
		if(a[i]<a[0])
		{
			a[0]=a[i];
			b[0]=b[i];	
		}
	}
	for(i=1;i<n;i++)
	{
		if(a[i]==a[0]&&b[i]==b[0])
		{
			a[i]=c;
			b[i]=d;
		}
	}
	for(i=1;i<n;i++)
	{
		for(j=1;j<n-1;j++)
		{
			if(a[j]>a[j+1])
			{
				e=a[j];
				a[j]=a[j+1];
				a[j+1]=e;
				f=b[j];
				b[j]=b[j+1];
				b[j+1]=f;
			}
		}
	}
	for(i=1;i<n;i++)
	{
		sum=0;
		for(j=0;j<i;j++)
		{
			if(a[i]<=b[j])
			{
				sum++;
			}
		}
		if(sum==0)
		{
			temp++;
		}
	}
	g=0;
	for(i=0;i<n;i++)
	{
		if(g<b[i])
		{
			g=b[i];
		}
	}
	if(temp==0)
	{
		printf("%d %d",a[0],g);
	}
	else
	{
		printf("no");
	}
	return 0;
}
int main(){
	int n,i,j;
	struct {
	int min;
	int max;}a[100],b[100],c[100];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d",&a[i].min,&a[i].max);
	    }
	for(i=0;i<n;i++){
		for(j=0;j<n-i-1;j++){
			if(a[j].min>a[j+1].min){
				b[j]=a[j+1];
	            a[j+1]=a[j];
				a[j]=b[j];}}}
    c[0].max=a[0].max;
	for(i=0;i<n-1;i++){
		if(c[0].max>=a[i+1].min&&c[0].max>=a[i+1].max){
	c[0].min=a[0].min;
	c[0].max=c[0].max;}else if(c[0].max<a[i+1].min){
		c[0].min=0;
	    c[0].max=0;
	    break;}else if(c[0].max>=a[i+1].min&&c[0].max<a[i+1].max){
	c[0].min=a[0].min;
	c[0].max=a[i+1].max;}
	}
	if(c[0].max!=0){
		printf("%d %d",c[0].min,c[0].max);}else{
		printf("no");}
	return 0;
}
int main()
{
	int n, i, j;
	int beg,end;
	int pos[20002] = { 0 };
	int num[50000][2] = { 0};
	scanf( "%d",&n);
	for( i = 0; i < n; i ++ )
	{
		scanf( "%d%d",&num[i][0],&num[i][1]);
		for( j = 2 * num[i][0]; j <= 2 * num[i][1]; j ++)
			pos[j] = 1;
	}
	i = 10000;
	while( pos[i] == 0 ) i--;
	end = i;
	i = 0;
	while( pos[i] == 0) i ++;
	beg = i;
	for( i = beg; i <= end; i ++)
	{
		if( pos[i] == 0 )
		{
			printf("no");
			break;
		}
	}
    if( i == end + 1)
	printf( "%d %d", beg/2, end/2);
	return 0;
}
int main(){
	int n,i,j,z,e;
	struct point{
		int a;
		int b;
	}m[5000],t;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d",&m[i].a,&m[i].b);
	}
	for(i=1;i<=n;i++){
		for(j=0;j<n-i;j++){
			if(m[j].a>m[j+1].a){
				t=m[j];
				m[j]=m[j+1];
				m[j+1]=t;
			}
		}
	}
	for(i=1;i<=n;i++){
		for(j=0;j<n-i;j++){
			if(m[j].b>m[j+1].b){
				e=m[j].b;
				m[j].b=m[j+1].b;
				m[j+1].b=e;
			}
		}
	}
	z=1;
	for(i=0;i<n-1;i++){
		if(m[i].b<m[i+1].a){
			z=0;
		}
	}
	if(z==1){
		printf("%d %d",m[0].a,m[n-1].b);
	}else{
		printf("no");
	}
	return 0;
}
int main()
{  int i,j,n,k,l,t1,t2,t3=0,t4,t5=0;
   int a[5000][2];
   scanf("%d",&n);
   for(k=0;k<n;k++)
	   for(l=0;l<2;l++)
   {scanf("%d",&a[k][l]);}
	   for(j=0;j<n-1;j++)
		for(i=0;i<n-1-j;i++)
		{   if(a[i][0]>a[i+1][0])
			{t1=a[i][0];
			a[i][0]=a[i+1][0];
			a[i+1][0]=t1;
			t2=a[i][1];
			a[i][1]=a[i+1][1];
			a[i+1][1]=t2;}
		}
  for(i=1;i<n;i++)
	{for(j=0;j<n;j++)
    {if((a[i][0]<=a[j][1])&(a[i][0]>=a[j][0])) {t5=t5;}
	else {t5=t5+1;}}
     
	
    if (t5==n-1){t3=0; 
	          printf("no"); 
	          break;}
	else{t3=1;
	t5=0;}
    }
t4=a[0][1];
if(t3!=0)
	{   for(i=0;i<n;i++)
	    { 
	      if (a[i][1]>=t4)
	      {t4=a[i][1];}
	    }
	printf("%d %d",a[0][0],t4);}
return 0;
}
int main()
{
int a[50000],b[50000],c[10001];
int i,n;
for(i=0;i<10002;i++){c[i]=0;}
scanf("%d",&n);
for(i=0;i<n;i++){
	scanf("%d %d",&a[i],&b[i]);}
int amin,bmax,j,ok;
ok=1;
amin=10000;
bmax=0;
for(i=0;i<n;i++){if(a[i]<amin){amin=a[i];}}
for(i=0;i<n;i++){if(b[i]>bmax){bmax=b[i];}}
for(i=0;i<n;i++){
for(j=a[i];j<=b[i]-1;j++){
	c[j]=1;}}
for(i=amin;i<=bmax-1;i++){
	if(c[i]==0){ok=0;}
}
if(ok==0){printf("no");}
else{printf("%d %d",amin,bmax);}
	return 0;
}
int main(){
	
int a[1000],b[1000],n,i,s[20000],j,k;
	
for(i=0;i<20000;i++)
	
	
s[i]=0;
	
   k=0;
	
scanf("%d",&n);
	
for( i=0;i<n;i++){
	
	
scanf("%d%d",&a[i],&b[i]);
	
	
for(j=0;j<20000;j++){
	
	
	
if(j>=2*a[i]&&j<=2*b[i])
	
	
	
	
s[j]=1;
	
	
}
	
}
	
int x,y;
	
for(i=1;i<20000;i++){
	
	
if(s[i]==0&&s[i+1]==1&&s[i-1]==1){
	
	
	
k++;
	
	
	
break;
	
	
}
	
	
else{
	
	
	
if(s[i]==1&&s[i+1]==1&&s[i-1]==0)
	
	
	
	
x=i/2;
	
	
	
if(s[i]==1&&s[i+1]==0&&s[i-1]==1)
	
	
	
	
y=i/2;
	
	
}
	
}
	
if(k==0)
	
	
printf("%d %d",x,y);
	

	
else{
	
	
printf("no");
	
}
return 0;
}
int main (){
    int i,m,k,n,t;
    double d;
    scanf("%d\n",&n);
    int a[n],b[n],A[n],B[n];
    for(i=0;i<n;i++){
        scanf("%d%d\n",&a[i],&b[i]);
}
    for(i=0;i<n;i++){
            A[i]=a[i];
            B[i]=b[i];
   }
    for(k=n-1;k>0;k--){
        for(i=0;i<k;i++){
            if(A[i]>A[i+1]){
               t=A[i];              
               A[i]=A[i+1];               
               A[i+1]=t;              
}
}
}
    for(k=n-1;k>0;k--){
        for(i=0;i<k;i++){
            if(B[i]>B[i+1]){
               m=B[i];
               B[i]=B[i+1];              
               B[i+1]=m; 
}
}
}
    for(d=A[0]+0.5;d<B[n-1];d++){
         for(i=0;i<n;i++){
             if(d>a[i]&&d<b[i]){
                break;
}
}
        if(i==n){
printf("no");
   break;  
}  
}
    if(d==B[n-1]+0.5){
   printf("%d %d",A[0],B[n-1]); 
}
return 0;
}
int main()
{
	int a[100], b[100], c[100], d[100];
	int i, k, e, n;
	double j;

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

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

	if(c[0] > d[0])
		c[0] = d[0];
	if(c[n-1] < d[n-1])
		c[n-1] = d[n-1];
	for(j = c[0]; j <= c[n-1]; j = j + 0.5)
	{
		k = 1;
		for(i = 0; i < n; i++)
		{
			if(j <= b[i] && j >= a[i])
				k = 0;
		}
		if(k == 1)
		{
			printf("no");
			break;
		}
	}
	if(k == 0)
	{
	printf("%d %d", c[0], c[n-1]);
	}





	return 0;
}
int main()
{
	int a[50001],b[50001],n,i,k,e,t,s,flag=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
	}
	for(k=1;k<n;k++)
	{
		for(i=0;i<n-k;i++)
		{
			if(a[i]>a[i+1])
			{
				e=a[i];
				a[i]=a[i+1];
				a[i+1]=e;
				t=b[i];
				b[i]=b[i+1];
				b[i+1]=t;
			}
		}
	}
	for(i=0;i<n-1;i++)
	{
		if(a[i+1]<=b[i])
		{
			if(b[i]>b[i+1])
			{
				b[i+1]=b[i];
			    continue;
			}
		}
        else
		{
			flag=1;
			printf("no");
			break;
		}
	}
	if(flag==0)
	{
		printf("%d %d",a[0],b[i]);
	}
	return 0;

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

return 0;
}
int main(){
    int a[50000], b[50000], n, s[50000];
    
    scanf("%d\n", &n);
    for(int i=0;i<n;i++){
        scanf("%d %d", &a[i], &b[i]);
    }
int c=a[0];
int d=b[0];
for(int i=0;i<n;i++){
  if(c>a[i]){
     c=a[i];
     }
  if(d<b[i]){
     d=b[i];
     }
for(int m=c;m<=d;m++){
   s[m]=1;
   for(int i=0;i<n;i++){
       if(m>=a[i]&&m<b[i]){
          s[m]=0;
          }
    }
 }
}
int result=0;
for(int m=c;m<d;m++){
    result+=s[m];
}
if(result==0){
printf("%d %d",c,d);
}else{
printf("no");
}
return 0;
}
int main(){
	int a[100],n,i,k,e,t,r=0;
	scanf("%d",&n);
	for (i=0;i<2*n;i++){
		scanf("%d",&a[i]);
	}
	for (k=1;k<=n;k++){
		for (i=0;i<2*n-2*k;i=i+2){
			if(a[i]>a[i+2]){
				e=a[i];
				a[i]=a[i+2];
				a[i+2]=e;
				t=a[i+1];
				a[i+1]=a[i+3];
				a[i+3]=t;
			}
		}
	}
	int p=a[0],q=a[1];
	for (i=0;i<2*n-2;i=i+2){
		if(a[i+2]>q){
			r=1;
			break;
		}
		else if(a[i+2]<=q&&a[i+3]>=q){
			q=a[i+3];
		}
	}
	if(r==1){printf("no\n");}
	else{
		printf("%d %d\n",p,q);
	}
		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,i,j,k,l,p,x=1;
  double m;
  int a[50000],b[50000];
  scanf("%d",&n);
  for(i=0;i<n;i++){
   scanf("%d%d",&a[i],&b[i]);}
  for(j=0,k=10000,l=1;j<n;j++){
   if(k>=a[j]){
     k=a[j];}
   if(l<=b[j]){
     l=b[j];}
  }
  for(m=k+0.1;m<l;m++){
   for(i=0,p=0;i<n;i++){
    if(m>a[i]&&m<b[i]){
     p=1;
     break;}
   }
   if(p==0){
    printf("no\n");
    x=0;}
  }
  if(x==1){
   printf("%d %d",k,l);}
  return 0;
}
int main(){
	int a[50000],b[50000],n,zuo,you,y,x=0,c=1,d=0;
	double z;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{scanf("%d%d",&a[i],&b[i]);}
	zuo=a[1];you=b[1];
	for(int j=0;j<n;j++)
	{if(a[j]<zuo)zuo=a[j];
	 if(b[j]>you)you=b[j];}
	z=zuo;
	y=you;
	for(z;z<=y;z+=0.5){
		for(int k=0;k<n;k++)
		{if((z<=1.0*b[k])&&(z>=1.0*a[k])){x=1;}}
	     c*=x;d++;x=0;
	}
	if(c==0){printf("no");}
		else{printf("%d %d",zuo,you);}
	                     
	
	return 0;
}
int main()
{
	int n;
	int i,j,k=1;
	struct qujian
	{
		int a;
		int b;
	}q[50000],t;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d",&q[i].a,&q[i].b);

	}
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if(q[i].a>q[j].a)
			{
				t=q[j];
				q[j]=q[i];
				q[i]=t;
			}
		}
	}
	for(i=0;i<n-1;i++)
	{
		if(q[i+1].a>q[i].b)
		{
			printf("no\n");
			k=0;
			break;
		}
		else
		{
			q[i+1].a=q[i].a;
			q[i+1].b=(q[i].b>q[i+1].b)?q[i].b:q[i+1].b;
		}
	}
	if(k)
	{
		printf("%d %d\n",q[n-1].a,q[n-1].b);
	}
	return 0;
}
int main()
{
    int n,i,j,m,k;
	int a[50000][2],b[10000],qj[10000];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d",&a[i][0],&a[i][1]);
	}
	for(i=0;i<10000;i++){
		b[i]=0;
	}
	for(i=0;i<n;i++){
		for(j=a[i][0];j<a[i][1];j++){
			b[j]=1;
		}
	}
	m=0;
k=0;
	for(i=0;i<10000;i++){
		if(b[i]!=0){
			qj[m]=i;
			m++;
		}
	}
	for(i=0;i<m-1;i++){
		if((qj[i+1]-qj[i])!=1){
k++;}
	}
	if(k==0){
printf("%d %d",qj[0],(qj[m-1]+1));}
	else{
printf("no");}
	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 i,j,a,c,e,b,d,h,t,min,max;
    int k,n;
	int x[10000][3],z[10000];
	scanf("%d",&n);
	for(i=1;i<=n;i++){
	   scanf("%d%d",&x[i][1],&x[i][2]);
	}
	min=x[1][1];
	max=x[1][2];
	for(i=1;i<=n;i++){
			if(min>x[i][1])min=x[i][1];
		}
	for(i=1;i<=n;i++){
			if(max<x[i][2])max=x[i][2];
		}
	t=0;
	for(i=1;i<=n;i++){
		for(j=x[i][1]+1;j<=x[i][2];j++){
			z[t]=j;
			t++;
		}
	}
	h=0;
	k=0;
	for(i=min+1;i<=max;i++){
		h=0;
		for(t=0;t<=10000;t++){
			if(z[t]==i){
				h=1;
				break;
			}
		}
		if(h==0)k=1;
	}
	if(k==1)printf("no");
	else printf("%d %d",min,max);
	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 a[5000][2];
	int i,n,x,d,m,s;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d",&a[i][0],&a[i][1]);
	}
	
		x=a[0][0];d=a[0][1];
		for(i=0;i<n;i++)
		{
			if(a[i][0]<x)
			{
				x=a[i][0];
			}
			if(a[i][1]>d)
			{
				d=a[i][1];
			}
		}
		int c[10000];
		for(i=x;i<d+1;i++)
		{
			c[i]=0;
		}
		for(i=0;i<n;i++)
		{
			m=a[i][0];
			s=a[i][1];
			for(m;m<=s-1;m++)
			{
				c[m]=1;
			}
			
			

		}
		for(i=x;i<d;i++)
		{
			if(c[i]==0)
			{printf("no");
			return 0;
			break;
			}

		}
		printf("%d %d",x,d);
		return 0;
}
int main()
{
	int a[100][100],n,i,j,k,e,o=0,l=0,u;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(j=0;j<2;j++){
			scanf("%d",&a[i][j]);
		}
	}
    for(k=1;k<=n;k++){
		for(i=0;i<n-k;i++){
			if(a[i][0]>a[i+1][0]){
				for(j=0;j<2;j++){
				e=a[i+1][j];
               a[i+1][j]=a[i][j];
               a[i][j]=e;
				}
			}
		}
	}



for(i=1;i<n;i++){
	for(u=0;u<i;u++){
	if(a[i][0]>a[u][1]){
		o++;
	}
	
	}
if(o==i) l++;
o=0;
}
for(k=1;k<=n;k++){
		for(i=0;i<n-k;i++){
			if(a[i][1]>a[i+1][1]){
				
				e=a[i+1][1];
               a[i+1][1]=a[i][1];
               a[i][1]=e;
				}
			}
		}
	


if(l==0) printf("%d %d",a[0][0],a[n-1][1]);
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;
}
int main(){
    int n,m,a;
    scanf("%d\n",&n);
    int sz[n],zs[n];
    for(int i=0;i<n;i++){
        scanf("%d%d",&sz[i],&zs[i]);
    }
    for(int x=0;x<n-1;x++){
    for(int i=0;i<n-1-x;i++){
        if(sz[i]>sz[i+1]){
            m=sz[i];
            sz[i]=sz[i+1];
            sz[i+1]=m;
        }
    }
    }
    for(int x=0;x<n-1;x++){
        for(int i=0;i<n-1;i++){
        if(zs[i]>zs[i+1]){
            m=zs[i];
            zs[i]=zs[i+1];
            zs[i+1]=m;
        }
    }
    }
    a=1;
    for(int i=0;i<n-1;i++){
        if(zs[i]<sz[i+1]){
            a=0;
        }
    }
    if(a==1){
        printf("%d %d",sz[0],zs[n-1]);
    }else{
        printf("no");
    }
    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,a[50000][2],i,j,ai,bi,s=0,k,ta,tb;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++)
	{
		for(j=0;j<2;j++)
		{
			scanf("%d",&a[i][j]);
		}
		

		if(i!=0)
		{
			for(k=0;k<i;k++)
			{
				if(a[k][0]>a[i][0])
				{
					ta=a[k][0];
					tb=a[k][1];
					a[k][1]=a[i][1];
					a[k][0]=a[i][0];
					a[i][0]=ta;
					a[i][1]=tb;
				}
			}
		}		
	}

	ai=a[0][0];
	bi=a[0][1];

	for(i=0;i<n;i++)
	{
		if(a[i][0]<=ai&&a[i][1]>=ai)
		{
			ai=a[i][0];
		}
		else if(a[i][1]<ai)
		{
			s=1;
		}

		if(a[i][1]>=bi&&a[i][0]<=bi)
		{
			bi=a[i][1];
		}
		else if(a[i][0]>bi)
		{
			s=1;
		}
	}

	if(s==1)
		printf("no");
	else
		printf("%d %d\n",ai,bi);
	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;
}