#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define ll long long
//#define file
using namespace std;

int a[100001],b[100001],n,i,j,k,l;
ll ans;

int main()
{
	#ifdef file
	freopen("b.in","r",stdin);
	#endif
	
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&a[i]);
	fo(i,1,n) scanf("%d",&j),ans+=(i&1)?j:a[i],a[i]-=j;
	for (i=2; i<=n; i+=2) a[i]=-a[i];
	
	sort(a+1,a+n+1);
	fd(i,n,n/2+1) ans+=a[i];
	printf("%lld\n",ans);
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i <= n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main(){
  int N;
  cin >> N;
  int a[N+10],b[N+10];
  rep(i,N) cin >> a[i] >> b[i];

  vector<int> tp(2*N),com(2*N, -1);
  bool ng = false;
  rep(i,N){
    if(a[i] != -1){
      --a[i];
      if(tp[a[i]]) ng = true;
      tp[a[i]] = i+1;
    }
    if(b[i] != -1){
      --b[i];
      if(tp[b[i]]) ng=true;
      tp[b[i]] = -(i+1);
    }

    if(a[i]!= -1 && b[i] != -1){
      com[a[i]] = b[i];
      com[b[i]] = a[i];
    }
  }
  if(ng){
    cout << "No" << endl;
    return 0;
  }

  vector<bool> dp(2*N+1);
  dp[0] = true;
  rep(i,2*N){
    if(!dp[i]) continue;
    for(int j=i+1; j<2*N; j++){
      int w = j - i + 1;
      if(w%2 == 1) continue;
      w /= 2;
      bool ok = true;
      vector<bool> exist(N+10);
      rep(k,w){
        int p = i + k;
        int q = i + k + w;
        if(com[p] != -1 && !(i <= com[p] && com[p] <= j)){
          ok = false; //共に-1ではない人が、片方が区間内なのにもう片方がはみ出している
        }
        if(com[q] != -1 && !(i <= com[q] && com[q] <= j)){
          ok = false;
        }

        bool same = true;
        if(tp[p] != 0 && tp[q] != 0){ 
          //p,qが共に-1でない
          if(tp[p] <= 0 || tp[p] + tp[q] != 0){ 
            //pは左向きか、pとqが別の人、(qが右向き)
            ok = false;
          }
        }
        if(tp[p] < 0 || tp[q] > 0){ //pが左向き、または、qが右向き
          ok = false;
        }
      }
      if(ok){
        dp[j+1] = true;
      }
    }
  }
  if(dp[2*N]) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}
