//
// Created by bytedance on 2020/4/10.
//


#include <bits/stdc++.h>
//#include <fstream>

using namespace std;
const int maxn = 1e5 + 5;

int a[maxn], b[maxn];
vector<int> even, odd;

int main() {
    int n;
    scanf("%d", &n);
    long long sum = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", a + i);
        sum += a[i];
    }
    for (int i = 0; i < n; i++) {
        scanf("%d", b + i);
    }
    even.clear();
    odd.clear();
    for (int i = 0; i < n; i++) {
        if (i & 1) {
            odd.push_back(b[i] - a[i]);
        } else {
            even.push_back(b[i] - a[i]);
        }
    }
    sort(odd.begin(), odd.end());
    sort(even.begin(), even.end());
    for (int i = 0; i < odd.size(); i++) {
        if (odd[i] + even[i] > 0) {
            sum += odd[i] + even[i];
        }
    }
    printf("%lld\n", sum);

    return 0;
}
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int64 cnt_diff(string s, char c) {
  int64 res = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    if (s[i] != c) res++;
  }
  return res;
}

int main() {
  string s;
  cin >> s;

  int N = s.size();
  string tmp = "";
  tmp += s.back();
  int atoha_onazi = N;
  char atoha_onazi_c = '*';
  int idx = N - 2;
  bool consective = false;
  int64 cnt = 0;

  while (idx >= 0) {
    if (s[idx] == atoha_onazi_c && consective == true) {
      atoha_onazi--;
      idx--;
      continue;
    }
    if (s[idx] == s[idx + 1]) {
      char tmp_c = s[idx];
      cnt += cnt_diff(tmp, tmp_c);
      debug(cnt_diff(tmp, tmp_c));
      if (tmp_c != atoha_onazi_c) cnt += N - atoha_onazi;
      atoha_onazi = idx;
      atoha_onazi_c = tmp_c;
      tmp = "";
      consective = true;
      debug(atoha_onazi_c, atoha_onazi, cnt);
    } else {
      tmp += s[idx];
      consective = false;
    }
    debug(tmp);
    idx--;
  }
  cout << cnt << '\n';
  return 0;
}