#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <array>
#include <numeric>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
typedef tuple<ll, ll, ll> tl3;

//typedef modint998244353 mint;

const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const double EPS = 1e-7;
const int MAX = 1e5 + 5;

const string ATC = "atcoder";

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	vector<int> c(n);
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		sum += b[i];
		c[i] = a[i] - b[i];
	}
	vector<priority_queue<ll>> pq(2);
	for (int i = 0; i < n; i++) {
		pq[i % 2].push(c[i]);
	}

	ll ans = sum;
	while (!pq[0].empty()) {
		ll p = pq[0].top() + pq[1].top();
		pq[0].pop();
		pq[1].pop();
		if (p <= 0) {
			break;
		}

		ans += p;
	}
	cout << ans << endl;
}



#include <bits/stdc++.h>
using namespace std;

template <typename T> T my_gcd(T a, T b) {
  if (b == 0) {
    return a;
  }
  else {
    return my_gcd(b, a%b);
  }
}

int main() {
  int n;
  cin >> n;

  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x.at(i);
  }

  set<int> s;
  for (int i = 0; i < n; i++) {
    int now = x.at(i);
    for (int j = 2; j*j <= now; j++) {
      if (now%j == 0) {
        s.insert(j);
        while (now%j == 0) {
          now /= j;
        }
      }
    }
    if (now > 1) {
      s.insert(now);
    }
  }

  long long res = 1;
  vector<int> p;
  for (int e : s) {
    res *= e;
    p.push_back(e);
  }

  int m = p.size();
  for (int i = 0; i < (1 << m); i++) {
    long long now = 1;
    for (int j = 0; j < m; j++) {
      if (i & (1 << j)) {
        now *= p.at(j);
      }
    }
    if (now > res) {
      continue;
    }
    bool check = true;
    for (int k = 0; k < n; k++) {
      if (my_gcd(now, (long long)x.at(k)) == 1) {
        check = false;
        break;
      }
    }
    if (check) {
      res = min(res, now);
    }
  }

  cout << res << endl;
}