#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = (int)(n); i >= 0; i--)
#define rep(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = (a); i >= (int)(n); i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
using ll = long long;
using vi = vector<int>;
using vii = vector<vector<int>>;
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if ( a < b ) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if ( a > b ) { a = b; return true; } return false; }
ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x; }
ll lcm(ll x, ll y) { return x/gcd(x, y)*y; }

const int M = 200005;

void dfs(vii& G, vector<bool>& seen, int v) {
    if(!seen[v]) return;
    seen[v] = false;
    for(auto& nv: G[v]) {
        if(seen[nv]) dfs(G, seen, nv);
    }
}

int main() {
    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    
    vii G(M);
    REP(i,N) {
        G[A[i]].pb(A[N-i-1]);
        G[A[N-i-1]].pb(A[i]);
    }

    int s = 0;
    vector<bool> seen(M);
    for(int i:A) {
        if(!seen[i]) {
            seen[i] = true;
            s++;
        }
    }

    REP(i,M-1) {
        if(seen[i]) {
            dfs(G, seen, i);
            s--;
        }
    }
    cout << s << endl;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
inline ll read(){
	ll x=0; char ch=getchar(); bool d=1;
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') d=0;
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return d?x:-x;
}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=205;
bool f[N][N][N][2];
int a[N],b[N],ti[N];
int main(){
	// freopen("ssw.in","r",stdin);
	int n=read();
	memset(a,-1,sizeof(a));
	For(i,1,n){
		int x=read(),y=read();
		if(x!=-1&&a[x]!=-1) return puts("No"),0;
		if(y!=-1&&a[y]!=-1) return puts("No"),0;
		if(x!=-1&&y!=-1&&x>y) return puts("No"),0;
		if(x!=-1&&y!=-1) b[y]=x;
		if(x!=-1) a[x]=0,ti[x]=i;
		if(y!=-1) a[y]=1,ti[y]=i;
	}
	f[0][0][0][0]=f[0][0][0][1]=1;
	For(i,0,2*n-1){
		if(a[i+1]==-1||a[i+1]==0){
			f[i+1][i+1][i+1][0]|=f[i][0][0][1];
		}
		For(l,1,i) For(r,l,i) For(k,0,1){
			if(!f[i][l][r][k]) continue;
			if(a[i+1]==-1||a[i+1]==0){
				if(k==0) f[i+1][l][r+1][0]=1;
			}
			if(a[i+1]==-1||a[i+1]==1){
				if(b[i+1]&&l!=b[i+1]) continue;
				if(a[i+1]==1&&a[l]!=-1&&ti[l]!=ti[i+1]) continue;
				if(l==r) f[i+1][0][0][1]=1;
				else f[i+1][l+1][r][1]=1;
			}
		}
	}
	if(f[2*n][0][0][0]||f[2*n][0][0][1]) puts("Yes");
	else puts("No");
}