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

typedef long long ll;
typedef unsigned long long ull;

#define mp make_pair
#define fr first
#define sc second

int n;
ll v[400010];

int main(){
	scanf("%d",&n);
	for(int i=0;i<2*n;i++)scanf("%lld",&v[i]);
	
	ll ret=0;
	priority_queue<ll> que;
	for(int i=0;i<n;i++){
		que.push(v[i]);
		que.push(v[2*n-1-i]);
		ret+=que.top();
		que.pop();
	}
	cout<<ret<<endl;
}


#include <algorithm>
#include <any>
#include <atomic>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

#define int long long

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define endl '\n'

#define si(v) ((int64_t)(v).size())
#define all(v) begin(v), end(v)
#define rep(i, n) for (ll (i) = 0; (i) < (n); ++(i))
#define rep2(i, n, m) for (ll (i) = n; (i) <= (m); ++(i))
#define rep3(i, n, m) for (ll (i) = n; (i) >= (m); --(i))
#define equal(a, b) (fabs((a) - (b)) < EPS)

#define INT(...) int __VA_ARGS__; IN(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__; IN(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__; IN(__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__; IN(__VA_ARGS__)

using namespace std;

using ll   = long long;
using ld   = long double;
using vi   = vector<int>;
using vvi  = vector<vi>;
using pii  = pair<int,int>;
using vpi  = vector<pii>;
using vvpi = vector<vpi>;

void IN() {}
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>,greater<T>>;
template <class S, class T> inline bool chmax(S &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class S, class T> inline bool chmin(S &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template <class S, size_t N, class T> void Fill(S (&array)[N], const T &val) { fill((T*)array, (T*)(array + N), val); }
template <class S, class... T> void IN(S &a, T &... b) { cin >> a; IN(b...); }
template <class T> ostream &operator << (ostream &os, const vector<T> &v) {
  for (auto itr = begin(v); itr != end(v); ++itr) {
    if (itr == begin(v)) os << *itr;
    else os << " " << *itr;
  }
  return os;
}

constexpr ll MOD   = 1000000007;
/* constexpr ll MOD   = 998244353; */
constexpr ll MAX   = 500005;
constexpr ll INF   = 2147483647;
constexpr ll INFLL = 9223372036854775807;
constexpr ld EPS   = (1e-10);

signed main(void)
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed; cout.precision(20);

  INT(n, k);
  int ans = 0;

  auto f = [&](int x) {
    if (x <= 1 || x > 2*n) return 0LL;
    if (x <= n) return x-1;
    if (x == 2*n) return 1LL;

    int diff = abs(2 * n - x);

    if (diff % 2) return (diff + 1) / 2 * 2;
    else return (diff / 2) * 2 + 1;
  };

  for (int b = 0; b + k <= 2 * n; ++b) {
    int a = b + k;
    if (a < 2) continue;

    ans += f(a) * f(b);
  }

  cout << ans << endl;

  return (0);
}
