//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu) FUNC(printe) FUNC(printe0);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> inout(2 * n);
    auto no = [&](){ 
        cout << "No" << '\n';
        exit(0);
    };
    for(int i = 1; i <= n; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        if(a >= 0 && b >= 0 && a >= b){
            no();
        }
        if(a >= 0){
            if(inout[a]){ no(); }
            inout[a] = i;
        }
        if(b >= 0){
            if(inout[b]){ no(); }
            inout[b] = - i;
        }
    }
    printde(inout);
    vector<int> dp(2 * n + 1);
    dp[0] = 1;
    for(int i = 0; i < 2 * n; i++){
        if(!dp[i]){ continue; }
        for(int j = 1; i + j * 2 <= 2 * n; j++){
            bool ok = true;
            for(int k = 0; k < j; k++){
                if(inout[i + k] < 0){
                    ok = false;
                }else if(inout[i + k] > 0){
                    ok &= inout[i + j + k] == 0 || inout[i + j + k] == - inout[i + k];
                }
            }
            for(int k = 0; k < j; k++){
                if(inout[i + j + k] > 0){
                    ok = false;
                }else if(inout[i + j + k] < 0){
                    ok &= inout[i + k] == 0 || inout[i + k] == - inout[i + j + k];
                }
            }
            if(ok){
                printde(i, j, dp);
                dp[i + j * 2] = 1;
            }
        }
    }
    if(!dp[2 * n]){
        no();
    }
    cout << "Yes" << '\n';
}

//#include <atcoder/all>
#include <bits/stdc++.h>

using namespace std;

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9+7; //998244353;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}
//using mint = atcoder::modint1000000007;

ll max_rectangle(const vector<int>& vec) {
	ll rtn = 0;
	stack<pii> stk;
	auto calstk = [&](int ps, int ht){
		int t = ps;
		for( ;!stk.empty() && stk.top().second >= ht; stk.pop()){
			if(stk.top().second == ht) return;
			t = stk.top().first;
			rtn = max(rtn, 1LL * (ps-t) * stk.top().second);
		}
		if(ht >0 ) stk.push(pii(t, ht)); 
	};
	rep(i, sz(vec)) calstk(i, vec[i]);
	calstk(sz(vec), 0);
	return rtn;
}
int main(){
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a(n);
	rep(i, n) cin >>a[i];
	ll ans = max_rectangle(a);
	cout << ans <<"\n";
	return 0;
}