#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<complex>
#include<cstdio>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
int st[205],en[205];
int dp[205][205];
int rec(int l,int r){
	if(dp[l][r]!=-1)return dp[l][r];
	int l1=l,r1=(l+r)/2,d=(r-l)/2+1;
	int f=0;
	for(;l1<=r1;l1++){
		int s=st[l1];
		int e=en[l1+d];
		//cout<<s<<" "<<l1<<" "<<e<<" "<<l1+d<<"\n";
		if(s>0&&s!=l1+d){f=1;break;}
		if(e>0&&e!=l1){f=1;break;}
		if(s==-1&&e==-1){f=1;break;}
	}
	//cout<<l<<" "<<r<<" "<<f<<"\n";
	if(!f)return dp[l][r]=1;
	dp[l][r]=0;
	for(int i=l+1;i+1<r;i+=2){
		dp[l][r]|=(rec(l,i)&rec(i+1,r));
	}
	return dp[l][r];
}
void solve(){
	int n;
	cin>>n;
	int f=0;
	for(int i=0;i<n;i++){
		int s,e;
		cin>>s>>e;
		if(s!=-1){
			if(st[s])f=1;
			st[s]=e;
		}
		if(e!=-1){
			if(en[e])f=1;
			en[e]=s;
		}
	}
	if(f){cout<<"No";return;}
	for(int i=1;i<=2*n;i++){
		if(st[i]>0&&st[i]<=i){cout<<"No";return;}
		if(en[i]>0&&en[i]>=i){cout<<"No";return;}
		if(st[i]>0&&en[i]>0){cout<<"No";return;}
		if(st[i]!=0)en[i]=i;
		else if(en[i]!=0)st[i]=i;
	}
	for(int i=0;i<=2*n;i++)for(int j=0;j<=2*n;j++)dp[i][j]=-1;
	if(rec(1,2*n))cout<<"Yes";
	else cout<<"No";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string.h>
#include <assert.h>
#include <iomanip>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define ull unsigned long long
#define F first
#define S second
#define nl "\n"
#define ld long double
#define sortv(v) sort(v.begin(),v.end())
#define rsortv(v) sort(v.rbegin(),v.rend())
#define div 1000000007
#define div2 998244353
#define PI 3.141592653589793
#define inf 1000000000000000000
#define blk 320
#define pb push_back


void solve()
{
    int n;cin>>n;
    vector<pair<int,int>> v;
    set<int> s;
    for(int i=0;i<n;i++)
    {
        int x,col;cin>>x>>col;
        --col;
        v.pb({x,col});
        s.insert(col);
    }
    int m=s.size();
    map<int,int> mp;
    int idx=0;
    for(int x:s)
        mp[x]=idx++;
    int c[m][2];
    for(int i=0;i<m;i++)
    {
        c[i][0]=inf;
        c[i][1]=-inf;
    }
    for(int i=0;i<n;i++)
    {
        int x=v[i].F,col=v[i].S;
        col=mp[col];
        c[col][0]=min(c[col][0],x);
        c[col][1]=max(c[col][1],x);
    }
    int dp[m][2];
    for(int i=0;i<m;i++)
        dp[i][0]=dp[i][1]=inf;
    if(c[0][0]<0 && c[0][1]>0)
    {
        dp[0][0]=abs(c[0][1])+abs(c[0][1]-c[0][0]);
        dp[0][1]=abs(c[0][0])+abs(c[0][0]-c[0][1]);
    }
    else
    {
        if(c[0][1]<0)
        {
            dp[0][0]=abs(c[0][0]);
            dp[0][1]=abs(c[0][0])+abs(c[0][0]-c[0][1]);
        }
        else
        {
            dp[0][1]=c[0][1];
            dp[0][0]=c[0][1]+(c[0][1]-c[0][0]);
        }
    }
    for(int i=1;i<m;++i)
    {
        int l=c[i][0],r=c[i][1];
        if(r<=c[i-1][0])
            dp[i][0]=dp[i-1][0]+abs(c[i-1][0]-l);
        else
            dp[i][0]=dp[i-1][0]+abs((r-l))+abs(r-c[i-1][0]);

        if(r<=c[i-1][1])
            dp[i][0]=min(dp[i][0],dp[i-1][1]+abs(c[i-1][1]-l));
        else
            dp[i][0]=min(dp[i][0],dp[i-1][1]+(r-l)+abs(r-c[i-1][1]));

        if(c[i-1][0]<l)
            dp[i][1]=min(dp[i][1],dp[i-1][0]+abs(c[i-1][0]-r));
        else
            dp[i][1]=min(dp[i][1],dp[i-1][0]+abs(c[i-1][0]-l)+abs(r-l));

        if(c[i-1][1]<l)
            dp[i][1]=min(dp[i][1],dp[i-1][1]+abs(c[i-1][1]-r));
        else
            dp[i][1]=min(dp[i][1],dp[i-1][1]+abs(c[i-1][1]-l)+abs(r-l));
    }
    int ans=min(dp[m-1][0]+abs(c[m-1][0]),dp[m-1][1]+abs(c[m-1][1]));
    cout<<ans;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
        int t=1;
        //cin>>t;
        while(t--)
        {
            solve();
        }
}