#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
int main(){
     ll n;
     cin>>n;
     V<V<ll>> g(n+1);
     for(ll i=1;i<=n;i++){
            for(ll j=i;j<=n;j+=i){
                  g[j].emplace_back(i);
            }
     }
     int ma=0;
     for(int i=1;i<=n;i++){
           chmax(ma,int(g[i].size()));
     }
     V<int> ans(n,0);
     for(int i=0;i<n;i++){
            V<bool> ok(ma+1,true);
            for(int v:g[i+1]){
                    ok[ans[v-1]]=false;
            }
            for(int j=1;j<=ma;j++){
                  if(ok[j]){
                         ans[i]=j;
                         break;
                  }
            }
     }
    print(ans);
}
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
    int N;
    cin >> N;
    V<int> A(N), B(N);
    int sz = N * 2;
    V<int> have(sz), go(sz, -1);

    bool ng = true;

    rep(i, N) {
        cin >> A[i] >> B[i];
        if (A[i] != -1) {
            --A[i];
            if (have[A[i]]) ng = false;
            have[A[i]] = i + 1;
        }
        if (B[i] != -1) {
            --B[i];
            if (have[B[i]]) ng = false;
            have[B[i]] = -(i + 1);
        }

        if (A[i] != -1 && B[i] != -1) {
            go[A[i]] = B[i];
            go[B[i]] = A[i];
        }
    }
    if (!ng) {
        puts("No");
        return 0;
    }

    V<bool> dp(sz + 1);
    dp[0] = true;

    rep(i, sz) {
        if (!dp[i]) continue;
        for (int j = i + 1; j < sz; ++j) {
            int w = j - i + 1;
            if (w & 1) continue;
            w /= 2;
            bool ok = true;
            V<bool> exist(N);

            rep(k, w) {
                int l = i + k, r = i + k + w;
                if (go[l] != -1 && go[l] != r) {
                    ok = false;
                }
                if (go[r] != -1 && go[r] != l) {
                    ok = false;
                }

                if (have[l] && have[r]) {
                    if (have[l] + have[r]) {
                        ok = false;
                    }
                }
                if (have[l] < 0 || have[r] > 0) {
                    ok = false;
                }
            }
            if (ok) {
                dp[j + 1] = true;
            }
        }
    }
    puts(dp[sz] ? "Yes" : "No");

    return 0;
}
