#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3e5 + 5;
ll tr[N << 1];
struct Node {
	int num, idx;
	bool operator<(const Node& a) {
		return num < a.num;
	}
};
Node a[N];
int n, b[N];
inline int lowbit(int x) { return x & -x; }
void add(int idx, int val) {
	while (idx <= 2 * n) tr[idx] += val, idx += lowbit(idx);
	return;
}
int getsum(int idx) {
	int cnt = 0;
	while (idx) cnt += tr[idx], idx -= lowbit(idx);
	return cnt;
}
ll res;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i].num;
		a[i].idx = i;
	}
	sort(a + 1, a + 1 + n);
	for (int i = 1; i <= n; ++i) {
		add(a[i].idx, 1);
		b[a[i].num] = i - getsum(a[i].idx);
		res += b[a[i].num];
	}
	sort(a + 1, a + 1 + n, [](Node& c, Node& d){
		return c.idx < d.idx;
		});
	for (int i = 1; i <= n; ++i) {
		cout << res << endl;
		res =res -  a[i].num ;
		res = res +  n - a[i].num - 1ll;
	}
	return 0;
}
#pragma comment(linker, "/STACK:512000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
#ifdef AIM
#include <sys/resource.h>
#endif
using namespace std;

#define all(a) a.begin(), a.end()
typedef long long li;
typedef long double ld;
void solve(__attribute__((unused)) bool);
void precalc();
clock_t start;
#define FILENAME ""

int main() {
#ifdef AIM
  string s = FILENAME;
//    assert(!s.empty());
  freopen("/home/alexandero/ClionProjects/cryptozoology/input.txt", "r", stdin);
  //freopen("/home/alexandero/ClionProjects/cryptozoology/output.txt", "w", stdout);
#else
//    freopen(FILENAME ".in", "r", stdin);
//    freopen(FILENAME ".out", "w", stdout);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    start = clock();
    int t = 1;
#ifndef AIM
  cout.sync_with_stdio(0);
  cin.tie(0);
#endif

#ifdef AIM
  const rlim_t kStackSize = 256 * 1024 * 1024;
  struct rlimit rl;
  int result;

  result = getrlimit(RLIMIT_STACK, &rl);
  if (result == 0)
  {
    if (rl.rlim_cur < kStackSize)
    {
      rl.rlim_cur = kStackSize;
      result = setrlimit(RLIMIT_STACK, &rl);
      if (result != 0)
      {
        fprintf(stderr, "setrlimit returned result = %d\n", result);
      }
    }
  }
#endif

  precalc();
  cout.precision(10);
  cout << fixed;
  //cin >> t;
  int testNum = 1;
  while (t--) {
      //cout << "Case #" << testNum++ << ": ";
      solve(true);
  }
  cout.flush();
#ifdef AIM1
    while (true) {
      solve(false);
  }
#endif

#ifdef AIM
  cout.flush();
  auto end = clock();

  usleep(10000);
  print_stats(end - start);
  usleep(10000);
#endif

    return 0;
}

template<typename T>
T binpow(T q, T w, T mod) {
    if (!w)
        return 1 % mod;
    if (w & 1)
        return q * 1LL * binpow(q, w - 1, mod) % mod;
    return binpow(q * 1LL * q % mod, w / 2, mod);
}

template<typename T>
T gcd(T q, T w) {
    while (w) {
        q %= w;
        swap(q, w);
    }
    return q;
}
template<typename T>
T lcm(T q, T w) {
    return q / gcd(q, w) * w;
}

template <typename T>
void make_unique(vector<T>& a) {
    sort(all(a));
    a.erase(unique(all(a)), a.end());
}

template<typename T>
void relax_min(T& cur, T val) {
    cur = min(cur, val);
}

template<typename T>
void relax_max(T& cur, T val) {
    cur = max(cur, val);
}

void precalc() {
}

#define int li
//const int mod = 1000000007;

void solve(__attribute__((unused)) bool read) {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ans += a[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  vector<vector<pair<int, int>>> res(2);
  for (int i = 0; i < n; ++i) {
    res[i & 1].push_back({a[i], b[i]});
  }
  for (auto& vec : res) {
    sort(all(vec), [&](const pair<int, int>& q, const pair<int, int>& w) {
      return q.first - q.second < w.first - w.second;
    });
  }
  int cur_ans = ans;
  for (int i = 0; i < res[0].size(); ++i) {
    for (int j = 0; j < 2; ++j) {
      cur_ans -= res[j][i].first;
      cur_ans += res[j][i].second;
    }
    relax_max(ans, cur_ans);
  }

  cout << ans << "\n";
}