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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  int n;
  cin >> n;
  long long ans = 0;
  vector<int> a(2 * n);
  for (auto &i : a) cin >> i;
  priority_queue<int, vector<int>, greater<int>> pq;
  pq.emplace(max(a[n - 1], a[n]));
  for (int i = 1; i < n; i++) {
    int u = a[n - i - 1];
    int v = a[n + i];
    if (pq.top() < min(u, v)) {
      pq.pop();
      pq.emplace(min(u, v));
    }
    pq.emplace(max(u, v));    
  }
  while (!pq.empty()) {
    ans += pq.top();
    pq.pop();
  }
  cout << ans << '\n';
  return 0;
}

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

int main(){
    int N; cin >> N;
    vector<pair<ll, ll>> range(N);
    for(int i = 0; i < N; i++){
        int t; ll l, r; cin >> t >> l >> r;
        l *= 2LL; r *= 2LL;
        if(t == 2 || t == 4)r--;
        if(t == 3 || t == 4)l++;
        range[i] = make_pair(l, r);
    }
    int ans = 0;
    for(int i = 0; i < N - 1; i++){
        ll l1 = range[i].first, r1 = range[i].second;
        for(int j = i + 1; j < N; j++){
            ll l2 = range[j].first, r2 = range[j].second;
            if(r1 < l2 || l1 > r2)continue;
            ans++;
        }
    }
    cout << ans << endl;
}