
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

//#include <atcoder/all>

//using namespace atcoder;
//typedef modint1000000007 mint;

int main(){
  int N;
  cin>>N;
  VL A(N),B(N);
  rep(i,N) cin>>A[i];
  rep(i,N) cin>>B[i];
  ll ans=0;
  rep(i,N) ans+=B[i];
  VVL X(2,VL(N/2));
  rep(i,N) X[i%2][i/2]=A[i]-B[i];
  rep(i,2) sort(all(X[i]));
  rep(i,N/2){
    ll tmp=X[0][N/2-1-i]+X[1][N/2-1-i];
    if(tmp>0) ans+=tmp;
  }
  cout<<ans<<endl;
}

#include <bits/stdc++.h>

const int N = 400000;

bool tag[N + 5]; int fa[N + 5], s[N + 5];
int find(int x) {return (fa[x] == x ? x : fa[x] = find(fa[x]));}
void unite(int x, int y) {
	int fx = find(x), fy = find(y);
	if( fx != fy ) fa[fx] = fy, tag[fy] |= tag[fx], s[fy] += s[fx];
	else tag[fx] = true;
}

int main() {
	int n; scanf("%d", &n);
	for(int i=1;i<=N;i++) fa[i] = i, s[i] = 1;
	for(int i=1,a,b;i<=n;i++) scanf("%d%d", &a, &b), unite(a, b);
	
	int ans = 0;
	for(int i=1;i<=N;i++) if( find(i) == i )
		ans += s[i] - (!tag[i]);
	printf("%d\n", ans);
}