#include <bits/stdc++.h>
using namespace std;
int ask(int c, int d){
    cout  <<"? "<< c << " "<< d<<endl;
    fflush(stdout);
    cin >> c;
    return c;
}
void res(int c , int d){
    cout << "! " << c << " " << d << endl;
}
int main(){
    int A =0 , B=0;
    int mainAsk = -2;
    for(int i = 29 ; i >= 0 ; i--){
        if(mainAsk == -2) mainAsk = ask(A,B);
        int save=mainAsk;
        if(mainAsk==0){
            // equal
            mainAsk = -2;
            int Ask = ask(A|(1<<i) , B);
            if(Ask == -1) {
                A = A | (1<<i) , B = B | (1<<i);
            }
            mainAsk = save;
        }
        else if(mainAsk==1){
            // a is greater

            mainAsk = -2;
            int Ask = ask(A|(1<<i) , B |(1<<i));
            if(Ask == -1) A = A | (1<<i);
            else if(Ask==1){
                int Ask = ask(A|(1<<i) , B);
                if(Ask == -1) {
                    A = A | (1<<i) , B = B | (1<<i);
                }
                mainAsk = save;
            }
            else assert(false);
        }
        else {
            mainAsk = -2;
            // b is greater
            int Ask = ask(A|(1<<i) , B |(1<<i));
            if(Ask == 1) B = B | (1<<i);
            else if(Ask== -1){
                int Ask = ask(A|(1<<i) , B);
                if(Ask == -1) {
                    A = A | (1<<i) , B = B | (1<<i);
                }
                mainAsk = save;
            }
            else assert(false);
        }
    }
    res(A,B);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi >
const int N=1000010;
int second(int);
int a=0,b=0;
int equal(int &i)
{
	while(i>=0)
	{
		int c=a,d=b|(1<<i),x;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		if(x==1)
			a|=(1<<i),b|=(1<<i);
		i--;
	}
}
int first(int &i)
{
	while(i>=0)
	{
		if(i==0)
		{
			a|=(1<<i);
			i--;
			return 0;
		}
		int c=a,d=b|(1<<i),x,y;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		c=a|(1<<i);d=b;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>y;
		if(x==1)
		{
			if(y==1)
			{
				a|=(1<<i);
				i--;
				first(i);
				return 0;
			}
			else
			{
				a|=(1<<i);
				b|=(1<<i);
				i--;
			}
		}
		else if(x==-1)
		{
			if(y==-1)
			{
				a|=(1<<i);
				i--;
				second(i);
				return 0;
			}
			i--;
		}
		else
		{
			a|=(1<<i);
			i--;
			if(y==0)
			return equal(i);
			else if(y==1)
			{
				return first(i);
			}
			else return second(i);
		}

	}
}
int second(int i)
{
	while(i>=0)
	{
		if(i==0)
		{
			b|=(1<<i);
			i--;
			return 0;
		}
		int c=a|(1<<i),d=b,x,y;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		c=a;d=b|(1<<i);
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>y;
		if(x==1)
		{
			if(y==1)
			{
				b|=(1<<i);
				i--;
				first(i);
				return 0;
			}
			else
				i--;
		}
		else if(x==-1)
		{
			a|=(1<<i);
			b|=(1<<i);
			i--;
		}
		else
		{
			b|=(1<<i);
			i--;
			if(y==0)
			return equal(i);
			else if(y==1)
			{
				return first(i);
			}
			else return second(i);
		}
	}
}
int main()
{
	for(int i=29;i>=0;i--)
	{
		int c=a,d=b,x;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		if(x==1)
		{
			first(i);
		}
		else if(x==-1)
		{
			second(i);
		}
		else equal(i);
	}
	cout<<"! "<<a<<" "<<b<<"\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi >
const int N=1000010;
int second(int);
int a=0,b=0;
int equal(int &i)
{
	while(i>=0)
	{
		//cout<<a<<" "<<b<<" equal\n";
		int c=a,d=b|(1<<i),x;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		if(x==1)
			a|=(1<<i),b|=(1<<i);
		i--;
	}
}
int first(int &i)
{
	while(i>=0)
	{
		if(i==0)
		{
			a|=(1<<i);
			i--;
			return 0;
		}
		//cout<<a<<" "<<b<<" first\n";
		int c=a,d=b|(1<<i),x,y;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		c=a|(1<<i);d=b;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>y;
		if(x==1)
		{
			if(y==1)
			{
				a|=(1<<i);
				i--;
				first(i);
				return 0;
			}
			else
			{
				a|=(1<<i);
				b|=(1<<i);
				i--;
			}
		}
		else if(x==-1)
		{
			if(y==-1)
			{
				a|=(1<<i);
				i--;
				second(i);
				return 0;
			}
			i--;
		}
		else
		{
			a|=(1<<i);
			i--;
			if(y==0)
			return equal(i);
			else if(y==1)
			{
				return first(i);
			}
			else return second(i);
		}

	}
}
int second(int i)
{
	while(i>=0)
	{
		if(i==0)
		{
			b|=(1<<i);
			i--;
			return 0;
		}
		//cout<<a<<" "<<b<<" sec\n";
		int c=a|(1<<i),d=b,x,y;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		c=a;d=b|(1<<i);
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>y;
		//cout<<x<<y<<"xy\n";
		if(x==1)
		{
			if(y==1)
			{
				b|=(1<<i);
				i--;
				first(i);
				return 0;
			}
			else
				i--;
		}
		else if(x==-1)
		{
			if(y==-1)
			{
				b|=(1<<i);
				i--;
				return second(i);
			}
			a|=(1<<i);
			b|=(1<<i);
			i--;
		}
		else
		{
			b|=(1<<i);
			i--;
			if(y==0)
			return equal(i);
			else if(y==1)
			{
				return first(i);
			}
			else return second(i);
		}
	}
}
int main()
{
	for(int i=29;i>=0;i--)
	{
		int c=a,d=b,x;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		if(x==1)
		{
			first(i);
		}
		else if(x==-1)
		{
			second(i);
		}
		else equal(i);
	}
	cout<<"! "<<a<<" "<<b<<"\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi >
const int N=1000010;
int second(int);
int a=0,b=0;
int equal(int &i)
{
	while(i>=0)
	{
		//cout<<a<<" "<<b<<" equal\n";
		int c=a,d=b|(1<<i),x;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		if(x==1)
			a|=(1<<i),b|=(1<<i);
		i--;
	}
}
int first(int &i)
{
	while(i>=0)
	{
		if(i==0)
		{
			a|=(1<<i);
			i--;
			return 0;
		}
		//cout<<a<<" "<<b<<" first\n";
		int c=a,d=b|(1<<i),x,y;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		c=a|(1<<i);d=b;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>y;
		if(x==1)
		{
			if(y==1)
			{
				a|=(1<<i);
				i--;
				first(i);
				return 0;
			}
			else
			{
				a|=(1<<i);
				b|=(1<<i);
				i--;
			}
		}
		else if(x==-1)
		{
			if(y==-1)
			{
				a|=(1<<i);
				i--;
				second(i);
				return 0;
			}
			i--;
		}
		else
		{
			a|=(1<<i);
			i--;
			if(y==0)
			return equal(i);
			else if(y==1)
			{
				return first(i);
			}
			else return second(i);
		}

	}
}
int second(int i)
{
	while(i>=0)
	{
		if(i==0)
		{
			b|=(1<<i);
			i--;
			return 0;
		}
		//cout<<a<<" "<<b<<" sec\n";
		int c=a|(1<<i),d=b,x,y;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		c=a;d=b|(1<<i);
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>y;
		//cout<<x<<y<<"xy\n";
		if(x==1)
		{
			if(y==1)
			{
				b|=(1<<i);
				i--;
				first(i);
				return 0;
			}
			else
				i--;
		}
		else if(x==-1)
		{
			if(y==-1)
			{
				b|=(1<<i);
				i--;
				return second(i);
			}
			a|=(1<<i);
			b|=(1<<i);
			i--;
		}
		else
		{
			b|=(1<<i);
			i--;
			if(y==0)
			return equal(i);
			else if(y==1)
			{
				return first(i);
			}
			else return second(i);
		}
	}
}
int main()
{
	for(int i=9;i>=0;i--)
	{
		int c=a,d=b,x;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		if(x==1)
		{
			first(i);
		}
		else if(x==-1)
		{
			second(i);
		}
		else equal(i);
	}
	cout<<"! "<<a<<" "<<b<<"\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi >
const int N=1000010;
int second(int);
int a=0,b=0;
int equal(int &i)
{
	while(i>=0)
	{
		//cout<<a<<" "<<b<<" equal\n";
		int c=a,d=b|(1<<i),x;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		if(x==1)
			a|=(1<<i),b|=(1<<i);
		i--;
	}
}
int first(int &i)
{
	while(i>=0)
	{
		if(i==0)
		{
			a|=(1<<i);
			i--;
			return 0;
		}
		//cout<<a<<" "<<b<<" first\n";
		int c=a,d=b|(1<<i),x,y;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		c=a|(1<<i);d=b;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>y;
		if(x==1)
		{
			if(y==1)
			{
				a|=(1<<i);
				i--;
				first(i);
				return 0;
			}
			else
			{
				a|=(1<<i);
				b|=(1<<i);
				i--;
			}
		}
		else if(x==-1)
		{
			if(y==-1)
			{
				a|=(1<<i);
				i--;
				second(i);
				return 0;
			}
			i--;
		}
		else
		{
			a|=(1<<i);
			i--;
			if(y==0)
			return equal(i);
			else if(y==1)
			{
				return first(i);
			}
			else return second(i);
		}

	}
}
int second(int i)
{
	while(i>=0)
	{
		if(i==0)
		{
			b|=(1<<i);
			i--;
			return 0;
		}
		//cout<<a<<" "<<b<<" sec\n";
		int c=a|(1<<i),d=b,x,y;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		c=a;d=b|(1<<i);
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>y;
		//cout<<x<<y<<"xy\n";
		if(x==1)
		{
			if(y==1)
			{
				b|=(1<<i);
				i--;
				first(i);
				return 0;
			}
			else
				i--;
		}
		else if(x==-1)
		{
			if(y==-1)
			{
				b|=(1<<i);
				i--;
				return second(i);
			}
			a|=(1<<i);
			b|=(1<<i);
			i--;
		}
		else
		{
			b|=(1<<i);
			i--;
			if(y==0)
			return equal(i);
			else if(y==1)
			{
				return first(i);
			}
			else return second(i);
		}
	}
}
int main()
{
	for(int i=28;i>=0;i--)
	{
		int c=a,d=b,x;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		if(x==1)
		{
			first(i);
		}
		else if(x==-1)
		{
			second(i);
		}
		else equal(i);
	}
	cout<<"! "<<a<<" "<<b<<"\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi >
const int N=1000010;
int second(int);
int a=0,b=0;
int equal(int &i)
{
	while(i>=0)
	{
		//cout<<a<<" "<<b<<" equal\n";
		int c=a,d=b|(1<<i),x;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		if(x==1)
			a|=(1<<i),b|=(1<<i);
		i--;
	}
}
int first(int &i)
{
	while(i>=0)
	{
		if(i==0)
		{
			a|=(1<<i);
			i--;
			return 0;
		}
		//cout<<a<<" "<<b<<" first\n";
		int c=a,d=b|(1<<i),x,y;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		c=a|(1<<i);d=b;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>y;
		if(x==1)
		{
			if(y==1)
			{
				a|=(1<<i);
				i--;
				first(i);
				return 0;
			}
			else
			{
				a|=(1<<i);
				b|=(1<<i);
				i--;
			}
		}
		else if(x==-1)
		{
			if(y==-1)
			{
				a|=(1<<i);
				i--;
				second(i);
				return 0;
			}
			i--;
		}
		else
		{
			a|=(1<<i);
			i--;
			if(y==0)
			return equal(i);
			else if(y==1)
			{
				return first(i);
			}
			else return second(i);
		}

	}
}
int second(int i)
{
	while(i>=0)
	{
		if(i==0)
		{
			b|=(1<<i);
			i--;
			return 0;
		}
		//cout<<a<<" "<<b<<" sec\n";
		int c=a|(1<<i),d=b,x,y;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		c=a;d=b|(1<<i);
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>y;
		//cout<<x<<y<<"xy\n";
		if(x==1)
		{
			if(y==1)
			{
				b|=(1<<i);
				i--;
				first(i);
				return 0;
			}
			else
				i--;
		}
		else if(x==-1)
		{
			if(y==-1)
			{
				b|=(1<<i);
				i--;
				return second(i);
			}
			a|=(1<<i);
			b|=(1<<i);
			i--;
		}
		else
		{
			b|=(1<<i);
			i--;
			if(y==0)
			return equal(i);
			else if(y==1)
			{
				return first(i);
			}
			else return second(i);
		}
	}
}
int main()
{
	for(int i=11;i>=0;i--)
	{
		int c=a,d=b,x;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		if(x==1)
		{
			first(i);
		}
		else if(x==-1)
		{
			second(i);
		}
		else equal(i);
	}
	cout<<"! "<<a<<" "<<b<<"\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi >
const int N=1000010;
int second(int);
int a=0,b=0;
int equal(int &i)
{
	while(i>=0)
	{
		//cout<<a<<" "<<b<<" equal\n";
		int c=a,d=b|(1<<i),x;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		if(x==1)
			a|=(1<<i),b|=(1<<i);
		i--;
	}
}
int first(int &i)
{
	while(i>=0)
	{
		if(i==0)
		{
			a|=(1<<i);
			i--;
			return 0;
		}
		//cout<<a<<" "<<b<<" first\n";
		int c=a,d=b|(1<<i),x,y;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		c=a|(1<<i);d=b;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>y;
		if(x==1)
		{
			if(y==1)
			{
				a|=(1<<i);
				i--;
				first(i);
				return 0;
			}
			else
			{
				a|=(1<<i);
				b|=(1<<i);
				i--;
			}
		}
		else if(x==-1)
		{
			if(y==-1)
			{
				a|=(1<<i);
				i--;
				second(i);
				return 0;
			}
			i--;
		}
		else
		{
			a|=(1<<i);
			i--;
			if(y==0)
			return equal(i);
			else if(y==1)
			{
				return first(i);
			}
			else return second(i);
		}

	}
}
int second(int i)
{
	while(i>=0)
	{
		if(i==0)
		{
			b|=(1<<i);
			i--;
			return 0;
		}
		//cout<<a<<" "<<b<<" sec\n";
		int c=a|(1<<i),d=b,x,y;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		c=a;d=b|(1<<i);
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>y;
		//cout<<x<<y<<"xy\n";
		if(x==1)
		{
			if(y==1)
			{
				b|=(1<<i);
				i--;
				first(i);
				return 0;
			}
			else
				i--;
		}
		else if(x==-1)
		{
			if(y==-1)
			{
				b|=(1<<i);
				i--;
				return second(i);
			}
			a|=(1<<i);
			b|=(1<<i);
			i--;
		}
		else
		{
			b|=(1<<i);
			i--;
			if(y==0)
			return equal(i);
			else if(y==1)
			{
				return first(i);
			}
			else return second(i);
		}
	}
}
int main()
{
	for(int i=20;i>=0;i--)
	{
		int c=a,d=b,x;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		if(x==1)
		{
			first(i);
		}
		else if(x==-1)
		{
			second(i);
		}
		else equal(i);
	}
	cout<<"! "<<a<<" "<<b<<"\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi >
const int N=1000010;
int second(int);
int a=0,b=0;
int equal(int &i)
{
	while(i>=0)
	{
		//cout<<a<<" "<<b<<" equal\n";
		int c=a,d=b|(1<<i),x;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		if(x==1)
			a|=(1<<i),b|=(1<<i);
		i--;
	}
}
int first(int &i)
{
	while(i>=0)
	{
		if(i==0)
		{
			a|=(1<<i);
			i--;
			return 0;
		}
		//cout<<a<<" "<<b<<" first\n";
		int c=a,d=b|(1<<i),x,y;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		c=a|(1<<i);d=b;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>y;
		if(x==1)
		{
			if(y==1)
			{
				a|=(1<<i);
				i--;
				first(i);
				return 0;
			}
			else
			{
				a|=(1<<i);
				b|=(1<<i);
				i--;
			}
		}
		else if(x==-1)
		{
			if(y==-1)
			{
				a|=(1<<i);
				i--;
				second(i);
				return 0;
			}
			i--;
		}
		else
		{
			a|=(1<<i);
			i--;
			if(y==0)
			return equal(i);
			else if(y==1)
			{
				return first(i);
			}
			else return second(i);
		}

	}
}
int second(int i)
{
	while(i>=0)
	{
		if(i==0)
		{
			b|=(1<<i);
			i--;
			return 0;
		}
		//cout<<a<<" "<<b<<" sec\n";
		int c=a|(1<<i),d=b,x,y;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		c=a;d=b|(1<<i);
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>y;
		//cout<<x<<y<<"xy\n";
		if(x==1)
		{
			if(y==1)
			{
				b|=(1<<i);
				i--;
				first(i);
				return 0;
			}
			else
				i--;
		}
		else if(x==-1)
		{
			if(y==-1)
			{
				b|=(1<<i);
				i--;
				return second(i);
			}
			a|=(1<<i);
			b|=(1<<i);
			i--;
		}
		else
		{
			b|=(1<<i);
			i--;
			if(y==0)
			return equal(i);
			else if(y==1)
			{
				return first(i);
			}
			else return second(i);
		}
	}
}
int main()
{
	for(int i=10;i>=0;i--)
	{
		int c=a,d=b,x;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		if(x==1)
		{
			first(i);
		}
		else if(x==-1)
		{
			second(i);
		}
		else equal(i);
	}
	cout<<"! "<<a<<" "<<b<<"\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi >
const int N=1000010;
int second(int &);
int a=0,b=0;
int equal(int &i)
{
	while(i>=0)
	{
		//cout<<a<<" "<<b<<" equal\n";
		int c=a,d=b|(1<<i),x;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		if(x==1)
			a|=(1<<i),b|=(1<<i);
		i--;
	}
}
int first(int &i)
{
	while(i>=0)
	{
		if(i==0)
		{
			a|=(1<<i);
			i--;
			return 0;
		}
		//cout<<a<<" "<<b<<" first\n";
		int c=a,d=b|(1<<i),x,y;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		c=a|(1<<i);d=b;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>y;
		if(x==1)
		{
			if(y==1)
			{
				a|=(1<<i);
				i--;
				first(i);
				return 0;
			}
			else
			{
				a|=(1<<i);
				b|=(1<<i);
				i--;
			}
		}
		else if(x==-1)
		{
			if(y==-1)
			{
				a|=(1<<i);
				i--;
				second(i);
				return 0;
			}
			i--;
		}
		else
		{
			a|=(1<<i);
			i--;
			if(y==0)
			return equal(i);
			else if(y==1)
			{
				return first(i);
			}
			else return second(i);
		}

	}
}
int second(int &i)
{
	while(i>=0)
	{
		if(i==0)
		{
			b|=(1<<i);
			i--;
			return 0;
		}
		//cout<<a<<" "<<b<<" sec\n";
		int c=a|(1<<i),d=b,x,y;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		c=a;d=b|(1<<i);
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>y;
		//cout<<x<<y<<"xy\n";
		if(x==1)
		{
			if(y==1)
			{
				b|=(1<<i);
				i--;
				first(i);
				return 0;
			}
			else
				i--;
		}
		else if(x==-1)
		{
			if(y==-1)
			{
				b|=(1<<i);
				i--;
				return second(i);
			}
			a|=(1<<i);
			b|=(1<<i);
			i--;
		}
		else
		{
			b|=(1<<i);
			i--;
			if(y==0)
			return equal(i);
			else if(y==1)
			{
				return first(i);
			}
			else return second(i);
		}
	}
}
int main()
{
	for(int i=29;i>=0;i--)
	{
		int c=a,d=b,x;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		if(x==1)
		{
			first(i);
		}
		else if(x==-1)
		{
			second(i);
		}
		else equal(i);
	}
	cout<<"! "<<a<<" "<<b<<"\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi >
const int N=1000010;

int main()
{
	int a=0,b=0,n=0;
	int c=a,d=b,x;
	cout<<"? "<<c<<" "<<d<<"\n";
	flush(cout);
	cin>>n;
	for(int i=29;i>=0;i--)
	{
		int c=a|(1<<i),d=b,x,y;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		c=a;b=d|(1<<i);
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>y;
		if(x==y)
		{
			if(n==1)a|=(1<<i);
			else b|=(1<<i);
			n=x;
		}
		else if(x==-1)
		a|=(1<<i),b|=(1<<i);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi >
const int N=1000010;
int second(int);
int a=0,b=0;
int equal(int &i)
{
	while(i>=0)
	{
		int c=a,d=b|(1<<i),x;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		if(x==1)
			a|=(1<<i),b|=(1<<i);
		i--;
	}
}
int first(int &i)
{
	while(i>=0)
	{
		if(i==0)
		{
			a|=(1<<i);
			i--;
			return 0;
		}
		int c=a,d=b|(1<<i),x,y;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		c=a|(1<<i);d=b;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>y;
		if(x==1)
		{
			if(y==1)
			{
				a|=(1<<i);
				i--;
				first(i);
				return 0;
			}
			else
			{
				a|=(1<<i);
				b|=(1<<i);
				i--;
			}
		}
		else if(x==-1)
		{
			if(y==-1)
			{
				a|=(1<<i);
				i--;
				second(i);
				return 0;
			}
			i--;
		}
		else
		{
			a|=(1<<i);
			i--;
			if(y==0)
			return equal(i);
			else if(y==1)
			{
				return first(i);
			}
			else return second(i);
		}

	}
}
int second(int i)
{
	while(i>=0)
	{
		if(i==0)
		{
			b|=(1<<i);
			i--;
			return 0;
		}
		int c=a|(1<<i),d=b,x,y;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		c=a;d=b|(1<<i);
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>y;
		if(x==1)
		{
			if(y==1)
			{
				b|=(1<<i);
				i--;
				first(i);
				return 0;
			}
			else
				i--;
		}
		else if(x==-1)
		{
			a|=(1<<i);
			b|=(1<<i);
			i--;
		}
		else
		{
			b|=(1<<i);
			i--;
			if(y==0)
			return equal(i);
			else if(y==1)
			{
				return first(i);
			}
			else return second(i);
		}
	}
}
int main()
{
	for(int i=4;i>=0;i--)
	{
		int c=a,d=b,x;
		cout<<"? "<<c<<" "<<d<<"\n";
		flush(cout);
		cin>>x;
		if(x==1)
		{
			first(i);
		}
		else if(x==-1)
		{
			second(i);
		}
		else equal(i);
	}
	cout<<"! "<<a<<" "<<b<<"\n";
	return 0;
}


//
#include <bits/stdc++.h>
#define mod 1000000007
#define inf 1000000000000000000
#define mk make_pair
#define pb push_back
#define pii pair<lli, lli>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef long long int lli;
typedef long double ld;
const lli sz=100010, sz2=1000010;
lli toint(const string &s) {stringstream ss; ss << s; lli x; ss >> x; return x;}
string tostring ( lli number ){stringstream ss; ss<< number; return ss.str();}
int parent[sz2];
void make (int n)
{
    for (int i=0; i<=n; i++) {
        parent[i]=i;
    }
}
int get (int n)
{
    if (parent[n]==n) {
        return n;
    }
    else {
        parent[n]=get(parent[n]);
        return parent[n];
    }
}
void Union (int x, int y)
{
    int px=get(x), py=get(y);
    parent[px]=py;
}
int main ()
{
    fastio;
    int n;
    cin>>n;
    vector<pii> a(n);
    for (int i=0; i<n; i++) {
        cin>>a[i].first>>a[i].second;
    }
    make(n);
    sort(a.begin(), a.end());
    map<pii, int> mp;
    string ans="YES";
    for (int i=0; i<n; i++) {
        for (int j=i+1; j<n && a[i].second>a[j].first; j++) {
            if (a[i].second>=a[j].first && a[i].second<=a[j].second) {
                if (get(i)==get(j)) {
                    ans="NO";
                }
                Union(i, j);
                mp[mk(i,j)]=1;
            }
        }
    }
    for (int i=0; i<2000000 && ans=="YES"; i++) {
        lli ff=rand()%n, ss=rand()%n;
        lli x=min(ff, ss), y=max(ff, ss);
        if ((a[x].first<a[y].first && a[x].second>=a[y].first && a[x].second<=a[y].second) ||
            (a[y].first<a[x].first && a[y].second>=a[x].first && a[y].second<=a[x].second)) {

            if (get(x)!=get(y)) {
                Union(x,y);
                mp[mk(x,y)]=1;
            }
            else {
                //cout<<a[x].first<<" "<<a[y].first<<endl;
                if (mp[mk(x,y)]==0) {
                    ans="NO";
                }
            }

        }
    }
    lli count=0;
    for (int i=0; i<n; i++) {
        if (get(i)==i) {
            count++;
        }
    }
    if (count>1) {
        ans="NO";
    }
    cout<<ans<<endl;
    return 0;
}


//
#include <bits/stdc++.h>
#define mod 1000000007
#define inf 1000000000000000000
#define mk make_pair
#define pb push_back
#define pii pair<lli, lli>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef long long int lli;
typedef long double ld;
const lli sz=100010, sz2=1000010;
lli toint(const string &s) {stringstream ss; ss << s; lli x; ss >> x; return x;}
string tostring ( lli number ){stringstream ss; ss<< number; return ss.str();}
int parent[sz2];
void make (int n)
{
    for (int i=0; i<=n; i++) {
        parent[i]=i;
    }
}
int get (int n)
{
    if (parent[n]==n) {
        return n;
    }
    else {
        parent[n]=get(parent[n]);
        return parent[n];
    }
}
void Union (int x, int y)
{
    int px=get(x), py=get(y);
    parent[px]=py;
}
int main ()
{
    fastio;
    int n;
    cin>>n;
    vector<pii> a(n);
    for (int i=0; i<n; i++) {
        cin>>a[i].first>>a[i].second;
    }
    make(n);
    sort(a.begin(), a.end());
    map<pii, int> mp;
    string ans="YES";
    for (int i=0; i<n && ans=="YES"; i++) {
        for (int j=i+1; j<i+8000 && j<n && a[i].second>a[j].first; j++) {
            if (a[i].second>=a[j].first && a[i].second<=a[j].second) {
                if (get(i)==get(j)) {
                    ans="NO";
                }
                Union(i, j);
                mp[mk(i,j)]=1;
            }
        }
    }
    for (int i=0; i<4000000 && ans=="YES"; i++) {
        lli ff=rand()%n, ss=rand()%n;
        lli x=min(ff, ss), y=max(ff, ss);
        if ((a[x].first<a[y].first && a[x].second>=a[y].first && a[x].second<=a[y].second) ||
            (a[y].first<a[x].first && a[y].second>=a[x].first && a[y].second<=a[x].second)) {

            if (get(x)!=get(y)) {
                Union(x,y);
                mp[mk(x,y)]=1;
            }
            else {
                //cout<<a[x].first<<" "<<a[y].first<<endl;
                if (mp[mk(x,y)]==0) {
                    ans="NO";
                }
            }

        }
    }
    lli count=0;
    for (int i=0; i<n; i++) {
        if (get(i)==i) {
            count++;
        }
    }
    if (count>1) {
        ans="NO";
    }
    cout<<ans<<endl;
    return 0;
}


//
#include <bits/stdc++.h>
#define mod 1000000007
#define inf 1000000000000000000
#define mk make_pair
#define pb push_back
#define pii pair<lli, lli>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef long long int lli;
typedef long double ld;
const lli sz=500010, sz2=1000010;
lli toint(const string &s) {stringstream ss; ss << s; lli x; ss >> x; return x;}
string tostring ( lli number ){stringstream ss; ss<< number; return ss.str();}
vector<int> g[sz], vis(sz, 0);
int cnt=0;
void dfs (int u, int p=-1)
{
    vis[u]=1;
    cnt++;
    for (int v:g[u]) {
        if (vis[v]==0) {
            dfs(v, u);
        }
    }
}
int main ()
{
    fastio;
    int n;
    cin>>n;
    vector<pair<pii, lli> > a(n);
    for (int i=0; i<n; i++) {
        cin>>a[i].first.first>>a[i].first.second;
        a[i].second=i;
    }
    sort(a.begin(), a.end());
    set<pii> s;
    int count=0;
    for (int i=0; i<n && count<n; i++) {
        pii temp=mk(a[i].first.first, -inf);
        auto start=s.upper_bound(temp);
        for (auto itr=start; itr!=s.end(); itr++) {
            pii p=*itr;
            if (p.first>=a[i].first.second) {
                break;
            }
            if (p.first<a[i].first.first) {
                continue;
            }
            g[p.second].pb(a[i].second);
            g[a[i].second].pb(p.second);
            count++;
        }
        s.insert(mk(a[i].first.second, a[i].second));
    }
    dfs(0);
    string ans="NO";
    if (count==n-1 && cnt==n) {
        ans="YES";
    }
    cout<<ans<<endl;
    return 0;
}


//
#include <bits/stdc++.h>
#define mod 1000000007
#define inf 1000000000000000000
#define mk make_pair
#define pb push_back
#define pii pair<lli, lli>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef long long int lli;
typedef long double ld;
const lli sz=100010, sz2=1000010;
lli toint(const string &s) {stringstream ss; ss << s; lli x; ss >> x; return x;}
string tostring ( lli number ){stringstream ss; ss<< number; return ss.str();}
int parent[sz2];
void make (int n)
{
    for (int i=0; i<=n; i++) {
        parent[i]=i;
    }
}
int get (int n)
{
    if (parent[n]==n) {
        return n;
    }
    else {
        parent[n]=get(parent[n]);
        return parent[n];
    }
}
void Union (int x, int y)
{
    int px=get(x), py=get(y);
    parent[px]=py;
}
int main ()
{
    fastio;
    int n;
    cin>>n;
    vector<pii> a(n);
    for (int i=0; i<n; i++) {
        cin>>a[i].first>>a[i].second;
    }
    make(n);
    sort(a.begin(), a.end());
    map<pii, int> mp;
    string ans="YES";
    for (int i=0; i<n; i++) {
        for (int j=i+1; j<i+6000 && j<n && a[i].second>a[j].first; j++) {
            if (a[i].second>=a[j].first && a[i].second<=a[j].second) {
                if (get(i)==get(j)) {
                    ans="NO";
                }
                Union(i, j);
                mp[mk(i,j)]=1;
            }
        }
    }
    for (int i=0; i<4000000 && ans=="YES"; i++) {
        lli ff=rand()%n, ss=rand()%n;
        lli x=min(ff, ss), y=max(ff, ss);
        if ((a[x].first<a[y].first && a[x].second>=a[y].first && a[x].second<=a[y].second) ||
            (a[y].first<a[x].first && a[y].second>=a[x].first && a[y].second<=a[x].second)) {

            if (get(x)!=get(y)) {
                Union(x,y);
                mp[mk(x,y)]=1;
            }
            else {
                //cout<<a[x].first<<" "<<a[y].first<<endl;
                if (mp[mk(x,y)]==0) {
                    ans="NO";
                }
            }

        }
    }
    lli count=0;
    for (int i=0; i<n; i++) {
        if (get(i)==i) {
            count++;
        }
    }
    if (count>1) {
        ans="NO";
    }
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <list>
#include <utility>
using namespace std;

typedef pair<int, int> pii;
const int sz = 1e6+10;
int segs[sz];

bool istree(int C) {
  list<pii> seen;
  seen.push_front(make_pair(1, segs[1]));
  int seensz = 1, req_edges = C - 1;
  int i = 2, i_end = 2*C;

  if (C == 1) return true;
  if (segs[1] == i_end) return false;

  while (i <= i_end) {
    if (seensz == 0 || req_edges < 0) return false;
    auto seg2 = seen.begin();
    if (i == seg2->second) {
      seen.pop_front();
      --seensz;
      ++i;
      continue;
    }

    int seg1 = segs[i];
    if (seg1 == i+1) return false;
    auto seen_end = seen.end();
    int last_seen = i;

    if (seg1 == i_end) {
      int last_seen = i;
      while (true) {
        if (seg2 == seen_end) {
          if (seg1-1 != last_seen) {
            i_end = seg1-1;
          }
          break;
        }
        else if (i > seg2->first) {
          if (seg2->second-1 != last_seen)
            i_end = seg2->second-1;
          last_seen = seg2->second;
          --req_edges;
        } else {
          return false;
        }
        ++seg2;
      }
    }
    else {
      while (seg2 != seen_end && seg1 > seg2->second) {
        if (i > seg2->first) {
          last_seen = seg2->second;
          --req_edges;
        } else {
          return false;
        }
        ++seg2;
      }
      seen.insert(seg2, make_pair(last_seen, seg1));
    }
    ++seensz;

    ++i;
  }

  if (req_edges) return false;

  return true;
}

int main () {
  int C, l, r;
  scanf("%d", &C);

  for (int i = 0; i < C; ++i) {
    scanf("%d %d", &l, &r);
    segs[l] = r;
  }

  if (istree(C)) {
    printf("YES");
  }
  else {
    printf("NO");
  }

  return 0;
}


#include <iostream>
#include <list>
#include <utility>
#include <algorithm>
using namespace std;

struct Segment {
  int left, right, index;

  Segment () {

  }

  Segment (int l, int r, int i) {
    left = l;
    right = r;
    index = i;
  }

  bool operator < (const Segment& other) const {
    return left < other.left;
  }
};

const int sz = 5e5 + 10;
Segment segs[sz];
int* graphs[sz];

bool istree(int C) {
  int vertices = 0, edges = 0;
  list<Segment> cur;
  int graph = 0, graphcount = 0;

  ///*
  auto segsend = segs+C;
  for (int i = 0; i < C; ++i) {
    if (graphcount > C-i) return false;
    Segment seg1 = segs[i];
    auto curend = cur.end();
    for (auto seg2 = cur.begin(); seg2 != curend; ) {
      if (seg2->right > seg1.left) {
        if (seg1.right > seg2->right) {
          ++edges;
          if (graphs[seg1.index] != NULL) {
            if (graphs[seg2->index] != NULL) {
              if (*graphs[seg1.index] == *graphs[seg2->index]) {
                return false;
              }
              *graphs[seg2->index] = *graphs[seg1.index];
              --graphcount;
            }
            else {
              graphs[seg2->index] = graphs[seg1.index];
              ++vertices;
            }
          }
          else {
            if (graphs[seg2->index] != NULL) {
              graphs[seg1.index] = graphs[seg2->index];
              ++vertices;
            }
            else {
              int* g;
              g = new int(graph);
              graphs[seg1.index] = g;
              graphs[seg2->index] = g;
              ++graph;
              ++graphcount;
              vertices += 2;
            }
          }
        }
        ++seg2;
      }
      else {
        seg2 = cur.erase(seg2);
      }
    }
    cur.emplace_back(seg1);
  }
  //*/

  //printf("%d %d\n", vertices, edges);

  if (vertices == 0 || vertices-1 == edges) {
    return true;
  }

  return false;
}

int main () {
  int C, l, r;
  scanf("%d", &C);

  for (int i = 0; i < C; ++i) {
    scanf("%d %d", &l, &r);
    segs[i] = Segment(l, r, i);
  }

  sort(segs, segs+C);

  if (istree(C)) {
    printf("YES");
  }
  else {
    printf("NO");
  }

  return 0;
}


#include <iostream>
#include <list>
#include <utility>
using namespace std;

typedef pair<int, int> pii;
const int sz = 1e6+10;
int segs[sz];

bool istree(int C) {
  list<pii> seen;
  seen.push_front(make_pair(1, segs[1]));
  int seensz = 1, req_edges = C - 1;
  int i = 2, C2 = 2 * C;
  while (i <= C2) {
    if (seensz == 0) return false;
    auto seg2 = seen.begin();
    if (i == seg2->second) {
      seen.pop_front();
      --seensz;
      ++i;
      continue;
    }

    int seg1 = segs[i];
    auto seen_end = seen.end();
    int last_seen = i;
    while (seg2 != seen_end && seg1 > seg2->second) {
      if (i > seg2->first) {
        last_seen = seg2->first;
        --req_edges;
      } else {
        return false;
      }
      ++seg2;
    }
    seen.insert(seg2, make_pair(last_seen, seg1));
    ++seensz;

    ++i;
  }

  if (req_edges) return false;

  return true;
}

int main () {
  int C, l, r;
  scanf("%d", &C);

  for (int i = 0; i < C; ++i) {
    scanf("%d %d", &l, &r);
    segs[l] = r;
  }

  if (istree(C)) {
    printf("YES");
  }
  else {
    printf("NO");
  }

  return 0;
}


#include <iostream>
#include <list>
#include <utility>
using namespace std;

typedef pair<int, int> pii;
const int sz = 1e6+10;
int segs[sz];

bool istree(int C) {
  list<pii> seen;
  seen.push_front(make_pair(1, segs[1]));
  int seensz = 1, req_edges = C - 1;
  int i = 2, C2 = 2 * C;
  while (i <= C2) {
    if (seensz == 0 || req_edges < 0) return false;
    auto seg2 = seen.begin();
    if (i == seg2->second) {
      seen.pop_front();
      --seensz;
      ++i;
      continue;
    }

    int seg1 = segs[i];
    auto seen_end = seen.end();
    int last_seen = i;
    while (seg2 != seen_end && seg1 > seg2->second) {
      if (i > seg2->first) {
        last_seen = seg2->first;
        --req_edges;
      } else {
        return false;
      }
      ++seg2;
    }
    seen.insert(seg2, make_pair(last_seen, seg1));
    ++seensz;

    ++i;
  }

  if (req_edges) return false;

  return true;
}

int main () {
  int C, l, r;
  scanf("%d", &C);

  for (int i = 0; i < C; ++i) {
    scanf("%d %d", &l, &r);
    segs[l] = r;
  }

  if (istree(C)) {
    printf("YES");
  }
  else {
    printf("NO");
  }

  return 0;
}


#include <iostream>
#include <unordered_map>
#include <list>
#include <set>
using namespace std;

struct Segment {
  int left, right, index;
  Segment (int l, int r, int i) {
    left = l;
    right = r;
    index = i;
  }

  bool operator < (const Segment& other) const {
    return left < other.left;
  }
};

set<Segment> segs;

bool istree() {
  int vertices = 0, edges = 0;
  unordered_map<int, int*> graphs;
  list<Segment> cur;
  int graph = 0;

  ///*
  for (auto seg1 = segs.begin(); seg1 != segs.end(); ++seg1) {
    auto curend = cur.end();
    for (auto seg2 = cur.begin(); seg2 != curend; ) {
      if (seg2->right > seg1->left) {
        if (seg1->right > seg2->right) {
          ++edges;
          auto seg1_g = graphs.find(seg1->index);
          auto seg2_g = graphs.find(seg2->index);
          auto graphs_end = graphs.end();
          if (seg1_g != graphs_end) {
            if (seg2_g != graphs_end) {
              if (*(seg1_g->second) == *(seg2_g->second)) {
                return false;
              }
              *(seg2_g->second) = *(seg1_g->second);
            }
            else {
              graphs[seg2->index] = seg1_g->second;
              ++vertices;
            }
          }
          else {
            if (seg2_g != graphs_end) {
              graphs[seg1->index] = seg2_g->second;
              ++vertices;
            }
            else {
              int* g;
              g = new int(graph);
              graphs[seg1->index] = g;
              graphs[seg2->index] = g;
              ++graph;
              vertices += 2;
            }
          }
        }
        ++seg2;
      }
      else {
        seg2 = cur.erase(seg2);
      }
    }
    cur.emplace_back(*seg1);
  }
  //*/

  //printf("%d %d\n", vertices, edges);

  if (vertices == 0 || vertices-1 == edges) {
    return true;
  }

  return false;
}

int main () {
  int C, l, r;
  scanf("%d", &C);

  for (int i = 0; i < C; ++i) {
    scanf("%d %d", &l, &r);
    segs.emplace(l, r, i);
  }

  if (istree()) {
    printf("YES");
  }
  else {
    printf("NO");
  }

  return 0;
}


#include <iostream>
#include <list>
#include <utility>
using namespace std;

typedef pair<int, int> pii;
const int sz = 1e6+10;
int segs[sz];

bool istree(int C) {
  list<pii> seen;
  seen.push_front(make_pair(1, segs[1]));
  int seensz = 1, req_edges = C - 1;
  int i = 2, i_end = 2*C;
  if (segs[1] == i_end) return false;
  while (i <= i_end) {
    if (seensz == 0 || req_edges < 0) return false;
    auto seg2 = seen.begin();
    if (i == seg2->second) {
      seen.pop_front();
      --seensz;
      ++i;
      continue;
    }

    int seg1 = segs[i];
    auto seen_end = seen.end();
    int last_seen = i;

    if (seg1 == i_end) {
      int last_seen = i;
      while (true) {
        if (seg2 == seen_end) {
          if (seg1-1 != last_seen) {
            i_end = seg1-1;
          }
          break;
        }
        else if (i > seg2->first) {
          if (seg2->second-1 != last_seen)
            i_end = seg2->second-1;
          last_seen = seg2->second;
          --req_edges;
        } else {
          return false;
        }
        ++seg2;
      }
    }
    else {
      while (seg2 != seen_end && seg1 > seg2->second) {
        if (i > seg2->first) {
          last_seen = seg2->second;
          --req_edges;
        } else {
          return false;
        }
        ++seg2;
      }
      seen.insert(seg2, make_pair(last_seen, seg1));
    }
    ++seensz;

    ++i;
  }

  if (req_edges) return false;

  return true;
}

int main () {
  int C, l, r;
  scanf("%d", &C);

  for (int i = 0; i < C; ++i) {
    scanf("%d %d", &l, &r);
    segs[l] = r;
  }

  if (istree(C)) {
    printf("YES");
  }
  else {
    printf("NO");
  }

  return 0;
}


#include <iostream>
#include <list>
#include <unordered_set>
#include <stack>
#include <utility>
using namespace std;

typedef pair<int, int> pii;
const int sz_1 = 1e6+10;
const int sz_2 = 5e5+10;
int segs[sz_1];
unordered_set<int> edges[sz_2];
bool visited[sz_1];

bool istree(int C) {
  list<pii> seen;
  seen.push_front(make_pair(1, segs[1]));
  int seensz = 1, req_edges = C - 1;
  int i = 2, i_end = 2*C;

  if (C == 1) return true;
  if (segs[1] == i_end) return false;

  while (i <= i_end) {
    if (seensz == 0 || req_edges < 0) return false;
    auto seg2 = seen.begin();
    if (i == seg2->second) {
      seen.pop_front();
      --seensz;
      ++i;
      continue;
    }

    int seg1 = segs[i];
    if (seg1 == i+1) return false;
    auto seen_end = seen.end();
    int last_seen = i;

    if (seg1 == i_end) {
      int last_seen = i;
      while (true) {
        if (seg2 == seen_end) {
          if (seg1-1 != last_seen) {
            i_end = seg1-1;
          }
          break;
        }
        else if (i > seg2->first) {
          if (seg2->second-1 != last_seen)
            i_end = seg2->second-1;
          last_seen = seg2->second;
          --req_edges;
          edges[seg1].emplace(last_seen);
          edges[seg2->second].emplace(seg1);
        } else {
          return false;
        }
        ++seg2;
      }
    }
    else {
      while (seg2 != seen_end && seg1 > seg2->second) {
        if (i > seg2->first) {
          last_seen = seg2->second;
          --req_edges;
          edges[seg1].emplace(last_seen);
          edges[last_seen].emplace(seg1);
        } else {
          return false;
        }
        ++seg2;
      }
      seen.insert(seg2, make_pair(last_seen, seg1));
    }
    ++seensz;

    ++i;
  }

  if (req_edges) return false;

  int count = 0;
  stack<int> next( {i_end} );
  while (!next.empty()) {
    int v1 = next.top();
    next.pop();
    if (!visited[v1]) {
      ++count;
      visited[v1] = true;
      for (auto v2 = edges[v1].begin(); v2 != edges[v1].end(); ++v2) {
        if (!visited[*v2]) {
          next.push(*v2);
        }
      }
    }
  }

  if (count == C) return true;

  return false;
}

int main () {
  int C, l, r;
  scanf("%d", &C);

  for (int i = 0; i < C; ++i) {
    scanf("%d %d", &l, &r);
    segs[l] = r;
  }

  if (istree(C)) {
    printf("YES");
  }
  else {
    printf("NO");
  }

  return 0;
}


#include <iostream>
#include <unordered_map>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

struct Segment {
  int left, right, index;
  Segment (int l, int r, int i) {
    left = l;
    right = r;
    index = i;
  }

  bool operator < (const Segment& other) const {
    return left < other.left;
  }
};

vector<Segment> segs;

bool istree() {
  int vertices = 0, edges = 0;
  unordered_map<int, int*> graphs;
  list<Segment> cur;
  int graph = 0;

  ///*
  auto segsend = segs.end();
  for (auto seg1 = segs.begin(); seg1 != segsend; ++seg1) {
    auto curend = cur.end();
    for (auto seg2 = cur.begin(); seg2 != curend; ) {
      if (seg2->right > seg1->left) {
        if (seg1->right > seg2->right) {
          ++edges;
          auto seg1_g = graphs.find(seg1->index);
          auto seg2_g = graphs.find(seg2->index);
          auto graphs_end = graphs.end();
          if (seg1_g != graphs_end) {
            if (seg2_g != graphs_end) {
              if (*(seg1_g->second) == *(seg2_g->second)) {
                return false;
              }
              *(seg2_g->second) = *(seg1_g->second);
            }
            else {
              graphs.insert(make_pair(seg2->index, seg1_g->second));
              ++vertices;
            }
          }
          else {
            if (seg2_g != graphs_end) {
              graphs.insert(make_pair(seg1->index, seg2_g->second));
              ++vertices;
            }
            else {
              int* g;
              g = new int(graph);
              graphs.insert(make_pair(seg1->index, g));
              graphs.insert(make_pair(seg2->index, g));
              ++graph;
              vertices += 2;
            }
          }
        }
        ++seg2;
      }
      else {
        seg2 = cur.erase(seg2);
      }
    }
    cur.emplace_back(*seg1);
  }
  //*/

  //printf("%d %d\n", vertices, edges);

  if (vertices == 0 || vertices-1 == edges) {
    return true;
  }

  return false;
}

int main () {
  int C, l, r;
  scanf("%d", &C);

  for (int i = 0; i < C; ++i) {
    scanf("%d %d", &l, &r);
    segs.emplace_back(l, r, i);
  }

  sort(segs.begin(), segs.end());

  if (istree()) {
    printf("YES");
  }
  else {
    printf("NO");
  }

  return 0;
}


#include <iostream>
#include <list>
#include <utility>
using namespace std;

typedef pair<int, int> pii;
const int sz = 1e6+10;
int segs[sz];

bool istree(int C) {
  list<pii> seen;
  seen.push_front(make_pair(1, segs[1]));
  int seensz = 1, req_edges = C - 1;
  int i = 2, i_end = 2*C;

  if (C == 1) return true;
  if (segs[1] == i_end) return false;

  while (i <= i_end) {
    if (seensz == 0 || req_edges < 0) return false;
    auto seg2 = seen.begin();
    if (i == seg2->second) {
      seen.pop_front();
      --seensz;
      ++i;
      continue;
    }

    int seg1 = segs[i];
    auto seen_end = seen.end();
    int last_seen = i;

    if (seg1 == i_end) {
      int last_seen = i;
      while (true) {
        if (seg2 == seen_end) {
          if (seg1-1 != last_seen) {
            i_end = seg1-1;
          }
          break;
        }
        else if (i > seg2->first) {
          if (seg2->second-1 != last_seen)
            i_end = seg2->second-1;
          last_seen = seg2->second;
          --req_edges;
        } else {
          return false;
        }
        ++seg2;
      }
    }
    else {
      while (seg2 != seen_end && seg1 > seg2->second) {
        if (i > seg2->first) {
          last_seen = seg2->second;
          --req_edges;
        } else {
          return false;
        }
        ++seg2;
      }
      seen.insert(seg2, make_pair(last_seen, seg1));
    }
    ++seensz;

    ++i;
  }

  if (req_edges) return false;

  return true;
}

int main () {
  int C, l, r;
  scanf("%d", &C);

  for (int i = 0; i < C; ++i) {
    scanf("%d %d", &l, &r);
    segs[l] = r;
  }

  if (istree(C)) {
    printf("YES");
  }
  else {
    printf("NO");
  }

  return 0;
}


#include <iostream>
#include <unordered_map>
#include <list>
#include <set>
using namespace std;

struct Segment {
  int left, right, index;
  Segment (int l, int r, int i) {
    left = l;
    right = r;
    index = i;
  }

  bool operator < (const Segment& other) const {
    return left < other.left;
  }
};

set<Segment> segs;

bool istree() {
  int vertices = 0, edges = 0;
  unordered_map<int, int*> graphs;
  list<Segment> cur;
  int graph = 0;

  ///*
  for (auto seg1 = segs.begin(); seg1 != segs.end(); ++seg1) {
    auto curend = cur.end();
    for (auto seg2 = cur.begin(); seg2 != curend; ++seg2) {
      if (seg2->right > seg1->left) {
        if (seg1->right > seg2->right) {
          ++edges;
          auto seg1_g = graphs.find(seg1->index);
          auto seg2_g = graphs.find(seg2->index);
          auto graphs_end = graphs.end();
          if (seg1_g != graphs_end) {
            if (seg2_g != graphs_end) {
              if (*(seg1_g->second) == *seg2_g->second) {
                return false;
              }
              *(seg2_g->second) = *(seg1_g->second);
            }
            else {
              graphs[seg2->index] = seg1_g->second;
              ++vertices;
            }
          }
          else {
            if (seg2_g != graphs_end) {
              graphs[seg1->index] = seg2_g->second;
              ++vertices;
            }
            else {
              int* g;
              g = new int(graph);
              graphs[seg1->index] = g;
              graphs[seg2->index] = g;
              ++graph;
              vertices += 2;
            }
          }
        }
      } else {
        seg2 = cur.erase(seg2);
      }
    }
    cur.emplace_back(*seg1);
  }
  //*/

  //printf("%d %d\n", vertices, edges);

  if (vertices == 0 || vertices-1 == edges) {
    return true;
  }

  return false;
}

int main () {
  int C, l, r;
  scanf("%d", &C);

  for (int i = 0; i < C; ++i) {
    scanf("%d %d", &l, &r);
    segs.emplace(l, r, i);
  }

  if (istree()) {
    printf("YES");
  }
  else {
    printf("NO");
  }

  return 0;
}


#include <iostream>
#include <list>
#include <utility>
#include <algorithm>
using namespace std;

struct Segment {
  int left, right, index;

  Segment () {

  }

  Segment (int l, int r, int i) {
    left = l;
    right = r;
    index = i;
  }

  bool operator < (const Segment& other) const {
    return left < other.left;
  }
};

const int sz = 5e5 + 10;
Segment segs[sz];
int* graphs[sz];

bool istree(int C) {
  int vertices = 0, edges = 0;
  list<Segment> cur;
  int graph = 0;

  ///*
  auto segsend = segs+C;
  for (int i = 0; i < C; ++i) {
    Segment seg1 = segs[i];
    auto curend = cur.end();
    for (auto seg2 = cur.begin(); seg2 != curend; ) {
      if (seg2->right > seg1.left) {
        if (seg1.right > seg2->right) {
          ++edges;
          if (graphs[seg1.index] != NULL) {
            if (graphs[seg2->index] != NULL) {
              if (*graphs[seg1.index] == *graphs[seg2->index]) {
                return false;
              }
              *graphs[seg2->index] = *graphs[seg1.index];
            }
            else {
              graphs[seg2->index] = graphs[seg1.index];
              ++vertices;
            }
          }
          else {
            if (graphs[seg2->index] != NULL) {
              graphs[seg1.index] = graphs[seg2->index];
              ++vertices;
            }
            else {
              int* g;
              g = new int(graph);
              graphs[seg1.index] = g;
              graphs[seg2->index] = g;
              ++graph;
              vertices += 2;
            }
          }
        }
        ++seg2;
      }
      else {
        seg2 = cur.erase(seg2);
      }
    }
    cur.emplace_back(seg1);
  }
  //*/

  //printf("%d %d\n", vertices, edges);

  if (vertices == 0 || vertices-1 == edges) {
    return true;
  }

  return false;
}

int main () {
  int C, l, r;
  scanf("%d", &C);

  for (int i = 0; i < C; ++i) {
    scanf("%d %d", &l, &r);
    segs[i] = Segment(l, r, i);
  }

  sort(segs, segs+C);

  if (istree(C)) {
    printf("YES");
  }
  else {
    printf("NO");
  }

  return 0;
}


#include <iostream>
#include <list>
#include <utility>
#include <algorithm>
using namespace std;

struct Segment {
  int left, right, index;

  Segment () {

  }

  Segment (int l, int r, int i) {
    left = l;
    right = r;
    index = i;
  }

  bool operator < (const Segment& other) const {
    return left < other.left;
  }
};

const int sz = 5e5 + 10;
Segment segs[sz];
int* graphs[sz];

bool istree(int C) {
  int vertices = 0, edges = 0;
  list<Segment> cur;
  int graph = 0, graphcount = 0;

  ///*
  auto segsend = segs+C;
  for (int i = 0; i < C; ++i) {
    if (graphcount-1 > C-i) return false;
    Segment seg1 = segs[i];
    auto curend = cur.end();
    for (auto seg2 = cur.begin(); seg2 != curend; ) {
      if (seg2->right > seg1.left) {
        if (seg1.right > seg2->right) {
          ++edges;
          if (graphs[seg1.index] != NULL) {
            if (graphs[seg2->index] != NULL) {
              if (*graphs[seg1.index] == *graphs[seg2->index]) {
                return false;
              }
              *graphs[seg2->index] = *graphs[seg1.index];
              --graphcount;
            }
            else {
              graphs[seg2->index] = graphs[seg1.index];
              ++vertices;
            }
          }
          else {
            if (graphs[seg2->index] != NULL) {
              graphs[seg1.index] = graphs[seg2->index];
              ++vertices;
            }
            else {
              int* g;
              g = new int(graph);
              graphs[seg1.index] = g;
              graphs[seg2->index] = g;
              ++graph;
              ++graphcount;
              vertices += 2;
            }
          }
        }
        ++seg2;
      }
      else {
        seg2 = cur.erase(seg2);
      }
    }
    cur.emplace_back(seg1);
  }
  //*/

  //printf("%d %d\n", vertices, edges);

  if (vertices == 0 || vertices-1 == edges) {
    return true;
  }

  return false;
}

int main () {
  int C, l, r;
  scanf("%d", &C);

  for (int i = 0; i < C; ++i) {
    scanf("%d %d", &l, &r);
    segs[i] = Segment(l, r, i);
  }

  sort(segs, segs+C);

  if (istree(C)) {
    printf("YES");
  }
  else {
    printf("NO");
  }

  return 0;
}


#include <iostream>
#include <list>
#include <utility>
using namespace std;

typedef pair<int, int> pii;
const int sz = 1e5+10;
int segs[sz];

bool istree(int C) {
  list<pii> seen;
  seen.push_front(make_pair(1, segs[1]));
  int seensz = 1, req_edges = C - 1;
  int i = 2, C2 = 2 * C;
  while (i <= C2) {
    if (seensz == 0) return false;
    auto seg2 = seen.begin();
    if (i == seg2->second) {
      seen.pop_front();
      --seensz;
      ++i;
      continue;
    }

    int seg1 = segs[i];
    auto seen_end = seen.end();
    int last_seen = i;
    while (seg2 != seen_end && seg1 > seg2->second) {
      if (i > seg2->first) {
        last_seen = seg2->first;
        --req_edges;
      } else {
        return false;
      }
      ++seg2;
    }
    seen.insert(seg2, make_pair(last_seen, seg1));
    ++seensz;

    ++i;
  }

  if (req_edges) return false;

  return true;
}

int main () {
  int C, l, r;
  scanf("%d", &C);

  for (int i = 0; i < C; ++i) {
    scanf("%d %d", &l, &r);
    segs[l] = r;
  }

  if (istree(C)) {
    printf("YES");
  }
  else {
    printf("NO");
  }

  return 0;
}


#include <iostream>
#include <list>
#include <utility>
using namespace std;

typedef pair<int, int> pii;
const int sz = 1e6+10;
int segs[sz];

bool istree(int C) {
  list<pii> seen;
  seen.push_front(make_pair(1, segs[1]));
  int seensz = 1, req_edges = C - 1;
  int i = 2, C2 = 2 * C;
  while (i <= C2) {
    if (seensz == 0 || req_edges < 0) return false;
    auto seg2 = seen.begin();
    if (i == seg2->second) {
      seen.pop_front();
      --seensz;
      ++i;
      continue;
    }

    int seg1 = segs[i];
    auto seen_end = seen.end();
    int last_seen = i;
    while (seg2 != seen_end && seg1 > seg2->second) {
      if (i > seg2->first) {
        last_seen = seg2->second;
        --req_edges;
      } else {
        return false;
      }
      ++seg2;
    }
    seen.insert(seg2, make_pair(last_seen, seg1));
    ++seensz;

    ++i;
  }

  if (req_edges) return false;

  return true;
}

int main () {
  int C, l, r;
  scanf("%d", &C);

  for (int i = 0; i < C; ++i) {
    scanf("%d %d", &l, &r);
    segs[l] = r;
  }

  if (istree(C)) {
    printf("YES");
  }
  else {
    printf("NO");
  }

  return 0;
}


#include <iostream>
#include <list>
#include <unordered_set>
#include <stack>
#include <utility>
using namespace std;

typedef pair<int, int> pii;
const int sz = 1e6+10;
int segs[sz];
unordered_set<int> edges[sz];
bool visited[sz];

bool istree(int C) {
  list<pii> seen;
  seen.push_front(make_pair(1, segs[1]));
  int seensz = 1, req_edges = C - 1;
  int i = 2, i_end = 2*C;

  if (C == 1) return true;
  if (segs[1] == i_end) return false;

  while (i <= i_end) {
    if (seensz == 0 || req_edges < 0) return false;
    auto seg2 = seen.begin();
    if (i == seg2->second) {
      seen.pop_front();
      --seensz;
      ++i;
      continue;
    }

    int seg1 = segs[i];
    if (seg1 == i+1) return false;
    auto seen_end = seen.end();
    int last_seen = i;

    if (seg1 == i_end) {
      int last_seen = i;
      while (true) {
        if (seg2 == seen_end) {
          if (seg1-1 != last_seen) {
            i_end = seg1-1;
          }
          break;
        }
        else if (i > seg2->first) {
          if (seg2->second-1 != last_seen)
            i_end = seg2->second-1;
          last_seen = seg2->second;
          --req_edges;
          edges[seg1].emplace(last_seen);
          edges[seg2->second].emplace(seg1);
        } else {
          return false;
        }
        ++seg2;
      }
    }
    else {
      while (seg2 != seen_end && seg1 > seg2->second) {
        if (i > seg2->first) {
          last_seen = seg2->second;
          --req_edges;
          edges[seg1].emplace(last_seen);
          edges[last_seen].emplace(seg1);
        } else {
          return false;
        }
        ++seg2;
      }
      seen.insert(seg2, make_pair(last_seen, seg1));
    }
    ++seensz;

    ++i;
  }

  if (req_edges) return false;

  int count = 0;
  stack<int> next( {i_end} );
  while (!next.empty()) {
    int v1 = next.top();
    next.pop();
    if (!visited[v1]) {
      ++count;
      visited[v1] = true;
      for (auto v2 = edges[v1].begin(); v2 != edges[v1].end(); ++v2) {
        if (!visited[*v2]) {
          next.push(*v2);
        }
      }
    }
  }

  if (count == C) return true;

  return false;
}

int main () {
  int C, l, r;
  scanf("%d", &C);

  for (int i = 0; i < C; ++i) {
    scanf("%d %d", &l, &r);
    segs[l] = r;
  }

  if (istree(C)) {
    printf("YES");
  }
  else {
    printf("NO");
  }

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{
	int l,r,lo;
};
int n;
node e[500005];
int q[500005];
bool cmp(node A,node B){
	return A.l<B.l;
}
bool cmp1(node A,node B){
	return A.r>B.r;
}
int tr[10000001];
void ch(int k,int l,int r,int to){
	if(l==r){
		tr[k]++;
		return;
	}
	int mid=(l+r)/2;
	if(to<=mid)ch(k*2,l,mid,to);
	else ch(k*2+1,mid+1,r,to);
	tr[k]=tr[k*2]+tr[k*2+1];
}
int findl(int k,int l,int r,int l1,int r1){
	if(l>=l1&&r<=r1){
		return tr[k];
	}
	int sum=0;
	int mid=(l+r)/2;
	if(l1<=mid)sum+=findl(k*2,l,mid,l1,r1);
	if(r1>mid)sum+=findl(k*2+1,mid+1,r,l1,r1);
	return sum;

}
signed main(){
cin>>n;
for(int i=1;i<=n;i++){
	scanf("%lld %lld",&e[i].l,&e[i].r);
	e[i].lo=i;
}
sort(e+1,e+1+n,cmp);
int las=e[1].r,la2=0,la3=0;
int ans=0;
ch(1,1,2*n,e[1].r);
q[1]=e[1].r;
int l1=1,r1=1;

for(int i=2;i<=n;i++){
while(l1<=r1&&e[i].l>q[l1])l1++;
if(r1-l1+1>=2&&e[i].r>q[l1+1]){
	printf("NO");
	return 0;
}
if(l1>r1||e[i].r>q[r1]){
	q[++r1]=e[i].r;
}
	int temp=findl(1,1,2*n,e[i].l,e[i].r);
ans+=temp;
ch(1,1,2*n,e[i].r);
}

if(ans==n-1){
	printf("YES");
}
else printf("NO");

return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct node{
	int l,r;
};
int n;
node e[500001];
bool cmp(node A,node B){
	return A.l<B.l;
}

int tr[4000001];
void ch(int k,int l,int r,int to){
	if(l==r){
		tr[k]++;
		return;
	}
	int mid=(l+r)/2;
	if(to<=mid)ch(k*2,l,mid,to);
	else ch(k*2+1,mid+1,r,to);
	tr[k]=tr[k*2]+tr[k*2+1];
}
int findl(int k,int l,int r,int l1,int r1){
	if(l>=l1&&r<=r1){
		return tr[k];
	}
	int sum=0;
	int mid=(l+r)/2;
	if(l1<=mid)sum+=findl(k*2,l,mid,l1,r1);
	if(r1>mid)sum+=findl(k*2+1,mid+1,r,l1,r1);
	return sum;

}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
	scanf("%d %d",&e[i].l,&e[i].r);
}
sort(e+1,e+1+n,cmp);
int las=e[1].r,la2=0,la3=0;
int ans=0;
ch(1,1,2*n,e[1].r);
for(int i=2;i<=n;i++){
if(e[i].r<las){
	printf("NO");
	return 0;
}
las=min(e[i].r,las);
//cout<<e[i].r<<endl;
ans+=findl(1,1,2*n,e[i].l,e[i].r);
//cout<<ans<<endl;
ch(1,1,2*n,e[i].r);
}
//cout<<ans<<endl;
if(ans==n-1){
	printf("YES");
}
else printf("NO");

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{
	int l,r,lo;
};
int n;
node e[500005];
int q[500005];
bool cmp(node A,node B){
	return A.l<B.l;
}
bool cmp1(node A,node B){
	return A.r>B.r;
}
int tr[10000001];
void ch(int k,int l,int r,int to){
	if(l==r){
		tr[k]++;
		return;
	}
	int mid=(l+r)/2;
	if(to<=mid)ch(k*2,l,mid,to);
	else ch(k*2+1,mid+1,r,to);
	tr[k]=tr[k*2]+tr[k*2+1];
}
int findl(int k,int l,int r,int l1,int r1){
	if(l>=l1&&r<=r1){
		return tr[k];
	}
	int sum=0;
	int mid=(l+r)/2;
	if(l1<=mid)sum+=findl(k*2,l,mid,l1,r1);
	if(r1>mid)sum+=findl(k*2+1,mid+1,r,l1,r1);
	return sum;

}
signed main(){
cin>>n;
for(int i=1;i<=n;i++){
	scanf("%lld %lld",&e[i].l,&e[i].r);
	e[i].lo=i;
}
sort(e+1,e+1+n,cmp);
int las=e[1].r,la2=0,la3=0;
int ans=0;
ch(1,1,2*n,e[1].r);
q[1]=e[1].r;
for(int i=2;i<=n;i++){
	int temp=findl(1,1,2*n,e[i].l,e[i].r);
ans+=temp;
if(temp)q[e[i].lo]=1;
ch(1,1,2*n,e[i].r);
}
memset(tr,0,sizeof(tr));
sort(e+1,e+1+n,cmp1);
ch(1,1,2*n,e[1].l);
for(int i=2;i<=n;i++){
	int temp=findl(1,1,2*n,e[i].l,e[i].r);
	ans+=temp;
	if(temp)q[e[i].lo]=1;
	ch(1,1,2*n,e[i].l);
}
bool flag=1;
for(int i=1;i<=n;i++){
	if(q[i]==0){
		printf("NO");
		return 0;
	}
}
if(ans==2*n-2){
	printf("YES");
}
else printf("NO");

return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define ls d<<1
#define rs d<<1|1
using namespace std;
typedef long long LL;
 #define data node
const int N=500005;

int n,f[N],cnt;
struct node{int l,r;}a[N];
vector<int> vec[N*8];

bool cmp(data a,data b)
{
	return a.r<b.r;
}

int find(int x)
{
	return f[x]==x?x:f[x]=find(f[x]);
}

void ins(int d,int l,int r,int x,int y,int z)
{
	if (x<=l&&r<=y) {vec[d].pb(z);return;}
	int mid=(l+r)/2;
	if (x<=mid) ins(ls,l,mid,x,y,z);
	if (y>mid) ins(rs,mid+1,r,x,y,z);
}

void build(int d,int l,int r,int x,int y)
{
	//cout<<x<<endl;
	for (int R=0;R<vec[d].size();R++)
	{
		int op=vec[d][R];
		if (find(y)==find(op))
		{
			puts("NO");
			exit(0);
		}
		f[find(y)]=find(op);
		cnt++;
	}
	if (l==r) return;
	int mid=(l+r)/2;
	if (x<=mid) build(ls,l,mid,x,y);
	else build(rs,mid+1,r,x,y);
}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d%d",&a[i].l,&a[i].r);
	std::sort(a+1,a+n+1,cmp);
	LL ans=0;
	for (int i=1;i<=n;i++) f[i]=i;
	for (int i=1;i<=n;i++)
	{
		build(1,1,n*2,a[i].l,i);
		ins(1,1,n*2,a[i].l,a[i].r,i);
	}
	puts(cnt==n-1?"YES":"NO");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{
	int l,r;
};
int n;
node e[500005];
bool cmp(node A,node B){
	return A.l<B.l;
}

int tr[10000001];
void ch(int k,int l,int r,int to){
	if(l==r){
		tr[k]++;
		return;
	}
	int mid=(l+r)/2;
	if(to<=mid)ch(k*2,l,mid,to);
	else ch(k*2+1,mid+1,r,to);
	tr[k]=tr[k*2]+tr[k*2+1];
}
int findl(int k,int l,int r,int l1,int r1){
	if(l>=l1&&r<=r1){
		return tr[k];
	}
	int sum=0;
	int mid=(l+r)/2;
	if(l1<=mid)sum+=findl(k*2,l,mid,l1,r1);
	if(r1>mid)sum+=findl(k*2+1,mid+1,r,l1,r1);
	return sum;

}
signed main(){
cin>>n;
for(int i=1;i<=n;i++){
	scanf("%lld %lld",&e[i].l,&e[i].r);
}
sort(e+1,e+1+n,cmp);
int las=e[1].r,la2=0,la3=0;
int ans=0;
ch(1,1,2*n,e[1].r);
for(int i=2;i<=n;i++){
ans+=findl(1,1,2*n,e[i].l,e[i].r);
ch(1,1,2*n,e[i].r);
}
bool flag=1;
for(int i=1;i<=n;i++){
	if(!findl(1,1,2*n,e[i].l,e[i].r-1))flag=0;
}
if(!flag){
	printf("NO");
	return 0;
}
//cout<<ans<<endl;
if(ans==n-1){
	printf("YES");
}
else printf("NO");

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{
	int l,r,lo;
};
int n;
node e[500005];
int q[500005];
bool cmp(node A,node B){
	return A.l<B.l;
}
bool cmp1(node A,node B){
	return A.r>B.r;
}
int tr[10000001];
void ch(int k,int l,int r,int to){
	if(l==r){
		tr[k]++;
		return;
	}
	int mid=(l+r)/2;
	if(to<=mid)ch(k*2,l,mid,to);
	else ch(k*2+1,mid+1,r,to);
	tr[k]=tr[k*2]+tr[k*2+1];
}
int findl(int k,int l,int r,int l1,int r1){
	if(l>=l1&&r<=r1){
		return tr[k];
	}
	int sum=0;
	int mid=(l+r)/2;
	if(l1<=mid)sum+=findl(k*2,l,mid,l1,r1);
	if(r1>mid)sum+=findl(k*2+1,mid+1,r,l1,r1);
	return sum;

}
signed main(){
cin>>n;
for(int i=1;i<=n;i++){
	scanf("%lld %lld",&e[i].l,&e[i].r);
	e[i].lo=i;
}
sort(e+1,e+1+n,cmp);
int las=e[1].r,la2=0,la3=0;
int ans=0;
ch(1,1,2*n,e[1].r);
q[1]=e[1].r;
for(int i=2;i<=n;i++){
	if(e[i].l>las){
		printf("NO");
		return 0;
	}
	las=max(las,e[i].r);
	int temp=findl(1,1,2*n,e[i].l,e[i].r);
ans+=temp;
if(temp)q[e[i].lo]=1;
ch(1,1,2*n,e[i].r);
}
memset(tr,0,sizeof(tr));
sort(e+1,e+1+n,cmp1);
ch(1,1,2*n,e[1].l);
for(int i=2;i<=n;i++){
	int temp=findl(1,1,2*n,e[i].l,e[i].r);
	ans+=temp;
	if(temp)q[e[i].lo]=1;
	ch(1,1,2*n,e[i].l);
}
bool flag=1;
for(int i=1;i<=n;i++){
	if(q[i]==0){
		printf("NO");
		return 0;
	}
}
if(ans==2*n-2){
	printf("YES");
}
else printf("NO");

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{
	int l,r,lo;
};
int n;
node e[500005];
int q[500005];
bool cmp(node A,node B){
	return A.l<B.l;
}
bool cmp1(node A,node B){
	return A.r>B.r;
}
int tr[10000001];
void ch(int k,int l,int r,int to){
	if(l==r){
		tr[k]++;
		return;
	}
	int mid=(l+r)/2;
	if(to<=mid)ch(k*2,l,mid,to);
	else ch(k*2+1,mid+1,r,to);
	tr[k]=tr[k*2]+tr[k*2+1];
}
int findl(int k,int l,int r,int l1,int r1){
	if(l>=l1&&r<=r1){
		return tr[k];
	}
	int sum=0;
	int mid=(l+r)/2;
	if(l1<=mid)sum+=findl(k*2,l,mid,l1,r1);
	if(r1>mid)sum+=findl(k*2+1,mid+1,r,l1,r1);
	return sum;

}
signed main(){
cin>>n;
for(int i=1;i<=n;i++){
	scanf("%lld %lld",&e[i].l,&e[i].r);
	e[i].lo=i;
}
sort(e+1,e+1+n,cmp);
int las=e[1].r,la2=0,la3=0;
int ans=0;
ch(1,1,2*n,e[1].r);
q[1]=e[1].r;
for(int i=2;i<=n;i++){
	if(e[i].l<las){
		printf("NO");
		return 0;
	}
	las=max(las,e[i].r);
	int temp=findl(1,1,2*n,e[i].l,e[i].r);
ans+=temp;
if(temp)q[e[i].lo]=1;
ch(1,1,2*n,e[i].r);
}
memset(tr,0,sizeof(tr));
sort(e+1,e+1+n,cmp1);
ch(1,1,2*n,e[1].l);
for(int i=2;i<=n;i++){
	int temp=findl(1,1,2*n,e[i].l,e[i].r);
	ans+=temp;
	if(temp)q[e[i].lo]=1;
	ch(1,1,2*n,e[i].l);
}
bool flag=1;
for(int i=1;i<=n;i++){
	if(q[i]==0){
		printf("NO");
		return 0;
	}
}
if(ans==2*n-2){
	printf("YES");
}
else printf("NO");

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{
	int l,r;
};
int n;
node e[500005];
bool cmp(node A,node B){
	return A.l<B.l;
}

int tr[10000001];
void ch(int k,int l,int r,int to){
	if(l==r){
		tr[k]++;
		return;
	}
	int mid=(l+r)/2;
	if(to<=mid)ch(k*2,l,mid,to);
	else ch(k*2+1,mid+1,r,to);
	tr[k]=tr[k*2]+tr[k*2+1];
}
int findl(int k,int l,int r,int l1,int r1){
	if(l>=l1&&r<=r1){
		return tr[k];
	}
	int sum=0;
	int mid=(l+r)/2;
	if(l1<=mid)sum+=findl(k*2,l,mid,l1,r1);
	if(r1>mid)sum+=findl(k*2+1,mid+1,r,l1,r1);
	return sum;

}
signed main(){
cin>>n;
for(int i=1;i<=n;i++){
	scanf("%lld %lld",&e[i].l,&e[i].r);
}
sort(e+1,e+1+n,cmp);
int las=e[1].r,la2=0,la3=0;
int ans=0;
ch(1,1,2*n,e[1].r);
for(int i=2;i<=n;i++){
ans+=findl(1,1,2*n,e[i].l,e[i].r);
ch(1,1,2*n,e[i].r);
}
//cout<<ans<<endl;
if(ans==n-1){
	printf("YES");
}
else printf("NO");

return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct node{
	int l,r;
};
int n;
node e[500005];
bool cmp(node A,node B){
	return A.l<B.l;
}

int tr[10000001];
void ch(int k,int l,int r,int to){
	if(l==r){
		tr[k]++;
		return;
	}
	int mid=(l+r)/2;
	if(to<=mid)ch(k*2,l,mid,to);
	else ch(k*2+1,mid+1,r,to);
	tr[k]=tr[k*2]+tr[k*2+1];
}
int findl(int k,int l,int r,int l1,int r1){
	if(l>=l1&&r<=r1){
		return tr[k];
	}
	int sum=0;
	int mid=(l+r)/2;
	if(l1<=mid)sum+=findl(k*2,l,mid,l1,r1);
	if(r1>mid)sum+=findl(k*2+1,mid+1,r,l1,r1);
	return sum;

}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
	scanf("%d %d",&e[i].l,&e[i].r);
}
sort(e+1,e+1+n,cmp);
int las=e[1].r,la2=0,la3=0;
int ans=0;
ch(1,1,2*n,e[1].r);
for(int i=2;i<=n;i++){
ans+=findl(1,1,2*n,e[i].l,e[i].r);
ch(1,1,2*n,e[i].r);
}
//cout<<ans<<endl;
if(ans==n-1){
	printf("YES");
}
else printf("NO");

return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct node{
	int l,r;
};
int n;
node e[500001];
bool cmp(node A,node B){
	return A.l<B.l;
}

int tr[8000001];
void ch(int k,int l,int r,int to){
	if(l==r){
		tr[k]++;
		return;
	}
	int mid=(l+r)/2;
	if(to<=mid)ch(k*2,l,mid,to);
	else ch(k*2+1,mid+1,r,to);
	tr[k]=tr[k*2]+tr[k*2+1];
}
int findl(int k,int l,int r,int l1,int r1){
	if(l>=l1&&r<=r1){
		return tr[k];
	}
	int sum=0;
	int mid=(l+r)/2;
	if(l1<=mid)sum+=findl(k*2,l,mid,l1,r1);
	if(r1>mid)sum+=findl(k*2+1,mid+1,r,l1,r1);
	return sum;

}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
	scanf("%d %d",&e[i].l,&e[i].r);
}
sort(e+1,e+1+n,cmp);
int las=e[1].r,la2=0,la3=0;
int ans=0;
ch(1,1,2*n,e[1].r);
for(int i=2;i<=n;i++){
if(e[i].r<las){
	printf("NO");
	return 0;
}
las=max(e[i].r,las);
//cout<<e[i].r<<endl;
ans+=findl(1,1,2*n,e[i].l,e[i].r);
//cout<<ans<<endl;
ch(1,1,2*n,e[i].r);
}
//cout<<ans<<endl;
if(ans==n-1){
	printf("YES");
}
else printf("NO");

return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct node{
	int l,r;
};
int n;
node e[500001];
bool cmp(node A,node B){
	return A.l<B.l;
}

int tr[8000001];
void ch(int k,int l,int r,int to){
	if(l==r){
		tr[k]++;
		return;
	}
	int mid=(l+r)/2;
	if(to<=mid)ch(k*2,l,mid,to);
	else ch(k*2+1,mid+1,r,to);
	tr[k]=tr[k*2]+tr[k*2+1];
}
int findl(int k,int l,int r,int l1,int r1){
	if(l>=l1&&r<=r1){
		return tr[k];
	}
	int sum=0;
	int mid=(l+r)/2;
	if(l1<=mid)sum+=findl(k*2,l,mid,l1,r1);
	if(r1>mid)sum+=findl(k*2+1,mid+1,r,l1,r1);
	return sum;

}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
	scanf("%d %d",&e[i].l,&e[i].r);
}
sort(e+1,e+1+n,cmp);
int las=e[1].r,la2=0,la3=0;
int ans=0;
ch(1,1,2*n,e[1].r);
for(int i=2;i<=n;i++){

//cout<<e[i].r<<endl;
ans+=findl(1,1,2*n,e[i].l,e[i].r);
//cout<<ans<<endl;
ch(1,1,2*n,e[i].r);
}
//cout<<ans<<endl;
if(ans==n-1){
	printf("YES");
}
else printf("NO");

return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define ls d<<1
#define rs d<<1|1
using namespace std;
typedef long long LL;

const int N=500005;

int n,f[N],cnt;
struct data{int l,r;}a[N];
vector<int> vec[N*8];

bool cmp(data a,data b)
{
	return a.r<b.r;
}

int find(int x)
{
	return f[x]==x?x:f[x]=find(f[x]);
}

void ins(int d,int l,int r,int x,int y,int z)
{
	if (x<=l&&r<=y) {vec[d].pb(z);return;}
	int mid=(l+r)/2;
	if (x<=mid) ins(ls,l,mid,x,y,z);
	if (y>mid) ins(rs,mid+1,r,x,y,z);
}

void build(int d,int l,int r,int x,int y)
{
	//cout<<x<<endl;
	for (int R=0;R<vec[d].size();R++)
	{
		int op=vec[d][R];
		if (find(y)==find(op))
		{
			puts("NO");
			exit(0);
		}
		f[find(y)]=find(op);
		cnt++;
	}
	if (l==r) return;
	int mid=(l+r)/2;
	if (x<=mid) build(ls,l,mid,x,y);
	else build(rs,mid+1,r,x,y);
}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d%d",&a[i].l,&a[i].r);
	std::sort(a+1,a+n+1,cmp);
	LL ans=0;
	for (int i=1;i<=n;i++) f[i]=i;
	for (int i=1;i<=n;i++)
	{
		build(1,1,n*2,a[i].l,i);
		ins(1,1,n*2,a[i].l,a[i].r,i);
	}
	puts(cnt==n-1?"YES":"NO");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{
	int l,r,lo;
};
int n;
node e[500005];
int q[500005];
bool cmp(node A,node B){
	return A.l<B.l;
}
bool cmp1(node A,node B){
	return A.r>B.r;
}
int tr[10000001];
void ch(int k,int l,int r,int to){
	if(l==r){
		tr[k]++;
		return;
	}
	int mid=(l+r)/2;
	if(to<=mid)ch(k*2,l,mid,to);
	else ch(k*2+1,mid+1,r,to);
	tr[k]=tr[k*2]+tr[k*2+1];
}
int findl(int k,int l,int r,int l1,int r1){
	if(l>=l1&&r<=r1){
		return tr[k];
	}
	int sum=0;
	int mid=(l+r)/2;
	if(l1<=mid)sum+=findl(k*2,l,mid,l1,r1);
	if(r1>mid)sum+=findl(k*2+1,mid+1,r,l1,r1);
	return sum;

}
signed main(){
cin>>n;
for(int i=1;i<=n;i++){
	scanf("%lld %lld",&e[i].l,&e[i].r);
	e[i].lo=i;
}
sort(e+1,e+1+n,cmp);
int las=e[1].r,la2=0,la3=0;
int ans=0;
ch(1,1,2*n,e[1].r);
q[1]=e[1].r;
int l1=1,r1=1;

for(int i=2;i<=n;i++){
while(l1<=r1&&e[i].l>q[l1])l1++;
if(r1-l1+1>=2&&e[i].r>q[l1+1]){
	printf("NO");
	return 0;
}
if(l1>r1||e[i].r>q[r1]){
	q[++r1]=e[i].r;
}
else{
	int l2=l1,r2=r1;
	while(l2<r2){
		int mid=(l2+r2)/2;
		if(q[mid]>e[i].r)r2=mid;
		else l2=mid+1;
	}
	q[l2]=e[i].r;
}
	int temp=findl(1,1,2*n,e[i].l,e[i].r);
ans+=temp;
ch(1,1,2*n,e[i].r);
}

if(ans==n-1){
	printf("YES");
}
else printf("NO");

return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 500'000;
const int LOGN = 19;

int n, m, k;

int t[N + N];

void inc(int p) {
  for (; p < N + N; p |= p + 1) {
    ++t[p];
  }
}

int get(int l, int r) {
  int res = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) {
    res += t[r];
  }
  --l;
  for (; l >= 0; l = (l & (l + 1)) - 1) {
    res -= t[l];
  }
  return res;
}

pair<int, int> seg[(N + N) * 4];
int mx[N + N], mn[N + N];

pair<int, int> merge(const pair<int, int>& l, const pair<int, int>& r) {
  return make_pair(min(l.first, r.first), max(l.second, r.second));
}

void build(int v, int l, int r) {
  if (l + 1 == r) {
    seg[v] = {mn[l], mx[l]};
  } else {
    int mid = (l + r) / 2;
    build(v * 2 + 1, l, mid);
    build(v * 2 + 2, mid, r);
    seg[v] = merge(seg[v * 2 + 1], seg[v * 2 + 2]);
  }
}

pair<int, int> get(int v, int l, int r, int ql, int qr) {
  if (l == ql && r == qr) {
    return seg[v];
  }
  int mid = (l + r) / 2;
  if (qr <= mid) {
    return get(v * 2 + 1, l, mid, ql, qr);
  }
  if (ql >= mid) {
    return get(v * 2 + 2, mid, r, ql, qr);
  }
  return merge(get(v * 2 + 1, l, mid, ql, mid),
             get(v * 2 + 2, mid, r, mid, qr));
}

void solve(int) {
  cin >> n;
  vector<pair<int, int>> a(n);
  for (auto& pr : a) {
    cin >> pr.first >> pr.second;
    --pr.first; --pr.second;
    mx[pr.first] = pr.second;
    mn[pr.second] = pr.first;
  }
  build(0, 0, n + n);
  sort(begin(a), end(a));
  int64 ans = 0;
  bool ok = true;
  for (const auto& pr : a) {
    ans += get(pr.first, pr.second);
    inc(pr.second);
    auto res = get(0, 0, n + n, pr.first, pr.second + 1);
    ok &= res.first < pr.first || res.second > pr.second;
  }
  if (ok && ans == n - 1) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 500'000;
const int LOGN = 19;

int n, m, k;

int t[N + N];

void inc(int p) {
  for (; p < N + N; p |= p + 1) {
    ++t[p];
  }
}

int get(int l, int r) {
  int res = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) {
    res += t[r];
  }
  --l;
  for (; l >= 0; l = (l & (l + 1)) - 1) {
    res -= t[l];
  }
  return res;
}

pair<int, int> seg[(N + N) * 4];
int mx[N + N], mn[N + N];

pair<int, int> merge(const pair<int, int>& l, const pair<int, int>& r) {
  return make_pair(min(l.first, r.first), max(l.second, r.second));
}

void build(int v, int l, int r) {
  if (l + 1 == r) {
    seg[v] = {mn[l], mx[l]};
  } else {
    int mid = (l + r) / 2;
    build(v * 2 + 1, l, mid);
    build(v * 2 + 2, mid, r);
    seg[v] = merge(seg[v * 2 + 1], seg[v * 2 + 2]);
  }
}

pair<int, int> get(int v, int l, int r, int ql, int qr) {
  if (l == ql && r == qr) {
    return seg[v];
  }
  int mid = (l + r) / 2;
  if (qr <= mid) {
    return get(v * 2 + 1, l, mid, ql, qr);
  }
  if (ql >= mid) {
    return get(v * 2 + 2, mid, r, ql, qr);
  }
  return merge(get(v * 2 + 1, l, mid, ql, mid),
             get(v * 2 + 2, mid, r, mid, qr));
}

void solve(int) {
  cin >> n;
  vector<pair<int, int>> a(n);
  for (auto& pr : a) {
    cin >> pr.first >> pr.second;
    --pr.first; --pr.second;
    mx[pr.first] = pr.second;
    mn[pr.second] = pr.first;
  }
  build(0, 0, n + n);
  sort(begin(a), end(a));
  int64 ans = 0;
  bool ok = true;
  for (const auto& pr : a) {
    ans += get(pr.first, pr.second);
    inc(pr.second);
    auto res = get(0, 0, n + n, pr.first, pr.second + 1);
    ok &= res.first < pr.first || res.second > pr.second;
  }
  if ((n == 1 || ok) && ans == n - 1) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 500'000;
const int LOGN = 19;

int n, m, k;

int t[N + N];

void inc(int p) {
  for (; p < N + N; p |= p + 1) {
    ++t[p];
  }
}

int get(int l, int r) {
  int res = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) {
    res += t[r];
  }
  --l;
  for (; l >= 0; l = (l & (l + 1)) - 1) {
    res -= t[l];
  }
  return res;
}

pair<int, int> seg[(N + N) * 4];
int mx[N + N], mn[N + N];

pair<int, int> merge(const pair<int, int>& l, const pair<int, int>& r) {
  return make_pair(min(l.first, r.first), max(l.second, r.second));
}

void build(int v, int l, int r) {
  if (l + 1 == r) {
    seg[v] = {mn[l], mx[l]};
  } else {
    int mid = (l + r) / 2;
    build(v * 2 + 1, l, mid);
    build(v * 2 + 2, mid, r);
    seg[v] = merge(seg[v * 2 + 1], seg[v * 2 + 2]);
  }
}

pair<int, int> get(int v, int l, int r, int ql, int qr) {
  if (l == ql && r == qr) {
    return seg[v];
  }
  int mid = (l + r) / 2;
  if (qr <= mid) {
    return get(v * 2 + 1, l, mid, ql, qr);
  }
  if (ql >= mid) {
    return get(v * 2 + 2, mid, r, ql, qr);
  }
  return merge(get(v * 2 + 1, l, mid, ql, mid),
             get(v * 2 + 2, mid, r, mid, qr));
}

void solve(int) {
  cin >> n;
  vector<pair<int, int>> a(n);
  for (auto& pr : a) {
    cin >> pr.first >> pr.second;
    --pr.first; --pr.second;
    mx[pr.first] = pr.second;
    mn[pr.second] = pr.first;
  }
  build(0, 0, n + n);
  sort(begin(a), end(a));
  int64 ans = 0;
  bool ok = true;
  int r = 0;
  for (const auto& pr : a) {
    ans += get(pr.first, pr.second);
    inc(pr.second);
    auto res = get(0, 0, n + n, pr.first, pr.second + 1);
    ok &= res.first < pr.first || res.second > pr.second;
    ok &= pr.first < r;
    r = max(r, pr.second);
  }
  if ((n == 1 || ok) && ans == n - 1) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 500'000;
const int LOGN = 19;

int n, m, k;

int t[N + N];

void inc(int p) {
  for (; p < N + N; p |= p + 1) {
    ++t[p];
  }
}

int get(int l, int r) {
  int res = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) {
    res += t[r];
  }
  --l;
  for (; l >= 0; l = (l & (l + 1)) - 1) {
    res -= t[l];
  }
  return res;
}

void solve(int) {
  cin >> n;
  vector<pair<int, int>> a(n);
  for (auto& pr : a) {
    cin >> pr.first >> pr.second;
    --pr.first; --pr.second;
  }
  sort(begin(a), end(a));
  bool ok = true;
  int64 ans = 0;
  int r = 0;
  for (const auto& pr : a) {
    ans += get(pr.first, pr.second);
    inc(pr.second);
    ok &= r >= pr.first;
    r = max(r, pr.second);
  }
  if (ok && ans == n - 1) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 500'000;
const int LOGN = 19;

int n, m, k;

int t[N + N];

void inc(int p) {
  for (; p < N + N; p |= p + 1) {
    ++t[p];
  }
}

int get(int l, int r) {
  int res = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) {
    res += t[r];
  }
  --l;
  for (; l >= 0; l = (l & (l + 1)) - 1) {
    res -= t[l];
  }
  return res;
}

pair<int, int> seg[(N + N) * 4];
int mx[N + N], mn[N + N];

pair<int, int> merge(const pair<int, int>& l, const pair<int, int>& r) {
  return make_pair(min(l.first, r.first), max(l.second, r.second));
}

void build(int v, int l, int r) {
  if (l + 1 == r) {
    seg[v] = {mn[l], mx[l]};
  } else {
    int mid = (l + r) / 2;
    build(v * 2 + 1, l, mid);
    build(v * 2 + 2, mid, r);
    seg[v] = merge(seg[v * 2 + 1], seg[v * 2 + 2]);
  }
}

pair<int, int> get(int v, int l, int r, int ql, int qr) {
  if (l == ql && r == qr) {
    return seg[v];
  }
  int mid = (l + r) / 2;
  if (qr <= mid) {
    return get(v * 2 + 1, l, mid, ql, qr);
  }
  if (ql >= mid) {
    return get(v * 2 + 2, mid, r, ql, qr);
  }
  return merge(get(v * 2 + 1, l, mid, ql, mid),
             get(v * 2 + 2, mid, r, mid, qr));
}

void solve(int) {
  cin >> n;
  vector<pair<int, int>> a(n);
  for (auto& pr : a) {
    cin >> pr.first >> pr.second;
    --pr.first; --pr.second;
    mx[pr.first] = pr.second;
    mn[pr.second] = pr.first;
  }
  build(0, 0, n + n);
  sort(begin(a), end(a));
  int64 ans = 0;
  bool ok = true;
  int r = 0;
  for (const auto& pr : a) {
    ans += get(pr.first, pr.second);
    inc(pr.second);
    auto res = get(0, 0, n + n, pr.first, pr.second + 1);
    ok &= res.first < pr.first || res.second > pr.second;
    ok &= pr.first <= r;
    r = max(r, pr.second);
  }
  if ((n == 1 || ok) && ans == n - 1) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 500'000;
const int LOGN = 19;

int n, m, k;

int t[N + N];

void inc(int p) {
  for (; p < N + N; p |= p + 1) {
    ++t[p];
  }
}

int get(int l, int r) {
  int res = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) {
    res += t[r];
  }
  --l;
  for (; l >= 0; l = (l & (l + 1)) - 1) {
    res -= t[l];
  }
  return res;
}

void solve(int) {
  cin >> n;
  vector<pair<int, int>> a(n);
  for (auto& pr : a) {
    cin >> pr.first >> pr.second;
  }
  sort(begin(a), end(a));
  bool ok = true;
  int64 ans = 0;
  pair<int, int> prev = a[0];
  for (const auto& pr : a) {
    ans += get(pr.first, pr.second);
    inc(pr.second);
    ok &= prev.second >= pr.first;
    prev = pr;
  }
  if (ok && ans == n - 1) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


    #include <bits/stdc++.h>
    //#include <ext/pb_ds/tree_policy.hpp>
    //#include <ext/pb_ds/assoc_container.hpp>
    //using namespace __gnu_pbds;
    //template<typename key, typename val>
    //using ordered_tree =
    //  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
    using namespace std;
    typedef long long int64;
    typedef complex<double> comp;
    const double pi = 3.14159265358979323846;
    const int inf = (int)1e+9 + 2;
    const int64 inf64 = (int64)1e+18 + 2;
    const double dinf = 1e+20;
    const int mod = 1'000'000'007;//*/998244353;
    const int base = 2187;
    const double eps = 1e-9;
    const int N = 500'000;
    const int LOGN = 19;

    int n, m, k;

    int t[N + N];

    void inc(int p) {
      for (; p < N + N; p |= p + 1) {
        ++t[p];
      }
    }

    int get(int l, int r) {
      int res = 0;
      for (; r >= 0; r = (r & (r + 1)) - 1) {
        res += t[r];
      }
      --l;
      for (; l >= 0; l = (l & (l + 1)) - 1) {
        res -= t[l];
      }
      return res;
    }

    void solve(int) {
      cin >> n;
      vector<pair<int, int>> a(n);
      for (auto& pr : a) {
        cin >> pr.first >> pr.second;
        --pr.first; --pr.second
      }
      sort(begin(a), end(a));
      bool ok = true;
      int64 ans = 0;
      pair<int, int> prev = a[0];
      for (const auto& pr : a) {
        ans += get(pr.first, pr.second);
        inc(pr.second);
        ok &= prev.second >= pr.first;
        prev = pr;
      }
      if (ok && ans == n - 1) {
        cout << "YES\n";
      } else {
        cout << "NO\n";
      }
    }

    void precalc() {
    }

    int main() {
      ios::sync_with_stdio(0);
      cin.tie(0), cout.tie(0);
      precalc();
      int test = 1;
      //cin >> test;
      //auto start = chrono::high_resolution_clock::now();
      for (int i = 1; i <= test; ++i) {
        solve(i);
      }
      //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
      return 0;
    }


#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 500'000;
const int LOGN = 19;

int n, m, k;

int p[N];

int find(int x) {
  if (x == p[x]) {
    return x;
  }
  return p[x] = find(p[x]);
}

void solve(int) {
  cin >> n;
  vector<pair<int, int>> a(n);
  iota(p, p + n, 0);
  for (auto& pr : a) {
    cin >> pr.first >> pr.second;
    --pr.first; --pr.second;
  }
  sort(begin(a), end(a));
  set<pair<int, int>> st;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    while (!st.empty() && begin(st)->first < a[i].first) {
      st.erase(begin(st));
    }
    for (const auto& pr : st) {
      if (ans > n || pr.first > a[i].second) {
        break;
      }
      ++ans;
      p[find(i)] = find(pr.second);
    }
    st.emplace(a[i].second, i);
  }
  bool ok = ans == n - 1;
  for (int i = 1; i < n; ++i) {
    ok &= find(0) == find(i);
  }
  if (ok) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


    #include <bits/stdc++.h>
    //#include <ext/pb_ds/tree_policy.hpp>
    //#include <ext/pb_ds/assoc_container.hpp>
    //using namespace __gnu_pbds;
    //template<typename key, typename val>
    //using ordered_tree =
    //  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
    using namespace std;
    typedef long long int64;
    typedef complex<double> comp;
    const double pi = 3.14159265358979323846;
    const int inf = (int)1e+9 + 2;
    const int64 inf64 = (int64)1e+18 + 2;
    const double dinf = 1e+20;
    const int mod = 1'000'000'007;//*/998244353;
    const int base = 2187;
    const double eps = 1e-9;
    const int N = 500'000;
    const int LOGN = 19;

    int n, m, k;

    int t[N + N];

    void inc(int p) {
      for (; p < N + N; p |= p + 1) {
        ++t[p];
      }
    }

    int get(int l, int r) {
      int res = 0;
      for (; r >= 0; r = (r & (r + 1)) - 1) {
        res += t[r];
      }
      --l;
      for (; l >= 0; l = (l & (l + 1)) - 1) {
        res -= t[l];
      }
      return res;
    }

    void solve(int) {
      cin >> n;
      vector<pair<int, int>> a(n);
      for (auto& pr : a) {
        cin >> pr.first >> pr.second;
        --pr.first; --pr.second;
      }
      sort(begin(a), end(a));
      bool ok = true;
      int64 ans = 0;
      pair<int, int> prev = a[0];
      for (const auto& pr : a) {
        ans += get(pr.first, pr.second);
        inc(pr.second);
        ok &= prev.second >= pr.first;
        prev = pr;
      }
      if (ok && ans == n - 1) {
        cout << "YES\n";
      } else {
        cout << "NO\n";
      }
    }

    void precalc() {
    }

    int main() {
      ios::sync_with_stdio(0);
      cin.tie(0), cout.tie(0);
      precalc();
      int test = 1;
      //cin >> test;
      //auto start = chrono::high_resolution_clock::now();
      for (int i = 1; i <= test; ++i) {
        solve(i);
      }
      //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
      return 0;
    }


#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
// __gnu_pbds::gp_hash_table<int,int> mp;
#define int long long int
#define pb push_back
vector<vector<int>> adj;
vector<int> visit;
int ans=1;
int cn=0,ce=0;
void dfs(int node)
{
     cn++;
     //cout<<node<<endl;
     visit[node]=1;
     for(auto u:adj[node])
     {
          if(!visit[u])
          {
               ce++;
               dfs(u);
          }
     }
}

signed main(){

   // clock_t t = clock();
//********************************************************************************************

 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 int n,x,y,c;
 cin>>n;

  adj=vector<vector<int>>(2*n);
 visit=vector<int>(2*n);
 unordered_set<int> us;
 __gnu_pbds::gp_hash_table<int,int> m3;
 map<int,int> mh;
 __gnu_pbds::gp_hash_table<int,tuple<int,int,int>> m;
  vector<int> msv(2*n);
  c=0;
 for(int i=1;i<=n;i++)
 {
       cin>>x>>y;
       msv[c]=x;
       msv[c+1]=y;
       c+=2;
      m[x]={y,i,1};
      m[y]={x,i,-1};
 }
 sort(msv.begin(),msv.end());
 x=0;
 for(auto i:msv)
 {
      if(get<2>(m[i])==1)
      {
           auto itr=mh.lower_bound(i);
           for(;itr!=mh.end();itr++)
           {
                if(itr->first<get<0>(m[i]))
                {
                     x--;
                     if((-x)>=n)
                     {
                          cout<<"NO";
                          return 0;
                     }
                     us.insert(get<1>(m[itr->first]));
                     us.insert(get<1>(m[i]));
                     //cout<<get<1>(m[itr->first])<<" "<<get<1>(m[i])<<endl;
                     adj[get<1>(m[itr->first])].pb(get<1>(m[i]));
                     adj[get<1>(m[i])].pb(get<1>(m[itr->first]));
                }
                else
                {
                     break;
                }
           }
           mh[get<0>(m[i])]=1;
      }
      else
      {
           mh.erase(i);
      }
     //  cout<<i<<"&&& ";
     //  for(auto k:mh)
     //  cout<<k.first<<" ";
     //  cout<<endl;
}
dfs(*us.begin());
if(cn!=ce+1)
{
     cout<<"NO";
     return 0;
}

for(auto i:us)
{
     if(!visit[i])
     {
          cout<<"NO";
          return 0;
     }
}
cout<<"YES";
//********************************************************************************************
    //t = clock() - t;
    //printf ( "Time 1: %lf\n", ( double ) t / CLOCKS_PER_SEC );
}


#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
// __gnu_pbds::gp_hash_table<int,int> mp;
#define int long long int
#define pb push_back

signed main(){

   // clock_t t = clock();
//********************************************************************************************

 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 int n,x,y,c;
 cin>>n;
 __gnu_pbds::gp_hash_table<int,int> m3;
 map<int,int> mh;
 __gnu_pbds::gp_hash_table<int,tuple<int,int,int>> m;
  vector<int> msv(2*n);
  c=0;
 for(int i=1;i<=n;i++)
 {
       cin>>x>>y;
       msv[c]=x;
       msv[c+1]=y;
       c+=2;
      m[x]={y,i,1};
      m[y]={x,i,-1};
 }
 sort(msv.begin(),msv.end());
 x=0;
 for(auto i:msv)
 {
      if(get<2>(m[i])==1)
      {
           auto itr=mh.lower_bound(i);
           for(;itr!=mh.end();itr++)
           {
                if(itr->first<get<0>(m[i]))
                {
                     x--;
                   //  cout<<get<1>(m[itr->first])<<" "<<get<1>(m[i])<<endl;
                    m3[get<1>(m[itr->first])]=1;
                    m3[get<1>(m[i])]=1;
                }
                else
                {
                     break;
                }
           }
           mh[get<0>(m[i])]=1;
      }
      else
      {
           mh.erase(i);
      }
     //  cout<<i<<"&&& ";
     //  for(auto k:mh)
     //  cout<<k.first<<" ";
     //  cout<<endl;
}

x+=m3.size();
if(n==1)
x=1;
if(x==1)
cout<<"YES";
else
cout<<"NO";
//********************************************************************************************
    //t = clock() - t;
    //printf ( "Time 1: %lf\n", ( double ) t / CLOCKS_PER_SEC );
}


#include<bits/stdc++.h>
using namespace std;

#define int long long int
#define pb push_back

signed main(){

   // clock_t t = clock();
//********************************************************************************************

 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 int n,x,y;
 cin>>n;
 unordered_map<int,int> mh;
 map<int,int> ms;
 unordered_map<int,pair<int,int>> m;
 for(int i=1;i<=n;i++)
 {
      cin>>x>>y;
      ms[x]++;
      ms[y]--;
      m[x]={y,i};
      m[y]={x,i};
 }
 vector<pair<int,int>> v;
 for(auto i:ms)
 {
     // cout<<i.first<<"*"<<i.second<<endl;
      if(i.second==1)
      {
           for(auto j:mh)
           {
                if(m[j.first].first<m[i.first].first)
                {
       //              cout<<m[j.first].first<<" "<<m[i.first].first<<endl;
                     v.push_back({m[j.first].second,m[i.first].second});
                }
           }
           mh[i.first]=1;
      }
      else
      {
        //cout<<  m[i.first].first<<endl;
           mh.erase(m[i.first].first);
      }
}

mh.clear();
// cout<<v.size()<<endl;
for(auto i:v){
//      cout<<i.first<<" "<<i.second<<endl;
mh[i.first]=1;
mh[i.second]=1;
}
x=mh.size()-v.size();
if(x==1)
cout<<"YES";
else
cout<<"NO";
//********************************************************************************************
    //t = clock() - t;
    //printf ( "Time 1: %lf\n", ( double ) t / CLOCKS_PER_SEC );
}


#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
// __gnu_pbds::gp_hash_table<int,int> mp;
#define int long long int
#define pb push_back
vector<vector<int>> adj(500005);
vector<int> visit(500005);
int ans=1;
int cn=0,ce=0;
void dfs(int node)
{
     cn++;
     //cout<<node<<endl;
     visit[node]=1;
     for(auto u:adj[node])
     {
          if(!visit[u])
          {
               ce++;
               dfs(u);
          }
     }
}

signed main(){

   // clock_t t = clock();
//********************************************************************************************

 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 int n,x,y,c;
 cin>>n;

 unordered_set<int> us;
 __gnu_pbds::gp_hash_table<int,int> m3;
 map<int,int> mh;
 __gnu_pbds::gp_hash_table<int,tuple<int,int,int>> m;
  vector<int> msv(2*n);
  c=0;
 for(int i=1;i<=n;i++)
 {
       cin>>x>>y;
       msv[c]=x;
       msv[c+1]=y;
       c+=2;
      m[x]={y,i,1};
      m[y]={x,i,-1};
 }
 sort(msv.begin(),msv.end());
 x=0;
 for(auto i:msv)
 {
      if(get<2>(m[i])==1)
      {
           auto itr=mh.lower_bound(i);
           for(;itr!=mh.end();itr++)
           {
                if(itr->first<get<0>(m[i]))
                {
                     x--;
                     if((-x)>=n)
                     {
                          cout<<"NO";
                          return 0;
                     }
                     us.insert(get<1>(m[itr->first]));
                     us.insert(get<1>(m[i]));
                     //cout<<get<1>(m[itr->first])<<" "<<get<1>(m[i])<<endl;
                     adj[get<1>(m[itr->first])].pb(get<1>(m[i]));
                     adj[get<1>(m[i])].pb(get<1>(m[itr->first]));
                }
                else
                {
                     break;
                }
           }
           mh[get<0>(m[i])]=1;
      }
      else
      {
           mh.erase(i);
      }
     //  cout<<i<<"&&& ";
     //  for(auto k:mh)
     //  cout<<k.first<<" ";
     //  cout<<endl;
}
if(us.size()==0)
{
     cout<<"YES";
     return 0;
}
dfs(*us.begin());
if(cn!=ce+1)
{
     cout<<"NO";
     return 0;
}

for(auto i:us)
{
     if(!visit[i])
     {
          cout<<"NO";
          return 0;
     }
}
cout<<"YES";
//********************************************************************************************
    //t = clock() - t;
    //printf ( "Time 1: %lf\n", ( double ) t / CLOCKS_PER_SEC );
}